/* ===========================================================================
   Erosolar — cosmic indigo theme, matched to the app icon.
   =========================================================================== */
:root {
  --bg: #0a0a12;
  --bg-2: #0e0e1c;
  --panel: #15152a;
  --panel-2: #1d1d38;
  --border: #2b2b4a;
  --text: #eef0fa;
  --text-dim: #a8aac8;
  --text-faint: #787b9d;
  --accent: #8b8cff;
  --accent-2: #b9baff;
  --accent-soft: rgba(139, 140, 255, 0.15);
  --user-bubble: #1b1b32;
  --danger: #ff6b6b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.55);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
button { -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1100px 760px at 50% -12%, #1d1d40 0%, var(--bg) 56%);
  color: var(--text);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
[hidden] { display: none !important; }

/* ---------- Brand icon ---------- */
.brand-icon { flex: none; display: block; width: 24px; height: 24px; border-radius: 7px; }
.brand-icon-sm { width: 22px; height: 22px; border-radius: 6px; }
.brand-icon-lg { width: 44px; height: 44px; border-radius: 12px; box-shadow: 0 6px 22px rgba(0, 0, 0, 0.5); }
.brand-icon-xl { width: 68px; height: 68px; border-radius: 17px; box-shadow: 0 0 44px rgba(139, 140, 255, 0.28); }

/* ===================== Login ===================== */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; }
.brand h1 { font-size: 30px; font-weight: 700; margin: 0; letter-spacing: -0.02em; }
.tagline { color: var(--text-dim); font-size: 15px; line-height: 1.5; margin: 18px 0 28px; }
.tagline strong { color: var(--text); font-weight: 600; }
.btn-google {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 12px 16px;
  background: #fff; color: #1f1f1f;
  border: none; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}
.btn-google:hover { box-shadow: 0 6px 20px rgba(0,0,0,0.35); }
.btn-google:active { transform: translateY(1px); }
.login-foot { color: var(--text-faint); font-size: 13px; margin: 22px 0 0; }

/* ===================== App shell ===================== */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100vh; height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.brand-sm { justify-content: flex-start; font-weight: 600; font-size: 16px; }
.btn-new {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--accent-soft);
  color: var(--accent-2);
  border: 1px solid rgba(139, 140, 255, 0.3);
  border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.btn-new:hover { background: rgba(139, 140, 255, 0.22); }

.convos { flex: 1; overflow-y: auto; padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 2px; }
.convo {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease;
}
.convo:hover { background: var(--panel); color: var(--text); }
.convo.active { background: var(--panel-2); color: var(--text); border-color: var(--border); }
.convo-title {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: none; border: 0; padding: 0; margin: 0;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.convo-live { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }
.convo-del {
  flex: none; opacity: 0; border: none; background: none; color: var(--text-faint);
  cursor: pointer; padding: 2px; border-radius: 6px; display: grid; place-items: center;
}
.convo:hover .convo-del { opacity: 1; }
/* Shared hover-revealed row action buttons (pin / rename / delete). */
.convo-act {
  flex: none; opacity: 0; border: none; background: none; color: var(--text-faint);
  cursor: pointer; padding: 2px; border-radius: 6px; display: grid; place-items: center;
  transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.convo:hover .convo-act,
.convo:focus-within .convo-act,
.convo-act:focus-visible { opacity: 1; }
.convo-act:hover { color: var(--text); background: var(--panel-2); }
.convo-del:hover { color: var(--danger); background: rgba(255, 107, 107, 0.12); }
.convo-pin.on { opacity: 1; color: var(--accent-2); }
.convo-rename-input {
  flex: 1; min-width: 0; font: inherit; font-size: 14px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px;
}
.convo-rename-input:focus { outline: none; }
.convo-empty { color: var(--text-faint); font-size: 13px; padding: 10px; text-align: center; }
.conv-search {
  width: auto; box-sizing: border-box; margin: 0 8px 8px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 8px 12px; font: inherit; font-size: 13px;
}
.conv-search:focus { outline: none; border-color: var(--accent); }
.conv-search::placeholder { color: var(--text-faint); }

.sidebar-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.avatar-img { width: 32px; height: 32px; border-radius: 50%; flex: none; background: var(--panel-2); object-fit: cover; }
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link { background: none; border: none; color: var(--text-faint); font: inherit; font-size: 12px; cursor: pointer; padding: 0; text-align: left; }
.link:hover { color: var(--accent-2); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(21, 17, 11, 0.6);
  backdrop-filter: blur(8px);
}
.chat-title { font-size: 15px; font-weight: 600; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { display: none; background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 4px; }

.messages { flex: 1; overflow-y: auto; padding: 28px 0; }

/* Empty state */
.empty { max-width: 720px; margin: 8vh auto 0; padding: 0 24px; text-align: center; }
.empty h3 { font-size: 24px; margin: 18px 0 6px; letter-spacing: -0.01em; }
.empty p { color: var(--text-dim); margin: 0 0 24px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip-suggest {
  background: var(--panel); border: 1px solid var(--border); color: var(--text-dim);
  padding: 10px 14px; border-radius: var(--radius-sm); font: inherit; font-size: 13px;
  cursor: pointer; text-align: left; transition: border-color 0.15s ease, color 0.15s ease;
}
.chip-suggest:hover { border-color: var(--accent); color: var(--text); }

/* Messages */
.msg { max-width: 800px; margin: 0 auto; padding: 14px 24px; display: flex; gap: 14px; }
.msg-avatar { width: 30px; height: 30px; flex: none; border-radius: 8px; display: grid; place-items: center; font-size: 14px; }
.msg-user .msg-avatar { background: var(--panel-2); color: var(--text-dim); }
.msg-assistant .msg-avatar {
  background-image: url("./icon-192.png");
  background-size: cover;
  background-position: center;
}
.msg-body { min-width: 0; flex: 1; padding-top: 3px; }
.msg-user .msg-body .content { white-space: pre-wrap; word-wrap: break-word; }

/* Spinner — live status indicator */
.spinner {
  width: 13px; height: 13px; flex: none;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Markdown content */
.content { line-height: 1.65; font-size: 15px; color: var(--text); overflow-wrap: anywhere; }
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3 { line-height: 1.3; margin: 1.2em 0 0.5em; }
.content h1 { font-size: 1.4em; }
.content h2 { font-size: 1.25em; }
.content h3 { font-size: 1.1em; }
.content p { margin: 0.6em 0; }
.content ul, .content ol { margin: 0.6em 0; padding-left: 1.5em; }
.content li { margin: 0.25em 0; }
.content a { color: var(--accent-2); text-decoration: none; border-bottom: 1px solid rgba(185,186,255,0.32); }
.content a:hover { border-bottom-color: var(--accent-2); }
.content code { font-family: var(--mono); font-size: 0.88em; background: var(--panel-2); padding: 2px 6px; border-radius: 6px; }
.content pre { background: #0b0b18; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; overflow-x: auto; margin: 0.8em 0; }
.content pre code { background: none; padding: 0; font-size: 0.85em; line-height: 1.55; }
.content blockquote { border-left: 3px solid var(--accent); margin: 0.8em 0; padding: 0.2em 0 0.2em 1em; color: var(--text-dim); }
.content table { border-collapse: collapse; width: 100%; margin: 0.8em 0; font-size: 0.92em; }
.content th, .content td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.content th { background: var(--panel-2); }
.content hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }

/* Reasoning log — collapsible, ABOVE the answer; open & live while running,
   collapsed once the answer is complete. */
.reasoning { margin: 0 0 12px; }
.reasoning summary {
  cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-faint); user-select: none;
}
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary::before { content: "›"; display: inline-block; transition: transform 0.15s ease; color: var(--accent); font-weight: 700; }
.reasoning[open] summary::before { transform: rotate(90deg); }
.reasoning.running summary::before { content: none; } /* spinner replaces the chevron while live */
.reasoning.running summary { color: var(--text-dim); }
.reasoning summary:hover { color: var(--text-dim); }
.reasoning-body {
  margin-top: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.6;
  color: var(--text-faint); white-space: pre-wrap; overflow-wrap: anywhere;
  background: rgba(0,0,0,0.18); border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 320px; overflow-y: auto;
}
.reasoning-body:empty { display: none; }

/* "Recalled from past chats" note */
.memory-note { margin: 0 0 10px; font-size: 12.5px; color: var(--accent-2); }

/* Confirm-before-act action cards */
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions:empty { display: none; }
.action-card {
  margin-top: 12px; padding: 12px 14px;
  background: var(--panel); border: 1px solid rgba(139, 140, 255, 0.35); border-radius: var(--radius-sm);
}
.action-card.done { border-color: var(--border); opacity: 0.85; }
.action-desc { font-size: 14px; color: var(--text); margin-bottom: 10px; overflow-wrap: anywhere; }
.action-btns { display: flex; gap: 8px; }
.act-confirm {
  background: var(--accent); color: #0b0b18; border: none; border-radius: 8px;
  font: inherit; font-weight: 600; font-size: 13px; padding: 7px 14px; cursor: pointer;
}
.act-confirm:hover:not(:disabled) { background: var(--accent-2); }
.act-confirm:disabled { opacity: 0.5; cursor: default; }
.act-dismiss {
  background: none; color: var(--text-dim); border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: 13px; padding: 7px 12px; cursor: pointer;
}
.act-dismiss:hover:not(:disabled) { color: var(--text); border-color: var(--text-faint); }
.action-status { display: inline-block; margin-top: 8px; font-size: 12.5px; color: var(--text-dim); }
.action-status.ok { color: #86e0b0; }
.action-status.error { color: var(--danger); }
.action-status a { color: var(--accent-2); }

/* Connections (memory manager) */
.connections-box { font-size: 13.5px; }
.conn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.conn-ok { color: #86e0b0; font-weight: 600; }
.conn-sub { color: var(--text-faint); font-size: 12.5px; line-height: 1.5; margin: 8px 0 0; }
.btn-connect {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent-soft); color: var(--accent-2); border: 1px solid rgba(139, 140, 255, 0.3);
  border-radius: var(--radius-sm); font: inherit; font-weight: 600; font-size: 14px; padding: 9px 14px; cursor: pointer;
}
.btn-connect:hover { background: rgba(139, 140, 255, 0.22); }

/* ===================== Memory manager ===================== */
.user-links { display: flex; align-items: center; gap: 7px; }
.dot-sep { color: var(--text-faint); font-size: 12px; }

.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
}
.modal-card {
  width: 100%; max-width: 620px; max-height: 85vh; max-height: 85dvh;
  display: flex; flex-direction: column;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-x { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 5px; display: grid; place-items: center; border-radius: 8px; }
.modal-x:hover { color: var(--text); background: var(--panel); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-intro { color: var(--text-dim); font-size: 13.5px; line-height: 1.5; margin: 0 0 18px; }
.mem-section { margin-bottom: 22px; }
.mem-section:last-child { margin-bottom: 0; }
.mem-section h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint); }
.profile-box { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; font-size: 14px; line-height: 1.6; color: var(--text); }
.profile-box.empty { color: var(--text-faint); }
.profile-box > *:first-child { margin-top: 0; } .profile-box > *:last-child { margin-bottom: 0; }
.mem-list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mem-list-head h4 { margin: 0; }
.link.danger { color: var(--danger); }
.link.danger:hover { color: #ff8a8a; }
.mem-list { display: flex; flex-direction: column; gap: 8px; }
.mem-item { display: flex; gap: 10px; align-items: flex-start; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.mem-main { flex: 1; min-width: 0; }
.mem-badge { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 6px; border-radius: 5px; margin-bottom: 5px; }
.mem-badge.user { background: rgba(139, 140, 255, 0.16); color: var(--accent-2); }
.mem-badge.assistant { background: var(--panel-2); color: var(--text-dim); }
.mem-badge.web { background: rgba(120, 220, 170, 0.14); color: #86e0b0; }
.mem-text { font-size: 13px; line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
.mem-meta { margin-top: 5px; font-size: 11.5px; color: var(--text-faint); }
.mem-meta a { color: var(--text-faint); }
.mem-meta a:hover { color: var(--accent-2); }
.mem-del { flex: none; background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 4px; border-radius: 6px; display: grid; place-items: center; }
.mem-del:hover { color: var(--danger); background: rgba(255, 107, 107, 0.12); }
.mem-empty { color: var(--text-faint); font-size: 13px; padding: 8px 0; }

/* Per-message copy button */
.msg-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 4px; }
.copy-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; color: var(--text-faint);
  font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 7px; cursor: pointer;
  opacity: 0.6; transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.copy-btn:hover { opacity: 1; color: var(--text); background: var(--panel); border-color: var(--border); }
.copy-btn.copied { color: var(--accent-2); opacity: 1; }
.msg:hover .copy-btn { opacity: 1; }
.regen-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; color: var(--text-faint);
  font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 7px; cursor: pointer;
  opacity: 0.6; transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.regen-btn:hover { opacity: 1; color: var(--text); background: var(--panel); border-color: var(--border); }
.msg:hover .regen-btn { opacity: 1; }
.edit-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid transparent; color: var(--text-faint);
  font: inherit; font-size: 12px; padding: 4px 8px; border-radius: 7px; cursor: pointer;
  opacity: 0.6; transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.edit-btn:hover { opacity: 1; color: var(--text); background: var(--panel); border-color: var(--border); }
.msg:hover .edit-btn { opacity: 1; }
.edit-input {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 56px;
  background: var(--bg-2); color: var(--text); border: 1px solid var(--accent);
  border-radius: 10px; padding: 9px 11px; font: inherit; font-size: 15px; line-height: 1.5;
}
.edit-input:focus { outline: none; }
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.edit-cancel, .edit-send {
  padding: 6px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border);
}
.edit-cancel { background: none; color: var(--text-dim); }
.edit-cancel:hover { color: var(--text); border-color: var(--text-faint); }
.edit-send { background: var(--accent); color: #0b0b18; border-color: transparent; }
.edit-send:hover { background: var(--accent-2); }

/* Sources */
.sources { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sources:empty { display: none; }
.sources-label { font-size: 12px; font-weight: 600; color: var(--text-faint); margin-right: 2px; }
.source-chip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-dim);
  background: var(--panel); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; text-decoration: none;
  max-width: 280px; transition: border-color 0.15s ease, color 0.15s ease;
}
.source-chip:hover { border-color: var(--accent); color: var(--text); }
.source-chip .num { color: var(--accent-2); font-weight: 700; }
.source-chip .host { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* streaming caret */
.content .caret { display: inline-block; width: 8px; height: 1.05em; background: var(--accent); vertical-align: text-bottom; margin-left: 1px; animation: blink 1s step-end infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Composer ---------- */
.composer { padding: 8px 0 max(18px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg); }
.composer-inner {
  max-width: 800px; margin: 0 auto; padding: 0 24px;
  display: flex; align-items: flex-end; gap: 10px;
}
.composer textarea {
  flex: 1; resize: none; max-height: 200px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 16px; font: inherit; font-size: 16px; line-height: 1.5;
  outline: none; transition: border-color 0.15s ease;
}
.composer textarea:focus { border-color: var(--accent); }
.composer textarea::placeholder { color: var(--text-faint); }
.send-btn {
  flex: none; width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent); color: #0b0b18; border: none;
  display: grid; place-items: center; cursor: pointer;
  transition: opacity 0.15s ease, transform 0.08s ease;
}
.send-btn:hover:not(:disabled) { background: var(--accent-2); }
.send-btn:active:not(:disabled) { transform: translateY(1px); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
/* Stop mode: the send button becomes a stop control while a response streams. */
.send-btn.stop { background: var(--danger); color: #fff; }
.send-btn.stop:hover:not(:disabled) { background: #ff8585; }

/* First-paint splash — shown until auth resolves, then removed by app.js. */
.splash {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: radial-gradient(900px 600px at 50% 32%, #1a1a38 0%, var(--bg) 62%);
}
.splash[hidden] { display: none; } /* override .splash display so [hidden] works */
.splash img { width: 72px; height: 72px; border-radius: 18px; animation: splashpulse 1.4s ease-in-out infinite; }
@keyframes splashpulse { 0%, 100% { opacity: 0.55; transform: scale(0.97); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .splash img { animation: none; } }

/* ===================== Accessibility ===================== */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; top: -120%; left: 12px; z-index: 100;
  background: var(--accent); color: #0b0b18; font-weight: 600; font-size: 14px;
  padding: 10px 16px; border-radius: 10px; text-decoration: none;
}
.skip-link:focus { top: 12px; }
/* The skip link targets #input, which lives in the (hidden) app shell — hide it
   until the chat UI exists so it can't focus a hidden element on the login screen. */
body:has(#app[hidden]) .skip-link { display: none; }
/* Visible keyboard focus everywhere (additive; no radius so it follows each shape). */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
/* The conversation delete button is opacity:0 until hover — reveal it on keyboard focus too. */
.convo:focus-within .convo-del,
.convo-del:focus-visible { opacity: 1; }
/* Respect reduced-motion globally: neutralize spinners, pulses, caret blink, transitions. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ===================== Resilience / UX ===================== */
/* Export button → right edge of the chat header. Self-styled (NOT .icon-btn, which
   is mobile-only); id rules win the cascade and honor [hidden] at every breakpoint. */
#export-chat {
  display: grid; place-items: center; margin-left: auto;
  width: 34px; height: 34px; border-radius: 9px;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
#export-chat:hover { background: var(--panel-2); color: var(--text); }
#export-chat[hidden] { display: none; }

/* Positioning context for the jump-to-latest pill. */
.chat { position: relative; }
.jump-latest {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 96px; z-index: 5;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.55);
  transition: border-color 0.15s ease, color 0.15s ease;
}
.jump-latest:hover { border-color: var(--accent); color: var(--accent-2); }
.jump-latest[hidden] { display: none; }

/* Recoverable turn error + Retry. */
.turn-error {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 10px; padding: 10px 12px;
  background: rgba(255, 107, 107, 0.08); border: 1px solid rgba(255, 107, 107, 0.32);
  border-radius: 10px; color: var(--text-dim); font-size: 14px;
}
.retry-btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 5px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.retry-btn:hover { border-color: var(--accent); color: var(--accent-2); }

/* ===================== Code blocks + citations ===================== */
.code-wrap { position: relative; }
.code-copy {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 6px;
  background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--border); cursor: pointer; opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.code-wrap:hover .code-copy,
.code-copy:focus-visible { opacity: 1; }
.code-copy:hover { color: var(--text); border-color: var(--accent); }
/* Touch devices have no hover — keep the copy button visible. */
@media (hover: none) { .code-copy { opacity: 1; } }
/* Keep our own code-block background even after highlight.js adds .hljs. */
.content pre code.hljs { background: none; padding: 0; }
/* Inline citation links. */
.cite { color: var(--accent-2); text-decoration: none; font-weight: 600; font-size: 0.82em; padding: 0 1px; }
.cite:hover { text-decoration: underline; }

/* ===================== Toasts + confirm dialog ===================== */
.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(92vw, 420px); pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 100%;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 16px; font-size: 14px;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.6);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error { border-color: rgba(255, 107, 107, 0.5); }

.confirm-overlay {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 20px;
  background: rgba(5, 5, 12, 0.6); opacity: 0; transition: opacity 0.15s ease;
}
.confirm-overlay.show { opacity: 1; }
.confirm-card {
  width: min(94vw, 420px);
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, 0.7);
}
.confirm-msg { margin: 0 0 18px; color: var(--text); font-size: 15px; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.btn-cancel, .btn-confirm {
  padding: 9px 18px; border-radius: 9px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border);
}
.btn-cancel { background: none; color: var(--text-dim); }
.btn-cancel:hover { color: var(--text); border-color: var(--text-faint); }
.btn-confirm { background: var(--accent); color: #0b0b18; border-color: transparent; }
.btn-confirm:hover { background: var(--accent-2); }
.btn-confirm.danger { background: var(--danger); color: #fff; }
.btn-confirm.danger:hover { background: #ff8585; }

/* Custom-instructions textarea (Memory panel). */
.ci-box {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 64px;
  margin-top: 8px; padding: 10px 12px;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 14px; line-height: 1.5;
}
.ci-box:focus { outline: none; border-color: var(--accent); }
.ci-box::placeholder { color: var(--text-faint); }
.attach-btn {
  flex: none; width: 40px; height: 44px; border-radius: 10px;
  background: none; border: none; color: var(--text-faint); cursor: pointer;
  display: grid; place-items: center;
  transition: color 0.15s ease, background 0.15s ease;
}
.attach-btn:hover { color: var(--text); background: var(--panel); }
.upload-status {
  max-width: 800px; margin: 0 auto 8px; padding: 0 24px;
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim);
}
.upload-status.ok { color: var(--accent-2); }
.upload-status.error { color: var(--danger); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-2); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--border); background-clip: padding-box; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 300px); z-index: 40;
    transform: translateX(-100%); transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    padding-top: env(safe-area-inset-top);
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .icon-btn { display: grid; place-items: center; padding: 8px; margin-left: -4px; }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 30; }

  .chat-head { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .messages { padding: 16px 0; }
  .msg { padding: 12px 16px; gap: 11px; }
  .composer-inner { padding: 0 14px; }
  .empty { margin-top: 12vh; padding: 0 18px; }
  .empty h3 { font-size: 21px; }
  .login-card { padding: 32px 22px; }
  /* Wide tables and code scroll within the bubble instead of overflowing */
  .content table { display: block; overflow-x: auto; }
  .content pre { font-size: 0.8em; }
  .source-chip { max-width: 100%; }
}
