/* ACP · FivePD Madrid — «Sala de mando»
   Oscuro grafito, rótulos pequeños en mayúscula y un solo azul acero. El color se reserva para
   los estados (bien, aviso, mal) y para los cuerpos. Todo sale de las variables de :root. */

:root {
  --fondo: #101317;
  --lateral: #0c0f12;
  --superficie: #161a1f;
  --superficie-2: #1d2228;
  --hundido: #13171b;
  --borde: #252b32;
  --borde-fuerte: #333b44;
  --texto: #e4e7eb;
  --texto-2: #9aa3ad;
  --texto-3: #69727c;
  --acento: #3d6fb4;
  --acento-hover: #4a7ec6;
  --acento-suave: #1a2433;
  --acento-texto: #86aee0;
  --exito: #4caf7d;
  --aviso-c: #d9a441;
  --mal: #e0645f;
  --mal-suave: #2c1819;
  --sombra-alta: 0 12px 32px rgb(0 0 0 / .5);

  --c-municipal: #4b8fe6;
  --c-cnp: #2aa57a;
  --c-fire: #e2683a;
  --c-ambulance: #d39a1d;
  --c-civil: #7d8695;

  --letra: 'Source Sans 3', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, Consolas, monospace;
  --radio: 3px;
  --alto-control: 34px;
  --lateral-ancho: 224px;
  color-scheme: dark;
}

/* ---------- Base ---------- */

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--texto); font: 14.5px/1.5 var(--letra); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p { margin: 0; }
/* Rótulo de página: pequeño, en mayúscula y con raya debajo; el contenido manda, no el título */
h1 { font-size: 17px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--texto-2); padding-bottom: 12px; border-bottom: 1px solid var(--borde); }
h2 { font-size: 11.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--texto-2); }
a { color: var(--acento-texto); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
.apagado { color: var(--texto-2); }
.error { color: var(--mal); }
[hidden] { display: none !important; }
svg { flex: none; }
::selection { background: var(--acento-suave); }

/* ---------- Controles ---------- */

.boton, button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--alto-control); padding: 0 12px;
  font: 500 13.5px var(--letra); color: var(--texto); white-space: nowrap; text-decoration: none;
  background: var(--superficie-2); border: 1px solid var(--borde-fuerte); border-radius: 2px;
  cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.boton:hover, button:hover { background: #242a31; border-color: #414a55; text-decoration: none; }
.boton:focus-visible, button:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
.primario { background: var(--acento); border-color: var(--acento); color: #fff; }
.primario:hover { background: var(--acento-hover); border-color: var(--acento-hover); }
.peligro { color: var(--mal); }
.peligro:hover { background: var(--mal-suave); border-color: var(--mal); }
.fantasma { background: transparent; border-color: transparent; color: var(--texto-2); }
.fantasma:hover { background: var(--superficie-2); color: var(--texto); }
.grande { height: 40px; padding: 0 18px; font-size: 14.5px; }
button:disabled { opacity: .55; cursor: default; }

input, select, textarea {
  font: 14px/1.4 var(--letra); color: var(--texto);
  background: var(--hundido); border: 1px solid var(--borde-fuerte); border-radius: 2px;
  padding: 7px 10px; min-width: 0; min-height: var(--alto-control);
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--texto-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--acento); box-shadow: 0 0 0 3px var(--acento-suave); }
input[type="checkbox"] { min-height: 0; accent-color: var(--acento); margin: 0; }

/* ---------- Entrada ---------- */

.puerta { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.puerta-caja { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.puerta-caja .marca { margin-bottom: 18px; padding: 0; }
.puerta-caja h1 { border: 0; padding: 0; }
.puerta-caja .boton { margin-top: 8px; }
.caja-error { background: var(--mal-suave); border-left: 2px solid var(--mal); padding: 10px 12px; font-size: 13.5px; }

/* ---------- Estructura ---------- */

.marca { display: flex; align-items: center; gap: 10px; padding: 4px 8px 0; }
.marca-escudo { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid var(--borde-fuerte); border-radius: var(--radio); }
.marca-escudo svg { width: 17px; height: 17px; fill: none; stroke: var(--texto); stroke-width: 1.6; stroke-linejoin: round; }
.marca-texto { display: grid; line-height: 1.2; }
.marca-texto strong { font-size: 13px; font-weight: 600; letter-spacing: .14em; }
.marca-texto small { font-size: 12px; color: var(--texto-2); }

.panel { display: grid; grid-template-columns: var(--lateral-ancho) minmax(0, 1fr); grid-template-rows: auto 1fr; min-height: 100vh; }
.lateral {
  grid-row: 1 / -1; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  padding: 16px 10px 12px; background: var(--lateral); border-right: 1px solid var(--borde);
}

.menu { display: flex; flex-direction: column; gap: 1px; flex: 1; min-height: 0; overflow-y: auto; }
.menu-grupo { margin: 14px 10px 4px; font-size: 10.5px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--texto-3); }
.menu-grupo:first-child { margin-top: 0; }
.menu button {
  justify-content: flex-start; gap: 10px; height: 32px; padding: 0 10px; width: 100%;
  background: transparent; border-color: transparent; color: var(--texto-2); font-weight: 500; font-size: 14px;
}
.menu button svg, .icono svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.menu button:hover { background: var(--superficie); border-color: transparent; color: var(--texto); }
.menu button.activo { background: var(--superficie-2); color: var(--texto); box-shadow: inset 2px 0 0 var(--acento); }
.menu button.activo svg { color: var(--acento-texto); }

.contador { margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 9px; background: var(--mal); color: #fff; font: 600 11px/18px var(--letra); text-align: center; }

.yo { display: flex; align-items: center; gap: 8px; padding: 10px 6px 0; border-top: 1px solid var(--borde); }
.yo img { width: 30px; height: 30px; border-radius: 50%; }
.yo-texto { display: grid; flex: 1; min-width: 0; line-height: 1.2; }
.yo-texto strong { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.yo-texto small { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--texto-3); }
.icono { width: 30px; height: 30px; padding: 0; background: transparent; border-color: transparent; color: var(--texto-2); }
.icono:hover { color: var(--texto); background: var(--superficie-2); border-color: transparent; }

.vista { padding: 28px 32px 56px; width: 100%; max-width: 1280px; }
.vista-dentro { display: grid; gap: 16px; }
.vista-dentro > h1 + .subtitulo { margin-top: -4px; }
.miga { font-size: 13.5px; margin-bottom: -8px; }
.miga a { color: var(--texto-2); }
.miga a:hover { color: var(--texto); }
.vista > .error, .vista > .apagado { padding: 8px 0; }

/* ---------- Bloques ---------- */

.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; min-width: 0; }
.formulario { display: grid; gap: 12px; align-content: start; }
.formulario label { display: grid; gap: 5px; font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--texto-3); }
/* Cabecera del bloque: el h2 de arriba ocupa todo el ancho con una raya debajo */
.tarjeta > h2:first-child { margin: -16px -16px 0; padding: 12px 16px; border-bottom: 1px solid var(--borde); }
/* Las tablas dentro de un bloque llegan a los bordes */
.tarjeta > .desliza { margin: 0 -16px; }
.tarjeta > .desliza:last-child { margin-bottom: -16px; }
.tarjeta > .desliza:last-child tbody tr:last-child td { border-bottom: 0; }
.tarjeta > h2:first-child + .desliza { margin-top: -12px; }
.tarjeta > :not(h2) + .desliza { border-top: 1px solid var(--borde); }
.tarjeta .tabla th:first-child, .tarjeta .tabla td:first-child { padding-left: 16px; }
.tarjeta .tabla th:last-child, .tarjeta .tabla td:last-child { padding-right: 16px; }

.subtitulo { color: var(--texto-2); font-size: 13.5px; max-width: 76ch; }

.rejilla { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.dos { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }

/* Cifras de resumen: la raya de abajo dice si algo va bien o mal */
.dato { display: grid; gap: 2px; align-content: start; padding: 14px 16px; }
.dato-etiqueta { font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--texto-3); }
.dato-valor { font-size: 26px; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }
.dato-pie { font-size: 12.5px; color: var(--texto-3); }
.dato.bien { box-shadow: inset 0 -2px 0 var(--exito); }
.dato.mal { box-shadow: inset 0 -2px 0 var(--mal); }
.dato.mal .dato-valor { color: var(--mal); }

.fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fila > input:not([type="number"]):not([type="checkbox"]), .fila > textarea { flex: 1 1 200px; }
.fila > input[type="number"] { width: 80px; }
.acciones { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.acciones button, .tabla td button, .tabla td select { height: 28px; min-height: 28px; padding-top: 0; padding-bottom: 0; font-size: 13px; }

/* ---------- Tablas ---------- */

.desliza { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla th { color: var(--texto-3); font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; }
.tabla tbody tr:hover td { background: var(--hundido); }
.tabla tr.clic { cursor: pointer; }
.tabla td.apagado { color: var(--texto-2); }
.tabla td > .acciones { justify-content: flex-end; }
.tabla td:last-child:has(> button, > .acciones) { text-align: right; }

/* ---------- Etiquetas de estado ---------- */

.chapa {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; overflow-wrap: anywhere;
  height: 22px; padding: 0 7px; border: 1px solid var(--borde-fuerte); border-radius: 2px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; line-height: 1; color: var(--texto-2);
}
.tabla .chapa { white-space: nowrap; overflow-wrap: normal; }
.chapa.mono { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12.5px; }
.chapa.ok { color: var(--exito); border-color: currentColor; }
.chapa.mal { color: var(--mal); border-color: currentColor; }
.chapa.aviso { color: var(--aviso-c); border-color: currentColor; }
.chapa.ok::before, .chapa.mal::before, .chapa.aviso::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
p.chapa { justify-self: start; height: auto; padding: 8px 10px; line-height: 1.4; }

.punto { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: var(--c-civil); }
.chapa .punto { margin-right: 0; }

/* Raya del color del cuerpo a la izquierda de su bloque */
.c-municipal, .c-cnp, .c-fire, .c-ambulance { border-left: 2px solid var(--c-municipal); }
.c-cnp { border-left-color: var(--c-cnp); }
.c-fire { border-left-color: var(--c-fire); }
.c-ambulance { border-left-color: var(--c-ambulance); }

/* ---------- Pestañas ---------- */

.pestanas { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; justify-self: start; background: var(--hundido); border: 1px solid var(--borde); border-radius: var(--radio); }
.pestanas button { height: 28px; padding: 0 12px; background: transparent; border-color: transparent; color: var(--texto-2); }
.pestanas button:hover { background: var(--superficie); border-color: transparent; color: var(--texto); }
.pestanas button.activo { background: var(--superficie-2); border-color: var(--borde-fuerte); color: var(--texto); }

/* ---------- Aviso flotante ---------- */

#aviso {
  position: fixed; right: 20px; bottom: 20px; left: 20px; margin-left: auto; max-width: 380px; z-index: 5;
  padding: 12px 14px; font-size: 14px;
  background: var(--superficie-2); border: 1px solid var(--borde-fuerte); border-left: 2px solid var(--acento); border-radius: var(--radio); box-shadow: var(--sombra-alta);
}
#aviso.mal { border-left-color: var(--mal); }
#aviso.ok { border-left-color: var(--exito); }

/* ---------- Fichas ---------- */

pre.detalle { margin: 0; max-width: 420px; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 var(--mono); color: var(--texto-2); }

.documento { display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: start; }
.documento .foto { width: 96px; height: 128px; object-fit: cover; border-radius: 2px; background: var(--superficie-2); border: 1px solid var(--borde); }
.documento img.firma { max-width: 160px; height: 40px; margin-top: 8px; object-fit: contain; filter: invert(1); opacity: .8; }
.documento dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.documento dt { color: var(--texto-3); }
.documento dd { margin: 0; }

.reporte { display: grid; gap: 10px; }
.reporte > .fila:first-child { gap: 12px; font-size: 13.5px; }
.reporte .texto { white-space: pre-wrap; padding: 10px 12px; background: var(--hundido); border-left: 2px solid var(--borde-fuerte); }

details { border-top: 1px solid var(--borde); padding: 10px 0 0; }
details > summary { cursor: pointer; font-weight: 500; }
details[open] > summary { margin-bottom: 10px; }
details dl.formulario { margin: 0; gap: 4px; }
details dd { margin: 0 0 8px; }
.filtro { max-width: 300px; }

/* ---------- Mapa ---------- */

.mapa-caja { position: relative; }
.mapa-caja canvas { width: 100%; height: auto; display: block; background: var(--hundido); border-radius: 2px; cursor: crosshair; }
.burbuja { position: absolute; pointer-events: none; z-index: 3; padding: 6px 10px; white-space: nowrap; font-size: 13px; background: var(--superficie-2); border: 1px solid var(--borde-fuerte); border-radius: 2px; box-shadow: var(--sombra-alta); }
.leyenda { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13.5px; color: var(--texto-2); }
.leyenda label { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; cursor: pointer; background: var(--superficie); border: 1px solid var(--borde); border-radius: 2px; }
.leyenda .punto { margin: 0; }

/* ---------- Gráficas ---------- */

.grafica svg { width: 100%; height: auto; display: block; overflow: visible; }
.grafica .eje { stroke: var(--borde-fuerte); stroke-width: 1; }
.grafica .rejilla-g { stroke: var(--borde); stroke-width: 1; }
.grafica text { fill: var(--texto-3); font: 11px var(--letra); }
.grafica .linea { fill: none; stroke: var(--acento-texto); stroke-width: 1.75; stroke-linejoin: round; }
.grafica .area { fill: var(--acento); opacity: .14; }
.grafica .barra { fill: var(--acento); }
.grafica .barra:hover, .grafica .zona:hover + .barra { fill: var(--acento-hover); }
.grafica .zona { fill: transparent; }
.grafica .cruz { stroke: var(--texto-3); stroke-width: 1; stroke-dasharray: 3 3; }
.grafica .marca { fill: var(--acento-texto); stroke: var(--superficie); stroke-width: 2; }

.barras-h { display: grid; gap: 8px; }
.barras-h .fila-b { display: grid; grid-template-columns: minmax(0, 150px) 1fr 88px; gap: 12px; align-items: center; font-size: 14px; }
.barras-h .fila-b > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barras-h .pista { height: 6px; background: var(--hundido); }
.barras-h .relleno { height: 6px; min-width: 2px; }
.barras-h .valor { text-align: right; color: var(--texto-2); font-variant-numeric: tabular-nums; }

.redondo { border-radius: 50%; }

/* ---------- Pantallas estrechas: la barra lateral pasa a barra de arriba ---------- */

@media (max-width: 900px) {
  .panel { grid-template-columns: minmax(0, 1fr); }
  .lateral { grid-row: auto; position: sticky; z-index: 4; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--borde); }
  .lateral .marca { padding: 0; }
  .menu { order: 3; flex: 1 0 100%; flex-direction: row; overflow-x: auto; overflow-y: hidden; gap: 2px; scrollbar-width: none; }
  .menu-grupo { display: none; }
  .menu button { width: auto; flex: none; }
  .menu button.activo { box-shadow: inset 0 -2px 0 var(--acento); }
  .yo { margin-left: auto; padding: 0; border-top: 0; }
  .yo-texto { display: none; }
  .vista { padding: 20px 16px 48px; }
}
@media (max-width: 640px) {
  .dos { grid-template-columns: minmax(0, 1fr); }
  .rejilla { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabla th, .tabla td { padding: 7px 8px; white-space: nowrap; }
  .barras-h .fila-b { grid-template-columns: 96px 1fr 72px; gap: 8px; }
  .documento { grid-template-columns: 72px 1fr; }
  .documento .foto { width: 72px; height: 96px; }
}
