/* shell.css — foundation-ui structural app-shell styles.
 *
 * Loaded AFTER tokens.css + themes.css (reads only var() tokens). Owns the shell
 * chrome: resets/typography, the header/sidebar/main/footer layout, the generic
 * .btn/.btn-icon controls, the whitebell vendor credit, and the AI chat panel
 * interior. App-specific rules (data tables, filters, page bodies) stay in the
 * consumer's own CSS. Re-skin by overriding token VALUES, never these selectors.
 */

@import url("footer.css"); /* the footer + vendor credit: its own file (increment-footer-host FH-U1) */

/* ─────────────────────────  Resets & typography  ───────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

/* Scrollbars are never the native OS look (ui_and_styling.md § Scrollbars): one themed default
   for every consumer. Hidden-bar panes (.sidebar, .main-content, .ctx-body, .cp-input) override
   it by specificity; nothing else restyles a visible scrollbar. */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
@supports not (scrollbar-color: auto) {
  *::-webkit-scrollbar { width: 8px; height: 8px; }
  *::-webkit-scrollbar-track { background: transparent; }
  *::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-sm); }
  *::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }
}
/* increment-number-spinner NS1 (owner 2026-10-30): the browser's number stepper is OS chrome — hidden;
   typing, arrow keys, min / max / step and the themed validation hint are unchanged. */
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; appearance: none; margin: 0; }


/* Tooltips are never the native title= bubble (ui_and_styling.md § Tooltips, owner ruling
   2026-09-26): js/tooltip.js shows a data-tip's text in this one fixed-position element. Tokens
   only — the same surface vocabulary as a popover — so it follows every theme. */
.fui-tip {
  position: fixed; z-index: 1000; pointer-events: none;
  width: max-content; max-width: 38ch; white-space: normal;
  padding: 7px 10px; font: 400 12.5px/1.45 var(--font-sans);
  background: var(--bg-card); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(var(--shadow-rgb), .35);
}
.fui-tip[hidden] { display: none; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%; /* viewport-locked shell (ree-x contract): the window never scrolls */
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Hover contract (owner ruling 2026-07-31): never underline — hover feedback comes
   from border/frame or surface color changes on the containing control, plus a
   slight brightness lift on bare text links. */
a { color: var(--accent); text-decoration: none; transition: color var(--t-fast), filter var(--t-fast); }
a:hover { text-decoration: none; filter: brightness(1.15); }
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }

h1, h2, h3, h4, h5, h6 { margin: 0 0 0.5em; font-weight: 600; line-height: 1.25; color: var(--fg); }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4, h5, h6 { font-size: var(--fs-md); }
p { margin: 0 0 1em; }

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1em 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid transparent; background: transparent; }
input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  color: var(--fg);
  transition: border-color var(--t-fast);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
::selection { background: var(--accent); color: var(--accent-fg); }

.ph, [class*=" ph-"], [class^="ph-"] { font-size: 1.05em; vertical-align: -0.15em; }
.muted { color: var(--fg-muted); }
.subtle { color: var(--fg-subtle); }
.mono { font-family: var(--font-mono); font-size: 0.92em; }

/* Accessibility: skip-to-content + visually-hidden (WCAG 2.4.1) */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.sr-only-focusable:focus-visible {
  position: fixed; top: 8px; left: 8px; width: auto; height: auto;
  padding: 6px 14px; margin: 0; overflow: visible; clip: auto; white-space: normal;
  background: var(--accent); color: var(--accent-fg); border-radius: var(--r-sm);
  font-weight: 600; z-index: 200; text-decoration: none;
}

/* ─────────────────────────  Page layout  ───────────────────────── */

/* Fixed-chrome contract (ree-x, platform foundation rule): header and footer are
   viewport-locked flex rows, .app-layout takes the exact remaining height, and each
   column (sidebar / main / chat) scrolls INTERNALLY. Pages never move the chrome and
   the AI panel is layout-independent from page content. */
body { display: flex; flex-direction: column; height: 100vh; min-height: 100vh; overflow: hidden; }

/* LT-U1: the main column is minmax(0, 1fr) in every variant — a bare 1fr's minimum is its
   content's min-content width, so a wide table would widen the layout past the window. */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  transition: grid-template-columns 0.16s ease;
}
body.nav-resizing .app-layout { transition: none; } /* live drag: no easing lag */
body[data-sidebar="collapsed"] .app-layout { grid-template-columns: var(--sidebar-w-mini) minmax(0, 1fr); }
body[data-chat="open"] .app-layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--chat-panel-w); }
body[data-chat="open"][data-sidebar="collapsed"] .app-layout {
  grid-template-columns: var(--sidebar-w-mini) minmax(0, 1fr) var(--chat-panel-w);
}
/* results/context pane — sits BETWEEN main and the chat column (owner ruling
   2026-07-31: RAG hits get their own pane; the chat keeps the answer) */
body[data-ctx="open"] .app-layout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--ctx-panel-w); }
body[data-ctx="open"][data-sidebar="collapsed"] .app-layout {
  grid-template-columns: var(--sidebar-w-mini) minmax(0, 1fr) var(--ctx-panel-w);
}
body[data-ctx="open"][data-chat="open"] .app-layout {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--ctx-panel-w) var(--chat-panel-w);
}
body[data-ctx="open"][data-chat="open"][data-sidebar="collapsed"] .app-layout {
  grid-template-columns: var(--sidebar-w-mini) minmax(0, 1fr) var(--ctx-panel-w) var(--chat-panel-w);
}

/* ── Header ── */
.top-header {
  flex: none; z-index: 30;
  height: var(--header-h);
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 var(--content-pad); gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: var(--fs-lg); color: var(--fg); }
.brand:hover { text-decoration: none; }
.brand .ph { font-size: 1.4em; color: var(--accent); }
.header-title { color: var(--fg-subtle); font-size: var(--fs-md); }
/* Header breadcrumb (spec header-breadcrumb): parents as links, the current page last. Separators
   are CSS so the markup stays a plain list; middle crumbs shrink first, the current page last. */
.fui-crumbs { min-width: 0; font-size: var(--fs-md); }
.fui-crumbs ol { display: flex; align-items: center; min-width: 0; margin: 0; padding: 0; list-style: none; white-space: nowrap; }
.fui-crumbs li { display: flex; align-items: center; flex-shrink: 10; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg-subtle); }
.fui-crumbs li + li::before { content: "›"; margin: 0 8px; color: var(--fg-muted); flex-shrink: 0; }
.fui-crumbs a { color: var(--fg-subtle); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fui-crumbs a:hover { color: var(--accent); text-decoration: none; }
.fui-crumbs a:focus-visible { color: var(--accent); outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
.fui-crumbs [aria-current="page"] { color: var(--fg); font-weight: 600; flex-shrink: 1; min-width: 0; }
.sidebar-toggle-btn {
  background: none; border: none; padding: 4px 6px; cursor: pointer;
  color: var(--fg-muted); font-size: 1.1em; line-height: 1;
  transition: color var(--t-fast); flex-shrink: 0;
}
.sidebar-toggle-btn:hover { color: var(--fg); }
.sidebar-toggle-btn .ph { display: inline-block; transition: transform var(--t-fast); }
body[data-sidebar="collapsed"] .sidebar-toggle-btn .ph { transform: rotate(180deg); }
.header-actions { display: flex; align-items: center; gap: 10px; }

/* ── User menu ── */
.user-menu-wrap { position: relative; }
.user-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border-radius: 6px; border: none; background: none;
  color: var(--fg); font-size: var(--fs-sm); cursor: pointer; transition: background 0.15s;
}
.user-badge:hover { background: var(--bg-hover); }
.user-menu-caret { font-size: 0.75em; opacity: 0.6; transition: transform 0.15s; }
.user-menu-wrap[data-open] .user-menu-caret { transform: rotate(180deg); }
/* ── Alert bell (spec alert-bell) ──
   A <details> popover hanging from an icon button. An absolute box takes its width from its
   containing block (the button), so max-content sets it and the viewport is the only bound:
   rows stay on one line, the list scrolls past 70vh, the corner resizes it (AB-U6). */
.fui-bell-slot { display: inline-flex; }
.fui-bell { position: relative; }
.fui-bell > summary { list-style: none; position: relative; }
.fui-bell > summary::-webkit-details-marker { display: none; }
.fui-bell-badge {
  position: absolute; top: -4px; right: -6px; min-width: 1.1rem; padding: 0 0.25rem;
  border-radius: var(--r-pill, 999px); font-size: 0.7rem; line-height: 1.1rem; text-align: center;
  background: rgba(var(--info-rgb), 0.18); color: var(--info); border: 1px solid var(--info);
}
.fui-bell-badge--accent  { background: rgba(var(--accent-rgb), 0.18);  color: var(--accent);  border-color: var(--accent); }
.fui-bell-badge--warning { background: rgba(var(--warning-rgb), 0.18); color: var(--warning); border-color: var(--warning); }
.fui-bell-badge--danger  { background: rgba(var(--danger-rgb), 0.18);  color: var(--danger);  border-color: var(--danger); }
.fui-bell-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
  width: max-content; max-width: calc(100vw - 2rem); max-height: 70vh;
  overflow: auto; resize: both; padding: 10px 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md, 6px); box-shadow: var(--shadow-pop);
}
/* A narrow window: anchored to the bell, a wide popover starts off-screen to the left; pin it to
   the viewport instead (alert-bell increment-narrow-viewport AB-U7). */
@media (max-width: 520px) {
  .fui-bell-pop { position: fixed; left: 1rem; right: 1rem; width: auto; top: calc(var(--header-h) + 6px); }
}
/* A new item rings the bell once (increment-new-item-ring AB-U11); reduced motion keeps it still (AB-S3). */
.fui-bell--ring > summary { animation: fui-bell-ring 0.8s ease-in-out 1; transform-origin: 50% 10%; }
@keyframes fui-bell-ring {
  0%, 100% { transform: rotate(0); }
  15% { transform: rotate(14deg); }
  30% { transform: rotate(-12deg); }
  45% { transform: rotate(9deg); }
  60% { transform: rotate(-6deg); }
  75% { transform: rotate(3deg); }
}
@media (prefers-reduced-motion: reduce) {
  .fui-bell--ring > summary { animation: none; }
}
.fui-bell-src + .fui-bell-src { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.fui-bell-src-head { margin: 0 0 6px; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--fg-muted); }
.fui-bell-src-count { color: var(--fg); }
.fui-bell-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.fui-bell-item { white-space: nowrap; }
.fui-bell-more, .fui-bell-note { margin: 6px 0 0; }
.fui-bell-all { display: inline-block; margin-top: 6px; font-size: 0.85em; }
.fui-bell-x { margin-left: 4px; vertical-align: middle; }
.fui-bell-clear { display: block; margin-top: 10px; }
.fui-bell-clear[hidden] { display: none; }

.user-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; min-width: 160px;
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px;
  box-shadow: var(--shadow-md); z-index: 100; overflow: hidden;
}
.user-menu-wrap[data-open] .user-menu { display: block; }
.user-menu-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 14px;
  color: var(--fg); font-size: var(--fs-sm); white-space: nowrap; text-decoration: none;
}
.user-menu-item:hover { background: var(--bg-hover); text-decoration: none; }
.user-menu-item .ph { opacity: 0.7; }

/* ── Sidebar ── */
.sidebar {
  min-height: 0; /* grid child: allow internal scroll instead of growing the track */
  overflow-y: auto; background: var(--bg-alt); border-right: 1px solid var(--border);
  padding: 12px 0;
  scrollbar-width: none; -ms-overflow-style: none; /* hidden scrollbar (functional) */
}
.sidebar::-webkit-scrollbar { display: none; }
/* The menu inside the sidebar (sections, links, nested groups) is sidebar.css. */

/* ── Main — the ONLY page-content scroll surface (hidden bar, ree-x idiom) ── */
.main-content {
  padding: var(--content-pad) calc(var(--content-pad) * 1.5); width: 100%;
  min-height: 0; overflow-y: auto;
  scrollbar-width: none; -ms-overflow-style: none;
}
.main-content::-webkit-scrollbar { display: none; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: var(--fs-xl); }


/* ── Loading / htmx affordances ── */
#loading-bar {
  position: fixed; top: 0; left: 0; height: 3px; background: var(--accent);
  z-index: 10000; width: 0; opacity: 0;
  transition: opacity 0.1s ease, width 0.1s ease; pointer-events: none;
}
#loading-bar.lb-active { opacity: 1; animation: lb-fill 8s ease-out forwards; }
#loading-bar.lb-done { width: 100%; opacity: 0; transition: opacity 0.3s ease 0.1s, width 0.1s; }
@keyframes lb-fill { 0% { width: 0; } 30% { width: 50%; } 70% { width: 75%; } 100% { width: 90%; } }
.htmx-indicator { opacity: 0; transition: opacity var(--t-fast); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
.spin { display: inline-block; animation: spin 0.8s linear infinite; }
.minimal-version { text-align: center; font-size: 0.72rem; margin-top: 12px; opacity: 0.5; }

/* ─────────────────────────  Generic controls  ───────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
  border-radius: var(--r-sm); border: 1px solid var(--border);
  background: var(--bg-card); color: var(--fg); font-size: var(--fs-md); font-weight: 500;
  cursor: pointer; transition: background var(--t-fast), border-color var(--t-fast);
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--border-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-xs { padding: 2px 8px; font-size: var(--fs-sm); }
.btn-icon { padding: 0; width: 36px; height: 36px; justify-content: center; align-items: center; flex-shrink: 0; }
.btn-icon .ph { font-size: 1.15em; }
.btn-icon.btn-xs { width: 28px; height: 28px; }
.btn-icon.btn-lg { width: 44px; height: 44px; }
.btn-icon.btn-icon-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-icon.btn-icon-primary:hover { filter: brightness(1.08); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--fg-muted); }
.status-auth { background: var(--success); }
.status-guest { background: var(--fg-muted); }

/* ─────────────  Popup context menu (mechanism: ctx-menu.js)  ───────────── */

.ui-ctxmenu {
  display: none; position: fixed; z-index: 1000; min-width: 180px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: 4px; font-size: var(--fs-sm);
}
.ui-ctxmenu-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border-radius: var(--r-sm); color: var(--fg); cursor: pointer; white-space: nowrap;
}
.ui-ctxmenu-item:hover { background: var(--bg-card-hover); }
/* Keyboard focus (increment-ctx-menu-keyboard KM-U2): the hover surface plus an accent ring. */
.ui-ctxmenu-item:focus-visible { background: var(--bg-card-hover); outline: 2px solid var(--accent); outline-offset: -2px; }
.ui-ctxmenu-item .ph { color: var(--fg-subtle); font-size: 1.05em; }
.ui-ctxmenu-divider { height: 1px; background: var(--border); margin: 4px 6px; }
.ui-ctxmenu-header {
  padding: 6px 10px 2px; font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--fg-muted);
}

/* Composer token rendered as a chip in the reader's own bubble (spec help-contract H5) */
.cp-help-chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px;
  border: 1px solid var(--accent); border-radius: var(--r-pill);
  background: rgba(var(--accent-rgb), .12); color: var(--accent);
  font-size: .78rem; font-family: var(--font-mono);
}

/* ─────────────  Modal frame (openModalFrom/closeModal, app-shell.js)  ───────────── */

.modal-overlay {
  position: fixed; inset: 0; z-index: 900; display: flex;
  align-items: center; justify-content: center; padding: 20px;
  background: rgba(var(--crust-rgb, 0, 0, 0), 0.55);
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  min-width: 320px; max-width: min(480px, 92vw); padding: 18px 20px;
}
.modal h3 { margin: 0 0 12px; font-size: var(--fs-lg); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
/* uiConfirm (app-shell.js) — the shell's answer to window.confirm. Only the message
   block is new; the frame, the button row and the buttons are the modal's own. */
.modal-confirm .modal-message { margin: 0; color: var(--fg-muted); line-height: 1.5; }

/* ─────────────  Context/results pane (between main and chat)  ───────────── */

.ctx-panel {
  position: relative; min-height: 0; display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--bg-alt);
}
.ctx-resize { position: absolute; left: -3px; top: 0; width: 6px; height: 100%; cursor: col-resize; z-index: 3; }
.ctx-resize:hover, body.ctx-resizing .ctx-resize { background: rgba(var(--accent-rgb), 0.25); }
body.ctx-resizing { user-select: none; cursor: col-resize; }
body:not([data-ctx="open"]) .ctx-panel { display: none; }
.ctx-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-size: .82rem; font-weight: 600;
  color: var(--fg-muted); flex-shrink: 0;
}
.ctx-head .ctx-spacer { flex: 1; }
.ctx-body {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  scrollbar-width: none; -ms-overflow-style: none;
}
.ctx-body::-webkit-scrollbar { display: none; }

/* ─────────────────────────  AI chat panel  ───────────────────────── */

.chat-panel {
  position: relative; /* ANCHOR for .cp-resize-handle — lost when sticky was removed
                         in the fixed-chrome rework (live bug: handle unreachable) */
  min-height: 0; /* grid child: own internal scroll (cp-log), independent of pages */
  display: flex; flex-direction: column;
  border-left: 1px solid var(--border); background: var(--bg-alt); overflow: hidden;
}
body:not([data-chat="open"]) .chat-panel { display: none; }
.cp-resize-handle {
  position: absolute; left: 0; top: 0; bottom: 0; width: 5px; cursor: ew-resize;
  z-index: 20; transition: background var(--t-fast);
}
.cp-resize-handle:hover, .cp-resize-handle.is-resizing { background: var(--accent); opacity: 0.4; }
.cp-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-size: .82rem; font-weight: 600;
  color: var(--fg-muted); flex-shrink: 0;
  flex-wrap: wrap; /* HN1: a host's full control set wraps to a second row instead of clipping */
}
/* HN2: glyph + name never break apart — one line, glyph centred on the text */
.cp-header .cp-title { flex: 1; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.cp-loop-selector {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px;
  color: var(--fg-subtle); font-size: var(--fs-sm); cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
  white-space: nowrap; max-width: 180px; overflow: hidden;
}
.cp-loop-selector .ph { font-size: 0.9em; flex-shrink: 0; }
.cp-loop-selector span { overflow: hidden; text-overflow: ellipsis; }
.cp-loop-selector:hover { border-color: var(--accent); color: var(--fg); background: var(--bg-hover); }
.cp-log {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px; font-size: .84rem;
}
.cp-msg { padding: 6px 10px; border-radius: 8px; line-height: 1.45; word-break: break-word; max-width: 100%; }
.cp-msg.cp-user { background: rgba(var(--accent-rgb), .12); color: var(--fg); align-self: flex-end; border-bottom-right-radius: 2px; }
.cp-msg.cp-assistant { background: var(--bg-card); border: 1px solid var(--border); color: var(--fg); align-self: flex-start; border-bottom-left-radius: 2px; }
.cp-msg.cp-thinking { opacity: .55; font-style: italic; }
/* Group-chat room mode (spec docs/specs/chat-rooms-panel/) — tokens only. */
.cp-rooms {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}
.cp-room-item {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  padding: 2px 8px; border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--bg-card); color: var(--fg-muted); font-size: var(--fs-xs); cursor: pointer;
}
.cp-room-item:hover { border-color: var(--accent); color: var(--fg); background: var(--bg-hover); }
.cp-room-item[aria-pressed="true"] { border-color: var(--accent); color: var(--fg); background: rgba(var(--accent-rgb), .12); }
.cp-room-item.is-archived { opacity: .6; }
.cp-room-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-room-unread {
  min-width: 1.4em; padding: 0 4px; border-radius: var(--r-pill); text-align: center;
  background: var(--accent); color: var(--accent-fg); font-size: var(--fs-xs);
}
.cp-msg.cp-room-line { background: var(--bg-card); border: 1px solid var(--border); color: var(--fg); align-self: flex-start; }
.cp-msg.cp-room-laura { border-color: rgba(var(--accent-rgb), .5); }
.cp-msg.cp-room-system { align-self: stretch; text-align: center; background: none; border: none; color: var(--fg-subtle); font-size: var(--fs-xs); padding: 0; }
.cp-room-meta { display: flex; align-items: center; gap: 6px; color: var(--fg-muted); font-size: var(--fs-xs); }
.cp-room-author { font-weight: 600; }
.cp-room-avatar {
  width: 20px; height: 20px; flex: none; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-hover); color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 600;
}
.cp-room-avatar[hidden] { display: none; }
.cp-msg.cp-room-system .cp-room-author { display: none; }
.cp-msg.cp-room-system .cp-room-meta { justify-content: center; }
/* chat-rooms-panel U7: the owner's live-share prompt — text and its two buttons on one row */
.cp-msg.cp-room-share { display: flex; align-items: center; gap: 8px; align-self: stretch; background: var(--bg-card); border: 1px solid var(--border); border-left: 3px solid var(--accent); color: var(--fg); }
.cp-room-share-text { flex: 1 1 auto; min-width: 0; }
.cp-room-share-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.cp-menu-link {
  color: var(--accent); text-decoration: none; cursor: pointer; font-size: inherit;
  border-bottom: 1px dotted var(--accent);
}
.cp-menu-link:hover { border-bottom-style: solid; filter: brightness(1.15); }

/* ── Rendered markdown inside an answer (spec docs/specs/chat-markdown/) ──
   The bubble is narrow, so anything that can outgrow it (tables, code) scrolls
   inside its own container instead of stretching the chat grid column. The
   horizontal bar stays visible here — it is the only cue that a table continues. */
.cp-md-p { margin: 0 0 6px; }
.cp-msg > .cp-md-p:last-child { margin-bottom: 0; }
.cp-md-h { margin: 10px 0 4px; font-size: .88rem; font-weight: 600; color: var(--fg); line-height: 1.3; }
.cp-msg > .cp-md-h:first-child { margin-top: 0; }
h6.cp-md-h { color: var(--fg-subtle); }
.cp-md-hr { margin: 8px 0; border: 0; border-top: 1px solid var(--border); }
.cp-md-list { margin: 0 0 6px; padding-left: 18px; }
.cp-md-list li { margin: 2px 0; }
.cp-md-link { color: var(--accent); text-decoration: none; border-bottom: 1px solid transparent; }
.cp-md-link:hover { border-bottom-color: var(--accent); }
.cp-md-code {
  font-family: var(--font-mono); font-size: .92em; padding: 1px 4px; border-radius: 3px;
  background: var(--bg-input); color: var(--fg); word-break: break-all;
}
.cp-md-pre {
  margin: 0 0 6px; padding: 8px 10px; border-radius: 6px; overflow-x: auto;
  background: var(--bg-input); border: 1px solid var(--border);
}
.cp-md-pre code { font-family: var(--font-mono); font-size: .82rem; line-height: 1.4; white-space: pre; }
.cp-md-tablewrap { margin: 0 0 6px; overflow-x: auto; max-width: 100%; }
.cp-md-table { border-collapse: collapse; font-size: .78rem; }
.cp-md-table th, .cp-md-table td {
  border: 1px solid var(--border); padding: 3px 7px; text-align: left; vertical-align: top;
  white-space: normal; word-break: normal;
}
.cp-md-table th { background: var(--bg-alt); font-weight: 600; color: var(--fg); }
.cp-md-table tbody tr:nth-child(even) td { background: rgba(var(--accent-rgb), .04); }
/* Column alignment from the delimiter row — scoped to beat `.cp-md-table th/td`. */
.cp-md-table .cp-md-left { text-align: left; }
.cp-md-table .cp-md-center { text-align: center; }
.cp-md-table .cp-md-right { text-align: right; }
.cp-form { position: relative; display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); flex-shrink: 0; }
.cp-input {
  flex: 1; resize: none; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--fg);
  font-size: .84rem; font-family: var(--font-sans); line-height: 1.4;
  min-height: 36px; max-height: 120px; overflow-y: auto;
  scrollbar-width: none; -ms-overflow-style: none; /* autosize owns the height — no arrows */
}
.cp-input::-webkit-scrollbar { display: none; }
.cp-input:focus { outline: none; border-color: var(--accent); }
.cp-send-btn { align-self: flex-end; }
.cp-stop { align-self: flex-end; }
.cp-stop[hidden] { display: none; } /* .btn-icon's display would override the attribute */
#chat-panel-toggle.cp-online { color: var(--success); }
#chat-panel-toggle.cp-offline { color: var(--danger); }

/* ── Sidebar resize handle (spec docs/specs/sidebar-resize/) ── */
.sidebar { position: relative; }
.sidebar-resize {
  position: absolute; top: 0; right: -3px; width: 6px; height: 100%;
  cursor: col-resize; z-index: 3;
}
.sidebar-resize:hover, body.sidebar-resizing .sidebar-resize {
  background: rgba(var(--accent-rgb), 0.25);
}
body.sidebar-resizing { user-select: none; cursor: col-resize; }
body[data-sidebar="collapsed"] .sidebar-resize { display: none; }

/* ── Example-question chips (empty-state suggestions) ── */
.cp-examples { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.cp-example {
  text-align: left; padding: 7px 10px; font-size: var(--fs-sm);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--fg-subtle); cursor: pointer;
}
.cp-example:hover { border-color: var(--accent); color: var(--fg); background: var(--bg-card-hover); }

/* ── Thinking indicator (johanna robot bob + vera elapsed ticker) ── */
.cp-thinking {
  display: flex; align-items: center; gap: 8px; align-self: flex-start;
  padding: 8px 12px; margin: 4px 0;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--fg-muted); font-size: var(--fs-sm);
}
.cp-thinking .ph { color: var(--accent); animation: cp-bob 1s ease-in-out infinite; }
.cp-elapsed { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
@keyframes cp-bob {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(-4px) rotate(-8deg); }
  60%      { transform: translateY(0) rotate(0deg); }
  80%      { transform: translateY(-2px) rotate(8deg); }
}

/* ── Per-turn usage badge + session total (vera/johanna pattern) ── */
.cp-usage {
  display: flex; gap: 10px; align-items: center; align-self: flex-start;
  font-size: var(--fs-xs); color: var(--fg-muted);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  padding: 0 2px; margin: -2px 0 4px;
}
.cp-usage .ph { font-size: 0.9em; }
.cp-usage-total {
  font-size: var(--fs-xs); color: var(--fg-muted);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; white-space: nowrap; /* HN2: "Σ ~25.0k" stays one line */
}

/* ── Result-tile score pill + top-k rest counter (results pane) ── */
.cp-card { position: relative; }
.cp-card-score {
  position: absolute; top: 8px; right: 8px;
  font-size: var(--fs-xs); font-family: var(--font-mono);
  color: var(--accent); background: rgba(var(--accent-rgb), 0.12);
  padding: 0 6px; border-radius: var(--r-pill, 999px);
}
.ctx-more { text-align: center; color: var(--fg-muted); font-size: var(--fs-xs); padding: 6px 0; }

/* ── Chat cited-tile cards (spec docs/specs/chat-cards/) ── */
.cp-cards { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.cp-card {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--r-md); text-decoration: none;
}
.cp-card:hover { border-color: var(--accent); }
.cp-card-cat { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.cp-card-title { font-size: var(--fs-sm); font-weight: 600; color: var(--fg); }
.cp-card-snippet {
  font-size: var(--fs-xs); color: var(--fg-muted);
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* replayed history turns (B5) — present but visually receded */
.cp-msg.cp-replay { opacity: 0.62; }

/* Progress narration beside the elapsed ticker (server-named stages). */
.cp-stage { color: var(--fg-muted); font-size: .78rem; margin-right: 6px; }
/* Source approval on the retrieved-article cards (opt-in host feature): the TILE is
   the toggle — a dropped card stays visible (provenance) but reads as excluded; the
   rerun action is the icon button in the pane header. */
.cp-card--off { opacity: .38; border-style: dashed; }
.cp-card--off:hover { opacity: .6; }
/* A low-confidence source is SHOWN, dimmed — never hidden. The cards are the answer's
   provenance, so removing one from view makes "what was this based on?" unanswerable,
   and makes source approval impossible: a card you cannot see is one you cannot untick. */
.cp-card--low { opacity: .62; }
.cp-card--low .cp-card-score { color: var(--fg-subtle, var(--fg-muted)); }

/* Page help — the [i] beside the header title. Anchored to the header so it sits in the same
   place on every page: a help affordance that moves is one people stop looking for. */
.page-help { position: relative; display: inline-flex; }
.page-help[hidden] { display: none; } /* the display above would override the attribute (HS8) */
.page-help-pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 60;
  width: 380px; max-width: calc(100vw - 32px); max-height: 60vh; overflow-y: auto;
  padding: 12px 14px; font-size: .84rem; line-height: 1.5; text-align: left;
  color: var(--fg); background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-md, 6px); box-shadow: var(--shadow-pop);
}
.page-help-pop[hidden] { display: none; }
.page-help-pop p { margin: 0 0 10px; }
.page-help-pop p:last-child { margin-bottom: 0; }
.page-help-pop ul { margin: 0 0 10px; padding-left: 18px; }
.page-help-pop code { background: var(--bg-input); padding: .1rem .3rem; border-radius: 3px;
  font-family: var(--font-mono); font-size: .95em; }

/* ── Form controls — the accepted control vocabulary ──────────────────────────
   docs/specs/ui-control-vocabulary/. A native <select> or checkbox paints OS chrome that
   ignores every token — the failure the 2026-09-15 scrollbar ruling already named, seen
   again as a blue checkbox on a dark theme. Tokens only, so these follow the theme. */

/* icon-push-toggle. aria-pressed IS the state, never a parallel data-* flag; the colour
   swap is the whole affordance (generalised from infra-forge .mf-template-toggle). */
.fui-toggle { color: var(--fg-muted); }
.fui-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

/* Segmented chips + loop share one markup: hidden radios carrying the data, labels
   carrying the look (generalised from iiriki .i2-mode-radio). */
.fui-chips, .fui-loop { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* Visually hidden, NOT display:none — the radio must keep its place in the tab order and
   stay arrow-key reachable, which is how a segmented control is operated without a mouse. */
.fui-chip-radio {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.fui-chip {
  display: inline-flex; align-items: center; padding: 3px 10px; cursor: pointer;
  font-size: var(--fs-sm); color: var(--fg-muted); background: var(--bg-input);
  border: 1px solid var(--border); border-radius: var(--r-pill);
}
.fui-chip:hover { border-color: var(--border-strong); }
.fui-chip-radio:checked + .fui-chip { color: var(--accent); border-color: var(--accent); }
/* Keyboard focus has to land somewhere visible once the input itself is hidden. */
.fui-chip-radio:focus-visible + .fui-chip { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The loop shows only the checked chip; its button advances to the next radio. */
.fui-loop .fui-chip { display: none; }
.fui-loop .fui-chip-radio:checked + .fui-chip { display: inline-flex; }

/* The global filter band (increment-prompt-band; lifted from ree-x .rx-filter-row): one row under
   the page title — the quick chips, the range control, apply and clear — wrapping only when the
   viewport is too narrow. A chip that is a link (the band's) marks the period in force with
   aria-current, the radio chip's checked look. Tokens only. */
.fui-prompt-band { margin: 0 0 12px; }
.fui-prompt-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.fui-prompt-field { display: flex; flex-direction: column; gap: 4px; flex: 0 1 auto; min-width: 0; }
.fui-prompt-label { font-size: var(--fs-sm); color: var(--fg-muted); }
.fui-prompt-band .fui-chips { min-height: 36px; }
a.fui-chip { text-decoration: none; }
a.fui-chip[aria-current="true"] { color: var(--accent); border-color: var(--accent); }
a.fui-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fui-prompt-actions { display: flex; align-items: center; gap: 6px; min-height: 36px; }
.fui-prompt-note { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; font-size: var(--fs-sm); color: var(--fg-muted); }

/* Inset form labels (increment-form-inset; ui_and_styling § Form fields). A form opts in with
   .form-inset: each .form-field puts its label INSIDE the control's top-left corner — static,
   never a floating placeholder — so a field costs one row of height, not two, and text, select,
   textarea and tom-select all read the same. The field's help is its data-tip, never a line under
   it. Lifted from infra-forge's components.css (the rule's reference) so the class contract has one
   home; consumers keep the class names. */
.form-inset .form-field { position: relative; }
.form-inset .form-field > label,
.form-inset label.form-field > span {
  position: absolute; top: 1px; left: 1px; right: 1px;
  padding: 3px 0 2px 10px;    /* the text keeps its 4px / 11px corner; the box covers the control's top padding */
  background: var(--bg-input); border-top-left-radius: var(--r-sm); border-top-right-radius: var(--r-sm);
                              /* FI7: opaque, so a scrolled textarea's text passes UNDER the label, never through
                                 it; FI9: it reaches the right edge — only a textarea's label stops short, below */
  z-index: 2;                 /* above tom-select's .ts-control (z-index 1) */
  font-size: var(--fs-xs); line-height: 1.2; color: var(--fg-muted);
  pointer-events: none;       /* a click lands on the control underneath */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.form-inset .form-field > input,
.form-inset .form-field > select,
.form-inset .form-field > textarea { padding: 19px 10px 5px; min-height: 44px; box-sizing: border-box;
  margin: 0; background: var(--bg-input); }  /* FI8: the label's own surface — a host's margin or background cannot split them */
/* FI9: a textarea scrolls — its label leaves the scrollbar visible. */
.form-inset .form-field:has(> textarea) > label { right: 12px; border-top-right-radius: 0; }
/* tom-select: four classes outrank the vendor's two or three, so no !important (infra-forge's
   copy needed it; the floor's own .ts-control has no padding rule to fight). */
.form-inset .form-field .ts-wrapper.single .ts-control,
.form-inset .form-field .ts-wrapper.multi .ts-control { padding: 17px 10px 3px; min-height: 44px; height: auto; }
.form-inset .form-field:focus-within > label,
.form-inset label.form-field:focus-within > span { color: var(--accent); }
/* A boolean in an inset form: the icon-push-toggle sits in the same box a text field draws. */
.form-inset .form-field-toggle {
  min-height: 44px; box-sizing: border-box;
  padding-top: 19px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px;
  border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-input);
}

/* ── tom-select option list — themed, resizable, scrollbar-clean ──────────────
   spec ui-control-vocabulary/increment-tomselect-resize.md (owner-accepted on pf-ui
   2026-09-28). The vendor sheet paints a white list; it is inserted BEFORE this sheet
   (form-controls.js) so these token rules win by cascade order, no !important. The
   scroll surface takes the `*` scrollbar default above — no .ts-* scrollbar rule.
   Resizing is a CUSTOM grip (.ts-resize-grip, appended by form-controls.js): the
   browser's `resize` corner is cancelled by tom-select's document mousedown handler. */
/* The control box: the vendor paints it light too. Hoisted from iiriki's app.css token bridge
   (TS17) so every consumer's chooser is themed, not only its option list. */
.ts-wrapper .ts-control {
  background-color: var(--bg-input); border-color: var(--border); color: var(--fg);
  border-radius: var(--r-sm);
}
.ts-wrapper.focus .ts-control { border-color: var(--accent); }
.ts-wrapper.multi .ts-control > div {
  background: var(--bg-card); border-color: var(--border); color: var(--fg);
  border-radius: var(--r-sm);
}
.ts-wrapper.multi .ts-control > div.active {
  background: rgba(var(--accent-rgb), .18); border-color: var(--accent); color: var(--fg);
}
.ts-control > input { color: var(--fg); }
.ts-dropdown {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--r-sm) var(--r-sm);
  color: var(--fg);
  overflow: hidden;            /* the box the grip sizes; the content scrolls */
  max-width: 90vw;
  max-height: 85vh;
}
/* The width floor belongs ONLY to the default parent (R-W1). tom-select appends the list to its
   own wrapper — `K(n.dropdownParent || r).appendChild(a)` — so there 100% IS the control's width,
   which is the intent. With `dropdownParent: 'body'` the same declaration resolves against the
   PAGE, and it wins: tom-select writes the control's width on a detached list inline, but
   min-width is a used-value constraint, not a cascade participant, so it outranks an inline width
   at any specificity. Live result before this was scoped: a 288px control, an 1100px list. */
.ts-wrapper > .ts-dropdown { min-width: 100%; }
.ts-dropdown-content { max-height: 320px; } /* modest default — never viewport-tall */
/* user-sized (inline height present): the list fills the box the user chose */
.ts-dropdown[style*="height"] .ts-dropdown-content { max-height: none; height: 100%; }
.ts-dropdown .option { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ts-dropdown .option.active, .ts-dropdown .option:hover { background: var(--bg-hover); color: var(--fg); }
.ts-dropdown .option.selected { color: var(--accent); }
.ts-dropdown .optgroup-header { background: var(--bg-card); color: var(--fg-muted); font-size: .8em; text-transform: uppercase; letter-spacing: .04em; }
.ts-dropdown .no-results { color: var(--fg-muted); }
.ts-dropdown [data-selectable] .highlight { background: var(--bg-hover); }
.ts-resize-grip {
  position: absolute; right: 0; bottom: 0; width: 16px; height: 16px;
  cursor: nwse-resize; touch-action: none; z-index: 1;
  color: var(--fg-muted);
  /* two diagonal strokes in currentColor — a themed replacement for the OS corner */
  background: linear-gradient(135deg, transparent 0 52%, currentColor 52% 60%, transparent 60% 72%, currentColor 72% 80%, transparent 80%);
}
.ts-resize-grip:hover { color: var(--fg); }

/* ── ui-probe — annotate mode (spec ui-control-vocabulary/increment-ui-probe.md) ──
   Off unless asked for. The layer is absolutely positioned and pointer-transparent, so
   annotating a page never reflows or blocks the layout being diagnosed. */
.fui-probe-layer { position: absolute; inset: 0; pointer-events: none; z-index: 9999; }
.fui-probe-tag {
  position: absolute; pointer-events: none; padding: 0 4px;
  font-family: var(--font-mono); font-size: 10px; line-height: 14px; white-space: nowrap;
  color: var(--accent-fg); background: var(--accent); border-radius: var(--r-xs);
  opacity: .92;
}
