/* ---------- Brand fonts (self-hosted, alpha.83) ---------- */
@font-face {
  font-family: "Manrope";
  src: url("/admin/static/fonts/Manrope-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Manrope";
  src: url("/admin/static/fonts/Manrope-Bold.ttf") format("truetype");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Robout";
  src: url("/admin/static/fonts/Robout-Regular.woff") format("woff"),
       url("/admin/static/fonts/Robout-Regular.ttf") format("truetype");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Robout";
  src: url("/admin/static/fonts/Robout-Medium.woff") format("woff"),
       url("/admin/static/fonts/Robout-Medium.ttf") format("truetype");
  font-weight: 500; font-style: normal; font-display: swap;
}

/*
 * AgentCube admin shell — minimal hand-rolled CSS.
 *
 * The S3 prompt called for "Pico CSS, bundled locally as a static asset
 * (no CDN)". We considered vendoring Pico but went with a focused
 * stylesheet that covers the appliance-style admin needs (nav, status
 * header, cards, forms) without pulling in a third-party dependency
 * we'd then have to keep current. The "no build pipeline, no CDN"
 * principle from spec §13.4 is preserved; the Pico-specific aesthetic
 * is approximated by sensible defaults below.
 */

:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-border: #e1e4e8;
  --color-text: #1f2328;
  --color-text-muted: #57606a;
  --color-accent: #1B4D3E;
  --color-accent-hover: #143829;
  --color-success: #1f883d;
  --color-warning: #bf8700;
  --color-danger: #cf222e;
  --color-nav-bg: #1f2328;
  --color-nav-text: #f7f8fa;
  --color-nav-active: #1B4D3E;
  --shadow-card: 0 1px 2px rgba(31, 35, 40, 0.08);
  --radius: 6px;
  --max-width: 80rem;
  --calendar-icon-filter: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

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

h1, h2, h3, h4 { margin: 0 0 0.5rem; font-weight: 600; font-family: "Robout", "Manrope", sans-serif; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.95rem; }
p { margin: 0 0 0.75rem; }

/* ---------- Layout ---------- */

.shell {
  display: grid;
  grid-template-columns: 14rem 1fr;
  grid-template-rows: 3rem 1fr auto;
  grid-template-areas:
    "header header"
    "nav    main"
    "nav    footer";
  min-height: 100vh;
}

.shell-header {
  grid-area: header;
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  gap: 1rem;
  /* alpha.85: sticky chrome. Header pins to viewport top as body scrolls;
     z-index keeps it above content. Nav uses sticky too (see .shell-nav). */
  position: sticky;
  top: 0;
  z-index: 20;
}
.shell-header .brand-logo {
  /* 2.4rem ≈ 80% of the 3rem header — confident brand presence at the
     upper end of best-practice band (Stripe 62%, Linear 70%, Notion 75%,
     Cloudflare 80%). alpha.83 shipped 1.75rem (undersized); alpha.84
     bumped to 2.1rem (balanced); alpha.85 to 2.4rem on UAT feedback. */
  height: 2.4rem;
  width: auto;
  flex: 0 0 auto;
}
.shell-header .brand-logo + .status { margin-left: auto; }
.shell-header .status { font-size: 0.8rem; font-weight: 500; }
.shell-header .status .dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.4rem;
  vertical-align: middle;
  background: var(--color-success);
}
.shell-header .status.degraded .dot { background: var(--color-warning); }
.shell-header .status.unhealthy .dot { background: var(--color-danger); }
.shell-header .version {
  font-size: 0.75rem;
  font-weight: 400;
  color: rgba(247, 248, 250, 0.6);
}

.shell-nav {
  grid-area: nav;
  background: var(--color-nav-bg);
  color: var(--color-nav-text);
  padding: 1rem 0;
  /* alpha.85: sticky left nav. Top offset matches the header's 3rem so the
     nav pins right below the sticky header. max-height + overflow lets the
     nav scroll independently if it ever outgrows the viewport. align-self:
     start is required for sticky inside a grid track — without it the grid
     stretches the nav to fill its row, defeating sticky's anchor behavior. */
  position: sticky;
  top: 3rem;
  align-self: start;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
}
.shell-nav ul { list-style: none; padding: 0; margin: 0; }
.shell-nav a {
  display: block;
  padding: 0.5rem 1.25rem;
  color: var(--color-nav-text);
  font-size: 0.92rem;
}
.shell-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  text-decoration: none;
}
.shell-nav a.active {
  background: rgba(27, 77, 62, 0.22);
  border-left: 3px solid var(--color-nav-active);
  padding-left: calc(1.25rem - 3px);
}
:root[data-theme="dark"] .shell-nav a.active {
  background: rgba(174, 223, 51, 0.18);
}
.shell-nav .nav-section {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(247, 248, 250, 0.4);
  padding: 1rem 1.25rem 0.25rem;
}

.shell-main {
  grid-area: main;
  padding: 1.5rem 2rem;
  max-width: var(--max-width);
}

.shell-footer {
  grid-area: footer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 2rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
}
.shell-footer form { display: inline; }
.shell-footer button {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.shell-footer button:hover { background: var(--color-bg); }

/* ---------- Cards / dashboard ---------- */

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(20rem, 1fr));
  gap: 1rem;
}
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow-card);
}
.card h3 {
  margin: 0 0 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.card .status-icon {
  font-size: 1rem;
  line-height: 1;
}
.card.ok .status-icon { color: var(--color-success); }
.card.warn .status-icon { color: var(--color-warning); }
.card.bad .status-icon { color: var(--color-danger); }
.card dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.25rem 0.75rem;
  margin: 0.5rem 0 0;
  font-size: 0.88rem;
}
.card dt { color: var(--color-text-muted); }
.card dd { margin: 0; word-break: break-word; }

/* ---------- Tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.9rem;
}
th, td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
}
th {
  background: var(--color-bg);
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(27, 77, 62, 0.05); }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}
.badge.active { background: #dafbe1; border-color: #2da44e; color: #1a7f37; }
.badge.disabled { background: #fff8c5; border-color: #d4a72c; color: #7d4e00; }
.badge.removed { background: #ffebe9; border-color: #ff8182; color: #82071e; }
.badge.source-env-var { background: #ddf4ff; border-color: #54aeff; color: #0550ae; }
.badge.source-db { background: #fbefff; border-color: #c297ff; color: #6639ba; }
.badge.na { background: var(--color-bg); border-color: var(--color-border); color: var(--color-text-muted, #57606a); }

/* Default POV values (#1158) — rows whose default is actually in use.
   "Which defaults are live right now" is the question that page exists to
   answer, and reading a status word per row does not answer it at a glance.
   Left rule + tint carries it peripherally; the status badge still states it
   explicitly, so the cue is redundant rather than load-bearing on color
   alone. */
/* Row actions. "Use" / "Don't use" are reversible status toggles; "Remove"
   deletes admin-authored config and is not their peer. Rendering all three as
   equal-weight buttons put an irreversible delete one misclick away from a
   toggle, so Remove is demoted to a subordinate link.
   The toggle cells are FIXED width with an empty placeholder when an action
   doesn't apply, so a row offering one toggle occupies the same shape as a row
   offering two — otherwise proposed rows (both toggles) wrapped while
   accepted/ignored rows (one) did not. */
/* Default POV values (#1158) — rows whose default is in use.
   Everything else on that page reuses the shared components (page-header,
   table.resizable, row-actions, status-active); this is the one addition,
   because no existing page needed to mark a row as live. Cells rather than
   the row: under border-collapse a row background is unreliable. */
tr.pov-live > td { background: rgba(31, 136, 61, 0.08); }
tr.pov-live > td:first-child { border-left: 3px solid var(--color-success); }
:root[data-theme="dark"] tr.pov-live > td { background: rgba(63, 185, 80, 0.13); }
:root[data-theme="dark"] tr.pov-live > td:first-child { border-left-color: #3fb950; }

/* ---------- Forms ---------- */

form.stacked {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  max-width: 36rem;
}
label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.88rem;
  font-weight: 500;
}
input[type="text"],
input[type="password"],
input[type="url"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.92rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -1px;
  border-color: var(--color-accent);
}
.help { font-size: 0.8rem; color: var(--color-text-muted); margin: 0.25rem 0 0; }

button.primary, .button.primary {
  background: var(--color-accent);
  color: #fff;
  border: 1px solid var(--color-accent);
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 500;
}
button.primary:hover { background: var(--color-accent-hover); }

button.secondary, .button.secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
button.secondary:hover { background: var(--color-bg); }

button.danger, .button.danger {
  background: var(--color-surface);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}
button.danger:hover { background: var(--color-danger); color: #fff; }

.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.92rem;
}
.banner.success { background: #dafbe1; border: 1px solid #2da44e; color: #1a7f37; }
.banner.error { background: #ffebe9; border: 1px solid #ff8182; color: #82071e; }
.banner.info { background: #ddf4ff; border: 1px solid #54aeff; color: #0550ae; }

.hidden { display: none !important; }
.muted { color: var(--color-text-muted); }
/* #1172 — admin-suppressed (tier, term) row, shown only when "show hidden
   terms" is checked. Dimmed, not hidden — distinct from .hidden above. */
.term-hidden-row { opacity: 0.55; }
.row-actions { display: flex; gap: 0.5rem; }
.row-actions form { display: inline; margin: 0; }
.row-actions.detail-actions { margin-top: 1rem; }
.code, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Detail-page meta dl: compact key/value grid. */
.detail-meta dl.detail-grid {
  display: grid;
  grid-template-columns: 11rem 1fr;
  gap: 0.4rem 1rem;
  margin: 0 0 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.detail-meta dt { color: var(--color-text-muted); font-size: 0.85rem; }
.detail-meta dd { margin: 0; word-break: break-word; }

/* Mapping table tightening + binding badge. */
.mapping-table .badge.binding {
  background: #fbefff;
  border-color: #c297ff;
  color: #6639ba;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.mapping-table .badge.binding[class*="inactive"] {
  background: var(--color-bg);
  border-color: var(--color-border);
  color: var(--color-text-muted);
}
.mapping-table .cell-description {
  max-width: 24rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

/* User-resizable table columns — opt-in via `<table class="resizable">`.
   The script (admin.js::bindResizableTables) captures each <th>'s initial
   pixel width, freezes the layout to `fixed`, and attaches an edge-grab
   handle on the right side of each header cell. Cells truncate with
   ellipsis when narrowed; widening re-reveals. Window resize doesn't
   reflow because widths are now pixel-pinned — refresh to re-capture. */
table.resizable[data-resizable-ready] {
  table-layout: fixed;
  width: 100%;
}
table.resizable[data-resizable-ready] th {
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
table.resizable[data-resizable-ready] td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Action cells must let their button row wrap onto a second line when
   the column is narrow — otherwise buttons get clipped silently by
   overflow:hidden and the user can't reach them at all. */
table.resizable[data-resizable-ready] td:has(.row-actions) {
  overflow: visible;
  white-space: normal;
}
.row-actions { flex-wrap: wrap; row-gap: 0.4rem; }
/* Slightly more compact buttons inside action cells so 3 fit in one row. */
.row-actions button,
.row-actions .button {
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}
.col-resize-handle {
  position: absolute;
  top: 0;
  right: 0;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  user-select: none;
  /* Transparent by default; visible accent on hover and during drag so
     the affordance shows up like Excel. */
  background: transparent;
  transition: background-color 80ms ease;
}
.col-resize-handle:hover,
.col-resize-handle.dragging {
  background-color: var(--color-link, #4a9eff);
}

/* Inline binding editor inside <details>. */
details.binding-editor summary { cursor: pointer; list-style: none; display: inline-block; }
details.binding-editor summary::-webkit-details-marker { display: none; }
/* #122 — once the form is open the summary is a redundant primary-styled
   button visually identical to the form's submit. Hiding it eliminates
   the dead "Bind"/"Edit" click that silently collapses the panel. The
   form's submit + Unbind buttons stay; implicit cancel = navigate away. */
details.binding-editor[open] > summary { display: none; }
details.binding-editor[open] {
  display: block;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
}
form.inline-form { margin: 0; max-width: 30rem; }
form.inline-form label { font-size: 0.85rem; }
form.inline-form textarea { font-family: inherit; font-size: 0.9rem; }

/* Listing toggle row. */
.listing-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
}
.listing-controls .toggle { color: var(--color-text-muted); }
.listing-controls .toggle a { font-weight: 500; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; }
.page-actions { display: flex; gap: 0.5rem; }

/* ---------- Admin modal (native <dialog>) ---------- */

dialog.admin-modal {
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  /* Use background-color (not the `background` shorthand) and explicit
     color so we beat the UA stylesheet's `background-color: Canvas` /
     `color: CanvasText` defaults on <dialog>. Canvas is a CSS system
     color that ignores our custom theme cascade in Chromium, which is
     why the dialog rendered light-on-dark before. */
  background-color: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 8px 32px rgba(31, 35, 40, 0.18);
  max-width: min(40rem, 92vw);
  width: 100%;
  max-height: 88vh;
  /* IMPORTANT: do NOT set `display` here unconditionally. The UA
     stylesheet sets `display: none` on closed dialogs; overriding it
     would make every dialog render inline in its DOM position from
     page load and stay visible after .close() (since the [open]
     attribute is removed but display stays). Scope display to [open]
     below so the standard show/hide behavior keeps working. */
  flex-direction: column;
}
dialog.admin-modal[open] {
  display: flex;
}
dialog.admin-modal.wide {
  max-width: min(56rem, 94vw);
}
dialog.admin-modal::backdrop {
  background-color: rgba(0, 0, 0, 0.4);
}
.admin-modal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.admin-modal-header h3 { margin: 0; flex: 1; font-size: 1rem; }
button.admin-modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-text-muted);
  padding: 0.25rem 0.4rem;
  border-radius: var(--radius);
}
button.admin-modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}
.admin-modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}
.admin-modal-body form.stacked {
  border: none;
  padding: 0;
  max-width: none;
  background: transparent;
  box-shadow: none;
}

/* Audit event detail rendered inside the modal. */
dl.event-detail {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.3rem 1rem;
  font-size: 0.88rem;
  margin: 0;
}
dl.event-detail dt {
  color: var(--color-text-muted);
  font-weight: 500;
  padding-top: 0.1rem;
  white-space: nowrap;
}
dl.event-detail dd {
  margin: 0;
  word-break: break-all;
}
dl.event-detail pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.82rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  max-height: 18rem;
  overflow-y: auto;
}

/* ---------- Mobile ---------- */

@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "nav"
      "main"
      "footer";
  }
  .shell-nav {
    padding: 0.5rem 0;
    /* alpha.85: on mobile the nav flows below the header as horizontal pills,
       so the desktop sticky-pin behavior doesn't apply. Reset to static so
       the nav scrolls with the page like content. */
    position: static;
    max-height: none;
    overflow: visible;
  }
  .shell-nav ul { display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0 0.5rem; }
  .shell-nav a { padding: 0.4rem 0.75rem; }
  .shell-nav .nav-section { display: none; }
  .shell-main { padding: 1rem; }
}

/* ---------- Dark mode (#100) ---------- */
/*
 * Theme is controlled by `data-theme="dark"` on <html>, set by the inline
 * boot script in base.html before paint to avoid a light-mode flash. The
 * preference is persisted in localStorage; first-load fallback is the
 * browser's `prefers-color-scheme: dark` media query. The toggle button
 * in the shell header writes the preference and flips the attribute.
 */

:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #0d1117;
  --color-surface: #161b22;
  --color-border: #30363d;
  --color-text: #e6edf3;
  --color-text-muted: #8b949e;
  --color-accent: #AEDF33;
  --color-accent-hover: #bce854;
  --color-success: #3fb950;
  --color-warning: #d29922;
  --color-danger: #f85149;
  --color-nav-bg: #010409;
  --color-nav-text: #e6edf3;
  --color-nav-active: #AEDF33;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Form fields need an explicit dark surface — browsers default to white. */
/* color-scheme: dark on the input itself (not :root) is what tells the browser */
/* to render native widgets (calendar icon, spinner) in a light-on-dark style.  */
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  color-scheme: dark;
}

/* #101 — Chromium ignores ancestor-scoped pseudo-element rules; route through a  */
/* CSS variable instead so the pseudo-element rule is a simple unconditional     */
/* selector that the browser can't skip. brightness(0) normalises the icon to    */
/* pure black first, then invert(1) flips it to white.                           */
:root[data-theme="dark"] { --calendar-icon-filter: brightness(0) invert(1); }
input::-webkit-calendar-picker-indicator { filter: var(--calendar-icon-filter); }

:root[data-theme="dark"] code,
:root[data-theme="dark"] pre {
  background: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}

/* #101 — sign-out button inherits browser defaults without explicit colors in dark mode. */
:root[data-theme="dark"] .shell-footer button {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
:root[data-theme="dark"] .shell-footer button:hover { background: var(--color-bg); }

/* Dark mode: lime accent needs dark foreground text for contrast on primary buttons. */
:root[data-theme="dark"] button.primary,
:root[data-theme="dark"] .button.primary {
  color: #0d1117;
}

/* Force dark surface colors on the dialog explicitly — `color-scheme: dark`
   on the dialog itself tells Chromium to interpret system colors (Canvas,
   CanvasText) in dark variants, so any UA-default that slips through still
   reads as dark. Without this the modal renders white-on-dark in some
   Chromium builds even with the CSS-variable override. */
:root[data-theme="dark"] dialog.admin-modal {
  background-color: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  color-scheme: dark;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
}
:root[data-theme="dark"] dialog.admin-modal::backdrop {
  background-color: rgba(0, 0, 0, 0.55);
}

/* Theme toggle button in the header — borderless icon button. */
.theme-toggle {
  margin-left: 0.5rem;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--color-nav-text);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1;
}
.theme-toggle:hover {
  border-color: rgba(255, 255, 255, 0.45);
}

/* 1B-S3 (#203) — discovery review surface. */
.filters {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  /* Use background-color (longhand, not the `background` shorthand)
     and a CSS variable that has a dark-mode override — same pattern
     the modals + dashboard cards use. The light/dark values get
     applied via the :root[data-theme="dark"] block below. */
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.filters label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.25rem;
  color: var(--color-text);
}
.filters select,
.filters input[type=text] {
  min-width: 14rem;
}

.admin-modal-wide {
  max-width: 64rem;
  width: 92vw;
}
.admin-modal-wide .admin-modal-body {
  max-height: 70vh;
  overflow-y: auto;
}
dl.kv {
  display: grid;
  grid-template-columns: 9rem 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 1rem;
}
dl.kv dt { color: var(--color-muted); font-size: 0.85rem; }
dl.kv dd { margin: 0; }
pre.payload {
  background: var(--color-code-bg, #f0f1f3);
  color: var(--color-code-fg, inherit);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-size: 0.8rem;
  max-height: 28rem;
}
.action-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1rem;
}
@media (max-width: 720px) {
  .action-pair { grid-template-columns: 1fr; }
}

.card-mini-table {
  width: 100%;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  border-collapse: collapse;
}
.card-mini-table th,
.card-mini-table td {
  padding: 0.15rem 0.4rem;
  text-align: right;
}
.card-mini-table th:first-child,
.card-mini-table td:first-child { text-align: left; }
.card-mini-table th {
  color: var(--color-muted);
  font-weight: 500;
  border-bottom: 1px solid var(--color-border, #ddd);
}

/* ---------- Resolution-trace tier chart (alpha.82, #313) ---------- */

.tier-chart {
  width: 100%;
  height: auto;
  display: block;
  margin: 0.5rem 0;
  overflow: visible;
}

/* Friendly tier label — native browser title tooltip for engineering ID */
.tier-label {
  border-bottom: 1px dotted var(--color-text-muted);
  cursor: help;
}

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.pager { display: flex; gap: 0.5rem; }

/* ── Multi-select checkboxes (1B-S3.1 #214) ────────────────────────── */

.col-check {
  width: 2.5rem;
  text-align: center;
  padding: 0 0.25rem;
}

/* Normalise checkbox appearance across browsers */
input[type="checkbox"].obs-row-check,
#obs-select-all {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: var(--color-primary, #2563eb);
  vertical-align: middle;
}

/* Highlight selected rows */
tr.obs-selected {
  background-color: var(--color-surface-alt, #f0f4ff);
}
:root[data-theme="dark"] tr.obs-selected {
  background-color: rgba(99, 102, 241, 0.15);
}

/* ── Sticky bulk action bar ─────────────────────────────────────────── */

.bulk-action-bar {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  border-radius: 8px;
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  font-size: 0.875rem;
  z-index: 200;
  white-space: nowrap;
}
:root[data-theme="dark"] .bulk-action-bar {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

.bulk-action-bar[hidden] { display: none; }

.bulk-count { font-weight: 600; }

.bulk-select-filter-link {
  color: var(--color-primary, #2563eb);
  text-decoration: underline;
  cursor: pointer;
}

.bulk-actions { display: flex; gap: 0.5rem; }

/* compact button sizing inside the action bar */
.bulk-action-bar .primary,
.bulk-action-bar .danger,
.bulk-action-bar .secondary {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

/* ── Bulk result failure list ───────────────────────────────────────── */

.bulk-failure-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 20rem;
  overflow-y: auto;
}

.bulk-failure-list li {
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background-color: var(--color-surface-alt, #f5f6f8);
  font-size: 0.85rem;
}
:root[data-theme="dark"] .bulk-failure-list li {
  background-color: var(--color-surface);
}

/* ── Column sort indicators ─────────────────────────────────────────── */

table.resizable thead th[style*="cursor: pointer"],
table.resizable thead th[title="Click to sort"] {
  user-select: none;
}

table.resizable thead th[data-sort-dir]::after {
  content: " ▲";
  font-size: 0.7em;
  opacity: 0.7;
}

table.resizable thead th[data-sort-dir="desc"]::after {
  content: " ▼";
}

table.resizable thead th:hover {
  background-color: var(--color-surface-alt, rgba(0,0,0,0.04));
}

/* Server-sorted tables render header text inside <a class="sort-link">.
   Style as inline header text — no block-level expansion, so the th's
   overflow:hidden + text-overflow:ellipsis doesn't truncate "Ring" into
   "..." because of a 100%-wide link inside a narrow column. */
table.resizable thead th .sort-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
table.resizable thead th .sort-link:hover {
  text-decoration: underline;
}

/* ── Pattern library editor (B2 #224) ───────────────────────────── */

.status-active {
  color: var(--color-success, #157f3f);
  font-weight: 600;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pattern-form fieldset {
  border: 1px solid var(--color-border, #ddd);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin: 0;
}
.pattern-form fieldset legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.4rem;
}
.pattern-form-error[hidden] { display: none; }
.pattern-form-error {
  color: var(--color-danger, #b00020);
  background: var(--color-surface, transparent);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-danger, #b00020);
  margin-top: 0.5rem;
  white-space: pre-wrap;
}
.pattern-json-preview {
  max-height: 12rem;
  margin: 0.25rem 0;
}
/* #235 — "Target table (derived from ring)" is a display-only input.
   Use --color-bg so it reads as slightly off-surface in light mode and
   stays dark in dark mode.  The dark-mode override is here explicitly
   so it wins over any UA stylesheet that might default readonly inputs
   to a light background.  cursor:default is set inline on the element;
   this rule only handles colour. */
.pf-target-table {
  background-color: var(--color-bg);
}
:root[data-theme="dark"] .pf-target-table {
  background-color: var(--color-bg);
  color: var(--color-text);
  border-color: var(--color-border);
}
