:root {
  --ink: #1f3044;          /* headings and main text */
  --ink-2: #4a5866;        /* secondary text */
  --ink-3: #7c8794;        /* muted text, table headers */
  --bg: #e9edf0;           /* page background */
  --paper: #ffffff;
  --paper-2: #f5f7f9;
  --line: #dde3e8;
  --nav: #16304a;          /* top bar and side menu */
  --money: #23a14a;        /* prices and totals */
  --kraft: #a86b26;
  --kraft-soft: #f6ead9;
  --open: #2563b0;
  --open-soft: #e3edf9;
  --issue: #c0392b;
  --issue-soft: #fbe5e2;
  --muted: #7c8794;
  --bar: #a7b8ca;
  --bar-now: #16304a;
  --tab-h: 58px;
  --side-w: 232px;
  --top-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6edf4; --ink-2: #b6c2ce; --ink-3: #8e9cab;
    --bg: #0f1923; --paper: #18242f; --paper-2: #1e2c39; --line: #2b3a48; --nav: #0b141c;
    --money: #4cc777; --kraft: #e0a35c; --kraft-soft: #3a2c1c;
    --open: #7fb0e6; --open-soft: #1c3150; --issue: #f08b80; --issue-soft: #43201d; --muted: #8e9cab;
    --bar: #3d5674; --bar-now: #9cc1ea;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #e6edf4; --ink-2: #b6c2ce; --ink-3: #8e9cab;
  --bg: #0f1923; --paper: #18242f; --paper-2: #1e2c39; --line: #2b3a48; --nav: #0b141c;
  --money: #4cc777; --kraft: #e0a35c; --kraft-soft: #3a2c1c;
  --open: #7fb0e6; --open-soft: #1c3150; --issue: #f08b80; --issue-soft: #43201d; --muted: #8e9cab;
  --bar: #3d5674; --bar-now: #9cc1ea;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--open); outline-offset: 2px; border-radius: 6px; }
.money { color: var(--money); font-weight: 700; }
.amt, .money, .facts b, .dtable td, .bar-tip, .month .amt { font-variant-numeric: tabular-nums; }

/* ---------- Top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--nav); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 10px; min-height: var(--top-h);
}
.top h1 { flex: 1; min-width: 0; margin: 0; font-size: 17px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { background: none; border: 0; padding: 6px 8px 6px 0; margin: -6px 0; cursor: pointer; display: none; align-items: center; gap: 4px; font-size: 16px; color: inherit; }
.back.show { display: inline-flex; }
.sync { flex: none; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.12); white-space: nowrap; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: #7fd39f; display: inline-block; }
.sync[data-state="updating"] i { background: #ffd27a; animation: pulse 1s ease-in-out infinite; }
.sync[data-state="offline"] i { background: #ff9b8f; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Page ---------- */
main { padding: 0 0 calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); max-width: 680px; margin: 0 auto; }
.section { padding: 20px 16px 4px; min-width: 0; }
.section > h2 { font-size: 18px; font-weight: 700; margin: 0 0 10px; color: var(--ink); display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.section > h2 a { font-size: 15px; font-weight: 600; color: var(--open); white-space: nowrap; }
.empty { color: var(--ink-3); font-size: 15px; padding: 12px 0; margin: 0; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr); }

/* Month headline on Today */
.month { padding: 18px 16px 6px; }
.month .label { font-size: 15px; color: var(--ink-2); }
.month .amt { font-size: 34px; font-weight: 750; letter-spacing: -.5px; margin: 2px 0; color: var(--money); }
.month .vs { font-size: 15px; color: var(--ink-2); }
.up { color: var(--money); font-weight: 600; } .down { color: var(--issue); font-weight: 600; }

/* Monthly bars (single series) */
.bars { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; align-items: end; height: 110px; margin-top: 14px; }
.bars button { all: unset; height: 100%; display: flex; align-items: flex-end; cursor: pointer; }
.bars span { display: block; width: 100%; background: var(--bar); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .now span { background: var(--bar-now); }
.bars button:focus-visible span, .bars button.sel span { outline: 2px solid var(--money); outline-offset: 1px; }
.bar-axis { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; font-size: 11px; color: var(--ink-3); text-align: center; margin-top: 4px; }
.bar-tip { min-height: 20px; font-size: 14px; color: var(--ink-2); margin-top: 6px; }

/* ---------- Rows ---------- */
.rows { background: var(--paper); border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; gap: 0 12px; align-items: center; padding: 12px 14px 12px 0; border-bottom: 1px solid var(--line); min-height: 64px; cursor: pointer; background: var(--paper); }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--paper-2); }
.row .rail { align-self: stretch; border-radius: 0 3px 3px 0; background: var(--line); margin: -12px 0; }
.row .t { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--ink-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .r { text-align: right; }
.row .amt { font-weight: 700; color: var(--money); }
.row .amt.plain-amt { color: var(--ink); }
.row.plain { grid-template-columns: minmax(0, 1fr) auto; padding-left: 14px; }
.rail.open { background: var(--open); } .rail.delivered { background: var(--money); }
.rail.issue { background: var(--issue); } .rail.preorder { background: var(--kraft); } .rail.cancelled { background: var(--muted); }

/* Badges: small solid labels */
.st, .badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 4px; margin-top: 4px; white-space: nowrap; color: #fff; line-height: 1.3; vertical-align: middle; }
.st.delivered, .badge.good { background: var(--money); }
.st.open, .badge.info { background: var(--open); }
.st.issue, .badge.bad { background: var(--issue); }
.st.preorder, .badge.warn { background: var(--kraft); }
.st.cancelled, .badge.muted { background: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .st, :root:not([data-theme="light"]) .badge { color: #0f1923; } }
:root[data-theme="dark"] .st, :root[data-theme="dark"] .badge { color: #0f1923; }
.tag { font-size: 11px; font-weight: 700; color: var(--kraft); border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 1px; }

.day-h { font-size: 14px; font-weight: 700; color: var(--ink-2); padding: 16px 16px 6px; }
.group { margin: 0 16px; }

/* ---------- Data tables (like the diagnostic report) ---------- */
.table-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.dtable { width: 100%; border-collapse: collapse; font-size: 15px; }
.dtable th { text-align: left; font-weight: 650; color: var(--ink-3); padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: bottom; }
.dtable td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: top; }
.dtable tr:first-child td { border-top: 0; }
.dtable th + th, .dtable td + td { border-left: 1px solid var(--line); }
.dtable .num { text-align: right; white-space: nowrap; }
.dtable td small { display: block; color: var(--ink-3); font-size: 13px; }
.dtable tr.short td { background: var(--issue-soft); }
.dtable tr.cleared td { color: var(--ink-3); }
.dtable .short-n { color: var(--issue); font-weight: 700; }
.dtable tfoot td { font-weight: 700; border-top: 1px solid var(--line); }

/* ---------- Detail cards (like "Confirmed Fix and Cost Estimates") ---------- */
.fix { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 16px 18px 18px; }
.fix + .fix { margin-top: 14px; }
.fix-h { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.fix-h h3 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.3; }
.fix-h .badge { margin-top: 0; }
.fix-b { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px 28px; padding-top: 12px; }
.fix-b p { margin: 0 0 8px; font-size: 15px; }
.fix-b p b { font-weight: 700; }
.fix-b ol { margin: 4px 0 0; padding-left: 20px; font-size: 15px; }
.fix-b ol li { margin-bottom: 4px; }
.fix-b ol li.warn { color: var(--issue); font-weight: 600; }
.fix-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.fix-actions .btn { padding: 9px 14px; font-size: 15px; }
.fix.done { opacity: .72; }
a.fix { display: block; }
a.fix:hover { border-color: var(--bar); }

/* Facts strip */
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 0 16px; }
.facts div { background: var(--paper); padding: 10px 12px; min-width: 0; }
.facts span { display: block; font-size: 13px; color: var(--ink-3); }
.facts b { font-size: 17px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.head { padding: 18px 16px 14px; }
.head h2 { margin: 0; font-size: 24px; line-height: 1.2; }
.head p { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.cat-h { font-size: 15px; font-weight: 700; color: var(--ink); padding: 18px 16px 8px; }
.meter { height: 4px; background: var(--paper-2); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--bar); border-radius: 2px; }

/* Search + filters */
.tools { position: sticky; top: calc(env(safe-area-inset-top) + var(--top-h)); z-index: 10; background: var(--bg); padding: 10px 16px 6px; }
.search { width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 10px 12px; font-size: 16px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--paper); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--nav); border-color: var(--nav); color: #fff; }

/* Skeleton */
.sk { height: 64px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, var(--paper) 30%, var(--paper-2) 50%, var(--paper) 70%); background-size: 300% 100%; animation: sk 1.1s linear infinite; }
@keyframes sk { from { background-position: 100% 0; } to { background-position: 0 0; } }
.sk-block { height: 130px; margin: 18px 16px; border-radius: 8px; }

/* Buttons */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 16px 0; }
.btn { border: 0; border-radius: 8px; padding: 13px 14px; font-size: 16px; font-weight: 650; cursor: pointer; background: var(--nav); color: #fff; text-align: center; }
.btn.ghost { background: var(--paper); color: var(--ink); border: 1px solid var(--line); }
.btn.go { background: var(--money); color: #fff; }
.btn.full { grid-column: 1 / -1; }
.btn[disabled] { opacity: .5; }
.more { display: block; width: calc(100% - 32px); margin: 12px 16px; }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 4px 0 0; }
.timeline li { display: grid; grid-template-columns: 14px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 16px; bottom: 0; width: 2px; background: var(--line); }
.timeline li:last-child::before { display: none; }
.timeline .dot { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--bg); background: var(--ink-3); margin-top: 3px; box-shadow: 0 0 0 1px var(--line); }
.timeline .delivered .dot { background: var(--money); }
.timeline .short .dot { background: var(--issue); }
.timeline .preorder .dot, .timeline .promo .dot { background: var(--kraft); }
.timeline .note .dot { background: var(--open); }
.timeline .when { font-size: 13px; color: var(--ink-3); }

.foot { font-size: 13px; color: var(--ink-3); padding: 18px 16px 0; line-height: 1.5; margin: 0; }

/* ---------- Navigation: bottom tabs on phones ---------- */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs .brand { display: none; }
.tabs a { display: flex; flex-direction: column; align-items: center; gap: 2px; height: var(--tab-h); justify-content: center; font-size: 11px; color: var(--ink-3); }
.tabs a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.tabs svg { width: 24px; height: 24px; flex: none; }

/* Sheet + toast */
.sheet-bg { position: fixed; inset: 0; background: rgba(10,20,30,.45); z-index: 40; display: none; }
.sheet-bg.show { display: block; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--paper); border-radius: 14px 14px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .2s ease; max-width: 560px; margin: 0 auto; }
.sheet.show { transform: none; }
.sheet h3 { margin: 0 0 10px; font-size: 18px; }
.sheet textarea { width: 100%; min-height: 96px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--paper-2); font-size: 16px; resize: vertical; }
.sheet .actions { margin: 12px 0 0; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 10px); background: var(--nav); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; max-width: calc(100% - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Small phones (iPhone SE, mini) ---------- */
@media (max-width: 374px) {
  .section, .head, .month, .tools { padding-left: 12px; padding-right: 12px; }
  .group, .facts { margin-left: 12px; margin-right: 12px; }
  .facts b { font-size: 15px; }
  .dtable { font-size: 14px; }
  .dtable th, .dtable td { padding: 10px; }
  .tabs a { font-size: 10px; }
  .month .amt { font-size: 30px; }
}

/* ---------- Wider phones / small tablets: repair card goes two-column ---------- */
@media (min-width: 560px) {
  .fix-b { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

/* ---------- iPad and laptop: side menu, wider content ---------- */
@media (min-width: 768px) {
  .tabs {
    top: 0; right: auto; width: var(--side-w); bottom: 0;
    display: flex; flex-direction: column; gap: 2px;
    background: var(--nav); border-top: 0; padding: calc(env(safe-area-inset-top) + 14px) 12px 16px;
  }
  .tabs .brand { display: block; color: #fff; font-weight: 750; font-size: 18px; padding: 4px 12px 16px; }
  .tabs .brand small { display: block; font-weight: 500; font-size: 12px; opacity: .7; }
  .tabs a { flex-direction: row; justify-content: flex-start; gap: 12px; height: 46px; padding: 0 12px; border-radius: 8px; font-size: 15px; color: rgba(255,255,255,.75); }
  .tabs a:hover { background: rgba(255,255,255,.08); color: #fff; }
  .tabs a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; }
  .tabs svg { width: 22px; height: 22px; }
  .top { margin-left: var(--side-w); padding-left: 24px; padding-right: 24px; background: var(--bg); color: var(--ink); border-bottom: 1px solid var(--line); }
  .top h1 { font-size: 20px; }
  .sync { background: var(--paper); border: 1px solid var(--line); }
  main { margin-left: var(--side-w); max-width: none; padding: 4px 16px 40px; }
  main > * { max-width: 1180px; margin-left: auto; margin-right: auto; }
  .tools { top: var(--top-h); }
  .toast { bottom: 24px; left: calc(50% + var(--side-w) / 2); }
  .sheet { bottom: auto; top: 50%; left: calc(var(--side-w) + 24px); right: 24px; border-radius: 12px; transform: translateY(-40%); opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; }
  .sheet.show { transform: translateY(-50%); opacity: 1; pointer-events: auto; }
  .facts b { font-size: 20px; }
  .month .amt { font-size: 40px; }
  .bars { height: 150px; }
  .day-h { padding-top: 20px; }
}
@media (min-width: 768px) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .top { color: var(--ink); }
}

/* iPad landscape (1024px+) and laptop: two columns where it helps */
@media (min-width: 1024px) {
  .grid2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 8px; align-items: start; }
  .grid2 > .wide { grid-column: 1 / -1; }
}
.sheet:not(.show) { visibility: hidden; }
.short-label { display: none; }
@media (max-width: 559px) {
  .long-label { display: none; }
  .short-label { display: inline; }
}

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

/* Lists read better at a comfortable width on iPad and laptop */
@media (min-width: 768px) {
  main > .narrow, main > div > .narrow, .narrow { max-width: 880px; margin-left: auto; margin-right: auto; }
}
@media (min-width: 768px) {
  main > .facts { width: calc(100% - 32px); max-width: 1148px; margin-left: auto; margin-right: auto; }
}
