*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0faf4;
  --sidebar-bg: #0f2027;
  --surface: #ffffff;
  --surface2: #f6fdf9;
  --border: #d4eddf;
  --accent: #059669;
  --accent-light: #d1fae5;
  --accent2: #7c3aed;
  --accent3: #f59e0b;
  --red: #ef4444;
  --red-light: #fee2e2;
  --blue: #3b82f6;
  --blue-light: #dbeafe;
  --text: #0f2027;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 4px 16px rgba(5,150,105,0.06);
  --sidebar-w: 240px;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem;
  z-index: 200;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0 0.5rem 2rem;
  font-family: 'Sora', sans-serif;
  font-weight: 800; font-size: 1.3rem; color: white;
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #34d399);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  color: #94a3b8; text-decoration: none;
  font-size: 0.9rem; font-weight: 500;
  transition: all 0.2s;
}
.nav-item:hover { background: rgba(255,255,255,0.07); color: white; }
.nav-item.active { background: rgba(5,150,105,0.25); color: #6ee7b7; }
.nav-icon { font-size: 1rem; }

.sidebar-region-toggle {
  margin-top: 1.5rem;
  padding: 1rem;
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.08);
}
.region-label {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: #64748b; margin-bottom: 0.6rem;
  display: block;
}
.region-btns { display: flex; gap: 0.4rem; }
.region-btn {
  flex: 1; background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: #94a3b8; padding: 0.5rem 0.4rem;
  border-radius: 8px; font-size: 0.82rem; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all 0.2s;
}
.region-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: white;
}

/* ── Main ── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* ── Mobile nav ── */
.mobile-nav {
  display: none; align-items: center; gap: 0.6rem;
  padding: 0.9rem 1rem;
  background: var(--sidebar-bg);
  position: sticky; top: 0; z-index: 200;
}
.logo-icon-sm {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, var(--accent), #34d399);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 0.9rem;
}
.mobile-logo-text {
  font-family: 'Sora', sans-serif; font-weight: 800;
  font-size: 1.1rem; color: white;
}
.mobile-region { margin-left: auto; display: flex; gap: 0.3rem; }
.mobile-region .region-btn { padding: 0.3rem 0.6rem; font-size: 0.75rem; }

/* ── Topbar ── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.5rem 2rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap; gap: 1rem;
}
.page-title {
  font-family: 'Sora', sans-serif; font-size: 1.5rem;
  font-weight: 700; color: var(--text);
}
.page-sub { color: var(--text-muted); font-size: 0.85rem; margin-top: 2px; }

.topbar-chips { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.chip {
  background: var(--accent-light); color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem; font-weight: 600;
  padding: 0.4rem 1rem; border-radius: 999px;
  border: 1px solid rgba(5,150,105,0.2);
}
.chip-green { background: #d1fae5; color: #065f46; border-color: rgba(5,150,105,0.3); }
.chip-red   { background: #fee2e2; color: #991b1b; border-color: rgba(239,68,68,0.3); }

/* ── Grid ── */
.page-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 1.5rem;
  padding: 1.5rem 2rem;
  align-items: start;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 1.5rem;
  flex-wrap: wrap; gap: 0.5rem;
}
.card-head h2 {
  font-family: 'Sora', sans-serif;
  font-size: 1rem; font-weight: 700;
}
.card-tag {
  background: var(--accent-light); color: var(--accent);
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 10px; border-radius: 999px;
  letter-spacing: 0.03em; text-transform: uppercase;
}
.card-desc { color: var(--text-muted); font-size: 0.88rem; line-height: 1.6; margin-bottom: 1.2rem; }

/* ── Form ── */
.form-group { margin-bottom: 1.2rem; }
.form-group.half { flex: 1; margin-bottom: 0; }
.form-row { display: flex; gap: 1rem; margin-bottom: 1.2rem; }
.input-row { display: flex; gap: 0.6rem; }
.flex1 { flex: 1; }
.w90 { width: 90px; flex-shrink: 0; }
.w160 { width: 160px; }

label {
  display: block; font-size: 0.78rem; font-weight: 700;
  color: var(--text-muted); margin-bottom: 0.4rem;
  text-transform: uppercase; letter-spacing: 0.05em;
}

.input-wrap {
  display: flex; align-items: center;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.1);
}
.input-prefix, .input-suffix {
  padding: 0 0.8rem; color: var(--text-muted);
  font-weight: 700; font-size: 0.9rem;
  background: var(--border); align-self: stretch;
  display: flex; align-items: center; flex-shrink: 0;
}
input[type="number"], input[type="text"] {
  border: none; background: transparent;
  padding: 0.72rem 1rem; font-size: 0.95rem;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: var(--text); width: 100%; outline: none;
  font-weight: 600;
}

.hint { font-size: 0.75rem; color: var(--text-light); margin-top: 0.3rem; }

.presets { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.presets button {
  background: var(--accent-light); color: var(--accent);
  border: none; padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 700; cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif; transition: all 0.2s;
}
.presets button:hover { background: var(--accent); color: white; }

/* ── LTV Bar ── */
.ltv-bar-wrap {
  margin-top: 0.6rem; height: 8px;
  background: var(--border); border-radius: 999px;
  position: relative; overflow: visible;
}
.ltv-bar {
  height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #34d399);
  transition: width 0.4s ease;
}
.ltv-label {
  display: block; font-size: 0.75rem;
  color: var(--text-muted); margin-top: 0.4rem;
  font-weight: 600;
}

/* ── Repayment toggle ── */
.repay-toggle {
  display: flex; gap: 0.5rem;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px;
}
.repay-btn {
  flex: 1; background: transparent; border: none;
  padding: 0.6rem 0.8rem; border-radius: 8px;
  font-size: 0.85rem; font-weight: 600; cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: var(--text-muted); transition: all 0.2s;
}
.repay-btn.active { background: var(--accent); color: white; }

/* ── Toggle ── */
.toggle-label {
  display: flex; align-items: center; gap: 0.6rem;
  cursor: pointer; font-size: 0.82rem; font-weight: 500;
  text-transform: none; letter-spacing: 0; color: var(--text);
}
.toggle-label.small { font-size: 0.78rem; }
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
  width: 36px; height: 20px; background: var(--border);
  border-radius: 999px; position: relative;
  transition: background 0.2s; flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; width: 14px; height: 14px;
  background: white; border-radius: 50%;
  position: absolute; top: 3px; left: 3px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-label input:checked + .toggle-switch { background: var(--accent); }
.toggle-label input:checked + .toggle-switch::after { left: 19px; }

/* ── Info row ── */
.info-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.info-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem; font-weight: 700; color: var(--accent2);
}

/* ── Monthly hero ── */
.monthly-hero {
  text-align: center;
  padding: 1.5rem 0 1.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.2rem;
}
.mh-label { font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 0.4rem; }
.mh-amount {
  font-family: 'Sora', sans-serif; font-size: 3rem;
  font-weight: 800; color: var(--accent); line-height: 1;
  letter-spacing: -0.02em; margin-bottom: 0.3rem;
}
.mh-sub { color: var(--text-muted); font-size: 0.82rem; }

/* ── Summary rows ── */
.summary-rows { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.5rem; }
.sum-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.8rem; border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.sum-row:hover { background: var(--surface2); }
.sum-label { color: var(--text-muted); font-weight: 500; }
.sum-val { font-family: 'JetBrains Mono', monospace; font-weight: 600; color: var(--text); }
.sum-row.highlight-red .sum-val { color: var(--red); }
.sum-row.highlight-green .sum-val { color: var(--accent); }

/* ── Donut ── */
.donut-wrap {
  position: relative; display: flex;
  justify-content: center;
  width: min(180px, 80vw); height: min(180px, 80vw);
  margin: 0 auto 0.8rem;
}
.donut-wrap canvas { width: 100% !important; height: 100% !important; }
.donut-center {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%); text-align: center;
}
.donut-pct { font-family: 'Sora', sans-serif; font-size: 1.6rem; font-weight: 800; }
.donut-lbl { font-size: 0.72rem; color: var(--text-muted); }
.donut-legend { display: flex; justify-content: center; gap: 1.2rem; font-size: 0.8rem; color: var(--text-muted); }
.dl { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }

/* ── Charts ── */
.chart-card { grid-column: 1 / -1; }
.chart-type-toggle { display: flex; gap: 0.3rem; }
.ct-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.35rem 0.9rem;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all 0.2s;
}
.ct-btn.active { background: var(--accent); color: white; border-color: var(--accent); }
.chart-container { position: relative; height: 320px; }

/* ── Overpayment ── */
.overpay-results {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem;
  margin-top: 1rem;
}
.overpay-stat {
  display: flex; align-items: flex-start; gap: 0.8rem;
  padding: 1rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.os-icon { font-size: 1.4rem; }
.os-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 0.3rem; }
.os-val { font-family: 'Sora', sans-serif; font-size: 1.1rem; font-weight: 700; }
.os-val.green { color: var(--accent); }

/* ── Renewal ── */
.renewal-compare {
  display: flex; align-items: center; justify-content: center;
  gap: 1rem; margin: 1rem 0;
}
.rc-box {
  flex: 1; padding: 1.2rem; border-radius: var(--radius-sm);
  text-align: center; border: 2px solid var(--border);
}
.rc-box.current { background: var(--accent-light); border-color: rgba(5,150,105,0.3); }
.rc-box.renewal { background: #fff7ed; border-color: rgba(245,158,11,0.3); }
.rc-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.4rem; }
.rc-rate { font-family: 'Sora', sans-serif; font-size: 1.8rem; font-weight: 800; color: var(--accent); }
.rc-box.renewal .rc-rate { color: var(--accent3); }
.rc-payment { font-family: 'JetBrains Mono', monospace; font-size: 1.2rem; font-weight: 700; margin-top: 0.3rem; }
.rc-sub { font-size: 0.75rem; color: var(--text-muted); }
.rc-arrow { font-size: 1.5rem; color: var(--text-light); }

.renewal-diff {
  text-align: center; padding: 0.8rem;
  background: var(--surface2); border-radius: var(--radius-sm);
  font-weight: 700; font-size: 0.95rem; margin-bottom: 1rem;
}
.renewal-stats { display: flex; flex-direction: column; gap: 0.4rem; }
.rs-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 0.8rem; border-radius: 8px; font-size: 0.88rem;
}
.rs-item:hover { background: var(--surface2); }
.rs-label { color: var(--text-muted); }
.rs-val { font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.rs-val.red { color: var(--red); }

/* ── Schedule ── */
.schedule-card { grid-column: 1 / -1; }
.schedule-view-toggle { display: flex; gap: 0.3rem; }
.sv-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); padding: 0.3rem 0.8rem;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all 0.2s;
}
.sv-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.schedule-wrap { overflow-x: auto; }
.schedule-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.85rem;
}
.schedule-table th {
  background: var(--surface2); padding: 0.7rem 1rem;
  text-align: right; font-size: 0.75rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
.schedule-table th:first-child { text-align: left; }
.schedule-table td {
  padding: 0.65rem 1rem; text-align: right;
  border-bottom: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace; font-size: 0.82rem;
}
.schedule-table td:first-child { text-align: left; font-family: 'Plus Jakarta Sans', sans-serif; font-weight: 600; }
.schedule-table tr:hover td { background: var(--surface2); }
.schedule-table tr.highlight td { background: #fef3c7; }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .page-grid { grid-template-columns: 1fr; }
  .chart-card, .schedule-card { grid-column: 1; }
}

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .mobile-nav { display: flex; }
  .page-grid { padding: 1rem; gap: 1rem; }
}

@media (max-width: 768px) {
  .topbar {
    flex-direction: column; align-items: flex-start;
    padding: 1rem; gap: 0.8rem;
    width: 100%;
  }
  .topbar-chips { width: 100%; flex-wrap: wrap; }
  .chip { font-size: 0.78rem; padding: 0.3rem 0.8rem; }
  .page-grid { padding: 0.75rem; gap: 0.75rem; width: 100%; }
  .card { padding: 1.2rem; width: 100%; min-width: 0; }

  /* Form */
  .form-row { flex-direction: column; gap: 0.8rem; }
  .form-group.half { width: 100%; min-width: 0; }
  .input-row { flex-wrap: nowrap; min-width: 0; }
  .w90 { width: 80px; flex-shrink: 0; }
  .w160 { width: 100%; }
  .input-wrap { min-width: 0; }
  input[type="number"], input[type="text"] { min-width: 0; width: 100%; }

  /* Monthly hero */
  .mh-amount { font-size: 2.2rem; }
  .mh-sub { font-size: 0.78rem; }

  /* Summary */
  .sum-row { font-size: 0.82rem; padding: 0.5rem 0.6rem; }
  .sum-label, .sum-val { font-size: 0.82rem; }

  /* Charts */
  .chart-card .card-head { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  .chart-type-toggle { flex-wrap: wrap; gap: 0.4rem; width: 100%; }
  .ct-btn { font-size: 0.75rem; padding: 0.3rem 0.7rem; }
  .chart-container { height: 220px; }

  /* Overpayment */
  .overpay-results { grid-template-columns: 1fr; }
  .os-val { font-size: 1rem; }

  /* Renewal */
  .renewal-compare { flex-direction: column; gap: 0.6rem; }
  .rc-arrow { transform: rotate(90deg); align-self: center; }
  .rc-rate { font-size: 1.5rem; }
  .rc-payment { font-size: 1rem; }
  .renewal-stats .rs-item { flex-wrap: wrap; gap: 0.2rem; }

  /* Schedule */
  .schedule-card .card-head { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
  .schedule-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; }
  .schedule-table { min-width: 500px; }
  .sv-btn { font-size: 0.75rem; padding: 0.3rem 0.7rem; }

  /* Presets */
  .presets button { font-size: 0.75rem; padding: 2px 9px; }
}

@media (max-width: 480px) {
  .page-title { font-size: 1.2rem; }
  .page-sub { font-size: 0.78rem; }
  .mh-amount { font-size: 1.8rem; }
  .card { padding: 0.9rem; }
  .card-head h2 { font-size: 0.9rem; }
  .page-grid { padding: 0.5rem; gap: 0.5rem; }

  /* Topbar chips grid */
  .topbar-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
  .chip { text-align: center; font-size: 0.72rem; padding: 0.3rem 0.5rem; }

  /* Inputs */
  .w90 { width: 68px; }
  input[type="number"], input[type="text"] { padding: 0.55rem 0.6rem; font-size: 0.85rem; }
  .input-prefix, .input-suffix { padding: 0 0.5rem; font-size: 0.8rem; }

  /* Monthly hero */
  .monthly-hero { padding: 1rem 0; }
  .mh-label { font-size: 0.72rem; }

  /* Renewal boxes */
  .rc-box { padding: 0.8rem; }

  /* Overpay stats */
  .overpay-stat { padding: 0.75rem; gap: 0.6rem; }
  .os-icon { font-size: 1.1rem; }
  .os-label { font-size: 0.7rem; }

  /* Schedule */
  .schedule-table { min-width: 440px; }
  .schedule-table th, .schedule-table td { padding: 0.45rem 0.5rem; font-size: 0.75rem; }

  /* Donut */
  .donut-wrap { width: 140px; height: 140px; }
  .donut-pct { font-size: 1.2rem; }
  .donut-legend { font-size: 0.75rem; gap: 0.8rem; }

  /* Info row */
  .info-row { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
  .info-val { font-size: 1rem; }

  /* Mobile nav */
  .mobile-logo-text { font-size: 0.95rem; }
  .mobile-region .region-btn { font-size: 0.7rem; padding: 0.25rem 0.5rem; }
}
