/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --primary: #7d2e1e;        /* deep terracotta / rust */
  --primary-hover: #6b2519;
  --primary-light: #f5ede9;
  --accent: #c0512f;         /* warm rust accent */
  --bg: #e8e0d8;             /* warm beige */
  --bg-dark: #dfd7ce;
  --surface: #f0ebe4;        /* card surface */
  --surface-2: #ede7df;
  --border: #d4ccc3;
  --text: #2a1f1a;           /* dark brown */
  --text-muted: #7a6e67;
  --shadow: 0 1px 3px rgba(42,31,26,0.08);
  --shadow-md: 0 4px 12px rgba(42,31,26,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

/* ── Language Toggle ────────────────────────────────────────────────────────── */
[data-es] { display: none !important; }
body.lang-es [data-en] { display: none !important; }
body.lang-es [data-es] { display: revert !important; }
body.lang-es span[data-es] { display: inline !important; }
body.lang-es li[data-es] { display: list-item !important; }
body.lang-es a[data-es] { display: block !important; }

.lang-switcher { display: flex; gap: 0.3rem; align-items: center; margin-left: 0.75rem; }
.lang-btn-en, .lang-btn-es {
  padding: 0.22rem 0.65rem; border-radius: 20px; border: 1.5px solid var(--border);
  background: transparent; font-size: 0.75rem; font-weight: 700; cursor: pointer;
  font-family: inherit; color: var(--text-muted); transition: all 0.15s; letter-spacing: 0.03em;
}
.lang-btn-en.active, .lang-btn-es.active { background: var(--primary); border-color: var(--primary); color: white; }
.lang-btn-en:hover:not(.active), .lang-btn-es:hover:not(.active) { background: var(--surface-2); color: var(--text); }

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; font-size: 15px; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
header { background: var(--bg); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
nav { max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; display: flex; align-items: center; justify-content: space-between; height: 58px; }
.logo { font-size: 1rem; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; letter-spacing: -0.01em; }
#navLinks { display: flex; gap: 0.1rem; list-style: none; }
#navLinks a { padding: 0.4rem 0.85rem; border-radius: 20px; color: var(--text-muted); font-size: 0.875rem; font-weight: 500; transition: all 0.15s; }
#navLinks a:hover, #navLinks a.active { background: var(--surface-2); color: var(--text); text-decoration: none; }
#menuToggle { display: none; background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text); }

/* ── Hero ───────────────────────────────────────────────────────────────────── */
.hero { background: var(--bg); text-align: center; padding: 3.5rem 1.5rem 3rem; border-bottom: 1px solid var(--border); }
.hero-badge { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 0.3rem 0.9rem; font-size: 0.8rem; color: var(--text-muted); font-weight: 500; margin-bottom: 1.5rem; }
.hero h1 { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; color: var(--text); line-height: 1.15; letter-spacing: -0.03em; margin-bottom: 0.6rem; }
.hero h1 span { color: var(--accent); }
.hero p { font-size: 1rem; color: var(--text-muted); max-width: 480px; margin: 0 auto 1.5rem; }
.hero-badges { display: flex; justify-content: center; gap: 1.5rem; flex-wrap: wrap; }
.hero-badge-item { font-size: 0.82rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.3rem; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.main-wrap { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.calc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 900px) { .calc-grid { grid-template-columns: 1fr; } }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.card-title { font-size: 0.875rem; font-weight: 700; color: var(--text); margin-bottom: 1.25rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.45rem; letter-spacing: -0.01em; }
.card-title svg { color: var(--accent); flex-shrink: 0; }
.logo svg { color: var(--accent); flex-shrink: 0; }

/* ── Form ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.3rem; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input, .form-group select {
  width: 100%; padding: 0.55rem 0.85rem; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.9rem; font-family: inherit;
  color: var(--text); background: var(--bg); transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(192,81,47,0.12);
}
.input-prefix-wrap { position: relative; }
.input-prefix-wrap .prefix { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.85rem; pointer-events: none; }
.input-prefix-wrap input { padding-left: 1.5rem; }
.input-suffix-wrap { position: relative; }
.input-suffix-wrap .suffix { position: absolute; right: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 0.85rem; pointer-events: none; }
.input-suffix-wrap input { padding-right: 2rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.2rem; }
.btn-row { display: flex; gap: 0.75rem; margin-top: 1.25rem; flex-wrap: wrap; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn { padding: 0.55rem 1.25rem; border-radius: 20px; border: none; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: inherit; letter-spacing: -0.01em; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-accent { background: var(--accent); color: white; }
.btn-accent:hover { background: var(--primary); }
.btn-sm { padding: 0.38rem 0.9rem; font-size: 0.82rem; }

/* ── Results Panel ──────────────────────────────────────────────────────────── */
.results-panel { position: sticky; top: 74px; }
.results-total { background: var(--primary); color: white; border-radius: var(--radius); padding: 1.75rem 1.5rem; margin-bottom: 1rem; text-align: center; }
.results-total .label { font-size: 0.75rem; opacity: 0.75; margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.results-total .amount { font-size: 2.8rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.results-total .sub { font-size: 0.78rem; opacity: 0.65; margin-top: 0.4rem; }

.breakdown-list { list-style: none; }
.breakdown-list li { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--border); font-size: 0.875rem; }
.breakdown-list li:last-child { border-bottom: none; }
.breakdown-list .res-label { color: var(--text-muted); }
.breakdown-list .res-val { font-weight: 600; font-variant-numeric: tabular-nums; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 1rem; }
.summary-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.75rem 1rem; }
.summary-item .s-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.summary-item .s-val { font-size: 0.95rem; font-weight: 700; color: var(--text); margin-top: 0.15rem; }

/* ── PMI Warning ────────────────────────────────────────────────────────────── */
#pmiWarning { background: #fef6ee; border: 1px solid #e8b97a; border-radius: var(--radius-sm); padding: 0.6rem 0.9rem; font-size: 0.82rem; color: #7a4a1a; display: none; margin-bottom: 0.75rem; }

/* ── Error ──────────────────────────────────────────────────────────────────── */
#calcError { background: #fdecea; border: 1px solid #e8a09a; border-radius: var(--radius-sm); padding: 0.6rem 0.9rem; font-size: 0.85rem; color: #7a1a1a; display: none; margin-bottom: 0.75rem; }

/* ── Charts ─────────────────────────────────────────────────────────────────── */
.charts-section { margin-top: 1.5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 700px) { .charts-section { grid-template-columns: 1fr; } }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.chart-wrap h3 { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 1rem; }
canvas { max-height: 240px; }

/* ── Tools Tabs ─────────────────────────────────────────────────────────────── */
.tools-section { margin-top: 1.5rem; }
.tabs { display: flex; gap: 0.4rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.tab-btn { padding: 0.4rem 1rem; border-radius: 20px; border: 1.5px solid var(--border); background: transparent; color: var(--text-muted); font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.tab-btn:hover:not(.active) { background: var(--surface-2); color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tool-result { background: var(--primary-light); border: 1px solid #d9b8ae; border-radius: var(--radius-sm); padding: 0.85rem 1rem; margin-top: 0.75rem; font-size: 0.88rem; color: var(--primary); font-weight: 500; }

/* ── Amortization Table ─────────────────────────────────────────────────────── */
.schedule-section { margin-top: 1.5rem; }
#schedulePanel { display: none; overflow-x: auto; margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.amort-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.amort-table th { background: var(--primary); color: white; padding: 0.65rem 0.75rem; text-align: right; font-weight: 600; white-space: nowrap; }
.amort-table th:first-child { text-align: center; }
.amort-table td { padding: 0.45rem 0.75rem; text-align: right; border-bottom: 1px solid var(--border); }
.amort-table td:first-child { text-align: center; color: var(--text-muted); }
.amort-table tr.even-year { background: var(--bg-dark); }
.amort-table tr:hover { background: var(--primary-light); }
.schedule-actions { display: flex; gap: 0.75rem; align-items: center; }

/* ── Compare Table ──────────────────────────────────────────────────────────── */
.compare-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 0.75rem; border-radius: var(--radius-sm); overflow: hidden; }
.compare-table th { background: var(--primary); color: white; padding: 0.6rem 0.75rem; text-align: center; }
.compare-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border); text-align: center; }
.compare-table tr.highlight td { background: var(--primary-light); font-weight: 700; color: var(--primary); }

/* ── Content Pages ──────────────────────────────────────────────────────────── */
.content-wrap { max-width: 820px; margin: 0 auto; padding: 2.5rem 1.5rem; }
.content-wrap h1 { font-size: 1.8rem; font-weight: 800; margin-bottom: 0.4rem; letter-spacing: -0.02em; }
.content-wrap .last-updated { color: var(--text-muted); font-size: 0.82rem; margin-bottom: 2rem; }
.content-wrap h2 { font-size: 1.05rem; font-weight: 700; margin: 2rem 0 0.6rem; color: var(--accent); letter-spacing: -0.01em; }
.content-wrap h3 { font-size: 0.95rem; font-weight: 700; margin: 1.25rem 0 0.4rem; color: var(--text); }
.content-wrap p { margin-bottom: 0.85rem; line-height: 1.75; color: #4a3d38; }
.content-wrap ul, .content-wrap ol { margin: 0.5rem 0 0.85rem 1.5rem; }
.content-wrap li { margin-bottom: 0.35rem; line-height: 1.7; color: #4a3d38; }
.disclaimer-box { background: #fef6ee; border: 1px solid #e8c49a; border-radius: var(--radius); padding: 1rem 1.25rem; margin: 1.5rem 0; }
.disclaimer-box strong { color: #7a4a1a; }

/* ── Manual TOC ─────────────────────────────────────────────────────────────── */
.manual-grid { display: grid; grid-template-columns: 210px 1fr; gap: 2rem; max-width: 1060px; margin: 0 auto; padding: 2.5rem 1.5rem; align-items: start; }
.toc { position: sticky; top: 74px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.toc h3 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 0.75rem; font-weight: 700; }
.toc a { display: block; font-size: 0.83rem; color: var(--text-muted); padding: 0.3rem 0.6rem; border-left: 2px solid transparent; transition: all 0.15s; border-radius: 0 4px 4px 0; }
.toc a:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; background: var(--primary-light); }
@media (max-width: 768px) { .manual-grid { grid-template-columns: 1fr; } .toc { position: static; } }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
footer { background: var(--surface); border-top: 1px solid var(--border); padding: 2rem 1.5rem; text-align: center; margin-top: 3rem; }
footer p { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; }
footer nav { margin-top: 0.75rem; }
footer nav a { font-size: 0.8rem; color: var(--text-muted); margin: 0 0.5rem; }
footer nav a:hover { color: var(--accent); }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #menuToggle { display: block; }
  #navLinks { display: none; position: absolute; top: 58px; left: 0; right: 0; background: var(--bg); flex-direction: column; padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); gap: 0.25rem; z-index: 99; }
  #navLinks.open { display: flex; }
  .form-row { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .results-panel { position: static; }
  .results-total .amount { font-size: 2.2rem; }
  .hero { padding: 2.5rem 1.5rem 2rem; }
}

@media print {
  header, footer, .btn-row, .tabs, #btnToggleSchedule { display: none; }
  body { background: white; }
  .card { border: 1px solid #ccc; }
}
