/* Card Tracker: plain CSS, light + dark, container queries for phone / foldable / desktop. */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #edf1f7;
  --text: #1a1f2b;
  --muted: #5d6678;
  --line: #dbe1ea;
  --accent: #2459c2;
  --accent-ink: #ffffff;
  --accent-soft: #e0e9fb;
  --warn: #a35a00;
  --warn-soft: #fbecd6;
  --danger: #b3261e;
  --danger-soft: #f9dedc;
  --good: #1e7a4f;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 14px rgb(0 0 0 / 6%);
  --nav-h: 64px;
  color-scheme: light dark;
}
/* Dark = AMOLED (true black). Applies when chosen in Appearance, or when the device is in dark mode
   and the user hasn't picked Light. */
:root[data-theme="dark"] {
    --bg: #000000;
    --surface: #0b0d11;
    --surface-2: #151922;
    --text: #e8ecf3;
    --muted: #9aa3b5;
    --line: #252b37;
    --accent: #7aa7ff;
    --accent-ink: #061636;
    --accent-soft: #14213b;
    --warn: #f0b05a;
    --warn-soft: #2e2210;
    --danger: #f2a39d;
    --danger-soft: #331816;
    --good: #5fcf98;
    --shadow: none;
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --surface: #0b0d11;
    --surface-2: #151922;
    --text: #e8ecf3;
    --muted: #9aa3b5;
    --line: #252b37;
    --accent: #7aa7ff;
    --accent-ink: #061636;
    --accent-soft: #14213b;
    --warn: #f0b05a;
    --warn-soft: #2e2210;
    --danger: #f2a39d;
    --danger-soft: #331816;
    --good: #5fcf98;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }
.boot { padding: 2rem; color: var(--muted); }

/* ---- app frame ------------------------------------------------------------------------------- */
.app { container: app / inline-size; min-height: 100%; overflow-x: clip; }   /* clip, not hidden: keeps sticky working */
.frame {
  /* App shell on phones: exactly the visible height (dvh follows browser toolbars sliding in/out), only
     <main> scrolls, and the nav is an ordinary item at the bottom: no position:fixed, which Firefox
     mispositions while its toolbar is showing. */
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
}
.main {
  container: main / inline-size;
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain;
  padding: 12px 14px 24px;
  width: 100%;          /* needed: as a grid item with auto margins + inline-size containment it would shrink to 0 */
  max-width: 1200px;
  margin: 0 auto;
}
.nav {
  order: 2; flex: none; position: relative; z-index: 20;
  display: flex; justify-content: space-around;
  height: var(--nav-h);
  background: var(--surface); border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .78rem;
}
.nav a .ico { font-size: 1.25rem; line-height: 1; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav .brand { display: none; }

@container app (min-width: 900px) {
  /* wide screens: the page scrolls normally, nav is a sticky side rail */
  .frame { display: grid; grid-template-columns: 220px 1fr; height: auto; min-height: 100vh; }
  .main { overflow: visible; min-height: auto; }
  .nav {
    order: 0; inset: auto; position: sticky; top: 0; height: 100vh; flex-direction: column; justify-content: flex-start;
    gap: 4px; padding: 18px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; }
  .nav .brand img { width: 28px; height: 28px; border-radius: 7px; }
  .nav a { flex: 0; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 12px;
           border-radius: 10px; font-size: .95rem; }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .main { padding: 22px 28px 40px; }
}

/* ---- header / toolbar ---------------------------------------------------------------------- */
.header { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin: 4px 0 12px; }
.sync { display: flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); }
.sync .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync.busy .dot { background: var(--warn); animation: pulse 1s infinite alternate; }
.sync.bad .dot { background: var(--danger); }
@keyframes pulse { to { opacity: .3; } }

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: .88rem; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .count { opacity: .75; margin-left: 4px; }

/* ---- lists ----------------------------------------------------------------------------------- */
.group-title { margin: 16px 2px 6px; font-size: .78rem; font-weight: 700; letter-spacing: .04em;
               text-transform: uppercase; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.row {
  width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px;
  padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; box-shadow: var(--shadow);
}
.row[aria-current="true"] { outline: 2px solid var(--accent); outline-offset: -1px; }
.row .title { font-weight: 600; display: flex; gap: 6px; align-items: center; min-width: 0; }
.row .title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { grid-column: 1; font-size: .83rem; color: var(--muted); white-space: nowrap; overflow: hidden;
            text-overflow: ellipsis; }
.row .amount { text-align: right; font-weight: 600; }
.row .when { text-align: right; font-size: .83rem; }
.row .bar { grid-column: 1 / -1; }
.row.dim { opacity: .62; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: .72rem; font-weight: 700;
         background: var(--surface-2); color: var(--muted); }
.badge.new { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }

.bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; }
.bar.over > i { background: var(--warn); }

.empty { padding: 32px 12px; text-align: center; color: var(--muted); }

/* ---- split view: list + detail -------------------------------------------------------------- */
.split { display: block; }
.detail-wrap { position: fixed; inset: 0; z-index: 30; display: none; }
.detail-wrap.open { display: block; }
.backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 35%); }
.detail {
  position: absolute; inset: auto 0 0 0; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 30px rgb(0 0 0 / 20%);
}
.detail .close { position: sticky; top: 0; float: right; }
@container main (min-width: 760px) {
  .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); gap: 20px; align-items: start; }
  .detail-wrap { inset: auto; position: sticky; top: 16px; display: block; z-index: auto; }  /* inset before top: it resets top */
  .detail-wrap .backdrop { display: none; }
  .detail { position: static; max-height: calc(100vh - 32px); border-radius: var(--radius); box-shadow: var(--shadow);
            background: var(--surface); border: 1px solid var(--line); }
  .detail .close { display: none; }
  .detail-placeholder { display: block; }
}
.detail-placeholder { display: none; padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---- detail content ------------------------------------------------------------------------- */
.section { margin-top: 16px; }
.section > h3 { margin-bottom: 8px; }
.section > h2 { margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat .label { font-size: .75rem; color: var(--muted); }
.stat .value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.uses { display: flex; flex-direction: column; gap: 6px; }
.use { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 10px; }
.use .grow { flex: 1; min-width: 0; }

form.inline, .inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > input, .inline > select { flex: 1 1 160px; width: auto; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); flex: 1; min-width: 110px; }
/* inputs inside a labelled .field must not inherit the label's smaller font (that made them shorter) */
.field input, .field select { font-size: 15px; color: var(--text); }
/* one control height everywhere so inputs, date pickers, selects and buttons line up */
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="search"], select {
  height: 42px;         /* exact: Chrome's date control is otherwise a little taller than text fields */
}
.btn:not(.small) { min-height: 42px; }
/* rows mixing labelled fields with buttons/inputs: line everything up on the input baseline, not the label */
.inline:has(> .field) { align-items: flex-end; }
/* date pickers need room for "11/30/2026" plus the calendar icon */
.field:has(input[type="date"]) { flex: 1 1 165px; min-width: 165px; }
input[type="date"] { min-width: 165px; }
input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="search"], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  color: var(--text);
}
input:focus-visible, select:focus-visible, button:focus-visible, .row:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 10px; cursor: pointer;
  font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0;
          border-top: 1px solid var(--line); }
.toggle:first-child { border-top: 0; }
.toggle input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

/* ---- reports -------------------------------------------------------------------------------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 8px 0 16px; }
@container main (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.report-card { padding: 14px; }
.report-card summary { list-style: none; cursor: pointer; }
.report-card summary::-webkit-details-marker { display: none; }
.report-head { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .88rem; }
.table th, .table td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-weight: 600; font-size: .78rem; }
.pos { color: var(--good); }
.neg { color: var(--danger); }

/* ---- offers --------------------------------------------------------------------------------- */
.offer { padding: 12px 14px; }
.offer .top { display: flex; justify-content: space-between; gap: 10px; }
.offer ul { margin: 6px 0 0; padding: 0; list-style: none; font-size: .85rem; color: var(--muted); }

/* ---- sign-in -------------------------------------------------------------------------------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin .card { padding: 28px; max-width: 360px; width: 100%; text-align: center; }
.signin img { width: 64px; height: 64px; border-radius: 16px; }
.signin p { color: var(--muted); }

/* ---- toast ---------------------------------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); color: #fff; }

/* ---- "shared with household" marker ------------------------------------------------------- */
.shared {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; margin-left: 6px; padding: 0; vertical-align: middle;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: help;
}
.shared:hover, .shared.open { color: var(--accent); background: var(--accent-soft); }
.shared .tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  width: max-content; max-width: 220px; padding: 6px 10px; border-radius: 8px;
  background: var(--text); color: var(--bg); font-size: .78rem; font-weight: 500; line-height: 1.3;
  display: none; pointer-events: none; z-index: 40; white-space: normal; text-align: center;
}
/* hidden tooltips take no space (an invisible one near the right edge made the page scroll sideways) */
.shared:hover .tip, .shared:focus-visible .tip, .shared.open .tip { display: block; }
/* icons near the right edge open their tooltip leftwards */
.inline > .shared:last-child .tip { left: auto; right: 0; transform: none; }

/* ---- pull to refresh (phones) ---------------------------------------------------------------- */
.ptr {
  height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .85rem; transition: height .18s ease;
}
.ptr.dragging { transition: none; }

/* series history: periods are tappable to edit */
.period-card { cursor: pointer; }
.period-card[aria-current="true"] { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---- person filter (icon button + menu) ------------------------------------------------------ */
.header-tools { display: flex; align-items: center; gap: 6px; }
.person-filter { position: relative; }
.person-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); cursor: pointer;
}
.person-btn.filtered { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.person-btn .initials {
  position: absolute; right: -4px; bottom: -4px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: var(--accent-ink);
  font-size: .66rem; font-weight: 700; line-height: 18px; text-align: center;
}
.person-filter .menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); z-index: 45; min-width: 200px;
  padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
}
.person-filter.open .menu { display: block; }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer; font-size: .92rem;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); }
.menu-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); color: var(--muted);
  font-size: .72rem; font-weight: 700;
}
.menu-item[aria-checked="true"] .menu-badge { background: var(--accent); color: var(--accent-ink); }
.menu-item .check { margin-left: auto; color: var(--accent); font-weight: 700; }

/* reports: step through periods */
.period-step { display: flex; align-items: center; gap: 8px; margin: 2px 0 6px; }
.period-step .btn.small { min-width: 36px; font-size: 1.05rem; line-height: 1; }
.period-label { min-width: 130px; text-align: center; font-weight: 600; }
.invisible { visibility: hidden; }   /* hidden but keeps its space */
