:root,
[data-theme="dark"] {
  --bg: #09090b;
  --bg-elev: #0f1014;
  --bg-panel: #14151b;
  --bg-card: #191b23;
  --bg-hover: #21242f;
  --bg-input: #0d0e12;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f4f4f5;
  --text-muted: #a1a1aa;
  --text-dim: #71717a;
  --accent: #60a5fa;
  --accent-2: #818cf8;
  --accent-3: #a78bfa;
  --accent-soft: rgba(96, 165, 250, 0.13);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.13);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.13);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.13);
  --user-bubble: #181a22;
  --code-bg: #0b0c10;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.55);
  --hljs-kw: #c084fc;
  --hljs-str: #34d399;
  --hljs-num: #fbbf24;
  --hljs-fn: #60a5fa;
  --hljs-com: #64748b;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-bottom, 0px));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-left, 0px));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-right, 0px));
}

[data-theme="light"] {
  --bg: #fafafa;
  --bg-elev: #ffffff;
  --bg-panel: #f4f4f6;
  --bg-card: #ffffff;
  --bg-hover: #eceef2;
  --bg-input: #f4f4f5;
  --border: rgba(9, 9, 11, 0.08);
  --border-strong: rgba(9, 9, 11, 0.15);
  --text: #18181b;
  --text-muted: #52525b;
  --text-dim: #71717a;
  --accent: #2563eb;
  --accent-2: #4f46e5;
  --accent-3: #7c3aed;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.11);
  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.12);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.1);
  --user-bubble: #eef2ff;
  --code-bg: #111318;
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
  --hljs-kw: #c084fc;
  --hljs-str: #34d399;
  --hljs-num: #fbbf24;
  --hljs-fn: #60a5fa;
  --hljs-com: #64748b;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
code, pre, kbd, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(161, 161, 170, 0.22); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(161, 161, 170, 0.4); }

.agy-spark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 700;
  font-size: 16px;
}
.agy-spark.pulse { animation: sparkPulse 1.8s ease-in-out infinite; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-stop-sm {
  border: 1px solid rgba(248, 113, 113, 0.35);
  background: var(--red-soft);
  color: var(--red);
  border-radius: 7px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-stop-sm:hover { background: rgba(248, 113, 113, 0.24); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.active { color: var(--accent); background: var(--accent-soft); }
.icon-xs { width: 24px; height: 24px; border-radius: 6px; }
.icon-btn svg, .cb-icon-btn svg { width: 15px; height: 15px; display: block; }

.kbd-btn {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
}
.kbd-btn:hover { color: var(--text); border-color: var(--border-strong); }

/* Auth Gate */
.auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background: var(--bg);
  z-index: 95;
}
.auth-card {
  max-width: 420px;
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-brand { font-size: 20px; font-weight: 700; margin-bottom: 10px; display: inline-flex; align-items: center; gap: 7px; }
.auth-card h1 { font-size: 17px; margin: 0 0 10px; }
.auth-card p { color: var(--text-muted); margin: 0 0 12px; font-size: 13.5px; }
.auth-hint { font-size: 12px; color: var(--text-dim); }
.auth-card code { background: var(--bg-panel); padding: 2px 6px; border-radius: 5px; color: var(--text); }

/* Shell */
.app-shell {
  display: flex;
  height: 100vh;
  height: var(--tg-vh, 100dvh);
  width: 100vw;
  overflow: hidden;
}

/* Left Sidebar */
.sidebar {
  width: 272px;
  flex-shrink: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  z-index: 45;
}
.sb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(11px + var(--safe-top)) 12px 8px calc(12px + var(--safe-left));
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 14.5px; letter-spacing: -0.01em; }
.sb-header-acts { display: flex; align-items: center; gap: 4px; }
.sse-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.sse-dot.offline { background: var(--amber); box-shadow: none; }

.mc-nav-card {
  margin: 2px 10px 8px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}
.mc-nav-card:hover { background: var(--bg-hover); }
.mc-nav-card.active {
  background: var(--accent-soft);
  border-color: rgba(96, 165, 250, 0.38);
  color: var(--accent);
}
.mc-nav-left { display: flex; align-items: center; gap: 8px; }
.mc-nav-icon svg { width: 15px; height: 15px; display: block; }
.slots-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.slots-pill.busy { background: var(--accent-soft); color: var(--accent); border-color: rgba(96, 165, 250, 0.35); }

.sb-controls { padding: 0 10px 8px; display: flex; flex-direction: column; gap: 7px; }
.search-box {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0 9px;
}
.search-box:focus-within { border-color: var(--accent); }
.search-ico { color: var(--text-dim); display: flex; }
.search-ico svg { width: 14px; height: 14px; }
.search-box input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  padding: 7px 0;
  outline: none;
}

.sb-filter-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.seg-group {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.seg-btn.active { background: var(--bg-card); color: var(--text); font-weight: 600; }
.btn-new-chat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-new-chat:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-new-chat svg { width: 13px; height: 13px; }

.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 2px 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chat-item {
  position: relative;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  gap: 3px;
  padding: 8px 9px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-card); border-color: var(--border-strong); }
.ci-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ci-name-wrap { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; }
.ci-indicator { width: 10px; height: 10px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ci-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-dim); opacity: 0.5; }
.ci-dot.unread { background: var(--accent); opacity: 1; box-shadow: 0 0 8px var(--accent); }
.ci-dot.waiting { background: var(--amber); opacity: 1; }
.ci-spin {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.7px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.75s linear infinite;
}
.ci-name { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item.active .ci-name { font-weight: 600; }
.ci-right { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ci-pin {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px;
  display: inline-flex;
  border-radius: 4px;
}
.chat-item:hover .ci-pin, .ci-pin.pinned { opacity: 1; }
.ci-pin.pinned { color: var(--accent); }
.ci-pin svg { width: 12px; height: 12px; }
.ci-time { font-size: 11px; color: var(--text-dim); }
.ci-bottom { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding-left: 17px; font-size: 11px; color: var(--text-dim); }
.ci-model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sb-footer {
  border-top: 1px solid var(--border);
  padding: 8px 10px calc(8px + var(--safe-bottom)) calc(10px + var(--safe-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.sb-foot-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.sb-foot-btn:hover { background: var(--bg-hover); color: var(--text); }
.sb-foot-btn svg { width: 14px; height: 14px; }
.sb-foot-right { display: flex; align-items: center; gap: 4px; }
.user-pill {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

/* Main Column & Tabs */
.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}
.tab-bar-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(40px + var(--safe-top));
  flex-shrink: 0;
  padding: calc(4px + var(--safe-top)) calc(8px + var(--safe-right)) 0 calc(8px + var(--safe-left));
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
}
.tab-mc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  margin-bottom: 4px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.tab-mc-btn:hover { background: var(--bg-hover); color: var(--text); }
.tab-mc-btn.active { background: var(--accent-soft); color: var(--accent); }
.tab-mc-btn svg { width: 15px; height: 15px; }

.tab-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 3px;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 178px;
  height: 33px;
  padding: 0 9px;
  border-radius: 8px 8px 0 0;
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}
.tab-item:hover { background: var(--bg-hover); color: var(--text); }
.tab-item.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
  font-weight: 600;
}
.tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab-close {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 13px;
  padding: 0;
}
.tab-close:hover { background: var(--bg-hover); color: var(--text); }
.tab-bar-right { display: flex; align-items: center; gap: 4px; padding-bottom: 4px; }
.mini-slots-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.mini-slots-btn.busy { border-color: rgba(96, 165, 250, 0.45); color: var(--accent); background: var(--accent-soft); }

/* Mission Control Dashboard */
.mission-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 24px 28px;
}
.mc-container { max-width: 1080px; margin: 0 auto; display: flex; flex-direction: column; gap: 26px; }
.mc-hero { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.mc-hero h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; }
.mc-hero p { margin: 0; color: var(--text-muted); font-size: 13.5px; }
.mc-hero-actions { display: flex; align-items: center; gap: 10px; }
.mc-slots-badge {
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.mc-sec-title {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.mc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.mc-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 13px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mc-card.running { border-color: rgba(96, 165, 250, 0.4); }
.mc-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mc-card-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.mc-card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mc-card-meta { font-size: 12px; color: var(--text-muted); }
.mc-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: auto; }
.mc-empty {
  grid-column: 1 / -1;
  background: var(--bg-panel);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  padding: 18px;
  color: var(--text-muted);
  font-size: 13px;
}
.mc-recent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.mc-recent-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 0.14s, background 0.14s;
}
.mc-recent-card:hover { background: var(--bg-hover); border-color: var(--border-strong); }

/* Chat View & Compact Header */
.chat-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 44px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.ch-left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ch-left h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}
.ch-right { display: flex; align-items: center; gap: 6px; }
.pop-anchor { position: relative; }
.ctx-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.ctx-pill-btn:hover { border-color: var(--border-strong); color: var(--text); }
.ctx-bar { width: 42px; height: 4px; border-radius: 99px; background: var(--bg-input); overflow: hidden; }
.ctx-fill { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 0.25s; }
.ctx-fill.warn { background: var(--amber); }
.ctx-fill.high { background: var(--red); }

.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 5px;
  box-shadow: var(--shadow);
  z-index: 65;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.popover.pop-up { top: auto; bottom: calc(100% + 8px); left: 0; right: auto; }
.pop-info { padding: 6px 9px; font-size: 11.5px; color: var(--text-dim); border-bottom: 1px solid var(--border); margin-bottom: 3px; }
.pop-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
}
.pop-item:hover { background: var(--bg-hover); }
.pop-item.danger { color: var(--red); }

/* Content Split */
.content-split { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.chat-pane.dragover::after {
  content: "Отпустите файл для прикрепления";
  position: absolute;
  inset: 12px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: rgba(9, 9, 11, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  z-index: 40;
}

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 18px 20px 20px;
}
.feed-inner { max-width: 820px; width: 100%; min-width: 0; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.load-more-wrap { text-align: center; }
.messages-list { display: flex; flex-direction: column; gap: 20px; }
.messages-list > * { flex-shrink: 0; min-width: 0; max-width: 100%; }
.empty-chat {
  margin: 48px auto;
  max-width: 440px;
  text-align: center;
  padding: 28px 22px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
}

/* User Message */
.msg-user-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.msg-user-meta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-dim); padding-right: 4px; }
.msg-user-card {
  max-width: min(84%, 640px);
  background: var(--user-bubble);
  border: 1px solid var(--border-strong);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-files { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.msg-img-thumb {
  max-width: 220px;
  max-height: 150px;
  border-radius: 9px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  object-fit: cover;
}
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
}

/* Assistant Media & Files */
.asst-files-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
  max-width: 100%;
  min-width: 0;
}
.asst-img-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}
.asst-img-grid.single {
  grid-template-columns: minmax(0, 380px);
}
.asst-img-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.asst-img-thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  background: var(--bg-input);
}
.asst-img-grid.single .asst-img-thumb {
  height: auto;
  max-height: 320px;
  object-fit: contain;
}
.asst-img-cap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
}
.asst-img-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.asst-dl-mini {
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex-shrink: 0;
}
.asst-dl-mini:hover { background: var(--bg-hover); color: var(--accent); }
.asst-dl-mini svg, .asst-file-meta svg, .asst-file-ico svg, .btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.asst-video-card, .asst-audio-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  overflow: hidden;
  max-width: 520px;
}
.asst-video {
  width: 100%;
  max-height: 420px;
  display: block;
  background: #000;
}
.asst-audio { width: 100%; display: block; padding: 8px 10px 4px; }
.asst-media-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.asst-file-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  flex-wrap: wrap;
}
.asst-file-main, .asst-file-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}
.asst-file-ico {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}
.asst-file-info { min-width: 0; flex: 1; }
.asst-file-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.asst-file-sub { font-size: 11.5px; color: var(--text-dim); }
.asst-file-acts { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.asst-file-acts a { text-decoration: none; }

.lightbox-wrap { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.lightbox-img { max-width: 100%; max-height: 70vh; border-radius: 10px; background: var(--bg-input); }
.lightbox-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.lightbox-nav, .lightbox-acts { display: flex; align-items: center; gap: 8px; }
.lightbox-acts a { text-decoration: none; }
.lightbox-cnt { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* System Divider */
.sys-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 11.5px;
}
.sys-divider::before, .sys-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.sys-divider.error span { color: var(--red); background: var(--red-soft); padding: 3px 10px; border-radius: 999px; }

/* Assistant Turn (Antigravity open flow) */
.msg-asst-turn { display: flex; flex-direction: column; gap: 9px; min-width: 0; max-width: 100%; }
.asst-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.asst-model { font-weight: 600; color: var(--text-muted); }

/* Trajectory & Interactive Step Accordion */
.traj-details {
  border: 1px solid var(--border);
  background: var(--bg-elev);
  border-radius: 11px;
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}
.traj-summary {
  list-style: none;
  cursor: pointer;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.traj-summary::-webkit-details-marker { display: none; }
.traj-details[open] .traj-summary { border-bottom: 1px solid var(--border); }
.traj-summary::after { content: "▾"; font-size: 11px; color: var(--text-dim); }
.traj-details:not([open]) .traj-summary::after { content: "▸"; }
.traj-list {
  display: block;
  padding: 4px;
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.step-item { border-radius: 8px; overflow: hidden; flex-shrink: 0; margin-bottom: 2px; }
.step-item:last-child { margin-bottom: 0; }
.step-row {
  width: 100%;
  max-width: 100%;
  min-height: 30px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 8px;
  border-radius: 7px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}
.step-row:hover { background: var(--bg-hover); color: var(--text); }
.step-left { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; }
.step-ico { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-dim); display: inline-flex; }
.step-ico.active { color: var(--accent); }
.step-ico.err { color: var(--red); }
.step-ico.ok { color: var(--green); }
.step-lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; max-width: 48%; min-width: 0; font-size: 11px; color: var(--text-dim); }
.step-right > span:not(.step-file-link) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-file-link {
  color: var(--accent);
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--accent-soft);
}
.step-file-link:hover { text-decoration: underline; }
.step-detail-box {
  margin: 2px 8px 6px 28px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  font-size: 11.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.step-cmd { color: #93c5fd; word-break: break-all; }
.step-out { margin: 0; color: #cbd5e1; white-space: pre-wrap; max-height: 180px; overflow-y: auto; font-size: 11.5px; }
.diff-box { display: flex; flex-direction: column; gap: 3px; font-family: ui-monospace, monospace; font-size: 11.5px; }
.diff-del { background: rgba(248, 113, 113, 0.14); color: #fca5a5; padding: 4px 7px; border-radius: 5px; white-space: pre-wrap; max-height: 110px; overflow: auto; }
.diff-add { background: rgba(52, 211, 153, 0.14); color: #6ee7b7; padding: 4px 7px; border-radius: 5px; white-space: pre-wrap; max-height: 110px; overflow: auto; }

.think-details {
  border: 1px solid var(--border);
  background: var(--bg-panel);
  border-radius: 10px;
  font-size: 12px;
}
.think-details summary { cursor: pointer; padding: 6px 11px; color: var(--text-dim); user-select: none; }
.think-body {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  white-space: normal;
  line-height: 1.5;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.think-body .md-body { font-size: 12.5px; color: var(--text-muted); }
.think-body .md-body p { margin: 0 0 8px; }

.asst-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  opacity: 0.72;
  transition: opacity 0.15s;
}
.msg-asst-turn:hover .asst-actions { opacity: 1; }
.act-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  border-radius: 7px;
  padding: 3px 8px;
  font-size: 11.5px;
  cursor: pointer;
}
.act-chip:hover { background: var(--bg-hover); color: var(--text); }
.act-chip svg { width: 12px; height: 12px; }

/* Live Turn inside Stream */
.live-turn {
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.05), transparent 120px), var(--bg-elev);
  border-radius: 14px;
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.lt-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.lt-head-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lt-brand { font-weight: 600; font-size: 13.5px; }
.lt-phase-pill {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.lt-model-pill {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 2px 8px;
  border-radius: 999px;
}
.lt-head-right { display: flex; align-items: center; gap: 8px; }
.lt-timer { font-size: 12px; font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.lt-checklist-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.lt-chk-head { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.lt-chk-bar { height: 4px; border-radius: 99px; background: var(--bg-input); overflow: hidden; }
.lt-chk-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--green)); transition: width 0.3s; }
.lt-checklist { display: flex; flex-direction: column; gap: 4px; }
.chk-row { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); }
.chk-row.in_progress { color: var(--text); font-weight: 600; }
.chk-row.done { color: var(--text-dim); }
.chk-row svg { width: 14px; height: 14px; flex-shrink: 0; }

.lt-subproc {
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 9px;
}
.lt-thinking {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  border-left: 2px solid var(--accent-2);
  padding: 4px 10px;
  background: var(--bg-panel);
  border-radius: 0 8px 8px 0;
}
.lt-writing {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}
.stream-cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--accent);
  vertical-align: middle;
  margin-left: 3px;
  animation: pulse 0.9s infinite;
}

/* Markdown & Syntax Highlight */
.md-body { min-width: 0; max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.md-body > :first-child { margin-top: 0; }
.md-body > :last-child { margin-bottom: 0; }
.md-body p { margin: 0 0 10px; }
.md-body ul, .md-body ol { margin: 0 0 10px; padding-left: 20px; }
.md-body li { margin: 3px 0; }
.md-body h1, .md-body h2, .md-body h3 { margin: 14px 0 6px; font-size: 1.06em; font-weight: 600; }
.md-body a { color: var(--accent); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body blockquote {
  margin: 8px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-panel);
  border-radius: 0 8px 8px 0;
  color: var(--text-muted);
}
.md-body code {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.89em;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.code-block-wrap {
  margin: 9px 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 11px;
  color: #a1a1aa;
}
.copy-code-btn {
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
  color: #e4e4e7;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.copy-code-btn:hover { background: rgba(255, 255, 255, 0.12); }
.code-block-wrap pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  color: #e4e4e7;
  font-size: 12.5px;
  line-height: 1.48;
}
.code-block-wrap pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; overflow-wrap: normal; word-break: normal; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in { color: var(--hljs-kw); }
.hljs-string, .hljs-attr, .hljs-attribute { color: var(--hljs-str); }
.hljs-number, .hljs-literal, .hljs-type { color: var(--hljs-num); }
.hljs-title, .hljs-function, .hljs-section { color: var(--hljs-fn); }
.hljs-comment, .hljs-quote { color: var(--hljs-com); font-style: italic; }

/* Unified Antigravity Composer */
.composer-shell {
  padding: 6px calc(20px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background: linear-gradient(180deg, transparent, var(--bg) 24%);
}
.composer-inner { max-width: 820px; margin: 0 auto; position: relative; }
.composer-card {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  padding: 8px 10px 7px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  transition: border-color 0.15s;
}
.composer-card:focus-within { border-color: rgba(96, 165, 250, 0.55); }
.attach-strip { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 7px; }
.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 12px;
}
.att-chip button { border: none; background: transparent; color: var(--text-dim); cursor: pointer; padding: 0 2px; }
.composer-card textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.48;
  resize: none;
  outline: none;
  max-height: 165px;
  padding: 3px 4px 6px;
}
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 4px; border-top: 1px solid var(--border); }
.cb-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cb-right { display: flex; align-items: center; gap: 6px; }
.cb-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.cb-icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.cb-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.cb-pill:hover { background: var(--bg-hover); color: var(--text); }
.cb-pill.plan-on { background: var(--amber-soft); color: var(--amber); border-color: rgba(251, 191, 36, 0.35); }
.cb-model-pill { color: var(--text); max-width: 175px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.once-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 7px;
  padding: 2px 7px;
  font-size: 11.5px;
  font-weight: 500;
}
.once-pill button { border: none; background: transparent; color: inherit; cursor: pointer; padding: 0; }

.cb-stop-btn {
  border: 1px solid rgba(248, 113, 113, 0.38);
  background: var(--red-soft);
  color: var(--red);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.cb-send-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}
.cb-send-btn:hover { filter: brightness(1.1); }
.cb-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.cb-send-btn svg { width: 15px; height: 15px; }

/* Model Popover & Slash Menu */
.model-pop { width: 310px; max-height: 380px; padding: 7px; }
.mp-scope-row { display: flex; gap: 4px; background: var(--bg-input); border-radius: 8px; padding: 3px; margin-bottom: 6px; }
.mp-scope-row .seg-btn { flex: 1; text-align: center; }
.mp-list { overflow-y: auto; -webkit-overflow-scrolling: touch; max-height: 315px; display: flex; flex-direction: column; gap: 2px; }
.mp-group { flex-shrink: 0; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); padding: 6px 8px 2px; }
.mp-opt {
  flex-shrink: 0;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.mp-opt:hover { background: var(--bg-hover); }
.mp-opt.active { background: var(--accent-soft); }
.mp-opt-title { font-size: 12.5px; font-weight: 600; display: flex; justify-content: space-between; }
.mp-opt-desc { font-size: 11px; color: var(--text-dim); }

.slash-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  width: min(340px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  padding: 5px;
  box-shadow: var(--shadow);
  z-index: 60;
}
.slash-opt {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 7px;
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}
.slash-opt:hover, .slash-opt.active { background: var(--bg-hover); }
.slash-opt span:last-child { color: var(--text-dim); font-size: 11.5px; }

/* Right Inspector */
.inspector-pane {
  width: 326px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 45;
}
.inspector-pane.collapsed { display: none; }
.insp-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(7px + var(--safe-top)) calc(10px + var(--safe-right)) 7px 10px;
  border-bottom: 1px solid var(--border);
}
.insp-tabs { display: flex; gap: 4px; background: var(--bg-input); padding: 2px; border-radius: 8px; border: 1px solid var(--border); flex: 1; }
.insp-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.insp-tab.active { background: var(--bg-card); color: var(--text); font-weight: 600; }
.insp-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) 12px; display: flex; flex-direction: column; gap: 10px; }
.insp-body > * { flex-shrink: 0; }
.insp-sec-lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-dim); }
.insp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  font-size: 12.5px;
  cursor: pointer;
}
.insp-item:hover { border-color: var(--accent); background: var(--bg-hover); }
.insp-item-main { display: flex; align-items: center; gap: 7px; min-width: 0; flex: 1; }
.insp-item-main svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-dim); }
.insp-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.act-badge { font-size: 10.5px; padding: 1px 6px; border-radius: 999px; background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); }
.act-badge.edited { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); }
.act-badge.created { color: var(--green); border-color: rgba(52, 211, 153, 0.35); }

/* Modals & Command Palette */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 10, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  z-index: 85;
}
.modal-box {
  width: 100%;
  max-width: 520px;
  max-height: 86vh;
  max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  box-shadow: var(--shadow);
  padding: 15px 17px;
}
.modal-box.modal-wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-head-acts { display: flex; align-items: center; gap: 6px; }
.modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: 12px; display: flex; flex-direction: column; gap: 11px; }
.modal-body > * { flex-shrink: 0; }
.modal-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 14px;
  outline: none;
}

.file-viewer-pre {
  margin: 0;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  overflow: auto;
  max-height: 68vh;
  font-size: 12.5px;
  line-height: 1.5;
  color: #e4e4e7;
}

.cmdk-box {
  width: 100%;
  max-width: 560px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  align-self: flex-start;
  margin-top: min(12vh, 90px);
}
.cmdk-input-wrap { display: flex; align-items: center; gap: 9px; padding: 11px 14px; border-bottom: 1px solid var(--border); }
.cmdk-input-wrap svg { width: 16px; height: 16px; color: var(--text-dim); }
.cmdk-input-wrap input { flex: 1; border: none; background: transparent; color: var(--text); font-size: 14.5px; outline: none; }
.cmdk-input-wrap kbd { font-size: 11px; color: var(--text-dim); border: 1px solid var(--border); padding: 2px 6px; border-radius: 5px; }
.cmdk-list { max-height: 360px; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; }
.cmdk-row {
  flex-shrink: 0;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  text-align: left;
  font-size: 13px;
}
.cmdk-row:hover, .cmdk-row.active { background: var(--bg-hover); }

.quota-group { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 11px; padding: 11px 13px; }
.quota-gtitle { font-weight: 600; margin-bottom: 8px; }
.quota-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.quota-row:last-child { margin-bottom: 0; }
.quota-labels { display: flex; justify-content: space-between; font-size: 12.5px; }
.quota-bar { height: 6px; border-radius: 99px; background: var(--bg-input); overflow: hidden; }
.quota-bar-fill { height: 100%; background: var(--green); }
.quota-bar-fill.mid { background: var(--amber); }
.quota-bar-fill.low { background: var(--red); }

.toast {
  position: fixed;
  bottom: calc(82px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 95;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast-act {
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.mobile-only { display: none; }
.desktop-only { display: inline-flex; }
.drawer-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.58); z-index: 40; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
@keyframes sparkPulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.16); opacity: 0.72; } }

@media (max-width: 1179px) {
  .inspector-pane {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(88vw, 350px);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    display: flex;
  }
  .inspector-pane.collapsed { display: flex; }
  .inspector-pane.mobile-open { transform: translateX(0); }
  #inspectorToggleBtn { display: none; }
  #mobileInspBtn, #inspCloseBtn { display: inline-flex; }
}

@media (max-width: 899px) {
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(86vw, 310px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .chat-header { padding: 0 10px; }
  .ch-left h2 { max-width: 170px; }
  .messages-scroll { padding: 12px 11px 14px; }
  .msg-user-card { max-width: 91%; }
  .composer-shell { padding: 4px calc(10px + var(--safe-right)) calc(10px + var(--safe-bottom)) calc(10px + var(--safe-left)); }
  .mission-view { padding: 14px calc(14px + var(--safe-right)) calc(14px + var(--safe-bottom)) calc(14px + var(--safe-left)); }
  .cb-model-pill { max-width: 132px; }
  .model-pop { width: min(300px, calc(100vw - 24px)); }
  .scroll-bottom-btn { right: calc(14px + var(--safe-right)); bottom: calc(102px + var(--safe-bottom)); }
}

/* ====== Расширения v2: теги, превью, поиск, diff, очередь, медиа, голос, телеметрия ====== */

.tag-filter-row {
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-top: 2px;
}
.tag-filter-row::-webkit-scrollbar { display: none; }
.tag-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.tag-chip:hover { border-color: var(--border-strong); color: var(--text); }
.tag-chip.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(96, 165, 250, 0.35); font-weight: 600; }

.ci-badges { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.ci-tag {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  max-width: 72px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ci-draft {
  font-size: 10px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 600;
}
.ci-preview {
  padding-left: 17px;
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ci-preview b { color: var(--text-dim); font-weight: 500; }

.inchat-search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  flex-shrink: 0;
}
.inchat-search input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 7px;
  padding: 5px 9px;
  font-size: 13px;
  outline: none;
}
.inchat-search input:focus { border-color: var(--accent); }
.inchat-cnt { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 34px; text-align: center; }

.sse-banner {
  background: var(--amber-soft);
  color: var(--amber);
  border-bottom: 1px solid rgba(251, 191, 36, 0.3);
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  flex-shrink: 0;
}

.scroll-bottom-btn {
  position: absolute;
  right: 22px;
  bottom: calc(112px + var(--safe-bottom));
  z-index: 35;
  height: 36px;
  min-width: 36px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
}
.scroll-bottom-btn:hover { border-color: var(--accent); color: var(--accent); }
.sb-new-badge {
  font-size: 11px;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 999px;
}

.queue-bar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
  padding: 7px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
}
.queue-head { font-size: 11px; font-weight: 600; color: var(--amber); text-transform: uppercase; letter-spacing: 0.04em; }
.queue-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
}
.queue-chip-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.queue-chip-rm {
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0 4px;
  font-size: 14px;
}
.queue-chip-rm:hover { color: var(--red); }

.msg-user-wrap.optimistic { opacity: 0.72; }
.msg-user-acts {
  display: flex;
  gap: 6px;
  margin-top: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}
.msg-user-wrap:hover .msg-user-acts { opacity: 1; }
@media (hover: none) {
  .msg-user-acts { opacity: 0.75; }
}
.act-chip-xs {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 4px;
}
.act-chip-xs:hover { color: var(--text); background: var(--bg-hover); }

.btn-exec-plan {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(96, 165, 250, 0.45);
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-exec-plan:hover { filter: brightness(1.1); }

.msg-flash {
  animation: msgFlash 1.8s ease;
}
@keyframes msgFlash {
  0%, 25% { box-shadow: 0 0 0 2px var(--accent); border-radius: 10px; background: var(--accent-soft); }
  100% { box-shadow: none; background: transparent; }
}

.diff-table {
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: auto;
  max-height: 260px;
  background: var(--code-bg);
  font-family: ui-monospace, monospace;
  font-size: 11.5px;
  line-height: 1.45;
}
.diff-line {
  display: flex;
  gap: 8px;
  padding: 1px 8px;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-line.del { background: rgba(248, 113, 113, 0.14); color: #fca5a5; }
.diff-line.add { background: rgba(52, 211, 153, 0.14); color: #6ee7b7; }
.diff-line.ctx { color: #94a3b8; }
.diff-sig { user-select: none; opacity: 0.75; flex-shrink: 0; width: 10px; }

.voice-btn.recording {
  color: #fff;
  background: var(--red);
  animation: pulse 1s infinite;
}

.insp-media-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}
.insp-media-thumb {
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow: hidden;
  background: var(--bg-panel);
  cursor: pointer;
}
.insp-media-thumb img {
  width: 100%;
  height: 92px;
  object-fit: cover;
  display: block;
}
.insp-media-cap {
  padding: 4px 6px;
  font-size: 10.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-mode-bar {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.md-preview-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  max-height: 68vh;
  overflow-y: auto;
}

.mc-sec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.mc-sys-wrap { display: flex; flex-direction: column; gap: 10px; }
.mc-sys-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(195px, 1fr)); gap: 10px; }
.mc-sys-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mc-sys-lbl { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.mc-sys-val { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.mc-sys-sub { font-size: 11.5px; color: var(--text-muted); }
.mc-svc-row { display: flex; flex-wrap: wrap; gap: 6px; }
.mc-svc-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text-muted);
}
.mc-svc-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.mc-svc-dot.down { background: var(--red); }

.cmdk-sec-lbl {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding: 7px 10px 3px;
}

.tag-presets-row { display: flex; flex-wrap: wrap; gap: 6px; }
.insp-item-acts { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.diff-mini-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--accent);
  border-radius: 6px;
  padding: 1px 6px;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}
.diff-mini-btn:hover { border-color: var(--accent); }

.icon-btn.notify-need-push { position: relative; }
.icon-btn.notify-need-push::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 2px var(--bg-elev);
}
