:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --ink: #10202b;
  --muted: #5b6b75;
  --line: #dde4e0;
  --accent: #0b7a5c;
  --accent-dark: #075c45;
  --accent-soft: #e3f3ed;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --danger: #b3261e;
  --radius: 14px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

a { color: var(--accent-dark); }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- cabecera ---------- */
.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.top .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  flex-wrap: wrap;
}
.logo {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
}
.logo span { color: var(--accent); }

.tabs { display: flex; gap: 4px; background: var(--bg); padding: 4px; border-radius: 999px; }
.tabs a {
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
}
.tabs a[aria-current="page"] { background: var(--accent); color: #fff; }

/* ---------- titular ---------- */
.intro { padding: 18px 0 12px; }
.intro h1 {
  margin: 0 0 4px;
  font-size: clamp(1.35rem, 3.4vw, 1.9rem);
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.intro p { margin: 0; color: var(--muted); }

/* ---------- herramienta ---------- */
.tool {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-items: start;
}
@media (min-width: 880px) {
  .tool { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
@media (max-width: 330px) {
  .fields { grid-template-columns: 1fr; }
}

label { font-weight: 600; font-size: 0.9rem; }
label small { font-weight: 400; color: var(--muted); }

input, select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #c4cfca;
  border-radius: 10px;
}
input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.nota { font-size: 0.82rem; color: var(--muted); }

.optional {
  grid-column: 1 / -1;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fdecea;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.92rem;
}

/* ---------- resultados ---------- */
.results.is-stale { opacity: 0.45; }

.cuota-label { margin: 0; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.cuota {
  margin: 0;
  font-size: clamp(2rem, 6vw, 2.9rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--accent-dark);
  overflow-wrap: anywhere;
}
.cuota-sub { margin: 4px 0 0; font-size: 0.88rem; color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
}
.stats div {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
.stats dt { font-size: 0.8rem; color: var(--muted); }
.stats dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }

.aviso {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}
.aviso-ok { background: var(--accent-soft); color: var(--accent-dark); }
.aviso-warn { background: var(--warn-soft); color: var(--warn); }

.bar {
  margin-top: 16px;
  height: 12px;
  border-radius: 999px;
  background: #f0b354;
  overflow: hidden;
}
.bar span { display: block; height: 100%; width: 60%; background: var(--accent); }
.bar-legend {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}
.bar-legend span::before {
  content: "";
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.bar-legend span + span::before { background: #f0b354; }

.chart-title { margin: 16px 0 4px; font-size: 0.9rem; font-weight: 600; color: var(--muted); }
#chart { display: block; width: 100%; height: auto; }
.ch-axis { stroke: var(--line); stroke-width: 1; }
.ch-area { fill: var(--accent-soft); }
.ch-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.ch-base { fill: none; stroke: #9aa7ae; stroke-width: 1.5; stroke-dasharray: 5 5; }
.ch-label { fill: var(--muted); font-size: 12px; }

/* ---------- tabla ---------- */
.amort { margin-top: 16px; }
.amort summary {
  cursor: pointer;
  font-weight: 700;
  padding: 4px 0;
}
.amort-actions { margin: 12px 0; }
.btn {
  display: inline-block;
  padding: 10px 16px;
  font: inherit;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dark); }
.table-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--ink); color: #fff; font-weight: 600; }
tbody tr:nth-child(even) { background: var(--bg); }

/* ---------- espacios de anuncio ---------- */
.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
  margin: 20px 0;
  border: 1px dashed #c4cfca;
  border-radius: 10px;
  color: #a3b0b6;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---------- contenido ---------- */
.content { max-width: 760px; padding: 8px 0 24px; }
.content h2 { margin: 28px 0 8px; font-size: 1.3rem; letter-spacing: -0.01em; }
.content h3 { margin: 18px 0 4px; font-size: 1.02rem; }
.content p, .content li { color: #2c3c46; }
.content details {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  margin: 8px 0;
}
.content summary { cursor: pointer; font-weight: 700; }
.content details p { margin: 8px 0 0; }

.other {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--ink);
}
.other strong { display: block; color: var(--accent-dark); }
.other:hover { border-color: var(--accent); }

.foot {
  border-top: 1px solid var(--line);
  padding: 18px 0 28px;
  font-size: 0.84rem;
  color: var(--muted);
}
.foot p { margin: 0 0 6px; }

/* En movil la cuota queda siempre a la vista mientras se rellenan los datos */
.cuota-fija { display: none; }
@media (max-width: 879px) {
  body { padding-bottom: 56px; }
  .cuota-fija {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 10;
    padding: 12px 16px;
    background: var(--ink);
    color: #fff;
    font-size: 0.9rem;
  }
  .cuota-fija strong { font-size: 1.25rem; letter-spacing: -0.02em; }
}

[hidden] { display: none !important; }
