/* Calculadora de préstamos — móvil primero.
   Amarillo suave = datos · Verde = resultados · Naranja = carencia */
:root {
  --ink: #1C2421;
  --muted: #56625D;
  --bg: #F4F5F1;
  --card: #FFFFFF;
  --line: #DFE3DC;

  --dato-bg: #FFF8D9;
  --dato-line: #E9D27A;
  --dato-focus: #C79A00;

  --ok: #1E7A46;
  --ok-deep: #145C33;
  --ok-bg: #E6F3EA;
  --ok-line: #BFDDC9;

  --car: #B85512;
  --car-bg: #FFE9D4;
  --car-line: #F4C59A;

  --err: #B3261E;
  --err-bg: #FDECEA;

  --sans: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --math: "STIX Two Text", "Cambria Math", "Times New Roman", serif;
  --r: 14px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body { margin: 0; font-family: var(--sans); font-size: 1rem; line-height: 1.5; color: var(--ink); background: var(--bg); }
h1, h2, h3 { margin: 0; line-height: 1.15; }
p { margin: 0; }
a { color: var(--ok-deep); }
button, input, select { font: inherit; color: inherit; }
svg { flex: none; }
:focus-visible { outline: 3px solid var(--dato-focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.show-sm { display: none; }
.skip { position: absolute; left: 12px; top: -60px; z-index: 99; padding: 10px 14px; border-radius: 10px; background: var(--ink); color: #fff; }
.skip:focus { top: 12px; }
[hidden] { display: none !important; }

/* Barra superior */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px clamp(12px, 3vw, 24px); background: var(--ok-deep); color: #fff;
}
.bar__brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; }
.bar__brand svg { width: 28px; height: 28px; fill: #FFE98A; }
.bar__actions { display: flex; gap: 4px; }
.iconbtn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px; justify-content: center; padding: 8px 12px;
  border: 0; border-radius: 10px; background: transparent; color: inherit; font-weight: 600; cursor: pointer;
}
.iconbtn:hover { background: rgba(255,255,255,.12); }
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn--plain { color: var(--ink); }
.iconbtn--plain:hover { background: var(--bg); }
.bar :focus-visible { outline-color: #FFE98A; }
@media (max-width: 520px) { .hide-sm { display: none; } .show-sm { display: inline; } .bar__brand span { font-size: .98rem; } }

.app { max-width: 980px; margin: 0 auto; padding: 20px clamp(12px, 3vw, 24px) 48px; display: grid; gap: 18px; }
.app:focus { outline: none; }
.app > *, .bloque > *, .resultado > * { min-width: 0; }

/* Inicio */
.hero h1 { font-size: clamp(1.8rem, 6vw, 2.6rem); letter-spacing: -.02em; }
.lead { margin-top: 10px; color: var(--muted); max-width: 60ch; font-size: 1.05rem; }
.lead--sm { margin-top: 4px; font-size: 1rem; }
.tipos { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .tipos { grid-template-columns: 1fr 1fr; } }
.tipo {
  display: flex; align-items: center; gap: 14px; min-height: 76px; padding: 14px 14px 14px 16px;
  border-radius: var(--r); background: var(--card); border: 1px solid var(--line); color: var(--ink); text-decoration: none;
  transition: border-color .15s, transform .15s var(--ease), box-shadow .15s;
}
.tipo:hover { border-color: var(--ok); box-shadow: 0 6px 20px -12px rgba(20,92,51,.5); transform: translateY(-1px); }
.tipo__txt { display: grid; flex: 1; min-width: 0; }
.tipo__frase { font-weight: 600; font-size: 1.02rem; }
.tipo__nombre { color: var(--ok-deep); font-weight: 700; font-size: .95rem; }
.tipo__nombre::before { content: "→ "; }
.tipo__go { width: 22px; height: 22px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.mini { width: 56px; height: 32px; flex: none; }
.mini rect { fill: var(--ok); }
.mini .mini__c { fill: var(--car); }
.mini .mini__g { fill: var(--dato-focus); }

/* Datos */
.crumb a { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; font-weight: 600; text-decoration: none; }
.crumb svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.datos { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: clamp(16px, 3vw, 24px); }
.datos__head { display: flex; gap: 14px; align-items: center; margin-bottom: 18px; }
.datos__head h1 { font-size: clamp(1.6rem, 5vw, 2.1rem); }
.form__grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .form__grid { grid-template-columns: 1fr 1fr; } }
.form__grid--ofertas { grid-template-columns: 1fr; }
.f { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.f--wide, .f--radios, .f[data-campo$="euribor"] { grid-column: 1 / -1; }
.f label, .f legend { font-weight: 600; padding: 0; }
.f__in { position: relative; display: flex; }
.f input, .f select, .q input, .buscar input {
  width: 100%; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--dato-line); background: var(--dato-bg); font-size: 1.05rem; font-variant-numeric: tabular-nums;
}
.f select { padding-right: 36px; }
.f__in--suf input { padding-right: 56px; }
.f__in--suf > span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.f input:focus-visible, .f select:focus-visible, .q input:focus-visible, .buscar input:focus-visible { outline: 3px solid var(--dato-focus); outline-offset: 0; border-color: var(--dato-focus); }
.f [aria-invalid="true"] { border-color: var(--err); background: var(--err-bg); }
.f__help { font-size: .92rem; color: var(--muted); }
.f__err { font-size: .92rem; color: var(--err); font-weight: 600; }
.quedan { display: inline-flex; align-items: center; gap: 6px; font-weight: 500 !important; }
.quedan input { width: 70px; min-height: 36px; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--dato-line); background: var(--dato-bg); }

.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { position: relative; }
.seg input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border-radius: 10px; border: 1.5px solid var(--dato-line); background: var(--dato-bg); font-weight: 500; }
.seg input:checked + span { background: var(--ok-deep); border-color: var(--ok-deep); color: #fff; font-weight: 600; }
.seg input:focus-visible + span { outline: 3px solid var(--dato-focus); outline-offset: 2px; }

.eur { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.eur__i { display: grid; gap: 4px; font-weight: 500 !important; font-size: .92rem; color: var(--muted); }
.eur__i .f__in { display: flex; }

.form__msg { margin-top: 12px; color: var(--err); font-weight: 600; min-height: 1.2em; }
.form__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.ofertas { display: grid; gap: 14px; }
.oferta { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--r); background: #FCFDFB; }
.oferta__head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.oferta__head select { flex: 1 1 170px; min-width: 0; }
.oferta__nombre, .oferta__head select { min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; }
.oferta__nombre { flex: 1 1 140px; min-width: 0; }
.btn--add { justify-self: start; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1.5px solid transparent;
  font-weight: 700; text-decoration: none; cursor: pointer; transition: background-color .15s, border-color .15s;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn--primary { background: var(--ok-deep); color: #fff; }
.btn--primary:hover { background: #0F4727; }
.btn--ghost { background: var(--card); border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { border-color: var(--ok); background: var(--ok-bg); }
.btn--sm { min-height: 44px; padding: 8px 12px; font-size: .92rem; }
.link { border: 0; background: none; padding: 8px 0; color: var(--ok-deep); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: 40px; }

/* Resultado */
.resultado { background: var(--ok-bg); border: 1px solid var(--ok-line); border-radius: 18px; padding: clamp(16px, 3vw, 24px); }
.res-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.resultado h2, .bloque h2 { font-size: 1.4rem; }
.resultado h2 { color: var(--ok-deep); }
h2:focus { outline: none; }
.acciones { display: flex; flex-wrap: wrap; gap: 6px; }
.res-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.res-card { background: var(--card); border-radius: 12px; padding: 12px 14px; border: 1px solid var(--ok-line); }
.res-card__k { font-size: .9rem; color: var(--muted); font-weight: 600; }
.res-card__v { font-size: 1.4rem; font-weight: 700; color: var(--ok-deep); font-variant-numeric: tabular-nums; line-height: 1.25; margin-top: 2px; overflow-wrap: anywhere; }
.res-card__s { font-size: .85rem; color: var(--muted); margin-top: 2px; }
.veredicto { font-size: 1.1rem; margin-bottom: 12px; }

.bloque { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: clamp(16px, 3vw, 24px); }
.bloque > h2 { margin-bottom: 14px; }

/* Paso a paso */
.pasos { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.paso { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: #FBFCFA; display: grid; gap: 6px; align-content: start; }
.paso__t { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .95rem; color: var(--muted); }
.paso__n { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--ok-deep); color: #fff; font-size: .8rem; flex: none; }
.paso__f { font-family: var(--math); font-style: italic; font-size: 1.35rem; line-height: 1.35; color: var(--ink); overflow-wrap: anywhere; }
.paso__s { font-variant-numeric: tabular-nums; color: var(--muted); overflow-wrap: anywhere; }
.paso__r { font-weight: 700; color: var(--ok-deep); font-size: 1.1rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.paso sup, .paso sub { font-size: .7em; line-height: 0; }

/* Preguntas */
.buscar { display: flex; gap: 8px; }
.buscar input { flex: 1; min-width: 0; }
.respuesta:not(:empty) { margin-top: 12px; padding: 14px; border-radius: 12px; background: var(--ok-bg); border: 1px solid var(--ok-line); }
.qgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin-top: 16px; }
.q { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: #FBFCFA; display: grid; gap: 8px; align-content: start; }
.q label { font-weight: 600; font-size: .95rem; }
.q__row { display: flex; gap: 8px; }
.q__row input { flex: 1; min-width: 0; }
.q__mini { width: 56px !important; min-height: 36px !important; padding: 4px 8px !important; display: inline-block; }
.q--car { border-color: var(--car-line); background: #FFF7EF; }
.q__out:empty { display: none; }
.q__exp { font-size: .9rem; color: var(--muted); font-style: italic; }
.q__ctx { font-weight: 600; font-size: .92rem; margin-top: 2px; }
.q__err { color: var(--err); font-weight: 600; }
.kvs { display: grid; gap: 4px; margin-top: 6px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; border-radius: 8px; background: rgba(255,255,255,.7); }
.kv span { color: var(--muted); font-size: .92rem; }
.kv strong { font-variant-numeric: tabular-nums; white-space: nowrap; }
.kv--hit { background: var(--ok-deep); }
.kv--hit span, .kv--hit strong { color: #fff; }
.tag-car { color: var(--car); }

/* Cuadro */
.leyenda { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--muted); font-size: .92rem; }
.leyenda__c { width: 16px; height: 16px; border-radius: 4px; background: var(--car-bg); border: 1px solid var(--car-line); }
.tabla-wrap { max-height: min(70vh, 640px); overflow: auto; border-radius: 12px; border: 1px solid var(--line); }
.tabla-wrap:focus-visible { outline: 3px solid var(--dato-focus); }
.tabla { width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; font-size: .95rem; }
.tabla th, .tabla td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
.tabla th:first-child, .tabla td:first-child, .tabla td:nth-child(2) { text-align: left; }
.tabla thead th { position: sticky; top: 0; z-index: 2; background: var(--ok-deep); color: #fff; font-weight: 600; font-size: .88rem; }
.tabla tfoot th, .tabla tfoot td { position: sticky; bottom: 0; background: var(--ok-bg); font-weight: 700; color: var(--ok-deep); border-top: 2px solid var(--ok); }
.tabla tfoot th { text-align: left; }
.tabla tbody tr:nth-child(even):not(.sep):not(.fila-car) td { background: #FAFBF8; }
.tabla .sep th { text-align: left; padding: 6px 12px; background: #EEF1EB; color: var(--muted); font-size: .82rem; font-weight: 700; letter-spacing: .02em; }
.tabla .fila-car td { background: var(--car-bg); color: #6E3209; }
.tabla .fila-car td:first-child { box-shadow: inset 4px 0 0 var(--car); }
.tabla .fila-ant td { background: #FFF4C2; font-weight: 600; }
.tabla .fila-0 td { color: var(--muted); }
.tabla tr.is-hit td { background: var(--ok-deep) !important; color: #fff !important; }
.tabla--cmp th[scope=row] { text-align: left; }
.tabla--cmp tr.mejor td, .tabla--cmp tr.mejor th { background: var(--ok-bg); font-weight: 700; }
.chip { display: inline-block; margin-left: 6px; padding: 2px 8px; border-radius: 999px; background: var(--ok-deep); color: #fff; font-size: .75rem; font-weight: 700; vertical-align: middle; }

.det summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.det summary::before { content: "▸"; color: var(--ok-deep); transition: transform .15s; }
.det[open] summary::before { transform: rotate(90deg); }
.det summary h2 { font-size: 1.15rem; }
.det[open] > *:not(summary) { margin-top: 14px; }

/* Pie y diálogos */
.foot { max-width: 980px; margin: 0 auto; padding: 8px clamp(12px, 3vw, 24px) 40px; color: var(--muted); font-size: .92rem; display: grid; gap: 4px; }
.foot strong { color: var(--ink); }
.dlg { width: min(480px, calc(100vw - 24px)); padding: 0; border: 0; border-radius: 18px; color: var(--ink); box-shadow: 0 30px 80px -20px rgba(0,0,0,.4); }
.dlg::backdrop { background: rgba(20,40,30,.45); }
.dlg__in { padding: 20px; display: grid; gap: 16px; }
.dlg__head { display: flex; justify-content: space-between; align-items: center; }
.dlg__head h2 { font-size: 1.3rem; }
.dlg__foot { display: flex; justify-content: flex-end; }
.opt { margin: 0; padding: 0; border: 0; display: grid; gap: 8px; }
.opt legend { font-weight: 700; margin-bottom: 6px; }
.radio { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; }
.radio input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--ok-deep); flex: none; }
.hist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 55vh; overflow: auto; }
.hist a { display: grid; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.hist a:hover { border-color: var(--ok); background: var(--ok-bg); }
.hist span { color: var(--muted); font-size: .92rem; }
.hist small { color: var(--muted); }
.hist__empty { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 24px); padding: 12px 18px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 600; box-shadow: 0 12px 30px -10px rgba(0,0,0,.5); }

@media (max-width: 520px) {
  .buscar { flex-direction: column; }
  .acciones .btn { flex: 1 1 auto; }
  .tabla th, .tabla td { padding: 8px 9px; font-size: .88rem; }
  .paso__f { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

/* Impresión / PDF */
@media print {
  body { background: #fff; font-size: 10.5pt; }
  .bar, .crumb, .form__actions, .acciones, .buscar, .qgrid, .respuesta, .foot a, .toast, .skip, .datos .f__help { display: none !important; }
  .app { padding: 0; max-width: none; gap: 10px; }
  .datos, .resultado, .bloque { border: 1px solid #ccc; border-radius: 6px; padding: 10px; break-inside: avoid-page; }
  .f input, .f select, .seg span { border: 0; background: none; padding: 0; min-height: 0; }
  .seg input:not(:checked) + span { display: none; }
  .seg input:checked + span { background: none; color: var(--ink); }
  .tabla-wrap { max-height: none; overflow: visible; border: 0; }
  .tabla thead th { position: static; background: #eee; color: #000; }
  .tabla tfoot th, .tabla tfoot td { position: static; }
  .tabla tr { break-inside: avoid; }
  .paso { break-inside: avoid; }
  .pasos { grid-template-columns: 1fr 1fr; }
  section:has(#t-preg) { display: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
