/* ============================================================================
   Alpha — chat UI. Fire-forged design system, matched to the DragonMeta
   landing page. Dark-first, warm-paper light mode, CSP-safe, self-hosted fonts.
   ========================================================================== */

/* ---- Self-hosted fonts (same-origin — no third-party request) ---- */
@font-face{font-family:'Inter';font-style:normal;font-weight:400;font-display:swap;src:url('/assets/fonts/Inter-400.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:500;font-display:swap;src:url('/assets/fonts/Inter-500.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:600;font-display:swap;src:url('/assets/fonts/Inter-600.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:700;font-display:swap;src:url('/assets/fonts/Inter-700.woff2') format('woff2')}
@font-face{font-family:'Inter';font-style:normal;font-weight:800;font-display:swap;src:url('/assets/fonts/Inter-800.woff2') format('woff2')}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:400;font-display:swap;src:url('/assets/fonts/JetBrainsMono-400.woff2') format('woff2')}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:500;font-display:swap;src:url('/assets/fonts/JetBrainsMono-500.woff2') format('woff2')}
@font-face{font-family:'JetBrains Mono';font-style:normal;font-weight:700;font-display:swap;src:url('/assets/fonts/JetBrainsMono-700.woff2') format('woff2')}
/* Arabic UI face (used when the interface language is Arabic). */
@font-face{font-family:'Cairo';font-style:normal;font-weight:400;font-display:swap;src:url('/assets/fonts/Cairo-400.woff2') format('woff2')}
@font-face{font-family:'Cairo';font-style:normal;font-weight:700;font-display:swap;src:url('/assets/fonts/Cairo-700.woff2') format('woff2')}

/* ---------------------------- Design tokens ------------------------------ */
:root {
  /* Sleek-futuristic dark: deep cool charcoal base, fire orange as the neon
     accent, glass panels layered with soft glow. */
  --bg: #07070a;
  --bg-2: #0c0c11;
  --bg-3: #131319;
  --surface: #14141b;
  --surface-2: #1b1b23;
  --surface-hover: #23232d;
  --border: #23242f;
  --border-2: #33343f;
  --border-3: #474956;
  --text: #f2f3f7;
  --muted: #a6aab7;
  --dim: #828695;

  --fire: #ff5a1f;
  --fire-2: #ff8f47;
  --fire-3: #ffc191;
  --fire-soft: rgba(255, 90, 31, .13);
  --fire-line: rgba(255, 143, 71, .40);
  --fire-glow: rgba(255, 96, 24, .50);
  --grad-fire: linear-gradient(135deg, #ff5a1f 0%, #ff9a4d 100%);
  --grad-head: linear-gradient(180deg, #ffffff 0%, #c3c6d2 100%);
  --grad-flame: linear-gradient(120deg, #ff7a3a 0%, #ffc08a 100%);

  /* Glassmorphism + neon helpers */
  --glass: rgba(16, 16, 21, 0.92);
  --glass-2: rgba(255, 255, 255, 0.045);
  --glass-brd: rgba(255, 255, 255, 0.09);
  --glass-blur: blur(8px) saturate(120%);
  --ring: 0 0 0 1px rgba(255,143,71,.35), 0 8px 30px -16px var(--fire-glow);

  --danger: #ff5a52;
  --success: #3ddc84;

  --radius: 20px;
  --radius-sm: 13px;
  --radius-xs: 9px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-ar: 'Cairo', 'Inter', ui-sans-serif, system-ui, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
  --sidebar-w: 272px;
  --thread-max: 800px;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.4, .64, 1);

  --shadow-sm: 0 1px 3px rgba(0,0,0,.5);
  --shadow-md: 0 14px 40px -16px rgba(0,0,0,.78);
  --shadow-lg: 0 22px 55px -26px rgba(0,0,0,.82);
  --code-bg: #0a0a0e;
  --code-head: #101017;
  --code-text: #e7e9f0;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-2: #eef0f4;
  --bg-3: #e5e8ee;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --surface-hover: #eceff4;
  --border: #e4e7ee;
  --border-2: #d2d6e0;
  --border-3: #bbc0ce;
  --text: #14161c;
  --muted: #565b68;
  --dim: #606673;

  --fire: #e24a12;
  --fire-2: #ff6a2b;
  --fire-3: #c2531c;
  --fire-soft: rgba(226, 74, 18, .09);
  --fire-line: rgba(226, 74, 18, .28);
  --fire-glow: rgba(226, 74, 18, .22);
  --grad-head: linear-gradient(180deg, #14161c 0%, #454a58 100%);

  --glass: rgba(255, 255, 255, 0.94);
  --glass-2: rgba(0, 0, 0, 0.025);
  --glass-brd: rgba(0, 0, 0, 0.06);
  --ring: 0 0 0 1px rgba(226,74,18,.30), 0 8px 28px -16px rgba(226,74,18,.22);

  --shadow-sm: 0 1px 3px rgba(40,45,60,.08);
  --shadow-md: 0 14px 40px -16px rgba(40,45,60,.22);
  --shadow-lg: 0 22px 52px -26px rgba(40,45,60,.22);
  --code-bg: #15171e;
  --code-head: #1e212b;
  --code-text: #e7e9f0;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  display: flex; height: 100vh; font-size: 15px; line-height: 1.65;
  letter-spacing: -.006em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--fire-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Ambient fire glow behind the whole app — subtle, fixed, non-interactive. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(66vw 44vh at 72% -12%, var(--fire-glow), transparent 66%),
    radial-gradient(42vw 34vh at 4% 112%, rgba(214,60,0,.07), transparent 70%);
  opacity: .5;
}
#sidebar, #main { position: relative; z-index: 1; }

/* utility */
.hidden { display: none !important; }
.hist-empty { padding: 22px 16px; text-align: center; color: var(--dim); font-size: 13px; }

/* ------------------------------- Sidebar -------------------------------- */
#sidebar {
  width: var(--sidebar-w);
  background: var(--glass);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--glass-brd);
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: margin-left .3s var(--ease); z-index: 20;
}
#sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
.sidebar-header { display: flex; align-items: center; gap: 12px; padding: 15px 16px 13px; }
.brand-mark { width: 30px; height: 30px; flex-shrink: 0; display: grid; place-items: center; }
.brand-mark svg { width: 30px; height: 30px; filter: drop-shadow(0 2px 8px var(--fire-glow)); }
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.brand-name b { color: var(--text); }
.brand-sub { font-size: 11px; color: var(--dim); margin-top: 1px; }
.sidebar-collapse {
  width: 30px; height: 30px; border-radius: var(--radius-xs); color: var(--dim);
  display: grid; place-items: center; opacity: 0;
  transition: opacity .15s, background .12s, color .12s;
}
.sidebar-header:hover .sidebar-collapse { opacity: 1; }
.sidebar-collapse:hover { background: var(--surface-hover); color: var(--text); }

.new-chat {
  margin: 6px 12px 10px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--glass-2); border: 1px solid var(--glass-brd); color: var(--text);
  font-size: 14px; font-weight: 600; display: flex; align-items: center;
  gap: 10px; transition: border-color .18s, background .18s, transform .12s, box-shadow .22s;
}
.new-chat:hover { border-color: var(--fire-line); background: var(--surface-hover); box-shadow: var(--ring); transform: translateY(-1px); }
.new-chat:active { transform: scale(.985); }
.new-chat .plus {
  width: 20px; height: 20px; border-radius: 6px; background: var(--grad-fire);
  color: #180a02; font-size: 15px; line-height: 20px; text-align: center;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
  box-shadow: 0 2px 8px -2px var(--fire-glow);
}
.sidebar-search { margin: 0 12px 8px; position: relative; }
.sidebar-search input {
  width: 100%; padding: 10px 12px 10px 33px; border-radius: var(--radius-xs);
  border: 1px solid var(--glass-brd); background: var(--glass-2); color: var(--text);
  font-size: 13px; outline: none; transition: border-color .16s, box-shadow .16s;
}
.sidebar-search input:focus { border-color: var(--fire-line); box-shadow: 0 0 0 3px var(--fire-soft); }
.sidebar-search input::placeholder { color: var(--dim); }
.sidebar-search svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--dim); pointer-events: none;
}

.history { flex: 1; overflow-y: auto; padding: 4px 8px; }
.hist-item {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 9px 10px 9px 13px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; margin-bottom: 2px;
  transition: background .14s, color .14s;
}
.hist-item::before {
  content: ""; position: absolute; left: 3px; top: 50%; transform: translateY(-50%) scaleY(0);
  width: 3px; height: 18px; border-radius: 3px; background: var(--grad-fire);
  transition: transform .2s var(--ease-spring);
}
.hist-item:hover { background: var(--surface-hover); color: var(--text); }
.hist-item.active { background: var(--fire-soft); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--fire-line); }
.hist-item.active::before { transform: translateY(-50%) scaleY(1); }
.hist-item .hist-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-item .hist-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .14s; }
.hist-item:hover .hist-actions, .hist-item.active .hist-actions { opacity: 1; }
.hist-action {
  width: 25px; height: 25px; border-radius: 6px; color: var(--dim);
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.hist-action:hover { background: var(--bg-3); color: var(--text); }
.hist-action.del:hover { color: var(--danger); }

.sidebar-foot {
  padding: 11px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--dim);
  display: flex; align-items: center; gap: 8px;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--dim); flex-shrink: 0; transition: background .2s; }
.dot.online { background: var(--success); box-shadow: 0 0 0 0 rgba(52,199,89,.5); animation: pulse 2.4s infinite; }
.dot.offline { background: #ff3b30; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(52,199,89,.5); } 50% { box-shadow: 0 0 0 4px rgba(52,199,89,0); } }

/* -------------------------------- Main ---------------------------------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 14px;
  flex-shrink: 0; position: relative; z-index: 6;
  background: color-mix(in srgb, var(--bg) 62%, transparent);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-brd);
  box-shadow: 0 1px 0 rgba(255,255,255,.02), 0 8px 24px -20px var(--fire-glow);
}
.topbar-title { font-weight: 700; font-size: 14.5px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-badge {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 2px;
  padding: 4px 11px 4px 9px; border-radius: 999px; border: 1px solid var(--glass-brd);
  background: var(--glass-2); font-size: 11px; font-weight: 600; color: var(--muted);
  font-family: var(--mono); letter-spacing: .02em;
}
.model-badge.online { border-color: rgba(61,220,132,.35); }
.model-badge.online .mb-dot { box-shadow: 0 0 10px var(--success); }
.model-badge .mb-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.model-badge.online .mb-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.model-badge.offline .mb-dot { background: #ff3b30; }
.spacer { flex: 1; }
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--radius-xs); color: var(--muted);
  display: grid; place-items: center; flex-shrink: 0;
  transition: background .12s, color .12s, transform .1s;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
/* The topbar toggle is the reliable way back to a collapsed sidebar. Show it
   whenever the sidebar is collapsed (any screen size); hide it only while the
   sidebar is already open on desktop, where the in-sidebar chevron collapses it. */
#menuBtn { display: grid; }
#sidebar:not(.collapsed) ~ #main #menuBtn { display: none; }

/* ------------------------------ Messages -------------------------------- */
.scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; overscroll-behavior: contain; }
.thread { max-width: var(--thread-max); margin: 0 auto; padding: 30px 26px 210px; }
.msg { display: flex; gap: 15px; margin-bottom: 30px; animation: msgIn .4s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; display: grid;
  place-items: center; font-size: 12px; font-weight: 700; margin-top: 1px;
}
.msg.user .avatar { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border-2); }
.msg.assistant .avatar { background: transparent; filter: drop-shadow(0 2px 8px var(--fire-glow)); }
.msg.assistant .avatar svg { width: 30px; height: 30px; }
.bubble { min-width: 0; flex: 1; }
.role {
  font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 5px;
  display: flex; align-items: center; gap: 6px; letter-spacing: -.01em;
}
.msg.assistant .role { color: var(--fire-2); }
.msg-actions { display: flex; gap: 2px; margin-left: auto; opacity: 0; transition: opacity .14s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  width: 28px; height: 28px; border-radius: 7px; color: var(--dim);
  display: grid; place-items: center; font-size: 13px; transition: background .12s, color .12s;
}
.msg-action:hover { background: var(--surface-hover); color: var(--text); }
.msg-action.copied { color: var(--success); }

/* User turns get a soft card so the conversation reads clearly turn-by-turn;
   assistant turns stay flush like a document for long-form answers. */
.msg.user .content {
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-2);
  border-radius: 6px 16px 16px 16px; padding: 12px 16px; width: fit-content; max-width: 100%;
  box-shadow: var(--shadow-sm);
}
.content { color: var(--text); overflow-wrap: anywhere; line-height: 1.72; font-size: 15px; }
.content p { margin: 0 0 15px; }
.content > *:last-child, .answer > *:last-child { margin-bottom: 0; }
.content h1, .content h2, .content h3, .content h4, .content h5, .content h6 { margin: 24px 0 11px; line-height: 1.32; font-weight: 700; letter-spacing: -.02em; }
.content h1 { font-size: 1.38em; }
.content h2 { font-size: 1.22em; }
.content h3 { font-size: 1.08em; }
.content h4 { font-size: 1em; }
.content h5 { font-size: .92em; color: var(--muted); }
.content h6 { font-size: .86em; color: var(--dim); text-transform: uppercase; letter-spacing: .04em; }
.content h1:first-child, .content h2:first-child, .content h3:first-child,
.content h4:first-child, .content h5:first-child, .content h6:first-child { margin-top: 2px; }
.content ul, .content ol { margin: 0 0 15px; padding-inline-start: 26px; }
.content li { margin: 5px 0; padding-inline-start: 3px; }
.content li::marker { color: var(--fire-2); }
/* Nested lists hug their parent item and vary marker style by depth so
   hierarchy reads at a glance. */
.content li > ul, .content li > ol { margin: 4px 0 2px; }
.content ol ol { list-style-type: lower-alpha; }
.content ol ol ol { list-style-type: lower-roman; }
/* GitHub task-list item: a custom checkbox (native disabled checkboxes render
   inconsistently across browsers). Completed items dim + strike through. */
.content li.task-item { list-style: none; margin-inline-start: -22px; padding-inline-start: 0; display: flex; align-items: flex-start; gap: 9px; }
.content li.task-item .task-check {
  width: 17px; height: 17px; margin-top: 2px; flex-shrink: 0; border-radius: 5px;
  border: 1.5px solid var(--border-3); background: var(--surface); position: relative;
  transition: background .15s, border-color .15s;
}
.content li.task-item .task-check.on { background: var(--grad-fire); border-color: transparent; }
.content li.task-item .task-check.on::after {
  content: ""; position: absolute; inset: 0;
  background: no-repeat center/10px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 7.5l3 3 5-6' stroke='%23180a02' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.content li.task-item .task-text { flex: 1; min-width: 0; }
.content li.task-item .task-check.on ~ .task-text { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border-3); }
.content a { color: var(--fire-2); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--fire-line); }
.content a:hover { text-decoration-color: var(--fire-2); }
.content strong { font-weight: 700; }
.content code.inline {
  background: var(--fire-soft); padding: 2px 7px; border-radius: 6px; font-family: var(--mono);
  font-size: .86em; color: var(--fire-2); border: 1px solid var(--fire-line);
}
.content blockquote {
  margin: 0 0 14px; padding: 6px 16px;
  border-left: 3px solid var(--fire-line); color: var(--muted); background: var(--fire-soft);
  border-radius: 0 8px 8px 0;
}
.content table { border-collapse: collapse; margin: 0 0 14px; font-size: .92em; display: block; overflow-x: auto; }
.content th, .content td { border: 1px solid var(--border-2); padding: 8px 12px; text-align: start; }
.content th { background: var(--surface-2); font-weight: 700; }
/* Column alignment from a table's :---: separator row. */
.content th.ta-left, .content td.ta-left { text-align: left; }
.content th.ta-center, .content td.ta-center { text-align: center; }
.content th.ta-right, .content td.ta-right { text-align: right; }
.content hr { border: none; border-top: 1px solid var(--border-2); margin: 22px 0; }

/* ----------------------------- Code blocks ------------------------------ */
.codewrap {
  position: relative; margin: 0 0 18px; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border); box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.04);
}
.codewrap-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--code-head); padding: 10px 14px; font-size: 12px;
  color: var(--fire-3); font-family: var(--mono); font-weight: 500; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.codewrap-head .cw-lang { position: relative; padding-left: 15px; }
.codewrap-head .cw-lang::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 7px; height: 7px; border-radius: 50%; background: var(--grad-fire);
  box-shadow: 0 0 8px var(--fire-glow);
}
.copy-btn {
  color: #9d938a; font-size: 12px; padding: 4px 9px; border-radius: 6px; font-family: var(--mono);
  display: flex; align-items: center; gap: 5px; transition: background .12s, color .12s;
}
.copy-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.copy-btn.copied { color: var(--success); }
.codewrap pre { background: var(--code-bg); padding: 15px 16px; overflow-x: auto; margin: 0; }
.codewrap pre code { font-family: var(--mono); font-size: 13px; color: var(--code-text); background: none; line-height: 1.62; }

/* ------------------------------ Thinking -------------------------------- */
.think {
  margin: 0 0 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 65%, transparent); overflow: hidden;
  transition: border-color .16s;
}
.think:hover { border-color: var(--border-2); }
.think summary {
  cursor: pointer; padding: 10px 14px; font-size: 12.5px; color: var(--dim); font-weight: 600;
  list-style: none; display: flex; align-items: center; gap: 8px; user-select: none;
  letter-spacing: .015em; transition: color .12s;
}
.think summary:hover { color: var(--muted); }
.think summary::-webkit-details-marker { display: none; }
.think summary .chev { transition: transform .2s var(--ease); display: inline-flex; color: var(--fire-2); }
.think[open] summary .chev { transform: rotate(90deg); }
.think .think-body {
  padding: 2px 16px 13px 36px; font-size: 13px; color: var(--muted);
  white-space: pre-wrap; line-height: 1.72;
}
.cursor {
  display: inline-block; width: 8px; height: 1.05em; background: var(--fire);
  vertical-align: -2px; margin-left: 2px; border-radius: 1px;
  animation: blink 1s steps(1) infinite; box-shadow: 0 0 8px var(--fire-glow);
}
@keyframes blink { 0%,50% { opacity: 1; } 50.01%,100% { opacity: 0; } }
.thinking-dots { display: inline-flex; gap: 5px; align-items: center; padding: 5px 0; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--fire-2);
  animation: dotPulse 1.3s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .18s; }
.thinking-dots span:nth-child(3) { animation-delay: .36s; }
@keyframes dotPulse { 0%,80%,100% { opacity: .3; transform: scale(.7); } 40% { opacity: 1; transform: scale(1); } }

/* Labelled loading "marquee" — shown while a server-side tool runs (web search,
   image generation, …) or while a long answer is being finished. */
.loading-status { display: inline-flex; align-items: center; gap: 9px; padding: 4px 0; font-size: 14px; }
.loading-status .ls-orb {
  width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--fire-line); border-top-color: var(--fire);
  box-shadow: 0 0 10px var(--fire-glow); animation: lsSpin .8s linear infinite;
}
.loading-status .ls-label {
  font-weight: 500; letter-spacing: -.01em;
  background: linear-gradient(100deg, var(--muted) 28%, var(--text) 50%, var(--muted) 72%);
  background-size: 220% 100%; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: lsShimmer 1.9s linear infinite;
}
.loading-status .ls-label::after { content: "…"; }
@keyframes lsSpin { to { transform: rotate(360deg); } }
@keyframes lsShimmer { to { background-position: -220% 0; } }
@media (prefers-reduced-motion: reduce) {
  .loading-status .ls-orb { animation: none; }
  .loading-status .ls-label { animation: none; -webkit-text-fill-color: var(--muted); color: var(--muted); }
}

/* ---------------------------- Error card -------------------------------- */
.error-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px;
  border-radius: var(--radius-sm); border: 1px solid rgba(240,80,58,.35);
  background: rgba(240,80,58,.08);
}
.error-ico { color: var(--danger); flex-shrink: 0; margin-top: 1px; display: inline-flex; }
.error-main { min-width: 0; }
.error-title { font-weight: 700; font-size: 14px; color: var(--text); margin-bottom: 3px; }
.error-text { color: var(--muted); font-size: 13.5px; margin-bottom: 13px; }
.error-retry {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 15px;
  border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600;
  transition: border-color .12s, background .12s, transform .1s;
}
.error-retry:hover { border-color: var(--fire-line); background: var(--surface-hover); }
.error-retry:active { transform: scale(.97); }

/* --------------------------- Sidebar scrim ------------------------------ */
.sidebar-scrim { display: none; }

/* --------------- Stop button (pinned above the composer) ---------------- */
.stop-btn {
  display: none; width: fit-content; margin: 0 auto 12px; padding: 9px 18px;
  border-radius: 999px; border: 1px solid var(--glass-brd);
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  color: var(--muted); font-size: 13px; font-weight: 600; gap: 7px; align-items: center;
  transition: border-color .14s, color .14s, background .14s, box-shadow .2s; box-shadow: var(--shadow-md);
  pointer-events: auto;
}
.stop-btn.visible { display: flex; }
.stop-btn:hover { background: var(--surface-hover); border-color: var(--fire-line); color: var(--text); }
.stop-btn svg { color: var(--fire); }

/* ------------------------------- Welcome -------------------------------- */
.welcome { text-align: center; padding: clamp(48px, 16vh, 120px) 20px 30px; animation: welcomeIn .6s var(--ease); }
@keyframes welcomeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.welcome .big-mark { width: 68px; height: 68px; margin: 0 auto 26px; display: grid; place-items: center; position: relative; animation: floatMark 6s ease-in-out infinite; }
@keyframes floatMark { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.welcome .big-mark::after {
  content: ""; position: absolute; inset: -34%; border-radius: 50%;
  background: radial-gradient(circle, var(--fire-glow), transparent 68%); filter: blur(16px); z-index: -1;
}
.welcome .big-mark svg { width: 68px; height: 68px; }
.welcome h1 {
  font-size: clamp(27px, 4.4vw, 36px); margin: 0 0 12px; font-weight: 800; letter-spacing: -.035em; line-height: 1.1;
  color: var(--text);
}
.welcome h1 .fire { color: var(--fire-2); }
.welcome p { color: var(--muted); margin: 0 0 20px; font-size: 15.5px; line-height: 1.6; }

/* Empty welcome state: no message exists yet, so the "act on the above" quick
   actions are meaningless (hidden), and the tall bottom reserve that keeps the
   last message clear of the composer isn't needed — shrink it so the welcome
   screen no longer needs to scroll. */
#main:has(.welcome) .quick-actions { display: none; }
#scroll:has(.welcome) .thread { padding-bottom: 110px; }

/* ------------------------------ Composer -------------------------------- */
.composer-wrap {
  position: absolute; bottom: 0; left: 0; right: 0; padding: 0 28px 22px;
  background: linear-gradient(to top, var(--bg) 52%, transparent);
  pointer-events: none; z-index: 5;
}
#composer {
  max-width: var(--thread-max); margin: 0 auto; position: relative;
  background: var(--glass);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd);
  border-radius: var(--radius); padding: 9px 12px 10px;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: auto; box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255,255,255,.05);
  transition: border-color .2s var(--ease), box-shadow .25s var(--ease), transform .2s var(--ease);
}
#composer:focus-within { border-color: var(--fire-line); box-shadow: var(--ring), var(--shadow-lg); transform: translateY(-1px); }
.composer-wrap.drag #composer { border-color: var(--fire-2); box-shadow: var(--shadow-lg), 0 0 0 3px var(--fire-soft); }
/* One row: send on the leading side, attach on the trailing side, input between.
   `order` + logical layout means this mirrors correctly in RTL automatically. */
.composer-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
#input {
  flex: 1; order: 1; background: none; border: none; outline: none; color: var(--text); resize: none;
  font-family: inherit; font-size: 15px; line-height: 1.55; max-height: 220px; padding: 8px 2px;
}
#input::placeholder { color: var(--dim); }
#send {
  order: 2; width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; position: relative; overflow: hidden;
  background: var(--grad-fire); color: #180a02; display: grid; place-items: center; align-self: flex-end;
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 8px 20px -8px var(--fire-glow);
  transition: transform .12s, box-shadow .16s, opacity .16s;
}
#send:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 12px 26px -8px var(--fire-glow); }
#send:active { transform: scale(.92); }
#send:disabled { opacity: .4; cursor: default; transform: none; box-shadow: none; }
.attach-btn {
  order: 0; width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0; align-self: flex-end;
  color: var(--dim); display: grid; place-items: center;
  transition: background .12s, color .12s, transform .1s;
}
.attach-btn:hover { background: var(--surface-hover); color: var(--fire-2); }
.attach-btn:active { transform: scale(.92); }

/* Attachment chips row (above the input) */
.attachments { display: none; flex-wrap: wrap; gap: 7px; padding: 2px 2px 0; }
.attachments.has-files { display: flex; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 240px;
  padding: 6px 8px 6px 10px; border-radius: 10px; border: 1px solid var(--border-2);
  background: var(--surface-2); font-size: 12px; color: var(--text);
}
.attach-chip .ac-ico { color: var(--fire-2); display: inline-flex; flex-shrink: 0; }
.attach-chip .ac-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.attach-chip .ac-size { color: var(--dim); font-size: 11px; flex-shrink: 0; }
.attach-chip .ac-x {
  width: 18px; height: 18px; border-radius: 5px; color: var(--dim); flex-shrink: 0;
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.attach-chip .ac-x:hover { background: var(--bg-3); color: var(--danger); }
/* Image attachment chips show a thumbnail instead of a file icon. */
.attach-chip.is-image { padding: 5px 8px 5px 5px; }
.attach-chip .ac-thumb {
  width: 30px; height: 30px; border-radius: 6px; object-fit: cover; flex-shrink: 0;
  border: 1px solid var(--border-2); display: block;
}

/* Images the user sent, shown inside their message bubble. */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.msg-images img {
  max-width: 260px; max-height: 260px; width: auto; height: auto;
  border-radius: 12px; border: 1px solid var(--border-2); object-fit: cover;
  box-shadow: var(--shadow-sm);
}
/* Model-generated images rendered inline from ![alt](url) in a reply. */
.gen-img {
  display: block; max-width: min(512px, 100%); height: auto; margin: 10px 0;
  border-radius: 12px; border: 1px solid var(--border-2);
  box-shadow: var(--shadow-sm); cursor: zoom-in;
  transition: transform .15s ease, box-shadow .15s ease;
}
.gen-img:hover { transform: translateY(-1px); box-shadow: var(--shadow-md, 0 8px 24px rgba(0,0,0,.28)); }

/* Full-screen lightbox for a generated image (click to open). */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column;
  background: rgba(8, 10, 14, .82); backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .16s ease;
}
.lightbox.show { opacity: 1; }
.lb-bar {
  display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  padding: 14px 18px; flex: 0 0 auto;
}
.lb-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 10px; cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 600;
  color: #fff; background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .18);
  transition: background .14s ease, transform .14s ease;
}
.lb-btn:hover { background: rgba(255, 255, 255, .22); }
.lb-btn:active { transform: scale(.96); }
.lb-close { padding: 8px; }
.lb-stage {
  flex: 1 1 auto; display: flex; align-items: center; justify-content: center;
  padding: 0 18px 24px; min-height: 0; cursor: zoom-out;
}
.lb-stage img {
  max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5); cursor: default;
}
.composer-hint {
  max-width: var(--thread-max); margin: 11px auto 0; text-align: center;
  font-size: 11.5px; color: var(--dim); pointer-events: auto;
}
.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-2);
  background: var(--surface); font-family: var(--mono); font-size: 11px; color: var(--muted);
}

/* --------------------------- Scroll-to-bottom --------------------------- */
.scroll-bottom {
  position: absolute; bottom: 132px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--glass-brd);
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  color: var(--muted); display: none; place-items: center;
  box-shadow: var(--shadow-md); z-index: 6; transition: border-color .16s, color .16s, transform .16s, box-shadow .2s;
  pointer-events: auto;
}
.scroll-bottom.visible { display: grid; }
.scroll-bottom:hover { border-color: var(--fire-line); color: var(--text); transform: translateX(-50%) translateY(-2px); }

/* -------------------------------- Toasts -------------------------------- */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 130;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
[dir="rtl"] .toast-container { right: auto; left: 24px; }
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); color: var(--text); font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); pointer-events: auto;
  animation: toastIn .25s var(--ease), toastOut .25s ease 2.5s forwards;
}
.toast.success { border-color: rgba(52,199,89,.5); }
.toast.error { border-color: rgba(240,80,58,.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }

/* --------------------------- Overlay + dialog --------------------------- */
.overlay {
  display: none; position: fixed; inset: 0; background: rgba(4,4,7,.64); z-index: 90;
  backdrop-filter: blur(10px) saturate(120%); -webkit-backdrop-filter: blur(10px) saturate(120%);
}
.overlay.visible { display: flex; align-items: center; justify-content: center; animation: fadeIn .18s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: var(--radius);
  padding: 26px; max-width: 400px; width: 90%; box-shadow: var(--shadow-lg);
  animation: dialogIn .24s var(--ease-spring);
}
@keyframes dialogIn { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
.dialog h3 { margin: 0 0 8px; font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.dialog p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.dialog-input {
  width: 100%; margin: 0 0 20px; padding: 10px 13px; border-radius: var(--radius-xs);
  border: 1px solid var(--border-2); background: var(--bg-3); color: var(--text);
  font-family: var(--font); font-size: 14px; outline: none; transition: border-color .14s, box-shadow .14s;
}
.dialog-input:focus { border-color: var(--fire-line); box-shadow: 0 0 0 3px var(--fire-soft); }
.dialog-btns { display: flex; gap: 10px; justify-content: flex-end; }
.dialog-btns button {
  padding: 9px 18px; border-radius: var(--radius-xs); border: 1px solid var(--border-2);
  font-size: 13.5px; font-weight: 600; transition: background .12s, opacity .12s, transform .1s;
}
.dialog-btns button:active { transform: scale(.97); }
.dialog-btns .btn-cancel { background: var(--surface); color: var(--text); }
.dialog-btns .btn-cancel:hover { background: var(--surface-hover); }
.dialog-btns .btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.dialog-btns .btn-danger:hover { opacity: .9; }
.dialog-btns .btn-confirm { background: var(--grad-fire); color: #180a02; border-color: transparent; }
.dialog-btns .btn-confirm:hover { opacity: .92; }

/* ------------------------------ Scrollbar ------------------------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-3); }

/* -------------------------------- Mobile -------------------------------- */
@media (max-width: 760px) {
  #sidebar { position: absolute; z-index: 30; height: 100%; box-shadow: var(--shadow-lg); }
  #sidebar.collapsed { margin-left: calc(-1 * var(--sidebar-w)); }
  /* Tap-anywhere-to-close backdrop while the sidebar is open over the chat. */
  #sidebar:not(.collapsed) ~ .sidebar-scrim {
    display: block; position: fixed; inset: 0; z-index: 25;
    background: rgba(6,5,4,.5); backdrop-filter: blur(2px); animation: fadeIn .2s ease;
  }
  .thread { padding: 22px 16px 168px; }
  .composer-wrap { padding: 0 16px 16px; }
  .welcome { padding: 44px 16px 20px; }
}
@media (max-width: 600px) { .model-badge { display: none; } }

/* --------------------------- Syntax highlight --------------------------- */
.hl-k { color: #ff9a4d; }
.hl-s { color: #9ece6a; }
.hl-c { color: #6b625a; font-style: italic; }
.hl-n { color: var(--fire-3); }
.hl-f { color: #ffd9a8; }
.cw-lang { color: var(--fire-3); font-family: var(--mono); }
.copy-btn span { line-height: 1; }

/* ------------------------------- Tables --------------------------------- */
.tablewrap { overflow-x: auto; margin: 0 0 15px; border-radius: 10px; border: 1px solid var(--border-2); width: fit-content; max-width: 100%; }
.tablewrap table { border-collapse: collapse; font-size: .92em; margin: 0; }
.tablewrap th, .tablewrap td { border: 1px solid var(--border-2); padding: 8px 13px; text-align: start; }
.tablewrap th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.tablewrap tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface) 55%, transparent); }

/* --------------------------- Sidebar tools ------------------------------ */
.sidebar-tools { padding: 6px 8px; border-top: 1px solid var(--border); }
.sidebar-tool {
  width: 100%; display: flex; align-items: center; gap: 11px; padding: 9px 13px;
  border-radius: 10px; color: var(--muted); font-size: 13.5px; font-weight: 500;
  transition: background .14s, color .14s;
}
.sidebar-tool:hover { background: var(--surface); color: var(--text); }
.sidebar-tool svg { flex-shrink: 0; }

/* --------------------------- Settings dialog ---------------------------- */
.settings-overlay { z-index: 100; }
#overlay { z-index: 115; }
.settings-dialog {
  width: min(760px, 94vw); max-height: min(88vh, 760px);
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
  animation: dialogIn .24s var(--ease-spring);
}
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 17px 22px; border-bottom: 1px solid var(--border); }
.settings-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -.01em; }
.settings-close { width: 32px; height: 32px; border-radius: 8px; color: var(--muted); display: grid; place-items: center; transition: background .12s, color .12s; }
.settings-close:hover { background: var(--surface-hover); color: var(--text); }
.settings-body { display: flex; min-height: 0; flex: 1; }
.settings-tabs {
  flex-shrink: 0; width: 176px; border-right: 1px solid var(--border);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
}
.settings-tab {
  text-align: start; padding: 9px 13px; border-radius: 9px; color: var(--muted);
  font-size: 13.5px; font-weight: 500; transition: background .12s, color .12s;
}
.settings-tab:hover { background: var(--surface); color: var(--text); }
.settings-tab.active { background: var(--fire-soft); color: var(--fire-2); font-weight: 600; }
.settings-panels { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 26px; }
.settings-panel { display: flex; flex-direction: column; gap: 20px; }

.set-section-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--dim); font-weight: 700; }
.set-section-title:not(:first-child) { margin-top: 6px; }
.set-field { display: flex; flex-direction: column; gap: 7px; }
.set-label { font-size: 14px; font-weight: 600; color: var(--text); }
.set-help { font-size: 12.5px; color: var(--dim); line-height: 1.5; }
.set-note { font-size: 12.5px; color: var(--muted); background: var(--fire-soft); border: 1px solid var(--fire-line); border-radius: 10px; padding: 10px 13px; line-height: 1.55; }
.set-input, .set-select {
  width: 100%; padding: 10px 13px; border-radius: 10px; border: 1px solid var(--border-2);
  background: var(--bg-3); color: var(--text); font-family: inherit; font-size: 14px; outline: none;
  transition: border-color .14s, box-shadow .14s;
}
.set-select { cursor: pointer; }
.set-input:focus, .set-select:focus { border-color: var(--fire-line); box-shadow: 0 0 0 3px var(--fire-soft); }
.set-textarea { resize: vertical; min-height: 68px; line-height: 1.55; }

.set-toggle-row, .set-action-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.set-toggle-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.switch { width: 44px; height: 26px; border-radius: 999px; background: var(--border-3); position: relative; flex-shrink: 0; transition: background .18s; }
.switch .knob { position: absolute; top: 3px; inset-inline-start: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .18s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.switch.on { background: var(--grad-fire); }
.switch.on .knob { transform: translateX(18px); }

.set-btn { padding: 9px 17px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; flex-shrink: 0; transition: background .12s, border-color .12s; }
.set-btn:hover { background: var(--surface-hover); border-color: var(--fire-line); }
.set-btn.danger { color: var(--danger); border-color: rgba(240,80,58,.4); }
.set-btn.danger:hover { background: rgba(240,80,58,.1); border-color: var(--danger); }

/* Usage */
.usage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.usage-stat { padding: 16px 18px; border: 1px solid var(--border-2); border-radius: 13px; background: var(--surface); }
.us-n { font-size: 25px; font-weight: 800; letter-spacing: -.02em; line-height: 1; color: var(--text); }
.us-l { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.usage-chart-wrap { display: flex; flex-direction: column; gap: 12px; }
.usage-chart { display: flex; align-items: flex-end; gap: 5px; height: 96px; }
.uc-bar { flex: 1; height: var(--h); min-height: 3px; border-radius: 4px 4px 2px 2px; background: var(--grad-fire); opacity: .85; transition: opacity .15s, transform .15s; }
.uc-bar.empty { background: var(--border-2); opacity: 1; }
.uc-bar:hover { opacity: 1; transform: scaleY(1.03); }
.usage-since { text-align: center; }

/* About */
.about-panel { align-items: center; text-align: center; gap: 7px; padding: 8px 0 4px; }
.about-mark { filter: drop-shadow(0 3px 12px var(--fire-glow)); }
.about-name { font-size: 21px; font-weight: 700; margin-top: 8px; }
.about-name b { color: var(--text); }
.about-tag { color: var(--muted); font-size: 14px; }
.about-built { color: var(--dim); font-size: 13px; }
.about-links { display: flex; flex-wrap: wrap; gap: 8px 18px; justify-content: center; margin-top: 14px; }
.about-links a { color: var(--fire-2); font-size: 13.5px; }

/* Welcome — a touch more breathing room now that the cards are gone. */
.welcome { max-width: 620px; margin: 0 auto; }
.welcome h1 { font-size: clamp(26px, 4.4vw, 34px); }
.welcome p { max-width: 46ch; margin-left: auto; margin-right: auto; }
.welcome .change-name {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 4px;
  font-size: 12.5px; color: var(--dim); cursor: pointer;
  transition: color .15s; background: none; border: none; font-family: inherit;
}
.welcome .change-name:hover { color: var(--fire-2); }

/* ------------------------------ RTL (Arabic) ---------------------------- */
:root[lang="ar"] body { font-family: var(--font-ar); letter-spacing: 0; }
[dir="rtl"] .sidebar-search input { padding: 9px 33px 9px 12px; }
[dir="rtl"] .sidebar-search svg { left: auto; right: 11px; }
[dir="rtl"] .hist-item::before { left: auto; right: 3px; }
[dir="rtl"] .hist-item { padding: 9px 13px 9px 10px; }
[dir="rtl"] .msg-actions { margin-left: 0; margin-right: auto; }
[dir="rtl"] .think .think-body { padding: 4px 38px 14px 16px; }
[dir="rtl"] .msg.user .content { border-radius: 14px 4px 14px 14px; }
[dir="rtl"] .settings-tabs { border-right: none; border-left: 1px solid var(--border); }
[dir="rtl"] .switch.on .knob { transform: translateX(-18px); }
[dir="rtl"] .composer-hint { direction: rtl; }

@media (max-width: 620px) {
  .settings-body { flex-direction: column; }
  .settings-tabs { width: auto; flex-direction: row; border-right: none; border-bottom: 1px solid var(--border); overflow-x: auto; padding: 10px; }
  [dir="rtl"] .settings-tabs { border-left: none; border-bottom: 1px solid var(--border); }
  .settings-tab { white-space: nowrap; }
  .settings-panels { padding: 20px 18px; }
  .settings-dialog { max-height: 92vh; width: 96vw; }
}

/* ----------------------------- Onboarding ------------------------------ */
.onboard-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4, 4, 7, .72);
  backdrop-filter: blur(14px) saturate(120%); -webkit-backdrop-filter: blur(14px) saturate(120%);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .3s ease;
}
.onboard-card {
  width: min(480px, 92vw);
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 40px 36px 36px;
  text-align: center;
  animation: dialogIn .35s var(--ease-spring);
}
.onboard-mark {
  width: 64px; height: 64px; margin: 0 auto 22px; display: grid; place-items: center;
  position: relative; animation: floatMark 6s ease-in-out infinite;
}
@keyframes floatMark { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.onboard-mark::after {
  content: ""; position: absolute; inset: -34%; border-radius: 50%;
  background: radial-gradient(circle, var(--fire-glow), transparent 68%); filter: blur(16px); z-index: -1;
}
.onboard-mark svg { width: 64px; height: 64px; }
.onboard-card h2 {
  font-size: 24px; font-weight: 800; letter-spacing: -.03em; margin: 0 0 8px;
  color: var(--text);
}
.onboard-card h2 .fire { color: var(--fire-2); }
.onboard-sub { color: var(--muted); font-size: 15px; margin: 0 0 28px; line-height: 1.6; }
.onboard-input {
  width: 100%; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-2); background: var(--bg-3); color: var(--text);
  font-family: var(--font); font-size: 16px; outline: none;
  transition: border-color .16s, box-shadow .16s;
  text-align: center;
}
.onboard-input::placeholder { color: var(--dim); }
.onboard-input:focus { border-color: var(--fire-line); box-shadow: 0 0 0 3px var(--fire-soft); }
.onboard-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }
.onboard-btn {
  padding: 12px 28px; border-radius: 999px; font-size: 14.5px; font-weight: 600;
  border: none; cursor: pointer; transition: transform .12s, box-shadow .16s, opacity .12s;
}
.onboard-btn.primary {
  background: var(--grad-fire); color: #180a02;
  box-shadow: 0 1px 0 rgba(255,255,255,.35) inset, 0 8px 20px -8px var(--fire-glow);
}
.onboard-btn.primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,.4) inset, 0 12px 26px -8px var(--fire-glow); }
.onboard-btn.primary:active { transform: scale(.97); }
.onboard-btn.primary:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.onboard-btn.secondary {
  background: var(--surface); color: var(--muted); border: 1px solid var(--border-2);
}
.onboard-btn.secondary:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-3); }
.onboard-hint { color: var(--dim); font-size: 12px; margin-top: 14px; }

/* ------------------------------ A11y / motion --------------------------- */
:focus-visible { outline: 2px solid var(--fire-2); outline-offset: 2px; border-radius: 6px; }
button:focus:not(:focus-visible) { outline: none; }
::selection { background: var(--fire); color: #180a02; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ==========================================================================
   NEXT-GEN WORKSPACE LAYER
   Three-column shell: conversation stays the spine; the right rail (Info /
   Artifacts / Sources / Task), in-thread task timeline, artifact system,
   command palette, slash menu and grouped history all orbit around it.
   Everything below is additive and token-driven — dark/light/RTL aware.
   ========================================================================== */
:root { --ctx-w: 372px; --ctx-w-focus: min(64vw, 960px); }

/* ----------------------------- Context panel ---------------------------- */
/* Kept at a fixed width and slid off-canvas with a negative margin so opening
   never reflows its contents (no per-frame text rewrap during the animation). */
#context {
  width: var(--ctx-w); margin-inline-end: calc(-1 * var(--ctx-w));
  display: flex; flex-direction: column; min-height: 0;
  background: var(--glass);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border-inline-start: 1px solid var(--glass-brd);
  transition: margin-inline-end .28s var(--ease), width .28s var(--ease);
}
body.ctx-open #context { margin-inline-end: 0; }
body.ctx-focus { --ctx-w: var(--ctx-w-focus); }
body.ctx-open .ctx-resizer {
  display: block; width: 7px; flex-shrink: 0; cursor: col-resize;
  position: relative; z-index: 16; margin-inline-end: -7px;
  transition: background .15s;
}
body.ctx-open .ctx-resizer::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 3px;
  width: 1px; background: var(--glass-brd); transition: background .15s, box-shadow .15s;
}
body.ctx-open .ctx-resizer:hover::before,
body.ctx-open .ctx-resizer.dragging::before { background: var(--fire-2); box-shadow: 0 0 0 1px var(--fire-line); }
body.ctx-resizing { cursor: col-resize; user-select: none; }
body.ctx-resizing #context { transition: none; }

.ctx-head {
  display: flex; align-items: center; gap: 6px; height: 56px; flex-shrink: 0;
  padding: 0 8px 0 12px; border-bottom: 1px solid var(--glass-brd);
}
.ctx-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.ctx-tabs::-webkit-scrollbar { display: none; }
.ctx-tab {
  padding: 7px 11px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  color: var(--dim); white-space: nowrap; position: relative;
  transition: background .12s, color .12s;
}
.ctx-tab:hover { background: var(--surface-hover); color: var(--text); }
.ctx-tab.active { color: var(--fire-2); background: var(--fire-soft); }
.ctx-tab .ctx-badge {
  display: none; margin-inline-start: 6px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--fire-soft); border: 1px solid var(--fire-line);
  color: var(--fire-2); font-size: 10px; font-weight: 700; line-height: 15px; text-align: center;
  vertical-align: middle;
}
.ctx-tab.has-count .ctx-badge { display: inline-block; }
.ctx-tab.running .ctx-badge {
  background: var(--fire); color: #180a02; border-color: transparent;
  animation: taskPulse 1.6s ease-in-out infinite;
}
@keyframes taskPulse { 0%,100% { box-shadow: 0 0 0 0 var(--fire-glow); } 50% { box-shadow: 0 0 0 4px transparent; } }
.ctx-head-actions { display: flex; gap: 2px; flex-shrink: 0; }
.ctx-icon {
  width: 30px; height: 30px; border-radius: 8px; color: var(--dim);
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.ctx-icon:hover { background: var(--surface-hover); color: var(--text); }
#ctxFocusBtn { display: none; }
body.ctx-can-focus #ctxFocusBtn { display: grid; }
body.ctx-focus #ctxFocusBtn { color: var(--fire-2); background: var(--fire-soft); }

.ctx-body { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; }
.ctx-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; text-align: center; min-height: 62%; color: var(--dim); padding: 24px 18px;
}
.ctx-empty .ce-ico { color: var(--border-3); opacity: .9; }
.ctx-empty .ce-title { font-size: 14px; font-weight: 600; color: var(--muted); }
.ctx-empty .ce-sub { font-size: 12.5px; line-height: 1.5; max-width: 30ch; }

.ctx-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--dim); font-weight: 700; margin: 4px 2px 10px;
}
.ctx-section-title:not(:first-child) { margin-top: 22px; }

/* Info mode: labelled rows */
.info-rows { display: flex; flex-direction: column; gap: 2px; }
.info-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 11px 12px; border-radius: 11px; background: var(--glass-2);
  border: 1px solid transparent; transition: border-color .14s, background .14s;
}
.info-row + .info-row { margin-top: 6px; }
.info-row:hover { border-color: var(--border-2); }
.info-k { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.info-k svg { color: var(--dim); flex-shrink: 0; }
.info-v { font-size: 12.5px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; text-align: end; }
.info-v.mono { font-family: var(--mono); font-size: 11.5px; }
.info-v .dot-online { color: var(--success); }
.info-actions { display: flex; flex-direction: column; gap: 7px; margin-top: 6px; }
.info-act {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px; width: 100%;
  border-radius: 11px; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600; text-align: start;
  transition: background .12s, border-color .12s, transform .1s;
}
.info-act svg { color: var(--fire-2); flex-shrink: 0; }
.info-act:hover { background: var(--surface-hover); border-color: var(--fire-line); }
.info-act:active { transform: scale(.99); }
.info-act.danger svg { color: var(--danger); }
.info-act.danger:hover { border-color: rgba(240,80,58,.5); background: rgba(240,80,58,.08); }

/* --------------------------- Artifact system ---------------------------- */
/* In-thread: a compact "Open" affordance folded into the code header so long
   outputs elevate into the panel without breaking chat flow. */
.cw-actions { display: flex; align-items: center; gap: 4px; }
.cw-open {
  color: #9d938a; font-size: 12px; padding: 4px 9px; border-radius: 6px; font-family: var(--mono);
  display: inline-flex; align-items: center; gap: 5px; transition: background .12s, color .12s;
}
.cw-open:hover { background: rgba(255,255,255,.08); color: #fff; }
:root[data-theme="light"] .cw-open:hover { background: rgba(255,255,255,.14); }

/* Panel: artifact list */
.artifact-list { display: flex; flex-direction: column; gap: 9px; }
.artifact-card {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; cursor: pointer;
  border-radius: 13px; border: 1px solid var(--border-2); background: var(--surface);
  text-align: start; width: 100%; transition: border-color .15s, box-shadow .15s, transform .12s, background .15s;
}
.artifact-card:hover { border-color: var(--fire-line); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.artifact-card.active { border-color: var(--fire-2); background: var(--fire-soft); box-shadow: inset 0 0 0 1px var(--fire-line); }
.artifact-ico {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 10px; display: grid; place-items: center;
  background: var(--fire-soft); border: 1px solid var(--fire-line); color: var(--fire-2); overflow: hidden;
}
.artifact-ico img { width: 100%; height: 100%; object-fit: cover; }
.artifact-meta { min-width: 0; flex: 1; }
.artifact-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.artifact-sub { font-size: 11.5px; color: var(--dim); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.artifact-type {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 6px; border-radius: 5px; background: var(--bg-3); color: var(--muted);
}
.artifact-card .artifact-go { color: var(--dim); flex-shrink: 0; transition: color .12s, transform .12s; }
.artifact-card:hover .artifact-go { color: var(--fire-2); transform: translateX(2px); }
[dir="rtl"] .artifact-card:hover .artifact-go { transform: translateX(-2px); }

/* Panel: artifact viewer */
.artifact-viewer { display: flex; flex-direction: column; min-height: 0; height: 100%; margin: -16px; }
.av-top {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; flex-shrink: 0;
  border-bottom: 1px solid var(--border); min-width: 0;
}
.av-back {
  width: 28px; height: 28px; border-radius: 8px; color: var(--muted); flex-shrink: 0;
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.av-back:hover { background: var(--surface-hover); color: var(--text); }
.av-title { flex: 1; min-width: 0; font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.av-tools { display: flex; gap: 3px; flex-shrink: 0; }
.av-tool {
  width: 30px; height: 30px; border-radius: 8px; color: var(--dim);
  display: grid; place-items: center; transition: background .12s, color .12s;
}
.av-tool:hover { background: var(--surface-hover); color: var(--fire-2); }
.av-tool.copied { color: var(--success); }
.av-tabs {
  display: flex; gap: 2px; padding: 8px 10px 0; overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none; border-bottom: 1px solid var(--border);
}
.av-tabs::-webkit-scrollbar { display: none; }
.av-tab {
  padding: 7px 12px 9px; font-size: 12px; font-weight: 600; color: var(--dim);
  white-space: nowrap; border-bottom: 2px solid transparent; font-family: var(--mono);
  transition: color .12s, border-color .12s;
}
.av-tab:hover { color: var(--muted); }
.av-tab.active { color: var(--fire-2); border-bottom-color: var(--fire-2); }
.av-stage { flex: 1; min-height: 0; overflow: auto; background: var(--code-bg); }
.av-codewrap { display: flex; min-height: 100%; font-family: var(--mono); font-size: 12.5px; line-height: 1.6; }
.av-gutter {
  position: sticky; inset-inline-start: 0; flex-shrink: 0; padding: 14px 0; text-align: end;
  color: var(--dim); background: var(--code-bg); user-select: none;
  border-inline-end: 1px solid var(--border); min-width: 44px;
}
.av-gutter span { display: block; padding: 0 12px; opacity: .55; }
.av-pre { margin: 0; padding: 14px 16px; white-space: pre; color: var(--code-text); flex: 1; }
.av-pre code { font-family: var(--mono); background: none; }
.av-imgstage { display: grid; place-items: center; padding: 20px; min-height: 100%; background: var(--bg-2); }
.av-imgstage img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow-md); }
.av-doc { padding: 20px 22px; overflow-y: auto; }
.av-doc.content { font-size: 14px; }

/* ---------------------------- Task timeline ----------------------------- */
/* In-thread: a serious, legible progress block — not a spinner in a bubble. */
.task-block {
  margin: 0 0 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 62%, transparent); overflow: hidden;
}
.task-head {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px; cursor: pointer;
  user-select: none; list-style: none;
}
.task-head::-webkit-details-marker { display: none; }
.task-orb {
  width: 16px; height: 16px; flex-shrink: 0; border-radius: 50%;
  border: 2px solid var(--fire-line); border-top-color: var(--fire);
  box-shadow: 0 0 8px var(--fire-glow); animation: lsSpin .8s linear infinite;
}
.task-block.done .task-orb {
  border: none; background: var(--success); box-shadow: 0 0 8px rgba(61,220,132,.5); animation: none;
  position: relative;
}
.task-block.done .task-orb::after {
  content: ""; position: absolute; inset: 0; background:
    no-repeat center/9px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 14 14' fill='none'%3E%3Cpath d='M3 7.5l3 3 5-6' stroke='%23180a02' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.task-titles { flex: 1; min-width: 0; }
.task-title { font-size: 13px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.task-sub { font-size: 11.5px; color: var(--dim); margin-top: 1px; }
.task-elapsed { font-family: var(--mono); font-size: 11px; color: var(--dim); flex-shrink: 0; font-variant-numeric: tabular-nums; }
.task-chev { color: var(--dim); flex-shrink: 0; transition: transform .2s var(--ease); }
.task-block[open] .task-chev { transform: rotate(90deg); }
[dir="rtl"] .task-chev { transform: scaleX(-1); }
[dir="rtl"] .task-block[open] .task-chev { transform: scaleX(-1) rotate(90deg); }
.task-steps { padding: 2px 14px 12px; }
.task-step {
  display: flex; align-items: flex-start; gap: 11px; padding: 6px 0; position: relative;
  font-size: 12.5px; color: var(--muted);
}
.task-step::before {
  content: ""; position: absolute; inset-inline-start: 6.5px; top: 20px; bottom: -6px;
  width: 1.5px; background: var(--border-2);
}
.task-step:last-child::before { display: none; }
.ts-dot {
  width: 14px; height: 14px; flex-shrink: 0; border-radius: 50%; margin-top: 1px;
  border: 2px solid var(--border-3); background: var(--surface); position: relative; z-index: 1;
}
.task-step.running .ts-dot { border-color: var(--fire); box-shadow: 0 0 0 3px var(--fire-soft); }
.task-step.running .ts-dot::after {
  content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--fire);
  animation: dotPulse 1.3s ease-in-out infinite;
}
.task-step.done .ts-dot { border-color: var(--success); background: var(--success); }
.ts-label { flex: 1; min-width: 0; padding-top: .5px; }
.ts-label b { font-weight: 600; color: var(--text); }
/* Per-tool glyph before each step label — makes the timeline read like a real
   process log rather than identical dots. */
.ts-ico { display: inline-flex; vertical-align: -2px; margin-inline-end: 6px; color: var(--dim); }
.ts-ico svg { width: 13px; height: 13px; }
.task-step.running .ts-ico { color: var(--fire-2); }
.task-step.done .ts-ico { color: var(--muted); }
.ts-detail { display: block; color: var(--dim); font-size: 11.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-step.running .ts-label b {
  background: linear-gradient(100deg, var(--muted) 28%, var(--text) 50%, var(--muted) 72%);
  background-size: 220% 100%; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; animation: lsShimmer 1.9s linear infinite;
}
@media (prefers-reduced-motion: reduce) {
  .task-orb, .task-step.running .ts-dot::after { animation: none; }
  .task-step.running .ts-label b { animation: none; -webkit-text-fill-color: var(--text); }
}

/* Panel task mirror reuses .task-steps inside .ctx-body */
.task-panel-head { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }

/* ------------------------------- Sources -------------------------------- */
/* Under a message: a compact citation cluster. */
.msg-sources { margin: 2px 0 4px; display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.msg-sources .src-lead { font-size: 11.5px; color: var(--dim); font-weight: 600; margin-inline-end: 2px; }
.src-chip {
  display: inline-flex; align-items: center; gap: 7px; max-width: 260px;
  padding: 5px 10px 5px 8px; border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--surface); font-size: 12px; color: var(--text);
  transition: border-color .14s, background .14s, transform .1s;
}
.src-chip:hover { border-color: var(--fire-line); background: var(--surface-hover); transform: translateY(-1px); }
.src-chip .src-fav {
  width: 15px; height: 15px; flex-shrink: 0; border-radius: 4px; display: grid; place-items: center;
  background: var(--fire-soft); color: var(--fire-2); font-size: 9px; font-weight: 700;
}
.src-chip .src-t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.src-num {
  width: 17px; height: 17px; flex-shrink: 0; border-radius: 5px; font-size: 10px; font-weight: 700;
  display: grid; place-items: center; background: var(--fire-soft); border: 1px solid var(--fire-line); color: var(--fire-2);
}
/* Panel sources list */
.source-list { display: flex; flex-direction: column; gap: 8px; }
.source-item {
  display: flex; align-items: flex-start; gap: 11px; padding: 11px 12px; border-radius: 12px;
  border: 1px solid var(--border-2); background: var(--surface); transition: border-color .14s, background .14s, transform .1s;
}
.source-item:hover { border-color: var(--fire-line); background: var(--surface-hover); transform: translateY(-1px); }
.source-item .src-num { margin-top: 1px; }
.source-body { min-width: 0; flex: 1; }
.source-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.4; }
.source-url { font-size: 11.5px; color: var(--fire-2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: ltr; text-align: start; }
.source-kind { font-size: 10.5px; color: var(--dim); margin-top: 3px; text-transform: capitalize; }

/* --------------------------- Command palette ---------------------------- */
.cmdk-overlay {
  position: fixed; inset: 0; z-index: 140; background: rgba(4,4,7,.5);
  backdrop-filter: blur(8px) saturate(120%); -webkit-backdrop-filter: blur(8px) saturate(120%);
  align-items: flex-start; justify-content: center; padding: 12vh 16px 16px;
}
.cmdk-overlay.visible { display: flex; animation: fadeIn .14s ease; }
.cmdk {
  width: min(620px, 100%); max-height: 62vh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: 16px; box-shadow: var(--shadow-lg);
  animation: dialogIn .2s var(--ease-spring);
}
.cmdk-inputwrap { display: flex; align-items: center; gap: 10px; padding: 15px 16px; border-bottom: 1px solid var(--border); }
.cmdk-inputwrap svg { color: var(--dim); flex-shrink: 0; }
.cmdk-input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-family: inherit; font-size: 15.5px; }
.cmdk-input::placeholder { color: var(--dim); }
.cmdk-esc { flex-shrink: 0; }
.cmdk-list { overflow-y: auto; padding: 8px; }
.cmdk-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--dim); font-weight: 700; padding: 10px 10px 6px; }
.cmdk-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 11px; border-radius: 10px; cursor: pointer;
  color: var(--muted); font-size: 13.5px;
}
.cmdk-item .cmdk-ico { width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; display: grid; place-items: center; background: var(--glass-2); border: 1px solid var(--glass-brd); color: var(--fire-2); }
.cmdk-item .cmdk-label { flex: 1; min-width: 0; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmdk-item .cmdk-hint { font-family: var(--mono); font-size: 11px; color: var(--dim); flex-shrink: 0; }
.cmdk-item.active, .cmdk-item:hover { background: var(--fire-soft); color: var(--text); box-shadow: inset 0 0 0 1px var(--fire-line); }
.cmdk-empty { padding: 26px 12px; text-align: center; color: var(--dim); font-size: 13px; }

/* ------------------------------ Slash menu ------------------------------ */
.slash-menu {
  position: absolute; bottom: calc(100% + 10px); inset-inline-start: 0; right: 0; z-index: 8;
  max-width: var(--thread-max); margin: 0 auto; overflow: hidden;
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: 14px; box-shadow: var(--shadow-lg);
  pointer-events: auto; animation: dialogIn .16s var(--ease-spring);
}
.slash-menu.visible { display: block; }
.slash-item { display: flex; align-items: center; gap: 12px; padding: 10px 13px; cursor: pointer; color: var(--muted); }
.slash-item .slash-cmd { font-family: var(--mono); font-size: 12.5px; color: var(--fire-2); font-weight: 600; flex-shrink: 0; min-width: 82px; }
.slash-item .slash-desc { font-size: 12.5px; color: var(--muted); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slash-item.active, .slash-item:hover { background: var(--fire-soft); box-shadow: inset 0 0 0 1px var(--fire-line); }
.slash-item.active .slash-desc { color: var(--text); }

/* --------------------------- Shortcuts overlay -------------------------- */
.shortcuts-overlay {
  position: fixed; inset: 0; z-index: 120; background: rgba(4,4,7,.6);
  backdrop-filter: blur(10px) saturate(120%); -webkit-backdrop-filter: blur(10px) saturate(120%);
  align-items: center; justify-content: center; padding: 20px;
}
.shortcuts-overlay.visible { display: flex; animation: fadeIn .16s ease; }
.shortcuts-card {
  width: min(560px, 96vw); max-height: 86vh; overflow-y: auto; padding: 24px 26px;
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: dialogIn .22s var(--ease-spring);
}
.shortcuts-card h3 { font-size: 17px; font-weight: 700; margin-bottom: 4px; }
.shortcuts-card .sc-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.sc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 26px; }
.sc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.sc-row .sc-desc { font-size: 13px; color: var(--muted); }
.sc-keys { display: flex; gap: 4px; flex-shrink: 0; }

/* -------------------- Sidebar: grouped history + pin -------------------- */
.hist-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim);
  font-weight: 700; padding: 12px 12px 5px; display: flex; align-items: center; gap: 6px;
}
.hist-group-label:first-child { padding-top: 4px; }
.hist-group-label .hgl-ico { color: var(--fire-2); opacity: .8; display: inline-flex; }
.hist-item.pinned .hist-title::after {
  content: ""; display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--fire-2); margin-inline-start: 7px; vertical-align: middle;
}
.hist-action.pin.on { color: var(--fire-2); }
.hist-meta { font-size: 10.5px; color: var(--dim); margin-inline-start: 8px; flex-shrink: 0; font-variant-numeric: tabular-nums; opacity: .8; }
.hist-item:hover .hist-meta, .hist-item.active .hist-meta { display: none; }

/* ------------------------------ Jump back ------------------------------- */
.welcome .jump-back { max-width: 560px; margin: 26px auto 0; text-align: start; }
.jb-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); font-weight: 700; margin-bottom: 10px; text-align: center; }
.jb-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.jb-item {
  display: inline-flex; align-items: center; gap: 8px; max-width: 240px; padding: 9px 14px; border-radius: 11px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-size: 13px; cursor: pointer;
  transition: border-color .14s, background .14s, transform .12s;
}
.jb-item:hover { border-color: var(--fire-line); background: var(--surface-hover); transform: translateY(-1px); }
.jb-item svg { color: var(--dim); flex-shrink: 0; }
.jb-item .jb-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Topbar toggle active state */
#panelBtn.on, #cmdkBtn.on { color: var(--fire-2); background: var(--fire-soft); }

/* -------------------- Responsive: panel as overlay drawer --------------- */
@media (max-width: 1180px) {
  #context {
    position: fixed; inset-block: 0; inset-inline-end: 0; width: min(var(--ctx-w), 92vw);
    margin-inline-end: calc(-1 * min(var(--ctx-w), 92vw)); box-shadow: var(--shadow-lg); z-index: 40;
  }
  body.ctx-focus #context { width: min(92vw, 720px); }
  body.ctx-open #context { margin-inline-end: 0; }
  body.ctx-open .ctx-resizer { display: none; }
  body.ctx-open::after {
    content: ""; position: fixed; inset: 0; z-index: 38; background: rgba(6,5,4,.5);
    backdrop-filter: blur(2px); animation: fadeIn .2s ease;
  }
}
@media (max-width: 560px) {
  #context, body.ctx-focus #context { width: 100vw; margin-inline-end: -100vw; }
  .sc-grid { grid-template-columns: 1fr; }
  .cmdk-overlay { padding: 8vh 10px 10px; }
}

/* ---------------------- Inline file download card ----------------------- */
.file-card {
  display: inline-flex; align-items: center; gap: 11px; max-width: 340px;
  margin: 2px 0 8px; padding: 9px 12px; border-radius: 13px;
  border: 1px solid var(--border-2); background: var(--surface); cursor: pointer;
  vertical-align: middle; text-align: start;
  transition: border-color .14s, background .14s, transform .1s, box-shadow .18s;
}
.file-card:hover { border-color: var(--fire-line); background: var(--surface-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.file-card:active { transform: scale(.99); }
.file-card .fc-ico {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; display: grid; place-items: center;
  background: var(--fire-soft); border: 1px solid var(--fire-line); color: var(--fire-2);
}
.file-card .fc-meta { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.file-card .fc-name { font-size: 13.5px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-sub { font-size: 11.5px; color: var(--dim); font-family: var(--mono); letter-spacing: .01em; }
.file-card .fc-dl { margin-inline-start: auto; color: var(--dim); flex-shrink: 0; transition: color .12s, transform .15s; }
.file-card:hover .fc-dl { color: var(--fire-2); transform: translateY(1px); }

/* --------------------------------- RTL ---------------------------------- */
[dir="rtl"] .source-url, [dir="rtl"] .av-pre, [dir="rtl"] .av-gutter { text-align: start; }
[dir="rtl"] .cmdk-input, [dir="rtl"] .slash-item .slash-cmd { text-align: right; }

/* Panel-button activity dot (something new is waiting while the panel is shut) */
#panelBtn { position: relative; }
#panelBtn.has-activity::after {
  content: ""; position: absolute; top: 5px; inset-inline-end: 5px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--fire);
  box-shadow: 0 0 6px var(--fire-glow);
}

/* ===================== Quick actions bar ===================== */
/* Calm, editorial ghost buttons — subtle until hover, no candy pills. Only
   shown once a conversation exists (hidden on the empty screen via
   body.chat-empty), since they act on "the above". */
.quick-actions {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 2px 2px 0;
  max-width: var(--thread-max); margin: 0 auto; pointer-events: auto;
}
.qa-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--dim); font-size: 12px; font-weight: 500; white-space: nowrap;
  transition: color .14s, background .14s, border-color .14s;
}
.qa-btn:hover { color: var(--text); background: var(--surface); border-color: var(--border); }
.qa-btn:active { background: var(--surface-2); }
.qa-btn svg { flex-shrink: 0; opacity: .65; transition: opacity .14s; }
.qa-btn:hover svg { opacity: 1; }
body.chat-empty .quick-actions { display: none; }

/* ===================== ENHANCED: Message stagger ===================== */
.msg.stagger-1 { animation-delay: .05s; }
.msg.stagger-2 { animation-delay: .1s; }
.msg.stagger-3 { animation-delay: .15s; }

/* ===================== ENHANCED: Image generation result ===================== */
.gen-image-wrap {
  margin: 8px 0 14px; border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--border-2); background: var(--surface);
  display: inline-flex; flex-direction: column; max-width: 512px;
}
.gen-image-wrap img { display: block; max-width: 100%; height: auto; }
.gen-image-wrap .gen-meta {
  padding: 8px 12px; font-size: 12px; color: var(--dim); display: flex;
  align-items: center; gap: 8px; border-top: 1px solid var(--border);
}
.gen-image-wrap .gen-meta .gen-dl { margin-inline-start: auto; color: var(--fire-2); font-weight: 600; cursor: pointer; }
.gen-image-wrap .gen-meta .gen-dl:hover { text-decoration: underline; }

/* ===================== ENHANCED: Mobile composer ===================== */
@media (max-width: 560px) {
  .composer-wrap { padding: 0 12px 14px; }
  #composer { border-radius: 16px; padding: 8px 10px 9px; }
  #send { width: 34px; height: 34px; border-radius: 10px; }
  .attach-btn { width: 34px; height: 34px; }
  .thread { padding: 20px 14px 180px; }
  .msg { gap: 10px; margin-bottom: 22px; }
  .avatar { width: 26px; height: 26px; border-radius: 8px; }
  .msg.assistant .avatar svg { width: 26px; height: 26px; }
  .welcome h1 { font-size: 24px; }
  .quick-actions { gap: 4px; }
  .qa-btn { padding: 4px 10px; font-size: 11px; }
  #topbar { height: 50px; padding: 0 10px; }
  .topbar-title { font-size: 13.5px; }
  .model-badge { font-size: 10px; padding: 3px 8px 3px 7px; }
  .sidebar-header { padding: 12px 14px 11px; }
  .new-chat { margin: 4px 10px 8px; padding: 10px 12px; font-size: 13px; }
}

/* ===================== ENHANCED: Better hover micro-interactions ===================== */
.msg.user .content { transition: box-shadow .2s, border-color .2s; }
.msg.user .content:hover { box-shadow: var(--shadow-md); border-color: var(--fire-line); }
.codewrap { transition: border-color .16s, box-shadow .2s; }
.codewrap:hover { border-color: var(--border-2); box-shadow: var(--shadow-md); }
.codewrap .copy-btn { transition: background .12s, color .12s, transform .1s; }
.codewrap:hover .copy-btn { color: var(--muted); }
.codewrap .copy-btn:hover { background: rgba(255,255,255,.1); color: var(--text); transform: scale(1.05); }

/* ===================== ENHANCED: Smooth scroll anchor ===================== */
html { scroll-behavior: smooth; }

/* ===================== ENHANCED: Toast notifications ===================== */
.toast-container { position: fixed; bottom: 100px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 16px; border-radius: 12px; font-size: 13px; font-weight: 600;
  background: var(--glass); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-brd); box-shadow: var(--shadow-md);
  animation: toastIn .25s var(--ease-spring); color: var(--text);
  max-width: 320px;
}
.toast.success { border-color: rgba(61,220,132,.35); }
.toast.error { border-color: rgba(255,90,82,.35); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.95); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-8px) scale(.95); } }

/* ===================== ENHANCED: Focus ring polish ===================== */
:focus-visible { outline: 2px solid var(--fire-2); outline-offset: 2px; border-radius: 6px; }
button:focus-visible { outline-offset: 2px; }
#input:focus-visible { outline: none; }

/* ===================== ENHANCED: Print styles ===================== */
@media print {
  #sidebar, #context, .composer-wrap, #topbar, .scroll-bottom, .toast-container { display: none !important; }
  #main { width: 100%; }
  .thread { padding: 20px; max-width: none; }
  body { background: #fff; color: #000; }
  .msg.user .content { background: #f5f5f5; border-color: #ddd; }
  .codewrap { border-color: #ccc; }
}
