/* ==========================================================================
   LoanLens — Loan Repayment Calculator
   Minimalist professional theme, light + dark, one accent color.
   ========================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #16202e;
  --text-muted: #55617a;
  --border: #dfe5ee;
  --accent: #1d4ed8;
  --accent-hover: #1e40af;
  --accent-soft: #e8eefc;
  --accent-contrast: #ffffff;
  --accent-ring: rgba(29, 78, 216, 0.22);
  --danger: #b91c1c;
  --chart-muted: #94a3b8;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 10px 28px -14px rgba(15, 23, 42, 0.14);
  --radius: 14px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0e1320;
  --surface: #161d2e;
  --surface-2: #1e2740;
  --text: #e9edf5;
  --text-muted: #9fabbf;
  --border: #2b3752;
  --accent: #7aa5ff;
  --accent-hover: #95b8ff;
  --accent-soft: #223050;
  --accent-contrast: #0c1322;
  --accent-ring: rgba(122, 165, 255, 0.28);
  --danger: #f87171;
  --chart-muted: #64748b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

img, svg { display: inline-block; vertical-align: middle; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 12px; }
p { margin: 0 0 10px; }
ul { margin: 0 0 10px; padding-left: 22px; }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
}

[hidden] { display: none !important; }

::selection { background: var(--accent); color: var(--accent-contrast); }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Utilities ---------- */
.container {
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 20px;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 200;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  padding: 10px 16px;
  border-radius: 10px;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark { color: var(--accent); }
.brand-name { font-size: 1.18rem; font-weight: 800; letter-spacing: -0.01em; }
.brand-name span { color: var(--accent); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: none; }

/* ---------- Hero ---------- */
.hero { padding-top: 52px; padding-bottom: 6px; max-width: 860px; }
.hero-eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero h1 {
  font-size: clamp(1.9rem, 4.6vw, 2.7rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.hero-sub {
  font-size: 1.08rem;
  color: var(--text-muted);
  max-width: 640px;
}
.privacy-note {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 20px 0 0;
  padding: 9px 15px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
}
.privacy-note svg { color: var(--accent); flex: none; }

/* ---------- Advertisement slots ---------- */
.ad-slot { margin: 30px auto; max-width: 760px; text-align: center; }
.ad-label {
  margin: 0 0 6px;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.ad-box {
  display: grid;
  gap: 3px;
  justify-items: center;
  padding: 28px 16px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  color: var(--text-muted);
}
.ad-box-title { font-weight: 700; color: var(--text); }
.ad-box-sub { font-size: 0.8rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}
.card-title { font-size: 1.18rem; font-weight: 800; margin-bottom: 18px; }

/* ---------- Calculator layout ---------- */
.calculator { margin-top: 26px; }
.calc-grid {
  display: grid;
  grid-template-columns: minmax(0, 10fr) minmax(0, 11fr);
  gap: 24px;
  align-items: start;
}

/* ---------- Form ---------- */
.field { margin-bottom: 18px; border: 0; padding: 0; }

.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.93rem;
  margin-bottom: 7px;
}
.optional { color: var(--text-muted); font-weight: 500; font-size: 0.85em; }

input, select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder { color: var(--text-muted); opacity: 0.75; }

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

input[aria-invalid="true"] { border-color: var(--danger); }
input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }

input[type="number"] { font-variant-numeric: tabular-nums; }

.affix { position: relative; }
.affix-symbol {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 13px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
}
.affix input { padding-left: 38px; }
.affix-right .affix-symbol { left: auto; right: 13px; }
.affix-right input { padding-left: 12px; padding-right: 34px; }

.term-row { display: grid; grid-template-columns: minmax(0, 1fr) 148px; gap: 12px; }

.field-hint { margin: 6px 0 0; font-size: 0.82rem; color: var(--text-muted); }
.field-error { margin: 6px 0 0; font-size: 0.85rem; font-weight: 600; color: var(--danger); }
.form-error {
  margin: 14px 0 0;
  padding: 11px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Segmented frequency control */
.seg-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg-option { position: relative; display: block; }
.seg-option input {
  position: absolute;
  opacity: 0;
  width: 100%; height: 100%;
  margin: 0;
  cursor: pointer;
}
.seg-option span {
  display: block;
  text-align: center;
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
  font-size: 0.93rem;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.seg-option:hover span { border-color: var(--accent); }
.seg-option input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}
.seg-option input:focus-visible + span {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  border-radius: 10px;
  padding: 12px 20px;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary:disabled:hover { border-color: var(--border); color: var(--text); }
.btn-sm { padding: 8px 14px; font-size: 0.88rem; }

.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 22px;
  flex-wrap: wrap;
}
.form-actions .btn-primary { flex: 1 1 auto; }

/* ---------- Results ---------- */
.results-card { position: sticky; top: 84px; }

.results-empty {
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
  padding: 44px 18px;
  color: var(--text-muted);
}
.results-empty svg { color: var(--border); }
.results-empty strong { color: var(--text); }

.stat-hero { margin-bottom: 18px; }
.stat-label {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.stat-value {
  display: block;
  font-size: clamp(1.9rem, 4.5vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.chip {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 0 0 18px;
}
.stat {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 13px 15px;
}
.stat dt {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.stat dd {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.savings-card {
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 14px;
}
.savings-title { font-size: 0.95rem; font-weight: 800; margin-bottom: 12px; }
.savings-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 8px;
}
.savings-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.savings-value {
  display: block;
  font-size: 1.18rem;
  font-weight: 800;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.savings-value-sm { font-size: 0.98rem; line-height: 1.3; font-weight: 700; }

/* ---------- Chart ---------- */
.chart-section { margin-top: 44px; }
.section-title { font-size: 1.35rem; font-weight: 800; margin-bottom: 8px; }
.chart-card { margin-top: 14px; }
.chart-wrap {
  max-width: 430px;
  height: 320px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  position: relative;
}
.chart-wrap canvas { max-width: 100%; }
.fallback-chart { display: grid; justify-items: center; gap: 14px; }
.fallback-total { font-size: 17px; font-weight: 800; fill: var(--text); }
.fallback-sub { font-size: 9px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; fill: var(--text-muted); }
.fallback-legend {
  display: grid;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}
.fallback-legend strong { color: var(--text); font-variant-numeric: tabular-nums; }
.fallback-legend .dot {
  display: inline-block;
  width: 11px; height: 11px;
  border-radius: 3px;
  margin-right: 7px;
}

/* ---------- Schedule ---------- */
.schedule-section { margin-top: 44px; }
.schedule-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.schedule-section .card { margin-top: 14px; }

.table-wrap {
  overflow: auto;
  max-height: 520px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.schedule-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.schedule-table th,
.schedule-table td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.schedule-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-align: left;
}
.schedule-table thead th.num { text-align: right; }
.schedule-table tbody tr:nth-child(even) { background: rgba(125, 145, 175, 0.06); }
.schedule-table tbody tr:hover { background: var(--accent-soft); }
.schedule-table tfoot td {
  background: var(--surface-2);
  font-weight: 800;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.page-info { font-size: 0.85rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ---------- FAQ ---------- */
.faq { margin-top: 48px; }
.faq-list { display: grid; gap: 12px; max-width: 820px; margin-top: 14px; }
.faq-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 20px;
}
.faq-item summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 0;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: "+";
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  flex: none;
}
.faq-item[open] summary::after { content: "\2212"; }
.faq-item p {
  padding: 0 0 16px;
  color: var(--text-muted);
  line-height: 1.68;
  margin: 0;
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 60px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 36px;
  padding-top: 34px;
  padding-bottom: 22px;
}
.footer-logo { margin-bottom: 10px; }
.footer-nav { display: grid; gap: 9px; justify-items: start; align-content: start; }
.footer-nav-title {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.footer-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}
.footer-link:hover { text-decoration: underline; }
.footer-bottom {
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.84rem;
}
.footer-bottom p { margin: 0; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(680px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
}
dialog::backdrop { background: rgba(8, 12, 24, 0.55); }
dialog[open] { animation: dlg-in 0.18s ease-out; }
@keyframes dlg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.dialog-inner { max-height: min(80vh, 720px); overflow: auto; padding: 26px 28px; }
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.dialog-title { margin: 0; font-size: 1.3rem; font-weight: 800; }
.dialog-close {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.dialog-close:hover { border-color: var(--accent); color: var(--accent); }
.dialog-body h3 { font-size: 1rem; font-weight: 800; margin: 20px 0 6px; }
.dialog-body p { color: var(--text-muted); line-height: 1.66; margin: 0 0 10px; }
.dialog-body ul { color: var(--text-muted); line-height: 1.66; margin-bottom: 10px; }
.dialog-body a { color: var(--accent); }

/* ---------- Cookie bar ---------- */
.cookie-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 100;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px -14px rgba(15, 23, 42, 0.3);
  transform: translateY(105%);
  transition: transform 0.28s ease;
}
.cookie-bar.visible { transform: translateY(0); }
.cookie-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding-top: 14px;
  padding-bottom: 14px;
}
.cookie-text { margin: 0; font-size: 0.88rem; color: var(--text-muted); max-width: 720px; }
.cookie-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cookie-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- No-JS banner ---------- */
.noscript-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  padding: 12px 20px;
  text-align: center;
  font-weight: 700;
  background: var(--danger);
  color: #fff;
}

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .calc-grid { grid-template-columns: 1fr; }
  .results-card { position: static; }
  .footer-grid { grid-template-columns: 1fr; gap: 24px; }
}

@media (max-width: 560px) {
  .card { padding: 20px 18px; }
  .hero { padding-top: 36px; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .savings-grid { grid-template-columns: 1fr; gap: 12px; }
  .schedule-head { flex-direction: column; align-items: flex-start; }
  .cookie-inner { align-items: flex-start; flex-direction: column; }
  .dialog-inner { padding: 22px 20px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}
