/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy:    #0c447c;
  --blue:    #185fa5;
  --blue-lt: #e6f1fb;
  --teal:    #0e7f8a;
  --bg:      #12181f;
  --surface: #1c2530;
  --surface2:#232e3c;
  --border:  #2e3d50;
  --text:    #dce4ee;
  --muted:   #7a8fa6;
  --green:   #3b6d11;
  --green-lt:#eaf3de;
  --red:     #a32d2d;
  --red-lt:  #fce8e8;
  --sand:    #f1efe8;
  --radius:  10px;
  --shadow:  0 4px 24px rgba(0,0,0,.45);
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

h1, h2, h3 { font-weight: 700; line-height: 1.2; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0a1520 0%, #12283a 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 44px 44px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo {
  font-size: 3rem;
  margin-bottom: 12px;
}

.login-card h1 {
  font-size: 1.5rem;
  color: #fff;
  margin-bottom: 6px;
}

.login-sub {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 24px;
}

.error-msg {
  background: var(--red-lt);
  color: var(--red);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: .85rem;
  margin-bottom: 16px;
  border: 1px solid #e8b0b0;
}

.input-wrap {
  margin-bottom: 16px;
}

.input-wrap input,
input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}

.input-wrap input:focus,
input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--blue);
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

.btn-primary:hover { background: #1a6ec4; }
.btn-primary:active { transform: scale(.98); }

/* ============================================================
   NAV
   ============================================================ */
.site-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nav-logo {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
  letter-spacing: -.01em;
}

.nav-links {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--muted);
  transition: background .15s, color .15s;
}

.nav-link:hover, .nav-link.active {
  background: var(--surface2);
  color: var(--text);
  text-decoration: none;
}

.nav-logout {
  color: #e07777;
}

.nav-logout:hover {
  background: rgba(163,45,45,.15);
  color: #f08080;
}

/* ============================================================
   PAGE LAYOUT
   ============================================================ */
.page-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 1.75rem;
  color: #fff;
  margin-bottom: 4px;
}

.page-header p {
  color: var(--muted);
  font-size: .9rem;
}

/* ============================================================
   GRID LAYOUT
   ============================================================ */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
}

/* Results/summaries above inputs */
.results-panel { order: -1; }

.inputs-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

/* ============================================================
   CARDS / PANELS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card-title {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ============================================================
   METRIC CARDS
   ============================================================ */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.metric-label {
  font-size: .72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.metric-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
}

.metric-val.blue  { color: #5ba3e8; }
.metric-val.green { color: #7cc94a; }
.metric-val.red   { color: #e07777; }
.metric-val.muted { color: var(--muted); }

/* ============================================================
   SLIDERS
   ============================================================ */
.slider-section {
  margin-bottom: 8px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(46,61,80,.5);
}

.slider-row:last-child { border-bottom: none; }

.slider-label {
  flex: 1;
  font-size: .85rem;
  color: var(--text);
  min-width: 0;
}

.slider-note {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 1px;
}

.slider-label-text { display: block; }

.slider-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  transition: transform .1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  border: 2px solid #fff;
}

.slider-val {
  font-size: .85rem;
  font-weight: 600;
  color: #fff;
  min-width: 72px;
  text-align: right;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  transition: border-color .15s, background .15s;
}

.slider-val:hover {
  border-color: var(--border);
  background: var(--surface2);
}

.slider-val-yr {
  font-size: .72rem;
  color: var(--muted);
  min-width: 62px;
  text-align: right;
  white-space: nowrap;
}

.slider-val-input {
  font-size: .85rem;
  font-weight: 600;
  min-width: 72px;
  width: 72px;
  text-align: right;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--blue);
  background: var(--surface2);
  color: #fff;
  outline: none;
}

/* ============================================================
   HOUSING BUY / RENT TOGGLE
   ============================================================ */
.housing-toggle-row {
  margin-bottom: 14px;
}

.housing-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.housing-toggle-btn {
  flex: 1;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s;
}

.housing-toggle-btn.active {
  background: var(--blue);
  color: #fff;
}

.housing-toggle-btn:not(.active):hover {
  background: var(--surface2);
  color: var(--text);
}

/* Disabled slider rows (rent mode) */
.slider-row-disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* ============================================================
   CATEGORY HEADERS
   ============================================================ */
.cat-header {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface2);
  padding: 6px 12px;
  margin: 12px -20px 4px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* ============================================================
   GAUGE BAR
   ============================================================ */
.gauge-wrap {
  margin-bottom: 16px;
}

.gauge-label-row {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.gauge-bar-bg {
  height: 12px;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.gauge-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width .3s ease, background .3s;
  background: var(--blue);
}

.gauge-bar-fill.warn  { background: #e09020; }
.gauge-bar-fill.over  { background: var(--red); }

/* ============================================================
   SURPLUS / DEFICIT STATUS BAR
   ============================================================ */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: 16px;
}

.status-bar.surplus {
  background: var(--green-lt);
  color: var(--green);
  border: 1px solid #b3d98a;
}

.status-bar.deficit {
  background: var(--red-lt);
  color: var(--red);
  border: 1px solid #e8b0b0;
}

.status-bar .status-amount {
  font-size: 1.15rem;
}

/* ============================================================
   EXPORT BUTTON
   ============================================================ */
.btn-export {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--navy);
  color: #fff;
  border: 1px solid #1a5a9e;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  margin-top: 8px;
  width: 100%;
  justify-content: center;
}

.btn-export:hover { background: var(--blue); }
.btn-export:active { transform: scale(.98); }

/* ============================================================
   RESULTS PANEL (right column)
   ============================================================ */
.results-panel .card {
  margin-bottom: 16px;
}

/* ============================================================
   CHART
   ============================================================ */
.chart-wrap {
  position: relative;
  height: 320px;
}

/* ============================================================
   SNAPSHOT TABLE
   ============================================================ */
.snapshot-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.snapshot-table th {
  background: var(--navy);
  color: #fff;
  padding: 8px 10px;
  text-align: right;
  font-weight: 600;
  font-size: .75rem;
  letter-spacing: .03em;
}

.snapshot-table th:first-child { text-align: left; }

.snapshot-table td {
  padding: 7px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.snapshot-table td:first-child { text-align: left; font-weight: 600; }

.snapshot-table tbody tr:nth-child(odd) { background: var(--surface2); }
.snapshot-table tbody tr:hover { background: rgba(24,95,165,.12); }

.snapshot-table .total-col { color: #5ba3e8; font-weight: 700; }
.snapshot-table .gain-col  { color: #7cc94a; }

/* ============================================================
   INCOME TABLE (budget summary)
   ============================================================ */
.income-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}

.income-table th {
  background: var(--navy);
  color: #fff;
  padding: 7px 10px;
  text-align: right;
  font-weight: 600;
  font-size: .75rem;
}

.income-table th:first-child { text-align: left; }

.income-table td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.income-table td:first-child { text-align: left; }

.income-table tbody tr:nth-child(odd) { background: var(--surface2); }

.income-table .highlight-row td {
  background: rgba(24,95,165,.18);
  color: #5ba3e8;
  font-weight: 700;
}

/* ============================================================
   INPUTS SECTION (salary, mortgage controls)
   ============================================================ */
/* .inputs-col grid is defined in the GRID LAYOUT section above */

.section-label {
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ============================================================
   COLLAPSIBLE BUDGET SECTION
   ============================================================ */
.budget-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  padding: 10px 0;
  user-select: none;
}

.budget-section-header:hover .cat-toggle { color: var(--text); }

.cat-toggle {
  font-size: .75rem;
  color: var(--muted);
  transition: transform .2s, color .15s;
}

.cat-toggle.open { transform: rotate(90deg); }

.budget-section-body {
  overflow: hidden;
  transition: max-height .25s ease;
}

/* ============================================================
   MISC UTILITIES
   ============================================================ */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.text-muted { color: var(--muted); }
.text-blue  { color: #5ba3e8; }
.text-green { color: #7cc94a; }
.text-red   { color: #e07777; }
.text-white { color: #fff; }
.fw-bold    { font-weight: 700; }
.fs-sm      { font-size: .8rem; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  .page-wrap { padding: 16px 14px 60px; }

  .metrics-row { grid-template-columns: 1fr 1fr; }

  .nav-link { padding: 5px 10px; font-size: .8rem; }

  /* Stack label above slider so the track goes nearly edge-to-edge */
  .slider-row {
    flex-wrap: wrap;
  }

  .slider-control {
    flex: 1 1 100%;
  }

  input[type="range"] {
    flex: 1;
    width: auto;
    height: 6px;
  }

  /* Bigger thumb for touch */
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
  }

  .slider-val { min-width: 62px; }
}
