/* Ventas Sintax — estilo iOS. Orden: styles.css (tokens claros + base + estructura), temas.css (oscuro y arena),
   componentes.css (controles y pantallas). Cada color sale de un token; aquí está la paleta clara COMPLETA. */
:root {
  color-scheme: light;
  /* Fondos */
  --bg: #f2f2f7;                          /* systemGroupedBackground */
  --surface: #ffffff;                     /* celdas y tarjetas */
  --surface-2: #f2f2f7;                   /* paneles dentro de una celda */
  --fill: rgba(118, 118, 128, 0.12);      /* campos, segmentados, botones grises */
  --fill-fuerte: rgba(118, 118, 128, 0.22);
  --pastilla: #ffffff;                    /* píldora del segmentado */
  --perilla: #ffffff;                     /* bolita del interruptor */
  --barra: rgba(249, 249, 249, 0.82);     /* encabezado y pestañas con blur */
  --barra-solida: #f9f9f9;
  /* Texto y líneas */
  --ink: #000000;
  --muted: #636366;
  --line: #c6c6c8;
  --line-fuerte: #aeaeb2;
  /* Acento (azul del sistema) */
  --accent: #007aff;                      /* trazos, indicadores, anillo de hoy */
  --accent-texto: #0060c4;                /* texto en acento: 4.5:1 sobre celdas y rellenos */
  --accent-relleno: #0071e3;              /* rellenos con texto blanco */
  --accent-ink: #ffffff;
  --accent-soft: rgba(0, 122, 255, 0.12);
  /* Semánticos: "vivo" para franjas y puntos, el otro para texto */
  --critical: #bf0010;
  --critical-vivo: #ff3b30;
  --critical-soft: rgba(255, 59, 48, 0.12);
  --sobre-critico: #ffffff;
  --warning: #c93400;
  --warning-vivo: #ff9500;
  --warning-soft: rgba(255, 149, 0, 0.14);
  --ok: #1e7b34;
  --ok-vivo: #34c759;
  --ok-soft: rgba(52, 199, 89, 0.14);
  --focus: #007aff;
  --scrim: rgba(0, 0, 0, 0.4);
  --grabber: rgba(60, 60, 67, 0.3);
  --sombra: 0 10px 30px rgba(0, 0, 0, 0.12);
  --sombra-pastilla: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
  --sombra-perilla: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.16);
  /* Forma, tipo y movimiento */
  --radio: 14px;
  --radio-grupo: 12px;
  --hair: 1px;                            /* separadores finos (0.5 px en pantallas retina) */
  --tabbar: 56px;
  --fuente: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Inter", system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --fuente-titulo: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "Inter", system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  --t-grande: 34px;
  --t-titulo1: 28px;
  --t-titulo2: 22px;
  --t-titulo3: 20px;
  --t-cuerpo: 17px;
  --t-sub: 15px;
  --t-nota: 13px;
  --t-cap: 11px;
  --curva: cubic-bezier(0.32, 0.72, 0, 1);  /* resorte de las hojas de iOS */
  /* Fondo de página [30-sep-2026]: mosaico en acuarela debajo de todo.
     Arena sube la opacidad; los tres bloques oscuros de temas.css lo cambian por el gyotaku en mosaico. "-ancho" = ≥900 px. */
  --fondo-imagen: url("fondo-sardinas.jpg");
  --fondo-repeat: repeat;
  --fondo-pos: 0 0;
  --fondo-pos-ancho: 0 0;
  --fondo-size: 420px;
  --fondo-size-ancho: 520px;
  --fondo-opacidad: 0.14;
  --fondo-mezcla: multiply;               /* la crema del mosaico se funde con --bg: sin costuras de color */
}

@media (min-resolution: 2dppx) { :root { --hair: 0.5px; } }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; } /* no depender solo del reset del host */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--fuente); font-size: var(--t-cuerpo);
  line-height: 1.35; letter-spacing: -0.011em; font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; overflow-x: hidden; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: var(--accent-texto); }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
.solo-lector { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ico { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico-chico { width: 14px; height: 14px; }
.con-hoja body { overflow: hidden; }

/* ---------- Fondo de página (decorativo) ----------
   Pseudo-elemento fijo del body en z-index -1: encima del lienzo (el body propaga --bg) y debajo de todo el
   contenido. Tarjetas, grupos, filas, paneles y hojas tienen fondo sólido: el texto nunca pisa el mosaico. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; -webkit-user-select: none; user-select: none;
  background-image: var(--fondo-imagen); background-repeat: var(--fondo-repeat);
  background-position: var(--fondo-pos); background-size: var(--fondo-size);
  opacity: var(--fondo-opacidad); mix-blend-mode: var(--fondo-mezcla);
}
@media (prefers-reduced-transparency: reduce), (forced-colors: active) {
  body::before { display: none; }
}

/* ---------- Estructura ---------- */
.app {
  max-width: 820px; margin: 0 auto; padding-inline: 16px;
  padding-block: 0 calc(var(--tabbar) + 84px + env(safe-area-inset-bottom, 0px)); /* libra el botón + Nuevo */
}
.cabecera {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; min-height: 44px; margin-inline: -16px; padding-inline: 16px 6px;
  background: var(--barra-solida); box-shadow: 0 0.5px 0 var(--line);
}
.marca { font-size: var(--t-cuerpo); font-weight: 600; letter-spacing: -0.02em; }
.marca b { color: var(--accent-texto); font-weight: 600; }
.cabecera-lado { display: flex; align-items: center; gap: 2px; }
.puntos { display: flex; gap: 8px; align-items: center; padding: 8px; }
.punto { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-fuerte); flex-shrink: 0; }
.punto.bien { background: var(--ok-vivo); }
.punto.mal { background: var(--critical-vivo); }
.punto.aviso { background: var(--warning-vivo); }
.punto.apagado { background: transparent; box-shadow: inset 0 0 0 1.5px var(--muted); }
.punto.espera { animation: latido 1.4s ease-in-out infinite; }
@keyframes latido { 50% { opacity: 0.35; } }
#btn-tema .ico { width: 22px; height: 22px; stroke-width: 1.8; }
#vista { outline: none; }
.titulo-vista {
  font-family: var(--fuente-titulo); font-size: var(--t-grande); font-weight: 700; letter-spacing: -0.022em; line-height: 1.15;
  margin: 14px 0 12px; overflow-wrap: anywhere;
}
.cabeza-vista { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.aviso-global p {
  display: flex; gap: 8px; align-items: center; margin-top: 12px; padding: 12px 16px; border-radius: var(--radio-grupo);
  background: var(--critical-soft); color: var(--critical); font-weight: 500;
}

/* Barras translúcidas: blur si el navegador lo soporta; si no, el color sólido de arriba. */
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .cabecera, .pestanas, .barra-guardar {
    background: var(--barra); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  }
}

/* Barra de pestañas (abajo en teléfono, riel a la izquierda en escritorio) */
.pestanas {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--barra-solida); box-shadow: 0 -0.5px 0 var(--line); padding-bottom: env(safe-area-inset-bottom, 0px);
}
.pestana {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tabbar);
  width: 100%; margin: 0; padding: 6px 2px 4px; border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 10px; font-weight: 500; letter-spacing: 0.005em; text-decoration: none;
}
.pestana .ico { width: 26px; height: 26px; stroke-width: 1.6; }
.pestana[aria-current="page"] { color: var(--accent-texto); }
.pestana[aria-current="page"] .ico { stroke-width: 2.1; }

/* ---------- Hoja (sheet): sube desde abajo con asa; en escritorio, tarjeta centrada ---------- */
.hoja { position: fixed; inset: 0; z-index: 50; }
.hoja-velo { position: absolute; inset: 0; background: var(--scrim); animation: velo 0.3s ease both; }
.hoja-marco {
  position: absolute; left: 0; right: 0; bottom: 0; top: calc(env(safe-area-inset-top, 0px) + 10px);
  display: flex; flex-direction: column; background: var(--bg); border-radius: 12px 12px 0 0;
  overflow-y: auto; overscroll-behavior: contain; box-shadow: var(--sombra); animation: subir 0.5s var(--curva) both;
}
@keyframes subir { from { transform: translateY(100%); } }
@keyframes velo { from { opacity: 0; } }
.hoja-cabeza {
  position: sticky; top: 0; z-index: 3; display: flex; align-items: center; gap: 8px; min-height: 60px;
  padding: 16px 8px 6px 16px; background: var(--bg);
}
.hoja-asa { position: absolute; top: 6px; left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: 3px; background: var(--grabber); }
.hoja-cabeza h2 {
  flex: 1; min-width: 0; font-family: var(--fuente-titulo); font-size: var(--t-titulo2); font-weight: 700; letter-spacing: -0.02em;
  overflow-wrap: anywhere; outline: none;
}
.btn-cerrar { position: relative; color: var(--muted); }
.btn-cerrar::before { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: var(--fill); }
.btn-cerrar .ico { position: relative; width: 14px; height: 14px; stroke-width: 2.8; }
.hoja-cuerpo { display: grid; gap: 22px; padding: 4px 16px calc(32px + env(safe-area-inset-bottom, 0px)); }
.barra-guardar {
  position: sticky; bottom: 0; z-index: 2; margin-inline: -16px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--barra-solida); box-shadow: 0 -0.5px 0 var(--line);
}
/* En Ajustes la página scrollea bajo la barra de pestañas fija: la barra se queda encima de ella. */
#form-ajustes .barra-guardar { bottom: calc(var(--tabbar) + env(safe-area-inset-bottom, 0px)); padding-bottom: 10px; }
.aviso-sucio { display: grid; gap: 8px; margin: 0 16px 8px; padding: 12px 16px; border-radius: var(--radio-grupo); background: var(--warning-soft); }
.aviso-sucio .btn.peligro { background: var(--surface); }

/* ---------- Avisos flotantes (HUD) ---------- */
.zona-aviso {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  display: flex; justify-content: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px; max-width: 520px; padding: 11px 18px; border-radius: 999px;
  background: var(--ink); color: var(--bg); box-shadow: var(--sombra); pointer-events: auto; font-size: var(--t-sub); font-weight: 500;
  animation: aparecer-toast 0.35s var(--curva) both;
}
.toast.error { background: var(--critical); color: var(--sobre-critico); border-radius: 16px; }
@keyframes aparecer-toast { from { opacity: 0; transform: translateY(12px) scale(0.96); } }

/* ---------- Escritorio: riel izquierdo y hoja centrada ---------- */
@media (min-width: 900px) {
  body::before { background-position: var(--fondo-pos-ancho); background-size: var(--fondo-size-ancho); }
  .pestanas {
    top: 0; right: auto; width: 240px; display: flex; flex-direction: column; gap: 2px; padding: 64px 12px 16px;
    box-shadow: 0.5px 0 0 var(--line);
  }
  .pestana {
    flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 44px; padding: 0 12px; border-radius: 10px;
    color: var(--ink); font-size: var(--t-sub); font-weight: 500; letter-spacing: -0.01em;
  }
  .pestana .ico { width: 22px; height: 22px; stroke-width: 1.8; color: var(--accent-texto); }
  .pestana[aria-current="page"] { background: var(--accent-relleno); color: var(--accent-ink); }
  .pestana[aria-current="page"] .ico { color: inherit; stroke-width: 2; }
  .app { margin-left: 240px; max-width: 920px; padding-inline: 32px; padding-bottom: 96px; }
  .cabecera { margin-inline: -32px; padding-inline: 32px 20px; }
  #form-ajustes .barra-guardar { bottom: 0; margin-inline: -32px; padding-inline: 32px; }
  .zona-aviso { bottom: 24px; left: 256px; }
  .hoja-marco {
    top: 5vh; bottom: 5vh; left: 50%; right: auto; width: min(620px, 92vw); margin-left: max(-310px, -46vw);
    border-radius: 14px; animation: aparecer 0.35s var(--curva) both;
  }
  .hoja-asa { display: none; }
  .hoja-cabeza { padding-top: 12px; }
  .hoja-cuerpo { padding-inline: 24px; }
  .hoja-cuerpo .barra-guardar { margin-inline: -24px; padding-inline: 24px; }
}
@keyframes aparecer { from { opacity: 0; transform: scale(0.96); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
