/* Argus V3 design tokens + components.
   Loaded on every v3 page. No external deps. */

:root {
  --bg-root:        #0a0f1e;
  --bg-surface:     #111827;
  --bg-surface-alt: #1a2332;
  --bg-input:       #0d1424;
  --border:         #1e2d4a;
  --border-light:   #2a3d5e;
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-dim:       #64748b;
  --blue:           #3b82f6;
  --blue-dim:       #2563eb;
  --blue-bg:        rgba(59,130,246,0.13);
  --amber:          #f59e0b;
  --amber-bg:       rgba(245,158,11,0.13);
  --green:          #22c55e;
  --green-bg:       rgba(34,197,94,0.13);
  --red:            #ef4444;
  --red-bg:         rgba(239,68,68,0.13);
  --red-critical:   #ff4444;
  --red-critical-bg:rgba(255,68,68,0.20);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
/* App-shell layout: html and body never scroll. The sidebar has its own
   overflow-y, and .v3-content has its own overflow-y — so switching tabs
   on a page (Internal vs Live) only changes the INNER scrollbar, never
   shifts the page-title / tab bar / sidebar. The "dance" was caused by
   the body scrollbar appearing/disappearing on tab switch; pinning the
   chrome above the scroll area eliminates that class of bug entirely. */
html, body { height: 100%; overflow: hidden; background: var(--bg-root); color: var(--text-primary); font-family: Inter, -apple-system, system-ui, sans-serif; font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
/* Layout containment on each tab panel so switching one doesn't trigger
   reflow above it. */
[data-tabpanel] { contain: layout style; }
a { color: var(--blue); text-decoration: none; }
a:hover { color: #5fa1ff; }
button { font-family: inherit; cursor: pointer; border: 0; }

/* ─── Shell ─── */
:root { --v3-sidebar-w: 220px; }
.v3-app { display: flex; height: 100%; }
.v3-sidebar {
  width: var(--v3-sidebar-w); flex-shrink: 0; background: var(--bg-surface); border-right: 1px solid var(--border);
  height: 100%;
  overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
  position: relative;
  /* Thin custom scrollbar so the sidebar doesn't get the chunky default
     bar (matches the .v3-content treatment). */
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.v3-sidebar::-webkit-scrollbar       { width: 6px; height: 6px; }
.v3-sidebar::-webkit-scrollbar-track { background: transparent; }
.v3-sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.v3-sidebar::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
/* Right-edge drag handle. Sits flush inside the sidebar so it doesn't
   trigger horizontal overflow. Becomes blue on hover for affordance. */
.v3-sidebar-resizer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 4px; cursor: col-resize; z-index: 50;
  background: transparent; transition: background 0.15s;
}
.v3-sidebar-resizer:hover { background: var(--blue); }

.v3-sidebar-brand {
  display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.v3-sidebar-brand .logo {
  width: 32px; height: 32px; background: var(--blue); border-radius: 6px;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 19px;
}
.v3-sidebar-brand .title { color: var(--text-primary); font-size: 16px; font-weight: 700; line-height: 1.1; }
.v3-sidebar-brand .subtitle { color: var(--text-dim); font-size: 10px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin-top: 2px; }

.v3-sidebar-clientpicker { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.v3-sidebar-clientpicker-label {
  color: var(--text-dim); font-size: 11px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px;
}
.v3-sidebar-clientpicker select {
  width: 100%; background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text-primary); font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 10px; border-radius: 6px; cursor: pointer;
}
.v3-sidebar-clientpicker select:hover { border-color: var(--blue); }
.v3-sidebar-clientpicker select:focus { outline: none; border-color: var(--blue); }

.v3-nav { padding: 8px 6px; display: flex; flex-direction: column; gap: 1px; flex: 1; }

/* Edit-menu toggle bar (above the tree). */
.v3-nav-edit-bar { padding: 6px 12px 4px; }
.v3-nav-edit-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
  padding: 5px 10px; border-radius: 4px; font-size: 12px; font-weight: 600;
  cursor: pointer; width: 100%; font-family: inherit;
}
.v3-nav-edit-btn:hover { color: var(--text-primary); border-color: var(--border-light); }
.v3-nav-edit-btn .when-editing { display: none; }
.v3-sidebar.editing .v3-nav-edit-btn .when-idle { display: none; }
.v3-sidebar.editing .v3-nav-edit-btn .when-editing { display: inline; }
.v3-sidebar.editing .v3-nav-edit-btn { border-color: var(--blue); color: var(--blue); background: var(--blue-bg); }

/* Recursive tree. Each <ul.v3-nav-list> is a Sortable container; nested
   <li.v3-nav-item> rows reveal their drag/rename/delete chrome only in
   edit mode (otherwise it's invisible). Each level adds 12px of left
   indent via .v3-nav-list[data-nav-level] selectors. */
.v3-nav-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.v3-nav-list[data-nav-level="1"] { padding-left: 12px; border-left: 1px solid var(--border); margin-left: 18px; }
.v3-nav-list[data-nav-level="2"] { padding-left: 12px; border-left: 1px solid var(--border); margin-left: 6px; }
.v3-nav-list[data-nav-level="3"] { padding-left: 12px; border-left: 1px solid var(--border); margin-left: 6px; }

.v3-nav-item { position: relative; }
.v3-nav-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; border-radius: 4px;
  position: relative;
}
.v3-nav-row:hover { background: var(--bg-surface-alt); }
.v3-nav-row.active { background: var(--blue-bg); }
.v3-nav-row.active .v3-nav-link { color: var(--blue); font-weight: 600; }
.v3-nav-link {
  flex: 1; min-width: 0;
  color: var(--text-secondary); text-decoration: none;
  font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v3-nav-row:hover .v3-nav-link { color: var(--text-primary); }

/* Per-branch collapse toggle. Sits on the LEFT of every row, aligned
   horizontally with the children's down-line so the line visually
   emerges from beneath it. Items without children render the toggle
   with visibility:hidden — same size, no glyph — so labels align
   across siblings whether or not they have children. */
.v3-nav-tree-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0;
  color: var(--text-secondary); cursor: pointer;
  width: 16px; height: 16px;
  font-size: 14px; font-weight: 700; line-height: 1;
  border-radius: 3px;
  font-family: inherit;
  flex-shrink: 0;
  margin-right: 2px;
  visibility: hidden; /* leaves: spacer only */
}
.v3-nav-tree-toggle::before { content: '–'; }
.v3-nav-item.has-children > .v3-nav-row > .v3-nav-tree-toggle {
  visibility: visible;
  border: 1px solid var(--border);
}
.v3-nav-item.has-children.collapsed > .v3-nav-row > .v3-nav-tree-toggle::before { content: '+'; }
.v3-nav-tree-toggle:hover { color: var(--text-primary); border-color: var(--border-light); }
/* Hide the children <ul> when this branch is collapsed. */
.v3-nav-item.collapsed > .v3-nav-list { display: none; }
.v3-nav .badge {
  min-width: 18px; padding: 1px 6px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center;
}

/* Edit-mode chrome: handle / rename / delete buttons. Hidden by default;
   revealed when .editing is on the sidebar. */
.v3-nav-handle, .v3-nav-rename, .v3-nav-delete {
  display: none; background: transparent; border: 0;
  color: var(--text-dim); cursor: pointer;
  padding: 0 4px; font-size: 13px; line-height: 1;
}
.v3-nav-handle { cursor: grab; font-size: 14px; }
.v3-sidebar.editing .v3-nav-handle,
.v3-sidebar.editing .v3-nav-rename,
.v3-sidebar.editing .v3-nav-delete { display: inline-flex; }
.v3-sidebar.editing .v3-nav-rename:hover,
.v3-sidebar.editing .v3-nav-handle:hover { color: var(--text-primary); }
.v3-sidebar.editing .v3-nav-delete:hover { color: var(--red); }

.v3-nav-link.renaming {
  background: var(--bg-input); outline: 2px solid var(--blue);
  border-radius: 3px; padding: 1px 6px; margin: -1px -6px;
  cursor: text; color: var(--text-primary);
}

/* Sortable visual states (mirrors .v3-nav-chosen used elsewhere). */
.v3-nav-chosen { background: var(--blue-bg) !important; box-shadow: inset 0 0 0 1px var(--blue); }
.v3-nav-ghost  { opacity: 0.35; }

/* "+ Add item" button shown at the end of each .v3-nav-list in edit mode. */
.v3-nav-add-wrap { padding: 4px 0 4px 4px; }
.v3-nav-add {
  background: transparent; border: 1px dashed var(--border-light);
  color: var(--text-dim); font-size: 12px; padding: 4px 8px;
  border-radius: 3px; cursor: pointer; width: 100%; text-align: left;
  font-family: inherit;
}
.v3-nav-add:hover { color: var(--blue); border-color: var(--blue); }

/* ─── Sidebar nav groups (collapsible sub-menus) ─────────────────── */
.v3-nav-group { display: flex; flex-direction: column; }
.v3-nav-group-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 12px; border-radius: 6px; color: var(--text-secondary);
  font-size: 14px; font-weight: 500; text-decoration: none;
}
.v3-nav-group-head:hover { background: var(--bg-surface-alt); color: var(--text-primary); }
.v3-nav-group-head.active { background: var(--blue-bg); color: var(--blue); font-weight: 600; }
.v3-nav-toggle {
  background: transparent; border: 0; color: inherit;
  padding: 0 4px; font-size: 11px; line-height: 1; cursor: pointer;
  opacity: 0.55; transition: transform 0.15s, opacity 0.15s;
}
.v3-nav-toggle:hover { opacity: 1; }
.v3-nav-group.collapsed .v3-nav-toggle { transform: rotate(-90deg); }
.v3-nav-children {
  display: flex; flex-direction: column;
  padding: 2px 0 4px 14px;
  border-left: 1px solid var(--border);
  margin: 2px 0 4px 18px;
  overflow: hidden;
}
.v3-nav-group.collapsed .v3-nav-children { display: none; }
.v3-nav-child {
  display: block; padding: 6px 12px;
  color: var(--text-dim); font-size: 13px; font-weight: 500;
  text-decoration: none; border-radius: 4px;
}
.v3-nav-child:hover { color: var(--text-primary); background: var(--bg-surface-alt); }
.v3-nav-child.active { color: var(--blue); font-weight: 600; background: var(--blue-bg); }

/* Customizable-nav states (admin only). Sortable.js sets .v3-nav-chosen
   on the picked-up item during long-press; .v3-nav-ghost on the
   placeholder slot during drag. .editing on the .v3-nav signals that
   any nav item interaction should NOT navigate. The contenteditable
   label gets a subtle box so the rename affordance is visible. */
.v3-nav-chosen { background: var(--blue-bg) !important; box-shadow: inset 0 0 0 1px var(--blue); cursor: grabbing; }
.v3-nav-ghost  { opacity: 0.35; }
.v3-nav.editing a { cursor: grabbing; }
.v3-nav-label.editing {
  background: var(--bg-input);
  outline: 1px solid var(--blue);
  border-radius: 3px;
  padding: 1px 5px;
  margin: -1px -5px;
  cursor: text;
  min-width: 60px;
  display: inline-block;
}
.v3-nav-label.editing:focus { outline: 2px solid var(--blue); }
/* Hint that long-press unlocks customization, only on admin nav. */
.v3-nav[data-nav-customizable="1"] a { user-select: none; }

/* margin-top: auto pins the footer to the bottom of the sidebar (the
   sidebar is flex-column). Without this, the footer floated up below
   the nav and could scroll out of view when the sidebar overflowed —
   that's why the sign-out button "wasn't there" even though the EJS
   rendered it. */
.v3-sidebar-footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--border); color: var(--text-dim); font-size: 12px; }
.v3-sidebar-footer .clients-summary { color: var(--text-secondary); }
.v3-sidebar-footer .clients-summary .active-count { color: var(--green); font-weight: 600; }

/* Identity block above the sign-out button. Avatar mirrors the brand
   logo at the top so the sidebar reads as "this app, signed in as you". */
.v3-sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0 10px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.v3-sidebar-user-avatar {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--blue); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.v3-sidebar-user-meta { min-width: 0; }
.v3-sidebar-user-meta .name { color: var(--text-primary); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v3-sidebar-user-meta .role { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }

.v3-sidebar-logout {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px; border-radius: 6px;
  background: var(--bg-surface-alt); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 13px; font-weight: 600;
  text-decoration: none; transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.v3-sidebar-logout .icon { font-size: 14px; opacity: 0.85; }
.v3-sidebar-logout:hover { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.v3-sidebar-logout:hover .icon { opacity: 1; }

.v3-content {
  flex: 1; min-width: 0;
  /* The content area itself scrolls — body and html never do. This pins
     the sidebar and prevents tab switches from shifting page chrome.
     overflow-x: hidden is explicit because once overflow-y: auto is set,
     overflow-x defaults to "auto" too — that's what was producing the
     phantom horizontal scrollbar even on pages with no horizontal overflow.
     scrollbar-gutter dropped: stable was reserving a permanent right strip
     that read as an always-on scrollbar even when content fit. Custom
     thin-scrollbar styling below keeps the vertical bar subtle. */
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
}
.v3-content::-webkit-scrollbar        { width: 8px; height: 8px; }
.v3-content::-webkit-scrollbar-track  { background: transparent; }
.v3-content::-webkit-scrollbar-thumb  { background: var(--border-light); border-radius: 4px; }
.v3-content::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }
/* Page-shell: the header band (title + subtitle) sits flush against the
   sidebar with a full-width underline that lines up with the sidebar
   brand's border-bottom. Everything below the subtitle gets horizontal
   margin so panels read as inset cards instead of edge-to-edge slabs.
   No max-width on the wrapper itself — the line spans the full content
   column on any monitor width.
   Header-band height tuned to match .v3-sidebar-brand (~64px). */
.v3-content-inner { max-width: none; margin: 0; padding: 0 0 24px; width: 100%; }
.v3-content-inner > * { margin-left: 24px; margin-right: 24px; }
.v3-page-title {
  color: var(--text-primary); font-size: 21px; font-weight: 700;
  line-height: 1.2; margin: 0; padding: 12px 24px 2px;
}
.v3-page-sub {
  color: var(--text-secondary); font-size: 14px; line-height: 1.4;
  margin: 0; padding: 0 24px 12px;
  border-bottom: 1px solid var(--border);
}
.v3-content-inner > .v3-page-sub + * { margin-top: 18px; }

/* ─── Cards / panels ─── */
.v3-panel { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 18px; }
.v3-section-header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.v3-section-header h2 { color: var(--text-primary); font-size: 16px; font-weight: 700; flex: 1; min-width: 0; }
.v3-section-header .right { color: var(--text-secondary); font-size: 14px; flex: 0 0 auto; }
.v3-section-header:hover { background: var(--bg-surface-alt); }

/* Collapse indicator — typical minimize-icon convention: a dash (–)
   when the panel is expanded, a plus (+) when collapsed. Lives on
   the right side of the section header (auto margin pushes it past
   any .right metadata). State persisted per-page in localStorage by
   the inline script in _foot.ejs. The glyph is injected via ::before
   so click-strip regexes in _foot.ejs don't have to chase a moving
   character. */
.v3-chevron {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  color: var(--text-secondary);
  font-size: 16px; font-weight: 700;
  line-height: 1;
  margin-left: 4px;
  width: 18px; height: 18px;
  border: 1px solid transparent;
  border-radius: 3px;
}
.v3-chevron::before { content: '–'; }
.v3-panel.collapsed .v3-chevron::before { content: '+'; }
.v3-section-header:hover .v3-chevron { color: var(--text-primary); border-color: var(--border-light); }

/* Move up/down buttons in section headers — appear at far right next to chevron */
.v3-move-btn {
  flex: 0 0 auto;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); font-size: 11px;
  padding: 3px 7px; border-radius: 4px;
  cursor: pointer; line-height: 1;
}
.v3-move-btn:hover:not(:disabled) { color: var(--text-primary); border-color: var(--border-light); background: var(--bg-input); }
.v3-move-btn:disabled { opacity: 0.25; cursor: not-allowed; }
.v3-section-header:hover .v3-move-btn { color: var(--text-secondary); }
.v3-panel.collapsed .v3-section-header { border-bottom-color: transparent; }
.v3-panel.collapsed > *:not(.v3-section-header) { display: none !important; }
/* v52 follow-up: when collapsed, append a visible hint after the title so the
   panel isn't mysteriously empty. Chevron flip to + is too subtle on its own. */
.v3-panel.collapsed .v3-section-header h2::after {
  content: ' 4 collapsed (click to expand)';
  color: var(--text-dim);
  font-weight: 400;
  font-size: 12px;
  letter-spacing: 0;
  margin-left: 6px;
}
/* Make the chevron slightly larger + more prominent when collapsed too. */
.v3-panel.collapsed .v3-chevron { background: rgba(95,161,255,0.10); border-color: var(--blue); color: var(--blue); }

/* ─── Tabs ─── */
.v3-tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 18px; gap: 2px; }
.v3-tabs button {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  padding: 12px 16px; cursor: pointer; font: inherit; color: var(--text-secondary);
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600;
  transition: color 0.15s, border-color 0.15s;
}
.v3-tabs button:hover { color: var(--text-primary); }
.v3-tabs button.active { color: var(--text-primary); border-bottom-color: var(--blue); }
.v3-tabs button .v3-tab-count {
  background: var(--bg-surface-alt); padding: 2px 9px; border-radius: 11px;
  font-size: 12px; font-weight: 700; color: var(--text-secondary); min-width: 24px; text-align: center;
}
.v3-tabs button.active .v3-tab-count { background: var(--blue-bg); color: #5fa1ff; }
.v3-tabs button .v3-tab-count.hot { background: var(--amber-bg); color: var(--amber); }
.v3-tabs button .v3-tab-count.danger { background: var(--red-bg); color: var(--red); }
[data-tabpanel] { display: none; }
[data-tabpanel].active { display: block; }

/* ─── KPI cards ─── */
.v3-kpi-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 18px; }
.v3-kpi { flex: 1 1 220px; min-width: 200px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px 18px; }
.v3-kpi-label { color: var(--text-dim); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 8px; }
.v3-kpi-value { color: var(--text-primary); font-size: 27px; font-weight: 700; line-height: 1.1; }
.v3-kpi-value.hot { color: var(--amber); }
.v3-kpi-sub   { color: var(--text-secondary); font-size: 14px; margin-top: 6px; }

/* ─── Pills ─── */
.v3-pill { display: inline-block; padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; }
.v3-pill.active    { background: var(--green-bg); color: var(--green); }
.v3-pill.paused    { background: rgba(148,163,184,0.12); color: var(--text-secondary); }
.v3-pill.connected { background: var(--blue-bg); color: #5fa1ff; }
.v3-pill.partial   { background: var(--amber-bg); color: var(--amber); }
.v3-pill.disabled  { background: rgba(148,163,184,0.12); color: var(--text-dim); }
.v3-pill.critical  { background: var(--red-critical-bg); color: var(--red-critical); }
.v3-pill.error     { background: var(--red-bg); color: var(--red); }
.v3-pill.warning   { background: var(--amber-bg); color: var(--amber); }
.v3-pill.info      { background: var(--blue-bg); color: #5fa1ff; }
.v3-pill.pass      { background: var(--green-bg); color: var(--green); }

/* ─── Status dot ─── */
.v3-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; vertical-align: middle; }
.v3-dot.green  { background: var(--green); }
.v3-dot.amber  { background: var(--amber); }
.v3-dot.red    { background: var(--red); }
.v3-dot.gray   { background: var(--text-dim); }
.v3-dot.blue   { background: var(--blue); }

/* ─── Score bar ─── */
.v3-score { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.v3-score-track { flex: 1; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; min-width: 60px; }
.v3-score-fill { height: 100%; transition: width .2s ease; }
.v3-score-fill.green { background: var(--green); }
.v3-score-fill.amber { background: var(--amber); }
.v3-score-fill.red   { background: var(--red); }
.v3-score-num { color: var(--text-primary); font-size: 14px; font-weight: 600; min-width: 22px; text-align: right; }
.v3-score-na  { color: var(--text-dim); font-size: 14px; }

/* ─── Tables ─── */
.v3-table { width: 100%; border-collapse: collapse; }
.v3-table thead th {
  text-align: left; color: var(--text-dim); font-size: 11px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase; padding: 12px 18px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.v3-table thead th.right { text-align: right; }
.v3-table tbody td { padding: 14px 18px; border-bottom: 1px solid var(--border); color: var(--text-primary); font-size: 15px; vertical-align: middle; }
.v3-table tbody td.right { text-align: right; }
.v3-table tbody td.muted { color: var(--text-secondary); font-size: 14px; }
.v3-table tbody td.dim   { color: var(--text-dim); font-size: 13px; font-family: ui-monospace,Menlo,Consolas,monospace; }
.v3-table tbody td .name { color: var(--text-primary); font-size: 15px; font-weight: 600; }
.v3-table tbody td .domain { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.v3-table tbody tr.dimmed { opacity: 0.45; }
.v3-table tbody tr:hover { background: var(--bg-surface-alt); }
.v3-zero-active { color: var(--red); font-weight: 700; }
.v3-table-wrap { overflow-x: auto; }

/* ─── Pipeline (Command Center) ─── */
.v3-pipeline-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: stretch; padding: 18px; }
.v3-pipeline-stage { flex: 1 1 0; min-width: 130px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.v3-pipeline-stage .label { color: var(--text-secondary); font-size: 12px; font-weight: 700; letter-spacing: 0.8px; text-transform: uppercase; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.v3-pipeline-stage .count { color: var(--text-primary); font-size: 23px; font-weight: 700; }
.v3-pipeline-arrow { color: var(--text-dim); font-size: 19px; align-self: center; }

/* ─── Activity feed (Command Center / Agents) ─── */
.v3-activity-row {
  display: grid; grid-template-columns: 60px 130px 70px 1fr; align-items: center; gap: 12px;
  padding: 8px 18px; border-bottom: 1px solid var(--border);
}
.v3-activity-row .time { color: var(--text-dim); font-size: 12px; font-family: ui-monospace,Menlo,Consolas,monospace; }
.v3-activity-row .agent { color: var(--text-primary); font-size: 14px; font-weight: 600; }
.v3-activity-row .client { color: var(--text-secondary); font-size: 13px; }
.v3-activity-row .event { display: flex; align-items: center; gap: 8px; color: var(--text-primary); font-size: 14px; }

/* ─── Exception rows ─── */
.v3-exc-row {
  display: grid; grid-template-columns: 90px 130px 1fr 220px 50px;
  align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.v3-exc-row .client { color: var(--text-primary); font-size: 14px; font-weight: 600; }
.v3-exc-row .problem { color: var(--text-primary); font-size: 15px; font-weight: 600; }
.v3-exc-row .detail  { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }
.v3-exc-row .action  { color: var(--amber); font-size: 13px; font-weight: 600; text-align: right; }
.v3-exc-row .age     { color: var(--text-dim); font-size: 12px; text-align: right; }

.v3-exc-card { padding: 18px; }
.v3-exc-card .head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.v3-exc-card .head-left { display: flex; align-items: center; gap: 12px; }
.v3-exc-card .problem { color: var(--text-primary); font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.v3-exc-card .detail  { color: var(--text-secondary); font-size: 13px; margin-bottom: 14px; }
.v3-exc-card .footer  { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.v3-exc-card .recommended { color: var(--amber); font-size: 14px; }
.v3-exc-card .recommended .label { color: var(--text-dim); font-weight: 600; margin-right: 6px; }

/* ─── Buttons ─── */
.v3-btn {
  display: inline-block; padding: 8px 14px; border-radius: 6px; font-size: 14px; font-weight: 600;
  background: var(--blue); color: #fff; border: 0; cursor: pointer;
}
.v3-btn:hover { background: var(--blue-dim); }
.v3-btn.outline { background: transparent; border: 1px solid var(--blue); color: var(--blue); }
.v3-btn.outline:hover { background: var(--blue-bg); }
.v3-btn.ghost { background: var(--bg-surface-alt); color: var(--text-secondary); }
.v3-btn.ghost:hover { color: var(--text-primary); }
.v3-btn.success { background: var(--green); color: #052; }
.v3-btn.sm { padding: 5px 10px; font-size: 13px; }
/* v51 #4 + v52 follow-up: stable width across the whole Retry/Manual/Dead
   trio so all three buttons align identically — and the trio is the same
   width regardless of whether Manual is a <details>/<summary> popover
   (forum rows) or a plain <form>/<button> resolve (QA rows). */
form[data-forum-row-retry] button.v3-btn.sm,
form[data-qa-retry] button.v3-btn.sm,
form[data-todo-resolve-async] button.v3-btn.sm,
details > summary.v3-btn.sm,
form[action$="/mark-dead"] button.v3-btn.sm,
form[action$="/discard"] button.v3-btn.sm { min-width: 92px; text-align: center; box-sizing: border-box; }
.v3-btn.dashed { background: transparent; border: 1.5px dashed var(--blue); color: var(--blue); padding: 8px 16px; }

/* ─── Client cards (Clients page) ─── */
.v3-client-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; overflow: hidden; }
.v3-client-card.dimmed { opacity: 0.55; }
.v3-client-head { padding: 18px 20px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; border-bottom: 1px solid var(--border); }
.v3-client-head .name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.v3-client-head .client-name { color: var(--text-primary); font-size: 18px; font-weight: 700; }
.v3-client-head .client-domain { color: var(--text-secondary); font-size: 14px; }
.v3-client-stats { padding: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 18px; }
.v3-client-stat .label { color: var(--text-dim); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 8px; }
.v3-client-stat .big { color: var(--text-primary); font-size: 23px; font-weight: 700; }
.v3-client-stat .big.hot { color: var(--amber); }
.v3-client-stat .big.red { color: var(--red); }

/* ─── Kanban (Content Studio + Tasks) ─── */
/* Flex instead of fixed-count grid so the row stretches to fill regardless
   of how many columns each page has — content has 8 (research..rejected),
   tasks has 5 (open..done). Every column gets an equal share of the
   available width via `flex: 1 1 0`. */
.v3-kanban { display: flex; gap: 10px; margin-bottom: 18px; }
.v3-kanban-col { flex: 1 1 0; min-width: 0; background: var(--bg-surface); border: 1px solid var(--border); border-radius: 8px; min-height: 200px; display: flex; flex-direction: column; }
.v3-kanban-col .col-head { padding: 12px 14px; border-bottom: 2px solid var(--border); display: flex; justify-content: space-between; align-items: center; border-top-left-radius: 8px; border-top-right-radius: 8px; }
.v3-kanban-col .col-head .label { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px; }
.v3-kanban-col .col-head .count { font-size: 14px; font-weight: 700; font-family: ui-monospace,Menlo,Consolas,monospace; }

/* Per-stage column accent colors. Header gets a tinted background + matching
   bottom border so each column is visually distinct. Body stays surface. */
.v3-kanban-col[data-stage="research"] .col-head { background: var(--blue-bg);  border-bottom-color: var(--blue);   }
.v3-kanban-col[data-stage="research"] .col-head .label { color: #5fa1ff; }
.v3-kanban-col[data-stage="writing"]  .col-head { background: var(--amber-bg); border-bottom-color: var(--amber);  }
.v3-kanban-col[data-stage="writing"]  .col-head .label { color: var(--amber); }
.v3-kanban-col[data-stage="qa"]       .col-head { background: var(--amber-bg); border-bottom-color: var(--amber);  }
.v3-kanban-col[data-stage="qa"]       .col-head .label { color: var(--amber); }
.v3-kanban-col[data-stage="ready"]    .col-head { background: var(--blue-bg);  border-bottom-color: var(--blue);   }
.v3-kanban-col[data-stage="ready"]    .col-head .label { color: #5fa1ff; }
.v3-kanban-col[data-stage="verified"] .col-head { background: var(--green-bg); border-bottom-color: var(--green);  }
.v3-kanban-col[data-stage="verified"] .col-head .label { color: var(--green); }
.v3-kanban-col[data-stage="posted"]   .col-head { background: var(--green-bg); border-bottom-color: var(--green);  }
.v3-kanban-col[data-stage="posted"]   .col-head .label { color: var(--green); }
.v3-kanban-col[data-stage="failed"]   .col-head { background: var(--red-bg);   border-bottom-color: var(--red);    }
.v3-kanban-col[data-stage="failed"]   .col-head .label { color: var(--red); }
.v3-kanban-col[data-stage="rejected"] .col-head { background: rgba(148,163,184,0.10); border-bottom-color: var(--text-secondary); }
.v3-kanban-col[data-stage="rejected"] .col-head .label { color: var(--text-secondary); }
.v3-kanban-col .col-head .count { color: var(--text-secondary); }

.v3-kanban-col .col-body { padding: 8px; flex: 1; max-height: 400px; overflow-y: auto; }
.v3-kanban-card {
  display: block; background: var(--bg-surface-alt); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px; margin-bottom: 6px; text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.v3-kanban-card:hover { border-color: var(--blue); background: var(--bg-input); }
.v3-kanban-card .title { color: var(--text-primary); font-size: 13px; font-weight: 600; line-height: 1.35; }
.v3-kanban-card .meta  { color: var(--text-dim); font-size: 11px; margin-top: 4px; font-family: ui-monospace,Menlo,Consolas,monospace; }

/* ─── Misc ─── */
.v3-empty { padding: 40px 18px; text-align: center; color: var(--text-secondary); font-size: 14px; }
.v3-mono  { font-family: ui-monospace,Menlo,Consolas,monospace; }
.v3-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.v3-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ─── Mobile-only chrome (the hamburger bar + backdrop) ─── */
.v3-mobile-bar { display: none; }
.v3-mobile-backdrop { display: none; }

/* Tablet: thin icon-only sidebar */
@media (max-width: 900px) and (min-width: 641px) {
  .v3-sidebar { width: 60px; }
  .v3-sidebar-brand .title, .v3-sidebar-brand .subtitle, .v3-nav a span:not(.badge), .v3-sidebar-footer .clients-summary { display: none; }
  .v3-sidebar-clientpicker { display: none; }
  .v3-nav a { justify-content: center; }
  .v3-kanban { grid-template-columns: 1fr; }
  .v3-content-inner { padding: 16px; }
}

/* Mobile: sidebar slides in as overlay; hamburger lives in a top bar. */
@media (max-width: 640px) {
  .v3-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 270px; max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 100;
    box-shadow: 4px 0 18px rgba(0,0,0,0.45);
  }
  .v3-sidebar.open { transform: translateX(0); }

  .v3-mobile-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.55);
    opacity: 0; pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 99;
  }
  .v3-mobile-backdrop.visible { opacity: 1; pointer-events: auto; }

  .v3-mobile-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
    flex: 0 0 auto;
  }
  .v3-mobile-toggle {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 9px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
  }
  .v3-mobile-toggle:active { background: var(--bg-surface-alt); }
  .v3-mobile-title { color: var(--text-primary); font-size: 15px; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  .v3-content { display: flex; flex-direction: column; }
  .v3-content-inner { padding: 16px; }

  /* Tighten dense panels on small screens */
  .v3-grid-2, .v3-grid-3 { grid-template-columns: 1fr; }
  /* Phase 2-F: kanban scrolls horizontally on touch instead of
     squeezing 8 columns into 320px. Each column gets a fixed min
     width so cards stay readable; user swipes left/right between
     columns. Cards inside are still long-press-draggable per the
     Sortable touch config. */
  .v3-kanban { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 8px; }
  .v3-kanban-col { flex: 0 0 280px; min-width: 280px; }
  .v3-tabs { overflow-x: auto; flex-wrap: nowrap; }
  .v3-section-header { flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .v3-section-header .right { font-size: 13px; flex-basis: 100%; }
  .v3-table { font-size: 13px; }
  .v3-table th, .v3-table td { padding: 8px 10px; }
}

/* ─── Forum live-progress stage indicator ─── */
.forum-stage-active {
  color: var(--blue) !important;
  font-style: italic;
}
.forum-stage-active::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--blue); margin-right: 6px;
  animation: forum-stage-pulse 1.2s ease-in-out infinite;
  vertical-align: middle;
}
.forum-stage-failed { color: var(--red) !important; }
@keyframes forum-stage-pulse {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50%      { opacity: 1; transform: scale(1.1); }
}

/* ─── Agent flow graph pulse animation ─── */
@keyframes agent-flow-pulse {
  0%, 100% { opacity: 1; r: 4; }
  50%      { opacity: 0.45; r: 5.5; }
}
.agent-dot.pulse { animation: agent-flow-pulse 1.4s ease-in-out infinite; }
.agent-row:hover rect { fill: rgba(59,130,246,0.08); }
.agent-row:hover text { fill: var(--text-primary); }

/* ─── Toast (floating flash messages) ──────────────────────────────
   Used in place of the older inline-styled v3-panel flash blocks.
   Pages include via _toast.ejs partial; the JS in _foot.ejs handles
   auto-dismiss (5s) and the × close button. Position fixed so it
   floats over content regardless of scroll position; centered
   horizontally; stacked z-index above modals (10000). */
.v3-toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  min-width: 320px; max-width: min(680px, 90vw);
  padding: 12px 44px 12px 18px;
  border-radius: 6px;
  font-size: 13px; line-height: 1.5;
  /* Solid opaque background so long error text is readable instead of
     bleeding into whatever's underneath. Severity is signaled by the
     left accent bar + body text color, not a tinted background. */
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-dim);
  box-shadow: 0 6px 22px rgba(0,0,0,0.55);
  animation: v3-toast-in 180ms ease-out, v3-toast-out 320ms ease-in 5000ms forwards;
}
.v3-toast.success { border-left-color: var(--green); }
.v3-toast.warning { border-left-color: var(--amber); }
.v3-toast.error   { border-left-color: var(--red); }
.v3-toast.info    { border-left-color: var(--blue); }
.v3-toast.success .v3-toast-body { color: var(--green); }
.v3-toast.warning .v3-toast-body { color: var(--amber); }
.v3-toast.error   .v3-toast-body { color: #ff8888; }
.v3-toast.info    .v3-toast-body { color: #5fa1ff; }

.v3-toast-body {
  display: block;
  /* Preserve newlines from server messages (Playwright errors include
     real \n separating "Call log:", "waiting for…", "retrying fill…"
     lines — collapsing them into one paragraph made the error
     unreadable). word-break wraps the inevitable long selector strings. */
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-height: 60vh;
  overflow-y: auto;
}

/* Errors are diagnostic — operators need to read them, but a 60vh blob
   of stack trace shouldn't dominate the page. Cap at ~200px scrollable.
   No auto-dismiss (manual close only); JS skips the removal timer
   for [data-toast-sticky]. */
.v3-toast.error {
  max-width: min(720px, 90vw);
  animation: v3-toast-in 180ms ease-out;
}
.v3-toast.error .v3-toast-body {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}
.v3-toast.error .v3-toast-body::-webkit-scrollbar       { width: 6px; }
.v3-toast.error .v3-toast-body::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
.v3-toast.error .v3-toast-body::-webkit-scrollbar-track { background: transparent; }

/* Inline screenshot preview inside an error toast — click to open full
   size in a new tab. Border-of-the-toast color cue stays via the
   existing left-accent bar; the preview itself uses a neutral chrome. */
.v3-toast .v3-toast-shot {
  display: block;
  margin-top: 10px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #000;
  text-decoration: none;
  position: relative;
  cursor: pointer;
}
.v3-toast .v3-toast-shot img {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 2px;
  pointer-events: none;
}
.v3-toast .v3-toast-shot span {
  position: absolute;
  bottom: 10px; right: 10px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  pointer-events: none;
}
.v3-toast .v3-toast-shot:hover { border-color: var(--blue); }

/* Inline links inside a toast body — visibly distinct from the body text
   color so the operator can see they're clickable. Cyan against red,
   yellow against amber-ish, etc. — anything but "same color, plus
   underline" which had been blending on error toasts. */
.v3-toast .v3-toast-link {
  color: #5fa1ff;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
  font-weight: 600;
  word-break: break-all;
}
.v3-toast .v3-toast-link:hover { color: #8ec1ff; background: rgba(95,161,255,0.12); padding: 0 2px; border-radius: 2px; }
.v3-toast .v3-toast-link:visited { color: #5fa1ff; }
.v3-toast .v3-toast-body { display: block; }
.v3-toast-close {
  position: absolute; top: 6px; right: 8px;
  background: transparent; border: 0;
  color: inherit; opacity: 0.55;
  cursor: pointer; padding: 2px 8px;
  font-size: 18px; line-height: 1;
  border-radius: 3px;
}
.v3-toast-close:hover { opacity: 1; }
.v3-toast.dismissed { animation: v3-toast-out 220ms ease-in forwards; }
@keyframes v3-toast-in {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes v3-toast-out {
  to { opacity: 0; transform: translate(-50%, -14px); pointer-events: none; }
}

/* Stack multiple toasts vertically. Subsequent siblings shift down. */
.v3-toast ~ .v3-toast { top: 86px; }
.v3-toast ~ .v3-toast ~ .v3-toast { top: 152px; }

/* ─── Broadcast composer (Visual / HTML / Preview) ───────────────── */
/* Mode switcher pills. */
.v3-broadcast-mode {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--bg-input); border: 1px solid var(--border); border-radius: 4px;
}
.v3-broadcast-mode button {
  background: transparent; border: 0; color: var(--text-secondary);
  padding: 4px 10px; border-radius: 3px;
  font-family: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.v3-broadcast-mode button:hover { color: var(--text-primary); }
.v3-broadcast-mode button.active { background: var(--blue); color: #fff; }

/* Toolbar above the editor. */
.v3-broadcast-toolbar {
  display: flex; flex-wrap: wrap; gap: 2px; align-items: center;
  padding: 6px 8px;
  background: var(--bg-surface-alt); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 6px 6px 0 0;
}
.v3-broadcast-toolbar button {
  background: transparent; border: 1px solid transparent;
  color: var(--text-secondary);
  padding: 4px 9px; border-radius: 3px;
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer; min-width: 28px;
}
.v3-broadcast-toolbar button:hover { background: var(--bg-input); border-color: var(--border-light); color: var(--text-primary); }
.v3-broadcast-toolbar button:active { background: var(--blue-bg); color: var(--blue); }
.v3-broadcast-toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }

/* Editor surfaces (visual contenteditable, raw textarea, preview iframe).
   Sized so the "Recent broadcasts" panel below the form is visible
   above the fold on a typical viewport — clamp keeps it usable on
   short screens without dominating tall ones. */
.v3-broadcast-visual,
.v3-broadcast-html,
.v3-broadcast-preview {
  width: 100%;
  height: clamp(240px, calc(100vh - 700px), 420px);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.55;
  overflow-y: auto;
}
.v3-broadcast-visual:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.v3-broadcast-visual h2, .v3-broadcast-visual h3 { color: var(--text-primary); margin: 0.8em 0 0.4em; }
.v3-broadcast-visual p { margin: 0.5em 0; }
.v3-broadcast-visual blockquote { border-left: 3px solid var(--border-light); padding-left: 12px; margin: 0.6em 0; color: var(--text-secondary); }
.v3-broadcast-visual a { color: var(--blue); }
.v3-broadcast-visual ul, .v3-broadcast-visual ol { margin: 0.6em 0; padding-left: 1.6em; }
.v3-broadcast-visual hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }
.v3-broadcast-html { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; resize: none; border-radius: 0 0 6px 6px; }
.v3-broadcast-preview { padding: 0; background: #fff; }

/* Date-range pills (Analytics → Live tab). Compact button group used to
   drive the embedded analytics iframe's range without forcing it to render
   its own TopBar inside the iframe. */
.v3-range-pill {
  background: var(--bg-surface-alt); border: 1px solid var(--border);
  color: var(--text-secondary); font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 4px; cursor: pointer;
}
.v3-range-pill:hover { color: var(--text-primary); border-color: var(--border-light); }
.v3-range-pill.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* List | Flow sub-toggle inside Agents tab */
.v3-subtab-bar { display: flex; gap: 4px; padding: 4px; background: var(--bg-surface-alt); border-radius: 6px; margin-bottom: 12px; width: max-content; }
.v3-subtab-bar button {
  background: transparent; border: 0; color: var(--text-secondary);
  padding: 6px 14px; border-radius: 4px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.v3-subtab-bar button.active { background: var(--bg-surface); color: var(--text-primary); }
.v3-subtab-bar button:hover { color: var(--text-primary); }

/* Toggle switch — used on /system/flags. Single-click on/off control
   that submits its enclosing form on change. Replaces the older
   pill + "flip → true/false" button pattern. */
.v3-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.v3-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.v3-toggle-track {
  position: relative; display: inline-block; width: 36px; height: 20px;
  background: var(--bg-surface-alt); border: 1px solid var(--border);
  border-radius: 999px; transition: background 0.15s, border-color 0.15s;
}
.v3-toggle-thumb {
  position: absolute; top: 1px; left: 1px; width: 16px; height: 16px;
  background: var(--text-dim); border-radius: 50%;
  transition: left 0.15s, background 0.15s;
}
.v3-toggle input:checked + .v3-toggle-track { background: var(--green); border-color: var(--green); }
.v3-toggle input:checked + .v3-toggle-track .v3-toggle-thumb { left: 17px; background: #fff; }
.v3-toggle input:focus-visible + .v3-toggle-track { outline: 2px solid var(--blue); outline-offset: 2px; }
.v3-toggle-label { color: var(--text-secondary); font-size: 12px; min-width: 36px; }
.v3-toggle input:checked ~ .v3-toggle-label { color: var(--green); }

/* Inline bool indicator — used by auto-CRUD list/edit when a column
   value is a boolean. Disabled (read-only) by default; non-interactive. */
.v3-bool {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid var(--border); background: var(--bg-surface-alt);
  position: relative; vertical-align: middle;
}
.v3-bool.on { background: var(--green); border-color: var(--green); }
.v3-bool.on::after {
  content: ''; position: absolute; left: 3px; top: 0px;
  width: 5px; height: 9px; border: solid #fff;
  border-width: 0 2px 2px 0; transform: rotate(45deg);
}

/* ============================================================
   v54 (spec 148, 2026-06-11): Viewer-role read-only styling.
   Active when <body data-role="viewer"> (set by _head.ejs).
   Three behaviors:
   1. Yellow banner above the dashboard explaining read-only mode.
   2. All submit buttons + elements opted-in via [data-admin-only]
      look disabled (faded, not-allowed cursor) and click-through is
      blocked (pointer-events:none). Forms can't submit either.
   3. Inputs/selects inside forms made readonly visually.
   The router-level mutation guard in v3.js + v3-extras.js is the
   actual security boundary — this CSS is for UX clarity. Anything
   that slips through still returns JSON 403 from the server.
   ============================================================ */
.v3-viewer-banner { display: none; }
body[data-role="viewer"] .v3-viewer-banner {
  display: block;
  background: #fef3c7;
  color: #78350f;
  border-bottom: 2px solid #f59e0b;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
  z-index: 100;
}
body[data-role="viewer"] button[type="submit"],
body[data-role="viewer"] input[type="submit"],
body[data-role="viewer"] form button:not([type="button"]):not(.viewer-allowed),
body[data-role="viewer"] [data-admin-only],
body[data-role="viewer"] a.v3-btn-danger,
body[data-role="viewer"] a.v3-btn-primary[data-action] {
  opacity: 0.5 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
  position: relative;
}
body[data-role="viewer"] button[type="submit"]::after,
body[data-role="viewer"] [data-admin-only]::after {
  content: '';
  position: absolute;
  inset: 0;
  cursor: not-allowed;
}
/* Allow navigation links + the role-aware logout */
body[data-role="viewer"] .v3-sidebar a,
body[data-role="viewer"] .v3-tab,
body[data-role="viewer"] .viewer-allowed,
body[data-role="viewer"] a.v3-btn[href]:not([data-action]) {
  opacity: 1 !important;
  cursor: pointer !important;
  pointer-events: auto !important;
}
