*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --sidebar-bg: #161b27;
  --border: rgba(255,255,255,0.08);
  --text: #e2e8f0;
  --text-dim: #7a8498;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --code-bg: #1e2535;
  --user-bg: #1e3a5f;
  --assistant-bg: #161b27;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body { height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; color-scheme: dark; }

.layout { display: flex; height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width, 260px);
  min-width: 180px;
  max-width: min(520px, 50vw);
  flex-shrink: 0;
  position: relative;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 12px;
  gap: 0;
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
  touch-action: none;
}
.sidebar-resizer:hover,
.sidebar-resizer.active {
  background: rgba(59, 130, 246, 0.35);
}
body.resizing-sidebar {
  cursor: col-resize !important;
  user-select: none;
}
body.resizing-sidebar * {
  cursor: col-resize !important;
}

.sidebar-content {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-right: 2px;
}

.sidebar-section-project {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-logo-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.sidebar-actions {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.logo-text { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }

.sidebar-section { margin-bottom: 18px; }

.section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.proj-row { display: flex; gap: 5px; align-items: center; }

.proj-select {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  background-color: #121820;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  appearance: auto;
  color-scheme: dark;
}
.proj-select:focus { outline: none; border-color: rgba(59,130,246,0.5); }
.proj-select option {
  background-color: #1a2030;
  color: #e2e8f0;
}

.proj-plus, .proj-folder {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(59,130,246,0.1);
  color: var(--accent);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s, opacity 0.15s;
}
.proj-plus:hover, .proj-folder:hover:not(:disabled) { background: rgba(59,130,246,0.2); }
.proj-folder:disabled {
  opacity: 0.35;
  cursor: default;
}

.proj-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.proj-action-btn {
  flex: 1 1 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 6px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.proj-action-btn:hover { background: rgba(59,130,246,0.12); color: var(--accent); }

.proj-path {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  word-break: break-all;
  line-height: 1.4;
  flex-shrink: 0;
  max-height: 2.6em;
  overflow: hidden;
}

/* File tree */
.proj-tree-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin-top: 6px;
  overflow: auto;
  border-radius: 8px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border);
  padding: 6px;
  box-sizing: border-box;
}
.proj-tree-wrap:empty { display: none; }
.proj-tree { list-style: none; padding: 0; margin: 0; }
.proj-tree .proj-tree { margin-left: 12px; border-left: 1px solid var(--border); padding-left: 6px; margin-top: 2px; }
.proj-item { margin: 0; }
.proj-dir, .proj-file {
  display: block;
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 12px;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
}
.proj-dir {
  color: #94a3b8;
  font-weight: 500;
  cursor: pointer;
}
.proj-dir:hover { background: rgba(255,255,255,0.04); }
.proj-dir::before { content: "▸ "; font-size: 9px; opacity: .7; }
.proj-dir.expanded::before { content: "▾ "; }
.proj-tree-children { display: none; }
.proj-tree-children.open { display: block; }
.proj-file { color: var(--text-dim); cursor: pointer; }
.proj-file:hover { color: var(--accent); background: rgba(59,130,246,0.08); }
.proj-tree-empty { font-size: 12px; color: var(--text-dim); padding: 4px; }

/* API key */
.key-input {
  width: 100%;
  padding: 8px 10px;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  margin-bottom: 6px;
}
.key-input:focus { outline: none; border-color: rgba(59,130,246,0.5); }

.save-btn {
  width: 100%;
  padding: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.save-btn:hover { background: var(--accent-hover); }

.ext-link { font-size: 12px; color: var(--accent); text-decoration: none; display: block; margin-top: 4px; }
.ext-link:hover { text-decoration: underline; }

.sidebar-bottom {
  flex: 0 0 auto;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.usage-block {
  margin-bottom: 14px;
}
.usage-pools {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.usage-empty {
  margin: 0;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.4;
}
.usage-pool-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
}
.usage-pool-label-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.usage-pool-label {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.usage-pool-hint {
  font-size: 9px;
  color: var(--text-dim);
  opacity: 0.85;
  line-height: 1.2;
}
.usage-login-btn {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(59,130,246,0.35);
  border-radius: 8px;
  background: rgba(59,130,246,0.12);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}
.usage-login-btn:hover { background: rgba(59,130,246,0.2); }
.usage-pool-pct {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  flex: 0 0 auto;
}
.usage-bar {
  height: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  overflow: hidden;
}
.usage-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.35s ease;
}
.usage-bar-fill.warn { background: #f59e0b; }
.usage-bar-fill.danger { background: #ef4444; }
.usage-pool-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--text-dim);
}
.usage-reset {
  margin: 2px 0 0;
  font-size: 10px;
  color: var(--text-dim);
}
.new-chat-btn {
  width: 100%;
  padding: 10px;
  background: rgba(59,130,246,0.1);
  border: 1px dashed rgba(59,130,246,0.3);
  border-radius: 8px;
  color: var(--accent);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: rgba(59,130,246,0.2); }
.new-window-btn {
  width: 100%;
  margin-top: 8px;
  padding: 9px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.new-window-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }

/* ── Main ── */
.main { flex: 1 1 auto; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-height: 48px;
}
.chat-title { font-size: 14px; font-weight: 600; color: var(--text-dim); }

/* Вкладки диалогов */
.chat-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  overflow-x: auto;
  min-width: 0;
}
.chat-tabs::-webkit-scrollbar { height: 0; }
.chat-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  max-width: 180px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.chat-tab:hover { background: rgba(255,255,255,0.04); }
.chat-tab.active { background: rgba(255,255,255,0.08); color: var(--text); }
.chat-tab-title { overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
.chat-tab-close {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0.55;
  padding: 0 2px;
}
.chat-tab-close:hover { opacity: 1; }
.chat-tab-add {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 8px;
  border-radius: 6px;
  flex: 0 0 auto;
}
.chat-tab-add:hover { background: rgba(255,255,255,0.06); color: var(--text); }

/* Хост контейнеров сообщений (по одному на диалог) */
.messages-host { flex: 1 1 auto; display: flex; overflow: hidden; }
.messages-host .messages { flex: 1 1 auto; }

.streaming-status {
  position: relative;
  flex: 0 0 auto;
  margin-left: 12px;
  animation: streaming-enter 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.streaming-status.hidden { display: none !important; }

.streaming-status-glow {
  position: absolute;
  inset: -1px;
  border-radius: 999px;
  background: linear-gradient(120deg, rgba(59,130,246,0.55), rgba(139,92,246,0.45), rgba(59,130,246,0.55));
  background-size: 200% 200%;
  animation: streaming-glow 2.4s ease infinite;
  opacity: 0.85;
}

.streaming-status-body {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px 7px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(22, 28, 42, 0.98), rgba(16, 20, 32, 0.98));
  border: 1px solid rgba(96, 165, 250, 0.22);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.streaming-status-body::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255,255,255,0.07) 50%, transparent 65%);
  transform: translateX(-120%);
  animation: streaming-shine 2.2s ease-in-out infinite;
  pointer-events: none;
}

.streaming-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(96, 165, 250, 0.22);
  border-top-color: #60a5fa;
  animation: streaming-spin 0.75s linear infinite;
  flex: 0 0 auto;
}

.streaming-status-text {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: #cbd5e1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.streaming-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 2px;
}
.streaming-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #60a5fa;
  animation: streaming-dot 1.2s ease-in-out infinite;
}
.streaming-dots i:nth-child(2) { animation-delay: 0.15s; }
.streaming-dots i:nth-child(3) { animation-delay: 0.3s; }

.streaming-stop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 2px;
  padding: 5px 10px 5px 8px;
  border: 1px solid rgba(248, 113, 113, 0.28);
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.streaming-stop:hover {
  background: rgba(239, 68, 68, 0.22);
  border-color: rgba(248, 113, 113, 0.45);
  transform: translateY(-1px);
}
.streaming-stop-icon {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.45);
}

@keyframes streaming-enter {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes streaming-glow {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}
@keyframes streaming-shine {
  0%, 75% { transform: translateX(-120%); }
  100% { transform: translateX(120%); }
}
@keyframes streaming-spin {
  to { transform: rotate(360deg); }
}
@keyframes streaming-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-3px); opacity: 1; }
}

/* legacy */
.stop-btn {
  padding: 5px 14px;
  background: rgba(239,68,68,0.15);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

/* Кнопки в шапке сайдбара */
.sidebar-icon-btn {
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-icon-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); }

/* Меню действий */
.actions-menu-btn {
  padding: 6px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.actions-menu-btn:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.actions-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--panel, #232838);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  padding: 4px;
  min-width: 180px;
  z-index: 100;
}
.actions-menu.hidden { display: none; }
.actions-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  border-radius: 6px;
  text-align: left;
}
.actions-menu-item:hover { background: rgba(255,255,255,0.08); }
.actions-menu-item svg { flex-shrink: 0; opacity: 0.7; }
.stop-btn:hover { background: rgba(239,68,68,0.25); }
.hidden { display: none !important; }

/* Messages */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Welcome */
.welcome { text-align: center; margin: auto; max-width: 500px; padding: 40px 20px; }
.welcome-icon { font-size: 52px; margin-bottom: 12px; }
.welcome h2 { font-size: 22px; margin-bottom: 8px; }
.welcome p { color: var(--text-dim); line-height: 1.6; margin-bottom: 20px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestion {
  padding: 8px 14px;
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 20px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.suggestion:hover { background: rgba(59,130,246,0.18); }

/* Message bubbles */
.msg { display: flex; flex-direction: column; gap: 2px; padding: 4px 0; }
.msg-header { font-size: 11px; font-weight: 600; color: var(--text-dim); padding: 0 4px; }
.msg-body {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.65;
  max-width: min(860px, 100%);
  box-sizing: border-box;
}
.msg.user .msg-body {
  background: var(--user-bg);
  border: 1px solid rgba(59,130,246,0.2);
  align-self: flex-end;
  max-width: 75%;
  width: fit-content;
}
.msg.assistant .msg-body {
  background: var(--assistant-bg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: min(860px, 100%);
  overflow: hidden;
}
.msg.assistant .answer {
  max-width: 100%;
  min-width: 0;
}
.msg.assistant .answer-text {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Markdown */
.msg-body p { margin: 0 0 8px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body ul, .msg-body ol { padding-left: 20px; margin: 6px 0; }
.msg-body li { margin-bottom: 3px; }
.msg-body h1,.msg-body h2,.msg-body h3 { margin: 12px 0 6px; }
.msg-body strong { color: #e2e8f0; font-weight: 600; }
.msg-body em { font-style: italic; }
.msg-body del { color: var(--text-dim); text-decoration: line-through; }
.msg-body a { color: var(--accent); }
.msg-body code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: "Fira Code", "Consolas", monospace;
  font-size: 12.5px;
}

/* Code blocks */
.msg-body pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}
.msg-body pre code { background: none; padding: 0; font-size: 13px; }

/* Copy + file badge on pre */
.code-wrap { position: relative; margin: 10px 0; }
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-dim);
}
.code-header .file-name { color: #60a5fa; font-weight: 500; }
.code-copy {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 4px;
}
.code-copy:hover { background: rgba(255,255,255,0.07); color: var(--text); }
.code-wrap pre { border-radius: 0 0 8px 8px; margin: 0; }
.code-wrap.streaming pre {
  min-height: 2.4em;
}
.code-wrap.streaming pre code::after {
  content: "▋";
  margin-left: 2px;
  opacity: 0.45;
  animation: codeCaret 1s step-end infinite;
}
@keyframes codeCaret {
  50% { opacity: 0; }
}

/* Files saved bar */
.files-saved-bar {
  margin: 0 20px 8px;
  padding: 10px 16px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 8px;
  font-size: 13px;
  color: #4ade80;
  animation: fadeIn .3s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Think box (рассуждения модели) */
.think-box {
  margin-bottom: 10px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
}
.think-label {
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 4px;
  cursor: pointer;
  user-select: none;
}
.think-label:hover { color: var(--text); }
.think-text {
  color: #8a94a8;
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 460px;
  overflow-y: auto;
}
.think-box.collapsed { opacity: 0.7; }
.think-box.collapsed .think-text {
  max-height: 34px;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, #000 40%, transparent);
}

/* Модальное окно ввода */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--panel, #232838);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  width: 340px;
  max-width: 90vw;
  box-shadow: 0 12px 40px rgba(0,0,0,0.4);
}
.modal-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.modal-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 14px;
  box-sizing: border-box;
}
.modal-input:focus { outline: none; border-color: var(--accent, #6366f1); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.modal-btn.ok { background: var(--accent, #6366f1); border-color: var(--accent, #6366f1); color: #fff; }
.modal-btn:hover { filter: brightness(1.1); }

/* Thinking indicator */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 10px 16px;
}
.dots span {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot 1.2s infinite;
}
.dots span:nth-child(2) { animation-delay: .2s; }
.dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot { 0%,80%,100% { opacity: .2; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* Input area */
.input-wrap {
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.input-wrap.drag-over {
  background: rgba(59, 130, 246, 0.06);
  box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.35);
}
.input-wrap.drag-over .message-input {
  border-color: rgba(59, 130, 246, 0.5);
}
.input-area {
  padding: 12px 20px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

/* Attach button */
.attach-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.attach-btn:hover { background: rgba(59,130,246,0.12); color: var(--accent); }

/* Attachment preview */
.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 20px 0;
}
.attach-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.attach-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-remove:hover { background: #ef4444; }

/* Images in message bubble */
.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.msg-images img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}
/* Сгенерированные картинки в ответе ассистента */
.gen-images {
  margin-bottom: 10px;
  max-width: 100%;
}
.gen-images:empty {
  display: none;
  margin: 0;
}
.gen-images .gen-image {
  max-width: 100%;
}
.gen-images .gen-image img {
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  cursor: zoom-in;
}
.gen-images .gen-image img:hover {
  border-color: rgba(59,130,246,0.4);
}

/* Лайтбокс — просмотр фото на весь экран */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  box-sizing: border-box;
}
.image-lightbox.hidden { display: none !important; }
.image-lightbox .lightbox-img {
  max-width: min(96vw, 1400px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}
.image-lightbox .lightbox-close {
  position: fixed;
  top: 16px;
  right: 20px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.image-lightbox .lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}
.attach-preview img { cursor: zoom-in; }
.message-input {
  flex: 1 1 auto;
  padding: 12px 16px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  resize: none;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}
.message-input:focus { outline: none; border-color: rgba(59,130,246,0.5); }
.message-input::placeholder { color: var(--text-dim); }

.send-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
.send-btn-icon { display: flex; align-items: center; justify-content: center; }
.send-btn-spinner {
  display: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #fff;
  animation: streaming-spin 0.75s linear infinite;
}
.send-btn.loading .send-btn-icon { display: none; }
.send-btn.loading .send-btn-spinner { display: block; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled:not(.loading) { background: #374151; cursor: default; }
.send-btn.loading,
.send-btn:disabled.loading {
  background: var(--accent);
  opacity: 0.92;
  cursor: wait;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
