:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #dde3e8;
  --border-strong: #c3ccd4;
  --text: #17212b;
  --muted: #5b6875;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e2f3f1;
  --accent-text: #ffffff;
  --err: #b42318;
  --err-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fff4e0;
  --info: #175cd3;
  --info-soft: #e8f0fd;
  --ok: #067647;
  --code-bg: #0f1720;
  --code-text: #dbe4ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1217;
    --surface: #151c23;
    --surface-2: #1a232c;
    --border: #2a3540;
    --border-strong: #3a4754;
    --text: #e6edf3;
    --muted: #94a3b2;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-soft: #123a37;
    --accent-text: #04201d;
    --err: #f97066;
    --err-soft: #3a1714;
    --warn: #fdb022;
    --warn-soft: #362408;
    --info: #84adff;
    --info-soft: #14244a;
    --ok: #47cd89;
    --code-bg: #0a0f14;
    --code-text: #d5dee7;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1217;
  --surface: #151c23;
  --surface-2: #1a232c;
  --border: #2a3540;
  --border-strong: #3a4754;
  --text: #e6edf3;
  --muted: #94a3b2;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-soft: #123a37;
  --accent-text: #04201d;
  --err: #f97066;
  --err-soft: #3a1714;
  --warn: #fdb022;
  --warn-soft: #362408;
  --info: #84adff;
  --info-soft: #14244a;
  --ok: #47cd89;
  --code-bg: #0a0f14;
  --code-text: #d5dee7;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  overflow-x: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .9em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 16px; }

/* ---------- Cabecera ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand h1 { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.tagline { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.icon { width: 36px; padding: 0; }
.btn.icon svg { width: 18px; height: 18px; }
.btn.small { min-height: 28px; padding: 3px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.preset select { min-height: 36px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); padding: 6px 10px; max-width: 220px; }

/* ---------- Pasos ---------- */
.steps {
  display: flex; gap: 6px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: thin; position: sticky; top: 0; z-index: 10;
}
.step {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 7px 12px; border-radius: 8px; border: 1px solid transparent; background: transparent; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 14px;
}
.step:hover { background: var(--surface-2); color: var(--text); }
.step[aria-current="page"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.step .num { font-family: var(--mono); font-size: 12px; opacity: .8; }
.step .badge { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); font-variant-numeric: tabular-nums; }
.step[aria-current="page"] .badge { background: var(--surface); }
.step .dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.error { background: var(--err); }
.dot.warn { background: var(--warn); }

/* ---------- Disposición ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; padding: 24px; max-width: 1440px; margin: 0 auto; align-items: start; }
main { min-width: 0; }
main:focus { outline: none; }
aside { position: sticky; top: 68px; display: flex; flex-direction: column; gap: 16px; max-height: calc(100vh - 88px); overflow-y: auto; }

.view-head { margin-bottom: 18px; }
.view-head .eyebrow { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.view-head h2 { font-size: 24px; margin-top: 2px; letter-spacing: -.015em; }
.view-head p { color: var(--muted); margin-top: 6px; max-width: 72ch; }
.view-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 16px; }
.panel h3 { font-size: 15px; }

/* ---------- Preguntas ---------- */
.questions { display: grid; gap: 16px; }
.q { padding: 16px; }
.q-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.q-title { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.q-n { font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 7px; border-radius: 6px; flex: none; }
.q-title h3 { font-size: 16px; }
.q-help { color: var(--muted); font-size: 13px; margin-top: 2px; }
.q-tools { display: flex; align-items: center; gap: 6px; }
.q-count { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 4px; }

.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.opt {
  position: relative; display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); cursor: pointer;
  transition: border-color .12s, background .12s;
}
.opt:hover { border-color: var(--border-strong); }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.opt-body { min-width: 0; }
.opt-label { font-weight: 600; font-size: 14px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.opt-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.tag { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 4px; border: 1px solid var(--border-strong); color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.equiv { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 3px; }
.equiv li { font-size: 12px; color: var(--muted); display: flex; gap: 6px; }
.equiv b { color: var(--text); font-weight: 600; flex: none; min-width: 64px; }

/* ---------- Formulario ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 13px; font-weight: 600; }
.field input, .field select {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface);
}
.field input[aria-invalid="true"] { border-color: var(--err); background: var(--err-soft); }
.field .hint { font-size: 12px; color: var(--muted); }
.form-section + .form-section { margin-top: 16px; }
.form-section h3 { margin-bottom: 12px; }

.secrets { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; margin-top: 12px; }
.secret { display: flex; justify-content: space-between; gap: 8px; align-items: center; font-size: 13px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); min-width: 0; }
.secret code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }

/* ---------- Lateral ---------- */
.side-block { padding: 14px 16px; }
.side-block h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 10px; }
.progress-list { display: grid; gap: 9px; }
.prog { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 13px; }
.prog .bar { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.prog .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.prog .val { color: var(--muted); font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.diag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.diag { border-radius: 8px; padding: 8px 10px; font-size: 13px; border: 1px solid transparent; }
.diag.error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.diag.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.diag.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.diag-kind { font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.diag.error .diag-kind { color: var(--err); }
.diag.warn .diag-kind { color: var(--warn); }
.diag.info .diag-kind { color: var(--info); }
.diag .btn { margin-top: 6px; }
.all-ok { color: var(--ok); font-weight: 600; font-size: 14px; }

/* ---------- Resultado ---------- */
.result { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.files { padding: 10px; max-height: 72vh; overflow: auto; }
.files input { width: 100%; min-height: 34px; padding: 6px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); margin-bottom: 8px; }
.folder { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 8px 6px 4px; }
.file-btn { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 5px 8px; border-radius: 6px; font-family: var(--mono); font-size: 13px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-btn:hover { background: var(--surface-2); }
.file-btn[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.viewer { overflow: hidden; display: flex; flex-direction: column; min-width: 0; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.viewer-bar code { font-weight: 600; word-break: break-all; }
.viewer-bar .meta { color: var(--muted); font-size: 12px; }
.viewer pre { margin: 0; padding: 14px 16px; background: var(--code-bg); color: var(--code-text); font: 13px/1.55 var(--mono); overflow: auto; max-height: 68vh; tab-size: 4; border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- Matriz ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); font-weight: 700; position: sticky; top: 0; }
td.n { font-family: var(--mono); color: var(--accent); font-weight: 700; white-space: nowrap; }
td.none { color: var(--muted); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Pie y avisos ---------- */
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 8px 24px 32px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; transition: .2s; max-width: calc(100vw - 32px); z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.noscript { padding: 24px; text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  aside { position: static; max-height: none; overflow: visible; }
  .result { grid-template-columns: minmax(0, 1fr); }
  .files { max-height: 260px; }
}
@media (max-width: 640px) {
  .topbar, .steps { padding-left: 16px; padding-right: 16px; }
  .layout { padding: 16px; gap: 16px; }
  .top-actions { width: 100%; }
  .top-actions .btn.primary { flex: 1; }
  .preset select { max-width: 150px; }
  .view-head h2 { font-size: 20px; }
  .opts { grid-template-columns: minmax(0, 1fr); }
  .tagline { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
