/* WareQuery web styles — Linear-minimal three-pane shell.
 *
 * Section index:
 *   1. Reset & base
 *   2. Layout (app-grid, topbar, panes)
 *   3. Sidebar
 *   4. Context panel
 *   5. Welcome card
 *   6. Message pair        (added in Task 4)
 *   7. Composer            (added in Task 5)
 *   8. Modals              (added in Task 6)
 *   9. Cmd+K palette       (added in Task 9)
 *  10. Toast               (added in Task 11)
 *  11. Responsive          (added in Task 12)
 */

/* ---------- 1. Reset & base ---------- */

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border: 0;
  padding: 0;
}

button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd { font-family: var(--font-mono); font-size: 0.92em; }

kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--color-border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-subtle);
  color: var(--color-text-muted);
  font-size: 11px;
  line-height: 1;
}

.inline { display: inline; }

.btn-ghost {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  transition: background var(--duration-fast) var(--easing);
}
.btn-ghost:hover { background: var(--color-bg-muted); color: var(--color-text); }

.btn-icon {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border-radius: var(--radius-md);
  transition: background var(--duration-fast) var(--easing);
}
.btn-icon:hover { background: var(--color-bg-muted); color: var(--color-text); }

/* Persona switcher in the topbar. A custom <details> dropdown rather than a
 * native <select>, because the OS-rendered option list can't be themed (its
 * selection highlight leaked the browser-default blue). Fully styled here in
 * site colours with a teal glow; mirrors the .user-menu pattern. */
.persona-menu { position: relative; }
.persona-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  cursor: pointer;
  padding: 4px 10px 4px var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-subtle);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--duration-fast) var(--easing),
              box-shadow var(--duration-fast) var(--easing);
}
.persona-trigger::-webkit-details-marker { display: none; }
.persona-trigger:hover,
.persona-trigger:focus-visible,
.persona-menu[open] .persona-trigger {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--glow);
}
.persona-menu-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  color: var(--color-accent);
}
.persona-menu-current { font-size: var(--text-sm); font-weight: 600; color: var(--color-text); }
.persona-menu-caret {
  font-size: 10px;
  color: var(--color-accent);
  transition: transform var(--duration-fast) var(--easing);
}
.persona-menu[open] .persona-menu-caret { transform: rotate(180deg); }

/* Loading state for the persona / vertical switchers. Each option POST replies
 * 204 + HX-Refresh, which triggers a full (slow) page reload; without feedback
 * users click several options. htmx adds .htmx-request to the clicked button
 * for the request's duration, so while any switch is in flight we swap the
 * caret for a spinner and lock the menu (pure CSS, no JS). The reload then
 * resets everything; a failed request clears .htmx-request so the menu re-arms. */
.switch-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid var(--color-accent);
  border-top-color: transparent;
  border-radius: 50%;
  display: none;
  animation: spinner-rotate 0.7s linear infinite;
  flex-shrink: 0;
}
.persona-menu:has(.htmx-request) .switch-spinner { display: inline-block; }
.persona-menu:has(.htmx-request) .persona-menu-caret { display: none; }
.persona-menu:has(.htmx-request) .persona-trigger { cursor: progress; }
.persona-menu:has(.htmx-request) .persona-menu-panel {
  pointer-events: none;
  opacity: 0.6;
}

.persona-menu-panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 184px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--space-1);
  background: var(--color-bg);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--glow), var(--shadow-lg);
}
.persona-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-text);
  background: transparent;
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing),
              color var(--duration-fast) var(--easing);
}
.persona-menu-item:hover { background: var(--color-bg-muted); color: var(--color-accent); }
.persona-menu-item.is-current { color: var(--color-accent); font-weight: 600; }
.persona-menu-check { width: 1em; flex: none; color: var(--color-accent); }

/* Admin "Requests" link in the topbar. Reuses .btn-icon shape and adds a
 * tiny count badge in the corner. Badge only appears when count > 0. */
.requests-link {
  position: relative;
  text-decoration: none;
  font-size: 16px;
}
.requests-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--color-accent, #ef4444);
  color: white;
  font-size: 10px;
  font-weight: 600;
  line-height: 16px;
  text-align: center;
}

/* Permission wall card (rendered when agent.answer returns BlockedResult). */
.permission-wall {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-muted);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.permission-wall-title {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text);
}
.permission-wall-body {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
}
.permission-wall-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

/* Modal footer (was implicit before — the access-request modal needs a
 * proper row of right-aligned buttons separated from the body). */
.modal-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--color-border);
}
/* Inline blockquote inside a modal section — used to quote back the
 * user's original question on the access-request modal. */
.modal-quote {
  margin: var(--space-2) 0 0 0;
  padding: var(--space-3) var(--space-4);
  border-left: 3px solid var(--color-border);
  background: var(--color-bg-muted);
  color: var(--color-text);
  font-style: italic;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
/* Narrower modal variant for short confirmation dialogs. */
dialog.modal.modal-narrow {
  width: min(440px, 90vw);
}

/* ---------- 2. Layout ---------- */

.app-shell {
  display: flex;
  flex-direction: column;
  /* Lock the shell to exactly one viewport tall and hide overflow at the
   * shell level. The internal panes (.sidebar, .context-panel, .message-list)
   * each have their own overflow-y: auto and scroll independently, which
   * keeps the left and right trays fixed while the chat scrolls. Without
   * this, a tall message list would push the grid row past 100vh and the
   * document scroller (with the trays attached) would scroll instead.
   * Paired with min-height: 0 on the panes (.main-pane, .sidebar,
   * .context-panel) so they can size below their intrinsic content. */
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: var(--space-2); }
.brand { font-weight: 600; font-size: var(--text-md); }
.brand-sep { color: var(--color-text-subtle); }
.brand-context { color: var(--color-text-muted); font-size: var(--text-sm); }

.theme-icon-light, .theme-icon-dark { display: inline-block; }
:root[data-theme="light"] .theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: none; }

.app-grid {
  display: grid;
  grid-template-columns: var(--sidebar-w) 5px 1fr 5px var(--context-w);
  flex: 1;
  min-height: 0;
}

/* Resize handles between panes. 5px thin column with a wider hover hit
 * area via ::before, draggable via JS in app.js. Persists widths to
 * localStorage. */
.resize-handle {
  position: relative;
  background: transparent;
  cursor: col-resize;
  z-index: 5;
  transition: background var(--duration-fast) var(--easing);
}
.resize-handle:hover,
.resize-handle:focus-visible,
.resize-handle.is-dragging {
  background: var(--color-border-focus);
  outline: none;
}
.resize-handle::before {
  content: "";
  position: absolute;
  inset: 0 -3px;
}
body.is-resizing-pane,
body.is-resizing-pane * { cursor: col-resize !important; user-select: none; }

.main-pane {
  display: flex;
  flex-direction: column;
  /* min-height: 0 lets the grid track height constrain this pane so that
   * the inner .message-list (flex: 1; overflow-y: auto) can actually
   * scroll. Without it, grid items default to their content's intrinsic
   * height, which leaves overflow-y: auto with no constraint to work
   * against and the pane just grows past the shell. Same reason we add
   * it to .sidebar and .context-panel below. */
  min-width: 0;
  min-height: 0;
  background: var(--color-bg);
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* ---------- 3. Sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
  padding: var(--space-3) var(--space-2);
  overflow-y: auto;
  min-height: 0; /* let grid track constrain so internal overflow-y works */
}

.sidebar-new { margin-bottom: var(--space-3); }
.btn-newthread {
  width: 100%;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.4px;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  transition: background var(--duration-fast) var(--easing);
}
.btn-newthread:hover { background: var(--color-bg-muted); }

.sidebar-section { margin-bottom: var(--space-4); }
.sidebar-section-label {
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
}

.sidebar-footer {
  margin-top: auto;
  padding: var(--space-3) var(--space-2);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}
.kbd-hint { display: inline-flex; align-items: center; gap: var(--space-1); }

/* D additions: thread search, thread list, hover affordances. */

.thread-search {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  margin: 0 0 var(--space-3);
  transition: border-color var(--duration-fast) var(--easing);
}
.thread-search:focus-visible {
  outline: none;
  border-color: var(--color-border-focus);
}

.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-item {
  position: relative;
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  cursor: default;
  transition: background var(--duration-fast) var(--easing);
}
.thread-item:hover { background: var(--color-bg-muted); }
.thread-item.is-active {
  background: var(--color-accent-bg);
  color: var(--color-accent-text);
  font-weight: 500;
}

.thread-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: inherit;
  text-decoration: none;
  padding-right: var(--space-2);
}
.thread-link:hover { text-decoration: none; color: inherit; }

.thread-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--text-sm);
}
.thread-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-subtle);
}
.thread-item.is-active .thread-meta { color: var(--color-accent-text); opacity: 0.8; }

.thread-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--easing);
}
.thread-item:hover .thread-actions { opacity: 1; }

.thread-edit-btn,
.thread-delete-btn {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  background: transparent;
}
.thread-edit-btn:hover,
.thread-delete-btn:hover {
  background: var(--color-bg-emphasis);
  color: var(--color-text);
}
.thread-delete-btn:hover { color: var(--color-danger); }

.thread-rename-form,
.thread-delete-confirm { display: none; width: 100%; gap: var(--space-1); align-items: center; }

.thread-item.is-renaming .thread-rename-form {
  display: flex;
}
.thread-item.is-renaming .thread-link,
.thread-item.is-renaming .thread-actions { display: none; }

.thread-rename-input {
  flex: 1;
  font-size: var(--text-sm);
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border-focus);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.thread-rename-save,
.thread-rename-cancel,
.thread-delete-yes,
.thread-delete-no {
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}

.thread-item.is-confirming-delete .thread-delete-confirm { display: flex; align-items: center; gap: var(--space-1); font-size: var(--text-xs); }
.thread-item.is-confirming-delete .thread-link,
.thread-item.is-confirming-delete .thread-actions { display: none; }

.thread-list-empty {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  font-style: italic;
  padding: var(--space-3) var(--space-2);
  margin: 0;
}
.thread-list-no-matches[hidden] { display: none; }

.thread-rename-error {
  margin: var(--space-1) 0 0;
  font-size: 10px;
  color: var(--color-danger);
}

/* ---------- 4. Context panel ---------- */

.context-panel {
  border-left: 1px solid var(--color-border);
  background: var(--color-bg-subtle);
  padding: var(--space-4);
  overflow-y: auto;
  min-height: 0; /* let grid track constrain so internal overflow-y works */
}

.context-section { margin-bottom: var(--space-5); }
.context-section-label {
  font-size: 10px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  font-weight: 600;
  margin-bottom: var(--space-2);
}
.context-section-body {
  font-size: var(--text-sm);
  color: var(--color-text);
  line-height: var(--leading-snug);
}
.context-list { list-style: none; margin: 0; padding: 0; font-size: var(--text-sm); }
.context-list li { padding: 2px 0; color: var(--color-text-muted); }
.context-list code {
  background: var(--color-bg-muted);
  padding: 1px 4px;
  border-radius: var(--radius-sm);
}
/* Warehouse identifiers (schema.table, metric.column) have no natural break
 * points, so without this they overflow the fixed-width panel. */
.context-list code,
.context-section-body code {
  overflow-wrap: anywhere;
}

.context-empty {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
  font-style: italic;
  padding: var(--space-3) 0;
  line-height: var(--leading-snug);
}

/* ---------- 5. Welcome card ---------- */

.welcome-card {
  padding: var(--space-12) var(--space-4);
  text-align: left;
  max-width: var(--content-max);
}
.welcome-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-2);
}
.welcome-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  margin: 0 0 var(--space-3);
  line-height: var(--leading-tight);
}
.welcome-body {
  font-size: var(--text-md);
  color: var(--color-text-muted);
  margin: 0;
}
.welcome-body em {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--color-bg-muted);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.soft-banner {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: var(--content-max);
}

/* Auth card (login page) */

.auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-6);
  /* Login splash. .auth-shell IS <body>, so this overrides the app's aurora
   * field on the auth pages only. Light theme: a soft green-tinted off-white
   * glow so the page reads as light and on-brand. Dark theme overrides below
   * with the deep bottle-green -> near-black splash. */
  background-color: #eef3ee;
  background-image:
    radial-gradient(130% 120% at 0% 0%,
      rgba(150,110,30,0.14) 0%,
      rgba(20,60,45,0.08) 30%,
      rgba(255,255,255,0) 62%),
    linear-gradient(150deg, #f2f5f1 0%, #f6f8f5 55%, #eaf0ec 100%);
  background-attachment: fixed;
}
:root[data-theme="dark"] .auth-shell {
  background-color: #050b09;
  background-image:
    radial-gradient(130% 120% at 0% 0%,
      rgba(26,120,86,0.55) 0%,
      rgba(14,70,52,0.42) 22%,
      rgba(8,34,25,0.22) 46%,
      rgba(5,11,9,0) 72%),
    linear-gradient(150deg, #0a241b 0%, #08140f 52%, #050a0b 100%);
}
/* Faint film grain over the gradient, like the reference. */
.auth-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="dark"] .auth-shell::before { opacity: 0.06; }

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--glow), var(--shadow-lg);
  overflow: hidden;
  text-align: center;
}
/* Hairline gradient cap along the top edge, echoing the answer card. */
.auth-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--grad-accent);
}

/* Brand lockup: the logo on its own (wordmark removed — the tagline carries
 * the voice). */
.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-5);
}
.auth-logo {
  width: 78px;
  height: 78px;
  border-radius: 19px;
  flex: none;
  /* Light: a gold hairline + soft lift. Dark: a teal glow (overridden below). */
  box-shadow: 0 0 0 1px rgba(199,154,62,0.55), var(--shadow-md);
}
:root[data-theme="dark"] .auth-logo {
  box-shadow: 0 0 0 1px rgba(230,205,134,0.5), 0 0 20px -2px rgba(222,182,94,0.40);
}

/* Tagline as the stylised hero line, with a glowing warm-orange accent word.
 * drop-shadow (not text-shadow) so the glow follows the gradient-clipped
 * glyphs, whose fill is transparent. */
.auth-tagline {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  line-height: 1.12;
  letter-spacing: -0.015em;
  color: var(--color-text);
  margin: 0 0 var(--space-3);
}
.auth-tagline em {
  font-style: italic;
  font-weight: 500;
  background: var(--grad-warm);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 14px rgba(249, 115, 22, 0.55));
}

.auth-eyebrow {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--color-text-subtle);
  margin-bottom: var(--space-2);
}
.auth-title {
  font-size: var(--text-xl);
  font-weight: 600;
  margin: 0 0 var(--space-2);
}
.auth-subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-5);
  line-height: var(--leading-snug);
}

.auth-error {
  background: rgba(239, 68, 68, 0.08);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}

.auth-form { display: flex; flex-direction: column; gap: var(--space-3); text-align: left; }
.auth-field { display: flex; flex-direction: column; gap: var(--space-1); }
.auth-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-muted);
  font-weight: 600;
}
.auth-input {
  font-family: var(--font-sans);
  font-size: var(--text-md);
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--easing),
              box-shadow var(--duration-fast) var(--easing);
}
.auth-input:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.20);
}
.auth-submit { width: 100%; margin-top: var(--space-2); }

/* ---------- 6. Message pair ---------- */

.turn-pair {
  max-width: var(--content-max);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.turn { padding: 0; }

.turn-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  margin-bottom: var(--space-1);
}
.turn-meta .speaker {
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10px;
}
.turn-meta .marker {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-subtle);
}

/* Groundedness badge (the "audited receipt" trust mark). Levels are told
 * apart by SHAPE (filled gold / filled grey / open ring) + the label text,
 * never by colour alone. Gold — the one scarce accent — is spent only on the
 * High mark. Reason string is exposed via the title attribute on hover. */
.turn-meta .grounding {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-text-subtle);
  cursor: default;
  white-space: nowrap;
}
.turn-meta .grounding-seal {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border-strong);
  flex: none;
}
.turn-meta .grounding-high {
  color: var(--color-accent-text);
  border-color: var(--color-accent);
  background: var(--color-accent-bg);
}
.turn-meta .grounding-high .grounding-seal { background: var(--color-accent); }
.turn-meta .grounding-medium { color: var(--color-text-muted); }
.turn-meta .grounding-medium .grounding-seal { background: var(--color-text-subtle); }
.turn-meta .grounding-low { color: var(--color-text-subtle); }
.turn-meta .grounding-low .grounding-seal {
  background: transparent;
  box-shadow: inset 0 0 0 1.5px var(--color-text-subtle);
}

.turn-user .turn-body {
  background: var(--color-bg-muted);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
  display: inline-block;
  max-width: 100%;
}

.turn-bot .turn-body {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  font-size: var(--text-md);
  line-height: var(--leading-relaxed);
  position: relative;
}
.turn-bot .turn-answer {
  font-variant-numeric: tabular-nums;
}

.copy-btn {
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: background var(--duration-fast) var(--easing);
}
.copy-btn:hover { background: var(--color-bg-muted); color: var(--color-text); }
.copy-btn.is-copied { background: var(--color-success); color: var(--color-text-inverse); border-color: transparent; }
.copy-btn-inline {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  opacity: 0;
  transition: opacity var(--duration-fast) var(--easing);
}
.turn-bot .turn-body:hover .copy-btn-inline { opacity: 1; }

.turn-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
}

.meta-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3px;
  padding: 2px var(--space-2);
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}
.meta-pill-plain {
  font-family: var(--font-sans);
  background: transparent;
  padding-left: 0;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}
.action-btn {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.3px;
  padding: var(--space-1) var(--space-3);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  transition: background var(--duration-fast) var(--easing);
}
.action-btn:hover { background: var(--color-bg-muted); border-color: var(--color-border-strong); }
.action-btn-loading .action-btn-busy { display: none; }
.action-btn-loading[disabled] .action-btn-label { display: none; }
.action-btn-loading[disabled] .action-btn-busy { display: inline; }

/* Inline result table */
.inline-result-table {
  margin-top: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  font-size: var(--text-sm);
}
.inline-result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
}
.inline-result-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-subtle);
  font-weight: 600;
}
.inline-result-table-wrap { overflow-x: auto; }
.trace-table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}
.trace-table th, .trace-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}
.trace-table th {
  background: var(--color-bg-subtle);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-muted);
}
.trace-table td { color: var(--color-text); }
.trace-table tbody tr:last-child td { border-bottom: 0; }

.inline-result-more {
  padding: var(--space-2) var(--space-3);
  margin: 0;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-bg-subtle);
}
.link-btn {
  background: none;
  color: var(--color-accent);
  text-decoration: underline;
  font: inherit;
}
.link-btn:hover { color: var(--color-accent-text); }

.chart-block {
  height: 280px;
  margin-top: var(--space-4);
  padding: var(--space-3);
  /* Use the next-step-lighter bg token so the chart area is visibly
   * distinct from the surrounding turn / page in dark mode. With
   * --color-bg-subtle the difference was almost imperceptible against
   * the dark page background. */
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.contract-citations {
  margin-top: var(--space-4);
  padding: var(--space-3);
  background: var(--color-bg-muted);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}
.contract-citations-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: var(--space-2);
}
.contract-citations-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-subtle);
}
.contract-citation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}
.contract-citation-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
}
.contract-citation-meta {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}
.contract-citation-title { font-weight: 600; color: var(--color-text); }
.contract-citation-type {
  background: var(--color-bg-muted);
  border-radius: var(--radius-sm);
  padding: 0 6px;
  font-family: var(--font-mono);
}
.contract-citation-score { margin-left: auto; font-variant-numeric: tabular-nums; }
.contract-citation-heading {
  font-size: var(--text-sm);
  font-weight: 500;
  margin: 2px 0 4px;
}
.contract-citation-snippet {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin: 0 0 var(--space-2);
  line-height: var(--leading-snug);
}
.contract-clause-body {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  max-height: 50vh;
  overflow: auto;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--color-text);
}
.contract-clause-contract {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.contract-clause-contract-title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--color-text);
}
.contract-clause-contract-party {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}
/* Reuse the SQL modal's section-head flex layout so the Copy
 * clause button sits to the right of the clause-type label
 * exactly like the SQL/results modals do. */
.modal-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.modal-section-head .modal-section-label { margin-bottom: 0; }

/* Subtitle line under the modal title, used by the full-contract
 * modal to surface counterparty / effective date inline. */
.modal-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  margin-top: 2px;
}

/* Wider modal variant for the full contract view (17 clauses scroll
 * better at ~960px than at the default 720px). */
dialog.modal.modal-wide { width: min(960px, 92vw); }

/* Per-clause entry inside the full-contract modal. */
.contract-clause-entry { padding-bottom: var(--space-3); border-bottom: 1px solid var(--color-border); }
.contract-clause-entry:last-child { border-bottom: 0; padding-bottom: 0; }
.contract-clause-entry-type {
  font-family: var(--font-mono);
  background: var(--color-bg-muted);
  border-radius: var(--radius-sm);
  padding: 0 6px;
  margin-left: var(--space-2);
  font-size: 10px;
}
.contract-clause-entry-body {
  margin: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--color-text-muted);
}

/* Citation card action row + ghost button variant for the secondary
 * 'View full contract' action. */
.contract-citation-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.action-btn-ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-muted);
}
.action-btn-ghost:hover { background: var(--color-bg-muted); color: var(--color-text); }

/* ---------- 7. Composer ---------- */

.composer {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  position: sticky;
  bottom: 0;
}

.composer textarea {
  width: 100%;
  resize: none;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  line-height: var(--leading-snug);
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  min-height: 56px;
  max-height: 180px;       /* 6 lines-ish; overflow scrolls internally */
  overflow-y: auto;
  transition: border-color var(--duration-fast) var(--easing),
              box-shadow var(--duration-fast) var(--easing);
}
.composer textarea:focus-visible {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.composer-hint {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-send {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-5);
  background: var(--color-text);
  color: var(--color-text-inverse);
  border: 1px solid var(--color-text);
  border-radius: var(--radius-md);
  transition: opacity var(--duration-fast) var(--easing);
}
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Inline spinner state for buttons that show loading after a form
 * submit. The login button uses this so users see immediate feedback
 * during the (slow) bcrypt + Postgres round trip on first auth. */
.btn-with-spinner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.btn-with-spinner .btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: none;
  animation: spinner-rotate 0.7s linear infinite;
  flex-shrink: 0;
}
.btn-with-spinner.is-loading .btn-spinner { display: inline-block; }

/* Thinking placeholder spinner shown in the agent's pending-response turn
 * while the LLM round-trip is in flight. Pairs with the .thinking class
 * applied by app.js makeTurn() when extraClass === "thinking". */
.turn-body.thinking {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-subtle);
}
.thinking-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  display: inline-block;
  animation: spinner-rotate 0.7s linear infinite;
  flex-shrink: 0;
}
.thinking-label {
  display: inline-block;
}
.thinking-label::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}
@keyframes thinking-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
  100% { content: ""; }
}
.btn-with-spinner.is-loading .btn-label { opacity: 0.7; }
.btn-with-spinner.is-loading {
  cursor: progress;
  opacity: 0.85;
}
@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

/* ---------- 8. Modals ---------- */

dialog.modal {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  color: var(--color-text);
  padding: 0;
  margin: auto;
  width: min(720px, 90vw);
  max-height: 85vh;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
}
dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
}
.modal-title {
  margin: 0;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text);
}
.modal-close {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--color-bg-muted); color: var(--color-text); }

.modal-body {
  padding: var(--space-5);
  overflow-y: auto;
  max-height: calc(85vh - 56px);
}

.modal-section { margin-bottom: var(--space-5); }
.modal-section:last-child { margin-bottom: 0; }
.modal-section-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-text-subtle);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.sql-block {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  line-height: var(--leading-snug);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  white-space: pre;
  overflow-x: auto;
  color: var(--color-text);
}
.sql-block .sql-comment { color: var(--color-text-subtle); }
.sql-block .sql-keyword { color: var(--color-accent-text); font-weight: 500; }

/* ---------- 9. Cmd+K palette ---------- */

dialog.cmdk {
  width: min(480px, 90vw);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
  color: var(--color-text);
  padding: 0;
  margin-top: 12vh;
  margin-left: auto;
  margin-right: auto;
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}
dialog.cmdk::backdrop {
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
}

.cmdk-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.cmdk-input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  background: transparent;
  border: 0;
  color: var(--color-text);
  outline: none;
}
.cmdk-esc {
  font-size: 10px;
  color: var(--color-text-subtle);
}

.cmdk-list { list-style: none; margin: 0; padding: var(--space-1); max-height: 320px; overflow-y: auto; }
.cmdk-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  cursor: pointer;
  color: var(--color-text);
}
.cmdk-item[hidden] { display: none; }
.cmdk-item.is-disabled { color: var(--color-text-subtle); cursor: not-allowed; opacity: 0.5; }
.cmdk-item.is-active,
.cmdk-item:hover:not(.is-disabled) { background: var(--color-bg-muted); }
.cmdk-item-hint { font-family: var(--font-mono); font-size: 10px; color: var(--color-text-subtle); }

/* ---------- 10. Toast ---------- */

#toast-root {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
  z-index: 100;
}

.toast {
  background: var(--color-text);
  color: var(--color-text-inverse);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in 180ms var(--easing) forwards,
             toast-out 200ms var(--easing) 2300ms forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(4px); }
}

/* ---------- 11. Responsive ---------- */

@media (max-width: 1024px) {
  .app-grid {
    grid-template-columns: var(--sidebar-w) 5px 1fr;
  }
  .context-panel { display: none; }
  .resize-handle-context { display: none; }
}

@media (max-width: 768px) {
  .app-grid {
    grid-template-columns: 1fr;
  }
  .resize-handle { display: none; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: 80vw;
    max-width: 320px;
    z-index: 25;
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--easing);
    box-shadow: var(--shadow-lg);
  }
  body[data-sidebar-open="1"] .sidebar { transform: translateX(0); }
  body[data-sidebar-open="1"]::before {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 20;
  }
  .message-list { padding: var(--space-3); }
  .composer { padding: var(--space-3); }
  .welcome-card { padding: var(--space-6) var(--space-3); }
  .welcome-title { font-size: var(--text-xl); }
}

@media (min-width: 769px) {
  .sidebar-toggle { display: none; }
}

/* ---------- User menu (topbar dropdown) ---------- */

.user-menu {
  position: relative;
  display: inline-block;
}
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  cursor: pointer;
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: background var(--duration-fast) var(--easing);
}
.user-menu-trigger::-webkit-details-marker { display: none; }
.user-menu-trigger:hover { background: var(--color-bg-muted); }

.user-menu-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-accent-bg);
  color: var(--color-accent-text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
}
.user-menu-name { font-weight: 500; }
.user-menu-caret { color: var(--color-text-subtle); font-size: 10px; }

.user-menu-panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 220px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-1);
  z-index: 40;
}

.user-menu-header {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-1);
}
.user-menu-display-name { font-weight: 600; font-size: var(--text-sm); }
.user-menu-email { font-size: var(--text-xs); color: var(--color-text-muted); }

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  text-decoration: none;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.user-menu-item:hover { background: var(--color-bg-muted); text-decoration: none; }
.user-menu-form { margin: 0; }
.user-menu-signout { color: var(--color-danger); }

/* ---------- Admin pages ---------- */

.admin-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.admin-main {
  max-width: 1100px;
  width: 100%;
  margin: var(--space-6) auto;
  padding: 0 var(--space-6);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}
.admin-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  margin: 0;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.admin-table th, .admin-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.admin-table th {
  background: var(--color-bg-subtle);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-muted);
  font-weight: 600;
}
.admin-table tbody tr:last-child td { border-bottom: 0; }
.admin-table tbody tr.is-disabled-row td { color: var(--color-text-subtle); }

/* Overview stat cards */
.overview-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
@media (max-width: 720px) {
  .overview-cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .overview-cards { grid-template-columns: 1fr; }
}
.overview-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-5) var(--space-5);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.overview-card:hover {
  border-color: var(--color-border-strong);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.card-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
}
.card-value {
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-text);
}
.card-detail {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
}
.card-empty { color: var(--color-text-subtle); }
.card-warn { color: var(--color-warning); }

.inline-form { display: inline; margin: 0; }
.role-select {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  padding: 2px var(--space-2);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
}

/* ---------- 12. Aurora refresh ----------
 * Layered on top of the token reskin: a soft aurora field behind the reading
 * column, gradient accents, a glow on the answer card, the Fraunces display
 * face on headlines, and the brand logo. Pure presentation — no class renames,
 * no structural assumptions, fully reversible by deleting this section. */

/* Fraunces display face on headlines + brand */
.welcome-title,
.auth-title,
.admin-title,
.modal-title {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.welcome-title { font-size: 30px; line-height: 1.08; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  /* Scale the wordmark up to match the 38px logo (was --text-md/15px, which
   * looked small beside the larger mark). */
  font-size: 30px;
  line-height: 1;
}
.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: block;
  flex: none;
  /* A hairline gold ring + soft lift so the mark stays distinct on the topbar
   * instead of melting into the bar. */
  box-shadow: var(--brand-mark-ring), var(--shadow-md);
}
/* Wordmark wrapper: keeps the flex gap between logo and word, but lets
 * "Ware" + "Query" sit flush (no gap between them). Ware in teal. */
.brand-word { color: var(--color-accent); }

/* Aurora background field — painted on the viewport (fixed) via the body
 * background. The topbar, sidebar, context panel and composer keep their
 * opaque surfaces; the central reading column (main-pane + message-list) is
 * made transparent so the glow shows around the floating answer cards. */
body {
  background-color: var(--color-bg);
  background-image:
    radial-gradient(60vw 52vw at 10% -10%, var(--aurora-1), transparent 60%),
    radial-gradient(55vw 46vw at 94% 0%,  var(--aurora-2), transparent 62%),
    radial-gradient(52vw 50vw at 74% 108%, var(--aurora-3), transparent 60%),
    radial-gradient(42vw 42vw at 18% 96%, var(--aurora-4), transparent 64%);
  background-attachment: fixed;
  background-repeat: no-repeat;
}
.main-pane { background: transparent; }
.message-list { background: transparent; }

/* The answer card — the hero moment: glass-ish surface with a teal glow and
 * a hairline gradient cap along the top edge. */
.turn-bot .turn-body {
  border-radius: var(--radius-xl);
  box-shadow: var(--glow);
  overflow: hidden;
}
.turn-bot .turn-body::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 2px;
  background: var(--grad-accent);
  opacity: 0.9;
}
.turn-user .turn-body { border-radius: var(--radius-xl) var(--radius-xl) var(--space-1) var(--radius-xl); }

/* Gradient send button + composer focus glow */
.btn-send {
  background: var(--grad-accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 20px -8px rgba(150,110,30,0.45);
  transition: transform var(--duration-fast) var(--easing),
              box-shadow var(--duration-fast) var(--easing),
              opacity var(--duration-fast) var(--easing);
}
.btn-send:hover { opacity: 1; transform: translateY(-1px); box-shadow: 0 12px 26px -8px rgba(150,110,30,0.55); }
.composer textarea:focus-visible {
  border-color: var(--color-accent);
  box-shadow: var(--glow);
}

/* New-thread button: accent on hover */
.btn-newthread:hover { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-bg); }

/* Citation / action chips: accent-on-hover lift */
.action-btn { transition: background var(--duration-fast) var(--easing),
                          border-color var(--duration-fast) var(--easing),
                          color var(--duration-fast) var(--easing),
                          transform var(--duration-fast) var(--easing); }
.action-btn:hover { border-color: var(--color-accent); color: var(--color-accent); transform: translateY(-1px); }

/* Tabular figures everywhere numbers line up */
.trace-table td, .admin-table td, .meta-pill, .contract-citation-score {
  font-variant-numeric: tabular-nums;
}

/* Context / lineage panel — was flat grey. Add a soft teal wash, turn each
 * lineage section into a card, tint the labels and code chips with the accent,
 * and give the empty state an icon + centred layout so it reads as designed
 * rather than blank. */
.context-panel {
  background:
    radial-gradient(120% 55% at 100% 0%, rgba(150,110,30,0.08), transparent 60%),
    var(--color-bg-subtle);
}
.context-section {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-normal) var(--easing),
              border-color var(--duration-normal) var(--easing);
}
.context-section:hover { border-color: var(--color-accent); transform: translateX(-2px); }
.context-section-label { color: var(--color-accent); }
.context-list code,
.context-section-body code {
  background: var(--color-accent-bg);
  color: var(--color-accent-text);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
}
.context-empty {
  margin-top: 22%;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-4);
  padding: var(--space-6) var(--space-5);
  font-style: normal;
  max-width: 30ch;
  margin-left: auto;
  margin-right: auto;
  color: var(--color-text-muted);
}
.context-empty::before {
  content: "";
  width: 52px;
  height: 52px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='52' height='52' viewBox='0 0 24 24' fill='none' stroke='%23a87c1f' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='6' y1='3' x2='6' y2='15'/%3E%3Ccircle cx='18' cy='6' r='3'/%3E%3Ccircle cx='6' cy='18' r='3'/%3E%3Cpath d='M18 9a9 9 0 0 1-9 9'/%3E%3C/svg%3E") center / contain no-repeat;
  opacity: 0.9;
}

/* Duo-coloured wordmark: "Ware" in ink, "Query" in the teal gradient. The
 * .brand font-family (Fraunces) is already set above. */
.brand-accent {
  background: var(--grad-warm);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Headline figures inside answer prose — Fraunces italic old-style numerals
 * (long ascending/descending tails), coloured. Wrapped by highlightFigures()
 * in app.js. Money tokens take the warm orange; everything else teal. */
.turn-answer .figure {
  font-family: var(--font-display);
  font-style: italic;
  font-feature-settings: "onum" 1, "pnum" 1;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--color-accent);
}
.turn-answer .figure-money { color: var(--color-orange); }

/* Dark-mode modals + command palette: a teal glow border so the dialog
 * lifts off the night-sky background instead of blending into it, plus a
 * hairline gradient cap along the top edge to echo the answer card. */
:root[data-theme="dark"] dialog.modal,
:root[data-theme="dark"] dialog.cmdk {
  border-color: var(--color-accent);
  box-shadow: var(--glow), var(--shadow-modal);
}
:root[data-theme="dark"] dialog.modal .modal-header {
  background-image: var(--grad-accent);
  background-repeat: no-repeat;
  background-size: 100% 2px;
  background-position: top left;
}

/* ---------- Section 13. Dashboard ----------
 * Full-viewport scrollable layout for the tile grid surface. Uses Aurora
 * tokens throughout; no raw hex values. Dark theme is automatic via tokens.
 * Structure: body.app-shell > .topbar (fixed height) + .dashboard-main (fills
 * remaining height, scrolls). Inside: .dashboard-grid (12-col CSS grid,
 * max-width 1280px, centred) containing .tile cards in -third/-half/-full
 * column spans. */

/* Scrollable main area below the topbar — mirrors .app-grid's flex: 1 /
 * min-height: 0 pattern so .app-shell (display:flex column, height:100vh)
 * constrains it correctly and overflow-y: auto activates real scrolling. */
.dashboard-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-6);
  background: transparent;
}

/* 12-column responsive grid, centred, max 1280px wide */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: var(--space-4);
  max-width: 1280px;
  margin: 0 auto;
}

/* Tile — surface card */
.tile {
  grid-column: span 12;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  min-height: 120px;
  transition: border-color var(--duration-normal) var(--easing),
              box-shadow var(--duration-normal) var(--easing);
}
.tile:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-md);
}

/* Column spans at wider viewports */
@media (min-width: 800px) {
  .tile-third { grid-column: span 4; }
  .tile-half  { grid-column: span 6; }
  .tile-full  { grid-column: span 12; }
}

/* Tile header row */
.tile-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.tile-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin: 0;
  line-height: var(--leading-snug);
}

/* "Ask ->" drill-through link */
.tile-ask {
  font-size: 0.8rem;
  color: var(--color-accent);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: var(--space-2);
  transition: opacity var(--duration-fast) var(--easing);
}
.tile-ask:hover { opacity: 0.75; text-decoration: underline; }

/* Big number KPI display */
.tile-big-number {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
  margin: auto 0;
  line-height: 1;
}

/* Chart area inside a tile — the outer .chart-block sets a fixed height for
 * the chat surface; inside tiles we want flex growth so override height and
 * let min-height drive the minimum instead. */
.tile .chart-block {
  height: auto;
  flex: 1;
  min-height: 220px;
  margin-top: 0;
  position: relative;
}

/* Tabular data — wrap prevents wide tables from overflowing the tile card */
.tile-table-wrap { overflow-x: auto; }
.tile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.tile-table th {
  text-align: left;
  color: var(--color-text-subtle);
  font-weight: 500;
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-1) var(--space-2) var(--space-2);
}
.tile-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

/* Locked / wall state — persona doesn't have access */
.tile-locked {
  opacity: 0.75;
}
.tile-wall {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  color: var(--color-text-subtle);
  font-size: 0.85rem;
}

/* Error state */
.tile-error {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  color: var(--color-text-subtle);
  font-size: 0.85rem;
}

/* Topbar navigation links (chat.html + dashboard.html) */
.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: var(--space-4);
}
.topbar-nav a {
  font-size: 0.85rem;
  color: var(--color-text-subtle);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color var(--duration-fast) var(--easing),
              background var(--duration-fast) var(--easing);
}
.topbar-nav a:hover {
  color: var(--color-text);
  background: var(--color-bg-muted);
}
.topbar-nav a.active {
  color: var(--color-accent);
  background: var(--color-bg-muted);
}

/* Empty state — spans the full grid width */
.dashboard-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--space-16) var(--space-4);
  color: var(--color-text-subtle);
}

/* ---- Consequence Analytics sign-in: split screen with the pulse ----
   Scoped to .auth-shell--ca, so it is inert under the default brand, which
   never sets that class. Every colour and typeface is a token, so this block
   contains no brand values of its own. */
.auth-shell--ca {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  align-items: stretch;
  min-height: 100vh;
  gap: 0;
  /* The base shell centres a card inside padding, on a light splash with
     hard-coded values that no token can reach. The split screen runs edge to
     edge instead, so both are reset here. The shorthand also clears
     background-image, which a background-color alone would leave behind and
     which would show through under prefers-color-scheme: light. */
  padding: 0;
  background: var(--color-bg);
}

/* The base shell paints a fixed decorative overlay. It belongs to the centred
   card layout and only muddies an edge-to-edge one. */
/* Beat the theme-scoped WareQuery splash, which is written as
   `:root[data-theme="dark"] .auth-shell` and therefore outranks a plain
   `.auth-shell--ca`. Forcing dark for this brand made that rule win and painted
   a green gradient across the Consequence Analytics hero. Matching its
   specificity is the fix; raising it further would just move the problem. */
:root[data-theme="dark"] .auth-shell--ca,
:root[data-theme="light"] .auth-shell--ca,
:root .auth-shell--ca {
  padding: 0;
  background: var(--color-bg);
}

:root .auth-shell--ca::before,
:root[data-theme="dark"] .auth-shell--ca::before { content: none; }

.auth-shell--ca .auth-hero {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1.25rem;
  padding: clamp(2rem, 5vw, 4.5rem);
  border-right: 1px solid var(--color-border);
}

.auth-shell--ca .auth-hero-logo { height: 34px; width: auto; }

.auth-shell--ca .auth-kicker {
  margin: 0;
  font-family: var(--font-mono);
  font-size: .6875rem;
  font-weight: 500;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--color-accent);
}

.auth-shell--ca .auth-hero-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.2vw, 3.25rem);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -.02em;
  color: var(--color-text);
}

.auth-shell--ca .auth-hero-title em {
  font-style: normal;
  color: var(--color-accent);
}

.auth-shell--ca .auth-hero-sub {
  margin: 0;
  max-width: 46ch;
  color: var(--color-text-muted);
}

.auth-shell--ca .pulse {
  position: relative;
  margin: .5rem 0 0;
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  aspect-ratio: 16 / 9;
  min-height: 200px;
  overflow: hidden;
}

.auth-shell--ca .pulse svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.auth-shell--ca .trace-ghost {
  fill: none;
  stroke: var(--color-border-strong);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.auth-shell--ca .trace {
  fill: none;
  stroke: var(--color-accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-dasharray: 1600;
  stroke-dashoffset: 1600;
  animation: pulse-draw 6s linear infinite;
}

@keyframes pulse-draw {
  0%   { stroke-dashoffset: 1600; }
  60%  { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: 0; }
}

.auth-shell--ca .pulse-label {
  position: absolute;
  left: 18px;
  bottom: 14px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: .6875rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.auth-shell--ca .auth-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0;
  padding: clamp(2rem, 4vw, 3.5rem);
  max-width: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--color-bg-subtle);
}

.auth-shell--ca .auth-card-title {
  margin: 0 0 .35rem;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
}

@media (max-width: 860px) {
  .auth-shell--ca { grid-template-columns: 1fr; }
  .auth-shell--ca .auth-hero {
    border-right: 0;
    border-bottom: 1px solid var(--color-border);
  }
}

@media (prefers-reduced-motion: reduce) {
  .auth-shell--ca .trace {
    animation: none;
    stroke-dashoffset: 0;
  }
}
