:root {
  --bg: #090b10;
  --panel: rgba(18, 22, 34, 0.75);
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.04);
  --accent: #e10600;
  --accent-hover: #ff1e19;
  --accent-glow: rgba(225, 6, 0, 0.35);
  --gold: #f59e0b;
  --silver: #94a3b8;
  --bronze: #b45309;
  --text: #f3f4f6;
  --muted: #848b98;
  --success: #10b981;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  background-image: radial-gradient(ellipse 80% 50% at 50% -20%, rgba(225, 6, 0, 0.12), transparent);
  color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 40px 20px;
}

.container {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.title-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.title-group h1 {
  font-size: 2rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.02em;
}

.badge-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--success);
  background: rgba(16, 185, 129, 0.1);
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1px solid rgba(16, 185, 129, 0.25);
  width: fit-content;
}

.badge-live .dot {
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--success);
}

.session-info {
  color: var(--muted);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
}

/* ================= CONTROLS TOOLBAR ================= */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 320px;
  min-width: 220px;
}

.search-icon {
  position: absolute;
  left: 14px;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.search-box {
  width: 100%;
  background: rgba(18, 22, 34, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 10px 38px 10px 40px;
  color: #fff;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  outline: none;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

.search-box::placeholder {
  color: rgba(255, 255, 255, 0.3);
  font-weight: 400;
}

.search-box:focus {
  border-color: rgba(225, 6, 0, 0.5);
  background: rgba(18, 22, 34, 0.9);
  box-shadow: 0 0 0 3px rgba(225, 6, 0, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.search-clear {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.35);
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
  line-height: 1;
  padding: 2px;
  transition: color 0.15s ease;
}

.search-clear:hover {
  color: #fff;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  background: rgba(12, 15, 24, 0.75);
  backdrop-filter: blur(10px);
  padding: 4px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  outline: none;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 9999px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
  white-space: nowrap;
}

.seg-btn:hover {
  color: #d1d5db;
}

.seg-btn.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-glow);
}

/* ================= TABLE ================= */
.card {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  padding: 14px 18px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease;
}

th.sortable:hover {
  color: #fff;
}

.sort-indicator {
  display: inline-block;
  margin-left: 5px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.2);
  transition: color 0.2s ease;
}

th.sorted .sort-indicator {
  color: var(--accent);
}

td {
  padding: 16px 18px;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border-subtle);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.text-right {
  text-align: right;
}

.col-rank {
  width: 60px;
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 0.8rem;
}

.rank-1 .rank-badge {
  background: rgba(245, 158, 11, 0.2);
  color: var(--gold);
  border: 1px solid var(--gold);
}

.rank-2 .rank-badge {
  background: rgba(148, 163, 184, 0.2);
  color: var(--silver);
  border: 1px solid var(--silver);
}

.rank-3 .rank-badge {
  background: rgba(180, 83, 9, 0.2);
  color: var(--bronze);
  border: 1px solid var(--bronze);
}

.driver-name {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.driver-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
  margin-top: 2px;
}

.lap-time {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 1rem;
  color: var(--success);
}

.gap-cell {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--muted);
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}