/* ==========================================================================
   Opulentia Console — design system
   --------------------------------------------------------------------------
   GP-facing fund-operations console. Light theme, calm and dense.

   Rules for anything added later (SPV forms, capital-call wizard, recon):
   1. No colour literals below the token block. Use the custom properties.
   2. Every status string renders as `.pill .pill--<status>` — never bare text.
      Add a new status by adding it to the hue groups in section 8, nothing else.
   3. Borders over shadows. One shadow level (--shadow), used sparingly.
   4. Numeric / timestamp text gets `font-variant-numeric: tabular-nums`.
   ========================================================================== */

/* --- 1. Tokens ---------------------------------------------------------- */

:root {
  /* type */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  /* surfaces — warm near-white page, white cards */
  --page: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fbfaf9; /* row hover */
  --surface-3: #f3f4f6; /* table head, code blocks */
  --on-accent: #ffffff;

  /* ink */
  --ink: #1b2333; /* navy-slate, primary text */
  --ink-2: #3c4657; /* body/detail text */
  --muted: #5b6577; /* secondary text — 5.5:1 on --surface */

  /* lines */
  --line: #e6e5e2; /* hairlines inside cards */
  --line-2: #d5d8de; /* control borders, dividers */

  /* accent — deep indigo, the only accent */
  --accent: #4338ca;
  --accent-hover: #372fa8;
  --accent-soft: #eaeafc;
  --accent-ring: rgba(67, 56, 202, 0.28);

  /* status hues — canonical. tint bg / mid marker / dark text, same hue. */
  --amber-bg: #fdf3d6;
  --amber-line: #f0d9a0;
  --amber-mid: #c98a04;
  --amber-fg: #855108;

  --green-bg: #e3f5e8;
  --green-line: #a8dcb8;
  --green-mid: #1f8a4c;
  --green-fg: #14683a;

  --red-bg: #fdeaea;
  --red-line: #f2b6b6;
  --red-mid: #d33b3b;
  --red-fg: #a11c1c;

  --blue-bg: #e6effd;
  --blue-line: #aecbf5;
  --blue-mid: #2b6fd4;
  --blue-fg: #1a4faa;

  --gray-bg: #eef0f2;
  --gray-line: #d3d8de;
  --gray-mid: #7b8794;
  --gray-fg: #4a5568;

  /* geometry */
  --r-card: 8px;
  --r-ctl: 6px;
  --r-pill: 999px;
  --ctl-h: 2rem;
  --shell: 1100px;
  --gutter: 1.5rem;

  /* the one shadow level */
  --shadow: 0 1px 2px rgba(23, 31, 46, 0.05);
}

/* --- 2. Base ------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font: 400 15px/1.55 var(--font);
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

code {
  font: 400 0.875em/1.4 var(--mono);
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05em 0.3em;
}

.mono {
  font-family: var(--mono);
  font-size: 0.8125rem;
  word-break: break-all;
}

.ts,
.num {
  font-variant-numeric: tabular-nums;
}

/* --- 3. Shell + top nav ------------------------------------------------- */

.shell {
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

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

.topbar__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  min-height: 3.5rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.005em;
  color: var(--ink);
}
.wordmark::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}

.nav {
  display: flex;
  align-items: center;
  gap: 0.125rem;
  flex-wrap: wrap;
}

.nav__link {
  padding: 0.375rem 0.625rem;
  border-radius: var(--r-ctl);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
}
.nav__link:hover {
  color: var(--ink);
  background: var(--surface-3);
  text-decoration: none;
}
.nav__link.is-active {
  color: var(--accent);
  background: var(--accent-soft);
}

.page {
  padding-top: 1.75rem;
  padding-bottom: 4rem;
}

/* --- 4. Page + section headers ------------------------------------------ */

.page-back {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
}
.page-back--foot {
  margin: 1.5rem 0 0;
}
.page-back a {
  color: var(--muted);
}
.page-back a:hover {
  color: var(--accent);
}

.page-head {
  margin-bottom: 1.5rem;
}
.page-title {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.012em;
  color: var(--ink);
}
.page-title .mono {
  font-size: 1rem;
  color: var(--ink-2);
}
.page-desc {
  margin: 0.375rem 0 0;
  max-width: 66ch;
  color: var(--muted);
  font-size: 0.9375rem;
}

.section {
  margin-bottom: 2rem;
}
.section:last-child {
  margin-bottom: 0;
}
.card + .section {
  margin-top: 1.75rem;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.section-title {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.section-meta {
  font-size: 0.8125rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.section-actions {
  margin-top: 0.875rem;
}

.sub-label {
  margin: 1.25rem 0 0.375rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

/* --- 5. Cards ----------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow);
}
.card--pad {
  padding: 1.25rem;
}
.card--flush {
  overflow: hidden; /* clips the table head to the card radius */
}
.card + .card {
  margin-top: 0.875rem;
}

/* --- 6. Stat cards ------------------------------------------------------ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  gap: 0.75rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gray-mid);
  border-radius: var(--r-card);
  padding: 0.875rem 1rem 1rem;
  box-shadow: var(--shadow);
}
.stat__value {
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.stat__label {
  margin-top: 0.625rem;
}

/* status-coloured left edge — same hue groups as the pills */
.stat--pending,
.stat--closing,
.stat--pending_approval,
.stat--no_payment_received {
  border-left-color: var(--amber-mid);
}
.stat--approved,
.stat--active,
.stat--done,
.stat--decided,
.stat--obtained,
.stat--matched {
  border-left-color: var(--green-mid);
}
.stat--rejected,
.stat--error,
.stat--flagged,
.stat--amount_mismatch,
.stat--unknown_sender,
.stat--ledger_gaps {
  border-left-color: var(--red-mid);
}
.stat--forming,
.stat--in_progress,
.stat--package_ready {
  border-left-color: var(--blue-mid);
}
.stat--closed,
.stat--not_started,
.stat--no_gate,
.stat--unknown,
.stat--ignored_non_credit {
  border-left-color: var(--gray-mid);
}

/* work waiting on a human reads louder than work that isn't */
.stat.is-prominent {
  border-color: var(--amber-line);
  border-left-color: var(--amber-mid);
  box-shadow: 0 0 0 3px var(--amber-bg), var(--shadow);
}
.stat.is-prominent .stat__value {
  color: var(--amber-fg);
}

/* --- 7. Tables ---------------------------------------------------------- */

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

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

.data thead th {
  background: var(--surface-3);
  border-bottom: 1px solid var(--line-2);
  padding: 0.625rem 0.875rem;
  text-align: left;
  white-space: nowrap;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.data tbody td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  color: var(--ink-2);
}
.data tbody tr:last-child td {
  border-bottom: none;
}
.data tbody tr:hover {
  background: var(--surface-2);
}
.data tbody td:first-child {
  color: var(--muted);
}
.data .cell-title {
  color: var(--ink);
  font-weight: 500;
}

/* --- 8. Status pills ---------------------------------------------------- */
/* One class + one modifier per status. Text always accompanies the colour. */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.1875rem 0.5rem 0.1875rem 0.4375rem;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  /* default = gray, so an unmapped status still looks deliberate */
  background: var(--gray-bg);
  border-color: var(--gray-line);
  color: var(--gray-fg);
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.pill--pending,
.pill--closing,
.pill--pending_approval,
.pill--no_payment_received {
  background: var(--amber-bg);
  border-color: var(--amber-line);
  color: var(--amber-fg);
}
.pill--approved,
.pill--active,
.pill--done,
.pill--decided,
.pill--obtained,
.pill--ein_obtained,
.pill--matched {
  background: var(--green-bg);
  border-color: var(--green-line);
  color: var(--green-fg);
}
.pill--rejected,
.pill--error,
.pill--flagged,
.pill--amount_mismatch,
.pill--unknown_sender,
.pill--ledger_gaps {
  background: var(--red-bg);
  border-color: var(--red-line);
  color: var(--red-fg);
}
.pill--forming,
.pill--in_progress,
.pill--package_ready {
  background: var(--blue-bg);
  border-color: var(--blue-line);
  color: var(--blue-fg);
}
.pill--closed,
.pill--not_started,
.pill--no_gate,
.pill--unknown,
.pill--ignored_non_credit {
  background: var(--gray-bg);
  border-color: var(--gray-line);
  color: var(--gray-fg);
}

/* live/polling state — the dot breathes, nothing moves layout */
.pill.is-polling::before {
  animation: pill-pulse 1.6s ease-in-out infinite;
}
@keyframes pill-pulse {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* neutral chip for non-status taxonomy (category tags, sources) */
.tag {
  display: inline-block;
  padding: 0.125rem 0.4375rem;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--surface-3);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

/* --- 9. Buttons + forms ------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  height: var(--ctl-h);
  padding: 0 0.75rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
  background: var(--surface);
  color: var(--ink);
  font: 600 0.8125rem/1 var(--font);
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.12s ease, border-color 0.12s ease,
    color 0.12s ease;
}
.btn:hover {
  background: var(--surface-3);
  text-decoration: none;
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn--approve {
  border-color: var(--green-mid);
  color: var(--green-fg);
}
.btn--approve:hover {
  background: var(--green-fg);
  border-color: var(--green-fg);
  color: var(--on-accent);
}

.btn--reject {
  border-color: var(--red-mid);
  color: var(--red-fg);
}
.btn--reject:hover {
  background: var(--red-fg);
  border-color: var(--red-fg);
  color: var(--on-accent);
}

.btn-row {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.input {
  height: var(--ctl-h);
  min-width: 0;
  padding: 0 0.625rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
  background: var(--surface);
  color: var(--ink);
  font: 400 0.875rem/1 var(--font);
  font-variant-numeric: tabular-nums;
}
.input::placeholder {
  color: var(--muted); /* 5.2:1 — placeholders stay readable */
  opacity: 1;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.input--wide {
  flex: 1 1 22rem;
  max-width: 30rem;
}

/* selects reuse .input; only the native chrome needs overriding */
select.input {
  appearance: none;
  padding-right: 1.75rem;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 0.875rem center, right 0.625rem center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}
select.input:invalid {
  color: var(--muted); /* the unchosen placeholder option reads as a placeholder */
}

/* result slot under a form — collapsed until a fragment is swapped in */
.form-result:not(:empty) {
  margin-top: 0.875rem;
}

/* --- 10. Key/value lists ----------------------------------------------- */

dl.kv {
  display: grid;
  grid-template-columns: minmax(8rem, 11rem) 1fr;
  margin: 0;
  font-size: 0.875rem;
}
dl.kv dt,
dl.kv dd {
  padding: 0.4375rem 0;
  border-top: 1px solid var(--line);
}
dl.kv dt:first-of-type,
dl.kv dt:first-of-type + dd {
  border-top: 0;
  padding-top: 0;
}
dl.kv dt {
  color: var(--muted);
  padding-right: 1rem;
}
dl.kv dd {
  margin: 0;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

/* --- 11. Code blocks ---------------------------------------------------- */

pre.code {
  margin: 0;
  padding: 0.875rem 1rem;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-ctl);
  color: var(--ink-2);
  font: 400 0.8125rem/1.6 var(--mono);
  font-variant-numeric: tabular-nums;
  overflow-x: auto;
}

/* --- 12. Callouts + empty states --------------------------------------- */

.callout {
  border: 1px solid var(--line-2);
  border-radius: var(--r-card);
  background: var(--surface);
  padding: 0.875rem 1rem;
  font-size: 0.875rem;
}
.callout--error {
  border-color: var(--red-line);
  background: var(--red-bg);
  color: var(--red-fg);
}
.callout--ok {
  border-color: var(--green-line);
  background: var(--green-bg);
  color: var(--green-fg);
}
.callout__title {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.callout p {
  margin: 0;
}
.callout-actions {
  margin-top: 0.875rem;
  gap: 0.5rem;
}

.empty-state {
  padding: 2.75rem 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9375rem;
}
.empty-state__title {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
  color: var(--ink-2);
}

/* small muted line under a value — timestamps, poll notices */
.meta {
  margin-top: 0.3125rem;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}
.meta--inline {
  margin-top: 0;
}

.run-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.evidence__head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-wrap: wrap;
  margin-bottom: 0.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}
.evidence__id {
  font: 600 0.75rem/1 var(--mono);
  color: var(--muted);
}
.evidence__agent {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--ink);
}
.evidence__time {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.evidence__summary {
  margin: 0;
  color: var(--ink-2);
  font-size: 0.9375rem;
}

/* --- 12b. Reconciliation screen ---------------------------------------- */
/* Stacked form (file + text), unlike the one-line .field-row on /spvs. */

.field-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.field__label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-2);
}
.field__hint {
  margin: 0.375rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

/* file inputs need their own height — the native button ignores --ctl-h */
.input--file {
  height: auto;
  padding: 0.375rem 0.625rem;
  max-width: 30rem;
  width: 100%;
  font-size: 0.8125rem;
}
.input--file::file-selector-button {
  margin-right: 0.625rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-ctl);
  background: var(--surface-3);
  color: var(--ink);
  font: 600 0.75rem/1.4 var(--font);
  cursor: pointer;
}

.reconcile-state {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.reconcile-state__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.reconcile-state .meta {
  margin-top: 0;
}

/* six buckets read as one row of numbers, so they get tighter columns */
.stat-grid--buckets {
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
}
/* a bucket tile is a link out to the Drive markdown — the per-row detail behind
   the count is not in the database, so the tile has somewhere else to point */
a.stat--link {
  display: block;
  text-decoration: none;
  color: inherit;
}
a.stat--link:hover {
  border-color: var(--line-2);
  background: var(--surface-2);
}
a.stat--link:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow);
}

/* compact per-bucket counts inside a history table cell */
.count-chip {
  display: inline-block;
  margin: 0 0.375rem 0.1875rem 0;
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.count-chip + .count-chip::before {
  content: "· ";
}

.link-list {
  margin: 0;
  padding-left: 1.125rem;
  color: var(--ink-2);
  font-size: 0.875rem;
}
.link-list li + li {
  margin-top: 0.25rem;
}

/* a sha256 has no break opportunities of its own */
.breakable {
  overflow-wrap: anywhere;
}

/* --- 12c. Capital call + action screens --------------------------------- */
/* Parallel to 12b rather than a rename of it: .reconcile-state is on merged,
   verified templates, and a shared .run-state would mean editing them to gain
   nothing this screen needs.

   .action-state joins the selector list rather than reusing the capital-call
   class under a foreign name (2026-08-25). Layout only — no colour, no token,
   nothing the action fragments need that this block did not already do. */

.capital-call-state,
.action-state {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.capital-call-state__head,
.action-state__head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.capital-call-state .meta,
.action-state .meta {
  margin-top: 0;
}

/* a percentage and a date are both short — full-width inputs would read as if
   they wanted a sentence */
.input--pct {
  width: 7.5rem;
}
.input--date {
  width: 11rem;
}
.field__unit {
  color: var(--muted);
  font-size: 0.8125rem;
}
.field__optional {
  margin-left: 0.375rem;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.75rem;
  text-transform: none;
}

/* "superseded" sits beside a run id: taxonomy, not status, so it reuses .tag
   at a lower contrast rather than borrowing a status colour it doesn't have */
.tag--muted {
  margin-left: 0.375rem;
  border-color: var(--line);
  background: transparent;
  color: var(--muted);
}

/* --- 13. htmx ----------------------------------------------------------- */

.htmx-request {
  opacity: 0.55;
}

/* --- 14. Responsive / motion ------------------------------------------- */

@media (max-width: 720px) {
  :root {
    --gutter: 1rem;
  }
  .topbar__inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
  }
  .nav {
    margin-left: -0.625rem;
  }
  dl.kv {
    grid-template-columns: 1fr;
  }
  dl.kv dt {
    padding-bottom: 0;
    border-top: 1px solid var(--line);
  }
  dl.kv dt:first-of-type + dd {
    border-top: 0;
  }
  dl.kv dd {
    border-top: 0;
    padding-top: 0.125rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
