/* ─── DESIGN TOKENS ─────────────────────────────────────────────────────── */
:root {
  /* Brand — white + green */
  --navy:          #064E3B;
  --blue-bright:   #059669;
  --blue-light:    #ECFDF5;
  --blue-mid:      #10B981;
  --blue-dark:     #047857;
  --blue-text:     #064E3B;

  /* Calculator segment colors — used on donut chart + breakdown rows */
  --clr-pi:        #059669;
  --clr-tax:       #3B82F6;
  --clr-ins:       #F59E0B;

  /* Status badges */
  --green-light:   #D1FAE5;
  --green-text:    #065F46;
  --amber-light:   #FEF3C7;
  --amber-text:    #92400E;

  /* Neutrals */
  --gray-bg:       #F3F4F6;
  --gray-border:   rgba(0,0,0,0.10);
  --text-primary:  #151515;
  --text-muted:    #5A6472;
  --radius-md:     8px;
  --radius-lg:     12px;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-weight: 400;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--gray-bg);
}

a { color: var(--blue-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── PAGE HEADING (H1) ──────────────────────────────────────────────────── */
.page-heading {
  padding: 20px 0 4px;
  margin-bottom: 24px;
}

.page-heading h1 {
  font-size: 26px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 6px;
}

.page-subhead {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 640px;
}

/* ─── SECTION HEADINGS ───────────────────────────────────────────────────── */
.section-title {
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ─── AD UNITS ───────────────────────────────────────────────────────────── */
/* No margin/min-height by default — collapses to zero when AdSense has no fill.
   Spacing between sections comes from section { margin-bottom } instead. */
.ad-unit {
  text-align: center;
  background: transparent;
  overflow: hidden;
}

/* ─── FAQ SECTION (off-screen for indexing, not visible) ─────────────────── */
#faq-section {
  margin-top: 40px;
  border-top: 1px solid var(--gray-border);
  padding-top: 32px;
}
#faq-section h2 {
  font-size: 20px;
  font-weight: 500;
  margin-bottom: 20px;
  color: var(--text-primary);
}
#faq-section h3 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0;
}
#faq-section dt {
  margin-top: 16px;
}
#faq-section dd {
  font-size: 14px;
  color: var(--text-muted);
  margin-left: 0;
  padding-left: 0;
  margin-top: 4px;
  max-width: 760px;
}

/* ─── NAVBAR ─────────────────────────────────────────────────────────────── */
#navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--gray-border);
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
}

#navbar .brand,
#navbar a.brand {
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: -0.3px;
  text-decoration: none;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: 16px;
}

.nav-link {
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: var(--radius-md);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--gray-bg); color: var(--text-primary); text-decoration: none; }
.nav-link.active { color: var(--navy); font-weight: 500; }

#navbar .nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

#navbar .timestamp {
  font-size: 13px;
  color: var(--text-muted);
}

#refresh-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-md);
  background: #fff;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}
#refresh-btn:hover { background: var(--gray-bg); }
#refresh-btn .icon { font-size: 14px; }
#refresh-btn.spinning .icon { animation: spin 0.8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── BANNERS ────────────────────────────────────────────────────────────── */
.banner {
  margin: 16px 24px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  display: none;
}
.banner.visible { display: block; }
.banner-warning { background: #FFFBEA; border: 1px solid #F59E0B; color: #78350F; }
.banner-error   { background: #FEF2F2; border: 1px solid #EF4444; color: #7F1D1D; }

/* ─── MAIN LAYOUT ───────────────────────────────────────────────────────── */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}

section { margin-bottom: 40px; }

/* ─── CARD BASE ──────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

/* ─── FED BANNER CARD ────────────────────────────────────────────────────── */
#fed-banner {
  background: var(--blue-light);
  border: 0.5px solid rgba(5,150,105,0.25);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

#fed-banner .fed-left { flex: 1; min-width: 220px; }

#fed-banner .fed-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--blue-text);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

#fed-banner .source-badge {
  font-size: 11px;
  font-weight: 400;
  background: rgba(4,120,87,0.12);
  color: var(--blue-dark);
  padding: 2px 7px;
  border-radius: 99px;
}

#fed-banner .fed-rate {
  font-size: 32px;
  font-weight: 500;
  color: var(--blue-text);
  line-height: 1.1;
}

#fed-banner .fed-meta {
  font-size: 12px;
  color: var(--blue-dark);
  margin-top: 6px;
}

#fed-banner .fed-right { text-align: right; }

#fed-banner .direction-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 14px;
  font-weight: 500;
  padding: 4px 12px;
  border-radius: 99px;
}
.direction-up    { background: #FEE2E2; color: #991B1B; }
.direction-down  { background: var(--green-light); color: var(--green-text); }
.direction-stable{ background: var(--amber-light); color: var(--amber-text); }

#fed-banner .fomc-note {
  font-size: 12px;
  color: var(--blue-dark);
  margin-top: 6px;
}

/* ─── SORT SELECT (shared) ───────────────────────────────────────────────── */
.filter-group {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  padding: 3px;
}

/* ─── TOOLS GRID ─────────────────────────────────────────────────────────── */
.tools-section { margin-bottom: 28px; }
.tools-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.tool-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: #fff;
  border: 1px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.tool-card:hover { border-color: var(--blue-mid); box-shadow: 0 2px 10px rgba(1,87,255,0.1); text-decoration: none; }
.tool-icon { font-size: 24px; margin-bottom: 2px; }
.tool-title { font-size: 14px; font-weight: 600; color: var(--navy); }
.tool-desc  { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ─── RATE TABS ──────────────────────────────────────────────────────────── */
.rate-tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0;
  border-bottom: 2px solid var(--gray-border);
  padding-bottom: 0;
}
.rate-tab {
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.rate-tab:hover { color: var(--navy); }
.rate-tab.active { color: var(--navy); border-bottom-color: var(--blue-bright); font-weight: 600; }
.tabs-sort-right { margin-left: auto; padding-bottom: 6px; }

.sort-select {
  padding: 6px 10px;
  font-size: 13px;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

/* ─── RATES TABLE ────────────────────────────────────────────────────────── */
.rates-table-wrap {
  background: #fff;
  border: 1px solid var(--gray-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  overflow: hidden;
}
#rates-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#rates-table thead { background: var(--navy); color: #fff; }
#rates-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.col-action { width: 110px; text-align: right; }
.col-lender { min-width: 140px; }
.sortable-col::after { content: ' ↓'; opacity: 0.5; }

.rate-row td { padding: 12px 16px; border-bottom: 1px solid var(--gray-border); vertical-align: middle; }
.rate-row:last-child td { border-bottom: none; }
.rate-row:hover { background: var(--blue-light); }
.rate-row-applied { background: #ECFDF5 !important; }

.lender-name  { font-weight: 500; color: var(--text-primary); }
.rate-strong  { font-size: 15px; font-weight: 700; color: var(--navy); }
.no-rate      { color: var(--text-muted); }
.muted-cell   { color: var(--text-muted); font-size: 13px; }
.col-action   { text-align: right; }

.quote-btn {
  display: inline-block;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--blue-light);
  color: var(--blue-dark);
  border-radius: var(--radius-md);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.quote-btn:hover { background: var(--blue-bright); color: #fff; text-decoration: none; }

.table-footnote {
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 16px;
  background: var(--gray-bg);
  border-top: 1px solid var(--gray-border);
}

/* ─── HISTORICAL CHART ───────────────────────────────────────────────────── */
.chart-card { padding: 20px 20px 16px; }
.chart-building-msg {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; color: var(--text-muted); font-size: 14px;
}
.chart-building-msg span { font-size: 24px; }
#rate-trend-chart { max-height: 260px; width: 100%; }

/* ─── SKELETON LOADING ───────────────────────────────────────────────────── */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.skeleton {
  background: #E2E2DF;
  border-radius: 4px;
  animation: skeleton-pulse 1.4s ease-in-out infinite;
}

.skeleton-card {
  background: #fff;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.skel-line { height: 14px; border-radius: 3px; }
.skel-rate { height: 22px; width: 80px; border-radius: 3px; }
.skel-bar  { height: 5px; border-radius: 99px; }

.skeleton-fed {
  background: var(--blue-light);
  border: 0.5px solid rgba(5,150,105,0.25);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  display: flex;
  gap: 16px;
}

/* ─── CALCULATOR ─────────────────────────────────────────────────────────── */
#calculator-section .calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 768px) {
  #calculator-section .calc-grid { grid-template-columns: 1fr; }
}

.calc-panel { padding: 20px; overflow: hidden; }

.calc-field { margin-bottom: 16px; }

.calc-field label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.calc-field .field-hint {
  font-size: 11px;
  color: var(--blue-dark);
  margin-top: 3px;
}

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

.input-wrap .prefix,
.input-wrap .suffix {
  position: absolute;
  font-size: 14px;
  color: var(--text-muted);
  pointer-events: none;
  user-select: none;
}
.input-wrap .prefix { left: 10px; }
.input-wrap .suffix { right: 10px; }

.calc-input {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  outline: none;
  color: var(--text-primary);
  background: #fff;
  transition: border-color 0.12s;
}
.calc-input:focus { border-color: var(--blue-mid); }
.calc-input.has-prefix { padding-left: 22px; }
.calc-input.has-suffix { padding-right: 28px; }

/* down payment row */
.dp-row { display: flex; gap: 8px; }
.dp-row .input-wrap { flex: 1; }

/* term buttons */
.term-buttons { display: flex; gap: 4px; }
.term-btn {
  flex: 1;
  padding: 7px 0;
  font-size: 13px;
  border: 0.5px solid var(--gray-border);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.term-btn.active {
  background: var(--blue-dark);
  color: #fff;
  border-color: var(--blue-dark);
}

/* results panel */
.result-monthly {
  background: var(--navy);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  text-align: center;
  padding: 20px 16px 18px;
  margin: -20px -20px 0;
}

.result-monthly .label {
  font-size: 11px;
  color: rgba(255,255,255,0.65);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.result-monthly .amount {
  font-size: 38px;
  font-weight: 600;
  color: #fff;
  line-height: 1;
}

.breakdown {
  margin: 16px 0 12px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  padding: 6px 0;
  border-bottom: 0.5px solid var(--gray-border);
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-row .b-label {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.breakdown-row.bd-pi  .b-label::before,
.breakdown-row.bd-tax .b-label::before,
.breakdown-row.bd-ins .b-label::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.breakdown-row.bd-pi  .b-label::before { background: var(--clr-pi); }
.breakdown-row.bd-tax .b-label::before { background: var(--clr-tax); }
.breakdown-row.bd-ins .b-label::before { background: var(--clr-ins); }
.breakdown-row .b-value { font-weight: 600; }

.totals-divider {
  border: none;
  border-top: 0.5px solid var(--gray-border);
  margin: 12px 0;
}

.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text-muted);
}
.total-row .t-value { color: var(--text-primary); font-weight: 500; }

/* donut chart */
#amort-chart-wrap {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
#amort-chart-wrap .chart-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  align-self: flex-start;
}
#amort-canvas {
  display: block;
  width: 180px;
  height: 180px;
}

.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
  justify-content: center;
}
.legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

/* ─── FOOTER ─────────────────────────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--gray-border);
  background: #fff;
}
footer a { color: var(--blue-dark); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ─── NOSCRIPT RATE TABLE ────────────────────────────────────────────────── */
.noscript-rates {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  margin-top: 16px;
}
.noscript-rates th {
  background: var(--navy);
  color: #fff;
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
}
.noscript-rates td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--gray-border);
  color: var(--text-primary);
}
.noscript-rates tr:nth-child(even) td { background: var(--blue-light); }

/* ─── UTILITIES ──────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── RESPONSIVE: 768px (tablet) ────────────────────────────────────────── */
@media (max-width: 768px) {
  main { padding: 20px 20px 56px; }

  .page-heading h1 { font-size: 22px; }

  section { margin-bottom: 28px; }

  /* filter bar: stack filter buttons above sort dropdown */
  #filter-bar { flex-direction: column; align-items: flex-start; gap: 8px; }

  /* calculator: already 1-column via grid rule above */
  .calc-panel { padding: 16px; }
}

/* ─── RESPONSIVE: 480px (large phone) ───────────────────────────────────── */
@media (max-width: 480px) {
  main { padding: 16px 16px 48px; }

  section { margin-bottom: 20px; }

  /* navbar: hide timestamp and nav links to save space */
  #navbar { padding: 0 16px; height: 48px; }
  #navbar .timestamp { display: none; }
  .nav-links { display: none; }

  /* page heading */
  .page-heading { padding: 16px 0 0; margin-bottom: 16px; }
  .page-heading h1 { font-size: 20px; }
  .page-subhead { font-size: 13px; }

  /* fed banner */
  #fed-banner { flex-direction: column; padding: 16px; }
  #fed-banner .fed-right { text-align: left; }
  #fed-banner .fed-rate { font-size: 26px; }
  #fed-banner .fed-left { min-width: unset; }

  /* tabs */
  .rate-tab { padding: 8px 12px; font-size: 13px; }
  .tabs-sort-right { display: none; }
  .hide-mobile { display: none; }
  .tools-grid { grid-template-columns: repeat(2, 1fr); }

  /* calculator */
  .calc-panel { padding: 14px 12px; }
  .term-buttons { gap: 3px; }
  .term-btn { font-size: 12px; padding: 6px 0; }

  /* faq */
  #faq-section h2 { font-size: 17px; }
}

/* ─── RESPONSIVE: 375px (small phone) ───────────────────────────────────── */
@media (max-width: 375px) {
  main { padding: 12px 12px 40px; }

  #navbar .brand { font-size: 15px; }

  .page-heading h1 { font-size: 18px; }

  #fed-banner .fed-rate { font-size: 22px; }

  .tools-grid { grid-template-columns: 1fr 1fr; }
  #rates-table th, .rate-row td { padding: 9px 10px; font-size: 13px; }

  .calc-input { font-size: 13px; }
  .result-monthly .amount { font-size: 26px; }
}
