/* === Loan Lab — design tokens + base layout =========================== */

:root {
  /* Light theme defaults — overridden by [data-theme] selectors below */
  --bg: #f6f3ec;
  --bg-2: #efece4;
  --surface: #ffffff;
  --surface-2: #fbfaf6;
  --ink: #131618;
  --ink-2: #4b5158;
  --ink-3: #8b9097;
  --ink-4: #b9bcc1;
  --line: #e6e2d8;
  --line-strong: #d6d2c6;
  --accent: oklch(0.46 0.08 165);
  --accent-ink: #ffffff;
  --accent-soft: oklch(0.94 0.03 165);
  --accent-line: oklch(0.86 0.06 165);
  --warn: oklch(0.65 0.16 55);
  --principal: oklch(0.46 0.08 165);
  --interest: oklch(0.72 0.13 60);
  --shadow: 0 1px 0 rgba(20, 23, 26, 0.04), 0 8px 24px -16px rgba(20, 23, 26, 0.18);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

[data-theme="dusk"] {
  --bg: #0f1113;
  --bg-2: #15181b;
  --surface: #1a1d20;
  --surface-2: #1f2326;
  --ink: #ecedef;
  --ink-2: #a6acb2;
  --ink-3: #71777e;
  --ink-4: #4a4f55;
  --line: #2a2e32;
  --line-strong: #353a3f;
  --accent: oklch(0.78 0.13 165);
  --accent-ink: #0c0e10;
  --accent-soft: oklch(0.28 0.05 165);
  --accent-line: oklch(0.4 0.07 165);
  --principal: oklch(0.78 0.13 165);
  --interest: oklch(0.78 0.13 60);
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4), 0 12px 40px -20px rgba(0, 0, 0, 0.7);
}

/* Accent overrides — apply on top of light or dusk theme via separate
   [data-accent] attribute so a user can pick dusk + indigo and BOTH apply. */
[data-accent="indigo"] {
  --accent: oklch(0.5 0.15 265);
  --accent-soft: oklch(0.94 0.04 265);
  --accent-line: oklch(0.86 0.07 265);
  --principal: oklch(0.5 0.15 265);
  --interest: oklch(0.7 0.13 30);
}
[data-accent="rose"] {
  --accent: oklch(0.55 0.16 25);
  --accent-soft: oklch(0.94 0.04 25);
  --accent-line: oklch(0.86 0.07 25);
  --principal: oklch(0.55 0.16 25);
  --interest: oklch(0.6 0.1 220);
}

/* Dusk + accent combos — slightly brighter accent so it pops on dark bg */
[data-theme="dusk"][data-accent="indigo"] {
  --accent: oklch(0.7 0.16 265);
  --accent-soft: oklch(0.32 0.06 265);
  --accent-line: oklch(0.45 0.08 265);
  --principal: oklch(0.7 0.16 265);
}
[data-theme="dusk"][data-accent="rose"] {
  --accent: oklch(0.72 0.16 25);
  --accent-soft: oklch(0.32 0.06 25);
  --accent-line: oklch(0.45 0.08 25);
  --principal: oklch(0.72 0.16 25);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}

body {
  min-height: 100vh;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  border: none;
  background: none;
  outline: none;
  padding: 0;
}

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

/* === App shell ======================================================== */

.app {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 32px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* === Navbar (app-style) ============================================== */

.navbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  margin: -28px -32px 20px;
  /* Safe-area aware so content clears the cutout on phones */
  padding-top: max(14px, calc(10px + env(safe-area-inset-top)));
}

.navbar-leading {
  display: flex;
  align-items: center;
  gap: 12px;
  grid-column: 1 / 2;
  min-width: 0;
}

.navbar-trailing {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  grid-column: 3 / 4;
}

.navbar-title-group {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.navbar-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar-subtitle {
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.navbar-title-centered {
  grid-column: 2 / 3;
  text-align: center;
  font-size: 17px;
}

.navbar-icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease;
  grid-column: 1 / 2;
  justify-self: start;
}

.navbar-icon-btn:hover,
.navbar-icon-btn:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.navbar-icon-btn .btn-icon {
  width: 18px;
  height: 18px;
}

.navbar-action {
  padding: 7px 14px;
  font-size: 13px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #131618;
  color: #f6f3ec;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex: none;
}

.brand-mark img {
  width: 24px;
  height: 24px;
  display: block;
  object-fit: contain;
}

.brand-name {
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 16px;
}

.brand-sub {
  font-size: 13px;
  color: var(--ink-3);
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Cards ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.card-title {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
}

/* === Layout grid ====================================================== */

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
  }
}


/* === Inputs ============================================================ */

.input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.field {
  background: var(--surface);
  padding: 22px 22px 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.15s ease;
}

.field.is-derived {
  background: var(--accent-soft);
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 8px;
}

.field.is-derived .field-label {
  color: var(--accent);
}

.solve-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.solve-toggle {
  font-size: 11px;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  transition: all 0.15s ease;
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.solve-toggle:hover {
  color: var(--ink);
  border-color: var(--ink-3);
}

.field-input-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.field-prefix,
.field-suffix {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--ink-3);
  font-weight: 400;
}

/* Inline unit toggle that replaces the static suffix on the tenure field */
.field-unit-toggle {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  align-self: center;
  flex: none;
}
.field-unit-toggle button {
  padding: 4px 10px;
  border-radius: 999px;
  color: var(--ink-3);
  transition: all 0.15s ease;
  line-height: 1;
}
.field-unit-toggle button:hover {
  color: var(--ink-2);
}
.field-unit-toggle button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.field-input {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  width: 100%;
  min-width: 0;
  padding: 0;
  font-feature-settings: "tnum";
}

.field.is-derived .field-input {
  color: var(--accent);
}

.field-input:focus {
  caret-color: var(--accent);
}

.field-helper {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--font-mono);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
}

.field-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  outline: none;
  margin-top: 4px;
}
.field-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.field-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.field-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink);
  cursor: pointer;
}

.field.is-derived .field-slider {
  opacity: 0.4;
}

/* === Recalc chooser (EMI field) ======================================== */

.recalc-chooser {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.recalc-label {
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.recalc-pills {
  display: inline-flex;
  background: var(--bg-2);
  border-radius: 999px;
  padding: 2px;
  gap: 0;
}

.recalc-pills button {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.recalc-pills button:hover {
  color: var(--ink-2);
}

.recalc-pills button.active {
  background: var(--ink);
  color: var(--bg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* === Tenure unit toggle ================================================ */

.unit-toggle {
  display: inline-flex;
  background: var(--bg-2);
  border-radius: 999px;
  padding: 2px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.unit-toggle button {
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--ink-3);
  transition: all 0.15s ease;
}

.unit-toggle button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

/* === Summary panel ===================================================== */

.summary {
  padding: 24px 24px 8px;
}

.summary-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.summary-hero-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.summary-hero-value {
  font-family: var(--font-mono);
  font-size: 56px;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
  font-feature-settings: "tnum";
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.summary-hero-value .ccy {
  font-size: 24px;
  color: var(--ink-3);
  font-weight: 400;
}

.summary-hero-value .frac {
  font-size: 24px;
  color: var(--ink-3);
}

.summary-hero-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
  text-align: right;
}

.summary-hero-meta strong {
  color: var(--ink);
  font-weight: 500;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  margin-bottom: 8px;
}

.stat {
  padding: 4px 16px;
  border-left: 1px solid var(--line);
}
.stat:first-child {
  border-left: none;
  padding-left: 0;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 2px;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-feature-settings: "tnum";
}

.stat-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 2px;
}

/* === Charts ============================================================ */

.charts {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 24px;
  padding: 24px;
  align-items: center;
  border-top: 1px solid var(--line);
}

.donut-wrap {
  position: relative;
  width: 200px;
  height: 200px;
}

.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.donut-center-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-weight: 500;
}

.donut-center-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-top: 2px;
  font-feature-settings: "tnum";
}

.timeline-chart {
  width: 100%;
}

.timeline-axis {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink-3);
}

.timeline-grid line {
  stroke: var(--line);
  stroke-dasharray: 2 3;
}

/* === Schedule ========================================================== */

.schedule-card {
  margin-bottom: 20px;
}

.schedule-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.schedule-table-wrap {
  max-height: 540px;
  overflow: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}

table.schedule {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 13px;
  font-feature-settings: "tnum";
}

.schedule thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  text-align: right;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  z-index: 1;
  font-family: var(--font-sans);
}
.schedule thead th:first-child {
  text-align: left;
}
.schedule tbody td {
  padding: 10px 16px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.schedule tbody td:first-child {
  text-align: left;
  color: var(--ink-2);
}
.schedule tbody tr:hover td {
  background: var(--surface-2);
}

.schedule .year-row {
  cursor: pointer;
  background: var(--surface-2);
}
.schedule .year-row td {
  font-weight: 500;
  color: var(--ink) !important;
}
.schedule .year-row td:first-child {
  color: var(--ink) !important;
}
.schedule .year-row:hover td {
  background: var(--bg-2);
}
.schedule .month-row td {
  background: var(--surface);
  color: var(--ink-2);
  padding-left: 32px;
}
.schedule .month-row td:first-child {
  padding-left: 32px;
  color: var(--ink-3);
}

.bar-cell {
  position: relative;
}
.bar-cell .bar {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 18px;
  display: flex;
  border-radius: 2px;
  overflow: hidden;
  opacity: 0.18;
  width: 100%;
}
.bar-cell .bar > span {
  display: block;
  height: 100%;
}
.bar-cell .bar .bar-p {
  background: var(--principal);
}
.bar-cell .bar .bar-i {
  background: var(--interest);
}

.density-compact .schedule tbody td {
  padding: 6px 16px;
  font-size: 12px;
}
.density-compact .schedule thead th {
  padding: 8px 16px;
}

/* === Buttons =========================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: all 0.15s ease;
  letter-spacing: -0.005em;
}

.btn:hover {
  border-color: var(--ink-3);
  background: var(--surface-2);
}

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--ink-2);
  border-color: var(--ink-2);
}

.btn-ghost {
  border-color: transparent;
}

.btn-icon {
  width: 14px;
  height: 14px;
  flex: none;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}

.schedule-collapse-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}
.schedule-collapse-btn .chevron {
  color: var(--ink-3);
  transition: transform 0.18s ease;
}
.schedule-collapse-btn .chevron.is-collapsed {
  transform: rotate(-90deg);
}
.schedule-collapse-btn:hover .chevron {
  color: var(--ink);
}
.schedule-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-left: 4px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
  text-transform: none;
  letter-spacing: 0;
}

/* === Footer note ======================================================= */

.footer-note {
  margin-top: 28px;
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
  font-family: var(--font-mono);
}

/* === Screen intro (Compare view header) =============================== */

.screen-intro {
  margin-bottom: 20px;
  padding: 8px 4px 20px;
}

.screen-intro-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 8px;
}

.screen-intro-title {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink);
  margin: 0 0 10px;
}

.screen-intro-sub {
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
  max-width: 640px;
  margin: 0;
}

/* In Compare view we drop the outer compare-card chrome — the section
   intro acts as the heading. Keep the inner card for scenarios. */
.compare-card {
  margin-top: 0;
}
.compare-card > .card-header {
  display: none;
}

/* === Compare section ================================================== */

.compare-card {
  margin-top: 20px;
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  gap: 0;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 880px) {
  .compare-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .compare-vs {
    flex-direction: row !important;
    justify-content: center;
  }
  .compare-vs-line {
    display: none;
  }
}

.scenario-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.scenario-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.scenario-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--ink-2);
  display: flex;
  align-items: center;
  gap: 8px;
}

.scenario-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  display: inline-block;
}

.scenario-emi {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.scenario-emi-l {
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.scenario-emi-v {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-feature-settings: "tnum";
}

.mini-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mini-field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  padding: 8px 10px;
  transition: all 0.15s ease;
}
.mini-field.is-derived {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.mini-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.mini-field-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  color: var(--ink-3);
}
.mini-derived-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 1px 5px;
  border-radius: 3px;
  font-weight: 500;
}
.mini-solve {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  font-weight: 500;
}
.mini-solve:hover { color: var(--ink-2); }

.mini-field-input {
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.mini-field-input input {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  width: 100%;
  font-feature-settings: "tnum";
  letter-spacing: -0.01em;
}
.mini-prefix, .mini-suffix {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-3);
}

.scenario-totals {
  display: flex;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-family: var(--font-mono);
  font-size: 12px;
}
.scenario-totals > div { display: flex; flex-direction: column; gap: 2px; }
.scenario-totals-l {
  font-family: var(--font-sans);
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.scenario-totals-v {
  font-weight: 500;
  letter-spacing: -0.01em;
}

.compare-vs {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 8px;
}
.compare-vs-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.compare-vs-line {
  width: 1px;
  flex: 1;
  background: var(--line);
}
.compare-diff {
  text-align: center;
}
.compare-diff-l {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-weight: 500;
  margin-bottom: 2px;
}
.compare-diff-v {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
}

/* === SIP section ====================================================== */

.sip-section {
  padding: 24px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.sip-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.sip-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.sip-sub {
  font-size: 13px;
  color: var(--ink-3);
  max-width: 520px;
}

.sip-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 880px) {
  .sip-grid { grid-template-columns: 1fr 1fr; }
}

.sip-result {
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius-xs);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.sip-result-l {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  opacity: 0.7;
  margin-bottom: 2px;
}
.sip-result-v {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-feature-settings: "tnum";
}
.sip-result-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  opacity: 0.6;
  margin-top: 2px;
}

.sip-chart {
  width: 100%;
  max-height: 200px;
}

/* === Verdict ========================================================== */

.verdict {
  padding: 24px;
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  align-items: center;
}
@media (max-width: 880px) {
  .verdict { grid-template-columns: 1fr; }
}

.verdict-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.verdict-col {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.verdict-col-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-2);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.verdict-tag {
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 500;
}
.verdict-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 4px 0;
  color: var(--ink-2);
}
.verdict-row span { font-family: var(--font-sans); font-size: 12px; }
.verdict-row strong { font-weight: 500; color: var(--ink); }
.verdict-row.total {
  border-top: 1px dashed var(--line);
  margin-top: 6px;
  padding-top: 8px;
  font-size: 13px;
}
.verdict-row.total span { font-weight: 500; color: var(--ink); }
.verdict-row.total strong { font-size: 14px; }

.verdict-banner {
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  text-align: center;
}
.verdict-banner-l {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  opacity: 0.7;
  margin-bottom: 6px;
}
.verdict-banner-v {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-bottom: 6px;
  font-feature-settings: "tnum";
}
.verdict-banner-sub {
  font-size: 11px;
  opacity: 0.6;
  font-family: var(--font-mono);
}

/* === Export menu (schedule controls) ================================== */

.export-menu {
  position: relative;
  display: inline-block;
}

.export-menu-caret {
  font-size: 9px;
  margin-left: 2px;
  opacity: 0.7;
}

.export-menu-pop {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, 0.35);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
}

.export-menu-pop button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  white-space: nowrap;
  transition: background 0.12s ease;
}

.export-menu-pop button:hover,
.export-menu-pop button:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.export-menu-pop .btn-icon {
  color: var(--ink-3);
  flex: none;
}

/* === Snackbar ========================================================= */

.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #131618;
  color: #f6f3ec;
  padding: 12px 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  box-shadow: 0 8px 28px -8px rgba(0, 0, 0, 0.45);
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.snackbar-success { background: oklch(0.46 0.08 165); }
.snackbar-error { background: oklch(0.5 0.18 25); }

.snackbar-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(246, 243, 236, 0.28);
  border-top-color: #f6f3ec;
  border-radius: 50%;
  animation: snackbar-spin 0.7s linear infinite;
  flex: none;
}

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

.snackbar-msg {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

.snackbar-action {
  background: rgba(246, 243, 236, 0.16);
  color: #f6f3ec;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  border: none;
  cursor: pointer;
  flex: none;
}

.snackbar-action:hover {
  background: rgba(246, 243, 236, 0.24);
}

.snackbar-close {
  background: transparent;
  color: rgba(246, 243, 236, 0.65);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  border: none;
  cursor: pointer;
  flex: none;
}

.snackbar-close:hover {
  color: #f6f3ec;
}

/* === Print =========================================================== */
@media print {
  body {
    background: white;
  }
  .topbar-actions,
  .schedule-controls,
  .field-slider,
  .solve-toggle,
  .footer-note,
  .tweaks-toggle {
    display: none !important;
  }
  .schedule-table-wrap {
    max-height: none;
    overflow: visible;
  }
  .card {
    box-shadow: none;
    break-inside: avoid;
  }
  .grid {
    gap: 12px;
  }
}

/* === Phone breakpoint — single column, tighter padding ================== */
/* Placed at end of file so cascade order overrides earlier 2-col grid defs. */
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }
  .app { padding: 14px 14px 96px; max-width: 100vw; }
  .navbar { margin: -14px -14px 16px; padding: 12px 14px; }
  .input-grid { grid-template-columns: 1fr; }
  .summary-grid { grid-template-columns: 1fr; }
  .mini-grid { grid-template-columns: 1fr; }
  .sip-grid { grid-template-columns: 1fr; }
  .compare-grid { grid-template-columns: 1fr; }
  .verdict-grid { grid-template-columns: 1fr; }
  .timeline-grid { grid-template-columns: 1fr; }
  .summary-hero { flex-direction: column; align-items: flex-start; gap: 8px; }
  .brand-sub { display: none; }
  /* Card must stay within viewport — internal scroll handled by .schedule-table-wrap.
     overflow-x: clip lets vertical popups (like the Export dropdown) escape the card,
     while still preventing horizontal page scroll from wide tables. */
  .card { max-width: 100%; overflow-x: clip; overflow-y: visible; }
  /* Card header — wrap title and controls onto separate lines on narrow screens */
  .card-header { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .card-header > * { min-width: 0; }
  /* Schedule controls (Yearly/Monthly toggle + Export) — wrap on mobile */
  .schedule-controls { flex-wrap: wrap; gap: 8px; width: 100%; justify-content: flex-start; }
  .schedule-controls > * { min-width: 0; }
  .schedule-meta { font-size: 11px; }
  /* Allow horizontal scroll within the table wrapper, but keep visible bounds */
  .schedule-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
  table.schedule { min-width: 480px; } /* ensure columns don't crush */
}

/* === v1.1 — Bottom tab nav, sticky hero EMI, prepayment, settings ====== */

/* Bottom tab bar — primary navigation on mobile */
.bottom-tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 24px -8px rgba(0, 0, 0, 0.18);
}
.bottom-tab {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  padding: 10px 4px 12px;
  background: transparent; border: 0;
  color: var(--ink-3);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.15s ease;
}
.bottom-tab:hover { color: var(--ink-2); }
.bottom-tab.is-active { color: var(--accent); }
.bottom-tab-icon { width: 22px; height: 22px; flex: none; }
.bottom-tab-label { font-weight: 500; letter-spacing: 0.01em; }

/* App needs bottom padding so content doesn't hide under tabs */
.app { padding-bottom: 96px; }

/* Hero EMI on Home tab */
.hero-emi {
  background: linear-gradient(160deg, var(--accent-soft), var(--surface) 60%);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  padding: 22px 22px 18px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.hero-emi-label {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--ink-3);
  font-family: var(--font-mono);
  margin-bottom: 6px;
}
.hero-emi-value {
  display: flex; align-items: baseline; gap: 4px;
  font-family: var(--font-mono);
  font-feature-settings: "tnum";
  letter-spacing: -0.02em;
}
.hero-emi-ccy { font-size: 22px; color: var(--accent); font-weight: 500; }
.hero-emi-num { font-size: 44px; font-weight: 700; color: var(--ink); line-height: 1; }
.hero-emi-meta {
  display: flex; gap: 18px; margin-top: 14px; flex-wrap: wrap;
}
.hero-emi-meta-item { min-width: 0; }
.hero-emi-meta-l {
  font-size: 10px; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: 0.08em; font-family: var(--font-mono);
}
.hero-emi-meta-v {
  font-size: 14px; color: var(--ink); font-weight: 500;
  font-family: var(--font-mono); margin-top: 2px;
}
.hero-emi-savings {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--radius-sm);
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  align-items: center; justify-content: space-between;
}
.hero-emi-savings-tag {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; font-family: var(--font-mono);
  opacity: 0.85;
}
.hero-emi-savings-v {
  font-size: 13px; font-weight: 600;
  font-family: var(--font-mono);
}

/* Prepayment card */
.prepayment-card {
  margin-top: 16px;
  margin-bottom: 16px;
  transition: border-color 0.18s ease;
}
.prepayment-card.is-on { border-color: var(--accent-line); }
.prepayment-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  background: transparent; border: 0; cursor: pointer;
  width: 100%; text-align: left;
  color: inherit;
}
.prepayment-head-text { flex: 1; min-width: 0; }
.prepayment-title {
  font-size: 14px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 8px;
}
.prepayment-on-tag {
  font-size: 9px; font-weight: 700; padding: 2px 6px;
  background: var(--accent); color: var(--accent-ink);
  border-radius: 4px; letter-spacing: 0.08em;
  font-family: var(--font-mono);
}
.prepayment-sub {
  font-size: 12px; color: var(--ink-3);
  margin-top: 4px; line-height: 1.4;
}
.prepayment-toggle {
  width: 40px; height: 22px;
  background: var(--line); border-radius: 100px;
  position: relative; flex: none;
  transition: background 0.18s ease;
}
.prepayment-toggle.is-on { background: var(--accent); }
.prepayment-toggle-dot {
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: var(--surface); border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.18s ease;
}
.prepayment-toggle.is-on .prepayment-toggle-dot { transform: translateX(18px); }

.prepayment-body {
  padding: 4px 20px 20px;
  display: flex; flex-direction: column; gap: 18px;
  border-top: 1px solid var(--line);
}
.prepayment-row { display: flex; flex-direction: column; gap: 8px; }
.prepayment-row-label {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-3);
  font-family: var(--font-mono);
}
.prepayment-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.prepayment-chip {
  padding: 8px 14px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 100px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.prepayment-chip.is-on {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}

.prepayment-amount {
  display: flex; align-items: baseline; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}
.prepayment-amount-ccy { color: var(--ink-3); font-family: var(--font-mono); font-size: 16px; }
.prepayment-amount-input {
  flex: 1; min-width: 0;
  font-family: var(--font-mono);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.01em;
  font-feature-settings: "tnum";
  color: var(--ink);
}

.prepayment-strategy { display: flex; gap: 8px; }
.prepayment-strategy-btn {
  flex: 1; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex; flex-direction: column; gap: 2px;
  text-align: left; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.prepayment-strategy-btn.is-on {
  background: var(--accent-soft); border-color: var(--accent-line);
}
.prepayment-strategy-label {
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.prepayment-strategy-hint {
  font-size: 11px; color: var(--ink-3);
}

.prepayment-savings {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 6px;
}
.prepayment-savings-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.prepayment-savings-l { color: var(--ink-3); }
.prepayment-savings-v {
  color: var(--accent); font-weight: 600;
  font-family: var(--font-mono); font-feature-settings: "tnum";
}

/* Settings page */
.settings-page {
  display: flex; flex-direction: column; gap: 12px;
}
.settings-card-body {
  padding: 12px 20px 16px;
  display: flex; flex-direction: column; gap: 16px;
}
.setting-row { display: flex; flex-direction: column; gap: 8px; }
.setting-label {
  font-size: 11px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--ink-3);
  font-family: var(--font-mono);
}
.setting-options { display: flex; gap: 6px; flex-wrap: wrap; }
.setting-chip {
  padding: 8px 14px; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 100px;
  font-size: 13px; font-weight: 500; color: var(--ink-2);
  cursor: pointer;
}
.setting-chip.is-on {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.settings-about {
  text-align: center; margin-top: 12px;
}

/* Hide top-right Compare/Tweaks buttons since we have bottom tabs now */
.navbar-app .navbar-trailing { display: none; }

/* === Field steppers (up/down arrows) =================================== */
.field-input-wrap { position: relative; display: flex; align-items: baseline; gap: 4px; }
.field-steppers {
  display: flex; flex-direction: column;
  gap: 2px;
  margin-left: auto;
  align-self: center;
}
.field-stepper {
  width: 22px; height: 18px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.field-stepper:hover { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.field-stepper:active { transform: translateY(0.5px); }
