:root {
  color-scheme: light;
  --page: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #6b3fa0;
  --accent-ink: #ffffff;
  --accent-soft: #efe8f7;
  --good: #006300;
  --bad: #b42323;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --seq-0: #f0efec; --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95; --seq-7: #0d366b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #b893e6; --accent-ink: #160b24; --accent-soft: #2a2236;
    --good: #0ca30c; --bad: #e66767;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-0: #232321; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf; --seq-5: #2a78d6; --seq-6: #5598e7; --seq-7: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #b893e6; --accent-ink: #160b24; --accent-soft: #2a2236;
  --good: #0ca30c; --bad: #e66767;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-0: #232321; --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #256abf; --seq-5: #2a78d6; --seq-6: #5598e7; --seq-7: #9ec5f4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--page); color: var(--ink); }
body { font-size: 14px; line-height: 1.45; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-row { display: flex; align-items: center; gap: 16px; padding: 10px 20px; max-width: 1480px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; }
.brand-name { font-weight: 650; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }
.sync-pill { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); cursor: pointer; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: #0ca30c; } .dot.run { background: #fab219; animation: pulse 1.2s infinite; } .dot.err { background: #d03b3b; }
@keyframes pulse { 50% { opacity: .35; } }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 8px; padding: 5px 9px; cursor: pointer; font: inherit; font-size: 12px; text-decoration: none; }

.tabs { display: flex; gap: 2px; padding: 0 20px; max-width: 1480px; margin: 0 auto; overflow-x: auto; scrollbar-width: none; }
.tab { border: none; background: none; font: inherit; color: var(--ink-2); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 20px; max-width: 1480px; margin: 0 auto; border-top: 1px solid var(--border); }
.filters label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: none; background: none; font: inherit; font-size: 12px; padding: 5px 10px; color: var(--ink-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
input[type=date], select, input[type=text], input[type=password], input[type=search] {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.range-note { font-size: 12px; color: var(--muted); }

main { max-width: 1480px; margin: 0 auto; padding: 18px 20px 60px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.section-head h1 { font-size: 20px; }
.section-head p { margin: 4px 0 0; color: var(--ink-2); max-width: 820px; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
@media (max-width: 1100px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .g2, .g3, .g4 { grid-template-columns: minmax(0, 1fr); } .span2 { grid-column: auto; }
  .topbar-row, .filters, .tabs, main { padding-left: 16px; padding-right: 16px; }
  .brand-sub { display: none; }
  #syncText { display: none; }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-head h3 { font-size: 14px; }
.card-head .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card-tools { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 200px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .label { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 4px; }
.kpi .value.small { font-size: 14px; white-space: normal; line-height: 1.35; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .delta { font-size: 12px; margin-top: 2px; color: var(--muted); }
.delta .up { color: var(--good); } .delta .down { color: var(--bad); }
.kpi .foot { font-size: 11px; color: var(--muted); margin-top: 2px; }
.info { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; border: 1px solid var(--axis); color: var(--muted); font-size: 9px; cursor: help; font-style: normal; }

/* tables */
.table-wrap { overflow: auto; max-height: 520px; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--ink-2); font-weight: 600; cursor: pointer; user-select: none; z-index: 1; }
th.n, td.n { text-align: right; }
td.wrap { white-space: normal; min-width: 220px; }
tbody tr:hover { background: var(--surface-2); }
th .arrow { color: var(--muted); font-size: 10px; }
.table-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.table-tools input[type=search] { width: 220px; }

/* heatmaps */
.heat { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 11.5px; }
.heat th, .heat td { border: none; padding: 5px 4px; text-align: center; position: static; cursor: default; }
.heat th { background: none; color: var(--muted); font-weight: 500; }
.heat td { border-radius: 4px; font-variant-numeric: tabular-nums; min-width: 38px; }
.heat td.empty { background: transparent; }
.heat th.rowhead { text-align: left; white-space: nowrap; }
.heat-wrap { overflow: auto; }
.scale { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 8px; }
.scale span.sw { display: inline-block; width: 22px; height: 10px; border-radius: 2px; }

/* buttons */
.btn { font: inherit; font-size: 13px; border-radius: 8px; padding: 7px 12px; border: 1px solid var(--border); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-sm { font-size: 12px; padding: 4px 9px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* segments */
.seg-card h3 { font-size: 15px; }
.seg-card .goal { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; margin-top: 6px; }
.seg-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.seg-stats div { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.seg-stats b { display: block; font-size: 15px; }
.seg-stats span { font-size: 11px; color: var(--muted); }
.seg-card p { margin: 6px 0; color: var(--ink-2); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.chip { font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.reco h4 { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.reco ul { margin: 4px 0 0; padding-left: 18px; font-size: 13px; }
.reco li { margin: 2px 0; }

/* campaign results */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.form-grid input, .form-grid select { width: 100%; font-weight: 400; padding: 7px 9px; }
.drop { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px dashed var(--axis); border-radius: 10px; padding: 14px; background: var(--surface-2); }
.file-stats { align-self: end; font-size: 13px; padding-bottom: 6px; }
.window-bar { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; }
.window-bar input { padding: 4px 6px; }

.kpis.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .kpis.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* misc */
.empty-state, .error-state { padding: 40px 20px; text-align: center; color: var(--ink-2); background: var(--surface); border: 1px dashed var(--axis); border-radius: var(--radius); }
.error-state { border-color: #d03b3b; }
.loading { padding: 50px; text-align: center; color: var(--muted); }
.note { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; margin: 0 0 14px; }
.note.warn { border-left: 3px solid #fab219; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
pre.log { background: var(--surface-2); border-radius: 8px; padding: 10px; font-size: 12px; max-height: 360px; overflow: auto; white-space: pre-wrap; }
.status { font-size: 12px; font-weight: 600; }
.status.success { color: var(--good); } .status.failed, .status.interrupted { color: var(--bad); } .status.running, .status.partial { color: #b07900; }
.glossary dt { font-weight: 600; margin-top: 8px; }
.glossary dd { margin: 2px 0 0; color: var(--ink-2); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--page); }
.login-shell { padding: 0; margin: 0; width: 100%; max-width: 880px; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,0.06); }
.login-side { background: linear-gradient(160deg, #6b3fa0 0%, #3f2266 100%); color: #fff; padding: 36px 36px 28px; display: flex; flex-direction: column; gap: 22px; }
.login-side .brand-mark { background: rgba(255,255,255,0.18); color: #fff; }
.login-side .brand-sub { color: rgba(255,255,255,0.7); }
.login-side h1 { font-size: 26px; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; margin-top: 18px; }
.login-points { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; color: rgba(255,255,255,0.88); font-size: 14px; }
.login-points li { padding-left: 22px; position: relative; }
.login-points li::before { content: ""; position: absolute; left: 0; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: #e8c27a; }
.login-foot { margin-top: auto; font-size: 12px; color: rgba(255,255,255,0.6); }
.login-card { padding: 40px 36px; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
.login-card h2 { font-size: 22px; }
.login-help { margin: 0 0 10px; color: var(--ink-2); font-size: 13px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.pw-wrap { position: relative; }
.pw-wrap input { width: 100%; font-size: 15px; padding: 11px 64px 11px 12px; border-radius: 10px; }
.pw-wrap input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: none; font: inherit; font-size: 12px; color: var(--accent); cursor: pointer; padding: 6px 8px; }
.login-btn { justify-content: center; font-size: 15px; padding: 11px 14px; margin-top: 6px; border-radius: 10px; }
.login-error { color: var(--bad); font-size: 13px; margin: 0; }
@media (max-width: 720px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-side { padding: 24px; gap: 14px; }
  .login-side h1 { font-size: 20px; margin-top: 6px; }
  .login-points, .login-foot { display: none; }
  .login-card { padding: 28px 24px; }
}
