/* Hearth — colours follow the validated reference palette.
   Categorical slots are assigned in fixed order and never cycled; status
   colours are reserved and always ship with an icon + label. Dark mode is a
   selected set of steps against the dark surface, not an inverted filter. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 16px rgba(11, 11, 11, 0.04);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-450: #2a78d6;
  --seq-600: #184f95;

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;

  --radius: 14px;
  --radius-sm: 8px;
  --gap: 16px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --shadow: none;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --seq-100: #184f95;
    --seq-250: #256abf;
    --seq-450: #3987e5;
    --seq-600: #86b6ef;
    --success-text: #0ca30c;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --shadow: none;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --seq-100: #184f95;
  --seq-250: #256abf;
  --seq-450: #3987e5;
  --seq-600: #86b6ef;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ shell */

.shell { max-width: 1680px; margin: 0 auto; padding: 20px; }

.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.topbar .date { color: var(--text-secondary); font-size: 14px; }
.topbar .spacer { flex: 1 1 auto; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-1);
  font-size: 13px; color: var(--text-secondary);
  cursor: pointer; min-height: 32px;
}
.chip:hover { border-color: var(--axis); }
.chip[aria-pressed='true'] { background: var(--seq-100); border-color: var(--seq-250); color: var(--text-primary); }
.chip.ghost { background: transparent; }

/* --------------------------------------------------------------- reminders */

.reminders { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.reminders:empty { display: none; }

.reminder {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  box-shadow: var(--shadow);
}
.reminder .icon { font-size: 18px; line-height: 1; flex: 0 0 auto; }
.reminder .body { flex: 1 1 auto; min-width: 0; }
.reminder .title { font-weight: 600; font-size: 14px; }
.reminder .detail { color: var(--text-secondary); font-size: 13px; }
.reminder[data-level='critical'] { border-left-color: var(--critical); }
.reminder[data-level='serious'] { border-left-color: var(--serious); }
.reminder[data-level='good'] { border-left-color: var(--good); }

/* -------------------------------------------------------------------- grid */

.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: 1.06fr 1fr 1fr;
  align-items: start;
}
.col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

@media (max-width: 1279px) and (min-width: 768px) {
  .grid { grid-template-columns: 1fr 1fr; }
  /* Two columns: fold the third column's cards in beside the others. */
  .col-c { display: contents; }
  #card-ynab, #card-weather { grid-column: 2; }
}

@media (max-width: 767px) {
  .shell { padding: 12px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  /* Columns dissolve so `order` can sequence the cards themselves. */
  .col { display: contents; }
  /* Phone order leads with what is actionable on a phone. */
  #card-tasks { order: 1; }
  #card-calendar { order: 2; }
  #card-daily { order: 3; }
  #card-weather { order: 4; }
  #card-nutrition { order: 5; }
  #card-ynab { order: 6; }
  .chip, .capture button { min-height: 44px; }
  .task .check { width: 26px; height: 26px; }
  .task .actions button { min-width: 34px; min-height: 34px; }
}

.card > header {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 12px;
}
.card h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin: 0; font-weight: 600;
}
.card header .meta { margin-left: auto; font-size: 12px; color: var(--text-muted); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary);
  white-space: nowrap;
}
.badge[data-tone='critical'] { color: var(--critical); border-color: var(--critical); }
.badge[data-tone='warning'] { color: var(--text-primary); border-color: var(--warning); background: color-mix(in srgb, var(--warning) 16%, transparent); }
.badge[data-tone='good'] { color: var(--success-text); border-color: var(--good); }
.badge[data-tone='stale'] { color: var(--text-muted); border-style: dashed; }
/* `display: inline-flex` above would otherwise beat the `hidden` attribute. */
.badge[hidden], .chip[hidden] { display: none; }

/* ------------------------------------------------------------------- tasks */

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

.task-list { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow-y: auto; }
.task {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 4px; border-bottom: 1px solid var(--grid);
}
.task:last-child { border-bottom: none; }
.task.busy { opacity: 0.5; }
.task .check {
  flex: 0 0 auto; width: 22px; height: 22px; margin-top: 1px;
  border-radius: 6px; border: 1.5px solid var(--axis);
  background: transparent; cursor: pointer;
  display: grid; place-items: center; font-size: 13px; line-height: 1;
  padding: 0;
}
.task .check:hover { border-color: var(--series-1); }
.task .main { flex: 1 1 auto; min-width: 0; }
.task .text { font-size: 14px; word-break: break-word; }
.task .sub {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  font-size: 12px; color: var(--text-muted); margin-top: 3px;
}
.task .sub a { color: var(--text-muted); }
.task .prio { font-size: 12px; }
.task .due { font-variant-numeric: tabular-nums; }
.task .due[data-bucket='overdue'] { color: var(--critical); font-weight: 600; }
.task .due[data-bucket='today'] { color: var(--text-primary); font-weight: 600; }
.task .actions { display: flex; gap: 4px; flex: 0 0 auto; }
.task .actions button {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-muted); padding: 2px 5px; border-radius: 6px; font-size: 13px;
}
.task .actions button:hover { background: var(--grid); color: var(--text-primary); }

.tag {
  font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: var(--grid); color: var(--text-secondary);
}

.capture { display: flex; gap: 6px; margin-top: 10px; }
.capture input {
  flex: 1 1 auto; min-width: 0; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--page);
}
.capture input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.capture button {
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--series-1); background: var(--series-1); color: #fff;
}

/* ------------------------------------------------------------------- ynab */

.pacing { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.pacing li { padding: 8px 2px; border-bottom: 1px solid var(--grid); }
.pacing li:last-child { border-bottom: none; }
.pacing .row1 {
  display: flex; align-items: baseline; gap: 8px; font-size: 13px;
}
.pacing .name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pacing .amt { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.pacing .basis { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.bar {
  position: relative; height: 8px; border-radius: 4px;
  background: var(--grid); margin-top: 6px; overflow: hidden;
}
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 4px; display: block; }
.bar > .pace {
  position: absolute; top: -2px; bottom: -2px; width: 2px;
  background: var(--text-secondary); border-radius: 1px;
}
.bar[data-status='on_track'] > i { background: var(--good); }
.bar[data-status='ahead'] > i { background: var(--warning); }
.bar[data-status='over'] > i { background: var(--critical); }

.stat-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 12px; }
.stat { min-width: 0; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.stat .label { font-size: 12px; color: var(--text-muted); }
.stat .value[data-tone='critical'] { color: var(--critical); }
.stat .value[data-tone='good'] { color: var(--success-text); }

.inbox { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.inbox li { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.inbox .payee { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox .amt { font-variant-numeric: tabular-nums; }

details > summary {
  cursor: pointer; font-size: 12px; color: var(--text-secondary);
  padding: 6px 0; list-style: revert;
}

/* -------------------------------------------------------------- nutrition */

.meals { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.meals li { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--grid); }
.meals .name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meals .kcal { font-variant-numeric: tabular-nums; color: var(--text-secondary); }
.meals .meal { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.macro-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; margin: 6px 0 4px; }
.macro-bar > span { display: block; height: 100%; }
.macro-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.macro-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* --------------------------------------------------------------- calendar */

.agenda { display: flex; flex-direction: column; gap: 10px; max-height: 480px; overflow-y: auto; }
.agenda-day > h3 {
  font-size: 12px; margin: 0 0 5px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  position: sticky; top: 0; background: var(--surface-1); padding: 3px 0;
}
.agenda-day[data-today='true'] > h3 { color: var(--text-primary); }
.event {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 5px 0; font-size: 13px;
}
.event .swatch { flex: 0 0 auto; width: 3px; align-self: stretch; border-radius: 2px; min-height: 20px; }
.event .time { flex: 0 0 auto; width: 78px; font-variant-numeric: tabular-nums; color: var(--text-secondary); font-size: 12px; }
.event .title { flex: 1 1 auto; min-width: 0; word-break: break-word; }
.event .cal { font-size: 11px; color: var(--text-muted); }
.empty-day { font-size: 12px; color: var(--text-muted); font-style: italic; padding: 2px 0; }

/* ---------------------------------------------------------------- weather */

.wx-now { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.wx-now .temp { font-size: 40px; font-weight: 650; letter-spacing: -0.03em; line-height: 1; }
.wx-now .glyph { font-size: 34px; line-height: 1; }
.wx-now .desc { font-size: 13px; color: var(--text-secondary); }

.wx-days { list-style: none; margin: 12px 0 0; padding: 0; }
.wx-days li {
  display: grid; grid-template-columns: 42px 26px 1fr 84px;
  gap: 8px; align-items: center; padding: 5px 0; font-size: 13px;
}
.wx-days .day { color: var(--text-secondary); }
.wx-days .range { font-variant-numeric: tabular-nums; text-align: right; }
.wx-days .range .lo { color: var(--text-muted); }
.wx-days .track { height: 5px; background: var(--grid); border-radius: 3px; position: relative; }
.wx-days .track > i { position: absolute; height: 100%; border-radius: 3px; background: linear-gradient(90deg, var(--seq-250), var(--series-2)); }
.wx-days .pop { font-size: 11px; color: var(--series-1); }

/* ---------------------------------------------------------------- charts */

.chart { width: 100%; display: block; }
.chart text { font-family: var(--font); }
.chart .axis-label { fill: var(--text-muted); font-size: 10px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .mark-gap { stroke: var(--surface-1); stroke-width: 2; }
.chart .direct-label { fill: var(--text-secondary); font-size: 11px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.chart-wrap { position: relative; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface-1); border: 1px solid var(--axis);
  border-radius: var(--radius-sm); padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14); white-space: nowrap;
  opacity: 0; transition: opacity 90ms;
}
.tooltip.on { opacity: 1; }
.tooltip .tt-row { display: flex; gap: 8px; justify-content: space-between; }
.tooltip .tt-head { font-weight: 600; margin-bottom: 3px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
table.data-table th, table.data-table td {
  text-align: right; padding: 3px 6px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
table.data-table th:first-child, table.data-table td:first-child { text-align: left; }
table.data-table th { color: var(--text-muted); font-weight: 600; }

/* ---------------------------------------------------------------- states */

.muted { color: var(--text-muted); font-size: 13px; }
.error-box {
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--critical); color: var(--critical);
  font-size: 13px; background: color-mix(in srgb, var(--critical) 8%, transparent);
}
.skeleton {
  height: 12px; border-radius: 6px; background: var(--grid);
  animation: pulse 1.4s ease-in-out infinite; margin: 8px 0;
}
@keyframes pulse { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text-primary); color: var(--surface-1);
  padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 50;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25); max-width: 90vw;
}
.toast[data-tone='critical'] { background: var(--critical); color: #fff; }

.task .text strong { font-weight: 650; }
.task .text code, .event code {
  font-family: ui-monospace, SFMono-Regular, monospace; font-size: 0.92em;
  background: var(--grid); border-radius: 4px; padding: 0 4px;
}
.wikilink { color: var(--series-1); }

/* --------------------------------------------------- nutrition quick log */

.quicklog { margin: 10px 0 4px; }
.quicklog-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.quicklog-row input, .quicklog-row select {
  padding: 8px 9px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--page); min-width: 0;
}
.quicklog-row input:focus, .quicklog-row select:focus {
  outline: 2px solid var(--series-1); outline-offset: -1px;
}
.quicklog-row .grow { flex: 1 1 130px; }
.quicklog-row .kcal-in { width: 74px; flex: 0 0 auto; }
.quicklog-row button {
  padding: 8px 13px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid var(--series-1); background: var(--series-1); color: #fff;
}
.quicklog-row button:disabled, .quicklog-row input:disabled, .quicklog-row select:disabled {
  opacity: 0.55; cursor: default;
}

/* Traffic-light flags always carry a word, never colour alone. */
.rating {
  font-size: 10px; padding: 1px 6px; border-radius: 999px; white-space: nowrap;
  border: 1px solid currentColor; flex: 0 0 auto;
}
.rating[data-tone='good'] { color: var(--success-text); }
.rating[data-tone='warning'] { color: var(--text-secondary); border-color: var(--warning); }
.rating[data-tone='critical'] { color: var(--critical); }

@media (max-width: 767px) {
  .quicklog-row button { min-height: 44px; }
  .quicklog-row input, .quicklog-row select { min-height: 44px; }
}

/* --------------------------------------------------------- login / account */

.login-page { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }

.login { width: 100%; max-width: 380px; }
.login-card { padding: 28px 24px 24px; text-align: center; }
.login-mark { font-size: 34px; line-height: 1; }
.login-card h1 { font-size: 22px; margin: 8px 0 4px; letter-spacing: -0.01em; }
.login-card .muted { margin: 0 0 18px; }

#login-form { display: flex; flex-direction: column; gap: 10px; }
#login-form input {
  padding: 11px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--page); width: 100%;
}
#login-form input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
#login-form button {
  padding: 11px 14px; border-radius: var(--radius-sm); cursor: pointer; min-height: 44px;
  border: 1px solid var(--series-1); background: var(--series-1); color: #fff; font-weight: 600;
}
#login-form button:disabled, #login-form input:disabled { opacity: 0.55; cursor: default; }

#login-error { margin-top: 14px; text-align: left; }
.login-card .default-hint { margin: 14px 0 0; text-align: left; }

/* The lock chip turns amber while the shipped default password is still set. */
#account-toggle[data-warn='1'] {
  border-color: var(--warning);
  background: color-mix(in srgb, var(--warning) 18%, transparent);
  color: var(--text-primary);
}

.account-dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-1); color: var(--text-primary);
  padding: 20px; width: min(380px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
.account-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.account-dialog h2 { font-size: 16px; margin: 0 0 4px; }
.account-dialog > .muted { margin: 0 0 16px; }

.account-form { display: flex; flex-direction: column; gap: 6px; }
.account-form label { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.account-form input {
  padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--page); width: 100%;
}
.account-form input:focus { outline: 2px solid var(--series-1); outline-offset: -1px; }
.account-form .error-box { margin-top: 10px; }

.account-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.account-actions button {
  padding: 9px 14px; border-radius: var(--radius-sm); cursor: pointer; min-height: 40px;
}
.account-actions .primary { border: 1px solid var(--series-1); background: var(--series-1); color: #fff; }
.account-actions .primary:disabled { opacity: 0.55; cursor: default; }
.account-actions .ghost { border: 1px solid var(--border); background: transparent; color: var(--text-secondary); }

.account-footer {
  display: flex; justify-content: flex-start;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--grid);
}
