/* styles.css — Simulador amortización
 * Vanilla CSS, BEM-ish, custom properties, dark/light via [data-theme].
 * No frameworks. No CDN.
 */

:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-2: #f0f4fa;
  --border: #d8e0ea;
  --text: #1a2433;
  --text-muted: #5a6b80;
  --primary: #1e63d6;
  --primary-hover: #1850b3;
  --primary-soft: #e2ecfb;
  --success: #1f9e58;
  --warning: #c97a07;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(15, 30, 60, 0.06), 0 6px 24px rgba(15, 30, 60, 0.05);
  --radius: 10px;
  --radius-sm: 6px;
  --maxw: 1100px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0e1521;
  --surface: #182233;
  --surface-2: #1f2c40;
  --border: #2c3a52;
  --text: #e6ecf5;
  --text-muted: #93a4be;
  --primary: #5d8bf0;
  --primary-hover: #7aa2f5;
  --primary-soft: #1d2a45;
  --success: #4ad18b;
  --warning: #f0b056;
  --danger: #ec6a5b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 24px rgba(0, 0, 0, 0.35);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; }
h1 { font-size: 1.85rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }
p { margin: 0 0 1em; }

a { color: var(--primary); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

img, svg { max-width: 100%; height: auto; }

/* Skip link */
.skip-link {
  position: absolute; top: -40px; left: 0; z-index: 1000;
  background: var(--primary); color: #fff; padding: .5em 1em;
  border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { top: 0; }

/* Focus */
:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Layout */
.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1rem;
}

@media (min-width: 720px) {
  .container { padding: 1.5rem 2rem; }
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.header__title { margin: 0; font-size: 1.25rem; font-weight: 700; }
.header__title a { color: var(--text); }
.header__subtitle { font-size: .9rem; color: var(--text-muted); margin: 0; max-width: 60ch; }
.header__tools { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  padding: .55em 1.1em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .05s, border-color .15s;
  min-height: 38px;
}
.btn:hover { background: var(--surface-2); border-color: var(--primary); }
.btn:active { transform: translateY(1px); }
.btn--primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn--ghost { background: transparent; }
.btn--danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--small { padding: .35em .8em; min-height: 32px; font-size: .85rem; }

/* Icon button (toggle theme/lang) */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn[data-active="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }

/* Disclaimer */
.disclaimer {
  background: #fff7e6;
  border: 1px solid #f0d28b;
  color: #6b4f00;
  padding: .9rem 1.1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  font-size: .92rem;
}
[data-theme="dark"] .disclaimer {
  background: #3a2c0e;
  border-color: #6b4f00;
  color: #f0d28b;
}
.disclaimer strong { color: inherit; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap;
}
.card__title { font-weight: 600; font-size: 1.05rem; margin: 0; }
.card__remove { font-size: .85rem; }

/* Form grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .85rem;
}
.field { display: flex; flex-direction: column; gap: .25rem; }
.field__label {
  font-size: .82rem; font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.field__help { font-size: .78rem; color: var(--text-muted); }
.field__input,
.field__select {
  width: 100%;
  padding: .55em .7em;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  min-height: 38px;
}
.field__input:focus,
.field__select:focus {
  border-color: var(--primary);
  outline: 3px solid var(--primary-soft);
  outline-offset: 0;
}
.field__input--error {
  border-color: var(--danger);
}
.field__error {
  font-size: .82rem;
  color: var(--danger);
  min-height: 1.2em;
}

/* Radio segmented */
.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}
.segmented input { display: none; }
.segmented label {
  padding: .4em .9em;
  cursor: pointer;
  font-size: .9rem;
  border-right: 1px solid var(--border);
  user-select: none;
}
.segmented label:last-child { border-right: none; }
.segmented input:checked + label {
  background: var(--primary);
  color: #fff;
}

/* Buttons bar */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: center;
  margin-top: 1rem;
}

/* Results */
.results {
  margin-top: 2rem;
  display: none;
}
.results[data-shown="true"] { display: block; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.tab {
  padding: .55em 1.1em;
  border: 1px solid var(--border);
  border-bottom: none;
  background: var(--surface-2);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  color: var(--text-muted);
}
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--surface);
  margin-bottom: -1px;
  font-weight: 600;
}
.tab:hover { color: var(--text); }

.tab-panel { display: none; }
.tab-panel[data-active="true"] { display: block; }

/* Summary cards */
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .8rem;
  margin-bottom: 1rem;
}
.summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
}
.summary__label {
  font-size: .78rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em;
  font-weight: 600;
}
.summary__value {
  font-size: 1.4rem;
  font-weight: 700;
  margin: .25rem 0 .15rem;
  font-variant-numeric: tabular-nums;
}
.summary__help { font-size: .78rem; color: var(--text-muted); }
.summary--best {
  background: var(--primary-soft);
  border-color: var(--primary);
}

/* Table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: .88rem;
}
.table thead th {
  background: var(--surface-2);
  font-weight: 600;
  text-align: right;
  padding: .55em .7em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0;
}
.table thead th:first-child { text-align: left; }
.table tbody td {
  padding: .45em .7em;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}
.table tbody td:first-child { text-align: left; font-weight: 500; }
.table tbody tr:nth-child(even) { background: var(--surface-2); }
.table tbody tr:hover { background: var(--primary-soft); }

.table-pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .5rem .75rem;
  background: var(--surface-2);
  border-bottom-left-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  font-size: .85rem;
}

/* Chart */
.chart-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  margin-bottom: 1rem;
}
.chart-wrap canvas {
  display: block;
  width: 100%;
  height: 280px;
}
@media (min-width: 720px) {
  .chart-wrap canvas { height: 340px; }
}
.chart-title {
  font-size: .95rem;
  font-weight: 600;
  margin: 0 0 .5rem;
  color: var(--text);
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: .5rem;
  font-size: .85rem;
}
.chart-legend__item {
  display: inline-flex; align-items: center; gap: .35rem;
}
.chart-legend__swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  display: inline-block;
}

/* Compare */
.compare {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
}
.compare__title { margin-bottom: .25rem; }
.compare__subtitle { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }

.compare-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: .9rem; }
.compare-table th, .compare-table td {
  padding: .55em .7em;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.compare-table th:first-child, .compare-table td:first-child { text-align: left; }
.compare-table thead th { background: var(--surface-2); font-weight: 600; }
.compare-table .winner {
  background: var(--primary-soft);
  font-weight: 600;
}
.compare-table .winner-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: .7rem;
  padding: .1em .45em;
  border-radius: 4px;
  margin-left: .35em;
  font-weight: 600;
  vertical-align: middle;
}

/* Footer */
.footer {
  margin-top: 3rem;
  padding: 1.5rem 0 2rem;
  border-top: 1px solid var(--border);
  font-size: .85rem;
  color: var(--text-muted);
  text-align: center;
}
.footer p { margin: .35rem 0; }
.footer .donate { font-weight: 500; color: var(--text); }

/* Modal */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0;
  background: rgba(10, 20, 35, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal__dialog {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  max-width: 480px; width: 100%;
  padding: 1.5rem;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal__title { margin-top: 0; }
.modal__body { font-size: .95rem; }
.modal__actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* Saved list */
.saved-list {
  list-style: none;
  padding: 0;
  margin: .5rem 0 0;
}
.saved-list li {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  margin-bottom: .35rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  font-size: .88rem;
}

/* Notice / status */
.notice {
  padding: .5rem .85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .9rem;
}
.notice--success { background: #e6f6ec; color: #146a39; border: 1px solid #a3d9b9; }
.notice--error { background: #fdecea; color: #962b22; border: 1px solid #f0b3ad; }
[data-theme="dark"] .notice--success { background: #163a25; color: #a3d9b9; border-color: #2c5e3e; }
[data-theme="dark"] .notice--error { background: #3a1815; color: #f0b3ad; border-color: #6b2a22; }

/* Ad slots */
.ad-slot {
  margin: 1.5rem 0;
  min-height: 90px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  color: var(--text-muted);
}

/* Helpers */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.text-center { text-align: center; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 2rem; }
.mb-1 { margin-bottom: 1rem; }

/* Print */
@media print {
  .header__tools, .form-actions, .ad-slot, .footer, .modal, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .results, .compare { box-shadow: none; border-color: #888; }
}