/* ============================================================
   CheQR — Sistema de diseño
   ============================================================ */
/* ---- Tipografía: Archivo (variable: peso 100–900, ancho 62–125 %), alojada en el sitio ----
   La misma declaración vive en web/src/app/globals.css para las rutas de React. */
@font-face {
  font-family: 'Archivo'; font-style: normal; font-display: swap; font-weight: 100 900; font-stretch: 62% 125%;
  src: url('/fonts/archivo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}
@font-face {
  font-family: 'Archivo'; font-style: normal; font-display: swap; font-weight: 100 900; font-stretch: 62% 125%;
  src: url('/fonts/archivo-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA,U+02BD-02C5,U+02C7-02CC,U+02CE-02D7,U+02DD-02FF,U+0304,U+0308,U+0329,U+1D00-1DBF,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
:root {
  color-scheme: dark;
  --bg-0: #070a14;
  --bg-1: #0b1020;
  --bg-2: #111830;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --text: #eef1fb;
  --text-dim: #a3acc8;
  --text-mut: #8791b3;   /* ≥4.5:1 sobre fondo y sobre tarjetas */
  --brand: #6d5efc;
  --brand-2: #22d3ee;
  --on-accent: #0a0d18;
  /* El extremo violeta se aclara para que el texto oscuro del botón cumpla 4.5:1 */
  --accent-grad: linear-gradient(135deg, #8a7dff 0%, #22d3ee 100%);
  --good: #34d399;
  --good-2: #10b981;
  --warn: #fbbf24;
  --bad: #f87171;
  --bad-text: #fca5a5;
  --ring: #a5b4fc;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font: 'Archivo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  /* Los títulos y las cifras de cartel van en el corte ancho de la familia. */
  --ancho-titulo: 112%;
  --ancho-cartel: 118%;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { scrollbar-color: rgba(255, 255, 255, 0.22) transparent; scrollbar-width: thin; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.5;
  overflow-x: hidden;
  accent-color: var(--brand);
  caret-color: var(--brand-2);
}
::selection { background: rgba(109, 94, 252, 0.45); color: #fff; }
.bg-aura {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(60% 50% at 15% 0%, rgba(109, 94, 252, 0.20), transparent 60%),
    radial-gradient(50% 50% at 100% 20%, rgba(34, 211, 238, 0.14), transparent 55%),
    radial-gradient(80% 60% at 50% 100%, rgba(109, 94, 252, 0.10), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { touch-action: manipulation; }

/* ---- Foco visible (teclado) ---- */
:focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; border-radius: 6px; }
.btn:focus-visible, .tab:focus-visible, .navitem:focus-visible, .lockbtn:focus-visible { border-radius: inherit; }

/* ---- Tipografía ---- */
h1, h2, h3 { font-weight: 750; font-stretch: var(--ancho-titulo); letter-spacing: -0.02em; line-height: 1.15; text-wrap: balance; }
p { text-wrap: pretty; }
.display { font-size: clamp(2.4rem, 6vw, 4.2rem); font-weight: 800; font-stretch: var(--ancho-cartel); letter-spacing: -0.035em; }
.muted { color: var(--text-dim); }
.mut2 { color: var(--text-mut); }
/* Énfasis de marca: color sólido (antes era texto con degradado). */
.grad-text { color: var(--brand-2); }
.mono { font-family: 'SF Mono', ui-monospace, 'Menlo', monospace; font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- Marcador: las cifras del reloj (Big Shoulders Stencil 900, la misma de Banderos+) ----
   Sus dígitos no tienen ancho fijo: por eso cada uno va en una caja de 0.54em que
   rueda (`rodar()` en common.js; `DigitosRodantes` en React). Solo se anima transform. */
@font-face {
  font-family: 'Big Shoulders Stencil'; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url('/fonts/marcador-latin.woff2') format('woff2');
}
.marcador { font-family: 'Big Shoulders Stencil', var(--font, sans-serif); font-weight: 900; font-variation-settings: 'opsz' 72; font-stretch: normal; letter-spacing: 0; font-variant-numeric: normal; }
.dr-caja { display: inline-flex; height: 1em; line-height: 1; vertical-align: top; }
.dr-fila { display: inline-flex; height: 1em; overflow: hidden; }
.dr-dig { display: block; width: .54em; height: 1em; overflow: hidden; text-align: center; }
.dr-col { display: block; transition: transform 380ms cubic-bezier(.3, .7, .2, 1); will-change: transform; }
.dr-col > i { display: block; height: 1em; font-style: normal; line-height: 1; }
.dr-fijo { display: block; height: 1em; line-height: 1; white-space: pre; }
.dr-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .dr-col { transition: none; } }

/* ---- Layout ---- */
.wrap { width: 100%; max-width: 1140px; margin: 0 auto; padding: 0 24px; }
.center-screen { min-height: 100dvh; display: grid; place-items: center; padding: 32px 20px; }
.stack { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; } .gap-24 { gap: 24px; }
.grow { flex: 1; }

/* ---- Marca ---- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-stretch: var(--ancho-titulo); letter-spacing: -0.02em; }
.brand .mark {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-grad); box-shadow: 0 8px 22px -6px rgba(109, 94, 252, 0.7);
  color: var(--on-accent); font-weight: 900;
}
.brand .mark svg { width: 20px; height: 20px; }

/* ---- Tarjetas de vidrio ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-shadow: var(--shadow);
}
.card.pad { padding: 28px; }
.card.pad-lg { padding: 40px; }
/* Las tablas anchas se desplazan dentro de su tarjeta, no de la página. */
.card:has(table) { overflow-x: auto; }

/* ---- Botones ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 44px; padding: 10px 20px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 650; line-height: 1.3; cursor: pointer;
  transition: transform .12s var(--ease-out), box-shadow .2s var(--ease-out), background .2s, border-color .2s, opacity .2s;
  user-select: none; white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary { background: var(--accent-grad); color: var(--on-accent); box-shadow: 0 12px 30px -10px rgba(109, 94, 252, 0.65); }
.btn-primary:hover { box-shadow: 0 16px 40px -10px rgba(109, 94, 252, 0.8); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: rgba(248, 113, 113, 0.12); border-color: rgba(248, 113, 113, 0.3); color: var(--bad-text); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }
.btn-lg { min-height: 54px; padding: 14px 28px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn[disabled]:active { transform: none; }
/* Estado de carga: el botón conserva su ancho y muestra un indicador. */
.btn.is-busy { position: relative; color: transparent !important; pointer-events: none; opacity: .85; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid rgba(10, 13, 24, 0.3); border-top-color: var(--on-accent);
  animation: spin .7s linear infinite;
}
.btn-ghost.is-busy::after, .btn-danger.is-busy::after { border-color: rgba(255, 255, 255, 0.25); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Formularios ---- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field label { font-size: .82rem; font-weight: 600; color: var(--text-dim); }
.field .hint { font-size: .8rem; color: var(--text-mut); }
.input {
  width: 100%; min-height: 46px; padding: 12px 15px; border-radius: 12px;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border); color: var(--text);
  transition: border-color .15s, background .15s, box-shadow .15s; outline: none;
}
.input::placeholder { color: var(--text-mut); opacity: 1; }
.input:hover { border-color: var(--border-strong); }
.input:focus { border-color: var(--brand); background: rgba(109, 94, 252, 0.06); box-shadow: 0 0 0 4px rgba(109, 94, 252, 0.22); }
.input[disabled] { opacity: .55; cursor: not-allowed; }
.input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.16); }
/* Autocompletado del navegador: conserva el tema oscuro (sin el fondo amarillo o blanco). */
.input:-webkit-autofill, .input:-webkit-autofill:hover, .input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--brand-2);
  -webkit-box-shadow: 0 0 0 1000px #121a30 inset; box-shadow: 0 0 0 1000px #121a30 inset;
}
select.input { appearance: none; -webkit-appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a3acc8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; }
select.input option { background: var(--bg-2); color: var(--text); }

/* ---- Etiquetas / chips ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--surface); border: 1px solid var(--border);
}
.chip.good { color: var(--good); background: rgba(52, 211, 153, 0.10); border-color: rgba(52, 211, 153, 0.25); }
.chip.out { color: var(--text-dim); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pulse { animation: pulse 2s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%, 100% { box-shadow: 0 0 0 8px transparent; }
}

/* ---- Avatares ---- */
.avatar {
  border-radius: 50%; object-fit: cover; background: var(--surface-2);
  border: 2px solid var(--border-strong); flex-shrink: 0;
}
.avatar-fallback {
  border-radius: 50%; display: grid; place-items: center; font-weight: 800;
  background: var(--accent-grad); color: var(--on-accent); flex-shrink: 0;
}

/* ---- Iconos (trazo único de 2px) ---- */
.ico-svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ---- Utilidades ---- */
.hidden { display: none !important; }
.text-c { text-align: center; }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.toast-host { position: fixed; top: max(20px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; align-items: center; gap: 10px; pointer-events: none; }
.toast {
  padding: 12px 18px; border-radius: 12px; background: #1a2138; border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); animation: slideDown .25s var(--ease-out); font-weight: 600; font-size: .92rem; max-width: 90vw;
  transition: opacity .3s;
}
.toast.err { border-color: rgba(248,113,113,.4); color: var(--bad-text); }
.toast.ok { border-color: rgba(52,211,153,.4); color: var(--good); }
@keyframes slideDown { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fadeUp .5s var(--ease-out) both; }

/* ---- Diálogo de confirmación (primitiva única: confirmDialog) ---- */
.dlg-bg { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; background: rgba(7, 10, 20, 0.78); animation: dlgIn .18s var(--ease-out); }
.dlg { width: 100%; max-width: 420px; padding: 28px; background: #141b33; backdrop-filter: none; -webkit-backdrop-filter: none; }
.dlg h3 { font-size: 1.25rem; margin-bottom: 10px; }
.dlg-hl { font-weight: 700; padding: 10px 12px; margin-bottom: 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); overflow-wrap: anywhere; }
.dlg p { font-size: .95rem; }
.dlg-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
@keyframes dlgIn { from { opacity: 0; } to { opacity: 1; } }

/* ---- Aviso de versión nueva (fuente única: aviso-version.js) ----
   Abajo a la derecha, fondo opaco. Por encima de los modales (90) y por debajo
   de confirmDialog (200). La salida dura lo mismo que SALIDA_MS en el script. */
.aviso-version {
  position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); z-index: 110;
  width: calc(100% - 32px); max-width: 384px; overflow: hidden;
  border-radius: var(--radius-sm); background: #141b33; border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); animation: avisoVersionIn .34s var(--ease-out) both; transition: bottom .3s var(--ease-out);
}
.aviso-version.is-leaving { animation: avisoVersionOut .25s ease-in both; }
.aviso-version__barra { height: 2px; background: var(--accent-grad); }
.aviso-version__cuerpo { padding: 14px 16px; }
.aviso-version__texto { display: flex; align-items: flex-start; gap: 12px; }
.aviso-version__texto > .ico-svg { width: 18px; height: 18px; margin-top: 2px; color: var(--brand-2); }
.aviso-version__titulo { font-size: .9rem; font-weight: 600; line-height: 1.35; }
.aviso-version__mensaje { margin-top: 4px; font-size: .78rem; line-height: 1.5; color: var(--text-dim); }
.aviso-version__acciones { display: flex; justify-content: center; gap: 8px; margin-top: 12px; }
.aviso-version__btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px;
  border: 1px solid transparent; background: none; color: var(--text-dim);
  font-size: .78rem; font-weight: 600; cursor: pointer; transition: color .2s, background .2s, border-color .2s;
}
.aviso-version__btn:hover { color: var(--text); }
.aviso-version__btn--ok { color: var(--text); background: rgba(34, 211, 238, 0.14); border-color: rgba(34, 211, 238, 0.5); }
.aviso-version__btn--ok:hover { background: rgba(34, 211, 238, 0.24); }
.aviso-version__btn .ico-svg { width: 13px; height: 13px; stroke-width: 2.5; }
@media (pointer: coarse) { .aviso-version__btn { min-height: 44px; padding: 7px 18px; } }
@keyframes avisoVersionIn { from { opacity: 0; transform: translateY(80px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes avisoVersionOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(80px); } }

/* ---- Skeletons: toda vista que pinta datos carga con filas fantasma ---- */
.skel { padding: 8px 0; }
.skel-row { display: flex; align-items: center; gap: 14px; padding: 14px; border-bottom: 1px solid var(--border); }
.skel-row:last-child { border-bottom: 0; }
.skel-dot, .skel-bar { background: linear-gradient(90deg, rgba(255,255,255,.05) 0%, rgba(255,255,255,.11) 50%, rgba(255,255,255,.05) 100%); background-size: 200% 100%; animation: skel 1.3s linear infinite; }
.skel-dot { width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0; }
.skel-bar { height: 12px; border-radius: 6px; flex: 1; max-width: 46%; }
.skel-bar.short { max-width: 18%; margin-left: auto; }
@keyframes skel { to { background-position: -200% 0; } }

/* ---- Pantallas táctiles ---- */
@media (pointer: coarse) {
  .btn.rowbtn { min-height: 44px; }
  /* 16px es el umbral exacto bajo el cual iOS hace zoom al enfocar un campo. */
  input, textarea, select { font-size: 16px; }
}

/* ---- Movimiento reducido: se conserva el cambio de estado, sin desplazamientos ---- */
@media (prefers-reduced-motion: reduce) {
  .fade-up, .toast, .state, .qbox, .confirm, .modal-bg, .result-ico, .cava, .dlg-bg, .aviso-version { animation: none !important; }
  .skel-dot, .skel-bar { animation: none; }
  .pulse { animation: none; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 30%, transparent); }
  .btn { transition: background .2s, border-color .2s, opacity .2s; }
  .btn:active { transform: none; }
  .btn.is-busy::after, .spinner { animation-duration: 1.6s; }
}
