:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3ed;
  --ink: #17211d;
  --muted: #607069;
  --line: #d8ded7;
  --line-strong: #b7c2ba;
  --green: #276749;
  --green-2: #84a98c;
  --gold: #b98324;
  --blue: #2f6f9f;
  --red: #a2413b;
  --shadow: 0 20px 50px rgba(31, 42, 36, 0.12);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 244, 0.94);
  backdrop-filter: blur(16px);
}

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

.brand-mark {
  position: relative;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 2px solid var(--green);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 48%, var(--green) 49% 52%, transparent 53%),
    linear-gradient(90deg, rgba(132, 169, 140, 0.35), rgba(47, 111, 159, 0.14));
}

.brand-mark::after {
  content: "";
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 1.28rem;
  line-height: 1.1;
  font-weight: 760;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--green);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  gap: 22px;
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 22px;
}

.control-panel {
  align-self: start;
  position: sticky;
  top: 100px;
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 116px);
  overflow: auto;
  padding-right: 2px;
}

.panel-section,
.chart-panel,
.table-panel,
.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.75) inset;
}

.panel-section {
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2,
.chart-head h2,
.table-head h2 {
  font-size: 0.96rem;
  line-height: 1.2;
  font-weight: 760;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.segment {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 720;
}

.segment.is-active {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--green);
  box-shadow: 0 2px 10px rgba(31, 42, 36, 0.08);
}

.field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  align-items: center;
  gap: 12px;
  margin-top: 11px;
  color: var(--muted);
  font-size: 0.93rem;
}

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

.input-wrap input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 34px 0 12px;
  background: #fbfcfa;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.input-wrap.money input {
  padding-left: 26px;
}

.input-wrap.money::before,
.input-wrap.percent::after,
.input-wrap.years::after {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.input-wrap.money::before {
  content: "$";
  left: 12px;
}

.input-wrap.percent::after {
  content: "%";
  right: 12px;
}

.input-wrap.years::after {
  content: "yr";
  right: 12px;
}

.range {
  width: 100%;
  accent-color: var(--green);
  margin: 8px 0 2px;
}

.text-button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fbfcfa;
  color: var(--ink);
  font-weight: 720;
}

.workspace {
  min-width: 0;
}

.warning {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(162, 65, 59, 0.35);
  border-radius: 8px;
  background: rgba(162, 65, 59, 0.08);
  color: #6d2925;
  font-size: 0.93rem;
}

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

.metric {
  min-height: 124px;
  padding: 16px;
}

.metric span,
.metric small {
  color: var(--muted);
}

.metric span {
  display: block;
  font-size: 0.86rem;
  font-weight: 720;
}

.metric strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(1.28rem, 1.8vw, 2rem);
  line-height: 1.05;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.metric small {
  display: block;
  margin-top: 8px;
  line-height: 1.35;
}

.metric.accent {
  border-color: rgba(39, 103, 73, 0.38);
  background: linear-gradient(180deg, #ffffff, #f1f7f2);
}

.chart-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
  margin-top: 14px;
}

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

.chart-head,
.table-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.chart-head p,
.table-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 20px;
  height: 3px;
  border-radius: 2px;
}

.chart-frame {
  position: relative;
  width: 100%;
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(#ffffff, #ffffff) padding-box,
    repeating-linear-gradient(0deg, transparent 0 44px, rgba(216, 222, 215, 0.6) 45px 46px);
  overflow: hidden;
}

.chart-tooltip {
  position: absolute;
  min-width: 188px;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  pointer-events: none;
  transform: translateY(-50%);
}

.tooltip-title {
  margin-bottom: 6px;
  font-weight: 760;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  line-height: 1.5;
  color: var(--muted);
}

.tooltip-row > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tooltip-row strong {
  color: var(--ink);
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.chart-panel:not(.wide) .chart-frame {
  min-height: 340px;
}

.chart-frame svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 340px;
}

.axis,
.grid-line {
  stroke: #d8ded7;
  stroke-width: 1;
}

.year-grid-line {
  opacity: 0.58;
}

.axis-label,
.tick-label {
  fill: var(--muted);
  font-size: 12px;
}

.year-tick-label {
  font-size: 11px;
}

.line-phase {
  stroke: var(--green);
}

.detail-grid {
  display: block;
  margin-top: 14px;
}

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

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  font-size: 0.9rem;
}

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

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

th {
  position: sticky;
  top: 0;
  background: #f5f8f4;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

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

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211d;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

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

  .control-panel {
    position: static;
    max-height: none;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .topbar {
    align-items: flex-start;
    padding: 14px 16px;
  }

  .brand p {
    display: none;
  }

  .app-shell {
    padding: 14px;
  }

  .control-panel,
  .metric-grid,
  .chart-row,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 10px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  .brand h1 {
    font-size: 1.05rem;
  }

  .top-actions {
    gap: 6px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .input-wrap input {
    text-align: left;
  }

  .chart-head,
  .table-head {
    flex-direction: column;
    align-items: stretch;
  }

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

}
