:root {
  --bg: #0b0d10;
  --bg-elev: #12151a;
  --bg-elev-2: #171b21;
  --surface: #1b2028;
  --border: #262c36;
  --border-soft: #20252e;
  --text: #e7ebf0;
  --text-dim: #9aa4b2;
  --text-faint: #6b7482;
  --accent: #6ea8fe;
  --accent-2: #7c5cff;
  --accent-grad: linear-gradient(135deg, #6ea8fe 0%, #7c5cff 100%);
  --user-bubble: #1e2937;
  --danger: #ff6b6b;
  --ok: #3fb950;
  --code-bg: #0c0e12;
  --code-head-bg: #090b0f;
  --code-gutter: #5a6472;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  --font: "IBM Plex Sans", "IBM Plex Sans Arabic", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "IBM Plex Mono", "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

/* Light theme overrides. */
:root[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-elev-2: #f0f2f5;
  --surface: #e8ebef;
  --border: #d5dae1;
  --border-soft: #e2e6ec;
  --text: #1a1f27;
  --text-dim: #56606e;
  --text-faint: #8a94a2;
  --accent: #2f6bd6;
  --accent-2: #6b4dff;
  --accent-grad: linear-gradient(135deg, #2f6bd6 0%, #6b4dff 100%);
  --user-bubble: #e3edfb;
  --danger: #d63b3b;
  --ok: #1a883a;
  --code-bg: #f4f6f8;
  --code-head-bg: #eaedf1;
  --code-gutter: #a2acba;
  --shadow: 0 10px 40px rgba(20, 30, 50, 0.14);
}

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

/* Keep hardcoded dark surfaces readable in the light theme. */
:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, 0.85); }
:root[data-theme="light"] .chat-scroll,
:root[data-theme="light"] .modal-body { scrollbar-color: #c2c9d2 transparent; }
:root[data-theme="light"] .chat-scroll::-webkit-scrollbar-thumb,
:root[data-theme="light"] .modal-body::-webkit-scrollbar-thumb { background: #c2c9d2; }
:root[data-theme="light"] .file-card { background: var(--code-bg); }
:root[data-theme="light"] .file-card:hover { background: var(--bg-elev-2); }

* { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules below. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(11, 13, 16, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }

.logo {
  font-size: 22px;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.title { font-weight: 650; letter-spacing: 0.2px; font-size: 16px; }

.model-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 500;
}
.model-badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(63, 185, 80, 0.7);
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.ghost-btn:hover { background: var(--surface); color: var(--text); border-color: #333b47; }
.ghost-btn.danger:hover { color: var(--danger); border-color: rgba(255, 107, 107, 0.4); }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-faint);
  margin-left: 2px;
}
.status-dot.online { background: var(--ok); box-shadow: 0 0 8px rgba(63, 185, 80, 0.6); }

/* ---- Messages ---- */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
}
.messages {
  flex: 1 0 auto;
  padding: 28px 20px 20px;
}

.chat-scroll, .modal-body { scrollbar-width: thin; scrollbar-color: #2a313c transparent; }
.chat-scroll::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 10px; }
.chat-scroll::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb {
  background: #2a313c; border-radius: 10px; border: 3px solid transparent; background-clip: content-box;
}

.msg-row { max-width: 820px; margin: 0 auto 22px; display: flex; gap: 14px; align-items: flex-start; }
.msg-row.user { flex-direction: row-reverse; }
.msg-col { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1; }
.msg-row.user .msg-col { align-items: flex-end; }

.avatar {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 8px;
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600;
}
.avatar.assistant { background: var(--accent-grad); color: #fff; }
.avatar.user { background: var(--surface); border: 1px solid var(--border); color: var(--text-dim); }
.avatar.user svg { display: block; }
.avatar.system { background: #2a2320; color: #e0b060; }

.bubble {
  min-width: 0;
  max-width: 100%;
  padding: 2px 2px;
}
.msg-row.user .bubble {
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 15px;
  max-width: 78%;
}
.msg-row.system .bubble {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 11px 15px;
  font-size: 13.5px;
  color: var(--text-dim);
  width: 100%;
}

.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 14px 14px;
  overflow-x: auto;
  margin: 12px 0;
}
.bubble pre code { font-family: var(--mono); font-size: 13px; background: none; padding: 0; }
.bubble code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  padding: 1.5px 5px;
  border-radius: 5px;
}
.bubble a { color: var(--accent); }
.bubble table { border-collapse: collapse; margin: 12px 0; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble blockquote { border-left: 3px solid var(--border); margin: 12px 0; padding-left: 14px; color: var(--text-dim); }

/* Right-to-left (Arabic, Hebrew): align the whole message, keep code/blockquote LTR. */
.bubble[dir="rtl"], .content[dir="rtl"] { text-align: right; }
.bubble[dir="rtl"] ul, .bubble[dir="rtl"] ol,
.content[dir="rtl"] ul, .content[dir="rtl"] ol { padding-inline-start: 1.6em; padding-inline-end: 0; }
.bubble[dir="rtl"] blockquote, .content[dir="rtl"] blockquote {
  border-left: none; border-right: 3px solid var(--border);
  padding-left: 0; padding-right: 14px;
}
.bubble[dir="rtl"] pre, .bubble[dir="rtl"] pre code,
.content[dir="rtl"] pre, .content[dir="rtl"] pre code {
  direction: ltr; text-align: left;
}
.bubble[dir="rtl"] table, .content[dir="rtl"] table { text-align: right; }

/* Code block: header above a flex body of [line-number gutter | scrolling <pre>]. */
.code-block {
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--code-bg);
}
.code-body { display: flex; align-items: stretch; }
.code-block pre {
  flex: 1;
  min-width: 0;
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 12px 14px;
  overflow-x: auto;
}
.code-block pre code { display: block; font-size: 13px; line-height: 1.55; }
.line-nums {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 0;
  text-align: right;
  -webkit-user-select: none;
  user-select: none;
  color: var(--code-gutter);
  border-right: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  background: var(--code-head-bg);
}
.line-nums span { padding: 0 10px 0 14px; }
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px 7px 14px;
  background: var(--code-head-bg);
  border-bottom: 1px solid var(--border);
  direction: ltr;
}
.code-lang {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.code-actions { display: flex; gap: 6px; }
.code-btn {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 10px;
  font-size: 11.5px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--font);
}
.code-btn:hover { color: var(--text); border-color: var(--border-soft); }
.code-btn.copied { color: var(--ok); border-color: rgba(63, 185, 80, 0.4); }

/* Theme toggle: icon-only button that swaps sun/moon by active theme. */
.ghost-btn.icon-only { padding: 8px; }
.icon-moon { display: none; }
.icon-sun { display: inline-flex; }
:root[data-theme="light"] .icon-sun { display: none; }
:root[data-theme="light"] .icon-moon { display: inline-flex; }

/* Per-message hover actions (copy / edit). Live in the message column so they
   sit inline with the bubble's edge (left for assistant, right for user). */
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-row.user .msg-actions { justify-content: flex-end; }
.msg-row:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-act {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.msg-act:hover { color: var(--text); border-color: var(--border-soft); background: var(--surface); }
.msg-act.done { color: var(--ok); border-color: rgba(63, 185, 80, 0.4); }

/* Inline message editor. */
.bubble.editing { width: 100%; max-width: 640px; }
.edit-area {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.edit-area:focus { border-color: #3d4757; box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.12); }
.edit-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.edit-btns .ghost-btn, .edit-btns .primary-btn { padding: 7px 14px; font-size: 13px; }

/* Retry button inside an error bubble. */
.error-box { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.retry-btn { display: inline-flex; align-items: center; gap: 6px; }

/* Line numbers gutter for file previews reuses .code-block styles. */
.file-item { display: flex; flex-direction: column; }
.file-preview { margin-top: 6px; }
.file-btn {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.file-btn:hover { color: var(--text); border-color: var(--accent); }

/* Back-to-top: subtle floating button above the composer, non-intrusive. */
.scroll-top {
  position: fixed;
  right: 22px;
  bottom: 104px;
  z-index: 50;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-dim);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow);
  opacity: 0.85;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}
.scroll-top:hover { opacity: 1; color: var(--text); border-color: var(--accent); transform: translateY(-2px); }

/* Drag & drop overlay. */
.drop-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(10, 12, 16, 0.72);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  pointer-events: none;
}
.drop-inner {
  border: 2px dashed var(--accent);
  border-radius: 18px;
  padding: 40px 60px;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-elev);
}

/* Tool status pills (web search / fetch url / create file). */
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tool-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  direction: ltr;
}
.tool-pill.ok { border-color: rgba(63, 185, 80, 0.4); }
.tool-pill .dots span {
  display: inline-block; width: 4px; height: 4px; margin-left: 1px;
  border-radius: 50%; background: currentColor; opacity: 0.5;
  animation: tooldot 1s infinite;
}
.tool-pill .dots span:nth-child(2) { animation-delay: 0.15s; }
.tool-pill .dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tooldot { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.9; } }

/* Downloadable file cards created by the model. */
.files { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.file-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--code-bg);
  color: var(--text);
  transition: border-color 0.15s, background 0.15s;
}
.file-card:hover { border-color: var(--accent); }
.file-icon { font-size: 20px; }
.file-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.file-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 11.5px; color: var(--text-dim); }

.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.msg-attachments img { max-width: 220px; max-height: 180px; border-radius: 8px; border: 1px solid var(--border); }
.msg-attachments .file-item { flex: 1 1 240px; min-width: 200px; max-width: 100%; }
.file-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; font-size: 12.5px; color: var(--text-dim);
}

.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint);
  animation: bounce 1.3s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* ---- Empty state ---- */
.empty {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--text-dim);
  gap: 6px;
}
.empty-logo {
  font-size: 52px;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 8px;
}
.empty h1 { font-size: 26px; font-weight: 650; color: var(--text); margin: 0; }
.empty p { max-width: 420px; margin: 0; }

/* ---- Composer ---- */
.composer { padding: 12px 20px 20px; background: linear-gradient(to top, var(--bg) 60%, transparent); flex-shrink: 0; }
.composer-inner { max-width: 820px; margin: 0 auto; }
.modal.modal-wide { max-width: min(900px, 92vw); }
.composer-guide-body {
  font-size: 14px;
  color: var(--text-dim);
}
.composer-guide-body h3 { font-size: 15px; color: var(--text); margin: 0 0 8px; }
.composer-guide-body h3:not(:first-child) { margin-top: 14px; }
.composer-guide-body ul { margin: 0; padding-left: 20px; }
.composer-guide-body li { margin: 6px 0; line-height: 1.6; }
.composer-guide-body strong { color: var(--text); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 8px 6px 10px; font-size: 12.5px; color: var(--text-dim);
  max-width: 220px;
}
.chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip img { width: 26px; height: 26px; border-radius: 5px; object-fit: cover; }
.chip .chip-x {
  border: none; background: none; color: var(--text-faint); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px;
}
.chip .chip-x:hover { color: var(--danger); }

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 7px 7px 7px 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-wrap:focus-within { border-color: #3d4757; box-shadow: 0 0 0 3px rgba(110, 168, 254, 0.1); }

#input {
  flex: 1;
  background: none; border: none; outline: none; resize: none;
  color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.5;
  max-height: 200px; padding: 8px 4px;
}
#input::placeholder { color: var(--text-faint); }

.icon-btn {
  flex-shrink: 0;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: none; border-radius: 11px;
  cursor: pointer;
  background: transparent; color: var(--text-dim);
  transition: all 0.15s ease;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.attach-btn svg { transform: rotate(0deg); }

.send-btn { background: var(--accent-grad); color: #fff; }
.send-btn:hover { filter: brightness(1.08); background: var(--accent-grad); color: #fff; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

.stop-btn { background: var(--surface); color: var(--danger); border: 1px solid var(--border); }
.stop-btn:hover { background: #241b1b; color: var(--danger); }

.hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text-faint);
  font-size: 11.5px;
  margin-top: 10px;
}
.usage-counter {
  flex-shrink: 0;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.usage-counter.warn {
  color: #e0b060;
  border-color: rgba(224, 176, 96, 0.4);
  background: rgba(224, 176, 96, 0.08);
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 460px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease;
  overflow: hidden;
}
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 16px; max-height: 60vh; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px; border-top: 1px solid var(--border-soft);
}
.confirm-message { margin: 0; font-size: 14px; line-height: 1.6; color: var(--text); }
.danger-btn {
  padding: 8px 16px; border-radius: 999px; cursor: pointer;
  border: 1px solid transparent; background: #d9384e; color: #fff;
  font-size: 13px; font-weight: 600; transition: background 0.15s ease;
}
.danger-btn:hover { background: #c02c41; }

.account-card {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.account-row { display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; }
.account-label { color: var(--text-faint); }
.account-value { font-weight: 550; }
.account-value.online { color: var(--ok); }
.account-value.offline { color: var(--text-dim); }

.muted { color: var(--text-dim); font-size: 13.5px; margin: 0; }

.device-box {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-start;
  margin-top: 12px;
}
.device-link { color: var(--accent); font-weight: 550; text-decoration: none; }
.device-link:hover { text-decoration: underline; }
.device-code {
  font-family: var(--mono); font-size: 24px; letter-spacing: 4px; font-weight: 700;
  color: var(--text); background: var(--bg); border: 1px dashed var(--border);
  padding: 10px 16px; border-radius: 10px; width: 100%; text-align: center;
}
.device-wait { display: flex; align-items: center; gap: 8px; }

.admin-msg { font-size: 13px; padding: 10px 12px; border-radius: 10px; }
.admin-msg.error { background: rgba(255, 107, 107, 0.12); color: #ff9a9a; border: 1px solid rgba(255, 107, 107, 0.3); }
.admin-msg.ok { background: rgba(63, 185, 80, 0.12); color: #7ee787; border: 1px solid rgba(63, 185, 80, 0.3); }

.primary-btn {
  background: var(--accent-grad); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: 10px 18px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: filter 0.15s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 18px; font-size: 13.5px; z-index: 200;
  box-shadow: var(--shadow);
  animation: toastin 0.2s ease;
  max-width: 90vw;
}
.toast.error { border-color: rgba(255, 107, 107, 0.4); color: #ff9a9a; }
@keyframes toastin { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* Active state for topbar toggles (follow / theme). */
.ghost-btn.icon-only.active { color: var(--accent); border-color: var(--accent); }

/* Clickable images open in the lightbox. */
.content img, .bubble img { max-width: 100%; border-radius: 8px; }
.content img, .bubble img, .msg-attachments img { cursor: zoom-in; }

/* Inline YouTube players (responsive 16:9). */
.yt-embed {
  position: relative;
  width: 100%;
  max-width: 560px;
  aspect-ratio: 16 / 9;
  margin: 12px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}
.yt-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* Image lightbox. */
.lightbox {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0, 0, 0, 0.9);
  display: grid; place-items: center;
  padding: 24px;
  animation: fade 0.15s ease;
}
.lightbox-img { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 8px; box-shadow: var(--shadow); }
.lightbox-btn {
  position: fixed; top: 18px;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.45);
  color: #fff; border-radius: 50%;
  cursor: pointer; text-decoration: none;
  transition: background 0.15s;
}
.lightbox-btn:hover { background: rgba(0, 0, 0, 0.75); }
.lightbox-close { right: 18px; }
.lightbox-dl { right: 72px; }
body.no-scroll { overflow: hidden; }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 8px; }
  .ghost-btn span:not(.status-dot) { display: none; }
  .ghost-btn { padding: 8px; }
  .messages { padding: 20px 12px 12px; }
  .msg-row { gap: 10px; margin-bottom: 18px; }
  .composer { padding: 10px 10px 14px; }
  .msg-row.user .bubble { max-width: 88%; }
  .empty h1 { font-size: 22px; }

  /* Touch devices have no hover — keep message actions visible. */
  .msg-actions { opacity: 1; }

  /* Code blocks: tighter gutter, allow the whole block to fit the screen. */
  .code-block pre { padding: 10px 12px; }
  .code-block pre code { font-size: 12.5px; }
  .line-nums { font-size: 12.5px; }
  .line-nums span { padding: 0 8px 0 10px; }
  .code-head { padding: 6px 8px 6px 12px; }
  .code-btn { padding: 3px 8px; font-size: 11px; }

  /* File cards wrap their buttons on narrow screens. */
  .file-card { flex-wrap: wrap; }
  .file-info { flex-basis: 100%; order: -1; }

  #input { font-size: 16px; } /* prevents iOS zoom-on-focus */
  .bubble.editing { max-width: 100%; }
  .katex-display { overflow-x: auto; overflow-y: hidden; }
  .scroll-top { right: 14px; bottom: 92px; width: 38px; height: 38px; }
}

/* Long equations should scroll rather than overflow the bubble. */
.katex-display { max-width: 100%; }
.workspace-panel {
  padding: 12px 20px;
  border-top: 1px solid var(--border, #444);
}
.workspace-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.workspace-toolbar select { max-width: 220px; padding: 6px; color: inherit; background: var(--bg, #222); }
.workspace-panel .file-item { margin: 8px 0; }
.workspace-panel .file-card, .msg-attachments .file-card { flex-wrap: wrap; gap: 8px; }
.file-preview pre { overflow-wrap: anywhere; }
.workspace-panel { flex-shrink: 0; }
.workspace-panel h2 { font-size: 15px; margin: 12px 0 6px; }
.workspace-task { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; margin: 8px 0; overflow-wrap: anywhere; }
.task-status { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; color: var(--text-dim); margin: 6px 0; }
.workspace-task small { display: block; }
.task-checks { white-space: pre-line; }
.task-attachments { font-size: 13px; margin: 6px 0; }
.task-details summary { cursor: pointer; color: var(--text-dim); font-size: 13px; }
.task-resume { margin-top: 8px; }
.file-validation, .validation-diagnostics { display: block; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; color: var(--text-dim); }
.file-validation[data-status="passed"] { color: var(--ok); }
.file-validation[data-status="failed"], .file-validation[data-status="warning"] { color: var(--danger); }
.file-diff { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; margin-top: 4px; font-size: 12px; }
.file-diff summary { cursor: pointer; overflow-wrap: anywhere; }
.file-diff pre { background: var(--code-bg); max-height: 240px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; padding: 8px; font-family: var(--mono); }
.file-btn:disabled { opacity: .5; cursor: not-allowed; }
.completion-status { font-size: .82rem; color: var(--muted, #a0a0a0); border-left: 3px solid #b08aff; padding: .45rem .7rem; }
.content.provisional { border-left: 2px dotted #777; padding-left: .7rem; }
