:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efeb;
  --line: #e3e1db;
  --line-2: #cfcdc5;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7d7b76;
  --accent: #2a78d6;
  --accent-soft: #e8f1fc;
  --accent-soft-2: #d5e5f9;
  --buy: #2a78d6;
  --rent: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #4a3aa7;
  --good: #0ca30c;
  --warn: #b97f00;
  --warn-bg: #fff6df;
  --crit: #d03b3b;
  --crit-bg: #fdeaea;
  --info-bg: #e8f1fc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 .6em; }
a { color: var(--accent); }
button { font: inherit; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.tiny { font-size: 11px; color: var(--text-3); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1480px; margin: 0 auto; padding: 10px 18px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand .sub { color: var(--text-2); font-size: 13px; }
.toolbar { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn { border: 1px solid var(--line-2); background: var(--surface); color: var(--text); border-radius: 8px; padding: 6px 11px; cursor: pointer; font-size: 13px; line-height: 1.2; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1f66bb; }
.btn.small { padding: 3px 8px; font-size: 12px; border-radius: 6px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }
.btn.danger { color: var(--crit); }
.btn[disabled] { opacity: .5; cursor: default; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.pill.buy { background: var(--accent-soft); color: var(--buy); }
.pill.rent { background: #fdeee6; color: #b84b1f; }
.pill.good { background: #e6f6e6; color: #0a7a0a; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.crit { background: var(--crit-bg); color: var(--crit); }

/* ---------- layout ---------- */
.layout { max-width: 1480px; margin: 0 auto; padding: 16px 18px 60px; display: grid; grid-template-columns: minmax(340px, 440px) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } .inputs { position: static !important; max-height: none !important; } }
.inputs { position: sticky; top: calc(var(--topbar-h, 52px) + 10px); max-height: calc(100vh - var(--topbar-h, 52px) - 26px); overflow: auto; padding-right: 4px; scrollbar-width: thin; }
.results { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card-body { padding: 14px 16px; }
.card-title { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card-title h2 { flex: 1; }

/* ---------- sections (accordion) ---------- */
details.sec { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; }
details.sec > summary { list-style: none; cursor: pointer; padding: 11px 14px; display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 14px; user-select: none; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary .chev { width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center; color: var(--text-3); transition: transform .15s; }
details.sec[open] > summary .chev { transform: rotate(90deg); }
details.sec > summary .stepnum { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--buy); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
details.sec > summary .summ { margin-left: auto; font-weight: 500; color: var(--text-2); font-size: 12px; text-align: right; }
details.sec > .sec-body { padding: 4px 14px 14px; border-top: 1px solid var(--line); }
.intro { padding: 10px 14px; background: var(--accent-soft); border: 1px solid var(--accent-soft-2); border-radius: var(--radius); margin-bottom: 10px; font-size: 13px; color: #1d477c; }
.intro b { color: #143562; }

/* ---------- fields ---------- */
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; margin-top: 10px; }
.fgrid.two { grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 5px; line-height: 1.25; }
.field .inwrap { position: relative; display: flex; align-items: center; }
.field input[type=number], .field input[type=text], .field select { width: 100%; border: 1px solid var(--line-2); border-radius: 7px; padding: 6px 8px; font: inherit; font-size: 14px; background: #fff; color: var(--text); min-width: 0; }
.field input[type=number] { text-align: right; padding-right: 30px; font-variant-numeric: tabular-nums; }
.field input.unit-wide { padding-right: 52px; }
.field .unit { position: absolute; right: 8px; color: var(--text-3); font-size: 12px; pointer-events: none; }
.field input:focus, .field select:focus { outline: 2px solid var(--accent-soft-2); border-color: var(--accent); }
.field.basic input, .field.basic select { background: #f5f9ff; border-color: #b9d3f3; }
.field input.invalid { border-color: var(--crit); background: var(--crit-bg); }
.field .sub { font-size: 11px; color: var(--text-3); }
.help { display: inline-flex; width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--line-2); color: var(--text-3); font-size: 10px; align-items: center; justify-content: center; cursor: help; flex: none; background: var(--surface); font-weight: 600; }
.help:hover, .help:focus { border-color: var(--accent); color: var(--accent); outline: none; }
.gtip { position: fixed; z-index: 200; max-width: 290px; background: #1f1f1e; color: #f4f3ef; padding: 8px 11px; border-radius: 8px; font-size: 12.5px; line-height: 1.45; display: none; box-shadow: 0 6px 20px rgba(0,0,0,.25); pointer-events: none; font-weight: 400; }
.jump { display: none; }
@media (max-width: 980px) { .jump { display: block; position: fixed; bottom: 14px; right: 14px; background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 999px; z-index: 40; text-decoration: none; font-weight: 600; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.2); } }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-top: 10px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.subhead { margin: 14px 0 2px; font-size: 12px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; }
.subhead .help { text-transform: none; letter-spacing: 0; }
.adv { display: none; }
body.show-adv .adv { display: revert; }
body.show-adv .fgrid .adv { display: flex; }
.adv-note { font-size: 11px; color: var(--text-3); margin-top: 8px; }
body.show-adv .adv-note { display: none; }
.total-line { font-size: 12px; color: var(--text-2); margin-top: 8px; }
.total-line b { color: var(--text); }

/* editable lists */
.list { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.list th { text-align: left; font-size: 11px; color: var(--text-3); font-weight: 600; padding: 2px 4px; }
.list td { padding: 2px 3px; }
.list input[type=number], .list select, .list input[type=text] { width: 100%; border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 5px; font: inherit; font-size: 13px; background: #fff; min-width: 0; }
.list input[type=number] { text-align: right; font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield; }
.list input[type=number]::-webkit-inner-spin-button, .list input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.list select { padding-right: 2px; }
.list .del { border: none; background: none; color: var(--text-3); cursor: pointer; font-size: 15px; padding: 0 4px; line-height: 1; }
.list .del:hover { color: var(--crit); }
.list .empty td { color: var(--text-3); font-style: italic; font-size: 12px; padding: 4px; }

/* offers chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.sel { border-color: var(--accent); background: var(--accent-soft); color: #143562; font-weight: 600; }
.chip .star { color: var(--s4); }
.offer-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- results ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { border: none; background: none; padding: 9px 13px; font-size: 13px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover { color: var(--text); }
.verdict { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .verdict { grid-template-columns: 1fr; } }
.side { padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); position: relative; overflow: hidden; }
.side::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.side.buy::before { background: var(--buy); }
.side.rent::before { background: var(--rent); }
.side .lbl { font-size: 12px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.side .big { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.side .note { font-size: 12px; color: var(--text-2); }
.headline { font-size: 15px; margin: 12px 0 4px; }
.headline b { font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.kpi { background: var(--surface-2); border-radius: 8px; padding: 9px 11px; }
.kpi .l { font-size: 11px; color: var(--text-2); }
.kpi .v { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .s { font-size: 11px; color: var(--text-3); }
.alerts { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.alert { padding: 8px 11px; border-radius: 8px; font-size: 13px; display: flex; gap: 8px; align-items: flex-start; }
.alert .ic { flex: none; font-weight: 700; width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; }
.alert.error { background: var(--crit-bg); color: #7a1f1f; } .alert.error .ic { background: var(--crit); }
.alert.warn { background: var(--warn-bg); color: #6b4a00; } .alert.warn .ic { background: var(--warn); }
.alert.info { background: var(--info-bg); color: #1d477c; } .alert.info .ic { background: var(--accent); }
.alert.ok { background: #e6f6e6; color: #0a5a0a; } .alert.ok .ic { background: var(--good); }
.toggle-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { accent-color: var(--accent); }

/* charts */
.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .tooltip { position: absolute; pointer-events: none; background: #1f1f1e; color: #f4f3ef; font-size: 12px; padding: 6px 9px; border-radius: 7px; box-shadow: 0 6px 20px rgba(0,0,0,.25); white-space: nowrap; z-index: 20; display: none; line-height: 1.35; }
.chart .tooltip .r { display: flex; justify-content: space-between; gap: 14px; }
.chart .tooltip .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 6px; }
.legend .it { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend .sw.dash { background: repeating-linear-gradient(90deg, currentColor 0 4px, transparent 4px 7px); height: 2px; }
.chart-title { font-size: 13px; font-weight: 650; margin-top: 4px; }
.chart-sub { font-size: 12px; color: var(--text-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

/* tables */
.tbl-wrap { overflow-x: auto; margin-top: 8px; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.data th, table.data td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data th { background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 11.5px; position: sticky; top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data tr:hover td { background: #f7f7f4; }
table.data td.neg { color: var(--crit); }
table.data td.best { background: #e6f6e6; font-weight: 600; }
table.data tr.hl td { background: var(--accent-soft); }
table.data tr.year-row { cursor: pointer; }
table.data tr.year-row td:first-child::before { content: "▸ "; color: var(--text-3); }
table.data tr.year-row.open td:first-child::before { content: "▾ "; }
table.data tr.month-row td { background: #fafaf8; color: var(--text-2); font-size: 12px; }
table.data td.mark { color: var(--good); font-weight: 700; }
.hitos { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin-top: 10px; }
.hito { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 12.5px; }
.hito h4 { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.hito .row { display: flex; justify-content: space-between; gap: 8px; }
.hito .row b { font-variant-numeric: tabular-nums; }

/* help page */
.prose { max-width: 820px; font-size: 14px; }
.prose h2 { margin: 20px 0 8px; font-size: 16px; }
.prose h3 { margin: 16px 0 6px; font-size: 14px; }
.prose ul { padding-left: 20px; margin: 0 0 10px; }
.prose li { margin-bottom: 4px; }
.prose dl { margin: 0; }
.prose dt { font-weight: 650; margin-top: 8px; }
.prose dd { margin: 2px 0 0 0; color: var(--text-2); }
.prose table.data th, .prose table.data td { text-align: left; white-space: normal; }

/* misc */
.footer { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 30px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #1f1f1e; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.nav-hint { font-size: 12px; color: var(--text-3); margin: -4px 0 10px; }
@media print { .topbar, .inputs, .tabs { display: none; } .layout { grid-template-columns: 1fr; } .card { box-shadow: none; break-inside: avoid; } }


/* --- cálculo en el servidor: indicador discreto mientras llega la respuesta --- */
.tabs { position: relative; }
.tabpane { transition: opacity .15s; }
body.calculando .tabpane { opacity: .55; transition: opacity .2s .45s; }
.calc-ind { margin-left: auto; align-self: center; font-size: 12px; color: var(--text-3); padding: 0 8px; opacity: 0; transition: opacity .15s; white-space: nowrap; pointer-events: none; }
body.calculando .calc-ind { opacity: 1; transition: opacity .2s .45s; }
