:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --card-2: #f0eee9;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #a1a1a6;
  --line: #e4e1db;
  --accent: #4f5bd5;
  --accent-soft: #e8eafb;
  --danger: #d9480f;
  --danger-soft: #fdebe3;
  --ok: #2f9e44;
  --ok-soft: #e3f4e6;
  --warn: #c47f00;
  --event: #8b5cf6;
  --event-soft: #f1ebfe;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 4px 16px rgba(0, 0, 0, .05);
  --radius: 14px;
  --tabs-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16171b;
    --card: #1f2026;
    --card-2: #2a2b32;
    --text: #f2f2f5;
    --muted: #a0a0aa;
    --faint: #6b6b75;
    --line: #2f3038;
    --accent: #8b94ff;
    --accent-soft: #2a2d4d;
    --danger: #ff7a45;
    --danger-soft: #3d2419;
    --ok: #51cf66;
    --ok-soft: #1d3324;
    --event: #b197fc;
    --event-soft: #2e2645;
    --on-accent: #14152b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
svg.i { width: 20px; height: 20px; flex: none; }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 12px) 16px calc(var(--tabs-h) + var(--safe-b) + 96px);
  min-height: 100vh;
}

/* ---------- header ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.head h1 { font-size: 30px; line-height: 1.1; margin: 0; letter-spacing: -.02em; }
.head .sub { color: var(--muted); font-size: 15px; margin-top: 2px; }
.offline-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, transparent); padding: 3px 10px; border-radius: 99px; margin-bottom: 10px;
}

/* ---------- segmented ---------- */
.seg { display: inline-flex; background: var(--card-2); border-radius: 10px; padding: 2px; flex: none; }
.seg button, .seg label {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); font-weight: 500;
}
.seg .on, .seg input:checked + span { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg label { padding: 0; }
.seg label span { display: block; padding: 6px 12px; border-radius: 8px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg.full { display: flex; width: 100%; }
.seg.full > * { flex: 1; text-align: center; }

/* ---------- sections + cards ---------- */
.section { margin: 22px 0 8px; display: flex; align-items: baseline; justify-content: space-between; }
.section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; font-weight: 600; }
.section h2.danger { color: var(--danger); }
.section .link { font-size: 14px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card + .card { margin-top: 10px; }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 500; }

.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 56px; width: 100%;
  background: none; border: 0; text-align: left; position: relative;
}
.row + .row { border-top: 1px solid var(--line); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.row .meta span { display: inline-flex; align-items: center; gap: 3px; }
.row .meta svg.i { width: 13px; height: 13px; }
.row .meta .over { color: var(--danger); font-weight: 500; }
.row .meta .soon { color: var(--accent); }
.row.projected { opacity: .55; }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--card-2); }
.flag { color: var(--danger); }

.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--faint); background: none; flex: none;
  display: grid; place-items: center; padding: 0; color: transparent; transition: all .15s;
}
.check svg { width: 16px; height: 16px; }
.check:active { transform: scale(.9); }
.check.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.check.sq { border-radius: 8px; width: 24px; height: 24px; }
.check.popping { animation: pop .35s ease; background: var(--ok); border-color: var(--ok); color: #fff; }
@keyframes pop { 50% { transform: scale(1.25); } }
.row.leaving { animation: leave .35s ease .15s forwards; }
@keyframes leave { to { opacity: 0; transform: translateX(24px); } }

.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  color: #fff; font-size: 12px; font-weight: 700; background: var(--faint);
}
.avatar.any { background: none; border: 1.5px dashed var(--faint); color: var(--muted); }
.avatar.lg { width: 34px; height: 34px; font-size: 14px; }
.ev-bar { width: 4px; align-self: stretch; border-radius: 2px; background: var(--event); flex: none; }
.ev-time { font-size: 13px; color: var(--muted); width: 56px; flex: none; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 20px; color: var(--text); font-weight: 600; margin-bottom: 4px; }
.summary { display: flex; gap: 10px; margin-bottom: 4px; }
.stat { flex: 1; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stat.danger b { color: var(--danger); }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head h1 { font-size: 26px; margin: 0; }
.cal-nav { display: flex; gap: 6px; }
.icon-btn {
  border: 0; background: var(--card); box-shadow: var(--shadow); border-radius: 10px; height: 36px; min-width: 36px;
  padding: 0 10px; display: inline-grid; place-items: center; color: var(--text); font-size: 14px; font-weight: 500;
}
.cal { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; font-weight: 600; }
.cal-day {
  border: 0; background: none; aspect-ratio: 1 / 1.05; border-radius: 10px; padding: 4px 0 0; display: flex; flex-direction: column;
  align-items: center; gap: 3px; font-size: 15px; font-variant-numeric: tabular-nums; min-width: 0;
}
.cal-day.other { color: var(--faint); }
.cal-day.today .n { background: var(--accent); color: var(--on-accent); }
.cal-day.sel { background: var(--accent-soft); }
.cal-day .n { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }
.dots { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; max-width: 30px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.dot.ev { background: var(--event); border-radius: 2px; }
.dot.done { background: none; border: 1.5px solid var(--ok); width: 6px; height: 6px; }

/* ---------- shopping ---------- */
.add-bar { display: flex; gap: 8px; position: sticky; top: calc(var(--safe-t) + 6px); z-index: 5; margin-bottom: 4px; }
.add-bar input { flex: 1; }
.cat-chip { font-size: 12px; color: var(--muted); }
.x-btn { border: 0; background: none; color: var(--faint); width: 32px; height: 32px; display: grid; place-items: center; flex: none; border-radius: 8px; }

/* ---------- forms ---------- */
.input, input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px;
  font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; min-height: 46px;
}
input[type=date], input[type=time] { min-height: 46px; }
textarea { resize: vertical; min-height: 80px; }
.input:focus, input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.field { margin: 14px 0; }
.field > .lbl { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }
.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }
.title-input { font-size: 20px !important; font-weight: 600; border: 0 !important; box-shadow: none !important; padding: 4px 0 !important; background: none !important; }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline input[type=number] { width: 76px; text-align: center; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip > span, button.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px; font-weight: 500; min-height: 36px; white-space: nowrap;
}
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.chip .avatar { width: 20px; height: 20px; font-size: 10px; margin-left: -4px; }
.chips.days .chip > span { width: 40px; justify-content: center; padding: 7px 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 0; }
.switch input { appearance: none; -webkit-appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; transition: .2s; flex: none; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { left: 20px; }

.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; font-size: 16px; min-height: 48px;
  background: var(--card-2); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: space-around;
  padding: 6px 4px calc(var(--safe-b) + 4px); background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 500;
  color: var(--faint); text-decoration: none; padding: 4px 0; position: relative;
}
.tabs a.on { color: var(--accent); }
.tabs svg.i { width: 24px; height: 24px; }
.badge {
  position: absolute; top: 0; left: calc(50% + 6px); background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 5px;
}
.fab {
  position: fixed; right: max(18px, calc(50vw - 302px)); bottom: calc(var(--tabs-h) + var(--safe-b) + 16px); z-index: 21;
  width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: var(--on-accent);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent); display: grid; place-items: center;
}
.fab svg.i { width: 28px; height: 28px; }
.fab:active { transform: scale(.94); }

/* ---------- sheets ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 40; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 18px 18px 0 0; max-height: calc(100vh - var(--safe-t) - 24px);
  display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2, .8, .2, 1);
}
@supports (height: 100dvh) { .sheet { max-height: calc(100dvh - var(--safe-t) - 24px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 4px 16px; gap: 8px; }
.sheet-head h3 { margin: 0; font-size: 17px; flex: 1; text-align: center; }
.sheet-head .link { min-width: 60px; padding: 8px 0; }
.sheet-head .link:last-child { text-align: right; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 0; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(var(--safe-b) + 20px); -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 16px calc(var(--safe-b) + 12px); border-top: 1px solid var(--line); background: var(--bg); }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
body.locked { overflow: hidden; }

.detail-title { font-size: 22px; font-weight: 700; margin: 6px 0 8px; letter-spacing: -.01em; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tag { font-size: 13px; padding: 4px 10px; border-radius: 99px; background: var(--card-2); color: var(--muted); display: inline-flex; gap: 4px; align-items: center; }
.tag svg.i { width: 14px; height: 14px; }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.notes { white-space: pre-wrap; background: var(--card); padding: 12px 14px; border-radius: var(--radius); margin-bottom: 12px; overflow-wrap: anywhere; }
.who-line { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.who-line .main { flex: 1; }
.snooze-opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.history { font-size: 14px; color: var(--muted); }
.history div { padding: 6px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.cl-edit { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b) + 86px); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; background: #2b2b30; color: #fff; padding: 10px 14px; border-radius: 12px; display: flex; align-items: center; gap: 14px;
  font-size: 15px; box-shadow: 0 6px 24px rgba(0, 0, 0, .25); animation: up .25s ease; max-width: 100%;
}
.toast.error { background: var(--danger); }
.toast button { background: none; border: 0; color: #a5b0ff; font-weight: 700; padding: 4px; }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; text-align: center; }
.login img { width: 76px; height: 76px; border-radius: 18px; margin-bottom: 12px; }
.login h1 { margin: 0 0 4px; }
.login p { color: var(--muted); margin: 0 0 24px; }
.login form { text-align: left; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 6px 0; }

/* ---------- settings ---------- */
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row .main { flex: 1; min-width: 0; }
.set-pad { padding: 4px 14px 14px; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.swatch.on { border-color: var(--text); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; color: var(--muted); }
.search { margin-bottom: 10px; }

body.locked .toasts { top: calc(var(--safe-t) + 12px); bottom: auto; }
.seg label span { white-space: nowrap; }
