:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --subtext: #475569;
  --muted: #94a3b8;
  --blue: #1b76df;
  --blue-dark: #1558b0;
  --blue-light: #eff6ff;
  --blue-mid: #dbeafe;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-border: #a7f3d0;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --orange: #d97706;
  --orange-bg: #fffbeb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.05), 0 10px 40px rgba(0,0,0,0.1);
  --radius: 14px;
  --radius-sm: 8px;
  --transition: 0.18s ease;
}

[data-theme="dark"] {
  --bg: #0a0f1a;
  --surface: #111827;
  --surface2: #1a2235;
  --border: #1e2d45;
  --text: #f1f5f9;
  --subtext: #94a3b8;
  --muted: #475569;
  --blue-light: #0f1f3d;
  --blue-mid: #1e3a5f;
  --green-bg: #052e16;
  --green-border: #064e3b;
  --red-bg: #1f0a0a;
  --orange-bg: #1c1204;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.3), 0 10px 40px rgba(0,0,0,0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Scope theme transitions only to elements that actually change colour */
body, .card, .result-hero, .result-tile, .hero, .support-card,
.site-header, .theme-btn, .field input, .field select,
.module-tab, .action-btn, .stress-box, .share-url-box {
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.page-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  object-fit: cover;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--blue);
}

.brand-tag {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.header-actions { display: flex; align-items: center; gap: 10px; }

.theme-btn {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--subtext);
  display: flex;
  align-items: center;
  gap: 5px;
}

.theme-btn:hover { border-color: var(--blue); color: var(--blue); }

.hero {
  text-align: center;
  margin-bottom: 32px;
  padding: 32px 20px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--blue), #60a5fa, var(--blue));
}

.hero h1 {
  font-size: clamp(22px, 4vw, 32px);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.hero p { font-size: 15px; color: var(--subtext); }

/* TRUST STRIP */
.trust-strip {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: -18px;
  margin-bottom: 20px;
}

.tip {
  background: #f8fafc;
  border-left: 3px solid #1b76df;
  padding: 10px;
  border-radius: 8px;
  font-size: 12px;
  margin-bottom: 8px;
  color: var(--subtext);
}

[data-theme="dark"] .tip {
  background: var(--surface2);
  color: var(--text);
}

.chart-summary {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

#calculateBtn {
  font-size: 16px;
  padding: 14px;
  background: linear-gradient(135deg, #1b76df, #2563eb);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 22px;
  margin-bottom: 18px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon {
  width: 28px;
  height: 28px;
  background: var(--blue-light);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

@media (max-width: 600px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--subtext);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-wrap { position: relative; }

.input-prefix,
.input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  pointer-events: none;
}

.input-prefix { left: 11px; }
.input-suffix { right: 11px; }

.field input,
.field select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface2);
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.03);
}

.field input.has-prefix { padding-left: 26px; }
.field input.has-suffix { padding-right: 32px; }

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  background: var(--surface);
}

.field input::placeholder { color: var(--muted); }

.dp-toggle {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 5px;
}

.dp-btn {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--subtext);
}

.dp-btn.active { background: var(--blue); color: #fff; }

.primary-btn {
  width: 100%;
  padding: 13px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  position: sticky;
  bottom: 10px;
  z-index: 10;
}

.primary-btn:hover { background: var(--blue-dark); transform: translateY(-1px); }
.primary-btn:active { transform: translateY(0); }

/* results section reveal */
#resultsSection { 
  display: none; 
  opacity: 0;
  transition: opacity 0.3s ease;
}
#resultsSection.show { 
  display: block; 
  opacity: 1;
}

.result-hero {
  background: linear-gradient(135deg, #1b76df, #2563eb);
  border-radius: 16px;
  padding: 28px;
  margin-bottom: 16px;
  color: #fff;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.result-hero::after {
  content: "";
  position: absolute;
  top: -40px;
  right: -40px;
  width: 160px;
  height: 160px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
}

.result-hero .payment-label { font-size: 13px; opacity: 0.8; margin-bottom: 4px; }

.result-hero .payment-amount {
  font-size: 42px;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
  letter-spacing: -1px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.result-hero .payment-sub {
  font-size: 13px;
  opacity: 0.7;
  margin-top: 4px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  .result-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 420px) {
  .result-grid { grid-template-columns: 1fr; }
}

/* STAGGER ANIMATIONS */
.result-tile {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  animation: fadeUp 0.4s ease forwards;
}

.result-tile:nth-child(1) { animation-delay: 0.05s; }
.result-tile:nth-child(2) { animation-delay: 0.1s; }
.result-tile:nth-child(3) { animation-delay: 0.15s; }

.result-tile .tile-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.result-tile .tile-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-family: 'DM Mono', monospace;
}

.result-tile .tile-value.green { color: var(--green); }
.result-tile .tile-value.red { color: var(--red); }
.result-tile .tile-value.blue { color: var(--blue); }

/* INTEREST HIGHLIGHT */
.breakdown-row .row-val.red {
  font-weight: 700;
  color: #b91c1c;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.breakdown-row:last-child { border-bottom: none; }

.breakdown-row .row-label { color: var(--subtext); }

.breakdown-row .row-val {
  font-weight: 600;
  font-family: 'DM Mono', monospace;
}

.breakdown-row.total-row {
  font-weight: 700;
  font-size: 14px;
  border-top: 2px solid var(--border);
  padding-top: 11px;
  margin-top: 4px;
}

.breakdown-row.total-row .row-val { color: var(--blue); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge.green { background: var(--green-bg); color: var(--green); border: 1px solid var(--green-border); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.orange { background: var(--orange-bg); color: var(--orange); }
.badge.blue { background: var(--blue-light); color: var(--blue); }

.stress-box {
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 12px;
  border: 1.5px solid var(--border);
}

.stress-box.pass { background: var(--green-bg); border-color: var(--green-border); }
.stress-box.fail { background: var(--red-bg); border-color: var(--red); }

.stress-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.stress-box.pass .stress-title { color: var(--green); }
.stress-box.fail .stress-title { color: var(--red); }

.stress-sub { font-size: 12px; color: var(--subtext); }

.module-section { display: none; }
.module-section.active { display: block; }

.module-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.module-tab {
  padding: 7px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--subtext);
}

.module-tab:hover { border-color: var(--blue); color: var(--blue); }
.module-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.amort-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-family: 'DM Mono', monospace;
}

.amort-table th {
  text-align: left;
  padding: 8px 10px;
  background: var(--surface2);
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: inherit;
  font-weight: 600;
}

.amort-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.amort-table tr:last-child td { border-bottom: none; }
.amort-table tr:hover td { background: var(--surface2); }

.table-wrap {
  max-height: 280px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* PREMIUM ACTION ROW */
.action-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  background: var(--surface2);
  padding: 10px;
  border-radius: var(--radius-sm);
}

.action-btn {
  padding: 10px 16px;
  background: var(--surface);
  color: var(--blue);
  border: 1.5px solid var(--blue);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease;
  opacity: 0.9;
}

.action-btn:hover {
  background: var(--blue);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.action-btn.success {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

#chartWrap { 
  margin-top: 12px;
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--border);
}

#mortgageChart { max-height: 260px; }

.support-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px;
  text-align: center;
  margin-bottom: 16px;
}

.bmc-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 9px;
  background: #FFDD00;
  color: #000;
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
}

.bmc-btn:hover { background: #f0ce00; transform: translateY(-1px); }

.support-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }

.site-footer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding-top: 8px;
}

.site-footer a { color: var(--blue); text-decoration: none; }

/* SAFETY MESSAGE */
.safe-note {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
}
.tooltip-wrap { 
  position: relative; 
  display: inline-flex; 
}

.tooltip-icon {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--border);
  color: var(--subtext);
  font-size: 9px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  margin-left: 4px;
}

.tooltip-box {
  display: none;
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  font-size: 11px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 7px;
  width: max-content;
  max-width: min(220px, 90vw);
  z-index: 99;
  pointer-events: none;
}

.tooltip-box::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #1e293b;
}

.tooltip-wrap:hover .tooltip-box { display: block; }

.error-msg {
  color: #dc2626;
  font-size: 12px;
  margin-top: 4px;
}

.input-error {
  border: 2px solid #dc2626 !important;
  background: #fef2f2;
}

.share-url-box {
  display: none;
  margin-top: 10px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.share-url-box input {
  width: 100%;
  background: none;
  border: none;
  font-size: 12px;
  font-family: 'DM Mono', monospace;
  color: var(--subtext);
  outline: none;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* ANIMATIONS */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-up { animation: fadeUp 0.4s ease forwards; }

/* PRINT MODE */
@media print {
  body {
    background: white;
    color: black;
  }

  .site-header,
  .support-card,
  .action-row,
  #themeBtn,
  #chartWrap {
    display: none !important;
  }

  .card, .result-hero {
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .page-wrap {
    max-width: 100%;
    padding: 0;
  }
}

/* ACCESSIBILITY FOCUS */
button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

/* MOBILE CARD SPACING */
@media (max-width: 600px) {
  .card {
    padding: 18px;
  }
}

.trust-strip {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin-top: -18px;
  margin-bottom: 20px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.feedback-box {
  font-size: 13px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-top: 16px;
  text-align: center;
}

[data-theme="dark"] .feedback-box {
  background: var(--surface2);
}

.rating-box {
  text-align: center;
  margin-top: 12px;
  padding: 12px;
}

.rating-buttons {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.rating-buttons button {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.rating-response {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
