/* ============================================================
   UFA BODY CHECK — base.css
   Tokens (§9), reset, tipografía, botones, tarjetas, formularios,
   toasts, badges y utilidades. Lo cargan TODAS las pantallas.
   Mobile-first: lo que no tiene media query vale desde 320 px.
   ============================================================ */

@import url('/fonts/fonts.css');

/* ---------- Tokens ---------- */
:root {
  /* Panel claro (estética de la página original) */
  --paper: #f3f5f8;
  --ink: #121214;
  --muted: #626874;
  --line: #e0e4eb;
  --soft: #eef5ff;
  /* Azul principal: #0066cc da 5,6:1 con texto blanco (el #007ffa original daba 3,9 y no pasaba AA) */
  --blue: #0066cc;
  --blue-oscuro: #0055b6;
  --blue-texto: #0055b6;
  --amber: #d9a843;
  --amber-fondo: #ffe08a;
  --amber-texto: #7b4d0b;
  --rojo: #c43d3d;
  --rojo-fondo: #b3261e;
  --verde: #177a43;      /* 5,4:1 con blanco; el #1f9d55 original daba 3,5 */
  --gris-texto: #5a6270; /* texto secundario sobre blanco o papel: ≥ 5:1 */

  /* TV oscura */
  --tv-bg: #101115;
  --tv-row: #1d2028;
  --tv-line: #333842;
  --tv-text: #fff;
  --tv-muted: #b2bdcd;
  --tv-accent: #4ca6ff;

  /* Podio */
  --oro: #f5c542;
  --plata: #c9d3e0;
  --bronce: #d08a4e;

  /* Formas */
  --radio-chico: 8px;
  --radio: 10px;
  --radio-grande: 16px;
  --sombra: 0 2px 4px rgba(23, 40, 70, 0.04);
  --sombra-alta: 0 12px 40px rgba(18, 18, 20, 0.18);
  --foco: 0 0 0 3px rgba(0, 127, 250, 0.25);

  /* Tipografía */
  --fuente: Roboto, Arial, Helvetica, sans-serif;
  --fuente-titulo: 'Sofia Sans Extra Condensed', 'Arial Narrow', Impact, sans-serif;

  /* Alturas táctiles (en pantallas táctiles y en el celu suben todas a 56 px: ver el @media de abajo) */
  --alto-input: 48px;
  --alto-btn: 48px;
  --alto-btn-chico: 44px;
  --alto-btn-grande: 56px;
  --alto-tick: 44px;
  --tamanio-tick: 22px;

  /* Letra mínima: 12 px en paneles de escritorio, 14 px en táctil y celu (P2 #23) */
  --letra-min: 12px;
  --letra-base: 15px;

  color-scheme: light;
}

/* Táctil (iPads, celu) o pantalla angosta (celu de Lautaro en /operacion): todo control ≥ 56 px y letra ≥ 14 px.
   El max-width entra también en Chrome de escritorio angosto, así el tester de 390 px mide lo mismo que un celu real. */
@media (pointer: coarse), (max-width: 430px) {
  :root {
    --alto-input: 56px;
    --alto-btn: 56px;
    --alto-btn-chico: 56px;
    --alto-btn-grande: 60px;
    --alto-tick: 56px;
    --tamanio-tick: 26px;
    --letra-min: 14px;
    --letra-base: 16px;
  }
}

/* ---------- Reset ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--fuente);
  font-size: var(--letra-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}

img, svg { max-width: 100%; display: block; }

button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, label { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; }

h1, h2, h3, h4, p, ul, ol, figure { margin-top: 0; }
ul, ol { padding-left: 20px; }

h1, h2, .titulo, .numero-grande {
  font-family: var(--fuente-titulo);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.2px;
}

h1 { font-size: 36px; margin-bottom: 4px; letter-spacing: -0.3px; }
h2 { font-size: 28px; margin-bottom: 14px; line-height: 1.1; }
h3 { font-size: 17px; margin-bottom: 8px; font-weight: 700; }
p { color: var(--muted); margin-bottom: 14px; }
p:last-child { margin-bottom: 0; }
strong, b { font-weight: 700; }
small { font-size: var(--letra-min); }
a { color: var(--blue-texto); }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: max(0.92em, var(--letra-min)); }
hr, .separador { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

:is(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid #49a8ff;
  outline-offset: 2px;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--alto-btn);
  padding: 10px 18px;
  border: 1px solid #ccd2dc;
  border-radius: 9px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.12s, border-color 0.12s, transform 0.08s, opacity 0.12s;
}
.btn:hover { background: #edf3fc; }
.btn:active { transform: scale(0.98); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn.primario { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primario:hover { background: var(--blue-oscuro); border-color: var(--blue-oscuro); }

.btn.secundario { background: #fff; border-color: #ccd2dc; color: var(--ink); }
.btn.secundario:hover { background: #edf3fc; }

.btn.peligro { background: var(--rojo); border-color: var(--rojo); color: #fff; }
.btn.peligro:hover { background: #a93131; border-color: #a93131; }
.btn.peligro.suave { background: #fff0ec; border-color: #f5c9bc; color: #9a3015; }
.btn.peligro.suave:hover { background: #ffe3dc; }

/* Seleccionado dentro de un selector (M/F, modo, tabs) */
.btn.activo { background: var(--ink); border-color: var(--ink); color: #fff; }

.btn.grande { min-height: var(--alto-btn-grande); padding: 12px 22px; font-size: 17px; border-radius: 12px; }
.btn.chico { min-height: var(--alto-btn-chico); padding: 6px 12px; font-size: max(13px, var(--letra-min)); }
.btn.lleno { width: 100%; }
.btn.fantasma { background: transparent; border-color: transparent; }
.btn.fantasma:hover { background: #edf3fc; }

/* Grupo de botones que se reparten el ancho (sexo M/F, modo, mezcla 3+4 / 4+3) */
.selector { display: flex; gap: 8px; }
.selector .btn { flex: 1 1 0; }

/* ---------- Tarjetas ---------- */
.tarjeta {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radio-grande);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--sombra);
}
.tarjeta > :last-child { margin-bottom: 0; }
.tarjeta.oscura { background: #17191e; border-color: #17191e; color: #fff; }
.tarjeta.oscura p, .tarjeta.oscura .ojal { color: #aeb6c2; }
.tarjeta.ambar { background: #fff8e6; border-color: #f1dca6; }
.tarjeta.compacta { padding: 14px 16px; }

.tarjeta-cabecera {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-bottom: 16px;
}
.tarjeta-cabecera h2 { margin-bottom: 0; }
.tarjeta-cabecera p { margin: 4px 0 0; }

.ojal {
  display: block;
  font-size: var(--letra-min);
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: #607184;
  margin-bottom: 8px;
}

.numero-grande { font-size: 48px; color: var(--blue); line-height: 1; }

.vacio { text-align: center; color: var(--muted); padding: 40px 20px; }

/* ---------- Formularios ---------- */
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--alto-input);
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  border: 1px solid #c9cfda;
  border-radius: var(--radio-chico);
  font-size: 16px; /* 16 px evita el zoom automático de iOS */
  line-height: 1.3;
}
textarea { min-height: 96px; resize: vertical; }
select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%23626874' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: var(--foco); }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f6; color: var(--muted); }
input::placeholder, textarea::placeholder { color: #6f7684; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="checkbox"], input[type="radio"] {
  width: var(--tamanio-tick); height: var(--tamanio-tick); min-width: var(--tamanio-tick); margin: 0; accent-color: var(--blue); cursor: pointer;
}

/* .campo = label + control (+ ayuda / error) */
.campo { display: block; margin-bottom: 14px; }
.campo > label, .campo > .etiqueta { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.campo .ayuda { display: block; color: var(--muted); font-size: var(--letra-min); font-weight: 400; margin-top: 5px; }
/* Error junto al campo (P1 #11): rojo, chico, debajo del control. Vacío u .oculto → no ocupa lugar. */
.campo .error { display: block; color: var(--rojo); font-size: var(--letra-min); font-weight: 600; margin-top: 5px; line-height: 1.35; }
.campo .error:empty { display: none; }
.campo .error::before { content: '⚠ '; }
.campo.invalido input, .campo.invalido select, .campo.invalido textarea { border-color: var(--rojo); }
.campo.aviso input { border-color: var(--amber); }
.campo.aviso .ayuda { color: #865006; }
.campo .con-unidad { position: relative; }
.campo .con-unidad input { padding-right: 52px; }
.campo .con-unidad .unidad {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: max(13px, var(--letra-min)); font-weight: 600; pointer-events: none;
}

/* Grilla de campos (medidas, config) */
.grilla-campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px 14px; }
.grilla-campos .campo { margin-bottom: 0; }

/* Tick = checkbox con área táctil grande */
.tick {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--alto-tick);
  padding: 8px 0;
  font-size: max(14px, var(--letra-min));
  font-weight: 400;
  cursor: pointer;
}
.tick input { flex-shrink: 0; }
.tick small { display: block; color: var(--muted); font-size: var(--letra-min); }
.tick.obligatorio span::after { content: ' *'; color: var(--rojo); }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled { opacity: 0.6; }

/* ---------- Acciones / filas ---------- */
.acciones { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin-top: 18px; }
.acciones .derecha { margin-left: auto; }
.fila { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.fila.entre { justify-content: space-between; }
.apilado { display: grid; gap: 12px; }

/* Confirmación en línea (reemplaza a confirm()) */
.confirmacion {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px 14px; margin-top: 10px;
  background: #fff0ec; border: 1px solid #f5c9bc; border-radius: var(--radio);
  color: #9a3015; font-size: 14px; font-weight: 500;
}
.confirmacion .acciones { margin: 0; margin-left: auto; }

/* ---------- Avisos en línea ---------- */
/* :not(.campo) porque .campo.aviso es el estado «medida rara» de un campo (otra cosa): sin esto el campo crecía 26 px */
.aviso:not(.campo) {
  padding: 12px 16px;
  margin-bottom: 14px;
  border-radius: var(--radio);
  font-size: 14px;
  background: var(--soft);
  color: var(--blue-texto);
  border: 1px solid #cfe3ff;
}
.aviso.error { color: #9a3015; background: #fff0ec; border-color: #f5c9bc; }
.aviso.ok { color: #175d3c; background: #e7f7ee; border-color: #bfe8d0; }
.aviso.pendiente { color: #7b4d0b; background: #fff1d7; border-color: #f1dca6; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  white-space: nowrap;
  padding: 5px 11px;
  border-radius: 30px;
  font-size: var(--letra-min);
  font-weight: 600;
  line-height: 1.3;
  background: #e8ebf0;
  color: #3d4451;
  vertical-align: middle;
}
.badge.azul { background: #e4f1ff; color: var(--blue-texto); }
.badge.ambar { background: #fff0d5; color: #865006; }
.badge.rojo { background: #fde8e8; color: #8f2626; }
.badge.verde { background: #e2f6ea; color: #15673a; }
.badge.gris { background: #e8ebf0; color: #3d4451; }
.badge.oscuro { background: var(--ink); color: #fff; }
.badge.chico { padding: 3px 8px; font-size: var(--letra-min); }

/* ---------- Estado de conexión ---------- */
.punto-conexion {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #4bdf9b;
  box-shadow: 0 0 0 3px rgba(75, 223, 155, 0.18);
  vertical-align: middle;
  flex-shrink: 0;
}
.punto-conexion.ok { background: #4bdf9b; box-shadow: 0 0 0 3px rgba(75, 223, 155, 0.18); }
.punto-conexion.off {
  background: #ffb45e;
  box-shadow: 0 0 0 3px rgba(255, 180, 94, 0.22);
  animation: latido 1.2s ease-in-out infinite;
}
@keyframes latido { 50% { opacity: 0.45; } }

/* ---------- Cinta de ensayo ---------- */
.cinta-ensayo {
  background: var(--amber);
  color: var(--ink);
  text-align: center;
  font-family: var(--fuente-titulo);
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 2.5px;
  padding: 6px 12px;
  background-image: repeating-linear-gradient(135deg, transparent 0 14px, rgba(0, 0, 0, 0.07) 14px 28px);
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  width: min(480px, calc(100% - 32px));
  z-index: 1000;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 13px 16px;
  border-radius: var(--radio);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--sombra-alta);
  border-left: 5px solid #8f98a8;
  animation: toast-entra 0.22s ease-out;
  cursor: pointer;
}
.toast.info { border-left-color: var(--blue); }
.toast.ok { border-left-color: #4bdf9b; }
.toast.error { border-left-color: #ff7b6b; background: #4a1f1b; }
.toast.saliendo { animation: toast-sale 0.25s ease-in forwards; }
@keyframes toast-entra { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-sale { to { opacity: 0; transform: translateY(8px); } }

/* ---------- Tablas simples ---------- */
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.tabla th { font-size: var(--letra-min); text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); font-weight: 700; }
.tabla td.num, .tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }
.desplazable { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Utilidades ---------- */
.oculto { display: none !important; }
.sr-solo { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.texto-mudo { color: var(--muted); }
.texto-chico { font-size: var(--letra-min); }
.texto-rojo { color: var(--rojo); }
.texto-verde { color: var(--verde); }
.texto-azul { color: var(--blue-texto); }
.centrado { text-align: center; }
.derecha { text-align: right; }
.ancho-total { width: 100%; }
.sin-margen { margin: 0 !important; }
.tabular { font-variant-numeric: tabular-nums; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }

/* Resaltado breve (fila recién guardada, etc.) */
.destello { animation: destello 1.6s ease-out; }
@keyframes destello { 0% { background: #dff0ff; } 100% { background: transparent; } }

/* ---------- Tamaños mayores (iPad 1024 y desktop) ---------- */
@media (min-width: 721px) {
  body { font-size: var(--letra-base); }
  h1 { font-size: 48px; }
  h2 { font-size: 34px; margin-bottom: 18px; }
  .tarjeta { padding: 28px; margin-bottom: 20px; }
  .tarjeta.compacta { padding: 18px 20px; }
  .numero-grande { font-size: 60px; }
  .toasts { left: auto; right: 20px; bottom: 20px; transform: none; width: 380px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
