:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --line: #dbe3ef;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #0f766e;
  --orange: #c2410c;
  --shadow: 0 22px 60px rgba(15, 23, 42, 0.09);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.14), transparent 34rem),
    linear-gradient(180deg, #eef4ff 0%, var(--bg) 28rem);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 2rem;
  align-items: flex-end;
  padding: 2.5rem clamp(1rem, 4vw, 3.5rem) 1.25rem;
  max-width: 1520px;
  margin: 0 auto;
}

.hero__copy {
  max-width: 780px;
}

.eyebrow {
  margin: 0 0 0.55rem;
  color: var(--primary-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0.75rem;
  font-size: clamp(2rem, 5vw, 4.5rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 0.35rem;
  font-size: 1rem;
  letter-spacing: -0.015em;
}

.hero p,
.section-heading p,
.card-heading p,
.assumptions li,
.field small,
.metric-card small {
  color: var(--muted);
}

.hero__copy > p:last-child {
  max-width: 680px;
  margin-bottom: 0;
  font-size: 1.08rem;
}

.hero__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.65rem;
  min-width: min(480px, 100%);
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  font-weight: 800;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button--secondary {
  background: var(--text);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
}

.button--secondary:hover {
  background: #1e293b;
}

.button--primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.2);
}

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

.button--ghost {
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  border: 1px solid rgba(148, 163, 184, 0.45);
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 1.25rem;
  max-width: 1520px;
  margin: 0 auto;
  padding: 0 clamp(1rem, 4vw, 3.5rem) 3rem;
}

.panel,
.metric-card {
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.controls-panel {
  position: sticky;
  top: 1rem;
  align-self: start;
  max-height: calc(100vh - 2rem);
  overflow: auto;
  padding: 1rem;
}

.controls {
  display: grid;
  gap: 1rem;
}

.control-section {
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface-strong);
}

.storage-section {
  border-color: rgba(37, 99, 235, 0.28);
  background: linear-gradient(180deg, #eff6ff 0%, #f8fafc 100%);
}

.save-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
}

.save-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.section-heading p,
.card-heading p {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 0.35rem;
  color: #1e293b;
  font-size: 0.92rem;
  font-weight: 750;
}

.field input,
.field select,
.input-prefix,
.input-suffix {
  width: 100%;
}

.field input,
.field select {
  min-height: 2.65rem;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  padding: 0.65rem 0.75rem;
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.field input:focus,
.field select:focus,
.input-prefix:focus-within,
.input-suffix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.13);
}

.field small {
  font-size: 0.78rem;
  font-weight: 550;
}

.input-prefix,
.input-suffix {
  display: grid;
  align-items: center;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-sm);
  background: #ffffff;
  overflow: hidden;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.input-prefix {
  grid-template-columns: auto 1fr;
}

.input-suffix {
  grid-template-columns: 1fr auto;
}

.input-prefix span,
.input-suffix span {
  display: inline-grid;
  place-items: center;
  align-self: stretch;
  min-width: 2.4rem;
  background: #eff6ff;
  color: #1e40af;
  font-weight: 850;
}

.input-prefix input,
.input-suffix input {
  border: 0;
  border-radius: 0;
  box-shadow: none !important;
}

.derived-pill {
  border: 1px dashed #93c5fd;
  border-radius: 14px;
  background: #eff6ff;
  color: #1d4ed8;
  padding: 0.75rem;
  font-size: 0.88rem;
  font-weight: 750;
}

.mode-panel {
  display: grid;
  gap: 0.85rem;
}

.mode-panel[hidden] {
  display: none;
}

.results {
  display: grid;
  gap: 1.25rem;
  min-width: 0;
}

.results > * {
  min-width: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
}

.metric-card {
  display: grid;
  gap: 0.35rem;
  min-height: 132px;
  padding: 1rem;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: clamp(1.35rem, 2.2vw, 2rem);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.metric-card small {
  font-size: 0.82rem;
}

.summary-panel,
.table-panel,
.assumptions,
.chart-card {
  padding: 1.15rem;
}

.summary-panel p:last-child,
.assumptions ul {
  margin-bottom: 0;
}

.warnings {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.85rem;
}

.warnings p {
  margin: 0;
  border: 1px solid #fed7aa;
  border-radius: 14px;
  background: #fff7ed;
  color: #9a3412;
  padding: 0.75rem;
  font-weight: 700;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem;
  min-width: 0;
  width: 100%;
}

.chart-card {
  min-width: 0;
  overflow: hidden;
}

.chart-card--wide {
  grid-column: 1 / -1;
}

.card-heading {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.card-heading p {
  max-width: 560px;
  text-align: right;
}

.chart-wrap {
  position: relative;
  min-width: 0;
  width: 100%;
  height: 340px;
  overflow: hidden;
}

.chart-wrap canvas {
  display: block;
  width: 100% !important;
  max-width: 100%;
}

.table-scroll {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  background: #ffffff;
}

th,
td {
  border-bottom: 1px solid #e2e8f0;
  padding: 0.8rem 0.75rem;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #475569;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f8fafc;
}

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

.positive {
  color: #047857;
  font-weight: 800;
}

.negative {
  color: #b91c1c;
  font-weight: 800;
}

.assumptions ul {
  padding-left: 1.2rem;
}

.assumptions li + li {
  margin-top: 0.45rem;
}

@media (max-width: 1180px) {
  .hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .hero__actions {
    justify-content: flex-start;
  }

  .layout {
    grid-template-columns: 1fr;
  }

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

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

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

@media (max-width: 760px) {
  .hero {
    padding-top: 1.5rem;
  }

  .hero__actions,
  .button {
    width: 100%;
  }

  .save-actions {
    grid-template-columns: 1fr;
  }

  .controls,
  .metric-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .card-heading {
    display: block;
  }

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

  .chart-wrap {
    height: clamp(240px, 72vw, 300px);
  }

  .metric-card {
    min-height: 110px;
  }
}

@media (max-width: 480px) {
  .layout,
  .hero {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .controls-panel,
  .summary-panel,
  .table-panel,
  .assumptions,
  .chart-card {
    padding: 0.85rem;
    border-radius: 18px;
  }

  .control-section {
    padding: 0.85rem;
  }

  .chart-wrap {
    height: 240px;
  }

  th,
  td {
    padding: 0.7rem 0.6rem;
  }
}
