/* Simulador ENURM — estilos
   Tokens con contraste AA verificado: texto ≥ 7:1, secundarios ≥ 5:1, bordes interactivos ≥ 3:1. */
:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #131a24;
  --text-2: #4b5768;
  --border: #d4dbe4;
  --border-strong: #7a8797;
  --primary: #0b5f8f;
  --primary-ink: #ffffff;
  --primary-soft: #e6f0f7;
  --ok: #11734a;
  --ok-bg: #e3f3ea;
  --bad: #b3261e;
  --bad-bg: #fce9e7;
  --warn: #7a5200;
  --warn-bg: #fff2d1;
  --focus: #1d4ed8;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .06);
  --radius: 14px;
  --radius-sm: 10px;
  --fs: 1.0625rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d1117; --surface: #151b23; --surface-2: #1c2430; --text: #e6ecf2; --text-2: #a3afbd;
    --border: #2a3441; --border-strong: #6b7a8c; --primary: #6cb8ef; --primary-ink: #06121c; --primary-soft: #13293b;
    --ok: #5cd38a; --ok-bg: #10301e; --bad: #ff8a80; --bad-bg: #3a1716; --warn: #f5c451; --warn-bg: #332709;
    --focus: #93c5fd; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1117; --surface: #151b23; --surface-2: #1c2430; --text: #e6ecf2; --text-2: #a3afbd;
  --border: #2a3441; --border-strong: #6b7a8c; --primary: #6cb8ef; --primary-ink: #06121c; --primary-soft: #13293b;
  --ok: #5cd38a; --ok-bg: #10301e; --bad: #ff8a80; --bad-bg: #3a1716; --warn: #f5c451; --warn-bg: #332709;
  --focus: #93c5fd; --shadow: 0 1px 2px rgba(0,0,0,.4);
}
:root[data-fs="grande"] { font-size: 112.5%; }
:root[data-fs="xl"] { font-size: 125%; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
@media (max-width: 899px) { html { scroll-padding-bottom: calc(84px + env(safe-area-inset-bottom)); } }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: var(--fs); line-height: 1.55; min-height: 100dvh;
}
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.saltar { position: absolute; left: 8px; top: -60px; background: var(--primary); color: var(--primary-ink); padding: 10px 14px; border-radius: 8px; z-index: 50; text-decoration: none; }
.saltar:focus { top: 8px; }

/* ---------- estructura ---------- */
.barra {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px;
}
.marca { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; font-size: 1rem; }
.marca svg { flex: none; }
.marca small { display: block; font-weight: 500; color: var(--text-2); font-size: .78rem; line-height: 1.2; }
.barra .espacio { flex: 1; }
.cuenta { font-size: .85rem; color: var(--text-2); text-align: right; line-height: 1.25; }
.cuenta b { color: var(--text); font-size: 1rem; }
.btn-icono { width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.btn-icono:hover { background: var(--surface-2); }

.layout { display: grid; grid-template-columns: 1fr; max-width: 1180px; margin: 0 auto; }
main { padding: 16px 16px 96px; min-width: 0; }
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px;
  color: var(--text-2); text-decoration: none; font-size: .72rem; font-weight: 600; border-radius: 12px;
}
.nav a[aria-current="page"] { color: var(--primary); background: var(--primary-soft); }
.nav svg { width: 24px; height: 24px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: 220px 1fr; gap: 8px; padding: 0 16px; }
  .nav {
    position: sticky; top: 72px; align-self: start; display: flex; flex-direction: column; gap: 4px;
    border: 1px solid var(--border); border-radius: var(--radius); margin-top: 16px; padding: 8px; background: var(--surface);
  }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; font-size: .95rem; min-height: 48px; }
  main { padding: 16px 8px 48px; }
}

/* ---------- tipografía y bloques ---------- */
h1 { font-size: 1.6rem; line-height: 1.2; margin: 4px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; line-height: 1.3; margin: 24px 0 10px; }
h3 { font-size: 1.02rem; margin: 0 0 6px; }
p { margin: 0 0 10px; }
.sub { color: var(--text-2); font-size: .95rem; }
.peq { font-size: .85rem; color: var(--text-2); }
.tarjeta { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tarjeta + .tarjeta { margin-top: 12px; }
.rejilla { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.rejilla-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.rejilla > .tarjeta + .tarjeta, .rejilla-2 > .tarjeta + .tarjeta { margin-top: 0; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .v { font-size: 1.9rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--text-2); font-size: .85rem; }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.entre { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.pri { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.aviso { border-radius: var(--radius-sm); padding: 12px 14px; background: var(--warn-bg); color: var(--warn); font-size: .92rem; }
.aviso.info { background: var(--primary-soft); color: var(--text); }
.vacio { text-align: center; padding: 32px 16px; color: var(--text-2); }

/* ---------- botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 650; font-size: 1rem; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--surface-2); }
.btn.pri { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.pri:hover { filter: brightness(1.08); }
.btn.peligro { color: var(--bad); border-color: var(--bad); }
.btn.bloque { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.chico { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.campo { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .95rem; }
.campo .peq { font-weight: 400; }
select, input[type="number"], input[type="date"], input[type="search"], input[type="text"], textarea {
  font: inherit; font-size: 1rem; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); width: 100%;
}
textarea { min-height: 90px; }
.opciones-filtro { display: flex; flex-wrap: wrap; gap: 8px; }
.toggle { position: relative; }
.toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.toggle span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; font-size: .92rem;
}
.toggle input:checked + span { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.toggle input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
fieldset { border: 0; padding: 0; margin: 0 0 16px; }
legend { font-weight: 700; margin-bottom: 8px; }

/* ---------- pregunta ---------- */
.q-cabecera { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.q-enunciado { font-size: calc(var(--fs) * 1.06); font-weight: 600; line-height: 1.55; margin: 6px 0 14px; white-space: pre-line; }
.q-opciones { display: grid; gap: 10px; list-style: none; padding: 0; margin: 0; }
.opcion {
  width: 100%; text-align: left; display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  min-height: 56px; padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.opcion:hover:not([disabled]) { background: var(--surface-2); }
.opcion .letra {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 750; font-size: .9rem;
  background: var(--surface-2); border: 1px solid var(--border-strong);
}
.opcion[aria-pressed="true"] { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1.5px var(--primary); }
.opcion[aria-pressed="true"] .letra { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.opcion.correcta { border-color: var(--ok); background: var(--ok-bg); }
.opcion.correcta .letra { background: var(--ok); color: var(--surface); border-color: var(--ok); }
.opcion.incorrecta { border-color: var(--bad); background: var(--bad-bg); }
.opcion.incorrecta .letra { background: var(--bad); color: var(--surface); border-color: var(--bad); }
.opcion.incorrecta[aria-pressed="true"] { box-shadow: inset 0 0 0 1.5px var(--bad); }
.opcion[disabled] { cursor: default; }
.opcion .icono-res { font-weight: 800; }
.explicacion { margin-top: 14px; border-left: 4px solid var(--primary); background: var(--surface-2); border-radius: 0 12px 12px 0; padding: 12px 14px; }
.explicacion h3 { margin-bottom: 4px; }
.explicacion .ref { margin-top: 8px; font-size: .85rem; color: var(--text-2); }
.resultado-linea { font-weight: 750; margin-top: 12px; }
.resultado-linea.ok { color: var(--ok); }
.resultado-linea.bad { color: var(--bad); }
.acciones-q { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.acciones-q .espacio { flex: 1; }
.progreso-barra { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.progreso-barra > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.reloj { font-variant-numeric: tabular-nums; font-weight: 750; font-family: var(--mono); }
.reloj.alerta { color: var(--bad); }

/* navegador de preguntas del simulacro */
.mapa { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.mapa button {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: inherit; font-size: .85rem; font-weight: 650; cursor: pointer; position: relative;
}
.mapa button.resp { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.mapa button[aria-current="step"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); text-decoration: underline 2px; text-underline-offset: 3px; font-weight: 800; }
.mapa button.marc::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 2px var(--surface); }
.mapa button.ok { background: var(--ok-bg); border-color: var(--ok); }
.mapa button.bad { background: var(--bad-bg); border-color: var(--bad); }

/* ---------- gráficos ---------- */
.barras { display: grid; gap: 10px; }
.barra-fila { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 52px; gap: 10px; align-items: center; font-size: .92rem; }
.barra-fila .pista { height: 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.barra-fila .pista i { display: block; height: 100%; background: var(--primary); }
.barra-fila .pista i.bajo { background: var(--bad); }
.barra-fila .pista i.medio { background: var(--warn); }
.barra-fila .pista i.alto { background: var(--ok); }
.barra-fila .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.grafico svg { width: 100%; height: auto; display: block; }
.calor { display: grid; grid-template-columns: repeat(auto-fill, 14px); gap: 3px; }
.calor i { width: 14px; height: 14px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.calor i.n1 {
  background: var(--primary-soft);
  background: color-mix(in srgb, var(--primary) 30%, var(--surface));
}
.calor i.n2 {
  background: var(--primary);
  background: color-mix(in srgb, var(--primary) 60%, var(--surface));
}
.calor i.n3 { background: var(--primary); }

/* ---------- lista del banco ---------- */
.lista { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.lista li a, .lista li button.item {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-decoration: none; font: inherit; cursor: pointer;
}
.lista li a:hover, .lista li button.item:hover { background: var(--surface-2); }
.lista .linea2 { font-size: .82rem; color: var(--text-2); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: min(560px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; }
.cargando { display: grid; place-items: center; min-height: 60vh; gap: 12px; text-align: center; color: var(--text-2); }
@media (prefers-reduced-motion: no-preference) {
  .opcion, .btn, .mapa button { transition: background-color .15s, border-color .15s; }
}
main:focus, h1[tabindex="-1"]:focus { outline: none; }
.q-enunciado, .opcion > span:nth-child(2), .lista li a, .explicacion, .barra-fila > span:first-child, .aviso { overflow-wrap: anywhere; hyphens: auto; }
::placeholder { color: var(--text-2); opacity: 1; }
.btn[aria-pressed="true"] { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.q-titulo { font-size: 1.05rem; margin: 0; line-height: 1.3; }
.h-tarjeta { font-size: 1.02rem; margin: 0 0 6px; }
.tarjeta.destacada { border-color: var(--primary); }
.reloj.alerta::before { content: "⚠ "; }
.dlg-botones { justify-content: flex-end; margin-top: 16px; }
.aviso-global { margin: 8px; position: relative; z-index: 70; }
.btn-archivo { position: relative; overflow: hidden; }
.archivo-oculto { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.btn-archivo:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.item-btn { width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; padding: 6px 4px; border-radius: 10px; cursor: pointer; }
.item-btn:hover { background: var(--surface-2); }
.filtro-anios summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 6px; }
.reporte summary { cursor: pointer; color: var(--text-2); font-size: .9rem; min-height: 32px; }
kbd { font-family: var(--mono); font-size: .85em; border: 1px solid var(--border-strong); border-radius: 4px; padding: 0 4px; }
/* cabecera de la sesión siempre visible */
.ses-cabecera { position: sticky; top: 57px; z-index: 10; background: var(--bg); padding: 8px 0 6px; margin-top: -8px; }
.ses-cabecera .fila-ses { gap: 6px; }
.ses-cuenta { font-weight: 600; }
@media (min-width: 521px) { .ses-cabecera { top: 65px; } }
@media (max-width: 899px) {
  /* acciones al alcance del pulgar */
  .acciones-q { position: sticky; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 5; background: var(--surface);
    margin: 16px -16px -16px; padding: 10px 16px; border-top: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); flex-wrap: wrap; }
  .acciones-q .btn { flex: 1 1 7.5rem; white-space: normal; min-width: 0; padding-inline: 10px; }
  .acciones-q .espacio { display: none; }
  body.en-sesion .nav { display: none; }
  body.en-sesion main { padding-bottom: 24px; }
  .pie-form { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); background: var(--surface); padding: 10px 0 0; margin-top: 8px; }
  .atajos { display: none; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .barra { min-height: 48px; padding: 4px 12px; }
  .barra .btn-icono { width: 40px; height: 40px; }
  .marca small, .cuenta-larga { display: none; }
  .nav a { min-height: 44px; flex-direction: row; gap: 6px; }
  .ses-cabecera { top: 49px; }
}
@media (max-width: 520px) {
  .marca small, .cuenta-larga { display: none; }
  .barra { min-height: 52px; padding: 8px 12px; }
  h1 { font-size: 1.4rem; }
  .q-cabecera { align-items: flex-start; }
}
.resultado-linea:focus { outline: none; }
/* ---------- E2-P04: caso de la pregunta anterior (IA-05) y texto editado por IA (IA-07) ----------
   Solo tokens existentes: texto --text sobre --surface-2 (>= 7:1), secundarios --text-2 (>= 5:1), borde --border-strong (>= 3:1).
   Sin anchos fijos: con 375 px y con el texto al 175-200 % (CAL-07) todo parte y baja de linea (overflow-wrap + flex-wrap). */
.caso-previo { margin: 6px 0 12px; border: 1px solid var(--border-strong); border-left: 4px solid var(--primary); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); padding: 0 14px 2px; }
.caso-previo summary { cursor: pointer; padding: 12px 0; font-weight: 700; font-size: .9rem; }
.caso-previo p { margin: 0 0 10px; white-space: pre-line; }
.texto-ia { margin: 10px 0; }
.texto-ia p { margin: 0 0 8px; }
.texto-ia.erratas { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: .85rem; color: var(--text-2); }
.texto-ia.erratas .orig-res { flex: 1 1 100%; }
.orig-res { margin-top: 8px; font-size: .92rem; }
.orig-res:empty { margin: 0; }
.orig-det { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); padding: 0 12px 6px; }
.orig-det summary { cursor: pointer; padding: 10px 0; font-weight: 700; }
.orig-det p { margin: 0 0 6px; white-space: pre-line; }
.orig-det ol { margin: 0; padding-left: 1.8em; }
.caso-previo, .caso-previo p, .texto-ia, .orig-det { min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
@media print {
  .barra, .nav, .acciones-q { display: none !important; }
  main { padding: 0; }
}
