:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77756f;
  --grid: #e6e5e1;
  --series-1: #2a78d6;
  --series-1-hover: #1c5cab;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --error: #b42323;
  --chip: #ebeae6;
  --row-hover: #f3f2ef;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #2e2e2b;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --grid: #2c2c29;
    --series-1: #3987e5;
    --series-1-hover: #6da7ec;
    --accent: #3987e5;
    --accent-ink: #0b0b0b;
    --error: #ef7b7b;
    --chip: #2a2a27;
    --row-hover: #20201e;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232321;
  --border: #2e2e2b;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #9a998f;
  --grid: #2c2c29;
  --series-1: #3987e5;
  --series-1-hover: #6da7ec;
  --accent: #3987e5;
  --accent-ink: #0b0b0b;
  --error: #ef7b7b;
  --chip: #2a2a27;
  --row-hover: #20201e;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text-primary);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
.muted { color: var(--text-muted); }
.small { font-size: 12.5px; margin: 2px 0 10px; }
button, input, select { font: inherit; color: inherit; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.logo {
  align-self: center; display: inline-grid; place-items: center; width: 28px; height: 28px;
  border-radius: 7px; background: var(--accent); color: var(--accent-ink); font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.02em; }
.brand-sub { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 12.5px; }

.app { max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px; display: grid; gap: 16px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.filters label { display: grid; gap: 4px; font-size: 12px; color: var(--text-secondary); }
.filters label.grow { flex: 1 1 200px; }
.filters label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; padding-bottom: 7px; }
select, input[type=search], input[type=email], input[type=password] {
  height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); min-width: 0;
}
select { padding-right: 6px; max-width: 220px; }
input[type=search] { width: 100%; }
select:focus, input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary, .btn-ghost {
  height: 34px; padding: 0 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; font-weight: 600; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { display: grid; gap: 4px; }
.kpi-label { font-size: 12.5px; color: var(--text-secondary); }
.kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--text-muted); margin-left: 4px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 12px; cursor: pointer; font-size: 12.5px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); font-weight: 600; }

.chart { position: relative; width: 100%; }
#chart-timeline { height: 260px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .label { fill: var(--text-secondary); font-size: 12px; }
.chart .value { fill: var(--text-secondary); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--text-muted); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .band:hover .bar, .chart .band.hover .bar { fill: var(--series-1-hover); }
.chart .band { cursor: pointer; }
.chart .hit { fill: transparent; }
.chart .empty { fill: var(--text-muted); font-size: 13px; }

.tooltip {
  position: fixed; z-index: 50; pointer-events: none; max-width: 280px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.tooltip strong { display: block; margin-bottom: 2px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-secondary); }
.tooltip .row b { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; color: var(--text-secondary); font-size: 12px;
  padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none;
}
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text-primary); }
.table th .arrow { color: var(--text-muted); margin-left: 3px; }
.table td { padding: 8px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover td { background: var(--row-hover); }
.table .nowrap { white-space: nowrap; }
.table-deals tbody tr.deal { cursor: pointer; }
.deal-title { font-weight: 500; }
.deal-sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip);
  color: var(--text-secondary); font-size: 11.5px; white-space: nowrap;
}
.detail td { background: var(--surface-2); }
.table tbody tr.detail:hover td { background: var(--surface-2); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; padding: 4px 2px; }
.detail-grid h3 { margin: 0 0 4px; font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.detail-summary { margin: 0 0 8px; }
.detail-grid ul { margin: 0; padding-left: 16px; }
.detail-grid a { color: var(--accent); }
.more { justify-self: center; margin-top: 12px; display: block; margin-inline: auto; }

.login { display: grid; place-items: center; min-height: calc(100vh - 60px); padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: grid; gap: 12px; padding: 24px; }
.login-card label { display: grid; gap: 4px; font-size: 12.5px; color: var(--text-secondary); }
.error { color: var(--error); min-height: 1em; margin: 0; font-size: 13px; }

@media (max-width: 1000px) {
  .two-col { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .topbar { padding: 10px 16px; }
  .brand-sub, #updated { display: none; }
  .app { padding: 16px 16px 40px; }
  .kpi-value { font-size: 22px; }
  .filters label { flex: 1 1 140px; }
  select { max-width: none; width: 100%; }
}
