/*
 * HE FORGE Vacas — mismo sistema visual que HE FORGE Flota:
 * tinta azul pizarra + fondo calido neutro + un solo acento ambar.
 * Los estados tambien se distinguen por texto e icono, no solo por color.
 */
@font-face { font-family: 'Archivo'; font-weight: 600; font-display: swap; src: url(/fonts/archivo-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'Archivo'; font-weight: 700; font-display: swap; src: url(/fonts/archivo-latin-700-normal.woff2) format('woff2'); }
@font-face { font-family: 'Archivo'; font-weight: 800; font-display: swap; src: url(/fonts/archivo-latin-800-normal.woff2) format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 400; font-display: swap; src: url(/fonts/ibm-plex-sans-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-sans-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'IBM Plex Sans'; font-weight: 600; font-display: swap; src: url(/fonts/ibm-plex-sans-latin-600-normal.woff2) format('woff2'); }
@font-face { font-family: 'IBM Plex Mono'; font-weight: 500; font-display: swap; src: url(/fonts/ibm-plex-mono-latin-500-normal.woff2) format('woff2'); }

:root {
  --tinta: #16202b;
  --tinta-2: #243242;
  --tinta-3: #2e3c4b;
  --fondo: #f3f1ec;
  --superficie: #ffffff;
  --superficie-2: #faf8f4;
  --borde: #e2ddd3;
  --borde-fuerte: #cfc8bb;
  --linea: #efebe3;
  --texto: #16202b;
  --texto-2: #5c6773;
  --texto-3: #8b94a0;
  --acento: #e8a33d;
  --acento-texto: #9a5410;
  --ok: #1f6b45;
  --ok-fondo: #e6f2ea;
  --ok-texto: #1f4d35;
  --alerta: #b5620f;
  --alerta-fondo: #fdf3e4;
  --alerta-texto: #7a420b;
  --peligro: #b42318;
  --peligro-fondo: #fceeec;
  --peligro-texto: #8c1d13;
  --info: #16798a;
  --info-fondo: #e1f0f1;
  --info-texto: #0e4f5a;
  --barra-dato: #2e3c4b;
  --radio: 8px;
  --radio-grande: 14px;
  --sombra: 0 1px 2px rgb(22 32 43 / 6%);
  --fuente: 'IBM Plex Sans', system-ui, sans-serif;
  --fuente-titulo: 'Archivo', 'IBM Plex Sans', sans-serif;
  --fuente-mono: 'IBM Plex Mono', ui-monospace, monospace;
  font-family: var(--fuente);
  color: var(--texto);
  background: var(--fondo);
  -webkit-font-smoothing: antialiased;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--fondo); font-size: 15px; line-height: 1.45; }
h1, h2, h3 { font-family: var(--fuente-titulo); letter-spacing: 0.1px; margin: 0 0 12px; }
h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
a { color: var(--texto); }
a:hover { color: var(--acento-texto); }
:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.barra {
  height: 64px; display: flex; align-items: center; gap: 14px; padding: 0 24px;
  padding-top: env(safe-area-inset-top);
  background: var(--superficie); border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; z-index: 10;
}
.barra .empresa { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.barra .empresa small { font-size: 12px; color: var(--texto-2); }
.barra .empresa strong { font-family: var(--fuente-titulo); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra .volver {
  width: 40px; min-height: 40px; height: 40px; margin: 0 0 0 -8px; padding: 0;
  background: transparent; color: var(--texto); border: 1px solid transparent; font-size: 20px;
}
.barra .volver:hover { background: var(--superficie-2); border-color: var(--borde); }
.espaciador { flex: 1; }
.red { font-size: 12px; font-weight: 600; background: var(--alerta-fondo); color: var(--alerta-texto); padding: 3px 10px; border-radius: 999px; }

.cuerpo { display: flex; flex: 1; min-height: 0; }
.menu {
  width: 232px; flex-shrink: 0; background: var(--tinta); color: #c9ced4;
  display: flex; flex-direction: column; gap: 4px; padding: 20px 14px;
  position: sticky; top: 64px; height: calc(100vh - 64px);
}
.marca { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; color: #fff; text-decoration: none; }
.marca-logo {
  width: 34px; height: 34px; border-radius: var(--radio); background: var(--acento);
  display: inline-flex; align-items: center; justify-content: center; color: var(--tinta); flex-shrink: 0;
}
.marca strong { font-family: var(--fuente-titulo); font-weight: 800; font-size: 17px; display: block; line-height: 1.1; }
.marca small { font-size: 11px; letter-spacing: 1.6px; text-transform: uppercase; color: #9aa6b2; }
.menu a {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 10px 12px;
  border-radius: var(--radio); color: #c9ced4; text-decoration: none; font-size: 14px;
}
.menu a:hover { background: var(--tinta-2); color: #fff; }
.menu a.active, .menu a.active:hover { background: var(--acento); color: var(--tinta); font-weight: 600; }
.menu :focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.menu svg { flex-shrink: 0; }
.menu .cuenta-alerta {
  margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--peligro); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.menu-pie { margin-top: auto; border-top: 1px solid var(--tinta-3); padding-top: 12px; }

.contenido {
  flex: 1; min-width: 0; width: 100%; max-width: 1280px; margin: 0 auto;
  padding: 28px 36px 48px;
}
.cabecera-pagina { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.cabecera-pagina h1 { margin: 0; }
.cabecera-pagina small { display: block; color: var(--texto-2); font-size: 13px; margin-bottom: 2px; }

/* ---------- Paneles e indicadores ---------- */
.panel {
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-grande);
  padding: 20px; box-shadow: var(--sombra); margin-bottom: 16px; min-width: 0;
}
.panel-cabecera { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-cabecera h2 { margin: 0; font-size: 16px; }
.panel-cabecera .pequeno { margin-left: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--texto); margin: 0; }
a.kpi:hover { border-color: var(--borde-fuerte); color: var(--texto); }
.kpi-titulo { font-size: 13px; color: var(--texto-2); }
.kpi-valor { font-family: var(--fuente-titulo); font-weight: 800; font-size: 32px; line-height: 1.15; }
.kpi-valor.peligro { color: var(--peligro); }
.kpi-detalle { font-size: 13px; font-weight: 600; color: var(--texto-2); }
.kpi-detalle.ok { color: var(--ok); }
.kpi-detalle.alerta { color: var(--alerta-texto); }
.kpi-detalle.peligro { color: var(--peligro-texto); }
.grilla-2 {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 16px; align-items: start;
}
.grilla-2 > .panel { margin-bottom: 0; }
.panel > .tabla-contenedor:last-child, .panel > div:last-child > .tabla-contenedor:last-child { border-radius: 0 0 var(--radio-grande) var(--radio-grande); }
.grilla-2 + .grilla-2, .grilla-2 + .panel { margin-top: 16px; }

.alerta-item {
  display: flex; gap: 12px; padding: 12px; border-radius: 10px;
  background: var(--alerta-fondo); margin-bottom: 8px; color: var(--texto); text-decoration: none;
}
.alerta-item::before { content: ''; width: 6px; flex-shrink: 0; border-radius: 3px; background: var(--alerta); }
.alerta-item.peligro { background: var(--peligro-fondo); }
.alerta-item.peligro::before { background: var(--peligro); }
.alerta-item.ok { background: var(--ok-fondo); }
.alerta-item.ok::before { background: var(--ok); }
.alerta-item.info { background: var(--info-fondo); }
.alerta-item.info::before { background: var(--info); }
.alerta-item > div { flex: 1; min-width: 0; }
.alerta-item strong { display: block; font-size: 14px; }
.alerta-item small { display: block; font-size: 13px; color: var(--texto-2); }
a.alerta-item:hover { color: var(--texto); filter: brightness(0.98); }
.vacio { color: var(--texto-2); padding: 16px 0; }

/* Alerta global: vaca en tratamiento en el lector ahora */
.alarma-global {
  position: sticky; top: 64px; z-index: 9; display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; background: var(--peligro); color: #fff;
  animation: latido 1.2s ease-in-out infinite;
}
.alarma-global strong { font-family: var(--fuente-titulo); font-size: 17px; display: block; }
.alarma-global small { display: block; font-size: 13px; opacity: .92; }
.alarma-global a { color: #fff; }
.alarma-global button { margin: 0 0 0 auto; background: rgb(255 255 255 / 18%); min-height: 36px; padding: 6px 12px; font-size: 13px; }
.alarma-global button:hover { background: rgb(255 255 255 / 28%); }
.alarma-global svg { flex-shrink: 0; }
@keyframes latido { 50% { background: #8c1d13; } }
@media (prefers-reduced-motion: reduce) { .alarma-global { animation: none; } }

/* ---------- Datos ---------- */
.num, td.num { text-align: right; font-family: var(--fuente-mono); font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.mono { font-family: var(--fuente-mono); font-size: 13px; }
.chapa {
  font-family: var(--fuente-mono); font-size: 14px; font-weight: 500; background: var(--fondo);
  border: 1px solid #d8d2c6; border-radius: 6px; padding: 2px 8px; white-space: nowrap; text-decoration: none;
}
a.chapa:hover { border-color: var(--acento); }
.pequeno { font-size: 13px; color: var(--texto-2); }
.fuerte { font-weight: 600; }

/* ---------- Botones ---------- */
button, .boton {
  font: 600 15px var(--fuente); min-height: 44px; padding: 10px 18px; border: 0; border-radius: var(--radio);
  background: var(--tinta); color: #fff; cursor: pointer; transition: background .15s ease;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none;
}
button:hover, .boton:hover { background: var(--tinta-2); color: #fff; }
button:disabled { opacity: .55; cursor: default; }
button.secundario, .boton.secundario { background: var(--superficie); color: var(--texto); border: 1px solid var(--borde-fuerte); }
button.secundario:hover, .boton.secundario:hover { background: var(--superficie-2); border-color: var(--texto-3); color: var(--texto); }
button.acento, .boton.acento { background: var(--acento); color: var(--tinta); font-family: var(--fuente-titulo); font-weight: 700; }
button.acento:hover, .boton.acento:hover { background: #dc9530; color: var(--tinta); }
button.peligro { background: var(--peligro); }
button.chico, .boton.chico { min-height: 36px; padding: 6px 12px; font-size: 13px; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.acciones.fin { justify-content: flex-end; margin-top: 18px; }

/* ---------- Formularios ---------- */
label { display: block; font-weight: 600; font-size: 14px; margin: 12px 0 6px; }
input, select, textarea {
  font: 16px var(--fuente); color: var(--texto); min-height: 44px; padding: 10px 12px; width: 100%;
  border: 1px solid var(--borde-fuerte); border-radius: var(--radio); background: var(--superficie);
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--tinta); box-shadow: 0 0 0 3px rgb(232 163 61 / 35%); }
input[type='checkbox'] { width: 20px; min-height: 20px; height: 20px; padding: 0; accent-color: var(--tinta); }
.casilla { font-weight: 400; display: flex; align-items: center; gap: 10px; min-height: 36px; margin: 0; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.filtros {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; width: fit-content; max-width: 100%;
  margin: 0 0 16px; padding: 14px 16px; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio-grande);
}
.filtros label { margin: 0; }
.filtros input:not([type='checkbox']), .filtros select { width: auto; min-width: 150px; }
.filtros input[type='search'] { min-width: 240px; }
@media (min-width: 1000px) {
  input, select, textarea { font-size: 15px; min-height: 40px; padding: 8px 12px; }
}

/* ---------- Pestanas (grupo de botones) ---------- */
.pestanas {
  display: flex; flex-wrap: wrap; gap: 4px; width: fit-content; max-width: 100%; margin-bottom: 16px; padding: 4px;
  background: var(--superficie); border: 1px solid var(--borde); border-radius: 10px;
}
.pestanas button {
  min-height: 38px; padding: 7px 14px; border-radius: 7px; background: transparent; color: #3a4652; font-size: 14px;
}
.pestanas button:hover { background: var(--superficie-2); color: var(--texto); }
.pestanas button.active { background: var(--tinta); color: #fff; }

/* ---------- Tablas ---------- */
.tabla-contenedor {
  width: 100%; overflow-x: auto; background: var(--superficie); border: 1px solid var(--borde);
  border-radius: var(--radio-grande); box-shadow: var(--sombra); margin-bottom: 16px;
}
.panel .tabla-contenedor { border: 0; box-shadow: none; border-radius: 0; margin: 0 -20px -20px; width: calc(100% + 40px); }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th {
  text-align: left; font-size: 12px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase;
  color: var(--texto-2); background: var(--superficie-2); padding: 12px 14px; border-bottom: 1px solid var(--borde); white-space: nowrap;
}
.tabla td { padding: 12px 14px; border-bottom: 1px solid var(--linea); vertical-align: middle; }
.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover td { background: #fcfbf8; }
.tabla tr.clic { cursor: pointer; }
.tabla td.acciones-celda { text-align: right; white-space: nowrap; }

/* ---------- Insignias ---------- */
.insignia {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  background: var(--alerta-fondo); color: var(--alerta-texto); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.insignia.ok { background: var(--ok-fondo); color: var(--ok-texto); }
.insignia.peligro { background: var(--peligro-fondo); color: var(--peligro-texto); }
.insignia.info { background: var(--info-fondo); color: var(--info-texto); }
.insignia.neutra { background: #efece6; color: var(--texto-2); }
.punto { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--texto-3); flex-shrink: 0; }
.punto.on { background: #2f9e62; box-shadow: 0 0 0 3px rgb(47 158 98 / 20%); }
.senal { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.senal i { display: block; width: 72px; height: 6px; border-radius: 3px; background: var(--linea); overflow: hidden; }
.senal i b { display: block; height: 100%; background: var(--tinta-3); border-radius: 3px; }

.banda { border-radius: var(--radio-grande); padding: 14px 16px; margin-bottom: 16px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.banda.ok { background: var(--ok-fondo); color: var(--ok-texto); }
.banda.peligro { background: var(--peligro-fondo); color: var(--peligro-texto); }
.datos { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 0; }
.datos dt { color: var(--texto-2); font-size: 14px; }
.datos dd { margin: 0; font-weight: 500; }

/* ---------- Graficos (SVG simples) ---------- */
.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: auto; overflow: visible; }
.grafico .eje { font: 11px var(--fuente); fill: var(--texto-3); }
.grafico .rejilla { stroke: var(--linea); stroke-width: 1; }
.grafico .base { stroke: var(--borde-fuerte); stroke-width: 1; }
.grafico .barra-dato { fill: var(--barra-dato); }
.grafico .barra-dato.alarma { fill: var(--peligro); }
.grafico .zona { fill: transparent; }
.grafico .zona:hover + .barra-dato, .grafico g:hover .barra-dato { opacity: .8; }
.grafico .etiqueta { font: 600 11px var(--fuente-mono); fill: var(--texto-2); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 3; background: var(--tinta); color: #fff;
  font-size: 12px; line-height: 1.35; padding: 6px 10px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%);
}
.tooltip b { font-family: var(--fuente-mono); }
.barras-h { display: grid; gap: 8px; }
.barras-h .fila { display: grid; grid-template-columns: minmax(90px, 180px) 1fr 40px; gap: 10px; align-items: center; font-size: 14px; }
.barras-h .fila span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barras-h .pista { height: 10px; background: var(--linea); border-radius: 0 4px 4px 0; }
.barras-h .pista i { display: block; height: 100%; background: var(--barra-dato); border-radius: 0 4px 4px 0; min-width: 2px; }

/* ---------- Dialogo y aviso ---------- */
dialog {
  border: 1px solid var(--borde); border-radius: var(--radio-grande); padding: 0; width: min(540px, calc(100vw - 32px));
  background: var(--superficie); color: var(--texto); max-height: calc(100vh - 40px); box-shadow: 0 20px 50px rgb(22 32 43 / 25%);
}
dialog::backdrop { background: rgb(22 32 43 / 45%); }
dialog form { padding: 22px; }
dialog h3 { font-size: 20px; margin-bottom: 4px; }
.aviso-flotante {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 30; max-width: calc(100vw - 32px);
  background: var(--tinta); color: #fff; padding: 12px 18px; border-radius: var(--radio); font-weight: 500;
  box-shadow: 0 8px 24px rgb(22 32 43 / 25%);
}

/* ---------- Ingreso ---------- */
.ingreso { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--tinta); }
.ingreso .panel { width: min(400px, 100%); padding: 28px; }
.ingreso .marca { color: var(--texto); padding: 0 0 18px; }
.ingreso .marca small { color: var(--texto-2); }
.ingreso button { width: 100%; margin-top: 18px; }

/* ---------- Telefono: menu abajo ---------- */
.solo-movil { display: none; }
@media (max-width: 900px) {
  .barra { padding: 0 16px; height: 58px; }
  .menu {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; width: auto; height: auto; z-index: 12;
    flex-direction: row; gap: 2px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .menu .marca, .menu a.marca-enlace, .menu-pie { display: none; }
  .menu a {
    flex: 1; flex-direction: column; gap: 2px; min-height: 52px; padding: 6px 2px; font-size: 11px;
    justify-content: center; text-align: center; position: relative;
  }
  .menu .cuenta-alerta { position: absolute; top: 2px; right: calc(50% - 22px); margin: 0; min-width: 18px; height: 18px; font-size: 11px; }
  .alarma-global { top: 58px; padding: 12px 16px; }
  .contenido { padding: 18px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 24px; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-valor { font-size: 26px; }
  .panel { padding: 16px; }
  .panel .tabla-contenedor { margin: 0 -16px -16px; width: calc(100% + 32px); }
  .filtros { width: 100%; }
  .filtros input:not([type='checkbox']), .filtros select, .filtros input[type='search'] { flex: 1; min-width: 0; width: 100%; }
  .oculta-movil { display: none; }
  .solo-movil { display: initial; }
  .aviso-flotante { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) { .fila-2 { grid-template-columns: 1fr; } }
