/* Ops — the one stylesheet, written in the Eclipse design language (DESIGN.md).
   Every value here transcribes that reference into plain CSS:
     - one electric-cyan accent #00D4E1, used sparingly (active nav, focus,
       primary CTAs, highlights) — never as a chart series color
     - explicit Tailwind-gray neutrals with a dark twin for every color;
       dark follows the system by default, or is pinned by the sidebar toggle
       (settings.theme -> <html data-theme>); see the note above the dark blocks
     - borders for depth, not shadows; rounded-xl panels; rounded-full pills
     - Cobane, vendored in /public/vendor/fonts/cobane/ (BR Cobane, converted
       from the Website repo's originals) — mono + tabular-nums for numerics
     - emerald ping-dots for live state; red-500 destructive; yellow warning
     - no ambient animation in data views: transitions 100–300ms, spinners only */

@font-face {
  font-family: 'Cobane'; font-style: normal; font-weight: 400;
  font-display: swap; src: url('/vendor/fonts/cobane/Cobane-Regular.woff2') format('woff2');
}
@font-face {
  font-family: 'Cobane'; font-style: normal; font-weight: 500;
  font-display: swap; src: url('/vendor/fonts/cobane/Cobane-Medium.woff2') format('woff2');
}
@font-face {
  font-family: 'Cobane'; font-style: normal; font-weight: 600;
  font-display: swap; src: url('/vendor/fonts/cobane/Cobane-SemiBold.woff2') format('woff2');
}
@font-face {
  font-family: 'Cobane'; font-style: normal; font-weight: 700;
  font-display: swap; src: url('/vendor/fonts/cobane/Cobane-Bold.woff2') format('woff2');
}

:root {
  color-scheme: light;                /* native chrome (scrollbars, selects) follows the theme */
  --bg: #ffffff;                      /* dashboard canvas is white — borders carry the depth */
  --sidebar: #ffffff;                 /* sidebar rail */
  --surface: #ffffff;                 /* card / panel */
  --surface-2: #f9fafb;               /* gray-50: thead, inset rows, hovers */
  --border: #e5e7eb;                  /* gray-200 */
  --border-soft: #f3f4f6;             /* gray-100 row rules */
  --ink: #111827;                     /* gray-900 primary text */
  --text-2: #4b5563;                  /* gray-600 secondary */
  --muted: #6b7280;                   /* gray-500 */
  --faint: #9ca3af;                   /* gray-400 muted/labels */
  --brand: #00D4E1;
  --brand-hover: #00bfc9;
  --brand-10: rgba(0, 212, 225, .10);
  --brand-08: rgba(0, 212, 225, .08);
  --brand-20: rgba(0, 212, 225, .20);
  --brand-30: rgba(0, 212, 225, .30);
  --on-brand: #000000;                /* text on solid brand: black in light */
  --flash-pos: #047857;                /* emerald-700: AA on the emerald-50 wash */
  --flash-neg: #b91c1c;                /* red-700 */
  --pos: #059669;                     /* emerald-600 */
  --pos-bg: #ecfdf5;                  /* emerald-50 */
  --pos-dot: #10b981;                 /* emerald-500 */
  --neg: #dc2626;                     /* red-600 text */
  --neg-bg: #fef2f2;
  --warn-bg: #fefce8;
  --warn-border: #fde68a;
  --warn-ink: #a16207;
  --row-hover: #f9fafb;
  --pill: #f3f4f6;                    /* gray-100 neutral pill/badge bg */
  /* Data-viz palette (DESIGN.md §2.4) — brand cyan is never a series color */
  --chart-accent: #2a78d6;
  --chart-s2: #eb6834;
  --chart-s3: #1baf7a;
  --chart-s4: #eda100;
  --chart-s5: #e87ba4;
  --chart-other: #9ca3af;
  --chart-neg: #ef4444;
  --chart-grid: #f3f4f6;
  --chart-axis: #e5e7eb;
  --chart-surface: #ffffff;
  --tooltip-bg: #111827;              /* gray-900: sits on the white canvas */
  --tooltip-ink: #ffffff;
  --r-md: 6px;                        /* buttons, inputs */
  --r-lg: 8px;                        /* table wrappers */
  --r-xl: 12px;                       /* panels */
  --t: 150ms ease;
  --sans: 'Cobane', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark is applied from two places, and the token list below must stay identical
   in both: the system preference (unless the operator has explicitly forced
   light), and an explicit choice stored in settings.theme and rendered onto
   <html data-theme>. Server-rendered, so there is no flash and no client state. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111827;                    /* gray-900 */
    --sidebar: #111827;               /* sidebar shares the canvas in dark */
    --surface: #1f2937;               /* gray-800 */
    --surface-2: rgba(17, 24, 39, .4);
    --border: #374151;                /* gray-700 */
    --border-soft: rgba(55, 65, 81, .6);
    --ink: #ffffff;
    --text-2: #d1d5db;                /* gray-300 */
    --muted: #9ca3af;                 /* gray-400 */
    --faint: #6b7280;                 /* gray-500 */
    --on-brand: #ffffff;              /* text on solid brand: white in dark */
    --flash-pos: #34d399;              /* emerald-400 reads on the dark wash */
    --flash-neg: #f87171;
    --pos: #34d399;                   /* emerald-400 */
    --pos-bg: rgba(16, 185, 129, .1);
    --neg: #f87171;                   /* red-400 */
    --neg-bg: rgba(239, 68, 68, .1);
    --warn-bg: rgba(234, 179, 8, .1);
    --warn-border: rgba(234, 179, 8, .25);
    --warn-ink: #facc15;
    --row-hover: rgba(55, 65, 81, .3);
    --pill: #374151;                  /* gray-700 */
    --chart-accent: #3987e5;
    --chart-s2: #d95926;
    --chart-neg: #f87171;
    --chart-grid: #374151;
    --chart-axis: #374151;
    --chart-surface: #1f2937;
    --tooltip-bg: #374151;            /* gray-700: lifts off the gray-900 canvas */
    --tooltip-ink: #ffffff;
  }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #111827;                    /* gray-900 */
    --sidebar: #111827;               /* sidebar shares the canvas in dark */
    --surface: #1f2937;               /* gray-800 */
    --surface-2: rgba(17, 24, 39, .4);
    --border: #374151;                /* gray-700 */
    --border-soft: rgba(55, 65, 81, .6);
    --ink: #ffffff;
    --text-2: #d1d5db;                /* gray-300 */
    --muted: #9ca3af;                 /* gray-400 */
    --faint: #6b7280;                 /* gray-500 */
    --on-brand: #ffffff;              /* text on solid brand: white in dark */
    --flash-pos: #34d399;              /* emerald-400 reads on the dark wash */
    --flash-neg: #f87171;
    --pos: #34d399;                   /* emerald-400 */
    --pos-bg: rgba(16, 185, 129, .1);
    --neg: #f87171;                   /* red-400 */
    --neg-bg: rgba(239, 68, 68, .1);
    --warn-bg: rgba(234, 179, 8, .1);
    --warn-border: rgba(234, 179, 8, .25);
    --warn-ink: #facc15;
    --row-hover: rgba(55, 65, 81, .3);
    --pill: #374151;                  /* gray-700 */
    --chart-accent: #3987e5;
    --chart-s2: #d95926;
    --chart-neg: #f87171;
    --chart-grid: #374151;
    --chart-axis: #374151;
    --chart-surface: #1f2937;
    --tooltip-bg: #374151;            /* gray-700: lifts off the gray-900 canvas */
    --tooltip-ink: #ffffff;
  }


* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.55 var(--sans);
  letter-spacing: -0.1px;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 18px; font-weight: 600; letter-spacing: -.025em; margin: 0; }
h2 { font-size: 14px; font-weight: 600; margin: 0; }
h3 { font-size: 12px; font-weight: 600; color: var(--muted); margin: 20px 0 10px; }
a { color: var(--ink); text-decoration: none; }
code {
  font-family: var(--mono); font-size: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px;
}

.num { font-family: inherit; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.link { font-size: 13px; color: var(--text-2); transition: color var(--t); }
.link:hover { color: var(--ink); }

/* --- shell: sidebar + content ------------------------------------------------ */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px; flex: none;
  position: sticky; top: 0; height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-card { height: 100%; display: flex; flex-direction: column; padding: 0 12px 16px; }
.brand {
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 10px;
  font-size: 15px; font-weight: 600; letter-spacing: -.01em; color: var(--ink);
}
.brand::before {
  content: ''; width: 8px; height: 8px; border-radius: 2px;
  background: var(--brand); flex: none;
}
.brand-sub { font-size: 11px; color: var(--faint); padding: 0 10px 14px; margin-top: -8px; }

.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; margin-bottom: 2px;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 500; color: var(--text-2);
  transition: color 100ms ease, background 100ms ease;
}
.nav a .nav-ic { display: inline-flex; width: 15px; height: 15px; color: var(--faint); transition: color 100ms ease; }
.nav a .nav-ic svg { width: 100%; height: 100%; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a.active { color: var(--ink); background: var(--brand-10); }
.nav a.active .nav-ic { color: var(--brand); }
.nav-sep { height: 1px; background: var(--border); margin: 10px 4px; }

.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--border); }
.sync-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.sync-note { font-size: 11px; color: var(--faint); }
.updated { margin-top: 12px; }

.content {
  flex: 1; min-width: 0;
  max-width: 1200px;
  padding: 20px 20px 64px;
  margin: 0 auto;
}
@media (min-width: 640px) { .content { padding: 24px 28px 72px; } }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar-card { flex-direction: row; align-items: center; gap: 6px; padding: 8px 14px; }
  .brand { height: auto; padding: 0 8px 0 0; }
  .brand-sub { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav a { margin-bottom: 0; padding: 6px 10px; }
  .nav-sep { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; border-top: none; padding: 0; display: flex; align-items: center; gap: 12px; }
  .updated { display: none; }
}

/* --- banners & pills ---------------------------------------------------------- */

.banner {
  margin: 0 0 16px; padding: 9px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg);
  font-size: 13px; color: var(--text-2);
}
.banner-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-ink); }
.banner-muted { color: var(--muted); }
.banner-ok { background: var(--pos-bg); border-color: transparent; color: var(--flash-pos); }
.banner-error { background: var(--neg-bg); border-color: transparent; color: var(--flash-neg); }

/* Pills: rounded-full, 11px medium */
.chip {
  display: inline-flex; align-items: center; vertical-align: 1px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500; letter-spacing: 0;
  background: var(--pill); color: var(--text-2);
}
.chip-dim { background: var(--pill); color: var(--muted); }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 1px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
}
/* Live state: emerald pill with the ping-dot idiom */
.badge-ok { background: var(--pos-bg); color: var(--pos); }
.badge-ok::before {
  content: ''; width: 6px; height: 6px; border-radius: 999px; flex: none;
  background: var(--pos-dot);
  box-shadow: 0 0 0 0 rgba(52, 211, 153, .6);
  animation: ping 1.8s cubic-bezier(0, 0, 0.2, 1) infinite;
}
.badge-amber { background: var(--warn-bg); color: var(--warn-ink); }
.badge-dim { background: var(--pill); color: var(--text-2); }
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(52, 211, 153, .5); }
  70% { box-shadow: 0 0 0 5px rgba(52, 211, 153, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); }
}
@media (prefers-reduced-motion: reduce) { .badge-ok::before { animation: none; } }

/* --- panels & layout ----------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 20px; margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 16px; flex-wrap: wrap;
}

.section-head { margin: 26px 0 12px; }
.section-head h2 { font-size: 15px; font-weight: 600; }
.section-sub { margin: 3px 0 0; font-size: 13px; color: var(--muted); max-width: 74ch; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.empty { color: var(--faint); font-size: 14px; text-align: center; padding: 12px 0; margin: 6px 0; }
.footnote { color: var(--faint); font-size: 12px; margin: 16px 0 0; }
.form-intro { font-size: 12.5px; margin: -4px 0 14px; }

/* --- KPI cards ------------------------------------------------------------------ */

.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: 1fr 1fr; } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-xl); margin: 0; padding: 16px 18px 14px;
}
.kpi-label { font-size: 12px; font-weight: 500; color: var(--muted); }
.kpi-value {
  font-size: 24px; font-weight: 600; letter-spacing: -.02em; line-height: 1.3;
  margin-top: 3px; font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }

/* --- filter row (Overview date range) ---------------------------------------- */

.filter-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.filter-row select, .filter-row input[type="date"],
.filter-row input[type="month"], .filter-row input[type="search"] {
  width: auto; margin-top: 0; height: 32px; padding: 0 10px;
  font-size: 13px; background: transparent;
}
.filter-row select { min-width: 140px; max-width: 220px; }
.filter-row input[type="date"] { width: 152px; }
.filter-dash { color: var(--faint); }
.filter-note { font-size: 11px; color: var(--faint); margin-left: 4px; white-space: nowrap; }

/* Chart-local controls (top-right of chart cards) */
.chart-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.check {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 12px var(--sans); color: var(--muted); cursor: pointer;
  text-transform: none; letter-spacing: 0;
}
.check input { width: auto; margin: 0; accent-color: var(--brand); }
.chart-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--faint); font-size: 14px;
}

/* Top customers */
.rank-col { width: 34px; }
.cust-email { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cust-last { font-size: 12px; color: var(--faint); }

/* --- chart panels ---------------------------------------------------------------- */

.chart-card { padding: 18px 20px 14px; }
.chart-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.chart-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chart-icon { display: inline-flex; width: 16px; height: 16px; color: var(--faint); }
.chart-icon svg { width: 100%; height: 100%; }
.chart-sub { font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 66ch; }
.chart-box { position: relative; margin-top: 14px; }
.chart-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .chart-pair { grid-template-columns: 1fr; } }
.chart-pair .chart-card { margin-bottom: 16px; }

.legend {
  display: flex; gap: 6px 12px; flex-wrap: wrap; justify-content: flex-end;
  font-size: 11px; color: var(--muted); white-space: nowrap; padding-top: 3px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.pdot-0 { background: var(--chart-accent); }
.pdot-1 { background: var(--chart-s2); }
.pdot-2 { background: var(--chart-s3); }
.pdot-3 { background: var(--chart-s4); }
.pdot-4 { background: var(--chart-s5); }
.pdot-5 { background: var(--chart-other); }
/* net-credit legend rows: hollow dot — the donut draws spend only */
.dot-credit { background: transparent; box-shadow: inset 0 0 0 1.5px var(--pos-dot); }

/* Chart.js responsive canvases MUST live in a fixed-height positioned box,
   or the resize observer grows them forever. .chart-box provides it. */
.spark-wrap { position: relative; height: 52px; margin-top: 8px; overflow: hidden; }
.spark-wrap canvas { max-width: 100%; }

/* --- product donut ---------------------------------------------------------------- */

.donut-row { display: flex; align-items: center; gap: 26px; margin-top: 16px; }
.donut-box { position: relative; width: 185px; height: 185px; flex: none; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; }
.donut-legend li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 2px; font-size: 13px; border-bottom: 1px solid var(--border-soft);
}
.donut-legend li:last-child { border-bottom: none; }
.donut-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-amt { font-weight: 500; font-variant-numeric: tabular-nums; }
.donut-pct { color: var(--faint); width: 40px; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) { .donut-row { flex-direction: column; align-items: stretch; } .donut-box { margin: 0 auto; } }

/* --- era toggle: underline tabs (admin tab-bar idiom) ------------------------------- */

.seg { display: inline-flex; gap: 2px; border-bottom: 1px solid var(--border); }
.seg a, .seg button {
  display: inline-block; padding: 6px 12px 8px;
  font: 500 13px var(--sans); letter-spacing: -0.1px; color: var(--faint);
  background: none; border: none; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color 100ms ease;
}
.seg a:hover, .seg button:hover { color: var(--text-2); }
.seg a.active, .seg button.active { color: var(--ink); border-bottom-color: var(--brand); }
.seg a:focus-visible, .seg button:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.seg-sm a, .seg-sm button { padding: 4px 10px 6px; font-size: 12px; }

/* --- tables ---------------------------------------------------------------------------- */

.table-wrap { border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table strong { font-weight: 500; }
.table th {
  text-align: left; padding: 8px 10px;
  font-size: 12px; font-weight: 500; color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.table th.right { text-align: right; }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border-soft); }
.table td.num, .table td .num { font-variant-numeric: tabular-nums; }
.table tbody tr { transition: background 100ms ease; }
.table tbody tr:hover { background: var(--row-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody + tfoot tr td { border-top: 1px solid var(--border); }
.table tfoot td { border-bottom: none; padding-top: 10px; font-weight: 500; }
.row-dim td { color: var(--faint); }
.row-dim .chip { opacity: .75; }
.row-error td { background: var(--neg-bg); }

/* --- tickers ------------------------------------------------------------------------------ */

.ticker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
  gap: 14px; margin-bottom: 16px;
}
.ticker { padding: 16px 18px 12px; margin-bottom: 0; }
.ticker-head { display: flex; justify-content: space-between; align-items: center; }
.ticker-name { font-weight: 600; font-size: 13px; }
.ticker-value {
  font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.ticker-meta { font-size: 11px; color: var(--faint); }

/* --- forms --------------------------------------------------------------------------------- */

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid-1 { grid-template-columns: 1fr; }
.form-grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .form-grid-4 { grid-template-columns: 1fr 1fr; } }
.span2 { grid-column: span 2; }
.form-grid-4 .span4 { grid-column: span 4; }
@media (max-width: 900px) { .form-grid-4 .span4 { grid-column: span 2; } }

label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); }
.hint { font-weight: 400; color: var(--faint); }
.hint-auto { display: block; margin-top: 3px; font-size: 12px; color: var(--pos); font-weight: 500; }

input, select, textarea {
  width: 100%; margin-top: 6px; padding: 7px 11px;
  font: 400 14px var(--sans); letter-spacing: -0.1px; color: var(--ink);
  background: transparent; border: 1px solid var(--border); border-radius: var(--r-md);
  transition: border-color var(--t), box-shadow var(--t);
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-10);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; }

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; margin: 0; }
.inline-form input { margin-top: 0; width: auto; }

.provider-row {
  display: grid; grid-template-columns: 2fr 1.4fr 1fr 1fr 1.2fr; gap: 12px;
  align-items: end;
  padding: 12px 0; border-bottom: 1px dashed var(--border);
}
.provider-row:last-child { border-bottom: none; }
@media (max-width: 1100px) { .provider-row { grid-template-columns: 1fr 1fr; } }

/* --- buttons --------------------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
  height: 36px; padding: 0 16px;
  font: 500 14px var(--sans); letter-spacing: -0.1px;
  color: var(--text-2); background: transparent;
  border: 1px solid var(--border); border-radius: var(--r-md); cursor: pointer;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
  transition: color var(--t), background var(--t), border-color var(--t);
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.btn-primary { background: var(--brand); border-color: transparent; color: var(--on-brand); font-weight: 500; box-shadow: none; }
.btn-primary:hover { background: var(--brand-hover); color: var(--on-brand); }
.btn-sm { height: 32px; padding: 0 12px; }
/* quiet inline controls: invisible until the row is engaged */
.btn-quiet { border-color: transparent; box-shadow: none; color: var(--faint); }
.btn-quiet:hover { border-color: var(--border); color: var(--ink); }
.cat-name input {
  width: 220px; border-color: transparent; background: transparent;
  transition: border-color var(--t), background var(--t);
}
.cat-name input:hover { border-color: var(--border); }
.cat-name input:focus { border-color: var(--brand); background: var(--surface); }

.btn-x {
  border: none; background: none; box-shadow: none; color: var(--faint);
  font-size: 15px; line-height: 1; cursor: pointer; padding: 6px; border-radius: var(--r-md);
  transition: color var(--t), background var(--t);
}
.btn-x:hover { color: var(--neg); background: var(--neg-bg); }
.confirm-armed { color: var(--flash-neg) !important; background: var(--neg-bg) !important; }
.btn-x.confirm-armed { width: auto; font-size: 11px; font-weight: 500; padding: 6px 8px; }

/* --- collapsible weeks / history ----------------------------------------------------------------- */

details.week { border-top: 1px solid var(--border-soft); }
details.week:first-of-type { border-top: none; }
details.week summary {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 4px; cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 500; color: var(--text-2);
  border-radius: var(--r-md);
  transition: background 100ms ease, color 100ms ease;
}
details.week summary::-webkit-details-marker { display: none; }
details.week summary::before {
  content: ''; flex: none; width: 7px; height: 7px; margin-right: -4px;
  border-right: 1.5px solid var(--faint); border-bottom: 1.5px solid var(--faint);
  transform: rotate(-45deg); transition: transform 150ms ease;
}
details.week[open] summary::before { transform: rotate(45deg); }
details.week summary > span:first-of-type { margin-right: auto; }
details.week summary:hover { background: var(--row-hover); color: var(--ink); }
details.week[open] summary { color: var(--ink); }
details.week .table { margin: 2px 0 12px; }

/* --- stocktake preview ---------------------------------------------------------------------------- */

.preview { margin-top: 16px; }
.preview .banner { margin: 12px 0 0; }
.preview-blocked .table tfoot td { color: var(--faint); }

/* --- editable rows, month ranges, expense page ---------------------------- */
/* Added with the expenses/editability pass. Every color here is a token, so the
   dark twin comes for free (DESIGN.md §1.2). */

/* Filter bars: a small label stacked over its control. */
.filter-label {
  display: inline-flex; flex-direction: column; gap: 4px;
  font-size: 11px; letter-spacing: .02em; color: var(--faint);
}
.filter-row input[type="month"] { width: 148px; }
.filter-row input[type="search"] { width: 190px; }
.filter-row-inline { margin: 0 0 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border-soft); }

/* Wider form grids for the inline edit forms. */
.form-grid-5 { grid-template-columns: repeat(5, 1fr); }
.form-grid-5 .span3 { grid-column: span 3; }
.form-grid-5 .span5 { grid-column: span 5; }
.form-grid-4 .span3 { grid-column: span 3; }
@media (max-width: 1100px) {
  .form-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .form-grid-5 .span3, .form-grid-5 .span5 { grid-column: span 2; }
}
@media (max-width: 900px) {
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid-3 .span2, .form-grid-3 .span3, .form-grid-4 .span3 { grid-column: span 1; }
}

.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
@media (max-width: 900px) { .kpi-grid-3 { grid-template-columns: 1fr; } }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: 1fr; }
  /* stacked: the short entry form goes above the long movements table */
  .grid-2-form-first > div:last-child { order: -1; }
}

/* A row swapped into edit mode: inset panel, not a floating dialog. */
.row-editing td { background: var(--surface-2); padding: 14px 12px; }
.row-form { margin: 0; }
.row-form .form-actions { display: flex; gap: 8px; align-items: center; }

.btn-danger { color: var(--neg); border-color: var(--border); }
.btn-danger:hover { background: var(--neg-bg); color: var(--neg); border-color: var(--neg); }

.link-sm { font-size: 12px; color: var(--text-2); transition: color var(--t); }
.link-sm:hover { color: var(--ink); }

.chip-warn { background: var(--warn-bg); color: var(--warn-ink); }

/* The year, dimmed, after a short date — keeps multi-year tables readable. */
.year-dim { color: var(--faint); font-size: 11px; }

.reopen-row { padding: 8px 12px; gap: 10px; font-size: 12px; }

.dot-pos { background: var(--chart-s3); }
.dot-neg { background: var(--chart-neg); }

/* --- appearance toggle (sidebar foot) ------------------------------------- */
/* Three tiny icon buttons: Auto / Light / Dark. A plain form post, so it works
   with JS off and the page arrives already themed. */
.theme-toggle {
  display: flex; gap: 2px; margin: 10px 0 8px;
  padding: 2px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface-2); width: fit-content;
}
.theme-toggle button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 22px; padding: 0;
  border: none; border-radius: 4px; background: none; cursor: pointer;
  color: var(--faint); transition: color var(--t), background var(--t);
}
.theme-toggle button svg { width: 13px; height: 13px; }
.theme-toggle button:hover { color: var(--ink); }
.theme-toggle button.active { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border); }
.theme-toggle button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* A reading too old to trust: the close leaves the field empty and says why. */
.hint-stale { color: var(--warn-ink); }
/* Why an adapter is failing, on the ticker itself rather than only on hover. */
.ticker-error {
  margin-top: 6px; font-size: 11px; line-height: 1.35; color: var(--warn-ink);
  overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* The month-range bar is a sibling of .page-head (Overview's day-range filter
   sits inside it and inherits its margin instead). Without this it butts
   straight into the KPI row while every other section keeps 16–18px. */
.range-bar { margin-bottom: 18px; }

/* --- login (cloud only) ---------------------------------------------------- */
/* One card, centered. The only page an unauthenticated visitor ever sees. */
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px;
}
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px;
  padding: 28px;
}
.login-card .brand { font-size: 20px; }
.login-card label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.login-card input[type="password"] {
  height: 40px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px;
}
.login-card input[type="password"]:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.login-card .btn { height: 40px; justify-content: center; }

/* --- assistant: page, markdown, widget (cloud only) ------------------------ */

/* Two-pane page: chat-list rail + conversation. The card is a fixed-height
   viewport so the conversation scrolls inside it and the page itself doesn't. */
.chat-page {
  display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 100%;
  gap: 0; padding: 0; height: calc(100vh - 176px); min-height: 420px; overflow: hidden;
}
.chat-page.is-disabled { grid-template-columns: 1fr; }
.chat-rail {
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0; background: var(--surface-2);
}
.chat-new { margin: 12px; }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.chat-list-empty { color: var(--faint); font-size: 12.5px; padding: 8px 6px; }
.chat-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 9px; border-radius: var(--r-md);
  cursor: pointer; position: relative; transition: background var(--t);
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-title {
  font-size: 13px; font-weight: 500; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-sub {
  font-size: 11.5px; color: var(--faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-meta { font-size: 11px; color: var(--faint); flex: none; }
.chat-item-del {
  border: none; background: none; color: var(--faint); cursor: pointer; font-size: 16px;
  line-height: 1; padding: 2px 4px; border-radius: 4px; opacity: 0; flex: none;
}
.chat-item:hover .chat-item-del { opacity: 1; }
.chat-item-del:hover { color: var(--neg); background: var(--neg-bg); }

.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; padding: 14px 16px 12px; }

/* Conversation log — the ONLY thing that scrolls. */
.chat-log {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  padding: 4px 2px 8px; min-height: 0;
}
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 460px; }
.chat-empty-title { font-size: 15px; color: var(--text-2); margin-bottom: 14px; }
.chat-suggests { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip-suggest {
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  border-radius: var(--r-md); padding: 7px 11px; font: inherit; font-size: 12.5px;
  cursor: pointer; transition: border-color var(--t), color var(--t);
}
.chip-suggest:hover { border-color: var(--brand); color: var(--ink); }

.chat-msg { display: flex; }
.chat-user { justify-content: flex-end; }
.chat-assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 82%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.chat-user .chat-bubble { background: var(--brand); color: var(--on-brand); border-bottom-right-radius: 4px; }
.chat-assistant .chat-bubble {
  background: var(--surface-2); color: var(--ink); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* markdown inside assistant bubbles */
.chat-bubble .md-p { margin: 0 0 8px; }
.chat-bubble .md-p:last-child { margin-bottom: 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble .md-h { margin: 10px 0 6px; font-size: 14px; font-weight: 600; }
.chat-bubble .md-ul, .chat-bubble .md-ol { margin: 4px 0 8px; padding-left: 20px; }
.chat-bubble .md-ul li, .chat-bubble .md-ol li { margin: 2px 0; }
.chat-bubble code {
  font-family: var(--mono); font-size: 12.5px; background: var(--pill);
  padding: 1px 5px; border-radius: 4px;
}
.chat-bubble .md-pre {
  background: var(--pill); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 10px 12px; overflow-x: auto; margin: 6px 0;
}
.chat-bubble .md-pre code { background: none; padding: 0; }
.chat-bubble .md-quote {
  border-left: 3px solid var(--border); padding-left: 10px; margin: 6px 0; color: var(--text-2);
}
.chat-bubble .md-hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.chat-bubble a { color: var(--brand-hover); text-decoration: underline; }
.md-table-wrap { overflow-x: auto; margin: 6px 0; }
.chat-bubble .md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.chat-bubble .md-table th, .chat-bubble .md-table td {
  border: 1px solid var(--border); padding: 5px 9px; text-align: left; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.chat-bubble .md-table th { background: var(--surface); font-weight: 600; }

.chat-typing { display: inline-flex; gap: 4px; align-items: center; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: chatblink 1.2s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatblink { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }

/* input — auto-growing textarea, no scrollbar until the cap */
.chat-input { display: flex; gap: 8px; align-items: flex-end; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.chat-input textarea {
  flex: 1; resize: none; overflow-y: hidden; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; padding: 9px 12px; line-height: 1.4;
  min-height: 40px;
}
.chat-input textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.chat-input .btn { height: 40px; }
.chat-foot { margin-top: 8px; }

/* confirm dialog (shared by page + widget) */
.chat-modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
.chat-modal-backdrop[hidden] { display: none; }
.chat-modal { width: 100%; max-width: 380px; }
.chat-modal h3 { margin: 0 0 14px; }
.confirm-fields { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; }
.confirm-fields dt { color: var(--muted); font-size: 12px; }
.confirm-fields dd { margin: 0; font-variant-numeric: tabular-nums; }
.confirm-warn { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-border); border-radius: var(--r-md); padding: 8px 10px; font-size: 12.5px; margin-bottom: 14px; }

/* --- floating widget ------------------------------------------------------- */
.ops-widget { position: fixed; right: 22px; bottom: 22px; z-index: 55; }
.widget-fab {
  width: 52px; height: 52px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: var(--on-brand); display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); transition: transform var(--t), background var(--t);
}
.widget-fab svg { width: 22px; height: 22px; }
.widget-fab:hover { background: var(--brand-hover); transform: translateY(-1px); }
.ops-widget.is-open .widget-fab { transform: scale(.9); opacity: .85; }
.widget-panel {
  position: absolute; right: 0; bottom: 64px; width: 384px; max-width: calc(100vw - 44px);
  height: 560px; max-height: calc(100vh - 120px); display: none; flex-direction: column;
  padding: 0; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.22);
}
.ops-widget.is-open .widget-panel { display: flex; }
.widget-head { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-bottom: 1px solid var(--border); }
.widget-select {
  flex: 1; min-width: 0; height: 30px; border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 12.5px; padding: 0 8px;
}
.widget-icon {
  flex: none; width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--muted); cursor: pointer; border-radius: var(--r-md);
  text-decoration: none; transition: color var(--t), background var(--t);
}
.widget-icon svg { width: 15px; height: 15px; }
.widget-icon:hover { color: var(--ink); background: var(--surface-2); }
.widget-panel .chat-log { padding: 12px; }
.widget-panel .chat-bubble { max-width: 88%; font-size: 13.5px; }
.widget-panel .chat-empty-title { font-size: 13.5px; }
.widget-input { padding: 10px 12px; border-top: 1px solid var(--border); }
.widget-input textarea { font-size: 13.5px; padding: 8px 10px; }
.widget-input .btn { height: 36px; }
@media (max-width: 720px) {
  .widget-panel { width: calc(100vw - 44px); height: calc(100vh - 120px); }
  .chat-page { grid-template-columns: 1fr; }
  .chat-rail { display: none; }
}

/* --- streaming thinking block ---------------------------------------------- */
.chat-think {
  margin: 0 0 8px; border: 1px solid var(--border-soft); border-radius: var(--r-md);
  background: var(--surface); overflow: hidden;
}
.chat-think[hidden] { display: none; }
.chat-think > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 7px;
  padding: 6px 10px; font-size: 12px; color: var(--muted); user-select: none;
}
.chat-think > summary::-webkit-details-marker { display: none; }
.chat-think > summary::before {
  content: ''; width: 6px; height: 6px; border-right: 1.5px solid var(--faint);
  border-bottom: 1.5px solid var(--faint); transform: rotate(-45deg); transition: transform var(--t); flex: none;
}
.chat-think[open] > summary::before { transform: rotate(45deg); }
.think-label { font-weight: 500; }
.think-dots { display: none; gap: 3px; }
.chat-think.is-thinking .think-dots { display: inline-flex; }
.think-dots span { width: 4px; height: 4px; border-radius: 50%; background: var(--faint); animation: chatblink 1.2s infinite ease-in-out; }
.think-dots span:nth-child(2) { animation-delay: .2s; }
.think-dots span:nth-child(3) { animation-delay: .4s; }
.think-body {
  padding: 2px 12px 10px; font-size: 12.5px; line-height: 1.5; color: var(--text-2);
  white-space: pre-wrap; max-height: 220px; overflow-y: auto; font-style: italic;
}
.chat-answer:empty { display: none; }
.widget-panel .think-body { max-height: 150px; font-size: 12px; }
