/* ═══════════════════════════════════════════════
   MoneyTools — Shared Stylesheet
   Linked from every page via <link rel="stylesheet" href="/styles.css">
═══════════════════════════════════════════════ */

/* ── Design Tokens ────────────────────────────── */
:root {
  --bg:         #f2f7f4;
  --surface:    #ffffff;
  --border:     #c8ddd2;
  --accent:     #007a40;
  --accent-dim: #007a4014;
  --text:       #0d1c12;
  --muted:      #496658;
  --gold:       #9a6c08;
  --red:        #c0390b;
  --red-dim:    #c0390b10;
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  18px;
  --site-max:   960px;  /* Fixed — nav and footer always this width */
}

/* ── Reset ────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ─────────────────────────────────────── */
body {
  background: linear-gradient(170deg, #e4f2ea 0%, #f2f7f4 28%, #f2f7f4 100%);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px 64px;
  overflow-x: hidden;
}

/* Offset for sticky nav so content isn't hidden on page load */
.site-nav + * { margin-top: 32px; }

/* Ambient glow */
body::before {
  content: '';
  position: fixed;
  top: -150px;
  left: 50%;
  transform: translateX(-50%);
  width: 900px;
  height: 600px;
  background: radial-gradient(circle, #007a401c 0%, transparent 65%);
  pointer-events: none;
  z-index: -1;
}

/* ── Navigation ───────────────────────────────── */
.site-nav {
  width: 100%;
  max-width: var(--site-max);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border), 0 4px 20px rgba(0, 80, 40, 0.05);
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  background: rgba(242, 247, 244, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 100;
}

/* Prevent sticky nav from overlapping jump targets */
/* scrollbar-gutter: stable prevents layout shift when scrollbar appears/disappears */
html { scroll-padding-top: 80px; scrollbar-gutter: stable; }

.nav-brand {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
  color: var(--text);
  text-decoration: none;
  flex-shrink: 0;
}
.nav-brand span { color: var(--accent); }

.nav-links { display: flex; gap: 4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.nav-links::-webkit-scrollbar { display: none; }

.nav-links a {
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  transition: color .2s, background .2s;
  white-space: nowrap;
}
.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Page Header ──────────────────────────────── */
.page-header {
  text-align: center;
  margin-bottom: 24px;
  max-width: var(--nav-max, 900px);
  width: 100%;
  animation: fadeDown .55s ease both;
}
.page-header .eyebrow {
  font-size: 11px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}
.page-header h1 {
  font-family: 'DM Serif Display', serif;
  font-size: clamp(26px, 4vw, 40px);
  font-weight: 400;
  line-height: 1.15;
}
.page-header h1 em { font-style: italic; color: var(--gold); }
.page-header p {
  margin-top: 10px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.75;
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

/* ── Card ─────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  width: 100%;
  max-width: var(--nav-max, 900px);
  box-shadow: 0 1px 3px rgba(0,60,30,0.05), 0 8px 28px rgba(0,60,30,0.07);
  animation: fadeUp .65s ease .1s both;
}
@media (max-width: 480px) {
  .card { padding: 24px 18px; }
}

/* ── Grid Helpers ─────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.span-2 { grid-column: 1 / -1; }

@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ── Form Fields ──────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 8px; }

label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}

.input-wrap { position: relative; display: flex; align-items: center; }

.prefix {
  position: absolute;
  left: 13px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
}
.suffix {
  position: absolute;
  right: 13px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
}

input[type="number"],
input[type="text"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 15px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23496658' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.has-prefix input { padding-left: 27px; }
.has-suffix input,
.has-suffix select { padding-right: 38px; }

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Keyboard navigation — show focus ring only for keyboard users */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Range input */
input[type="range"] {
  width: 100%;
  height: 3px;
  background: var(--border);
  border-radius: 99px;
  outline: none;
  -webkit-appearance: none;
  cursor: pointer;
  margin-top: 4px;
  accent-color: var(--accent);
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
}
.range-field { grid-column: 1 / -1; }

/* ── Calculate Button ─────────────────────────── */
.calc-btn-wrap {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-start;
  margin-top: 4px;
}

.calc-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #ffffff;
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  padding: 13px 28px;
  cursor: pointer;
  transition: opacity .15s, transform .1s, box-shadow .2s;
  box-shadow: 0 0 0 0 #007a4030;
}
.calc-btn:hover {
  opacity: .88;
  box-shadow: 0 2px 12px #007a4030;
}
.calc-btn:active { transform: scale(.97); }

@keyframes btnPulse {
  0%   { box-shadow: 0 0 0 0 #007a4040; }
  70%  { box-shadow: 0 0 0 10px #007a4000; }
  100% { box-shadow: 0 0 0 0 #007a4000; }
}
.calc-btn.did-calc { animation: btnPulse .5s ease; }

/* Stale state — inputs changed, button needs clicking */
@keyframes btnStale {
  0%, 100% { box-shadow: 0 0 8px #007a4040; }
  50%       { box-shadow: 0 0 18px #007a4070, 0 0 32px #007a4020; }
}
.calc-btn.needs-calc { animation: btnStale 1.6s ease-in-out infinite; }

/* ── Divider ──────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

/* ── Result Boxes ─────────────────────────────── */
.results-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 24px;
}
.results-row.two   { grid-template-columns: repeat(2, 1fr); }
.results-row.four  { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 600px) {
  .results-row,
  .results-row.two,
  .results-row.four { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 380px) {
  .results-row,
  .results-row.two,
  .results-row.four { grid-template-columns: 1fr; }
}

.result-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px 16px;
  text-align: center;
  transition: border-color .3s;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.03);
}
.result-box.highlight {
  border-color: var(--accent);
  background: linear-gradient(145deg, #e2f5eb, #f0faf5);
  box-shadow: 0 2px 12px rgba(0, 122, 64, 0.12);
}
.result-box.warn {
  border-color: var(--red);
  background: var(--red-dim);
}
.result-box .r-label {
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.result-box .r-value {
  font-family: 'DM Serif Display', serif;
  font-size: 30px;
  color: var(--text);
}
.result-box.highlight .r-value { color: var(--accent); }
.result-box.warn      .r-value { color: var(--red); }
.result-box .r-sub { font-size: 11px; color: var(--muted); margin-top: 5px; }

/* ── Section Panels (budget / net worth) ──────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0,60,30,0.04), 0 4px 16px rgba(0,60,30,0.06);
}
.panel-title {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.panel-title.income      { color: var(--accent); }
.panel-title.expense     { color: var(--red); }
.panel-title.assets      { color: var(--accent); }
.panel-title.liabilities { color: var(--red); }

/* Line-item rows */
.line-item { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.line-item input[type="text"] {
  flex: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .2s;
}
.line-item input[type="number"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 13px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .2s;
  appearance: none;
}
.line-item input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.line-item input:focus { border-color: var(--accent); }

.del-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color .2s;
}
.del-btn:hover { color: var(--red); }

.add-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 10px 14px;
  cursor: pointer;
  width: 100%;
  margin-top: 4px;
  transition: border-color .2s, color .2s;
}
.add-btn:hover { border-color: var(--accent); color: var(--accent); }

.panel-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.pt-label {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
}
.pt-val {
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
}
.pt-val.income,
.pt-val.assets      { color: var(--accent); }
.pt-val.expense,
.pt-val.liabilities { color: var(--red); }

/* ── Section Label ────────────────────────────── */
.section-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
}

/* ── Status Banner ────────────────────────────── */
.status-banner {
  width: 100%;
  max-width: var(--nav-max, 900px);
  margin-top: 20px;
  border-radius: 12px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 14px;
  animation: fadeUp .65s ease .2s both;
}
.status-banner.good { background: #00e87a12; border: 1px solid var(--accent); }
.status-banner.bad  { background: var(--red-dim); border: 1px solid var(--red); }
.status-icon { font-size: 22px; }
.status-text { font-size: 14px; line-height: 1.7; color: var(--text); }

/* ── Ad Slot ──────────────────────────────────── */
.ad-slot {
  width: 100%;
  max-width: var(--nav-max, 900px);
  margin: 16px 0;
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--border);
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

/* ── Content Section ──────────────────────────── */
.content-section {
  max-width: var(--nav-max, 900px);
  width: 100%;
  margin-top: 32px;
}
.content-section h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}
.content-section h3 {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  font-weight: 400;
  color: var(--gold);
  margin: 20px 0 8px;
}
.content-section p {
  font-size: 14px;
  line-height: 1.85;
  color: var(--muted);
  margin-bottom: 12px;
}

/* ── FAQ Accordion ────────────────────────────── */
.faq-item { border-bottom: 1px solid var(--border); padding: 18px 0; }
.faq-item:last-child { border-bottom: none; }
.faq-q {
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
  gap: 12px;
}
.faq-q::after {
  content: '+';
  color: var(--accent);
  font-size: 20px;
  flex-shrink: 0;
  transition: transform .2s;
}
.faq-item.open .faq-q::after { transform: rotate(45deg); }
.faq-a {
  font-size: 14px;
  color: var(--muted);
  line-height: 1.8;
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease;
}
.faq-item.open .faq-a { max-height: 400px; padding-top: 12px; }

/* ── Formula Box ──────────────────────────────── */
.formula-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 16px 20px;
  font-size: 15px;
  color: var(--text);
  margin: 16px 0;
  letter-spacing: 1px;
}

/* ── Bar Chart ────────────────────────────────── */
.bars {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 160px;
  padding: 0 4px;
}
.bar-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}
.bar-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  height: 140px;
  gap: 2px;
}
.bar-interest {
  background: var(--accent);
  opacity: .85;
  border-radius: 3px 3px 0 0;
  width: 100%;
  min-height: 1px;
  transition: height .6s cubic-bezier(.34, 1.56, .64, 1);
}
.bar-principal {
  background: var(--gold);
  opacity: .7;
  width: 100%;
  min-height: 2px;
  transition: height .6s cubic-bezier(.34, 1.56, .64, 1);
}
.bar-contrib {
  background: var(--gold);
  opacity: .7;
  width: 100%;
  border-radius: 0;
  transition: height .5s ease;
}
.bar-growth {
  background: var(--accent);
  opacity: .8;
  border-radius: 3px 3px 0 0;
  width: 100%;
  transition: height .5s ease;
}
.bar-label { font-size: 10px; color: var(--muted); text-align: center; }

.legend {
  display: flex;
  gap: 24px;
  justify-content: center;
  margin-top: 12px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.legend-dot { width: 10px; height: 10px; border-radius: 2px; }

/* ── Data Table ───────────────────────────────── */
.table-wrap {
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.data-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }

/* ── Toggle Row ───────────────────────────────── */
.toggle-row { display: flex; gap: 8px; margin-bottom: 20px; }
.tog {
  flex: 1;
  padding: 11px;
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--muted);
  transition: all .2s;
  font-family: 'DM Mono', monospace;
}
.tog.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Footer ───────────────────────────────────── */
footer {
  max-width: var(--site-max);
  width: 100%;
  margin-top: 48px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
footer p { font-size: 12px; color: var(--muted); letter-spacing: 0.5px; }
footer nav { display: flex; gap: 16px; }
footer nav a {
  font-size: 12px;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: color .2s;
}
footer nav a:hover { color: var(--accent); }

/* ── Mobile ───────────────────────────────────── */
@media (max-width: 640px) {

  /* Reduce body padding so content has more room */
  body { padding-left: 16px; padding-right: 16px; padding-bottom: 48px; }

  /* Bleed sticky nav background to full viewport width */
  .site-nav {
    margin-left:  -16px;
    margin-right: -16px;
    padding-left:  16px;
    padding-right: 16px;
    width: calc(100% + 32px);
    max-width: none;
    padding-top: 12px;
    padding-bottom: 12px;
    gap: 8px;
  }

  /* Give nav-links a fixed width so overflow-x: auto kicks in correctly */
  .nav-links {
    width: 100%;
    padding-bottom: 2px; /* breathing room above bottom border */
  }

  /* Page header tighter */
  .page-header { margin-bottom: 16px; }
  .page-header p { font-size: 13px; }

  /* Prevent iOS Safari from zooming on input focus (triggers below 16px) */
  input, select, textarea { font-size: 16px; }

  /* Bar chart: allow bars to shrink below their label width */
  .bar-group { min-width: 0; }
  .bar-label { font-size: 9px; }

  /* Mortgage amortisation table: horizontal scroll */
  .table-wrap { overflow-x: auto; }

  /* Footer: stack on narrow screens */
  footer { flex-direction: column; align-items: flex-start; gap: 12px; }
}

@media (max-width: 400px) {
  .nav-brand { font-size: 17px; }
  .nav-links a { font-size: 10px; padding: 5px 7px; }
  .page-header h1 { font-size: clamp(22px, 6vw, 32px); }
}

/* ── Animations ───────────────────────────────── */
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes resultFlash {
  0%   { opacity: 1; }
  30%  { opacity: 0.5; }
  100% { opacity: 1; }
}
.r-value.refreshing { animation: resultFlash .3s ease; }
