/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d0d0f;
  --bg-2: #13131a;
  --bg-3: #1a1a24;
  --bg-4: #22223a;
  --border: #2a2a40;
  --accent: #6c63ff;
  --accent-hover: #7c74ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --text: #e8e8f0;
  --text-muted: #7878a0;
  --text-dim: #4a4a6a;
  --green: #00e5a0;
  --red: #ff4d6a;
  --yellow: #ffc84a;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --sidebar-w: 260px;
  --transition: 180ms ease;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), min-width var(--transition);
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
  white-space: nowrap;
}

.sidebar-logo span { color: var(--text); }

#btn-new-chat {
  margin: 12px 10px 6px;
  padding: 9px 12px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
#btn-new-chat:hover {
  background: var(--accent);
  color: #fff;
}

.conv-list-label {
  padding: 8px 14px 4px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 6px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 8px;
  transition: background var(--transition);
  overflow: hidden;
}
.conv-item:hover { background: var(--bg-3); }
.conv-item.active { background: var(--accent-dim); }

.conv-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: var(--text);
}
.conv-item.active .conv-item-title { color: var(--accent); }

.conv-item-del {
  display: none;
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 15px;
  padding: 0 2px;
  border-radius: 3px;
  transition: color var(--transition);
}
.conv-item:hover .conv-item-del { display: flex; align-items: center; }
.conv-item-del:hover { color: var(--red); }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.sidebar-footer strong { color: var(--accent); }

/* ── Main Area ────────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
#topbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
}

#btn-toggle-sidebar {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  flex-shrink: 0;
}
#btn-toggle-sidebar:hover { color: var(--text); }

#conv-title-display {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
.topbar-user strong { color: var(--green); }

/* ── Messages Area ───────────────────────────────────────────────────────── */
#messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.msg-row {
  display: flex;
  padding: 6px 20px;
  gap: 12px;
  max-width: 100%;
}
.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 2px;
}
.msg-row.user .msg-avatar { background: var(--accent-dim); color: var(--accent); }
.msg-row.assistant .msg-avatar { background: var(--bg-4); color: var(--green); }

.msg-bubble {
  max-width: min(680px, 82%);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}
.msg-row.user .msg-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(108, 99, 255, 0.25);
  color: var(--text);
  border-bottom-right-radius: 3px;
}
.msg-row.assistant .msg-bubble {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

/* Markdown inside assistant bubbles */
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
  margin: 12px 0 6px;
  color: var(--text);
  font-weight: 700;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 14px; }
.msg-bubble ul, .msg-bubble ol {
  padding-left: 20px;
  margin: 6px 0;
}
.msg-bubble li { margin: 3px 0; }
.msg-bubble code {
  background: var(--bg-4);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--green);
}
.msg-bubble pre {
  background: #0a0a12;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
  position: relative;
}
.msg-bubble pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 13px;
  color: var(--text);
}
.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 8px 0;
  color: var(--text-muted);
}
.msg-bubble a { color: var(--accent); text-decoration: underline; }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; width: 100%; font-size: 13px; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg-bubble th { background: var(--bg-4); color: var(--text); }
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; color: var(--text-muted); }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Copy button on code blocks */
.code-wrapper { position: relative; }
.copy-code-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: color var(--transition);
}
.copy-code-btn:hover { color: var(--text); }

/* Streaming cursor */
.cursor { display: inline-block; width: 2px; height: 14px; background: var(--accent); animation: blink 1s step-end infinite; vertical-align: text-bottom; margin-left: 1px; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Attachments in user bubble */
.msg-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-attachment-thumb { max-width: 120px; max-height: 80px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }

/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 16px;
  color: var(--text-muted);
  text-align: center;
}
.empty-logo { font-size: 48px; }
.empty-title { font-size: 22px; font-weight: 700; color: var(--text); }
.empty-subtitle { font-size: 14px; max-width: 360px; line-height: 1.7; }
.empty-tips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}
.tip-chip {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}
.tip-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── Input Area ──────────────────────────────────────────────────────────── */
#input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

#attachment-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.att-preview-item {
  position: relative;
}
.att-preview-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.att-preview-del {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--red);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px;
  transition: border-color var(--transition);
}
.input-row:focus-within { border-color: var(--accent); }

#msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 180px;
  overflow-y: auto;
  padding: 4px 4px 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#msg-input::placeholder { color: var(--text-dim); }

#btn-attach {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
  flex-shrink: 0;
}
#btn-attach:hover { color: var(--accent); }

#btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:active { transform: scale(0.97); }
#btn-send:disabled { opacity: 0.45; cursor: not-allowed; }

.input-hint {
  padding: 4px 8px 0;
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Loading / Thinking indicator ─────────────────────────────────────────── */
.thinking-row {
  display: flex;
  padding: 6px 20px;
  gap: 12px;
  align-items: center;
}
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 999;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); color: var(--red); }

/* ── Scrollbar global ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; }
  #sidebar.collapsed { transform: translateX(-100%); }
  #sidebar.collapsed { width: var(--sidebar-w); min-width: var(--sidebar-w); }
  .msg-bubble { max-width: 90%; }
}

/* ── Phase 2 additions ─────────────────────────────────────────────────────── */

/* Sidebar header with settings button */
.sidebar-header { display: flex; align-items: center; justify-content: space-between; }
#btn-settings {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  padding: 5px; border-radius: 6px; line-height: 0; flex-shrink: 0;
}
#btn-settings:hover { background: var(--bg-3); color: var(--accent); }

/* Sidebar search */
.sidebar-search {
  display: flex; align-items: center; gap: 7px;
  margin: 4px 12px 8px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px;
}
.sidebar-search svg { flex-shrink: 0; color: var(--text-dim); }
#search-input {
  background: none; border: none; outline: none; width: 100%;
  color: var(--text); font-size: 13px;
}
#search-input::placeholder { color: var(--text-dim); }

/* Folder chips */
#folder-bar {
  display: flex; gap: 6px; padding: 0 12px 8px; overflow-x: auto;
  scrollbar-width: none;
}
#folder-bar::-webkit-scrollbar { display: none; }
.folder-chip {
  flex-shrink: 0; background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-muted); padding: 4px 10px; border-radius: 20px;
  font-size: 11px; cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; gap: 5px;
  transition: background 0.15s, border-color 0.15s;
}
.folder-chip:hover { background: var(--bg-4); }
.folder-chip.active {
  background: rgba(108, 99, 255, 0.15); border-color: var(--accent);
  color: var(--accent);
}
.folder-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--chip-color, var(--accent));
}

/* Conversation list sections */
.conv-section-label {
  font-size: 10px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: 0.05em; padding: 8px 14px 2px;
  display: flex; align-items: center; gap: 5px;
}
.conv-empty {
  padding: 10px 14px; font-size: 12px; color: var(--text-dim);
}
.conv-pin-icon { font-size: 10px; margin-right: 3px; }

/* Conv item options button */
.conv-item-menu {
  display: none; background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 0 4px; line-height: 1;
  border-radius: 4px;
}
.conv-item:hover .conv-item-menu { display: block; }
.conv-item-menu:hover { background: var(--bg-4); color: var(--text); }

/* Search snippet */
.conv-search-snippet {
  font-size: 11px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-search-snippet mark {
  background: rgba(108, 99, 255, 0.3); color: var(--accent); border-radius: 2px;
}

/* Context menu */
.ctx-menu {
  position: fixed; z-index: 500;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  min-width: 160px; padding: 4px 0; overflow: hidden;
}
.ctx-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; color: var(--text);
  padding: 8px 14px; font-size: 13px; cursor: pointer;
}
.ctx-menu button:hover { background: var(--bg-4); }

/* Topbar actions */
.topbar-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.topbar-icon-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 6px; border-radius: 6px; line-height: 0;
}
.topbar-icon-btn:hover { background: var(--bg-3); color: var(--text); }
.topbar-icon-btn.active { color: var(--accent); }

/* Prompt library button in input */
#btn-prompt-lib {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 6px; border-radius: 6px; line-height: 0; flex-shrink: 0;
}
#btn-prompt-lib:hover { background: var(--bg-4); color: var(--accent); }

/* PDF attachment preview */
.att-preview-pdf {
  background: var(--bg-4); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 10px; font-size: 12px; color: var(--text);
  max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-pdf-badge {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-4); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--text-muted);
}

/* Modal overlay */
.modal-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(0,0,0,0.6); display: flex;
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 480px;
  max-height: 85vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg-3); color: var(--text); }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-section { display: flex; flex-direction: column; gap: 8px; }
.modal-label { font-size: 13px; font-weight: 600; color: var(--text); }
.modal-desc { font-size: 12px; color: var(--text-dim); margin: 0; }
.modal-input {
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; color: var(--text);
  font-size: 13px; outline: none; font-family: inherit;
}
.modal-input:focus { border-color: var(--accent); }

/* Buttons */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: 8px; font-size: 13px;
  cursor: pointer; font-weight: 500;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  background: var(--bg-4); color: var(--text); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { background: var(--bg-3); }

/* Prompt list */
.prompt-list { display: flex; flex-direction: column; gap: 8px; }
.prompt-empty { font-size: 12px; color: var(--text-dim); text-align: center; padding: 16px; }
.prompt-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px;
}
.prompt-info { flex: 1; min-width: 0; }
.prompt-title { font-size: 13px; font-weight: 600; }
.prompt-preview { font-size: 11px; color: var(--text-dim); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prompt-actions { display: flex; gap: 6px; flex-shrink: 0; }
.btn-use-prompt {
  background: var(--accent); color: #fff; border: none;
  padding: 5px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.btn-del-prompt {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 4px; border-radius: 4px; font-size: 14px;
}
.btn-del-prompt:hover { color: var(--red); }

/* Folder manager */
.folder-manager-list { display: flex; flex-direction: column; gap: 6px; }
.folder-mgr-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
}
.folder-dot-lg { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.folder-mgr-name { flex: 1; font-size: 13px; }
.btn-del-folder {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 3px; border-radius: 4px; font-size: 14px;
}
.btn-del-folder:hover { color: var(--red); }

/* Usage stats */
.usage-today { font-size: 13px; margin-bottom: 10px; }
.usage-bar {
  height: 5px; background: var(--bg-4); border-radius: 3px;
  margin-top: 6px; overflow: hidden;
}
.usage-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.3s; }
.usage-history { display: flex; flex-direction: column; gap: 4px; }
.usage-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); }
.usage-date { }
.usage-val { color: var(--text); }

/* ── Phase 3: Mobile sidebar overlay ────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}
#sidebar-overlay.show { display: block; }

@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    border-right: 1px solid var(--border) !important;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
  }
  #main { width: 100%; }
  .msg-row { padding: 6px 12px; }
  .msg-bubble { max-width: 92%; }
  #topbar { padding: 10px 12px; gap: 8px; }
  #conv-title-display { font-size: 14px; }
  #input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-box { max-height: 92vh; margin: 4vh auto; }
  .topbar-user { display: none; }
  .input-hint { display: none; }
}

/* ── Phase 3: Regenerate button ──────────────────────────────────────────── */
.msg-regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.msg-regen-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Phase 3: Settings use_context toggle ────────────────────────────────── */
.modal-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.modal-toggle-row label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.modal-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Phase 3: Mobile sidebar overlay ────────────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}
#sidebar-overlay.show { display: block; }

@media (max-width: 767px) {
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
    border-right: 1px solid var(--border) !important;
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-w) !important;
    min-width: var(--sidebar-w) !important;
  }
  #main { width: 100%; }
  .msg-row { padding: 6px 12px; }
  .msg-bubble { max-width: 92%; }
  #topbar { padding: 10px 12px; gap: 8px; }
  #conv-title-display { font-size: 14px; }
  #input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .modal-box { max-height: 92vh; margin: 4vh auto; }
  .topbar-user { display: none; }
  .input-hint { display: none; }
}

/* ── Phase 3: Regenerate button ──────────────────────────────────────────── */
.msg-regen-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.msg-regen-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Phase 3: Settings use_context toggle ────────────────────────────────── */
.modal-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.modal-toggle-row label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.modal-toggle-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
