:root {
  color-scheme: light;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --surface-2: #f9f9f7;
  --surface-3: #f0efec;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --good-soft: #e5f5e5;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-soft: #fff4dc;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --bad-soft: #fde8e8;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --radius: 10px;
  --sidebar: 236px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #20201f; --surface-3: #2a2a28;
    --border: rgba(255,255,255,0.10); --border-strong: rgba(255,255,255,0.18);
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8d86;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #15263b;
    --good-ink: #3fc23f; --good-soft: #10260f; --warn-ink: #fab219; --warn-soft: #2e2410; --bad-ink: #f07a7a; --bad-soft: #341616;
    --grid: #2c2c2a; --axis: #383835;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #20201f; --surface-3: #2a2a28;
  --border: rgba(255,255,255,0.10); --border-strong: rgba(255,255,255,0.18);
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8d86;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #15263b;
  --good-ink: #3fc23f; --good-soft: #10260f; --warn-ink: #fab219; --warn-soft: #2e2410; --bad-ink: #f07a7a; --bad-soft: #341616;
  --grid: #2c2c2a; --axis: #383835;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.num, td.amt, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; color: #fff; flex: none; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-3); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.sidebar .foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 8px; font-size: 12px; color: var(--muted); }
.main { min-width: 0; padding: 24px 28px 48px; }
.topbar { display: none; }
.scrim { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open .scrim { display: block; }
  .scrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
  .main { padding: 16px 16px 40px; }
}

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px 0; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid.two, .grid.halves { grid-template-columns: minmax(0, 1fr); } }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -0.02em; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.text .value { font-size: 18px; line-height: 1.25; margin-top: 6px; }
.kpi.warn .value { color: var(--warn-ink); }
.kpi.good .value { color: var(--good-ink); }

.sample-banner { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); color: var(--text); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.sample-banner strong { color: var(--warn-ink); }
.alert { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.alert.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.alert.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 40%, transparent); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--text); }
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--text-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
input[type=text], input[type=search], input[type=date], input[type=number], input[type=password], select, textarea {
  border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
label.field input, label.field select, label.field textarea { font-size: 14px; color: var(--text); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: var(--surface); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 11px; cursor: pointer; color: var(--text-2); font-weight: 500; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent-ink); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }

/* ---------- badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.badge.review { background: var(--warn-soft); color: var(--warn-ink); }
.badge.reviewed { background: var(--good-soft); color: var(--good-ink); }
.badge.auto { background: var(--accent-soft); color: var(--accent-ink); }
.badge.refund { background: var(--good-soft); color: var(--good-ink); }
.badge.partial { background: var(--warn-soft); color: var(--warn-ink); }
.badge.sample { background: var(--warn-soft); color: var(--warn-ink); }
.badge.transfer { background: var(--surface-3); color: var(--muted); }
.badge svg { width: 12px; height: 12px; }
.cat-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 220px; }
.cat-chip i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.cat-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; z-index: 1; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }
table.data td.amt, table.data th.amt { text-align: right; white-space: nowrap; }
table.data td.wrap { max-width: 320px; }
table.data .desc { color: var(--text-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
table.data .merchant { font-weight: 600; }
table.data tr.is-refund .amt { color: var(--good-ink); }
table.data tr.is-transfer td { color: var(--muted); }
table.data tr.selected td { background: var(--accent-soft); }
table.data tfoot td { font-weight: 650; background: var(--surface-2); }
.amt-strike { text-decoration: line-through; color: var(--muted); font-size: 12px; display: block; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 12px; }

/* thumbnails */
.thumb { width: 44px; height: 44px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-3); display: grid; place-items: center; overflow: hidden; cursor: zoom-in; flex: none; padding: 0; }
.thumb img, .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.lg { width: 96px; height: 96px; }
.thumb.none { cursor: pointer; border-style: dashed; color: var(--muted); font-size: 10px; line-height: 1.1; text-align: center; padding: 2px; }
.thumb.none:hover { border-color: var(--accent); color: var(--accent-ink); }
.thumb .doc-ic { font-size: 10px; font-weight: 700; color: var(--text-2); }

/* ---------- modal / drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 20px 60px rgba(0,0,0,.3); width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.overlay.drawer { justify-content: flex-end; padding: 0; align-items: stretch; }
.overlay.drawer .modal { width: min(720px, 100%); max-height: 100vh; border-radius: 0; }
.preview-stage { background: var(--surface-3); border-radius: 8px; display: grid; place-items: center; min-height: 300px; overflow: auto; }
.preview-stage img { max-width: 100%; max-height: 75vh; display: block; }
.preview-stage iframe { width: 100%; height: 75vh; border: 0; background: #fff; }
.detail-grid { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 18px; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-preview .big { width: 100%; aspect-ratio: 3/4; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-3); display: grid; place-items: center; overflow: hidden; cursor: zoom-in; }
.detail-preview .big img, .detail-preview .big canvas { width: 100%; height: 100%; object-fit: contain; }
.detail-preview .big.none { cursor: default; color: var(--muted); text-align: center; padding: 12px; font-size: 12px; border-style: dashed; }
.history { font-size: 12px; color: var(--text-2); }
.history li { margin-bottom: 4px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; margin: 18px 0 8px; }

/* ---------- toast ---------- */
#toast-root { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; display: flex; gap: 10px; align-items: center; }
.toast.bad { background: var(--bad); color: #fff; }
.toast button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 6px; padding: 2px 8px; cursor: pointer; }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 280px; padding: 8px 14px 14px; }
.chart-box.tall { height: 360px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); padding: 8px 18px 0; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.bar-list { padding: 8px 18px 16px; display: flex; flex-direction: column; gap: 9px; }
.bar-item { display: grid; grid-template-columns: minmax(110px, 180px) minmax(0, 1fr) 90px; gap: 10px; align-items: center; font-size: 13px; cursor: pointer; border-radius: 6px; }
.bar-item:hover .bar-name { color: var(--accent-ink); }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { height: 10px; background: var(--surface-3); border-radius: 0 4px 4px 0; overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- import ---------- */
.dropzone { border: 2px dashed var(--border-strong); border-radius: 12px; padding: 36px 20px; text-align: center; background: var(--surface); transition: .15s; cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone svg { width: 40px; height: 40px; color: var(--accent); }
.file-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; }
.result-file { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.result-file ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 12px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); padding: 28px; }
.auth-card .brand { padding: 0 0 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card .err { color: var(--bad-ink); font-size: 13px; min-height: 18px; }

/* Amazon */
.amz-group { margin-bottom: 0; }
.amz-group-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: 600; }
.img-missing { display: inline-flex; align-items: center; gap: 4px; color: var(--warn-ink); font-size: 11.5px; font-weight: 600; }
.split-row { display: grid; grid-template-columns: minmax(0, 1fr) 160px 120px 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 600px) { .split-row { grid-template-columns: 1fr 1fr; } }
.cand { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor: pointer; }
.cand:hover { border-color: var(--accent); }
