/* ============ DESIGN TOKENS ============ */
:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #14172a;
  --ink-2: #3d4258;
  --muted: #7c829c;
  --line: #e6e8f2;
  --line-2: #eef0f7;

  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef0ff;

  --ok: #059669;
  --ok-bg: #e7f9f1;
  --warn: #d97706;
  --warn-bg: #fff4e0;
  --bad: #e11d48;
  --bad-bg: #ffe8ec;
  --sky: #0ea5e9;
  --sky-bg: #e3f4fe;

  --r-xs: 8px;
  --r-sm: 10px;
  --r: 14px;
  --r-lg: 18px;
  --r-xl: 22px;

  --shadow-xs: 0 1px 2px rgba(20, 23, 42, .05);
  --shadow-sm: 0 1px 3px rgba(20, 23, 42, .06), 0 1px 2px rgba(20, 23, 42, .04);
  --shadow: 0 4px 16px rgba(60, 60, 130, .08);
  --shadow-lg: 0 12px 32px rgba(20, 23, 42, .16);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --h-top: 56px;
}

@media (prefers-color-scheme:dark) {
  :root {
    --bg: #0b0d18;
    --surface: #151827;
    --surface-2: #1b1f31;
    --ink: #eef0fb;
    --ink-2: #c3c7dc;
    --muted: #8a90ab;
    --line: #252a40;
    --line-2: #1f2338;
    --brand-soft: #1e1f45;
    --ok-bg: #0a3d2e;
    --warn-bg: #3d2a0a;
    --bad-bg: #3d0f1e;
    --sky-bg: #0a2c44;
    --shadow: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}

/* ============ RESET ============ */
*,
*::before,
*::after {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%
}

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  padding-bottom: var(--safe-b);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0
}

img,
svg {
  display: block;
  max-width: 100%
}

code {
  background: var(--line);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--ink-2)
}

/* ============ HEADER ============ */
.top {
  position: sticky;
  top: 0;
  z-index: 30;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  padding-top: var(--safe-t);
  box-shadow: 0 4px 18px rgba(79, 70, 229, .28);
}

.top-in {
  max-width: 1100px;
  margin: auto;
  padding: 10px 14px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
}

.brand {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 0
}

.logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .22);
  display: grid;
  place-items: center;
  font-size: 17px;
  flex: none;
  backdrop-filter: blur(8px);
}

.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.2px;
  line-height: 1.1
}

.brand small {
  opacity: .8;
  font-size: 11px
}

.datebar {
  display: flex;
  align-items: center;
  gap: 4px
}

.datebar input {
  background: rgba(255, 255, 255, .18);
  border: 0;
  border-radius: 9px;
  padding: 6px 8px;
  color: #fff;
  font-weight: 600;
  font-size: 12.5px;
  color-scheme: dark;
  min-width: 0;
  max-width: 130px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: none;
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: transform .12s, background .15s;
}

.icon-btn:active {
  transform: scale(.9);
  background: rgba(255, 255, 255, .28)
}

.chip-btn {
  background: #fff;
  color: var(--brand);
  font-weight: 700;
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  transition: transform .12s;
}

.chip-btn:active {
  transform: scale(.94)
}

.search {
  grid-column: 1/-1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, .96);
  border-radius: 11px;
  padding: 0 11px;
  color: #5a5f78;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .08) inset;
}

.search svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  flex: none
}

.search input {
  flex: 1;
  border: 0;
  background: none;
  padding: 9px 0;
  outline: none;
  color: #1c2030;
  min-width: 0;
  font-size: 13.5px;
}

.search input::placeholder {
  color: #9aa0b8
}

/* ============ MAIN ============ */
main {
  max-width: 1100px;
  margin: auto;
  padding: 10px 12px calc(80px + var(--safe-b));
}

/* ============ STATS ============ */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.stat {
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 8px 8px 11px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--c);
  border-radius: 0 3px 3px 0;
}

.stat b {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  color: var(--c);
  font-weight: 800
}

.stat span {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .02em
}

.s-total {
  --c: var(--brand)
}

.s-present {
  --c: var(--ok)
}

.s-absent {
  --c: var(--bad)
}

.s-warn {
  --c: var(--warn)
}

/* ============ LIST ============ */
.cols {
  display: none
}

.list {
  display: grid;
  gap: 7px
}

.item {
  background: var(--surface);
  border-radius: var(--r);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 8px;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  cursor: pointer;
  transition: transform .12s, box-shadow .15s;
  animation: up .22s both;
  border: 1px solid transparent;
}

.item:active {
  transform: scale(.99);
  box-shadow: var(--shadow-xs)
}

@keyframes up {
  from {
    opacity: 0;
    transform: translateY(6px)
  }

  to {
    opacity: 1;
    transform: none
  }
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: 13.5px;
  background: var(--av, var(--brand));
  flex: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .12);
}

.who {
  min-width: 0
}

.who b {
  display: block;
  font-size: 13.5px;
  line-height: 1.25;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.who small {
  color: var(--muted);
  font-size: 11.5px;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.shift {
  display: inline-block;
  margin-left: 5px;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--sky-bg);
  color: var(--sky);
  font-size: 10px;
  font-weight: 700;
  vertical-align: middle;
}

.badge {
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  background: var(--line);
  color: var(--muted);
  justify-self: end;
  white-space: nowrap;
}

.badge.Present {
  background: var(--ok-bg);
  color: var(--ok)
}

.badge.Absent {
  background: var(--bad-bg);
  color: var(--bad)
}

.badge.Leave {
  background: var(--warn-bg);
  color: var(--warn)
}

.times {
  grid-column: 1/-1;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  align-items: stretch;
}

.t {
  border-radius: 10px;
  padding: 6px 9px;
  min-width: 0
}

.t small {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  opacity: .9;
  margin-bottom: 1px;
}

.t b {
  font-size: 14px;
  font-weight: 800;
  display: block;
  line-height: 1.15
}

.t sup {
  font-size: 9px;
  font-weight: 700;
  margin-left: 2px
}

.t.in {
  background: var(--ok-bg);
  color: var(--ok)
}

.t.out {
  background: var(--warn-bg);
  color: var(--warn)
}

.t.none {
  background: var(--line-2);
  color: var(--muted)
}

.pc {
  display: grid;
  place-items: center;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--line-2);
  font-weight: 800;
  min-width: 40px;
  text-align: center;
  line-height: 1.1;
  color: var(--ink-2);
  font-size: 14px;
}

.pc small {
  display: block;
  font-size: 9px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase
}

.go {
  display: none
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  background: var(--surface);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
}

.empty big {
  display: block;
  font-size: 36px;
  margin-bottom: 6px
}

.skel {
  height: 96px;
  border-radius: var(--r);
  background: linear-gradient(90deg, var(--surface) 25%, var(--line-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: sh 1.2s infinite;
}

@keyframes sh {
  to {
    background-position: -200% 0
  }
}

/* ============ BOTTOM SHEET / DIALOG ============ */
dialog {
  border: 0;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
  max-width: 520px;
  margin: auto auto 0;
  border-radius: 20px 20px 0 0;
  max-height: 90dvh;
  overflow: auto;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, .28);
  animation: sheet .26s cubic-bezier(.2, .9, .3, 1);
}

dialog::backdrop {
  background: rgba(10, 12, 30, .5);
  backdrop-filter: blur(2px)
}

@keyframes sheet {
  from {
    transform: translateY(60%);
    opacity: .4
  }

  to {
    transform: none;
    opacity: 1
  }
}

.grab {
  width: 36px;
  height: 4px;
  border-radius: 9px;
  background: var(--line);
  margin: 7px auto 0
}

.sheet-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px 8px
}

.sheet-head .avatar {
  width: 38px;
  height: 38px;
  font-size: 14px
}

.sheet-head .icon-btn {
  background: var(--line-2);
  color: var(--muted);
  font-size: 13px;
  margin-left: auto;
  width: 30px;
  height: 30px;
}

.sh-txt {
  min-width: 0
}

.sh-txt h2 {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.2
}

.sh-txt p {
  margin: 0;
  color: var(--muted);
  font-size: 11.5px
}

.tabs {
  display: flex;
  gap: 4px;
  margin: 0 14px 0;
  background: var(--surface-2);
  padding: 3px;
  border-radius: 11px;
  border: 1px solid var(--line-2);
}

.tab {
  flex: 1;
  padding: 8px 6px;
  border-radius: 8px;
  font-weight: 600;
  color: var(--muted);
  font-size: 12.5px;
  transition: .15s;
}

.tab.on {
  background: var(--surface);
  color: var(--brand);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .08);
}

.tab i {
  font-style: normal;
  background: var(--brand);
  color: #fff;
  border-radius: 99px;
  padding: 0 6px;
  font-size: 10px;
  margin-left: 3px;
  font-weight: 700;
}

.pane {
  display: none;
  padding: 14px 14px calc(14px + var(--safe-b))
}

.pane.on {
  display: block
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px
}

.field>span {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px
}

.field input {
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 9px 10px;
  width: 100%;
  min-width: 0;
  outline: none;
  transition: .15s;
  color-scheme: light dark;
  font-size: 13px;
}

.field input:focus,
.add-punch input:focus,
.pr input:focus {
  border-color: var(--brand);
  background: var(--surface);
}

.field.in>span {
  color: var(--ok)
}

.field.out>span {
  color: var(--warn)
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px
}

.seg button {
  padding: 9px 6px;
  border-radius: 10px;
  background: var(--surface-2);
  font-weight: 600;
  color: var(--muted);
  border: 1.5px solid transparent;
  font-size: 12.5px;
  transition: .15s;
}

.seg button.on[data-v=Present] {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok)
}

.seg button.on[data-v=Absent] {
  background: var(--bad-bg);
  color: var(--bad);
  border-color: var(--bad)
}

.seg button.on[data-v=Leave] {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn)
}

.hint {
  color: var(--muted);
  font-size: 11.5px;
  margin: 2px 0 12px;
  line-height: 1.4
}

.btns {
  display: grid;
  gap: 7px
}

.btn {
  padding: 11px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 13.5px;
  transition: transform .12s, box-shadow .15s;
}

.btn:active {
  transform: scale(.97)
}

.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, .32);
}

.btn.ghost {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line-2)
}

.btn.sm {
  padding: 9px 12px;
  border-radius: 10px;
  white-space: nowrap;
  font-size: 12.5px
}

.btn[disabled] {
  opacity: .55;
  pointer-events: none
}

.punch-list {
  display: grid;
  gap: 6px;
  margin-bottom: 10px
}

.pr {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 5px;
  align-items: center;
  background: var(--surface-2);
  padding: 6px;
  border-radius: 11px;
}

.pr input {
  background: var(--surface);
  border: 1.5px solid transparent;
  border-radius: 8px;
  padding: 7px 8px;
  min-width: 0;
  width: 100%;
  outline: none;
  color-scheme: light dark;
  font-size: 12.5px;
}

.pr .src {
  grid-column: 1/-1;
  font-size: 10.5px;
  color: var(--muted);
  padding: 0 4px
}

.sq {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  font-size: 14px;
  display: grid;
  place-items: center;
  transition: transform .12s;
}

.sq:active {
  transform: scale(.9)
}

.sq.ok {
  background: var(--ok-bg);
  color: var(--ok)
}

.sq.del {
  background: var(--bad-bg);
  color: var(--bad)
}

.add-punch {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px
}

.add-punch input {
  background: var(--surface-2);
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
  outline: none;
  color-scheme: light dark;
  font-size: 12.5px;
}

/* ============ TOAST ============ */
#toast {
  position: fixed;
  top: calc(10px + var(--safe-t));
  left: 50%;
  transform: translate(-50%, -160%);
  padding: 10px 16px;
  border-radius: 12px;
  color: #fff;
  background: #111827;
  font-weight: 600;
  font-size: 13px;
  z-index: 99;
  transition: transform .3s cubic-bezier(.2, .9, .3, 1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  max-width: 92vw;
}

#toast.show {
  transform: translate(-50%, 0)
}

#toast.err {
  background: var(--bad)
}

#toast.ok {
  background: var(--ok)
}

/* ============ DESKTOP ============ */
@media (min-width:760px) {
  .top-in {
    grid-template-columns: auto 1fr auto;
    gap: 16px;
    padding: 12px 22px
  }

  .search {
    grid-column: auto;
    order: 2;
    max-width: 380px;
    justify-self: center;
    width: 100%
  }

  .datebar {
    order: 3
  }

  main {
    padding: 16px 22px 40px
  }

  .stat {
    padding: 12px 14px 12px 16px
  }

  .stat b {
    font-size: 24px
  }

  .cols,
  .item {
    display: grid;
    grid-template-columns: 2.4fr 1.1fr 1.1fr .7fr .9fr 36px;
    gap: 12px;
    align-items: center;
  }

  .cols {
    padding: 0 14px 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
  }

  .item {
    padding: 10px 14px;
    border: 1.5px solid transparent
  }

  .item:hover {
    border-color: var(--brand);
    transform: translateY(-1px);
    box-shadow: var(--shadow)
  }

  .item .lead {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0
  }

  .times {
    display: contents
  }

  .pc {
    background: none;
    display: block;
    text-align: left;
    padding: 0;
    font-size: 14px
  }

  .pc small {
    display: none
  }

  .badge {
    justify-self: start
  }

  .go {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--surface-2);
    color: var(--muted);
    transition: .15s;
  }

  .item:hover .go {
    background: var(--brand);
    color: #fff
  }

  dialog {
    margin: auto;
    border-radius: 20px;
    max-height: 86vh
  }

  .grab {
    display: none
  }

  .btns {
    grid-template-columns: 1fr 1fr
  }
}

@media (max-width:759px) {
  .item .lead {
    display: contents
  }

  .item .go {
    display: none
  }

  .avatar {
    width: 34px;
    height: 34px;
    font-size: 13px
  }

  .stat {
    padding: 7px 6px 7px 10px
  }

  .stat b {
    font-size: 16px
  }

  .stat span {
    font-size: 9.5px
  }
}

@media (max-width:400px) {
  .datebar .chip-btn {
    display: none
  }

  .datebar input {
    max-width: 118px;
    font-size: 12px
  }

  .brand h1 {
    font-size: 15px
  }

  .brand small {
    display: none
  }

  .stats {
    gap: 5px
  }

  .stat {
    padding: 6px 4px 6px 9px
  }

  .stat b {
    font-size: 15px
  }

  .stat span {
    font-size: 9px
  }

  .item {
    padding: 9px 10px
  }

  .t b {
    font-size: 13px
  }
}

@media (prefers-reduced-motion:reduce) {
  * {
    animation: none !important;
    transition: none !important
  }

  html {
    scroll-behavior: auto
  }
}