:root {
  color-scheme: light;
  --bg: #eef7ff;
  --surface: #ffffff;
  --surface-soft: #f8fbff;
  --chart-bg: #ffffff;
  --header-card: rgba(255, 255, 255, 0.82);
  --tabs-bg: #f4f9ff;
  --table-head-bg: #edf6ff;
  --hover-bg: #e7f3ff;
  --active-bg: rgba(0, 184, 217, 0.13);
  --page-glow: rgba(0, 184, 217, 0.18);
  --ink: #10213f;
  --muted: #61728a;
  --line: #d4e4f2;
  --line-strong: #b6d0e7;
  --green: #00b8d9;
  --green-dark: #005fb8;
  --blue: #123fbc;
  --gold: #2d94ff;
  --red: #a33d3d;
  --shadow: 0 18px 40px rgba(21, 77, 130, 0.1);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101713;
  --surface: #18221d;
  --surface-soft: #121b17;
  --chart-bg: #0f1713;
  --header-card: rgba(24, 34, 29, 0.88);
  --tabs-bg: #141d18;
  --table-head-bg: #1b2922;
  --hover-bg: #203128;
  --active-bg: rgba(71, 196, 155, 0.14);
  --page-glow: rgba(71, 196, 155, 0.09);
  --ink: #edf5ef;
  --muted: #a8b6ad;
  --line: #2d3d34;
  --line-strong: #43564c;
  --green: #47c49b;
  --green-dark: #79e1c1;
  --blue: #7da4e8;
  --gold: #d69a37;
  --red: #e17373;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, var(--page-glow), rgba(245, 246, 241, 0) 220px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 18px;
}

.app-header h1,
.panel-heading h2 {
  margin: 0;
  color: var(--ink);
  line-height: 1.1;
}

.app-header h1 {
  font-size: 2rem;
  font-weight: 750;
}

.brand-name {
  display: inline;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 auto;
  width: 62px;
  height: 62px;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 14px 32px rgba(18, 63, 188, 0.16);
}

.panel-heading h2 {
  font-size: 1.35rem;
  font-weight: 720;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green-dark);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.header-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(132px, 1fr));
  gap: 10px;
  min-width: 300px;
}

.header-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.theme-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header-card);
  color: var(--ink);
  padding: 10px 14px;
  font-size: 0.84rem;
  font-weight: 760;
  white-space: nowrap;
}

.theme-button:hover {
  background: var(--hover-bg);
}

.theme-icon {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--green-dark);
  font-size: 1.15rem;
  line-height: 1;
}

.header-summary span {
  display: grid;
  gap: 3px;
  min-height: 62px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header-card);
  color: var(--muted);
  font-size: 0.82rem;
}

.header-summary strong {
  color: var(--ink);
  font-size: 1rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  align-items: start;
}

.tool-panel {
  max-width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-panel {
  position: sticky;
  top: 16px;
  padding: 20px;
}

.output-panel {
  min-width: 0;
  overflow: hidden;
}

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

.panel-heading.compact {
  margin-bottom: 14px;
}

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

.field {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
}

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

.cdi-lookup-field {
  grid-column: 1 / -1;
}

.field > span:first-child,
.field-label,
.segmented-group legend {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 680;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  outline: none;
  padding: 10px 12px;
}

.field input:focus,
.field select:focus,
.tab-button:focus-visible,
.ghost-button:focus-visible,
.lookup-button:focus-visible,
.theme-button:focus-visible,
.stepper-button:focus-visible,
.visibility-button:focus-visible,
.chart-control:focus-visible,
.legend-action:focus-visible,
.primary-button:focus-visible {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(49, 93, 159, 0.16);
}

.field .input-prefix + input {
  padding-left: 42px;
}

.field .input-suffix + input {
  padding-right: 40px;
}

.stepper-control {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  min-width: 0;
}

.stepper-control input {
  grid-column: 1 / -1;
  padding-right: 46px;
}

.stepper-control .input-prefix + input {
  padding-left: 42px;
}

.stepper-buttons {
  position: absolute;
  top: 4px;
  right: 4px;
  display: grid;
  gap: 2px;
  width: 30px;
  height: calc(100% - 8px);
}

.stepper-button {
  display: grid;
  place-items: center;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1;
  padding: 0;
}

.stepper-button:hover {
  background: var(--hover-bg);
  color: var(--green-dark);
}

.input-with-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.input-wrap {
  position: relative;
  display: block;
  min-width: 0;
}

.input-wrap .input-suffix + input {
  padding-right: 40px;
}

.input-prefix,
.input-suffix {
  position: absolute;
  bottom: 12px;
  color: var(--muted);
  font-size: 0.92rem;
  pointer-events: none;
}

.input-prefix {
  left: 13px;
}

.input-suffix {
  right: 13px;
}

.segmented-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0 12px;
  padding: 0;
  border: 0;
}

.segmented-group legend {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.segmented-group label {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 720;
}

.segmented-group input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-group label:has(input:checked) {
  border-color: rgba(17, 121, 95, 0.4);
  background: var(--active-bg);
  color: var(--green-dark);
}

.rate-grid {
  align-items: end;
}

.field-hint {
  min-height: 18px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.field-hint.success {
  color: var(--green-dark);
}

.field-hint.error {
  color: var(--red);
}

.is-hidden {
  display: none !important;
}

.ghost-button,
.primary-button,
.lookup-button,
.tab-button {
  min-height: 38px;
  border-radius: 8px;
  font-weight: 740;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.ghost-button {
  border: 1px solid var(--line-strong);
  background: var(--surface-soft);
  color: var(--ink);
  padding: 8px 12px;
}

.lookup-button {
  align-self: stretch;
  border: 1px solid rgba(17, 121, 95, 0.35);
  background: var(--active-bg);
  color: var(--green-dark);
  padding: 8px 12px;
  white-space: nowrap;
}

.ghost-button:hover,
.lookup-button:hover,
.tab-button:hover {
  background: var(--hover-bg);
}

.lookup-button:disabled {
  cursor: wait;
  opacity: 0.68;
}

.primary-button {
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: #ffffff;
  padding: 8px 14px;
}

.primary-button:hover {
  background: var(--green-dark);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--tabs-bg);
}

.tab-button {
  flex: 0 1 auto;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 12px;
}

.tab-button.is-active {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

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

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

.metric {
  display: grid;
  align-content: space-between;
  gap: 8px;
  min-height: 94px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.metric .metric-label,
.metric > span:first-child {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.metric-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.metric strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 1.22rem;
  line-height: 1.12;
}

.visibility-button {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.visibility-button:hover {
  color: var(--green-dark);
  background: var(--hover-bg);
}

.eye-icon {
  position: relative;
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-radius: 75% 15%;
  transform: rotate(45deg);
}

.eye-icon::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.eye-icon.is-off::after {
  content: "";
  position: absolute;
  top: 6px;
  left: -5px;
  width: 22px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-90deg);
}

.visual-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(230px, 300px);
  gap: 12px;
}

.chart-block,
.comparison-block,
.rate-table,
.tax-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.chart-block {
  min-width: 0;
}

.chart-block.narrow {
  display: grid;
  align-content: start;
}

.chart-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 10px;
}

.chart-title strong {
  font-size: 0.95rem;
}

.chart-title span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
  text-align: right;
}

.chart-controls {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 10px;
}

.chart-control {
  min-height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 760;
}

.chart-control.is-active {
  border-color: rgba(17, 121, 95, 0.4);
  background: var(--active-bg);
  color: var(--green-dark);
}

canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  border-radius: 6px;
}

#growthChart {
  cursor: crosshair;
}

#breakdownChart {
  cursor: pointer;
}

#growthChart {
  aspect-ratio: 7 / 3;
  min-height: 240px;
}

#breakdownChart {
  aspect-ratio: 1 / 1;
  max-height: 260px;
  margin: 0 auto;
}

.legend-row,
.legend-stack {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 690;
}

.legend-row {
  flex-wrap: wrap;
  margin-top: 10px;
}

.legend-stack {
  display: grid;
  grid-template-columns: 1fr;
  margin-top: 12px;
}

.legend-action {
  display: flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  text-align: left;
  font-size: 0.82rem;
  font-weight: 720;
}

.legend-action:hover,
.legend-action.is-active {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.legend {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
  vertical-align: -1px;
}

.legend.invested {
  background: var(--blue);
}

.legend.gross {
  background: var(--gold);
}

.legend.net {
  background: var(--green);
}

.legend.tax {
  background: var(--red);
}

.comparison-block {
  margin-top: 12px;
}

.inflation-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 14px;
  cursor: pointer;
}

.inflation-option input { accent-color: var(--blue); }
.inflation-hint { margin: 6px 0 0 24px; color: var(--muted); font-size: 12px; }
.comparison-rate {
  width: 80px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.selection-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.selection-detail span,
.selection-detail strong {
  display: block;
}

.selection-detail .detail-item {
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 9px 10px;
}

.selection-detail span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 720;
}

.selection-detail strong {
  margin-top: 4px;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.composition-detail {
  grid-template-columns: 1fr;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.compact-table {
  max-height: 320px;
}

.schedule-table {
  max-height: 610px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--table-head-bg);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 780;
}

td {
  color: var(--ink);
  font-size: 0.9rem;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tr.active-row td {
  background: rgba(17, 121, 95, 0.08);
  color: var(--green-dark);
  font-weight: 720;
}

.tax-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.tax-line {
  display: grid;
  gap: 8px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 13px;
}

.tax-line span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 680;
}

.tax-line strong {
  overflow-wrap: anywhere;
  line-height: 1.15;
}

.tax-note {
  margin-bottom: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.rate-table strong {
  display: block;
  margin-bottom: 10px;
}

.app-footer {
  width: min(1440px, calc(100% - 40px));
  margin: 14px auto 28px;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

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

@media (max-width: 760px) {
  .app-header,
  .app-shell,
  .app-footer {
    width: calc(100% - 24px);
    max-width: 1440px;
  }

  .app-header {
    display: grid;
    align-items: start;
    padding-top: 18px;
  }

  .header-actions {
    display: grid;
    width: 100%;
  }

  .theme-button,
  .header-summary {
    width: 100%;
    min-width: 0;
  }

  .app-header h1 {
    font-size: 1.35rem;
    line-height: 1.16;
  }

  .brand-name {
    display: block;
  }

  .brand-separator {
    display: none;
  }

  .brand-block {
    align-items: flex-start;
    gap: 10px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  .header-summary,
  .field-grid,
  .metric-grid,
  .visual-grid,
  .tax-grid {
    grid-template-columns: 1fr;
  }

  .segmented-group {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: visible;
  }

  .tab-button {
    flex: 1 1 0;
    min-width: 0;
    padding-right: 6px;
    padding-left: 6px;
    font-size: 0.82rem;
  }

  .chart-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .chart-title span {
    text-align: left;
  }

  .chart-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .chart-control {
    padding-right: 4px;
    padding-left: 4px;
    font-size: 0.74rem;
  }

  .selection-detail {
    grid-template-columns: 1fr;
  }

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

  .primary-button,
  .ghost-button,
  .lookup-button {
    width: 100%;
  }

  .input-with-action {
    grid-template-columns: 1fr;
  }

  .stepper-control {
    grid-template-columns: minmax(0, 1fr) 38px;
    gap: 6px;
  }

  .stepper-control input {
    grid-column: 1;
    padding-right: 12px;
  }

  .stepper-control .input-prefix + input {
    padding-left: 42px;
  }

  .stepper-buttons {
    position: static;
    grid-column: 2;
    width: 38px;
    height: 44px;
  }

  .tab-panel,
  .input-panel {
    padding: 14px;
  }

  #growthChart {
    min-height: 210px;
  }
}
