:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17211d;
  --muted: #5b6861;
  --line: #d9e0dc;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d9f2ed;
  --good-bg: #dff5e8;
  --good-ink: #14532d;
  --bad-bg: #ffe1df;
  --bad-ink: #8a1f17;
  --warn-bg: #fff3d6;
  --warn-ink: #684600;
  --shadow: 0 22px 60px rgba(19, 35, 30, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(500px, 580px) minmax(0, 1fr);
  gap: 16px;
  width: min(1380px, calc(100% - 24px));
  margin: 12px auto;
  align-items: start;
}

.input-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  padding: 16px;
  position: sticky;
  top: 12px;
  overflow-x: hidden;
}

.results-panel {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.title-block {
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: start;
}

.eyebrow {
  grid-column: 1 / -1;
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.reset-button {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
  min-height: 34px;
  padding: 0 12px;
}

.reset-button:hover,
.reset-button:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.mode-switch {
  grid-column: 1;
  display: flex;
  width: fit-content;
  max-width: 100%;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
}

.mode-button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
  padding: 0 14px;
}

.mode-help-button {
  grid-column: 2;
  justify-self: end;
  align-self: center;
  width: 32px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--accent-dark);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 900;
  padding: 0;
}

.mode-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(19, 35, 30, 0.12);
}

.mode-button:focus,
.mode-help-button:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
}

.mode-help-button:hover {
  background: var(--panel);
  color: var(--ink);
}

.app-shell.is-simple .detailed-only {
  display: none !important;
}

.app-shell.is-detailed .simple-only {
  display: none !important;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 1.8vw, 1.8rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

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

fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px 10px;
}

.form-grid > fieldset {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

legend {
  grid-column: 1 / -1;
  padding: 0 0 4px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
  min-width: 0;
}

input {
  width: 100%;
  min-width: 0;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fbfcfb;
  color: var(--ink);
}

input:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  border-color: var(--accent);
}

.money-input,
.suffix-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  overflow: hidden;
  min-width: 0;
}

.suffix-input {
  grid-template-columns: minmax(0, 1fr) auto;
}

.money-input span,
.suffix-input span {
  padding: 0 11px;
  color: var(--muted);
  font-weight: 800;
}

.money-input input,
.suffix-input input {
  border: 0;
  height: 34px;
  border-radius: 0;
  background: transparent;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
  align-self: end;
  min-width: 0;
}

.segmented label {
  display: block;
  cursor: pointer;
}

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

.segmented span {
  display: grid;
  min-height: 30px;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: center;
  line-height: 1.1;
  padding: 0 4px;
}

.segmented input:checked + span {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(19, 35, 30, 0.12);
}

.toggle-row {
  grid-column: 1 / -1;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.toggle-row span {
  font-size: 0.82rem;
  line-height: 1.25;
}

details {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 800;
}

.assumptions-dialog {
  width: min(560px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--ink);
  box-shadow: var(--shadow);
}

.assumptions-dialog::backdrop {
  background: rgba(23, 33, 29, 0.42);
}

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

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.assumption-summary {
  display: grid;
  gap: 8px;
  padding: 16px 18px 4px;
}

.assumption-summary p {
  margin: 0;
  color: var(--ink);
  font-size: 0.98rem;
  line-height: 1.35;
}

.simple-assumptions {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 14px 24px 18px 38px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.35;
}

.simple-assumptions strong {
  font-weight: 850;
}

.assumptions {
  margin-top: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.assumptions legend {
  grid-column: 1 / -1;
}

.warning {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-weight: 750;
}

.hero-result {
  padding: 24px;
  border-radius: 8px;
  background: var(--accent-soft);
  border: 1px solid #b8e2db;
}

.hero-result p,
.hero-result span {
  color: var(--accent-dark);
}

.hero-result p {
  margin-bottom: 4px;
  font-weight: 800;
}

.hero-result strong {
  display: block;
  margin-bottom: 6px;
  font-size: clamp(2.6rem, 7vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero-result span {
  display: block;
  max-width: 58ch;
  font-size: 0.95rem;
}

.savings-status {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.savings-status.is-good {
  background: var(--good-bg);
  border-color: #a8dfbd;
  color: var(--good-ink);
}

.savings-status.is-bad {
  background: var(--bad-bg);
  border-color: #f3b4af;
  color: var(--bad-ink);
}

.savings-status p,
.savings-status span {
  margin: 0 0 5px;
  display: block;
  font-size: 0.84rem;
  font-weight: 800;
}

.savings-status strong {
  display: block;
  font-size: 1.25rem;
  line-height: 1.15;
}

.app-shell.is-simple .savings-status {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 20px;
}

.app-shell.is-simple .savings-status strong {
  font-size: 1.45rem;
}

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

.app-shell.is-simple .metrics-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.metrics-grid article {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  align-content: space-between;
  gap: 12px;
}

.metrics-grid span,
.income-band span,
.section-heading p {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.metrics-grid strong {
  font-size: 1.18rem;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.income-band {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 18px 0;
}

.income-band.is-good {
  border-color: #a8dfbd;
}

.income-band.is-bad {
  border-color: #f3b4af;
}

.income-alert {
  width: fit-content;
  margin-bottom: 0;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 800;
}

.income-option-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
  width: fit-content;
  max-width: 100%;
}

.income-option-button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  padding: 0 12px;
}

.income-option-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(19, 35, 30, 0.12);
}

.income-option-button:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
}

.income-band.is-good .income-alert {
  background: var(--good-bg);
  color: var(--good-ink);
}

.income-band.is-bad .income-alert {
  background: var(--bad-bg);
  color: var(--bad-ink);
}

.income-band,
.income-band > div {
  display: grid;
  gap: 14px;
}

.income-band > div {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.income-band p {
  margin-bottom: 0;
  display: grid;
  gap: 3px;
}

.income-band strong {
  font-size: 1.6rem;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.section-heading p {
  margin-bottom: 0;
  text-align: right;
}

.tabbed-section {
  display: grid;
  gap: 12px;
}

.tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f0;
  width: fit-content;
  max-width: 100%;
}

.tab-button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
  padding: 0 12px;
}

.tab-button.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(19, 35, 30, 0.12);
}

.tab-button:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18);
}

.tab-panel {
  min-width: 0;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.breakdown-table table {
  min-width: 1500px;
}

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

th {
  background: #eef3f0;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

td:nth-child(3),
td:nth-child(4) {
  font-weight: 800;
}

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

  .input-panel {
    position: static;
  }

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

  .savings-status {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 580px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    margin: 10px auto;
  }

  .input-panel,
  .results-panel {
    padding: 16px;
  }

  .assumptions,
  .form-grid > fieldset,
  .metrics-grid,
  .income-band > div {
    grid-template-columns: 1fr;
  }

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

  .section-heading p {
    text-align: left;
  }
}
