/* GameBlink: "trading desk" design. Dark by default, light via [data-theme="light"].
   Every color is a token below; components only use the tokens. */

@font-face { font-family: "IBM Plex Sans"; font-weight: 400; font-display: swap; src: url("/vendor/fonts/plex-sans/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 500; font-display: swap; src: url("/vendor/fonts/plex-sans/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 600; font-display: swap; src: url("/vendor/fonts/plex-sans/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-weight: 700; font-display: swap; src: url("/vendor/fonts/plex-sans/ibm-plex-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url("/vendor/fonts/plex-mono/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: url("/vendor/fonts/plex-mono/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap; src: url("/vendor/fonts/plex-mono/ibm-plex-mono-latin-600-normal.woff2") format("woff2"); }

:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1014;
  --panel: #161920;
  --panel-2: #1e222b;
  --line: #252932;
  --line-soft: #1c2028;
  --text: #e7e9ee;
  --text-2: #b8bdc7;
  --muted: #8c93a0;
  --accent: #3987e5;
  --accent-ink: #0e1014;
  --link: #7fb2f0;
  --good: #4cc26a;
  --bad: #e66767;
  --warn: #e8a33c;
  --bad-soft: rgba(230, 103, 103, 0.12);
  --warn-soft: rgba(232, 163, 60, 0.12);
  --grid: #22262e;
  --axis: #2c313b;
  --track: #22262e;
  --hover: rgba(57, 135, 229, 0.08);
  --row-warning: #3a2f16;
  --row-highlight: #1b2c47;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  /* Chart series: categorical slots 1-3, dark steps (validated on --panel). */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f6f3;
  --panel: #ffffff;
  --panel-2: #eef1f6;
  --line: #e3e2dc;
  --line-soft: #efeee9;
  --text: #17181b;
  --text-2: #45464b;
  --muted: #6a6b70;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --link: #1f5fae;
  --good: #1e6b2e;
  --bad: #b42f2f;
  --warn: #8a5a00;
  --bad-soft: #fdecec;
  --warn-soft: #fff4dd;
  --grid: #ecebe6;
  --axis: #c3c2b7;
  --track: #efeee9;
  --hover: rgba(42, 120, 214, 0.06);
  --row-warning: #fff4d6;
  --row-highlight: #dbe7ff;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
  /* Chart series: categorical slots 1-3, light steps (validated on white). */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.mono, .num { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--good); }
.down { color: var(--bad); }
.flat { color: var(--muted); }

input, select, textarea {
  background: var(--panel);
  border: 1px solid var(--axis);
  border-radius: 6px;
  padding: 6px 9px;
  color: var(--text);
}

input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- Buttons ---------- */

.primary-btn, .secondary-btn {
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.primary-btn { background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent); }
.secondary-btn { background: var(--panel); color: var(--text); border: 1px solid var(--axis); }
.secondary-btn:hover { background: var(--panel-2); }
.secondary-btn:disabled { opacity: 0.5; cursor: default; }

.link-btn {
  background: none;
  border: none;
  padding: 0 4px;
  color: var(--link);
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
}

.close-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

/* ---------- App bar (top) and bottom nav (phones) ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 20px;
}

.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand-name { font-weight: 700; font-size: 14px; letter-spacing: 0.04em; }

.appnav { display: flex; gap: 2px; font-size: 13px; }
.appnav a {
  text-decoration: none;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 6px;
}
.appnav a:hover { color: var(--text); }
.appnav a.active { color: var(--text); background: var(--panel-2); }

.appbar-spacer { flex: 1 1 auto; }

.appbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 16px; height: 16px; }
:root[data-theme="dark"] .icon-moon, :root[data-theme="light"] .icon-sun { display: none; }

.bottom-nav { display: none; }

/* ---------- Filters ---------- */

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  font-size: 12px;
  color: var(--muted);
}
.filter-row label { display: inline-flex; align-items: center; gap: 6px; }
.filter-row select, .filter-row input { padding: 5px 8px; font-size: 12px; }
.custom-range { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Dashboard ---------- */

.dashboard { padding-bottom: 32px; }

.kpi-strip {
  display: grid;
  grid-template-columns: 1.3fr repeat(5, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.kpi {
  padding: 14px 20px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.kpi:last-child { border-right: none; }
.kpi-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.kpi-value {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-hero .kpi-value { font-size: 26px; }
.kpi-delta { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 12px; color: var(--muted); min-height: 1em; }
.kpi-delta.up { color: var(--good); }
.kpi-delta.down { color: var(--bad); }

.subbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
}

.tabs { display: flex; gap: 2px; }
.tab {
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); background: var(--panel-2); border-color: var(--line); }

.period-label { font-size: 12px; color: var(--muted); }

#dashboardBody { transition: opacity 0.15s; }
#dashboardBody.loading { opacity: 0.55; }

.split {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
}
.split-main { flex: 999 1 640px; min-width: 0; border-right: 1px solid var(--line); }
.split-side { flex: 1 1 340px; min-width: 0; }

.section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-2);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
}

.section-sub { margin: 0; font-size: 12px; color: var(--muted); }

.pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.pair > .section:first-child { border-right: 1px solid var(--line); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-line { display: inline-block; width: 14px; height: 2px; border-radius: 2px; }
.legend-line.series-1 { background: var(--series-1); }
.legend-line.series-2 { background: var(--series-2); }
.legend-line.series-3 { background: var(--series-3); }

.chart-tools { display: flex; align-items: center; gap: 10px; }

.segmented { display: inline-flex; border: 1px solid var(--axis); border-radius: 6px; overflow: hidden; }
.segmented button {
  border: none;
  background: var(--panel);
  color: var(--muted);
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--axis); }
.segmented button.active { background: var(--panel-2); color: var(--text); font-weight: 600; }

/* Needs action */
.alert-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 12.5px;
  line-height: 1.45;
  text-decoration: none;
}
a.alert:hover, button.alert:hover { background: var(--panel-2); }
button.alert { width: 100%; text-align: left; cursor: pointer; }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex: 0 0 auto; }
.alert-dot.bad { background: var(--bad); }
.alert-dot.warn { background: var(--warn); }
.alert-dot.good { background: var(--good); }
.alert strong.bad { color: var(--bad); }
.alert strong.warn { color: var(--warn); }
.alert strong.good { color: var(--good); }

/* Sync panel */
.status-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; font-size: 12.5px; }
.status-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line-soft); }
.status-list strong { font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 8px; background: var(--muted); }
.dot-green { background: var(--good); }
.dot-amber { background: var(--warn); }
.dot-red { background: var(--bad); }
.dot-blue { background: var(--accent); }
.sync-error { margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); font-size: 12px; }

/* Lists of items to fix */
details.fixlist { border-top: 1px solid var(--line-soft); }
details.fixlist > summary {
  cursor: pointer;
  list-style: none;
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-2);
}
details.fixlist > summary::-webkit-details-marker { display: none; }
details.fixlist > summary::after { content: "▾"; color: var(--muted); }
details.fixlist[open] > summary::after { content: "▴"; }

.issue-list { list-style: none; margin: 0; padding: 0; max-height: 340px; overflow-y: auto; }
.issue-list li {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12.5px;
  line-height: 1.45;
}
.issue-list li.issue-empty { display: block; color: var(--muted); border-bottom: none; }
.issue-actions { display: flex; gap: 4px; white-space: nowrap; }

/* Stock tab headline */
.stock-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.stock-figure { padding: 12px 14px; border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stock-figure:last-child { border-right: none; }
.stock-note { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.data-table .stock-note { font-family: "IBM Plex Sans", system-ui, sans-serif; }

/* ---------- Charts ---------- */

.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart .chart-grid { stroke: var(--grid); stroke-width: 1; }
.chart .chart-baseline { stroke: var(--axis); stroke-width: 1; }
.chart .chart-crosshair { stroke: var(--axis); stroke-width: 1; }
.chart .chart-axis { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 10.5px; fill: var(--muted); }
.chart .chart-label { font-size: 12px; fill: var(--text); }
.chart .chart-value { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 11.5px; fill: var(--text-2); }
.chart .chart-hit.clickable { cursor: pointer; }
.chart .chart-hit:hover, .chart .chart-hit:focus { fill: var(--hover); outline: none; }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12px;
  min-width: 160px;
}
.chart-tooltip-title { color: var(--muted); margin-bottom: 4px; }
.chart-tooltip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tooltip-row strong { color: var(--text); font-family: "IBM Plex Mono", ui-monospace, monospace; font-weight: 500; }
.chart-tooltip-row span:last-child { color: var(--text-2); }
.chart-tooltip-key { display: inline-block; width: 12px; height: 2px; border-radius: 2px; }

.empty { padding: 24px 0; text-align: center; color: var(--muted); }

/* ---------- Tables ---------- */

.table-wrap, .table-view { overflow: auto; }
.table-view { max-height: 360px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.data-table th {
  font-weight: 500;
  color: var(--muted);
  border-bottom-color: var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg);
}
.data-table .num { text-align: right; white-space: nowrap; }
.data-table th.num { font-family: inherit; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover, .data-table tr.clickable:focus { background: var(--hover); outline: none; }
.data-table th[data-sort] { cursor: pointer; user-select: none; }
.data-table th.sorted { color: var(--text); }
.data-table th.sorted::after { content: " " attr(data-dir); font-size: 10px; }
.product-name { display: block; }
.product-category { display: block; font-size: 11px; color: var(--muted); }

.days { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.days-bar { width: 64px; height: 6px; border-radius: 3px; background: var(--track); display: inline-block; overflow: hidden; }
.days-bar > span { display: block; height: 6px; border-radius: 3px; }
.days.bad { color: var(--bad); } .days.bad .days-bar > span { background: var(--bad); }
.days.warn { color: var(--warn); } .days.warn .days-bar > span { background: var(--warn); }
.days.good { color: var(--good); } .days.good .days-bar > span { background: var(--good); }
.days.none { color: var(--muted); }

.table-footer { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }

.search { min-width: 220px; }

/* ---------- Dialogs ---------- */

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.key-form { width: min(440px, calc(100vw - 32px)); padding: 14px 18px 18px; }
.key-form label { display: grid; gap: 6px; margin-bottom: 12px; font-size: 12.5px; color: var(--text-2); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.dialog-header h3 { margin: 0; font-size: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.form-error { color: var(--bad); font-size: 12.5px; margin: 0 0 8px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 12.5px; resize: vertical; }
.revealed-code {
  display: block;
  padding: 12px;
  border-radius: 6px;
  background: var(--panel-2);
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 15px;
  word-break: break-all;
  user-select: all;
}
.copy-status { margin: 10px 0 8px; color: var(--good); font-weight: 500; font-size: 12.5px; }
#copyCodesText { width: 100%; }

.move-sold-form { width: min(640px, calc(100vw - 32px)); }
.move-sold-table { width: 100%; border-collapse: collapse; margin: 8px 0 4px; font-size: 12.5px; }
.move-sold-table th, .move-sold-table td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.move-sold-actions { display: flex; justify-content: flex-end; gap: 8px; }

.product-dialog { width: min(900px, calc(100vw - 24px)); }
.product-dialog-body { padding: 16px 20px 20px; }
.product-dialog h4 { margin: 18px 0 8px; font-size: 12px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-2); }
.kpi-small { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.kpi-small .kpi { padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.kpi-small .kpi:nth-child(3n) { border-right: none; }
.kpi-small .kpi:nth-last-child(-n + 3) { border-bottom: none; }
.kpi-small .kpi-value { font-size: 16px; }

/* ---------- Login ---------- */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%);
  padding: 26px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card .brand { margin-bottom: 20px; }
.login-card label { display: grid; gap: 6px; margin-bottom: 14px; font-size: 12.5px; color: var(--text-2); }
.login-card .primary-btn { width: 100%; justify-content: center; padding: 9px 12px; }

/* ---------- Key Ledger ---------- */

.ledger-content { padding: 12px 20px; }
.ledger-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.ledger-toolbar .filters, .filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ledger-toolbar select, .ledger-toolbar input { padding: 6px 9px; font-size: 13px; }
#dateRange { display: inline-flex; gap: 6px; }
.find-form { display: flex; gap: 6px; }
.find-form input { width: 190px; font-family: "IBM Plex Mono", ui-monospace, monospace; }

.ledger-status { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin: 10px 0 8px; font-size: 12px; color: var(--muted); }
.status-right { display: flex; align-items: center; gap: 16px; }
.page-size { display: inline-flex; align-items: center; gap: 6px; }
.page-size select { padding: 3px 6px; font-size: 12px; }
.save-state { color: var(--good); font-weight: 500; }
.save-state.saving { color: var(--muted); }
.save-state.warning { color: var(--warn); }
.filter-count { margin-left: 10px; color: var(--link); font-weight: 500; }
.tick-state { margin-left: 14px; padding-left: 14px; border-left: 1px solid var(--line); color: var(--text); }
.tick-state #tickCount { font-weight: 500; }

.problem-list {
  margin: 0 0 8px;
  padding: 8px 12px;
  list-style: none;
  background: var(--warn-soft);
  border: 1px solid var(--warn);
  border-radius: 8px;
  font-size: 12px;
  max-height: 120px;
  overflow-y: auto;
}
.problem-list li { padding: 2px 0; }

.ledger-grid { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.ledger-hint { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); }

/* Spreadsheet grid (Jspreadsheet) on the theme */
.ledger-grid .jexcel_content { width: 100% !important; max-width: 100%; overflow: auto; }
.ledger-grid .jexcel_content::-webkit-scrollbar-track { background: var(--panel); }
.ledger-grid .jexcel_content::-webkit-scrollbar-thumb { background: var(--axis); }
.jexcel { background-color: var(--panel); color: var(--text); }
.jexcel > thead > tr > td {
  background-color: var(--panel-2);
  color: var(--text-2);
  border-top-color: var(--line);
  border-left-color: var(--line);
  white-space: normal;
  line-height: 1.15;
  font-size: 11.5px;
  padding: 4px;
}
.jexcel > thead > tr > td.selected { background-color: var(--line); }
.jexcel > tbody > tr > td {
  border-top-color: var(--line-soft);
  border-left-color: var(--line-soft);
  font-size: 12.5px;
  white-space: nowrap;
}
.jexcel > tbody > tr > td:first-child { background-color: var(--panel-2); color: var(--muted); }
.jexcel > tbody > tr.selected > td:first-child { background-color: var(--line); color: var(--text); }
.jexcel > tbody > tr > td.readonly { color: var(--muted); }
.jexcel .highlight, .jexcel .selection { background-color: var(--hover); }
.jexcel .highlight-top { border-top-color: var(--accent); }
.jexcel .highlight-left { border-left-color: var(--accent); }
.jexcel .highlight-right { border-right-color: var(--accent); }
.jexcel .highlight-bottom { border-bottom-color: var(--accent); }
.jexcel .selection-top, .jexcel .selection-left, .jexcel .selection-right, .jexcel .selection-bottom { border-color: var(--muted); }
.jexcel_corner { background-color: var(--accent); border-color: var(--panel); }
.jexcel .jexcel_column_filter { cursor: pointer; font-size: 11px; }
:root[data-theme="dark"] .jexcel .jexcel_column_filter,
:root[data-theme="dark"] .jexcel > thead > tr > td.arrow-up,
:root[data-theme="dark"] .jexcel > thead > tr > td.arrow-down,
:root[data-theme="dark"] .jexcel > tbody > tr > td.jexcel_dropdown { background-blend-mode: normal; filter: none; }
.jexcel > tbody > tr > td input[type="checkbox"] { accent-color: var(--accent); }
.jexcel > tbody > tr > td > input, .jexcel .editor input, .jexcel .editor textarea { background: var(--panel-2); color: var(--text); }
.jexcel_pagination { padding: 8px 10px; font-size: 12px; color: var(--muted); }
.jexcel_pagination > div > div { border-color: var(--line); }
.jexcel_page { cursor: pointer; border-radius: 6px; }
.jexcel_page_selected { background-color: var(--accent) !important; color: var(--accent-ink); font-weight: 600; }
.jcontextmenu, .jdropdown-container, .jdropdown-content, .jdropdown-header, .jcalendar-content {
  background-color: var(--panel-2) !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}
.jcontextmenu > div { color: var(--text); }
.jcontextmenu > div:hover, .jdropdown-item:hover, .jdropdown-cursor { background-color: var(--hover) !important; }
.jcontextmenu hr { border-color: var(--line); }
.jdropdown-item { color: var(--text) !important; }
.jdropdown-header { color: var(--text) !important; }

/* ---------- Phones ---------- */

@media (max-width: 1100px) {
  .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi { border-bottom: 1px solid var(--line); }
  .kpi:nth-child(3n) { border-right: none; }
}

@media (max-width: 720px) {
  body { padding-bottom: 72px; }
  /* Logo + buttons on one line, filters as one swipeable row below; the bar scrolls away. */
  .appbar { position: static; padding: 10px 14px; gap: 8px 12px; }
  .appnav, .appbar-user .user-name, .appbar-spacer { display: none; }
  .brand { flex: 1 1 auto; }
  .appbar-user { order: 1; }
  .filter-row { order: 2; width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .filter-row::-webkit-scrollbar { display: none; }
  .filter-row label { white-space: nowrap; }
  .kpi:last-child:nth-child(even) { grid-column: 1 / -1; }

  /* Narrow tables: keep the columns that matter, scroll sideways if still too wide. */
  .data-table { font-size: 12px; }
  .data-table td:first-child { min-width: 140px; }
  /* Phones keep: product, net revenue, %margin, days left / product, in stock, days left. */
  #productTable th:nth-child(2), #productTable td:nth-child(2),
  #productTable th:nth-child(4), #productTable td:nth-child(4),
  #productTable th:nth-child(6), #productTable td:nth-child(6),
  #productTable th:nth-child(7), #productTable td:nth-child(7),
  #productTable th:nth-child(8), #productTable td:nth-child(8),
  #stockTable th:nth-child(3), #stockTable td:nth-child(3),
  #stockTable th:nth-child(4), #stockTable td:nth-child(4),
  #stockTable th:nth-child(6), #stockTable td:nth-child(6) { display: none; }
  .stock-summary { grid-template-columns: 1fr 1fr; }
  .stock-figure:last-child { grid-column: 1 / -1; }
  .data-table td:first-child { min-width: 0; }
  .data-table th, .data-table td { padding: 7px 5px; }
  .days { gap: 5px; }
  .days-bar { width: 30px; }

  .kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 12px 14px; }
  .kpi:nth-child(3n) { border-right: 1px solid var(--line); }
  .kpi:nth-child(odd):not(.kpi-hero) { border-right: none; }
  .kpi-hero { grid-column: 1 / -1; border-right: none; padding: 18px 16px; }
  .kpi-hero .kpi-value { font-size: 30px; }
  .kpi-value { font-size: 16px; }

  .subbar .tabs { display: none; }
  .subbar { padding: 8px 14px; }
  .split-main { border-right: none; }
  .split-side { order: -1; }
  .section { padding: 14px; }
  .pair { grid-template-columns: 1fr; }
  .pair > .section:first-child { border-right: none; }
  .search { min-width: 0; width: 100%; }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
  }
  .bottom-nav a, .bottom-nav button {
    min-height: 48px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
  }
  .bottom-nav svg { width: 18px; height: 18px; }
  .bottom-nav .active { background: var(--panel-2); color: var(--accent); }

  .ledger-content { padding: 10px 12px; }
  .find-form input { width: 140px; }
  .ledger-status { flex-wrap: wrap; }
}
