/* Folio. La hoja A4 es la protagonista; la interfaz se queda atrás.
   El amarillo de rotulador marca dónde estás y lo que conviene revisar. */
:root {
  --desk: #e8ebef;
  --surface: #ffffff;
  --ink: #18202b;
  --ink-2: #414b5a;
  --muted: #566070;
  --line: #cfd5dc;
  --line-soft: #dfe3e8;
  --marker: #f6e05e;
  --marker-soft: #fbf1b0;
  --danger: #b42318;
  --warn: #8a5a00;
  --ok: #17703c;
  --radius-sheet: 2px;
  --radius-ui: 10px;
  --shadow-sheet: 0 1px 2px rgba(24, 32, 43, .08), 0 8px 24px rgba(24, 32, 43, .10);
  --font-ui: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --gutter: 16px;
  --max: 1280px;
}
@media (min-width: 720px) { :root { --gutter: 32px; } }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; z-index: 50; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 6px; }
.skip:focus { top: 8px; }

/* Foco visible: trazo de tinta con halo de rotulador. */
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--marker); border-radius: 4px; }

.muted { color: var(--muted); }
.lead { font-size: 1.125rem; color: var(--ink-2); max-width: 60ch; }

/* ---------------- Barra superior ---------------- */
.bar { position: sticky; top: 0; z-index: 20; background: rgba(232, 235, 239, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.bar-inner { max-width: var(--max); margin: 0 auto; padding: 10px var(--gutter); display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { font-family: var(--font-display); font-size: 1.6rem; font-style: italic; color: var(--ink); text-decoration: none; line-height: 1; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
.steps button {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer;
  padding: 6px 10px; border-radius: 6px; color: var(--muted); font-size: .95rem;
}
.steps button:disabled { cursor: default; opacity: .55; }
.steps button:not(:disabled):hover { color: var(--ink); }
.steps .n { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid currentColor; font-size: .78rem; font-weight: 700; }
.steps button[aria-current="step"] { color: var(--ink); font-weight: 700; background: linear-gradient(transparent 55%, var(--marker) 55%, var(--marker) 92%, transparent 92%); }
.steps button[aria-current="step"] .n { background: var(--ink); color: var(--marker); border-color: var(--ink); }
.steps button.done .n { background: var(--ink-2); border-color: var(--ink-2); color: #fff; }
.demo-note { max-width: var(--max); margin: 0 auto; padding: 6px var(--gutter) 8px; font-size: .9rem; color: var(--ink-2); }
.demo-note::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; background: var(--marker); border: 1px solid #c9b22f; border-radius: 2px; vertical-align: 0; }

/* ---------------- Botones ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px; border-radius: 999px; cursor: pointer;
  border: 1.5px solid var(--ink); background: var(--surface); color: var(--ink); font-weight: 600;
  text-decoration: none;
}
.btn:hover { background: #f4f6f8; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #2b3644; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; padding-inline: 10px; }
.btn-quiet:hover { background: rgba(24, 32, 43, .06); }
.btn-wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: progress; }
.link { display: inline; border: 0; background: none; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: .95rem; }
.link:hover { text-decoration-thickness: 2px; }

/* ---------------- Pantallas ---------------- */
main { max-width: var(--max); margin: 0 auto; padding: 32px var(--gutter) 64px; }
.screen h1 { font-family: var(--font-display); font-weight: 500; letter-spacing: -.01em; line-height: 1.1; font-size: clamp(2rem, 1.4rem + 2.2vw, 2.9rem); }
.screen h1:focus { outline: none; box-shadow: none; }
.screen-head { margin-bottom: 28px; display: grid; gap: 10px; }
.screen-foot { margin-top: 28px; display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }

/* Empezar */
.screen-start { display: grid; gap: 48px; align-items: start; }
@media (min-width: 1040px) { .screen-start { grid-template-columns: minmax(0, 1fr) minmax(0, 520px); gap: 64px; } }
.start-copy { display: grid; gap: 20px; max-width: 640px; }
.start-copy h1 { font-size: clamp(2.3rem, 1.5rem + 3vw, 3.6rem); }
.options-title { font-size: 1.05rem; font-weight: 700; margin-top: 8px; }
.options { display: grid; gap: 10px; }
.option {
  display: grid; grid-template-columns: 48px 1fr; gap: 16px; align-items: center; text-align: left;
  width: 100%; padding: 16px 18px; border: 1.5px solid var(--line); border-radius: var(--radius-ui);
  background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.option:hover { border-color: var(--ink); }
.option:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--marker); }
.option.dragover { border-color: var(--ink); background: var(--marker-soft); }
.option-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 8px; background: var(--desk); }
.option-icon svg { width: 26px; height: 26px; }
.option-body { display: grid; gap: 2px; }
.option-title { font-weight: 700; font-size: 1.08rem; }
.option-desc { color: var(--ink-2); font-size: .97rem; }
.drop-hint, .privacy { font-size: .9rem; color: var(--muted); }
.help { border-top: 1px solid var(--line); padding-top: 14px; }
.help summary { cursor: pointer; font-weight: 600; }
.help ol { margin: 10px 0 0; padding-left: 22px; color: var(--ink-2); display: grid; gap: 4px; }

.draft { background: var(--surface); border: 1.5px solid var(--ink); border-radius: var(--radius-ui); padding: 14px 16px; display: grid; gap: 10px; }
.draft-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.busy { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: var(--radius-ui); background: var(--surface); border: 1.5px solid var(--line); }
.busy-title { font-weight: 700; }
.busy-step { color: var(--muted); font-size: .95rem; }
.spinner { width: 22px; height: 22px; flex: none; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--ink); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.start-sheets { margin: 0; position: relative; padding: 0 0 40px 40px; display: none; }
@media (min-width: 1040px) { .start-sheets { display: block; } }
.start-sheets figcaption { position: absolute; bottom: 0; left: 40px; font-size: .9rem; color: var(--muted); }
.sheet-back { position: absolute; top: 34px; left: 0; width: 82%; opacity: .9; }
.sheet-front { position: relative; margin-left: auto; width: 88%; }

/* Hoja: iframe a tamaño A4 real, escalado para encajar. */
.sheet-frame, .preview { position: relative; min-width: 0; width: 100%; }
.sheet { background: #fff; box-shadow: var(--shadow-sheet); border-radius: var(--radius-sheet); overflow: hidden; position: relative; width: 100%; aspect-ratio: 210 / 297; }
/* El iframe va fuera del flujo para que su ancho real (794 px) no ensanche la columna. */
.sheet iframe { position: absolute; top: 0; left: 0; border: 0; width: 794px; transform-origin: 0 0; display: block; background: #fff; pointer-events: none; }
.preview .sheet iframe { pointer-events: auto; }
.tpl .sheet iframe { pointer-events: none; }
.preview-empty { aspect-ratio: 210 / 297; background: #fff; box-shadow: var(--shadow-sheet); display: grid; place-items: center; padding: 32px; text-align: center; color: var(--muted); }
.preview-status { position: absolute; top: 10px; right: 10px; z-index: 2; font-size: .8rem; background: var(--ink); color: #fff; padding: 2px 8px; border-radius: 999px; }

/* Pantallas divididas: trabajo a la izquierda, hoja a la derecha. */
.screen-split { display: grid; gap: 32px; align-items: start; }
@media (min-width: 1040px) {
  .screen-split { grid-template-columns: minmax(0, 1fr) minmax(0, 500px); gap: 48px; }
  .pane-preview { position: sticky; top: 92px; }
  .screen-download { grid-template-columns: minmax(0, 1fr) minmax(0, 420px); }
}
.pane { min-width: 0; }
.pane-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.inline-field { display: grid; gap: 4px; font-size: .88rem; color: var(--muted); }
.inline-field select { min-height: 40px; padding: 6px 10px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.pane-foot { margin-top: 24px; display: flex; justify-content: flex-end; }

/* Entrevista */
.sections { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.sections li { font-size: .85rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); background: var(--surface); }
.sections li.done { color: var(--ink-2); border-color: var(--ink-2); }
.sections li[aria-current="step"] { background: var(--marker); border-color: #c9b22f; color: var(--ink); font-weight: 700; }
.chat { display: grid; gap: 14px; padding: 4px 0 16px; max-height: min(56vh, 620px); overflow-y: auto; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { .chat { scroll-behavior: auto; } .spinner { animation-duration: 2.4s; } }
.msg { max-width: 62ch; white-space: pre-wrap; }
.msg-assistant { font-size: 1.08rem; color: var(--ink); padding-left: 14px; border-left: 3px solid var(--marker); }
.msg-user { justify-self: end; background: var(--surface); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; padding: 10px 14px; color: var(--ink-2); }
.msg-skip { font-style: italic; color: var(--muted); }
.msg-typing { color: var(--muted); padding-left: 14px; border-left: 3px solid var(--line); }
.composer { display: grid; gap: 10px; background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius-ui); padding: 12px; }
.composer:focus-within { border-color: var(--ink); }
.composer textarea { width: 100%; border: 0; resize: vertical; min-height: 72px; background: transparent; padding: 4px; }
.composer textarea:focus { outline: none; box-shadow: none; }
.composer-actions { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.composer-done { display: grid; gap: 10px; justify-items: start; }

/* Revisar */
.marker-note { background: var(--marker-soft); border-left: 4px solid var(--marker); padding: 12px 14px; border-radius: 0 8px 8px 0; margin-bottom: 14px; color: var(--ink); }
.review-tools { display: flex; justify-content: flex-end; margin: -6px 0 10px; }
.editor { display: grid; gap: 12px; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-ui); }
.group > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 700; font-size: 1.05rem; }
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--ink-2); border-bottom: 2px solid var(--ink-2); transform: rotate(45deg); transition: transform .15s; flex: none; margin-right: 4px; }
.group[open] > summary::after { transform: rotate(-135deg); }
.group .count { font-weight: 400; color: var(--muted); font-size: .9rem; margin-left: auto; }
.group-body { padding: 4px 16px 16px; display: grid; gap: 14px; }
.grid-2 { display: grid; gap: 12px; }
@media (min-width: 560px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.field { display: grid; gap: 4px; align-content: start; }
.field input:disabled { background: var(--desk); color: var(--muted); border-style: dashed; }
.field > span { font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--muted); font-size: .82rem; }
.field input, .field textarea, .field select {
  width: 100%; min-height: 42px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px; background: #fff;
}
.field textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
.field input:focus, .field textarea:focus { border-color: var(--ink); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.check-field { display: flex; gap: 8px; align-items: center; font-size: .92rem; color: var(--ink-2); }
.check-field input { width: 18px; height: 18px; accent-color: var(--ink); }
.item { border: 1px solid var(--line-soft); border-radius: 8px; padding: 12px; display: grid; gap: 12px; background: #fbfcfd; }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.editor > *, .group-body > *, .item > * { min-width: 0; }
.item-title { flex: 1; min-width: 0; font-weight: 700; color: var(--ink-2); font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tools { display: flex; gap: 2px; flex: none; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.icon-btn:hover { background: var(--desk); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }
.add-btn { justify-self: start; border: 1.5px dashed var(--line); background: none; border-radius: 8px; padding: 8px 14px; cursor: pointer; color: var(--ink-2); font-weight: 600; }
.add-btn:hover { border-color: var(--ink); color: var(--ink); }

/* Plantillas */
.template-grid { display: grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.tpl { min-width: 0; display: grid; gap: 12px; text-align: left; padding: 14px; border: 2px solid transparent; border-radius: 14px; background: transparent; cursor: pointer; }
.tpl:hover { background: rgba(255, 255, 255, .55); }
.tpl[aria-checked="true"] { border-color: var(--ink); background: var(--surface); }
.tpl-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tpl-name { font-family: var(--font-display); font-size: 1.45rem; font-weight: 500; }
.tpl-desc { color: var(--ink-2); font-size: .95rem; }
.badge { font-size: .78rem; font-weight: 700; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); white-space: nowrap; }
.badge-premium { background: var(--ink); color: var(--marker); border-color: var(--ink); }
.tpl[aria-checked="true"] .tpl-pick { display: inline-flex; }
.tpl-pick { display: none; align-items: center; gap: 6px; font-weight: 700; font-size: .9rem; }
.tpl-pick::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--marker); border: 2px solid var(--ink); }

/* Descargar */
.pane-side { display: grid; gap: 22px; align-content: start; }
.actions { display: grid; gap: 10px; }
.hint { font-size: .88rem; color: var(--muted); }
.more-exports { display: grid; gap: 8px; justify-items: start; padding-top: 6px; }
.check { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-ui); padding: 18px; display: grid; gap: 14px; }
.check h2 { font-size: 1.05rem; }
.verdict { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.verdict-text { font-family: var(--font-display); font-size: 1.7rem; font-weight: 500; line-height: 1.1; }
.verdict-score { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 99px; background: var(--desk); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ink); border-radius: 99px; }
.issues, .passed { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.issue { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: .94rem; }
.issue-tag { font-size: .75rem; font-weight: 700; padding: 1px 7px; border-radius: 4px; align-self: start; margin-top: 2px; }
.issue-error .issue-tag { background: #fde7e5; color: var(--danger); }
.issue-warn .issue-tag { background: var(--marker-soft); color: var(--warn); }
.issue-tip .issue-tag { background: var(--desk); color: var(--ink-2); }
.issue .link { grid-column: 2; justify-self: start; font-size: .88rem; }
.passed li { font-size: .92rem; color: var(--ink-2); padding-left: 22px; position: relative; }
.passed li::before { content: ""; position: absolute; left: 2px; top: .38em; width: 10px; height: 6px; border-left: 2px solid var(--ok); border-bottom: 2px solid var(--ok); transform: rotate(-45deg); }
.check-sub { font-size: .9rem; font-weight: 700; color: var(--ink-2); }

/* Aviso flotante */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; max-width: min(92vw, 560px); box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.error { background: var(--danger); }

/* Móvil: los pasos muestran solo el número salvo el actual (el texto sigue disponible para lectores de pantalla). */
@media (max-width: 559px) {
  .steps button:not([aria-current]) .lbl { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .bar-inner { flex-wrap: nowrap; }
}

/* Foto en el editor */
.photo-field { display: grid; grid-template-columns: 76px 1fr; gap: 14px; align-items: start; padding-bottom: 4px; }
.photo-thumb { width: 76px; height: 95px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--desk); }
.photo-empty { display: grid; place-items: center; font-size: .78rem; color: var(--muted); text-align: center; border-style: dashed; }
.photo-body { display: grid; gap: 4px; min-width: 0; }
.photo-label { font-size: .88rem; font-weight: 600; color: var(--ink-2); }
.photo-hint { font-size: .85rem; color: var(--muted); }
.photo-actions { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 4px; }
.btn-small { min-height: 36px; padding: 6px 14px; font-size: .92rem; }
.btn-small.btn-quiet { padding-inline: 8px; }
label.btn:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; box-shadow: 0 0 0 6px var(--marker); }
.tpl-note { font-size: .88rem; color: var(--muted); margin-top: -4px; }

/* Diálogo de encuadre */
.crop { border: 0; padding: 0; border-radius: 14px; width: min(92vw, 400px); background: var(--surface); color: var(--ink); box-shadow: 0 24px 64px rgba(24, 32, 43, .3); }
.crop::backdrop { background: rgba(24, 32, 43, .55); }
.crop-inner { padding: 20px; display: grid; gap: 14px; }
.crop h2 { font-family: var(--font-display); font-weight: 500; font-size: 1.6rem; line-height: 1.1; }
.crop-stage { justify-self: center; width: min(100%, 300px); }
.crop-stage canvas { display: block; width: 100%; aspect-ratio: 4 / 5; border-radius: 6px; cursor: grab; touch-action: none; background: var(--desk); box-shadow: 0 0 0 1px var(--line); }
.crop-stage canvas.dragging { cursor: grabbing; }
.crop-zoom { display: grid; gap: 4px; font-size: .9rem; font-weight: 600; color: var(--ink-2); }
.crop-zoom input { width: 100%; accent-color: var(--ink); }
.crop-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* PDF preparado para IA: un solo recorrido en tres estados (descargar, elegir el guardado y listo) */
.pdf-flow { display: grid; gap: 10px; margin-bottom: 6px; padding: 16px; border-radius: var(--radius-ui); background: var(--surface); border: 1px solid var(--line); }
.ai-ready { justify-self: start; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--marker-soft); font-size: .85rem; font-weight: 700; }
.ai-ready svg, .done-title svg { display: block; width: 16px; height: 16px; }
.pdf-step { display: grid; gap: 8px; }
.pdf-step[hidden] { display: none; }
.pdf-step-next { padding: 10px 0 2px 12px; box-shadow: inset 4px 0 0 var(--marker); }
.step-count { font-size: .85rem; font-weight: 600; color: var(--muted); }
.done-title { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ok); }
.save-title { font-weight: 700; }
label.btn { cursor: pointer; }
.pdf-status { font-size: .92rem; background: var(--marker-soft); border-radius: 8px; padding: 8px 10px; }
