/* ============================================================================
   LRD-TECH Programming Assistant — interface stylesheet
   ----------------------------------------------------------------------------
   A calm, product-grade chat workspace: one restrained accent, hairline
   borders, real typographic hierarchy and generous spacing. No animated grids,
   no floating particles, no competing glows — the answer is the interface.

   Layout
     desktop (>=1080px) : context rail (300px) + chat column
     tablet / mobile    : single chat column, context rail becomes a drawer
   ========================================================================== */

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  /* surfaces */
  --bg:            #070a12;
  --bg-elev:       #0b101c;
  --bg-inset:      #05070e;
  --surface:       rgba(255, 255, 255, .035);
  --surface-2:     rgba(255, 255, 255, .065);
  --surface-3:     rgba(255, 255, 255, .095);
  --line:          rgba(255, 255, 255, .08);
  --line-2:        rgba(255, 255, 255, .15);

  /* text */
  --text:          #e8edf8;
  --text-2:        #a7b2c8;
  --text-3:        #78849c;

  /* accent + state */
  --acc:           #22d3ee;
  --acc-2:         #6366f1;
  --acc-text:      #a5f3fc;
  --ok:            #34d399;
  --warn:          #fbbf24;
  --bad:           #f87171;

  /* geometry */
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-full: 999px;
  --header-h: 60px;

  /* depth */
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .45);
  --shadow-2: 0 18px 40px -26px rgba(0, 0, 0, .9);
  --inset-hi: inset 0 1px 0 rgba(255, 255, 255, .04);

  --ease: cubic-bezier(.22, 1, .36, 1);
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;                 /* the app shell owns every scroll region */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--acc); }
img { max-width: 100%; }
::selection { background: rgba(34, 211, 238, .28); color: #fff; }
:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; border-radius: var(--r-xs); }

/* ── Background ─────────────────────────────────────────────────────────── */
.ai-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
  background:
    radial-gradient(1100px 520px at 50% -260px, #131e3a 0%, rgba(7, 10, 18, 0) 62%),
    radial-gradient(760px 460px at 100% 8%, rgba(34, 211, 238, .05), transparent 70%),
    var(--bg);
}
.ai-bg-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, .022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .022) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 80% 60% at 50% 0%, #000 20%, transparent 78%);
}
.ai-bg-glow { position: absolute; border-radius: 50%; filter: blur(150px); opacity: .16; }
.g1 { width: 560px; height: 560px; background: #4338ca; top: -300px; left: -120px; }
.g2 { width: 480px; height: 480px; background: #0e7490; top: 34%; right: -240px; opacity: .12; }
.g3 { width: 420px; height: 420px; background: #6d28d9; bottom: -280px; left: 34%; opacity: .1; }
/* legacy decoration stays hidden: the shell must never look "busy" */
.ai-bg-particles, .ai-bg-particles span { display: none; }

/* A reusable translucent surface (kept for markup compatibility). */
.glass {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ── Shell ──────────────────────────────────────────────────────────────── */
.ai-shell {
  position: relative; z-index: 1;
  height: 100dvh; max-height: 100dvh;
  display: flex; flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.ai-header {
  flex: 0 0 auto;
  height: var(--header-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 10, 18, .84);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 20;
}
.ai-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.ai-logo {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 9px; object-fit: contain;
  background: #fff; padding: 3px;
  border: 1px solid var(--line-2);
}
.ai-header h1 {
  font-size: 15px; font-weight: 600; letter-spacing: -.2px;
  line-height: 1.25; white-space: nowrap;
}
.ai-header h1 .grad {
  background: linear-gradient(92deg, var(--acc), var(--acc-2));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.tagline {
  font-size: 12px; color: var(--text-3); line-height: 1.35;
  margin-top: 1px; white-space: nowrap;
}
.ai-header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ai-status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3);
  padding: 6px 11px; border-radius: var(--r-full);
  border: 1px solid var(--line); background: var(--surface);
  white-space: nowrap;
}
.ai-status i { font-size: 7px; color: var(--text-3); }
.ai-status.online i { color: var(--ok); }
.ai-status.knowledge i { color: var(--acc); }
.ai-status.knowledge { color: var(--text-2); }
.ai-role {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); padding: 6px 10px; border-radius: var(--r-full);
  border: 1px solid var(--line); background: var(--surface);
  white-space: nowrap;
}
.ai-role i { font-size: 10px; }
.ai-home {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; font-weight: 500; color: var(--text-2);
  text-decoration: none; padding: 7px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.ai-home:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-2); }
.drawer-btn {
  display: none; width: 38px; height: 38px; flex: 0 0 38px;
  align-items: center; justify-content: center;
  border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text-2);
}
.drawer-btn:hover { background: var(--surface-2); color: var(--text); }
.drawer-btn.open { background: var(--surface-3); color: var(--text); }

/* ── Two-column layout ──────────────────────────────────────────────────── */
.ai-layout {
  flex: 1 1 auto; min-height: 0;
  width: 100%; max-width: 1560px; margin: 0 auto;
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
}

/* ---- Context rail ------------------------------------------------------- */
.ai-panel {
  min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px 20px;
  display: flex; flex-direction: column; gap: 13px;
  border-right: 1px solid var(--line);
  background: rgba(9, 13, 24, .55);
}
.ai-panel::-webkit-scrollbar { width: 8px; }
.ai-panel::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--r-full); }
.ai-panel::-webkit-scrollbar-track { background: transparent; }

.panel-box {
  position: relative;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--inset-hi);
}
.panel-box h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-3);
  padding-bottom: 11px; margin-bottom: 3px;
  border-bottom: 1px solid var(--line);
}
.panel-box h3 i { font-size: 11px; color: var(--acc); }
.panel-box label {
  display: block;
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3);
  margin: 12px 0 6px;
}

/* select control */
.sel-wrap { position: relative; }
.sel-wrap select {
  width: 100%;
  appearance: none; -webkit-appearance: none;
  padding: 10px 32px 10px 12px;
  font-size: 13px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: border-color .16s var(--ease), background .16s var(--ease);
}
.sel-wrap select:hover { border-color: var(--line-2); }
.sel-wrap select:focus { outline: none; border-color: rgba(34, 211, 238, .5); background: var(--surface-3); }
.sel-wrap select option { background: #0c1322; color: var(--text); }
.sel-wrap::after {
  content: ''; position: absolute; right: 13px; top: calc(50% - 2px);
  width: 6px; height: 6px;
  border-right: 1.5px solid var(--text-3); border-bottom: 1.5px solid var(--text-3);
  transform: rotate(45deg) translateY(-50%);
  pointer-events: none;
}

/* privacy + feature list */
.privacy ul { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 2px; }
.privacy li {
  position: relative; padding-left: 22px;
  font-size: 12px; line-height: 1.55; color: var(--text-2);
}
.privacy li i, .privacy i {
  position: absolute; left: 0; top: 2px;
  font-size: 10px; color: var(--ok);
}
.privacy h3 { color: var(--text-3); }
.privacy h3 i { position: static; font-size: 11px; color: var(--acc); }

/* ---- Attachments panel -------------------------------------------------- */
.upload-list { display: flex; flex-direction: column; gap: 8px; }
.upload-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.upload-item img {
  width: 34px; height: 34px; flex: 0 0 34px;
  object-fit: cover; border-radius: var(--r-xs);
  border: 1px solid var(--line);
}
.upload-item .name { font-size: 12.5px; font-weight: 500; }
.upload-item .ttl { font-size: 10.5px; color: var(--text-3); }
.upload-item .name, .upload-item .ttl { display: block; min-width: 0; }
.upload-item button {
  margin-left: auto;
  width: 28px; height: 28px; flex: 0 0 28px;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--r-xs);
  background: transparent; color: var(--text-3); font-size: 11px;
}
.upload-item button:hover { color: var(--bad); border-color: rgba(248, 113, 113, .35); }
.upload-drop { margin-top: 10px; }
.muted { font-size: 12px; line-height: 1.6; color: var(--text-3); }

/* ---- Buttons ------------------------------------------------------------ */
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 12px;
  font-size: 12.5px; font-weight: 500;
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.btn-ghost i { font-size: 11.5px; }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-2); }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
.upload-drop .btn-ghost { width: 100%; }

/* ── Chat column ────────────────────────────────────────────────────────── */
.ai-main {
  position: relative; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
}

/* context strip */
.ctx-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px;
  font-size: 12px; color: var(--text-3);
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 24, .5);
  cursor: pointer;
  transition: background .16s var(--ease);
}
.ctx-bar:hover, .ctx-bar:active { background: var(--surface); }
.ctx-bar i.lead { color: var(--acc); font-size: 12px; }
.ctx-bar .ctx-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3);
}
.ctx-bar .ctx-value { color: var(--text-2); font-weight: 500; }
.ctx-bar .ctx-sep { color: var(--line-2); }

/* toolbar: mode switcher + actions */
.ai-toolbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 13, 24, .72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.ai-mode-switcher {
  display: inline-flex; align-items: center; gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--surface);
}
.mode-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  font-size: 12.5px; font-weight: 500;
  color: var(--text-3);
  background: transparent; border: 0; border-radius: var(--r-full);
  white-space: nowrap;
  transition: background .16s var(--ease), color .16s var(--ease), box-shadow .16s var(--ease);
}
.mode-pill i { font-size: 11.5px; }
.mode-pill:hover:not(.active) { color: var(--text-2); background: var(--surface-2); }
.mode-pill.active { color: var(--text); background: var(--surface-3); box-shadow: var(--shadow-1); }
.mode-pill[data-filter="study"].active {
  color: #c7d2fe;
  box-shadow: inset 0 0 0 1px rgba(99, 102, 241, .38), var(--shadow-1);
}
.mode-pill[data-filter="research"].active {
  color: var(--acc-text);
  box-shadow: inset 0 0 0 1px rgba(34, 211, 238, .38), var(--shadow-1);
}
.ai-toolbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-toolbar .btn-ghost { padding: 7px 11px; }
.ai-note { font-size: 11.5px; color: var(--text-3); }

/* web availability badge */
.web-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ok);
  border: 1px solid rgba(52, 211, 153, .28);
  background: rgba(52, 211, 153, .07);
  border-radius: var(--r-full);
  white-space: nowrap;
}
.web-badge i { font-size: 10px; }
.web-badge.off {
  color: var(--text-3);
  border-color: var(--line);
  background: var(--surface);
}

/* depth chooser (Study / Research handshake) */
.depth-options-wrap {
  margin: 12px 0 2px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.depth-options-label {
  display: block; margin-bottom: 10px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3);
}
.depth-options-label i { color: var(--acc); margin-right: 5px; }
.depth-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.depth-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 13px;
  font-size: 12.5px; color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease);
}
.depth-btn i { font-size: 11px; color: var(--text-3); }
.depth-btn:hover:not(:disabled) { color: var(--text); border-color: var(--line-2); background: var(--surface-3); }
.depth-btn.selected {
  color: var(--text);
  border-color: rgba(34, 211, 238, .45);
  background: rgba(34, 211, 238, .1);
}
.depth-btn.selected i { color: var(--acc); }
.depth-btn:disabled { opacity: .55; cursor: default; }

/* ── Conversation ───────────────────────────────────────────────────────── */
.ai-chat {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 22px 20px 10px;
  display: flex; flex-direction: column; gap: 16px;
  scrollbar-gutter: stable;
}
.ai-chat::-webkit-scrollbar { width: 10px; }
.ai-chat::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: var(--r-full); border: 3px solid transparent; background-clip: content-box; }
.ai-chat::-webkit-scrollbar-track { background: transparent; }

.msg {
  display: flex; align-items: flex-start; gap: 11px;
  width: 100%; max-width: 940px; margin: 0 auto;
  animation: msgIn .22s var(--ease);
}
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  display: grid; place-items: center;
  font-size: 12px;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.msg.user .avatar {
  color: var(--acc-text);
  background: linear-gradient(135deg, rgba(34, 211, 238, .18), rgba(99, 102, 241, .18));
  border-color: rgba(34, 211, 238, .3);
}

.bubble {
  position: relative;
  max-width: min(760px, 100%);
  padding: 12px 15px;
  font-size: 14px; line-height: 1.68;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: linear-gradient(180deg, rgba(34, 211, 238, .1), rgba(99, 102, 241, .09));
  border-color: rgba(99, 102, 241, .24);
}
.bubble.blocked {
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 13.5px;
  color: #fde68a;
  background: rgba(251, 191, 36, .06);
  border-color: rgba(251, 191, 36, .3);
}
.bubble.blocked i { margin-top: 3px; flex: 0 0 auto; color: var(--warn); }

/* rendered markdown inside an answer */
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5 {
  font-weight: 600; line-height: 1.35; letter-spacing: -.15px;
  margin: 14px 0 7px;
}
.bubble h1 { font-size: 18px; }
.bubble h2 { font-size: 16.5px; }
.bubble h3 { font-size: 15px; }
.bubble h4, .bubble h5 { font-size: 14px; }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble p { margin: 8px 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0; padding-left: 20px; }
.bubble li { margin: 4px 0; }
.bubble li::marker { color: var(--acc); }
.bubble strong { font-weight: 600; color: #fff; }
.bubble em { font-style: italic; color: var(--text-2); }
.bubble hr { margin: 14px 0; border: 0; border-top: 1px solid var(--line); }
.bubble a { color: var(--acc); text-decoration: none; border-bottom: 1px solid rgba(34, 211, 238, .35); }
.bubble a:hover { border-bottom-color: var(--acc); }
.bubble blockquote {
  margin: 10px 0; padding: 2px 0 2px 12px;
  border-left: 2px solid var(--acc-2);
  color: var(--text-2);
}
.bubble table { width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 13px; }
.bubble th, .bubble td { padding: 7px 10px; border: 1px solid var(--line); text-align: left; vertical-align: top; }
.bubble th { background: var(--surface-2); font-weight: 600; color: var(--text); }
.bubble code {
  font-family: var(--mono); font-size: 12.5px;
  padding: 2px 5px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  color: #cbe7f5;
}

/* code block + language tag + copy button */
.code-wrap {
  position: relative;
  margin: 11px 0;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.code-wrap pre {
  margin: 0; padding: 14px;
  overflow-x: auto;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  color: #d7e6f2;
  tab-size: 2;
}
.code-wrap pre code { padding: 0; background: none; border: 0; color: inherit; font-size: inherit; }
.code-lang {
  position: absolute; top: 0; left: 0;
  padding: 4px 9px;
  font-size: 9.5px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-bottom-right-radius: var(--r-xs);
}
.copy-btn {
  position: absolute; top: 7px; right: 7px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px;
  font-size: 11px; color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  opacity: 0;
  transition: opacity .16s var(--ease), color .16s var(--ease), background .16s var(--ease);
}
.code-wrap:hover .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--text); background: var(--surface-3); }
.copy-btn:focus-visible { opacity: 1; }
.msg-attachment {
  display: block; margin-top: 9px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}

/* sources panel */
.sources {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px;
  margin-top: 12px; padding-top: 11px;
  border-top: 1px dashed var(--line);
}
.sources .src-title {
  flex: 0 0 100%;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 1px;
}
.src-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 5px 10px;
  font-size: 11.5px; color: var(--text-2);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  transition: color .16s var(--ease), border-color .16s var(--ease), background .16s var(--ease);
}
.src-chip i { font-size: 9.5px; color: var(--text-3); }
.src-chip:hover { color: var(--text); border-color: var(--line-2); background: var(--surface-2); }
.src-chip.plain, .src-chip.plain:hover { cursor: default; color: var(--text-2); border-color: var(--line); background: var(--surface); }
.src-chip.k-syllabus i { color: var(--acc-2); }
.src-chip.k-pdf i { color: var(--bad); }
.src-chip.k-document i { color: var(--ok); }
.src-chip.k-site i { color: #c4b5fd; }
.src-chip.k-web i { color: var(--acc); }
.src-chip.k-external i { color: var(--acc); }

/* ── Thinking indicator ─────────────────────────────────────────────────── */
.ai-typing {
  display: flex; align-items: center; gap: 5px;
  max-width: 980px; width: 100%; margin: 0 auto;
  padding: 0 20px 8px;
}
.ai-typing[hidden] { display: none; }
.ai-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--acc); opacity: .35;
  animation: think 1.1s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: .16s; }
.ai-typing span:nth-child(3) { animation-delay: .32s; }
.ai-typing em { font-style: normal; font-size: 12px; color: var(--text-3); margin-left: 7px; }
@keyframes think {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-2px); }
}

/* ── Suggestions ────────────────────────────────────────────────────────── */
.ai-suggest {
  flex: 0 0 auto;
  display: flex; gap: 8px;
  padding: 2px 20px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.ai-suggest[hidden] { display: none; }
.ai-suggest::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  font-size: 12.5px; color: var(--text-2);
  white-space: nowrap;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  transition: color .16s var(--ease), border-color .16s var(--ease), background .16s var(--ease);
}
.chip:hover { color: var(--text); border-color: rgba(34, 211, 238, .38); background: rgba(34, 211, 238, .08); }

/* ── Composer ───────────────────────────────────────────────────────────── */
.ai-composer {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  margin: 0 20px 10px;
  padding: 9px 9px 9px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-2);
  transition: border-color .16s var(--ease), box-shadow .16s var(--ease);
}
.ai-composer:focus-within {
  border-color: rgba(34, 211, 238, .45);
  box-shadow: var(--shadow-2), 0 0 0 3px rgba(34, 211, 238, .1);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-attach {
  width: 34px; height: 34px; flex: 0 0 34px;
  display: grid; place-items: center;
  font-size: 13px; color: var(--text-2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm);
  margin-bottom: 2px;
}
.composer-attach:hover { color: var(--text); background: var(--surface-2); border-color: var(--line-2); }
.ai-composer textarea {
  flex: 1 1 auto; min-width: 0;
  max-height: 168px;
  padding: 8px 2px;
  font-size: 14px; line-height: 1.6;
  color: var(--text);
  background: transparent;
  border: 0; outline: none;
  resize: none;
  overflow-y: auto;
}
.ai-composer textarea::placeholder { color: var(--text-3); }
.ai-composer textarea:focus { outline: none; }
.btn-send {
  width: 38px; height: 38px; flex: 0 0 38px;
  display: grid; place-items: center;
  font-size: 14px;
  color: #04121a;
  background: linear-gradient(135deg, var(--acc), var(--acc-2));
  border: 0; border-radius: 11px;
  box-shadow: var(--shadow-1);
  transition: filter .16s var(--ease), transform .1s var(--ease), opacity .16s var(--ease);
}
.btn-send:hover:not(:disabled) { filter: brightness(1.08); }
.btn-send:active:not(:disabled) { transform: translateY(1px); }
.btn-send:disabled { opacity: .45; cursor: not-allowed; }
.composer-attachments { display: flex; align-items: center; gap: 6px; padding-bottom: 2px; }
.composer-attachments[hidden] { display: none; }
.composer-attachments img {
  width: 38px; height: 38px; object-fit: cover;
  border: 1px solid var(--line); border-radius: var(--r-sm);
}
.ai-footnote {
  flex: 0 0 auto;
  margin: 0 20px 12px;
  font-size: 11px; line-height: 1.6; color: var(--text-3);
  text-align: center;
}
.ai-footnote i { color: var(--text-3); margin-right: 3px; }

/* ── Welcome / empty state ──────────────────────────────────────────────── */
.welcome {
  margin: auto;
  max-width: 620px;
  padding: 30px 26px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--inset-hi);
}
.welcome .orb {
  width: 52px; height: 52px;
  display: grid; place-items: center;
  margin: 0 auto 15px;
  font-size: 21px; color: var(--acc-text);
  background: linear-gradient(135deg, rgba(34, 211, 238, .16), rgba(99, 102, 241, .16));
  border: 1px solid rgba(99, 102, 241, .28);
  border-radius: 15px;
}
.welcome h2 { font-size: 17.5px; font-weight: 600; letter-spacing: -.2px; margin-bottom: 10px; }
.welcome p { font-size: 13.5px; line-height: 1.75; color: var(--text-2); }
.welcome p + p { margin-top: 10px; color: var(--text-3); font-size: 12.5px; }
.welcome .kbd {
  display: inline-block; padding: 1px 6px;
  font-family: var(--mono); font-size: 11.5px;
  background: var(--surface-3); border: 1px solid var(--line);
  border-radius: var(--r-xs);
}

/* ── Toast ──────────────────────────────────────────────────────────────── */
.ai-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: min(92vw, 440px);
  padding: 11px 16px;
  font-size: 12.5px; line-height: 1.5; color: var(--text);
  background: rgba(12, 18, 32, .97);
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-2);
  z-index: 60;
  animation: toastIn .2s var(--ease);
}
.ai-toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ── Mobile drawer ──────────────────────────────────────────────────────── */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(3, 6, 12, .66);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none;
  transition: opacity .2s var(--ease);
}
.drawer-backdrop[hidden] { display: none; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .ai-layout { grid-template-columns: 264px minmax(0, 1fr); }
  .ai-panel { padding: 14px 12px 18px; }
}

/* Tablet / mobile: the context rail becomes a slide-in drawer */
@media (max-width: 1080px) {
  .ai-layout { grid-template-columns: minmax(0, 1fr); }
  .drawer-btn { display: inline-flex; }
  .ai-panel {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 40;
    width: min(88vw, 330px);
    padding: 18px 15px 26px;
    border-right: 1px solid var(--line-2);
    background: rgba(9, 13, 24, .985);
    box-shadow: var(--shadow-2);
    transform: translateX(-102%);
    transition: transform .26s var(--ease);
    overflow-y: auto;
  }
  .ai-panel.open { transform: none; }
}

@media (max-width: 860px) {
  .tagline { display: none; }
  .ai-header { padding: 0 14px; gap: 10px; }
}

@media (max-width: 720px) {
  :root { --header-h: 56px; }
  .ai-header h1 { font-size: 14px; }
  .ai-role { display: none; }
  .ai-home span { display: none; }
  .ai-home { padding: 8px 10px; }
  .ai-toolbar { flex-wrap: wrap; gap: 9px; padding: 10px 14px; }
  .ai-mode-switcher { order: 1; }
  .ai-toolbar-actions { order: 2; margin-left: 0; width: 100%; }
  .ai-toolbar-actions .btn-ghost { flex: 1 1 auto; justify-content: center; }
  .ctx-bar { padding: 9px 14px; }
  .ai-chat { padding: 18px 14px 8px; gap: 14px; }
  .ai-typing { padding: 0 14px 8px; }
  .ai-suggest { padding: 2px 14px 10px; }
  .ai-composer { margin: 0 14px 9px; }
  .ai-footnote { margin: 0 14px 10px; font-size: 10.5px; }
  .bubble { font-size: 13.5px; padding: 11px 13px; }
  .bubble table { font-size: 12.5px; }
  .welcome { padding: 24px 18px; }
  .welcome h2 { font-size: 16.5px; }
}

@media (max-width: 560px) {
  /* Icon-only modes keep the switcher from wrapping; the active one keeps its label. */
  .mode-pill { padding: 8px 11px; }
  .mode-pill:not(.active) span { display: none; }
  .ai-brand { gap: 9px; }
  .ai-logo { width: 30px; height: 30px; flex-basis: 30px; }
  .avatar { width: 26px; height: 26px; flex-basis: 26px; font-size: 11px; }
  .msg { gap: 9px; }
  .sources .src-title { flex: 1 1 100%; }
  .depth-buttons { flex-direction: column; }
  .depth-btn { width: 100%; justify-content: flex-start; }
}

/* Very short viewports (landscape phones): keep the composer reachable */
@media (max-height: 520px) {
  .ai-footnote { display: none; }
  .welcome { padding: 18px; }
  .welcome .orb { display: none; }
}

/* ── Motion & print ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}
@media print {
  .ai-bg, .ai-header, .ai-panel, .ai-toolbar, .ai-suggest, .ai-composer, .ai-footnote, .ai-toast { display: none !important; }
  html, body { overflow: visible; background: #fff; color: #111; }
  .ai-shell { height: auto; }
  .bubble { border-color: #ddd; background: #fff; color: #111; }
}
