/* ═══════════════════════════════════════════════════════════
   PAIE · Sovereign AI — Design System
═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-base:      #060810;
  --bg-surface:   #0b0e18;
  --bg-elevated:  #111520;
  --bg-hover:     #181d2e;
  --border:       rgba(148,163,184,0.08);
  --border-focus: rgba(59,130,246,0.45);

  --accent:       #3b82f6;
  --accent-light: #93c5fd;
  --accent-glow:  rgba(59,130,246,0.12);
  --accent-2:     #67e8f9;

  --text-primary:   #e8edf5;
  --text-secondary: #8fa3bc;
  --text-muted:     #3d5066;
  --text-accent:    #93c5fd;

  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;

  --sidebar-w: 260px;
  --right-w:   320px;
  --radius:    10px;
  --radius-lg: 16px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Light theme ──────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:      #f0f3f8;
  --bg-surface:   #ffffff;
  --bg-elevated:  #e8edf5;
  --bg-hover:     #dde4ef;
  --border:       rgba(0,0,0,0.08);
  --border-focus: rgba(59,130,246,0.4);

  --text-primary:   #0d1520;
  --text-secondary: #3d5066;
  --text-muted:     #8fa3bc;
  --text-accent:    #2563eb;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.15s ease;
}

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

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
}

/* ── Layout shell ─────────────────────────────────────────── */

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr var(--right-w);
  grid-template-rows: 100vh;
  grid-template-areas: "left main right";
}

body.left-collapsed  { grid-template-columns: 60px 1fr var(--right-w); }
body.right-collapsed { grid-template-columns: var(--sidebar-w) 1fr 0px; }
body.left-collapsed.right-collapsed { grid-template-columns: 60px 1fr 0px; }

/* ── Sidebar base ─────────────────────────────────────────── */

.sidebar {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--transition);
  position: relative;
  z-index: 10;
}

.sidebar-left  { grid-area: left; border-right: 1px solid var(--border); }
.sidebar-right { grid-area: right; border-left: 1px solid var(--border); }

/* ── Sidebar header ───────────────────────────────────────── */

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 60px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.05em;
  color: var(--text-accent);
}

.logo-icon {
  font-size: 22px;
  filter: drop-shadow(0 0 8px var(--accent));
}

.pane-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

/* ── Icon button ──────────────────────────────────────────── */

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
#mention-btn { font-size: 15px; font-weight: 700; }
#tools-btn.active { background: var(--accent, #6366f1); color: #fff; }

/* ── New Chat button ──────────────────────────────────────── */

.new-chat-btn {
  margin: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border-focus);
  border-radius: var(--radius);
  background: var(--accent-glow);
  color: var(--text-accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition);
  flex-shrink: 0;
}
.new-chat-btn svg { width: 16px; height: 16px; }
.new-chat-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

/* ── Nav ──────────────────────────────────────────────────── */

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.nav-section { margin-bottom: 20px; }

.nav-label {
  display: block;
  padding: 6px 16px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  margin: 1px 8px;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  position: relative;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-glow);
  color: var(--text-accent);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  height: 50%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.nav-badge {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  background: var(--accent-glow);
  color: var(--accent-light);
  border-radius: 4px;
  border: 1px solid var(--border-focus);
}

/* ── History list ─────────────────────────────────────────── */

.history-list { padding: 0 8px; }
.history-empty { padding: 10px 8px; color: var(--text-muted); font-size: 12px; }

.history-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--transition);
}
.history-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.history-item.active { background: var(--accent-glow); color: var(--accent-light); }

/* ── Sidebar footer ───────────────────────────────────────── */

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-selector-wrap { display: flex; flex-direction: column; gap: 4px; }
.model-label { font-size: 10px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }

.model-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.model-manage-btn {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.model-manage-btn:hover { color: var(--text-accent); border-color: var(--border-focus); background: var(--accent-glow); }

.show-all-btn {
  margin-top: 5px;
  width: 100%;
  padding: 5px;
  font-size: 10px;
  font-weight: 500;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.show-all-btn:hover { color: var(--text-secondary); border-color: var(--text-muted); }

/* Model manage modal */
.model-modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}
.model-modal-row:last-child { border-bottom: none; }

.star-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity var(--transition), transform 0.15s ease;
  line-height: 1;
}
.star-btn.starred { opacity: 1; }
.star-btn:hover { opacity: 0.8; transform: scale(1.2); }

.model-select {
  width: 100%;
  padding: 7px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
.model-select:focus { border-color: var(--accent); }
.model-select option { background: var(--bg-elevated); }

.connection-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  color: var(--text-muted);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-dot.ok      { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.error   { background: var(--danger); }
.status-dot.loading { background: var(--warning); animation: pulse 1s infinite; }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ══════════════════════════════════════════════════════════
   MAIN CHAT
══════════════════════════════════════════════════════════ */

.main-chat {
  grid-area: main;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-base);
}

/* ── Chat header ──────────────────────────────────────────── */

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 60px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
}

.chat-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: center;
}

/* ── Messages ─────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ── Welcome screen ───────────────────────────────────────── */

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  text-align: center;
  padding: 40px 20px;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  align-self: center;
  animation: fadeIn 0.6s ease;
}

.welcome-logo {
  font-size: 56px;
  filter: drop-shadow(0 0 24px var(--accent));
  line-height: 1;
  margin-bottom: 8px;
}

.welcome-screen h2 {
  font-size: 28px;
  font-weight: 700;
  background: linear-gradient(135deg, #93c5fd, #67e8f9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.chip {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.chip:hover {
  border-color: var(--accent);
  color: var(--text-accent);
  background: var(--accent-glow);
}

/* ── Message bubbles ──────────────────────────────────────── */

.message {
  width: 100%;
  max-width: 720px;
  padding: 10px 24px;
  display: flex;
  gap: 14px;
  animation: fadeIn 0.3s ease;
}

/* User message — right aligned */
.user-message {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.user-message .message-body {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.user-message .message-role {
  text-align: right;
}

.user-message .message-content {
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 18px 18px 4px 18px;
  display: inline-block;
  max-width: 100%;
}

/* Assistant message — left aligned */
.assistant-message {
  align-self: flex-start;
}

.assistant-message .message-body {
  max-width: 85%;
}

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

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
  align-self: flex-end;
}

.user-message .message-avatar      { background: var(--accent); color: #fff; align-self: flex-end; }
.assistant-message .message-avatar { background: var(--bg-elevated); color: var(--text-accent); border: 1px solid var(--border); align-self: flex-start; }

.message-body { flex: 1; min-width: 0; }

.message-role {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.message-content {
  color: var(--text-primary);
  line-height: 1.75;
  word-break: break-word;
  white-space: pre-wrap;
}

.message-content.streaming::after {
  content: '▋';
  display: inline-block;
  animation: blink 0.7s infinite;
  color: var(--accent-light);
  margin-left: 2px;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Citations ────────────────────────────────────────────── */

.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.citation-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: 2px;
}

.citation-badge {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  cursor: pointer;
  transition: all var(--transition);
}
.citation-badge:hover {
  border-color: var(--accent);
  color: var(--text-accent);
  background: var(--accent-glow);
}

/* ── Input area ───────────────────────────────────────────── */

.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.input-wrap {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea#message-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
}
textarea#message-input::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mode-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
  white-space: nowrap;
  border: 1px solid transparent;
}

/* ── Focus badge — retrieval scope indicator ─────────────── */
.focus-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 10px;
  border-radius: 5px;
  cursor: pointer;
  user-select: none;
  transition: all var(--transition);
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
  /* Unbound (default) — amber, signals wide-open scope */
  background: rgba(245,158,11,0.12);
  color: #fbbf24;
  border-color: rgba(245,158,11,0.35);
}
.focus-badge:hover { background: rgba(245,158,11,0.22); }

/* Scoped — violet, signals a bounded focus is active */
.focus-badge.scoped {
  background: rgba(139,92,246,0.15);
  color: #c4b5fd;
  border-color: rgba(139,92,246,0.4);
}
.focus-badge.scoped:hover { background: rgba(139,92,246,0.26); }

/* Model — cold gray, no vault access */
.mode-badge.mode-model {
  background: rgba(100,116,139,0.15);
  color: #94a3b8;
  border-color: rgba(100,116,139,0.3);
}
.mode-badge.mode-model:hover { background: rgba(100,116,139,0.3); }

/* Recall — steel blue, read-only vault */
.mode-badge.mode-recall {
  background: rgba(59,130,246,0.12);
  color: #93c5fd;
  border-color: rgba(59,130,246,0.35);
}
.mode-badge.mode-recall:hover { background: rgba(59,130,246,0.25); }

/* Active — green, full read-write */
.mode-badge.mode-active {
  background: rgba(16,185,129,0.15);
  color: #10b981;
  border-color: rgba(16,185,129,0.4);
  box-shadow: 0 0 12px rgba(16,185,129,0.15);
}
.mode-badge.mode-active:hover { background: rgba(16,185,129,0.28); }

/* ── REC indicator ────────────────────────────────────────── */
.rec-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #ef4444;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid rgba(239,68,68,0.3);
  background: rgba(239,68,68,0.08);
}
.rec-indicator.visible { display: flex; }
.rec-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ef4444;
  box-shadow: 0 0 6px #ef4444;
  animation: rec-pulse 1.2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.3; transform: scale(0.85); }
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.send-btn svg { width: 15px; height: 15px; }
.send-btn:hover { background: #6d28d9; box-shadow: 0 0 16px var(--accent-glow); transform: scale(1.05); }
.send-btn:disabled { background: var(--bg-hover); color: var(--text-muted); transform: none; box-shadow: none; cursor: not-allowed; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
}

/* ══════════════════════════════════════════════════════════
   RIGHT PANE
══════════════════════════════════════════════════════════ */

.right-pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pane-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
}

.pane-empty-icon {
  font-size: 32px;
  opacity: 0.3;
}

.pane-empty p { font-size: 12px; line-height: 1.7; }

.pane-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand-hex { width: 26px; height: 26px; color: var(--accent-light); flex-shrink: 0; }
.brand-name { font-size: 14px; font-weight: 800; letter-spacing: 0.08em; color: var(--text-primary); }
.brand-status { display: flex; align-items: center; gap: 5px; margin-left: 4px; }
.status-text-sm { font-size: 9px; color: var(--text-muted); font-weight: 500; letter-spacing: 0.04em; }

.settings-full-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.settings-full-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.settings-full-btn:hover { color: var(--accent-light); border-color: var(--border-focus); background: var(--accent-glow); }

.pane-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.pane-count {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
}

/* ── Source cards ─────────────────────────────────────────── */

.sources-list, .trace-list { padding: 8px; display: flex; flex-direction: column; gap: 6px; }

.source-card {
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
  animation: fadeIn 0.3s ease;
}
.source-card:hover { border-color: var(--accent); background: var(--accent-glow); }

.source-uuid {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.source-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.source-tag {
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ── Source feedback buttons ──────────────────────────────── */

.source-feedback {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.fb-btn {
  flex: 1;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  opacity: 0.5;
}
.fb-btn:hover:not(:disabled) { opacity: 1; background: var(--bg-hover); }
.fb-btn:disabled { cursor: default; }
.fb-btn.fb-voted { opacity: 1; }
.fb-up.fb-voted  { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.4); }
.fb-down.fb-voted { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.3); }

/* ── Trace items ──────────────────────────────────────────── */

.trace-item {
  display: flex;
  gap: 8px;
  padding: 8px;
  border-left: 2px solid var(--accent);
  background: var(--bg-surface);
  border-radius: 0 6px 6px 0;
  font-size: 11px;
  animation: fadeIn 0.3s ease;
}

.trace-step {
  font-family: 'JetBrains Mono', monospace;
  color: var(--accent-light);
  flex-shrink: 0;
}

.trace-text { color: var(--text-secondary); }

/* ── Metrics ──────────────────────────────────────────────── */

.metrics-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}

.metric-label { color: var(--text-muted); }
.metric-value {
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-accent);
  font-weight: 500;
}

.metric-bar-wrap { background: var(--bg-surface); border-radius: 4px; height: 4px; overflow: hidden; flex: 1; margin: 0 10px; }
.metric-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 4px; transition: width 0.5s ease; }

/* ══════════════════════════════════════════════════════════
   COLLAPSED STATES
══════════════════════════════════════════════════════════ */

body.left-collapsed .sidebar-left  .logo-text,
body.left-collapsed .sidebar-left  .new-chat-btn span,
body.left-collapsed .sidebar-left  .nav-item span,
body.left-collapsed .sidebar-left  .nav-label,
body.left-collapsed .sidebar-left  .nav-badge,
body.left-collapsed .sidebar-left  .history-section,
body.left-collapsed .sidebar-left  .model-selector-wrap,
body.left-collapsed .sidebar-left  #status-text,
body.left-collapsed .sidebar-left  #history-section { display: none; }

body.left-collapsed .sidebar-left  { width: 60px; }
body.left-collapsed .new-chat-btn  { justify-content: center; padding: 10px; margin: 12px 8px; }
body.left-collapsed .nav-item      { justify-content: center; padding: 10px; }

body.right-collapsed .sidebar-right { width: 0; border: none; overflow: hidden; }

/* ══════════════════════════════════════════════════════════
   SETTINGS PANEL
══════════════════════════════════════════════════════════ */

.sidebar-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.settings-gear {
  color: var(--text-secondary) !important;
}
.settings-gear:hover {
  color: var(--accent-light) !important;
  background: var(--accent-glow) !important;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  backdrop-filter: blur(4px);
}

.settings-panel {
  width: 480px;
  max-width: 95vw;
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  animation: slide-in-right 0.25s cubic-bezier(0.4,0,0.2,1);
}
@keyframes slide-in-right {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.settings-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.settings-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 12px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.stab {
  padding: 7px 16px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.stab:hover { color: var(--text-secondary); }
.stab.active {
  color: var(--accent-light);
  background: var(--accent-glow);
}
.stab.active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: var(--accent);
}

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

.settings-section-label {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  border-left: 2px solid var(--accent);
}

/* Prompt cards */
.prompts-list { display: flex; flex-direction: column; gap: 16px; }
.prompts-loading { color: var(--text-muted); font-size: 13px; }

.prompt-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}
.prompt-card:focus-within { border-color: var(--border-focus); }

.prompt-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.prompt-card-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}
.prompt-card-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.prompt-stage {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 4px;
  text-transform: uppercase;
}
.prompt-stage.read  { background: rgba(59,130,246,0.12); color: #93c5fd; }
.prompt-stage.write { background: rgba(16,185,129,0.12); color: #6ee7b7; }

.prompt-textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px 14px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.6;
  border: none;
  resize: vertical;
  outline: none;
}

.prompt-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}
.prompt-used-by {
  font-size: 9px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  flex: 1;
  margin-right: 8px;
}
.prompt-save-btn {
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border-focus);
  background: var(--accent-glow);
  color: var(--accent-light);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.prompt-save-btn:hover { background: var(--accent); color: #fff; }
.prompt-save-btn.saved { background: rgba(16,185,129,0.15); border-color: rgba(16,185,129,0.4); color: #6ee7b7; }

/* About tab */
.about-block { display: flex; flex-direction: column; gap: 16px; }
.about-row {
  display: flex;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.about-icon { font-size: 20px; flex-shrink: 0; margin-top: 1px; }
.about-row strong { color: var(--text-primary); display: block; margin-bottom: 3px; }

/* ══════════════════════════════════════════════════════════
   MODAL
══════════════════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 15px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

/* Reader overlay (Kavita, etc.) — much larger than the standard modal */
.modal-reader {
  width: 92vw;
  max-width: 1400px;
  height: 90vh;
  max-height: 90vh;
  padding: 12px;
}
.modal-reader iframe {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: var(--radius);
  background: #fff;
}

.modal-uuid {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 6px 10px;
  border-radius: 6px;
  word-break: break-all;
}

.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.modal-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--accent-glow);
  color: var(--accent-light);
  border: 1px solid var(--border-focus);
}
.modal-tag-remove {
  cursor: pointer;
  opacity: 0.55;
  font-weight: 700;
  line-height: 1;
}
.modal-tag-remove:hover { opacity: 1; color: var(--danger); }

.modal-tag-add-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.modal-tag-input {
  flex: 1;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
}
.modal-tag-input:focus { outline: none; border-color: var(--border-focus); }
.modal-tag-add-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 5px;
  border: 1px solid var(--border-focus);
  background: var(--accent-glow);
  color: var(--accent-light);
  cursor: pointer;
  white-space: nowrap;
}
.modal-tag-add-btn:hover { background: var(--border-focus); }

/* ── Watched folders (Settings tab) ──────────────────────── */
.watch-list { display: flex; flex-direction: column; gap: 6px; }
.watch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
}
.watch-row-path {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
  word-break: break-all;
}
.watch-row-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(100,116,139,0.15);
  color: var(--text-muted);
  white-space: nowrap;
}
.watch-row-remove {
  cursor: pointer;
  opacity: 0.55;
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
}
.watch-row-remove:hover { opacity: 1; color: var(--danger); }
.watch-list-empty { font-size: 11px; color: var(--text-muted); padding: 4px 0; }

/* ── Focus scope modal: folder/tag sub-tabs ──────────────────── */
.focus-scope-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.fstab {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 600;
  border: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.fstab:hover { color: var(--text-secondary); }
.fstab.active { color: var(--accent-light); background: var(--accent-glow); }

.focus-scope-body { max-height: 340px; overflow-y: auto; }

.focus-breadcrumb {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  word-break: break-word;
}
.focus-crumb {
  cursor: pointer;
  color: var(--accent-light);
}
.focus-crumb:hover { text-decoration: underline; }
.focus-crumb-sep { color: var(--text-muted); margin: 0 3px; }
.focus-crumb-static { color: var(--text-muted); }

.focus-folder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  border-bottom: 1px solid var(--border);
}
.focus-folder-row:hover { background: var(--bg-hover); }
.focus-folder-row-select-current {
  background: var(--accent-glow);
  border-radius: 6px;
  border-bottom: none;
  margin-bottom: 4px;
}
.focus-folder-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-primary);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.focus-folder-name-path {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-secondary);
}

.modal-notes {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

/* ══════════════════════════════════════════════════════════
   SCROLLBAR
══════════════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ══════════════════════════════════════════════════════════
   VOICE ORB
══════════════════════════════════════════════════════════ */
#mic-btn.recording { color: #ef4444; }
#mic-btn.recording svg { animation: micPulse 1s ease-in-out infinite; }
@keyframes micPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.voice-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  animation: fadeIn 0.2s ease;
}

.voice-orb {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #93c5fd, #3b82f6 45%, #1d4ed8 75%, #1e3a8a);
  box-shadow: 0 0 60px 10px rgba(59,130,246,0.5);
  animation: orbListen 1.6s ease-in-out infinite;
}
.voice-orb.thinking {
  background: radial-gradient(circle at 35% 30%, #fde68a, #f59e0b 45%, #b45309 75%, #78350f);
  box-shadow: 0 0 60px 10px rgba(245,158,11,0.5);
  animation: orbThink 0.9s linear infinite;
}
.voice-orb.speaking {
  background: radial-gradient(circle at 35% 30%, #6ee7b7, #10b981 45%, #047857 75%, #064e3b);
  box-shadow: 0 0 60px 10px rgba(16,185,129,0.5);
  animation: orbSpeak 0.5s ease-in-out infinite;
}

@keyframes orbListen {
  0%,100% { transform: scale(1); }
  50%     { transform: scale(1.12); }
}
@keyframes orbThink {
  0%   { transform: rotate(0deg) scale(1); }
  50%  { transform: rotate(180deg) scale(0.94); }
  100% { transform: rotate(360deg) scale(1); }
}
@keyframes orbSpeak {
  0%,100% { transform: scale(1) translateY(0); }
  50%     { transform: scale(1.06) translateY(-2px); }
}

.voice-status {
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  min-height: 22px;
  max-width: 80vw;
  text-align: center;
}

.voice-cancel-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-secondary);
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.voice-cancel-btn:hover { background: rgba(255,255,255,0.15); color: #fff; }
