/* Juno dashboard. Colors are tokens so light/dark are swapped in one place;
   the --series-* values are a validated colorblind-safe categorical palette
   (charts read them at runtime, see charts.js). */
:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-ink: #ffffff;
  --accent-soft: #e6effb;
  --link: #1c5cab;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --good-bg: rgba(12, 163, 12, 0.13);
  --warning-bg: rgba(250, 178, 25, 0.22);
  --critical-bg: rgba(208, 59, 59, 0.13);
  --good-ink: #006300;
  --warning-ink: #7a5000;
  --critical-ink: #a32626;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-other: #b3b2ab;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-ink: #ffffff;
    --accent-soft: #1b2a3d;
    --link: #86b6ef;
    --good-bg: rgba(12, 163, 12, 0.22);
    --warning-bg: rgba(250, 178, 25, 0.20);
    --critical-bg: rgba(208, 59, 59, 0.24);
    --good-ink: #5fd35f;
    --warning-ink: #fcc659;
    --critical-ink: #f08b8b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-other: #5f5e5a;
    --shadow: none;
  }
}

/* Theme setting: "dark" forces the dark tokens whatever the device says
   (and "light", via the :not() guard above, keeps the light ones). */
:root[data-theme="dark"] {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242423;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-ink: #ffffff;
    --accent-soft: #1b2a3d;
    --link: #86b6ef;
    --good-bg: rgba(12, 163, 12, 0.22);
    --warning-bg: rgba(250, 178, 25, 0.20);
    --critical-bg: rgba(208, 59, 59, 0.24);
    --good-ink: #5fd35f;
    --warning-ink: #fcc659;
    --critical-ink: #f08b8b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-other: #5f5e5a;
    --shadow: none;
  }


* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--link); }
h1, h2, h3 { line-height: 1.2; }
h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 0 0 12px; }
code { font-size: 0.9em; }
.app { max-width: 1200px; margin: 0 auto; padding: 0 16px 120px; }

/* ---------- Buttons & form controls ---------- */
button, .button {
  font: inherit; font-size: 14px; padding: 8px 16px; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid transparent;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.55; cursor: default; }
button.secondary, .button.secondary {
  background: transparent; color: var(--ink-2); border-color: var(--axis);
}
button.secondary:hover { background: var(--surface-2); }
input, select, textarea {
  font: inherit; font-size: 14px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--axis); background: var(--surface); color: var(--ink);
}
textarea { width: 100%; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ---------- Header ---------- */
.site-header {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 16px 32px;
  padding: 20px 0 16px;
}
.brand { display: flex; flex-direction: column; gap: 10px; }
.brand h1 { margin: 0; font-size: 28px; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.logo { display: block; flex: none; }
.timeframe { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.timeframe select { font-weight: 600; }
.amount-switch { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; margin-left: 4px; }
.amount-switch label { cursor: pointer; }
.amount-switch input { position: absolute; opacity: 0; pointer-events: none; }
.amount-switch span { display: block; padding: 6px 12px; font-size: 14px; color: var(--ink-2); }
.amount-switch input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.amount-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.trend-switch { vertical-align: middle; margin-left: 8px; }
.trend-switch span { padding: 2px 10px; }
.pattern-filter { margin: 0 0 16px; padding: 16px 20px; }
.small-button { font-size: 13px; padding: 4px 10px; }
.timeframe { flex-wrap: wrap; }
/* Changing the timeframe/period/amount loads in the background (dashboard.js):
   the old numbers stay, dimmed, with a spinner by the controls. The dimming
   starts after a short delay, so quick loads don't flicker. */
.loading-indicator { display: none; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.is-loading .loading-indicator { display: inline-flex; }
.spinner {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--grid); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
/* Timeframe tabs load on their own (dashboard.js): a placeholder until the
   first load, and the old numbers dimmed while one on screen is reloaded. */
.pane-loading { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 48px 16px; color: var(--ink-2); }
.tab-pane.pane-refreshing { opacity: 0.45; pointer-events: none; transition: opacity 0.2s 0.12s; }
.is-loading .summary,
.is-loading #pane-sales, .is-loading #pane-clips, .is-loading #pane-clients, .is-loading #pane-patterns {
  opacity: 0.45; pointer-events: none; transition: opacity 0.2s 0.12s;
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-top-color: var(--grid); }
  .is-loading .summary, .is-loading .tab-pane { transition: none; }
}
.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 32px);
}
.toast[hidden] { display: none; }
.custom-range { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 13px; color: var(--ink-2); }
.custom-range label { display: inline-flex; align-items: center; gap: 6px; }
.custom-range .presets { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.custom-range .presets a { padding: 4px 10px; border: 1px solid var(--axis); border-radius: 999px; text-decoration: none; color: var(--ink-2); white-space: nowrap; }
.custom-range .presets a:hover { background: var(--surface-2); color: var(--ink); }
.custom-range .presets a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.period-nav { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.period-nav a, .period-nav .disabled {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--axis); border-radius: 8px;
  text-decoration: none; color: var(--ink-2); font-size: 16px;
}
.period-nav a:hover { background: var(--surface-2); color: var(--ink); }
.period-nav .disabled { opacity: 0.35; }
.period-nav .period-title { font-weight: 650; min-width: 150px; text-align: center; }
.period-nav a.period-now { width: auto; padding: 0 10px; font-size: 13px; }
.cal-title { font-weight: 600; }
/* Dividers between the days and the totals: a narrow spacer column before
   Weekly and a short spacer row before Totals, each with a 2px line through
   the middle. The lines overlap the 3px cell spacing so they run unbroken. */
table.calendar th.cal-sep, table.calendar td.cal-sep { width: 14px; padding: 0; background: none; position: relative; }
table.calendar td.cal-sep::after {
  content: ""; position: absolute; top: -3px; bottom: -3px; left: 50%; width: 2px; margin-left: -1px;
  background: var(--axis); border-radius: 1px;
}
table.calendar tr.cal-sep-row td { height: 10px; padding: 0; background: none; position: relative; }
table.calendar tr.cal-sep-row td::before {
  content: ""; position: absolute; left: -3px; right: -3px; top: 50%; height: 2px; margin-top: -1px; background: var(--axis);
}
table.calendar tr.cal-sep-row td:first-child::before { left: 0; }
table.calendar tr.cal-sep-row td:last-child::before { right: 0; }
.summary { text-align: right; margin-left: auto; }
.account { display: flex; justify-content: flex-end; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.account form { margin: 0; }
.last-sync { display: inline-flex; align-items: center; gap: 6px; }
.small-spinner { width: 12px; height: 12px; border-width: 2px; }
.account button { padding: 4px 12px; font-size: 13px; }
.summary-label { font-size: 13px; color: var(--ink-2); }
.hero { font-size: 40px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; }
.hero-sub { font-size: 16px; font-weight: 400; color: var(--ink-2); letter-spacing: 0; }
.forecast { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.change { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.change.up { color: var(--good-ink); }
.change.down { color: var(--critical-ink); }
.goal-line { margin-top: 6px; font-size: 15px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; }
.goal-stats { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.goal-stats span + span::before { content: "·"; margin: 0 6px; color: var(--muted); }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px 2px 8px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
}
.status-badge::before { font-size: 12px; }
.status-badge.on-track { background: var(--good-bg); color: var(--good-ink); }
.status-badge.on-track::before { content: "✓"; }
.status-badge.behind { background: var(--warning-bg); color: var(--warning-ink); }
.status-badge.behind::before { content: "!"; }
.status-badge.at-risk { background: var(--critical-bg); color: var(--critical-ink); }
.status-badge.at-risk::before { content: "✕"; }

@media (max-width: 640px) {
  .summary { text-align: left; margin-left: 0; width: 100%; }
  .account, .goal-line { justify-content: flex-start; }
  .site-header { flex-direction: column; }
  .hero { font-size: 34px; }
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--grid); margin-bottom: 20px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  padding: 10px 14px; text-decoration: none; color: var(--ink-2); font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.tab-pane[hidden] { display: none; }

/* ---------- Cards & layout ---------- */
.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px;
  box-shadow: var(--shadow); min-width: 0;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.stat, .muted { color: var(--ink-2); }
.small { font-size: 13px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- Charts ---------- */
.chart-title { font-size: 14px; font-weight: 600; margin: 0 0 2px; }
.chart-sub { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.chart-box { position: relative; height: 300px; }
.chart-box.pie { height: 280px; }
details.table-view { margin-top: 12px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--ink-2); }
details.table-view table { margin-top: 8px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); font-size: 14px; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.rank { color: var(--muted); width: 1%; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
/* Long ranked tables scroll inside their card with a sticky header row. The
   scrolling box has no padding (the card's padding would leave a strip above
   the stuck header where rows show through), and the header's bottom line is
   a shadow because collapsed-table borders don't stick with the cell. */
.card.rank-table { padding: 0; overflow: hidden; }
.rank-table .rank-scroll { max-height: 640px; overflow-y: auto; }
.rank-table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  border-bottom: none; box-shadow: inset 0 -1px 0 var(--grid); padding-top: 14px;
}
.rank-table th:first-child, .rank-table td:first-child { padding-left: 20px; }
.rank-table th:last-child, .rank-table td:last-child { padding-right: 20px; }
.rank-table tbody tr:last-child td { border-bottom: none; }
.client-search { flex: 0 1 260px; }
.client-search input { width: 100%; }
.rank-pager .pager { margin: 0; padding: 12px 20px; border-top: 1px solid var(--border); }
.handle { color: var(--muted); font-size: 13px; }
.link-button { background: none; border: none; padding: 2px 4px; color: var(--link); font-size: 13px; }
.link-button:hover { background: none; text-decoration: underline; }
.alias-field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 8px 12px; align-items: center; margin-bottom: 10px; font-size: 14px; }
.alias-field .who { overflow-wrap: anywhere; }
.alias-field .who small { display: block; color: var(--muted); }

/* Suggested aliases: why, the two clients side by side, then the actions. */
.suggestions { list-style: none; margin: 0; padding: 0; }
.suggestion { display: grid; grid-template-columns: 140px minmax(0, 1fr) auto; gap: 8px 16px; align-items: start; padding: 12px 0; border-top: 1px solid var(--grid); }
.suggestion:first-child { border-top: none; padding-top: 4px; }
.suggestion-why { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; color: var(--ink-2); }
.suggestion-clients { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; overflow-wrap: anywhere; }
.suggestion-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; white-space: nowrap; }
.suggestion-actions form { margin: 0; }
.suggestion.loading { opacity: 0.5; pointer-events: none; }
.badge.strong { background: var(--good-bg); color: var(--good-ink); }
@media (max-width: 640px) {
  .suggestion { grid-template-columns: minmax(0, 1fr); }
  .suggestion-why { flex-direction: row; align-items: center; }
  .suggestion-actions { flex-direction: row; justify-content: flex-start; gap: 12px; }
}

/* ---------- Calendar ---------- */
.calendar-scroll { overflow-x: auto; }
table.calendar { table-layout: fixed; min-width: 780px; border-collapse: separate; border-spacing: 3px; }
table.calendar th { text-align: center; border: none; padding: 4px; }
table.calendar td { border: none; padding: 6px 8px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
table.calendar th.row-labels-head { width: 64px; }
table.calendar td.row-labels { background: none; color: var(--muted); font-size: 12px; padding-left: 0; }
.cal-amounts { display: grid; gap: 1px; font-variant-numeric: tabular-nums; }
.cal-amounts > div { display: flex; justify-content: flex-end; white-space: nowrap; }
.cal-amounts .total { font-weight: 650; }
.cal-amounts .zero { color: var(--muted); }
.row-labels .cal-amounts > div { justify-content: flex-start; }
.cal-day-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 2px; min-height: 18px; }
.cal-day-head .num { font-weight: 600; }
table.calendar td.other-month { opacity: 0.45; }
table.calendar td.today { box-shadow: inset 0 0 0 2px var(--accent); }
table.calendar td.week-total, table.calendar td.weekday-total { background: var(--accent-soft); }
table.calendar td.good { background: var(--good-bg); }
table.calendar td.warning { background: var(--warning-bg); }
table.calendar td.critical { background: var(--critical-bg); }
.mark { font-size: 11px; font-weight: 700; }
.good .mark { color: var(--good-ink); }
.warning .mark { color: var(--warning-ink); }
.critical .mark { color: var(--critical-ink); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend .swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }
.swatch.good { background: var(--good-bg); box-shadow: inset 0 0 0 1px var(--good); }
.swatch.warning { background: var(--warning-bg); box-shadow: inset 0 0 0 1px var(--warning); }
.swatch.critical { background: var(--critical-bg); box-shadow: inset 0 0 0 1px var(--critical); }

/* ---------- Data tab (sync, export, raw tables) ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin: 12px 0; }
.flash.ok { background: var(--good-bg); color: var(--good-ink); }
.flash.error { background: var(--critical-bg); color: var(--critical-ink); }
.flash.warn { background: var(--warning-bg); color: var(--warning-ink); }
.notices .flash { margin-top: 0; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 12px; }
td.err { color: var(--critical-ink); font-family: ui-monospace, monospace; font-size: 12px; word-break: break-word; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); }
.badge.failed { background: var(--critical-bg); color: var(--critical-ink); }
/* Checkbox sets (partials/checkGroup.ejs): a heading with quick-select
   buttons, then the boxes in even columns that wrap to the width. */
.check-group { margin-top: 12px; }
.check-group + .check-group { margin-top: 20px; }
.pattern-filter .check-group { margin-top: 0; }
.check-group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-bottom: 10px; }
.check-group .group-label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.check-presets { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.check-columns { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); gap: 8px 16px; }
.check-columns label { display: flex; align-items: center; gap: 6px; font-size: 14px; min-width: 0; cursor: pointer; }
.check-columns label span { overflow-wrap: anywhere; }
@media (max-width: 480px) { .check-columns { grid-template-columns: 1fr 1fr; } }
form.row-action { margin: 0; }
form.row-action button { padding: 3px 10px; font-size: 12px; background: transparent; color: var(--ink-2); border: 1px solid var(--axis); }
form.row-action button:hover { color: var(--critical-ink); border-color: var(--critical); }
form.row-action.restore button:hover { color: var(--accent); border-color: var(--accent); }
.data-section + .data-section { margin-top: 16px; }
.sales-filter { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; margin-bottom: 4px; }
.sales-filter .field { margin-bottom: 10px; }
.sales-filter .grow { flex: 1 1 240px; }
.sales-filter .filter-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-top: 12px; }
.pager-links { display: flex; align-items: center; gap: 6px; }
.pager-links a, .pager-links .disabled {
  display: inline-block; padding: 4px 10px; border: 1px solid var(--axis); border-radius: 8px;
  font-size: 13px; text-decoration: none; color: var(--ink-2); white-space: nowrap;
}
.pager-links a:hover { background: var(--surface-2); color: var(--ink); }
.pager-links .disabled { opacity: 0.4; }
.pager-links .small { padding: 0 6px; color: var(--ink-2); white-space: nowrap; }
.data-table.loading { opacity: 0.5; pointer-events: none; transition: opacity 0.15s; }

/* ---------- Settings ---------- */
.settings-form { max-width: 560px; }
.settings-form h2 { margin-bottom: 16px; }
.settings-block { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid var(--grid); }
.settings-block h3 { margin: 0 0 8px; font-size: 16px; }

/* ---------- Help ---------- */
.help { max-width: 820px; }
.help .card + .card { margin-top: 16px; }
.help p, .help li, .help dd { line-height: 1.55; }
.help h3 { font-size: 18px; }
.help-toc { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; margin-top: 12px; }
.help-toc a { font-size: 14px; }
.help-section { scroll-margin-top: 16px; }
.help dl { margin: 0; }
.help dt { font-weight: 600; margin-top: 12px; }
.help dd { margin: 2px 0 0; color: var(--ink-2); }
.help ol, .help ul { padding-left: 22px; }
.help li + li { margin-top: 6px; }
.help-statuses { list-style: none; padding-left: 0 !important; }
.help-statuses .status-badge { margin-right: 6px; }
.settings-form fieldset { border: none; padding: 0; margin: 0 0 20px; }
.settings-form legend { font-weight: 600; font-size: 16px; margin-bottom: 8px; padding: 0; }

/* ---------- Modals & fields ---------- */
/* Padding lives on the inner form so a click on the dialog element itself is always a backdrop click. */
dialog.modal {
  border: none; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
dialog.modal > form { padding: 24px; }
dialog.modal.wide { width: min(600px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.modal h2 { margin: 0 0 16px; }
dialog.modal.xwide { width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
.detail h2 { margin-bottom: 4px; }
.detail-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 14px 0 18px; }
.detail-stats > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.detail-stats span { font-size: 12px; color: var(--ink-2); }
.detail-stats b { font-size: 18px; letter-spacing: -0.01em; }
.detail-stats small { font-size: 12px; color: var(--muted); }
.detail-tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 20px; margin-top: 18px; }
.detail-tables table td, .detail-tables table th { font-size: 13px; padding: 6px 8px; }
.detail-loading { display: flex; align-items: center; gap: 8px; color: var(--ink-2); }
.name-link { background: none; border: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px; }
.name-link:hover { background: none; color: var(--link); text-decoration-color: currentColor; }
.import-columns { margin-top: 8px; }
.import-columns td, .import-columns th { padding: 6px 8px; font-size: 13px; }
.req { color: var(--critical-ink); font-weight: 600; font-size: 12px; }
.opt { color: var(--muted); font-size: 12px; }
.error-list { margin: 0; padding-left: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 14px; }
.field .hint { font-size: 12px; color: var(--muted); }
.check-line { display: flex; align-items: center; gap: 8px; }
.field[hidden] { display: none; } /* display:flex above would otherwise override the hidden attribute */
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Floating buttons ---------- */
.fab-stack { position: fixed; right: 24px; bottom: 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; z-index: 10; }
.fab-stack form { margin: 0; }
.fab { width: 56px; height: 56px; padding: 0; border-radius: 50%; font-size: 28px; line-height: 1; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25); }
.fab.secondary { width: 44px; height: 44px; background: var(--surface); color: var(--accent); border: 1px solid var(--border); }
.fab.secondary:hover { background: var(--accent-soft); }
.fab svg { display: block; margin: auto; }
.fab.spinning svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .fab.spinning svg { animation: none; } }
@media (max-width: 640px) { .fab-stack { right: 16px; bottom: 16px; } }

/* ---------- Footer ---------- */
.site-footer { text-align: center; color: var(--ink-2); font-size: 13px; padding: 32px 0 8px; border-top: 1px solid var(--grid); margin-top: 32px; }
.site-footer p { margin: 4px 0; }

/* ---------- Landing page (signed out) ----------
   Full-width bands (hero, features, steps, platforms + privacy, closing call)
   with a centered .l-inner column. Colors are the logo blue plus the chart
   palette (--series-*), so the page matches the app it advertises. */
.landing {
  --hero-a: #184f95;
  --hero-b: #2a78d6;
  --hero-ink: #ffffff;
  --hero-ink-2: rgba(255, 255, 255, 0.82);
  --pv-blue: #2a78d6; --pv-orange: #eb6834; --pv-aqua: #1baf7a; --pv-yellow: #eda100; --pv-muted: #b3b2ab;
  --tint: #edf3fb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .landing { --hero-a: #0d366b; --hero-b: #1c5cab; --tint: #121a24; }
}
:root[data-theme="dark"] .landing { --hero-a: #0d366b; --hero-b: #1c5cab; --tint: #121a24; }

.l-inner { max-width: 1080px; margin: 0 auto; padding-left: max(20px, env(safe-area-inset-left, 0px)); padding-right: max(20px, env(safe-area-inset-right, 0px)); }
.l-hero {
  color: var(--hero-ink); padding-bottom: 72px; position: relative; overflow: hidden;
  background:
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, 0.10) 0 120px, transparent 121px),
    radial-gradient(circle at 88% 12%, rgba(255, 255, 255, 0.06) 0 210px, transparent 211px),
    radial-gradient(circle at 6% 96%, rgba(27, 175, 122, 0.30) 0 160px, transparent 161px),
    linear-gradient(160deg, var(--hero-a), var(--hero-b));
}
.l-top { display: flex; justify-content: space-between; align-items: center; padding: 22px 0; }
.landing-brand { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; color: var(--hero-ink); }
.landing-brand .logo { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85); border-radius: 50%; }
.l-top-signin { color: var(--hero-ink); text-decoration: none; font-weight: 600; padding: 7px 16px; border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 999px; }
.l-top-signin:hover { background: rgba(255, 255, 255, 0.12); }
.l-hero-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; margin-top: 32px; }
.l-pitch { min-width: 0; }
.l-eyebrow { margin: 0 0 12px; font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #9ee6c8; }
.l-hero h1 { font-size: clamp(32px, 5vw, 50px); line-height: 1.08; letter-spacing: -0.025em; margin: 0 0 18px; text-wrap: balance; }
.l-lead { font-size: 18px; line-height: 1.55; color: var(--hero-ink-2); margin: 0 0 28px; max-width: 34em; }
.l-fine { font-size: 13px; color: var(--hero-ink-2); margin: 18px 0 0; max-width: 34em; }
.l-alert { display: inline-block; margin: 16px 0 0; padding: 8px 14px; border-radius: 8px; background: rgba(208, 59, 59, 0.9); color: #fff; }
.l-alert.l-alert-info { background: rgba(255, 255, 255, 0.95); color: #184f95; max-width: 34em; }
.google-button {
  display: inline-flex; align-items: center; gap: 12px; padding: 13px 24px; border-radius: 999px;
  background: #ffffff; color: #1f1f1f; border: 1px solid rgba(0, 0, 0, 0.08); font: 600 15px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  text-decoration: none; box-shadow: 0 6px 20px rgba(9, 30, 66, 0.25);
}
.google-button:hover { background: #f5f8fd; }
@media (prefers-reduced-motion: no-preference) {
  .google-button { transition: transform 0.15s, box-shadow 0.15s; }
  .google-button:hover { transform: translateY(-1px); box-shadow: 0 10px 26px rgba(9, 30, 66, 0.3); }
}

/* The example dashboard in the hero */
.l-preview { margin: 0; min-width: 0; }
.l-preview figcaption { font-size: 12px; color: var(--hero-ink-2); text-align: right; margin-top: 8px; }
.pv-card {
  background: #fcfcfb; color: #0b0b0b; border-radius: 18px; padding: 20px; transform: rotate(1.2deg);
  box-shadow: 0 24px 60px rgba(4, 20, 50, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.4);
}
.pv-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.pv-label { display: block; font-size: 12px; color: #52514e; }
.pv-total { display: block; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.pv-up { display: block; font-size: 12px; color: #006300; margin-top: 2px; }
.pv-badge { font-size: 12px; font-weight: 700; color: #006300; background: rgba(12, 163, 12, 0.13); padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pv-chart { display: block; width: 100%; height: 90px; margin: 14px 0; }
.pv-row { display: flex; gap: 16px; align-items: center; justify-content: space-between; }
.pv-cal { display: grid; grid-template-columns: repeat(7, 18px); gap: 4px; }
.pv-cal span { height: 18px; border-radius: 4px; }
.pv-cal .g { background: rgba(12, 163, 12, 0.35); }
.pv-cal .y { background: rgba(250, 178, 25, 0.55); }
.pv-cal .r { background: rgba(208, 59, 59, 0.4); }
.pv-donut { display: flex; align-items: center; gap: 10px; }
.pv-donut svg { width: 64px; height: 64px; }
.pv-donut ul { list-style: none; margin: 0; padding: 0; font-size: 11px; color: #52514e; display: grid; gap: 3px; }
.pv-donut i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* Bands below the hero */
.l-band { padding: 64px 0; }
.l-tint { background: var(--tint); }
.l-h2 { font-size: clamp(24px, 3.2vw, 32px); letter-spacing: -0.02em; margin: 0 0 24px; text-wrap: balance; }
.l-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; }
.l-feature { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.l-feature h3 { font-size: 17px; margin: 14px 0 6px; }
.l-feature p { margin: 0; color: var(--ink-2); line-height: 1.55; }
.l-chip {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  background: color-mix(in srgb, var(--chip) 16%, transparent); color: var(--chip);
}
.l-chip svg, .l-privacy h2 svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.l-steps { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 24px; }
.l-steps h3 { margin: 12px 0 4px; font-size: 18px; }
.l-steps p { margin: 0; color: var(--ink-2); line-height: 1.55; }
.l-num { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--chip); color: #fff; font-weight: 700; font-size: 18px; }
.l-split { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; align-items: start; }
.l-platforms { display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 12px; }
.l-platforms span { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: 14px; }
.l-platforms i { width: 10px; height: 10px; border-radius: 50%; background: var(--chip); }
.l-privacy { background: color-mix(in srgb, var(--series-3) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--series-3) 30%, transparent); border-radius: 16px; padding: 24px; }
.l-privacy h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.l-privacy h2 svg { color: var(--series-6); width: 28px; height: 28px; }
.l-privacy ul { padding-left: 20px; margin: 0 0 12px; line-height: 1.6; }
.l-privacy li + li { margin-top: 6px; }
.l-cta { background: linear-gradient(160deg, var(--hero-a), var(--hero-b)); color: var(--hero-ink); padding: 56px 0; text-align: center; }
.l-cta h2 { font-size: clamp(24px, 3.4vw, 34px); letter-spacing: -0.02em; margin: 0 0 22px; }
.landing .site-footer { margin-top: 0; border-top: none; padding: 28px 0 32px; }
@media (max-width: 860px) {
  .l-hero-grid, .l-split { grid-template-columns: 1fr; gap: 36px; }
  .pv-card { transform: none; }
}
@media (max-width: 420px) {
  .pv-cal { grid-template-columns: repeat(7, 14px); }
  .pv-cal span { height: 14px; }
  .pv-row { flex-wrap: wrap; }
}

/* ---------- Phone-sized calendar ----------
   Below 700px the calendar table (9 wide columns) is replaced by a grid of
   squares: day number + total, the week total on the right, weekday totals
   underneath, colored by goal like the table. */
.cal-compact { display: none; }
@media (max-width: 700px) {
  .calendar-scroll { display: none; }
  .cal-compact { display: grid; gap: 3px; }
}
.cc-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(0, 1.15fr); gap: 3px; }
.cc-head span { font-size: 11px; color: var(--muted); text-align: center; }
.cc-row .cc-total { margin-left: 3px; }
.cc-totals { margin-top: 6px; padding-top: 6px; border-top: 2px solid var(--axis); }
.cc-cell {
  display: grid; justify-items: center; gap: 1px; padding: 5px 2px; border-radius: 6px; background: var(--surface-2);
  font-size: 11px; font-variant-numeric: tabular-nums; min-width: 0; overflow: hidden; white-space: nowrap;
}
.cc-cell b { font-size: 10px; font-weight: 600; color: var(--ink-2); }
.cc-cell.cc-total { background: var(--accent-soft); font-weight: 600; }
.cc-cell.other-month { opacity: 0.45; }
.cc-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cc-cell.good { background: var(--good-bg); }
.cc-cell.warning { background: var(--warning-bg); }
.cc-cell.critical { background: var(--critical-bg); }

/* ---------- Day x hour heatmap (Patterns) ----------
   One blue, light (little) to dark (a lot), stepped separately for dark mode. */
:root { --heat-0: var(--surface-2); --heat-1: #cde2fb; --heat-2: #9ec5f4; --heat-3: #6da7ec; --heat-4: #3987e5; --heat-5: #256abf; --heat-6: #184f95; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --heat-1: #13233a; --heat-2: #184f95; --heat-3: #1c5cab; --heat-4: #2a78d6; --heat-5: #5598e7; --heat-6: #9ec5f4; }
}
:root[data-theme="dark"] { --heat-1: #13233a; --heat-2: #184f95; --heat-3: #1c5cab; --heat-4: #2a78d6; --heat-5: #5598e7; --heat-6: #9ec5f4; }
.heat-section { grid-column: 1 / -1; }
.heat-scroll { overflow-x: auto; }
table.heatmap { border-collapse: separate; border-spacing: 2px; width: 100%; min-width: 560px; table-layout: fixed; }
table.heatmap th { font-size: 11px; font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; padding: 2px; border: none; text-align: left; white-space: nowrap; }
table.heatmap thead th:first-child, table.heatmap tbody th { width: 40px; }
table.heatmap td { height: 22px; padding: 0; border: none; border-radius: 3px; }
.heat-0 { background: var(--heat-0); } .heat-1 { background: var(--heat-1); } .heat-2 { background: var(--heat-2); }
.heat-3 { background: var(--heat-3); } .heat-4 { background: var(--heat-4); } .heat-5 { background: var(--heat-5); } .heat-6 { background: var(--heat-6); }
.heat-legend { display: flex; align-items: center; gap: 4px; margin-top: 10px; color: var(--ink-2); flex-wrap: wrap; }
.heat-legend i { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.heat-legend span:first-child { margin-right: 4px; } .heat-legend span:last-child { margin-left: 4px; }

/* ---------- Records (All Sales) ---------- */
.record-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; }
.record { display: grid; gap: 2px; padding: 16px 18px; }
.record-label { font-size: 12px; color: var(--ink-2); }
.record-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.record-unit { font-size: 15px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.record-when { font-size: 12px; color: var(--muted); }
.track-record { margin-top: 12px; }
.track-row { display: grid; grid-template-columns: 64px auto 1fr; align-items: center; gap: 12px; margin-top: 10px; }
.track-name { font-size: 13px; color: var(--ink-2); }
.track-squares { display: flex; gap: 4px; flex-wrap: wrap; }
.track-square {
  width: 24px; height: 24px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--surface-2);
}
.track-square.good { background: var(--good-bg); color: var(--good-ink); }
.track-square.warning { background: var(--warning-bg); color: var(--warning-ink); }
.track-square.critical { background: var(--critical-bg); color: var(--critical-ink); }
.track-tally { color: var(--ink-2); }
@media (max-width: 640px) { .track-row { grid-template-columns: 1fr; gap: 6px; } }

/* ---------- Tax summary (/tax) ---------- */
.tax-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; }
.tax-actions { display: flex; flex-wrap: wrap; gap: 8px; }
a.button { display: inline-block; text-decoration: none; }
.tax-page .card.table-scroll { padding: 8px 12px; }
.tax-page tfoot td { font-weight: 650; border-bottom: none; border-top: 2px solid var(--axis); }
.tax-page tr.muted td { color: var(--muted); }
.tax-notes { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: 14px; color: var(--ink-2); }
.print-only { display: none; }
/* Printed (or saved as PDF): light colors whatever the theme, no controls,
   and cards that don't split across pages. */
@media print {
  :root:not([data-print]), :root[data-theme] {
    color-scheme: light;
    --page: #ffffff; --surface: #ffffff; --surface-2: #f2f2f2; --ink: #000000; --ink-2: #333333;
    --muted: #555555; --grid: #d0d0d0; --axis: #999999; --border: rgba(0, 0, 0, 0.18); --shadow: none;
  }
  .no-print { display: none !important; }
  .print-only { display: block; }
  .tax-page .app { max-width: none; padding: 0; }
  .tax-page .card, .tax-page .section { break-inside: avoid; }
  .tax-page .table-scroll { overflow: visible; }
}

/* ---------- Admin (views/admin.ejs, adminEmail.ejs) ---------- */
/* Viewing as another user: a bar across the top of every page. */
.impersonation-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px;
  padding: 8px 16px; color: var(--warning-ink); font-size: 14px;
  background: linear-gradient(var(--warning-bg), var(--warning-bg)), var(--surface); /* solid: it's sticky */
  position: sticky; top: 0; z-index: 20;
}
.impersonation-bar form { margin: 0; }
form.inline { display: inline; margin: 0; }
.admin-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.admin-filter a {
  padding: 4px 10px; border: 1px solid var(--axis); border-radius: 8px; font-size: 13px;
  text-decoration: none; color: var(--ink-2); white-space: nowrap;
}
.admin-filter a.active { background: var(--surface-2); color: var(--ink); border-color: var(--ink-2); }
.err-text { color: var(--critical-ink); }
.admin-reparse { margin-bottom: 16px; }
.admin-reparse .flash:last-child { margin-bottom: 0; }
.admin-meta { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0; font-size: 14px; }
.admin-meta dt { color: var(--muted); }
.admin-meta dd { margin: 0; overflow-wrap: anywhere; }
.admin-body {
  white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.5; margin: 0;
  max-height: 70vh; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: 8px;
}
@media (max-width: 640px) { .admin-meta { grid-template-columns: minmax(0, 1fr); } .admin-meta dt { margin-top: 6px; } }
