:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #1c2530;
  --muted: #64707d;
  --line: #d8dde3;
  --blue: #2563eb;
  --teal: #0f766e;
  --red: #c0264d;
  --shadow: 0 18px 44px rgba(28, 37, 48, 0.1);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px max(18px, calc((100vw - 1480px) / 2 + 22px));
  border-bottom: 1px solid rgba(28, 37, 48, 0.08);
  background: rgba(238, 241, 244, 0.88);
  backdrop-filter: blur(16px);
}

.topbar h1,
h2,
h3,
p {
  letter-spacing: 0;
}

.topbar h1,
h2,
h3,
p {
  margin-top: 0;
}

.topbar h1 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
  line-height: 1.15;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tab-nav {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.75);
}

.tab-nav button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  padding: 8px 12px;
}

.tab-nav button.active {
  background: var(--ink);
  color: #fff;
}

.shell {
  max-width: 1480px;
  margin: 0 auto;
  padding: 22px;
}

.inputs-panel {
  display: grid;
  grid-template-columns: minmax(360px, 500px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.content-stack {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.input-panel {
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 104px);
  overflow: auto;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #fbfcfd);
}

.button-row {
  display: flex;
  gap: 8px;
}

.sample-tools {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(160px, 220px) auto;
}

.sample-control {
  gap: 5px;
}

.sample-control span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.sample-control select {
  min-height: 36px;
  padding: 7px 9px;
}

.ghost-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
  padding: 8px 11px;
}

.compact-button {
  flex: 0 0 auto;
  min-width: 88px;
}

.ghost-button:hover,
.ghost-button:focus {
  border-color: var(--blue);
  color: var(--blue);
  outline: none;
}

.form-grid {
  display: grid;
  gap: 14px;
  padding: 16px;
}

fieldset {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

legend {
  padding: 0 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.input-label-help {
  align-items: center;
  cursor: help;
  display: inline-flex;
  justify-self: start;
}

.input-label-help:focus {
  border-radius: 4px;
  outline: 2px solid rgba(37, 99, 235, 0.18);
  outline-offset: 3px;
}

.input-help-tooltip,
.table-value-tooltip,
.chart-tooltip {
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(28, 37, 48, 0.16);
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;
  padding: 11px 12px;
  pointer-events: none;
}

.input-help-tooltip,
.table-value-tooltip {
  left: 0;
  position: fixed;
  top: 0;
  z-index: 80;
}

.table-value-tooltip {
  white-space: pre-line;
  z-index: 90;
}

.tooltip-title {
  color: var(--ink);
  display: block;
  font-size: 13px;
  font-weight: 950;
  line-height: 1.25;
}

.tooltip-body {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 7px;
  margin-top: 8px;
  padding-top: 8px;
}

.tooltip-row {
  align-items: start;
  border-left: 3px solid #cbd3dd;
  display: grid;
  gap: 4px 9px;
  grid-template-columns: minmax(82px, max-content) minmax(0, 1fr);
  padding-left: 8px;
}

.tooltip-row.divider {
  border-top: 1px solid var(--line);
  margin-top: 2px;
  padding-top: 8px;
}

.tooltip-label {
  color: var(--muted);
  font-weight: 950;
}

.tooltip-detail {
  color: var(--ink);
  font-weight: 750;
  min-width: 0;
  overflow-wrap: anywhere;
}

.tooltip-detail:only-child {
  grid-column: 1 / -1;
}

.tooltip-formula {
  background: #f6f8fb;
  border: 1px solid #e4e9ef;
  border-radius: 5px;
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.5;
  padding: 2px 5px;
}

.tooltip-row.hdb {
  border-left-color: var(--teal);
}

.tooltip-row.hdb .tooltip-label {
  color: var(--teal);
}

.tooltip-row.condo {
  border-left-color: var(--red);
}

.tooltip-row.condo .tooltip-label {
  color: var(--red);
}

.tooltip-row.investment {
  border-left-color: #7c3aed;
}

.tooltip-row.investment .tooltip-label {
  color: #6d28d9;
}

.tooltip-row.gap {
  border-left-color: var(--blue);
}

.tooltip-row.gap .tooltip-label {
  color: var(--blue);
}

.tooltip-row.loan,
.tooltip-row.example {
  border-left-color: #8b98a8;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 9px 10px;
}

input:disabled,
select:disabled {
  background: #f2f5f8;
  color: #8b98a8;
  cursor: not-allowed;
}

.muted-field span {
  color: #8b98a8;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.result-panel {
  background: linear-gradient(135deg, #ffffff 0%, #f7fbff 100%);
}

.result-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
  border-bottom: 1px solid var(--line);
}

.result-hero p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.result-hero strong {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 34px;
  line-height: 1;
  text-align: right;
}

.metric-grid,
.quick-breakdown {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px;
}

.metric,
.quick-breakdown div {
  min-width: 0;
  border: 1px solid rgba(28, 37, 48, 0.07);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.75);
  padding: 13px;
}

.metric span,
.quick-breakdown span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.25;
}

.metric strong,
.quick-breakdown strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.metric small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.warning-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 16px 20px 18px 38px;
}

.warning-list li {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
}

.breakdown-bars {
  display: grid;
  gap: 16px;
  padding: 0 16px 18px;
}

.breakdown-group {
  display: grid;
  gap: 9px;
}

.breakdown-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.breakdown-heading span {
  color: var(--muted);
  font-weight: 850;
}

.stack-bar {
  display: flex;
  height: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e9ee;
}

.stack-bar span.hdb,
.breakdown-legend i.hdb,
.chart-legend i.hdb {
  background: var(--teal);
}

.stack-bar span.investment,
.breakdown-legend i.investment {
  background: var(--blue);
}

.stack-bar span.condo,
.breakdown-legend i.condo,
.chart-legend i.condo {
  background: var(--red);
}

.breakdown-legend,
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.breakdown-legend span,
.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.breakdown-legend i,
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.assumptions-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 18px;
  align-items: start;
}

.sources-panel {
  grid-column: 1 / -1;
}

.assumption-list {
  display: grid;
  gap: 0;
  padding: 16px 20px 20px;
}

details {
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

details:first-child {
  border-top: 1px solid var(--line);
}

summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 12px 0;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::after {
  content: "+";
  color: var(--blue);
  font-size: 18px;
  line-height: 1;
}

details[open] summary {
  border-bottom: 0;
}

details[open] summary::after {
  content: "-";
}

details p {
  margin: 0;
  padding: 0 24px 14px 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.5;
}

.sample-profile-list {
  display: grid;
  gap: 12px;
  padding: 0 0 15px;
}

.sample-profile-list article {
  padding: 0;
}

.sample-profile-list h3 {
  font-size: 13px;
  margin: 0 0 4px;
}

.sample-profile-list p {
  padding: 0;
}

.panel-note {
  margin: 0;
  padding: 0 20px 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 16px 20px 20px;
}

.source-list a {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
  padding: 8px 10px;
  text-decoration: none;
}

.source-list a:hover,
.source-list a:focus {
  border-color: var(--blue);
  outline: none;
}

.chart-frame {
  padding: 12px 18px 18px;
  overflow-x: auto;
}

.chart-frame svg {
  display: block;
  width: 100%;
}

.chart-stage {
  min-width: 680px;
  position: relative;
}

.chart-grid {
  stroke: #dfe5eb;
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hdb-line {
  stroke: var(--teal);
}

.condo-line {
  stroke: var(--red);
}

.line-dot {
  stroke: #fff;
  stroke-width: 2;
}

.hdb-dot {
  fill: var(--teal);
}

.condo-dot {
  fill: var(--red);
}

.chart-hit-area {
  cursor: crosshair;
  fill: transparent;
  pointer-events: all;
}

.crosshair-line {
  stroke: rgba(28, 37, 48, 0.58);
  stroke-dasharray: 4 4;
  stroke-width: 1.5;
}

.crosshair-line.vertical {
  stroke: rgba(28, 37, 48, 0.72);
  stroke-width: 1.7;
}

.crosshair-line.year-tick {
  stroke: rgba(28, 37, 48, 0.72);
  stroke-dasharray: none;
  stroke-linecap: round;
}

.crosshair-line.hdb-horizontal {
  stroke: rgba(15, 118, 110, 0.72);
}

.crosshair-line.condo-horizontal {
  stroke: rgba(192, 38, 77, 0.72);
}

.crosshair-gap-line {
  stroke: rgba(28, 37, 48, 0.78);
  stroke-linecap: round;
  stroke-width: 3;
}

.crosshair-dot {
  stroke: #fff;
  stroke-width: 2;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
}

.chart-tooltip .tooltip-row {
  align-items: center;
  grid-template-columns: auto 1fr auto;
}

.chart-tooltip i {
  border-radius: 999px;
  display: inline-block;
  height: 9px;
  width: 9px;
}

.chart-tooltip i.hdb {
  background: var(--teal);
}

.chart-tooltip i.condo {
  background: var(--red);
}

.table-wrap {
  width: 100%;
  overflow: visible;
}

.table-panel {
  overflow: visible;
}

.table-wrap.compact {
  padding: 16px 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.projection-table {
  min-width: 1120px;
}

.projection-table.advanced {
  min-width: 100%;
}

.projection-table.advanced th,
.projection-table.advanced td {
  font-size: 12px;
  padding-left: 7px;
  padding-right: 7px;
}

.projection-table thead tr:first-child th:first-child,
.projection-table tbody th {
  width: 72px;
  min-width: 72px;
  max-width: 72px;
  white-space: nowrap;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: right;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 25;
  background: #f3f6f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.projection-table thead tr:first-child th {
  top: 0;
}

.projection-table thead tr:nth-child(2) th {
  top: 39px;
  z-index: 24;
}

.projection-table .scenario-head {
  color: var(--ink);
  text-align: center;
}

.projection-table .hdb-head {
  background: #e8f7f2;
}

.projection-table .condo-head {
  background: #fff0f4;
  border-left: 3px solid #cbd3dd;
}

tbody th,
.number-table th {
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-align: left;
}

.projection-table tbody th,
.projection-table thead tr:first-child th:first-child {
  background: #fff;
  box-shadow: 1px 0 0 var(--line);
  left: 0;
  position: sticky;
  z-index: 23;
}

.projection-table thead tr:first-child th:first-child {
  background: #f3f6f9;
  z-index: 27;
}

td {
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.projection-table td.hdb-cell {
  background: rgba(237, 253, 247, 0.62);
}

.projection-table td.condo-cell {
  background: rgba(255, 242, 245, 0.68);
}

.projection-table .scenario-start,
.projection-table .scenario-start-subhead {
  border-left: 3px solid #cbd3dd;
}

.projection-table td.difference-cell {
  background: #fff;
  font-weight: 950;
}

.projection-table [data-tooltip],
.stack-bar [data-tooltip] {
  cursor: help;
}

.projection-table .scenario-total {
  font-weight: 950;
}

.projection-table .checkpoint-row th,
.projection-table .checkpoint-row td {
  border-top: 2px solid #aeb8c4;
}

tbody tr:hover th,
tbody tr:hover td {
  background: #fbfdff;
}

.positive {
  color: var(--teal);
}

.negative {
  color: var(--red);
}

.number-table th,
.number-table td {
  padding: 10px 0;
}

.number-table tr:last-child th,
.number-table tr:last-child td,
.projection-table tr:last-child th,
.projection-table tr:last-child td {
  border-bottom: 0;
}

.top-button {
  align-items: center;
  background: rgba(28, 37, 48, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  bottom: 22px;
  box-shadow: 0 18px 42px rgba(28, 37, 48, 0.2);
  color: #fff;
  display: flex;
  font-size: 18px;
  height: 44px;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  position: fixed;
  right: 22px;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease, background 160ms ease;
  width: 44px;
  z-index: 30;
}

.top-button.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.top-button:hover,
.top-button:focus {
  background: var(--blue);
  outline: none;
}

@media (max-width: 1120px) {
  .inputs-panel,
  .assumptions-grid {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
    max-height: none;
  }

  .metric-grid,
  .quick-breakdown {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .table-wrap,
  .table-panel .table-wrap {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }

  .projection-table.advanced {
    min-width: 1760px;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .tab-nav {
    overflow-x: auto;
  }

  .tab-nav button {
    flex: 1 0 auto;
  }

  .shell {
    padding: 12px;
  }

  .panel {
    border-radius: 7px;
  }

  .form-grid {
    padding: 12px;
  }

  .panel-heading,
  .result-hero {
    padding: 16px;
  }

  fieldset,
  .metric-grid,
  .quick-breakdown {
    grid-template-columns: 1fr;
  }

  .result-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-hero strong {
    text-align: left;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .sample-tools {
    align-items: stretch;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .button-row {
    width: 100%;
  }

  .button-row .ghost-button {
    flex: 1 1 0;
  }

  .metric-grid,
  .quick-breakdown {
    padding: 12px;
  }

  .chart-frame {
    padding: 8px 12px 14px;
  }

  .chart-stage {
    min-width: 560px;
  }

  .projection-table {
    min-width: 980px;
  }

  th,
  td {
    font-size: 12px;
    padding: 9px 8px;
  }

  .projection-table thead tr:nth-child(2) th {
    top: 36px;
  }

  .table-panel .table-wrap {
    overflow-x: auto;
  }

  .top-button {
    bottom: 16px;
    height: 42px;
    right: 16px;
    width: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
