/* ═══════════════════════════════════════════════════════════════════════
   PokéPapi LLM Council — UI v2.0 OVERRIDE LAYER
   Loads on top of style_v1.css (baseline). Refines tokens + polishes
   high-visibility components. Big-4 LLM minimalist aesthetic
   (Claude / ChatGPT / Gemini / Perplexity inspired).
   To roll back: change body[data-ui="v2"] toggle in app.js.
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Refined design tokens (override root) ── */
:root {
  /* Surfaces — softer elevation */
  --bg-primary: #0d0d10;
  --bg-secondary: #161619;
  --bg-tertiary: #1d1d22;
  --bg-elevated: #232329;
  --bg-hover: rgba(255,255,255,0.04);
  /* Borders */
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.12);
  --border-active: rgba(139,92,246,0.45);
  /* Text */
  --text-primary: #e8e8ec;
  --text-secondary: #a1a1aa;
  --text-dim: #6b6b75;
  --text-muted: #54545c;
  /* Accents — restrained */
  --accent: #a78bfa;
  --accent-hover: #c4b5fd;
  --accent-dim: rgba(167,139,250,0.12);
  --accent-glow: rgba(167,139,250,0.25);
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  /* Spacing — 4px base grid */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px;
  /* Radii */
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius-xl: 18px;
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 0 3px var(--accent-glow);
  /* Motion */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-mid: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 240ms cubic-bezier(0.4, 0, 0.2, 1);
}

body { background: var(--bg-primary); color: var(--text-primary); }

/* ── Typography refinement ── */
body { font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11'; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { letter-spacing: -0.02em; font-weight: 600; }
button, input, select, textarea { font-family: inherit; }

/* ── Header refinement ── */
#header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  height: 52px;
  padding: 0 var(--s-4);
  gap: var(--s-3);
}
#toggle-sidebar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: transparent; border: none;
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: background var(--t-fast), color var(--t-fast);
}
#toggle-sidebar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
#header-title { font-weight: 600; letter-spacing: -0.01em; }
.header-status { background: var(--bg-tertiary); border: 1px solid var(--border); }
.header-status .dot { background: var(--success); box-shadow: 0 0 0 2px rgba(34,197,94,0.2); }

/* ── Mode toggle (Chat ↔ Code) refinement ── */
.mode-toggle {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px; gap: 0;
}
.mode-toggle-btn {
  background: transparent; color: var(--text-secondary);
  border: none; border-radius: 4px; padding: 4px 10px;
  font-size: 11px; font-weight: 500; transition: all var(--t-fast);
}
.mode-toggle-btn.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ── Sidebar refinement ── */
#sidebar { background: var(--bg-secondary); border-right: 1px solid var(--border); }
#sidebar-header {
  padding: var(--s-4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--s-3);
}
#sidebar-logo { width: 32px; height: 32px; border-radius: var(--radius-sm); }
#sidebar-title { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
#sidebar-subtitle { font-size: 11px; color: var(--text-dim); }

#new-session-btn {
  margin: var(--s-3); padding: var(--s-3); border-radius: var(--radius-md);
  background: var(--accent); color: #fff; border: none; font-weight: 600; font-size: 13px;
  cursor: pointer; transition: all var(--t-fast);
  display: flex; align-items: center; justify-content: center; gap: var(--s-2);
}
#new-session-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* Sidebar Projects section — cleaner */
#projects-section { padding: var(--s-1) 0 var(--s-3); border-bottom: 1px solid var(--border); }
.sidebar-section-header {
  padding: var(--s-3) var(--s-4) var(--s-2);
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--text-dim); text-transform: uppercase;
}
.sidebar-section-header button {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  font-size: 10px; padding: 3px var(--s-2); border-radius: var(--radius-sm);
  color: var(--text-secondary); transition: all var(--t-fast); font-weight: 600;
}
.sidebar-section-header button:hover { background: var(--accent-dim); color: var(--accent-hover); border-color: var(--accent); }
.project-item {
  margin: 2px var(--s-2); border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.project-item:hover { background: var(--bg-hover); }

#session-list { padding: var(--s-2); flex: 1; overflow-y: auto; }
.session-item {
  padding: var(--s-3); border-radius: var(--radius-md);
  margin-bottom: var(--s-2); /* clear visual separation between sessions */
  cursor: pointer; transition: all var(--t-fast);
  border: 1px solid var(--border);     /* hairline border so each session reads as a card */
  background: rgba(255,255,255,0.015); /* very subtle surface tint */
  position: relative;
}
.session-item:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.session-item.active {
  background: var(--bg-elevated); border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(167,139,250,0.2), var(--shadow-sm);
}
.session-item.pinned {
  background: rgba(167,139,250,0.06);
  border-left: 3px solid var(--accent);
  padding-left: calc(var(--s-3) - 2px);
}
.session-item.pinned::after {
  content: 'PINNED'; position: absolute; top: 4px; right: 6px;
  font-size: 8px; font-weight: 700; letter-spacing: 0.08em;
  color: var(--accent); opacity: 0.5;
}
.session-item.dragging { opacity: 0.4; transform: scale(0.98); }
.session-item.drag-over {
  border-top: 2px solid var(--accent);
  margin-top: -1px;
}
.session-item-title {
  font-size: 14.5px; line-height: 1.35; color: var(--text-primary); font-weight: 500;
  /* Allow up to 2 lines to wrap, then ellipsis — matches ChatGPT's sidebar legibility. */
  white-space: normal !important;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; text-overflow: ellipsis;
  word-break: break-word;
}
.session-item-date { font-size: 10px; color: var(--text-dim); margin-top: 4px; }
/* Custom-sort mode: row gets a subtle drag affordance */
body[data-sort="custom"] .session-item { cursor: grab; }
body[data-sort="custom"] .session-item:active { cursor: grabbing; }

#sidebar-footer {
  padding: var(--s-3); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-2);
}
#user-badge { font-size: 11px; color: var(--text-secondary); }
#settings-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: var(--radius-sm);
  padding: 6px var(--s-3); font-size: 12px; cursor: pointer;
  transition: all var(--t-fast);
}
#settings-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-strong); }

/* ── Chat area + welcome ──
   Logo = HUGE on the welcome screen; same logo persists as a barely-visible watermark
   behind the chat once messages start. The watermark uses the cropped favicon (mostly
   white shield) so it reads even at 4% opacity. */
#chat-area {
  background: transparent; /* let body::before watermark show through */
  padding: var(--s-6) var(--s-4);
  position: relative;
}
#main { background: transparent; } /* chain of transparency to body */
/* Fixed-position watermark behind chat — uses body::before so it stays put when
   the chat scrolls, and sized conservatively so top + bottom never clip.
   Positioned within the visible chat region by offsetting from sidebar/header/input. */
body::before {
  content: ''; position: fixed; pointer-events: none; z-index: 0;
  top: 70px;     /* clear header (52px) + breathing room */
  bottom: 120px; /* clear input area + discussion bar */
  left: 290px;   /* clear sidebar width */
  right: 10px;
  background-image: url('/images/favicon-512.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain; /* whole shield always visible — never clips */
  background-origin: content-box;
  padding: 40px;             /* shrinks effective bg area, leaves margin around shield */
  opacity: 0.05;
  transition: opacity 0.4s ease;
}
/* Hide watermark on welcome — class toggled by JS instead of an expensive :has() selector
   on body (which forced full style invalidation on every DOM mutation, jank on typing/sidebar). */
body.on-welcome::before { opacity: 0; }

/* Fullscreen card modal — opened from the ⛶ icon on any AI card.
   Dark backdrop, large readable card, Esc / click-outside / X to close. */
#card-fullscreen-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.85);
  z-index: 99998; display: flex; align-items: center; justify-content: center;
  padding: 24px; animation: fadeIn 0.15s ease-out;
}
#card-fullscreen-box {
  background: var(--bg-secondary, #161619);
  border: 1px solid var(--border, rgba(255,255,255,0.12));
  border-radius: 14px; max-width: 1100px; width: 100%;
  max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}
#card-fullscreen-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  font-size: 15px; font-weight: 600;
}
#card-fullscreen-header img { width: 22px; height: 22px; border-radius: 4px; }
#card-fullscreen-close {
  margin-left: auto; background: rgba(255,255,255,0.06); border: none;
  color: var(--text-primary); padding: 6px 10px; border-radius: 6px;
  cursor: pointer; font-family: inherit; font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px;
}
#card-fullscreen-close:hover { background: rgba(239,68,68,0.18); color: #fca5a5; }
#card-fullscreen-body {
  padding: 20px 24px; overflow-y: auto; flex: 1;
  font-size: 14px; line-height: 1.65; color: var(--text-primary);
}
#card-fullscreen-body pre { background: var(--bg-primary); padding: 12px; border-radius: 6px; overflow-x: auto; }
#card-fullscreen-body code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* CSS containment — isolates layout/paint work inside the chat. Without this,
   resizing the sidebar reflows every .msg card and forces the watermark to
   recompute, which was the root of the 5-10s mouse stutter on sidebar toggle.
   `contain: layout` tells the browser: nothing outside this box affects what's
   inside, and nothing inside affects what's outside (for layout purposes). */
#chat-area { contain: layout paint; }
.msg { contain: layout style; }
.msg-row { contain: layout; }

/* Kill transition: all during sidebar toggle. Any element with transition: all
   would animate its width when the chat widens — multiplied across dozens of
   cards + buttons = continuous repaint for the duration of the slide. While the
   body has .sidebar-animating, transitions are disabled wholesale. */
body.sidebar-animating *,
body.sidebar-animating *::before,
body.sidebar-animating *::after { transition: none !important; }
/* Mobile: sidebar overlays so reset left offset, and tighten vertical insets */
@media (max-width: 1024px) {
  body::before { left: 10px; top: 60px; bottom: 100px; }
}
@media (max-width: 480px) {
  body::before { top: 50px; bottom: 90px; opacity: 0.04; }
}
/* Class-toggled by JS when impersonation banner is shown (replaces a body[style*=]
   attribute-substring selector that forced style recomputation on every inline-style change). */
body.has-banner::before { top: calc(70px + var(--banner-h, 40px)); }
/* Make sure all app content sits above the watermark */
#app { position: relative; z-index: 1; }

#welcome {
  padding: clamp(40px, 10vh, 100px) var(--s-4);
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: var(--s-3);
}
#welcome-logo {
  width: clamp(180px, 38vw, 360px);
  height: clamp(180px, 38vw, 360px);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 80px rgba(167,139,250,0.15);
  animation: welcomeLogoFloat 4s ease-in-out infinite;
}
@keyframes welcomeLogoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
#welcome h1 {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700; letter-spacing: -0.03em;
  margin: var(--s-3) 0 var(--s-2);
  background: linear-gradient(135deg, var(--text-primary), var(--accent-hover));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
#welcome p {
  color: var(--text-secondary); max-width: 540px; margin: 0 auto;
  line-height: 1.5; font-size: clamp(14px, 1.4vw, 16px);
}

/* ── Chat bubbles — refined member identity ── */
.msg {
  display: flex; gap: var(--s-3);
  padding: var(--s-3) 0;
  position: relative;
  animation: msgFadeIn 0.3s ease-out;
}
@keyframes msgFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
/* Avatar — let the corporate logos breathe at full size, no dark circle swallowing them.
   Provider SVGs are designed to read at this size; we just give them clean square space. */
.msg-avatar {
  flex: 0 0 44px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 0;
  overflow: visible;
}
.msg-avatar img { width: 44px; height: 44px; object-fit: contain; display: block; }
/* Human avatar (👤 emoji) keeps the rounded purple chip — visually distinguishes user from AI */
.msg.user .msg-avatar {
  width: 36px; height: 36px; flex: 0 0 36px;
  background: var(--accent); border-radius: 50%;
  font-size: 18px; color: #fff;
}
/* System messages get a small dim chip so they don't compete with member logos */
.msg.system:not([data-provider]) .msg-avatar {
  width: 28px; height: 28px; flex: 0 0 28px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 50%; font-size: 14px;
}
.msg-body { flex: 1; min-width: 0; }
.msg-header {
  display: flex; align-items: center; gap: var(--s-2);
  margin-bottom: var(--s-2);
}
.msg-model-name { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.msg-time { font-size: 11px; color: var(--text-dim); }
.msg-content {
  padding: var(--s-3) var(--s-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px; line-height: 1.6;
  color: var(--text-primary);
}
/* Provider color stripes — instant visual identity */
.msg[data-provider="claude"] .msg-content { border-left: 3px solid #d97706; }
.msg[data-provider="chatgpt"] .msg-content { border-left: 3px solid #10b981; }
.msg[data-provider="gemini"] .msg-content { border-left: 3px solid #8b5cf6; }
.msg[data-provider="grok"] .msg-content { border-left: 3px solid #ef4444; }
.msg[data-provider="deepseek"] .msg-content { border-left: 3px solid #4d6bfe; }
.msg.user .msg-content { background: var(--accent-dim); border-color: var(--accent); border-left: 3px solid var(--accent); color: var(--text-primary); }

/* ── Bigger / brighter copy/edit icons in chat (the main user complaint) ── */
.msg-actions, .copy-btn, .edit-btn, .msg-action-btn {
  display: inline-flex; align-items: center; gap: var(--s-1);
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-secondary); cursor: pointer;
  padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500;
  transition: all var(--t-fast); margin-top: var(--s-2);
}
.msg-actions:hover, .copy-btn:hover, .edit-btn:hover, .msg-action-btn:hover {
  background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.msg-actions svg, .copy-btn svg, .edit-btn svg { width: 14px; height: 14px; }

/* ── Input area refinement ── */
#input-area {
  background: var(--bg-primary); border-top: 1px solid var(--border);
  padding: var(--s-4);
}
#input-row {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--s-2) var(--s-3);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
#input-row:focus-within { border-color: var(--accent); box-shadow: var(--shadow-glow); }
#promptInput {
  background: transparent; border: none; color: var(--text-primary);
  font-size: 14px; line-height: 1.5; padding: var(--s-2);
  resize: none; outline: none;
}
#promptInput::placeholder { color: var(--text-dim); }
.input-btn {
  background: transparent; border: none; color: var(--text-secondary);
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--t-fast);
}
.input-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.input-btn svg { width: 18px; height: 18px; }
#sendBtn {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-md); padding: var(--s-2) var(--s-4);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all var(--t-fast); display: inline-flex; align-items: center; gap: var(--s-2);
}
#sendBtn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ── Discussion mode bar — sleeker ── */
#discussion-mode-bar {
  background: var(--bg-secondary); border-bottom: 1px solid var(--border);
  padding: var(--s-3) var(--s-4); gap: var(--s-3);
}
.discuss-target-btn {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px var(--s-3);
  font-size: 12px; font-weight: 500; transition: all var(--t-fast);
}
.discuss-target-btn:hover { background: var(--bg-elevated); border-color: var(--border-strong); }
.discuss-target-btn.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent); font-weight: 600;
  box-shadow: var(--shadow-glow);
}
#continue-debate-btn, #send-arbiter-btn {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  padding: 6px var(--s-3); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all var(--t-fast);
}
#continue-debate-btn:hover, #send-arbiter-btn:hover {
  background: var(--bg-elevated); border-color: var(--accent); color: var(--accent-hover);
}
#send-arbiter-btn { border-color: var(--accent); color: var(--accent-hover); background: var(--accent-dim); }
#send-arbiter-btn:hover { background: var(--accent); color: #fff; }

/* ── Settings panel polish ── */
.settings-panel { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.settings-nav { background: var(--bg-primary); border-right: 1px solid var(--border); padding: var(--s-3); }
.settings-nav-btn {
  border-radius: var(--radius-sm); padding: var(--s-2) var(--s-3);
  font-size: 13px; transition: all var(--t-fast);
}
.settings-nav-btn:hover { background: var(--bg-hover); }
.settings-nav-btn.active { background: var(--accent-dim); color: var(--accent-hover); }
.settings-content { padding: var(--s-6); }
.setting-group { margin-bottom: var(--s-5); }
.setting-label { font-weight: 600; font-size: 13px; color: var(--text-primary); }
.setting-hint { font-size: 12px; color: var(--text-dim); line-height: 1.5; margin-top: 2px; }
.setting-input, .setting-input-sm, .setting-textarea {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.setting-input:focus, .setting-input-sm:focus, .setting-textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--shadow-glow);
}

/* ── Council seat cards (Settings → Council pane) — visual grid feel ── */
.llm-config-card {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-md); margin-bottom: var(--s-3);
  overflow: hidden; transition: border-color var(--t-fast);
}
.llm-config-card:hover { border-color: var(--border-strong); }
.llm-config-header {
  padding: var(--s-3) var(--s-4); background: var(--bg-secondary);
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 13px;
}
.llm-config-body { padding: var(--s-4); }

/* ── Buttons (primary/secondary/danger) consolidated ── */
.setting-btn-primary {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-md); padding: 10px var(--s-4);
  font-weight: 600; font-size: 13px; cursor: pointer;
  transition: all var(--t-fast);
}
.setting-btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.setting-btn-secondary {
  background: var(--bg-tertiary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 10px var(--s-4); font-weight: 500; font-size: 13px;
  cursor: pointer; transition: all var(--t-fast);
}
.setting-btn-secondary:hover { background: var(--bg-elevated); border-color: var(--border-strong); }

/* ── Streaming pulse ── */
.msg.thinking .msg-content::after {
  content: '●●●'; display: inline-block; margin-left: 4px;
  letter-spacing: 2px; opacity: 0.5;
  animation: pulseDots 1.4s ease-in-out infinite;
}
@keyframes pulseDots { 0%, 100% { opacity: 0.3; } 50% { opacity: 0.7; } }

/* ── Multi-column response layout (NEW) ──
   Activated by body[data-chat-layout="columns"]. Each .debate-stage's member responses
   render side-by-side in a horizontal scrolling row of cards. Each card truncates
   to ~12 lines with a "Show full" toggle that expands in place. */
body[data-chat-layout="columns"] .debate-stage-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-3);
  align-items: start;
  padding: var(--s-3) !important;
}

/* Historical / non-debate AI messages: app.js wraps consecutive AI .msg divs into
   a .msg-row container so the layout toggle affects past replies too. */
.msg-row { display: flex; flex-direction: column; gap: var(--s-2); padding: 0 var(--s-3); }
body[data-chat-layout="columns"] .msg-row {
  display: grid;
  /* Smaller min so more cards fit per row, especially on wide screens. */
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-2);
  align-items: start;
  padding: 0 var(--s-3);
}
/* Force cards to use the full grid track width — no max-width games. */
.msg-row > .msg, .debate-stage-body > .debate-card { width: 100%; min-width: 0; }
.msg-row > .msg .msg-body { max-width: 100% !important; }
/* Compact card layout — thin top-right action row (copy/expand/fullscreen) replaces
   the chunky bottom toggle bar. Goal: 5-7 cards visible at once instead of 1-2.
   The big external avatar column is hidden in favor of a small inline logo in the
   header so the card body uses the full width. */
.msg-row > .msg.system {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  margin: 0;
  display: block;
  position: relative;
  overflow: hidden;
  padding: 8px 12px;
}
.msg-row > .msg.system > .msg-avatar { display: none; }
.msg-row > .msg.system > .msg-body { padding: 0; }
.msg-row > .msg.system > .msg-body > .msg-header {
  display: flex; align-items: center; gap: 6px; margin-bottom: 4px;
  font-size: 12px; min-height: 18px;
}
.msg-row > .msg.system .msg-header-inline-logo {
  width: 16px; height: 16px; border-radius: 3px; flex-shrink: 0;
}
.msg-row > .msg.system .msg-model-name { font-weight: 600; }
.msg-row > .msg.system .msg-time { color: var(--text-dim); font-size: 11px; }
/* Top-right action row: copy / expand / fullscreen */
.msg-row > .msg.system .msg-actions {
  margin-left: auto; display: flex; align-items: center; gap: 2px;
}
.msg-row > .msg.system .msg-action-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); padding: 4px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: color var(--t-fast), background var(--t-fast);
}
.msg-row > .msg.system .msg-action-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.06); }
/* Hide the old in-body Copy button + the bottom toggle bar (replaced by icons) */
.msg-row > .msg.system > .msg-body > .copy-btn { display: none; }
.msg-row > .msg.system > .msg-card-toggle { display: none !important; }

.msg-row > .msg.system .msg-content {
  /* True 3-line clamp via -webkit-line-clamp — exact, no em guessing. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  position: relative;
  line-height: 1.5;
}
/* Fade gradient at bottom of clipped content so the cut-off looks intentional */
.msg-row > .msg.system:not(.expanded) .msg-content::after {
  content: '';
  position: absolute; left: 0; right: 0; bottom: 0; height: 40px;
  background: linear-gradient(to bottom, transparent, var(--bg-secondary));
  pointer-events: none;
}
.msg-row > .msg.system.expanded .msg-content {
  -webkit-line-clamp: unset;
  display: block;
  max-height: none;
}
/* In columns mode, expanded cards span the full row */
body[data-chat-layout="columns"] .msg-row > .msg.system.expanded {
  grid-column: 1 / -1;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}
/* In rows mode, expanded cards just get the highlight (already full width) */
body[data-chat-layout="stacked"] .msg-row > .msg.system.expanded {
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

/* Rows-mode default vertical stack with comfortable spacing between cards */
body[data-chat-layout="stacked"] .msg-row { gap: var(--s-3); padding: 0 var(--s-3); }

/* The bottom toggle button — visible in BOTH layouts now */
.msg-card-toggle {
  padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border);
  background: var(--bg-tertiary); cursor: pointer; text-align: center;
  font-size: 11px; font-weight: 600; color: var(--accent-hover);
  transition: background var(--t-fast); width: 100%; border-left: none;
  border-right: none; border-bottom: none; display: block;
  font-family: inherit;
}
.msg-card-toggle::before { content: '▾ Expand full message'; }
.msg.system.expanded .msg-card-toggle::before { content: '▴ Collapse'; }
.msg-card-toggle:hover { background: var(--accent-dim); color: var(--accent); }
body[data-chat-layout="columns"] .debate-card {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg-secondary); overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 340px;
  transition: max-height var(--t-slow), border-color var(--t-fast);
}
body[data-chat-layout="columns"] .debate-card:hover { border-color: var(--border-strong); }
body[data-chat-layout="columns"] .debate-card.expanded { max-height: 4000px; grid-column: 1 / -1; border-color: var(--accent); box-shadow: var(--shadow-glow); }
body[data-chat-layout="columns"] .debate-card-header {
  padding: var(--s-2) var(--s-3); background: var(--bg-elevated);
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: var(--s-2);
  font-size: 12px; font-weight: 600;
}
body[data-chat-layout="columns"] .debate-card-content {
  padding: var(--s-3); overflow-y: auto; flex: 1;
  font-size: 13px; line-height: 1.5;
}
/* Bottom expand/collapse toggle — present in BOTH stacked and columns layouts.
   Text is driven by CSS so it always reflects current .collapsed state, even when
   auto-collapse on stage transitions mutates the class outside our toggle handler. */
.debate-card-toggle {
  padding: var(--s-2) var(--s-3); border-top: 1px solid var(--border);
  background: var(--bg-tertiary); cursor: pointer; text-align: center;
  font-size: 11px; font-weight: 600; color: var(--accent-hover);
  transition: background var(--t-fast); width: 100%; border-left: none;
  border-right: none; border-bottom: none; display: block;
}
.debate-card-toggle::before { content: '▴ Collapse'; }
.debate-card.collapsed .debate-card-toggle::before { content: '▾ Expand full message'; }
.debate-card-toggle:hover { background: var(--accent-dim); color: var(--accent); }
/* Hide redundant header arrow now that the bottom button is the single source of truth */
.debate-card-arrow { display: none; }

/* Discussion-mode-bar is now always visible (overrides display:none from style.css)
   so the persistent Layout toggle + Filter status never vanish. The dynamic contents
   (filter buttons, round/arbiter buttons) hide themselves individually when not in use. */
/* Dropdown actions for "↻ New Round" + "⚖ Send to Arbiter" only show in a session
   that has an active or completed debate. Empty/fresh sessions don't need them. */
body:not(.has-debate-session) .sel-option.debate-action-only { display: none !important; }

/* ── Hide-user-messages toggle (in the discussion-mode-bar) ── */
.hide-user-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-secondary);
  cursor: pointer; user-select: none; margin-left: var(--s-2);
}
.hide-user-toggle input[type="checkbox"] {
  width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer;
}
#chat-area.hide-user-msgs .msg.user,
#chat-area.hide-user-msgs .msg[data-provider="human"] { display: none !important; }
/* The old top-bar round/arbiter buttons are deprecated — keep hidden. */
#continue-debate-btn, #send-arbiter-btn { display: none !important; }

/* ── Persistent action row above the chat input ── */
#debate-actions-row {
  display: flex; flex-direction: column; align-items: stretch;
  padding: 8px 16px 6px; gap: 4px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}
body.has-debate-session #debate-actions-row { display: flex !important; }
.debate-actions-buttons {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.debate-action-btn {
  flex: 1; min-width: 130px; padding: 8px 14px;
  background: var(--bg-tertiary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all var(--t-fast);
}
.debate-action-btn:hover { background: var(--bg-elevated); border-color: var(--accent); color: var(--accent-hover); }
.debate-action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.debate-action-arbiter {
  background: var(--accent-dim); color: var(--accent-hover); border-color: var(--accent);
}
.debate-action-arbiter:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.debate-actions-hint {
  font-size: 11px; color: var(--text-dim); text-align: center; font-style: italic;
  padding-top: 2px;
}

/* ── LLM response formatting — uniform typography across all members ──
   Different models produce wildly different markdown (some go heavy on h1/h2,
   others bold-heavy, etc.). Lock everything into a consistent compact hierarchy. */
.msg-content, .debate-card-content, #card-fullscreen-body {
  font-size: 14px; line-height: 1.55;
}
.msg-content h1, .debate-card-content h1, #card-fullscreen-body h1,
.msg-content h2, .debate-card-content h2, #card-fullscreen-body h2 {
  font-size: 17px; font-weight: 700; margin: 14px 0 6px;
  line-height: 1.3; color: var(--text-primary);
}
.msg-content h3, .debate-card-content h3, #card-fullscreen-body h3,
.msg-content h4, .debate-card-content h4, #card-fullscreen-body h4 {
  font-size: 15px; font-weight: 600; margin: 12px 0 4px;
  line-height: 1.3; color: var(--text-primary);
}
.msg-content h5, .debate-card-content h5, #card-fullscreen-body h5,
.msg-content h6, .debate-card-content h6, #card-fullscreen-body h6 {
  font-size: 14px; font-weight: 600; margin: 10px 0 4px;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-secondary);
}
.msg-content p, .debate-card-content p, #card-fullscreen-body p {
  font-size: 14px; margin: 0 0 8px; line-height: 1.55;
}
.msg-content ul, .debate-card-content ul, #card-fullscreen-body ul,
.msg-content ol, .debate-card-content ol, #card-fullscreen-body ol {
  margin: 4px 0 8px; padding-left: 22px;
}
.msg-content li, .debate-card-content li, #card-fullscreen-body li {
  font-size: 14px; margin: 2px 0; line-height: 1.5;
}
.msg-content blockquote, .debate-card-content blockquote, #card-fullscreen-body blockquote {
  border-left: 3px solid var(--border-strong); padding-left: 12px;
  margin: 8px 0; color: var(--text-secondary); font-style: italic;
}
.msg-content strong, .debate-card-content strong, #card-fullscreen-body strong { font-weight: 700; color: var(--text-primary); }
.msg-content em, .debate-card-content em, #card-fullscreen-body em { font-style: italic; color: var(--text-secondary); }
.msg-content code, .debate-card-content code, #card-fullscreen-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; padding: 1px 5px; border-radius: 3px;
  background: rgba(255,255,255,0.06); color: var(--text-primary);
}
.msg-content pre, .debate-card-content pre, #card-fullscreen-body pre {
  font-size: 12.5px; line-height: 1.5; margin: 8px 0;
}
.msg-content hr, .debate-card-content hr, #card-fullscreen-body hr {
  border: none; border-top: 1px solid var(--border); margin: 10px 0;
}
/* First child no top margin */
.msg-content > *:first-child,
.debate-card-content > *:first-child,
#card-fullscreen-body > *:first-child { margin-top: 0; }

#discussion-mode-bar { display: flex !important; align-items: center; }
/* Filter buttons + filter status always visible — users can filter / re-filter any time.
   Round / Arbiter buttons stay controlled by inline style from showDiscussionBar(). */
#discussion-mode-bar #discuss-target-wrap { display: flex !important; }
#discussion-mode-bar #filter-status { display: inline-flex !important; align-items: center; gap: 4px; }
#discussion-mode-bar:not(.active) .mode-label { opacity: 0.4; }

/* Layout toggle pill — sits on the right of the bar, always visible */
#chat-layout-toggle {
  display: inline-flex; background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px; gap: 0; margin-left: auto;
}
#chat-layout-toggle button {
  background: transparent; border: none; color: var(--text-secondary);
  padding: 4px 10px; font-size: 11px; cursor: pointer;
  border-radius: 4px; font-weight: 500; transition: all var(--t-fast);
}
#chat-layout-toggle button:hover { color: var(--text-primary); }
#chat-layout-toggle button.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
/* Role-gating — hide admin/dev-only content from regular users */
body:not([data-role="admin"]) .requires-admin { display: none !important; }
body:not([data-code-mode="true"]) .requires-code-mode { display: none !important; }

/* Persistent filter status replaces the static explainer text */
#discussion-mode-bar #filter-status {
  color: var(--accent-hover); font-size: 12px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── Decision card refined ── */
#v2-decision-card .msg-content {
  background: linear-gradient(135deg, rgba(167,139,250,0.06), rgba(167,139,250,0.02));
  border: 1px solid var(--border-active);
  border-radius: var(--radius-md);
  padding: var(--s-5);
}
#v2-decision-card button[data-action="arbiter"] {
  background: var(--accent); color: #fff; box-shadow: var(--shadow-md);
}
#v2-decision-card button[data-action="arbiter"]:hover { background: var(--accent-hover); transform: translateY(-1px); }
#v2-decision-card button[data-action="round"] {
  background: var(--bg-elevated); color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
#v2-decision-card button[data-action="round"]:hover { background: var(--bg-tertiary); border-color: var(--accent); }

/* ── Impersonation banner — restraint ── */
#impersonation-banner { background: linear-gradient(90deg, #fbbf24, #f59e0b) !important; }

/* ── Scrollbars (webkit) ── */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }
