/* Bounded answer surfaces: metadata and controls never scroll with the answer. */
.shell { overflow: clip; }
.topbar { min-width: 0; }
.view-mode-switcher { min-width: 0; flex: 0 0 auto; overflow: visible; }
.mode-tab { flex: 0 0 auto; }
.topbar > button { flex-shrink: 0; }
#mode-companion::before, #mode-companion::after { display: none; }
#mode-companion { box-shadow: none; animation: none; }
.arena-card.result-card, .message.assistant.result-card {
  display: flex; flex-direction: column; height: 540px; min-height: 0;
  max-height: none; overflow: hidden; min-width: 0; box-shadow: none;
}
.arena-card.result-expanded, .message.assistant.result-expanded { height: 760px; }
.result-card > header, .result-card .arena-card-head { flex: 0 0 auto; position: relative; padding: 12px 16px; gap: 6px; }
.result-expand { align-self: flex-start; padding: 5px 10px; border: 1px solid var(--line); border-radius: 5px; font: 12px var(--sans); color: var(--text); background: var(--raised); cursor: pointer; }
.result-metrics { flex: 0 0 auto; padding: 8px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font: 12px/1.65 var(--sans); overflow-wrap: anywhere; }
.result-card .arena-answer-window, .result-card .message-answer-window,
[data-theme="light"] .result-card .arena-answer-window, [data-theme="light"] .result-card .message-answer-window {
  display: block; flex: 1 1 0; min-height: 80px; height: auto; max-height: none;
  overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-gutter: stable;
}
.result-card .arena-card-body { display: block; padding: 12px 16px 24px; overflow: visible; min-height: 0; }
.result-card .message-body { overflow-wrap: anywhere; min-width: 0; }
.message.assistant.result-card .message-answer-window { padding: 0 12px 20px; }
.result-card > .response-actions-toolbar, .result-card .arena-bottom-dock { flex: 0 0 auto; }
.result-card .response-actions-toolbar { margin: 0; padding: 8px 0; }
.result-card .message-body > :last-child { margin-bottom: 16px; }
.result-card .run-telemetry { border-color: var(--line); }
.arena-comparison, .arena-evaluation { flex: 0 0 auto; margin-top: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; font: 13px/1.6 var(--sans); color: var(--text); }
.arena-comparison h3 { margin: 0 0 10px; }
.comparison-table { overflow-x: auto; }
.comparison-table table { border-collapse: collapse; width: 100%; font-size: 12px; }
.comparison-table td, .comparison-table th { padding: 8px; text-align: left; border-bottom: 1px solid var(--line); }
.arena-evaluation label { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.arena-evaluation input, .arena-evaluation textarea { padding: 8px; width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 4px; }
.arena-evaluation fieldset { min-width: 0; margin: 10px 0; border: 1px solid var(--line); }
.plugin-popover { width: min(460px, calc(100vw - 32px)); max-height: min(600px, 70dvh); overflow-y: auto; color: var(--text); background: var(--bg); }
#plugin-popover { position: fixed !important; left: var(--plugin-left, 8px) !important; right: auto !important; bottom: var(--plugin-bottom, 70px) !important; width: min(460px, calc(100vw - 16px)) !important; max-height: min(600px, var(--plugin-height, 70dvh)); z-index: 110; }
.composer-area { position: relative; z-index: 12; }
.composer { overflow: visible; }
.plugin-popover .plugin-grid { display: grid; grid-template-columns: 1fr; gap: 6px; }
.plugin-popover .plugin-item { display: grid; grid-template-columns: 1fr auto; text-align: left; white-space: normal; color: var(--text); }
.plugin-item small { grid-column: 1 / -1; color: var(--muted); }
.plugin-item span { font-size: 11px; color: var(--muted); }
.plugin-status { font: 12px/1.5 var(--sans); padding: 8px; }
.plugin-popover > button { margin: 8px; }
#plugin-popover { display: flex; flex-direction: column; overflow: hidden; padding: 12px; }
#plugin-popover .plugin-popover-head { flex: 0 0 auto; margin-bottom: 10px; }
.plugin-filters { display: grid; grid-template-columns: minmax(0, 1fr) 160px; gap: 8px; margin-bottom: 10px; flex-shrink: 0; }
.plugin-filters input, .plugin-filters select { min-width: 0; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--text); font: 12px var(--sans); }
#plugin-popover .plugin-grid { display: block; flex: 1 1 auto; min-height: 0; max-height: none !important; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.plugin-category { margin-bottom: 12px; }
.plugin-category > h3 { margin: 8px 4px; font: 600 11px var(--sans); color: var(--muted); letter-spacing: .03em; }
#plugin-popover .plugin-item { width: 100%; display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 7px; border: 1px solid transparent; border-radius: 8px; background: transparent; transform: none; }
#plugin-popover .plugin-item:hover { background: var(--raised); border-color: var(--line); }
#plugin-popover .plugin-copy { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
#plugin-popover .plugin-copy strong { color: var(--text); font: 600 13px/1.3 var(--sans); }
#plugin-popover .plugin-copy small { color: var(--muted); font: 11px/1.5 var(--sans); }
#plugin-popover .plugin-state { color: var(--muted); font: 10px/1.4 var(--sans); max-width: 82px; text-align: right; }
#plugin-popover .plugin-state[data-state=available], #plugin-popover .plugin-state[data-state=configured] { color: var(--green); }
#plugin-popover .plugin-icon { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 38px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--raised); overflow: hidden; }
#plugin-popover .plugin-icon-brand { background: #fff; border-color: #dce2eb; }
.plugin-icon svg { width: 23px; height: 23px; }
.plugin-icon img { display: block; width: 28px; height: 28px; object-fit: contain; }
.plugin-back { align-self: flex-start; flex-shrink: 0; margin: 0 0 10px !important; padding: 6px 8px; font: 12px var(--sans); }
.plugin-setup-heading { display: flex; align-items: center; gap: 12px; margin: 8px 0 16px; }
.plugin-setup-heading h3 { margin: 0; font-size: 16px; }
.plugin-setup p { font: 13px/1.65 var(--sans); }
.plugin-setup a { display: block; color: var(--cyan); margin: 14px 0; }
.plugin-status { flex-shrink: 0; margin: 8px 0 0; padding: 8px 0; border-top: 1px solid var(--line); }
.plugin-empty { padding: 16px 8px; color: var(--muted); font-size: 13px; }
.plugin-runner label { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; font: 12px/1.5 var(--sans); }
.plugin-runner input, .plugin-runner select { width: 100%; min-width: 0; padding: 9px; color: var(--text); background: var(--raised); border: 1px solid var(--line); border-radius: 6px; }
.plugin-runner button { padding: 8px 12px; color: var(--text); background: var(--raised); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.plugin-runner button:disabled { opacity: .5; cursor: default; }
.plugin-runner-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.plugin-runner .plugin-runner-note { font: 11px/1.5 var(--sans); color: var(--muted); }
.plugin-runner p { overflow-wrap: anywhere; }
.google-connect { margin: 18px 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.google-connect h3 { margin: 0 0 8px; }
.google-connect details { margin: 12px 0; }
.google-connect summary { cursor: pointer; }
.google-connect code { display: block; overflow-wrap: anywhere; margin: 8px 0; }
.google-connect a { display: inline-block; margin: 8px 0; color: var(--text); text-decoration: underline; }
.google-connect > button { margin: 4px 6px 4px 0; }
.plugin-results pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 10px; border: 1px solid var(--line); border-radius: 6px; font: 12px/1.6 var(--sans); }
@media (max-width: 480px) { .plugin-filters { grid-template-columns: 1fr; } }
.result-expand:focus-visible, .result-card [tabindex]:focus-visible, .plugin-popover :focus-visible,
.arena-evaluation :focus-visible, #richard-panel :focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* Reserve space only while the nonmodal avatar is open. */
body.avatar-open .main { margin-right: 336px; }
#richard-panel { position: fixed; inset: 72px 12px auto auto; margin: 0; width: 320px; min-width: 270px; min-height: 280px; max-height: calc(100dvh - 88px); padding: 12px; z-index: 20; border-radius: 16px; background: var(--bg); color: var(--text); box-shadow: 0 8px 32px #0004; overflow-y: auto; pointer-events: auto; resize: both; }
#richard-panel .richard-header { position: sticky; top: -12px; padding: 6px 0; z-index: 2; background: var(--bg); cursor: grab; user-select: none; }
#richard-panel .richard-stage { width: 150px; margin: 6px auto; box-shadow: inset 0 0 14px #00f2fe30; overflow: hidden; pointer-events: auto; border-radius: 50%; }
.richard-orbit, .richard-face, .richard-stage::before, .richard-stage::after { pointer-events: none; }
.richard-response-telemetry { font: 11px/1.5 var(--sans); padding: 8px; color: var(--muted); border-bottom: 1px solid var(--line); }
#richard-response { height: 160px; overflow-y: auto; overscroll-behavior: contain; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.65 var(--sans); padding: 10px 6px; }
#richard-text { height: 88px; max-height: 160px; overflow-y: auto; }
.live-transcript-card { max-height: 300px; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.live-transcript-role { flex-shrink: 0; }
.live-transcript-body { max-height: 220px; overflow-y: auto; overscroll-behavior: contain; white-space: pre-wrap; }
@media (max-width: 1100px) {
  .topbar .breadcrumb, .topbar #theme-label { display: none; }
  body.avatar-open .main { margin-right: 0; }
  #richard-panel { position: relative; inset: auto; width: calc(100% - 24px); max-height: 240px; flex: 0 0 auto; margin: 8px 12px; z-index: 10; }
  #richard-panel .richard-stage { float: right; width: 56px; margin: 4px; }
}
@media (min-width: 769px) and (max-width: 960px) {
  .shell.no-sidebar .main, .shell.no-sidebar .topbar { grid-column: 1 / -1; }
}
@media (max-width: 600px) {
  .arena-card.result-card, .message.assistant.result-card { height: 490px; }
  .arena-card.result-expanded, .message.assistant.result-expanded { height: 680px; }
  .result-card .arena-card-head, .result-metrics { padding-left: 10px; padding-right: 10px; }
  .result-metrics { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  #richard-panel *, #richard-launcher, .result-card { animation: none !important; transition: none !important; scroll-behavior: auto; }
}
@media print {
  .result-card, .result-card .message-answer-window, .result-card .arena-answer-window { display: block !important; height: auto !important; max-height: none !important; overflow: visible !important; }
  .result-expand { display: none !important; }
}

/* Dense reading surfaces remain opaque, without nested backdrop blur. */
.arena-card.result-card, .message.assistant.result-card {
  background:var(--surface-strong);color:var(--text);border:1px solid var(--line);border-radius:10px;
  backdrop-filter:none;-webkit-backdrop-filter:none;
}
.message.user { background:var(--surface-soft);color:var(--text);border:1px solid var(--line);border-radius:10px; }
.result-metrics { border-color:var(--line); }
.result-expand { min-height:28px;height:28px;padding:2px 8px;font-size:11px;border-radius:6px; }
#richard-panel { border-radius:12px;background:var(--surface-strong);border-color:var(--line);box-shadow:var(--glass-shadow);backdrop-filter:none;-webkit-backdrop-filter:none; }
#richard-panel .richard-header { background:var(--surface-strong); }

/* Compact Synchronized Response Toolbars (Top & Bottom) */
.response-actions-toolbar {
  display: flex !important;
  align-items: center !important;
  gap: 5px !important;
  padding: 4px 12px !important;
  min-height: 28px !important;
  border: 0 !important;
  background: transparent !important;
  flex-wrap: nowrap !important;
  overflow-x: auto;
  scrollbar-width: none;
}
.response-actions-toolbar::-webkit-scrollbar { display: none; }
.response-actions-toolbar.toolbar-top {
  border-bottom: 1px solid var(--line) !important;
  margin-bottom: 4px !important;
  padding-bottom: 6px !important;
}
.response-actions-toolbar.toolbar-bottom {
  border-top: 1px solid var(--line) !important;
  margin-top: 4px !important;
  padding-top: 6px !important;
}
.response-actions-toolbar .response-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  height: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  padding: 2px 8px !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  border-radius: 6px !important;
  border: 1px solid var(--line) !important;
  background: var(--raised) !important;
  color: var(--text) !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.15s ease !important;
  line-height: 1 !important;
}
.response-actions-toolbar .response-btn:hover {
  background: var(--hover) !important;
  border-color: var(--cyan) !important;
  color: var(--text-bright) !important;
}
.response-actions-toolbar .response-btn .icon-2d {
  width: 12px !important;
  height: 12px !important;
  flex-shrink: 0;
}
.response-actions-toolbar .response-overflow-btn {
  min-width: 28px !important;
  width: 28px !important;
  padding: 0 !important;
}
.response-export-options {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 180px;
  max-width: min(300px, calc(100vw - 16px));
  max-height: min(340px, 70vh);
  overflow-y: auto;
  padding: 6px;
  z-index: 120;
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--glass-shadow);
}
.response-export-options[hidden] { display: none; }
.response-export-options .response-btn {
  width: 100%;
  min-height: 28px;
  height: 28px;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: 11px var(--sans, sans-serif);
  cursor: pointer;
}
.response-export-options .response-btn:hover { background: var(--hover); }

/* Document Type Export Dialog */
dialog.b1x-export-dialog {
  padding: 16px 20px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-strong, var(--bg));
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  max-width: 440px;
  width: calc(100vw - 32px);
  z-index: 1000;
}
dialog.b1x-export-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.export-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.export-dialog-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
}
.export-dialog-head .icon {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.export-dialog-head .icon:hover { color: var(--text); background: var(--hover); }
.export-dialog-subtitle {
  font-size: 11px;
  color: var(--muted);
  margin: 0 0 12px;
}
.export-format-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.export-format-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
}
.export-format-item:hover {
  background: var(--hover);
  border-color: var(--cyan);
  transform: translateY(-1px);
}
.export-format-item svg {
  width: 18px;
  height: 18px;
  stroke: var(--cyan);
  flex-shrink: 0;
}
.export-format-meta strong {
  display: block;
  font-size: 12px;
  color: var(--text-bright);
}
.export-format-meta small {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
}

/* Compact meta-row: status dot, one-line summary, chevron details. */
.result-metrics { padding: 0; }
.result-metrics > summary { list-style: none; }
.result-metrics > summary::-webkit-details-marker { display: none; }
.result-meta-toggle { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 16px; cursor: pointer; color: var(--muted); font: 12px/1.4 var(--sans); }
.result-meta-toggle:hover { color: var(--text); }
.result-meta-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--cyan); }
.result-metrics[data-state="completed"] .result-meta-dot { background: var(--green); }
.result-metrics[data-state="failed"] .result-meta-dot { background: var(--red); }
.result-metrics[data-state="partial"] .result-meta-dot { background: var(--amber); }
.result-metrics[data-state="active"] .result-meta-dot { background: var(--cyan); animation: result-dot-pulse 1.6s ease-in-out infinite; }
@keyframes result-dot-pulse { 50% { opacity: .3; } }
.result-meta-line { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-chevron { flex: 0 0 auto; width: 14px; height: 14px; transition: transform .16s ease; }
.result-metrics[open] .result-chevron { transform: rotate(90deg); }
.result-detail-body { display: grid; gap: 4px; padding: 2px 16px 10px; border-top: 1px dashed var(--line); color: var(--muted); font: 12px/1.6 var(--sans); overflow-wrap: anywhere; }

/* Short answers read fully inline; expansion is only offered for long ones. */
.arena-card.result-card.result-short, .message.assistant.result-card.result-short { height: auto; }
.result-card.result-short .result-expand { display: none; }
.result-card.result-short .arena-answer-window, .result-card.result-short .message-answer-window { flex: 0 1 auto; min-height: 0; }
.result-expand { display: inline-flex; align-items: center; gap: 6px; }
.result-expand .icon-2d { width: 15px; height: 15px; }
@media (prefers-reduced-motion: reduce) {
  .result-meta-dot, .result-chevron { animation: none !important; transition: none !important; }
}
@media (max-width: 600px) {
  .result-meta-toggle { padding-left: 10px; padding-right: 10px; }
  .result-detail-body { padding-left: 10px; padding-right: 10px; }
}

/* Answer action toolbar (chat answers): one compact, left-aligned row of
   uniform buttons — Expand, Copy, Download, PDF, DOCX, ⋯ — at the top and
   bottom of every answer. The header Expand (.result-expand) that
   result-card.js moves into the top toolbar replaces the toolbar's own
   .btn-expand there, so Expand appears once. Short answers hide
   .result-expand, so .btn-expand stays visible for them. */
:root[data-theme] #shell .message.assistant .response-actions-toolbar {
  justify-content: flex-start !important;
  gap: 4px !important;
}
:root[data-theme] #shell .message.assistant:not(.result-short) .response-actions-toolbar:has(> .result-expand) > .btn-expand {
  display: none !important;
}
:root[data-theme] #shell .message.assistant .response-actions-toolbar :is(.response-btn, .result-expand) {
  height: 28px !important;
  min-height: 28px !important;
  max-height: 28px !important;
  padding: 0 8px !important;
  gap: 4px !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  line-height: 1 !important;
  border: 1px solid var(--line) !important;
  border-radius: 6px !important;
  background: var(--raised) !important;
  color: var(--text) !important;
  align-self: center !important;
}
:root[data-theme] #shell .message.assistant .response-actions-toolbar .result-expand .icon-2d {
  width: 12px !important;
  height: 12px !important;
}
:root[data-theme] #shell .message.assistant .response-actions-toolbar .response-overflow-btn {
  width: 28px !important;
  min-width: 28px !important;
  padding: 0 !important;
}
/* Phones: Expand / Copy / Download become icon-only (label kept for screen
   readers) so the full set fits on one row without clipping. PDF and DOCX
   keep their text because their icons look alike. */
@media (max-width: 700px) {
  :root[data-theme] #shell .message.assistant .response-actions-toolbar {
    gap: 3px !important;
    padding-inline: 8px !important;
  }
  :root[data-theme] #shell .message.assistant .response-actions-toolbar :is(.result-expand, .btn-expand, .btn-copy, .btn-download) {
    padding: 0 7px !important;
  }
  :root[data-theme] #shell .message.assistant .response-actions-toolbar :is(.result-expand, .btn-expand, .btn-copy, .btn-download) > span {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
  }
  :root[data-theme] #shell .message.assistant .response-actions-toolbar :is(.result-expand, .btn-expand, .btn-copy, .btn-download) .icon-2d.sm {
    width: 14px !important;
    height: 14px !important;
  }
}

/* Parallel section drafting: per-section draft blocks streamed while the
   adjudicator merge runs. Everything derives from theme tokens. */
.section-drafts {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 4px 0 12px;
}
.section-draft {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px 12px;
  background: color-mix(in srgb, var(--b1x-solid, transparent) 55%, transparent);
  min-width: 0;
}
.section-draft-failed {
  border-color: color-mix(in srgb, var(--red, currentColor) 45%, var(--line));
}
.section-draft-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.section-draft-index {
  font: 600 11px/1.4 var(--mono);
  color: var(--muted);
}
.section-draft-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.95em;
  font-weight: 600;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.section-draft-chip {
  flex: none;
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font: 550 11px/1.5 var(--font-ui);
  letter-spacing: 0.01em;
  color: var(--muted);
}
.section-draft-chip[data-state="drafting"],
.section-draft-chip[data-state="restarting"] {
  color: var(--cyan);
  border-color: color-mix(in srgb, var(--cyan) 40%, var(--line));
  background: color-mix(in srgb, var(--cyan) 8%, transparent);
}
.section-draft-chip[data-state="completed"] {
  color: var(--green);
  border-color: color-mix(in srgb, var(--green) 40%, var(--line));
}
.section-draft-chip[data-state="failed"] {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
}
.section-draft-body {
  margin-top: 6px;
  font-size: 0.92em;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.section-draft-failed .section-draft-body {
  color: var(--muted);
  font-style: italic;
}
