/* ---------- Tokens ---------- */
:root {
  --bg: #F7F4FB; --surface: #FFFFFF; --ink: #1F2230; --muted: #5D5A6E; --border: #DCD3E8;
  --primary: #6B4C8F; --on-primary: #FFFFFF; --primary-deep: #6B4C8F;
  --done: #3F7D5A; --on-done: #FFFFFF;
  --lilac-tint: #F3E6FB; --lilac-ring: #A77BC9; --lilac-ink: #4A2A66; --off: #EEEAF3;
  --danger: #9A3F12; --radius: 18px;
  --shadow: 0 1px 2px rgba(31,34,48,.06), 0 8px 24px rgba(31,34,48,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15141B; --surface: #201E28; --ink: #ECEAF2; --muted: #A7A3B8; --border: #3A3545;
    --primary: #B996D6; --on-primary: #241533; --primary-deep: #CDB2E6;
    --done: #7FC49A; --on-done: #10261A;
    --lilac-tint: #2D2339; --lilac-ring: #B996D6; --lilac-ink: #E6D3F7; --off: #2A2732;
    --danger: #F08A5D; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15141B; --surface: #201E28; --ink: #ECEAF2; --muted: #A7A3B8; --border: #3A3545;
  --primary: #B996D6; --on-primary: #241533; --primary-deep: #CDB2E6;
  --done: #7FC49A; --on-done: #10261A;
  --lilac-tint: #2D2339; --lilac-ring: #B996D6; --lilac-ink: #E6D3F7; --off: #2A2732;
  --danger: #F08A5D; --shadow: none; color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink); font-family: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.4; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.2; }
h2 { font-size: 15px; }
a { color: var(--primary-deep); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary-deep); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
:root[data-theme="dark"] .card { border: 1px solid var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .card { border: 1px solid var(--border); } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 600; }
input[type="email"], input[type="password"], input[type="text"], input:not([type]), select {
  min-height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; /* stops iOS zooming on focus */
}
.field-error, .alert { color: var(--danger); font-size: 13px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-size: 14px; font-weight: 500; }
.check-row input { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; border-radius: 14px; border: 0; font-weight: 700; font-size: 15px; text-decoration: none; cursor: pointer; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--ink); font-weight: 600; }
.btn-danger { background: var(--danger); color: var(--surface); }
.btn-block { width: 100%; min-height: 48px; }
.link-btn { background: none; border: 0; padding: 0 2px; min-height: 44px; font-weight: 600; font-size: 14px; color: var(--primary-deep); text-decoration: underline; cursor: pointer; display: inline-flex; align-items: center; }
.link-danger { color: var(--danger); }

/* ---------- Sign-in pages ---------- */
.auth { max-width: 408px; margin: 0 auto; padding: 20px 16px 40px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.auth > * { width: 100%; }
.auth-brand { margin: 0; }
.auth-logo { display: block; width: 208px; height: auto; margin: 0 auto; }
.auth-mark { width: 96px; height: 96px; margin: 0 auto; }
.auth-heading { font-size: 22px; }
.auth .card { padding: 20px; gap: 12px; }

/* ---------- App shell ---------- */
.page { max-width: 440px; margin: 0 auto; padding: 12px 16px 104px; display: flex; flex-direction: column; gap: 12px; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 20px; color: var(--lilac-ink); text-decoration: none; min-height: 44px; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-link { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--lilac-tint); color: var(--lilac-ink); font-size: 14px; font-weight: 700; border: 1px solid var(--lilac-ring); text-decoration: none; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bottom-nav-in { max-width: 440px; margin: 0 auto; display: flex; }
.nav-link { flex: 1; min-width: 0; min-height: 60px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 12px; font-weight: 600; text-decoration: none; }
.nav-link.on { color: var(--primary-deep); }
.notice { background: var(--lilac-tint); color: var(--lilac-ink); border-radius: 14px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 52px; border-top: 1px solid var(--off); padding: 4px 0; }
.row:first-of-type { border-top: 0; }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; display: block; }
.row-meta { font-size: 13px; color: var(--muted); display: block; overflow-wrap: anywhere; }
.more-link { display: flex; align-items: center; gap: 12px; min-height: 52px; font-weight: 600; font-size: 15px; color: var(--ink); text-decoration: none; border-top: 1px solid var(--off); }
.more-link:first-of-type { border-top: 0; }
.more-link svg { color: var(--primary-deep); flex: none; }
.tag { flex: none; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; background: var(--off); color: var(--muted); }
.inline-form { display: contents; }
.link-box { background: var(--lilac-tint); color: var(--lilac-ink); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.radio-row { display: flex; gap: 8px; }
.radio-row label { flex: 1; min-height: 44px; display: flex; align-items: center; gap: 6px; font-size: 14px; }

/* ---------- Sections ---------- */
textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; resize: vertical; }
input[type="date"], input[type="time"] { min-height: 44px; width: 100%; padding: 0 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; }
input[type="file"] { width: 100%; min-height: 44px; font: inherit; font-size: 14px; }
.fields { display: flex; gap: 8px; }
.fields > .field { flex: 1; min-width: 0; }
.add { display: flex; gap: 8px; }
.add input { flex: 1; min-width: 0; }
.row-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-link { display: block; color: inherit; text-decoration: none; padding: 4px 0; }
.row-meta.late { color: #8A4A1F; font-weight: 600; }
:root[data-theme="dark"] .row-meta.late { color: #F2A97A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .row-meta.late { color: #F2A97A; } }
.row.big { min-height: 64px; }
.row.big .row-title { font-size: 18px; }
.row.done .row-title { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.check { flex: none; width: 44px; height: 44px; margin-left: -9px; display: grid; place-items: center; background: none; border: 0; cursor: pointer; }
.check i { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--lilac-ring); display: grid; place-items: center; font-style: normal; font-size: 15px; font-weight: 700; color: var(--on-done); }
.check.on i { background: var(--done); border-color: var(--done); }
.tag.lilac { background: var(--lilac-tint); color: var(--lilac-ink); }
.aisle { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin: 6px 0; }
.staples { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px; scrollbar-width: none; }
.staple { flex: none; min-height: 44px; padding: 0 12px; background: var(--lilac-tint); color: var(--lilac-ink); border: 0; border-radius: 14px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); font-size: 13px; font-weight: 600; text-decoration: none; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.undo-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--ink); color: var(--bg); border-radius: 14px; padding: 4px 14px; font-size: 14px; font-weight: 600; }
.undo-btn { color: inherit; flex: none; }
.shop-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.shop-bar .link-btn { color: inherit; }
.dash { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.full { grid-column: span 2; }
.tile { background: var(--off); border-radius: 14px; padding: 12px; min-height: 68px; color: inherit; text-decoration: none; display: block; }
.tile-num { display: block; font-size: 24px; font-weight: 700; line-height: 1.15; }
.tile-label { display: block; font-size: 13px; color: var(--muted); }
.mini { width: 40px; height: 44px; border: 0; background: none; border-radius: 10px; font-weight: 700; color: var(--muted); }
.mini[disabled] { opacity: .3; cursor: default; }
.file-row { display: flex; align-items: center; gap: 10px; font-size: 14px; flex-wrap: wrap; }
.file-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.inline-check { display: inline-flex; align-items: center; gap: 4px; font-weight: 500; min-height: 44px; }
.month-title { font-size: 20px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.dow { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.day { min-height: 44px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 14px; font-weight: 500; color: var(--ink); text-decoration: none; }
.day i { display: block; width: 5px; height: 5px; border-radius: 50%; }
.day.has i { background: var(--lilac-ring); }
.day.now { font-weight: 700; color: var(--primary-deep); }
.day.sel { background: var(--primary); color: var(--on-primary); font-weight: 700; }
.day.sel i { background: var(--on-primary); }
.list-row { border-top: 1px solid var(--off); padding: 6px 0; display: flex; flex-direction: column; }
.rename { display: flex; gap: 8px; align-items: center; }
.rename input { flex: 1; min-width: 0; }
.list-actions { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
[hidden] { display: none !important; }
