/* ============================================================
   Shopee Insight
   Operator console. Cool neutral field, one warm accent.
   Tokens and rules follow DESIGN.md.
   ============================================================ */

/* ---------- Tokens: light ---------- */
:root {
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #fafbfc;
  --surface-3:   #f0f2f5;
  --line:        #e3e6ea;
  --line-strong: #cfd4db;
  --text:        #14161a;
  --text-2:      #5b626e;
  --text-3:      #68707d;

  /* Three roles for one brand colour:
     --accent        surfaces and marks, where 3:1 is the bar
     --accent-strong fills that carry white label text, where 4.5:1 is the bar
     --accent-ink    accent-coloured text on a light ground */
  --accent:        #ee4d2d;
  --accent-strong: #d8391b;
  --accent-press:  #c62f15;
  --accent-ink:    #c03418;
  --accent-soft:   #fff1ed;
  --accent-line:   #f8c3b5;
  --on-accent:     #ffffff;

  --pos:  #0a7049;
  --neg:  #c22c25;
  --warn: #8a5608;
  --info: #2454c2;

  --pos-soft:  #e7f6ef;
  --neg-soft:  #fdedec;
  --warn-soft: #fdf3e2;
  --info-soft: #ecf1fd;

  --sh-1: 0 1px 2px rgba(16, 20, 28, .06), 0 1px 1px rgba(16, 20, 28, .04);
  --sh-2: 0 8px 24px -6px rgba(16, 20, 28, .14), 0 2px 6px -2px rgba(16, 20, 28, .08);
  --ring: 0 0 0 3px rgba(238, 77, 45, .22);

  /* chart ramp: neutral to accent, never seven brand colours */
  --c1: #ee4d2d; --c2: #f5804f; --c3: #7f8794; --c4: #a9b0bb; --c5: #2b62d9;

  --r-panel: 14px;
  --r-ctl:   10px;
  --r-pill:  999px;

  --ease:      cubic-bezier(.23, 1, .32, 1);
  --ease-move: cubic-bezier(.77, 0, .175, 1);

  --gut: 24px;
  --rail-w: 320px;

  color-scheme: light;
}

/* ---------- Tokens: dark ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0e1013;
    --surface:     #16191e;
    --surface-2:   #1b1f26;
    --surface-3:   #21262e;
    --line:        #262b33;
    --line-strong: #39404b;
    --text:        #eceef2;
    --text-2:      #a3aab6;
    --text-3:      #858d9a;

    --accent:        #ff6a45;
    --accent-strong: #ff6a45;
    --accent-press:  #ef5c37;
    --accent-ink:    #ff6a45;
    --accent-soft:   #2a1a15;
    --accent-line:   #5a3324;
    --on-accent:     #1a0d08;

    --pos:  #3ecf8e;
    --neg:  #ff6f6a;
    --warn: #e0a33c;
    --info: #6f9bff;

    --pos-soft:  #13291f;
    --neg-soft:  #2c1719;
    --warn-soft: #2b2114;
    --info-soft: #161f33;

    --sh-1: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 1px rgba(0, 0, 0, .30);
    --sh-2: 0 10px 24px -8px rgba(0, 0, 0, .60), 0 3px 8px -3px rgba(0, 0, 0, .45);
    --ring: 0 0 0 3px rgba(255, 106, 69, .26);

    --c1: #ff6a45; --c2: #ff9670; --c3: #8e96a4; --c4: #5d6472; --c5: #6f9bff;

    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg:          #0e1013;
  --surface:     #16191e;
  --surface-2:   #1b1f26;
  --surface-3:   #21262e;
  --line:        #262b33;
  --line-strong: #39404b;
  --text:        #eceef2;
  --text-2:      #a3aab6;
  --text-3:      #858d9a;

  --accent:        #ff6a45;
  --accent-strong: #ff6a45;
  --accent-press:  #ef5c37;
  --accent-ink:    #ff6a45;
  --accent-soft:   #2a1a15;
  --accent-line:   #5a3324;
  --on-accent:     #1a0d08;

  --pos:  #3ecf8e;
  --neg:  #ff6f6a;
  --warn: #e0a33c;
  --info: #6f9bff;

  --pos-soft:  #13291f;
  --neg-soft:  #2c1719;
  --warn-soft: #2b2114;
  --info-soft: #161f33;

  --sh-1: 0 1px 2px rgba(0, 0, 0, .40), 0 1px 1px rgba(0, 0, 0, .30);
  --sh-2: 0 10px 24px -8px rgba(0, 0, 0, .60), 0 3px 8px -3px rgba(0, 0, 0, .45);
  --ring: 0 0 0 3px rgba(255, 106, 69, .26);

  --c1: #ff6a45; --c2: #ff9670; --c3: #8e96a4; --c4: #5d6472; --c5: #6f9bff;

  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }

/* Class-level display rules must never beat the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: .875rem;
  font-weight: 500;
  line-height: 1.55;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p, ul, ol, figure, figcaption { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
img, canvas, svg { max-width: 100%; }
table { border-collapse: collapse; }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sprite symbol { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Browser surfaces ---------- */
::selection { background: var(--accent-strong); color: var(--on-accent); }

:where(a, button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

input { caret-color: var(--accent); accent-color: var(--accent); }

* { scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid var(--bg);
  border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ---------- Type scale ---------- */
.lbl {
  display: block;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}

.hint, .pane-note, .foot-note { font-size: .8125rem; color: var(--text-2); }
.num { text-align: right; }

/* Names each tab panel for screen readers and keeps the heading order intact;
   the tab label already carries the name visually. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
  transition: box-shadow 180ms var(--ease);
}
.topbar.is-stuck { box-shadow: var(--sh-2); }

.topbar-in {
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 var(--gut);
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: var(--accent);
  display: grid; place-items: center;
  box-shadow: var(--sh-1);
}
.brand-mark svg { width: 30px; height: 30px; fill: var(--on-accent); }
.brand-name { font-size: 1rem; font-weight: 800; letter-spacing: -.02em; }

.topbar-meta {
  display: flex; align-items: center; gap: 10px;
  margin-left: 4px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
  font-size: .8125rem;
  color: var(--text-2);
}
.topbar-meta .sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-3); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--r-ctl);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  font-size: .8125rem;
  font-weight: 700;
  letter-spacing: -.005em;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease),
              color 140ms var(--ease), transform 120ms var(--ease), box-shadow 140ms var(--ease);
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-sm { height: 34px; padding: 0 12px; font-size: .78125rem; }
.btn-icon { width: 38px; padding: 0; }

.btn-primary { background: var(--accent-strong); color: var(--on-accent); box-shadow: var(--sh-1); }
.btn-primary:active { background: var(--accent-press); }

.btn-quiet { background: var(--surface); border-color: var(--line); color: var(--text); }

.btn-ghost { color: var(--text-2); padding: 0 10px; }
.btn-danger { color: var(--neg); }

@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: var(--accent-press); box-shadow: var(--sh-2); }
  .btn-quiet:hover { border-color: var(--line-strong); background: var(--surface-2); }
  .btn-ghost:hover { color: var(--text); background: var(--surface-3); }
  .btn-danger:hover { color: var(--neg); background: var(--neg-soft); }
}

/* theme icon swap */
.ico-dark { display: none; }
:root[data-theme="dark"] .ico-light { display: none; }
:root[data-theme="dark"] .ico-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico-light { display: none; }
  :root:not([data-theme="light"]) .ico-dark { display: block; }
}

/* ============================================================
   SHELL
   ============================================================ */
.shell {
  max-width: 1560px;
  margin: 0 auto;
  padding: 24px var(--gut) 56px;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.rail {
  display: grid;
  /* minmax(0,...) lets the track shrink below its content min-width, so wide
     children (date inputs carry a large intrinsic minimum) clip and wrap
     instead of spilling over the results column. */
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  position: sticky;
  top: 84px;
}

.results { min-width: 0; }
.shell > * { min-width: 0; }

@media (max-width: 1079px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
}
@media (max-width: 640px) {
  :root { --gut: 16px; }
  .shell { padding-top: 16px; gap: 16px; }
  .rail { grid-template-columns: minmax(0, 1fr); }
  .topbar-meta { display: none; }
  #btnDemo span, #btnGuide span { display: none; }
  #btnDemo, #btnGuide { width: 38px; padding: 0; }
  .topbar-in { gap: 8px; }
  .topbar-actions { gap: 4px; }
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 18px;
}
.panel-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -.015em;
  margin-bottom: 14px;
}
.panel-main { padding: 0; overflow: hidden; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--surface-2);
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms var(--ease), background-color 160ms var(--ease), transform 120ms var(--ease);
}
.dropzone:active { transform: scale(.99); }
.dropzone.is-over {
  border-color: var(--accent);
  border-style: solid;
  background: var(--accent-soft);
}
@media (hover: hover) and (pointer: fine) {
  .dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
}
.dz-ico { width: 26px; height: 26px; color: var(--text-3); fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.dropzone.is-over .dz-ico, .dropzone:hover .dz-ico { color: var(--accent-ink); }
.dz-title { margin-top: 8px; font-weight: 700; }
.dz-sub { font-size: .8125rem; color: var(--text-2); }
.link { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1.5px; }

.hint { margin-top: 10px; }

.filelist { margin-top: 12px; display: grid; gap: 6px; }
.filelist:empty { margin-top: 0; }
.filelist li {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  font-size: .8125rem;
}
.filelist .ico { color: var(--pos); }
.filelist .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .frows { color: var(--text-3); font-size: .75rem; }

.privacy {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex; gap: 8px;
  font-size: .78125rem;
  color: var(--text-2);
  line-height: 1.5;
}
.privacy .ico { color: var(--pos); margin-top: 1px; }

/* ---------- Fields ---------- */
/* Stacked fields get vertical rhythm, but the two fields sitting side by side
   inside .field-2 are grid siblings and must stay on the same baseline. */
.field + .field, .field-2 + .field, .field + .field-2 { margin-top: 14px; }
.field-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: end; }
.field-2 > .field + .field { margin-top: 0; }

.input-grp {
  display: flex; align-items: center;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.input-grp:focus-within { border-color: var(--line-strong); box-shadow: var(--ring); }
.input-grp input {
  flex: 1; min-width: 0;
  height: 100%;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.input-grp input:focus { outline: none; }
.input-grp input::-webkit-outer-spin-button,
.input-grp input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input-grp input[type=number] { -moz-appearance: textfield; }
.affix {
  padding: 0 10px;
  font-size: .8125rem;
  font-weight: 700;
  color: var(--text-3);
  background: var(--surface-2);
  align-self: stretch;
  display: grid; place-items: center;
  border-left: 1px solid var(--line);
}
.affix-pre { border-left: 0; border-right: 1px solid var(--line); }

.slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  margin-top: 12px;
  border-radius: var(--r-pill);
  background: var(--line);
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--sh-1);
  transition: transform 120ms var(--ease);
}
.slider:active::-webkit-slider-thumb { transform: scale(1.15); }
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
}

.readout {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--r-ctl);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .8125rem;
  color: var(--text-2);
}
.readout b { color: var(--text); }

/* ---------- Switch ---------- */
.switch {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0;
  cursor: pointer;
  font-size: .8125rem;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  flex: none;
  width: 34px; height: 20px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  transition: background-color 160ms var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .28);
  transition: transform 160ms var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch-text { color: var(--text-2); }
.switch input:checked ~ .switch-text { color: var(--text); }

.field-dates { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.daterow { display: flex; align-items: center; gap: 8px; }
.daterow input {
  flex: 1 1 0; min-width: 0; width: 100%;
  height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--surface);
  font-size: .8125rem;
  font-weight: 600;
}
.daterow input:focus { outline: none; border-color: var(--line-strong); box-shadow: var(--ring); }
.daterow .to { width: 8px; height: 1px; background: var(--text-3); flex: none; }
.field-dates .btn { margin-top: 10px; }
#btnReset { margin-top: 14px; width: 100%; justify-content: flex-start; }

/* ============================================================
   EMPTY STATE
   ============================================================ */
.onboard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  padding: 44px var(--gut);
}
.onboard-in { max-width: 62ch; }
.onboard h1 {
  font-size: 1.625rem;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.25;
}
.onboard > .onboard-in > p { margin-top: 12px; color: var(--text-2); }

.steps { margin-top: 28px; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.steps li {
  background: var(--surface);
  padding: 14px 16px;
  display: grid;
  gap: 3px;
}
.steps b { font-size: .875rem; font-weight: 700; }
.steps span { font-size: .8125rem; color: var(--text-2); }
.onboard .btn-primary { margin-top: 24px; }

/* ============================================================
   SKELETON
   ============================================================ */
.skeleton { display: grid; gap: 20px; }
.sk-kpi { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-panel); overflow: hidden; }
.sk-kpi i { display: block; height: 92px; background: var(--surface); }
.sk-panel { border: 1px solid var(--line); border-radius: var(--r-panel); background: var(--surface); overflow: hidden; }
.sk-bar { height: 52px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.sk-rows { padding: 14px 18px; display: grid; gap: 12px; }
.sk-rows i { display: block; height: 14px; border-radius: 5px; background: var(--surface-3); }
.sk-kpi i, .sk-rows i { position: relative; overflow: hidden; }
.sk-kpi i::after, .sk-rows i::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 7%, transparent), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
@media (max-width: 900px) { .sk-kpi { grid-template-columns: repeat(2, 1fr); } }

/* ============================================================
   KPI STRIP
   ============================================================ */
.kpi {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  overflow: hidden;
  margin-bottom: 20px;
}
.kpi-cell { background: var(--surface); padding: 16px 18px; min-width: 0; }
.kpi-lbl {
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-2);
}
.kpi-val {
  margin-top: 6px;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kpi-sub { margin-top: 3px; font-size: .75rem; color: var(--text-3); }
.kpi-val.is-pos { color: var(--pos); }
.kpi-val.is-neg { color: var(--neg); }
.kpi-val.is-warn { color: var(--warn); }

@media (max-width: 1360px) { .kpi { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi-val { font-size: 1.25rem; } }

/* ============================================================
   TABS
   ============================================================ */
.tabbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.tabs {
  position: relative;
  display: flex;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  flex: none;
  height: 50px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: color 140ms var(--ease);
}
.tab.is-on { color: var(--text); }
@media (hover: hover) and (pointer: fine) { .tab:not(.is-on):hover { color: var(--text); } }
.tab .count {
  display: inline-grid; place-items: center;
  min-width: 19px; height: 19px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: .6875rem;
  font-weight: 700;
}
.tab.is-on .count { background: var(--accent-soft); color: var(--accent-ink); }
/* Fixed 100px base scaled on the compositor: animating width would relayout
   the tab strip on every switch. */
.tab-ind {
  position: absolute;
  left: 0; bottom: 0;
  height: 2px;
  width: 100px;
  transform-origin: left center;
  transform: translateX(0) scaleX(0);
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transition: transform 220ms var(--ease-move);
}
.tabbar > .btn { margin: 8px 0; }

.pane { display: none; padding: 18px; }
.pane.is-on { display: block; animation: paneIn 200ms var(--ease); }
@keyframes paneIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.pane-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.pane-note { max-width: 68ch; }

.searchbox {
  position: relative;
  flex: none;
  width: min(280px, 42vw);
}
.searchbox .ico {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
.searchbox input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--surface);
  font-size: .8125rem;
  font-weight: 600;
}
.searchbox input::placeholder { color: var(--text-3); }
.searchbox input:focus { outline: none; border-color: var(--line-strong); box-shadow: var(--ring); }
.searchbox input::-webkit-search-cancel-button { -webkit-appearance: none; }

@media (max-width: 700px) {
  .pane-head { flex-direction: column; }
  .searchbox { width: 100%; }
  .pane { padding: 14px; }
}

/* ============================================================
   TABLES
   ============================================================ */
.tablewrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 620px;
  background: var(--surface);
}
.tablewrap-cap { max-height: 300px; }

.tbl { width: 100%; font-size: .8125rem; }
.tbl thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  font-size: .6875rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-2);
  white-space: nowrap;
}
.tbl thead th.num { text-align: right; }
.tbl th.sortable { cursor: pointer; user-select: none; transition: color 140ms var(--ease); }
@media (hover: hover) and (pointer: fine) { .tbl th.sortable:hover { color: var(--text); } }
.tbl th.sortable::after {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 3.5px solid transparent;
  border-right: 3.5px solid transparent;
  border-bottom: 4.5px solid currentColor;
  opacity: .28;
  transition: opacity 140ms var(--ease), transform 160ms var(--ease);
}
.tbl th.sortable.asc::after { opacity: 1; color: var(--accent); }
.tbl th.sortable.desc::after { opacity: 1; color: var(--accent); transform: rotate(180deg); }

.tbl tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  white-space: nowrap;
}
.tbl tbody td.cell-name { white-space: normal; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background-color 120ms var(--ease); }
@media (hover: hover) and (pointer: fine) { .tbl tbody tr:hover { background: var(--surface-2); } }
.tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .c-idx { width: 46px; color: var(--text-3); text-align: right; }
.tbl td.c-idx { color: var(--text-3); }
.tbl .cell-strong { font-weight: 700; }
.tbl .cell-pos { color: var(--pos); font-weight: 700; }
.tbl .cell-neg { color: var(--neg); }
.tbl .cell-fee { color: var(--warn); }
/* The product column is the one that wraps; give it room so rows stay short.
   The table scrolls inside its own container, so a minimum here is safe. */
.tbl .cell-name { min-width: 210px; max-width: 340px; }
.tbl .cell-sub { display: block; font-size: .75rem; color: var(--text-3); }
.tbl-tight tbody td, .tbl-tight thead th { padding: 7px 10px; }

.tbl .empty-row td {
  padding: 34px 12px;
  text-align: center;
  color: var(--text-3);
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 21px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  font-size: .6875rem;
  font-weight: 700;
  white-space: nowrap;
}
.chip-ok   { background: var(--pos-soft);  color: var(--pos); }
.chip-bad  { background: var(--neg-soft);  color: var(--neg); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-info { background: var(--info-soft); color: var(--info); }
.chip-mute { background: var(--surface-3); color: var(--text-2); }

.delta { font-weight: 700; }
.delta-up { color: var(--pos); }
.delta-down { color: var(--neg); }
.delta-flat { color: var(--text-3); }

.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bar-cell .bar { width: 42px; height: 4px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; flex: none; }
.bar-cell .bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- Pager ---------- */
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font-size: .8125rem;
  color: var(--text-2);
}
.pager .spacer { flex: 1; }
.pager button {
  height: 32px;
  min-width: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 140ms var(--ease), background-color 140ms var(--ease), transform 120ms var(--ease);
}
.pager button:active { transform: scale(.96); }
.pager button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.pager button.is-on { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--on-accent); }
@media (hover: hover) and (pointer: fine) {
  .pager button:not(:disabled):not(.is-on):hover { border-color: var(--line-strong); background: var(--surface-2); }
}

/* ============================================================
   CHARTS
   ============================================================ */
.chartrow {
  display: grid;
  /* min() keeps the track from exceeding a narrow container and forcing
     the page to scroll sideways. */
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.chart {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 16px;
  min-width: 0;
}
.chart-wide { margin-bottom: 18px; }
.chart figcaption, .chart-h {
  font-size: .875rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 12px;
}
.chart .pane-note { margin-top: -6px; margin-bottom: 12px; }
.cv { position: relative; height: 220px; }
.cv-tall { height: 280px; }
.cv-xl { height: 340px; }

/* ---------- Events ---------- */
.events { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.events li { background: var(--surface); padding: 11px 13px; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline; }
.events .ev-name { font-weight: 700; font-size: .8125rem; }
.events .ev-when { font-size: .75rem; color: var(--text-2); white-space: nowrap; }
.events .ev-tip { grid-column: 1 / -1; font-size: .75rem; color: var(--text-3); }
.events .ev-soon { color: var(--accent-ink); }

/* ---------- Mapping ---------- */
.mapgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.mapcell { display: grid; gap: 6px; }
.mapcell select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  background: var(--surface);
  font-size: .8125rem;
  font-weight: 600;
  cursor: pointer;
}
.mapcell select:focus { outline: none; border-color: var(--line-strong); box-shadow: var(--ring); }
.mapcell .mapstate { font-size: .75rem; }
.mapstate.ok { color: var(--pos); }
.mapstate.missing { color: var(--warn); }

/* ---------- Log ---------- */
.log {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  padding: 12px 14px;
  max-height: 320px;
  overflow: auto;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .75rem;
  line-height: 1.7;
}
.log div { display: grid; grid-template-columns: 62px 1fr; gap: 10px; }
.log .t { color: var(--text-3); }
.log .lv-info b { color: var(--info); }
.log .lv-ok b { color: var(--pos); }
.log .lv-warn b { color: var(--warn); }
.log .lv-err b { color: var(--neg); }

/* ============================================================
   FOOTER
   ============================================================ */
.foot {
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 var(--gut) 40px;
  color: var(--text-2);
  font-size: .8125rem;
}
.foot-note { color: var(--text-3); margin-top: 2px; }

/* ============================================================
   TOASTS
   ============================================================ */
.toasts {
  position: fixed;
  right: 20px; bottom: 20px;
  z-index: 90;
  display: grid;
  gap: 8px;
  justify-items: end;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: var(--r-ctl);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--sh-2);
  font-size: .8125rem;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
}
.toast.is-out { opacity: 0; transform: translateY(8px) scale(.97); }
@starting-style { .toast { opacity: 0; transform: translateY(8px) scale(.97); } }
.toast .ico { margin-top: 1px; }
.toast.t-ok .ico { color: var(--pos); }
.toast.t-warn .ico { color: var(--warn); }
.toast.t-err .ico { color: var(--neg); }

/* ============================================================
   GUIDE DIALOG
   A modal is right here: the guide is occasional and wants
   protected focus while it is open.
   ============================================================ */
.onboard-actions { margin-top: 24px; display: flex; flex-wrap: wrap; gap: 10px; }
.onboard .btn-primary { margin-top: 0; }

.guide {
  width: min(760px, calc(100vw - 32px));
  max-height: min(84vh, 860px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-panel);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--sh-2);
  overflow: hidden;
}
.guide::backdrop { background: rgba(10, 12, 16, .55); backdrop-filter: blur(3px); }

/* Modals stay centred: they are not anchored to a trigger. */
.guide[open] { animation: guideIn 220ms var(--ease); }
.guide[open]::backdrop { animation: fadeIn 220ms var(--ease); }
@keyframes guideIn { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.guide-card { display: flex; flex-direction: column; max-height: inherit; }

.guide-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 16px 16px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
.guide-head h2 { font-size: 1.125rem; font-weight: 800; letter-spacing: -.02em; }

.guide-body { padding: 4px 22px 26px; overflow-y: auto; }
.guide-body section { padding-top: 24px; }
.guide-body section + section { border-top: 1px solid var(--line); }
.guide-body h3 {
  font-size: .9375rem;
  font-weight: 700;
  letter-spacing: -.01em;
  margin-bottom: 8px;
}
.guide-body p { color: var(--text-2); max-width: 68ch; }
.guide-body p + p { margin-top: 8px; }
.guide-body b { color: var(--text); font-weight: 700; }
.guide-body code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .8125em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-3);
}

.guide-ol, .guide-ul { margin-top: 8px; display: grid; gap: 6px; color: var(--text-2); max-width: 68ch; }
.guide-ol { counter-reset: g; }
.guide-ol li { position: relative; padding-left: 26px; counter-increment: g; }
.guide-ol li::before {
  content: counter(g);
  position: absolute; left: 0; top: 2px;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: .6875rem;
  font-weight: 700;
}
.guide-ul li { position: relative; padding-left: 18px; }
.guide-ul li::before {
  content: "";
  position: absolute; left: 4px; top: 9px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--text-3);
}

.guide-tip {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--r-ctl);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: .8125rem;
}

.guide-dl { margin-top: 8px; display: grid; gap: 2px; }
.guide-dl dt { font-weight: 700; font-size: .8125rem; margin-top: 12px; }
.guide-dl dt:first-child { margin-top: 0; }
.guide-dl dd { margin: 0; color: var(--text-2); font-size: .8125rem; max-width: 68ch; }

@media (max-width: 560px) {
  .guide-body { padding: 4px 16px 22px; }
  .guide-head { padding-left: 16px; }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
  .btn:active, .dropzone:active, .pager button:active { transform: none; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  .topbar, .rail, .tabbar, .pager, .toasts, .foot { display: none !important; }
  .shell { display: block; padding: 0; }
  .panel, .chart, .tablewrap { border-color: #ccc; break-inside: avoid; }
  .tablewrap { max-height: none; }
  .pane { display: block !important; }
}
