/* ===========================================================================
   GV Monitoreo — Tema corporativo (Gasvalpo: azul, naranja, blanco).
   Los valores replican common/gvcommon/marca.py. Si se obtienen los hex
   exactos de gasvalpo.cl / telemedidagv.cl, actualizar ambos lugares.
   Mobile-first, alto contraste para lectura en exteriores.
   =========================================================================== */
:root {
  --az: #004B87;          /* azul corporativo */
  --az-osc: #00335C;
  --nar: #FF6C00;         /* naranja de acento */
  --nar-osc: #CC5600;
  --blanco: #FFFFFF;
  --gris-fondo: #F4F6F8;
  --gris-borde: #DBE1E8;
  --texto: #1B1F24;
  --texto-suave: #5A6370;
  --ok: #1E7B34;
  --adv: #B35C00;
  --crit: #C62828;
  --sincom: #6B7280;
  --sombra: 0 1px 3px rgba(16,32,48,.12), 0 1px 2px rgba(16,32,48,.08);
  --radio: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gris-fondo);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--az); }

/* ---- Barra superior ---- */
.barra {
  background: var(--az);
  color: var(--blanco);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--sombra);
}
.barra .logo { height: 30px; display: block; }
.barra .marca { font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.barra .sep { flex: 1; }
.barra .usuario { font-size: .85rem; opacity: .95; white-space: nowrap; }
.barra a { color: var(--blanco); text-decoration: none; }
.barra .acento { height: 3px; background: var(--nar); }

/* ---- Navegación ---- */
.nav {
  background: var(--az-osc);
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: #Cfe0ef;
  text-decoration: none;
  padding: 11px 15px;
  white-space: nowrap;
  font-size: .9rem;
  border-bottom: 3px solid transparent;
}
.nav a.activo { color: var(--blanco); border-bottom-color: var(--nar); font-weight: 600; }
.nav a:hover { color: var(--blanco); }

/* ---- Contenedor ---- */
.contenido { padding: 16px; max-width: 1200px; margin: 0 auto; }
h1 { font-size: 1.4rem; margin: 4px 0 16px; color: var(--az); }
h2 { font-size: 1.1rem; color: var(--az); margin: 20px 0 10px; }

/* ---- Filtros ---- */
.filtros { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filtros input, .filtros select {
  padding: 9px 12px; border: 1px solid var(--gris-borde); border-radius: var(--radio);
  font-size: 1rem; background: var(--blanco); min-height: 42px;
}
.filtros input[type=search] { flex: 1; min-width: 150px; }

/* ---- Totales (chips) ---- */
.totales { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  background: var(--blanco); border: 1px solid var(--gris-borde); border-radius: 999px;
  padding: 6px 14px; font-size: .85rem; font-weight: 600; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .pt { width: 10px; height: 10px; border-radius: 50%; }
.chip.sel { border-color: var(--az); box-shadow: 0 0 0 2px rgba(0,75,135,.15); }

/* ---- Grilla de tarjetas (dashboard) ---- */
.tarjetas { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 560px) { .tarjetas { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .tarjetas { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1150px){ .tarjetas { grid-template-columns: repeat(4, 1fr); } }

.tarjeta {
  background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra);
  border-left: 5px solid var(--sincom); padding: 14px; text-decoration: none; color: inherit;
  display: block; transition: transform .08s;
}
.tarjeta:active { transform: scale(.99); }
.tarjeta.normal { border-left-color: var(--ok); }
.tarjeta.alarma { border-left-color: var(--crit); }
.tarjeta.sin_comunicacion { border-left-color: var(--sincom); }
.tarjeta.desconocido { border-left-color: var(--gris-borde); }
.tarjeta .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.tarjeta .nombre { font-weight: 700; font-size: 1.02rem; }
.tarjeta .cliente { font-size: .8rem; color: var(--texto-suave); }
.tarjeta .meta { font-size: .82rem; color: var(--texto-suave); margin-top: 8px; }
.estado-badge {
  font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  color: var(--blanco); white-space: nowrap; text-transform: uppercase; letter-spacing: .3px;
}
.estado-badge.normal { background: var(--ok); }
.estado-badge.alarma { background: var(--crit); }
.estado-badge.sin_comunicacion { background: var(--sincom); }
.estado-badge.desconocido { background: #9AA4B0; }
.tarjeta .alarmas-n { color: var(--crit); font-weight: 700; }

/* ---- Indicadores de variable (vista de unidad) ---- */
.variables { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px) { .variables { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px){ .variables { grid-template-columns: repeat(4, 1fr); } }

.indicador {
  background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra);
  padding: 14px; text-align: center; border-top: 4px solid var(--ok);
}
.indicador.alarma { border-top-color: var(--crit); }
.indicador.pendiente { border-top-color: var(--adv); }
.indicador.falla { border-top-color: var(--sincom); opacity: .75; }
.indicador .etq { font-size: .82rem; color: var(--texto-suave); min-height: 2.4em; }
.indicador .valor { font-size: 2.1rem; font-weight: 700; line-height: 1.1; margin: 6px 0; color: var(--az); }
.indicador.alarma .valor { color: var(--crit); }
.indicador .um { font-size: 1rem; color: var(--texto-suave); font-weight: 400; }
.indicador .barra-rango { height: 8px; border-radius: 4px; background: var(--gris-borde); position: relative; margin-top: 8px; overflow: hidden; }
.indicador .barra-rango .marca { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--crit); }
.indicador .barra-rango .val { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--az); }
.indicador .limites { font-size: .72rem; color: var(--texto-suave); margin-top: 6px; }

/* Indicador digital (bit) */
.indicador.bit .valor { font-size: 1.3rem; }
.estado-pill { display: inline-block; padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 1rem; }
.estado-pill.on { background: #FCE8E6; color: var(--crit); }
.estado-pill.off { background: #E6F4EA; color: var(--ok); }

/* ---- Tablas ---- */
.tabla-wrap { overflow-x: auto; background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--gris-borde); white-space: nowrap; }
th { background: #EEF2F6; color: var(--az); font-weight: 700; position: sticky; top: 0; }
tr:hover td { background: #FAFBFC; }
.sev { font-weight: 700; padding: 2px 8px; border-radius: 4px; font-size: .78rem; color: #fff; }
.sev.critica { background: var(--crit); }
.sev.advertencia { background: var(--adv); }
.sev.info { background: var(--sincom); }
.badge-estado { font-size: .78rem; font-weight: 700; }
.badge-estado.activa { color: var(--crit); }
.badge-estado.normalizada { color: var(--ok); }

/* ---- Botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--nar); color: var(--blanco); border: none; border-radius: var(--radio);
  padding: 10px 18px; font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none;
  min-height: 44px;
}
.btn:hover { background: var(--nar-osc); }
.btn.sec { background: var(--az); }
.btn.sec:hover { background: var(--az-osc); }
.btn.gris { background: #6B7686; }
.btn.chico { padding: 6px 12px; font-size: .85rem; min-height: 36px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Formularios ---- */
.form { background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra); padding: 18px; max-width: 640px; }
.campo { margin-bottom: 14px; }
.campo label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; color: var(--texto); }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--gris-borde); border-radius: var(--radio);
  font-size: 1rem; min-height: 44px; background: var(--blanco);
}
.campo .ayuda { font-size: .78rem; color: var(--texto-suave); margin-top: 4px; }
.fila { display: flex; gap: 12px; flex-wrap: wrap; }
.fila .campo { flex: 1; min-width: 140px; }
.acciones { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }

/* ---- Mensajes ---- */
.msg { padding: 12px 16px; border-radius: var(--radio); margin-bottom: 16px; font-size: .92rem; }
.msg.error { background: #FCE8E6; color: #8A1C13; border: 1px solid #F3B4AE; }
.msg.ok { background: #E6F4EA; color: #14532D; border: 1px solid #A7D8B5; }
.msg.info { background: #E8F0FA; color: var(--az-osc); border: 1px solid #B9D3EC; }
.msg.adv { background: #FEF3E2; color: #7A4A00; border: 1px solid #F4D399; }

/* ---- Login ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, var(--az) 0%, var(--az-osc) 100%); }
.login-card { background: var(--blanco); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  padding: 32px 26px; width: 100%; max-width: 380px; }
.login-card .logo-box { text-align: center; margin-bottom: 8px; }
.login-card .logo-box img { height: 44px; }
.login-card h1 { text-align: center; font-size: 1.15rem; margin: 10px 0 20px; }

/* ---- Utilidades ---- */
.muted { color: var(--texto-suave); }
.oculto { display: none !important; }
.cargando { text-align: center; padding: 40px; color: var(--texto-suave); }
.spin { display: inline-block; width: 22px; height: 22px; border: 3px solid var(--gris-borde);
  border-top-color: var(--az); border-radius: 50%; animation: giro .7s linear infinite; }
@keyframes giro { to { transform: rotate(360deg); } }
.right { text-align: right; }
.flex { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.flex .sep { flex: 1; }
.pie { text-align: center; color: var(--texto-suave); font-size: .78rem; padding: 24px 16px; }
.actualizado { font-size: .78rem; color: var(--texto-suave); }

@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }
