/* =============================================================
   1. Tokens
   ============================================================= */
:root {
  --bg: #eef2ff;
  --bg-soft: #f7f8ff;
  --surface: rgba(255, 255, 255, .78);
  --surface-solid: #ffffff;
  --surface-muted: #f1f3fb;
  --ink: #172033;
  --ink-soft: #46516b;
  --ink-muted: #69758f;
  --line: rgba(32, 47, 96, .13);
  --primary: #3347b7;
  --primary-dark: #25358d;
  --primary-soft: #e7eaff;
  --green: #23845f;
  --green-soft: #dff7ec;
  --coral: #e45d56;
  --coral-soft: #ffebe9;
  --gold: #c18b2f;
  --gold-soft: #fff4d8;
  --shadow-sm: 0 8px 24px rgba(35, 48, 103, .08);
  --shadow-md: 0 22px 58px rgba(35, 48, 103, .15);
  --radius-sm: 12px;
  --radius: 20px;
  --radius-lg: 28px;
  --sidebar-width: 268px;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-soft: cubic-bezier(.25, .46, .45, .94);
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #101425;
  --bg-soft: #151a2f;
  --surface: rgba(27, 34, 59, .86);
  --surface-solid: #1b223b;
  --surface-muted: #232b49;
  --ink: #f5f7ff;
  --ink-soft: #c9d0e5;
  --ink-muted: #9da8c5;
  --line: rgba(223, 229, 255, .13);
  --primary: #8f9cff;
  --primary-dark: #bec6ff;
  --primary-soft: #2e3768;
  --green: #75d8ae;
  --green-soft: #173c32;
  --coral: #ff8a83;
  --coral-soft: #452728;
  --gold: #f0bf68;
  --gold-soft: #473b25;
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, .18);
  --shadow-md: 0 22px 58px rgba(0, 0, 0, .3);
}

/* =============================================================
   2. Reset and base
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; background: var(--bg); }
body {
  margin: 0;
  min-width: 300px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: clip;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; color: inherit; }
button { border: 0; cursor: pointer; }
a { color: inherit; }
svg { display: block; }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
p { text-wrap: pretty; }
input, select { min-width: 0; }
::selection { background: var(--primary); color: #fff; }

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
  border-radius: 7px;
}

/* =============================================================
   3. Utilities
   ============================================================= */
.skip-link {
  position: fixed;
  z-index: 9999;
  top: -90px;
  left: 1rem;
  padding: .7rem 1rem;
  border-radius: 10px;
  color: #fff;
  background: var(--primary-dark);
  font-weight: 750;
  transition: top .2s var(--ease-out);
}
.skip-link:focus { top: 1rem; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
[hidden] { display: none !important; }

.ambient {
  position: fixed;
  z-index: 0;
  width: 58vw;
  height: 58vw;
  min-width: 420px;
  min-height: 420px;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(90px);
  opacity: .36;
  animation: ambient-drift 24s ease-in-out infinite alternate;
}
.ambient-one { top: -28vw; left: 10vw; background: #aab5ff; }
.ambient-two { right: -24vw; bottom: -30vw; background: #9ce8ca; animation-delay: -11s; }
@keyframes ambient-drift { to { transform: translate3d(4vw, 3vw, 0) scale(1.08); } }

/* =============================================================
   4. Shell, sidebar and header
   ============================================================= */
.app-shell { position: relative; z-index: 1; min-height: 100vh; min-height: 100svh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 500;
  width: min(var(--sidebar-width), 86vw);
  padding: 22px 16px 18px;
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, .94);
  border-right: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  transform: translateX(-105%);
  transition: transform .34s var(--ease-out);
}
:root[data-theme="dark"] .sidebar { background: rgba(20, 26, 46, .96); }
.sidebar.is-open { transform: translateX(0); }
.drawer-backdrop { position: fixed; inset: 0 0 0 min(var(--sidebar-width), 86vw); z-index: 450; background: rgba(8, 14, 37, .5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }

.brand-lockup { display: flex; align-items: center; gap: 12px; padding: 2px 6px 26px; }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; color: #fff; background: linear-gradient(145deg, var(--primary), #1a286f); box-shadow: 0 12px 24px rgba(51, 71, 183, .24); }
.brand-mark svg { width: 30px; }
.brand-lockup strong { display: block; letter-spacing: .12em; font-size: 1.05rem; }
.brand-lockup small { display: block; margin-top: 1px; color: var(--ink-muted); font-size: .73rem; }
.side-nav { display: grid; gap: 6px; }
.nav-link { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; min-height: 50px; padding: 8px 11px; border-radius: 14px; color: var(--ink-soft); text-decoration: none; font-size: .9rem; font-weight: 650; transition: background .2s var(--ease-out), color .2s, transform .2s var(--ease-out); }
.nav-link.is-active { color: var(--primary-dark); background: var(--primary-soft); }
.nav-icon { display: grid; place-items: center; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 10px; font-size: .64rem; letter-spacing: .08em; }
.nav-link.is-active .nav-icon { border-color: transparent; color: #fff; background: var(--primary); }
.nav-count { min-width: 23px; height: 23px; display: grid; place-items: center; padding: 0 6px; border-radius: 999px; color: var(--ink-muted); background: var(--surface-muted); font-size: .7rem; }
.local-note { margin-top: auto; display: flex; align-items: flex-start; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-muted); }
.status-dot { width: 9px; height: 9px; margin-top: 5px; flex: 0 0 auto; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 5px rgba(35, 132, 95, .12); }
.local-note strong, .local-note small { display: block; }
.local-note strong { font-size: .78rem; }
.local-note small { margin-top: 3px; color: var(--ink-muted); font-size: .7rem; line-height: 1.35; }

.main-area { min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 300;
  min-height: 70px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(247, 248, 255, .82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
}
:root[data-theme="dark"] .app-header { background: rgba(16, 20, 37, .84); }
.header-left { display: flex; align-items: center; gap: 11px; }
.header-eyebrow { color: var(--primary); font-size: .63rem; font-weight: 800; text-transform: uppercase; letter-spacing: .16em; }
.app-header h1 { margin-top: 1px; font-size: clamp(1.05rem, 3.5vw, 1.35rem); line-height: 1.15; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.save-indicator { display: none; color: var(--green); font-size: .72rem; font-weight: 700; }
.icon-button { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }
.icon-button svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.theme-toggle { position: relative; color: var(--ink); transition: color .2s ease, background .2s ease, border-color .2s ease, transform .2s ease; }
.theme-toggle:hover { color: var(--primary); transform: translateY(-1px); }
.theme-toggle:active { transform: translateY(0) scale(.96); }
.theme-icon { position: absolute; transition: opacity .2s ease, transform .3s var(--ease-out); }
.theme-icon-moon { opacity: 0; transform: rotate(-35deg) scale(.7); }
:root[data-theme="dark"] .theme-icon-sun { opacity: 0; transform: rotate(35deg) scale(.7); }
:root[data-theme="dark"] .theme-icon-moon { opacity: 1; transform: rotate(0) scale(1); }

.content { width: 100%; max-width: 1440px; margin: 0 auto; padding: 24px 16px 56px; flex: 1; }
.app-ready .view:not(.is-active) { display: none; }
.app-ready .view.is-active { animation: view-in .45s var(--ease-out) both; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } }
.view + .view { margin-top: 72px; padding-top: 42px; border-top: 1px solid var(--line); }
.app-ready .view + .view { margin-top: 0; padding-top: 0; border-top: 0; }

/* =============================================================
   5. Typography and controls
   ============================================================= */
.view-intro { display: grid; gap: 18px; margin-bottom: 24px; }
.view-intro h2 { max-width: 760px; margin-top: 8px; font-size: clamp(1.75rem, 5.6vw, 3rem); line-height: 1.04; letter-spacing: -.045em; }
.view-intro p { max-width: 700px; margin-top: 10px; color: var(--ink-soft); font-size: .95rem; }
.kicker, .step-tag { color: var(--primary); font-size: .67rem; font-weight: 850; text-transform: uppercase; letter-spacing: .16em; }
.trust-pill { width: max-content; max-width: 100%; padding: 9px 13px; border: 1px solid rgba(35, 132, 95, .22); border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: .73rem; font-weight: 750; }
.compact-intro h2 { font-size: clamp(1.8rem, 5vw, 2.7rem); }

.panel {
  background: rgba(255, 255, 255, .72);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
:root[data-theme="dark"] .panel { background: rgba(27, 34, 59, .84); border-color: rgba(255, 255, 255, .07); }
@supports (backdrop-filter: blur(20px)) {
  .panel { background: var(--surface); backdrop-filter: blur(20px) saturate(145%); -webkit-backdrop-filter: blur(20px) saturate(145%); }
}
.form-panel, .settings-card, .list-panel, .amortization-panel { padding: 19px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-heading h3 { margin-top: 3px; font-size: 1.08rem; letter-spacing: -.02em; }
.panel-copy { margin: -4px 0 17px; color: var(--ink-muted); font-size: .82rem; }

.field-grid { display: grid; grid-template-columns: 1fr; gap: 15px; }
.field { min-width: 0; }
.field label { display: block; margin-bottom: 7px; color: var(--ink-soft); font-size: .76rem; font-weight: 750; }
.field input, .field select, .search-box input, .filter-control select {
  width: 100%;
  min-height: 48px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  color: var(--ink);
  background: var(--surface-solid);
  transition: border-color .2s, box-shadow .2s, transform .2s var(--ease-out);
}
.field input:focus, .field select:focus, .search-box input:focus, .filter-control select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(51, 71, 183, .12); }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--coral); box-shadow: 0 0 0 4px rgba(228, 93, 86, .1); }
.field-help { display: block; margin-top: 5px; color: var(--ink-muted); font-size: .68rem; }
.input-affix { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-solid); overflow: hidden; transition: border-color .2s, box-shadow .2s; }
.input-affix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(51, 71, 183, .12); }
.input-affix > span { padding-left: 13px; color: var(--primary); font-size: .8rem; font-weight: 850; white-space: nowrap; }
.input-affix input { border: 0; box-shadow: none !important; background: transparent; }
.input-affix-right { grid-template-columns: minmax(0, 1fr) auto; }
.input-affix-right > span { padding: 0 13px 0 0; }
.derived-periods { margin-top: 15px; padding: 10px 12px; border-radius: 11px; color: var(--primary-dark); background: var(--primary-soft); font-size: .76rem; font-weight: 750; }

.button { min-height: 44px; padding: 10px 15px; display: inline-flex; align-items: center; justify-content: center; border-radius: 12px; text-decoration: none; font-size: .82rem; font-weight: 780; transition: transform .2s var(--ease-out), box-shadow .2s, background .2s; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); box-shadow: 0 9px 20px rgba(51, 71, 183, .22); }
.button-soft { color: var(--primary-dark); background: var(--primary-soft); }
.button-quiet { color: var(--ink-soft); background: transparent; border: 1px solid var(--line); }
.button-small { min-height: 36px; padding: 7px 10px; font-size: .72rem; }
.text-button, .danger-link { padding: 4px 2px; color: var(--primary); background: transparent; font-size: .76rem; font-weight: 780; text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 4px; }
.danger-link { margin-top: 18px; color: var(--coral); }

@media (hover: hover) {
  .button:hover { transform: translateY(-2px); }
  .button-primary:hover { box-shadow: 0 14px 28px rgba(51, 71, 183, .28); }
  .nav-link:hover { transform: translateX(3px); color: var(--primary-dark); background: var(--primary-soft); }
  .text-button:hover, .danger-link:hover { text-decoration-color: currentColor; }
}

/* =============================================================
   6. Calculator and results
   ============================================================= */
.calculator-layout { display: grid; grid-template-areas: "loan" "result" "advanced"; gap: 16px; }
.loan-panel { grid-area: loan; }
.advanced-panel { grid-area: advanced; }
.results-panel { grid-area: result; }
.advanced-grid { margin-top: 17px; padding-top: 17px; border-top: 1px solid var(--line); }
.charge-list { display: grid; gap: 8px; }
.empty-inline { padding: 12px 0; color: var(--ink-muted); font-size: .78rem; }
.charge-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 10px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-muted); }
.charge-item strong { display: block; font-size: .82rem; }
.charge-item small { display: block; color: var(--ink-muted); font-size: .68rem; }
.charge-item > span { color: var(--primary-dark); font-size: .78rem; font-weight: 800; }
.mini-delete { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: var(--coral); background: var(--coral-soft); }

.results-panel { min-height: 420px; padding: 21px; overflow: hidden; position: relative; }
.results-panel::after { content: ""; position: absolute; width: 220px; height: 220px; top: -120px; right: -100px; border-radius: 50%; background: radial-gradient(circle, rgba(142, 156, 255, .28), transparent 68%); pointer-events: none; }
.results-empty { min-height: 370px; display: grid; place-items: center; align-content: center; text-align: center; }
.results-empty h3 { margin-top: 21px; font-size: 1.12rem; }
.results-empty p { margin-top: 7px; color: var(--ink-muted); font-size: .8rem; }
.result-orbit { position: relative; width: 94px; height: 94px; display: grid; place-items: center; border: 1px solid rgba(51, 71, 183, .2); border-radius: 50%; animation: orbit-breathe 4s ease-in-out infinite; }
.result-orbit::before, .result-orbit::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(51, 71, 183, .15); }
.result-orbit::before { inset: 12px; }
.result-orbit::after { inset: 27px; background: linear-gradient(145deg, var(--primary), var(--green)); border: 0; box-shadow: 0 12px 30px rgba(51, 71, 183, .25); }
.result-orbit i { position: absolute; z-index: 1; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
@keyframes orbit-breathe { 50% { transform: scale(1.06); } }
.result-topline { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.hero-amount { display: block; margin: 6px 0 14px; font-size: clamp(2.25rem, 9vw, 3.75rem); line-height: 1; letter-spacing: -.06em; }
.tcea-block { display: flex; align-items: center; gap: 8px; width: max-content; max-width: 100%; padding: 8px 10px; border-radius: 10px; color: var(--green); background: var(--green-soft); font-size: .73rem; }
.tcea-block strong { font-size: .86rem; }
.info-button { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: var(--green); background: rgba(255, 255, 255, .58); font-size: .7rem; font-weight: 900; }
.result-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin: 18px 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--line); }
.result-metrics div { padding: 11px; background: var(--surface-solid); }
.result-metrics dt { color: var(--ink-muted); font-size: .67rem; }
.result-metrics dd { margin: 4px 0 0; font-size: .84rem; font-weight: 830; }
.cost-bar { height: 10px; display: flex; border-radius: 999px; overflow: hidden; background: var(--surface-muted); }
.cost-bar span { min-width: 0; transition: width .5s var(--ease-out); }
.cost-capital, .capital-dot { background: var(--primary); }
.cost-interest, .interest-dot { background: var(--coral); }
.cost-fees, .fees-dot { background: var(--gold); }
.cost-legend { display: flex; flex-wrap: wrap; gap: 11px; margin-top: 8px; color: var(--ink-muted); font-size: .65rem; }
.cost-legend span { display: flex; align-items: center; gap: 5px; }
.cost-legend i { width: 8px; height: 8px; border-radius: 3px; }
.calculation-note { margin: 15px 0; padding: 10px 12px; border-left: 3px solid var(--primary); color: var(--ink-soft); background: var(--surface-muted); font-size: .72rem; }
.result-actions { display: grid; gap: 8px; }
.result-actions .button { width: 100%; }
.share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.share-actions button { min-height: 38px; padding: 7px; border-radius: 10px; color: var(--ink-soft); background: var(--surface-muted); font-size: .68rem; font-weight: 740; }
.mobile-result-dock { display: none; }

.amortization-panel { margin-top: 17px; }
.chart-wrap { display: none; height: 220px; margin: 5px 0 18px; padding: 12px; border-radius: 14px; background: linear-gradient(180deg, var(--primary-soft), transparent); }
.balance-chart { width: 100%; height: 100%; overflow: visible; }
#chart-area { fill: rgba(51, 71, 183, .1); }
#chart-line { fill: none; stroke: var(--primary); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.table-wrap { width: 100%; overflow-x: auto; overflow-y: visible; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; min-width: 870px; border-collapse: collapse; background: var(--surface-solid); }
th, td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th { color: var(--ink-muted); background: var(--surface-muted); font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; }
td { color: var(--ink-soft); font-size: .75rem; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
tfoot td { color: var(--ink); font-weight: 830; background: var(--primary-soft); border-bottom: 0; }

/* =============================================================
   7. Credits and comparisons
   ============================================================= */
.summary-grid, .comparison-grid, .about-grid { display: grid; gap: 13px; }
.summary-card { min-height: 140px; padding: 20px; display: flex; flex-direction: column; justify-content: flex-end; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.summary-card span { color: var(--ink-muted); font-size: .72rem; font-weight: 750; text-transform: uppercase; letter-spacing: .08em; }
.summary-card strong { margin: 9px 0 4px; font-size: clamp(1.45rem, 6vw, 2rem); letter-spacing: -.04em; }
.summary-card small { color: var(--ink-muted); font-size: .7rem; }
.accent-card { color: #fff; border-color: transparent; background: linear-gradient(145deg, var(--primary), #17256f); }
.accent-card span, .accent-card small { color: rgba(255, 255, 255, .76); }
.list-panel { margin-top: 15px; }
.list-toolbar { display: grid; gap: 10px; margin-bottom: 16px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 13px; top: 50%; width: 18px; transform: translateY(-50%); fill: none; stroke: var(--ink-muted); stroke-width: 2; stroke-linecap: round; }
.search-box input { padding-left: 42px; }
.filter-control { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 9px; color: var(--ink-muted); font-size: .72rem; font-weight: 750; }
.filter-control select { min-height: 44px; padding: 8px 10px; }
.credit-list { display: grid; gap: 11px; }
.empty-state { min-height: 220px; display: grid; place-items: center; align-content: center; padding: 32px; color: var(--ink-muted); text-align: center; }
.empty-state strong { color: var(--ink); font-size: 1rem; }
.empty-state p { margin-top: 6px; font-size: .78rem; }
.credit-card { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-solid); transition: transform .2s var(--ease-out), box-shadow .2s; }
.credit-main { min-width: 0; }
.credit-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.credit-title-row h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .98rem; }
.status-badge { padding: 4px 7px; border-radius: 999px; color: var(--green); background: var(--green-soft); font-size: .62rem; font-weight: 830; text-transform: uppercase; letter-spacing: .06em; }
.status-badge.is-paid { color: var(--primary-dark); background: var(--primary-soft); }
.status-badge.is-overdue { color: var(--coral); background: var(--coral-soft); }
.credit-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 6px; color: var(--ink-muted); font-size: .7rem; }
.credit-progress { height: 7px; margin-top: 12px; border-radius: 999px; overflow: hidden; background: var(--surface-muted); }
.credit-progress span { height: 100%; display: block; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--green)); }
.credit-numbers { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.credit-number { padding: 9px 10px; border-radius: 11px; background: var(--surface-muted); }
.credit-number small, .credit-number strong { display: block; }
.credit-number small { color: var(--ink-muted); font-size: .62rem; }
.credit-number strong { margin-top: 2px; font-size: .78rem; }
.credit-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.credit-actions button { min-height: 36px; padding: 7px 10px; border-radius: 10px; color: var(--primary-dark); background: var(--primary-soft); font-size: .68rem; font-weight: 780; }
.credit-actions .delete-credit { color: var(--coral); background: var(--coral-soft); }
@media (hover: hover) { .credit-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); } }

.comparison-card { position: relative; overflow: hidden; padding: 19px; }
.comparison-card.is-best { border-color: rgba(35, 132, 95, .38); }
.best-ribbon { position: absolute; top: 14px; right: -32px; width: 120px; padding: 5px; transform: rotate(36deg); color: #fff; background: var(--green); text-align: center; font-size: .58rem; font-weight: 850; text-transform: uppercase; letter-spacing: .08em; }
.comparison-card h3 { padding-right: 35px; font-size: 1rem; }
.comparison-rate { margin-top: 4px; color: var(--ink-muted); font-size: .7rem; }
.comparison-payment { display: block; margin: 17px 0 2px; font-size: 1.8rem; letter-spacing: -.045em; }
.comparison-payment-label { color: var(--ink-muted); font-size: .67rem; }
.comparison-list { display: grid; gap: 8px; margin: 16px 0; }
.comparison-list div { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-size: .72rem; }
.comparison-list span { color: var(--ink-muted); }
.comparison-remove { color: var(--coral); background: transparent; font-size: .7rem; font-weight: 760; }

/* =============================================================
   8. Settings, about and footer
   ============================================================= */
.settings-grid { display: grid; grid-template-columns: minmax(0, 760px); gap: 14px; }
.settings-fields { display: grid; gap: 14px; }
.custom-field-list { display: grid; gap: 8px; }
.custom-field-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 11px 12px; border-radius: 11px; background: var(--surface-muted); }
.custom-field-item strong, .custom-field-item small { display: block; }
.custom-field-item strong { font-size: .8rem; }
.custom-field-item small { color: var(--ink-muted); font-size: .66rem; }
.stack-actions { display: grid; gap: 8px; }
.file-button { cursor: pointer; }
.about-card { min-height: 220px; padding: 21px; }
.about-number { color: var(--primary); font-size: .68rem; font-weight: 850; letter-spacing: .14em; }
.about-card h3 { margin-top: 50px; font-size: 1.12rem; }
.about-card p { margin-top: 9px; color: var(--ink-soft); font-size: .82rem; }
.contact-panel { margin-top: 14px; padding: 22px; display: grid; gap: 20px; }
.contact-panel h3 { margin-top: 5px; font-size: 1.25rem; }
.contact-panel p { margin-top: 7px; color: var(--ink-muted); font-size: .76rem; }
.contact-actions { display: grid; gap: 8px; }
.site-footer { padding: 17px 16px calc(17px + env(safe-area-inset-bottom)); display: grid; gap: 10px; color: var(--ink-muted); border-top: 1px solid var(--line); background: rgba(247, 248, 255, .72); font-size: .68rem; }
:root[data-theme="dark"] .site-footer { background: rgba(16, 20, 37, .74); }
.footer-brand, .footer-links { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 13px; }
.footer-brand strong { color: var(--ink); letter-spacing: .1em; }
.mini-mark { width: 12px; height: 12px; transform: rotate(45deg); border: 2px solid var(--green); }
.footer-links a { color: var(--primary); font-weight: 730; text-decoration: none; }

/* =============================================================
   9. Dialogs and notifications
   ============================================================= */
.dialog { width: min(520px, calc(100% - 24px)); max-height: min(88vh, 760px); max-height: min(88dvh, 760px); margin: auto; padding: 0; overflow: auto; color: var(--ink); background: var(--surface-solid); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 32px 90px rgba(10, 17, 50, .32); }
.dialog::backdrop { background: rgba(9, 15, 39, .58); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.dialog[open] { animation: dialog-in .3s var(--ease-out) both; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.dialog > form, .dialog > .dialog-heading, .dialog > p, .dialog > .credit-detail-summary, .dialog > .table-wrap, .dialog > .dialog-actions { margin-left: 20px; margin-right: 20px; }
.dialog > form { margin: 0; padding: 20px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-top: 20px; margin-bottom: 18px; }
form .dialog-heading { margin: 0 0 18px; }
.dialog-heading h2 { margin-top: 3px; font-size: 1.25rem; }
.dialog-heading p { margin-top: 4px; color: var(--ink-muted); font-size: .72rem; }
.dialog-close { width: 38px; height: 38px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 12px; color: var(--ink-soft); background: var(--surface-muted); font-size: 1.35rem; }
.dialog-fields, .custom-values { display: grid; gap: 13px; }
.custom-values:not(:empty) { margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 20px; }
.dialog > .dialog-actions { margin-bottom: 20px; }
.wide-dialog { width: min(940px, calc(100% - 24px)); }
.credit-detail-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.detail-stat { padding: 11px; border-radius: 11px; background: var(--surface-muted); }
.detail-stat span, .detail-stat strong { display: block; }
.detail-stat span { color: var(--ink-muted); font-size: .65rem; }
.detail-stat strong { margin-top: 3px; font-size: .82rem; }
.detail-table-wrap { max-height: 380px; overflow: auto; }
.detail-table-wrap table { min-width: 690px; }
.payment-check { width: 20px; height: 20px; accent-color: var(--green); }
.info-dialog > p { margin-bottom: 14px; color: var(--ink-soft); font-size: .86rem; }
.info-dialog .fine-print { padding: 12px; border-radius: 12px; background: var(--surface-muted); color: var(--ink-muted); font-size: .72rem; }
.toast-region { position: fixed; z-index: 1200; left: 12px; right: 12px; bottom: 12px; display: grid; justify-items: end; gap: 8px; pointer-events: none; }
.toast { max-width: 360px; padding: 11px 14px; border-radius: 12px; color: #fff; background: #172033; box-shadow: var(--shadow-md); font-size: .75rem; font-weight: 680; animation: toast-in .35s var(--ease-out) both; }
.toast.is-error { background: #8e302c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }

/* =============================================================
   10. Responsive
   ============================================================= */
@media (min-width: 540px) {
  .content { padding-inline: 24px; }
  .field-grid { grid-template-columns: 1fr 1fr; }
  .field-wide { grid-column: 1 / -1; }
  .advanced-grid { grid-template-columns: 1fr 1fr 140px; }
  .advanced-grid .field:first-child { grid-column: auto; }
  .share-actions { grid-template-columns: repeat(4, 1fr); }
  .summary-grid, .about-grid { grid-template-columns: repeat(3, 1fr); }
  .summary-card { min-height: 158px; }
  .list-toolbar { grid-template-columns: minmax(0, 1fr) 210px; align-items: center; }
  .credit-card { grid-template-columns: minmax(0, 1.4fr) minmax(180px, .75fr); align-items: center; }
  .credit-actions { grid-column: 1 / -1; }
  .comparison-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-fields { grid-template-columns: 1fr 1fr; }
  .stack-actions { grid-template-columns: 1fr 1fr; }
  .contact-panel { grid-template-columns: 1fr auto; align-items: center; }
  .contact-actions { grid-template-columns: auto auto; }
  .site-footer { grid-template-columns: 1fr auto; align-items: center; }
  .footer-links { justify-content: flex-end; }
  .save-indicator { display: inline; }
  .chart-wrap { display: block; }
}

@media (min-width: 720px) {
  .content { padding-top: 34px; padding-bottom: 70px; }
  .view-intro { grid-template-columns: 1fr auto; align-items: end; margin-bottom: 30px; }
  .compact-intro { align-items: center; }
  .form-panel, .settings-card, .list-panel, .amortization-panel { padding: 24px; }
  .results-panel { padding: 25px; }
  .comparison-grid { grid-template-columns: repeat(3, 1fr); }
  .credit-detail-summary { grid-template-columns: repeat(4, 1fr); }
}

@media (min-width: 960px) {
  .sidebar { width: var(--sidebar-width); transform: none; box-shadow: none; background: rgba(255, 255, 255, .62); backdrop-filter: blur(22px) saturate(140%); -webkit-backdrop-filter: blur(22px) saturate(140%); }
  :root[data-theme="dark"] .sidebar { background: rgba(20, 26, 46, .7); }
  .main-area { margin-left: var(--sidebar-width); }
  .menu-button { display: none; }
  .app-header { padding-inline: 28px; }
  .calculator-layout { grid-template-columns: minmax(0, 1.65fr) minmax(320px, .85fr); grid-template-areas: "loan result" "advanced result"; align-items: start; }
  .results-panel { position: sticky; top: 94px; }
  .toast-region { left: auto; width: 390px; }
}

@media (min-width: 1280px) {
  .content { padding-inline: 40px; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calculator-layout { grid-template-columns: minmax(0, 1.72fr) minmax(360px, .82fr); gap: 20px; }
  .form-panel, .settings-card, .list-panel, .amortization-panel { padding: 28px; }
  .results-panel { padding: 28px; }
  .credit-card { grid-template-columns: minmax(0, 1.5fr) minmax(260px, .7fr) auto; }
  .credit-actions { grid-column: auto; justify-content: flex-end; }
}

@media (max-width: 539px) {
  .content { padding: 14px 12px 112px; }
  .app-header { min-height: 64px; }
  .header-actions .button { display: none; }
  .view-intro h2 { max-width: 16ch; }
  .panel-heading { align-items: center; }
  .advanced-grid .field:last-child { max-width: 160px; }
  .site-footer .footer-links span { display: none; }
  .form-panel { padding: 16px; }
  .results-panel { min-height: 0; padding: 16px; }
  .results-empty { min-height: 145px; }
  .result-orbit { width: 62px; height: 62px; }
  .result-orbit::after { inset: 18px; }
  .result-orbit::before { inset: 8px; }
  .results-empty h3 { margin-top: 13px; }
  .hero-amount { font-size: clamp(2rem, 12vw, 3rem); }
}

@media (min-width: 360px) and (max-width: 539px) {
  .loan-panel .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 10px; }
  .loan-panel .field-wide { grid-column: 1 / -1; }
  .loan-panel .field input, .loan-panel .field select { min-height: 46px; padding: 9px 10px; }
  .loan-panel .input-affix > span { padding-left: 10px; }
  .loan-panel .input-affix-right > span { padding: 0 10px 0 0; }
}

@media (max-width: 959px) {
  .content { padding-bottom: 112px; }
  .toast-region { bottom: calc(92px + env(safe-area-inset-bottom)); }
  .mobile-result-dock:not([hidden]) {
    position: fixed;
    z-index: 420;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 10px 10px 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface-solid);
    box-shadow: 0 16px 44px rgba(10, 17, 48, .28);
  }
  .mobile-result-dock span, .mobile-result-dock strong { display: block; }
  .mobile-result-dock span { color: var(--ink-muted); font-size: .68rem; }
  .mobile-result-dock span b { font-weight: 750; }
  .mobile-result-dock strong { margin-top: 1px; font-size: 1.15rem; line-height: 1.15; }
  .mobile-result-dock .button { min-height: 42px; padding-inline: 13px; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient { animation-duration: 45s; }
  .result-orbit { animation-duration: 7s; }
}

/* Defensive rule required by the deployment template. */
.reveal[data-split] { opacity: 1; transform: none; }

/* =============================================================
   11. Print
   ============================================================= */
@media print {
  :root { color-scheme: light; }
  body { color: #111; background: #fff; }
  .ambient, .sidebar, .app-header, .view-intro, .calculator-fields, .result-actions, .share-actions, .site-footer, .toast-region { display: none !important; }
  .main-area { margin: 0; }
  .content { max-width: none; padding: 0; }
  .app-ready .view:not(.is-active), .app-ready #view-calculator { display: block !important; }
  .app-ready .view:not(#view-calculator) { display: none !important; }
  .calculator-layout { display: block; }
  .results-panel, .amortization-panel { position: static; display: block !important; box-shadow: none; border: 1px solid #ccc; background: #fff; }
  .results-empty { display: none !important; }
  .results-ready { display: block !important; }
  .amortization-panel { margin-top: 16px; }
  .chart-wrap { display: none; }
  .table-wrap { overflow: visible; border: 0; }
  table { min-width: 0; }
  th, td { padding: 5px 6px; font-size: 9px; color: #111; }
  .panel { break-inside: avoid; }
}
