/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #172321;
  --text-muted: #5b6b67;
  --border: #dbe3e0;
  --accent: #0f6e5c;
  --accent-dark: #0b5346;
  --accent-soft: #e3f3ee;
  --danger: #b3411f;
  --danger-soft: #fbe9e3;
  --capital-color: #0f6e5c;
  --interes-color: #c98a1f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 30, 27, 0.06), 0 6px 20px rgba(15, 30, 27, 0.06);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1513;
    --surface: #161f1c;
    --surface-2: #1d2926;
    --text: #eef3f1;
    --text-muted: #a7b6b1;
    --border: #2a3733;
    --accent: #37c99e;
    --accent-dark: #2aa483;
    --accent-soft: #16302a;
    --danger: #e07a55;
    --danger-soft: #2e1d18;
    --capital-color: #37c99e;
    --interes-color: #e0ab4d;
  }
}

/* =============================================================
   2. Reset & base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; tab-size: 2; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
  overscroll-behavior-y: none;
}
[hidden] { display: none !important; }
img, svg, video { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: inherit; text-decoration: none; }
p { text-wrap: pretty; }
h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; letter-spacing: -0.01em; font-weight: 800; }
::selection { background: var(--accent-soft); color: var(--accent-dark); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
input[type="number"] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* =============================================================
   3. Utilities
   ============================================================= */
.container { width: 100%; max-width: 1040px; margin-inline: auto; padding-inline: 1rem; }
.skip-link {
  position: fixed; top: -100px; left: 1rem; padding: .6rem 1rem;
  background: var(--accent); color: #fff; z-index: 9999; border-radius: 8px; font-weight: 600;
}
.skip-link:focus { top: 1rem; }
.no-print { }

/* =============================================================
   4. Header / hero
   ============================================================= */
.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.header-inner { display: flex; align-items: center; justify-content: space-between; padding-block: .5rem; min-height: 44px; }
.brand { display: flex; align-items: center; gap: .4rem; font-weight: 800; color: var(--accent-dark); font-size: 1.02rem; }
@media (prefers-color-scheme: dark) { .brand { color: var(--accent); } }
.badge-free {
  font-size: .68rem; font-weight: 700; color: var(--accent-dark); background: var(--accent-soft);
  padding: .3rem .55rem; border-radius: 999px; white-space: nowrap;
}
@media (prefers-color-scheme: dark) { .badge-free { color: var(--accent); } }

.hero { padding-block: 1rem .6rem; }
.hero h1 { font-size: clamp(1.3rem, 4.4vw, 1.9rem); max-width: 30ch; }
.hero .subtitle { color: var(--text-muted); margin-top: .35rem; font-size: .92rem; max-width: 58ch; }

/* =============================================================
   5. Tool card & form
   ============================================================= */
.tool-section { padding-block: .4rem .9rem; }
.tool-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: .9rem .9rem 1rem;
}
.tool-card + .tool-card { margin-top: .75rem; }
.scenario-heading { font-size: .95rem; margin-bottom: .5rem; color: var(--accent-dark); }
@media (prefers-color-scheme: dark) { .scenario-heading { color: var(--accent); } }

.calc-form { display: flex; flex-direction: column; gap: .55rem; }
.field-row { display: flex; flex-direction: column; gap: .3rem; }
.field-row label, .field-label {
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted);
}
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.two-col > div { display: flex; flex-direction: column; gap: .3rem; }

input[type="number"] {
  width: 100%; height: 2.35rem; padding: 0 .6rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font-size: .95rem; font-weight: 600; font-family: inherit;
  transition: border-color .15s var(--ease-out), box-shadow .15s var(--ease-out);
}
input[type="number"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.input-suffix { position: relative; display: flex; align-items: center; }
.input-suffix input { padding-right: 3.1rem; }
.input-suffix .suffix {
  position: absolute; right: .6rem; font-size: .78rem; font-weight: 700; color: var(--text-muted); pointer-events: none;
}

/* Segmented control — pure CSS, works without JS styling assist */
.segmented-group { flex-direction: row; align-items: center; flex-wrap: wrap; gap: .5rem; }
.segmented {
  display: inline-flex; border: 1px solid var(--border); border-radius: 999px; padding: 2px; background: var(--surface-2);
}
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented label {
  padding: .38rem .75rem; font-size: .8rem; font-weight: 700; border-radius: 999px; color: var(--text-muted);
  cursor: pointer; transition: background .15s var(--ease-out), color .15s var(--ease-out); white-space: nowrap;
}
.segmented input:checked + label { background: var(--accent); color: #fff; }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.segmented-sm label { padding: .3rem .55rem; font-size: .74rem; }

.uf-inline {
  display: flex; align-items: center; gap: .4rem; font-size: .78rem; color: var(--text-muted);
  background: var(--surface-2); border-radius: var(--radius-sm); padding: .4rem .6rem;
}
.uf-inline[data-stale] { color: var(--danger); background: var(--danger-soft); }
.uf-refresh, .uf-manual-toggle {
  width: 1.6rem; height: 1.6rem; border-radius: 999px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--surface); border: 1px solid var(--border); font-size: .82rem; line-height: 1;
}
.uf-refresh { margin-left: auto; }
.uf-refresh:hover, .uf-manual-toggle:hover { color: var(--accent); }
.uf-inline span:first-child { flex: 1 1 auto; }

.pie-row { }
.pie-inputs { display: flex; gap: .5rem; align-items: center; }
.pie-inputs .input-suffix { flex: 1 1 auto; }
.pie-computed { font-size: .74rem; color: var(--text-muted); }

.results-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: .8rem;
  padding-top: .8rem; border-top: 1px dashed var(--border);
}
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat-label { font-size: .64rem; font-weight: 700; text-transform: uppercase; letter-spacing: .02em; color: var(--text-muted); }
.stat-value { font-size: 1.02rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stat-primary .stat-value { color: var(--accent-dark); font-size: 1.25rem; }
@media (prefers-color-scheme: dark) { .stat-primary .stat-value { color: var(--accent); } }
.stat-sub { font-size: .68rem; color: var(--text-muted); }

.tool-note { margin-top: .6rem; font-size: .72rem; color: var(--text-muted); }

.disclaimer {
  margin-top: .75rem; font-size: .78rem; color: var(--danger); background: var(--danger-soft);
  border-radius: var(--radius-sm); padding: .55rem .7rem; font-weight: 600;
}
.uf-source { margin-top: .5rem; font-size: .74rem; color: var(--text-muted); }
.uf-source a { color: var(--accent-dark); text-decoration: underline; }
@media (prefers-color-scheme: dark) { .uf-source a { color: var(--accent); } }

.tool-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.btn {
  display: inline-flex; align-items: center; gap: .35rem; padding: .55rem .9rem; border-radius: 999px;
  font-weight: 700; font-size: .82rem; transition: transform .12s var(--ease-out), background .15s var(--ease-out);
}
.btn:active { transform: scale(.97); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent-dark); }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-secondary:hover { background: var(--accent-dark); }
.btn-sm { padding: .4rem .7rem; font-size: .74rem; }

@media (min-width: 720px) {
  .field-row.segmented-group { flex-direction: row; }
  .results-strip { grid-template-columns: 1.2fr 1fr 1fr; }
}

/* =============================================================
   6. Ad slots
   ============================================================= */
.ad-slot {
  border: 1.5px dashed var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--text-muted); display: flex; align-items: center; justify-content: center;
}
.ad-label { font-size: .72rem; font-weight: 700; letter-spacing: .08em; }
.ad-leaderboard { max-width: 1040px; margin: 0 auto; min-height: 90px; }
.ad-incontent { max-width: 1040px; margin: 1.5rem auto; min-height: 250px; margin-inline: 1rem; }
@media (min-width: 720px) { .ad-incontent { margin-inline: auto; } }

.corner-toast {
  position: fixed; right: .8rem; bottom: .8rem; z-index: 40; min-width: 168px; min-height: 64px;
  padding: .6rem 1.8rem .6rem .8rem; box-shadow: var(--shadow); animation: toastIn .35s var(--ease-out);
}
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.toast-close {
  position: absolute; top: .3rem; right: .3rem; width: 1.4rem; height: 1.4rem; border-radius: 999px;
  display: grid; place-items: center; background: var(--surface); border: 1px solid var(--border); font-size: .85rem;
}

dialog.ad-popup {
  position: fixed; inset: 0; margin: auto;
  border: none; border-radius: var(--radius); padding: 0; box-shadow: var(--shadow);
  width: min(92vw, 420px); height: fit-content;
}
dialog.ad-popup::backdrop { background: rgba(10, 20, 18, .45); }
.ad-popup-slot { width: 100%; min-height: 250px; padding: 1rem; border: none; border-radius: 0; }
.dialog-close {
  position: absolute; top: .5rem; right: .5rem; width: 1.8rem; height: 1.8rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); font-size: 1rem; z-index: 1;
}

/* =============================================================
   7. Detail section: chart + table
   ============================================================= */
.detail-section { padding-block: 1.4rem; }
.detail-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.detail-heading { font-size: 1.15rem; }

.print-summary { display: none; }
.print-summary .ps-block + .ps-block { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--border); }
.print-summary .ps-title { font-weight: 800; font-size: .95rem; margin-bottom: .3rem; }
.print-summary .ps-params { font-size: .8rem; color: var(--text-muted); margin-bottom: .4rem; }
.print-summary .ps-stats { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.print-summary .ps-stats div { font-size: .85rem; }
.print-summary .ps-stats b { display: block; font-size: 1rem; }

.compare-summary {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem;
  margin-bottom: 1rem;
}
.compare-summary .cs-item { display: flex; flex-direction: column; gap: .15rem; }
.compare-summary .cs-label { font-size: .68rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); }
.compare-summary .cs-value { font-size: 1rem; font-weight: 800; }
.compare-summary .cs-value.positive { color: var(--accent-dark); }
.compare-summary .cs-value.negative { color: var(--danger); }
@media (prefers-color-scheme: dark) { .compare-summary .cs-value.positive { color: var(--accent); } }

.charts-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1.2rem; }
@media (min-width: 960px) { .charts-grid[data-count="2"] { grid-template-columns: 1fr 1fr; } }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; }
.chart-title { font-size: .92rem; margin-bottom: .5rem; }
.chart-card canvas { width: 100%; height: auto; aspect-ratio: 2 / 1; }
.chart-legend { list-style: none; display: flex; gap: 1rem; margin-top: .6rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); }
.chart-legend .dot { width: .6rem; height: .6rem; border-radius: 999px; display: inline-block; margin-right: .3rem; }
.dot-capital { background: var(--capital-color); }
.dot-interes { background: var(--interes-color); }

.table-block + .table-block { margin-top: 1.6rem; }
.table-block-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.table-block-head h2 { font-size: 1.02rem; }
.table-scroll { overflow-x: auto; overflow-y: visible; border: 1px solid var(--border); border-radius: var(--radius); }
.amort-table { width: 100%; border-collapse: collapse; font-size: .82rem; min-width: 480px; }
.amort-table th, .amort-table td { padding: .5rem .6rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.amort-table th:first-child, .amort-table td:first-child { text-align: left; }
.amort-table thead th { background: var(--surface-2); font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); position: sticky; top: 0; }
.amort-table tbody tr:nth-child(even) { background: var(--surface-2); }
.table-loading { text-align: center; color: var(--text-muted); font-size: .8rem; padding: .6rem; }

/* =============================================================
   8. Content sections
   ============================================================= */
.how-it-works, .use-cases, .seo-text, .faq { padding-block: 1.6rem; }
.how-it-works h2, .use-cases h2, .seo-text h2, .faq h2 { font-size: 1.3rem; margin-bottom: .9rem; }

.steps { list-style: none; display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .steps { grid-template-columns: repeat(3, 1fr); } }
.steps li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.steps svg { color: var(--accent); margin-bottom: .5rem; }
.steps h3 { font-size: .96rem; margin-bottom: .3rem; }
.steps p { font-size: .85rem; color: var(--text-muted); }

.cases-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
@media (min-width: 720px) { .cases-grid { grid-template-columns: repeat(3, 1fr); } }
.cases-grid article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.cases-grid h3 { font-size: .96rem; margin-bottom: .35rem; color: var(--accent-dark); }
@media (prefers-color-scheme: dark) { .cases-grid h3 { color: var(--accent); } }
.cases-grid p { font-size: .85rem; color: var(--text-muted); }

.seo-text p { max-width: 74ch; color: var(--text-muted); margin-bottom: .8rem; font-size: .92rem; }
.seo-text strong { color: var(--text); }

.faq details {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .9rem; margin-bottom: .55rem;
}
.faq summary { font-weight: 700; cursor: pointer; font-size: .92rem; }
.faq details p { margin-top: .5rem; color: var(--text-muted); font-size: .87rem; }

/* =============================================================
   9. Footer
   ============================================================= */
.site-footer { border-top: 1px solid var(--border); padding-block: 1.4rem; margin-top: 1rem; }
.site-footer .disclaimer { max-width: 60ch; }
.uf-credit { font-size: .8rem; color: var(--text-muted); margin-top: .6rem; }
.uf-credit a { color: var(--accent-dark); text-decoration: underline; }
@media (prefers-color-scheme: dark) { .uf-credit a { color: var(--accent); } }
.footer-links { display: flex; gap: 1rem; margin-top: .8rem; }
.footer-links a { font-size: .82rem; color: var(--text-muted); text-decoration: underline; }
.copyright { margin-top: .8rem; font-size: .76rem; color: var(--text-muted); }

/* =============================================================
   10. Responsive breakpoints reference
   ============================================================= */
@media (min-width: 540px) { .container { padding-inline: 1.25rem; } }
@media (min-width: 1280px) { .container { padding-inline: 1.5rem; } }

/* =============================================================
   11. Print
   ============================================================= */
@media print {
  .site-header, .hero, .tool-section, .ad-slot, .corner-toast, .how-it-works,
  .use-cases, .seo-text, .faq, .site-footer, .no-print, dialog { display: none !important; }
  .detail-section { padding: 0; }
  .print-summary { display: block !important; }
  .compare-summary, .charts-grid, .chart-card { break-inside: avoid; }
  .table-scroll { overflow: visible; border: none; }
  .amort-table { font-size: 10px; }
  .amort-table thead th { position: static; }
  body { background: #fff; color: #000; }
  .container { max-width: 100%; padding: 0; }
}
