/* ============================================================
   BEWYTEC DESIGN SYSTEM  (tokens reales del dashboard-ce)
   + layout del visor GPS del celular
   ============================================================ */
:root {
  --bw-blue:        #026EEE;
  --bw-blue-soft:   #5598EF;
  --bw-yellow:      #F7B923;
  --bw-ink:         #0c224e;
  --bw-surface:     #f2f4f7;
  --bw-white:       #ffffff;
  --bw-border:      rgba(2, 110, 238, 0.09);
  --bw-shadow-card: 0 2px 12px rgba(2,110,238,0.07), 0 1px 3px rgba(0,0,0,0.04);
  --bw-shadow-hover:0 8px 28px rgba(2,110,238,0.14), 0 2px 8px rgba(0,0,0,0.06);
}
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  color: #0f172a; background: var(--bw-surface);
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Topbar ---------- */
.topbar {
  background: linear-gradient(100deg, var(--bw-ink), var(--bw-blue));
  color: #fff; padding: 0.9rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; box-shadow: 0 2px 14px rgba(2,110,238,0.25);
  position: sticky; top: 0; z-index: 2000;   /* sobre overlays del mapa (HUD/Leaflet ~1150); debajo del modal de tendencia (2900+) */
}
.topbar .brand { display: flex; align-items: center; gap: 0.7rem; }
.topbar .logo {
  width: 2.1rem; height: 2.1rem; border-radius: 0.6rem;
  background: var(--bw-yellow); color: var(--bw-ink);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 1.1rem; flex-shrink: 0;
}
.topbar .title { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }
.topbar .sub { font-size: 0.72rem; opacity: 0.8; font-weight: 500; }
.topbar .right { display: flex; align-items: center; gap: 0.8rem; }
.pill {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.25);
  border-radius: 9999px; padding: 0.3rem 0.8rem; font-size: 0.78rem; font-weight: 700;
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,0.25); }
.link-hist { color: #fff; font-size: 0.78rem; font-weight: 700; text-decoration: none; opacity: 0.85; white-space: nowrap; }
.link-hist:hover { opacity: 1; text-decoration: underline; }

/* Botón "Ver en vivo": un link blanco sobre el degradado azul no se leía.
   Botón rojo sólido + punto que parpadea = contraste claro y lectura de "live". */
.btn-vivo {
  display: inline-flex; align-items: center; gap: 0.45rem;
  background: #ef4444; color: #fff;
  font-size: 0.78rem; font-weight: 800; letter-spacing: 0.01em;
  padding: 0.4rem 0.85rem; border-radius: 9999px;
  text-decoration: none; white-space: nowrap;
  box-shadow: 0 2px 10px rgba(239,68,68,0.45);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn-vivo:hover { background: #dc2626; transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(239,68,68,0.55); }
.btn-vivo .dot-vivo {
  width: 7px; height: 7px; border-radius: 50%; background: #fff;
  animation: parpadeo 1.2s ease-in-out infinite;
}
@keyframes parpadeo { 0%,100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Fila de sesión seleccionada en la tabla */
.bw-table tbody tr.sel td { background: rgba(2,110,238,0.09); font-weight: 700; color: var(--bw-ink); }
.bw-table tbody tr.clickable { cursor: pointer; }
.btn-todos {
  margin-top: 0.9rem; border: 1px solid var(--bw-border); background: #fff;
  color: var(--bw-blue); font-family: inherit; font-size: 0.78rem; font-weight: 700;
  padding: 0.45rem 0.9rem; border-radius: 0.6rem; cursor: pointer;
  transition: background 0.15s ease;
}
.btn-todos:hover { background: rgba(2,110,238,0.06); }

/* Timeline de recorridos (chips con nota) — usado en el histórico y en /vivo */
.tl-inline { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.6rem; }
.tl-dia-lbl { font-size: 0.66rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.06em; color: #94a3b8; margin-top: 0.4rem; }
.tl-fila { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.tl-chip {
  border: 1px solid var(--bw-border); background: #fff; color: var(--bw-ink);
  border-radius: 0.7rem; padding: 0.28rem 0.55rem 0.28rem 0.4rem; cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.45rem; line-height: 1.1;
  font-family: inherit; transition: background 0.15s ease, border-color 0.15s ease;
}
.tl-chip:hover { background: rgba(2,110,238,0.06); }
.tl-chip.activo { background: var(--bw-blue); border-color: var(--bw-blue); }
.tl-chip.activo b { color: #fff; } .tl-chip.activo .tl-info span { color: rgba(255,255,255,0.85); }
.tl-chip b { font-size: 0.78rem; font-weight: 800; }
.tl-g { width: 1.5rem; height: 1.5rem; border-radius: 0.45rem; color: #fff;
  font-size: 0.62rem; font-weight: 900; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; }
.tl-info { display: flex; flex-direction: column; align-items: flex-start; }
.tl-info span { font-size: 0.62rem; color: #94a3b8; font-weight: 600; }
.tl-todos { padding: 0.4rem 0.8rem; }
.tl-todos b { margin: 0 0.35rem; }
.tl-todos span { font-size: 0.68rem; color: #94a3b8; font-weight: 700; }
.tl-todos.activo span { color: rgba(255,255,255,0.85); }

/* ---------- Layout ---------- */
.wrap { max-width: 1320px; margin: 0 auto; padding: 1.5rem; }

/* ===== MÓVIL (para que Nacho lo vea bien en el celular) ===== */
@media (max-width: 680px) {
  body { overflow-x: hidden; }
  .topbar { flex-wrap: wrap; gap: 0.5rem; padding: 0.65rem 0.9rem; }
  .topbar .brand { flex: 1 1 100%; }
  .topbar .sub { display: none; }              /* ocultar subtítulo en móvil */
  .topbar .title { font-size: 0.98rem; white-space: nowrap; }
  .topbar .right { flex: 1 1 100%; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-start; }
  .topbar select, .topbar .btn-vivo, .topbar .pill, .topbar .link-hist { font-size: 0.72rem; }
  .wrap { padding: 0.9rem; }
  .kpi-card { padding: 1rem 1.1rem; }
  .kpi-value { font-size: 1.55rem; }
  .section-card { padding: 1rem; }
  .section-title { margin: 1.1rem 0 0.6rem; }
  /* la fila de tasas (card de eventos) se apila en vez de salirse */
  .tasa-row { flex-direction: column; gap: 0.5rem; align-items: flex-start; }
  .tasa-row .t-hint { margin-left: 0; max-width: none; }
  /* tablas que no quepan → scroll horizontal dentro de su card */
  .section-card .bw-table { font-size: 0.78rem; }
  .bw-table thead th, .bw-table tbody td { padding: 0.5rem 0.6rem; }
}
.page-fade { animation: fadeInUp 0.35s ease-out both; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(10px);} to { opacity:1; transform:none;} }
.grid { display: grid; gap: 1.1rem; }
.kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
/* align-items:start → cada tarjeta toma la altura de SU contenido.
   Sin esto el grid las estira a la más alta y la corta queda con un hueco blanco. */
.two-col { grid-template-columns: 1.6fr 1fr; align-items: start; }
@media (max-width: 900px){ .two-col { grid-template-columns: 1fr; } }

/* ===== Dashboard: reubica las cards para verse en una sola pantalla sin scroll (PC ancho) ===== */
.dash { display: flex; flex-direction: column; gap: 1.1rem; }
.dash > .d-title { margin: 0.2rem 0 0; }
@media (min-width: 1280px) {
  .dash {
    display: grid;
    height: calc(100vh - 66px - 3rem);            /* topbar + padding del .wrap */
    grid-template-columns: 1.7fr 1fr 1fr;
    grid-template-rows: auto auto minmax(0, 1.3fr) minmax(0, 1fr);
    grid-template-areas:
      "title title title"
      "kpis  kpis  kpis"
      "map   nota  tend"
      "map   ev    rec";
    gap: 0.9rem;
  }
  .dash > .d-title { grid-area: title; margin: 0; align-self: center; }
  .dash > .d-kpis  { grid-area: kpis; grid-template-columns: repeat(6, 1fr); }
  .dash > .d-map   { grid-area: map; display: flex; flex-direction: column; min-height: 0; }
  .dash > .d-map #map { flex: 1 1 auto; height: auto; min-height: 0; }
  .dash > .d-nota  { grid-area: nota; min-height: 0; overflow: auto; }
  .dash > .d-tend  { grid-area: tend; min-height: 0; overflow: auto; }
  .dash > .d-ev    { grid-area: ev;   min-height: 0; overflow: auto; }
  .dash > .d-rec   { grid-area: rec;  min-height: 0; overflow: auto; }
  .dash > .d-radar { display: none; }               /* redundante con las barras de la nota */
  .dash > .d-note  { display: none; }
  .dash .kpi-card  { padding: 0.7rem 0.95rem; }
  .dash .kpi-value { font-size: 1.4rem; }
}
.section-title {
  font-size: 0.78rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; color: #94a3b8; margin: 1.6rem 0 0.7rem;
}

/* ---------- KPI cards ---------- */
.kpi-card {
  background: var(--bw-white); border-radius: 1rem; padding: 1.15rem 1.3rem;
  border: 1px solid var(--bw-border); box-shadow: var(--bw-shadow-card);
  transition: box-shadow 0.2s ease, transform 0.2s ease;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.kpi-card:hover { box-shadow: var(--bw-shadow-hover); transform: translateY(-2px); }
.kpi-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.07em; color: #94a3b8; }
.kpi-value { font-size: 1.85rem; font-weight: 900; color: var(--bw-ink);
  line-height: 1; letter-spacing: -0.02em; }
.kpi-value small { font-size: 0.9rem; font-weight: 700; color: #94a3b8; }
.kpi-value.value-success { color: #16a34a; }
.kpi-value.value-danger  { color: #ef4444; }
.kpi-value.value-warning { color: #d97706; }
.kpi-foot { font-size: 0.72rem; color: #94a3b8; font-weight: 600; }

/* ---------- Section cards ---------- */
.section-card {
  background: var(--bw-white); border-radius: 1rem; padding: 1.4rem;
  border: 1px solid var(--bw-border); box-shadow: var(--bw-shadow-card);
}
.section-card-title { font-size: 0.95rem; font-weight: 800; color: var(--bw-ink);
  margin: 0 0 1rem; display: flex; align-items: center; gap: 0.5rem; }

/* ---------- Nota (grade) card ---------- */
.nota-card {
  background: linear-gradient(135deg, #fff, #f4f8ff);
  border: 1px solid var(--bw-border); border-radius: 1rem; padding: 1.4rem;
  box-shadow: var(--bw-shadow-card); text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
}
.grade {
  width: 5.5rem; height: 5.5rem; border-radius: 1.2rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.4rem; font-weight: 900; color: #fff; letter-spacing: -0.02em;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
.g-AAA,.g-AA { background: linear-gradient(135deg,#16a34a,#22c55e); }
.g-A { background: linear-gradient(135deg,#0284c7,#0ea5e9); }
.g-B { background: linear-gradient(135deg,#d97706,#f59e0b); }
.g-C { background: linear-gradient(135deg,#ea580c,#f97316); }
.g-D { background: linear-gradient(135deg,#dc2626,#ef4444); }
.nota-num { font-size: 2.6rem; font-weight: 900; color: var(--bw-ink); line-height: 1; }
.nota-num small { font-size: 1rem; color: #94a3b8; font-weight: 700; }

/* ---------- Component bars ---------- */
.comp-row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.7rem; }
.comp-label { width: 5.2rem; font-size: 0.78rem; font-weight: 700; color: #475569; }
.progress-track { flex: 1; height: 8px; background: #e2e8f0; border-radius: 9999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 9999px;
  background: linear-gradient(90deg, var(--bw-blue), var(--bw-blue-soft)); transition: width 0.7s ease; }
.comp-val { width: 2.4rem; text-align: right; font-size: 0.82rem; font-weight: 800; color: var(--bw-ink); }

/* ---------- Tables ---------- */
.bw-table { width: 100%; border-collapse: collapse; }
.bw-table thead th { padding: 0.55rem 0.9rem; text-align: left; font-size: 0.68rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: #94a3b8;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
.bw-table tbody td { padding: 0.65rem 0.9rem; font-size: 0.85rem; color: #334155;
  border-bottom: 1px solid #f1f5f9; }
.bw-table tbody tr:last-child td { border-bottom: none; }
.bw-table tbody tr:hover td { background: rgba(2,110,238,0.03); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.6rem;
  border-radius: 9999px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.03em; }
.badge-green  { background: #dcfce7; color: #16a34a; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-slate  { background: #f1f5f9; color: #64748b; }
.badge-blue   { background: rgba(2,110,238,0.1); color: var(--bw-blue); }
.badge-orange { background: #ffedd5; color: #ea580c; }

/* Tasa de eventos por 100 km — el número que realmente mueve la nota */
.tasa-row {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; align-items: baseline;
  background: #f8fafc; border: 1px solid #eef2f7; border-radius: 0.8rem;
  padding: 0.75rem 1rem; margin-top: 1rem;
}
.tasa-row .t-val { font-size: 1.35rem; font-weight: 900; color: var(--bw-ink); line-height: 1; }
.tasa-row .t-lab { font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: #94a3b8; display: block; margin-bottom: 0.2rem; }
.tasa-row .t-hint { font-size: 0.7rem; color: #94a3b8; font-weight: 600; margin-left: auto; max-width: 15rem; }

/* ---------- Event chips ---------- */
.ev-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.7rem; }
.ev-chip { border-radius: 0.8rem; padding: 0.8rem 1rem; border: 1px solid #eef2f7;
  display: flex; flex-direction: column; gap: 0.15rem; }
.ev-chip .n { font-size: 1.5rem; font-weight: 900; line-height: 1; }
.ev-chip .l { font-size: 0.72rem; font-weight: 700; color: #64748b; }
.ev-accel { background: #fff7ed; } .ev-accel .n { color: #ea580c; }
.ev-freno { background: #eff6ff; } .ev-freno .n { color: #2563eb; }

/* ---------- Map ---------- */
#map { height: 460px; border-radius: 0.9rem; z-index: 0; }
.leaflet-container { z-index: 0; }
.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin-top: 0.8rem; font-size: 0.75rem; color: #475569; font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }
.legend i.dot-ev { width: 9px; height: 9px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.15); }

/* Aviso de nota poco confiable (recorrido demasiado corto) */
.aviso-nota {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 0.7rem; padding: 0.6rem 0.8rem; margin-top: 0.6rem;
  font-size: 0.72rem; font-weight: 600; line-height: 1.35; text-align: left;
}

/* Marcador de exceso de velocidad: etiqueta roja con la velocidad pico */
.exc-tag {
  background: #dc2626; color: #fff; font-size: 0.66rem; font-weight: 800;
  border-radius: 0.4rem; border: 2px solid #fff; padding: 1px 4px; text-align: center;
  box-shadow: 0 1px 5px rgba(220,38,38,0.55); line-height: 1.2; white-space: nowrap;
}

/* Interruptores sobre el mapa (eventos / paradas) */
.chk-ev {
  margin-left: 0.9rem; font-size: 0.72rem; font-weight: 600; color: #64748b;
  display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer;
  text-transform: none; letter-spacing: 0;
}
.chk-ev input { cursor: pointer; margin: 0; }

/* ---------- Charts (SVG) ---------- */
.chart { width: 100%; height: 150px; display: block; }
.chart-cap { font-size: 0.72rem; color: #94a3b8; font-weight: 600; margin-top: 0.3rem; }

/* ---------- Note banner ---------- */
.note {
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 0.8rem; padding: 0.7rem 1rem; font-size: 0.8rem; font-weight: 600;
  display: flex; gap: 0.5rem; align-items: flex-start; margin-top: 1rem;
}
.muted { color: #94a3b8; }
.loading { text-align: center; padding: 4rem; color: #94a3b8; font-weight: 600; }
select { font-family: inherit; font-size: 0.82rem; font-weight: 700; color: var(--bw-ink);
  border: 1px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.15); color: #fff;
  border-radius: 0.6rem; padding: 0.3rem 0.6rem; }
select option { color: #0f172a; }
