/* ============================================================================
   Chilaquilli · sistema de diseño (copia propia de esta app)
   Dirección: "taquería editorial" — carbón cálido, chile + maíz + lima,
   titulares condensados en versalitas, números monoespaciados, papel y grano.
   Lo usa solo la administración: cada app lleva su copia y no depende de las demás.
   ============================================================================ */

/* --- Tokens ----------------------------------------------------------------- */
:root {
  color-scheme: dark;

  /* Superficies: carbón cálido (no azulado), del fondo hacia arriba */
  --bg:        #14100E;
  --side:      #1A1512;
  --surface:   #221B16;
  --surface-2: #2C231C;
  --surface-3: #3B2F25;

  --line:   rgba(255, 235, 210, 0.09);
  --line-2: rgba(255, 235, 210, 0.19);

  --text:   #F7EEE2;
  --text-2: #CFBCA6;
  --muted:  #97846D;

  --accent:        #E8452C;  /* chile */
  --accent-strong: #C63318;
  --accent-soft:   rgba(232, 69, 44, 0.16);
  --maiz:          #F2A93B;  /* maíz */

  --lime:          #9CC24A;  /* lima */
  --cielo:         #5FB3CE;  /* cielo */

  --ok:        #7FB03C;
  --ok-text:   #B6DC77;
  --ok-soft:   rgba(127, 176, 60, 0.18);
  --warn:      #F2A93B;
  --warn-soft: rgba(242, 169, 59, 0.15);
  --bad:       #D8432C;
  --bad-text:  #FF9077;

  --radius:    18px;
  --radius-sm: 13px;
  --radius-lg: 26px;

  /* Tipografía: display condensada para titulares, cuerpo legible,
     monoespaciada para dinero y conteos (se lee como un ticket). */
  --font:         "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-display: "Bahnschrift", "DIN Alternate", "Franklin Gothic Medium", "Arial Narrow", var(--font);
  --font-num:     "Cascadia Mono", Consolas, ui-monospace, SFMono-Regular, monospace;

  --ease:     cubic-bezier(0.22, 1, 0.36, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur:      180ms;

  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.40);
  --sh-2: 0 10px 28px rgba(0, 0, 0, 0.45);
  --sh-3: 0 26px 64px rgba(0, 0, 0, 0.60);

  /* Texturas (SVG en línea: no piden archivos extra ni CDN) */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  --picado: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='28' height='13'%3E%3Cpath d='M0 0h14L7 12z' fill='%23E8452C'/%3E%3Cpath d='M14 0h14L21 12z' fill='%23F2A93B'/%3E%3Cpath d='M7 0h14L14 12z' fill='%23E8452C' opacity='.75'/%3E%3C/svg%3E");
}

/* --- Base ------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  touch-action: manipulation;
}

/* Grano sutil por encima de todo: da textura de papel, no un plano digital.
   Va arriba (z-index alto) con pointer-events:none, así que no estorba. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 9999; pointer-events: none;
  background-image: var(--grain); background-size: 160px 160px; opacity: 0.035;
}
body > * { position: relative; z-index: 1; }

button {
  font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { cursor: not-allowed; }
input, textarea, select { font: inherit; color: inherit; }
/* En pantallas táctiles los campos miden 16 px: con menos, iOS hace zoom al enfocarlos. */
@media (pointer: coarse) { input, textarea, select { font-size: 16px; } }
textarea { resize: vertical; }
h1, h2, h3, p { margin: 0; }
svg.i { display: block; flex: none; }

::selection { background: var(--accent-soft); color: #fff; }

/* Foco visible y consistente en todo (nunca outline:none sin reemplazo). */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Barras de desplazamiento discretas */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }

#app { height: 100vh; height: 100dvh; }

/* --- Tipografía -------------------------------------------------------------- */
h1, h2, h3 { text-wrap: balance; }
h1 {
  font-family: var(--font-display); font-size: 26px; line-height: 1.04;
  text-transform: uppercase; letter-spacing: 0.005em;
}
h2 { font-family: var(--font-display); font-size: 19px; line-height: 1.14; text-transform: uppercase; letter-spacing: 0.012em; }
h3 { font-size: 15px; line-height: 1.25; }

.label, .field > label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.hint { font-size: 12.5px; color: var(--muted); }
.err-text { color: var(--bad-text); font-size: 13px; min-height: 18px; }

/* --- Botones ----------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line); font-weight: 650;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              transform 90ms var(--ease-out), box-shadow var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--line-2); }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.985); }
.btn:disabled { opacity: 0.42; }

.btn.primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(232, 69, 44, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.btn.primary:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: 0 9px 26px rgba(232, 69, 44, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
.btn.ghost { background: transparent; border-color: var(--line-2); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.danger { background: transparent; border-color: rgba(216, 67, 44, 0.5); color: var(--bad-text); }
.btn.danger:hover:not(:disabled) { background: rgba(216, 67, 44, 0.14); }

.btn.sm { min-height: 36px; padding: 0 13px; font-size: 13px; border-radius: 11px; }

.icon-btn {
  width: 42px; height: 42px; display: inline-grid; place-items: center; flex: none;
  border-radius: 13px; color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform 90ms var(--ease-out);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.danger:hover { color: var(--bad-text); background: rgba(216, 67, 44, 0.14); }

/* --- Campos ------------------------------------------------------------------ */
.input {
  width: 100%; min-height: 48px; padding: 10px 15px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder { color: var(--muted); }
.input:hover { border-color: var(--line-2); }
.input:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input.sm { min-height: 38px; padding: 6px 11px; border-radius: 10px; }
textarea.input { min-height: 72px; }
.field { display: grid; gap: 6px; }
.field:focus-within > label { color: var(--text); }

/* Interruptor (disponible / agotado). */
.switch { position: relative; width: 48px; height: 27px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--surface-3); transition: background var(--dur) var(--ease); }
.switch span::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 21px; height: 21px; border-radius: 50%;
  background: #fff; transition: transform var(--dur) var(--ease-out);
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(21px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Piezas ------------------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--sh-1);
}

.chip {
  display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 17px;
  border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
  color: var(--text-2); font-weight: 600; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform 90ms var(--ease-out);
}
.chip:hover { background: var(--surface-2); color: var(--text); border-color: var(--line-2); }
.chip:active { transform: scale(0.97); }
.chip.active {
  border-color: var(--accent); color: var(--text);
  background: var(--accent-soft); box-shadow: inset 0 0 0 1px rgba(232, 69, 44, 0.25);
}
.chip:disabled { opacity: 0.4; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2);
  letter-spacing: 0.01em;
}

.badge.ok { background: var(--ok-soft); color: var(--ok-text); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: rgba(216, 67, 44, 0.16); color: var(--bad-text); }

/* Marca de la casa: cuadro con la inicial, inclinado como un sello. */
.logo-mark {
  width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff; font-family: var(--font-display); font-size: 28px; font-weight: 800;
  box-shadow: 0 8px 22px rgba(232, 69, 44, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  flex: none;
}

/* --- Imagen de producto ------------------------------------------------------ */
/* El contenedor define el tamaño; sin foto se muestran las iniciales. */
.pimg { display: block; width: 100%; height: 100%; object-fit: cover; }
.pimg.ph {
  display: grid; place-items: center; font-family: var(--font-display);
  font-weight: 800; letter-spacing: 0.06em; font-size: 1.15em;
  color: rgba(255, 246, 232, 0.55);
  background:
    radial-gradient(120% 120% at 20% 0%, hsl(var(--h) 32% 26%) 0%, transparent 60%),
    linear-gradient(145deg, hsl(var(--h) 26% 22%), hsl(var(--h) 22% 13%));
  box-shadow: inset 0 0 0 1px rgba(255, 235, 210, 0.06);
}

/* --- Modal ------------------------------------------------------------------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(12, 8, 6, 0.68);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fade 160ms var(--ease-out);
}
.modal {
  width: min(540px, 100%); max-height: 100%; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-lg);
  box-shadow: var(--sh-3); animation: pop 200ms var(--ease-out); overflow: hidden;
}
.modal.wide { width: min(700px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 6px; flex: none; }
.modal-head h2 { font-size: 19px; flex: 1; }
.modal-body {
  padding: 10px 20px 16px; overflow: auto; min-height: 0; display: grid; gap: 16px; align-content: start;
  overscroll-behavior: contain;
}
.modal-actions {
  display: flex; gap: 10px; padding: 14px 20px 20px; border-top: 1px solid var(--line); flex: none;
  background: linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.18));
}
.modal-actions .btn { flex: 1; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.975); } }

/* --- Avisos ------------------------------------------------------------------ */
.toasts {
  position: fixed; z-index: 80; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: grid; gap: 8px; width: min(460px, calc(100% - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 13px 17px;
  background: var(--surface-3); border: 1px solid var(--line-2); border-radius: 15px;
  box-shadow: var(--sh-2); font-weight: 600; animation: pop 200ms var(--ease-out);
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--cielo); flex: none; }
.toast.err { border-color: rgba(216, 67, 44, 0.55); }
.toast.err::before { background: var(--bad); }
.toast.ok { border-color: rgba(127, 176, 60, 0.55); }
.toast.ok::before { background: var(--lime); }

/* --- Pantalla de PIN --------------------------------------------------------- */
.pin-screen { height: 100%; display: grid; place-items: center; padding: 20px; overflow: auto; }
.pin-box { width: min(348px, 100%); display: grid; gap: 18px; justify-items: center; text-align: center; }
.pin-box .logo-mark { width: 76px; height: 76px; border-radius: 24px; font-size: 34px; transform: rotate(-3deg); }
.pin-dots { display: flex; gap: 12px; min-height: 18px; }
.pin-dots i {
  width: 14px; height: 14px; border-radius: 50%; background: var(--surface-3);
  transition: background 140ms var(--ease), transform 140ms var(--ease-out);
}
.pin-dots i.on { background: var(--accent); transform: scale(1.15); box-shadow: 0 0 12px var(--accent-soft); }
.pin-box.shake .pin-dots { animation: shake 380ms var(--ease-out); }
@keyframes shake { 20%, 60% { transform: translateX(-9px); } 40%, 80% { transform: translateX(9px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; }
.keypad button {
  height: 68px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line);
  font-family: var(--font-display); font-size: 25px; font-weight: 700; display: grid; place-items: center;
  transition: background var(--dur) var(--ease), transform 90ms var(--ease-out), border-color var(--dur) var(--ease);
}
.keypad button:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-2); }
.keypad button:active:not(:disabled) { transform: scale(0.955); }
.keypad .go { background: linear-gradient(180deg, var(--accent), var(--accent-strong)); border-color: transparent; color: #fff; }
.keypad .go:disabled { opacity: 0.4; filter: grayscale(0.4); }

/* --- Estados y espera -------------------------------------------------------- */
.spin {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
/* Aviso que aparece solo si la app tarda en arrancar (p. ej. al abrir index.html con doble clic). */
.slow-hint { max-width: 420px; color: var(--muted); font-size: 13.5px; opacity: 0; animation: reveal 0s 3.5s forwards; }
@keyframes reveal { to { opacity: 1; } }
.center-fill {
  height: 100%; display: grid; place-items: center; text-align: center; gap: 14px;
  padding: 24px; align-content: center; justify-items: center;
}

/* --- Animaciones ------------------------------------------------------------- */
/* Entrada de elementos: la usa el CSS propio de la app (animation: ...). */
@keyframes rise { from { opacity: 0; transform: translateY(9px); } }

/* --- Accesibilidad: menos movimiento ---------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

