:root {
  --bg: #09090b;
  --bg-elevated: #141416;
  --bg-hover: #1c1c1f;
  --border: #27272a;
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --accent: #e4e4e7;
  --user-bubble: #27272a;
  --assistant-bubble: transparent;
  --reasoning: #3f3f46;
  /* semantic color tokens (dark = current values; light overrides in [data-theme="light"]) */
  --link: #93c5fd;
  --badge-blue: #3b82f6;
  --badge-blue-bg: rgba(59, 130, 246, 0.08);
  --badge-blue-bg-hover: rgba(59, 130, 246, 0.14);
  --badge-green: #22c55e;
  --badge-green-text: #86efac;
  --badge-green-bg: rgba(34, 197, 94, 0.08);
  --badge-green-bg-hover: rgba(34, 197, 94, 0.14);
  --danger-bg: #3b1219;
  --danger-border: #7f1d1d;
  --danger-text: #fecaca;
  --toast-bg: rgba(127, 29, 29, 0.2);
  --toast-border: rgba(248, 113, 113, 0.35);
  --toast-text: #fca5a5;
  --warn-panel-bg: #1a1a2e;
  --warn-panel-border: #3f3f5c;
  --warn-panel-text: #c4c4d4;
  --border-strong: #52525b;
  --accent-blue-soft: rgba(107, 159, 255, 0.08);
  --shadow-strong: rgba(0, 0, 0, 0.6);
  --shadow-drawer: rgba(0, 0, 0, 0.35);
  --shadow-overlay: rgba(0, 0, 0, 0.45);
  --success: #3fb950;
  --warn-fg: #d29922;
  --info: #58a6ff;
  --cache-text: #0a7d39;
  --cache-bg: rgba(16, 163, 74, 0.12);
  --cache-border: rgba(16, 163, 74, 0.3);
  --docchip-text: #1d4ed8;
  --docchip-bg: rgba(37, 99, 235, 0.1);
  --docchip-border: rgba(37, 99, 235, 0.3);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ── Light theme (set via toggle or prefers-color-scheme; see head FOUC script) ── */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f4f4f5;
  --bg-hover: #e8e8eb;
  --border: #d4d4d8;
  --text: #18181b;
  --text-muted: #52525b;
  --accent: #18181b;
  --user-bubble: #e7e7ea;
  --assistant-bubble: transparent;
  --reasoning: #d4d4d8;
  --link: #2563eb;
  --badge-blue: #2563eb;
  --badge-blue-bg: rgba(37, 99, 235, 0.10);
  --badge-blue-bg-hover: rgba(37, 99, 235, 0.18);
  --badge-green: #16a34a;
  --badge-green-text: #15803d;
  --badge-green-bg: rgba(22, 163, 74, 0.12);
  --badge-green-bg-hover: rgba(22, 163, 74, 0.20);
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --danger-text: #b91c1c;
  --toast-bg: #fef2f2;
  --toast-border: rgba(220, 38, 38, 0.35);
  --toast-text: #b91c1c;
  --warn-panel-bg: #eef2ff;
  --warn-panel-border: #c7d2fe;
  --warn-panel-text: #3730a3;
  --border-strong: #a1a1aa;
  --accent-blue-soft: rgba(37, 99, 235, 0.08);
  --shadow-strong: rgba(0, 0, 0, 0.18);
  --shadow-drawer: rgba(0, 0, 0, 0.12);
  --shadow-overlay: rgba(0, 0, 0, 0.15);
  --success: #15803d;
  --warn-fg: #b45309;
  --info: #2563eb;
  --cache-text: #0a7d39;
  --cache-bg: rgba(16, 163, 74, 0.14);
  --cache-border: rgba(16, 163, 74, 0.35);
  --docchip-text: #1d4ed8;
  --docchip-bg: rgba(37, 99, 235, 0.10);
  --docchip-border: rgba(37, 99, 235, 0.30);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  overflow: hidden;
}

.shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  background: var(--bg);
  overflow: hidden;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.view-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.view-panel[hidden] {
  display: none;
}

.view-chat {
  align-items: center;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 900px;
  position: relative;  /* 0d: anchor for the "↓ new messages" pill */
}

.view-settings {
  width: 100%;
}

/* ── Sidebar (nav + chat history) ── */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.settings-btn {
  width: 30px;
  height: 30px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.settings-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.sidebar-settings {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar-settings[hidden] {
  display: none;
}

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

.side-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.side-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.side-nav-item.active {
  background: var(--bg-hover);
  color: var(--text);
}

.side-nav-icon {
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

.side-nav-label {
  flex: 1;
  min-width: 0;
}

.sidebar-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.sidebar-chat[hidden] {
  display: none;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sidebar-new {
  padding: 5px 10px;
  font-size: 0.75rem;
  white-space: nowrap;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.history-empty {
  padding: 14px 10px;
  color: var(--text-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

/* Phase A sidebar search (01-08) */
.history-search {
  padding: 4px 10px 8px;
}
.history-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border, #d0d4dc);
  background: var(--panel-2, rgba(0, 0, 0, 0.04));
  color: inherit;
  font-size: 0.86rem;
  outline: none;
}
.history-search input:focus {
  border-color: var(--accent, #4a7dff);
}
.history-group {
  list-style: none;
  padding: 10px 12px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.55;
}
.history-note {
  list-style: none;
  padding: 8px 12px;
  font-size: 0.75rem;
  opacity: 0.6;
}
.history-item.kbd-selected .history-open {
  outline: 2px solid var(--accent, #4a7dff);
  outline-offset: -2px;
  border-radius: 8px;
}

.history-item {
  position: relative;            /* the ⋮ is overlaid absolutely so the title keeps full width */
  margin-bottom: 2px;
}

.history-item.active .history-open {
  background: var(--bg-hover);
}

.history-item.running .history-title::after {
  content: " …";
  opacity: 0.65;
}

.history-open {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.history-open:hover {
  background: var(--bg-hover);
}

.history-title {
  font-size: 0.82rem;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.history-when {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.pin-flag {
  font-size: 0.7em;             /* compact 📌 cue on pinned rows */
  opacity: 0.9;
}

/* "Load more" row at the bottom of the paginated session list */
.history-load-more {
  margin-top: 4px;
}
.history-load-more button {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
}
.history-load-more button:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}
.history-load-more button:disabled {
  opacity: 0.6;
  cursor: default;
}

/* ⋮ overflow-menu trigger: overlaid at the right, shown on hover only — no reserved space */
.history-menu {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.12s;
}
.history-item:hover .history-menu,
.history-item:focus-within .history-menu {
  opacity: 0.75;
  background: var(--bg-hover);   /* opaque so it cleanly masks the title edge underneath */
}
.history-menu:hover {
  opacity: 1;
  color: var(--text);
}

/* Popup menu (Pin / Rename / Delete) — fixed-positioned, appended to <body> */
.history-menu-popup {
  position: fixed;
  z-index: 1000;
  min-width: 144px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 26px var(--shadow-strong);
}
.history-menu-item {
  text-align: left;
  padding: 8px 11px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.history-menu-item:hover {
  background: var(--bg-hover);
}
.history-menu-item.danger {
  color: var(--danger-text);
}
.history-menu-item.danger:hover {
  background: var(--danger-bg);
}

.history-rename-input {
  width: 100%;
  min-width: 0;
  margin: 2px 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.82rem;
  font-family: inherit;
}
.history-rename-input:focus {
  outline: none;
  border-color: var(--text-muted);
}

.menu-btn {
  display: none;
  margin-right: 4px;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.brand-icon {
  font-size: 1.25rem;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app-version {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  vertical-align: middle;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  max-width: 200px;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}

.btn.ghost:hover {
  background: var(--bg-hover);
}

/* ── Chat log ── */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 12px;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.welcome {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.welcome h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  font-weight: 500;
  color: var(--text);
}

.welcome p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.welcome p.welcome-tagline {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text);
}

.welcome-sub {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.8rem;
  opacity: 0.7;
}

.welcome p.welcome-powered {
  margin-top: 14px;
  font-size: 0.78rem;
  opacity: 0.75;
}

.welcome-powered a {
  color: var(--link);
  text-decoration: none;
  font-weight: 600;
}

.welcome-powered a:hover { text-decoration: underline; }

.thin-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-muted);
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border, rgba(127, 127, 127, 0.2));
  border-radius: 8px;
}

.numcheck-notice {
  margin-top: 12px;
  padding: 8px 12px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
  background: rgba(214, 158, 46, 0.10);
  border: 1px solid rgba(214, 158, 46, 0.45);
  border-radius: 8px;
}
.numcheck-notice .numcheck-head { font-weight: 600; }
.numcheck-notice ul { margin: 4px 0 0; padding-left: 20px; }
.numcheck-notice li { margin: 2px 0; }

.thin-notice-text {
  flex: 1 1 auto;
  min-width: 60%;
}

.thin-broaden {
  flex: 0 0 auto;
  padding: 4px 12px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border, rgba(127, 127, 127, 0.4));
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.thin-broaden:hover {
  background: var(--accent, #4a7dff);
  border-color: var(--accent, #4a7dff);
  color: #fff;
}

.msg {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.msg.user .msg-avatar {
  background: var(--user-bubble);
}

.msg-body {
  max-width: 85%;
  min-width: 0;
}

.msg.user .msg-body {
  text-align: right;
}

.msg.assistant .msg-body {
  flex: 1;
  max-width: calc(100% - 40px);
}

.msg-content {
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.assistant .msg-content.markdown {
  white-space: normal;
  font-size: 1rem;
  line-height: 1.7;
  max-inline-size: 76ch;
  overflow-wrap: anywhere;
}

.msg.assistant .msg-content.markdown > :first-child {
  margin-top: 0;
}

.msg.assistant .msg-content.markdown > :last-child {
  margin-bottom: 0;
}

.msg.assistant .msg-content.markdown p {
  margin: 0 0 0.9em;
}

.msg.assistant .msg-content.markdown h1,
.msg.assistant .msg-content.markdown h2,
.msg.assistant .msg-content.markdown h3,
.msg.assistant .msg-content.markdown h4 {
  margin: 1.5em 0 0.55em;
  line-height: 1.3;
  font-weight: 600;
  text-wrap: balance;
}

.msg.assistant .msg-content.markdown h1 { font-size: 1.35rem; }
.msg.assistant .msg-content.markdown h2 { font-size: 1.2rem; }
.msg.assistant .msg-content.markdown h3 { font-size: 1.05rem; }
.msg.assistant .msg-content.markdown h4 { font-size: 0.98rem; color: var(--text-muted); }

.msg.assistant .msg-content.markdown ul,
.msg.assistant .msg-content.markdown ol {
  margin: 0.4em 0 0.85em;
  padding-left: 1.35em;
}

.msg.assistant .msg-content.markdown li {
  margin: 0.35em 0;
}

.msg.assistant .msg-content.markdown li > p {
  margin: 0;
}

.msg.assistant .msg-content.markdown code {
  font-family: Consolas, "Cascadia Code", "Segoe UI Mono", monospace;
  font-size: 0.88em;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.1em 0.35em;
}

.msg.assistant .msg-content.markdown pre {
  margin: 0.75em 0;
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto;
}

.msg.assistant .msg-content.markdown pre code {
  display: block;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 0.84rem;
  line-height: 1.6;
  white-space: pre;
}

.msg.assistant .msg-content.markdown blockquote {
  margin: 0.75em 0;
  padding: 0.35em 0 0.35em 12px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}

.msg.assistant .msg-content.markdown a {
  color: var(--link);
  text-decoration: none;
}

.msg.assistant .msg-content.markdown a:hover {
  text-decoration: underline;
}

.msg.assistant .msg-content.markdown table {
  display: block;
  overflow-x: auto;
  width: 100%;
  margin: 0.75em 0;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.msg.assistant .msg-content.markdown th,
.msg.assistant .msg-content.markdown td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  min-inline-size: 8rem;
  word-break: normal;
  overflow-wrap: break-word;
}

.msg.assistant .msg-content.markdown th {
  background: var(--bg-elevated);
  font-weight: 600;
}

.msg.assistant .msg-content.markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.msg.assistant .msg-content.markdown a.cite-ref {
  color: var(--link);
  text-decoration: none;
  font-size: 0.82em;
  vertical-align: super;
  line-height: 0;
  padding: 0 1px;
}

.msg.assistant .msg-content.markdown a.cite-ref:hover {
  text-decoration: underline;
}

.msg.assistant .sources-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.84rem;
}

.msg-model {
  margin-top: 0.5rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  opacity: 0.75;
  letter-spacing: 0.01em;
}

.msg.assistant .sources-footer-title {
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  cursor: pointer;
  min-height: 44px;
  align-content: center;
}

.msg.assistant .sources-footer-title:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 3px;
  border-radius: 4px;
}

.msg.assistant .sources-footer-list { overflow-wrap: anywhere; }
.msg.assistant .sources-footer-list li { padding-block: 0.3rem; }

.msg.assistant .sources-footer-list {
  margin: 0;
  padding-left: 1.25rem;
}

.msg.assistant .sources-footer-list li {
  margin: 0.2em 0;
}

.msg.assistant .sources-footer-list a {
  color: var(--link);
  text-decoration: none;
}

.msg.assistant .sources-footer-list a:hover {
  text-decoration: underline;
}

.msg.user .msg-content {
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: inline-block;
  text-align: left;
}

.msg-media {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.msg-media img {
  max-width: 220px;
  max-height: 160px;
  border-radius: 10px;
  border: 1px solid var(--border);
  object-fit: cover;
}

.media-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.reasoning {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.reasoning summary {
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.reasoning-body {
  padding: 0 12px 10px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.msg.assistant {
  align-items: flex-start;
}

.msg.assistant .msg-status {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
  min-width: 0;
  padding-top: 5px;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.msg.assistant .msg-status[hidden] {
  display: none !important;
}

.msg.assistant.is-working:not(.has-reply) .msg-body {
  display: none;
}

.msg-status-spinner {
  width: 12px;
  height: 12px;
  margin-top: 3px;
  border: 2px solid var(--border);
  border-top-color: var(--text-muted);
  border-radius: 50%;
  animation: warmup-spin 0.8s linear infinite;
  flex-shrink: 0;
}

.msg.assistant.streaming.has-reply .msg-content:not(:empty)::after {
  content: "▋";
  animation: blink 0.9s step-end infinite;
  margin-left: 2px;
  opacity: 0.7;
}

@keyframes blink {
  50% { opacity: 0; }
}

.error-banner {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* warmup-spin is the shared working-spinner keyframe (.msg-status-spinner).
   The old .warmup-banner component that also used it was dead CSS (no JS/HTML
   references) — removed 2026-07-02 (0c-lite). */
@keyframes warmup-spin {
  to { transform: rotate(360deg); }
}

/* 0c-lite: interrupted-turn marker (user Stop or connection drop) — the reply
   above it is a PARTIAL. Muted on purpose: informational, not an error. */
.stopped-chip {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* 0c-lite: keyboard-visible focus ring for controls that had NO focus
   affordance (buttons, links, tabs, history items). Text fields are exempt BY
   DESIGN — #messageInput (composer :focus-within border), .history-rename-input
   and .login-field input (:focus border-color) keep their border-based
   affordance; their higher-specificity outline:none rules win over this one.
   --accent is theme-aware (near-white on dark, near-black on light). */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent, #6b9fff);
  outline-offset: 2px;
}

/* ── Composer ── */
.composer-wrap {
  flex-shrink: 0;
  padding: 12px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 10px 4px 4px;
  font-size: 0.78rem;
}

.attach-chip img {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  object-fit: cover;
}

.attach-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 1rem;
  line-height: 1;
}

.attach-chip button:hover {
  color: var(--text);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 8px 10px 8px 6px;
}

.composer:focus-within {
  border-color: var(--border-strong);
}

/* Phase 2 composer redesign: the 4 upload buttons club into one "+" menu,
   same popover pattern as .user-menu (position:relative wrap, absolutely
   positioned panel) but anchored to the BOTTOM of the composer and opening
   UPWARD, since the composer sits at the bottom of the page. */
.composer-attach-wrap { position: relative; display: inline-flex; align-self: flex-end; }
.composer-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.composer-attach-btn:hover { background: var(--bg-hover); color: var(--text); }
.composer-attach-btn[aria-expanded="true"] {
  background: var(--bg-hover);
  color: var(--text);
}
.composer-attach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 160px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 200;
  box-shadow: 0 8px 24px var(--shadow-strong);
}
.composer-attach-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 8px 11px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
}
.composer-attach-item:hover { background: var(--bg-hover); }

/* Phase 3 composer redesign: a persistent hint so #search/#knowledge/
   #nosearch stay discoverable now that the composer is cleaner -- the
   textarea's placeholder text already documents them, but that vanishes
   the moment the user types anything. This small "i" button (native title
   tooltip, same pattern as every other icon-btn's title attribute -- no
   new tooltip component) stays visible regardless of typing state. */
.composer-hint-btn {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1;
  cursor: help;
  opacity: 0.7;
}
.composer-hint-btn:hover { background: var(--bg-hover); opacity: 1; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.75;
}

.icon-btn:hover {
  background: var(--bg-hover);
  opacity: 1;
}

.prompt-copy-btn { align-self: flex-end; }
.prompt-copy-btn:disabled { opacity: .3; cursor: default; }
.ws-doc-ocr { color: var(--accent-strong, #3730a3); }

/* Phase 1 composer redesign: web-search toggle living next to Send, mirroring
   the account-level Settings → "Web search (DDGS)" checkbox (#webSearchToggle).
   Same setting, two controls — kept in sync in app.js. */
.composer-web-search-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-end;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.composer-web-search-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.composer-web-search-btn[aria-pressed="true"] {
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
  border-color: var(--accent, #6366f1);
  color: var(--accent, #6366f1);
}
.composer-web-search-icon { flex: none; }
.composer-web-search-label { white-space: nowrap; }

/* 0g: one compact row of small icon boxes per reply — like/dislike, and (on
   the last turn only) regenerate/edit share this same row instead of each
   taking a full-width line of its own. */
.msg-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  font-size: .95rem;
  line-height: 1;
  color: var(--text-muted);
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.msg-action-btn:hover {
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
  border-color: var(--accent, #6366f1);
  color: var(--text);
}
.msg-action-btn:disabled {
  opacity: .5;
  cursor: default;
}

.feedback-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--text-muted);
  font-size: .78rem;
}
.feedback-controls button { font: inherit; }
.feedback-form { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; margin-top: 6px; }
.feedback-submit-btn {
  flex: 0 0 auto;
  font-size: .8rem;
  color: var(--text);
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}
.feedback-submit-btn:hover {
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
  border-color: var(--accent, #6366f1);
}
.feedback-form textarea, .feedback-form select {
  flex: 1 1 180px;
  min-height: 34px;
  resize: vertical;
  font: inherit;
  color: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.45;
  resize: none;
  /* Grows up to 4 visible lines, then scrolls internally rather than
     pushing the composer taller indefinitely (measured: 4 lines = 100px
     at this font-size/line-height, 5th line onward scrolls). */
  max-height: 100px;
  padding: 6px 4px;
  outline: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
  opacity: 0.9;
}

/* Stop state: while a reply is streaming, Send morphs into a Stop control. */
.send-btn .stop-icon {
  display: none;
}
.send-btn.is-stop {
  background: #e5484d;
  color: #fff;
}
.send-btn.is-stop .send-icon {
  display: none;
}
.send-btn.is-stop .stop-icon {
  display: block;
}

.hint {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.resource-label {
  font-variant-numeric: tabular-nums;
}

/* ── Settings page (main window) ── */
.settings-page-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.settings-menu-btn {
  display: none;
}

.settings-page-title-wrap {
  flex: 1;
  min-width: 0;
}

.settings-page-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.settings-page-sub {
  margin: 4px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.settings-page-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px 32px;
}

.settings-tab-panel[hidden] {
  display: none;
}

.settings-section-wide {
  max-width: 720px;
}

.model-select-full {
  width: 100%;
  max-width: none;
}

.settings-field-block {
  margin-bottom: 10px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: start;
  overflow: visible;
  max-width: 1100px;
}

.settings-prompt-col {
  margin-bottom: 0;
}

.settings-side-col {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.prompt-active {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}

.prompt-active-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-hover);
}

.prompt-source {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.prompt-updated {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.prompt-locked,
.prompt-editable {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.prompt-preview {
  margin: 0;
  padding: 10px 12px;
  max-height: 220px;
  overflow-y: auto;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
}

/* Same boxed look as .prompt-preview (shares the .prompt-active wrapper),
   but an actual editable textarea for the About-you panel — border/background
   live on the shared wrapper, so this stays borderless/transparent inside it. */
.prompt-preview-input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  min-height: 120px;
  max-height: 220px;
  resize: vertical;
  overflow-y: auto;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text);
}

.prompt-preview-input:focus {
  outline: none;
}

.settings-section {
  margin-bottom: 22px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section h3 {
  margin: 0 0 6px;
  font-size: 0.88rem;
  font-weight: 600;
}

.settings-section-retired {
  opacity: 0.6;
}

.settings-retired-badge {
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 500;
  background: var(--bg-hover);
  color: var(--text-muted);
  vertical-align: middle;
}

.settings-hint {
  margin: 0 0 10px;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.settings-hint code {
  background: var(--bg-hover);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.settings-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.save-confirm {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--success);
}

.settings-toggle {
  margin-top: 4px;
}

.knowledge-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.knowledge-empty {
  padding: 14px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.knowledge-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.knowledge-item:last-child {
  border-bottom: none;
}

.knowledge-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
}

.knowledge-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.knowledge-delete:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ── Workspaces (A-1) ── */
.ws-open {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  padding: 2px 0;
}
.ws-open:hover { color: var(--accent); }
.knowledge-item.ws-active { background: var(--bg-hover); border-radius: 6px; }

/* Both pickers share ONE row (owner request) — they wrap on narrow screens. */
.composer-ws-row {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin: 0 4px;
}
.composer-workspace {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.composer-workspace .select { font-size: 0.78rem; max-width: 240px; }

.private-egress-indicator {
  margin: 0 0 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
  white-space: nowrap;
}
.private-egress-indicator.is-disabled {
  color: var(--text-muted);
  background: var(--bg-hover);
}
.private-egress-indicator.is-enabled {
  color: #175c36;
  border-color: #3a9b64;
  background: #e7f7ed;
}
.private-egress-indicator:disabled { cursor: not-allowed; opacity: 0.7; }

.ws-flag {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.ws-flag.is-organization {
  color: #6b4f00;
  font-weight: 650;
}

/* P8 (D4): topbar workspace chip for the open chat (pinned workspace name). */
.ws-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-badge.is-organization {
  color: #6b4f00;
  border-color: #c9a227;
  background: #fff8dc;
}

/* P3 (Q1): one-line non-blocking composer notice (auto-dismisses). */
.composer-notice {
  margin: 0 0 6px;
  font-size: 0.78rem;
  color: var(--warn-panel-text, #b98900);
}

.private-egress-panel {
  margin: 0 0 8px;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--warning, #b7791f) 55%, transparent);
  border-radius: 10px;
  background: color-mix(in srgb, var(--warning, #b7791f) 9%, var(--surface, #fff));
  font-size: 12px;
}

.private-egress-status { font-weight: 600; }

.private-egress-consent {
  display: grid;
  gap: 7px;
  margin-top: 7px;
}

.private-egress-consent > span { display: flex; gap: 7px; align-items: center; }

.private-egress-consent input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
}

.private-egress-consent small { color: var(--muted); line-height: 1.35; }

/* B-viewer: egress audit badges + query cell */
.egress-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.egress-redacted { color: var(--warn-panel-text, #b98900); border-color: currentColor; }
.egress-queries { max-width: 340px; word-break: break-word; }

/* 0b: tool-activity strip — one row per step, failures first-class. */
.steps-strip {
  margin: 0 0 8px;
  padding: 0 2px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.steps-strip > summary {
  cursor: pointer; list-style: none; font-weight: 600;
  min-height: 44px; display: flex; align-items: center; gap: 8px;
  overflow-wrap: anywhere;
}
.steps-strip > summary::before { content: "›"; font-size: 1.15rem; }
.steps-strip[open] > summary::before { transform: rotate(90deg); }
.steps-strip > summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.steps-strip > summary::-webkit-details-marker { display: none; }
.step-row { padding: 2px 0 0 6px; }

/* Inbox: collapsed "Show flat list" toggle wrapping the flat quick-scan table. */
.flat-list { margin: 0 0 10px; }
.flat-list > summary {
  cursor: pointer;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 2px 0;
}
.flat-list > summary:hover { color: var(--accent); }
.flat-list > summary::-webkit-details-marker { display: none; }
.flat-list > summary::before { content: "▸"; font-size: 0.9em; }
.flat-list[open] > summary::before { content: "▾"; }
.flat-list[open] > summary { margin-bottom: 6px; }
.step-fail { color: var(--danger-text, #c0392b); }
.step-live { color: var(--text-muted); line-height: 1.6; overflow-wrap: anywhere; }

.office-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 10px;
  width: min(520px, 100%);
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
}
.office-card-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.office-card-copy { display: grid; min-width: 0; gap: 2px; }
.office-card-copy strong { overflow-wrap: anywhere; }
.office-card-type, .office-card-detail { color: var(--text-muted); font-size: 0.75rem; }
.office-download {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 1.2rem;
}
.office-download:hover { border-color: var(--accent); color: var(--accent); }
.office-download:disabled { cursor: wait; opacity: 0.5; }
.office-card.is-expired, .office-card.is-unavailable {
  opacity: 0.7;
  grid-template-columns: 38px minmax(0, 1fr);
}
.excel-confirm-card { width: min(560px, 100%); margin-top: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elevated); }
.excel-confirm-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.excel-confirm-head span, .excel-confirm-status { color: var(--text-muted); font-size: .74rem; }
.excel-confirm-card p { margin: 8px 0; font-size: .82rem; }
.excel-confirm-targets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.excel-confirm-targets code { padding: 3px 6px; border-radius: 4px; background: var(--bg); font-size: .72rem; }
.excel-confirm-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.excel-confirm-actions .btn { width: auto; }

/* 0d: "new messages below" pill — anchored OUTSIDE chatLog (its innerHTML is
   wiped on every render); floats above the composer. */
.new-msg-pill {
  position: absolute;
  bottom: 118px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong, var(--border));
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.new-msg-pill:hover { background: var(--bg-hover); }

/* A-3: per-doc async-index status */
.ws-doc-pending { color: var(--warn-panel-text, #b98900); }
.ws-doc-failed { color: var(--danger-text, #c0392b); cursor: help; }
.ws-doc-ready { color: var(--cache-text, #2e7d32); cursor: help; }

.settings-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.spell-hint,
.web-search-hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

.web-search-hint a {
  color: var(--accent, #6b9fff);
  text-decoration: none;
}

.web-search-hint a:hover {
  text-decoration: underline;
}

.settings-inline {
  margin-top: 10px;
  gap: 12px;
  flex-wrap: wrap;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.settings-field input,
.settings-field select {
  min-width: 100px;
}

.api-key-create {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.api-key-name-input {
  flex: 1;
  min-width: 180px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
}

.api-key-reveal {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--accent, #6b9fff);
  border-radius: 8px;
  background: var(--accent-blue-soft);
}

.api-key-rate-note {
  margin: 6px 0 0;
  font-size: 0.72rem;
  color: var(--text-muted, #6b7280);
  letter-spacing: 0.01em;
}

.api-key-reveal-label {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--text);
}

.api-key-reveal-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.api-key-value {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.76rem;
  word-break: break-all;
}

.api-key-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  max-height: 220px;
  overflow-y: auto;
}

.api-key-empty {
  padding: 14px 12px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.api-key-item:last-child {
  border-bottom: none;
}

.api-key-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 2px;
}

.api-key-delete {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.api-key-delete:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.api-usage-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

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

.api-usage-table th,
.api-usage-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.api-usage-table th {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--bg-hover);
}

/* Model badge + picker */
.model-badge-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

/* Topbar placement: opens downward */
.topbar-model .model-picker {
  top: calc(100% + 8px);
  bottom: unset;
  right: 0;
  left: unset;
}

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  white-space: nowrap;
}

.model-badge:hover {
  border-color: var(--accent);
  color: var(--text);
}

.model-badge.smart {
  border-color: var(--badge-blue);
  color: var(--link);
  background: var(--badge-blue-bg);
}

.model-badge.smart:hover {
  background: var(--badge-blue-bg-hover);
}

.model-badge.fast {
  border-color: var(--badge-green);
  color: var(--badge-green-text);
  background: var(--badge-green-bg);
}

.model-badge.fast:hover {
  background: var(--badge-green-bg-hover);
}

.model-badge::after {
  content: "▾";
  font-size: 0.62rem;
  opacity: 0.55;
}

.model-picker {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 180px;
  max-width: calc(100vw - 16px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 200;
  box-shadow: 0 8px 24px var(--shadow-strong);
}

.model-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 8px 11px;
  border: none;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.12s;
}

.model-option:hover {
  background: var(--bg-hover);
}

.model-option.active {
  background: var(--bg-hover);
  color: var(--text);
}

.model-option-name {
  font-weight: 500;
  color: var(--text);
}

.model-option-desc {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.model-option.active .model-option-name::after {
  content: " ✓";
  font-size: 0.7rem;
  opacity: 0.65;
}

.model-switch-chip {
  text-align: center;
  font-size: 0.74rem;
  color: var(--text-muted);
  padding: 6px 0;
  margin: 4px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* 0g: 2 suggested-followup chips side by side in one line instead of each
   stacked on its own row (the label still takes its own full-width line
   above them via flex-basis: 100%). */
.followups {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.followups-label {
  flex: 1 1 100%;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.followup-chip {
  flex: 1 1 calc(50% - 3px);
  min-width: 140px;
  text-align: left;
  white-space: normal;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface-2, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.followup-chip:hover {
  background: var(--accent-soft, rgba(99, 102, 241, 0.12));
  border-color: var(--accent, #6366f1);
}
/* "Rewrite smarter (Smart)" action chip — stands out from the question chips. */
.followup-chip.followup-smart {
  font-weight: 600;
  color: var(--accent, #6366f1);
  background: var(--accent-soft, rgba(99, 102, 241, 0.10));
  border-color: var(--accent, #6366f1);
}
.followup-chip.followup-smart:hover {
  background: var(--accent, #6366f1);
  color: #fff;
}

.api-usage-table tr:last-child td {
  border-bottom: none;
}

.api-usage-empty {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.api-usage-key-name {
  font-weight: 500;
}

.api-usage-key-prefix {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.api-usage-prompt {
  max-width: 360px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.api-usage-hint {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Workspace Connector ─────────────────────────────────────────────── */
.connector-screen { max-width: 1180px; margin: 0 auto; }
.connector-hero { display: flex; justify-content: space-between; gap: 28px; align-items: flex-end; margin-bottom: 24px; }
.connector-hero h2 { margin: 4px 0 8px; font-size: 1.7rem; letter-spacing: -0.02em; }
.connector-kicker { color: var(--info); font-size: 0.68rem; font-weight: 750; letter-spacing: 0.12em; }
.connector-workspace-field { display: flex; flex-direction: column; gap: 7px; min-width: 260px; font-size: 0.75rem; color: var(--text-muted); font-weight: 650; }
.connector-workspace-field select { width: 100%; color: var(--text); background: var(--bg-elevated); }
.connector-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.connector-dropzone { min-height: 260px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border: 1px dashed var(--border-strong); border-radius: 18px; background: linear-gradient(135deg, var(--accent-blue-soft), transparent 60%), var(--bg-elevated); transition: border-color .15s, background .15s, transform .15s; cursor: pointer; padding: 28px; }
.connector-dropzone:hover, .connector-dropzone.connector-dragover { border-color: var(--info); background: var(--accent-blue-soft); transform: translateY(-1px); }
.connector-dropzone h3 { margin: 8px 0 4px; font-size: 1.08rem; }
.connector-dropzone p { margin: 0; color: var(--text-muted); }
.connector-drop-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; color: var(--info); background: var(--badge-blue-bg); font-size: 1.8rem; font-weight: 300; }
.connector-browse { border: 0; padding: 0; color: var(--link); background: none; font: inherit; text-decoration: underline; cursor: pointer; }
.connector-format-line { margin-top: 22px; color: var(--text); font-size: .78rem; font-weight: 700; letter-spacing: .08em; }
.connector-limit-line { margin-top: 6px; color: var(--text-muted); font-size: .72rem; }
.connector-help-card, .connector-prompt-card, .connector-documents-card { border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elevated); padding: 18px; }
.connector-help-card h3, .connector-prompt-card h3, .connector-documents-card h3 { margin: 0; font-size: .98rem; }
.connector-help-card ul { margin: 14px 0 0; padding-left: 18px; color: var(--text-muted); font-size: .78rem; line-height: 1.55; }
.connector-help-card li + li { margin-top: 9px; }
.connector-upload-actions, .connector-prompt-actions { display: flex; align-items: center; gap: 10px; min-height: 42px; margin-top: 10px; }
.connector-status { color: var(--text-muted); font-size: .76rem; line-height: 1.35; }
.connector-status-error { color: var(--danger-text); }
.connector-staged-list, .connector-document-list { list-style: none; margin: 12px 0 0; padding: 0; }
.connector-staged-item, .connector-document-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.connector-staged-item span:first-child, .connector-document-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.connector-staged-item strong, .connector-document-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
.connector-staged-item small, .connector-document-main span { color: var(--text-muted); font-size: .72rem; }
.connector-prompt-card, .connector-documents-card { margin-top: 16px; }
.connector-card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; }
.connector-card-heading h3 { margin-top: 3px; }
.connector-default-badge, .connector-count { white-space: nowrap; color: var(--badge-green-text); background: var(--badge-green-bg); border: 1px solid var(--badge-green-border, var(--border)); border-radius: 999px; padding: 5px 9px; font-size: .68rem; font-weight: 700; }
.connector-count { color: var(--text-muted); background: transparent; }
.connector-prompt-card .settings-hint, .connector-documents-card .settings-hint { margin: 9px 0 12px; }
.connector-prompt-card textarea { width: 100%; min-height: 120px; resize: vertical; }
.connector-document-icon { flex: 0 0 38px; display: grid; place-items: center; height: 38px; border-radius: 10px; color: var(--info); background: var(--badge-blue-bg); font-size: .62rem; font-weight: 800; }
.connector-empty, .connector-empty-docs { color: var(--text-muted); text-align: center; }
.connector-empty { max-width: 560px; margin: 70px auto; padding: 42px 24px; border: 1px dashed var(--border-strong); border-radius: 18px; }
.connector-empty h3 { color: var(--text); margin: 12px 0 8px; }
.connector-empty p { line-height: 1.55; }
.connector-empty-icon { margin: auto; width: 48px; height: 48px; display: grid; place-items: center; border-radius: 14px; background: var(--badge-blue-bg); color: var(--info); font-size: 1.6rem; }
.connector-empty-docs { padding: 26px 8px; font-size: .82rem; }

@media (max-width: 760px) {
  .connector-hero { flex-direction: column; align-items: stretch; }
  .connector-workspace-field { min-width: 0; }
  .connector-grid { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .prompt-preview,
  .prompt-preview-input {
    max-height: 160px;
  }

  .settings-page-body {
    padding: 16px;
  }
}

@media (max-width: 860px) {
  .menu-btn,
  .settings-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: none;
  }

  .shell.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 12px 0 32px var(--shadow-drawer);
  }

  .shell.sidebar-open .main::after {
    content: "";
    position: absolute;
    inset: 0;
    background: var(--shadow-overlay);
    z-index: 50;
    pointer-events: auto;
  }

  .msg-body {
    max-width: 92%;
  }

  .topbar {
    padding: 10px 14px;
    gap: 8px;
  }

  .composer-wrap {
    padding: 10px 12px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

/* Narrow phones: hide email, keep model badge and logout */
@media (max-width: 540px) {
  .topbar-email {
    display: none;
  }

  .topbar {
    padding: 8px 12px;
    gap: 6px;
  }

  .brand h1 {
    font-size: 0.92rem;
  }

  .app-version {
    display: none;
  }

  .brand-icon {
    font-size: 1rem;
  }

  .hint {
    font-size: 0.68rem;
  }

  .composer-attach-btn {
    width: 32px;
    height: 32px;
    font-size: 1.1rem;
  }

  .composer-hint-btn {
    width: 28px;
    height: 28px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }

  .composer-web-search-btn {
    padding: 6px;
    border-radius: 50%;
  }

  .composer-web-search-label {
    display: none;
  }
}

/* ── Code / table / reply export toolbars ──────────────────────────────────── */
pre { position: relative; }
.msg.assistant .msg-content.markdown pre { padding-top: 3.5rem; } /* clearance for touch-accessible toolbar */
.cb-toolbar { position: absolute; top: 6px; right: 6px; display: flex; gap: 8px; opacity: 1; }
pre:hover .cb-toolbar { opacity: 1; }
.cb-btn { font: inherit; font-size: 0.72rem; line-height: 1; padding: 4px 7px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-elevated); color: var(--text-muted); cursor: pointer; }
.cb-btn:hover { color: var(--text); background: var(--bg-hover); }
.msg-content > pre .cb-btn, .tb-toolbar .cb-btn, .msg-export .cb-btn {
  min-height: 44px; min-width: 44px; padding-inline: 12px;
}
.cb-btn:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.msg.assistant .msg-content.markdown .md-stream-tail { padding: 8px 12px; }
@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}
.tb-toolbar { display: flex; gap: 4px; margin: 0 0 4px; }
.msg-export { display: flex; gap: 4px; margin-top: 8px; }
/* Document-artifact card (letter/report/draft/…): reads like a document, with Copy + ⬇ .md */
.doc-card { position: relative; margin: 0.7rem 0; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elevated); padding: 2rem 1.05rem 0.9rem; }
.doc-card-bar { position: absolute; top: 6px; right: 6px; opacity: 0.45; }
.doc-card:hover .doc-card-bar { opacity: 1; }
.doc-card-body { line-height: 1.55; color: var(--text); font-size: 0.92rem; }
.doc-card-body strong { font-weight: 650; }
.doc-card-body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; }
.doc-card-body .doc-h { font-weight: 700; color: var(--text); margin: 0.7rem 0 0.3rem; line-height: 1.3; }
.doc-card-body .doc-h:first-child { margin-top: 0; }
.doc-card-body .doc-h1 { font-size: 1.12em; }
.doc-card-body .doc-h2 { font-size: 1.04em; }
.doc-card-body .doc-h3 { font-size: 0.97em; color: var(--text-muted); }
.doc-card-body .doc-ul, .doc-card-body .doc-ol { margin: 0.3rem 0; padding-left: 1.4rem; }
.doc-card-body .doc-ul li, .doc-card-body .doc-ol li { margin: 0.12rem 0; }

/* ── Login view (multi-user TOTP gate) ─────────────────────────────────────── */
.login-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 200;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 10px 40px var(--shadow-overlay);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.login-brand .brand-icon {
  font-size: 28px;
  line-height: 1;
}

.login-brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
}

.login-sub {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.login-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.98rem;
  outline: none;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.login-remember input {
  width: 15px;
  height: 15px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent, #4f46e5);
}

.login-btn {
  margin-top: 4px;
  padding: 10px 14px;
  font-weight: 600;
}

.login-error {
  color: var(--toast-text);
  font-size: 0.82rem;
  background: var(--toast-bg);
  border: 1px solid var(--toast-border);
  border-radius: 8px;
  padding: 8px 10px;
}

.login-hint {
  margin: 6px 0 0;
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
}

/* Topbar user badge (shown after login) */
.topbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.topbar-email {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  /* now a button (opens the profile editor) — keep it looking like plain text */
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 2px 4px;
  border-radius: 6px;
  cursor: pointer;
}
.topbar-email:hover { background: var(--bg-hover); color: var(--text); }

/* ── Profile modal ─────────────────────────────────────────────────────────── */
.profile-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--shadow-overlay, rgba(0, 0, 0, 0.5));
  z-index: 300;
  padding: 24px;
}
.profile-overlay[hidden] { display: none; }
.profile-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: 0 10px 40px var(--shadow-overlay, rgba(0, 0, 0, 0.4));
}
.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.profile-head h2 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.profile-sub { margin: 0 0 16px; font-size: 0.85rem; color: var(--text-muted); line-height: 1.4; }
.profile-field { display: block; margin-bottom: 14px; }
.profile-label { display: block; font-size: 0.82rem; font-weight: 500; margin-bottom: 5px; }
.profile-field .input { width: 100%; }
.profile-hint { display: block; font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; line-height: 1.35; }
.profile-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 18px;
}
.profile-status { margin-right: auto; font-size: 0.8rem; color: var(--text-muted); }
.profile-status.ok { color: #16a34a; }
.profile-status.err { color: #dc2626; }

.btn.ghost.small {
  padding: 4px 9px;
  font-size: 0.78rem;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
}

.btn.ghost.small:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* ── API guide ─────────────────────────────────────────────────────────── */
.api-guide { max-width: 900px; line-height: 1.55; }
.api-guide .guide-h { margin: 1.6rem 0 0.6rem; font-size: 1.05rem; color: var(--text); }
.api-guide .guide-h:first-child { margin-top: 0; font-size: 1.3rem; }
.api-guide .guide-intro { color: var(--text-muted); font-size: 0.92rem; }
.api-guide code { background: var(--bg-hover); padding: 0.05rem 0.35rem; border-radius: 5px; font-size: 0.85em; }
.api-guide pre { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.7rem 0.85rem; overflow-x: auto; margin: 0; }
.api-guide pre code { background: none; padding: 0; font-size: 0.82rem; line-height: 1.5; white-space: pre; }

.guide-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.7rem; }
.guide-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.85rem; background: var(--bg-elevated); }
.guide-card-label { font-weight: 600; margin-bottom: 0.3rem; }
.guide-card-best { color: var(--text-muted); font-size: 0.86rem; }

.guide-matrix { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.guide-matrix th, .guide-matrix td { border: 1px solid var(--border); padding: 0.45rem 0.6rem; text-align: center; }
.guide-matrix th { background: var(--bg-hover); font-weight: 600; }
.guide-matrix td:first-child, .guide-matrix th:first-child { text-align: left; }
.guide-size { color: var(--text-muted); font-size: 0.78rem; margin-left: 0.4rem; }
.cap-y { color: var(--success); font-weight: 700; }
.cap-n { color: var(--text-muted); }
.cap-warn { color: var(--warn-fg); font-weight: 600; font-size: 0.8rem; }
.cap-ok { color: var(--info); font-weight: 600; font-size: 0.8rem; }

/* Top-level guide section switcher (Chat & models / PDF / Web search) */
.guide-sec-tabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 1.3rem 0 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.guide-sec-tab { padding: 0.5rem 1.15rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elevated);
  color: var(--text); cursor: pointer; font-size: 0.92rem; font-weight: 600; transition: border-color 0.15s, background 0.15s; }
.guide-sec-tab:hover { border-color: var(--accent); color: var(--text); }
/* --accent is a LIGHT colour in this theme, so the active fill needs DARK text. */
.guide-sec-tab.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.guide-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; flex-wrap: wrap; }
.guide-tab { padding: 0.4rem 0.95rem; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elevated);
  color: var(--text-muted); cursor: pointer; font-size: 0.88rem; }
.guide-tab.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.guide-badges { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.7rem; }
.guide-badge { font-size: 0.74rem; padding: 0.12rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); }
.guide-badge.on { color: var(--success); border-color: rgba(63,185,80,0.4); }
.guide-badge.off { color: var(--text-muted); opacity: 0.65; }
.guide-badge.warn { color: var(--warn-fg); border-color: rgba(210,153,34,0.4); }
.guide-best, .guide-avoid, .guide-note { font-size: 0.9rem; margin: 0.35rem 0; }
.guide-avoid, .guide-note { color: var(--text-muted); }

.guide-samples { display: grid; gap: 0.8rem; margin-top: 0.9rem; }
.guide-sample-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; font-size: 0.85rem; font-weight: 600; }
.guide-copy { font-size: 0.74rem; padding: 0.18rem 0.6rem; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-hover); color: var(--text); cursor: pointer; }
.guide-copy:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* OCR document-view affordance (appears under a message after a scanned PDF is OCR'd) */
.ocr-doc-links { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.55rem; align-items: center; }
.ocr-cached { font-size: 0.78rem; font-weight: 600; color: var(--cache-text);
  background: var(--cache-bg); border: 1px solid var(--cache-border);
  padding: 0.16rem 0.5rem; border-radius: 8px; }
.ocr-doc-chip { display: inline-flex; gap: 0.35rem; align-items: center; }
.ocr-doc-view, .ocr-doc-dl { font-size: 0.82rem; padding: 0.28rem 0.7rem; border-radius: 8px;
  text-decoration: none; border: 1px solid var(--border); background: var(--bg-hover); color: var(--text); }
.ocr-doc-view { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 600; }
.ocr-doc-view:hover { filter: brightness(1.08); }
.ocr-doc-dl:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }

/* "Computed from spreadsheet" badge — exact pandas compute (structured-data path). */
.compute-badge { margin-top: 0.4rem; font-size: 0.8rem; }
.compute-badge-tag { display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.55rem; border-radius: 8px; font-weight: 600;
  color: var(--cache-text); background: var(--cache-bg); border: 1px solid var(--cache-border); }
.compute-q { display: inline-block; margin-left: 0.5rem; vertical-align: middle; }
.compute-q > summary { cursor: pointer; color: var(--text-muted); font-size: 0.78rem; list-style: none; }
.compute-q > summary:hover { color: var(--accent); }
.compute-q pre { margin: 0.35rem 0 0; padding: 0.5rem 0.7rem; border-radius: 8px;
  background: var(--bg-hover); border: 1px solid var(--border); font-size: 0.78rem;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto; }

/* "from pages …" chip — prose-RAG provenance (answer grounded in retrieved passages). */
.rag-chip { margin-top: 0.4rem; font-size: 0.8rem; }
.rag-chip-tag { display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.18rem 0.55rem; border-radius: 8px; font-weight: 600;
  color: var(--docchip-text); background: var(--docchip-bg); border: 1px solid var(--docchip-border); }

/* ── User menu (Sign-out dropdown → Admin dashboard entry) ─────────────────── */
.user-menu-wrap { position: relative; display: inline-flex; }
.user-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  z-index: 200;
  box-shadow: 0 8px 24px var(--shadow-strong);
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 8px 11px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.82rem;
  text-align: left;
  border-radius: 6px;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--bg-hover); }

/* ── Admin dashboard ─────────────────────────────────────────────────────── */
.admin-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.admin-refresh-note { font-size: 0.76rem; color: var(--text-muted); }
.admin-kpi-row { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 0.6rem; }
.admin-kpi-card {
  flex: 1 1 140px;
  min-width: 120px;
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
}
.admin-kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.admin-kpi-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
.admin-kpi-card.admin-loading, .admin-kpi-card.admin-error { color: var(--text-muted); font-size: 0.85rem; }
.admin-role-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.admin-role-admin { color: var(--text); border-color: var(--border-strong); background: var(--accent-blue-soft); }
.admin-bars { display: flex; flex-direction: column; gap: 0.65rem; margin-top: 0.5rem; }
.admin-bar { display: flex; align-items: center; gap: 0.6rem; }
.admin-bar-label { flex: 0 0 260px; font-size: 0.8rem; color: var(--text-muted); }
.admin-bar-track { flex: 1; height: 8px; border-radius: 5px; background: var(--bg-hover); overflow: hidden; }
.admin-bar-fill { height: 100%; background: var(--text-muted); border-radius: 5px; }
.admin-bar-pct { flex: 0 0 40px; text-align: right; font-size: 0.78rem; color: var(--text-muted); }
.admin-subtle { font-size: 0.82rem; color: var(--text-muted); }
.admin-error { font-size: 0.85rem; color: var(--text-muted); }

/* ── Admin "Chat log" viewer (real message content — the one exception) ──── */
.chatlog-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--shadow-overlay, rgba(0, 0, 0, 0.5));
  z-index: 300;
  padding: 24px;
}
.chatlog-overlay[hidden] { display: none; }
.chatlog-card {
  width: 100%;
  max-width: 720px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: 0 10px 40px var(--shadow-overlay, rgba(0, 0, 0, 0.4));
}
.chatlog-body { overflow-y: auto; margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.7rem; }
.chatlog-turn { border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; }
.chatlog-turn-meta { font-size: 0.74rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.chatlog-turn-prompt { font-size: 0.86rem; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.chatlog-turn-reply { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px dashed var(--border);
  font-size: 0.86rem; color: var(--text-muted); white-space: pre-wrap; word-break: break-word; }
.chatlog-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 1.5rem 0; }
/* RC-2 (Rm-4): audited "show model context" expander — snipped server-side */
.chatlog-turn-mc { margin-top: 0.4rem; }
.chatlog-turn-mc summary { font-size: 0.78rem; color: var(--text-muted); cursor: pointer; }
.chatlog-turn-mc pre { margin: 0.35rem 0 0; padding: 0.5rem; max-height: 240px; overflow: auto;
  font-size: 0.76rem; background: var(--bg-secondary, rgba(128,128,128,0.08));
  border: 1px dashed var(--border); border-radius: 8px;
  white-space: pre-wrap; word-break: break-word; }

/* ── Talk-to-Inbox draft composer affordance (PLAN_INBOX_DRAFT_FIXES 29-07):
   the editable textarea read as static text; the caption + border + focus
   outline make editability unmistakable. Vars are themed above, so one rule
   set covers light + dark. ── */
.draft-edit-hint {
  font-size: 0.78rem;
  opacity: 0.8;
  margin: 0.1rem 0 0.35rem;
  font-style: italic;
}
.draft-composer textarea.draft-body-edit {
  border: 1px solid var(--border-strong, #a1a1aa);
  background: var(--bg, #fff);
}
.draft-composer textarea.draft-body-edit:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-blue-soft);
}
.draft-composer.draft-stale .draft-edit-hint,
.draft-composer.draft-sent .draft-edit-hint {
  opacity: 0.45;
  text-decoration: none;
  font-style: normal;
}

/* ── Knowledge document table (UX plan rev 2 Phase A) ─────────────────── */
.knowledge-toolbar { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 4px; }
.knowledge-toolbar-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.knowledge-counts { color: var(--text-muted); font-size: .78rem; }
.knowledge-filter { max-width: 300px; }
.knowledge-help { position: relative; }
.knowledge-help > summary { list-style: none; cursor: pointer; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; border: 1px solid var(--border-strong); color: var(--text-muted); font-weight: 700; user-select: none; }
.knowledge-help > summary::-webkit-details-marker { display: none; }
.knowledge-help[open] > summary { color: var(--info); border-color: var(--info); }
.knowledge-help-pop { position: absolute; z-index: 30; top: 38px; left: 0; width: 330px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elevated); box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: .78rem; }
.knowledge-help-pop ul { margin: 8px 0; padding-left: 18px; color: var(--text-muted); line-height: 1.5; }
.knowledge-help-pop .knowledge-help-limits { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); color: var(--text-muted); }
.knowledge-table-wrap { margin-top: 10px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elevated); overflow-x: auto; transition: border-color .15s, background .15s; }
.knowledge-table-wrap.knowledge-dragover { border: 1px dashed var(--info); background: var(--accent-blue-soft); }
.knowledge-row { display: grid; grid-template-columns: minmax(180px, 1fr) 128px 150px 110px 76px 40px; gap: 10px; align-items: center; padding: 10px 16px; min-width: 720px; }
.knowledge-row-head { color: var(--text-muted); font-size: .7rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; border-bottom: 1px solid var(--border); padding-top: 12px; padding-bottom: 8px; }
.knowledge-doc-list { list-style: none; margin: 0; padding: 0; }
.knowledge-doc-item { border-bottom: 1px solid var(--border); }
.knowledge-doc-item:last-child { border-bottom: 0; }
.knowledge-doc-item .knowledge-row { padding-top: 11px; padding-bottom: 11px; }
.knowledge-name { display: flex; align-items: center; gap: 9px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .84rem; font-weight: 600; }
.knowledge-ext { flex: 0 0 auto; padding: 3px 6px; border-radius: 7px; color: var(--info); background: var(--badge-blue-bg); font-size: .6rem; font-weight: 800; letter-spacing: .04em; }
.knowledge-chip { white-space: nowrap; padding: 4px 9px; border-radius: 999px; font-size: .7rem; font-weight: 700; }
.knowledge-chip-ready { color: var(--badge-green-text); background: var(--badge-green-bg); }
.knowledge-chip-pending { color: var(--info); background: var(--badge-blue-bg); }
.knowledge-chip-error { color: var(--danger-text); background: var(--danger-bg); border: 1px solid var(--danger-border); }
.knowledge-added, .knowledge-when, .knowledge-size { color: var(--text); font-size: .78rem; white-space: nowrap; }
.knowledge-muted { color: var(--text-muted); }
.knowledge-guidance { grid-column: 1 / -1; margin: -4px 16px 10px 16px; padding-left: 12px; color: var(--text-muted); font-size: .75rem; line-height: 1.5; }
.website-source-line { margin: -4px 16px 10px 16px; padding-left: 36px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.website-source-link { border: 0; padding: 0; background: transparent; color: var(--link); cursor: pointer; font-size: .72rem; text-decoration: underline; text-underline-offset: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.website-source-link:hover { color: var(--info); }
.website-details { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.website-details div { padding: 9px; border: 1px solid var(--border); border-radius: 9px; background: var(--badge-blue-bg); }
.website-details span, .website-details strong { display: block; }
.website-details span { color: var(--text-muted); font-size: .68rem; }
.website-details strong { margin-top: 3px; font-size: .8rem; }
@media (max-width: 560px) { .website-details { grid-template-columns: repeat(2, 1fr); } }
.knowledge-doc-item[data-status="failed"] .knowledge-guidance,
.knowledge-doc-item[data-status="delete_failed"] .knowledge-guidance { color: var(--danger-text); }
.knowledge-more { display: inline; }
.knowledge-more > summary { display: inline; cursor: pointer; color: var(--link); list-style: none; }
.knowledge-more > summary::-webkit-details-marker { display: none; }
.knowledge-empty-drop { margin-top: 14px; }

/* ── Knowledge Phase B: staged target + bottom Integrations ───────────── */
.knowledge-staged-target { margin-top: 12px; padding: 10px 14px; border: 1px solid var(--border); border-left: 3px solid var(--info); border-radius: 10px; background: var(--badge-blue-bg); color: var(--text); font-size: .8rem; line-height: 1.5; }
.knowledge-integrations { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--border); }
.knowledge-integration-row { margin-top: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elevated); }
.knowledge-integration-row > summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; }
.knowledge-integration-row > summary::-webkit-details-marker { display: none; }
.knowledge-integration-name { flex: 1; min-width: 0; font-size: .86rem; font-weight: 650; }
.knowledge-integration-manage { color: var(--link); font-size: .78rem; font-weight: 650; }
.knowledge-integration-row[open] .knowledge-integration-manage { color: var(--text-muted); }
.knowledge-integration-body { padding: 0 16px 14px; border-top: 1px solid var(--border); }
.knowledge-integration-body .settings-hint { margin-top: 12px; }
.knowledge-ws-field { min-width: 230px; margin-right: 4px; }
.knowledge-toolbar-row .knowledge-ws-field span { font-size: .7rem; }

/* ── Workspaces tab redesign (03-08): compact list + card detail ──────── */
.ws-list-col { max-width: 380px; }
.ws-create-more { margin: 8px 0 4px; font-size: .78rem; }
.ws-create-more > summary { cursor: pointer; color: var(--text-muted); list-style: none; }
.ws-create-more > summary::-webkit-details-marker { display: none; }
.ws-create-more > summary::before { content: "▸ "; }
.ws-create-more[open] > summary::before { content: "▾ "; }
.ws-create-more textarea { width: 100%; margin-top: 8px; }
.ws-compact-list { margin-top: 14px; }
.ws-compact-list .ws-row { padding: 0; border-bottom: 1px solid var(--border); }
.ws-compact-list .ws-open { display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 10px; border: 0; background: none; color: var(--text); font: inherit; font-size: .84rem; cursor: pointer; text-align: left; border-radius: 8px; }
.ws-compact-list .ws-open:hover { background: var(--bg-elevated); }
.ws-compact-list .ws-active .ws-open { background: var(--badge-blue-bg); font-weight: 650; }
.ws-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-row-dot { color: var(--info); font-size: .6rem; }
.ws-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.ws-detail-head h3 { margin: 0; }
.ws-detail-actions { display: flex; gap: 8px; }
.ws-card { margin-top: 14px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elevated); }
.org-hub-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.org-hub-heading h3 { margin: 0; }
.org-hub-heading .ws-card-hint { margin-top: 4px; }
.org-workspace-create-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: end; margin-top: 14px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.org-ws-field { display: grid; gap: 5px; min-width: 0; }
.org-ws-field > span { color: var(--text-muted); font-size: .7rem; font-weight: 700; }
.org-ws-field .api-key-name-input { width: 100%; min-width: 0; }
.org-ws-field textarea { width: 100%; resize: vertical; }
.org-form-span { grid-column: 1 / -1; }
.org-form-actions { display: flex; justify-content: flex-end; gap: 8px; grid-column: 1 / -1; }
.org-form-actions-split { flex-wrap: wrap; }
.org-workspace-detail { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.org-workspace-detail .ws-card-title,
.org-workspace-detail .ws-card-hint,
.org-workspace-detail .org-form-actions { grid-column: 1 / -1; }
.org-admin-badge { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; background: var(--badge-blue-bg); color: var(--info); font-size: .68rem; font-weight: 750; }
#orgWorkspaceAdminPanel { margin-top: 24px; }
.org-admin-step { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.org-admin-step-title { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.org-admin-step-title > div { display: grid; gap: 2px; }
.org-admin-step-title strong { color: var(--text); font-size: .9rem; }
.org-admin-step-title small { color: var(--text-muted); font-size: .72rem; line-height: 1.45; }
.org-admin-step-number { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; background: var(--badge-blue-bg); color: var(--info); font-size: .72rem; font-weight: 800; }
.org-admin-step .api-key-create { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; margin-bottom: 0; }
.org-admin-step .api-key-create .btn { justify-self: end; }
.org-admin-membership-action { grid-column: 1 / -1; }
.org-admin-organization-list { display: grid; gap: 10px; margin-bottom: 14px; }
.org-admin-organization { display: grid; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elevated); }
.org-admin-organization-summary { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.org-admin-organization-summary > div { display: grid; gap: 3px; min-width: 0; }
.org-admin-organization-summary span { color: var(--text-muted); font-size: .7rem; }
.org-admin-state { flex: 0 0 auto; padding: 3px 7px; border-radius: 999px; background: var(--badge-blue-bg); text-transform: capitalize; }
.org-admin-organization-actions { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; gap: 8px; align-items: center; }
.btn.danger { border-color: var(--danger-border); color: var(--danger-text); }
.org-archive-impact-counts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 10px 0; }
.org-archive-impact-counts span { padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--badge-blue-bg); }
.app-modal-confirmation-field { display: grid; gap: 6px; margin-top: 16px; font-weight: 700; }
.app-modal-confirmation-field input { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.org-admin-membership-guidance { margin: 0 0 14px; padding: 10px 12px; border-left: 3px solid var(--info); border-radius: 6px; background: var(--badge-blue-bg); color: var(--text-muted); font-size: .76rem; line-height: 1.5; }
.org-field-help { color: var(--text-muted); font-size: .68rem; line-height: 1.4; }
.org-admin-step > .settings-hint { margin: 10px 0 0; }
.org-ws-no-organization { margin-top: 14px; }
.org-library-toolbar { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.org-library-toolbar .org-ws-field { flex: 1 1 260px; }
.org-library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.org-library-upload { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-elevated); }
.org-library-upload input[type="file"] { width: 100%; color: var(--text-muted); font-size: .76rem; }
.org-library-upload .btn { justify-self: end; }
.org-library-lists { display: grid; gap: 16px; margin-top: 14px; }
.org-library-lists h4 { margin: 0 0 8px; font-size: .82rem; color: var(--text); }
.org-library-table td:last-child { text-align: right; white-space: nowrap; }
.slash-menu { margin: 0 0 8px 54px; width: min(420px, calc(100% - 54px)); padding: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elevated); box-shadow: 0 10px 24px rgba(0,0,0,.18); }
.slash-menu-item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.slash-menu-item:hover, .slash-menu-item:focus { background: var(--badge-blue-bg); outline: none; }
.slash-menu-item strong { font-size: .82rem; }
.slash-menu-item span { min-width: 0; color: var(--text-muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.org-command-chip { display: inline-flex; align-items: center; width: fit-content; max-width: calc(100% - 54px); margin: 0 0 8px 54px; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; background: var(--badge-blue-bg); color: var(--info); font-size: .72rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.office-card-provenance { display: block; margin-top: 2px; color: var(--text-muted); font-size: .7rem; }
.office-field-receipt { margin-top: 6px; color: var(--text-muted); font-size: .7rem; }
.office-field-receipt summary { cursor: pointer; font-weight: 700; }
.office-field-receipt-row { display: grid; grid-template-columns: minmax(120px, .8fr) minmax(0, 1.2fr); gap: 8px; padding: 3px 0; border-top: 1px solid var(--border); }
.office-field-receipt-row strong { min-width: 0; color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.template-fill-card { margin-top: 12px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elevated); }
.template-fill-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.template-fill-head strong { font-size: .9rem; }
.template-fill-head span { color: var(--text-muted); font-size: .72rem; }
.template-fill-form { display: grid; gap: 12px; }
.template-fill-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.template-fill-group legend { padding: 0 4px; color: var(--text-muted); font-size: .72rem; font-weight: 700; }
.template-fill-field { display: grid; gap: 4px; min-width: 0; }
.template-fill-field span { color: var(--text-muted); font-size: .7rem; }
.template-fill-field input { width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: .8rem; }
.template-fill-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.template-fill-status { color: var(--text-muted); font-size: .74rem; }
.website-import-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.website-import-form input { flex: 1 1 280px; min-width: 180px; }
.website-import-form select { flex: 0 1 210px; min-width: 180px; }
.website-import-progress { margin-top: 10px; color: var(--text-muted); font-size: .78rem; line-height: 1.5; }
.website-import-card .connector-status { display: block; margin-top: 7px; }
.website-report-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin: 10px 0; }
.website-report-summary div { padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--badge-blue-bg); }
.website-report-summary span, .website-report-summary strong { display: block; }
.website-report-summary span { color: var(--text-muted); font-size: .66rem; }
.website-report-summary strong { margin-top: 2px; font-size: .8rem; }
.website-report-note { padding: 9px 11px; border-left: 3px solid var(--info); background: var(--badge-blue-bg); }
.website-report-table-wrap { max-height: 330px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.website-report-table { width: 100%; border-collapse: collapse; font-size: .72rem; }
.website-report-table th, .website-report-table td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.website-report-table th { position: sticky; top: 0; background: var(--bg-elevated); color: var(--text-muted); font-size: .65rem; text-transform: uppercase; }
.website-report-table td:first-child { min-width: 180px; max-width: 250px; overflow-wrap: anywhere; }
.website-report-table a { color: var(--link); }
.website-report-status { font-weight: 700; white-space: nowrap; }
.website-report-reason { margin-top: 3px; color: var(--text-muted); line-height: 1.35; }
.website-report-use-url { display: block; margin-top: 5px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 5px; background: transparent; color: var(--link); cursor: pointer; font-size: .66rem; }
.ws-card-title { font-size: .72rem; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; }
.ws-card-hint { margin: 10px 0 0; color: var(--text-muted); font-size: .74rem; line-height: 1.5; }
.ws-card textarea { width: 100%; }
.ws-knowledge-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ws-knowledge-summary { font-size: .86rem; font-weight: 600; }
.ws-summary-error { color: var(--danger-text); }
.ws-efix-chip { padding: 4px 10px; border-radius: 999px; font-size: .7rem; font-weight: 700; color: var(--badge-green-text); background: var(--badge-green-bg); }

/* ── Workspaces v2: single-column list → drill-in ─────────────────────── */
.ws-screen { max-width: 760px; }
.ws-screen-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.ws-screen-head .settings-hint { margin: 0; }
.ws-cards { list-style: none; margin: 0; padding: 0; }
.ws-card-row { margin-top: 10px; padding: 0; }
.ws-card-row .ws-open { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; border: 0; background: none; color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.ws-card-row:hover { border-color: var(--info); }
.ws-row-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; font-weight: 650; }
.ws-row-meta { color: var(--text-muted); font-size: .72rem; white-space: nowrap; }
.ws-row-go { color: var(--text-muted); font-size: 1.1rem; }
.ws-back { border: 0; background: none; padding: 0 0 6px; color: var(--link); font: inherit; font-size: .8rem; cursor: pointer; }
.ws-view-title { margin: 6px 0 2px; }
.ws-optional { margin-left: 6px; font-weight: 500; text-transform: none; letter-spacing: 0; color: var(--text-muted); }
.ws-name-heading { flex: 1; min-width: 0; border: 1px solid transparent; border-radius: 8px; background: none; color: var(--text); font-size: 1.25rem; font-weight: 700; padding: 4px 8px; margin-left: -8px; }
.ws-name-heading:hover { border-color: var(--border); }
.ws-name-heading:focus { border-color: var(--info); outline: none; background: var(--bg-elevated); }
.ws-danger-row { margin-top: 16px; display: flex; justify-content: flex-end; }
.ws-danger-row .btn { color: var(--danger-text); }
.ws-staged-fact { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ── App modal (03-08 polish) ─────────────────────────────────────────── */
.app-modal-overlay { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.app-modal { width: min(480px, 100%); max-height: 85vh; overflow-y: auto; padding: 22px 24px; border: 1px solid var(--border); border-radius: 16px; background: var(--bg-elevated); box-shadow: 0 24px 60px rgba(0,0,0,.4); }
.app-modal h3 { margin: 0 0 12px; font-size: 1.05rem; line-height: 1.4; }
.app-modal-body { color: var(--text); font-size: .84rem; line-height: 1.55; }
.app-modal-body p { margin: 10px 0 0; color: var(--text-muted); }
.app-modal-files { margin: 0; padding-left: 20px; }
.app-modal-files li { margin: 3px 0; font-weight: 600; }
.app-modal-note { margin-top: 12px; padding: 10px 14px; border: 1px solid var(--border); border-left: 3px solid var(--info); border-radius: 10px; background: var(--badge-blue-bg); }
.app-modal-note ul { margin: 6px 0 0; padding-left: 18px; color: var(--text-muted); }
.app-modal-warn { margin-top: 8px; color: var(--danger-text); font-weight: 600; }
.app-modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.app-modal-danger { color: var(--danger-text); border-color: var(--danger-border); }

/* ── Mobile pass (<860px): Knowledge + Workspaces (03-08 polish) ──────── */
@media (max-width: 860px) {
  .knowledge-toolbar-row { flex-direction: column; align-items: stretch; }
  .knowledge-ws-field { min-width: 0; margin-right: 0; }
  .knowledge-toolbar-row .btn { width: 100%; }
  .knowledge-help { align-self: flex-start; }
  .knowledge-help-pop { width: min(330px, 86vw); }
  .knowledge-filter { max-width: none; }
  .ws-screen-head { flex-direction: column; align-items: stretch; }
  .ws-screen-head .btn { width: 100%; }
  .ws-detail-head { flex-wrap: wrap; }
  .ws-name-heading { font-size: 1.1rem; }
  .ws-row-meta { display: none; }   /* name + chevron only on phones */
  .org-workspace-create-form { grid-template-columns: 1fr; align-items: stretch; }
  .org-workspace-create-form .btn { width: 100%; }
  .org-workspace-detail,
  .org-library-grid,
  .org-admin-step .api-key-create { grid-template-columns: 1fr; }
  .org-admin-organization-actions { grid-template-columns: 1fr; }
  .org-admin-organization-actions .btn { width: 100%; }
  .org-library-upload .btn { width: 100%; justify-self: stretch; }
  .template-fill-group { grid-template-columns: 1fr; }
  .template-fill-actions { align-items: stretch; flex-direction: column; }
  .org-hub-heading { align-items: stretch; flex-direction: column; }
  .org-hub-heading .btn { width: 100%; }
  .org-form-actions { justify-content: stretch; }
  .org-form-actions .btn { flex: 1 1 auto; }
  .app-modal { padding: 18px; }
}
.side-nav-group { margin: 0; }
.side-nav-child { padding-left: 30px; font-size: .8rem; }
.side-nav-chevron { color: var(--text-muted); font-size: .9rem; }
@media (max-width: 560px) { .website-report-summary { grid-template-columns: repeat(2, 1fr); } }
/* Durable review action, visually a button while retaining keyboard link behavior. */
.msg-content a[href^="/office/drafts/"] {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border: 1px solid currentColor;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: none;
}
.msg-content a[href^="/office/drafts/"]:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}
.msg-content a[href^="/office/drafts/"][aria-disabled="true"] { opacity: 0.65; }
