/* staffkit — visual system grounded in shadcn/ui neutral + Vercel Geist:
   white-on-white with hairline borders (no card-on-gray), near-black primary,
   neutral grays, accent used sparingly, tabular numerals, quiet labels. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --muted: #f5f5f5;          /* hover / secondary surfaces */
  --border: #e5e5e5;
  --text: #171717;
  --text-2: #525252;
  --text-3: #8f8f8f;
  --primary: #171717;        /* buttons are near-black; color is for meaning */
  --accent: #c2410c;         /* small moments only: links, active nav, focus */
  --green: #15803d; --green-bg: #f0fdf4; --green-bd: #bbf7d0;
  --red: #b91c1c;   --red-bg: #fef2f2;   --red-bd: #fecaca;
  --amber: #92400e; --amber-bg: #fffbeb; --amber-bd: #fde68a;
  --radius: 10px;
  --tabbar-h: 60px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  font-size: .9375rem;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
a { color: var(--text); text-decoration: none; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

/* ---------- header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  min-height: 54px;
}
.topbar h1 { font-size: 1.05rem; margin: 0; flex: 1; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { color: var(--text-3); font-weight: 400; font-size: .9rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin: -4px;
  border: 0; background: none; color: var(--text-2); border-radius: 8px;
}
.icon-btn:active { background: var(--muted); }
.icon-btn.accent { color: var(--text-2); }
.btn-text {
  border: 0; background: none; color: var(--text); font-weight: 500;
  padding: 8px 10px; margin: -8px -10px; border-radius: 8px; font-size: .9rem;
}
.btn-text:active { background: var(--muted); }

/* ---------- screens / layout ---------- */
.screen { padding: 16px 16px calc(var(--tabbar-h) + 24px); }
.section-label {
  font-size: .8rem; font-weight: 500;
  color: var(--text-3); margin: 22px 2px 8px;
}
.section-label:first-child { margin-top: 4px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }

/* list rows */
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 12px 14px; min-height: 52px;
  background: var(--surface); border: 0; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.row:last-child { border-bottom: 0; }
.row:active { background: var(--muted); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
.row .meta { color: var(--text-3); font-size: .85rem; display: block; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta-2 { color: var(--text-3); font-size: .8rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta.wrap { white-space: normal; }
.row .right { text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.chevron { color: var(--text-3); flex-shrink: 0; }

/* status chips — tinted bg + tinted border + dark tinted text (Geist 1/3/9) */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: .76rem; font-weight: 500; white-space: nowrap;
  border: 1px solid var(--border); background: var(--muted); color: var(--text-2);
}
.pill.green { background: var(--green-bg); border-color: var(--green-bd); color: var(--green); }
.pill.red { background: var(--red-bg); border-color: var(--red-bd); color: var(--red); }
.pill.amber { background: var(--amber-bg); border-color: var(--amber-bd); color: var(--amber); }
.pill.gray { background: var(--muted); border-color: var(--border); color: var(--text-2); }
.pill.accent { background: #fff7ed; border-color: #fed7aa; color: var(--accent); }

/* ---------- buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 44px; padding: 10px 14px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; font-size: .9rem;
}
.btn:active { background: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: #2e2e2e; }
.btn.danger { color: var(--red); }
.btn.small { width: auto; min-height: 34px; padding: 5px 12px; font-size: .84rem; border-radius: 7px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn-stack > .btn + .btn { margin-top: 8px; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .84rem; font-weight: 500; color: var(--text-2); margin: 0 1px 6px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 1rem;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus,
.msg-box:focus, .search input:focus {
  outline: none; border-color: #a3a3a3; box-shadow: 0 0 0 3px rgba(0,0,0,.06);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.hint { color: var(--text-3); font-size: .84rem; margin: 6px 1px 0; }

/* day-of-week picker */
.daypick { display: flex; gap: 6px; }
.daypick button {
  flex: 1; min-height: 40px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-weight: 500; font-size: .85rem;
}
.daypick button.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* search */
.search { position: relative; margin-bottom: 12px; }
.search input {
  width: 100%; min-height: 42px; padding: 10px 12px 10px 38px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-size: 1rem;
}
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

/* ---------- KPI stats — quiet label on top, large tabular number below ---------- */
.stat-strip { display: flex; gap: 10px; margin-bottom: 16px; }
.stat {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; text-align: left;
  display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 2px;
}
.stat .n {
  font-size: 1.45rem; font-weight: 600; line-height: 1.25; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.stat .l { color: var(--text-3); font-size: .78rem; font-weight: 500; }
.stat.alert .n { color: var(--red); }
button.stat:active { background: var(--muted); }

/* time block on class rows */
.timecol { width: 70px; flex-shrink: 0; text-align: left; font-variant-numeric: tabular-nums; }
.timecol .t1 { font-weight: 600; display: block; font-size: .9rem; }
.timecol .t2 { color: var(--text-3); font-size: .8rem; display: block; }

/* ---------- attendance ---------- */
.att-row {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px 9px 14px; min-height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.att-row:last-child { border-bottom: 0; }
.att-row .name { flex: 1; font-weight: 500; min-width: 0; letter-spacing: -.01em; }
.att-row .name .nm { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-row .name .sub { display: block; font-weight: 400; color: var(--text-3); font-size: .8rem; }
.att-row .avatar.sm { width: 28px; height: 28px; font-size: .68rem; }
.att-seg { display: flex; gap: 5px; flex-shrink: 0; }
.att-seg button {
  min-width: 47px; min-height: 40px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-2); font-weight: 500; font-size: .82rem; padding: 0 6px;
}
.att-seg button.on-present { background: var(--green-bg); border-color: var(--green-bd); color: var(--green); }
.att-seg button.on-absent { background: var(--red-bg); border-color: var(--red-bd); color: var(--red); }
.att-seg button.on-late { background: var(--amber-bg); border-color: var(--amber-bd); color: var(--amber); }

.progress-note { text-align: center; color: var(--text-3); font-size: .84rem; margin: 12px 0 0; }

/* ---------- billing ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav .label { font-weight: 600; font-size: 1rem; letter-spacing: -.01em; }
.month-nav button {
  width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.month-nav button:active { background: var(--muted); }
.bill-summary { display: flex; gap: 10px; margin-bottom: 16px; }

/* ---------- avatars — neutral, not rainbow ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--muted); border: 1px solid var(--border);
  color: var(--text-2); font-weight: 600; font-size: .78rem; letter-spacing: .01em;
}
.avatar.sm { width: 30px; height: 30px; font-size: .68rem; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); border-radius: 14px 14px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; max-height: 80vh; overflow-y: auto;
}

/* message composer */
.msg-box {
  width: 100%; min-height: 110px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; line-height: 1.5;
  resize: vertical;
}

/* schedule-makeup inline link on absent rows */
.mk-link {
  border: 0; background: none; color: var(--accent); font-weight: 500;
  font-size: .8rem; padding: 4px 6px; margin: -4px 0 -4px -6px;
}

/* test-mode hint box */
.hint-box {
  background: var(--amber-bg); border: 1px solid var(--amber-bd); color: var(--amber);
  border-radius: 8px; padding: 10px 12px;
  font-size: .84rem; margin-bottom: 14px; line-height: 1.5;
}

/* switch (autopay) */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .knob { position: absolute; inset: 0; border-radius: 999px; background: #d4d4d4; transition: background .15s; cursor: pointer; }
.switch .knob::before {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: transform .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .knob { background: var(--text); }
.switch input:checked + .knob::before { transform: translateX(18px); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-box { width: 100%; max-width: 360px; }
.login-box h1 { text-align: center; font-size: 1.35rem; letter-spacing: -.02em; margin: 0 0 4px; }
.login-box .tagline { text-align: center; color: var(--text-3); font-size: .9rem; margin: 0 0 28px; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 40px 24px; color: var(--text-3); font-size: .9rem; }
.empty .big { font-size: .98rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%) translateY(20px);
  background: #171717; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: .88rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; max-width: 90vw; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }

/* ---------- bottom tab bar (mobile) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  background: rgba(255,255,255,.94); backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  display: flex; height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  max-width: 560px; margin: 0 auto;
}
.tabbar button {
  flex: 1; border: 0; background: none; color: var(--text-3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .68rem; font-weight: 500;
}
.tabbar button.active { color: var(--text); }

/* sidebar-only elements, hidden on mobile (.tabbar prefix outranks `.tabbar button`) */
.tabbar .side-brand, .tabbar .side-spacer, .tabbar .side-settings { display: none; }
.only-desktop { display: none; }

/* ====================================================================
   Desktop (≥900px): light sidebar + quiet page header + reading column
   ==================================================================== */
@media (min-width: 900px) {
  body { padding-left: 232px; font-size: .875rem; }
  #app { max-width: 800px; margin: 0 auto; min-height: 100vh; }

  /* --- sidebar (restyled tabbar): white, hairline border, muted items --- */
  .tabbar {
    left: 0; top: 0; bottom: 0; right: auto; width: 232px; height: auto; max-width: none;
    margin: 0; flex-direction: column; align-items: stretch;
    background: #fafafa; border-top: 0; border-right: 1px solid var(--border);
    padding: 16px 10px; gap: 1px; backdrop-filter: none;
  }
  .tabbar button {
    flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 10px;
    padding: 8px 10px; border-radius: 7px; min-height: 36px;
    color: var(--text-2); font-size: .875rem; font-weight: 500;
  }
  .tabbar button svg { width: 18px; height: 18px; }
  .tabbar button:hover { background: #f0f0f0; color: var(--text); }
  .tabbar button.active { background: #ececec; color: var(--text); }
  .tabbar .side-brand {
    display: block; color: var(--text); font-weight: 600; font-size: .95rem; letter-spacing: -.01em;
    padding: 4px 10px 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .tabbar .side-spacer { display: block; flex: 1; }
  .tabbar .side-settings { display: flex; }

  /* --- page header --- */
  .topbar {
    background: var(--bg); backdrop-filter: none;
    padding: 26px 4px 14px; min-height: 0;
    border-bottom: 1px solid var(--border);
  }
  .topbar h1 { font-size: 1.3rem; font-weight: 600; letter-spacing: -.02em; }
  .topbar .icon-btn[data-nav="#/settings"] { display: none; }

  .screen { padding: 20px 4px 48px; }

  /* --- hover affordances --- */
  button.row:hover { background: #fafafa; }
  button.stat:hover { background: #fafafa; }
  .btn:hover { background: var(--muted); }
  .btn.primary:hover { background: #2e2e2e; }
  .btn { min-height: 38px; font-size: .86rem; }
  .field input, .field select { min-height: 40px; font-size: .9rem; }
  .search input { font-size: .9rem; }
  .stat { padding: 14px 16px; }
  .stat .n { font-size: 1.6rem; }

  /* --- sheets become centered modals --- */
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { border-radius: 12px; max-width: 440px; padding: 18px 18px 20px; border: 1px solid var(--border); }

  #toast { bottom: 32px; left: calc(50% + 116px); }

  /* login has no sidebar — pin it over the full viewport */
  .login-wrap { position: fixed; inset: 0; z-index: 20; }

  .only-mobile { display: none; }
  .only-desktop { display: inline; }
}
