@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Source+Sans+3:wght@400;500;600;700&display=swap");

:root {
  --teal: #2a9b8f;
  --teal-deep: #1a6b63;
  --ink: #14201e;
  --paper: #f4f7f6;
  --card: #ffffff;
  --muted: #5a6e6a;
  --line: rgba(20, 32, 30, 0.12);
  --good: #047857;
  --warn: #b45309;
  --bad: #b91c1c;
  --shadow: 0 18px 50px rgba(20, 32, 30, 0.08);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(42, 155, 143, 0.16), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(26, 107, 99, 0.1), transparent 50%),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

a { color: var(--teal-deep); }

.app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 0.85rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 700;
}

.brand img { width: 28px; height: 28px; }
.brand b { color: var(--teal-deep); }

.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: #e8efed;
  padding: 0.25rem;
  border-radius: 999px;
}

.modes a {
  font: inherit;
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.modes a.active {
  background: var(--ink);
  color: #fff;
}

.doc-sync {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1rem;
  width: min(1400px, calc(100% - 2rem));
  margin: 1rem auto 2rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
}

.chart-panel { grid-column: 1; }
.table-panel { grid-column: 1; }
.inputs-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: start;
  position: sticky;
  top: 4.5rem;
  max-height: calc(100vh - 5.5rem);
  overflow: auto;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-head.compact { align-items: center; }

h1, h2 {
  font-family: var(--font-display);
  margin: 0 0 0.35rem;
  letter-spacing: -0.02em;
}

h1 { font-size: 1.65rem; }
h2 { font-size: 1.2rem; }

.lede {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  max-width: 62ch;
}

.lede.small { font-size: 0.88rem; margin-bottom: 1rem; }

.control-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-end;
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  background: #e8efed;
  padding: 0.25rem;
  border-radius: 999px;
}

.toggle-group.subtle { background: #f0f4f3; }

.toggle-group button,
.ghost {
  font: inherit;
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
}

.toggle-group button.active {
  background: var(--ink);
  color: #fff;
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.chart-wrap {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 0.75rem 0.5rem;
  margin-bottom: 1rem;
}

#scenarioChart {
  display: block;
  max-width: 100%;
}

.chart-mode-note,
.metric-note {
  margin: 0;
  padding: 0 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.chart-mode-note {
  padding-top: 0.15rem;
}

.metric-note {
  margin-bottom: 0.5rem;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 0.35rem 0.5rem 0.6rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend i {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}

.legend i.legend-dashed {
  height: 0;
  border-top: 2px dashed #6366f1;
  background: transparent;
  border-radius: 0;
}

.legend i.legend-vline {
  width: 2px;
  height: 14px;
  border-radius: 1px;
  background: var(--teal-deep, #1c4e3f);
}

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

.metric {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fbfcfc;
}

.metric b {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.metric.pos b { color: var(--good); }
.metric.neg b { color: var(--bad); }

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
}

.note { font-size: 0.82rem; color: var(--muted); }

.note-recurring-team {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0.35rem 0.85rem 0.85rem;
}

.field-span {
  grid-column: 1 / -1;
  margin: 0;
}

.field-currency {
  grid-template-columns: 1fr minmax(96px, 112px);
}

.currency-wrap {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 0.35rem 0 0.45rem;
  background: #fff;
}

.currency-wrap input {
  border: 0;
  padding: 0.35rem 0.15rem 0.35rem 0;
  width: 100%;
  min-width: 0;
  background: transparent;
}

.currency-prefix {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  flex-shrink: 0;
}

.field.readonly input,
.field-row5.readonly input {
  background: #f3f6f5;
  color: var(--muted);
  cursor: default;
}

.metric-desc .metric-detail {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--muted);
}

.phased-compare-intro {
  margin: 0 0 0.75rem;
  line-height: 1.45;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

th, td {
  text-align: left;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.input-section summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  background: #f7fbfa;
  list-style: none;
}

.input-section summary::-webkit-details-marker { display: none; }

.input-section summary::before {
  content: "";
  flex-shrink: 0;
  width: 0.42rem;
  height: 0.42rem;
  border-right: 2px solid var(--teal-deep);
  border-bottom: 2px solid var(--teal-deep);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.input-section[open] summary::before {
  transform: rotate(45deg);
}

.input-section[open] summary {
  border-bottom: 1px solid var(--line);
}

.input-grid {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem 0.85rem;
}

.field {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 0.45rem;
  align-items: center;
}

.field label {
  font-size: 0.82rem;
  line-height: 1.35;
}

.field input,
.field select {
  font: inherit;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 100%;
}

.field .hint {
  grid-column: 1 / -1;
  font-size: 0.72rem;
  color: var(--muted);
}

.field-row5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
  grid-column: 1 / -1;
}

.field-row5 label {
  font-size: 0.72rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.15rem;
}

.foot {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .inputs-panel {
    grid-column: 1;
    grid-row: auto;
    position: static;
    max-height: none;
  }
  .metric-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Bridge plan (£250k SEIS) */
.bridge-panel {
  grid-column: 1;
}

.bridge-chart-wrap {
  margin-bottom: 0.75rem;
}

#bridgeCashChart {
  width: 100%;
  height: auto;
  display: block;
}

.bridge-metrics {
  margin-bottom: 1.25rem;
}

.bridge-breakdown-wrap {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}

.bridge-breakdown-wrap h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0 0 0.5rem;
}

.bridge-narrative {
  margin: 0 0 0.85rem;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.bridge-narrative li + li {
  margin-top: 0.25rem;
}

.bridge-cash-story {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-left: 3px solid var(--accent, #1c4e3f);
  background: rgba(28, 78, 63, 0.06);
  border-radius: 0 6px 6px 0;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.5;
}

.bridge-cash-story p + p {
  margin-top: 0.55rem;
}

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

.bridge-phase-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #fbfcfc;
}

.bridge-phase-card.phase1 {
  border-top: 3px solid rgba(42, 155, 143, 0.55);
}

.bridge-phase-card.phase2 {
  border-top: 3px solid rgba(99, 102, 241, 0.5);
}

.bridge-phase-card h4 {
  font-family: var(--font-display);
  font-size: 0.92rem;
  margin: 0 0 0.15rem;
}

.bridge-phase-card .phase-total {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0 0 0.55rem;
}

.bridge-breakdown table {
  font-size: 0.8rem;
}

.bridge-breakdown table td:last-child,
.bridge-breakdown table th:last-child {
  text-align: right;
}

.bridge-breakdown table tr.total-row td {
  border-top: 2px solid var(--line);
  font-weight: 600;
  padding-top: 0.55rem;
}

.bridge-breakdown-note {
  grid-column: 1 / -1;
  margin: 0;
}

.gantt-wrap {
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}

.gantt-wrap h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 0 0 0.75rem;
}

.gantt {
  --gantt-cols: 12;
  display: grid;
  gap: 0.35rem 0;
  font-size: 0.78rem;
}

.gantt-phase-row {
  display: grid;
  grid-template-columns: 140px repeat(var(--gantt-cols), 1fr);
  gap: 2px;
  margin-bottom: 0.35rem;
}

.gantt-phase-band {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.2rem 0.15rem;
  border-radius: 4px;
  line-height: 1.2;
}

.gantt-phase-band.phase1 {
  background: rgba(42, 155, 143, 0.18);
  color: #1a6b63;
}

.gantt-phase-band.phase2 {
  background: rgba(99, 102, 241, 0.16);
  color: #4338ca;
}

.gantt-header {
  display: grid;
  grid-template-columns: 140px repeat(var(--gantt-cols), 1fr);
  gap: 2px;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.gantt-header span:first-child {
  grid-column: 1;
}

.gantt-header span:not(:first-child) {
  text-align: center;
}

.gantt-row {
  display: grid;
  grid-template-columns: 140px repeat(var(--gantt-cols), 1fr);
  gap: 2px;
  align-items: center;
  min-height: 1.6rem;
}

.gantt-label {
  font-weight: 600;
  font-size: 0.76rem;
  line-height: 1.25;
  padding-right: 0.35rem;
}

.gantt-cell {
  height: 1.25rem;
  border-radius: 3px;
  background: #eef2f1;
}

.gantt-cell.active {
  border-radius: 4px;
}

.gantt-cell.phase1 { background: rgba(42, 155, 143, 0.55); }
.gantt-cell.phase2 { background: rgba(99, 102, 241, 0.5); }
.gantt-cell.steady { background: rgba(245, 158, 11, 0.45); }
.gantt-cell.founders { background: rgba(26, 107, 99, 0.5); }

.gantt-note {
  margin-top: 0.65rem;
}

.phased-compare {
  margin-top: 1rem;
  border-top: 1px dashed var(--line);
  padding-top: 0.75rem;
}

.phased-compare summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--teal-deep);
  margin-bottom: 0.5rem;
}

.phased-compare table td.delta-pos { color: var(--good); }
.phased-compare table td.delta-neg { color: var(--bad); }

.field-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  grid-column: 1 / -1;
}

.field-checkbox input[type="checkbox"] {
  width: auto;
}

.field-checkbox label {
  font-size: 0.82rem;
}

@media (max-width: 640px) {
  .gantt-phase-row,
  .gantt-header,
  .gantt-row {
    grid-template-columns: 100px repeat(var(--gantt-cols), 1fr);
  }
  .gantt-label { font-size: 0.7rem; }
  .metric-row { grid-template-columns: 1fr; }
  .field-row5 { grid-template-columns: repeat(2, 1fr); }
  .control-row { align-items: stretch; }
  .bridge-breakdown { grid-template-columns: 1fr; }
}

/* AWAIR BOM (sidebar panel + legacy layout) */
.bom-section-inner {
  padding: 0.75rem 0.85rem;
}

.bom-intro {
  margin: 0 0 0.5rem;
}

.bom-doc-status {
  font-size: 0.78rem;
  margin: 0 0 0.75rem;
}

.inputs-panel .bom-grid {
  grid-template-columns: 1fr;
}

.inputs-panel .bom-metrics {
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.bom-variant {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.75rem;
  background: #fafcfb;
}

.bom-variant-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.bom-variant-head h3 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  margin: 0;
}

.bom-layout {
  width: min(1200px, calc(100% - 2rem));
  margin: 1rem auto 2rem;
  display: grid;
  gap: 1rem;
}

.bom-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.bom-subhead {
  font-family: var(--font-display);
  font-size: 1rem;
  margin: 1rem 0 0.5rem;
}

.bom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  margin-bottom: 0.5rem;
}

.bom-table th,
.bom-table td {
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.bom-table input[type="text"],
.bom-table input[type="number"] {
  width: 100%;
  font: inherit;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.bom-table .total-row td {
  border-top: 2px solid var(--line);
  padding-top: 0.55rem;
}

.labour-grid .field {
  grid-template-columns: 1fr;
}

.labour-grid .field input {
  width: 100%;
}

.bom-totals {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
  font-size: 0.88rem;
}

.bom-totals div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.bom-totals span:first-child {
  color: var(--muted);
  font-size: 0.78rem;
}

.sync-badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.sync-badge.ok {
  background: rgba(4, 120, 87, 0.12);
  color: var(--good);
}

.sync-badge.warn {
  background: rgba(180, 83, 9, 0.12);
  color: var(--warn);
}

.btn-sm {
  padding: 0.15rem 0.45rem;
  font-size: 1rem;
  line-height: 1;
}

.bom-summary-panel {
  margin-top: 0.25rem;
}

@media (max-width: 900px) {
  .bom-grid {
    grid-template-columns: 1fr;
  }
  .bom-totals {
    grid-template-columns: 1fr;
  }
}
