/* memento app: mobile first, native feel. Colors come from Theme tokens (--p, --bar, --tint …). */
:root {
  --text: #18181b;
  --muted: #52525b;
  --line: #d4d4d8;
  --line-soft: #e4e4e7;
  --bg: #f4f4f5;
  --surface: #fff;
  --danger: #b91c1c;
  --warn-bg: #fef3c7;
  --warn-line: #f59e0b;
  --warn-text: #78350f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; background: var(--bg); }
body { touch-action: manipulation; }
button, a, label, .row-tap { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
a { color: var(--p); }
.mu { color: var(--muted); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Screen layout: fixed bar, scrolling content */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.bar { flex: none; display: flex; align-items: center; gap: 2px; padding: calc(6px + var(--safe-top)) 4px 6px; min-height: calc(56px + var(--safe-top)); background: var(--bar); color: var(--bar-text); }
.bar .ttl { flex: 1; min-width: 0; padding: 0 4px; }
.bar .ttl strong { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: 13px; color: var(--bar-muted); display: flex; gap: 8px; align-items: center; }
.bar .sub .ov { color: #fca5a5; font-weight: 600; }
.content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: calc(96px + var(--safe-bottom)); }
.foot { flex: none; padding: 12px 16px calc(14px + var(--safe-bottom)); background: var(--surface); border-top: 1px solid var(--line); }

.ib { font: inherit; min-width: 44px; height: 44px; border: 0; background: none; color: inherit; cursor: pointer; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; padding: 0 8px; flex: none; }
.ib.big { font-size: 24px; }
.btn { font: inherit; font-weight: 600; min-height: 50px; padding: 0 18px; border: 1px solid #a1a1aa; border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; width: 100%; }
.btn.p { background: var(--p); border-color: var(--p); color: #fff; }
.btn.d { color: var(--danger); border-color: #fca5a5; }
.btn:disabled { opacity: .5; }
.inp { font: inherit; min-height: 48px; padding: 0 12px; border: 1px solid #a1a1aa; border-radius: 10px; background: var(--surface); color: var(--text); width: 100%; }
textarea.inp { padding: 12px; resize: none; }
.lbl { display: block; font-size: 13px; font-weight: 600; color: #3f3f46; margin: 0 0 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; line-height: 1.45; }
.row { display: flex; align-items: center; gap: 8px; }
.row > .grow { flex: 1; min-width: 0; }

/* Setup */
.setup { padding: calc(72px + var(--safe-top)) 24px 32px; display: flex; flex-direction: column; gap: 22px; background: var(--surface); min-height: 100%; }
.setup h1 { margin: 0; font-size: 32px; }
.notice { background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-text); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.error { background: #fee2e2; border: 1px solid #fca5a5; color: #7f1d1d; border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.5; }

/* Home */
.tabs { display: flex; background: rgba(255,255,255,.12); border-radius: 10px; padding: 3px; margin: 2px 10px 6px 12px; }
.tabs button { font: inherit; flex: 1; min-height: 38px; border: 0; border-radius: 8px; background: none; color: var(--bar-muted); font-weight: 600; cursor: pointer; }
.tabs button.on { background: #fff; color: var(--text); }
.bar.stack { flex-direction: column; align-items: stretch; padding-bottom: 8px; }
.sec { font: inherit; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 16px; border: 0; background: none; color: #3f3f46; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; cursor: pointer; text-align: left; }
.card { display: flex; flex-direction: column; gap: 8px; margin: 0 12px 10px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text); }
.card .meter { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.card .meter div { height: 100%; background: var(--p); }
.ov { color: var(--danger); font-weight: 600; }
.fab { position: fixed; right: 16px; bottom: calc(24px + var(--safe-bottom)); display: flex; align-items: center; gap: 8px; min-height: 56px; padding: 0 22px; border-radius: 999px; background: var(--p); color: #fff; text-decoration: none; font-weight: 600; box-shadow: 0 6px 18px rgba(0,0,0,.25); border: 0; font-size: 16px; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: var(--p); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); line-height: 1.6; }

/* List view */
.banner { flex: none; padding: 8px 14px; font-size: 14px; background: var(--warn-bg); color: var(--warn-text); border-bottom: 1px solid var(--warn-line); }
.cat { font: inherit; display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 0 6px 0 14px; border: 0; border-bottom: 1px solid var(--line-soft); background: var(--surface); color: var(--text); text-align: left; }
.cat .open { font: inherit; flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; min-height: 52px; border: 0; background: none; color: inherit; text-align: left; cursor: pointer; padding: 0; }
.cat.active { box-shadow: inset 3px 0 0 var(--p); }
.cat .name { flex: 1; font-weight: 600; }
.cat .chev { color: var(--muted); width: 14px; }
.cat.off .name, .it.off .t { color: var(--muted); text-decoration: line-through; }
.it { display: flex; align-items: center; gap: 2px; min-height: 56px; padding: 0 10px 0 6px; border-bottom: 1px solid #f4f4f5; background: var(--surface); }
.it .ck { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex: none; }
.it .ck input { width: 24px; height: 24px; accent-color: var(--p); margin: 0; }
.it .body { flex: 1; min-width: 0; padding: 8px 0; text-decoration: none; color: inherit; }
.it .t.done { color: var(--muted); text-decoration: line-through; }
.it .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.it .meta.ov { color: var(--danger); }
.it.future { opacity: .55; }
.it.pending .t::after { content: " ·"; color: var(--muted); }
.prio { font-size: 12px; font-weight: 700; color: #7c2d12; background: #ffedd5; border-radius: 4px; padding: 2px 6px; flex: none; }
.addrow { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 18px; border-bottom: 1px solid var(--line-soft); background: var(--surface); }
.addrow button.link { font: inherit; border: 0; background: none; color: var(--p); min-height: 44px; cursor: pointer; padding: 0 8px; }

/* Sheets & dialogs */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(24,24,27,.5); display: flex; flex-direction: column; justify-content: flex-end; }
.sheet { background: var(--surface); border-radius: 16px 16px 0 0; padding: 8px 0 calc(20px + var(--safe-bottom)); max-height: 92%; overflow-y: auto; box-shadow: 0 -8px 24px rgba(0,0,0,.2); }
.sheet .grab { width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 6px; }
.sheet h2 { margin: 0; padding: 8px 20px; font-size: 18px; }
.sheet .h { font-size: 12px; font-weight: 700; color: #3f3f46; text-transform: uppercase; letter-spacing: .05em; padding: 14px 20px 4px; margin: 0; }
.sheet .sw { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 4px 20px; }
.sheet .act { font: inherit; display: flex; flex-direction: column; justify-content: center; width: 100%; min-height: 52px; padding: 4px 20px; border: 0; background: none; color: var(--text); text-align: left; cursor: pointer; text-decoration: none; }
.sheet .act small { color: var(--muted); font-size: 13px; }
.sheet .act.danger { color: var(--danger); }
.sheet .pad { padding: 8px 20px; display: flex; flex-direction: column; gap: 14px; }
.sheet hr { border: 0; border-top: 1px solid var(--line-soft); margin: 8px 0 0; }
.sw input, .switch { width: 22px; height: 22px; accent-color: var(--p); margin: 0; flex: none; }

/* Full-screen forms (item sheet, new list, update template) */
.grp { background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 14px 16px; display: flex; flex-direction: column; gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; padding: 14px 0 24px; }
.stack.padded { padding: 16px; gap: 18px; }
.seg { display: flex; border: 1px solid #a1a1aa; border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; flex: 1; min-height: 46px; border: 0; background: var(--surface); color: var(--text); cursor: pointer; }
.seg button + button { border-left: 1px solid #a1a1aa; }
.seg button.on { background: var(--p); color: #fff; }
.stepper { display: flex; align-items: center; border: 1px solid #a1a1aa; border-radius: 10px; overflow: hidden; }
.stepper button { font: inherit; width: 48px; height: 46px; border: 0; background: var(--surface); font-size: 20px; color: var(--text); }
.stepper span { flex: 1; text-align: center; }
.choice { font: inherit; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 14px; border: 0; border-bottom: 1px solid var(--line-soft); background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.choice:last-child { border-bottom: 0; }
.choice.on { background: var(--tint); }
.dot { flex: none; width: 20px; height: 20px; border-radius: 999px; border: 2px solid #71717a; }
.choice.on .dot { border: 6px solid var(--p); }
.box { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.card-p { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.change { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; }
.change .sym { width: 18px; flex: none; font-weight: 700; font-family: ui-monospace, monospace; }

/* Toasts */
#toasts { position: fixed; z-index: 60; left: 12px; right: 12px; bottom: calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; background: #18181b; color: #fafafa; border-radius: 12px; padding: 6px 6px 6px 16px; min-height: 52px; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); pointer-events: auto; }
.toast span { flex: 1; padding: 8px 0; }
.toast button { font: inherit; font-weight: 700; min-height: 44px; padding: 0 14px; border: 0; border-radius: 8px; background: none; color: #93c5fd; cursor: pointer; }
.toast.err { background: #7f1d1d; }
.toast.warn { background: #78350f; }

@media (min-width: 720px) {
  .content > *, .stack { max-width: 720px; margin-left: auto; margin-right: auto; }
  .sheet { max-width: 560px; width: 100%; margin: 0 auto; }
}
