/* ── Unified palette (single source of truth) ── */
:root {
  /* Native UI (scrollbars, selects, pickers) must follow the palette, otherwise
     the UA paints dark chrome onto light surfaces. */
  color-scheme: light;

  /* What overlays are made of. Borders, hovers and faint fills are all "a little
     ink over the surface" — they are not white, they are the opposite of the
     background. Holding it as bare channels lets them stay `rgba(…, α)` and keep
     their own alpha, which a hex token cannot do. Flip this line and the ~270
     overlay sites across 21 stylesheets follow; that is the whole point of it. */
  --ink-rgb: 17, 24, 39;

  /* Ink for text sitting on a saturated fill — a primary button, a status chip.
     It is white in either theme, because the fill under it is mid-tone in either
     theme. It exists as a token so it reads as a decision: a bare `#fff` here
     looks like a dark-theme leftover, and a contrast sweep that could not tell
     the difference rewrote ten of them to `--text` before this existed. */
  --on-accent: #ffffff;

  /* The values proven on `/search` since 15 Sep, lifted here unchanged so that
     page's own copy could be deleted without its appearance moving. */
  --bg: #f6f7f9;
  --surface: #ffffff;
  /* `--raised` was the *brightest* of the three on dark, meaning "elevated". On
     light, `--surface` is already white, so there is nothing brighter to be and
     the three-step scale honestly collapses to two: anything raised separates
     itself with `--border` or a shadow instead. Kept as a token because ~20
     rules name it, and re-pointing it here beats hunting them. */
  --raised: #ffffff;
  --border: #e4e7ec;
  --text: #111827;
  --muted: #6b7280;

  /* Accents re-picked for contrast against white, not lightened for dark. The
     dark set were pastels — `--green: #6ee7b7` mint, `--amber: #fbbf24` — which
     on white read as roughly 1.4:1 and are unreadable as text. */
  --accent: #1c4ed8;
  --purple: #6d4bd8;
  --green: #047857;
  --amber: #b45309;
  --cyan: #0e7490;
  --err: #b42318;
  --ok: #047857;
  --rose: #be123c;
}
* { box-sizing: border-box; margin: 0; }

/* The `hidden` attribute has to beat any layout rule an element carries, because
   scripts here hide things by setting it. The browser's own `[hidden]` rule lives
   in the user-agent stylesheet, so a single author declaration of `display: flex`
   or `display: grid` silently outranks it and the element stays on screen with
   whatever it last said in it. That is a hard failure to see in review — the
   markup says hidden — so it is settled once, here, rather than patched per
   component. */
[hidden] { display: none !important; }

/* ── Pointer affordance on controls ──
   `cursor: pointer` on a macOS `<button>` is a lie: DevTools shows it, the OS
   still paints the arrow, because the UA bezel owns the cursor until appearance
   is stripped. Measured 16 Sep — every nav and Search button computed `pointer`
   and none of them showed a hand. `appearance: none` is the fix; it is not
   applied to `select` / checkbox / radio, whose chrome we still use.

   `:has()` is a rule of its own. In any engine that cannot parse it, a shared
   selector list would drop `button` too. */
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
a,
a *,
button *,
summary,
select,
input[type="checkbox"],
input[type="radio"],
input[type="file"],
input[type="color"],
[role="button"],
[role="button"] *,
[role="link"],
[role="link"] * { cursor: pointer; }
::-webkit-file-upload-button { cursor: pointer; }

label:has(input[type="checkbox"]),
label:has(input[type="radio"]) { cursor: pointer; }

/* A disabled control is not clickable, and saying so is the arrow's one honest
   use. `default` rather than `not-allowed` to match what the pages already do:
   eight of them write `cursor: default` on `:disabled`, three `not-allowed`. */
button:disabled,
button:disabled *,
select:disabled,
input:disabled,
label:has(input:disabled) { cursor: default; }

/* ── Base typography ── */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 0.82em;
  background: rgba(var(--ink-rgb), 0.06);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: var(--cyan);
}
h1 { font-size: 1.8rem; font-weight: 700; margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); font-size: 0.95rem; margin-bottom: 1.5rem; }
.back { color: var(--muted); text-decoration: none; font-size: 0.82rem; }
.back:hover { color: var(--accent); }
.empty-state { color: var(--muted); font-size: 0.85rem; padding: 3rem; text-align: center; }

/* ── Site navigation ── */
.site-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.25rem 0.6rem;
  border-radius: 5px;
  transition: color 0.15s, background 0.15s;
}
.site-nav a:hover { color: var(--text); background: rgba(var(--ink-rgb), 0.05); }
.site-nav a.active { color: var(--accent); background: rgba(110,168,254,0.1); }
.site-nav .nav-sep { color: rgba(var(--ink-rgb), 0.1); margin: 0 0.15rem; user-select: none; }

/* Wordmark, leading edge. Same 100×20 box and invert as `/search` and login:
   the file is light-on-transparent. Hover is opacity, not the link wash —
   a tinted box around the mark reads as a button. */
.nav-logo {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0.15rem 0.85rem 0.15rem 0;
}
.site-nav a.nav-logo:hover { background: transparent; }
.nav-logo img {
  display: block;
  width: 100px;
  height: 20px;
  filter: invert(1);
}
.nav-logo:hover img { opacity: 0.65; }

/* User destinations, trailing edge. Same spacer the Administrative
   dropdown and `.nav-user` use: the leading edge is the wordmark only. */
.site-nav .nav-user-menu {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
}

/* ── Nav dropdown ──
   Trailing edge, next to the user chip. `margin-left: auto` is the same
   spacer `.nav-user` uses when there is no dropdown. The menu opens left
   from the toggle so a right-edge control does not hang off the viewport. */
.site-nav .nav-dropdown { position: relative; display: inline-flex; margin-left: auto; }
.site-nav .nav-dropdown-toggle { cursor: pointer; }
.site-nav .nav-dropdown-toggle .caret { font-size: 0.6rem; margin-left: 0.25rem; }
.site-nav .nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: auto;
  right: 0;
  min-width: 190px;
  margin-top: 0.25rem;
  padding: 0.25rem;
  display: none;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.4);
  z-index: 50;
}
.site-nav .nav-dropdown:hover .nav-dropdown-menu { display: flex; }
.site-nav .nav-dropdown-menu a { white-space: nowrap; }
/* Transparent bridge over the margin gap so hover survives toggle→menu travel */
.site-nav .nav-dropdown-menu::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -0.25rem;
  height: 0.25rem;
}

/* ── Signed-in user, flush to the trailing edge of the nav ──
   Appended by shared/auth.js. Closed: the initial. Open (hover, same as
   Administrative): name, email, Logout. `margin-left: auto` absorbs free
   space unless the user menu or Administrative already owns the spacer. */
.nav-user {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  font-size: 0.78rem;
}
.site-nav:has(.nav-dropdown) .nav-user,
.site-nav:has(.nav-user-menu) .nav-user { margin-left: 0.75rem; }
.site-nav .nav-user:hover .nav-dropdown-menu { display: flex; }
.nav-user-avatar {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(var(--ink-rgb), 0.05);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}
.nav-user:hover .nav-user-avatar {
  border-color: var(--accent);
  background: rgba(110,168,254,0.1);
}
.nav-user-identity {
  padding: 0.4rem 0.6rem 0.35rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.15rem;
}
.nav-user-name {
  color: var(--text);
  font-weight: 600;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-user-email {
  color: var(--muted);
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-user-link { color: var(--muted); }
.nav-user-logout {
  width: 100%;
  padding: 0.25rem 0.6rem;
  font: inherit;
  font-size: inherit;
  text-align: left;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 5px;
}
.nav-user-logout:hover { color: var(--text); background: rgba(var(--ink-rgb), 0.05); }

/* ── Controls a client must not see ──
   Hidden by role rather than removed by script, because all of this markup is
   re-rendered after load — company_detail.js redraws its section list, its
   class-position panel and its source-file rows on every state change, and
   my_reports.js re-renders its rows after each action — so a one-off node
   removal would not survive.

   Each line sits in front of an endpoint src/api/lib/acl.py refuses to a
   client, so leaving it visible would offer a control whose only outcome is a
   403. Named individually, with the endpoint each one calls:

     #classPositionRefreshBtn       POST /api/v1/jobs          (starts pipeline work)
     .source-file-actions/-btn      GET  /api/v1/uploads/{id}  (raw decks, filings)
     [data-section="ingestion"]     GET  .../ingestion-provenance
     [data-section="history"]       GET  .../history           (pipeline run log)
     [data-action="activate"]       POST /report-briefs/{id}/runs  (spends model budget)
     [data-action="pause"]          POST /report-briefs/{id}/pause */
body.role-client #classPositionRefreshBtn,
body.role-client .source-file-actions,
body.role-client .source-file-btn,
body.role-client [data-section="ingestion"],
body.role-client [data-section="history"],
body.role-client [data-action="activate"],
body.role-client [data-action="pause"] { display: none !important; }

/* ── Status chips ── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip.ok { color: var(--ok); background: rgba(63,185,80,0.1); }
.chip.ok .dot { background: var(--ok); }
.chip.running { color: var(--amber); background: rgba(251,191,36,0.1); }
.chip.running .dot { background: var(--amber); }
.chip.error, .chip.failed, .chip.dead { color: var(--err); background: rgba(248,81,73,0.1); }
.chip.error .dot, .chip.failed .dot, .chip.dead .dot { background: var(--err); }
.chip.rejected { color: var(--rose); background: rgba(251,113,133,0.12); }
.chip.rejected .dot { background: var(--rose); }
.chip.queued, .chip.retry { color: var(--muted); background: rgba(148,163,184,0.1); }
.chip.queued .dot, .chip.retry .dot { background: var(--muted); }
.chip.aborted { color: var(--purple); background: rgba(167,139,250,0.1); }
.chip.aborted .dot { background: var(--purple); }

/* ── Pipeline badges ── */
.pipe-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pipe-badge.ingestion { color: var(--accent); background: rgba(110,168,254,0.1); }
.pipe-badge.enrichment { color: var(--purple); background: rgba(167,139,250,0.1); }
.pipe-badge.graph { color: var(--green); background: rgba(110,231,183,0.1); }
.pipe-badge.class_position { color: var(--amber); background: rgba(251,191,36,0.1); }

/* ── Small buttons ── */
.btn-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.72rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn-sm:hover { border-color: var(--accent); }

/* ── Result-row links ──
   The open-in-new-window glyph emitted by asset_search.js. Lives here rather
   than in a page stylesheet because the renderer is shared by /graph and the
   home search table, which carry separate CSS files. */
.row-link-icon {
  margin-left: 0.25rem;
  vertical-align: -1px;
  opacity: 0.5;
}
.row-link:hover .row-link-icon { opacity: 1; }

/* ── Hover legend ── */
.hover-legend {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(var(--ink-rgb), 0.04);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  cursor: help;
  user-select: none;
}
.hover-legend:hover,
.hover-legend:focus-visible {
  color: var(--text);
  border-color: rgba(110,168,254,0.35);
}
.hover-legend::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 50%;
  transform: translateX(-50%);
  width: min(28rem, 80vw);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.45;
  white-space: normal;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  opacity: 0;
  pointer-events: none;
  z-index: 200;
}
.hover-legend:hover::after,
.hover-legend:focus-visible::after {
  opacity: 1;
}
.hover-legend.has-panel::after {
  display: none;
}
.hover-legend-panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 50%;
  transform: translateX(-50%);
  width: min(30rem, 84vw);
  max-width: calc(100vw - 1rem);
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  /* Flat `--surface`, not a gradient. The dark original ran two near-identical
     slate stops for a faint sheen; on white there is no sheen to have, and the
     panel separates from the page by its border and shadow instead. */
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: 0 14px 36px rgba(0,0,0,0.18);
  white-space: normal;
  opacity: 0;
  pointer-events: none;
  z-index: 220;
}
.hover-legend:hover .hover-legend-panel,
.hover-legend:focus-visible .hover-legend-panel {
  opacity: 1;
}
.hover-legend-title {
  display: block;
  margin-bottom: 0.55rem;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.hover-legend-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: start;
}
.hover-legend-row + .hover-legend-row {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(var(--ink-rgb), 0.06);
}
.hover-legend-row .chip {
  min-width: 5.4rem;
  justify-content: center;
  font-size: 0.68rem;
}
.hover-legend-copy {
  color: var(--text);
  font-size: 0.76rem;
  line-height: 1.4;
  white-space: normal;
}
.hover-legend-copy strong {
  color: var(--text);
}

/* ── Step dots + pulse animation ── */
.step-bar { display: flex; gap: 2px; margin: 0.25rem 0; }
.step-dot { width: 2px; height: 10px; border-radius: 3px; background: rgba(var(--ink-rgb), 0.08); }
.step-dot.ok { background: var(--ok); }
.step-dot.running { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.step-dot.error { background: var(--err); }
.step-dot.pending { background: rgba(var(--ink-rgb), 0.08); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Domain autocomplete ── */
.domain-ac { position: relative; display: inline-flex; align-items: center; }
.domain-ac input { padding-right: 1.4rem !important; }
.domain-ac-clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  color: var(--muted); cursor: pointer; font-size: 0.9rem; line-height: 1;
  z-index: 2; user-select: none;
}
.domain-ac-clear:hover { color: var(--err); }
.domain-ac-dropdown {
  display: none; position: absolute; top: 100%; left: 0; right: 0;
  min-width: 260px; max-height: 240px; overflow-y: auto;
  background: var(--raised); border: 1px solid rgba(var(--ink-rgb), 0.08);
  border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,0.4);
  z-index: 300; margin-top: 2px;
}
.domain-ac-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.4rem 0.65rem; cursor: pointer; gap: 0.5rem; transition: background 0.1s;
}
.domain-ac-item:hover, .domain-ac-item.hl { background: rgba(110,168,254,0.12); }
.domain-ac-label {
  font-size: 0.8rem; color: var(--text); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.domain-ac-sub { font-size: 0.68rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.domain-ac-empty { padding: 0.5rem 0.65rem; font-size: 0.78rem; color: var(--muted); }

/* ── Loading overlay ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
  font-size: 0.875rem;
  color: var(--muted);
}
.loading-overlay.hidden { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
}
