/* HoldenHome: "Dusk on sand" (PLAN.md section 3, A3-SPEC.md). Every colour is a token here; the only literal
   outside :root is #fff on the switch knob. Gold is for fills only: never gold text on white. */
:root {
  --bg: #F6F3EC; --card: #FFFFFF; --ink: #1B2440; --muted: #5E6577; --line: #E4DED2;
  --accent: #22346B; --accent-ink: #FFFFFF; --gold: #E3A12F; --warm: #A85A22;
  --ok: #2E7D4F; --alert: #B3261E; --soft: #EEF1F7;
  --alert-ink: #FFFFFF;            /* text on an --alert fill (tab badges) */
  --toast-act: #F2C14E;            /* Undo on the navy toast (9:1) */
  --scrim: rgba(15, 23, 48, .45);
  --shadow: rgba(0, 0, 0, .18);
  --warn: var(--alert);            /* old name, kept one release */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1730; --card: #18223F; --ink: #E8ECF5; --muted: #A3ABBF; --line: #2A3556;
    --accent: #F2C14E; --accent-ink: #1B2440; --gold: #F2C14E; --warm: #E8A36A;
    --ok: #6FCF97; --alert: #FF6B5E; --soft: #1F2B4D;
    --alert-ink: #1B2440; --toast-act: #22346B; --scrim: rgba(0, 0, 0, .55); --shadow: rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
  --bg: #0F1730; --card: #18223F; --ink: #E8ECF5; --muted: #A3ABBF; --line: #2A3556;
  --accent: #F2C14E; --accent-ink: #1B2440; --gold: #F2C14E; --warm: #E8A36A;
  --ok: #6FCF97; --alert: #FF6B5E; --soft: #1F2B4D;
  --alert-ink: #1B2440; --toast-act: #22346B; --scrim: rgba(0, 0, 0, .55); --shadow: rgba(0, 0, 0, .45);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%; }
body { padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); overflow-x: hidden; }
body.sheet-open { overflow: hidden; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Header: on --bg, the mark + the screen's title; date and time on Today */
.top { display: flex; align-items: center; gap: 10px; max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px 8px; }
.mark { width: 32px; height: 32px; flex: none; }
.mark .roof { fill: none; stroke: var(--warm); stroke-width: 60; stroke-linecap: round; stroke-linejoin: round; }
.mark .hh { fill: var(--ink); }
.mark .win { fill: var(--gold); }
.top h1 { flex: 1; min-width: 0; margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.3px; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { flex: none; text-align: right; font-size: 13px; line-height: 1.3; color: var(--muted); }
.when span { display: block; }

main { max-width: 640px; margin: 0 auto; padding: 4px 16px calc(56px + 24px + env(safe-area-inset-bottom)); }
body.has-fab main { padding-bottom: calc(56px + 16px + 52px + 24px + env(safe-area-inset-bottom)); }

/* Tab bar: 5 line icons, a pill above the active one, badges at the icon's top right */
nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-width: 640px; margin: 0 auto; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.bottom a { flex: 1 1 0; min-width: 64px; height: 56px; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding-top: 4px; color: var(--muted); text-decoration: none; font-size: 12px; line-height: 1.2; }
nav.bottom a.on { color: var(--accent); font-weight: 600; }
nav.bottom a.on::before { content: ""; position: absolute; top: 4px; left: 50%; width: 24px; height: 3px; margin-left: -12px; border-radius: 2px; background: var(--accent); }
nav.bottom .ic { position: relative; width: 24px; height: 24px; }
nav.bottom svg, .icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }
.badge { position: absolute; top: -5px; left: 15px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--alert); color: var(--alert-ink);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
@media (min-width: 642px) { nav.bottom { border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; } }

/* Cards and type */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; margin: 0 0 12px; }
.card h2 { margin: 0 0 8px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.card.list { padding: 0; overflow: hidden; }
.card.list > h2 { padding: 14px 16px 2px; margin: 0; }
.card.list > .empty { padding: 14px 16px; margin: 0; }
.muted { color: var(--muted); font-size: 15px; }
.warn { color: var(--alert); }
.ok { color: var(--ok); }
p { margin: 8px 0; }
.msg { margin-top: 8px; font-size: 15px; }
.msg:empty { display: none; }

/* Buttons: primary 48 px, secondary 44 px */
button, .btn { font: inherit; font-weight: 600; border: 0; border-radius: 12px; padding: 12px 18px; background: var(--accent); color: var(--accent-ink);
  cursor: pointer; min-height: 48px; }
button.plain { background: transparent; color: var(--accent); border: 1px solid var(--line); min-height: 44px; padding: 10px 16px; }
button.danger { background: transparent; color: var(--alert); border: 1px solid var(--line); min-height: 44px; padding: 10px 16px; }
button.text { background: transparent; color: var(--accent); min-height: 44px; padding: 10px 10px; }
button.text.danger { color: var(--alert); border: 0; }
button.small { min-height: 44px; padding: 8px 14px; font-size: 15px; }
button:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
a.more, a.linkrow { display: flex; align-items: center; min-height: 44px; padding: 0 16px; color: var(--accent); text-decoration: none; font-weight: 600; font-size: 15px; }
a.more { border-top: 1px solid var(--line); }
.links { display: flex; flex-direction: column; margin: 0 0 12px; }
.links a.linkrow { padding: 0 4px; }
a.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); text-decoration: none; font-weight: 600; font-size: 15px; margin-bottom: 4px; }

/* Inputs */
select, textarea, input[type=text], input[type=date], input[type=number], input[type=time] { font: inherit; width: 100%; padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--ink); min-height: 48px; }
textarea { min-height: 90px; resize: vertical; }
input.code { font-size: 26px; letter-spacing: 3px; text-transform: uppercase; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; }
label.field, legend.field { display: block; margin: 14px 0 6px; padding: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
fieldset.fs { border: 0; margin: 14px 0 0; padding: 0; min-width: 0; }
fieldset.fs > legend.field { margin-top: 0; }

/* Switch rows: title 17, one line 14 muted, switch 52 x 32, min 56 px */
.swrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; }
.card h2 + .swrow { border-top: 0; }
.swtext { min-width: 0; }
.swt { display: block; font-size: 17px; }
.sws { display: block; font-size: 14px; color: var(--muted); }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 16px; background: var(--line); position: relative; flex: none; cursor: pointer; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; }
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 23px; box-shadow: 0 0 0 2px var(--accent-ink); }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.row:first-of-type, .card h2 + .row { border-top: 0; }
.row.dev { flex-wrap: wrap; }
.row.dev > div:first-child { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.bigcode { font: 600 40px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: 4px; text-align: center; margin: 12px 0; user-select: all; }
ol.steps { padding-left: 22px; } ol.steps li { margin: 6px 0; }
.ev { border-top: 1px solid var(--line); padding: 10px 0; }
.ev:first-child { border-top: 0; }
.ev .d { font-size: 14px; color: var(--muted); }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 8px; }
.cardhead h2 { margin: 0; }

/* Today */
.msgcard { display: block; background: var(--soft); border-radius: 16px; padding: 14px 16px; margin: 0 0 12px; color: var(--ink); text-decoration: none; }
.msgcard .mh { font-size: 15px; color: var(--muted); }
.msgcard .who { color: var(--accent); font-weight: 700; }
.msgcard .b { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.msgcard .more { font-size: 14px; color: var(--muted); margin-top: 4px; }
a.tile { display: flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; }
.big { font-size: 42px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.tile .tl { flex: 1; min-width: 0; }
.tile .tl .muted { font-size: 14px; }
.chev { color: var(--muted); font-size: 22px; }
a.quiet { display: flex; align-items: center; min-height: 44px; margin: 0 0 12px; padding: 0 4px; color: var(--muted); font-size: 15px; text-decoration: none; }
.card.alertcard { border: 2px solid var(--alert); }
.alerttitle { margin: 0 0 4px; color: var(--alert); font-weight: 600; }

/* + Add: floats bottom-right, 16 px above the tab bar, inside the centred 640 px column */
.fab { position: fixed; z-index: 12; bottom: calc(56px + 16px + env(safe-area-inset-bottom)); right: max(16px, calc(50vw - 320px + 16px));
  height: 52px; min-height: 52px; padding: 0 22px; border-radius: 26px; font-weight: 700; box-shadow: 0 4px 14px var(--shadow); }

/* Skeleton loading */
.skel { height: 12px; border-radius: 6px; background: var(--soft); margin: 12px 0; }
.skel.w40 { width: 40%; } .skel.w60 { width: 60%; } .skel.w80 { width: 80%; }
.skel.lab { width: 30%; margin-top: 2px; }

/* To-do */
.quickadd { display: flex; gap: 8px; margin: 0 0 12px; }
.quickadd input { flex: 1; min-width: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 12px; align-items: center; }
.chip { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; min-height: 44px; font-weight: 600; font-size: 15px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
select.chip { width: auto; flex: 1 1 0; min-width: 104px; max-width: 200px; background: var(--card); padding: 8px 6px 8px 12px; min-height: 44px; }
.itemwrap { display: grid; grid-template-rows: 1fr; }
.itemwrap + .itemwrap { border-top: 1px solid var(--line); }
.item { display: flex; align-items: stretch; min-height: 0; overflow: hidden; }
.item.now { box-shadow: inset 4px 0 0 var(--alert); }
.tick { flex: none; position: relative; width: 52px; min-height: 52px; margin-left: 2px; background: transparent; border: 0; padding: 0; border-radius: 0;
  display: flex; align-items: center; justify-content: center; }
.tick::before { content: ""; width: 28px; height: 28px; border: 2px solid var(--accent); border-radius: 50%; box-sizing: border-box; }
.tick::after { content: ""; position: absolute; top: 50%; left: 50%; width: 7px; height: 13px; margin: -9px 0 0 -4px; border: solid var(--accent-ink);
  border-width: 0 2.5px 2.5px 0; transform: rotate(45deg); opacity: 0; }
.ticking .tick::before { background: var(--accent); }
.ticking .tick::after { opacity: 1; }
.item .body { flex: 1; min-width: 0; min-height: 52px; text-align: left; background: transparent; color: var(--ink); border: 0; padding: 10px 16px 10px 4px;
  border-radius: 0; font-weight: 400; }
.item .t { font-size: 17px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.3; }
.item .meta { font-size: 14px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.due-late { color: var(--alert); font-weight: 600; }
.due-today { color: var(--ok); font-weight: 600; }
.remind { color: var(--warm); font-weight: 600; white-space: nowrap; }
.remind .icon { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px; stroke-width: 2.2; }
.photo { max-width: 100%; border-radius: 12px; margin-top: 8px; display: block; }
.daylabel { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 16px 0 2px; }
.daylabel:first-of-type { margin-top: 4px; }

/* Sheets: edit sheet and the + Add menu. --vvh/--vvt follow the visual viewport so the footer stays above the iOS keyboard. */
.sheet { position: fixed; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100%); background: var(--scrim); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center; }
.panel { background: var(--card); width: 100%; max-width: 640px; max-height: calc(100% - 16px); display: flex; flex-direction: column;
  border-radius: 22px 22px 0 0; box-shadow: 0 -8px 30px var(--shadow); }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; flex: none; }
.sheetscroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.sheettitle { margin: 4px 0 2px; font-size: 22px; font-weight: 700; letter-spacing: -.3px; }
.lastdone { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
button.wide { width: 100%; margin: 8px 0 4px; }
.sheetfoot { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--card); }
.sheetfoot .msg { flex: 1 0 100%; margin: 0 0 4px; }
.sheetfoot .save { flex: 1; }
.inline { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.inline input[type=number] { width: 88px; flex: none; }
.inline select { flex: 1; }
.actionsheet { padding: 0 16px calc(12px + env(safe-area-inset-bottom)); }
.actionsheet .sheettitle { margin: 4px 0 8px; }
.actionsheet button { width: 100%; margin: 0 0 8px; min-height: 52px; }
.actionsheet button.text { margin: 0; }

/* Segmented controls: real radios under the styling (keyboard + screen readers) */
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg label { flex: 1 1 0; min-width: 0; position: relative; display: flex; cursor: pointer; }
.seg input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.seg span { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px; padding: 4px 3px;
  font-size: 15px; line-height: 1.15; border-left: 1px solid var(--line); overflow-wrap: anywhere; }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: -3px; }
.seg + input[type=time] { margin-top: 8px; }

/* Toast: above the tab bar, and above + Add when it shows */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(56px + 12px + env(safe-area-inset-bottom)); max-width: 608px; margin: 0 auto; z-index: 15;
  background: var(--ink); color: var(--bg); border-radius: 12px; padding: 6px 6px 6px 14px; min-height: 48px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 15px; }
body.has-fab .toast { bottom: calc(56px + 16px + 52px + 12px + env(safe-area-inset-bottom)); }
.toast span { padding: 6px 0; overflow-wrap: anywhere; }
.toast button { flex: none; background: transparent; color: var(--toast-act); border: 0; min-height: 44px; padding: 8px 12px; font-weight: 700; }

/* Messages */
.sendrow { justify-content: space-between; align-items: center; }
.note { border-top: 1px solid var(--line); padding: 10px 0; }
.note:first-child { border-top: 0; }
.note .nh { font-size: 14px; color: var(--muted); }
.note .nh strong { color: var(--ink); }
.note .b { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }

/* House placeholder */
.house { text-align: center; padding: 28px 20px; }
.house .icon { width: 48px; height: 48px; color: var(--muted); margin: 0 auto 8px; stroke-width: 1.6; }
.house p { margin: 6px 0; }

/* Desktop: hover states */
@media (hover: hover) {
  .item .body:hover, a.tile:hover, a.msgcard:hover { background: var(--soft); }
  a.tile:hover { border-radius: 16px; }
  button:not(.text):not(.plain):not(.danger):not(.tick):not(.body):hover:not(:disabled) { filter: brightness(.94); }
  button.plain:hover, button.text:hover, button.danger:hover, .chip:not(.on):hover { background: var(--soft); }
  nav.bottom a:hover { color: var(--ink); }
  nav.bottom a.on:hover { color: var(--accent); }
}

/* Motion only for people who haven't asked to reduce it */
@media (prefers-reduced-motion: no-preference) {
  .panel { animation: slideup .2s ease-out; }
  .sheet { animation: fadein .2s ease-out; }
  .toast { animation: fadein .15s ease-out; }
  .switch::after { transition: left .15s; }
  .tick::before, .tick::after { transition: background-color .15s, opacity .15s; }
  .itemwrap { transition: grid-template-rows .2s ease-out, opacity .2s ease-out; }
}
.itemwrap.gone { grid-template-rows: 0fr; opacity: 0; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
