/* ============================================================
   Backfin Research cockpit — design tokens
   Ledger palette: warm paper ground, ink text, one bottle-green accent.
   Self-hosted IBM Plex (Sans 400/600 for UI, Mono 400 for numbers only).
   ============================================================ */

@font-face {
  font-family: "Plex Sans";
  src: url("fonts/IBMPlexSans-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Sans";
  src: url("fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url("fonts/IBMPlexMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* light (default) */
  --paper: #faf8f4;
  --paper-raised: #f2efe8;
  --ink: #1c1a16;
  --ink-muted: #635e54;
  --line: #ddd6c8;
  --accent: #1a5c46;
  --accent-ink: #f4f8f6; /* text on accent fill */
  --accent-hover: #134634;
  --focus-ring: #1a5c46;
  --up: #1a5c46;
  --down: #8c2a1e;
  --shadow: none;

  --font-ui: "Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

:root[data-theme="dark"] {
  --paper: #14140f;
  --paper-raised: #1c1c15;
  --ink: #e9e4d8;
  --ink-muted: #a39c8c;
  --line: #3a3928;
  --accent: #3ea882;
  --accent-ink: #0b1712;
  --accent-hover: #57bd97;
  --focus-ring: #3ea882;
  --up: #3ea882;
  --down: #d9705f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14140f;
    --paper-raised: #1c1c15;
    --ink: #e9e4d8;
    --ink-muted: #a39c8c;
    --line: #3a3928;
    --accent: #3ea882;
    --accent-ink: #0b1712;
    --accent-hover: #57bd97;
    --focus-ring: #3ea882;
    --up: #3ea882;
    --down: #d9705f;
  }
}

:root[data-theme="light"] {
  --paper: #faf8f4;
  --paper-raised: #f2efe8;
  --ink: #1c1a16;
  --ink-muted: #635e54;
  --line: #ddd6c8;
  --accent: #1a5c46;
  --accent-ink: #f4f8f6;
  --accent-hover: #134634;
  --focus-ring: #1a5c46;
  --up: #1a5c46;
  --down: #8c2a1e;
}

/* ============================================================
   Base
   ============================================================ */

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  font-size: 15px;
  line-height: 1.45;
}

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

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

/* ============================================================
   Header
   ============================================================ */

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.75rem;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { font-weight: 600; }
header nav { display: flex; align-items: center; gap: 1rem; }
header nav span { color: var(--ink-muted); font-size: 0.9rem; }

.theme-toggle {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--ink-muted);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--ink); border-color: var(--ink-muted); }

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 2rem 1.75rem 3rem;
}

h1 { font-size: 1.3rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.5rem; }

/* ============================================================
   Companies table
   ============================================================ */

.filter-row { margin-bottom: 0.9rem; }

#filter {
  width: 100%;
  max-width: 360px;
  padding: 0.5rem 0.7rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
}
#filter:focus-visible { outline-offset: 1px; }

.table-wrap {
  max-height: 72vh;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 3px;
}

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

thead th {
  position: sticky;
  top: 0;
  background: var(--paper-raised);
  text-align: left;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-bottom: 1px solid var(--line);
  z-index: 1;
}

td {
  padding: 0.45rem 0.9rem;
  border-bottom: 1px solid var(--line);
}

tbody tr:hover { background: var(--paper-raised); }
tbody tr:last-child td { border-bottom: none; }

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
th.num { text-align: right; }

/* ============================================================
   Login
   ============================================================ */

form.login {
  max-width: 320px;
  margin: 4.5rem auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
form.login h1 { text-align: center; margin-bottom: 0.5rem; }
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--ink-muted); }

input {
  padding: 0.55rem 0.65rem;
  font-family: var(--font-ui);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
}

button {
  padding: 0.6rem 0.9rem;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 3px;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }

.error { color: var(--down); font-size: 0.9rem; }

/* ============================================================
   Company page
   ============================================================ */

dl.stats {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem 1.25rem;
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
}
dl.stats dt { color: var(--ink-muted); }
dl.stats dd { margin: 0; }
dl.stats dd.num { text-align: left; }

.actions { display: flex; gap: 0.75rem; margin: 1.5rem 0; }

.button {
  display: inline-block;
  padding: 0.55rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--accent-ink);
  background: var(--accent);
  border: none;
  border-radius: 3px;
  text-decoration: none;
}
.button:hover { background: var(--accent-hover); text-decoration: none; }

.v2 {
  margin-top: 2.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--ink-muted);
}
.v2 h2 { color: var(--ink-muted); }

/* ============================================================
   Coverage: status badges, credit meter, queue groups
   ============================================================ */

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid var(--line);
  color: var(--ink-muted);
}
.badge-generating { color: var(--ink-muted); }
.badge-needs_review { color: var(--down); border-color: var(--down); }
.badge-approved { color: var(--accent); border-color: var(--accent); }
.badge-published { color: var(--accent); border-color: var(--accent); background: var(--paper-raised); }
.badge-generation_failed { color: var(--down); border-color: var(--down); background: var(--paper-raised); }

.credit-meter {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  color: var(--ink-muted);
  font-size: 0.88rem;
}
.credit-meter strong { color: var(--ink); font-weight: 600; }

.queue-group { margin-bottom: 2rem; }
.queue-group h2 { color: var(--ink-muted); font-size: 0.85rem; text-transform: none;
  letter-spacing: 0.02em; margin-bottom: 0.5rem; }

.provenance { color: var(--ink-muted); font-size: 0.82rem; font-family: var(--font-num); }

/* ============================================================
   Ask
   ============================================================ */

.beta-tag {
  display: inline-block;
  margin-left: 0.6rem;
  padding: 0.15rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  vertical-align: middle;
}

form.ask { display: flex; flex-direction: column; gap: 0.9rem; max-width: 640px; }
form.ask textarea {
  padding: 0.6rem 0.7rem;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 3px;
  min-height: 5.5rem;
  resize: vertical;
}
form.ask button { align-self: flex-start; }

.answer { margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.answer .table-wrap { margin: 1rem 0; max-height: none; }
.sources, .qna-note { color: var(--ink-muted); font-size: 0.85rem; }
