:root {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2330;
  --line: #262d3a;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c8dff;
  --pos: #f2545b;   /* cost going UP is bad -> red */
  --neg: #3fb950;   /* cost going DOWN is good -> green */
  --grid: #222a36;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
}

/* Light tokens: applied when the viewer explicitly picks light, or when the OS
   prefers light and they have not overridden it. */
:root[data-theme="light"],
:root:not([data-theme="dark"]) {
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel-2: #f2f5f9;
  --line: #dde3ea;
  --text: #1c2128;
  --muted: #5d6b7a;
  --accent: #1f6feb;
  --grid: #e7ecf1;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 20px rgba(16,24,40,.08);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1c2330;
    --line: #262d3a;
    --text: #e6edf3;
    --muted: #8b98a9;
    --accent: #4c8dff;
    --grid: #222a36;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1116;
  --panel: #161b22;
  --panel-2: #1c2330;
  --line: #262d3a;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4c8dff;
  --grid: #222a36;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.24);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; letter-spacing: -.01em; }
h2 { font-size: 13px; }
h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.rapido-logo { display: inline-flex; align-items: center; gap: 7px; color: var(--text); }
.rapido-mark {
  display: grid; place-items: center; width: 25px; height: 25px;
  border-radius: 7px; background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 800; font-style: italic; letter-spacing: -.08em;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.rapido-wordmark { font-size: 17px; font-weight: 800; letter-spacing: -.04em; }
.rapido-logo + div { border-left: 1px solid var(--line); padding-left: 14px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; align-items: flex-end; gap: 10px; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 268px minmax(0, 1fr); align-items: start; }
.sidebar {
  position: sticky; top: 57px; height: calc(100vh - 57px); overflow-y: auto;
  padding: 16px; background: var(--panel); border-right: 1px solid var(--line);
}
.content { padding: 18px 20px 48px; min-width: 0; display: grid; gap: 14px; }

.side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.side-block { padding: 12px 0; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.side-block:first-of-type { border-top: 0; }

/* ---------- form controls ---------- */
.field { display: grid; gap: 4px; }
.field > span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field.compact { gap: 3px; }
select, input[type="date"] {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 7px;
}
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: -1px; }
.topbar-actions select { min-width: 160px; }

button { font: inherit; cursor: pointer; }
.ghost {
  padding: 7px 11px; font-size: 12px; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
}
.ghost:hover { border-color: var(--accent); }
.link { background: none; border: 0; color: var(--accent); font-size: 12px; padding: 0; }

.quick-range { display: flex; gap: 6px; }
.quick-range button {
  flex: 1; padding: 5px 0; font-size: 12px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
}
.quick-range button:hover, .quick-range button.on { color: var(--text); border-color: var(--accent); }

/* ---------- label filters ---------- */
.filter-group { border-top: 1px solid var(--line); }
.filter-group:first-child { border-top: 0; }
.filter-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 8px 0; background: none; border: 0;
  color: var(--text); font-size: 12px; font-weight: 500; text-align: left;
}
.filter-head .count {
  font-size: 10px; color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 20px; padding: 1px 7px;
}
.filter-body { display: none; padding: 0 0 10px; max-height: 190px; overflow-y: auto; }
.filter-group.open .filter-body { display: block; }
.filter-body label {
  display: flex; align-items: center; gap: 7px; padding: 3px 2px;
  font-size: 12.5px; color: var(--muted); cursor: pointer; border-radius: 4px;
}
.filter-body label:hover { color: var(--text); background: var(--panel-2); }
.filter-body input { accent-color: var(--accent); }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 6px 3px 10px; font-size: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
}
.chip b { font-weight: 500; color: var(--muted); }
.chip button { background: none; border: 0; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 2px; }
.chip button:hover { color: var(--pos); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  padding: 14px 16px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.kpi .k-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi .k-value { margin-top: 6px; font-size: 25px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .k-foot { margin-top: 4px; font-size: 12px; color: var(--muted); }
.up { color: var(--pos); }
.down { color: var(--neg); }

/* ---------- cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.hint { font-size: 11px; color: var(--muted); }
.chart { padding: 12px 8px 4px; }
.chart.short { padding-bottom: 12px; }
.split { display: grid; grid-template-columns: 1.55fr 1fr; gap: 14px; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.legend span { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

svg { display: block; width: 100%; overflow: visible; }
.grid-line { stroke: var(--grid); stroke-width: 1; }
.axis-text { fill: var(--muted); font-size: 10.5px; }
.bar { cursor: pointer; }
.bar:hover, .seg:hover { opacity: .82; }

/* ---------- table ---------- */
.table-wrap { max-height: 440px; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 8px 14px; text-align: left; white-space: nowrap; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  padding: 8px 10px; font-size: 12px; line-height: 1.45;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 7px; box-shadow: var(--shadow);
}
.tooltip b { font-variant-numeric: tabular-nums; }

.empty { padding: 36px 16px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .split { grid-template-columns: 1fr; }
}
