/* Project-X UI — Devin-inspired interface.
   Split workspace with chat + progress timeline + knowledge panel.
   Dark, dense, professional. Clean animations.                              */

:root {
  --bg-0: #09090b;
  --bg-1: #0f1117;
  --bg-2: #151821;
  --bg-3: #1a1e2b;
  --bg-4: #1f2435;
  --surface: #12141c;
  --surface-hover: #1a1d28;
  --line: rgba(255, 255, 255, 0.06);
  --line-strong: rgba(255, 255, 255, 0.1);
  --text: #e4e7ed;
  --text-dim: #8b93a8;
  --text-faint: #515972;
  --accent: #7c6aef;
  --accent-light: #9b8bff;
  --accent-soft: rgba(124, 106, 239, 0.1);
  --accent-border: rgba(124, 106, 239, 0.25);
  --ok: #34d399;
  --ok-soft: rgba(52, 211, 153, 0.1);
  --warn: #fbbf24;
  --err: #f87171;
  --err-soft: rgba(248, 113, 113, 0.1);
  --blue: #60a5fa;
  --blue-soft: rgba(96, 165, 250, 0.1);
  --blue-border: rgba(96, 165, 250, 0.25);
  --cyan: #22d3ee;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --font: 'Inter', ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 260px;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ─── BACKGROUND ────────────────────────────────────────── */

.bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(800px 500px at 65% -5%, rgba(124,106,239,0.04), transparent 60%),
    radial-gradient(600px 400px at -5% 105%, rgba(96,165,250,0.03), transparent 60%);
}

/* ─── LAYOUT ────────────────────────────────────────────── */

body { display: grid; grid-template-columns: var(--sidebar-w) 1fr; }
body.file-panel-open { grid-template-columns: var(--sidebar-w) 1fr var(--file-panel-w, 420px); }

/* ─── SIDEBAR ───────────────────────────────────────────── */

.sidebar {
  position: relative; z-index: 2;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}

/* Sidebar hamburger toggle — always visible */
.sidebar-toggle-btn { display: inline-flex; }

/* Sidebar collapse on desktop */
body.sidebar-collapsed { grid-template-columns: 0 1fr; }
body.sidebar-collapsed .sidebar { transform: translateX(-100%); pointer-events: none; opacity: 0; }
.sidebar { transition: transform 0.25s ease, opacity 0.2s ease; }

/* Sidebar overlay on mobile */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 199; display: none;
}
.sidebar-backdrop.visible { display: block; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.3px; }
.brand-name .accent { color: var(--accent-light); }

.sidebar-section {
  padding: 10px 8px 8px;
  border-bottom: 1px solid var(--line);
}
.sidebar-section:last-of-type { border-bottom: 0; }

.sidebar-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-faint); padding: 4px 8px 6px; display: block; font-weight: 600;
}
.sidebar-label-button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: transparent; border: 0;
  color: var(--text-faint); padding: 4px 8px 6px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 600;
}
.sidebar-label-button .chev { transition: transform 0.15s; }
.sidebar-label-button[aria-expanded="true"] .chev { transform: rotate(90deg); }
.collapsible { display: none; padding: 0 4px; }
.sidebar-label-button[aria-expanded="true"] + .collapsible { display: block; }

/* Sidebar nav (Devin-style) */
.sidebar-nav {
  display: flex; flex-direction: column; gap: 1px;
  padding: 8px 8px 0;
}
.sidebar-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: 13px; font-weight: 400;
  text-decoration: none; transition: all 0.1s;
}
.sidebar-nav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.sidebar-nav-item.active { color: var(--text); font-weight: 500; }
.sidebar-nav-item svg { flex-shrink: 0; opacity: 0.7; }
.sidebar-nav-item.active svg { opacity: 1; }
.nav-badge {
  font-size: 9px; background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; color: var(--text-faint);
  margin-left: auto; text-transform: uppercase; letter-spacing: 0.5px;
}
.sidebar-label-flex {
  display: flex; align-items: center; justify-content: space-between;
}
.sidebar-label-actions {
  display: flex; gap: 2px;
}
.icon-btn-mini {
  background: transparent; border: 0; color: var(--text-faint);
  cursor: pointer; padding: 3px; border-radius: 4px; display: flex; align-items: center;
  transition: all 0.1s;
}
.icon-btn-mini:hover { color: var(--text); background: var(--surface-hover); }

/* Settings button in sidebar footer */
.sidebar-settings-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; background: transparent; border: 0;
  color: var(--text-faint); font-size: 12px; padding: 8px 12px;
  cursor: pointer; transition: all 0.1s;
}
.sidebar-settings-btn:hover { color: var(--text); background: var(--surface-hover); }

/* Sessions */
.sessions {
  display: flex; flex-direction: column; gap: 1px;
  max-height: 40vh; overflow-y: auto;
}
.session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; margin: 0 4px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; color: var(--text-dim);
  transition: all 0.1s;
}
.session-item:hover { background: var(--surface-hover); color: var(--text); }
.session-item.active { background: var(--accent-soft); color: var(--text); border: 1px solid var(--accent-border); }
.session-item .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.session-item .del {
  background: transparent; border: 0; color: var(--text-faint);
  cursor: pointer; opacity: 0; padding: 2px; border-radius: 3px;
  transition: opacity 0.1s;
}
.session-item:hover .del { opacity: 1; }
.session-item .del:hover { color: var(--err); }
.sessions-empty { padding: 8px 12px; color: var(--text-faint); font-size: 12px; }

/* Brain stats */
.brain-stats { padding: 0 8px; }
.brain-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 3px 0; font-size: 12px;
}
.stat-label { color: var(--text-faint); }
.stat-value { color: var(--text-dim); font-weight: 600; font-variant-numeric: tabular-nums; }

/* GH repos */
.row { display: flex; gap: 6px; padding: 0 4px; }
.row input[type="text"] {
  flex: 1; background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); border-radius: var(--radius-xs);
  padding: 6px 10px; font-size: 12px; outline: none;
}
.row input[type="text"]:focus { border-color: var(--accent-border); }
.ghost {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text-dim); padding: 6px 10px; border-radius: var(--radius-xs);
  font-size: 11px; transition: all 0.1s;
}
.ghost:hover { background: var(--bg-3); color: var(--text); }
.gh-list { padding: 6px 0; display: flex; flex-direction: column; gap: 1px; max-height: 180px; overflow-y: auto; }
.gh-list .repo {
  padding: 5px 10px; margin: 0 4px; border-radius: var(--radius-xs);
  font-size: 12px; cursor: pointer; color: var(--text-dim); transition: all 0.1s;
}
.gh-list .repo:hover { background: var(--surface-hover); color: var(--text); }
.gh-list .repo .meta { color: var(--text-faint); font-size: 10px; margin-top: 1px; }

.sidebar-foot {
  margin-top: auto; padding: 10px 16px;
  border-top: 1px solid var(--line); font-size: 12px; color: var(--text-faint);
}
.status-row { display: flex; align-items: center; gap: 8px; }
.status-row .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint); flex-shrink: 0;
}
.status-row.ok .dot { background: var(--ok); box-shadow: 0 0 8px rgba(52,211,153,0.5); }
.status-row.bad .dot { background: var(--err); box-shadow: 0 0 8px rgba(248,113,113,0.5); }

/* ─── MAIN ──────────────────────────────────────────────── */

.main { position: relative; z-index: 1; height: 100vh; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 48px; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--bg-1);
}
.session-title {
  font-size: 13px; color: var(--text-dim); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* Model toggle */
.model-toggle {
  display: inline-flex; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 2px;
}
.model-btn {
  background: transparent; border: 0; color: var(--text-faint);
  padding: 4px 12px; border-radius: 999px; font-size: 11px; font-weight: 500;
  transition: all 0.12s;
}
.model-btn:hover { color: var(--text-dim); }
.model-btn.active {
  background: var(--accent-soft); color: var(--accent-light);
  box-shadow: inset 0 0 0 1px var(--accent-border);
}

/* Workspace tabs (Devin-style) */
.workspace-tabs {
  display: inline-flex; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px;
}
.ws-tab {
  background: transparent; border: 0; color: var(--text-faint);
  padding: 4px 14px; border-radius: var(--radius-xs); font-size: 11.5px; font-weight: 500;
  transition: all 0.12s;
}
.ws-tab:hover { color: var(--text-dim); }
.ws-tab.active { background: var(--bg-3); color: var(--text); }

/* ─── WORKSPACE PANELS ──────────────────────────────────── */

.workspace { flex: 1; min-height: 0; position: relative; }
.ws-panel { display: none; height: 100%; }
.ws-panel.active { display: flex; flex-direction: column; }

/* ─── CHAT / CONVERSATION ───────────────────────────────── */

.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.messages {
  flex: 1; overflow-y: auto; padding: 20px 0 8px;
  scroll-behavior: smooth;
}

/* Welcome */
.welcome {
  max-width: 680px; margin: 20vh auto 0; padding: 0 24px; text-align: center;
}
.welcome-icon { margin-bottom: 24px; }
.welcome-brain {
  width: 80px; height: 80px; border-radius: 50%; margin: 0 auto; display: block;
  filter: drop-shadow(0 0 24px rgba(124,106,239,0.4));
  animation: brain-pulse 3s ease-in-out infinite;
}
@keyframes brain-pulse {
  0%, 100% { filter: drop-shadow(0 0 24px rgba(124,106,239,0.4)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 40px rgba(124,106,239,0.7)); transform: scale(1.05); }
}
.welcome-title {
  font-size: 26px; font-weight: 600; letter-spacing: -0.3px; color: var(--text);
}

/* Real-time activity log (Devin-style) */
.activity-log {
  margin-bottom: 8px; padding: 0; border-left: 2px solid var(--accent-border);
  margin-left: 4px;
}
.activity-step {
  display: flex; align-items: center; gap: 8px; padding: 4px 0 4px 12px;
  font-size: 12px; color: var(--text-dim); line-height: 1.4;
  animation: step-in 0.2s ease-out;
}
@keyframes step-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}
.activity-icon { font-size: 13px; flex-shrink: 0; }
.activity-text { flex: 1; }
.activity-time { font-size: 10px; color: var(--text-faint); font-family: var(--mono); }
.activity-thinking { color: var(--accent-light); }
.activity-step.activity-step { border-bottom: 1px solid var(--line); }
.activity-step:last-child { border-bottom: none; }
.activity-search { color: var(--blue); }
.activity-streaming { color: var(--ok); }
.activity-done { color: var(--ok); font-weight: 500; }
.activity-error { color: var(--err); }

/* GitHub user info in sidebar */
.gh-user-info {
  display: flex; align-items: center; gap: 4px; padding: 6px 8px;
  background: var(--surface); border-radius: var(--radius-sm);
  font-size: 12px;
}

/* Messages */
.msg {
  display: flex; gap: 12px; max-width: 760px; margin: 14px auto;
  padding: 0 24px; animation: msg-in 0.15s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

.msg .avatar {
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  margin-top: 2px; overflow: hidden;
}
.msg .avatar .avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 8px;
}
.msg.user .avatar {
  background: var(--bg-3); color: var(--text-dim); border: 1px solid var(--line);
}
.msg.assistant .avatar {
  background: linear-gradient(135deg, #7c6aef, #60a5fa);
  color: #fff; border: 0; position: relative;
}
.msg.assistant .avatar .avatar-glow {
  position: absolute; inset: -4px; border-radius: 10px;
  background: radial-gradient(circle, rgba(124,106,239,0.25) 0%, transparent 70%);
  animation: glow 3s ease-in-out infinite; z-index: -1;
}
@keyframes glow {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.1); }
}

.msg .bubble {
  flex: 1; min-width: 0; font-size: 14px; line-height: 1.6; word-wrap: break-word;
}
.msg.user .bubble { color: var(--text); white-space: pre-wrap; }
.msg .bubble img {
  max-width: 320px; max-height: 280px; border-radius: 8px; margin-top: 8px;
  display: block; border: 1px solid var(--line);
}

/* Markdown */
.msg .bubble code {
  font-family: var(--mono); background: rgba(255,255,255,0.05);
  padding: 1px 5px; border-radius: 3px; font-size: 0.88em;
}
.msg .bubble pre {
  font-family: var(--mono); background: var(--bg-2); border: 1px solid var(--line);
  padding: 12px 14px; border-radius: 8px; overflow-x: auto;
  font-size: 12px; line-height: 1.5; white-space: pre-wrap; margin: 8px 0;
}
.msg .bubble pre code { background: transparent; padding: 0; border-radius: 0; }
.msg .bubble h2, .msg .bubble h3, .msg .bubble h4 {
  margin: 0.8em 0 0.3em; font-weight: 600; color: var(--text);
}
.msg .bubble h2 { font-size: 1.2em; }
.msg .bubble h3 { font-size: 1.1em; }
.msg .bubble ul, .msg .bubble ol { padding-left: 1.4em; margin: 0.4em 0; }
.msg .bubble li { margin: 0.15em 0; }
.msg .bubble strong { color: var(--text); font-weight: 600; }
.msg .bubble a { color: var(--accent-light); }
.msg .bubble p { margin: 0.4em 0; }

/* ─── THINKING PANEL (Devin-style) ──────────────────────── */

.thinking-panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 8px;
  animation: think-in 0.2s ease-out;
}
@keyframes think-in {
  from { opacity: 0; height: 0; }
  to { opacity: 1; height: auto; }
}

.thinking-header { display: flex; align-items: center; gap: 10px; }

.thinking-dots { display: inline-flex; align-items: center; gap: 3px; }
.thinking-dots .dot {
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent-light);
  animation: tdot 1.2s ease-in-out infinite;
}
.thinking-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes tdot { 0%,100% { opacity: 0.25; transform: scale(0.8); } 50% { opacity: 1; transform: scale(1.2); } }

.thinking-label { font-size: 12px; color: var(--accent-light); font-weight: 500; }

/* Phase colors */
.thinking-panel.phase-searching-the-web {
  border-color: var(--blue-border); background: var(--blue-soft);
}
.thinking-panel.phase-searching-the-web .thinking-dots .dot { background: var(--blue); }
.thinking-panel.phase-searching-the-web .thinking-label { color: var(--blue); }

.thinking-panel.phase-thinking {
  border-color: rgba(52,211,153,0.2); background: var(--ok-soft);
}
.thinking-panel.phase-thinking .thinking-dots .dot { background: var(--ok); }
.thinking-panel.phase-thinking .thinking-label { color: var(--ok); }

/* Auto-search badge */
.auto-search-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; color: var(--blue); background: var(--blue-soft);
  border: 1px solid var(--blue-border); border-radius: 999px;
  padding: 2px 8px; margin-top: 8px;
}

/* Cursor */
.cursor {
  display: inline-block; width: 5px; height: 13px;
  background: var(--accent-light); vertical-align: -1px; margin-left: 1px;
  animation: blink 0.9s steps(2) infinite; border-radius: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

.err { color: var(--err); font-size: 12px; margin-top: 6px; }

/* ─── COMPOSER ──────────────────────────────────────────── */

.composer {
  padding: 0 24px 18px; flex-shrink: 0;
  background: linear-gradient(180deg, transparent, rgba(9,9,11,0.9) 30%);
}
.attachments { max-width: 760px; margin: 0 auto 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.attachments .chip {
  background: var(--accent-soft); border: 1px solid var(--accent-border);
  border-radius: 999px; padding: 3px 10px; font-size: 11px;
  display: flex; align-items: center; gap: 5px;
}
.attachments .chip button {
  background: transparent; border: 0; color: var(--text-dim); font-size: 13px; line-height: 1;
}

.composer-row {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px 4px 4px 6px;
  transition: all 0.15s;
}
.composer-row:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(124,106,239,0.06);
}

textarea#input {
  flex: 1; background: transparent; border: 0; outline: 0; resize: none;
  color: var(--text); font: inherit; padding: 8px 4px; max-height: 180px;
  font-size: 14px;
}
textarea#input::placeholder { color: var(--text-faint); }

.icon-btn {
  background: transparent; border: 0; color: var(--text-faint);
  padding: 6px; border-radius: var(--radius-xs);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.1s;
}
.icon-btn:hover { color: var(--text-dim); background: var(--bg-3); }

.composer-actions { display: flex; align-items: center; gap: 2px; }

.mini-toggle {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--text-faint); padding: 5px 8px;
  border-radius: var(--radius-xs); cursor: pointer; transition: all 0.1s;
  user-select: none;
}
.mini-toggle:hover { color: var(--text-dim); background: rgba(255,255,255,0.02); }
.mini-toggle input { display: none; }
.mini-toggle:has(input:checked) { color: var(--blue); }
.mini-toggle:has(input:checked) svg { stroke: var(--blue); }

/* + button (Devin-style, left side of composer) */
.plus-menu-wrap { position: relative; }
.plus-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: transparent; border: 1px solid var(--line);
  color: var(--text-faint); display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.plus-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--line-strong); }

/* Plus menu popup */
.plus-menu {
  position: absolute; bottom: 110%; left: 0;
  background: var(--bg-2); border: 1px solid var(--line-strong);
  border-radius: var(--radius); min-width: 220px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5); z-index: 100;
  padding: 6px;
}
.plus-menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: transparent; border: 0; color: var(--text);
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; transition: all 0.1s; text-align: left;
}
.plus-menu-item:hover { background: var(--surface-hover); }
.plus-menu-icon { font-size: 16px; font-weight: 600; color: var(--text-dim); width: 16px; text-align: center; }

/* Send button (circular arrow like Devin) */
.send-btn-round {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--text); color: var(--bg-0); border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.send-btn-round:hover { background: #fff; transform: scale(1.05); }
.send-btn-round:active { transform: scale(0.95); }

/* Mic button */
.icon-btn-round {
  width: 32px; height: 32px; border-radius: 50%;
  background: transparent; border: 0; color: var(--text-faint);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.1s; flex-shrink: 0;
}
.icon-btn-round:hover { color: var(--text); background: var(--surface-hover); }

/* Stop button (square icon like Devin) */
.stop-btn-round {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--text); color: var(--bg-0); border: 0;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s; flex-shrink: 0;
}
.stop-btn-round:hover { background: #fff; }

.send-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(0,0,0,0.2); border-top-color: var(--bg-0);
  border-radius: 50%; display: none;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.send-btn-round.busy .send-icon { display: none; }
.send-btn-round.busy .send-spinner { display: inline-block; }

/* Image thumbnails in composer (Devin-style) */
.image-thumbnails {
  max-width: 760px; margin: 0 auto; padding: 0;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.image-thumbnail {
  position: relative; width: 64px; height: 64px;
  border-radius: var(--radius-sm); overflow: hidden;
  border: 1px solid var(--line); cursor: pointer;
}
.image-thumbnail img {
  width: 100%; height: 100%; object-fit: cover;
}
.image-thumbnail:hover { border-color: var(--accent-border); }
.image-thumbnail .thumb-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.7); border: 0; color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
}
.image-thumbnail:hover .thumb-remove { opacity: 1; }

/* Image preview overlay */
.image-preview-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.85); display: flex;
  align-items: center; justify-content: center;
  cursor: pointer;
}
.image-preview-overlay img {
  max-width: 90vw; max-height: 90vh; border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(0,0,0,0.5);
}

/* VM Desktop styles */
/* VM styles removed — Desktop/VM section no longer used */

/* ─── PROGRESS PANEL ────────────────────────────────────── */

.progress-panel {
  height: 100%; display: flex; flex-direction: column;
  overflow: hidden;
}
.progress-header {
  padding: 16px 24px 12px; border-bottom: 1px solid var(--line);
}
.progress-header h3 { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.progress-sub { font-size: 12px; color: var(--text-faint); }

.progress-timeline {
  flex: 1; overflow-y: auto; padding: 16px 24px;
}
.progress-empty {
  text-align: center; padding: 60px 20px; color: var(--text-faint);
}
.progress-empty p { margin-top: 12px; font-size: 13px; }

/* Timeline entries */
.timeline-entry {
  position: relative; padding: 0 0 20px 28px;
  border-left: 2px solid var(--line); margin-left: 8px;
  animation: msg-in 0.15s ease-out;
}
.timeline-entry:last-child { border-left-color: transparent; }
.timeline-entry::before {
  content: ""; position: absolute; left: -5px; top: 4px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--bg-3); border: 2px solid var(--text-faint);
}
.timeline-entry.type-thinking::before { border-color: var(--accent-light); background: var(--accent-soft); }
.timeline-entry.type-search::before { border-color: var(--blue); background: var(--blue-soft); }
.timeline-entry.type-answer::before { border-color: var(--ok); background: var(--ok-soft); }
.timeline-entry.type-error::before { border-color: var(--err); background: var(--err-soft); }

.timeline-time { font-size: 10px; color: var(--text-faint); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.timeline-content { font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.timeline-content strong { color: var(--text); }

/* ─── KNOWLEDGE PANEL (n8n-style graph) ─────────────────── */

.knowledge-panel {
  height: 100%; display: flex; flex-direction: column; overflow: hidden;
}

/* Compact top bar with stats + actions */
.knowledge-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  z-index: 2;
  flex-shrink: 0;
}
.knowledge-topbar-stats {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.k-stat-pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px 3px 6px;
  font-size: 11px; color: var(--text-dim); font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.k-pill-icon { font-size: 13px; }
.knowledge-topbar-actions {
  display: flex; gap: 6px; flex-shrink: 0;
}

.action-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-dim); padding: 6px 12px; border-radius: var(--radius-sm);
  font-size: 11.5px; font-weight: 500; transition: all 0.12s;
}
.action-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--accent-border); }
.action-btn.loading { opacity: 0.6; pointer-events: none; }
.action-btn.loading svg { animation: spin 0.7s linear infinite; }
.action-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-light); }

/* Graph canvas fills remaining space */
.kg-graph-container {
  flex: 1; position: relative; overflow: hidden;
  background: #0d0d0f;
}
.kg-canvas {
  display: block; width: 100%; height: 100%;
  touch-action: none;
}

/* ─── ASK PANEL (Community Board + Live Chat) ────────────── */

.ask-panel {
  height: 100%; display: flex; gap: 0; overflow: hidden;
}

/* Left: Posts / Reports */
.ask-posts {
  flex: 1; display: flex; flex-direction: column; border-right: 1px solid var(--line);
  min-width: 0;
}
.ask-posts-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  flex-shrink: 0;
}
.ask-posts-header h3 {
  font-size: 13px; font-weight: 600; color: var(--text); margin: 0;
}
.ask-posts-list {
  flex: 1; overflow-y: auto; padding: 12px;
}
.ask-empty {
  text-align: center; color: var(--text-dim); font-size: 12px;
  padding: 40px 20px; opacity: 0.6;
}

/* Post card */
.ask-post {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
  margin-bottom: 10px; cursor: pointer;
  transition: border-color 0.15s;
}
.ask-post:hover { border-color: var(--accent-border); }
.ask-post-title {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 4px;
}
.ask-post-body {
  font-size: 11.5px; color: var(--text-dim); line-height: 1.5;
  max-height: 60px; overflow: hidden;
}
.ask-post-meta {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
  font-size: 10px; color: var(--text-dim); opacity: 0.7;
}
.ask-post-tag {
  display: inline-flex; align-items: center;
  background: var(--accent-soft); color: var(--accent-light);
  padding: 1px 6px; border-radius: 999px;
  font-size: 9px; font-weight: 600; text-transform: uppercase;
}
.ask-post-comments {
  margin-left: auto;
}
.ask-post-delete {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 14px; padding: 2px 4px; opacity: 0.5; transition: opacity 0.15s;
}
.ask-post-delete:hover { opacity: 1; color: #f53b3a; }

/* Post detail view */
.ask-post-detail {
  display: flex; flex-direction: column; height: 100%;
}
.ask-post-detail-header {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-1); flex-shrink: 0;
}
.ask-post-detail-header button {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 12px;
}
.ask-post-detail-body {
  flex: 1; overflow-y: auto; padding: 16px;
}
.ask-post-detail-body .ask-post-title { font-size: 16px; margin-bottom: 8px; }
.ask-post-detail-body .ask-post-body { max-height: none; font-size: 13px; color: var(--text); }
.ask-comment {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.ask-comment-author {
  font-size: 11px; font-weight: 600; color: var(--accent-light); margin-bottom: 3px;
}
.ask-comment-text {
  font-size: 12px; color: var(--text); line-height: 1.5;
}
.ask-comment-time {
  font-size: 10px; color: var(--text-dim); margin-top: 3px; opacity: 0.6;
}
.ask-comment-delete {
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  font-size: 12px; padding: 1px 4px; opacity: 0.4; float: right;
}
.ask-comment-delete:hover { opacity: 1; color: #f53b3a; }
.ask-post-detail-compose {
  padding: 10px 16px; border-top: 1px solid var(--line);
  display: flex; gap: 6px; flex-shrink: 0;
  background: var(--bg-1);
}
.ask-post-detail-compose input {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); padding: 6px 10px; border-radius: var(--radius-sm);
  font-size: 12px; outline: none;
}
.ask-post-detail-compose input:focus { border-color: var(--accent); }

/* Right: Live chat */
.ask-chat {
  width: 320px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg-1);
}
.ask-chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px; font-weight: 600; color: var(--text);
  flex-shrink: 0;
}
.ask-chat-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #34d399; display: inline-block;
  animation: chatPulse 2s ease-in-out infinite;
}
@keyframes chatPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.ask-online-badge {
  margin-left: auto; font-size: 10px; font-weight: 400;
  color: var(--text-dim); background: var(--surface);
  padding: 2px 8px; border-radius: 999px;
}
.ask-chat-messages {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.ask-chat-msg {
  max-width: 85%; padding: 6px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.4; word-break: break-word;
}
.ask-chat-msg.self {
  align-self: flex-end;
  background: var(--accent-soft); color: var(--accent-light);
  border-bottom-right-radius: 2px;
}
.ask-chat-msg.other {
  align-self: flex-start;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 2px;
}
.ask-chat-msg .chat-author {
  font-size: 10px; font-weight: 600; color: var(--accent-light);
  display: block; margin-bottom: 2px;
}
.ask-chat-msg .chat-time {
  font-size: 9px; color: var(--text-dim); opacity: 0.6;
  display: block; margin-top: 2px; text-align: right;
}
.ask-chat-msg .chat-delete-btn {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 10px; opacity: 0.3;
  float: right; margin-left: 6px;
}
.ask-chat-msg .chat-delete-btn:hover { opacity: 1; color: #f53b3a; }
.ask-chat-compose {
  padding: 10px 12px; border-top: 1px solid var(--line);
  display: flex; gap: 6px; flex-shrink: 0;
}
.ask-chat-compose input {
  flex: 1; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 12px; outline: none;
}
.ask-chat-compose input:focus { border-color: var(--accent); }

/* New post modal */
.ask-new-post-modal {
  display: none; position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.6); align-items: center; justify-content: center;
}
.ask-new-post-modal.visible { display: flex; }
.ask-new-post-form {
  background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; width: 420px; max-width: 90vw;
}
.ask-new-post-form h3 {
  font-size: 14px; margin: 0 0 12px; color: var(--text);
}
.ask-new-post-form input,
.ask-new-post-form textarea,
.ask-new-post-form select {
  width: 100%; background: var(--surface); border: 1px solid var(--line);
  color: var(--text); padding: 8px 10px; border-radius: var(--radius-sm);
  font-size: 12px; outline: none; margin-bottom: 10px; font-family: inherit;
  box-sizing: border-box;
}
.ask-new-post-form textarea { resize: vertical; min-height: 80px; }
.ask-new-post-form input:focus,
.ask-new-post-form textarea:focus { border-color: var(--accent); }
.ask-new-post-form .form-actions {
  display: flex; gap: 8px; justify-content: flex-end;
}
.ask-new-post-form .btn-cancel {
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text-dim); padding: 6px 14px; border-radius: var(--radius-sm);
  font-size: 12px; cursor: pointer;
}
.ask-new-post-form .btn-submit {
  background: var(--accent-soft); border: 1px solid var(--accent);
  color: var(--accent-light); padding: 6px 14px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer;
}

/* ─── RIGHT PANEL (Devin-style workspace) ───────────────── */

.file-panel {
  display: none; height: 100vh;
  flex-direction: column; background: var(--bg-1);
  border-left: 1px solid var(--line); z-index: 2;
  overflow: hidden;
}
body.file-panel-open .file-panel { display: flex; }

/* --- Tab bar at top --- */
.rp-tab-bar {
  display: flex; align-items: center; gap: 0;
  height: 40px; flex-shrink: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2); padding: 0 4px;
  overflow-x: auto; overflow-y: hidden;
}
.rp-tab {
  display: inline-flex; align-items: center; gap: 5px;
  background: transparent; border: 0; color: var(--text-faint);
  padding: 6px 12px; font-size: 11.5px; font-weight: 500;
  cursor: pointer; transition: all 0.1s; white-space: nowrap;
  border-bottom: 2px solid transparent; flex-shrink: 0;
}
.rp-tab:hover { color: var(--text-dim); background: rgba(255,255,255,0.03); }
.rp-tab.active {
  color: var(--accent-light); border-bottom-color: var(--accent);
}
.rp-tab svg { opacity: 0.6; }
.rp-tab.active svg { opacity: 1; }
.rp-tab-spacer { flex: 1; }
.rp-close { flex-shrink: 0; margin-left: 4px; }

/* --- Content panels --- */
.rp-content {
  display: none; flex-direction: column; flex: 1;
  overflow: hidden;
}
.rp-content.active { display: flex; }

.rp-section-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.rp-section-head h4 {
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.6px; margin: 0;
}
.rp-badge {
  background: var(--accent-soft); color: var(--accent-light);
  font-size: 10px; font-weight: 700; padding: 1px 7px;
  border-radius: 999px;
}
.rp-empty {
  text-align: center; padding: 40px 20px; color: var(--text-faint);
  font-size: 12.5px; line-height: 1.6;
}
.rp-empty p { margin-top: 10px; }

/* --- Changes tab --- */
.changes-list { flex: 1; overflow-y: auto; padding: 8px; }
.change-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: var(--radius-xs);
  font-size: 12px; cursor: pointer; transition: background 0.1s;
}
.change-item:hover { background: rgba(255,255,255,0.03); }
.change-item .ch-icon { flex-shrink: 0; }
.change-item .ch-icon.added { color: var(--ok); }
.change-item .ch-icon.modified { color: #f0c040; }
.change-item .ch-name { color: var(--text-dim); font-family: var(--mono); font-size: 11.5px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.change-item .ch-stat { color: var(--text-faint); font-size: 10px; flex-shrink: 0; }

/* --- Worklog tab --- */
.worklog-entries { flex: 1; overflow-y: auto; padding: 8px 12px; }
.wl-entry {
  display: flex; gap: 8px; padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  font-size: 12px; animation: msg-in 0.15s ease-out;
}
.wl-entry:last-child { border-bottom: 0; }
.wl-time { color: var(--text-faint); font-size: 10px; flex-shrink: 0; font-variant-numeric: tabular-nums; min-width: 50px; }
.wl-text { color: var(--text-dim); flex: 1; line-height: 1.4; }
.wl-text strong { color: var(--text); font-weight: 500; }

/* --- Desktop tab --- */
.desktop-viewport { flex: 1; padding: 12px; overflow: auto; display: flex; flex-direction: column; }
.desktop-screen {
  flex: 1; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column;
  background: #1a1a1a;
}
.desktop-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--bg-2);
  border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.dt-dots { display: flex; gap: 5px; }
.dt-dot { width: 10px; height: 10px; border-radius: 50%; }
.dt-dot.red { background: #ff5f57; }
.dt-dot.yellow { background: #febc2e; }
.dt-dot.green { background: #28c840; }
.dt-url {
  font-size: 10.5px; color: var(--text-faint); font-family: var(--mono);
  flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}
.desktop-body {
  flex: 1; overflow: auto; background: #0d0d0d;
  position: relative;
}
.desktop-body iframe {
  width: 100%; height: 100%; border: 0; background: #fff;
}

/* --- Shell tab --- */
.shell-terminal {
  flex: 1; overflow: auto; padding: 0;
  background: #0c0c0c; display: flex; flex-direction: column;
}
.shell-output {
  flex: 1; overflow-y: auto; padding: 12px; font-family: var(--mono);
  font-size: 12px; line-height: 1.6;
}
.shell-line { color: var(--text-dim); white-space: pre-wrap; word-break: break-all; }
.shell-line.prompt { color: var(--ok); }
.shell-line.error { color: var(--err); }
.shell-line.info { color: var(--accent-light); }

/* --- IDE tab (files) --- */
.file-panel-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.file-panel-tabs-inner {
  display: flex; align-items: center; gap: 2px; flex: 1;
  overflow-x: auto; overflow-y: hidden; min-width: 0;
}
.file-panel-title {
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.file-tab {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text-dim); padding: 3px 10px; border-radius: var(--radius-xs);
  font-size: 11px; font-weight: 500; cursor: pointer;
  white-space: nowrap; transition: all 0.1s; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 5px; margin-left: 4px;
}
.file-tab:hover { background: var(--bg-3); color: var(--text); }
.file-tab.active {
  background: var(--accent-soft); color: var(--accent-light);
  border-color: var(--accent-border);
}
.file-tab .tab-close {
  background: transparent; border: 0; color: var(--text-faint);
  font-size: 12px; padding: 0 2px; cursor: pointer; line-height: 1;
}
.file-tab .tab-close:hover { color: var(--err); }

.file-panel-name {
  padding: 4px 12px; border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.file-panel-name span {
  font-size: 11.5px; color: var(--text-dim); font-weight: 500;
  font-family: var(--mono);
}
.file-actions { display: flex; gap: 4px; flex-shrink: 0; }
.file-action-btn {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text-dim); padding: 4px 7px; border-radius: var(--radius-xs);
  display: inline-flex; align-items: center; transition: all 0.1s; cursor: pointer;
}
.file-action-btn:hover { background: var(--bg-3); color: var(--text); border-color: var(--accent-border); }
.file-action-btn.copied { color: var(--ok); border-color: rgba(52,211,153,0.3); }

.file-panel-body { flex: 1; overflow: auto; padding: 0; }
.file-empty {
  text-align: center; padding: 50px 20px; color: var(--text-faint);
}
.file-empty p { margin-top: 10px; font-size: 12.5px; }

.file-code {
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  padding: 8px 0; white-space: pre-wrap; word-break: break-all;
}
.file-code .line {
  display: flex; min-height: 19px; padding: 0 12px 0 0;
}
.file-code .line:hover { background: rgba(255,255,255,0.02); }
.file-code .line-num {
  color: var(--text-faint); text-align: right; padding: 0 12px 0 8px;
  min-width: 40px; user-select: none; flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.file-code .line-text { flex: 1; min-width: 0; color: var(--text-dim); }

/* File attachment in chat (clickable) */
.file-attachment {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 12px; margin-top: 8px;
  cursor: pointer; transition: all 0.12s; max-width: 320px;
}
.file-attachment:hover {
  border-color: var(--accent-border); background: var(--surface-hover);
}
.file-attachment .fa-icon {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--accent-soft); border: 1px solid var(--accent-border);
  display: grid; place-items: center; flex-shrink: 0;
}
.file-attachment .fa-icon svg { color: var(--accent-light); }
.file-attachment .fa-info { min-width: 0; }
.file-attachment .fa-name {
  font-size: 12.5px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block;
}
.file-attachment .fa-size {
  font-size: 10.5px; color: var(--text-faint); display: block; margin-top: 1px;
}

.file-panel-toggle { position: relative; }
.file-panel-toggle .file-count {
  position: absolute; top: -2px; right: -4px;
  background: var(--accent); color: #fff;
  font-size: 9px; font-weight: 700; min-width: 14px; height: 14px;
  border-radius: 999px; display: grid; place-items: center;
  line-height: 1; padding: 0 3px;
}

/* ─── LIGHT THEME ───────────────────────────────────────── */
body.light-theme {
  --bg-0: #f5f5f7; --bg-1: #ffffff; --bg-2: #f0f0f2; --bg-3: #e8e8ec; --bg-4: #ddd;
  --surface: #fafafa; --surface-hover: #f0f0f5;
  --line: rgba(0,0,0,0.08); --line-strong: rgba(0,0,0,0.14);
  --text: #1a1a2e; --text-dim: #5a5a7a; --text-faint: #9999aa;
  --accent: #6c5ce7; --accent-light: #5b4ccf; --accent-soft: rgba(108,92,231,0.08);
  --accent-border: rgba(108,92,231,0.2);
}
body.light-theme .bg { background: #f5f5f7; }
body.light-theme .shell-terminal, body.light-theme .desktop-body { background: #f0f0f2; }

/* ─── TOPBAR SELECTS ────────────────────────────────────── */
.topbar-select {
  background: var(--bg-2); color: var(--text-dim); border: 1px solid var(--line);
  padding: 4px 8px; border-radius: var(--radius-xs); font-size: 11px;
  cursor: pointer; outline: none;
}
.topbar-select:focus { border-color: var(--accent-border); }
.topbar-select option { background: var(--bg-1); color: var(--text); }

/* ─── TOKEN COUNTER ─────────────────────────────────────── */
.token-counter {
  font-size: 10px; color: var(--text-faint); text-align: right;
  padding: 2px 12px 0; font-variant-numeric: tabular-nums;
}

/* ─── COMMAND PALETTE ───────────────────────────────────── */
.cmd-palette-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 9999; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 15vh;
}
.cmd-palette {
  background: var(--bg-1); border: 1px solid var(--line-strong);
  border-radius: var(--radius); width: 520px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4); overflow: hidden;
}
.cmd-palette input {
  width: 100%; background: transparent; border: 0; color: var(--text);
  padding: 14px 16px; font-size: 14px; outline: none;
  border-bottom: 1px solid var(--line);
}
.cmd-results { max-height: 300px; overflow-y: auto; }
.cmd-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; font-size: 13px;
  color: var(--text-dim); transition: background 0.08s;
}
.cmd-item:hover, .cmd-item.active { background: var(--accent-soft); color: var(--text); }
.cmd-item .cmd-key {
  margin-left: auto; font-size: 10px; color: var(--text-faint);
  background: var(--bg-3); padding: 2px 6px; border-radius: 3px;
  font-family: var(--mono);
}

/* ─── SEARCH OVERLAY ────────────────────────────────────── */
.search-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 9998; display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
}
.search-box {
  background: var(--bg-1); border: 1px solid var(--line-strong);
  border-radius: var(--radius); width: 560px; max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4); position: relative; overflow: hidden;
}
.search-box input {
  width: 100%; background: transparent; border: 0; color: var(--text);
  padding: 14px 40px 14px 16px; font-size: 14px; outline: none;
  border-bottom: 1px solid var(--line);
}
.search-results { max-height: 360px; overflow-y: auto; }
.search-result {
  padding: 10px 16px; cursor: pointer; border-bottom: 1px solid var(--line);
  transition: background 0.08s;
}
.search-result:hover { background: var(--accent-soft); }
.search-result .sr-title { font-size: 12px; font-weight: 500; color: var(--text); }
.search-result .sr-preview { font-size: 11px; color: var(--text-faint); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── NOTIFICATION CENTER ───────────────────────────────── */
.notif-container {
  position: fixed; top: 16px; right: 16px; z-index: 10000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.notif {
  background: var(--bg-1); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 12px 16px; min-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); pointer-events: auto;
  animation: notif-in 0.25s ease-out;
  font-size: 12.5px; color: var(--text);
}
.notif.success { border-left: 3px solid var(--ok); }
.notif.error { border-left: 3px solid var(--err); }
.notif.info { border-left: 3px solid var(--accent); }
.notif-title { font-weight: 600; margin-bottom: 2px; }
.notif-body { color: var(--text-dim); }
@keyframes notif-in { from { opacity: 0; transform: translateY(-8px); } }

/* ─── MODAL ─────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 9997; display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-1); border: 1px solid var(--line-strong);
  border-radius: var(--radius); width: 480px; max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4); overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-header h3 { font-size: 14px; color: var(--text); font-weight: 600; }
.modal-body { max-height: 320px; overflow-y: auto; padding: 8px; }
.modal-footer {
  display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line);
}
.modal-footer input {
  flex: 1; background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 6px 10px; border-radius: var(--radius-xs);
  font-size: 12px; outline: none;
}
.template-item {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  cursor: pointer; border-radius: var(--radius-xs); transition: background 0.08s;
}
.template-item:hover { background: var(--accent-soft); }
.template-item .t-name { flex: 1; font-size: 12.5px; color: var(--text); }
.template-item .t-del { color: var(--text-faint); cursor: pointer; font-size: 14px; }
.template-item .t-del:hover { color: var(--err); }

/* ─── MESSAGE ACTIONS (regen, favorite, pin) ────────────── */
.msg-actions {
  display: none; gap: 4px; margin-top: 6px;
}
.msg:hover .msg-actions, .msg-actions.visible { display: flex; }
.msg-action {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text-faint);
  padding: 3px 8px; border-radius: var(--radius-xs); font-size: 10px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  transition: all 0.1s;
}
.msg-action:hover { background: var(--bg-3); color: var(--text); border-color: var(--accent-border); }
.msg-action.active { color: var(--accent-light); border-color: var(--accent-border); }
.msg-action.fav-active { color: var(--warn); }

/* ─── SMART FOLLOW-UPS ──────────────────────────────────── */
.follow-ups {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px;
}
.follow-up {
  background: var(--accent-soft); border: 1px solid var(--accent-border);
  color: var(--accent-light); padding: 5px 12px; border-radius: 999px;
  font-size: 11px; cursor: pointer; transition: all 0.1s;
}
.follow-up:hover { background: var(--accent); color: #fff; }

/* ─── RATE LIMIT BANNER ─────────────────────────────────── */
.rate-limit-banner {
  background: var(--err-soft); border: 1px solid rgba(248,113,113,0.2);
  color: var(--err); padding: 8px 14px; font-size: 12px;
  border-radius: var(--radius-xs); margin: 8px 16px; text-align: center;
}

/* ─── DRAG DROP OVERLAY ─────────────────────────────────── */
.drag-overlay {
  position: fixed; inset: 0; background: rgba(124,106,239,0.1);
  border: 2px dashed var(--accent); z-index: 9999;
  display: none; align-items: center; justify-content: center;
  font-size: 18px; color: var(--accent-light); font-weight: 500;
}
.drag-overlay.active { display: flex; }

/* ─── 3D GLOBE (NASA) ──────────────────────────────────── */
.globe-container {
  background: var(--bg-0); border: 1px solid var(--line-strong);
  border-radius: var(--radius); width: 700px; max-width: 95vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6); overflow: hidden;
}
.globe-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.globe-header h3 { font-size: 14px; font-weight: 600; color: var(--text); }
.globe-controls { display: flex; align-items: center; gap: 8px; }
.globe-search-input {
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text); padding: 6px 12px; border-radius: var(--radius-xs);
  font-size: 12px; outline: none; width: 200px;
}
.globe-search-input:focus { border-color: var(--accent-border); }
.globe-viewport {
  width: 100%; height: 450px; position: relative;
  background: #09090b; cursor: grab;
}
.globe-viewport:active { cursor: grabbing; }
.globe-viewport canvas { display: block; }
.globe-info {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-top: 1px solid var(--line);
  background: var(--bg-1);
}
.globe-coords { font-family: var(--mono); font-size: 12px; color: var(--accent-light); }
.globe-status { font-size: 11px; color: var(--text-faint); }

/* ─── RESPONSIVE ────────────────────────────────────────── */

/* Tablets (768-860px) */
@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  body.file-panel-open { grid-template-columns: 1fr; }
  .sidebar { 
    position: fixed; left: -100%; top: 0; bottom: 0; width: 280px;
    z-index: 200; transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }
  .file-panel { position: fixed; top: 0; right: 0; width: 100vw; height: 100vh; z-index: 100; }
  .suggestions { grid-template-columns: 1fr; }
  .knowledge-topbar { flex-direction: column; gap: 6px; }
  .topbar-select { display: none; }
  .workspace-tabs { display: none; }
  .model-toggle { display: none; }
  .topbar-left { max-width: 50%; }
  .session-title { font-size: 12px; }

  /* Add hamburger toggle area */
  .topbar-left::before {
    content: "\2630"; font-size: 18px; cursor: pointer;
    margin-right: 8px; color: var(--text-dim);
  }

  .composer { padding: 0 12px 12px; }
  .composer-row { border-radius: 12px; }
  .globe-viewport { height: 300px; }
  .globe-search-input { width: 140px; }
}

/* Mobile phones (max 480px) */
@media (max-width: 480px) {
  html, body { font-size: 13px; }
  .sidebar {
    position: fixed; left: -100%; top: 0; bottom: 0; width: 100vw;
    z-index: 200; transition: left 0.3s ease;
  }
  .sidebar.open { left: 0; }

  .topbar { padding: 8px 10px; }
  .topbar-right { gap: 2px; }
  .icon-btn { padding: 4px; }
  .file-panel-toggle { display: none; }

  .messages { padding: 8px; }
  .msg { padding: 10px; max-width: 95%; }

  .composer { padding: 0 8px 8px; }
  .composer-row { padding: 3px; border-radius: 10px; }
  textarea#input { padding: 6px 4px; font-size: 14px; }
  .plus-btn { width: 32px; height: 32px; }
  .send-btn-round { width: 32px; height: 32px; }
  .stop-btn-round { width: 32px; height: 32px; }
  .mini-toggle { display: none; }

  .welcome-brain { width: 60px; height: 60px; }
  .welcome-title { font-size: 16px; }

  /* File panel takes full screen on mobile */
  .file-panel {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh; z-index: 150;
  }
  .rp-tab span { display: none; }
  .rp-tab { padding: 6px 8px; }

  /* Globe on mobile */
  .globe-container { width: 100vw; max-width: 100vw; border-radius: 0; }
  .globe-viewport { height: 250px; }
  .globe-search-input { width: 120px; font-size: 11px; }
  .globe-header h3 { font-size: 12px; }

  /* Plus menu on mobile */
  .plus-menu { min-width: 180px; }

  /* Image thumbnails smaller on mobile */
  .image-thumbnail { width: 48px; height: 48px; }

  /* Notifications */
  .notif-container { left: 8px; right: 8px; top: 8px; }
  .notif { min-width: auto; }

  /* Knowledge graph */
  .knowledge-topbar-stats { gap: 4px; }
  .k-stat-pill { font-size: 10px; padding: 2px 8px 2px 4px; }

  /* Ask panel — stack on mobile */
  .ask-panel { flex-direction: column; }
  .ask-posts { border-right: none; border-bottom: 1px solid var(--line); flex: 1; }
  .ask-chat { width: 100%; flex: 1; border-top: 1px solid var(--line); }
}

/* Touch-friendly improvements for all touch devices */
@media (hover: none) and (pointer: coarse) {
  .session-item { padding: 12px 10px; }
  .sidebar-nav-item { padding: 12px 14px; }
  .icon-btn { min-width: 36px; min-height: 36px; }
  .msg-action { padding: 6px 12px; font-size: 11px; }
  .follow-up { padding: 8px 16px; font-size: 12px; }
  .plus-menu-item { padding: 14px 16px; }
  .rp-tab { padding: 10px 12px; }

  .template-item { padding: 12px 14px; }
  .session-item .del { opacity: 1; } /* Always show delete on touch */
  .image-thumbnail .thumb-remove { opacity: 1; } /* Always show X on touch */
}

/* Landscape mode on phones */
@media (max-height: 500px) and (orientation: landscape) {
  .globe-viewport { height: 200px; }
  .welcome-brain { width: 40px; height: 40px; }
  .welcome-title { font-size: 14px; }
  .topbar { padding: 4px 8px; }
}

/* Extra large screens (ultrawide) */
@media (min-width: 1600px) {
  .composer-row { max-width: 900px; }
  .messages { max-width: 1000px; margin: 0 auto; }
  .attachments { max-width: 900px; }
  .image-thumbnails { max-width: 900px; }
}

/* Print styles */
@media print {
  .sidebar, .topbar, .composer, .file-panel, .bg { display: none !important; }
  body { grid-template-columns: 1fr !important; }
  .messages { max-height: none; overflow: visible; }
}

/* ─── SCROLLBAR ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.05); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.1); }

/* Safe areas for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .composer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .sidebar-foot { padding-bottom: env(safe-area-inset-bottom); }
}
