/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #17222b;
  --ink-soft: #4a5a66;
  --line: #e3e1d9;
  --accent: #4338ca;
  --accent-soft: #e6e8fb;
  --accent-ink: #ffffff;
  --warn: #a05a00;
  --warn-bg: #fdf3e3;
  --danger: #b3261e;
  --radius: 14px;
  --gutter: clamp(1rem, 4vw, 2rem);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Sora", var(--sans);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10181e;
    --surface: #182229;
    --ink: #edf2f4;
    --ink-soft: #9fb0ba;
    --line: #2a3740;
    --accent: #93a2f8;
    --accent-soft: #232a55;
    --accent-ink: #0c1033;
    --warn: #e5a54b;
    --warn-bg: #2b2211;
    --danger: #ff8a80;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; }
p { text-wrap: pretty; }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; line-height: 1.12; letter-spacing: -0.02em; }
::selection { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.skip-link {
  position: fixed; top: -100px; left: 1rem;
  padding: .6rem 1rem; background: var(--surface); color: var(--ink);
  z-index: 9999; border-radius: 8px; font-weight: 600; text-decoration: none;
  box-shadow: 0 4px 18px rgba(0,0,0,.18);
}
.skip-link:focus { top: 1rem; }

.container { max-width: 1060px; margin-inline: auto; padding-inline: var(--gutter); }

/* =============================================================
   3. Header / footer
   ============================================================= */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .9rem var(--gutter);
  max-width: 1060px; margin-inline: auto;
}
.logo { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 700; font-size: 1.06rem; text-decoration: none; }
.logo svg { width: 26px; height: 26px; }
.logo span em { font-style: normal; color: var(--accent); }
.header-nav a {
  text-decoration: none; font-weight: 600; font-size: .92rem; color: var(--ink-soft);
  padding: .45rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  transition: color .25s var(--ease-out), border-color .25s var(--ease-out);
}
.header-nav a:hover { color: var(--accent); border-color: var(--accent); }

.site-footer {
  border-top: 1px solid var(--line);
  margin-top: 4rem; padding: 2rem var(--gutter) 2.6rem;
  font-size: .88rem; color: var(--ink-soft);
}
.site-footer .container { display: grid; gap: .8rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 1.1rem; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }

/* =============================================================
   4. Hero / intro
   ============================================================= */
.tool-hero { padding: 1.6rem 0 1.1rem; }
.tool-hero h1 { font-size: clamp(1.55rem, 4.6vw, 2.4rem); max-width: 21ch; }
.tool-hero .sub { margin-top: .5rem; color: var(--ink-soft); max-width: 58ch; font-size: 1.02rem; }
.independence-note {
  display: inline-flex; align-items: flex-start; gap: .45rem;
  margin-top: .8rem; padding: .5rem .85rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  font-size: .82rem; color: var(--ink-soft); max-width: 64ch;
}
.independence-note svg { flex: 0 0 auto; margin-top: .2rem; }

/* =============================================================
   5. Tool card
   ============================================================= */
.tool-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(1.1rem, 3vw, 1.7rem);
  box-shadow: 0 10px 34px rgba(23, 34, 43, .06);
}
.tool-form { display: grid; gap: 1rem; }
.field { display: grid; gap: .35rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .8rem; color: var(--ink-soft); }
.field input[type="number"], .field select {
  width: 100%; padding: .68rem .8rem;
  font: inherit; color: var(--ink);
  background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 10px;
  transition: border-color .2s var(--ease-out);
}
.field input:focus, .field select:focus { border-color: var(--accent); outline: none; }
.field-row { display: grid; gap: 1rem; }
.plazo-wrap { display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.plazo-wrap select { width: auto; }

.segmented { display: inline-flex; background: var(--bg); border: 1.5px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px; }
.segmented button {
  padding: .42rem 1rem; border-radius: 999px; font-weight: 600; font-size: .88rem; color: var(--ink-soft);
  transition: background .2s var(--ease-out), color .2s var(--ease-out);
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 1.02rem;
  padding: .85rem 1.6rem; border-radius: 12px;
  transition: transform .2s var(--ease-out), filter .2s var(--ease-out);
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-secondary {
  display: inline-flex; align-items: center; gap: .45rem;
  font-weight: 600; font-size: .9rem; color: var(--accent);
  padding: .55rem 1rem; border: 1.5px solid var(--accent); border-radius: 10px;
  text-decoration: none;
  transition: background .2s var(--ease-out), color .2s var(--ease-out);
}
.btn-secondary:hover { background: var(--accent); color: var(--accent-ink); }

.tool-note { display: flex; gap: .5rem; align-items: flex-start; font-size: .84rem; color: var(--ink-soft); margin-top: .9rem; }
.tool-note svg { flex: 0 0 auto; margin-top: .15rem; }

.tool-warning {
  margin-top: .6rem; padding: .6rem .85rem; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn); font-size: .86rem; font-weight: 500;
}
.tool-warning:empty { display: none; }

/* =============================================================
   6. Results
   ============================================================= */
.results { display: none; margin-top: 1.4rem; border-top: 1px dashed var(--line); padding-top: 1.3rem; }
.tool-card[data-state="done"] .results { display: block; }

.result-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.result-item { background: var(--bg); border-radius: 12px; padding: .85rem 1rem; }
.result-item .k { font-size: .78rem; font-weight: 600; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.result-item .v { font-family: var(--display); font-weight: 700; font-size: clamp(1.15rem, 3vw, 1.5rem); margin-top: .15rem; }
.result-item.highlight { background: var(--accent-soft); }
.result-item.highlight .v { color: var(--accent); }

.result-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin-top: 1.1rem; }

.chart-wrap { margin-top: 1.3rem; }
.chart-wrap canvas { width: 100%; height: auto; border-radius: 10px; }
.chart-legend { display: flex; gap: 1.2rem; font-size: .8rem; color: var(--ink-soft); margin-top: .4rem; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; }

/* Amortization table */
.amort-wrap { margin-top: 1.2rem; }
.amort-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; max-height: 420px; overflow-y: auto; }
table.amort { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 560px; }
table.amort th, table.amort td { padding: .5rem .75rem; text-align: right; white-space: nowrap; }
table.amort th:first-child, table.amort td:first-child { text-align: center; }
table.amort thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
table.amort tbody tr:nth-child(even) { background: color-mix(in srgb, var(--bg) 60%, transparent); }
table.amort tfoot td { font-weight: 700; border-top: 1px solid var(--line); background: var(--surface); position: sticky; bottom: 0; }
.amort-more { margin: .7rem auto 0; display: block; }

/* =============================================================
   7. Content sections
   ============================================================= */
.section { margin-top: 2.6rem; }
.section h2 { font-size: clamp(1.25rem, 3vw, 1.6rem); margin-bottom: .9rem; }
.section p + p { margin-top: .8rem; }
.section .prose { max-width: 70ch; color: var(--ink); }
.section .prose strong { color: var(--accent); }

.steps { display: grid; gap: 1rem; margin-top: 1rem; }
.step { display: flex; gap: .9rem; align-items: flex-start; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; }
.step .n {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: .9rem;
}
.step h3 { font-size: .98rem; margin-bottom: .15rem; }
.step p { font-size: .89rem; color: var(--ink-soft); }

/* FAQ */
.faq details {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: .9rem 1.1rem; margin-bottom: .7rem;
}
.faq summary { font-weight: 600; cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 1rem; align-items: center; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-family: var(--display); font-size: 1.2rem; color: var(--accent); transition: rotate .25s var(--ease-out); }
.faq details[open] summary::after { rotate: 45deg; }
.faq details p { margin-top: .6rem; color: var(--ink-soft); font-size: .93rem; }

/* Tool cross-links */
.tools-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-top: 1rem; }
.tool-link {
  display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.1rem;
  transition: border-color .25s var(--ease-out), transform .25s var(--ease-out);
}
.tool-link:hover { border-color: var(--accent); transform: translateY(-2px); }
.tool-link h3 { font-size: .97rem; color: var(--accent); margin-bottom: .2rem; }
.tool-link p { font-size: .85rem; color: var(--ink-soft); }

/* =============================================================
   8. Ad slots (placeholders — invariante 8)
   ============================================================= */
.ad-slot {
  margin-top: 2.2rem; min-height: 100px;
  display: grid; place-items: center;
  border: 1.5px dashed var(--line); border-radius: 12px;
  color: var(--ink-soft); font-size: .75rem; letter-spacing: .12em; text-transform: uppercase;
}

/* =============================================================
   9. Legal pages
   ============================================================= */
.legal { padding-top: 1.8rem; max-width: 72ch; }
.legal h1 { font-size: clamp(1.5rem, 4vw, 2rem); margin-bottom: 1rem; }
.legal h2 { font-size: 1.15rem; margin: 1.6rem 0 .5rem; }
.legal p, .legal li { color: var(--ink-soft); font-size: .95rem; }
.legal ul { padding-left: 1.2rem; }

/* =============================================================
   10. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .field-row { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 720px) {
  .tool-form { grid-template-columns: 1fr 1fr; align-items: end; }
  .tool-form .field-full, .tool-form .form-actions { grid-column: 1 / -1; }
  .steps { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 960px) {
  .tool-hero { padding-top: 2.4rem; }
}

/* =============================================================
   11. Print — la tabla imprime limpia
   ============================================================= */
@media print {
  .site-header, .site-footer, .ad-slot, .header-nav, .result-actions,
  .section, .tool-note, .tool-form, .skip-link, .amort-more, .chart-wrap { display: none !important; }
  body { background: #fff; color: #000; }
  .tool-card { border: 0; box-shadow: none; padding: 0; }
  .results { display: block !important; border: 0; }
  .amort-scroll { max-height: none; overflow: visible; border: 0; }
  table.amort { min-width: 0; font-size: 11px; }
  table.amort thead th, table.amort tfoot td { position: static; }
  table.amort tr { break-inside: avoid; }
  /* tfoot como grupo normal: el Total imprime UNA vez al final, no en cada página */
  table.amort tfoot { display: table-row-group; }
  .print-title { display: block !important; font-size: 14px; margin-bottom: 8px; }
}
.print-title { display: none; }

/* =============================================================
   12. Reduced motion (solo efectos intrusivos)
   ============================================================= */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .btn-primary:hover, .tool-link:hover { transform: none; }
}
