:root {
  /* Shared Base Colors */
  --bg: #f7f8fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e6eaf2;
  --soft: #f2f5fb;
  --accent: #1e293b;

  /* Brand Colors */
  --navy-2: #111827;
  --gold: #d4a843;
  --gold-lt: #f0c865;

  /* Utilities */
  --shadow: 0 0.625rem 1.5625rem rgba(15, 23, 42, 0.06);
  --radius: 1rem;
  --focus: 0 0 0 0.25rem rgba(37, 99, 235, 0.15);
}

* {
  box-sizing: border-box;
}

/* ── Base Calculator App Shell ── */
body {
  background-color: #0f172a;
  background-image:
    radial-gradient(at 0% 0%, hsla(263, 45%, 25%, 0.4) 0px, transparent 70%), radial-gradient(at 100% 100%, hsla(180, 50%, 20%, 0.25) 0px, transparent 70%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.25' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.03'/%3E%3C/svg%3E");
  background-blend-mode: normal, normal, overlay;
  background-attachment: fixed;
  color: var(--text);
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  height: 100%;
  max-height: 1440px;
  padding: 1.5rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 1.5rem;
  width: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page {
  animation: fadeUp 0.2s ease both;
  display: none;
  max-width: 35rem;
  width: 100%;
}
.page.active {
  display: flex;
  flex-direction: column;
}
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.grid {
  display: grid;
  gap: 1rem;
  width: 100%;
}

label {
  color: var(--muted);
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.375rem;
}

.field {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  display: flex;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
}
.field:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

input,
select {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 0.875rem;
  outline: 0;
  width: 100%;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ── Button Components ── */
.btn {
  border-radius: 0.75rem;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  transition: all 0.2s;
  border: none;
  white-space: normal;
  line-height: 1.2;
  text-align: center;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  max-width: 264px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}
.btn.primary:hover {
  background: #0f172a;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
}

/* ── Calculator Specific Layouts ── */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-shrink: 0;
  min-height: 56px;
}
.nav-back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: #475569;
  border-radius: 50%;
  display: flex;
  align-items: center;
  width: 32px;
  height: 32px;
  justify-content: center;
}
.nav-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.visual-area {
  height: 180px;
  margin-bottom: 0.5rem;
  width: 100%;
  position: relative;
}
.chart-container {
  height: 100%;
  min-height: 170px;
  width: 100%;
  position: relative;
}
.play-zone {
  padding: 0.75rem;
  margin-top: 0.5rem;
  border-radius: 8px;
  background: var(--soft);
  border: 1px solid var(--line);
}

/* ── Sliders & Inputs ── */
.labelWithTip {
  display: flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  padding-top: 0.25rem;
  margin-bottom: 0.25rem;
}
.slider-group {
  margin-bottom: 0.75rem;
}
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}
.slider-input {
  width: 90px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-align: right;
  color: var(--accent);
}
input[type="number"].slider-input {
  width: 4ch;
  min-width: 40px;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  border-radius: 2px;
  cursor: pointer;
  margin-top: 8px;
  outline: none;
  --track-fill: #3273f6;
  --track-muted: rgba(255, 255, 255, 0.15);
  --pct: 0%;
  background: linear-gradient(to right, var(--track-fill) 0%, var(--track-fill) var(--pct), var(--track-muted) var(--pct), var(--track-muted) 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}
input[type="range"].accent-target {
  --track-fill: var(--palette-target);
}
input[type="range"].accent-principal,
input[type="range"].accent-current {
  --track-fill: var(--palette-principal);
}
input[type="range"].accent-contribution {
  --track-fill: var(--palette-contributions);
}
input[type="range"].accent-return {
  --track-fill: var(--palette-returns);
}
input[type="range"].accent-fee,
input[type="range"].accent-income {
  --track-fill: var(--palette-fees);
}
input[type="range"].accent-gold {
  --track-fill: var(--palette-gold, #d4a843);
  --track-muted: rgba(255, 255, 255, 0.1);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  cursor: pointer;
  border: 0.5px solid var(--muted);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
  transition: transform 0.1s;
}
input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.2);
}
input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 2px;
  background: var(--track-muted);
  border: none;
}
input[type="range"]::-moz-range-progress {
  height: 5px;
  border-radius: 2px;
  background: var(--track-fill);
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--track-fill);
  cursor: pointer;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
}

/* ── Tabs & Grids ── */
.seg-toggle {
  display: flex;
  gap: 0.375rem;
  background: #e2e8f0;
  border-radius: 0.6rem;
  padding: 0.2rem;
  margin-bottom: 0.75rem;
}
.seg-toggle button {
  flex: 1;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #64748b;
  transition: all 0.2s;
}
.seg-toggle button.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.row-paired {
  display: grid;
  gap: 1rem;
}
.row-paired .slider-group {
  margin-bottom: 0;
}
.row-7-3 {
  grid-template-columns: 7fr 3fr;
}
.row-1-1 {
  grid-template-columns: 1fr 1fr;
}

/* ── Dynamic Line Items (Estate & Life Cover) ── */
.line-items {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.line-item-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}
.li-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.li-header input {
  border: none;
  outline: none;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.75rem;
  flex: 1;
}
.li-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.li-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.li-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
}

.line-item-simple {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.line-item-simple input.li-desc {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0;
}
.li-amount-wrap {
  width: 130px;
  flex-shrink: 0;
}

.remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #cbd5e1;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0;
}
.remove-btn-simple {
  background: none;
  border: none;
  cursor: pointer;
  color: #cbd5e1;
  font-size: 1.25rem;
  line-height: 1;
  padding: 0 0.25rem;
}
.add-btn {
  width: 100%;
  padding: 0.75rem;
  border: 1px dashed #cbd5e1;
  border-radius: 0.75rem;
  background: transparent;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.add-btn:hover {
  background: #fff;
  border-color: var(--gold);
  color: var(--gold);
}

/* ── Estate Ledger Waterfall ── */
.ledger-container {
  background: #1e293b;
  border-radius: 8px;
  padding: 1rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  color: #e2e8f0;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.2);
  overflow-y: auto;
}
.ledger-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0;
  font-size: 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.ledger-row:last-child {
  border-bottom: none;
}
.ledger-label {
  color: #94a3b8;
}
.ledger-val {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ledger-subtotal {
  margin-top: 0.25rem;
  padding-top: 0.5rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
}
.ledger-subtotal .ledger-label {
  color: #f8fafc;
  font-weight: 600;
  font-size: 0.8rem;
}
.ledger-final {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 2px solid rgba(255, 255, 255, 0.2);
}
.ledger-final .ledger-label {
  color: #4ade80;
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
}
.ledger-final .ledger-val {
  color: #4ade80;
  font-size: 1.1rem;
  font-weight: 800;
}
.val-negative {
  color: #f87171;
}
.val-tax {
  color: #facc15;
}

/* ── Special Components (TFSA / Ret / Life) ── */
.annual-cap-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  margin: -0.25rem 0 0.75rem;
  padding: 0.2rem 0.1rem;
}
.annual-cap-value {
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}
.annual-cap-value.at-limit {
  color: #ef4444;
}

.tax-summary-box {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
  box-sizing: border-box;
}
.tax-summary-box .slider-group {
  margin-bottom: 0;
}
.tax-metrics-container {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}
.tax-metric-card {
  flex: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
.tax-metric-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.15rem;
}
.tax-metric-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: #06b6d4;
}
.tax-metric-val.secondary {
  color: #4ade80;
}

.bracket-viz {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.75rem;
}
.bracket-viz-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.6rem;
}
.bracket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  margin-bottom: 0.25rem;
  transition: all 0.2s;
  border: 1px solid transparent;
}
.bracket-row.active {
  background: #1e293b;
  color: #fff;
  border-color: #334155;
}
.bracket-row.below {
  background: rgba(30, 41, 59, 0.04);
  color: var(--muted);
}
.bracket-row.above {
  color: #94a3b8;
}
.br-range {
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}
.br-calc {
  font-size: 0.65rem;
  text-align: right;
  line-height: 1.4;
}
.br-you {
  font-weight: 700;
  color: #f59e0b;
  display: none;
}
.bracket-row.active .br-you {
  display: inline;
}

.inflation-footer {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.inflation-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

/* ── Mobile Adjustments ── */
@media (max-width: 480px) {
  .app {
    padding: 0;
  }
  .card {
    border-radius: 0;
    border: none;
  }
  .content {
    padding: 0.5rem 0.75rem !important;
  }
}

/* =============================================================================
   DESKTOP LAYOUT  ≥ 1000px
   ─────────────────────────────────────────────────────────────────────────────
   Two-panel split: controls left, results + chart right.
============================================================================= */
@media (min-width: 1000px) {
  .app {
    max-width: 1100px;
    padding: 1.5rem 2rem;
  }
  .content {
    overflow-y: hidden;
    padding: 0 !important;
    align-items: stretch;
  }
  .page {
    max-width: none;
  }
  .page.active {
    max-width: none;
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  .report-container {
    display: grid;
    grid-template-columns: 360px 1fr;
    grid-template-rows: auto 1fr;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .play-zone {
    grid-column: 1;
    grid-row: 1 / span 2;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: var(--soft);
    margin-top: 0;
    padding: 1.25rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  /* Calculators with a Chart/Ledger Area */
  .report-container > .ch-hero--with-chart {
    grid-column: 2;
    grid-row: 1;
    padding: 1rem 1.25rem 0.75rem;
  }

  /* Calculators without a Chart span the full right side */
  .report-container > .ch-hero--full {
    grid-column: 2;
    grid-row: 1 / span 2;
    border-radius: 0;
    margin-bottom: 0;
    padding: 1.5rem;
    box-shadow: none;
    border-top: none;
    border-right: none;
    border-bottom: none;
  }

  .visual-area {
    grid-column: 2;
    grid-row: 2;
    height: auto !important;
    margin-bottom: 0;
    padding: 0 1rem 1rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  .chart-container {
    flex: 1;
    min-height: 0;
    height: 100% !important;
    min-height: 180px;
  }
  .tax-summary-box {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
}
