:root {
  --bg: #103D29;
  --surface: #1B513B;
  --surface-2: #225E45;
  --line: rgba(183, 228, 199, 0.16);
  --primary: #B7E4C7;
  --on-primary: #103D29;
  --text: #E5F6EB;
  --muted: #B2CCBD;
  --nav-active: #B7E4C7;
  --soon: #F2C879;
  --danger: #F29B91;
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 46px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; padding: calc(16px + var(--safe-t)) 16px calc(var(--nav-h) + 24px + var(--safe-b)); }
.screen.no-nav { padding-bottom: calc(24px + var(--safe-b)); }
.topbar { display: flex; align-items: center; gap: 8px; min-height: var(--tap); margin-bottom: 12px; }
.topbar h1 { font-size: 19px; font-weight: 650; margin: 0; flex: 1; letter-spacing: -0.01em; }
.brandmark { width: 34px; height: 34px; border-radius: 9px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; margin: 20px 0 8px; }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.card.tight { padding: 12px 14px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; }
.card-link { display: block; text-decoration: none; color: inherit; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.summary-grid .card { min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; }
.total { font-size: 23px; font-weight: 650; letter-spacing: -0.01em; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1.5px solid var(--primary);
  background: transparent; color: var(--primary); font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  text-decoration: none; touch-action: manipulation;
}
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.ghost { border-color: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 12px; font-size: 14px; border-width: 1px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 12px; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text);
}
.icon-btn:active, .btn:active { transform: scale(0.98); }
.icon { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.sm { width: 18px; height: 18px; }

/* ---------- quick actions ---------- */
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick button {
  min-height: 70px; border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; font-size: 13px; font-weight: 550; cursor: pointer;
}
.quick button .icon { color: var(--primary); }

/* ---------- segmented ---------- */
.segments { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface); border-radius: 12px; padding: 4px; gap: 2px; }
.segments button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px;
}
.segments button[aria-selected="true"] { background: var(--primary); color: var(--on-primary); }
.count { font-size: 11.5px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px; display: inline-flex; align-items: center; justify-content: center; background: rgba(0,0,0,.18); }
.segments button.has-overdue:not([aria-selected="true"]) .count { background: var(--danger); color: #3a120d; }

/* ---------- reminder card ---------- */
.reminder { background: var(--surface); border-radius: var(--radius); padding: 12px 14px; }
.reminder-head { display: flex; gap: 10px; align-items: flex-start; text-decoration: none; color: inherit; }
.reminder-title { font-size: 15px; font-weight: 600; margin: 0 0 2px; word-break: break-word; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12.5px; color: var(--muted); align-items: center; }
.meta span { display: inline-flex; align-items: center; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.chip.soon { background: rgba(242, 200, 121, 0.16); color: var(--soon); }
.chip.overdue { background: rgba(242, 155, 145, 0.16); color: var(--danger); }
.chip.done { background: rgba(183, 228, 199, 0.14); color: var(--primary); }
.actions { display: flex; gap: 6px; margin-top: 10px; }
.actions .btn { flex: 1; }

.empty { text-align: center; padding: 26px 16px; color: var(--muted); }
.empty .icon { width: 30px; height: 30px; color: var(--primary); margin-bottom: 6px; }
.empty p { margin: 4px 0 14px; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: #0d3222;
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.nav ul { list-style: none; margin: 0 auto; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); max-width: 560px; }
.nav a {
  height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 550;
}
.nav a[aria-current="page"] { color: var(--nav-active); }
.nav a[aria-current="page"] .icon { stroke-width: 2.3; }

/* ---------- forms ---------- */
label.field { display: block; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
.input, select.input, textarea.input {
  width: 100%; min-height: var(--tap); border-radius: 12px; border: 1.5px solid transparent; background: var(--surface);
  padding: 10px 14px; font-size: 16px; color: var(--text); outline: none;
}
.input:focus { border-color: var(--primary); }
textarea.input { min-height: 90px; resize: vertical; }
.input::-webkit-calendar-picker-indicator { filter: invert(0.85); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; display: flex; gap: 6px; align-items: flex-start; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-height: 38px; padding: 0 12px; border-radius: 999px; border: 1.5px solid var(--line); background: transparent;
  color: var(--text); font-size: 14px; cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
.panel { background: var(--surface); border-radius: var(--radius); padding: 14px; }
.panel h2 { font-size: 15px; margin: 0 0 4px; }

/* list rows (settings) */
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.list-row {
  min-height: 52px; display: flex; align-items: center; gap: 12px; padding: 10px 14px; text-decoration: none; color: inherit;
  width: 100%; background: none; border: 0; text-align: left; cursor: pointer;
}
.list-row .icon { color: var(--primary); }
.list-row .value { color: var(--muted); font-size: 13px; text-align: right; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border-radius: 999px; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: transform .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); background: var(--on-primary); }

/* ---------- auth / PIN ---------- */
.auth { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b)); }
.auth .logo { width: min(200px, 52vw); aspect-ratio: 1; border-radius: 24px; display: block; }
.auth .logo.small { width: min(128px, 36vw); border-radius: 18px; }
.auth h1 { font-size: 20px; margin: 14px 0 4px; text-align: center; }
.auth p.lead { color: var(--muted); text-align: center; margin: 0 0 18px; max-width: 320px; }
.auth form, .auth .body { width: 100%; max-width: 360px; }
.tagline { color: var(--primary); font-weight: 600; letter-spacing: .02em; margin-top: 6px; }
.dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 8px; }
.dots i { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--primary); display: block; }
.dots i.on { background: var(--primary); }
.dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.pin-msg { min-height: 22px; text-align: center; font-size: 13px; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px 26px; justify-content: center; margin-top: 10px; }
.keypad button {
  width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text);
  font-size: 24px; font-weight: 500; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center;
}
.keypad button:active { background: var(--surface-2); }
.keypad button.plain { background: transparent; font-size: 14px; color: var(--muted); }
.code-input { letter-spacing: 0.4em; text-align: center; font-size: 22px; font-variant-numeric: tabular-nums; }
.steps { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }
.steps i { width: 22px; height: 4px; border-radius: 2px; background: var(--surface-2); }
.steps i.on { background: var(--primary); }

/* ---------- sheet / toast / banner ---------- */
.scrim { position: fixed; inset: 0; background: rgba(4, 18, 11, 0.6); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: #154631; width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 10px 16px calc(18px + var(--safe-b));
  max-height: 88dvh; overflow-y: auto; animation: rise .18s ease-out;
}
.sheet .grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 17px; margin: 0 0 4px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + var(--safe-b)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.toast.err { background: var(--danger); color: #3a120d; }
.banner { border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.banner.warn { background: rgba(242, 200, 121, 0.14); color: var(--soon); }
.banner.err { background: rgba(242, 155, 145, 0.14); color: var(--danger); }
.banner.ok { background: rgba(183, 228, 199, 0.12); color: var(--primary); }
.offline { position: sticky; top: 0; z-index: 30; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; text-align: right; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.timeline li:first-child { border-top: 0; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--primary); animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 600px) {
  .screen { padding-left: 24px; padding-right: 24px; }
  .scrim { align-items: center; }
  .sheet { border-radius: 18px; }
}
@media (max-width: 350px) {
  .keypad { grid-template-columns: repeat(3, 64px); gap: 12px 20px; }
  .keypad button { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.card-link.row { display: flex; }
