:root {
  --bg: #f3f4f1;
  --card: #ffffff;
  --text: #1b1f1a;
  --muted: #6a7167;
  --line: #e2e5de;
  --accent: #1f6f3f;
  --on-accent: #ffffff;
  --warn: #c2410c;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(0,0,0,.06);

  --s-pdy: #16a34a;
  --s-school: #2563eb;
  --s-leave: #7c3aed;
  --s-pass: #0e7490;
  --s-staffduty: #b45309;
  --s-recovery: #be123c;
  --s-ftx: #5c6b1e;

  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1210;
    --card: #181c19;
    --text: #e8ebe6;
    --muted: #9aa398;
    --line: #2a302b;
    --accent: #3fae6a;
    --on-accent: #06140b;
    --warn: #fb923c;
    --danger: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }

.view { max-width: 640px; margin: 0 auto; padding-bottom: 32px; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar .title { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -.01em; }
.topbar .sub { font-size: 13px; color: var(--muted); }
.topbar .back { margin-left: -8px; }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 12px;
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Sync bar ---------- */
.syncbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
}
.sync-text { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: pre-line; }
.sync-text.error { color: var(--danger); }
.push-btn {
  flex: none; min-height: 40px; padding: 0 16px;
  border-radius: 20px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); font-weight: 600; font-size: 14px;
}
.push-btn.has-changes { background: var(--warn); border-color: var(--warn); color: #fff; }
.push-btn:disabled { opacity: .6; }

/* ---------- Summary ---------- */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 0 16px 12px;
}
.chip {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 8px 10px; min-height: 54px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); text-align: left;
}
.chip .n { font-size: 20px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.chip .l { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; display: flex; align-items: center; gap: 4px; }
.chip .l i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--c, var(--muted)); }
.chip.zero .n { color: var(--muted); font-weight: 500; }
.chip.active { border-color: var(--text); }
.chip.needs .n { color: var(--warn); }
.chip.needs.zero .n { color: var(--muted); }

/* ---------- Roster list ---------- */
.list { list-style: none; margin: 0 12px; padding: 0; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 16px; min-height: 60px;
  background: none; border: 0; text-align: left;
}
.row:active { background: var(--line); }
.who { flex: 1; min-width: 0; }
.name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.name.overdue { color: var(--danger); }
.name .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); flex: none; }
.note { font-size: 14px; margin-top: 2px; overflow-wrap: anywhere; }
.meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meta.stale { color: var(--warn); }

.status-box {
  flex: none; width: 92px; height: 40px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  border-radius: 10px; font-size: 13px; font-weight: 700; color: #fff;
  background: var(--c); text-align: center; line-height: 1.1; padding: 0 4px;
}
.status-box svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.status-box.unset { background: none; border: 2px dashed var(--line); color: var(--muted); font-weight: 500; }
.status-box.stale { opacity: .45; }

.empty { margin: 8px 16px; padding: 24px 20px; background: var(--card); border-radius: 14px; text-align: center; box-shadow: var(--shadow); }
.empty p { margin: 0 0 14px; color: var(--muted); }
.list-foot { padding: 16px; text-align: center; }

/* ---------- Status sheet ---------- */
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.4); }
.sheet {
  position: fixed; z-index: 21; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgba(0,0,0,.2);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; align-items: center; gap: 8px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 19px; }
.sheet-head .icon-btn { margin-right: -8px; }
.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.status-opt {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; padding: 0 14px;
  border-radius: 12px; border: 2px solid var(--line); background: var(--card);
  font-weight: 600; font-size: 16px; text-align: left;
}
.status-opt i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.status-opt.selected { background: var(--c); border-color: var(--c); color: #fff; }
.status-opt.selected i { background: #fff; }
.status-opt:active { transform: scale(.98); }
.sheet-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; font-size: 13px; }

/* ---------- Forms / panels ---------- */
.panel { margin: 12px; padding: 14px 16px; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 6px; font-size: 16px; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.panel .lbl:first-child { margin-top: 0; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.hint.pad { padding: 0 16px; }
.field {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.field { resize: vertical; }
#sheet-note { margin-top: 8px; }
.row-inline { display: flex; gap: 8px; }
.row-inline .field { flex: 1; min-width: 0; }

.primary-btn, .ghost-btn, .danger-btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; font-weight: 600;
}
.primary-btn { background: var(--accent); border: 0; color: var(--on-accent); }
.ghost-btn { background: var(--card); border: 1px solid var(--line); }
.danger-btn { background: none; border: 1px solid var(--line); color: var(--danger); }
.wide { width: 100%; margin-top: 10px; }
.link-btn { background: none; border: 0; padding: 8px 0; color: var(--danger); font-weight: 600; }

.test-result { margin-top: 10px; font-size: 14px; padding: 10px 12px; border-radius: 10px; background: var(--bg); }
.test-result.ok { color: var(--accent); }
.test-result.bad { color: var(--danger); }

/* ---------- Manage list ---------- */
.manage-list { list-style: none; margin: 0 12px; padding: 0; background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.manage-list li { display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; }
.manage-list li + li { border-top: 1px solid var(--line); }
.manage-list input { flex: 1; min-width: 0; min-height: 44px; border: 0; background: none; font-size: 16px; }
.manage-list input:focus { outline: none; }
.manage-list li:focus-within { background: var(--bg); }
.manage-list .icon-btn { color: var(--danger); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; z-index: 30; left: 16px; right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto; padding: 12px 16px;
  background: #1b1f1a; color: #fff; border-radius: 12px; font-size: 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.bad { background: #7f1d1d; }
