/* Windfall visual language: warm paper ground, ink text, bronze/gold accent,
   quiet borders and surfaces. Tokens first; components below. */

:root {
  --bg: #f7f4ec;
  --surface: #fffdf8;
  --surface-soft: #faf7ef;
  --border: #e5dfd0;
  --border-strong: #cfc6af;
  --ink: #211d14;
  --text: #2a261c;
  --muted: #746d5c;
  --accent: #8a5714;
  --accent-strong: #6e4510;
  --accent-soft: #f2e7cf;
  --gold: #b98a2b;
  --ok: #2e6b45;
  --ok-soft: #e3efe5;
  --err: #a03325;
  --err-soft: #f8e4de;
  --run: #8a6a10;
  --run-soft: #f6ecc9;
  --gain: #16733a;
  --loss: #b1261b;
  --shadow: 0 1px 2px rgb(33 29 20 / 5%);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #151712;
  --surface: #1c1f19;
  --surface-soft: #24281f;
  --border: #34392e;
  --border-strong: #4c5343;
  --ink: #f2eddf;
  --text: #ded8c9;
  --muted: #aaa28f;
  --accent: #bc8130;
  --accent-strong: #e2b66c;
  --accent-soft: #392f20;
  --gold: #e0b45a;
  --ok: #82d09a;
  --ok-soft: #1d3525;
  --err: #ff9483;
  --err-soft: #3d2422;
  --run: #e2c96e;
  --run-soft: #3a3420;
  --gain: #79d796;
  --loss: #ff8c7a;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #151712;
    --surface: #1c1f19;
    --surface-soft: #24281f;
    --border: #34392e;
    --border-strong: #4c5343;
    --ink: #f2eddf;
    --text: #ded8c9;
    --muted: #aaa28f;
    --accent: #bc8130;
    --accent-strong: #e2b66c;
    --accent-soft: #392f20;
    --gold: #e0b45a;
    --ok: #82d09a;
    --ok-soft: #1d3525;
    --err: #ff9483;
    --err-soft: #3d2422;
    --run: #e2c96e;
    --run-soft: #3a3420;
    --gain: #79d796;
    --loss: #ff8c7a;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 3px;
}

.brandbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brandbar-inner {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto;
  max-width: 1180px;
  padding: 10px 20px;
}

.brand {
  align-items: center;
  color: var(--ink);
  display: inline-flex;
  font-family: "Iowan Old Style", Palatino, Georgia, serif;
  font-size: 17px;
  gap: 9px;
  letter-spacing: 0.01em;
}

.brand:hover {
  color: var(--accent-strong);
  text-decoration: none;
}

.brand svg {
  display: block;
}

.brand svg path {
  stroke: var(--ink);
}

.brand svg circle {
  fill: var(--accent);
}

.brand-tag {
  color: var(--muted);
  font-size: 12.5px;
}

.brandbar-actions {
  align-items: center;
  display: flex;
  gap: 12px;
}

.theme-toggle {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  min-width: 74px;
  padding: 6px 9px;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 26px 20px 48px;
}

.topbar {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  margin-bottom: 22px;
  padding-bottom: 18px;
}

.topbar h1 {
  color: var(--ink);
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.01em;
  line-height: 1.1;
  margin: 0;
}

.topbar p {
  color: var(--muted);
  margin: 4px 0 0;
}

.topbar nav {
  align-items: center;
  display: flex;
  gap: 14px;
}

.topbar nav span {
  color: var(--muted);
  font-size: 13px;
}

.link-button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--accent-strong);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.link-button:hover {
  text-decoration: underline;
}

.notice {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  padding: 12px 14px;
}

.notice-error {
  background: var(--err-soft);
  border-color: #dba796;
}

.notice-ok {
  background: var(--ok-soft);
  border-color: #a3c6ab;
}

.notice strong {
  display: block;
  margin-bottom: 3px;
}

.action-row {
  align-items: center;
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.inline-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(240px, 1fr) 120px auto;
  padding: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.field input,
.field select,
.field textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.field textarea {
  min-height: 96px;
  resize: vertical;
}

.field-help,
.field-label {
  color: var(--muted);
  font-size: 12px;
}

.field-label {
  font-weight: 650;
}

.readonly-field {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 7px;
  min-height: 38px;
  padding: 8px 10px;
}

.button {
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #fffdf8;
  display: inline-flex;
  font-weight: 650;
  line-height: 1;
  padding: 10px 14px;
}

.button:hover {
  background: var(--accent-strong);
  text-decoration: none;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.metrics-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 22px;
}

.detail-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 22px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-height: 86px;
  padding: 14px;
}

.metric span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.metric strong {
  color: var(--ink);
  display: block;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.pnl {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  white-space: nowrap;
}

.pnl-positive {
  color: var(--gain);
}

.pnl-negative {
  color: var(--loss);
}

.pnl-neutral {
  color: var(--muted);
}

.pnl-marker {
  font-size: 0.75em;
}

.sr-only {
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.panel-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-wide {
  grid-column: 1 / -1;
}

.panel header {
  border-bottom: 1px solid var(--border);
  padding: 13px 14px;
}

.panel h2 {
  color: var(--ink);
  font-size: 15px;
  margin: 0;
}

.panel-note {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
  padding: 12px 14px 0;
}

table {
  border-collapse: collapse;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

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

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.empty {
  color: var(--muted);
  margin: 0;
  padding: 18px 14px;
}

.json-block {
  background: var(--surface-soft);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
  margin: 0;
  overflow-x: auto;
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.status {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 650;
  line-height: 1;
  padding: 5px 9px;
}

.status-ok,
.status-connected {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-error {
  background: var(--err-soft);
  color: var(--err);
}

.status-running {
  background: var(--run-soft);
  color: var(--run);
}

.status-fresh {
  background: var(--ok-soft);
  color: var(--ok);
  margin-left: 5px;
}

.status-stale,
.status-read-only {
  background: var(--accent-soft);
  color: var(--muted);
  margin-left: 5px;
}

.status-needs_reauth,
.status-disabled {
  background: var(--accent-soft);
  color: var(--muted);
}

.pill {
  background: var(--accent-soft);
  border-radius: 999px;
  color: var(--accent-strong);
  display: inline-block;
  font-size: 12px;
  margin: 0 4px 4px 0;
  padding: 4px 8px;
}

.table-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.account-panel-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.account-panel-header p {
  color: var(--muted);
  font-size: 12px;
  margin: 3px 0 0;
}

.account-panel-meta {
  line-height: 1.6;
}

.account-metrics {
  margin: 14px;
}

.account-metrics .metric {
  min-height: 76px;
}

.account-metrics .metric strong {
  font-size: 20px;
}

.panel-subhead {
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  color: var(--ink);
  font-size: 13px;
  margin: 0;
  padding: 10px 14px;
}

.draft-safety-notice {
  background: var(--accent-soft);
  border-color: var(--border-strong);
}

.draft-form-panel {
  overflow: visible;
}

.draft-form {
  padding: 16px;
}

.draft-form-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.draft-form-wide {
  grid-column: 1 / -1;
}

.draft-form-actions {
  align-items: center;
  display: flex;
  gap: 14px;
  margin-top: 18px;
}

.draft-form-errors {
  margin-bottom: 16px;
}

.draft-form-errors ul {
  margin: 6px 0 0;
  padding-left: 20px;
}

.draft-note {
  border-top: 1px solid var(--border);
  margin: 0;
  padding: 14px;
  white-space: pre-wrap;
}

.validation-metrics {
  margin: 14px;
}

.validation-metrics .metric strong {
  font-size: 19px;
}

.validation-issues {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.validation-issue {
  align-items: start;
  border: 1px solid var(--border);
  border-radius: 7px;
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr;
  padding: 10px 12px;
}

.validation-issue > span {
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 7px;
  text-transform: uppercase;
}

.validation-issue strong,
.validation-issue code,
.validation-issue small {
  display: block;
}

.validation-issue code,
.validation-issue small {
  color: var(--muted);
  margin-top: 3px;
}

.validation-issue-error {
  background: var(--err-soft);
  border-color: #dba796;
}

.validation-issue-error > span,
.status-validation-failed {
  background: var(--err);
  color: white;
}

.validation-issue-warning {
  background: var(--run-soft);
  border-color: #ddca7e;
}

.validation-issue-warning > span,
.status-validation-warning {
  background: var(--run);
  color: white;
}

.status-validation-passed {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-active {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-archived {
  background: var(--accent-soft);
  color: var(--muted);
}

.situation-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-bottom: 16px;
}

.situation-count {
  align-items: baseline;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  gap: 7px;
  min-width: 104px;
  padding: 10px 12px;
}

.situation-count strong {
  color: var(--ink);
  font-size: 20px;
}

.situation-count span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.situation-manage,
.situation-monitor {
  border-color: var(--run);
}

.situation-ready,
.situation-watch {
  border-color: var(--ok);
}

.status-situation-manage,
.status-situation-monitor,
.status-situation-prepare {
  background: var(--run-soft);
  color: var(--run);
}

.status-situation-ready,
.status-situation-watch {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-situation-refresh,
.status-situation-blocked {
  background: var(--err-soft);
  color: var(--err);
}

.status-situation-review,
.status-situation-observe {
  background: var(--accent-soft);
  color: var(--muted);
}

.situation-cell {
  min-width: 210px;
}

.situation-cell small {
  color: var(--muted);
  display: block;
  line-height: 1.35;
  margin-top: 6px;
}

.situation-action {
  font-weight: 650;
  min-width: 98px;
}

.action-book-principle {
  align-items: baseline;
  background: var(--accent-soft);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin-bottom: 16px;
  padding: 14px 16px;
}

.action-book-principle span,
.action-lane-header p,
.lane-empty span,
.research-bench header span,
.research-bench small {
  color: var(--muted);
}

.action-lane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  padding: 18px;
}

.action-lane-header {
  align-items: flex-start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 15px;
}

.action-lane-header h2 {
  color: var(--ink);
  font-size: 20px;
  margin: 2px 0 3px;
}

.action-lane-header p {
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .07em;
  margin: 0;
  text-transform: uppercase;
}

.lane-empty {
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  padding: 18px;
}

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

.action-card {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 15px;
}

.action-card > header {
  align-items: flex-start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.action-card h3 {
  color: var(--ink);
  font-size: 23px;
  margin: 2px 0 0;
}

.action-card h3 small {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .05em;
}

.action-metrics,
.research-bench dl {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0;
}

.action-metrics div,
.research-bench dl div {
  min-width: 0;
}

.action-metrics dt,
.research-bench dt {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.action-metrics dd,
.research-bench dd {
  color: var(--ink);
  font-weight: 700;
  margin: 1px 0 0;
}

.decision-gate {
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
  padding: 12px 0;
}

.decision-gate p,
.action-card-plan p {
  margin: 7px 0 0;
}

.action-card-plan {
  flex: 1;
  font-size: 13px;
  padding: 4px 0 13px;
}

.action-card > footer {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 12px;
  padding-top: 12px;
}

.action-card > footer small {
  color: var(--muted);
  line-height: 1.35;
}

.action-card-actions {
  display: flex;
  justify-content: flex-end;
}

.research-bench {
  border-top: 1px solid var(--border);
  margin-top: 16px;
  padding-top: 14px;
}

.research-bench > header {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 10px;
  margin-bottom: 10px;
}

.research-bench > article {
  background: var(--surface-soft);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(165px, .8fr) minmax(360px, 2fr) minmax(220px, 1.5fr);
  padding: 12px;
}

.research-bench > article > div {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.research-bench dl {
  grid-template-columns: repeat(6, minmax(70px, 1fr));
  margin: 0;
}

.status-withheld,
.status-maturity-experimental,
.status-maturity-provisional {
  background: var(--accent-soft);
  color: var(--muted);
}

.status-maturity-qualified,
.status-maturity-high_confidence {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-maturity-needs_review {
  background: var(--err-soft);
  color: var(--err);
}

@media (max-width: 980px) {
  .action-card-grid {
    grid-template-columns: 1fr;
  }

  .research-bench > article {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .action-lane {
    padding: 14px;
  }

  .action-lane-header {
    display: block;
  }

  .action-lane-header > .status {
    display: inline-block;
    margin-top: 9px;
  }

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

.auth-shell {
  display: grid;
  justify-items: center;
  padding: 9vh 20px 48px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-width: 380px;
  padding: 26px 24px;
  width: 100%;
}

.auth-card h1 {
  color: var(--ink);
  font-size: 20px;
  margin: 0 0 16px;
}

.auth-card form {
  display: grid;
  gap: 12px;
}

.auth-card input:not([type="submit"]) {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: var(--text);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.auth-card .button {
  justify-content: center;
}

.auth-links {
  font-size: 13px;
  margin-top: 14px;
}

@media (max-width: 760px) {
  .brand-tag {
    display: none;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .topbar nav {
    flex-wrap: wrap;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

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

  .draft-form-grid {
    grid-template-columns: 1fr;
  }

  .draft-form-wide {
    grid-column: auto;
  }

  table {
    display: block;
    overflow-x: auto;
  }
}
