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

:root {
  --sidebar-w: 300px;
  --bg: #111111;
  --sidebar-bg: #1a1a1a;
  --border: #2a2a2a;
  --text: #e0e0e0;
  --text-muted: #666;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --user-bubble: #2563eb;
  --user-text: #ffffff;
  --bot-bubble: #212121;
  --bot-text: #e0e0e0;
  --tool-bg: #1f1a0e;
  --tool-border: #4a3800;
  --tool-text: #c9a227;
  --error-bg: #1f0e0e;
  --error-border: #5c1a1a;
  --error-text: #f87171;
  --thinking-bg: #111820;
  --thinking-border: #1e3a5f;
  --thinking-text: #6b9fd4;
  --thinking-pre-text: #5a8ab0;
  --plan-bg: #111a12;
  --plan-border: #1e4a20;
  --plan-text: #6db86f;
  --input-bg: #1e1e1e;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0,0,0,0.4);
}

html, body {
  height: 100%;
  overflow: hidden; /* prevent page-level scroll — only inner containers scroll */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

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

.app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height: accounts for mobile browser chrome */
  overflow: hidden;
}

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

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sidebar-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sidebar-logo {
  height: 24px;
  width: auto;
  display: block;
}

.sidebar-header select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  outline: none;
}
.sidebar-header select:focus { border-color: var(--accent); }

.btn-new {
  width: 100%;
  padding: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-new:hover { background: var(--accent-hover); }
.btn-new:disabled { opacity: 0.5; cursor: not-allowed; }

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s;
  margin-bottom: 2px;
}
.session-item:hover { background: #222; }
.session-item.active { background: #1a2540; }
.session-item .s-profile { font-size: 11px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 2px; }
.session-item .s-preview {
  font-size: 13px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}
.session-item .s-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.session-item .s-body { flex: 1; min-width: 0; }
.session-item { display: flex; align-items: flex-start; gap: 6px; }
.session-item.pinned { border-left: 2px solid var(--accent); padding-left: 10px; }

.s-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  padding-top: 2px; /* align buttons with first line of preview */
}
.session-item:hover .s-actions { opacity: 1; }

.btn-pin, .btn-delete {
  width: 22px;
  height: 22px;
  background: none;
  border: none;
  border-radius: 5px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  color: var(--text-muted);
}
.btn-pin:hover   { background: #1a2540; }
.btn-delete:hover { background: #3d1a1a; color: var(--error-text); }
/* always show pin icon for pinned sessions */
.session-item.pinned .s-actions { opacity: 1; }

.empty-sessions { padding: 20px 12px; color: var(--text-muted); font-size: 13px; text-align: center; }

/* ── Spinners ────────────────────────────────────────── */

@keyframes spin { to { transform: rotate(360deg); } }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

/* Small inline spinner — used inside tool card headers */
.spinner-inline {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid rgba(255,255,255,0.2);
  border-top-color: var(--tool-text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
.tool-card.error .spinner-inline { border-top-color: var(--error-text); }

/* Centred in the session list column */
.sidebar-spinner {
  display: flex;
  justify-content: center;
  padding: 24px 0;
}

/* Centred in the chat messages area */
.chat-spinner {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
}
.chat-spinner .spinner { width: 28px; height: 28px; border-width: 3px; }

/* ── Sub-agent step log (inside spawn_agent card) ────── */

.subagent-log {
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-top: 1px solid var(--tool-border);
  padding-top: 6px;
  margin-top: 2px;
}

.subagent-step {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--tool-text);
  opacity: 0.85;
  padding: 2px 4px;
  border-radius: 4px;
}
.subagent-step.pending  { opacity: 1; }
.subagent-step.error    { color: var(--error-text); }
.subagent-step.done     { opacity: 0.6; }

.step-arrow { color: var(--text-muted); font-size: 10px; }
.step-icon  { font-size: 12px; }
.step-name  { flex: 1; }
.step-status { font-size: 11px; }

/* ── Main chat area ──────────────────────────────────── */

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  padding: 14px 20px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
  min-height: 49px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.token-counter {
  margin-left: auto;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
  transition: color 0.3s;
}
.token-counter.warn { color: #b8860b; }
.token-counter.danger { color: #c0392b; }

.chat-header .profile-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
}
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  box-shadow: var(--shadow);
  word-break: break-word;
  /* no white-space: pre-wrap — markdown handles this */
}
.msg.user .bubble { background: var(--user-bubble); color: var(--user-text); border-bottom-right-radius: 3px; white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--bot-bubble); color: var(--bot-text); border-bottom-left-radius: 3px; }

/* Images inside chat bubbles */
.bubble-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.bubble-img {
  max-width: 320px;
  max-height: 240px;
  border-radius: 6px;
  object-fit: contain;
  cursor: pointer;
}
.bubble-img:only-child { max-width: 100%; }

.msg-time { font-size: 11px; color: var(--text-muted); margin-top: 4px; padding: 0 2px; }

/* ── Markdown prose ───────────────────────────────── */

.prose { line-height: 1.6; }
.prose p  { margin: 0 0 0.6em; }
.prose p:last-child { margin-bottom: 0; }
.prose h1,.prose h2,.prose h3,.prose h4 { font-weight: 700; margin: 0.8em 0 0.3em; line-height: 1.25; }
.prose h1 { font-size: 1.4em; } .prose h2 { font-size: 1.2em; } .prose h3 { font-size: 1.05em; }
.prose ul,.prose ol { padding-left: 1.4em; margin: 0.4em 0; }
.prose li { margin: 0.15em 0; }
.prose code { font-family: "Fira Code", "Cascadia Code", ui-monospace, monospace; font-size: 0.85em;
  background: #2a2a2a; color: #e2b97e; padding: 1px 5px; border-radius: 4px; }
.prose pre { margin: 0.6em 0; border-radius: 8px; overflow: hidden; }
.prose pre code { background: none; color: inherit; padding: 0; border-radius: 0; font-size: 1em; }
.prose pre .hljs { padding: 12px 16px; border-radius: 8px; font-size: 1em; }
.prose blockquote { border-left: 3px solid #444; margin: 0.5em 0; padding: 0.2em 0 0.2em 0.8em; color: var(--text-muted); }
.prose table { border-collapse: collapse; width: 100%; margin: 0.5em 0; font-size: 0.9em; }
.prose th,.prose td { border: 1px solid #333; padding: 5px 10px; text-align: left; }
.prose th { background: #222; }
.prose a { color: #60a5fa; text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose hr { border: none; border-top: 1px solid #333; margin: 0.8em 0; }
.prose strong { font-weight: 700; }
.prose em { font-style: italic; }

/* ── Tool call card (accordion) ──────────────────── */

.tool-card {
  align-self: flex-start;
  max-width: 84%;
  background: var(--tool-bg);
  border: 1px solid var(--tool-border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--tool-text);
}
.tool-card.error { background: var(--error-bg); border-color: var(--error-border); color: var(--error-text); }

.tool-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  border-radius: var(--radius);
}
.tool-header:hover { background: rgba(255,255,255,0.04); }
.tool-icon { font-size: 14px; }
.tool-name { flex: 1; }
.tool-status { font-size: 13px; opacity: 0.8; }
.tool-card:not(.open) .tool-header::after { content: '›'; font-size: 16px; opacity: 0.5; }
.tool-card.open       .tool-header::after { content: '‹'; font-size: 16px; opacity: 0.5; }

.tool-body {
  border-top: 1px solid var(--tool-border);
  padding: 8px 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
}
.tool-card.open .tool-body,
.tool-card.pending .tool-body-open {
  display: flex;
  animation: fadeSlide 0.18s ease;
}
/* pending: no chevron toggle while running */
.tool-card.pending .tool-header::after { content: ''; }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.tool-args {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 2px 10px;
  font-size: 11px;
  opacity: 0.85;
}
.arg-key { color: var(--text-muted); font-style: italic; }
.arg-val { word-break: break-all; }

.tool-result-pre {
  margin: 0;
  padding: 8px 10px;
  background: rgba(0,0,0,0.25);
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 260px;
  overflow-y: auto;
  color: var(--text);
}

/* ── Context summary card (compressed history) ───────── */

.summary-card {
  align-self: flex-start;
  max-width: 84%;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
}

.summary-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  border-radius: var(--radius);
}
.summary-header:hover { background: rgba(255,255,255,0.03); }
.summary-icon { font-size: 13px; }
.summary-card:not(.open) .summary-header::after { content: '›'; font-size: 16px; opacity: 0.5; }
.summary-card.open       .summary-header::after { content: '‹'; font-size: 16px; opacity: 0.5; }

.summary-body {
  border-top: 1px solid #30363d;
  padding: 8px 12px;
  display: none;
  color: var(--text-muted);
}
.summary-card.open .summary-body {
  display: block;
  animation: fadeSlide 0.18s ease;
}
.summary-body .prose { font-size: 12px; line-height: 1.55; }

/* Compression notice — inline divider */
.compression-notice {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 12px;
  border-radius: 99px;
  border: 1px solid #30363d;
  background: #161b22;
  opacity: 0.7;
}

/* ── Agent note — model text between tool calls ──────── */

.agent-note {
  align-self: flex-start;
  max-width: 72%;
  font-size: 13px;
  font-style: italic;
  color: var(--text-muted);
  padding: 4px 10px;
  border-left: 2px solid var(--border);
  margin: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.subagent-note {
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  padding: 2px 4px 2px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
}

.subagent-thinking {
  margin: 4px 0 4px 8px;
}
.subagent-thinking summary {
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 2px 0;
}
.subagent-thinking summary::-webkit-details-marker { display: none; }
.subagent-thinking-pre {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 4px 0 0 0;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  line-height: 1.4;
}

/* ── Thinking card ───────────────────────────────────── */

.thinking-card {
  align-self: flex-start;
  max-width: 84%;
  background: var(--thinking-bg);
  border: 1px solid var(--thinking-border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--thinking-text);
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  border-radius: var(--radius);
}
.thinking-header:hover { background: rgba(255,255,255,0.03); }
.thinking-icon { font-size: 14px; }
.thinking-label { flex: 1; }
.thinking-card:not(.open) .thinking-header::after { content: '›'; font-size: 16px; opacity: 0.5; }
.thinking-card.open       .thinking-header::after { content: '‹'; font-size: 16px; opacity: 0.5; }

.thinking-body {
  border-top: 1px solid var(--thinking-border);
  padding: 8px 12px;
  display: none;
}
.thinking-card.open .thinking-body {
  display: block;
  animation: fadeSlide 0.18s ease;
}

.thinking-pre {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  color: var(--thinking-pre-text);
}

/* ── Plan card ───────────────────────────────────────── */

.plan-card {
  align-self: flex-start;
  max-width: 84%;
  background: var(--plan-bg);
  border: 1px solid var(--plan-border);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--plan-text);
}

.plan-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  border-radius: var(--radius);
}
.plan-header:hover { background: rgba(255,255,255,0.03); }
.plan-icon { font-size: 14px; }
.plan-label { flex: 1; }
.plan-card:not(.open) .plan-header::after { content: '›'; font-size: 16px; opacity: 0.5; }
.plan-card.open       .plan-header::after { content: '‹'; font-size: 16px; opacity: 0.5; }

.plan-body {
  border-top: 1px solid var(--plan-border);
  padding: 10px 14px;
  display: none;
}
.plan-card.open .plan-body {
  display: block;
  animation: fadeSlide 0.18s ease;
}
.plan-body .prose { color: var(--plan-text); font-size: 12px; }
.plan-body .prose ol,
.plan-body .prose ul { padding-left: 1.4em; }
.plan-body .prose li { margin: 3px 0; }
.plan-body .prose p  { margin: 4px 0; }

/* Typing indicator */
.typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--bot-bubble);
  border-radius: var(--radius);
  border-bottom-left-radius: 3px;
  box-shadow: var(--shadow);
}
.typing span { width: 7px; height: 7px; background: var(--text-muted); border-radius: 50%; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* Cursor while streaming */
.cursor::after { content: "▋"; animation: cursor-blink 0.7s step-start infinite; font-size: 0.9em; margin-left: 1px; }
@keyframes cursor-blink { 50% { opacity: 0; } }

/* Error message */
.msg-error {
  align-self: center;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
}

/* Empty state */
.empty-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
}
.empty-chat .icon { font-size: 40px; }
.empty-chat p { font-size: 15px; }

/* ── Input bar ───────────────────────────────────────── */

.input-bar {
  padding: 12px 20px 16px;
  background: var(--sidebar-bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Image preview strip */
.image-preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.image-preview-strip:empty { display: none; }

.img-thumb-wrap {
  position: relative;
  width: 72px;
  height: 72px;
}
.img-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.img-thumb-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: var(--error-text);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* File badges (non-image uploads) */
.file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  max-width: 180px;
  cursor: default;
}
.file-badge-icon { font-size: 18px; flex-shrink: 0; }
.file-badge-info { overflow: hidden; }
.file-badge-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.file-badge-size { font-size: 11px; color: var(--text-muted); }
.file-badge-remove {
  margin-left: auto;
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.file-badge-remove:hover { color: var(--error-text); }

/* Upload progress bar */
.upload-progress-bar {
  position: relative;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.upload-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.1s linear;
  width: 0%;
}
.upload-progress-label {
  position: absolute;
  right: 0;
  top: 6px;
  font-size: 10px;
  color: var(--text-muted);
}

/* Input row: attach + textarea + send */
.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.btn-attach {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--input-bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-attach:hover { border-color: var(--accent); color: var(--accent); }
.btn-attach:disabled { opacity: 0.5; cursor: not-allowed; }

.input-bar textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  resize: none;
  min-height: 44px;
  max-height: 180px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
}
.input-bar textarea:focus { border-color: var(--accent); }
.input-bar textarea:disabled { opacity: 0.5; }

.btn-send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 18px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-send.stop-mode { background: #c0392b; font-size: 14px; }
.btn-send.stop-mode:hover { background: #a93226; }
.btn-send.stop-mode:disabled { background: #c0392b; opacity: 0.5; }

/* ── Scrollbar ───────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 99px; }

/* ── Sidebar toggle button (hidden on desktop) ───────── */

.btn-sidebar-toggle {
  display: none;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.btn-sidebar-toggle:hover { background: #222; color: var(--text); }

/* ── Sidebar backdrop (mobile overlay) ───────────────── */

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sidebar-backdrop.visible {
  display: block;
  opacity: 1;
}

/* ── Responsive breakpoint ───────────────────────────── */

@media (max-width: 768px) {
  /* Sidebar becomes a fixed drawer */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }

  /* Hamburger button visible */
  .btn-sidebar-toggle { display: flex; }

  /* Chat fills the full width */
  .chat { width: 100%; }

  /* Wider bubbles on small screens */
  .msg      { max-width: 90%; }
  .tool-card,
  .thinking-card,
  .plan-card,
  .summary-card { max-width: 96%; }

  /* Tighter message padding */
  .messages { padding: 16px 12px; gap: 12px; }

  /* Input bar tighter */
  .input-bar { padding: 10px 12px 12px; }

  /* Chat header smaller */
  .chat-header { padding: 10px 14px; min-height: 44px; }
}
