:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface-1: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text-primary: #191919;
  --text-secondary: #666666;
  --accent: #2370cd;
  --accent-ink: #ffffff;
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #ececec;
  --good: #0a7d24;
  --good-bg: #e7f6ea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --bad: #b42318;
  --bad-bg: #fde8e7;
  --info-bg: #e8f1fc;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111213; --surface-1: #191919; --surface-2: #222324; --border: #2e3033;
    --text-primary: #efefef; --text-secondary: #9c9c9c; --accent: #338ced; --accent-ink: #0b0b0b;
    --series-1: #338ced; --series-2: #e76624; --grid: #2a2a2a;
    --good: #5fd37a; --good-bg: #14301b; --warn: #f2c14e; --warn-bg: #33290f; --bad: #ff8a80; --bad-bg: #3a1714; --info-bg: #15263b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111213; --surface-1: #191919; --surface-2: #222324; --border: #2e3033;
  --text-primary: #efefef; --text-secondary: #9c9c9c; --accent: #338ced; --accent-ink: #0b0b0b;
  --series-1: #338ced; --series-2: #e76624; --grid: #2a2a2a;
  --good: #5fd37a; --good-bg: #14301b; --warn: #f2c14e; --warn-bg: #33290f; --bad: #ff8a80; --bad-bg: #3a1714; --info-bg: #15263b;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface-1); border-right: 1px solid var(--border); padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 17px; padding: 4px 10px 14px; letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; color: var(--text-primary); text-decoration: none; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--info-bg); color: var(--accent); font-weight: 600; }
.badge-count { background: var(--accent); color: var(--accent-ink); border-radius: 999px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.side-foot { margin-top: auto; padding: 10px; display: grid; gap: 8px; }
.main { padding: 20px 28px 40px; max-width: 1180px; width: 100%; }
.topbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; letter-spacing: -.01em; }
.sync { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; }

/* controls */
.btn { border: 1px solid var(--border); background: var(--surface-1); padding: 7px 12px; border-radius: 8px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
textarea { width: 100%; resize: vertical; min-height: 64px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, .nav a:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* cards */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .grow { flex: 1; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 14px; }
.two { grid-template-columns: 3fr 2fr; }
.kpi .label { color: var(--text-secondary); font-size: 12px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { color: var(--text-secondary); font-size: 12px; margin-top: 4px; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th.num { text-align: right; }
.scroll { overflow-x: auto; }

/* chips & status */
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); background: var(--surface-1); cursor: pointer; }
.chip:hover { background: var(--surface-2); }
.status { display: inline-flex; align-items: center; gap: 4px; border-radius: 6px; padding: 1px 7px; font-size: 12px; font-weight: 600; }
.status.pending { background: var(--warn-bg); color: var(--warn); }
.status.approved { background: var(--info-bg); color: var(--accent); }
.status.posted { background: var(--good-bg); color: var(--good); }
.status.failed, .status.rejected { background: var(--bad-bg); color: var(--bad); }
.note { border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 6px 0; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.note.good { background: var(--good-bg); color: var(--good); }
.note.info { background: var(--info-bg); }

/* chat */
.chat { display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); padding: 9px 13px; border-radius: 14px 14px 4px 14px; }
.msg.bot { background: var(--surface-1); border: 1px solid var(--border); padding: 12px 14px; border-radius: 14px 14px 14px 4px; box-shadow: var(--shadow); }
.msg.bot .text { white-space: pre-wrap; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--text-secondary); }
.tier { border-radius: 6px; padding: 1px 7px; font-weight: 600; background: var(--surface-2); color: var(--text-primary); }
.tier.agent { background: var(--info-bg); color: var(--accent); }
.verified { color: var(--good); font-weight: 600; }
.unverified { color: var(--warn); font-weight: 600; }
details summary { cursor: pointer; color: var(--text-secondary); font-size: 12px; }
.composer { position: sticky; bottom: 0; background: var(--bg); padding-top: 12px; }
.composer form { display: flex; gap: 8px; }
.composer input { flex: 1; padding: 10px 12px; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.thinking { color: var(--text-secondary); font-style: italic; }

/* charts */
.chart svg { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-secondary); stroke-width: 1; opacity: .5; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar:hover { filter: brightness(1.1); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .s1 { background: var(--series-1); }
.legend .s2 { background: var(--series-2); }
.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
.tooltip b { font-variant-numeric: tabular-nums; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 400px; padding: 24px; }
.login form { display: grid; gap: 10px; }
.login .demo { margin-top: 14px; font-size: 12px; }
.login .demo button { margin: 3px 4px 0 0; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal { max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--text-secondary); }
.tabs button.active { background: var(--surface-1); color: var(--text-primary); font-weight: 600; box-shadow: var(--shadow); border: 1px solid var(--border); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 8px; align-items: center; }
  .brand { padding: 4px 8px; }
  .nav { display: flex; gap: 2px; }
  .side-foot { display: none; }
  .main { padding: 14px 16px 40px; }
  .two { grid-template-columns: 1fr; }
}
