:root {
  --bg: #0b1020;
  --bg-soft: #131a2d;
  --panel: rgba(16, 24, 44, 0.78);
  --panel-strong: rgba(12, 19, 36, 0.9);
  --panel-lite: rgba(255, 255, 255, 0.03);
  --ink: #eff4ff;
  --muted: #97a4bd;
  --line: rgba(151, 164, 189, 0.18);
  --accent-a: #ff6b57;
  --accent-b: #3dd2c0;
  --accent-c: #7ea1ff;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(126, 161, 255, 0.18), transparent 22%),
    radial-gradient(circle at 85% 15%, rgba(61, 210, 192, 0.12), transparent 26%),
    radial-gradient(circle at 50% 100%, rgba(255, 107, 87, 0.12), transparent 30%),
    linear-gradient(180deg, #0a0f1c 0%, var(--bg) 100%);
}

body.modal-open {
  overflow: hidden;
}

.chart-tooltip {
  position: fixed;
  z-index: 120;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(6, 10, 18, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34);
  white-space: nowrap;
}

.page {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 56px;
}

.topbar,
.panel,
.kpi-card {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.topbar {
  border-radius: 18px;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

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

.brand-logo {
  width: 62px;
  height: auto;
  display: block;
  flex: 0 0 auto;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.22));
}

.brand-title {
  font-size: 14px;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--muted);
}

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

h2 {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.hero-meta {
  white-space: nowrap;
  font-size: 13px;
  color: var(--muted);
}

.kpi-grid,
.two-col {
  display: grid;
  gap: 22px;
  margin-top: 22px;
}

.kpi-grid + .panel {
  margin-top: 22px;
}

.two-col + .panel {
  margin-top: 14px;
}

.analysis-row + .panel {
  margin-top: 14px;
}

.kpi-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.kpi-card,
.panel {
  border-radius: var(--radius);
  padding: 24px;
}

.driver-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.chip {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 8px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric {
  padding: 14px 14px 16px;
  border-radius: 16px;
  background: var(--panel-lite);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric-value {
  display: block;
  font-size: 22px;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-weight: 600;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-controls-label {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

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

.compact-range {
  gap: 8px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.trend-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  align-items: center;
}

.toggle-group,
.range-group {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.toggle-pill,
.range-pill {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-pill.is-active,
.range-pill.is-active {
  background: rgba(126, 161, 255, 0.16);
  color: var(--ink);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
}

.legend-swatch-a {
  background: var(--accent-a);
}

.legend-swatch-b {
  background: var(--accent-b);
}

.legend-swatch-c {
  background: var(--accent-c);
}

.legend-trend {
  width: 18px;
  height: 0;
  border-top-width: 3px;
  border-top-style: dashed;
  display: inline-block;
}

.legend-trend-a {
  border-top-color: rgba(255, 107, 87, 0.95);
}

.legend-trend-b {
  border-top-color: rgba(61, 210, 192, 0.95);
}

.chart-wrap {
  width: 100%;
  min-height: 320px;
  padding: 10px 0 0;
  position: relative;
}

.chart-wrap.compact {
  min-height: 290px;
}

.chart-controls {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chart {
  width: 100%;
  height: 100%;
  display: block;
}

.axis,
.grid-line {
  stroke: var(--line);
  stroke-width: 1;
}

.grid-line {
  stroke-dasharray: 3 8;
}

.zero-line {
  stroke: rgba(239, 244, 255, 0.42);
  stroke-width: 2;
  stroke-dasharray: none;
}

.series-a {
  fill: none;
  stroke: var(--accent-a);
  stroke-width: 1.8;
  opacity: 0.88;
}

.series-b {
  fill: none;
  stroke: var(--accent-b);
  stroke-width: 1.8;
  opacity: 0.88;
}

.median-line {
  fill: none;
  stroke: var(--accent-c);
  stroke-width: 2.5;
  stroke-dasharray: 8 8;
}

.series-c {
  fill: none;
  stroke: var(--accent-c);
  stroke-width: 2.4;
  stroke-dasharray: 10 8;
}

.trend-a {
  fill: none;
  stroke: rgba(255, 107, 87, 0.95);
  stroke-width: 2;
  stroke-dasharray: 10 8;
}

.trend-b {
  fill: none;
  stroke: rgba(61, 210, 192, 0.95);
  stroke-width: 2;
  stroke-dasharray: 10 8;
}

.dot-a {
  fill: var(--accent-a);
  stroke: #0b1020;
  stroke-width: 1.5;
}

.dot-b {
  fill: var(--accent-b);
  stroke: #0b1020;
  stroke-width: 1.5;
}

.bar-a {
  fill: rgba(255, 107, 87, 0.84);
}

.bar-b {
  fill: rgba(61, 210, 192, 0.84);
}

.comparison-line {
  fill: none;
  stroke: rgba(239, 244, 255, 0.7);
  stroke-width: 1.6;
}

.comparison-dot {
  fill: #f5f8ff;
  stroke: #0b1020;
  stroke-width: 1.5;
}

.label {
  font-size: 12px;
  fill: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  padding-top: 4px;
}

.heat-row {
  cursor: pointer;
  transition: background 160ms ease, transform 160ms ease;
}

.heat-row:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.heat-row.is-selected td {
  background: rgba(126, 161, 255, 0.09);
}

.heat-detail-empty {
  color: var(--muted);
  font-size: 14px;
}

.heat-detail-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.heat-detail-metric {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.heat-detail-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
}

.heat-detail-value {
  display: block;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.heat-lap-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.heat-mini-chart {
  padding: 14px 14px 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.heat-mini-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 8px;
}

.heat-mini-subtitle {
  color: var(--muted);
  font-size: 12px;
}

.heat-driver-block {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.heat-driver-name {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}

.heat-driver-empty {
  color: var(--muted);
  font-size: 13px;
}

.lap-pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lap-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.lap-pill.is-purple-lap {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.22), rgba(216, 180, 254, 0.1));
  border-color: rgba(196, 151, 255, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 10px 24px rgba(94, 50, 140, 0.16);
}

.lap-pill.is-purple-lap .lap-pill-time {
  color: #f6f7fb;
  font-weight: 700;
}

.lap-pill-number {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lap-pill-time {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-shell[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 16, 0.76);
  backdrop-filter: blur(12px);
}

.modal-card {
  position: relative;
  width: min(980px, calc(100vw - 40px));
  max-height: min(88vh, 920px);
  overflow: auto;
  padding: 24px;
  border-radius: 24px;
  background: rgba(10, 16, 30, 0.97);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 40px 120px rgba(0, 0, 0, 0.45);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.modal-close {
  appearance: none;
  border: 0;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.modal-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 18px;
}

.modal-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 16px;
  border-radius: 999px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.modal-tab.is-active {
  background: rgba(126, 161, 255, 0.16);
  color: var(--ink);
}

.modal-body {
  display: grid;
  gap: 16px;
}

.insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.insight-card {
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-lite);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.insight-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.insight-metrics {
  display: grid;
  gap: 8px;
}

.insight-metric {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.insight-label {
  color: var(--muted);
}

.insight-value {
  color: var(--ink);
  font-weight: 600;
}

.outlier-list-wrap {
  overflow-x: auto;
}

.outlier-table {
  min-width: 100%;
}

.outlier-delta {
  color: #ff9d9d;
  font-weight: 600;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 760px;
}

th,
td {
  padding: 14px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sort-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  padding: 0;
  cursor: pointer;
}

.sort-button:hover,
.sort-button.is-active {
  color: var(--ink);
}

td {
  font-size: 14px;
}

.lap-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lap-value {
  color: var(--ink);
}

.lap-cell.has-purple-lap {
  padding: 4px 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(216, 180, 254, 0.08));
  border: 1px solid rgba(196, 151, 255, 0.28);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 8px 20px rgba(94, 50, 140, 0.16);
  backdrop-filter: blur(10px);
}

.lap-value.is-purple-lap {
  color: #f6f7fb;
  font-weight: 700;
  text-shadow: 0 1px 10px rgba(103, 41, 164, 0.22);
}

.delta-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.delta-badge.is-better {
  color: #7ff0c3;
  background: rgba(30, 181, 117, 0.14);
  border-color: rgba(69, 226, 154, 0.22);
}

.delta-badge.is-worse {
  color: #ff9d9d;
  background: rgba(255, 107, 87, 0.14);
  border-color: rgba(255, 107, 87, 0.22);
}

@media (max-width: 860px) {
  .topbar,
  .driver-header,
  .panel-header,
  .modal-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .kpi-grid,
  .two-col,
  .metric-grid,
  .insight-grid,
  .heat-detail-grid,
  .heat-lap-columns {
    grid-template-columns: 1fr;
  }
}
