:root {
  --bg: #0b1020;
  --bg-2: #10162e;
  --surface: #161d38;
  --surface-2: #1d2647;
  --line: #2a335a;
  --text: #eef1fb;
  --muted: #9aa3c7;
  --muted-2: #6c76a0;
  --accent: #7c9cff;
  --accent-ink: #0b1020;

  --present: #35c77f;
  --present-bg: #14351f;
  --late: #f2b53a;
  --late-bg: #3a2f10;
  --absent: #f26d6d;
  --absent-bg: #3a1717;

  --radius: 16px;
  --radius-sm: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --tap: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% -10%, #1a2350 0%, transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Login ---------- */
.view { min-height: 100dvh; }
#view-login {
  display: grid; place-items: center; padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}
.login-card {
  width: 100%; max-width: 420px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow);
}
.brand { text-align: center; margin-bottom: 20px; }
.brand-mark { font-size: 40px; }
.brand h1 { margin: 8px 0 2px; font-size: 26px; letter-spacing: .3px; }
.brand-sub { margin: 0; color: var(--muted); font-size: 14px; }

.field { display: block; margin: 14px 0; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
textarea, .text-input, .search, .date-input {
  width: 100%; background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 16px; outline: none;
}
textarea { resize: vertical; line-height: 1.4; }
textarea:focus, .text-input:focus, .search:focus, .date-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,156,255,.18);
}

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 16px; font-weight: 600; color: var(--text);
  background: var(--surface-2); transition: transform .05s ease, filter .15s ease;
  min-height: var(--tap);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-block { width: 100%; }
.btn-soft { background: var(--surface-2); border-color: var(--line); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }

.error { color: var(--absent); font-size: 14px; margin: 10px 2px 0; }
.help { margin-top: 18px; color: var(--muted); font-size: 14px; }
.help summary { cursor: pointer; color: var(--accent); }
.help ol { padding-left: 18px; line-height: 1.6; }
.muted { color: var(--muted-2); font-size: 12px; }
.center { text-align: center; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(11,16,32,.82); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + var(--safe-top)) 12px 10px;
  display: grid; gap: 8px;
}
.topbar-row { display: flex; align-items: center; gap: 8px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 8px 14px; font-size: 15px; font-weight: 600;
  min-height: 40px; max-width: 100%;
}
.chip-lg { font-size: 17px; }
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-caret { color: var(--muted); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: 20px; line-height: 1;
  display: grid; place-items: center;
}
.date-input { flex: 1; min-height: 40px; padding: 8px 12px; color-scheme: dark; }

.sync { font-size: 12px; color: var(--muted); min-width: 8px; }
.sync.saving { color: var(--late); }
.sync.saved { color: var(--present); }
.sync.error { color: var(--absent); }
.sync.offline { color: var(--muted-2); }

/* Progress */
.progress { display: grid; gap: 6px; }
.progress-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.pill {
  font-size: 12px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px;
}
.pill b { color: var(--text); }
.pill-present b { color: var(--present); }
.pill-late b { color: var(--late); }
.pill-absent b { color: var(--absent); }
.progress-bar { height: 6px; background: var(--surface); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--present), #6ee0a5); transition: width .25s ease; }

/* ---------- Toolbar / tabs ---------- */
.toolbar { display: flex; gap: 8px; padding: 10px 12px 4px; }
.toolbar .search { flex: 1; min-height: 44px; }
.toolbar .btn { white-space: nowrap; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px 6px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.tab.is-active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- List ---------- */
.list { padding: 6px 12px calc(28px + var(--safe-bottom)); display: grid; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: grid; gap: 10px;
}
.card.s-present { border-color: color-mix(in srgb, var(--present) 45%, var(--line)); }
.card.s-late { border-color: color-mix(in srgb, var(--late) 45%, var(--line)); }
.card.s-absent { border-color: color-mix(in srgb, var(--absent) 45%, var(--line)); }

.card-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: var(--surface-2); display: grid; place-items: center;
  font-weight: 700; color: var(--accent); overflow: hidden; font-size: 16px;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.who { min-width: 0; flex: 1; }
.who .name { font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.note-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 10px; min-width: 40px; height: 40px; padding: 0 10px; font-size: 16px;
}
.note-btn.has-note { color: var(--late); border-color: color-mix(in srgb, var(--late) 50%, var(--line)); }

/* Segmented 3-state control */
.seg { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.seg-btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--muted);
  border-radius: 12px; min-height: var(--tap); font-size: 15px; font-weight: 700;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.seg-btn[data-status="present"].on { background: var(--present-bg); color: var(--present); border-color: var(--present); }
.seg-btn[data-status="late"].on { background: var(--late-bg); color: var(--late); border-color: var(--late); }
.seg-btn[data-status="absent"].on { background: var(--absent-bg); color: var(--absent); border-color: var(--absent); }
.seg-lg .seg-btn { min-height: 54px; font-size: 16px; }

.tardy-tag { font-size: 12px; color: var(--late); }

.empty { text-align: center; color: var(--muted); padding: 48px 24px; }

/* ---------- Sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(4,7,18,.6);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 520px; background: var(--surface);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  border: 1px solid var(--line); border-bottom: none;
  padding: 10px 18px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow); animation: rise .2s ease;
  max-height: 88dvh; overflow-y: auto;
}
@keyframes rise { from { transform: translateY(24px); } }
.sheet-handle { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 4px auto 12px; }
.sheet-name { margin: 0 0 12px; font-size: 18px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
.checkbox-field { display: flex; align-items: center; gap: 10px; }
.checkbox-field input { width: 22px; height: 22px; }

.menu-sheet .menu-item {
  display: block; width: 100%; text-align: left; background: transparent;
  border: none; border-top: 1px solid var(--line); color: var(--text);
  padding: 16px 4px; font-size: 16px;
}
.menu-item.danger { color: var(--absent); }
.menu-who { color: var(--muted); font-size: 14px; padding: 4px 4px 12px; }

.picker-list { display: grid; gap: 6px; margin-top: 10px; }
.picker-item {
  text-align: left; width: 100%; background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); border-radius: 12px; padding: 14px; font-size: 15px;
}
.picker-item.on { border-color: var(--accent); }
.picker-item .pi-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 18px; font-size: 14px; z-index: 80; box-shadow: var(--shadow);
  animation: rise .18s ease;
}
.toast.error { border-color: var(--absent); color: var(--absent); }
