:root {
  --bg: #F4F1EC;
  --card: #FFFFFF;
  --ink: #17252A;
  --muted: #5F6B6E;
  --line: #E4DED5;
  --brand: #0E4F54;
  --brand-ink: #FFFFFF;
  --gold: #C9962E;
  --gold-soft: #FBF1DC;
  --warn: #B4361E;
  --warn-soft: #FCE8E3;
  --ok: #2E7D4F;
  --ok-soft: #E3F2E8;
  --chip: #E9E4DC;
  --shadow: 0 1px 2px rgba(23, 37, 42, .06), 0 4px 14px rgba(23, 37, 42, .06);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1517;
    --card: #192225;
    --ink: #EEF2F1;
    --muted: #9AA7A9;
    --line: #273235;
    --brand: #3FA7A4;
    --brand-ink: #071415;
    --gold: #E3B55A;
    --gold-soft: #3A2F18;
    --warn: #FF8A70;
    --warn-soft: #3B1F19;
    --ok: #6CCB92;
    --ok-soft: #173023;
    --chip: #243033;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; letter-spacing: -0.02em; }
button { font: inherit; color: inherit; }
a { color: var(--brand); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 14px; }

/* ---------- Sign in ---------- */
#login { min-height: 100vh; display: grid; place-items: center; padding: calc(var(--safe-top) + 24px) 24px calc(var(--safe-bottom) + 24px); }
.login-wrap { width: 100%; max-width: 340px; text-align: center; }
.logo { border-radius: 18px; box-shadow: var(--shadow); }
#login h1 { font-size: 26px; margin-top: 14px; }
.pin-dots { display: flex; gap: 18px; justify-content: center; margin: 32px 0 10px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--brand); transition: background .12s; }
.pin-dots i.on { background: var(--brand); }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.login-msg { min-height: 22px; color: var(--muted); font-size: 15px; margin: 0 0 18px; }
.login-msg.err { color: var(--warn); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; justify-items: center; }
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--card);
  font-size: 30px; font-weight: 400; box-shadow: var(--shadow); touch-action: manipulation;
}
.keypad button:active { background: var(--chip); transform: scale(.96); }
.keypad button[data-k="del"] { background: transparent; box-shadow: none; font-size: 26px; }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid transparent;
}
.top.scrolled { border-bottom-color: var(--line); }
.top-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.top h1 { font-size: 32px; font-weight: 700; }
.eyebrow { margin: 0 0 2px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--chip); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 0; border-radius: 8px; font-size: 15px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.net { font-size: 13px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--gold-soft); color: var(--gold); }

/* ---------- Layout ---------- */
.tab { padding: 4px 16px calc(var(--safe-bottom) + 96px); max-width: 640px; margin: 0 auto; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(var(--safe-bottom) + 6px); background: color-mix(in srgb, var(--card) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(18px); backdrop-filter: saturate(180%) blur(18px); border-top: 1px solid var(--line);
}
.tabbar button { border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar button.on { color: var(--brand); }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); border: 1px solid var(--line); }
.card h2 { font-size: 19px; margin-bottom: 8px; }
.card h3 { font-size: 16px; margin: 0 0 6px; }
.sec { margin: 22px 4px 6px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }

/* ---------- Chips / pickers ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; background: var(--chip); padding: 8px 13px; border-radius: 999px; font-size: 15px; font-weight: 600; color: var(--ink); min-height: 38px; }
.chip.on { background: var(--brand); color: var(--brand-ink); }
.chip small { opacity: .7; font-weight: 600; margin-left: 4px; font-size: 12px; }
.label { font-size: 13px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; display: block; }

/* ---------- Timer ---------- */
.timer { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-top: 4px; }
.timer-face { font-size: 40px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.timer-face.idle { color: var(--muted); font-size: 18px; font-weight: 600; letter-spacing: 0; }
.btn.go { min-width: 120px; min-height: 56px; font-size: 18px; border-radius: 16px; }
.btn.stop { background: var(--warn); color: #fff; }
.dur { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dur .round { width: 44px; height: 44px; font-size: 24px; border: 0; border-radius: 50%; background: var(--chip); color: var(--brand); }
.dur-val { font-size: 26px; font-weight: 800; min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Forms ---------- */
.field { display: grid; gap: 5px; margin: 10px 0; text-align: left; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.35; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.count { font-size: 12px; color: var(--muted); text-align: right; margin-top: -2px; }
.count.bad { color: var(--warn); font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.toggle input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); flex: none; }
details.more { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 6px; }
details.more summary { font-size: 15px; font-weight: 600; color: var(--brand); padding: 8px 0; cursor: pointer; list-style: none; }
details.more summary::-webkit-details-marker { display: none; }
.photo-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.photo-thumb { width: 52px; height: 52px; border-radius: 10px; object-fit: cover; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 11px 16px; min-height: 44px;
  background: var(--brand); color: var(--brand-ink); font-weight: 600; font-size: 16px; text-decoration: none; cursor: pointer;
}
.btn:active { opacity: .8; }
.btn.ghost { background: var(--chip); color: var(--ink); }
.btn.danger { background: var(--warn-soft); color: var(--warn); }
.btn.small { padding: 7px 12px; min-height: 34px; font-size: 14px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Entries ---------- */
.entry { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 8px 0; color: var(--ink); font: inherit; }
.entry.voided { opacity: .55; }
.entry.voided .e-top b { text-decoration: line-through; }
.e-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.e-top b { font-size: 16px; }
.e-dur { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.e-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.e-narr { font-size: 14px; margin-top: 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--chip); color: var(--ink); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.gold { background: var(--gold-soft); color: var(--gold); }
.banner { display: flex; gap: 12px; align-items: center; background: var(--gold-soft); color: var(--gold); border-radius: 14px; padding: 12px 14px; margin-top: 12px; font-size: 15px; font-weight: 600; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner .btn { margin-left: auto; flex: none; }
.empty { text-align: center; padding: 36px 20px; color: var(--muted); }

/* ---------- Week ---------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.day { border-radius: 12px; padding: 8px 2px; text-align: center; background: var(--card); border: 1px solid var(--line); }
.day .dn { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.day .dd { font-size: 17px; font-weight: 800; }
.day .dh { font-size: 12px; font-weight: 700; color: var(--ok); font-variant-numeric: tabular-nums; }
.day.gap { background: var(--warn-soft); border-color: transparent; }
.day.gap .dh { color: var(--warn); }
.day.future { opacity: .4; }
.day.today { outline: 2px solid var(--brand); }

/* ---------- Dashboard ---------- */
.big { font-size: 40px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.big small { font-size: 16px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--chip); margin: 10px 0 6px; gap: 2px; }
.bar i { display: block; height: 100%; }
.bar .c { background: var(--ok); }
.bar .r { background: var(--gold); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.dot.c { background: var(--ok); }
.dot.r { background: var(--gold); }
.tests { display: grid; gap: 8px; margin-top: 12px; }
.test { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: start; padding: 10px 12px; background: var(--bg); border-radius: 12px; font-size: 14px; }
.test .pf { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.test .pf.pass { background: var(--ok-soft); color: var(--ok); }
.test .pf.fail { background: var(--warn-soft); color: var(--warn); }
.test .why { grid-column: 2; color: var(--muted); font-size: 13px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 14px; margin-top: 10px; font-variant-numeric: tabular-nums; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; font-weight: 600; }
.controls { display: grid; gap: 10px; margin-top: 8px; }

/* ---------- Sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 90vh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 22px 22px 0 0; padding: 8px 18px calc(var(--safe-bottom) + 18px);
  animation: up .25s cubic-bezier(.2,.8,.2,1); max-width: 640px; margin: 0 auto;
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 22px; margin-bottom: 10px; }
.group { background: var(--card); border-radius: 14px; margin: 12px 0; overflow: hidden; border: 1px solid var(--line); }
.item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; text-decoration: none; color: var(--ink); font: inherit; }
.item:last-child { border-bottom: 0; }
.item .chev { color: var(--muted); font-size: 20px; }
.item p { margin: 2px 0 0; }
.hist { border-left: 3px solid var(--line); padding: 2px 0 2px 12px; margin: 10px 0; font-size: 14px; }
.hist.void { border-color: var(--warn); }
.hist.revision { border-color: var(--gold); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; }
.pick-list { display: grid; gap: 12px; margin: 24px 0 8px; }
.pick-list .btn { min-height: 60px; font-size: 20px; }
.login-wrap .field input { text-align: center; font-size: 22px; letter-spacing: .3em; }
.err-list { margin: 8px 0 0; padding-left: 18px; color: var(--warn); font-size: 14px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-size: 15px; font-weight: 600;
  z-index: 30; box-shadow: 0 6px 24px rgba(0,0,0,.2); width: max-content; max-width: min(calc(100% - 32px), 420px); text-align: center;
}
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
