:root {
  color-scheme: light;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: #f4f1ec;
  color: #1f2a2e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(247, 244, 238, 0.96), rgba(236, 240, 237, 0.96)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='80' viewBox='0 0 80 80'%3E%3Cpath d='M0 79h80M1 0v80' stroke='%23d4d8d2' stroke-width='1' opacity='.45'/%3E%3C/svg%3E");
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: #16697a;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 1050px;
  margin-bottom: 10px;
  font-size: clamp(1.55rem, 1.75vw, 1.75rem);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 3px;
  font-size: 1.06rem;
}

h3 {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.lede {
  max-width: 680px;
  margin-bottom: 0;
  color: #5f696b;
  font-size: 1.02rem;
  line-height: 1.55;
}

.primary-action,
.ghost-button,
.select-button,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 750;
}

.primary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 22px;
  background: #16697a;
  color: #fff;
  box-shadow: 0 12px 30px rgba(22, 105, 122, 0.2);
}

.run-action {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.simulation-running-message {
  max-width: 260px;
  margin: 0;
  color: #5f696b;
  font-size: 0.82rem;
  font-weight: 750;
  line-height: 1.35;
  text-align: right;
}

.button-spinner,
.simulation-spinner {
  flex: 0 0 auto;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.button-spinner {
  width: 16px;
  height: 16px;
}

.simulation-spinner {
  width: 30px;
  height: 30px;
  color: #16697a;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ghost-button,
.select-button {
  padding: 0 14px;
  border-color: #ccd6d4;
  background: #fff;
  color: #243235;
}

.secondary-action {
  border-color: #8fb4af;
  background: #edf6f4;
  color: #16697a;
  box-shadow: none;
}

.ghost-button:disabled,
.primary-action:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.compact-action {
  min-height: 34px;
  padding: 0 12px;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  background: #f4d7d2;
  color: #842316;
}

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

.panel,
.metric-card,
.empty-state {
  border: 1px solid rgba(36, 50, 53, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 20px 60px rgba(35, 47, 46, 0.08);
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel-heading,
.cashflow-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-heading p {
  margin-bottom: 0;
  color: #667174;
  font-size: 0.9rem;
}

.scenario-list {
  display: grid;
  gap: 12px;
}

.side-form {
  display: grid;
  gap: 12px;
}

.model-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 12px;
  border: 1px solid #d8dfdc;
  border-radius: 8px;
  background: #fbfcfa;
}

.scenario-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: end;
}

.scenario-name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 0.46fr 34px;
  gap: 8px;
  align-items: end;
}

.scenario-save-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.save-scenario-button {
  width: 100%;
  grid-column: span 2;
}

.saved-scenario-select {
  min-width: 0;
}

.delete-scenario-button {
  align-self: end;
}

.scenario-message {
  margin: 0;
  color: #536064;
  font-size: 0.86rem;
  font-weight: 700;
}

.field-error {
  margin: 0;
  color: #9b2c1f;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.35;
}

.scenario-panel .compact-grid {
  grid-template-columns: 1fr;
}

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

.assumption-row {
  display: grid;
  gap: 10px;
}

.assumption-row.two-column {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.assumption-row.one-column {
  grid-template-columns: 1fr;
}

.assumption-row.three-column {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.assumption-row label span {
  min-height: 2em;
  display: flex;
  align-items: end;
}

.allocation-group {
  display: grid;
  gap: 10px;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid #e1e6e3;
}

.allocation-group h3 {
  color: #344144;
}

.calculated-return {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  color: #536064;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calculated-return span {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: 8px;
  background: #eef5f2;
}

.calculated-return .tooltip-label {
  grid-template-columns: auto 16px;
  align-items: center;
}

.calculated-return .tooltip-label strong {
  grid-column: 1 / -1;
}

.calculated-return strong {
  color: #16697a;
  font-size: 1rem;
}

.scenario-editor {
  display: grid;
  gap: 12px;
}

.scenario-editor.active {
  border-color: #16697a;
  box-shadow: inset 4px 0 0 #16697a;
}

.scenario-save-panel,
.scenario-editor,
.side-section {
  padding: 14px;
  border: 1px solid #d8dfdc;
  border-radius: 8px;
  background: #fbfcfa;
}

.side-section {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.side-section .panel-heading {
  margin-bottom: 0;
}

.scenario-topline,
.check-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.check-label {
  justify-content: start;
  color: #526064;
  font-size: 0.9rem;
  font-weight: 700;
  min-height: 24px;
}

.model-options .check-label input[type="checkbox"] {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
}

.model-options .check-label {
  font-size: 0.72rem;
}

.model-options .tooltip-label b {
  width: 14px;
  height: 14px;
  font-size: 0.62rem;
}

label,
.field-label {
  display: grid;
  gap: 6px;
  color: #536064;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #ccd6d4;
  border-radius: 8px;
  background: #fff;
  color: #1f2a2e;
  padding: 8px 10px;
  font-size: 0.94rem;
  font-weight: 600;
  text-transform: none;
}

textarea {
  min-height: 86px;
  resize: vertical;
  line-height: 1.35;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
}

input[type="radio"] {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 0;
}

.return-tax-field {
  gap: 10px;
}

.segmented-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(116px, 1fr));
  gap: 8px;
}

.tax-mode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

.radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #d8dfdc;
  border-radius: 8px;
  background: #fff;
  color: #536064;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.tax-rate-table {
  display: grid;
  gap: 4px;
  max-height: 260px;
  overflow: auto;
}

.tax-rate-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 7px 8px;
  border-radius: 7px;
  background: #f6f8f6;
  color: #344144;
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: none;
}

.tax-rate-header {
  background: transparent;
  color: #6d777a;
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

.assumption-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.main-panel,
.results-grid {
  display: grid;
  gap: 18px;
}

.simulation-running-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  border-color: #8fb4af;
  background: #f5fbf8;
}

.simulation-running-panel h2 {
  margin-bottom: 2px;
}

.simulation-running-panel p {
  margin: 0;
  color: #5f696b;
  font-size: 0.92rem;
}

.cashflow-heading {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid #e1e6e3;
}

.cashflow-table,
.summary-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.cashflow-table:has(.rich-tooltip:hover),
.cashflow-table:has(.rich-tooltip:focus-within),
.summary-table:has(.rich-tooltip:hover),
.summary-table:has(.rich-tooltip:focus-within) {
  overflow: visible;
}

.detail-table {
  display: grid;
  gap: 8px;
  overflow-x: auto;
}

.cashflow-row,
.summary-row {
  display: grid;
  gap: 8px;
  align-items: center;
}

.cashflow-row {
  grid-template-columns: 1.16fr 0.45fr 0.45fr 0.8fr 0.95fr 0.45fr 34px;
  min-width: 980px;
}

.cashflow-tax-control {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.cashflow-tax-control:has(input) {
  grid-template-columns: minmax(0, 1fr) 70px;
}

.summary-row {
  grid-template-columns: 1.1fr 0.45fr 0.58fr 0.52fr 0.68fr 0.75fr 0.75fr 0.85fr 1fr;
  min-width: 1080px;
  padding: 11px 12px;
  border-radius: 8px;
  background: #f6f8f6;
  color: #344144;
  font-weight: 650;
}

.summary-row:not(.summary-header) > :nth-child(5) {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 6px;
  background: #f6e2a8;
  color: #5f4700;
  font-weight: 850;
}

.detail-row {
  display: grid;
  grid-template-columns: 0.34fr 0.34fr 0.9fr 0.88fr 0.8fr 0.76fr 0.8fr 0.74fr 0.68fr 0.86fr;
  gap: 4px;
  align-items: center;
  min-width: 0;
  padding: 9px 8px;
  border-radius: 8px;
  background: #f6f8f6;
  color: #344144;
  font-size: 0.8rem;
  font-weight: 650;
}

.detail-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.cashflow-header,
.summary-header,
.detail-header {
  background: transparent;
  color: #6d777a;
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

.inline-select {
  width: min(260px, 100%);
}

.tooltip-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tooltip-label b {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 1px solid #9aaba8;
  border-radius: 50%;
  color: #16697a;
  font-family: Georgia, serif;
  font-size: 0.72rem;
  font-style: italic;
  font-weight: 800;
  line-height: 1;
}

.rich-tooltip {
  position: relative;
}

.tooltip-card {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 20;
  display: none;
  width: min(380px, calc(100vw - 32px));
  padding: 10px 12px;
  border: 1px solid #b9cbc7;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 14px 35px rgba(35, 47, 46, 0.16);
  color: #344144;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.35;
  text-transform: none;
}

.calculated-return .tooltip-card {
  display: none;
  pointer-events: none;
}

.cashflow-table .tooltip-card,
.summary-table .tooltip-card {
  right: 0;
  left: auto;
}

.summary-table .summary-header .tooltip-card {
  top: calc(100% + 8px);
  right: 0;
  left: auto;
}

.model-options .tooltip-card,
.calculated-return .tooltip-card,
.summary-table .tooltip-card,
.cashflow-table .tooltip-card {
  font-size: 0.92rem;
}

.assumption-row label .tooltip-card {
  display: none;
  min-height: 0;
  align-items: initial;
}

.tooltip-card span,
.tooltip-card a {
  display: block;
}

.tooltip-card .tooltip-spacer {
  height: 8px;
}

.tooltip-card a {
  margin-top: 4px;
  color: #16697a;
  overflow-wrap: anywhere;
}

.rich-tooltip:hover .tooltip-card,
.rich-tooltip:focus-within .tooltip-card {
  display: block;
}

.calculated-return .rich-tooltip:focus-within .tooltip-card {
  display: none;
}

.calculated-return .rich-tooltip:hover .tooltip-card {
  display: block;
}

.histogram-frame {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.histogram-y-axis {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  height: 180px;
  margin-top: 8px;
  color: #6d777a;
  font-size: 0.72rem;
  font-weight: 800;
  text-align: right;
}

.histogram {
  --bar-count: 45;
  display: grid;
  grid-template-columns: repeat(var(--bar-count), minmax(12px, 1fr));
  gap: 4px;
  min-height: 220px;
  overflow-x: auto;
  padding: 8px 0 4px;
}

.histogram-item {
  display: grid;
  grid-template-rows: 180px auto;
  gap: 8px;
  min-width: 16px;
}

.histogram-bar-wrap {
  display: flex;
  align-items: end;
  min-height: 180px;
  border-radius: 6px;
  background: #edf2ef;
  overflow: hidden;
}

.histogram-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 6px 6px 0 0;
  background: #16697a;
}

.histogram-item span {
  color: #6d777a;
  font-size: 0.7rem;
  font-weight: 800;
  text-align: center;
}

.chart-panel {
  overflow: hidden;
}

.chart-panel .line-chart {
  overflow: visible;
}

.chart-panel {
  overflow-x: auto;
}

.line-chart {
  min-width: 680px;
  width: 100%;
  height: auto;
  display: block;
}

.axis {
  stroke: #738083;
  stroke-width: 1.4;
}

.axis-tick {
  stroke: #738083;
  stroke-width: 1.2;
}

.grid-line {
  stroke: #dfe5e2;
  stroke-width: 1;
}

.tick-label {
  fill: #6a7679;
  font-size: 13px;
  font-weight: 700;
}

.x-tick-label {
  font-size: 12px;
}

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

.iteration-line {
  fill: none;
  stroke: #16697a;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.12;
}

.all-path-average-line {
  stroke: #16697a;
  stroke-width: 4;
  opacity: 0.95;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 8px;
  color: #536064;
  font-size: 0.9rem;
  font-weight: 750;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.metric-card {
  padding: 16px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  color: #16697a;
  font-size: 2.4rem;
  line-height: 1;
}

.metric-card > span {
  color: #657174;
  font-weight: 700;
}

.metric-pair {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: #536064;
}

.metric-pair b {
  color: #263235;
}

.empty-state {
  min-height: 240px;
  padding: 38px;
  display: grid;
  place-content: center;
  text-align: center;
}

.empty-state p {
  margin-bottom: 0;
  color: #667174;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .masthead {
    align-items: start;
  }

  .scenario-list,
  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cashflow-row,
  .summary-row,
  .detail-row {
    gap: 6px;
    font-size: 0.9rem;
  }

  .cashflow-header,
  .summary-header,
  .detail-header {
    font-size: 0.7rem;
  }

  .cashflow-row {
    min-width: 900px;
  }

  .summary-row {
    min-width: 980px;
  }

  .detail-row {
    min-width: 0;
  }
}

@media (max-width: 820px) {
  .shell {
    width: min(100% - 20px, 760px);
    padding-top: 10px;
  }

  .masthead {
    display: grid;
    gap: 16px;
    padding: 18px 0;
  }

  .run-action,
  .primary-action {
    width: 100%;
  }

  .run-action {
    justify-items: stretch;
  }

  .simulation-running-message {
    max-width: none;
    text-align: left;
  }

  .panel {
    padding: 14px;
  }

  .panel-heading {
    display: grid;
    align-items: start;
  }

  .panel-heading .ghost-button,
  .panel-heading .inline-select {
    width: 100%;
  }

  .scenario-list,
  .compact-grid,
  .assumption-grid,
  .metric-strip,
  .plan-row,
  .assumption-row.two-column,
  .assumption-row.three-column,
  .tax-mode-row,
  .calculated-return {
    grid-template-columns: 1fr;
  }

  .scenario-actions {
    grid-template-columns: 1fr 34px;
  }

  .scenario-name-row {
    grid-template-columns: 1fr 34px;
  }

  .scenario-name-row label {
    grid-column: 1 / -1;
  }

  .saved-scenario-select {
    grid-column: 1 / -1;
  }

  .model-options {
    grid-template-columns: 1fr;
  }

  .histogram-frame {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .histogram {
    grid-template-columns: repeat(var(--bar-count), minmax(16px, 1fr));
  }

  .cashflow-row,
  .summary-row,
  .detail-row {
    font-size: 0.82rem;
  }

  .cashflow-row input,
  .cashflow-row select {
    padding: 6px 7px;
    font-size: 0.82rem;
  }

  .cashflow-row {
    min-width: 820px;
  }

  .summary-row {
    min-width: 900px;
  }

  .detail-row {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100% - 12px, 540px);
  }

  .scenario-save-panel,
  .scenario-editor,
  .side-section {
    padding: 12px;
  }

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

  .save-scenario-button {
    grid-column: auto;
  }

  .cashflow-row,
  .summary-row,
  .detail-row {
    gap: 5px;
    font-size: 0.76rem;
  }

  .cashflow-header,
  .summary-header,
  .detail-header {
    font-size: 0.66rem;
  }

  .cashflow-row {
    min-width: 760px;
  }

  .summary-row {
    min-width: 830px;
  }

  .detail-row {
    min-width: 0;
  }

  .line-chart {
    min-width: 620px;
  }

  .tooltip-card {
    width: min(320px, calc(100vw - 24px));
  }
}
