/* ===== Clasificación Final — Estilo tipo broadcast ===== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800;900&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: #1a1a2e;
  color: #fff;
  font-family: 'Inter', Arial, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px;
}

/* ===== Título ===== */
.page-title {
  font-size: clamp(18px, 3.5vw, 28px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #e0e0e0;
  margin-bottom: 20px;
  text-align: center;
}

/* ===== Contenedor tabla ===== */
.table-wrapper {
  width: 100%;
  max-width: 780px;
  overflow-x: auto;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
}

/* Scrollbar personalizado */
.table-wrapper::-webkit-scrollbar {
  width: 6px;
}
.table-wrapper::-webkit-scrollbar-track {
  background: #1a1a2e;
}
.table-wrapper::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.2);
  border-radius: 3px;
}
.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,.35);
}

/* ===== Tabla ===== */
table {
  width: 100%;
  border-collapse: collapse;
}

/* ===== Filas base ===== */
tr {
  transition: background .15s ease;
}

tr:hover {
  filter: brightness(1.12);
}

/* ===== Celdas ===== */
td {
  padding: 10px 14px;
  font-size: clamp(13px, 2.2vw, 16px);
  font-weight: 600;
  border-bottom: 1px solid rgba(255,255,255,.06);
  white-space: nowrap;
}

/* Posición */
td.pos {
  width: 48px;
  text-align: center;
  font-weight: 800;
  font-size: clamp(14px, 2.5vw, 18px);
}

/* Nombre */
td.name {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: .5px;
  padding-left: 16px;
}

/* Tiempo / Puntos */
td.value, th.value {
  text-align: right;
  font-weight: 800;
  font-size: clamp(14px, 2.5vw, 18px);
  padding-right: 18px;
  min-width: 80px;
}

/* ===== Columna Reajuste ===== */
td.ajuste-col, th.ajuste-col {
  text-align: center;
  font-size: clamp(10px, 1.8vw, 13px);
  font-weight: 600;
  color: #7ddfb0;
  min-width: 70px;
  letter-spacing: 0.3px;
}
tr.top1 td.ajuste-col,
tr.top2 td.ajuste-col,
tr.top3 td.ajuste-col {
  color: rgba(255,255,255,0.7);
}

/* ===== Columna Diferencia ===== */
td.diff, th.diff {
  text-align: right;
  font-size: clamp(11px, 1.9vw, 14px);
  font-weight: 600;
  color: #f0a0a0;
  padding-right: 18px;
  min-width: 80px;
  letter-spacing: 0.3px;
}
tr.top1 td.diff { color: rgba(255,255,255,0.5); }
tr.top2 td.diff,
tr.top3 td.diff {
  color: rgba(255,255,255,0.7);
}

/* ===== Cabecera tabla ===== */
thead tr.header-row {
  background: #16213e;
}
thead th {
  padding: 10px 14px;
  font-size: clamp(11px, 2vw, 14px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #8a8aa0;
  border-bottom: 2px solid rgba(255,255,255,.12);
  white-space: nowrap;
}
thead th.pos { text-align: center; }
thead th.name { text-align: left; padding-left: 16px; }

/* ===== Podio: top 3 ===== */

/* 1.º — Dorado/naranja */
tr.top1 {
  background: linear-gradient(90deg, #c87a1a 0%, #e8942d 50%, #d4851f 100%);
}
tr.top1 td { color: #fff; }

/* 2.º — Azul oscuro */
tr.top2 {
  background: linear-gradient(90deg, #1a5276 0%, #2471a3 50%, #1a5276 100%);
}
tr.top2 td { color: #fff; }

/* 3.º — Azul medio */
tr.top3 {
  background: linear-gradient(90deg, #2e6ea0 0%, #3b8ac4 50%, #2e6ea0 100%);
}
tr.top3 td { color: #fff; }

/* ===== Badge "TA" (Time Attack) junto al tiempo ===== */
.ta-badge {
  color: #52b788;
  font-size: clamp(9px, 1.6vw, 11px);
  font-weight: 700;
  letter-spacing: .5px;
  margin-right: 4px;
}
tr.top1 .ta-badge,
tr.top2 .ta-badge,
tr.top3 .ta-badge {
  color: #b7e4c7;
}

/* ===== Resto de filas ===== */
tr.normal:nth-child(odd)  { background: #2a2a3e; }
tr.normal:nth-child(even) { background: #232337; }

/* ===== Punto rojo indicador (esquina inferior derecha) ===== */
.live-dot {
  position: fixed;
  bottom: 18px;
  right: 18px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e74c3c;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .4; transform: scale(.8); }
}

/* ===== Timestamp ===== */
.timestamp {
  margin-top: 14px;
  font-size: 12px;
  color: #666;
  text-align: center;
}

/* ===== Estado vacío ===== */
.empty-msg {
  text-align: center;
  padding: 40px 20px;
  font-size: 16px;
  color: #888;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  body { padding: 12px 8px; }
  td { padding: 8px 10px; }
  td.value { padding-right: 12px; }
  .admin-panel { padding: 12px; }
  .admin-row { flex-direction: column; gap: 6px; }
}

/* ===== Panel Admin: control de ajustes TMR ===== */
.admin-panel {
  width: 100%;
  max-width: 780px;
  background: #16213e;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}

.admin-title {
  font-size: 14px;
  font-weight: 700;
  color: #8a8aa0;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.admin-label {
  font-size: 14px;
  font-weight: 600;
  color: #ccc;
}

.admin-detail {
  font-size: 11px;
  font-weight: 400;
  color: #666;
  margin-left: 4px;
}

/* Detalle de la referencia: 2 mejores vueltas + media */
.ref-laps {
  color: #8a8aa0;
  font-size: 12px;
  margin: 2px 0 10px 4px;
  padding: 4px 8px;
  border-left: 2px solid rgba(77,171,247,.5);
  background: rgba(255,255,255,.03);
  border-radius: 4px;
}
.ref-laps b { color: #4dabf7; }

.toggle-btn {
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  cursor: pointer;
  transition: background .2s, color .2s, opacity .2s;
  min-width: 120px;
  text-align: center;
}

.toggle-btn.on {
  background: #2d6a4f;
  color: #b7e4c7;
}
.toggle-btn.on:hover {
  background: #40916c;
}

.toggle-btn.off {
  background: #6c2020;
  color: #f0a0a0;
}
.toggle-btn.off:hover {
  background: #8c3030;
}

.toggle-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* ===== Sanciones ===== */
tr.penalized td.name {
  color: #ff9999;
}
tr.penalized.top1 td.name,
tr.penalized.top2 td.name,
tr.penalized.top3 td.name {
  color: #ffcccc;
}

/* ===== Filas con bonificación ===== */
tr.bonified td.name {
  color: #99ffaa;
}
tr.bonified.top1 td.name,
tr.bonified.top2 td.name,
tr.bonified.top3 td.name {
  color: #ccffcc;
}

.penalty-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(231,76,60,.25);
  color: #ff6b6b;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-left: 4px;
  vertical-align: middle;
}

.bonus-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(46,204,113,.25);
  color: #2ecc71;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ===== Botón Inicio ===== */
.home-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  padding: 6px 14px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  background: #16213e;
  color: #a0c4ff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-decoration: none;
  z-index: 100;
  transition: all .2s ease;
}
.home-btn:hover {
  background: #1a3a5c;
  border-color: rgba(160,196,255,.4);
  color: #fff;
}

/* ===== Select de piloto de referencia ===== */
.ref-select {
  background: #1a2744;
  color: #e0e0e0;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  min-width: 200px;
  transition: border-color .2s;
}
.ref-select:hover,
.ref-select:focus {
  border-color: #3498db;
  outline: none;
}
.ref-select option {
  background: #1a2744;
  color: #e0e0e0;
}

/* ===== Tabs de vista (admin) ===== */
.view-tabs {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 14px;
  max-width: 780px;
  width: 100%;
}
.view-tab {
  padding: 7px 18px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background: #16213e;
  color: #8a8aa0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .4px;
  cursor: pointer;
  transition: all .2s;
}
.view-tab:hover {
  background: #1a3050;
  color: #ccc;
}
.view-tab.active {
  background: #1a3a5c;
  color: #a0c4ff;
  border-color: #3498db;
}

/* ===================== MODO CLARO ===================== */
:root[data-theme="light"] body { background: #eef1f6; color: #1f2733; }
:root[data-theme="light"] .page-title { color: #24303f; }
:root[data-theme="light"] .home-btn { background: rgba(0,0,0,.06); color: #24303f; }
:root[data-theme="light"] .home-btn:hover { background: rgba(0,0,0,.12); }
:root[data-theme="light"] .table-wrapper { box-shadow: 0 8px 28px rgba(20,30,50,.12); }
:root[data-theme="light"] .table-wrapper::-webkit-scrollbar-track { background: #e2e6ee; }
:root[data-theme="light"] .table-wrapper::-webkit-scrollbar-thumb { background: rgba(0,0,0,.22); }
:root[data-theme="light"] thead tr.header-row { background: #e7ebf3; }
:root[data-theme="light"] thead th { color: #5a6472; border-bottom-color: rgba(0,0,0,.14); }
:root[data-theme="light"] tr.normal:nth-child(odd)  { background: #ffffff; }
:root[data-theme="light"] tr.normal:nth-child(even) { background: #f4f6fa; }
:root[data-theme="light"] tr.normal td { color: #24303f; border-bottom-color: rgba(0,0,0,.06); }
/* Podios (top1/2/3) conservan su color y texto blanco */
:root[data-theme="light"] .penalty-badge { background: rgba(231,76,60,.90); color: #fff; }
:root[data-theme="light"] .bonus-badge   { background: rgba(46,204,113,.85); color: #10321f; }
/* Panel admin */
:root[data-theme="light"] .admin-panel { background: #ffffff; border-color: rgba(0,0,0,.10); }
:root[data-theme="light"] .admin-title { color: #24303f; }
:root[data-theme="light"] .admin-label { color: #2b3442; }
:root[data-theme="light"] .admin-detail { color: #6a7482; }
:root[data-theme="light"] .admin-row { border-bottom-color: rgba(0,0,0,.08); }
:root[data-theme="light"] .ref-select { background: #ffffff; color: #1f2733; border-color: rgba(0,0,0,.18); }
:root[data-theme="light"] .ref-select:hover,
:root[data-theme="light"] .ref-select:focus { background: #eef4ff; border-color: rgba(36,113,163,.5); color: #14202c; }
:root[data-theme="light"] .ref-laps { background: rgba(36,113,163,.06); border-left-color: rgba(36,113,163,.5); color: #4a5563; }
:root[data-theme="light"] .ref-laps b { color: #1d6fa5; }
