/* ============================================================
   Tracker 2.0 — design system
   Mobile-first. Dark by default, light supported, system-aware.
   ============================================================ */

:root {
  color-scheme: dark light;

  /* Type */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", "Segoe UI Mono", "Roboto Mono", ui-monospace, monospace;

  --t-2xs: 0.6875rem;  /* 11 */
  --t-xs:  0.75rem;    /* 12 */
  --t-sm:  0.8125rem;  /* 13 */
  --t-base:0.9375rem;  /* 15 */
  --t-md:  1.0625rem;  /* 17 */
  --t-lg:  1.375rem;   /* 22 */
  --t-xl:  1.75rem;    /* 28 */
  --t-2xl: 2.25rem;    /* 36 */

  /* Space — 4pt grid */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;

  --tap: 44px;                       /* minimum touch target */
  --header-h: 56px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ---- Dark (default) ---- */
:root, :root[data-theme="dark"] {
  --bg:        #0a0b0d;
  --bg-elev:   #101215;
  --surface:   #15181c;
  --surface-2: #1c2026;
  --surface-3: #242930;
  --line:      #262b32;
  --line-soft: #1d2127;

  --ink:       #eef1f5;
  --ink-2:     #b6bdc7;
  --ink-3:     #7d8593;
  --ink-4:     #565e6b;

  --accent:      #7f92f5;
  --accent-ink:  #0a0b0d;
  --accent-soft: rgba(127, 146, 245, 0.14);
  --accent-line: rgba(127, 146, 245, 0.34);

  --ok:    #4fa87c;  --ok-soft:    rgba(79, 168, 124, 0.14);
  --warn:  #d3a244;  --warn-soft:  rgba(211, 162, 68, 0.14);
  --risk:  #d3776b;  --risk-soft:  rgba(211, 119, 107, 0.14);
  --info:  #5aa8c7;  --info-soft:  rgba(90, 168, 199, 0.14);

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 4px 16px rgba(0,0,0,.45);
  --shadow-3: 0 16px 48px rgba(0,0,0,.55);
  --scrim: rgba(0,0,0,.62);
}

/* ---- Light ---- */
:root[data-theme="light"] {
  --bg:        #f6f7f9;
  --bg-elev:   #ffffff;
  --surface:   #ffffff;
  --surface-2: #f1f3f6;
  --surface-3: #e6e9ee;
  --line:      #dfe3e9;
  --line-soft: #ebeef2;

  --ink:       #14171c;
  --ink-2:     #464e5a;
  --ink-3:     #6d7684;
  --ink-4:     #98a1af;

  --accent:      #4a5fd4;
  --accent-ink:  #ffffff;
  --accent-soft: rgba(74, 95, 212, 0.09);
  --accent-line: rgba(74, 95, 212, 0.28);

  --ok:    #2f7d55;  --ok-soft:    rgba(47, 125, 85, 0.10);
  --warn:  #9a6c12;  --warn-soft:  rgba(154, 108, 18, 0.10);
  --risk:  #b0483a;  --risk-soft:  rgba(176, 72, 58, 0.10);
  --info:  #2b7593;  --info-soft:  rgba(43, 117, 147, 0.10);

  --shadow-1: 0 1px 2px rgba(16,24,40,.06);
  --shadow-2: 0 4px 16px rgba(16,24,40,.08);
  --shadow-3: 0 16px 48px rgba(16,24,40,.14);
  --scrim: rgba(16,24,40,.34);
}

/* ============================================================
   Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over any display: set by a class. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Accessible focus — visible on every interactive surface */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-soft); }

/* ============================================================
   Layout
   ============================================================ */
.app {
  min-height: 100dvh;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--header-h) + var(--safe-t));
  padding-top: var(--safe-t);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding-inline: var(--s-4);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--line-soft);
}

.header__title { flex: 1; min-width: 0; }
.header__eyebrow {
  font-size: var(--t-2xs);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  font-weight: 600;
}
.header__date {
  font-size: var(--t-base);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  padding: var(--s-5) var(--s-4);
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + var(--s-8));
  max-width: 760px;
  margin: 0 auto;
}

.view[hidden] { display: none; }
.view { animation: fade .22s var(--ease); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }

/* ---- Bottom nav (mobile) ---- */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  padding-inline: var(--safe-l) var(--safe-r);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}

.nav__btn {
  appearance: none;
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tap);
  color: var(--ink-3);
  cursor: pointer;
  transition: color .15s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.nav__btn svg { width: 21px; height: 21px; stroke-width: 1.7; }
.nav__label {
  font-size: var(--t-2xs);
  font-weight: 550;
  letter-spacing: -0.005em;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav__btn[aria-selected="true"] { color: var(--accent); }
.nav__btn:active { transform: scale(0.94); }

/* Six tabs must fit a 320px phone. Tighten the labels instead of letting
   "Decisions" clip or the bar overflow sideways. The 44px tap target is kept:
   the button still fills its full column height. */
@media (max-width: 400px) {
  .nav__btn { padding-inline: 2px; min-width: 0; }
  .nav__btn svg { width: 19px; height: 19px; }
  .nav__label { font-size: 10px; letter-spacing: -0.025em; }
}

/* ============================================================
   Cards & primitives
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-3);
}
.card--flush { padding: 0; overflow: hidden; }
.card--accent { border-color: var(--accent-line); background: var(--bg-elev); }

.section {
  margin-bottom: var(--s-6);
}
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
  padding-inline: var(--s-1);
}
.section__title {
  font-size: var(--t-2xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
}
.section__meta { font-size: var(--t-xs); color: var(--ink-4); font-variant-numeric: tabular-nums; }

/* ---- Hierarchy rail: quarter -> month -> week ---- */
.rail {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line-soft);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  margin-bottom: var(--s-5);
}
.rail__row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface);
  min-height: var(--tap);
}
.rail__tier {
  flex: 0 0 58px;
  font-size: var(--t-2xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-4);
}
.rail__body { flex: 1; min-width: 0; }
.rail__text {
  font-size: var(--t-sm);
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail__text strong { color: var(--ink); font-weight: 600; }
.rail__count {
  font-size: var(--t-2xs);
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

/* ---- Main priority hero ---- */
.hero {
  background: linear-gradient(150deg, var(--accent-soft), transparent 62%), var(--surface);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-xl);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
}
.hero__label {
  font-size: var(--t-2xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: var(--s-2);
}
.hero__text {
  font-size: var(--t-lg);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.hero__text--empty { color: var(--ink-4); font-weight: 400; font-size: var(--t-md); }
.hero__foot {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid var(--line);
  font-size: var(--t-xs);
  color: var(--ink-3);
}

/* ---- Task list ---- */
.tasks { display: flex; flex-direction: column; gap: var(--s-2); }

.task {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  min-height: var(--tap);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.task--done { background: var(--bg-elev); border-color: var(--line-soft); }
.task--blocked { border-color: color-mix(in srgb, var(--risk) 44%, var(--line)); }

/* A full 44px touch target wrapping a 24px visual box. The negative margins
   let the target bleed into the card padding without shifting the visuals. */
.task__check {
  flex-shrink: 0;
  width: var(--tap); height: var(--tap);
  margin: -4px -6px -4px -10px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.task__check__box {
  width: 24px; height: 24px;
  border-radius: 7px;
  border: 1.5px solid var(--ink-4);
  background: transparent;
  display: grid;
  place-items: center;
  transition: all .15s var(--ease);
}
.task__check svg { width: 14px; height: 14px; opacity: 0; stroke-width: 3; }
.task__check[aria-checked="true"] .task__check__box {
  background: var(--ok);
  border-color: var(--ok);
  color: #fff;
}
.task__check[aria-checked="true"] svg { opacity: 1; }
.task__check:active .task__check__box { transform: scale(0.9); }

.task__body { flex: 1; min-width: 0; }
.task__text {
  font-size: var(--t-base);
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.task--done .task__text { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-4); }
.task__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-2);
}
.task__more {
  flex-shrink: 0;
  width: var(--tap); height: var(--tap);
  margin: -10px -8px -10px 0;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: var(--r-sm);
  color: var(--ink-4);
  cursor: pointer;
}
.task__more svg { width: 18px; height: 18px; }
.task__more:hover { color: var(--ink-2); background: var(--surface-2); }

/* ---- Chips / badges ---- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--t-2xs);
  font-weight: 550;
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-3);
  border: 1px solid transparent;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip--goal  { background: var(--accent-soft); color: var(--accent); }
.chip--admin { background: var(--surface-2); color: var(--ink-4); }
.chip--ok    { background: var(--ok-soft);   color: var(--ok); }
.chip--warn  { background: var(--warn-soft); color: var(--warn); }
.chip--risk  { background: var(--risk-soft); color: var(--risk); }
.chip--info  { background: var(--info-soft); color: var(--info); }

/* ---- Buttons ---- */
.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--tap);
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  font-size: var(--t-base);
  font-weight: 550;
  cursor: pointer;
  transition: all .14s var(--ease);
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn--ghost { background: transparent; border-color: var(--line); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--quiet { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn--quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn--danger { color: var(--risk); border-color: color-mix(in srgb, var(--risk) 40%, var(--line)); background: transparent; }
.btn--block { width: 100%; }
.btn--sm { min-height: 40px; padding: 0 var(--s-3); font-size: var(--t-sm); border-radius: var(--r-sm); }
.btn--icon { width: var(--tap); padding: 0; flex-shrink: 0; }
.btn--icon svg { width: 19px; height: 19px; }

.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.btn-row--split > * { flex: 1 1 0; min-width: 130px; }

/* ---- Forms ---- */
.field { margin-bottom: var(--s-4); }
.label {
  display: block;
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: var(--s-2);
  letter-spacing: -0.005em;
}
.hint { font-size: var(--t-xs); color: var(--ink-4); margin-top: var(--s-2); line-height: 1.45; }

.input, .textarea, .select {
  width: 100%;
  min-height: var(--tap);
  padding: var(--s-3);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--ink);
  font-size: var(--t-md);         /* >=16px: stops iOS zoom-on-focus */
  transition: border-color .14s var(--ease), background .14s var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  background: var(--surface);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%237d8593' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  padding-right: var(--s-10);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }

/* ---- Stat tiles ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: var(--s-2); }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s-3);
  text-align: left;
}
.stat__val {
  font-size: var(--t-xl);
  font-weight: 640;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}
.stat__label {
  font-size: var(--t-2xs);
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  margin-top: var(--s-1);
}
.stat--ok .stat__val { color: var(--ok); }
.stat--warn .stat__val { color: var(--warn); }
.stat--risk .stat__val { color: var(--risk); }

/* ---- Progress ---- */
.bar {
  height: 5px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
}
.bar__fill {
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  transition: width .4s var(--ease);
}
.bar__fill--ok { background: var(--ok); }

/* ---- Goal rows ---- */
.goal {
  display: flex;
  align-items: flex-start;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  margin-bottom: var(--s-2);
  min-height: var(--tap);
}
.goal--done { background: var(--bg-elev); }
.goal--done .goal__text { color: var(--ink-3); text-decoration: line-through; }
.goal--archived, .goal--superseded { opacity: .6; }
.goal__body { flex: 1; min-width: 0; }
.goal__text { font-size: var(--t-base); line-height: 1.4; overflow-wrap: anywhere; }
.goal__meta { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-2); }

/* ---- Empty states ---- */
.empty {
  text-align: center;
  padding: var(--s-8) var(--s-4);
  color: var(--ink-4);
}
.empty__title { font-size: var(--t-base); color: var(--ink-2); font-weight: 550; margin-bottom: var(--s-2); }
.empty__text { font-size: var(--t-sm); line-height: 1.5; max-width: 34ch; margin: 0 auto var(--s-4); }

/* ---- Sync pill ---- */
.sync {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: var(--t-2xs);
  font-weight: 600;
  color: var(--ink-3);
  flex-shrink: 0;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.sync__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}
.sync[data-state="saving"] { color: var(--info); }
.sync[data-state="saving"] .sync__dot { background: var(--info); animation: pulse 1.1s infinite; }
.sync[data-state="error"], .sync[data-state="offline"] { color: var(--risk); border-color: color-mix(in srgb, var(--risk) 40%, var(--line)); }
.sync[data-state="error"] .sync__dot, .sync[data-state="offline"] .sync__dot { background: var(--risk); }
.sync[data-state="stale"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); background: var(--warn-soft); }
.sync[data-state="stale"] .sync__dot { background: var(--warn); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.sync__label { display: none; }
@media (min-width: 360px) { .sync__label { display: inline; } }

/* ---- Banner ---- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  line-height: 1.45;
  margin-bottom: var(--s-3);
  border: 1px solid transparent;
}
.banner--warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.banner--risk { background: var(--risk-soft); color: var(--risk); border-color: color-mix(in srgb, var(--risk) 30%, transparent); }
.banner--info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }
.banner__body { flex: 1; min-width: 0; }
.banner .btn { flex-shrink: 0; }

/* ============================================================
   Sheet / modal — bottom sheet on phones, centred dialog on desktop
   ============================================================ */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: scrimIn .25s var(--ease);
  border: 0;
  padding: 0;
  cursor: pointer;
}
@keyframes scrimIn { from { opacity: 0; } }

.sheet__panel {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: calc(100dvh - var(--s-8));
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  box-shadow: var(--shadow-3);
  animation: sheetUp .3s var(--ease);
  overflow: hidden;
}
@keyframes sheetUp { from { transform: translateY(100%); } }

.sheet__grip {
  width: 36px; height: 4px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  margin: var(--s-3) auto var(--s-1);
  flex-shrink: 0;
}
.sheet__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4) var(--s-3);
  border-bottom: 1px solid var(--line-soft);
  flex-shrink: 0;
}
.sheet__title { flex: 1; font-size: var(--t-md); font-weight: 640; letter-spacing: -0.015em; }
.sheet__body {
  padding: var(--s-4);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  overscroll-behavior: contain;
}
.sheet__foot {
  padding: var(--s-3) var(--s-4);
  padding-bottom: calc(var(--s-3) + var(--safe-b));
  border-top: 1px solid var(--line-soft);
  background: var(--bg-elev);
  flex-shrink: 0;
  display: flex;
  gap: var(--s-2);
}
.sheet__foot > .btn { flex: 1; }

/* ---- Action list (rollover menu) ---- */
.actions { display: flex; flex-direction: column; gap: var(--s-1); }
.action {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  min-height: var(--tap);
  padding: var(--s-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  text-align: left;
  cursor: pointer;
  transition: background .14s var(--ease);
}
.action:hover { background: var(--surface-2); }
.action__icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-3);
  flex-shrink: 0;
}
.action__icon svg { width: 16px; height: 16px; }
.action__body { flex: 1; min-width: 0; }
.action__title { font-size: var(--t-base); font-weight: 550; }
.action__desc { font-size: var(--t-xs); color: var(--ink-4); margin-top: 1px; }
.action[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); }
.action[aria-pressed="true"] .action__icon { background: var(--accent); color: var(--accent-ink); }

/* ---- Toast ---- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + var(--s-3));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  width: calc(100% - var(--s-8));
  max-width: 420px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface-3);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-2);
  font-size: var(--t-sm);
  animation: toastIn .25s var(--ease);
  pointer-events: auto;
}
.toast--ok   { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.toast--risk { border-color: color-mix(in srgb, var(--risk) 45%, var(--line)); }
.toast__body { flex: 1; min-width: 0; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ---- Skeleton loading ---- */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.skeleton--line { height: 14px; margin-bottom: var(--s-2); }
.skeleton--card { height: 76px; margin-bottom: var(--s-3); }

/* ---- Segmented control ---- */
.segmented {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--r-md);
  margin-bottom: var(--s-4);
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented__btn {
  flex: 1 0 auto;
  min-height: 36px;
  padding: 0 var(--s-3);
  border: 0;
  border-radius: calc(var(--r-md) - 3px);
  background: transparent;
  color: var(--ink-3);
  font-size: var(--t-sm);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s var(--ease);
}
.segmented__btn[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

/* ---- Date stepper ---- */
.stepper { display: flex; align-items: center; gap: var(--s-1); }
.stepper .btn--icon { min-height: var(--tap); width: var(--tap); border-color: transparent; background: transparent; }

/* ---- Definition rows ---- */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: var(--t-sm);
}
.row:last-child { border-bottom: 0; }
.row__k { color: var(--ink-3); flex-shrink: 0; }
.row__v { text-align: right; font-weight: 550; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* ============================================================
   Finances
   Money reads better in one column. Everything here is a row or a
   bar — no chart library, no canvas, nothing that reflows badly on a
   phone or that a screen reader cannot follow.
   ============================================================ */
.fin__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-4);
}
.fin__sub { font-size: var(--t-xs); color: var(--ink-4); margin-top: 2px; }
.fin__sub[data-state="stale"] { color: var(--warn); }
.fin__sub[data-state="error"] { color: var(--risk); }

/* Headline figure — one number that matters, then the context under it. */
.fin-hero {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  margin-bottom: var(--s-3);
}
.fin-hero__label {
  font-size: var(--t-2xs);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-weight: 600;
}
.fin-hero__val {
  font-size: var(--t-2xl);
  font-weight: 660;
  letter-spacing: -0.035em;
  font-variant-numeric: tabular-nums;
  line-height: 1.06;
  margin-top: var(--s-2);
  overflow-wrap: anywhere;
}
.fin-hero__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2);
  margin-top: var(--s-3);
  font-size: var(--t-sm);
  color: var(--ink-3);
}

/* Money rows: label left, figure right, never wrapping into each other. */
.fin-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--line-soft);
  min-height: 40px;
}
.fin-row:last-child { border-bottom: 0; }
.fin-row__body { min-width: 0; flex: 1; }
.fin-row__name {
  font-size: var(--t-base);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fin-row__meta {
  font-size: var(--t-xs);
  color: var(--ink-4);
  margin-top: 2px;
  overflow-wrap: anywhere;
}
.fin-row__val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.fin-row__val--out { color: var(--ink); }
.fin-row__val--in  { color: var(--ok); }
.fin-row__val--debt { color: var(--risk); }

/* Bars: the whole point is comparison, so the track is always full width. */
.fin-bars { display: flex; flex-direction: column; gap: var(--s-2); }
.fin-bar {
  display: grid;
  grid-template-columns: minmax(72px, 34%) 1fr auto;
  align-items: center;
  gap: var(--s-2);
  min-height: 34px;
  font-size: var(--t-sm);
}
.fin-bar__name {
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fin-bar__track {
  height: 10px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
  min-width: 0;
}
.fin-bar__fill {
  display: block;
  height: 100%;
  border-radius: var(--r-full);
  background: var(--accent);
  min-width: 3px;
}
.fin-bar__fill--muted { background: var(--ink-4); }
.fin-bar__fill--now { background: var(--accent); }
.fin-bar__fill--past { background: color-mix(in srgb, var(--accent) 42%, transparent); }
.fin-bar__val {
  font-variant-numeric: tabular-nums;
  color: var(--ink-2);
  white-space: nowrap;
  font-size: var(--t-xs);
}

.fin-split { display: flex; height: 10px; border-radius: var(--r-full); overflow: hidden; }
.fin-split i { display: block; height: 100%; }

.fin-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-3);
  font-size: var(--t-xs);
  color: var(--ink-4);
}
.fin-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 5px; }

.fin-note {
  font-size: var(--t-xs);
  color: var(--ink-4);
  line-height: 1.5;
  margin-top: var(--s-3);
}

.fin-delta { font-size: var(--t-xs); font-variant-numeric: tabular-nums; }
.fin-delta--up   { color: var(--risk); }   /* spending more is not good news */
.fin-delta--down { color: var(--ok); }

.fin-mask {
  font-family: var(--font-num);
  font-size: var(--t-xs);
  color: var(--ink-4);
  letter-spacing: 0.04em;
}

.fin-id {
  font-family: var(--font-num);
  font-size: var(--t-2xs);
  color: var(--ink-4);
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}

/* ============================================================
   Tablet / desktop
   ============================================================ */
@media (min-width: 720px) {
  .main { padding: var(--s-8) var(--s-6); padding-bottom: var(--s-12); }
  .grid-2 { gap: var(--s-4); }
  .sheet { align-items: center; padding: var(--s-6); }
  .sheet__panel {
    border-radius: var(--r-xl);
    border-bottom: 1px solid var(--line);
    max-height: min(760px, calc(100dvh - var(--s-12)));
    animation: dialogIn .24s var(--ease);
  }
  @keyframes dialogIn { from { opacity: 0; transform: translateY(14px) scale(.985); } }
  .sheet__grip { display: none; }
  .sheet__foot { padding-bottom: var(--s-3); }
  .sheet__foot > .btn { flex: 0 1 auto; }
  .sheet__foot { justify-content: flex-end; }
  .toasts { bottom: var(--s-6); }
}

@media (min-width: 960px) {
  :root { --header-h: 64px; }

  .app {
    display: grid;
    grid-template-columns: 232px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "nav header" "nav main";
    min-height: 100dvh;
  }
  .header {
    grid-area: header;
    padding-inline: var(--s-8);
  }
  .main {
    grid-area: main;
    max-width: 860px;
    margin: 0;
    padding: var(--s-8);
    padding-bottom: var(--s-12);
    width: 100%;
  }

  /* Bottom nav becomes a sidebar */
  .nav {
    grid-area: nav;
    position: sticky;
    top: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: var(--s-5) var(--s-3);
    border-top: 0;
    border-right: 1px solid var(--line);
    background: var(--bg-elev);
    backdrop-filter: none;
  }
  .nav__brand {
    display: block;
    padding: 0 var(--s-3) var(--s-5);
    font-size: var(--t-sm);
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--ink);
  }
  .nav__brand span { display: block; font-size: var(--t-2xs); color: var(--ink-4); font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase; margin-top: 2px; }
  .nav__btn {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--s-3);
    padding: 0 var(--s-3);
    min-height: 42px;
    border-radius: var(--r-md);
  }
  .nav__btn:hover { background: var(--surface-2); color: var(--ink-2); }
  .nav__btn[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
  .nav__label { font-size: var(--t-base); font-weight: 550; }
  .nav__spacer { flex: 1; }

  .toasts { left: auto; right: var(--s-6); transform: none; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
}

@media (min-width: 1200px) {
  .main { max-width: 940px; }
}

/* Mobile only: hide the desktop brand block */
@media (max-width: 959px) {
  .nav__brand, .nav__spacer, .nav__btn--desktop { display: none; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---- Print ---- */
@media print {
  .nav, .header, .sheet, .toasts { display: none !important; }
  .main { padding: 0; max-width: none; }
}

/* ============================================================
   Login
   ============================================================ */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--s-6);
  padding-top: calc(var(--s-6) + var(--safe-t));
  padding-bottom: calc(var(--s-6) + var(--safe-b));
}
.login__card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: var(--s-8) var(--s-6);
  box-shadow: var(--shadow-2);
}
.login__mark {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: var(--t-md);
  letter-spacing: -0.03em;
  margin-bottom: var(--s-5);
}
.login__title { font-size: var(--t-lg); letter-spacing: -0.025em; margin-bottom: var(--s-1); }
.login__sub { font-size: var(--t-sm); color: var(--ink-3); margin-bottom: var(--s-6); }
.login__error {
  background: var(--risk-soft);
  color: var(--risk);
  border: 1px solid color-mix(in srgb, var(--risk) 30%, transparent);
  padding: var(--s-3);
  border-radius: var(--r-md);
  font-size: var(--t-sm);
  margin-bottom: var(--s-4);
}
.login__foot { margin-top: var(--s-5); font-size: var(--t-xs); color: var(--ink-4); text-align: center; line-height: 1.5; }
