:root {
  --fondo: #F3F6F7;
  --superficie: #FFFFFF;
  --texto: #10303A;
  --texto-suave: #4B6670;
  --acento: #0B7A75;
  --sobre-acento: #FFFFFF;
  --acento-suave: #D7F0EC;
  --acento-texto: #06524E;
  --apagado-fondo: #E6ECEE;
  --apagado-texto: #3B525B;
  --alerta-fondo: #FFF1D6;
  --alerta-texto: #6E4300;
  --alerta-suave: #FFF8EA;
  --linea: #DDE5E8;
  --separador: #E7EDEF;
  --eje: #9FB2B9;
  --borde-filtro: #C5D3D8;
  --borde-campo: #A9BAC0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0E1A1D;
    --superficie: #16262A;
    --texto: #E6F0F2;
    --texto-suave: #9DB3BA;
    --acento: #3CC4BD;
    --sobre-acento: #06302D;
    --acento-suave: #123C3A;
    --acento-texto: #8FE3DE;
    --apagado-fondo: #22343A;
    --apagado-texto: #B5C7CC;
    --alerta-fondo: #3A2C10;
    --alerta-texto: #F5CF8A;
    --alerta-suave: #2E2410;
    --linea: #28393E;
    --separador: #22333A;
    --eje: #5E7379;
    --borde-filtro: #3A4E54;
    --borde-campo: #46595F;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--acento); }
:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }

/* Estructura */
.pantalla { min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }
.barra {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  min-height: 64px;
  padding: env(safe-area-inset-top, 0px) 12px 0 12px;
  background: var(--fondo);
}
.barra h1 {
  margin: 0; padding-left: 12px;
  font-size: 24px; font-weight: 800; letter-spacing: -0.3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.barra > a.icono-btn + h1 { padding-left: 4px; font-size: 22px; }
.contenido {
  flex: 1;
  display: flex; flex-direction: column; gap: 16px;
  padding: 4px 24px calc(100px + env(safe-area-inset-bottom, 0px));
}
.crece { flex: 1; min-width: 0; }
.pila { display: flex; flex-direction: column; gap: 16px; }
.pila-chica { display: flex; flex-direction: column; gap: 8px; }
.fila { display: flex; align-items: center; gap: 12px; }
.fila-base { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.derecha { text-align: right; }

h2 { margin: 0; font-size: 16px; font-weight: 800; }
h2.dia { font-size: 14px; color: var(--texto-suave); }
.suave { margin: 0; color: var(--texto-suave); font-weight: 500; }
.chico { font-size: 13px; }

/* Navegación inferior */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--superficie);
  border-top: 1px solid var(--linea);
  padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px));
}
.nav-item {
  flex: 1; max-width: 180px; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--texto-suave); font-size: 12px; font-weight: 700; text-decoration: none;
}
.nav-icono { width: 64px; height: 32px; border-radius: 16px; display: flex; align-items: center; justify-content: center; }
.nav-item.activo { color: var(--acento); font-weight: 800; }
.nav-item.activo .nav-icono { background: var(--acento-suave); }

/* Tarjetas */
.tarjeta {
  background: var(--superficie); border-radius: 20px;
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 14px;
  color: inherit; text-decoration: none;
}
.tarjeta.enlace { flex-direction: row; align-items: center; gap: 12px; }
.tarjeta.lista { padding: 0; gap: 0; }
.titulo-tarjeta { font-size: 17px; font-weight: 700; }
.accion { color: var(--acento); font-size: 14px; font-weight: 800; }
.avatar {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--acento-suave); color: var(--acento);
}
.avatar.alerta { background: var(--alerta-fondo); color: var(--alerta-texto); }

.metricas { display: flex; gap: 12px; }
.metrica { flex: 1; display: flex; flex-direction: column; background: var(--fondo); border-radius: 12px; padding: 10px 12px; }
.metrica span { font-size: 12px; font-weight: 500; color: var(--texto-suave); }
.metrica strong { font-size: 20px; font-weight: 800; }
.metrica.suelta { background: var(--superficie); border-radius: 20px; padding: 16px 18px; }
.metrica.suelta span { font-size: 13px; }
.metrica.suelta strong { font-size: 24px; }

.numero-grande { font-size: 40px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.unidad { font-size: 14px; font-weight: 700; color: var(--texto-suave); }
.chico-15 { font-size: 15px; }
.mensaje-alerta { background: var(--alerta-suave); color: var(--alerta-texto); border-radius: 12px; padding: 10px 12px; font-size: 14px; font-weight: 500; }
.numero-medio { font-size: 20px; font-weight: 800; }
canvas.grafico { width: 100%; height: 160px; display: block; }

/* Estados */
.chip {
  display: inline-flex; align-items: center; gap: 6px; align-self: flex-start;
  border-radius: 14px; padding: 5px 12px;
  font-size: 13px; font-weight: 700; white-space: nowrap;
}
.chip-on { background: var(--acento-suave); color: var(--acento-texto); }
.chip-off { background: var(--apagado-fondo); color: var(--apagado-texto); }
.chip-alerta { background: var(--alerta-fondo); color: var(--alerta-texto); }
.punto { width: 8px; height: 8px; border-radius: 4px; background: currentColor; flex-shrink: 0; }
.punto-hueco { background: transparent; border: 2px solid currentColor; }
.icono-chico { width: 14px; height: 14px; stroke-width: 2.4; }

/* Historial */
.evento { display: flex; align-items: center; gap: 12px; padding: 12px 18px; min-height: 64px; }
.evento { position: relative; }
.evento + .evento::before { content: ''; position: absolute; top: 0; left: 18px; right: 18px; height: 1px; background: var(--separador); }
.marca-evento { width: 36px; height: 36px; border-radius: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.marca-evento.on { background: var(--acento-suave); color: var(--acento-texto); }
.marca-evento.off { background: var(--apagado-fondo); color: var(--apagado-texto); }
.marca-evento.alerta { background: var(--alerta-fondo); color: var(--alerta-texto); }
.marca-evento .icono-chico { width: 18px; height: 18px; stroke-width: 2; }

.filtros { display: flex; gap: 8px; flex-wrap: wrap; }
.filtro {
  height: 44px; padding: 0 18px; border-radius: 22px;
  border: 1px solid var(--borde-filtro); background: transparent; color: var(--texto);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.filtro.activo { background: var(--texto); border-color: var(--texto); color: var(--fondo); }
.marca-evento .punto { width: 10px; height: 10px; border-radius: 5px; }
.titulo-evento { font-size: 15px; font-weight: 700; }
.hora { font-size: 13px; font-weight: 700; }

/* Botones */
.btn {
  min-height: 52px; padding: 0 20px; border-radius: 26px; border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 16px; font-weight: 800; text-decoration: none; cursor: pointer;
}
.btn.primario { background: var(--acento); color: var(--sobre-acento); min-height: 56px; border-radius: 28px; }
.btn.secundario { background: transparent; color: var(--acento); border: 1.5px solid var(--acento); }
.btn:disabled { opacity: 0.5; cursor: default; }
.botones { display: flex; gap: 10px; }
.botones .btn { flex: 1; font-size: 14px; padding: 0 12px; }
.btn-texto {
  align-self: flex-start; min-height: 44px; padding: 0;
  background: none; border: 0; cursor: pointer;
  color: var(--acento); font: inherit; font-size: 14px; font-weight: 800;
}
.icono-btn {
  width: 48px; height: 48px; border-radius: 24px; border: 0; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; color: var(--texto); cursor: pointer;
}

/* Formularios */
.campo { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; }
.campo input {
  height: 52px; padding: 0 16px;
  border: 1px solid var(--borde-campo); border-radius: 14px;
  background: var(--superficie); color: var(--texto);
  font: inherit; font-size: 16px; font-weight: 500;
}
.campo input::placeholder { color: var(--texto-suave); }
.opciones { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.opciones legend { padding: 0; margin-bottom: 8px; font-size: 14px; font-weight: 700; }
.opcion {
  min-height: 52px; padding: 0 16px;
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--borde-campo); border-radius: 14px;
  background: var(--superficie); font-size: 16px; font-weight: 500;
}
.opcion:has(input:checked) { border: 1.5px solid var(--acento); background: var(--acento-suave); font-weight: 700; }
input[type=radio], input[type=range] { accent-color: var(--acento); }
.opcion input { width: 20px; height: 20px; margin: 0; }

.selector {
  position: relative; display: flex; align-items: center;
  height: 56px; border-radius: 16px; background: var(--superficie); color: var(--texto);
}
.selector select {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 100%; padding: 0 52px 0 18px;
  border: 0; border-radius: 16px; background: transparent; color: inherit;
  font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
}
.selector svg { position: absolute; right: 18px; pointer-events: none; }
.visualmente-oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.niveles { font-size: 13px; font-weight: 700; }
.barra-niveles { position: relative; height: 24px; }
.barra-niveles::before { content: ''; position: absolute; left: 0; right: 0; top: 7px; height: 10px; border-radius: 5px; background: var(--apagado-fondo); }
.barra-niveles .banda { position: absolute; top: 7px; height: 10px; background: var(--acento); opacity: 0.3; }
.barra-niveles .marca-nivel { position: absolute; top: 1px; width: 8px; height: 22px; margin-left: -4px; border-radius: 4px; background: var(--acento); }

.rango { display: flex; flex-direction: column; gap: 2px; }
.rango-cabeza { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; font-weight: 700; }
.rango-cabeza output { color: var(--acento); font-weight: 800; }
.rango input { width: 100%; height: 32px; margin: 0; }

.aviso {
  background: var(--alerta-fondo); color: var(--alerta-texto);
  border-radius: 16px; padding: 14px 16px;
  font-size: 13px; font-weight: 500; line-height: 1.45;
}
.aviso a { color: inherit; font-weight: 800; }
.mensaje { margin: 0; min-height: 1em; font-size: 14px; font-weight: 600; color: var(--alerta-texto); }
.mensaje:empty { display: none; }

.vacio {
  background: var(--superficie); border-radius: 20px; padding: 24px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 16px;
}
.vacio p { margin: 0; line-height: 1.5; }

/* Vincular (3 pasos) */
.pila-6 { display: flex; flex-direction: column; gap: 6px; }
.paso { font-size: 13px; font-weight: 800; color: var(--acento); }
.titulo-paso { font-size: 22px; letter-spacing: -0.3px; }
.escaner { position: relative; height: 300px; border-radius: 24px; background: #10303A; overflow: hidden; flex-shrink: 0; }
.escaner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.esquina { position: absolute; width: 44px; height: 44px; border: 0 solid #FFFFFF; }
.esquina.arriba-izq { left: 56px; top: 48px; border-top-width: 4px; border-left-width: 4px; border-radius: 10px 0 0 0; }
.esquina.arriba-der { right: 56px; top: 48px; border-top-width: 4px; border-right-width: 4px; border-radius: 0 10px 0 0; }
.esquina.abajo-izq { left: 56px; bottom: 72px; border-bottom-width: 4px; border-left-width: 4px; border-radius: 0 0 0 10px; }
.esquina.abajo-der { right: 56px; bottom: 72px; border-bottom-width: 4px; border-right-width: 4px; border-radius: 0 0 10px 0; }
.escaner-texto { position: absolute; left: 16px; right: 16px; bottom: 24px; margin: 0; text-align: center; color: #FFFFFF; font-size: 14px; font-weight: 700; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.info { background: var(--superficie); border-radius: 16px; padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; color: var(--acento); }
.info svg { flex-shrink: 0; width: 22px; height: 22px; margin-top: 1px; }
.info p { margin: 0; font-size: 13px; font-weight: 500; line-height: 1.45; color: var(--texto-suave); }
.fila-aviso { display: flex; gap: 12px; align-items: flex-start; }
.fila-aviso p { margin: 0; }
.fila-aviso .icono-chico { width: 22px; height: 22px; flex-shrink: 0; stroke-width: 1.8; }
.btn-texto.centrado { align-self: center; }

/* Ingreso */
.login {
  max-width: 440px; margin: 0 auto;
  padding: calc(56px + env(safe-area-inset-top, 0px)) 24px 32px;
  display: flex; flex-direction: column; gap: 12px;
}
.login h1 { margin: 8px 0 0; font-size: 30px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.15; }
.login form { margin-top: 12px; }
.marca { display: inline-flex; align-items: center; gap: 10px; color: var(--acento); font-size: 18px; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
