/* Pantalla de TV: 1920x1080, vista a 3-4 m, sin scroll. */
:root {
  --fondo: #0b0f16;
  --superficie: #151b26;
  --tarjeta: #1d2533;
  --borde: #2a3445;
  --texto: #f2f4f8;
  --texto-2: #b9c1cf;
  --texto-3: #7d8899;
  --rojo: #e5484d;
  --naranja: #f5a524;
  --verde: #30a46c;
  --alto-tarjeta: 85px;    /* app.js lo lee para saber cuántas caben (4 por columna) */
  --hueco: 6px;
  --pulso-ms: 1800;        /* periodo del parpadeo de las rojas; app.js lo usa para sincronizar */
  --rojo-pulso: #4a1c21;   /* fondo de la tarjeta roja en el punto alto del pulso */

  /* Pastillas de etiqueta (tarjetas y barra): fondo claro, texto oscuro del mismo tono, borde.
     INI usa #0369a1 en vez de #0284c7: con este fondo daba 3,6:1 y no llegaba a 4,5:1. */
  --pen-fondo: #fef3c7; --pen-texto: #b45309; --pen-borde: #fde68a;
  --cam-fondo: #f3e8ff; --cam-texto: #7e22ce; --cam-borde: #d8b4fe;
  --ini-fondo: #e0f2fe; --ini-texto: #0369a1; --ini-borde: #7dd3fc;
  --rep-fondo: #ccfbf1; --rep-texto: #0f766e; --rep-borde: #5eead4;
  --rev-fondo: #ffedd5; --rev-texto: #c2410c; --rev-borde: #fdba74;
  --ter-fondo: #dcfce7; --ter-texto: #15803d; --ter-borde: #86efac;
  --otro-fondo: #f1f5f9; --otro-texto: #475569; --otro-borde: #cbd5e1;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--fondo);
  color: var(--texto);
  font-family: system-ui, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- vistas (paneles y mapa; con ?rotar=1 se alternan) ---------- */
.vista { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.vista[hidden] { display: none; }

/* ---------- barra superior ---------- */
.barra {
  flex: 0 0 104px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--superficie);
  border-bottom: 2px solid var(--borde);
}
.grupo {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding-right: 14px;
  border-right: 2px solid var(--borde);
}
.grupo:last-child { border-right: 0; padding-right: 0; }
.grupo.hora { margin-left: auto; }
.etiqueta { font-size: 16px; letter-spacing: .08em; color: var(--texto-3); font-weight: 700; }
.dato { font-size: 36px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dato b { color: var(--texto-2); font-weight: 600; margin-right: 4px; }
.dato small { font-size: 18px; color: var(--texto-2); font-weight: 500; }
/* TIPO: separador vertical discreto entre cada par letra-número */
.tipos .dato + .dato { border-left: 2px solid var(--borde); padding-left: 16px; }
.estados .dato { display: inline-flex; align-items: center; gap: 10px; }
.estados .pastilla { font-size: 24px; line-height: 32px; padding: 0 8px; border-radius: 6px; }
.carros .dato { font-size: 30px; }   /* barra del mapa */
.carros .dato[hidden] { display: none; }
.dato.sin-datos { color: var(--texto-3); font-weight: 600; }
.dato.alerta { color: var(--rojo); }
.dato.alerta small { color: var(--rojo); }

/* ---------- aviso ---------- */
/* Paneles: barra más baja que la del mapa para ganar alto (4 tarjetas por columna) */
#barra { flex-basis: 80px; }

.aviso {
  flex: 0 0 auto;
  padding: 10px 20px;
  background: var(--rojo);
  color: #fff;
  font-size: 34px;
  font-weight: 800;
  text-align: center;
  animation: latido 2s ease-in-out infinite;
}
.aviso[hidden] { display: none; }
@keyframes latido { 50% { opacity: .75; } }

/* ---------- paneles ---------- */
#paneles {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  padding: 8px;
}
.panel {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--superficie);
  border: 2px solid var(--borde);
  border-radius: 10px;
  padding: 6px 8px 8px;
}
.panel-cabecera {
  flex: 0 0 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.panel-titulo { font-size: 30px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; }
.conteos { display: flex; gap: 10px; font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.conteos span { min-width: 54px; text-align: center; padding: 0 8px; border-radius: 6px; border: 2px solid; }
.conteos .rojo { border-color: var(--rojo); }
.conteos .naranja { border-color: var(--naranja); }
.conteos .verde { border-color: var(--verde); }

.columnas {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.columna { min-height: 0; min-width: 0; display: flex; flex-direction: column; }
.columna-cabecera {
  flex: 0 0 30px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 6px 6px 0 0;
  font-size: 21px;
  font-weight: 800;
  color: #0b0f16;
  white-space: nowrap;
}
.mas {
  flex: 0 0 26px;
  font-size: 23px;
  font-weight: 700;
  color: var(--texto-2);
  text-align: center;
  line-height: 26px;
}
.columna.rojo .columna-cabecera { background: var(--rojo); }
.columna.naranja .columna-cabecera { background: var(--naranja); }
.columna.verde .columna-cabecera { background: var(--verde); }
.columna-cuerpo {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: var(--hueco);
  padding-top: var(--hueco);
}
.vacio { color: var(--texto-3); font-size: 20px; text-align: center; padding-top: 16px; }

/* ---------- tarjeta ---------- */
/* Rejilla: tiempo | tipo · cliente | etiqueta · técnico y jefe a todo el ancho. */
.tarjeta {
  flex: 0 0 var(--alto-tarjeta);
  height: var(--alto-tarjeta);
  background: var(--tarjeta);
  border-left: 8px solid;
  border-radius: 6px;
  padding: 1px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: auto auto auto;
  align-content: space-between;
  column-gap: 6px;
  overflow: hidden;
}
.rojo .tarjeta { border-color: var(--rojo); }
.naranja .tarjeta { border-color: var(--naranja); }
.verde .tarjeta { border-color: var(--verde); }
.tiempo { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tiempo.estimado { color: var(--texto-2); font-weight: 600; }   /* hora de respaldo: más apagado */
.tipo { align-self: center; justify-self: end; font-size: 20px; font-weight: 700; color: var(--texto-2); }
.pastilla {
  border: 1px solid var(--otro-borde);
  border-radius: 4px;
  background: var(--otro-fondo);
  color: var(--otro-texto);
  font-weight: 800;
  letter-spacing: .04em;
}
.pastilla[data-etiqueta="PEN"] { background: var(--pen-fondo); color: var(--pen-texto); border-color: var(--pen-borde); }
.pastilla[data-etiqueta="CAM"] { background: var(--cam-fondo); color: var(--cam-texto); border-color: var(--cam-borde); }
.pastilla[data-etiqueta="INI"] { background: var(--ini-fondo); color: var(--ini-texto); border-color: var(--ini-borde); }
.pastilla[data-etiqueta="REP"] { background: var(--rep-fondo); color: var(--rep-texto); border-color: var(--rep-borde); }
.pastilla[data-etiqueta="REV"] { background: var(--rev-fondo); color: var(--rev-texto); border-color: var(--rev-borde); }
.pastilla[data-etiqueta="TER"] { background: var(--ter-fondo); color: var(--ter-texto); border-color: var(--ter-borde); }
.tarjeta .pastilla { align-self: center; justify-self: end; padding: 0 5px; font-size: 17px; line-height: 21px; }
.cliente, .personas { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.05; }
.cliente { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cliente.ancho { grid-column: 1 / -1; }
.personas { grid-column: 1 / -1; font-size: 24px; font-weight: 500; color: #ccd3de; }

/* Rojas: pulso lento del fondo (no del texto), todas en fase (app.js fija animation-delay). */
.columna.rojo .tarjeta { animation: pulso-rojo calc(var(--pulso-ms) * 1ms) ease-in-out infinite; }
@keyframes pulso-rojo { 50% { background: var(--rojo-pulso); } }
.sin-parpadeo .columna.rojo .tarjeta { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .columna.rojo .tarjeta { animation: none; }
}

/* ---------- franja de validación (bajo Reportado) ---------- */
.validacion {
  flex: 0 0 auto;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--tarjeta);
  border: 2px solid var(--borde);
  font-size: 22px;
  font-weight: 600;
  color: var(--texto-2);
  line-height: 1.3;
}
.validacion b { color: var(--texto); }
.validacion.alerta { background: #4a1517; border-color: var(--rojo); color: var(--texto); }

/* ---------- vista del mapa (mapa.html o ?rotar=1) ---------- */
:root { --gris: #8b95a5; --azul: #60a5fa; }   /* azul: parado (< 40 min), distinto del verde y el naranja */
.titulo-vista { font-size: 30px; font-weight: 800; letter-spacing: .02em; }
.mapa-cuerpo { flex: 1 1 auto; min-height: 0; display: flex; gap: 12px; padding: 12px; }
.mapa-marco {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  border: 2px solid var(--borde);
  border-radius: 10px;
  overflow: hidden;
}
.mapa-lienzo { position: absolute; inset: 0; }
/* OSM estándar en tema oscuro: invertir y devolver los tonos de agua y parques */
.teselas-oscuras { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.6); }
.mapa-lienzo.leaflet-container { background: var(--fondo); font-family: inherit; }
.mapa-lienzo .leaflet-control-attribution { background: rgba(11, 15, 22, .7); color: var(--texto-3); font-size: 12px; }
.mapa-lienzo .leaflet-control-attribution a { color: var(--texto-2); }
.mapa-vacio {
  position: absolute;
  inset: 0;
  z-index: 1000;   /* encima de las teselas y marcadores de Leaflet */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(11, 15, 22, .75);
  color: var(--texto-2);
  font-size: 64px;
  font-weight: 800;
}
.mapa-vacio[hidden] { display: none; }

/* marcador: punto de color + rótulo grande (legible a 3-4 m) */
.icono-carro { background: none; border: 0; }
.carro { position: relative; width: 36px; height: 36px; white-space: nowrap; }
.carro .punto { position: absolute; inset: 0; }
.punto {
  display: inline-block;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  border: 4px solid var(--fondo);
  box-shadow: 0 0 0 3px var(--texto);
  background: var(--verde);
}
.punto.parado, .carro.parado .punto { background: var(--azul); }
.punto.detenido, .carro.detenido .punto { background: var(--naranja); }
.punto.sin-reporte, .carro.sin-reporte .punto { background: var(--gris); }
.rotulo {
  position: absolute;
  top: 50%;
  left: 46px;
  transform: translateY(-50%);
  padding: 2px 12px;
  border-radius: 6px;
  border: 2px solid var(--verde);
  background: rgba(11, 15, 22, .88);
  color: var(--texto);
  font-size: 28px;
  font-weight: 800;
  line-height: 1.25;
}
.carro.izquierda .rotulo { left: auto; right: 46px; }
.carro.parado .rotulo { border-color: var(--azul); }
.carro.detenido .rotulo { border-color: var(--naranja); }
.carro.sin-reporte .rotulo { border-color: var(--gris); border-style: dashed; color: var(--texto-2); }
/* rótulo tapado por otro de más prioridad (mapa.js): se oculta sin perder su tamaño medido */
.carro.sin-rotulo .rotulo { visibility: hidden; }
/* sin reportar hace más de 1 día: punto gris chico, sin rótulo */
.carro.viejo .punto { inset: 11px; width: 14px; height: 14px; border-width: 2px; box-shadow: 0 0 0 1px var(--texto-3); opacity: .8; }
.carro.viejo .rotulo { display: none; }
.placa { margin-left: 10px; font-size: 20px; font-weight: 600; color: var(--texto-2); }

/* lista lateral: detenidos (el más antiguo arriba) y sin reportar (el más reciente arriba) */
.mapa-lista {
  flex: 0 0 420px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--superficie);
  border: 2px solid var(--borde);
  border-radius: 10px;
  overflow: hidden;
}
.lista-titulo { flex: 0 0 auto; font-size: 30px; font-weight: 800; display: flex; justify-content: space-between; }
.lista-items { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 8px; }
.lista-item { flex: 0 0 auto; background: var(--tarjeta); border-left: 8px solid var(--naranja); border-radius: 6px; padding: 8px 12px; }
.lista-item.sin-reporte { border-left-color: var(--gris); }
.lista-nombre { font-size: 28px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lista-detalle { font-size: 22px; color: var(--texto-2); font-weight: 600; }
.lista-mas { flex: 0 0 auto; font-size: 22px; font-weight: 700; color: var(--texto-2); padding-left: 4px; }
.lista-viejos { flex: 0 0 auto; font-size: 22px; font-weight: 600; color: var(--texto-3); border-left: 8px solid var(--borde); padding: 4px 12px; }
.lista-viejos[hidden] { display: none; }
.leyenda { flex: 0 0 auto; display: flex; flex-direction: column; gap: 8px; padding-top: 10px; border-top: 2px solid var(--borde); font-size: 22px; color: var(--texto-2); }
.leyenda div { display: flex; align-items: center; gap: 12px; }
.leyenda .punto { width: 24px; height: 24px; flex-basis: 24px; border-width: 3px; box-shadow: 0 0 0 2px var(--texto); }

/* ---------- seguimiento (mapa.html?modo=seguimiento): 3×2 mapas, uno por carro ---------- */
.seg-cuerpo { position: relative; flex: 1 1 auto; min-height: 0; padding: 8px; }
.seg-grilla {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.seg-atribucion {
  position: absolute; right: 14px; bottom: 12px; z-index: 1100;
  padding: 0 6px; border-radius: 4px; background: rgba(11, 15, 22, .7);
  color: var(--texto-3); font-size: 12px;
}
.puesto {
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--superficie);
  border: 2px solid var(--borde);
  border-radius: 10px;
  overflow: hidden;
}
.puesto.detenido { border-color: var(--naranja); }
.puesto.sin-reporte { border-color: var(--gris); border-style: dashed; }
.puesto-cab { flex: 0 0 auto; padding: 4px 12px 6px; }
.fila1, .fila2 { display: flex; align-items: center; gap: 10px; white-space: nowrap; min-width: 0; }
.fila1 { height: 40px; }
.fila2 { height: 32px; }
.pin { flex: 0 0 auto; width: 22px; height: 22px; color: var(--texto-2); }   /* puesto fijado por el administrador */
.pin svg { width: 100%; height: 100%; fill: currentColor; }
.pin[hidden] { display: none; }
.p-nombre { font-size: 28px; font-weight: 800; }
.puesto .placa { margin-left: 0; }
.p-estado:empty { display: none; }
.p-estado {
  padding: 0 8px; border-radius: 6px;
  font-size: 20px; font-weight: 800; line-height: 28px; color: #0b0f16;
  background: var(--verde);
}
.puesto.parado .p-estado { background: var(--azul); }
.puesto.detenido .p-estado { background: var(--naranja); }
.puesto.sin-reporte .p-estado { background: var(--gris); }
.p-der { margin-left: auto; flex: 0 0 auto; display: flex; gap: 12px; font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.p-hace { color: var(--texto-2); font-weight: 600; }
.fila2 .pastilla { flex: 0 0 auto; padding: 0 6px; font-size: 18px; line-height: 24px; }
.fila2 .pastilla[hidden] { display: none; }
.p-texto { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 22px; font-weight: 600; }
.p-texto.tecnico { color: var(--texto-2); font-weight: 500; }
.puesto-mapa { position: relative; flex: 1 1 auto; min-height: 0; }
.puesto-lienzo { position: absolute; inset: 0; }
.puesto-lienzo.leaflet-container { background: var(--fondo); font-family: inherit; }
/* Sin reportar: mapa atenuado; el aviso "sin señal" queda encima, sobre la última posición. */
.puesto.sin-reporte .leaflet-tile-pane,
.puesto.sin-reporte .leaflet-overlay-pane { opacity: .4; }
.puesto-libre {
  position: absolute; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: var(--superficie); color: #566070;   /* más tenue que --texto-3 */
  font-size: 34px; font-weight: 600; text-align: center;
}
.puesto.libre .puesto-libre { display: flex; }
.puesto.libre .fila1 .p-nombre { color: var(--texto-3); }

/* marcador del carro: punto de estado + flecha según rumbo (gira alrededor del centro) */
.seg-carro { position: relative; width: 72px; height: 72px; }
.seg-carro .punto { position: absolute; left: 18px; top: 18px; }
.seg-carro.parado .punto { background: var(--azul); }
.seg-carro.detenido .punto { background: var(--naranja); }
.seg-carro.sin-reporte .punto { background: var(--gris); }
.seg-carro .flecha { position: absolute; inset: 0; width: 72px; height: 72px; fill: var(--texto); stroke: var(--fondo); stroke-width: 2; }
.seg-carro.sin-reporte .flecha { fill: var(--gris); }
.sin-senal {
  position: absolute; left: 50%; bottom: 100%; transform: translateX(-50%);
  padding: 2px 10px; border-radius: 6px;
  border: 2px dashed var(--gris); background: rgba(11, 15, 22, .9);
  color: var(--texto); font-size: 22px; font-weight: 700; white-space: nowrap;
}
.sin-senal:empty { display: none; }

/* destino: rombo con los colores de la pastilla de su etiqueta */
.seg-destino {
  width: 24px; height: 24px; margin: 2px; transform: rotate(45deg);
  border: 3px solid var(--otro-texto); background: var(--otro-fondo);
  box-shadow: 0 0 0 2px var(--fondo);
}
.seg-destino[data-etiqueta="PEN"] { background: var(--pen-fondo); border-color: var(--pen-texto); }
.seg-destino[data-etiqueta="CAM"] { background: var(--cam-fondo); border-color: var(--cam-texto); }
.seg-destino[data-etiqueta="INI"] { background: var(--ini-fondo); border-color: var(--ini-texto); }
.seg-destino[data-etiqueta="REP"] { background: var(--rep-fondo); border-color: var(--rep-texto); }
.seg-destino[data-etiqueta="REV"] { background: var(--rev-fondo); border-color: var(--rev-texto); }
.seg-destino[data-etiqueta="TER"] { background: var(--ter-fondo); border-color: var(--ter-texto); }

/* ---------- sesión de usuario (modo sesión, comun.js): esquina discreta ----------
   En el hueco libre de la barra superior, a la izquierda de "ACTUALIZADO" (igual en las tres
   vistas); abajo tapaba la leyenda del mapa y la atribución del seguimiento. */
.sesion-usuario {
  position: fixed; right: 330px; top: 25px; z-index: 3000;
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px 4px 12px; border-radius: 8px;
  background: rgba(21, 27, 38, .85); border: 1px solid var(--borde);
  font-size: 15px; color: var(--texto-3);
  opacity: .7;
}
.sesion-usuario:hover, .sesion-usuario:focus-within { opacity: 1; }
/* Pantallas más angostas que la TV: la barra no deja hueco; abajo a la derecha. */
@media (max-width: 1700px) { .sesion-usuario { top: auto; bottom: 8px; right: 8px; } }
.sesion-salir {
  font: inherit; color: var(--texto-2); background: var(--tarjeta);
  border: 1px solid var(--borde); border-radius: 6px; padding: 3px 10px; cursor: pointer;
}
.sesion-salir:hover { color: var(--texto); border-color: var(--texto-3); }

/* ---------- login.html (pensado para PC: letra normal) ---------- */
body.login { align-items: center; justify-content: center; overflow: auto; padding: 16px; }
.login-caja {
  width: 100%; max-width: 360px; padding: 28px 28px 24px;
  background: var(--superficie); border: 1px solid var(--borde); border-radius: 12px;
  font-size: 16px;
}
.login-caja h1 { margin: 0 0 4px; font-size: 22px; }
.login-caja .sub { margin: 0 0 22px; color: var(--texto-3); font-size: 14px; }
.login-caja label { display: block; margin: 0 0 6px; color: var(--texto-2); font-size: 14px; }
.login-caja input {
  width: 100%; margin: 0 0 16px; padding: 10px 12px; font: inherit; color: var(--texto);
  background: var(--fondo); border: 1px solid var(--borde); border-radius: 8px;
}
.login-caja input:focus { outline: 2px solid var(--ini-borde); outline-offset: 1px; border-color: transparent; }
.login-caja button {
  width: 100%; margin-top: 4px; padding: 11px; font: inherit; font-weight: 700; color: var(--fondo);
  background: var(--texto); border: 0; border-radius: 8px; cursor: pointer;
}
.login-caja button:disabled { opacity: .6; cursor: wait; }
.login-error {
  margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; font-size: 14px;
  background: var(--rojo-pulso); border: 1px solid var(--rojo); color: var(--texto);
}
.login-error[hidden] { display: none; }
