:root {
  --ink: #0a0a0a;
  --ink-soft: #2b2b2b;
  --ink-inverse: #ffffff;
  --paper: #ffffff;
  --line: #111111;
  --line-faint: #e2e2e2;
  --muted: #8a8a8a;
  --field: #fafafa;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;

  /* Semantic (kept monochrome-adjacent — this app does not use a brand hue) */
  --danger: #b3261e;
  --danger-faint: rgba(179, 38, 30, 0.08);
  --ok: #2f7d4f;
  --warn: #9a6b12;
  --accent-faint: rgba(10, 10, 10, 0.05);

  /* A preview surface is always light — a previewed PDF/image/doc keeps its
     own colors regardless of app theme, so this token is intentionally never
     overridden in the dark block below. */
  --preview-surface: #fafafa;

  /* Chart.js reads these via getComputedStyle at render time (see buildChart
     in app.js) so charts retint with the theme without their own literals. */
  --chart-grid: #ececec;
  --chart-text: #6b6b6b;
  --chart-pie-border: #ffffff;

  /* Spacing scale */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;

  --border: 1.5px solid var(--line);
  --border-faint: 1.5px solid var(--line-faint);

  --dur-fast: 120ms;
  --dur-med: 180ms;
  --ease: cubic-bezier(0.2, 0, 0.2, 1);

  --z-dock: 60;
  --z-modal: 100;
  --z-palette: 120;
  --z-toast: 140;
}

/* Dark palette. Applied when the OS prefers dark AND the user hasn't chosen
   light explicitly, or when the user has explicitly chosen dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f2f2f0;
    --ink-soft: #d4d4d1;
    --ink-inverse: #0a0a0a;
    --paper: #131312;
    --line: #f0f0ee;
    --line-faint: #35342f;
    --muted: #93938d;
    --field: #1c1c1a;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
    --danger: #ff7a6b;
    --danger-faint: rgba(255, 122, 107, 0.12);
    --ok: #6fcf97;
    --warn: #e0b355;
    --accent-faint: rgba(255, 255, 255, 0.07);
    --chart-grid: #333331;
    --chart-text: #a3a39d;
    --chart-pie-border: #131312;
  }
}
:root[data-theme="dark"] {
  --ink: #f2f2f0;
  --ink-soft: #d4d4d1;
  --ink-inverse: #0a0a0a;
  --paper: #131312;
  --line: #f0f0ee;
  --line-faint: #35342f;
  --muted: #93938d;
  --field: #1c1c1a;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
  --danger: #ff7a6b;
  --danger-faint: rgba(255, 122, 107, 0.12);
  --ok: #6fcf97;
  --warn: #e0b355;
  --accent-faint: rgba(255, 255, 255, 0.07);
  --chart-grid: #333331;
  --chart-text: #a3a39d;
  --chart-pie-border: #131312;
}

/* Respect the OS/browser motion preference everywhere. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Visible keyboard focus everywhere; components with a tighter fit (list
   rows, buttons already on a border) override with a more specific rule. */
:focus-visible {
  outline: 1.5px solid var(--ink);
  outline-offset: 2px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}
body {
  display: flex;
  flex-direction: column;
}
#app-shell {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
#app-shell.hidden { display: none !important; }
.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wordmark-logo {
  height: 48px;      /* adjust to match your text size */
  width: auto;
  display: block;
}
/* ---------- Masthead ---------- */
.masthead { border-bottom: 1.5px solid var(--line); }
.masthead-inner {
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.wordmark { font-family: var(--serif); font-size: 27px; letter-spacing: 0.01em; }
.wordmark-main { font-weight: 500; }
.wordmark-sep { margin: 0 6px; color: var(--muted); }
.wordmark-sub { font-style: italic; color: var(--ink-soft); }
.masthead-meta { display: flex; align-items: center; gap: 10px; }
.masthead-tagline {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  transition: background 0.3s;
}
.dot.online { background: var(--ink); }
.dot.offline { box-shadow: inset 0 0 0 1.5px var(--muted); background: transparent; }

/* ---------- Layout ---------- */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 260px 360px 1fr;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}

/* ---------- Suggestion + saved bars (above composer) ---------- */
.suggestions,
.samples-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 22px 0;
}
.suggestions-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 2px;
}
.suggestion {
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  text-align: left;
  padding: 7px 11px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.suggestion:hover { border-color: var(--line); color: var(--ink); }

/* "Used:" source chips under an answer. */
.src-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}
.src-label {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}
.src-chip {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  padding: 3px 8px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  color: var(--ink-soft);
  cursor: pointer;
}
.src-chip:hover { border-color: var(--line); color: var(--ink); }

/* Aggregate provenance: "Based on all N invoices" -> expandable chips. */
.agg-sources { margin-top: 10px; }
.agg-toggle {
  font-family: "Inter", sans-serif;
  font-size: 0.74rem;
  background: none;
  border: none;
  padding: 0;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 1px dashed var(--line-faint);
}
.agg-toggle::before { content: "▸ "; }
.agg-toggle.open::before { content: "▾ "; }
.agg-toggle:hover { color: var(--ink); }
.agg-list { display: none; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.agg-list.open { display: flex; }

/* Rendered chart container inside an assistant message. */
.chart-box {
  margin-top: 12px;
  padding: 14px;
  border: 1.5px solid var(--line-faint);
  background: var(--paper);
  max-width: 540px;
}
.chart-box canvas { width: 100% !important; height: auto !important; }
.chart-dl {
  margin-top: 10px;
  font-family: "Inter", sans-serif;
  font-size: 0.74rem;
  padding: 5px 10px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  color: var(--ink-soft);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.chart-dl:hover { border-color: var(--line); color: var(--ink); }

/* ---------- Clickable invoice rows ---------- */
.doc-item-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--paper);
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.panel--history,
.panel--kb { border-right: 1.5px solid var(--line); }
.panel--kb { padding: 26px; overflow-y: auto; }

/* History */
.panel--history { padding: 22px 18px; overflow: hidden; }
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 0 4px;
}
.history-head .panel-title { font-size: 18px; }
.history-head .btn--ghost { padding: 6px 12px; font-size: 12px; }
.history-head-actions { display: flex; align-items: center; gap: 6px; }
.history-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: none;
  border: 1.5px solid transparent;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}
.history-toggle:hover { background: var(--field); border-color: var(--line-faint); }

/* Collapsed = thin icon rail: hide everything except the toggle + avatar. */
.panel--history.collapsed { padding: 22px 8px; align-items: center; }
.panel--history.collapsed .history-head { flex-direction: column-reverse; gap: 10px; }
.panel--history.collapsed .panel-title,
.panel--history.collapsed #new-chat,
.panel--history.collapsed .history-body,
.panel--history.collapsed .profile-info,
.panel--history.collapsed .profile-chevron { display: none; }
.panel--history.collapsed .profile-card { justify-content: center; padding: 8px 0; }
.panel--history.collapsed .history-profile { border-top: none; }

.layout.history-collapsed { grid-template-columns: 64px 360px 1fr; }

.history-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.session-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-faint) transparent;
}
.session-empty {
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
  padding: 4px;
}
.session-item {
  text-align: left;
  background: none;
  border: none;
  border-left: 2.5px solid transparent;
  padding: 11px 8px 11px 12px;
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  transition: background 0.12s, border-color 0.12s;
}
.session-item:hover { background: var(--field); }
.session-item:focus-visible { outline: 1.5px solid var(--ink); outline-offset: -1.5px; }
.session-item.active { background: var(--field); border-left-color: var(--ink); }
.session-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-item-title {
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.session-item.active .session-item-title { font-weight: 600; }
.session-item-meta {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.session-del {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.session-item:hover .session-del,
.session-item:focus-within .session-del { opacity: 1; }
.session-del:hover { color: var(--paper); background: var(--ink); }
.session-del svg { display: block; }

/* Bottom-of-sidebar account card (avatar + name + logout menu). */
.history-profile {
  position: relative;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1.5px solid var(--line-faint);
}
.profile-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  text-align: left;
}
.profile-card:hover { background: var(--field); }
.profile-avatar {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.profile-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.profile-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.profile-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-badge {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1.5px solid var(--line-faint);
  padding: 1px 4px;
}
.profile-sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.profile-chevron { color: var(--muted); font-size: 14px; }
.profile-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 8px;
  right: 8px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  padding: 5px;
  z-index: 10;
  animation: pop 0.14s ease;
}
.profile-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s;
}
.profile-menu-item { text-decoration: none; font-family: inherit; }
.profile-menu-item svg { flex-shrink: 0; color: var(--muted); }
.profile-menu-item:hover { background: var(--field); }
.profile-menu-item:hover svg { color: var(--ink); }

.panel-head { margin-bottom: 20px; }
.panel-title { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 21px; }
.panel-desc { margin: 6px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); }

/* ---------- Forms / dropzone ---------- */
.ingest-form { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin-top: 6px;
}
.muted { color: var(--muted); }
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 26px 16px;
  border: 1.5px dashed var(--line-faint);
  background: var(--field);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--line); background: var(--paper); }
.dropzone-icon {
  font-size: 20px;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: 1.5px solid var(--line);
  border-radius: 50%;
}
.dropzone-text { font-size: 14px; font-weight: 500; }
.dropzone.has-file .dropzone-text { font-family: var(--mono); font-size: 12.5px; }
.dropzone-hint { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--muted); }

/* KB documents list */
.kb-docs { margin-top: 24px; padding-top: 18px; border-top: 1.5px solid var(--line-faint); }
.kb-docs-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.kb-docs-head .field-label { margin-top: 0; }
.kb-docs-count { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--muted); }
.docs-list { display: flex; flex-direction: column; gap: 2px; }
.docs-empty { font-size: 12.5px; color: var(--muted); font-style: italic; margin: 2px 0; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 6px 8px 10px;
  border-left: 2.5px solid var(--line-faint);
  transition: background 0.12s, border-color 0.12s;
}
.doc-item:hover { background: var(--field); border-left-color: var(--ink); }
.doc-item-name {
  font-size: 12.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item-body:hover .doc-item-name { text-decoration: underline; }
.doc-item-meta {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.doc-del {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.12s, color 0.12s, background 0.12s;
}
.doc-item:hover .doc-del { opacity: 1; }
.doc-del:hover { color: var(--paper); background: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  padding: 11px 18px;
  cursor: pointer;
  border: 1.5px solid var(--line);
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.btn--solid { background: var(--ink); color: var(--paper); margin-top: 14px; }
.btn--solid:hover { background: var(--ink-soft); }
.btn--ghost { background: var(--paper); color: var(--ink); padding: 8px 16px; }
.btn--ghost:hover { background: var(--ink); color: var(--paper); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Ingest log ---------- */
.log { margin-top: 18px; display: flex; flex-direction: column; gap: 7px; }
.log-item {
  font-family: var(--mono);
  font-size: 12px;
  padding: 9px 12px;
  border-left: 2.5px solid var(--line);
  background: var(--field);
  line-height: 1.5;
  animation: slide 0.25s ease;
}
.log-item.err { border-left-color: var(--muted); color: var(--ink-soft); }
@keyframes slide { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; } }

.ingest-log-head { margin-top: 18px; }
.ingest-log-head.hidden { display: none; }

/* Per-file upload progress row. */
.ingest-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-left: 2.5px solid var(--line-faint);
  background: var(--field);
  overflow: hidden;
  animation: slide 0.2s ease;
}
.ingest-row-name {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ingest-row-detail {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 40%;
}
.ingest-row-state {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  padding: 2px 6px;
  border: 1.5px solid currentColor;
}
.ingest-row-state--queued,
.ingest-row-state--extracting { color: var(--ink-soft); }
.ingest-row-state--stored { color: var(--ok); }
.ingest-row-state--duplicate { color: var(--warn); }
.ingest-row-state--error { color: var(--danger); }
.ingest-row-bar {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 2px;
  background: var(--line-faint);
  overflow: hidden;
}
.ingest-row-bar-fill {
  position: absolute;
  inset: 0;
  width: 40%;
  background: var(--ink);
  animation: ingest-sweep 1.1s ease-in-out infinite;
}
@keyframes ingest-sweep {
  0% { left: -40%; }
  100% { left: 100%; }
}

/* =====================================================================
   CHAT + PREVIEW SPLIT
   The chat column is a flex row: chat on the left, a dockable preview on the
   right with a draggable divider. When the dock is hidden, chat fills the
   column.
   ===================================================================== */
.panel--chat {
  overflow: hidden;
  flex-direction: row;
}
.chat-main {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.preview-resizer {
  flex: 0 0 6px;
  cursor: col-resize;
  background: var(--line-faint);
  transition: background 0.12s;
}
.preview-resizer:hover,
.preview-resizer.dragging { background: var(--line); }
.preview-resizer[hidden] { display: none; }

.preview-dock {
  flex: 0 0 46%;
  min-width: 320px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.preview-dock[hidden] { display: none; }

.preview-dock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1.5px solid var(--line-faint);
}
.preview-dock-title {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-dock-close {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--ink-soft);
}
.preview-dock-close:hover { color: var(--ink); }

.preview-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1.5px solid var(--line-faint);
}
.ptab {
  font-family: "Inter", sans-serif;
  font-size: 0.78rem;
  padding: 5px 11px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  color: var(--ink-soft);
  cursor: pointer;
  text-decoration: none;
}
.ptab.active { border-color: var(--line); color: var(--ink); }
.ptab--dl { margin-left: auto; }

/* The pane fills remaining dock height; its single child stretches to fill. */
.preview-pane {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.preview-pane > * { flex: 1; min-height: 0; }

.preview-frame { width: 100%; height: 100%; border: none; background: var(--preview-surface); display: block; }
.preview-image { width: 100%; height: 100%; object-fit: contain; background: var(--preview-surface); display: block; }

.preview-doc { overflow: auto; padding: 16px; font-size: 13px; line-height: 1.6; }
.preview-pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
}
.preview-note {
  margin: 0 0 12px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.preview-loading {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}
.preview-loading.err { color: var(--ink-soft); }

/* Tables rendered inside any preview doc (CSV / Excel / extracted data). */
.preview-doc table,
.preview-table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 12px;
}
.preview-doc th, .preview-doc td,
.preview-table th, .preview-table td {
  border: 1px solid var(--line-faint);
  padding: 6px 9px;
  text-align: left;
  vertical-align: top;
}
.preview-doc th,
.preview-table th { background: var(--field); font-weight: 600; }
.preview-doc--rich { line-height: 1.65; }
.preview-doc--rich h1, .preview-doc--rich h2, .preview-doc--rich h3 {
  font-family: var(--serif);
  margin: 16px 0 8px;
}
.preview-doc--rich p { margin: 0 0 10px; }
.preview-doc--rich img { max-width: 100%; height: auto; }
/* mammoth carries inline colors from the source .docx's run formatting —
   force them off so a dark-on-white doc can't render as dark-on-dark. */
.preview-doc--rich, .preview-doc--rich * {
  color: var(--ink) !important;
  background-color: transparent !important;
}

/* Excel sheet switcher */
.sheet-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.sheet-tab {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 9px;
  border: 1.5px solid var(--line-faint);
  background: var(--paper);
  color: var(--ink-soft);
  cursor: pointer;
}
.sheet-tab.active { border-color: var(--line); color: var(--ink); }
.sheet-pane { overflow: auto; }

/* ---------- Chat head / thread / messages ---------- */
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 20px 14px;
  border-bottom: 1.5px solid var(--line-faint);
}
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 320px; }
.empty-mark { font-size: 40px; color: var(--line-faint); margin-bottom: 14px; }
.empty-state p { font-family: var(--serif); font-size: 16px; line-height: 1.6; font-style: italic; }

.msg { display: flex; flex-direction: column; gap: 7px; max-width: 86%; animation: rise 0.3s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }
.msg-role {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.msg-body {
  font-size: 14.5px;
  line-height: 1.65;
  padding: 13px 16px;
  border: 1.5px solid var(--line-faint);
}
.msg-body strong { font-weight: 600; }
.msg--user { align-self: flex-end; align-items: flex-end; }
.msg--user .msg-body { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msg--assistant { align-self: flex-start; }
.msg--assistant .msg-body { background: var(--paper); }

.msg-typing .msg-body { display: inline-flex; gap: 5px; }
.msg-typing .dotpulse {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: pulse 1.1s infinite;
}
.msg-typing .dotpulse:nth-child(2) { animation-delay: 0.18s; }
.msg-typing .dotpulse:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

/* Comparison tables in answers */
.msg-body table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.msg-body th, .msg-body td {
  border: 1px solid var(--line-faint);
  padding: 7px 10px;
  text-align: left;
  vertical-align: top;
}
.msg-body th { background: var(--field); font-weight: 600; }
.msg-body tr:nth-child(even) td { background: var(--field); }
.msg-body p { margin: 0 0 10px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { margin: 8px 0; padding-left: 20px; }
.msg-body li { margin: 3px 0; }
.msg-body code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--field);
  padding: 1px 5px;
  border: 1px solid var(--line-faint);
}
.msg-body pre {
  background: var(--field);
  border: 1.5px solid var(--line-faint);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}
.msg-body pre code { background: none; border: none; padding: 0; }
.msg-body blockquote {
  border-left: 2.5px solid var(--line-faint);
  margin: 8px 0;
  padding-left: 12px;
  color: var(--ink-soft);
}

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px 16px;
  border-top: 1.5px solid var(--line-faint);
}
.composer-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.composer-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.5;
  padding: 12px 14px;
  border: 1.5px solid var(--line-faint);
  background: var(--field);
  resize: none;
  outline: none;
  max-height: 140px;
}
.composer-input:focus { border-color: var(--line); background: var(--paper); }
.composer-btn { margin-top: 0; height: 44px; }

/* ---------- Source cards (open in the side panel) ---------- */
.preview { margin-top: 10px; border: 1.5px solid var(--line-faint); }
.preview-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: var(--field);
  border-bottom: 1.5px solid var(--line-faint);
}
.preview-label {
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.preview-name {
  flex: 1; min-width: 0; font-size: 12.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.preview-actions { display: flex; gap: 8px; padding: 8px 12px; }
.preview-open, .preview-dl {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 5px 12px;
  cursor: pointer;
  border: 1.5px solid var(--line-faint);
  background: var(--paper);
  color: var(--ink-soft);
  text-decoration: none;
}
.preview-open:hover, .preview-dl:hover {
  background: var(--ink); color: var(--paper); border-color: var(--ink);
}

/* ---------- Sources expander ---------- */
.sources { margin-top: 2px; }
.sources-toggle {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-bottom: 1px solid var(--line-faint);
  padding: 0 0 2px;
  cursor: pointer;
}
.sources-toggle:hover { border-bottom-color: var(--line); }
.sources-list { margin-top: 10px; display: none; flex-direction: column; gap: 8px; }
.sources-list.open { display: flex; }

/* ---------- Saved-question chip ---------- */
.saved-chip { display: inline-flex; align-items: stretch; }
.saved-chip .suggestion { border-right: none; }
.saved-x {
  font-family: "Inter", sans-serif;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0 8px;
  background: var(--paper);
  border: 1.5px solid var(--line-faint);
  color: var(--ink-soft);
  cursor: pointer;
}
.saved-x:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Copy / Excel action buttons ---------- */
.copy-wrap { position: relative; margin: 10px 0; }
.copy-wrap > pre, .copy-wrap > table { margin: 0; }
.copy-wrap--table { overflow-x: auto; }
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 4px 9px;
  background: var(--paper);
  color: var(--ink-soft);
  border: 1.5px solid var(--line-faint);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  z-index: 2;
}
.copy-wrap:hover .copy-btn,
.copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.copy-btn.copied { opacity: 1; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msg--user .copy-btn { background: var(--ink); color: var(--paper); border-color: var(--paper); }
.msg--user .copy-btn:hover { background: var(--paper); color: var(--ink); }

/* ---------- Modal (confirm / duplicate) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--paper);
  border: 1.5px solid var(--line);
  max-width: 700px;
  width: calc(100% - 48px);
  padding: 26px 26px 22px;
  animation: pop 0.16s ease;
}
@keyframes pop { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-text { margin: 0; font-family: var(--serif); font-size: 19px; font-weight: 500; }
.modal-sub { margin: 8px 0 0; font-size: 13px; line-height: 1.55; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.modal-actions .btn { margin-top: 0; padding: 9px 18px; }
.modal-actions--three { flex-wrap: wrap; }
.modal-actions--three .btn { flex: 1; min-width: 90px; }
#dup-overlay .modal { max-width: 460px; }

#login-overlay .modal { max-width: 360px; }
.login-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
.login-input {
  font-family: var(--sans);
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--line-faint);
  background: var(--field);
  color: var(--ink);
}
.login-input:focus { outline: none; border-color: var(--ink); }
.login-error { color: var(--danger); }
#login-overlay .modal-actions { justify-content: stretch; }
#login-overlay .modal-actions .btn { flex: 1; }

/* ---------- Boot splash (pre-auth-check state, avoids a login-modal flash) ---------- */
#boot-splash {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  z-index: var(--z-modal);
}
#boot-splash .dot { animation: pulse 1.1s infinite; }
#boot-splash.hidden { display: none !important; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--ink);
  color: var(--paper);
  border: 1.5px solid var(--ink);
  font-size: 13px;
  line-height: 1.5;
  animation: rise 0.2s ease;
  pointer-events: auto;
}
.toast--danger { background: var(--danger); border-color: var(--danger); color: var(--ink-inverse); }
.toast--leaving { opacity: 0; transition: opacity var(--dur-med) var(--ease); }
.toast-msg { flex: 1; }
.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: inherit;
  opacity: 0.7;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.toast-close:hover { opacity: 1; }

/* ---------- Skeleton loaders ---------- */
.skeleton-row {
  height: 34px;
  margin: 2px 0;
  background: linear-gradient(
    100deg,
    var(--field) 30%,
    var(--line-faint) 50%,
    var(--field) 70%
  );
  background-size: 220% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -20% 0; }
}

/* ---------- Command palette ---------- */
.palette-modal {
  background: var(--paper);
  border: 1.5px solid var(--line);
  width: 560px;
  max-width: calc(100% - 48px);
  max-height: min(480px, 70vh);
  display: flex;
  flex-direction: column;
  animation: pop 0.16s ease;
}
.palette-input {
  border: none;
  border-bottom: 1.5px solid var(--line-faint);
  padding: 16px 18px;
  font-family: var(--sans);
  font-size: 15px;
  background: var(--paper);
  color: var(--ink);
}
.palette-input:focus { outline: none; border-bottom-color: var(--line); }
.palette-list { overflow-y: auto; flex: 1; min-height: 0; }
.palette-group {
  padding: 10px 18px 4px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.palette-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2.5px solid transparent;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  cursor: pointer;
}
.palette-row:hover, .palette-row.focused { background: var(--field); border-left-color: var(--ink); }
.palette-row-hint {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.palette-empty {
  padding: 24px 18px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.palette-empty.hidden { display: none; }

/* ---------- Shortcuts sheet ---------- */
.shortcuts-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.shortcuts-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; }
.shortcuts-keys { font-family: var(--mono); font-size: 11px; color: var(--ink-soft); }
kbd.key {
  display: inline-block;
  border: 1.5px solid var(--line-faint);
  padding: 1px 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  margin-left: 3px;
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-faint); }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .layout { grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; }
  .panel--history {
    grid-column: 1; grid-row: 1;
    max-height: 38vh;
    border-bottom: 1.5px solid var(--line);
  }
  .panel--kb { grid-column: 1; grid-row: 2; }
  .panel--chat { grid-column: 2; grid-row: 1 / 3; }
}

/* Below this width the split is too tight — the dock becomes a full overlay. */
@media (max-width: 900px) {
  .preview-resizer { display: none !important; }
  .preview-dock:not([hidden]) {
    position: fixed;
    inset: 0;
    z-index: var(--z-dock);
    flex-basis: auto !important;
    border-left: none;
    box-shadow: 0 0 0 100vmax rgba(10, 10, 10, 0.42);
  }
  /* The masthead now carries the agent switcher, theme toggle and (on the
     admin page) an account menu too — let it wrap instead of overflowing. */
  .masthead-inner { flex-wrap: wrap; row-gap: 8px; }
  .masthead-tagline { display: none; }
  .masthead-center { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .agent-chip-name { max-width: 160px; }
}

@media (max-width: 760px) {
  body { display: block; }
  .layout { display: block; }
  .panel { border-right: none !important; border-bottom: 1.5px solid var(--line); height: auto; }
  .panel--history { max-height: 240px; }
  .panel--chat { height: 72vh; flex-direction: row; }
  .agent-switcher { left: 0; transform: none; width: min(340px, 100vw); }
}

/* ---------- agent chip + switcher (masthead) ---------- */
.masthead-center { position: relative; display: flex; justify-content: center; flex: 1; }
.agent-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: none;
  border: 1.5px solid var(--line-faint);
  color: var(--ink);
  font-family: var(--sans);
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease);
  max-width: 100%;
}
.agent-chip:hover { border-color: var(--line); }
.agent-chip[aria-expanded="true"] { border-color: var(--line); background: var(--field); }
.agent-chip--empty { color: var(--muted); font-style: italic; }
.agent-chip-mark {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--ink-inverse);
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
}
.agent-chip--empty .agent-chip-mark { background: var(--muted); }
.agent-chip-name {
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-chip-caret { flex-shrink: 0; color: var(--muted); transition: transform var(--dur-fast) var(--ease); }
.agent-chip[aria-expanded="true"] .agent-chip-caret { transform: rotate(180deg); }

.agent-switcher {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: 340px;
  max-width: 90vw;
  background: var(--paper);
  border: 1.5px solid var(--line);
  z-index: var(--z-palette);
  animation: pop 0.14s ease;
}
.agent-switcher.hidden { display: none; }
.agent-switcher-list {
  max-height: 340px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.agent-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2.5px solid transparent;
  border-bottom: 1px solid var(--line-faint);
  padding: 10px 12px;
  font-family: inherit;
  cursor: pointer;
}
.agent-row:last-child { border-bottom: none; }
.agent-row:hover, .agent-row.focused { background: var(--field); }
.agent-row.active { background: var(--field); border-left-color: var(--ink); }
.agent-row-mark {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--ink-inverse);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 1px;
}
.agent-row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-row-name { font-size: 13.5px; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.agent-row-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }
.agent-row-stats {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}
.agent-row-active-badge {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.agent-switcher-empty {
  margin: 0;
  padding: 16px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
}
.agent-switcher-empty.hidden { display: none; }
.agent-switcher-manage {
  display: block;
  padding: 10px 12px;
  border-top: 1.5px solid var(--line-faint);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  text-decoration: none;
}
.agent-switcher-manage:hover { background: var(--field); color: var(--ink); }
.agent-switcher-manage.hidden { display: none; }

/* ---------- icon buttons (masthead) ---------- */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1.5px solid transparent;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}
.icon-btn:hover { border-color: var(--line-faint); color: var(--ink); }

/* ---------- zero-agent workspace ---------- */
.no-agent-state {
  display: none;
  margin: auto;
  text-align: center;
  max-width: 380px;
  padding: 40px 20px;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.no-agent-state.hidden { display: none !important; }
.chat-main--empty #thread,
.chat-main--empty #suggestions,
.chat-main--empty #saved-bar,
.chat-main--empty #ask-form { display: none !important; }
.chat-main--empty .no-agent-state { display: flex; flex: 1; }
.no-agent-title { margin: 4px 0 0; font-family: var(--serif); font-size: 20px; font-weight: 500; }
.no-agent-text { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.6; }
#no-agent-cta { margin-top: 6px; }

.layout--no-agent { grid-template-columns: 260px 1fr; }
.layout--no-agent .panel--kb { display: none; }
.layout--no-agent.history-collapsed { grid-template-columns: 64px 1fr; }

/* ---------- admin console ---------- */
#admin-shell { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#admin-shell.hidden { display: none !important; }
.masthead-meta { display: flex; align-items: center; gap: 14px; }

.admin-account { position: relative; }
.admin-who {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  padding: 4px 2px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.admin-who:hover { color: var(--ink); }
.admin-account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: auto;
  width: 160px;
}

.admin-layout {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 40px;
}
.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1.5px solid var(--line-faint);
  margin-bottom: 24px;
}
.admin-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1.5px;
  padding: 9px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}
.admin-tab:hover { color: var(--ink); }
.admin-tab.active { color: var(--ink); border-bottom-color: var(--line); }

/* Overview */
.stat-tiles { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 0; }
.stat-tile {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 20px;
  border: 1.5px solid var(--line);
  border-left: none;
}
.stat-tile:first-child { border-left: 1.5px solid var(--line); }
.stat-tile-value { font-family: var(--serif); font-size: 32px; font-weight: 500; line-height: 1; }
.stat-tile-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-panel { display: grid; grid-template-columns: 340px 1fr; gap: 36px; align-items: start; }
.admin-panel.hidden { display: none; }
.admin-col { min-width: 0; }
.admin-col-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.admin-col-head .panel-title { margin: 0; }
.admin-col .panel-desc { margin: 8px 0 16px; font-size: 12.5px; line-height: 1.55; color: var(--muted); }

.admin-list { display: flex; flex-direction: column; gap: 2px; }
.admin-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-left: 2.5px solid transparent;
  padding: 10px 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.admin-item:hover { background: var(--field); }
.admin-item.active { background: var(--field); border-left-color: var(--ink); }
.admin-item-name { font-size: 14px; color: var(--ink); }
.admin-item-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.admin-badge {
  font-family: var(--mono);
  font-style: normal;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1.5px solid var(--line-faint);
  padding: 1px 4px;
  margin-left: 6px;
}

.admin-form {
  border: 1.5px solid var(--line);
  padding: 22px 24px 24px;
  background: var(--paper);
}
.admin-form.hidden { display: none; }
.admin-form-title { margin: 0 0 18px; font-family: var(--serif); font-weight: 500; font-size: 19px; }
.admin-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.admin-field-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.admin-field-label--row { display: flex; align-items: baseline; justify-content: space-between; }
.admin-char-count { font-family: var(--mono); font-size: 10px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.admin-field .login-input { width: 100%; }
.admin-textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  resize: vertical;
  min-height: 180px;
}
.admin-textarea--short { min-height: 90px; }
.admin-inline-btn {
  align-self: flex-start;
  margin: -8px 0 16px;
  background: none;
  border: none;
  border-bottom: 1px dashed var(--line-faint);
  padding: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  cursor: pointer;
}
.admin-inline-btn:hover { color: var(--ink); border-bottom-color: var(--line); }

/* The non-editable tool contract, collapsed by default. */
.admin-contract {
  margin: 0 0 16px;
  border: 1.5px solid var(--line-faint);
}
.admin-contract summary {
  padding: 9px 12px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.admin-contract summary:hover { color: var(--ink); background: var(--field); }
.admin-contract-body {
  margin: 0;
  padding: 12px;
  border-top: 1.5px solid var(--line-faint);
  background: var(--field);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}
.admin-note {
  margin: -8px 0 16px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}
.admin-grants {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 220px;
  overflow-y: auto;
  border: 1.5px solid var(--line-faint);
  padding: 8px 10px;
}
.admin-grant-desc { display: block; font-size: 11.5px; color: var(--muted); margin-left: 24px; }
.admin-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 13.5px;
  cursor: pointer;
}
.admin-check input { accent-color: var(--ink); cursor: pointer; }
.admin-check input:disabled { cursor: default; }
.confirm-checkbox-row { margin-top: 16px; }

/* Segmented control (role picker) */
.segmented { display: flex; border: 1.5px solid var(--line-faint); }
.segmented-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 12px;
  background: var(--paper);
  border: none;
  border-right: 1.5px solid var(--line-faint);
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}
.segmented-btn:last-child { border-right: none; }
.segmented-btn:hover { background: var(--field); }
.segmented-btn.active { background: var(--ink); color: var(--ink-inverse); }
.segmented-btn.active .segmented-hint { color: inherit; opacity: 0.7; }
.segmented-hint { font-size: 10.5px; color: var(--muted); font-weight: 400; }

.admin-form-actions { display: flex; align-items: center; gap: 10px; margin-top: 20px; }
.admin-form-actions .btn { margin-top: 0; }
.admin-danger { color: var(--danger); margin-left: auto; }
.admin-danger.hidden { display: none; }
.admin-error { margin: 14px 0 0; font-size: 13px; color: var(--danger); }
.admin-error.hidden { display: none; }

@media (max-width: 900px) {
  .admin-panel { grid-template-columns: 1fr; gap: 24px; }
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .stat-tile:nth-child(3) { border-left: 1.5px solid var(--line); }
  .stat-tile:nth-child(n+3) { border-top: none; }
}
