/* Shared base design system — the app shell, form controls, buttons,
   tables, and every other visual primitive common to EVERY portal
   (PLATFORM today; COMPETITION/STUDIO later). Lives outside any one
   portal's folder for the same reason public/shared/modal.css does:
   copy-pasting this per portal is how two consoles quietly drift apart —
   see plan/ui/shared-components.md.

   Design tokens (:root) are the single source of truth for every color/
   radius value a portal-specific stylesheet or public/shared/modal.css
   might reference via var(--accent, ...) fallbacks — defining them here,
   once, is what makes a future re-skin a one-file edit instead of a
   find-and-replace across every portal.

   A portal's own <style> block should hold ONLY what's genuinely specific
   to it (PLATFORM's icon-set editor and strings/translation admin UI are
   the current examples) — anything else belongs here instead. */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-hover: #1d212b;
  --panel-border: #262b36;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --accent: #5b8cff;
  --accent-hover: #6f9aff;
  --danger: #ff6b6b;
  --success: #35c98f;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  /* Safety net, not the primary fix (see .sub-nav-scroll-wrap and
     .content below for that) — if anything anywhere ever overflows its
     container's width, this keeps it from widening the whole page and
     giving mobile a page-level horizontal scrollbar/shift. Worst case an
     offending element gets visually clipped instead, which is still
     better than the entire viewport shifting. */
  overflow-x: hidden;
}
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }

/* Links otherwise inherit the browser's default blue/purple-visited
   palette, which reads harshly against this dark theme and doesn't match
   anything else in it — pick up the same accent blue every button
   already uses, with no separate "visited" color (a visited row isn't a
   meaningfully different state here the way it is on the open web). */
a { color: var(--accent); }
a:visited { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* ---- Login screen ----
   Starts hidden (see the "hidden" class on the element itself) while a
   portal's own app.js decides whether a saved session can be resumed. If
   login turns out to be needed, "hidden" is removed and "login-visible"
   is added a frame later, so it fades in and drops from a -4em offset
   over 200ms instead of flashing in immediately. Every portal's login
   screen should reuse these classes rather than redefining its own — the
   actual FIELDS inside .login-card differ per portal/role, the shell
   around them shouldn't. */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transform: translateY(-4em);
  transition: opacity 200ms ease-out, transform 200ms ease-out;
}
.login-screen.login-visible {
  opacity: 1;
  transform: translateY(0);
}
.login-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.login-card h1 {
  font-size: 18px;
  margin: 0 0 4px;
}
.login-card .hint {
  margin: 0;
}

/* ---- App shell (ChatGPT-style: sidebar with footer identity, no top
   banner). Every portal's own index.html should reuse this exact
   structure/class set — only NAV_SECTIONS-equivalent content and the
   router logic that drives it differ per portal. ---- */
.app-shell {
  display: flex;
  height: 100vh;
}
.sidebar {
  width: 230px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
}
.sidebar-brand {
  padding: 16px 20px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--panel-border);
}
.sidebar-brand .sub {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}
.nav-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  color: var(--text-dim);
  padding: 9px 12px;
  cursor: pointer;
  font-size: 14px;
}
.nav-item:hover { background: var(--panel-hover); color: var(--text); }
.nav-item.active { background: rgba(91,140,255,0.12); color: var(--accent); }

/* Identity + logout pinned to the bottom of the sidebar, a la ChatGPT */
.sidebar-footer {
  flex: none;
  border-top: 1px solid var(--panel-border);
  padding: 10px;
  position: relative;
}
.identity-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 8px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.identity-btn:hover { background: var(--panel-hover); }
.identity-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.identity-email {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.identity-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  overflow: hidden;
}
.identity-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
}
.identity-menu button:hover { background: var(--panel-hover); }

/* ---- Main area ---- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
/* public/shared/scrollable-tabs.js wraps every .sub-nav in one of these
   at runtime (idempotent — safe to call again on every re-render) so a
   tab row with more items than fit on a narrow screen scrolls
   horizontally within its own box — finger-drag/swipe via native touch
   scrolling, no extra JS needed for that part — instead of overflowing
   the page width (the actual bug: an un-contained overflow here was
   widening the whole document, giving mobile a page-level horizontal
   scrollbar). The edge fade + </> arrows are driven by two JS-toggled
   state classes below (.sub-nav-scrollable, .sub-nav-at-start/-at-end),
   since CSS alone has no way to know scrollLeft/scrollWidth. A .sub-nav
   that doesn't actually overflow is wrapped too (harmless — the fade/
   arrows just never get .sub-nav-scrollable and stay invisible), so
   nothing about a normal desktop tab bar changes. */
.sub-nav-scroll-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
  flex: none;
  min-width: 0;
  margin-bottom: 16px;
}
/* PLATFORM's single persistent #sub-nav toggles its own .hidden class
   (never the wrap's) when there's no sub-nav to show at all — e.g. no
   comp selected yet. Without this, the wrap's margin-bottom above would
   leave a stray empty gap even with the nav itself fully collapsed. */
.sub-nav-scroll-wrap:has(.sub-nav.hidden) { display: none; }
.sub-nav {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 24px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--bg);
  /* Moved to .sub-nav-scroll-wrap above — kept here too (margin-bottom:
     0) for the rare case something renders a bare, unwrapped .sub-nav
     before enhanceScrollableTabs() has run on first paint. */
  margin-bottom: 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* old Edge/IE */
}
.sub-nav::-webkit-scrollbar { display: none; } /* Chrome/Safari */
.sub-nav-back {
  flex: none;
  white-space: nowrap;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 12px 10px 12px 0;
  margin-right: 6px;
  cursor: pointer;
  font-size: 13px;
  border-right: 1px solid var(--panel-border);
}
.sub-nav-back:hover { color: var(--text); }
.sub-nav-item {
  flex: none;
  white-space: nowrap;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  padding: 12px 14px;
  border-bottom: 2px solid transparent;
}
.sub-nav-item:hover { color: var(--text); }
.sub-nav-item.active { color: var(--text); border-bottom-color: var(--accent); }

/* Edge fade vignettes — pseudo-elements on the wrap rather than extra
   DOM nodes, since they're purely decorative. var(--bg) matches .sub-nav's
   own background exactly above, so the fade reads as "the bar thinning
   out" rather than a visibly separate overlay. */
.sub-nav-scroll-wrap::before,
.sub-nav-scroll-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 1;
}
.sub-nav-scroll-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg) 0%, transparent 100%);
}
.sub-nav-scroll-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg) 0%, transparent 100%);
}
.sub-nav-scroll-wrap.sub-nav-scrollable:not(.sub-nav-at-start)::before { opacity: 1; }
.sub-nav-scroll-wrap.sub-nav-scrollable:not(.sub-nav-at-end)::after { opacity: 1; }

.sub-nav-scroll-arrow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  z-index: 2;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, color 0.15s ease;
}
.sub-nav-scroll-arrow:hover { color: var(--text); }
.sub-nav-scroll-arrow:disabled { cursor: default; }
.sub-nav-scroll-arrow-left { left: 0; }
.sub-nav-scroll-arrow-right { right: 0; }
.sub-nav-scroll-wrap.sub-nav-scrollable:not(.sub-nav-at-start) .sub-nav-scroll-arrow-left,
.sub-nav-scroll-wrap.sub-nav-scrollable:not(.sub-nav-at-end) .sub-nav-scroll-arrow-right {
  opacity: 1;
  pointer-events: auto;
}
.content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  /* Contains any wide inner element's overflow to a scrollbar on THIS
     box rather than letting it leak into a page-level horizontal
     scrollbar (html/body's own overflow-x: hidden above is the last-
     resort backstop; this is the one that actually keeps the content
     reachable instead of silently clipped). */
  overflow-x: auto;
  padding: 24px;
}
.loading { color: var(--text-dim); font-size: 13px; }

/* ---- Mobile nav: sidebar becomes an off-canvas panel behind a
   hamburger, below the breakpoint. Hidden entirely on desktop. 768px is
   the one shared breakpoint every portal-agnostic component in this
   project uses (modal.css's mobile takeover matches it too — keep them
   in sync if this ever changes). ---- */
.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel);
  flex: none;
}
.mobile-topbar .sidebar-brand { padding: 0; border: none; }
.hamburger-btn {
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
}
.hamburger-btn:hover { border-color: var(--accent); }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@media (max-width: 768px) {
  .mobile-topbar { display: flex; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    max-width: 82vw;
    z-index: 50;
    transform: translateX(-100%);
    opacity: 0;
    /* Same timing as the account flyout: fast start, slow finish, 200ms. */
    transition: transform 200ms ease-out, opacity 200ms ease-out;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.4);
  }
  body.sidebar-open .sidebar { transform: translateX(0); opacity: 1; }
  body.sidebar-open .sidebar-backdrop { display: block; animation: backdrop-in 200ms ease-out; }
  @media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
    body.sidebar-open .sidebar-backdrop { animation: none; }
  }
  body.sidebar-open { overflow: hidden; }
  .content { padding: 16px; }
  .panel-header { flex-wrap: wrap; gap: 8px; }
  .row { flex-direction: column; gap: 0; }
}

/* ---- Core component styles — panels, cards, forms, tables, buttons,
   badges, messages. The design-system vocabulary every portal's own
   screens are built out of. ---- */
.panel { display: flex; flex-direction: column; gap: 16px; max-width: 880px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { margin: 0; font-size: 16px; }
.panel h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card.danger-zone { border-color: rgba(255,107,107,0.3); }
label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: #0d0f14;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  /* Explicit, not inherited — a <button> is a form control too, and
     browsers give form controls their own UA line-height (~1.2, "normal")
     that does NOT reliably inherit the body's declared 1.5 the way plain
     text does. Declaring it here removes the ambiguity on this side; .btn
     below declares the identical value so both compute to the same pixel
     content-height regardless of what either element would have defaulted
     to on its own. This, not the border, was the real source of every
     button/field height mismatch — see .toolbar's comment. */
  line-height: 1.5;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { width: auto; }
input[type="radio"] { margin: 0; flex: none; }

/* Expand/collapse panel: toggle .open on .cr-collapse; the content goes in .cr-collapse-inner. 200 ms ease, no fixed height needed. */
.cr-collapse { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 200ms ease; }
.cr-collapse.open { grid-template-rows: 1fr; }
.cr-collapse > .cr-collapse-inner { overflow: hidden; min-height: 0; }
@media (prefers-reduced-motion: reduce) { .cr-collapse { transition: none; } }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; }
.row .field { flex: 1; min-width: 0; }
.form-actions { display: flex; gap: 8px; }
/* The recurring "inline toolbar" row: one or more labeled .field pickers
   beside one or more bare <button>s, e.g. "[Person v] [Role v] [Add] [+New]".
   align-items: flex-end lines up the bottom of each field's INPUT with each
   button (not the vertical center of the whole row, which centers a bare
   button against a field's taller label+input block and looks off). A
   .field's own margin-bottom (for vertical rhythm when fields stack) has to
   be zeroed here too — left in place, it pushes a .field's alignment edge
   below its visible input, so even bottom-aligned buttons end up looking a
   few pixels low. Every portal should reach for this class (or extend it,
   as COMPETITION's own .list-toolbar does) instead of re-deriving the same
   flex/align-items/margin combination inline per screen — that's exactly
   how this kept recurring. */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.toolbar .field { margin-bottom: 0; }
.btn {
  appearance: none;
  /* Two deliberate matches to input/select/textarea above, both needed to
     make a .btn's rendered height come out identical to a field's — this is
     what actually made every toolbar mixing fields and bare buttons look
     misaligned, not the flex alignment itself:
       1. A real (transparent) 1px border, not "none" — a button with no
          border is 2px shorter than a bordered field even at the same font
          size/line-height.
       2. font-size and line-height matching input/select exactly (14px /
          1.5 → 21px of content height either way). A browser's native
          line-height for a <button> ("normal", ~1.15-1.2) does NOT reliably
          inherit the page's declared 1.5 the way ordinary text does, so a
          13px button with no explicit line-height renders its content
          around 15px tall against a same-size field's 21px — a 6px gap,
          the dominant part of the mismatch, not the 2px border.
     Get both wrong and align-items: flex-end still "works" (bottoms do
     line up) but the button visibly reads as a different, shorter box
     than the field beside it. See .toolbar above. */
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 500;
  cursor: pointer;
  background: var(--accent);
  color: white;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn { display: inline-flex; align-items: center; gap: 8px; }
.spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.btn-ghost { background: transparent; border: 1px solid var(--panel-border); color: var(--text); }
.btn-ghost:hover { border-color: var(--accent); background: transparent; color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #ff8080; }
.btn-small { padding: 6px 10px; font-size: 12px; }
.msg { font-size: 13px; padding: 8px 12px; border-radius: 6px; display: none; }
.msg.error { display: block; background: rgba(255,107,107,0.1); color: var(--danger); }
.msg.success { display: block; background: rgba(53,201,143,0.1); color: var(--success); }
.hint { color: var(--text-dim); font-size: 12px; }
code { background: #0d0f14; padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.empty { color: var(--text-dim); font-size: 13px; padding: 8px 0; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th, table.data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--panel-border); vertical-align: middle; }
table.data-table th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.status-pill, .badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  background: rgba(91,140,255,0.15);
  color: var(--accent);
}
.badge-muted { background: rgba(154,163,178,0.15); color: var(--text-dim); }
.status-pill-success { background: rgba(53,201,143,0.15); color: var(--success); }
.status-pill-danger { background: rgba(255,107,107,0.15); color: var(--danger); }
.detail-list { display: grid; grid-template-columns: 140px 1fr; row-gap: 8px; font-size: 13px; margin: 0; }
.detail-list dt { color: var(--text-dim); }
.detail-list dd { margin: 0; }
.setting-row { border: 1px solid var(--panel-border); border-radius: 8px; padding: 14px 16px; }
.setting-row-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.setting-row-control { margin: 8px 0; max-width: 320px; }
.setting-row-actions { display: flex; gap: 8px; }
.settings-list { display: flex; flex-direction: column; gap: 10px; }
details.card summary { cursor: pointer; font-size: 13px; color: var(--text-dim); }
details.card[open] summary { margin-bottom: 12px; }

/* ---- Pager — the generic "N of M, load more / prev / next" control.
   Currently used by the strings admin (page-number style, per
   api-design-standards.md's rule-4 exception for that one endpoint);
   also the shape the future cursor-pager helper
   (plan/ui/shared-components.md) and the eventual tabular-data
   presenter's own pagination row should visually match, so a "pager"
   looks the same everywhere it appears regardless of which pagination
   strategy is driving it underneath. ---- */
.pager {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.pager-jump { display: flex; align-items: center; gap: 6px; margin-left: auto; }

/* ---- Icon action buttons (shared by every portal) ----
   The round icon buttons in table rows and edit forms. Transparent so they
   sit on the dark panel in every portal; the browser's default light button
   was what made them look out of place. */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }
.icon-btn-danger:hover { border-color: var(--danger); color: var(--danger); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn:disabled:hover { border-color: var(--panel-border); color: var(--text); }

/* A plain, hand-rolled <table class="data-table"> row's own action cell
   (edit/delete icon buttons) — the same width:1%/nowrap/right-align
   treatment table-presenter.css's .cr-table-th-anchor-end/
   .cr-table-td-anchor-end give a TablePresenter table's anchored 'end'
   column "for free" (see that file's own comment), just as a plain class
   for a page that isn't using TablePresenter at all. Pair with the
   .cr-table-row-actions flex wrapper (table-presenter.css, usable on any
   page regardless of whether a TablePresenter instance is present) around
   the buttons themselves. See plan/ui/row-actions-standard.md.
   Selector is qualified (table.data-table td.cr-row-actions-cell, not
   just .cr-row-actions-cell) to out-specificity table.data-table's own
   "th, td { text-align: left }" base rule above — a bare single-class
   selector loses to that one on specificity regardless of source order,
   which is exactly the bug that shipped first (the action buttons
   rendered left-aligned instead of right). */
table.data-table td.cr-row-actions-cell {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

/* Tri-toggle (public/shared/tri-toggle.js) — a compact inline 3-state
   segmented control (Unanswered/Yes/No), replacing a pair of full-width
   stacked buttons for exactly this shape of question. One pill, three
   small segments, the active one highlighted by color — first built for
   the CREW Availability panel's per-row answer, kept here (not in
   CREW's own connections.css) since it's genuinely portal-agnostic. */
.tri-toggle {
  display: inline-flex;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}
.tri-toggle-seg {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tri-toggle-seg + .tri-toggle-seg { border-left: 1px solid var(--panel-border); }
.tri-toggle-seg:hover { background: rgba(255, 255, 255, 0.06); color: var(--text); }
.tri-toggle-seg.active.tri-toggle-unanswered { background: var(--panel-border); color: var(--text); }
.tri-toggle-seg.active.tri-toggle-yes { background: #15803d; color: #fff; }
.tri-toggle-seg.active.tri-toggle-no { background: #b91c1c; color: #fff; }

/* ---- Lookup field (shared/lookup-field.js): type-ahead dropdown ---- */
.lookup-wrap { position: relative; }
.lookup-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 50;
}
.lookup-list.hidden { display: none; }
.lookup-option, .lookup-message { padding: 7px 10px; border-radius: 4px; font-size: 13px; }
.lookup-option { cursor: pointer; }
.lookup-option:hover, .lookup-option.is-active { background: rgba(91, 140, 255, 0.15); }
.lookup-message { color: var(--text-dim); }

/* ---- Filter pills: one per active filter, each with an X to drop it ---- */
.filter-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.filter-pills:empty { display: none; }
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(91, 140, 255, 0.15);
  color: var(--text);
  border: 1px solid rgba(91, 140, 255, 0.35);
}
.filter-pill button {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--text-dim);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}
.filter-pill button:hover { background: rgba(255, 255, 255, 0.12); color: var(--text); }
/* Count of active filters on a "Filters" button. */
.filter-count {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

/* Standard new-tab marker (public/shared/new-tab-icon.js). */
.new-tab-icon { vertical-align: -2px; margin-left: 2px; opacity: 0.8; flex: none; }

/* ---- STANDARD FIELD ERROR REPORTING (all portals) ----
   An invalid control is wrapped in .field-wrap and the wrapper gets
   .has-error. The signal is NOT colour alone: a dashed outline, a small "!"
   icon inside the field (right aligned), and a text reason elsewhere
   (.form-block-note beside the submit button, or .field-error-text under a
   field). Nothing here changes layout: the outline is drawn outside the box,
   the icon is absolutely positioned and always present (only its visibility
   toggles), and the note keeps a reserved two-line height. */
.field-wrap { position: relative; display: block; min-width: 0; }
.field-wrap > input, .field-wrap > select, .field-wrap > textarea { width: 100%; }
.field-wrap.has-error > input, .field-wrap.has-error > select, .field-wrap.has-error > textarea {
  outline: 2px dashed var(--danger); outline-offset: 1px; border-color: var(--danger);
}
.field-err-icon {
  position: absolute; top: 50%; right: 8px; transform: translateY(-50%);
  width: 14px; height: 14px; border: 1.5px solid var(--danger); border-radius: 50%;
  color: var(--danger); font-size: 10px; font-weight: 700; line-height: 11px; text-align: center;
  pointer-events: none; visibility: hidden;
}
.field-wrap.has-error > .field-err-icon { visibility: visible; }
.field-wrap > select ~ .field-err-icon { right: 30px; } /* clear the native dropdown arrow */
.form-block-note { flex: 1 1 14rem; min-height: 2.8em; display: flex; align-items: center; color: var(--danger); font-size: 13px; line-height: 1.4; }
.form-block-note:empty::before { content: ''; }

/* Number inputs: no spinner arrows in any portal (they are cramped and
   ugly; people type the number). The numeric keypad still appears on phones. */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Messages under a form or popup: room above, and a little below so they never sit tight to the edge of a popup. */
.msg.error, .msg.success, .msg.info { margin: 12px 0 4px; }
.cr-modal-body > .msg:last-child { margin-bottom: 4px; }
/* Controls marked invalid in place (shared/field-error.js markInvalid): dashed outline, not colour alone. */
.field-invalid { outline: 2px dashed var(--danger); outline-offset: 1px; border-color: var(--danger) !important; }

/* The portals are dark: draw the native date/time picker (calendar icon) light so it contrasts. */
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"] { color-scheme: dark; }

/* A table cell holding only a checkbox is a full-size click target. shared/cell-checkbox.js does the toggling and marks the
   cell .cr-cell-check as the pointer arrives (so the cursor matches exactly what a click will do). See plan/ui/checkbox-cells.md. */
.cr-cell-check { cursor: pointer; }

/* ---- Scroll shadow (standard for any box that scrolls inside itself) ----
   Add class "cr-scroll" to the scrolling element and give it a max-height. A soft shadow along the bottom edge says "there is more
   below" and disappears by itself once the content is scrolled to the end. "cr-scroll-both" adds the same cue at the top.
   Pure CSS (background-attachment: local covers the shadow with the surface colour when scrolled to an edge), so no script.
   --scroll-bg must match the surface the box sits on (default: the panel colour; set it on the element or an ancestor if different). */
.cr-scroll {
  --scroll-bg: var(--panel, #171a21);
  --scroll-shadow: rgba(0, 0, 0, 0.55);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.28) transparent; /* a slim dark scrollbar instead of the browser's light one */
  background:
    linear-gradient(transparent, var(--scroll-bg) 85%) bottom / 100% 36px no-repeat local,
    radial-gradient(farthest-side at 50% 100%, var(--scroll-shadow), transparent) bottom / 100% 12px no-repeat scroll;
}
.cr-scroll.cr-scroll-both {
  background:
    linear-gradient(var(--scroll-bg) 15%, transparent) top / 100% 36px no-repeat local,
    linear-gradient(transparent, var(--scroll-bg) 85%) bottom / 100% 36px no-repeat local,
    radial-gradient(farthest-side at 50% 0, var(--scroll-shadow), transparent) top / 100% 12px no-repeat scroll,
    radial-gradient(farthest-side at 50% 100%, var(--scroll-shadow), transparent) bottom / 100% 12px no-repeat scroll;
}

/* ---- Edge fade (works on ANY background; preferred over .cr-scroll when the surface colour is not known) ----
   Add class "cr-fade-scroll" to a box that already scrolls (overflow-y: auto plus a max-height or height). The content fades to
   transparent along an edge that has more beyond it: the bottom while there is more below, the top once you have scrolled down.
   Nothing is painted in a surface colour, so there is no --scroll-bg to match. A box that does not scroll gets no fade (its scroll
   timeline is inactive, so both widths stay at their 0 starting value).
   Only the content fades: the box's own border, rounded corners and scrollbar stay fully visible (see the mask layers below).
   Needs scroll-driven animations (Chrome, Edge, Safari 26+). Where they are missing the class does nothing, and a box that also
   carries .cr-scroll keeps that class's shadow (in a darker shade of its surface, so it still shows on dark surfaces). */
.cr-scroll.cr-fade-scroll { --scroll-shadow: color-mix(in oklch, var(--scroll-bg), black 55%); }
@property --fade-top { syntax: '<length>'; inherits: false; initial-value: 0px; }
@property --fade-bottom { syntax: '<length>'; inherits: false; initial-value: 0px; }
@keyframes cr-fade-top { from { --fade-top: 0px; } to { --fade-top: 28px; } }
@keyframes cr-fade-bottom { from { --fade-bottom: 28px; } to { --fade-bottom: 0px; } }
@supports (animation-timeline: scroll()) {
  .cr-fade-scroll {
    /* Three mask layers, so only the content fades and the box's own border and scrollbar stay fully visible:
       1) the fade, limited to the padding box (inside the border and scrollbar); 2) a solid fill of the border box minus 3) a solid
       fill of the padding box = a ring (border + scrollbar) that is always shown. Result: fade UNION ring. */
    mask-image: linear-gradient(to bottom, transparent, #000 var(--fade-top), #000 calc(100% - var(--fade-bottom)), transparent),
      linear-gradient(#000, #000), linear-gradient(#000, #000);
    mask-clip: padding-box, border-box, padding-box;
    mask-origin: padding-box, border-box, padding-box;
    mask-composite: add, subtract, add;
    animation: cr-fade-top linear both, cr-fade-bottom linear both;
    animation-timeline: scroll(self), scroll(self);
    animation-range: 0 28px, calc(100% - 28px) 100%;
  }
  .cr-scroll.cr-fade-scroll { background-image: none; } /* the fade replaces the shadow */
  /* "cr-fade-bottom-only": no top fade, for a box with a sticky heading that must stay fully visible while scrolling. */
  .cr-fade-scroll.cr-fade-bottom-only {
    animation-name: cr-fade-bottom;
    animation-timeline: scroll(self);
    animation-range: calc(100% - 28px) 100%;
  }
}

/* ---- Pill option (a choice you tap to select; a check mark appears when selected) ---- */
.cr-pill-option {
  display: flex; align-items: center; gap: 10px; width: 100%; box-sizing: border-box; text-align: left; font: inherit; color: var(--text, #e6e9ef);
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--panel-border, #262b36); background: rgba(255, 255, 255, 0.03); cursor: pointer;
  transition: background 200ms ease, border-color 200ms ease, transform 200ms ease;
}
.cr-pill-option:hover { background: rgba(255, 255, 255, 0.07); }
.cr-pill-option:focus-visible { outline: 2px solid var(--accent, #5b8cff); outline-offset: 2px; }
.cr-pill-option:active { transform: scale(0.99); }
.cr-pill-option[aria-pressed="true"] { background: color-mix(in srgb, var(--accent, #5b8cff) 22%, transparent); border-color: var(--accent, #5b8cff); }
.cr-pill-option .cr-pill-check { flex: none; display: inline-flex; width: 0; margin-right: -10px; opacity: 0; transform: scale(0.5); overflow: hidden; color: var(--accent, #5b8cff); transition: width 200ms ease, margin 200ms ease, opacity 200ms ease, transform 200ms ease; }
.cr-pill-option[aria-pressed="true"] .cr-pill-check { width: 18px; margin-right: 0; opacity: 1; transform: scale(1); }
.cr-pill-option .cr-pill-lead { flex: none; min-width: 2.4em; color: var(--text-dim, #9aa3b2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cr-pill-option .cr-pill-main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cr-pill-option .cr-pill-sub { flex: none; color: var(--text-dim, #9aa3b2); font-size: 12px; white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { .cr-pill-option, .cr-pill-option .cr-pill-check { transition: none; } }

/* The list PillSelect (public/shared/pill-select.js) draws: pills stacked, room at the bottom for the scroll shadow. */
.cr-pill-list { display: flex; flex-direction: column; gap: 6px; padding: 2px 4px 16px 2px; margin: 4px 0 10px; }
.cr-pill-list .cr-pill-empty { margin: 8px 4px; }

/* ---- Disclosure (expandable region; public/shared/disclosure.js) ---- */
.cr-disclosure { margin-top: 14px; border: 1px solid var(--panel-border); border-radius: var(--radius, 8px); }
.cr-disclosure-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; padding: 12px 14px; background: none; border: 0; color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; border-radius: var(--radius, 8px); }
.cr-disclosure-head:hover { background: rgba(255, 255, 255, 0.04); }
.cr-disclosure-head:focus-visible { outline: 2px solid var(--accent, #5b8cff); outline-offset: -2px; }
.cr-disclosure-head .hint { font-weight: 400; margin-left: 6px; }
.cr-disclosure-chev { flex: none; width: 8px; height: 8px; border-right: 2px solid var(--text-dim); border-bottom: 2px solid var(--text-dim); transform: rotate(45deg); margin-right: 4px; transition: transform 200ms ease; }
.cr-disclosure-head[aria-expanded="true"] .cr-disclosure-chev { transform: rotate(-135deg); }
.cr-disclosure > .cr-collapse > .cr-collapse-inner > * { margin-left: 14px; margin-right: 14px; }
.cr-disclosure > .cr-collapse > .cr-collapse-inner > *:last-child { margin-bottom: 14px; }
@media (prefers-reduced-motion: reduce) { .cr-disclosure-chev { transition: none; } }
