/* ── Design system ── */
:root {
  --bg:           #080808;
  --bg-card:      #111111;
  --bg-raised:    #1a1a1a;
  --bg-input:     #161616;
  --border:       rgba(255, 255, 255, 0.07);
  --border-hover: rgba(255, 255, 255, 0.14);
  --accent:       #E10600;
  --accent-dim:   rgba(225, 6, 0, 0.15);
  --accent-glow:  rgba(225, 6, 0, 0.35);
  --text:         #f0f0f0;
  --text-muted:   #777;
  --text-dim:     #444;
  --radius:       8px;
  --radius-lg:    12px;
  --sidebar-w:    220px;
  --font:         'Inter', system-ui, -apple-system, sans-serif;
  --shadow:       0 4px 24px rgba(0,0,0,0.5);
  --transition:   0.18s ease;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}
.logo-f1 {
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 7px;
  border-radius: 4px;
}
.logo-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  width: 100%;
  text-align: left;
}
.nav-item svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
}
.nav-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-dim);
  color: var(--text);
  border: 1px solid rgba(225,6,0,0.2);
}
.nav-item.active svg { stroke: var(--accent); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: var(--transition);
}
.live-dot.active {
  background: #22c55e;
  box-shadow: 0 0 6px #22c55e;
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ── Main ── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  overflow-y: auto;
}
.page-container {
  padding: 28px 32px;
  max-width: 1600px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ── Loading ── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 60vh;
  color: var(--text-muted);
  font-size: 14px;
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Page header ── */
.page-header {
  margin-bottom: 28px;
}
.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
}
.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── KPI Cards row ── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kpi-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}
.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1;
}
.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Section ── */
.section {
  margin-bottom: 28px;
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Card ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  overflow: hidden;
}

/* ── Next race hero ── */
.next-race-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: start;
  margin-bottom: 24px;
}
.race-name { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.race-meta { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.race-sessions { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.race-session-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.race-session-label {
  width: 100px;
  font-weight: 500;
  color: var(--text-muted);
}
.race-session-time { color: var(--text); }
.countdown-block {
  text-align: right;
}
.countdown-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.countdown-digits {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.countdown-unit {
  text-align: center;
}
.countdown-num {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
}
.countdown-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ── Podium ── */
.podium-row {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
  align-items: end;
}
.podium-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.podium-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.podium-p1::before { background: linear-gradient(90deg, #ffd700, #ffb800); }
.podium-p2::before { background: linear-gradient(90deg, #c0c0c0, #a8a8a8); }
.podium-p3::before { background: linear-gradient(90deg, #cd7f32, #b8691e); }
.podium-pos {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.podium-code {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
}
.podium-p1 .podium-code { font-size: 30px; }
.podium-name { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.podium-team { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.podium-time {
  font-size: 13px;
  font-weight: 500;
  margin-top: 10px;
  font-variant-numeric: tabular-nums;
}
.podium-points {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.podium-fastest {
  display: inline-block;
  font-size: 11px;
  color: #a855f7;
  margin-top: 4px;
}
.podium-p1 { padding-top: 70px; }
.podium-p2 { padding-top: 25px; }

/* ── Standings table ── */
.standings-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.standings-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.standings-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  vertical-align: middle;
}
.standings-table tr:last-child td { border-bottom: none; }
.standings-table tr:hover td { background: rgba(255,255,255,0.02); }
.pos-num {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 13px;
  width: 32px;
}
.pos-num.top { color: var(--text); }
.driver-code { font-weight: 700; font-size: 14px; }
.driver-name { color: var(--text-muted); font-size: 12px; }
.team-badge {
  display: inline-block;
  width: 3px;
  height: 14px;
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
  flex-shrink: 0;
}
.points-val { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── Chart container ── */
.chart-wrap {
  position: relative;
  width: 100%;
}

/* ── Two-column layout ── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

/* ── Telemetry page ── */
.tel-controls {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}
.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 160px;
}
.control-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
}
.control-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}
.control-select:focus, .control-select:hover {
  border-color: var(--border-hover);
}
.control-select option { background: var(--bg-input); }

.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid;
  margin-left: auto;
}
.mode-badge.live {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.3);
  color: #22c55e;
}
.mode-badge.history {
  background: rgba(99,102,241,0.1);
  border-color: rgba(99,102,241,0.3);
  color: #818cf8;
}
.mode-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.mode-badge.live .mode-dot { animation: pulse 1.5s infinite; }

/* ── Telemetry grid ── */
.tel-grid {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 1200px) { .tel-grid { grid-template-columns: 1fr; } }

.tel-charts-col { display: flex; flex-direction: column; gap: 8px; }
.tel-chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.tel-chart-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.tel-chart-label span {
  color: var(--text);
  font-weight: 700;
  margin-left: 6px;
}

/* ── Circuit canvas ── */
.circuit-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.circuit-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.circuit-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-height: 420px;
}
#circuitCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: var(--radius);
}
.circuit-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 80px;
  overflow-y: auto;
}
.circuit-legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--text-muted);
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── Tyre strategy ── */
.strategy-canvas-wrap {
  width: 100%;
  overflow-x: auto;
}
#strategyCanvas { display: block; }

/* ── Live stats bar ── */
.live-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.live-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  text-align: center;
}
.live-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.live-stat-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.live-stat-unit {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.tyre-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 18px;
  font-weight: 800;
  margin: 0 auto;
  box-shadow: 0 0 12px currentColor;
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 13px;
}
.empty-state svg {
  width: 40px; height: 40px;
  stroke: var(--text-dim);
}

/* ── Error state ── */
.error-banner {
  background: rgba(225,6,0,0.08);
  border: 1px solid rgba(225,6,0,0.2);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: #f87171;
  margin-bottom: 16px;
}

/* ── Race picker (onglet Résultats) ── */
.race-picker {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  padding: 10px 14px;
  margin-bottom: 20px;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.race-picker:hover { border-color: #444; }
.race-picker:focus { border-color: #e10600; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .logo-text, .nav-item span, .live-label { display: none; }
  .main-content { margin-left: 64px; }
  .page-container { padding: 16px; }
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .podium-row { grid-template-columns: 1fr; }
  .next-race-card { grid-template-columns: 1fr; }
  .live-stats { grid-template-columns: repeat(2, 1fr); }
}
