/* Tu Casa en Cifras — hoja de estilos
   Concepto: la ficha técnica de una vivienda. Verde pino de plano de arquitecto, acento teja
   para lo que cuesta dinero, cifras tabulares y gráfico de amortización año a año. */
:root {
  --paper: #f4f5f1;
  --surface: #ffffff;
  --ink: #18221e;
  --muted: #5b6862;
  --line: #d8ddd6;
  --line-soft: #e8ebe5;
  --accent: #1f5f4b;
  --accent-soft: #e3eee8;
  --on-accent: #ffffff;
  --mark: #f3d9a4;
  --mark-ink: #2a1f06;
  --good: #2c7a4b;
  --warn: #b5532a;
  --ad: #ecefe9;

  --f-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --f-body: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-num: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;

  --step--1: .875rem; --step-0: 1rem; --step-1: 1.2rem; --step-2: 1.5rem; --step-3: 2rem; --step-4: 2.6rem;
  --radius: 6px;
  --wrap: 1120px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101513; --surface: #171e1b; --ink: #e4ebe7; --muted: #9caaa3; --line: #2a3530; --line-soft: #212b27;
    --accent: #84c7aa; --accent-soft: #1a2c25; --on-accent: #101513; --mark: #5a4513; --mark-ink: #fbeccb;
    --good: #6cc792; --warn: #e88f62; --ad: #1a221f; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #101513; --surface: #171e1b; --ink: #e4ebe7; --muted: #9caaa3; --line: #2a3530; --line-soft: #212b27;
    --accent: #84c7aa; --accent-soft: #1a2c25; --on-accent: #101513; --mark: #5a4513; --mark-ink: #fbeccb;
    --good: #6cc792; --warn: #e88f62; --ad: #1a221f; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 var(--step-0)/1.65 var(--f-body);
}
img { max-width: 100%; }
a { color: var(--accent); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
h1, h2, h3 { font-family: var(--f-display); font-weight: 700; line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: var(--step-4); letter-spacing: -.01em; }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-1); }
p { margin: 0; }
.num, .tabular { font-variant-numeric: tabular-nums; }

.wrap {
  max-width: var(--wrap); margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Cabecera */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-block: 14px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-family: var(--f-display); font-weight: 700; font-size: 1.2rem; letter-spacing: -.01em; }
.logo-mark { width: 30px; height: 30px; color: var(--accent); display: block; }
.logo-mark svg { width: 100%; height: 100%; display: block; }
.nav { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: var(--step--1); }
.nav a { color: var(--muted); text-decoration: none; padding: 4px 0; border-bottom: 2px solid transparent; }
.nav a:hover, .nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Migas */
.crumbs { font-size: var(--step--1); color: var(--muted); padding-top: 22px; }
.crumbs a { color: var(--muted); }

/* Cabecera de página */
.page-head { padding-block: 14px 26px; display: grid; gap: 12px; max-width: 760px; }
.page-head .lead { font-size: var(--step-1); color: var(--muted); line-height: 1.5; }
.meta { font-size: var(--step--1); color: var(--muted); display: flex; gap: 6px 16px; flex-wrap: wrap; }
.meta strong { color: var(--ink); font-weight: 600; }

/* Calculadora */
.calc { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 24px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.form { padding: 22px; display: grid; gap: 16px; }
.form h2, .result h2 { font-size: var(--step-1); }
.field { display: grid; gap: 6px; }
.field label, .field .label { font-weight: 600; font-size: .94rem; }
.field .hint { font-size: .82rem; color: var(--muted); line-height: 1.4; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
input[type="number"], input[type="date"], select {
  width: 100%; font: inherit; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line); border-radius: 4px; padding: 9px 11px; min-height: 42px;
}
input[type="number"] { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
input:focus, select:focus { border-color: var(--accent); outline: 2px solid var(--accent-soft); }
.input-unit { position: relative; }
.input-unit input { padding-right: 42px; }
.input-unit span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: .9rem; pointer-events: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; width: 100%; }
.seg label { flex: 1; text-align: center; font-weight: 500; font-size: .9rem; padding: 9px 6px; cursor: pointer; background: var(--paper); border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--on-accent); }
.seg label:has(input:checked) { background: var(--accent); color: var(--on-accent); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .92rem; }
.check input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent); }
details.more { border-top: 1px dashed var(--line); padding-top: 12px; }
details.more summary { cursor: pointer; font-weight: 600; font-size: .92rem; color: var(--accent); }
details.more[open] summary { margin-bottom: 14px; }
details.more > div { display: grid; gap: 16px; }

/* Resultado tipo recibo */
.result { padding: 22px; display: grid; gap: 18px; position: sticky; top: 16px; }
.headline { display: grid; gap: 4px; }
.headline .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.headline .big { font: 600 clamp(2rem, 6vw, 2.8rem)/1.1 var(--f-num); letter-spacing: -.02em; }
.headline .big mark { background: linear-gradient(transparent 55%, var(--mark) 55%); color: inherit; padding: 0 2px; }
.headline .sub { color: var(--muted); font-size: .92rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.kpi { background: var(--surface); padding: 10px 12px; display: grid; gap: 2px; }
.kpi span { font-size: .78rem; color: var(--muted); }
.kpi strong { font: 600 1.1rem/1.2 var(--f-num); font-variant-numeric: tabular-nums; }
.receipt { width: 100%; border-collapse: collapse; font-size: .92rem; }
.receipt caption { text-align: left; font: 600 .78rem/1 var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding-bottom: 8px; }
.receipt th, .receipt td { padding: 7px 0; border-bottom: 1px dotted var(--line); text-align: left; vertical-align: top; }
.receipt td:last-child, .receipt th:last-child { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px; }
.receipt .tipo { color: var(--muted); font-family: var(--f-num); font-size: .82rem; }
.receipt tr.total td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; padding-top: 10px; }
.receipt tr.minus td:last-child { color: var(--warn); }
.receipt .note { display: block; color: var(--muted); font-size: .8rem; }
.bar { display: flex; height: 10px; border-radius: 2px; overflow: hidden; background: var(--line-soft); }
.bar i { display: block; height: 100%; }
.bar .b-neto { background: var(--accent); }
.bar .b-ss { background: var(--muted); }
.bar .b-irpf { background: var(--warn); }
.legend { display: flex; gap: 6px 16px; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--c); }
.alert { font-size: .88rem; border-left: 3px solid var(--warn); padding: 8px 12px; background: var(--paper); color: var(--ink); }
.disclaimer { font-size: .8rem; color: var(--muted); line-height: 1.45; }

/* Publicidad */
.ad-slot { margin-block: 28px; background: var(--ad); border-radius: 4px; min-height: 100px; display: grid; place-items: center; position: relative; }
.ad-slot::before { content: "Publicidad"; position: absolute; top: 6px; left: 10px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ad-slot.vacio { display: none; }

/* Artículo */
.content { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 40px; padding-block: 24px 48px; }
.article { max-width: 70ch; display: grid; gap: 18px; min-width: 0; }
.article h2 { margin-top: 18px; font-size: var(--step-2); }
.article h3 { margin-top: 6px; }
.article ul, .article ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.article .example { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 8px; }
.article .example strong:first-child { font-family: var(--f-display); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.data { width: 100%; border-collapse: collapse; font-size: .92rem; min-width: 420px; }
.data th, .data td { padding: 9px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.data th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--paper); }
.data td.n { text-align: right; font-family: var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.data tr:last-child td { border-bottom: 0; }
.faq { display: grid; gap: 0; border-top: 1px solid var(--line); }
.faq details { border-bottom: 1px solid var(--line); padding: 12px 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin-top: 8px; }
.sources { font-size: .88rem; color: var(--muted); }
.aside { display: grid; gap: 20px; align-content: start; position: sticky; top: 16px; }
.toc { font-size: .9rem; display: grid; gap: 6px; }
.toc strong { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.toc a { color: var(--ink); text-decoration: none; }
.toc a:hover { color: var(--accent); text-decoration: underline; }
.related { display: grid; gap: 8px; font-size: .9rem; }
.related strong { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* Portada */
.hero { padding-block: 44px 28px; display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 32px; align-items: end; }
.hero h1 { font-size: clamp(2.1rem, 5vw, 3.3rem); }
.hero p { font-size: var(--step-1); color: var(--muted); margin-top: 14px; max-width: 46ch; }
.figures { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; font-size: .9rem; }
.figures h2 { font-size: .78rem; font-family: var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.figures dl { margin: 0; display: grid; grid-template-columns: 1fr auto; }
.figures dt, .figures dd { padding: 7px 0; border-bottom: 1px dotted var(--line); margin: 0; }
.figures dd { font-family: var(--f-num); font-variant-numeric: tabular-nums; text-align: right; }
.figures dl > :nth-last-child(-n+2) { border-bottom: 0; }
.tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 40px; }
.tool { background: var(--surface); padding: 20px 22px; display: grid; gap: 8px; text-decoration: none; color: var(--ink); grid-template-rows: auto auto 1fr auto; }
.tool:hover { background: var(--accent-soft); }
.tool h2 { font-size: var(--step-1); }
.tool p { color: var(--muted); font-size: .94rem; }
.tool .go { font-size: .88rem; color: var(--accent); font-weight: 600; }
.tool.propose { background: var(--paper); }
.tool .q { font-family: var(--f-num); font-size: .78rem; color: var(--muted); }
.home-text { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 28px; padding-block: 8px 48px; }
.home-text section { display: grid; gap: 10px; align-content: start; }
.home-text h2 { font-size: var(--step-2); }

/* Páginas de texto */
.prose { max-width: 70ch; display: grid; gap: 16px; padding-block: 8px 56px; }
.prose h2 { font-size: var(--step-2); margin-top: 14px; }
.prose ul { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.placeholder { background: var(--mark); color: var(--mark-ink); padding: 0 4px; border-radius: 2px; }

/* Pie */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); font-size: .88rem; color: var(--muted); }
.site-footer .wrap { padding-block: 28px; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 24px; }
.site-footer h2 { font: 600 .78rem/1 var(--f-body); text-transform: uppercase; letter-spacing: .08em; color: var(--ink); margin-bottom: 10px; }
.site-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.site-footer a { color: var(--muted); }
.site-footer .legal { grid-column: 1 / -1; border-top: 1px solid var(--line-soft); padding-top: 16px; }

@media (max-width: 900px) {
  .calc, .content, .hero { grid-template-columns: minmax(0, 1fr); }
  .result, .aside { position: static; }
  .aside { order: -1; }
  .toc { display: none; }
}
@media (max-width: 520px) {
  h1 { font-size: 2rem; }
  .row2 { grid-template-columns: 1fr; }
  .form, .result { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
@media print { .site-header, .site-footer, .ad-slot, .aside, .form { display: none; } .calc { display: block; } }

/* Gráficos */
.chart { display: grid; gap: 8px; }
.chart-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .ax { fill: var(--muted); font: 11px var(--f-num); }
.chart .grid { stroke: var(--line-soft); stroke-width: 1; }
.chart .c-cap { fill: var(--accent); }
.chart .c-int { fill: var(--warn); }
.chart .l-comprar { stroke: var(--accent); stroke-width: 2.5; fill: none; }
.chart .l-alquilar { stroke: var(--warn); stroke-width: 2.5; fill: none; }
.chart .dot-comprar { fill: var(--accent); }
.chart .dot-alquilar { fill: var(--warn); }
.versus { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.versus > div { background: var(--surface); padding: 12px; display: grid; gap: 4px; }
.versus .win { background: var(--accent-soft); }
.versus span { font-size: .8rem; color: var(--muted); }
.versus strong { font: 600 1.15rem/1.2 var(--f-num); }
.amort-table { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.amort-table table { min-width: 0; font-size: .85rem; }
.amort-table th { position: sticky; top: 0; }
[hidden] { display: none !important; }
