:root {
  --bg: #f4f6fa; --surface: #fff; --text: #0a1020; --muted: #3a4560; --line: #8a94ab;
  --primary: #0b3d91; --on-primary: #fff; --ok: #0a5c2e; --warn: #7a4a00; --bad: #a11212;
  --ok-bg: #d8f2e1; --warn-bg: #ffecc2; --bad-bg: #fbdada; --info-bg: #dbe6fb;
  --focus: #ff9d00; --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #151e32; --text: #f2f5fb; --muted: #c0c9dc; --line: #6d7a96;
    --primary: #7fb0ff; --on-primary: #06142e; --ok: #7fe0a4; --warn: #ffd37a; --bad: #ff9a9a;
    --ok-bg: #0f3321; --warn-bg: #3b2a05; --bad-bg: #431414; --info-bg: #14284f;
  }
}
* { box-sizing: border-box; }
html { font-size: 18px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.35; }
#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 700; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.view { padding: 0 0 8px; }
.top { padding: 14px 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 5; border-bottom: 1px solid var(--line); }
.top-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 4px 0; }
.who { font-weight: 700; font-size: 1.1rem; }
.date { color: var(--muted); }
.total { margin: 6px 0; }
.total-n { font-size: 1.6rem; font-weight: 800; }
.days { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.date-jump { flex: 1; min-height: 48px; border: 2px solid var(--line); border-radius: var(--r); background: var(--surface); padding: 0 10px; text-align: center; }

.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.bar h2 { margin: 0; font-size: 1.15rem; flex: 1; }
.icon-btn { min-width: 48px; min-height: 48px; border: 2px solid var(--line); background: var(--surface); border-radius: var(--r); font-size: 1.3rem; }
.icon-btn:disabled { opacity: .4; }
.icon-btn.danger { color: var(--bad); }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px; border: 2px solid var(--line); border-radius: var(--r); background: var(--surface); text-decoration: none; font-weight: 600; transition: transform 120ms ease, opacity 120ms ease; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.big { min-height: 60px; width: 100%; font-size: 1.15rem; }
.btn.small { min-height: 48px; padding: 0 14px; }

.pill { display: inline-flex; gap: 8px; align-items: center; min-height: 48px; padding: 0 16px; border-radius: 999px; border: 2px solid currentColor; font-weight: 700; background: var(--surface); }
.pill.ok { color: var(--ok); } .pill.warn { color: var(--warn); } .pill.bad { color: var(--bad); }

.banner { margin: 8px 16px; padding: 12px 14px; border-radius: var(--r); display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.bad { background: var(--bad-bg); color: var(--bad); font-weight: 700; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--info-bg); }

.entries { list-style: none; margin: 8px 16px; padding: 0; display: grid; gap: 10px; }
.entry { background: var(--surface); border: 2px solid var(--line); border-radius: var(--r); }
.entry-body { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 12px 14px; min-height: 48px; }
.e-time { font-weight: 800; font-size: 1.1rem; display: flex; justify-content: space-between; gap: 8px; }
.e-dur { color: var(--muted); font-weight: 600; }
.e-code { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.e-desc { margin-top: 4px; color: var(--muted); overflow-wrap: anywhere; }
.e-state { margin-top: 6px; font-weight: 700; }
.e-state.warn { color: var(--warn); } .e-state.bad { color: var(--bad); } .e-state.ro { color: var(--muted); font-weight: 600; }
.code-desc { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; background: var(--line); border: 2px solid var(--text); }
.empty { margin: 32px 24px; text-align: center; color: var(--muted); }

.fab-space { height: 96px; }
.fab-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); max-width: 480px; margin: 0 auto; z-index: 6; }

.splash { display: grid; justify-items: center; gap: 12px; padding: 12vh 24px 24px; text-align: center; }
.splash h1 { margin: 0; font-size: 2rem; }
.splash .btn { max-width: 360px; }
.lead { font-size: 1.15rem; color: var(--muted); margin: 0 0 12px; }
.warn-text { color: var(--warn); font-weight: 700; }

.facts { margin: 0; padding: 12px 16px; }
.facts dt { color: var(--muted); font-size: .85rem; margin-top: 12px; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.stack { display: grid; gap: 12px; }

/* overlays */
#overlay .screen { position: fixed; inset: 0; background: var(--bg); z-index: 20; display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; animation: up 180ms ease-out; }
#overlay .screen + .screen { z-index: 21; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 30; display: flex; align-items: flex-end; justify-content: center; animation: fade 150ms ease-out; }
.sheet { background: var(--surface); width: 100%; max-width: 480px; border-radius: 20px 20px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); animation: up 180ms ease-out; }
.sheet h2 { margin: 0 0 8px; font-size: 1.2rem; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row-actions .btn { flex: 1; }
.scroll { overflow-y: auto; flex: 1; }
.pad { padding: 12px 16px; }
.footer-actions { display: flex; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.footer-actions .btn { flex: 1; min-height: 56px; }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.input { width: 100%; min-height: 52px; padding: 10px 12px; border: 2px solid var(--line); border-radius: var(--r); background: var(--surface); }
textarea.input { resize: none; overflow: hidden; }
.input.invalid { border-color: var(--bad); }
.code-btn { display: flex; gap: 8px; align-items: center; text-align: left; }
.placeholder { color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; gap: 6px; margin-top: 6px; }
.chip { flex: 1; min-height: 48px; border: 2px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 600; }
.duration { font-weight: 800; font-size: 1.15rem; margin: 0 0 16px; min-height: 1.4em; }
.error { color: var(--bad); font-weight: 700; margin: 6px 0 0; }
.error:empty { display: none; }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.counter:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--text); border: 2px solid var(--warn); border-radius: var(--r); padding: 12px; margin-top: 8px; }
.warn p { margin: 0; font-weight: 600; }

.group { padding: 10px 16px 4px; font-size: .85rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
#picker-list { overflow-y: auto; flex: 1; }
.code-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 16px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; }
.code-row.active, .code-row[aria-selected="true"] { background: var(--info-bg); }
.code-main { display: grid; min-width: 0; }
.code-city { color: var(--muted); font-size: .85rem; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(90px + env(safe-area-inset-bottom)); display: grid; justify-items: center; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 700; max-width: 90%; animation: up 160ms ease-out; }

@keyframes up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
