:root {
  color-scheme: light;
  --page: #f6f7f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #257de0;
  --accent-track: #cce3fd;
  --accent-strong: #1b64be;
  --series-1: #257de0;
  --series-2: #f47230;
  --good-text: #006c10;
  --bad-text: #b42324;
  --warning: #fbb315;
  --warning-bg: #fff4d6;
  --warning-text: #6b4a00;
  --hover: rgba(11, 11, 11, 0.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #338ced;
    --accent-track: #0e3d7e;
    --accent-strong: #84b9f3;
    --series-1: #338ced;
    --series-2: #e76624;
    --good-text: #53c556;
    --bad-text: #eb6263;
    --warning-bg: #3a2e0c;
    --warning-text: #fbd36b;
    --hover: rgba(255, 255, 255, 0.05);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.muted {
  color: var(--text-2);
}

.wordmark {
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.wordmark span {
  color: var(--accent);
}

/* ---------- Login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  display: grid;
  gap: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
}

.login-card h1 {
  font-size: 20px;
  margin-top: 8px;
}

.login-card label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}

input,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--axis);
  border-radius: 8px;
  padding: 10px 12px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-weight: 600;
  background: var(--accent);
  color: #ffffff;
}

button:hover {
  filter: brightness(1.08);
}

.form-error {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.form-error span {
  font-weight: 800;
  margin-right: 4px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-divider {
  width: 1px;
  height: 28px;
  background: var(--axis);
}

.brand-client {
  display: grid;
  line-height: 1.15;
}

.brand-client span {
  font-size: 12px;
  color: var(--text-2);
}

.user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.link-button {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-weight: 500;
}

/* ---------- Layout ---------- */

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px clamp(16px, 4vw, 40px) 48px;
  display: grid;
  gap: 20px;
}

.page-title h1 {
  font-size: 26px;
  letter-spacing: -0.01em;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
}

.segments {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.segment {
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--text-2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.segment:hover {
  background: var(--hover);
}

.segment.is-current {
  background: var(--accent);
  color: #ffffff;
}

.meta {
  font-size: 13px;
  color: var(--text-2);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.card h2 {
  font-size: 16px;
}

.card > .muted,
.card-head .muted {
  font-size: 13px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.empty {
  color: var(--text-2);
  padding: 24px 0;
}

/* ---------- KPI tiles ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  gap: 4px;
  align-content: start;
}

.tile h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.tile-value {
  font-size: 34px;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tile-hero .tile-value {
  font-size: 48px;
}

.tile-hint {
  font-size: 12.5px;
  color: var(--text-2);
}

.delta {
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 4px;
}

.delta .muted {
  font-weight: 400;
}

.delta-up {
  color: var(--good-text);
}

.delta-down {
  color: var(--bad-text);
}

.delta-flat {
  color: var(--text-2);
}

/* ---------- Legend & line chart ---------- */

.legend {
  display: flex;
  gap: 16px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
  color: var(--text-2);
}

.legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.key-line {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  display: inline-block;
}

.key-line.s1 {
  background: var(--series-1);
}

.key-line.s2 {
  background: var(--series-2);
}

.chart {
  position: relative;
  height: 260px;
}

.chart svg {
  display: block;
  overflow: visible;
}

.chart .gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .baseline {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .tick {
  fill: var(--text-2);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.chart .line {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart .line.s1,
.chart .dot.s1 {
  stroke: var(--series-1);
}

.chart .line.s2,
.chart .dot.s2 {
  stroke: var(--series-2);
}

.chart .dot {
  stroke-width: 2;
  stroke: var(--surface);
}

.chart .dot.s1 {
  fill: var(--series-1);
  stroke: var(--surface);
}

.chart .dot.s2 {
  fill: var(--series-2);
  stroke: var(--surface);
}

.chart .crosshair {
  stroke: var(--axis);
  stroke-width: 1;
}

.chart .hit {
  fill: transparent;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12.5px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
  min-width: 170px;
  display: grid;
  gap: 4px;
}

.tooltip[hidden] {
  display: none;
}

.tooltip-title {
  color: var(--text-2);
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tooltip-row strong {
  font-size: 14px;
  min-width: 2ch;
}

.tooltip-row span:last-child {
  color: var(--text-2);
}

/* ---------- Meters & ranked bars ---------- */

.meter-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.meter-row {
  display: grid;
  grid-template-columns: minmax(120px, 34%) 1fr auto;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.meter-label {
  overflow-wrap: anywhere;
}

.meter-value {
  min-width: 84px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border: 0;
  border-radius: 5px;
  background: var(--accent-track);
  overflow: hidden;
}

progress::-webkit-progress-bar {
  background: var(--accent-track);
  border-radius: 5px;
}

progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 5px;
}

progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 5px;
}

/* Ranked bars compare against each other, not against a whole: no track. */
progress.bar,
progress.bar::-webkit-progress-bar {
  background: transparent;
}

progress.bar {
  height: 14px;
}

progress.bar::-webkit-progress-value {
  border-radius: 0 4px 4px 0;
}

progress.bar::-moz-progress-bar {
  border-radius: 0 4px 4px 0;
}

progress.meter-thin {
  height: 6px;
  width: 64px;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  padding: 8px 10px;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}

tbody tr:hover {
  background: var(--hover);
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cell-title {
  display: block;
  font-weight: 550;
}

.cell-sub {
  display: block;
  font-size: 12.5px;
  color: var(--text-2);
}

.rate-cell {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.rate-cell span {
  min-width: 4ch;
}

.table-filter {
  min-width: 220px;
  padding: 8px 12px;
  font-size: 14px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
}

.status-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.table-view summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  width: fit-content;
}

.table-view table {
  margin-top: 8px;
}

.notes {
  font-size: 13px;
  color: var(--text-2);
  max-width: 820px;
}

@media (max-width: 640px) {
  .meter-row {
    grid-template-columns: 1fr auto;
  }

  .meter-row progress {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .tile-hero .tile-value {
    font-size: 40px;
  }

  .brand-divider,
  .brand-client span {
    display: none;
  }
}
