:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: rgba(255,255,255,.92);
  --surface-strong: #ffffff;
  --text: #151922;
  --muted: #667085;
  --line: #e2e7ef;
  --accent: #2764e7;
  --accent-soft: #eaf0ff;
  --success: #117a4d;
  --danger: #b42318;
  --shadow: 0 16px 45px rgba(35, 45, 70, .09);
  --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 10% 0%, rgba(39,100,231,.12), transparent 34rem),
    radial-gradient(circle at 100% 10%, rgba(89,190,164,.10), transparent 28rem),
    var(--bg);
  color: var(--text);
}

button, input, select { font: inherit; }

.app-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 22px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #2764e7, #4b7ff0);
  color: white;
  box-shadow: 0 10px 25px rgba(39,100,231,.25);
  font-size: 22px;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.25rem, 2vw, 1.65rem); margin-bottom: 3px; }
.subtitle { color: var(--muted); margin: 0; font-size: .92rem; }

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }

.soft-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.82);
  color: var(--text);
  min-height: 40px;
  border-radius: 12px;
  padding: 0 13px;
  cursor: pointer;
}

.soft-button:hover { border-color: #bfc9d9; }

.language-select {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.82);
  color: var(--text);
  min-height: 40px;
  border-radius: 12px;
  padding: 0 30px 0 13px;
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23667085'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  outline: none;
}

.language-select:hover { border-color: #bfc9d9; }

.language-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(39,100,231,.11);
}

.toolbar-desktop { display: flex; gap: 9px; align-items: center; }

.hamburger-button {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.82);
  cursor: pointer;
  padding: 0;
}

.hamburger-line {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: .22s ease;
}

.hamburger-button.open {
  position: relative;
  z-index: 110;
}

.hamburger-button.open .hamburger-line:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger-button.open .hamburger-line:nth-child(2) {
  opacity: 0;
}

.hamburger-button.open .hamburger-line:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.mobile-cost-bar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.85);
  box-shadow: 0 8px 30px rgba(35,45,70,.12);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  padding: 10px 16px;
  margin-bottom: 16px;
  justify-content: space-between;
  align-items: center;
}

.mobile-cost-label {
  color: var(--muted);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 750;
}

.mobile-cost-value {
  font-size: 1.45rem;
  font-weight: 820;
  letter-spacing: -.04em;
  color: var(--text);
}

.mobile-menu {
  display: none;
}

.mobile-menu:not([hidden]) {
  display: block;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  background: rgba(15,18,28,.35);
  backdrop-filter: blur(4px);
}

.mobile-menu-inner {
  position: absolute;
  top: 0;
  right: 0;
  width: min(100%, 400px);
  height: 100%;
  background: var(--surface-strong);
  overflow-y: auto;
  padding: 16px 18px 24px;
  box-shadow: -8px 0 40px rgba(15,18,28,.18);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.mobile-menu-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 4px;
}

.mobile-menu-title {
  font-weight: 800;
  font-size: .95rem;
  color: var(--text);
}

.mobile-menu-close {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text);
  line-height: 1;
  padding: 0;
}

.mobile-menu-close:hover {
  background: #f5f5f5;
}

.mobile-menu-section {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.mobile-menu-section:first-child { border-top: 0; padding-top: 0; }

.mobile-menu-label {
  display: block;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 7px;
}

.mobile-lang-select { width: 100%; }

.mobile-menu-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.mobile-menu-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--text);
  cursor: pointer;
  font-weight: 720;
}

.mobile-menu-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-weight: 800;
  font-size: .88rem;
  color: var(--text);
}

.mini-icon-button {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: white;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.mobile-record-input { margin-bottom: 6px; }

.mobile-saved-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
  margin-top: 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(245px, .56fr) minmax(0, 1.38fr) minmax(320px, .8fr);
  gap: 22px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.85);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
}

.form-card { padding: 24px; }
.saved-card, .summary-card { padding: 20px; position: sticky; top: 18px; }

.saved-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.saved-header h2 {
  margin: 0;
  font-size: 1.03rem;
}

.icon-button {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: white;
  color: var(--accent);
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
}

.saved-description {
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.45;
  margin-bottom: 16px;
}

.record-name-input {
  width: 100%;
  height: 44px;
  border: 1px solid #d8dee8;
  background: rgba(255,255,255,.95);
  border-radius: 12px;
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.record-name-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(39,100,231,.11);
}

.primary-button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 12px;
  margin-top: 9px;
  background: linear-gradient(145deg, #2764e7, #4b7ff0);
  color: white;
  font-weight: 780;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(39,100,231,.20);
}

.record-notice {
  min-height: 18px;
  margin: 8px 1px 2px;
  font-size: .73rem;
  color: var(--success);
}

.record-notice.error { color: var(--danger); }

.saved-list-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 15px 0 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.saved-count {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475467;
}

.saved-list {
  display: grid;
  gap: 8px;
  max-height: min(48vh, 480px);
  overflow: auto;
  padding-right: 2px;
}

.saved-empty {
  border: 1px dashed #cfd7e3;
  border-radius: 13px;
  padding: 15px 12px;
  text-align: center;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.45;
}

.saved-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px;
  align-items: stretch;
  border: 1px solid #e1e6ee;
  background: rgba(255,255,255,.78);
  border-radius: 13px;
  overflow: hidden;
  transition: .16s ease;
}

.saved-item:hover { border-color: #bac7d9; transform: translateY(-1px); }
.saved-item.active { border-color: var(--accent); background: var(--accent-soft); }

.saved-load {
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 11px 9px 10px 11px;
  cursor: pointer;
}

.saved-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: .82rem;
  font-weight: 780;
  margin-bottom: 4px;
}

.saved-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .68rem;
}

.saved-cost { color: var(--accent); font-weight: 780; white-space: nowrap; }

.saved-delete {
  border: 0;
  border-left: 1px solid rgba(206,214,225,.75);
  background: transparent;
  color: #98a2b3;
  cursor: pointer;
  font-size: 1.05rem;
}

.saved-delete:hover { background: #fff0ee; color: var(--danger); }

.storage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.storage-actions button {
  min-height: 37px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: #475467;
  cursor: pointer;
  font-size: .72rem;
  font-weight: 720;
}

.storage-help {
  color: var(--muted);
  font-size: .68rem;
  line-height: 1.4;
  margin: 10px 1px 0;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #edf0f5;
  border-radius: 15px;
  padding: 4px;
  margin-bottom: 24px;
}

.mode-toggle button {
  border: 0;
  background: transparent;
  border-radius: 12px;
  min-height: 44px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 750;
}

.mode-toggle button.active {
  background: white;
  color: var(--accent);
  box-shadow: 0 4px 14px rgba(29,41,57,.08);
}

.section {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-bottom: 16px;
  background: var(--surface);
}

.section:last-of-type { margin-bottom: 0; }
.section-heading { margin-bottom: 16px; }
.section-heading h2 { font-size: 1rem; margin-bottom: 5px; }
.section-heading p { color: var(--muted); font-size: .86rem; margin-bottom: 0; line-height: 1.45; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.field.full { grid-column: 1 / -1; }

label {
  display: block;
  font-size: .82rem;
  font-weight: 720;
  color: #344054;
  margin-bottom: 7px;
}

.input-wrap { position: relative; }
.input-wrap input, select {
  width: 100%;
  height: 47px;
  border: 1px solid #d8dee8;
  background: rgba(255,255,255,.92);
  border-radius: 12px;
  color: var(--text);
  padding: 0 13px;
  outline: none;
  transition: .18s ease;
}

.input-wrap input.has-prefix { padding-left: 38px; }
.input-wrap input.has-suffix { padding-right: 42px; }

.input-wrap input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(39,100,231,.11);
}

.prefix, .suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  font-size: .9rem;
}
.prefix { left: 13px; }
.suffix { right: 13px; }

.helper {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .76rem;
  line-height: 1.4;
}

.residual-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px;
  align-items: start;
}

.mini-button {
  height: 47px;
  border: 1px solid #cdd6e3;
  background: white;
  border-radius: 12px;
  padding: 0 13px;
  cursor: pointer;
  color: var(--accent);
  font-weight: 730;
  white-space: nowrap;
}

.finance-only[hidden] { display: none !important; }

.notice {
  display: none;
  margin: 0 0 18px;
  border: 1px solid #f2c9c5;
  background: #fff4f2;
  color: var(--danger);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: .82rem;
  line-height: 1.45;
}
.notice.show { display: block; }

.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .7rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.monthly-cost {
  font-size: clamp(2.15rem, 5vw, 3.25rem);
  font-weight: 820;
  letter-spacing: -.045em;
  margin-bottom: 5px;
}

.per-month { color: var(--muted); margin-bottom: 20px; }

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

.metric {
  background: #f7f9fc;
  border: 1px solid #e8ecf2;
  border-radius: 14px;
  padding: 12px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: .72rem;
  margin-bottom: 5px;
}
.metric strong { font-size: .98rem; }

.formula-box {
  background: var(--accent-soft);
  color: #183a82;
  border-radius: 14px;
  padding: 13px;
  font-size: .78rem;
  line-height: 1.55;
  margin-bottom: 16px;
}

details {
  border-top: 1px solid var(--line);
  padding: 3px 0;
}

summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 0;
  font-weight: 760;
  font-size: .9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--muted); font-size: 1.05rem; font-weight: 400; }
details[open] summary::after { content: "\2212"; }

.breakdown { padding: 0 0 12px; }

.line-item {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 7px 0;
  font-size: .8rem;
  color: #344054;
}

.line-item span:first-child { color: var(--muted); }
.line-item.total {
  border-top: 1px dashed #cad2df;
  margin-top: 6px;
  padding-top: 12px;
  font-weight: 800;
  color: var(--text);
}
.line-item.negative strong { color: var(--success); }

.year-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .73rem;
}
.year-table th, .year-table td {
  padding: 8px 5px;
  text-align: right;
  border-bottom: 1px solid #edf0f4;
}
.year-table th:first-child, .year-table td:first-child { text-align: left; }
.year-table th { color: var(--muted); font-weight: 750; }

.disclaimer {
  color: var(--muted);
  font-size: .72rem;
  line-height: 1.5;
  margin: 16px 0 0;
}

@media (max-width: 1120px) {
  .layout { grid-template-columns: 255px minmax(0, 1fr); }
  .summary-card { grid-column: 2; position: static; }
}

@media (max-width: 850px) {
  .toolbar-desktop { display: none; }
  .hamburger-button { display: flex; }
  .saved-card { display: none; }
  .mobile-cost-bar { display: flex; }

  .app-shell { width: min(100% - 20px, 1180px); padding-top: 12px; }

  .topbar {
    margin-bottom: 14px;
    gap: 10px;
  }

  .brand {
    flex: 1;
    min-width: 0;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 17px;
    flex-shrink: 0;
  }

  h1 { font-size: 1.15rem; }
  .subtitle { display: none; }

  .layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .summary-card { position: static; grid-column: auto; }

  .form-card { padding: 18px; }
  .summary-card { padding: 18px; }

  .grid { gap: 12px; }

  .section { padding: 16px; margin-bottom: 12px; }
}

@media (max-width: 570px) {
  .app-shell { width: min(100% - 14px, 1180px); padding-top: 10px; }

  .topbar { margin-bottom: 10px; }

  .brand-mark { display: none; }

  h1 { font-size: 1rem; }

  .form-card, .summary-card {
    padding: 14px;
    border-radius: 16px;
  }

  .grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }

  .summary-grid { grid-template-columns: 1fr 1fr; }

  .mobile-cost-bar {
    border-radius: 12px;
    padding: 10px 14px;
  }

  .mobile-cost-value { font-size: 1.35rem; }

  .mobile-menu-inner {
    width: 100%;
    padding: 14px 12px 20px;
  }

  .hamburger-button.open {
    z-index: 90;
  }

  .mode-toggle button { min-height: 40px; font-size: .9rem; }

  .input-wrap input, select { height: 44px; }

  .primary-button { min-height: 42px; }

  .mini-button { height: 44px; }

  .soft-button { padding: 0 10px; }
}

@media (max-width: 380px) {
  .monthly-cost { font-size: 1.8rem; }

  .summary-grid { grid-template-columns: 1fr; }

  .mobile-cost-value { font-size: 1.2rem; }
  .mobile-cost-label { font-size: .68rem; }
}

@media print {
  body { background: white; }
  .app-shell { width: 100%; padding: 0; }
  .topbar .toolbar, .saved-card, .form-card, .mobile-cost-bar, .hamburger-button, .mobile-menu { display: none; }
  .layout { display: block; }
  .summary-card { position: static; box-shadow: none; border: 1px solid #ddd; }
  details { display: block; }
  details > * { display: block; }
}
