:root {
  /* F8b restyle (HaloB PTL F8b, marketing strategy section 2A): one dark-first
     palette shared with the Halo website. Dark by default; a light variant follows the OS (founder 2026-11-15). */
  color-scheme: light dark;
  --bg: #070b16;
  --fg: #e8ecf6;
  --muted: #a8b2ca;
  --border: rgba(160, 185, 255, 0.16);
  --control-border: rgba(160, 185, 255, 0.5);
  --accent: #7cc4ff;
  --accent-fg: #04121c;
  --sidebar-bg: rgba(12, 18, 34, 0.72);
  --danger: #f87171;
  --panel: rgba(15, 22, 40, 0.62);
  --panel-solid: #0d1426;
  --gold: #fbbf24;
  --violet: #b79cff;
  --ok: #4ade9f;
  --radius: 14px;
  --warning-bg: #3b2f12;
  --warning-fg: #f6dd9a;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.centered {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.centered h1 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.centered p { margin: 0; color: var(--muted); max-width: 28rem; }

.chat-layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.signed-in-as {
  margin: 0;
  padding: 0.5rem 0.75rem 0;
  font-size: 0.8rem;
  overflow-wrap: anywhere;
}

.sidebar-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header button {
  flex: 1;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
}

#thread-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
}

#thread-list li {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#thread-list li.active,
#thread-list li:hover {
  background: var(--border);
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.message {
  max-width: 70%;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-fg);
}

.message-assistant {
  align-self: flex-start;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
}

/* A send failure, rendered inline in the conversation but never
   persisted as a message (app.js's showSendFailure). */
.message-error {
  align-self: center;
  max-width: 90%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* The in-flight "Working... (N s)" row (app.js's startWorkingIndicator);
   removed on success and failure, never persisted. */
.message-working {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
}

.message-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
}

.message-form input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.95rem;
}

.message-form button {
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.95rem;
  cursor: pointer;
}

.message-form button:disabled {
  opacity: 0.6;
  cursor: default;
}

.storage-warning {
  margin: 0.5rem 1rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--warning-bg, #4a3a1a);
  color: var(--warning-fg, #f0d9a0);
  font-size: 0.85rem;
}

.history-notice {
  margin: 0.5rem 1rem 0;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.welcome-panel {
  margin: 0.75rem 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.welcome-panel p {
  margin: 0 0 0.5rem;
  color: var(--fg);
}

.welcome-panel p:last-of-type {
  margin-bottom: 0.75rem;
}

.welcome-starter-heading {
  font-weight: 600;
}

.welcome-panel button {
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.error-recovery-action {
  margin-top: 0.75rem !important;
  font-size: 0.85rem;
}

/* --- Projects (build spec §10) ----------------------------------------- */

.projects-section {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-heading {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.project-switcher {
  display: flex;
  gap: 0.4rem;
}

.project-switcher select {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  font-size: 0.85rem;
}

.project-switcher button {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.project-actions {
  display: flex;
  gap: 0.4rem;
}

.project-actions button {
  flex: 1;
  padding: 0.3rem 0.4rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  border-radius: 6px;
  cursor: pointer;
}

.project-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}

.project-file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 8rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.project-file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.8rem;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  background: var(--sidebar-bg);
}

.project-file-list .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-file-list .file-status {
  color: var(--muted);
  font-size: 0.7rem;
  flex-shrink: 0;
}

.project-file-list button,
.attachment-list button,
.share-list button {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0 0.2rem;
  flex-shrink: 0;
}

.file-upload-label {
  display: block;
  text-align: center;
  padding: 0.4rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.upload-status {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

/* --- Per-conversation attachments (build spec §10) ---------------------- */

.attachment-bar {
  padding: 0.4rem 1rem 0;
}

.attachment-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.attachment-list li {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.attachment-list .attachment-status-failed {
  color: #b91c1c;
}

.attachment-upload-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.5rem;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

/* --- Share dialog (build spec §10) -------------------------------------- */

.share-dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  padding: 1rem;
  width: min(22rem, 90vw);
}

.share-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

.share-dialog h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.share-dialog-subtitle {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.share-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
  max-height: 10rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.share-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.25rem 0.4rem;
  border-radius: 5px;
  background: var(--sidebar-bg);
  font-size: 0.85rem;
}

.share-add-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.share-add-row select {
  flex: 1;
  min-width: 0;
  padding: 0.35rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.share-add-row button,
.share-dialog-actions button {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.share-dialog-actions {
  display: flex;
  justify-content: flex-end;
}

/* --- Admin metrics (guard-local metrics scope doc §3 step 5) ----------- */

.admin-metrics {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.admin-metrics-tabs {
  display: flex;
  gap: 0.4rem;
}

.admin-metrics-tab {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
}

.admin-metrics-tab.active {
  color: var(--fg);
  font-weight: 600;
}

.admin-metrics-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.5rem;
}

.admin-metrics-dl dt {
  color: var(--muted);
}

.admin-metrics-dl dd {
  margin: 0;
}

.admin-metrics-dl dd.admin-metrics-backup-error {
  color: var(--danger);
}

.admin-metrics-empty,
.admin-metrics-note {
  color: var(--muted);
  margin: 0;
}

.admin-metrics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.admin-metrics-table th,
.admin-metrics-table td {
  text-align: left;
  padding: 0.2rem 0.3rem;
  border-bottom: 1px solid var(--border);
}

.escrow-panel {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.85rem;
}

/* `display: flex` above (and on .escrow-reenroll-banner) outranks the
   UA stylesheet's [hidden] rule, so without this the owner-only panels and
   the banners render for every session regardless of `hidden`. */
.escrow-panel[hidden],
.escrow-reenroll-banner[hidden],
.admin-metrics[hidden],
.chat-layout[hidden],
.projects-section[hidden],
.attachment-upload-label[hidden] {
  display: none;
}

.escrow-file-label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.escrow-reenroll-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: #78350f;
  color: #fef3c7;
  font-size: 0.85rem;
}

.escrow-reenroll-banner span {
  flex: 1;
}

.escrow-reenroll-banner button {
  flex-shrink: 0;
}

.escrow-reenroll-help {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* False-refusal reporting (app.js's showSendFailure / renderAdminMetricsSafety). */
.refusal-report {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.refusal-report-button {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}

.refusal-report-button:disabled {
  color: var(--muted);
  cursor: default;
}

.admin-metrics-safety-window-heading {
  margin: 0.5rem 0 0.2rem;
  font-size: 0.85rem;
}


/* ==== F8b restyle: halo backdrop, glass panels, calmer chat (CSS only; every id, class hook and script is unchanged) ==== */

body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

/* The halo ring behind everything, quiet enough not to compete with text. Workspace page only: the unlock and Restore-B pages
   share this file and their CSP has no img-src, so an unscoped url() there is a blocked load. */
body.workspace::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("halo-bg.jpg") 60% 55% / cover no-repeat;
  opacity: 0.2;
  pointer-events: none;
}

.centered h1 { font-size: 1.6rem; letter-spacing: -0.02em; }
.centered p { line-height: 1.6; }
.centered button,
.escrow-reenroll-banner button,
.welcome-panel button {
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.centered button:hover,
.welcome-panel button:hover { border-color: var(--accent); }
.centered a, .sidebar-link a { color: var(--accent); }

/* sidebar */
.sidebar {
  width: 272px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0.9rem 0.2rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.01em;
}
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--gold); flex: none; }
.signed-in-as { color: var(--muted); padding: 0 0.9rem 0.6rem; }
.sidebar-header { flex-wrap: wrap; border-bottom-color: var(--border); }
.sidebar-header button,
.project-switcher button,
.project-actions button,
.refusal-report-button {
  border-color: var(--control-border);
  background: var(--panel);
  border-radius: 10px;
}
.sidebar-header button:hover,
.project-switcher button:hover,
.project-actions button:hover:not(:disabled) { border-color: var(--accent); }
#new-thread-button {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-weight: 600;
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}
#sign-out-clear-button { flex-basis: 100%; color: var(--muted); font-size: 0.78rem; }
.sidebar-link { margin: 0; padding: 0.5rem 0.9rem; font-size: 0.85rem; }
#thread-list li { border-radius: 10px; }
#thread-list li.thread-group { padding: 0; cursor: default; background: transparent; overflow: visible; }
#thread-list li.thread-group:hover { background: transparent; }
.thread-group-items { list-style: none; margin: 0; padding: 0; }
#thread-list .thread-group-items li { padding: 0; overflow: visible; cursor: default; background: transparent; }
#thread-list .thread-group-items li:hover { background: transparent; }
.thread-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.thread-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--fg); }
.thread-item:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); color: var(--fg); }
.thread-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.sidebar-heading { letter-spacing: 0.12em; font-size: 0.68rem; }
.projects-section, .admin-metrics, .escrow-panel {
  margin: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.project-switcher select,
.admin-metrics select,
.escrow-panel select {
  border-color: var(--border);
  border-radius: 10px;
  background: var(--panel-solid);
  color: var(--fg);
}
.project-file-list li { background: color-mix(in srgb, var(--fg) 5%, transparent); }
.file-upload-label { border-radius: 10px; }
.file-upload-label:hover { border-color: var(--accent); color: var(--fg); }

/* chat column */
.chat-main { align-items: stretch; }
.message-list {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem;
  gap: 0.9rem;
}
.message {
  max-width: min(720px, 88%);
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  line-height: 1.6;
}
.message-user {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  color: var(--fg);
  border-top-right-radius: 4px;
}
.message-assistant {
  background: var(--panel);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}
.message-error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); color: var(--danger); background: var(--panel); }

.message-form {
  width: calc(100% - 2.5rem);
  max-width: 780px;
  margin: 0 auto 1.25rem;
  padding: 0.6rem 0.7rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 10px 40px rgba(0, 0, 20, 0.35);
}
.message-form:focus-within {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent), 0 10px 40px rgba(0, 0, 20, 0.35);
}
.message-form input,
.message-form textarea {
  border: 0;
  background: transparent;
  outline: none;
  padding: 0.5rem 0.4rem;
}
.message-form input::placeholder, .message-form textarea::placeholder { color: var(--muted); }
.message-form button {
  border-radius: 12px;
  padding: 0.55rem 1.2rem;
  font-weight: 650;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  color: var(--accent-fg);
}
.attachment-bar { max-width: 780px; width: 100%; margin: 0 auto; padding: 0.4rem 1.25rem 0; }
.attachment-list .attachment-status-failed { color: var(--danger); }
.storage-warning, .history-notice, .welcome-panel {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
  border-radius: var(--radius);
}
.welcome-panel, .history-notice { background: var(--panel); border-color: var(--border); }

/* banners */
.escrow-reenroll-banner { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }

@media (max-width: 760px) {
  .message { max-width: 94%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ==== F8b Phase B: admin drawer (CSS-only toggle; panels keep their ids and their hidden-until-200 behaviour) ==== */

.admin-drawer-toggle {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
/* The sidebar entry shows only while at least one admin panel has been unhidden by a real 200 fetch. */
/* Fallback first: a browser without :has() (Firefox before 121) shows the entry to everyone, so the owner panels stay reachable;
   modern browsers hide it for members, who have no unhidden admin panel. */
.admin-toggle { display: block; }
.chat-layout:not(:has(.admin-drawer > section:not([hidden]))) .admin-toggle { display: none; }
.admin-toggle label {
  display: block;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.admin-toggle label:hover { border-color: var(--accent); }
.chat-layout:has(.admin-drawer-toggle:focus-visible) .admin-toggle label { outline: 2px solid var(--accent); outline-offset: 2px; }

.admin-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  width: min(460px, 100vw);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 0.4rem 1.5rem;
  background: var(--sidebar-bg);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border-left: 1px solid var(--border);
  box-shadow: -20px 0 60px rgba(0, 0, 20, 0.4);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.admin-drawer-toggle:checked ~ .admin-drawer {
  transform: none;
  visibility: visible;
  transition: transform 0.25s ease;
}
.admin-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(2, 4, 10, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0s linear 0.25s;
}
.admin-drawer-toggle:checked ~ .admin-drawer-backdrop {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s ease;
}
.admin-drawer-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 0.8rem 0.6rem;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}
.admin-drawer-close {
  background: transparent;
  font: inherit;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.admin-drawer-close:hover { color: var(--fg); border-color: var(--accent); }
.admin-drawer-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.admin-drawer .admin-metrics,
.admin-drawer .escrow-panel { margin: 0.75rem 0.4rem; padding: 0.9rem; }
.admin-metrics-tabs { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.admin-metrics-tab {
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.admin-metrics-tab.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--fg); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.admin-drawer .admin-metrics-table { width: 100%; font-size: 0.78rem; }
.admin-drawer input[type="file"], .admin-drawer input[type="password"] { max-width: 100%; }
.admin-drawer .escrow-panel button,
.admin-drawer .admin-metrics > button,
.admin-drawer .restore-panel button {
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-solid);
  color: var(--fg);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.admin-drawer .escrow-panel button:hover:not(:disabled) { border-color: var(--accent); }
.admin-drawer .escrow-panel button:disabled { opacity: 0.5; cursor: default; }
.admin-drawer input[type="file"] { color: var(--muted); font-size: 0.8rem; }
.admin-drawer input[type="file"]::file-selector-button {
  margin-right: 0.6rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--fg);
  font: inherit;
  cursor: pointer;
}
.admin-drawer input[type="password"], .admin-drawer select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-solid);
  color: var(--fg);
}

/* Workspace keys link, moved from the sidebar into the Admin drawer (owner only). Shown by default so a browser without :has()
   still reaches it; hidden whenever the escrow panel (owner-only) is not unhidden. */
.drawer-keys-link { margin: 0.75rem 0.8rem 0; font-size: 0.85rem; }
.drawer-keys-link a { color: var(--accent); font-weight: 600; }
.drawer-keys-link span { display: block; color: var(--muted); font-size: 0.78rem; }
.admin-drawer:has(#escrow-panel[hidden]) .drawer-keys-link { display: none; }

/* Sidebar session groups and search (F8b follow-on; reversible with the logic.js / app.js block) */
.thread-search {
  margin: 0.4rem 0.6rem 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--fg) 5%, transparent);
  color: var(--fg);
  font: inherit;
  font-size: 0.85rem;
  outline: none;
}
.thread-search { border-color: var(--control-border); }
.thread-search::placeholder { color: var(--muted); }
.thread-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#thread-list .thread-group-label,
#thread-list li.thread-empty {
  margin: 0;
  font-weight: 400;
  padding: 0.9rem 0.6rem 0.25rem;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: default;
  pointer-events: none;
}
#thread-list li.thread-empty { text-transform: none; letter-spacing: 0; font-size: 0.85rem; }

/* ==== F8b phone layout (design critique must-fix 1): off-canvas sidebar below 760px, CSS-only toggle ==== */
.nav-drawer-toggle { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
/* Desktop: the toggle does nothing, so it is no tab stop either (it is shown again below 760px). */
.nav-drawer-toggle, .nav-drawer-backdrop, .nav-open { display: none; }
@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 25;
    width: min(86vw, 300px);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
  }
  .nav-drawer-toggle:checked ~ .sidebar { transform: none; visibility: visible; transition: transform 0.25s ease; }
  .nav-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 24;
    background: rgba(2, 4, 10, 0.55);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
  }
  .nav-drawer-toggle:checked ~ .nav-drawer-backdrop { opacity: 1; visibility: visible; transition: opacity 0.25s ease; }
  .nav-drawer-toggle { display: block; }
  .nav-open { display: block; margin: 0; padding: 0.6rem 0.8rem 0; }
  .nav-open label {
    display: inline-block;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--control-border);
    border-radius: 10px;
    background: var(--panel);
    color: var(--accent);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
  }
  .chat-layout:has(.nav-drawer-toggle:focus-visible) .nav-open label { outline: 2px solid var(--accent); outline-offset: 2px; }
}

/* F8b should-fix 5: the destructive action lives in a footer, away from New chat */
.sidebar-footer { margin-top: auto; padding: 0.75rem; border-top: 1px solid var(--border); }
.sidebar-footer #sign-out-clear-button { width: 100%; padding: 0.45rem 0.7rem; border: 1px solid var(--control-border); border-radius: 10px; background: var(--panel); color: var(--muted); font: inherit; font-size: 0.78rem; cursor: pointer; }
.sidebar-footer #sign-out-clear-button:hover { border-color: var(--accent); color: var(--fg); }
.sidebar #thread-list { flex: 1 1 auto; min-height: 8rem; }

/* ==== F8b light theme: follows the OS (prefers-color-scheme). Tokens only; the ring backdrop is inverted to dark-on-light. ==== */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5fb;
    --fg: #121a2e;
    --muted: #46506a;
    --border: rgba(30, 50, 110, 0.16);
    --control-border: rgba(30, 50, 110, 0.56); /* 3.2:1 on --bg, the 3:1 control floor */
    --accent: #135a9c;
    --accent-fg: #ffffff;
    --sidebar-bg: rgba(255, 255, 255, 0.72);
    --danger: #b42318;
    --panel: rgba(255, 255, 255, 0.74);
    --panel-solid: #ffffff;
    --gold: #b7791f;
    --violet: #5b3fc8;
    --ok: #0f7a55;
    --warning-bg: #fff1c7;
    --warning-fg: #5c3d00;
  }
  body.workspace::before { filter: invert(1); opacity: 0.16; }
  .admin-drawer-backdrop, .nav-drawer-backdrop { background: rgba(20, 28, 50, 0.35); }
  .admin-drawer { box-shadow: -20px 0 60px rgba(20, 28, 50, 0.18); }
}

.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.message-form textarea {
  flex: 1;
  resize: none;
  max-height: 40vh;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--fg);
}
.icon-clip { display: block; color: var(--muted); }
.attachment-upload-label:hover .icon-clip { color: var(--accent); }
