:root {
  --canvas: #f6f2e9;
  --panel: #fffdf8;
  --panel-soft: #fbf5e7;
  --ink: #202421;
  --muted: #6f756d;
  --line: #ded6c5;
  --gold: #c9a227;
  --gold-dark: #9b7820;
  --green: #587468;
  --red: #b04432;
  --shadow: 0 18px 38px rgba(50, 42, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
}

button,
input {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 242, 233, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #3b3d37;
  background: var(--ink);
  color: #fff7df;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span:not(.brand-mark) {
  color: var(--muted);
  font-size: 12px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-links a {
  padding: 8px 10px;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 13px;
}

.nav-links a.is-active {
  border-color: var(--line);
  background: #fffaf0;
  color: var(--ink);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 18px;
  width: min(1680px, 100%);
  max-width: 100vw;
  margin: 0 auto;
  padding: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-self: start;
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  min-width: 0;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.workspace-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 2px 2px;
}

.workspace-header h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 42px);
  line-height: 1.04;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.subtitle {
  max-width: 780px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.eyebrow,
.section-heading p {
  margin: 0 0 4px;
  color: var(--gold-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.side-panel,
.editor-panel,
.audit-panel,
.formula-panel,
.glossary-panel,
.chart-panel,
.mix-panel {
  padding: 16px;
}

.section-heading h2,
.panel-heading h2 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

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

.segmented,
.horizon-grid {
  display: grid;
  gap: 8px;
}

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

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

.segmented button,
.horizon-grid button,
.plain-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffaf0;
  color: var(--ink);
  font-weight: 700;
}

.segmented button.is-active,
.horizon-grid button.is-selected,
.plain-button:hover {
  border-color: var(--gold);
  background: #f3e5b8;
}

.input-stack,
.multiplier-grid {
  display: grid;
  gap: 10px;
}

.multiplier-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-top: 12px;
}

.input-field,
.editor-row label {
  display: grid;
  gap: 5px;
}

.input-field span,
.editor-row label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.input-field input,
.editor-row input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  border: 1px solid #d8cfbc;
  border-radius: 6px;
  background: #fffefa;
  color: var(--ink);
  padding: 7px 9px;
}

.input-field.compact input {
  padding-inline: 6px;
}

.assumption-list {
  display: grid;
  gap: 8px;
}

.assumption {
  display: grid;
  gap: 3px;
  padding: 9px;
  border: 1px solid #eadfca;
  border-left: 3px solid var(--gold);
  background: #fff9ea;
}

.control-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.assumption strong {
  font-size: 12px;
}

.assumption span,
.assumption em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.kpi-strip {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(5, minmax(140px, 1fr));
  gap: 10px;
}

.status-card,
.kpi-card {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 13px;
  box-shadow: var(--shadow);
}

.status-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(88, 116, 104, 0.12);
}

.status-dot.is-warning {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(176, 68, 50, 0.12);
}

.status-card span,
.kpi-card span,
.mini-metrics span,
.mix-list span:not(.swatch) {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-card strong,
.kpi-card strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.is-negative {
  color: var(--red) !important;
}

.overview-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.8fr);
  gap: 16px;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.legend-row i {
  display: inline-block;
  width: 20px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

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

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

.chart-wrap {
  height: 280px;
  border: 1px solid #eee2ce;
  border-radius: 8px;
  background:
    linear-gradient(to right, rgba(32, 36, 33, 0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(32, 36, 33, 0.05) 1px, transparent 1px),
    #fffdf7;
  background-size: 100px 100%, 100% 56px;
  overflow: hidden;
}

.line-chart {
  width: 100%;
  height: 100%;
}

#zeroLine {
  stroke: rgba(32, 36, 33, 0.25);
  stroke-width: 1;
  stroke-dasharray: 6 8;
}

#revenuePath {
  stroke: var(--gold);
  stroke-width: 4;
  stroke-linecap: round;
}

#profitPath {
  stroke: var(--green);
  stroke-width: 3;
  stroke-linecap: round;
}

.mini-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.mini-metrics div {
  border: 1px solid #eadfca;
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 11px;
}

.mini-metrics strong {
  font-size: 18px;
}

.donut-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: 12px;
}

.donut-wrap svg {
  width: 150px;
  height: 150px;
  transform: rotate(-90deg);
}

.donut-wrap circle {
  fill: transparent;
  stroke: #202421;
  stroke-width: 14;
}

#donutSub {
  stroke: var(--gold);
  stroke-dasharray: 0 282.743;
}

.donut-wrap div span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.donut-wrap div strong {
  display: block;
  margin-top: 4px;
  font-size: 34px;
}

.mix-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.mix-list p {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.mix-list strong {
  color: var(--ink);
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
}

.gold-bg {
  background: var(--gold);
}

.ink-bg {
  background: var(--ink);
}

.green-bg {
  background: var(--green);
}

.editor-table {
  display: grid;
  gap: 10px;
}

.editor-row {
  display: grid;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid #eadfca;
  border-radius: 8px;
  background: #fffbf2;
}

.subscription-row {
  grid-template-columns: 1.1fr 0.8fr 0.6fr 1.2fr 0.55fr 0.65fr 0.6fr 0.6fr 0.7fr 34px;
}

.product-row {
  grid-template-columns: 1.1fr 0.75fr 0.65fr 1.25fr 0.55fr 0.65fr 0.6fr 0.7fr 34px;
}

.remove-button {
  width: 34px;
  height: 34px;
  border: 1px solid #d7cbb6;
  border-radius: 6px;
  background: #fff6e4;
  color: var(--red);
  font-size: 19px;
  font-weight: 800;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #eadfca;
  border-radius: 8px;
}

.audit-table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  background: #fffefa;
}

.audit-table th,
.audit-table td {
  padding: 10px 11px;
  border-bottom: 1px solid #eee4d3;
  text-align: right;
  white-space: nowrap;
  font-size: 13px;
}

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

.audit-table th {
  position: sticky;
  top: 0;
  background: #f8efdc;
  color: #5a513f;
  font-size: 11px;
  text-transform: uppercase;
}

.audit-table small {
  color: var(--muted);
}

.formula-grid,
.glossary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.formula-grid div,
.glossary-item {
  display: grid;
  gap: 5px;
  min-height: 88px;
  border: 1px solid #eadfca;
  border-radius: 8px;
  background: #fffbf2;
  padding: 12px;
}

.formula-grid strong,
.glossary-item strong {
  font-size: 14px;
}

.formula-grid span,
.glossary-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

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

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

  .status-card {
    grid-column: span 2;
  }

  .subscription-row,
  .product-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 34px;
  }

  .formula-grid,
  .glossary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 760px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .top-nav,
  .workspace-header {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-links {
    overflow-x: auto;
  }

  .app-shell {
    display: block;
    width: 100vw;
    max-width: 100vw;
    padding: 12px;
    overflow: hidden;
  }

  .sidebar,
  .workspace {
    width: 100%;
    max-width: 100%;
  }

  .sidebar {
    margin-bottom: 16px;
  }

  .panel {
    max-width: calc(100vw - 24px);
  }

  .workspace-header h1 {
    font-size: 25px;
    max-width: 15ch;
  }

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

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

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

  .sidebar,
  .kpi-strip,
  .overview-grid,
  .mini-metrics,
  .formula-grid,
  .glossary-grid {
    grid-template-columns: 1fr;
  }

  .status-card {
    grid-column: auto;
  }

  .donut-wrap {
    grid-template-columns: 120px 1fr;
  }

  .segmented button,
  .horizon-grid button {
    padding-inline: 6px;
  }

  .input-field.compact input {
    padding-inline: 4px;
  }

  .donut-wrap svg {
    width: 120px;
    height: 120px;
  }

  .subscription-row,
  .product-row {
    grid-template-columns: 1fr;
  }

  .remove-button {
    width: 100%;
  }
}
