:root {
  color-scheme: light;

  --surface-0: #f5f5f4;
  --surface-1: #ffffff;
  --border: #e2e2df;
  --border-strong: #cfcfca;

  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #85847e;

  --series-1: #2a78d6; /* cost per sale */
  --series-2: #eb6834; /* lifetime value */

  --good: #008300;
  --critical: #e34948;

  /* Brand cream. In DARK it is the reading colour for input text, field labels
     and hint lines. In LIGHT it is deliberately NOT cream -- #f5f5f4 IS
     --surface-0 there, so cream text would be cream on cream. Light keeps its
     existing inks and only the sizes change. */
  --text-cream: var(--text-primary);
  --text-cream-soft: var(--text-secondary);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #2e2e2b;
    --border-strong: #43423e;

    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e85;

    /* The brand cream, the same #f5f5f4 the light surface uses. Warmer than the
       pure #ffffff --text-primary, which is why it reads as brand rather than
       as default. */
    --text-cream: #f5f5f4;
    --text-cream-soft: #f5f5f4;

    --series-1: #3987e5;
    --series-2: #d95926;

    --good: #3fb950;
    --critical: #e66767;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-logo {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  margin: 0 auto 20px;
}

/* Same dark-background chip as the nav logo, see .brand img. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .login-logo {
    background: #f5f5f4;
    border-radius: 8px;
    padding: 10px 14px;
  }
}

:root[data-theme="dark"] .login-logo {
  background: #f5f5f4;
  border-radius: 8px;
  padding: 10px 14px;
}

.login-card .sub {
  margin: 0 0 24px;
  color: var(--text-secondary);
  font-size: 13px;
  text-align: center;
}

/* ---------- App shell ---------- */

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  height: 100%;
}

.brand img {
  height: 30px;
  width: auto;
  display: block;
}

/* The logo's wordmark is dark green/black, drawn for a light background.
   Dark mode gives it a light chip behind it rather than recoloring the
   asset. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .brand img {
    background: #f5f5f4;
    border-radius: 6px;
    padding: 4px 8px;
  }
}

:root[data-theme="dark"] .brand img {
  background: #f5f5f4;
  border-radius: 6px;
  padding: 4px 8px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 13px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

section {
  margin-bottom: 24px;
}

h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-cream-soft);
  margin: 0 0 12px;
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- KPI tiles ---------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.kpi {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.kpi .label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-cream-soft);
  margin-bottom: 6px;
}

.kpi .value {
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.kpi .meta {
  font-size: 13px;
  color: var(--text-cream-soft);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- Charts ---------- */

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 760px) {
  .charts {
    grid-template-columns: 1fr;
  }
}

.chart-card h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
}

.chart-card .hint {
  margin: 2px 0 14px;
  font-size: 12px;
  color: var(--text-muted);
}

.swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: none;
}

.chart-box {
  position: relative;
  height: 200px;
}

/* ---------- Form ---------- */

.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
}

.field label {
  display: block;
  font-size: 13px;
  color: var(--text-cream-soft);
  margin-bottom: 5px;
}

input {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: var(--text-cream);
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
}

input:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: transparent;
}

button {
  font: inherit;
  font-weight: 550;
  padding: 8px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: var(--series-1);
  color: #fff;
  cursor: pointer;
}

button:hover:not(:disabled) {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.6;
  cursor: default;
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

button.ghost:hover {
  color: var(--text-primary);
}

.btn-full {
  width: 100%;
  padding: 9px;
}

/* ---------- Table ---------- */

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

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

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

th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-cream-soft);
}

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

tbody tr:hover {
  background: var(--surface-0);
}

/* ---------- States ---------- */

.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-muted);
}

.empty strong {
  display: block;
  color: var(--text-secondary);
  font-weight: 550;
  margin-bottom: 4px;
}

.msg {
  min-height: 20px;
  font-size: 13px;
  margin-top: 12px;
}

.msg.error {
  color: var(--critical);
}

.msg.ok {
  color: var(--good);
}

[hidden] {
  display: none !important;
}

/* ---------- Verdict banner ---------- */

.verdict {
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 14px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: var(--surface-1);
  box-shadow: var(--shadow);
  border-left: 3px solid var(--border-strong);
}

.verdict strong {
  color: var(--text-primary);
  font-weight: 650;
  margin-right: 4px;
}

.verdict.ok {
  border-left-color: var(--good);
}

.verdict.bad {
  border-left-color: var(--critical);
}

/* ---------- Range switcher ---------- */

.range-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ranges {
  display: inline-flex;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.ranges button {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}

.ranges button:hover:not(.on) {
  color: var(--text-primary);
  filter: none;
}

.ranges button.on {
  background: var(--series-1);
  color: #fff;
}

.range-note {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- KPI deltas & tone ---------- */

.delta {
  font-weight: 600;
  margin-left: 2px;
  white-space: nowrap;
}

.delta.up {
  color: var(--good);
}

.delta.down {
  color: var(--critical);
}

.kpi .value.good {
  color: var(--good);
}

.kpi .value.bad {
  color: var(--critical);
}

td.good {
  color: var(--good);
}

td.bad {
  color: var(--critical);
}

/* ---------- Row actions ---------- */

.row-actions {
  white-space: nowrap;
}

button.link {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 2px;
}

button.link:hover {
  color: var(--text-primary);
  filter: none;
}

button.link.danger:hover {
  color: var(--critical);
}

/* ---------- Costs drawer ---------- */

.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 20;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 340px;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  z-index: 21;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-primary);
  font-weight: 650;
}

.drawer-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 20px;
  line-height: 1.5;
}

.drawer .field {
  margin-bottom: 16px;
}

.drawer .sub {
  display: block;
  font-size: 12px;
  color: var(--text-cream-soft);
  margin-top: 4px;
}

.who {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40vw;
}

@media (max-width: 560px) {
  .who {
    display: none;
  }
  main {
    padding: 16px;
  }
  .topbar {
    padding: 0 16px;
  }
}

/* ---------- Nav ---------- */

.nav {
  display: flex;
  gap: 4px;
  margin-left: 20px;
  margin-right: auto;
}

.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 7px;
}

.nav a:hover {
  color: var(--text-primary);
  background: var(--surface-0);
}

.nav a.on {
  color: var(--text-primary);
  background: var(--surface-0);
  font-weight: 600;
}

/* ---------- Plan page ---------- */

.plan-head {
  margin-bottom: 22px;
}

.plan-head h1 {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.plan-head .lede {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 62ch;
}

.plan-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}

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

.inputs {
  position: sticky;
  top: 76px;
}

.inputs h2 {
  margin: 22px 0 12px;
}

.inputs h2:first-child {
  margin-top: 0;
}

.inputs .field {
  margin-bottom: 14px;
}

.inputs .sub {
  display: block;
  font-size: 12px;
  color: var(--text-cream-soft);
  margin-top: 4px;
}

.results {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.results .verdict {
  margin-bottom: 0;
}

.results .card h2 {
  margin-top: 0;
}

/* Input affixes */

.prefix,
.suffix {
  display: flex;
  align-items: center;
  gap: 6px;
}

.prefix span,
.suffix span {
  color: var(--text-muted);
  font-size: 13px;
  flex: none;
}

/* ---------- Print ---------- */

@media print {
  :root {
    --surface-0: #fff;
    --surface-1: #fff;
    --border: #ccc;
    --border-strong: #999;
    --text-primary: #000;
    --text-secondary: #333;
    --text-muted: #555;
  }
  .topbar,
  .nav,
  .topbar-right {
    display: none !important;
  }
  main {
    padding: 0;
    max-width: none;
  }
  .plan-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .inputs {
    position: static;
  }
  .card,
  .kpi,
  .verdict {
    box-shadow: none;
    break-inside: avoid;
  }
  .kpis {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* A figure the model computes, shown where an input used to sit. Reads as a
   readout, not a disabled field -- there is nothing here to try to type in. */
.derived {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  padding: 6px 0 2px;
}
