/* ── RESET ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0d1117;
  --bg-soft:    #161b22;
  --bg-hover:   #1c2128;
  --bg-side:    #0a0d12;
  --panel:      #21262d;
  --border:     #30363d;
  --border-soft:#21262d;
  --text:       #e6edf3;
  --text-dim:   #8b949e;
  --text-muted: #6e7681;
  --text-faint: #484f58;
  --accent:     #58a6ff;
  --accent-2:   #1f6feb;
  --send:       #238636;
  --send-hover: #2ea043;
  --danger:     #f85149;
  --code-inline:#ff7b72;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg); color: var(--text);
  height: 100vh; overflow: hidden; display: flex;
  font-size: 14px;
}

.hidden { display: none !important; }

/* ── LOGIN ─────────────────────────────────────────────────────────────────── */
#login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
#login-box {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 14px;
  padding: 36px 32px; width: 340px; display: flex; flex-direction: column; gap: 12px;
}
#login-box h2 { text-align: center; color: var(--accent); font-size: 22px; margin-bottom: 4px; }
#login-box input {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 13px; color: var(--text); font-size: 14px; outline: none;
  transition: border-color .15s;
}
#login-box input:focus { border-color: var(--accent); }
#send-code-btn, #login-btn {
  background: var(--accent-2); border: none; border-radius: 8px; padding: 11px;
  color: #fff; font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background .15s;
}
#send-code-btn:hover, #login-btn:hover { background: #388bfd; }
#send-code-btn:disabled, #login-btn:disabled { opacity: .6; cursor: not-allowed; }
#back-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 9px;
  color: var(--text-muted); font-size: 13px; cursor: pointer; transition: border-color .15s;
}
#back-btn:hover { border-color: var(--accent); color: var(--text); }
.otp-hint { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0; }
#login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ── APP ──────────────────────────────────────────────────────────────────── */
#app { display: flex; width: 100vw; height: 100vh; }

/* ── SIDEBAR ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: 270px; min-width: 270px;
  background: var(--bg-side);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column; overflow: hidden;
  transition: width .2s, min-width .2s, margin-left .2s;
}
#sidebar.collapsed { width: 0; min-width: 0; margin-left: -1px; border-right: none; }

#sidebar-top {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 10px 4px;
}
#btn-collapse, #btn-expand {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
#btn-collapse:hover, #btn-expand:hover { background: var(--bg-soft); color: var(--text); }

#btn-new-chat {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text); font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .12s;
  text-align: left;
  text-decoration: none;
}
#btn-new-chat:hover { background: var(--bg-soft); }
#btn-new-chat svg { opacity: .7; flex-shrink: 0; }
#btn-new-chat span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#btn-projects {
  display: flex; align-items: center; gap: 8px;
  margin: 2px 10px 2px;
  padding: 8px 12px;
  background: transparent; border: none; border-radius: 8px;
  color: var(--text-dim); font-size: 13.5px; cursor: pointer;
  transition: background .12s, color .12s;
}
#btn-projects:hover { background: var(--bg-soft); color: var(--text); }
#btn-projects svg { opacity: .6; flex-shrink: 0; }
#btn-projects span:first-of-type { flex: 1; text-align: left; }

.badge-soon {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-faint); border: 1px solid var(--border); border-radius: 999px;
  padding: 1px 6px; flex-shrink: 0;
}

.section-label {
  padding: 14px 16px 6px;
  font-size: 11px; font-weight: 600; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .5px;
}

#dialogs-section { flex: 1; overflow-y: auto; padding: 0 8px 8px; }

.dialog-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px; cursor: pointer;
  color: var(--text-dim); font-size: 13px; margin-bottom: 1px;
  transition: background .1s, color .1s;
  min-width: 0; position: relative;
  text-decoration: none;  /* for <a> */
}
.dialog-item:hover { background: var(--bg-soft); color: var(--text); }
.dialog-item.active { background: var(--panel); color: var(--text); }
.dialog-item .d-icon  { font-size: 13px; opacity: .5; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.dialog-item .d-src {
  font-size: 9.5px; font-weight: 600; letter-spacing: .3px;
  padding: 2px 6px; border-radius: 5px; line-height: 1;
  background: var(--panel); color: var(--text-dim);
  flex-shrink: 0; text-transform: uppercase;
}
.dialog-item .d-src-web { background: rgba(88,166,255,.15); color: #79b8ff; }
.dialog-item .d-src-tg  { background: rgba(56,139,253,.12); color: var(--accent); }
.dialog-item .d-src-uni { background: rgba(188,140,255,.16); color: #bc8cff; }
.dialog-item .d-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-item .d-count { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }

/* "..." button — absolutely positioned over the count, hidden until hover */
.d-menu-btn {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 5px;
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); padding: 0;
  opacity: 0; pointer-events: none;
  transition: opacity .1s, background .1s, color .1s;
}
.d-menu-btn:hover { background: rgba(255,255,255,.1); color: var(--text); }
.dialog-item .d-count { transition: opacity .1s; }
.dialog-item:hover .d-count,
.dialog-item.ctx-open .d-count { opacity: 0; }
.dialog-item:hover .d-menu-btn,
.dialog-item.ctx-open .d-menu-btn { opacity: 1; pointer-events: auto; }

/* Dialog context menu (Rename / Delete) */
#dialog-ctx-menu {
  position: fixed;
  min-width: 170px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 300;
  display: flex; flex-direction: column;
}
#dialog-ctx-menu.hidden { display: none; }
#dialog-ctx-menu button {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; border-radius: 7px;
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 13px; text-align: left;
  transition: background .1s, color .1s; width: 100%;
}
#dialog-ctx-menu button:hover { background: var(--panel); }
#dialog-ctx-menu .dctx-delete:hover { color: var(--danger); }

/* ── RENAME MODAL ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 400;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 14px; padding: 24px 24px 20px;
  min-width: 320px; max-width: 460px; width: 90%;
  box-shadow: 0 16px 48px rgba(0,0,0,.65);
}
.modal-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 14px; }
.modal-input {
  width: 100%; background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; box-sizing: border-box;
  color: var(--text); font-size: 14px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-btn-cancel {
  padding: 7px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text); font-size: 13.5px; cursor: pointer;
  transition: background .1s;
}
.modal-btn-cancel:hover { background: var(--panel); }
.modal-btn-save {
  padding: 7px 16px; border-radius: 8px; border: none;
  background: #e6edf3; color: #0d1117; font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .1s;
}
.modal-btn-save:hover { background: #fff; }

/* ── SIDEBAR FOOTER / USER MENU ──────────────────────────────────────────── */
#sidebar-footer {
  padding: 8px; border-top: 1px solid var(--border-soft);
  position: relative;
}
#btn-user {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: 10px;
  background: none; border: none; color: var(--text); cursor: pointer;
  transition: background .12s;
}
#btn-user:hover { background: var(--bg-soft); }
#btn-user svg { opacity: .5; flex-shrink: 0; }

.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  text-transform: uppercase;
}
.user-name {
  flex: 1; text-align: left; font-size: 13.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

#user-menu {
  position: absolute; left: 8px; right: 8px; bottom: 60px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: flex; flex-direction: column;
  z-index: 10;
}
#user-menu button {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 7px;
  background: none; border: none; color: var(--text); font-size: 13px;
  cursor: pointer; text-align: left; width: 100%;
  transition: background .1s, color .1s;
}
#user-menu button:hover:not(:disabled) { background: var(--panel); }
#user-menu button:disabled { color: var(--text-muted); cursor: not-allowed; }
#user-menu button svg { opacity: .6; flex-shrink: 0; }
#user-menu #btn-logout:hover { color: var(--danger); }

/* ── MAIN ─────────────────────────────────────────────────────────────────── */
#main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; background: var(--bg);
}

/* topbar */
#topbar {
  height: 48px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
}
#btn-expand {
  width: 32px; height: 32px; border-radius: 8px;
}
#chat-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 60%;
}
#topbar-spacer { flex: 1; }

#btn-memory, #btn-gen-settings, #btn-files, #btn-incognito {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
  flex-shrink: 0;
  text-decoration: none;
}
#btn-memory:hover, #btn-gen-settings:hover, #btn-files:hover, #btn-incognito:hover {
  background: var(--bg-soft); color: var(--text);
}
#btn-files.active, #btn-gen-settings.active { background: var(--panel); color: var(--text); }

/* Incognito-toggle: подсветка active и disabled state. */
#btn-incognito.active { background: rgba(155, 89, 182, 0.18); color: #c084fc; }
#btn-incognito.active:hover { background: rgba(155, 89, 182, 0.28); }
#btn-incognito:disabled {
  opacity: 0.35; cursor: not-allowed; pointer-events: none;
}

/* Visual indicator активного incognito-режима: пурпурный бордюр вокруг
   chat-area + бейдж в topbar. Сигнал юзеру что чат не пишется на диск. */
body.incognito #main { box-shadow: inset 0 0 0 2px rgba(155, 89, 182, 0.45); }
body.incognito #topbar {
  background: linear-gradient(180deg, rgba(155, 89, 182, 0.10), transparent);
}
body.incognito #chat-title::after {
  content: "🕶 Incognito";
  margin-left: 10px; padding: 2px 8px;
  background: rgba(155, 89, 182, 0.20); color: #c084fc;
  border-radius: 8px; font-size: 11px; font-weight: 500;
  vertical-align: middle;
}

/* context info pill in topbar */
#context-info {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-dim);
  padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 999px;
  cursor: help; user-select: none;
  transition: background .12s, color .12s, border-color .12s;
  white-space: nowrap;
}
#context-info:hover { background: var(--bg-soft); color: var(--text); }
#context-info .ctx-sep { color: var(--text-faint); }
#context-info .ctx-unit { color: var(--text-faint); font-size: 11px; }
#ctx-bar {
  width: 56px; height: 4px;
  background: var(--panel); border-radius: 2px; overflow: hidden;
}
#ctx-bar-fill {
  height: 100%; width: 0%;
  background: var(--accent);
  transition: width .25s, background .25s;
}
#context-info.warn { border-color: rgba(240,136,62,.4); }
#context-info.warn #ctx-bar-fill { background: #f0883e; }
#context-info.danger { border-color: rgba(248,81,73,.4); color: var(--danger); }
#context-info.danger #ctx-bar-fill { background: var(--danger); }

/* "show more" button used in dialog list */
#dialogs-more {
  margin: 6px 8px 4px;
  padding: 7px 10px;
  background: transparent; border: 1px dashed var(--border-soft);
  border-radius: 8px;
  color: var(--text-faint); font-size: 12px; cursor: pointer;
  text-align: center;
  transition: background .12s, color .12s, border-color .12s;
}
#dialogs-more:hover { background: var(--bg-soft); color: var(--text-dim); border-color: var(--border); }
#dialogs-more:disabled { opacity: .5; cursor: default; }

/* messages scroll */
#messages-wrap { flex: 1; overflow-y: auto; min-height: 0; }
#messages {
  max-width: 760px; margin: 0 auto;
  padding: 36px 28px 8px;
  display: flex; flex-direction: column;
  min-height: 100%;
}

/* empty state */
#empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
}
#empty-state h1 {
  font-size: 30px; font-weight: 500; color: var(--text);
  letter-spacing: -.5px;
}

/* ── EXCHANGE BLOCKS ─────────────────────────────────────────────────────── */
.exchange-block { display: flex; flex-direction: column; margin-bottom: 22px; flex-shrink: 0; }
.exchange-user  { display: flex; flex-direction: column; }
.exchange-model { display: flex; flex-direction: column; margin-top: 10px; }

/* Show user-side actions aligned right, model-side actions aligned left */
.exchange-user .msg-actions { justify-content: flex-end; }
.exchange-block:hover .msg-actions { opacity: 1; }

/* ── MESSAGE BLOCKS ──────────────────────────────────────────────────────── */
/* `.msg-user-wrap` / `.msg-ai-wrap` / `.msg-*-bubble` / `.msg-ai-content` —
 * это шаренные классы для user/model карточек ВНУТРИ `exchange-block`.
 * До 2026-05 они также использовались отдельным standalone-рендером
 * (`.msg-row`), но скриптом migration legacy данных переведены на
 * exchange-block формат, и legacy путь убран из app.js. */

.msg-user-wrap { display: flex; justify-content: flex-end; }
.msg-user-bubble {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px 18px 4px 18px;
  padding: 11px 16px; max-width: 78%;
  font-size: 15px; line-height: 1.6; color: var(--text);
  word-break: break-word;
}

.msg-ai-wrap { display: flex; flex-direction: column; }
.msg-ai-content {
  font-size: 15px; line-height: 1.75; color: var(--text);
  word-break: break-word;
}

/* shared markdown body */
.md-body p { margin: 0 0 10px; }
.md-body p:last-child { margin: 0; }
.md-body ul, .md-body ol { padding-left: 24px; margin: 4px 0 10px; }
.md-body li { margin-bottom: 3px; }
.md-body pre {
  background: #0b0f14; border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; overflow-x: auto; font-size: 13px; margin: 10px 0;
  line-height: 1.55;
}
.md-body pre code { background: none; padding: 0; font-size: 13px; color: inherit; }
.md-body :not(pre) > code {
  background: rgba(255, 123, 114, .12);
  color: var(--code-inline);
  padding: 1.5px 5px; border-radius: 5px;
  font-size: .88em;
  font-family: 'Consolas', 'Monaco', monospace;
}
.md-body h1, .md-body h2, .md-body h3 { margin: 14px 0 8px; font-weight: 600; }
.md-body h1 { font-size: 20px; }
.md-body h2 { font-size: 18px; }
.md-body h3 { font-size: 16px; }
.md-body blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--text-dim); margin: 6px 0; }
.md-body a { color: var(--accent); text-decoration: none; }
.md-body a:hover { text-decoration: underline; }
.md-body table { border-collapse: collapse; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 8px 12px; }
.md-body th { background: var(--bg-soft); }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

/* typing cursor */
.typing-cursor::after { content: '▋'; animation: blink .8s step-end infinite; color: var(--accent); margin-left: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* images */
.chat-image {
  max-width: 420px; height: auto; border-radius: 10px;
  display: block; margin-top: 8px; cursor: zoom-in; border: 1px solid var(--border);
  align-self: flex-start;
}

/* generate_video / present_file(.mp4): инлайн-плеер прямо в сообщении */
.chat-video {
  max-width: 420px; height: auto; border-radius: 10px;
  display: block; margin-top: 8px; border: 1px solid var(--border);
  align-self: flex-start; background: #000;
}

/* generate_music / present_file(.wav/.mp3): инлайн-аудиоплеер */
.chat-audio {
  width: 360px; max-width: 100%;
  display: block; margin-top: 8px; align-self: flex-start;
}

/* промпт-«плашка» генерации (картинка/видео/музыка): акцентная карточка
   с текстом промпта — в стиле «вот что генерировалось». Поверх .tool-block. */
.prompt-card { border-left: 3px solid var(--accent, #6c8cff); }
.prompt-card > summary { font-weight: 600; }
.prompt-card .tool-section code {
  white-space: pre-wrap; word-break: break-word; display: inline-block; margin-top: 2px;
}

/* meta */
.msg-meta {
  font-size: 11px; color: var(--text-faint); margin-top: 6px; flex-shrink: 0;
}

/* hover actions on messages */
.msg-actions {
  display: flex; align-items: center; gap: 2px;
  margin-top: 4px; height: 22px;
  opacity: 0; transition: opacity .12s;
  font-size: 11px; color: var(--text-faint);
}
.msg-actions .ma-date { margin-right: 6px; }
.msg-actions button {
  width: 26px; height: 22px; border-radius: 5px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.msg-actions button:hover:not(:disabled) { background: var(--bg-soft); color: var(--text); }
.msg-actions button:disabled { cursor: not-allowed; opacity: .6; }
.msg-actions button.copied { color: #56d364; }
.msg-actions .ma-model {
  margin-left: auto;
  font-size: 11px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}

/* system block */
.msg-system {
  align-self: center; max-width: 80%; flex-shrink: 0;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; color: var(--text-dim); cursor: pointer; margin-bottom: 16px;
}
.msg-system summary { padding: 6px 12px; list-style: none; user-select: none; display: flex; gap: 6px; }
.msg-system summary::-webkit-details-marker { display: none; }
.msg-system pre {
  padding: 8px 12px; font-size: 12px; white-space: pre-wrap;
  border-top: 1px solid var(--border); color: var(--text-dim); font-family: inherit;
}

/* live tool call indicator (shown during streaming, removed on done) */
.tool-live {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; margin-bottom: 8px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px;
  font-size: 12px; color: var(--text-dim);
  animation: tool-pulse 1.5s ease-in-out infinite;
}

/* Rich live-card (per-tool override). Поднаследует визуал от .tool-block
 * (раскрывающийся <details>), но добавляет «дышащую» рамку — это
 * сигнал что внутри что-то происходит. Спиннер в summary — небольшая
 * крутилка справа от заголовка. */
.tool-live-rich {
  display: block;
  border-radius: 10px;
  animation: tool-pulse 2s ease-in-out infinite;
}
.tool-live-rich summary { align-items: center; }
.tool-live-spinner {
  display: inline-block; width: 12px; height: 12px; margin-left: 8px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spinner-rotate 0.9s linear infinite;
  vertical-align: middle;
}
@keyframes spinner-rotate { to { transform: rotate(360deg); } }

/* DeepSeek reasoning ('мышление') — сворачиваемый блок над ответом */
.msg-reasoning {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  font-size: 12px; margin-bottom: 8px; overflow: hidden;
}
.msg-reasoning summary {
  padding: 6px 12px; cursor: pointer; user-select: none;
  color: var(--text-dim); list-style: none;
}
.msg-reasoning summary::-webkit-details-marker { display: none; }
.msg-reasoning-body {
  padding: 8px 12px; white-space: pre-wrap; color: var(--text-faint);
  font-style: italic; max-height: 300px; overflow-y: auto;
  border-top: 1px solid var(--border);
}
@keyframes tool-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* tool blocks */
.tool-block {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; margin-bottom: 10px; overflow: hidden; flex-shrink: 0;
}
.tool-block summary {
  padding: 8px 14px; cursor: pointer; user-select: none;
  display: flex; align-items: center; gap: 8px; color: var(--text-dim); list-style: none;
}
.tool-block summary::-webkit-details-marker { display: none; }
.tool-block summary b { color: var(--text); }
.tool-block summary .tool-count { font-size: 11px; color: var(--text-faint); margin-left: auto; }
.tool-block:hover summary { background: var(--bg-hover); }
.tool-block[open] summary { border-bottom: 1px solid var(--border); }
.tool-json {
  padding: 12px; font-size: 12px; overflow-x: auto; white-space: pre-wrap;
  color: var(--text-dim); font-family: 'Consolas', 'Monaco', monospace;
  background: var(--bg); max-height: 400px; overflow-y: auto;
}
.tool-body { padding: 10px 14px; display: flex; flex-direction: column; gap: 8px; }
.tool-section { font-size: 13px; }
.tool-section b { color: var(--text-dim); font-weight: 500; }
.source-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.source-link {
  color: var(--accent); text-decoration: none; font-size: 12px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.source-link:hover { text-decoration: underline; }

/* ── INPUT AREA ──────────────────────────────────────────────────────────── */
#input-outer {
  padding: 0 28px 18px;
  display: flex; flex-direction: column; align-items: center;
}
#input-box {
  width: 100%; max-width: 760px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 18px;
  display: flex; flex-direction: column; overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
#input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, .08);
}

#editor {
  min-height: 54px; max-height: 220px; overflow-y: auto;
  padding: 14px 18px 10px;
  font-size: 15px; line-height: 1.55; color: var(--text);
  outline: none; white-space: pre-wrap; word-break: break-word;
}
#editor:empty::before {
  content: attr(data-placeholder); color: var(--text-faint); pointer-events: none;
}

/* editor code block */
.editor-code-block {
  display: block;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin: 6px 0;
  font-family: 'Consolas', 'Monaco', monospace; font-size: 13px;
  color: #79c0ff; outline: none; white-space: pre; overflow-x: auto;
  caret-color: var(--text);
}
.editor-code-block::before {
  content: attr(data-lang);
  display: block; font-size: 10px; color: var(--text-faint);
  margin-bottom: 4px; font-family: inherit; text-transform: uppercase; letter-spacing: .5px;
}

/* editor inline code */
.editor-inline-code {
  background: rgba(255, 123, 114, .14);
  color: var(--code-inline);
  padding: 1.5px 5px; border-radius: 5px;
  font-family: 'Consolas', 'Monaco', monospace; font-size: .9em;
}

/* toolbar */
#input-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px 8px;
}

#btn-attach {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
#btn-attach:hover:not(:disabled) { background: var(--panel); color: var(--text); }
#btn-attach:disabled { opacity: .4; cursor: not-allowed; }

/* custom model picker */
#model-picker {
  margin-left: auto;
  position: relative;
}
#model-btn {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); font-size: 12.5px;
  padding: 6px 10px; border-radius: 7px;
  transition: background .12s, color .12s;
  max-width: 220px;
}
#model-btn:hover { background: var(--panel); color: var(--text); }
#model-btn svg { opacity: .6; flex-shrink: 0; }
#model-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#model-menu {
  position: fixed;
  min-width: 240px; max-width: 300px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
  z-index: 200;
  display: flex; flex-direction: column;
}
.model-item {
  display: flex; align-items: center;
  padding: 9px 12px; border-radius: 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 13px; text-align: left;
  transition: background .1s;
}
.model-item:hover { background: var(--panel); }
.model-item.selected { background: var(--panel); }

#send-btn {
  width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0;
  background: var(--send); border: none; cursor: pointer;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, opacity .12s;
}
#send-btn:hover:not(:disabled) { background: var(--send-hover); }
#send-btn:disabled { background: var(--panel); color: var(--text-faint); cursor: not-allowed; }
#send-btn.stopping { background: var(--text); color: var(--bg); }
#send-btn.stopping:hover { background: #fff; }

#input-hint {
  font-size: 11px; color: var(--text-faint); margin-top: 8px;
  display: flex; justify-content: space-between; align-items: center;
}
#input-token-count {
  opacity: 0; transition: opacity 0.15s; white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-size: 12px; color: var(--text-dim);
  padding: 4px 8px; border-radius: 6px;
  border: 1px solid transparent;
}
#input-token-count.visible {
  opacity: 1;
  border-color: var(--border);
  background: var(--bg-soft);
}

/* ── IMAGE MODAL ─────────────────────────────────────────────────────────── */
#img-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, .85);
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
  cursor: zoom-out;
  animation: fade-in .15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
#img-modal img {
  max-width: 100%; max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
  cursor: default;
}
#img-modal-close {
  position: absolute; top: 20px; right: 24px;
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255, 255, 255, .1); border: none; color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .12s;
}
#img-modal-close:hover { background: rgba(255, 255, 255, .2); }

/* ── CODE BLOCK IN CHAT (header + copy) ──────────────────────────────────── */
.md-body pre {
  position: relative;
  padding: 0;
  overflow: hidden;
}
.md-body pre > code {
  display: block;
  padding: 12px 14px;
  overflow-x: auto;
}
.md-body pre .code-header {
  display: flex; align-items: center;
  padding: 6px 10px 6px 14px;
  background: #0e141b;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-muted);
  font-family: 'Consolas', 'Monaco', monospace;
  text-transform: lowercase; letter-spacing: .3px;
  min-height: 28px;
}
.md-body pre .code-lang { flex: 1; }
.md-body pre .code-copy {
  opacity: 0;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); padding: 4px 6px; border-radius: 5px;
  display: flex; align-items: center; gap: 4px;
  font-size: 11.5px;
  transition: opacity .12s, background .12s, color .12s;
}
.md-body pre:hover .code-copy { opacity: 1; }
.md-body pre .code-copy:hover { background: var(--panel); color: var(--text); }
.md-body pre .code-copy.copied { opacity: 1; color: #56d364; }

/* ── FILES PANEL ─────────────────────────────────────────────────────────── */
#files-panel {
  width: 320px; min-width: 320px; flex-shrink: 0;
  background: var(--bg-soft); border-left: 1px solid var(--border-soft);
  display: flex; flex-direction: column; overflow: hidden;
}
#files-header {
  display: flex; align-items: center;
  padding: 0 10px 0 16px;
  height: 48px; flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13.5px; font-weight: 500; color: var(--text);
}
#files-header span { flex: 1; }
#btn-files-close {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
#btn-files-close:hover { background: var(--panel); color: var(--text); }
/* Хлебные крошки навигации по папкам workspace */
#files-crumb {
  flex-shrink: 0; display: flex; align-items: center; flex-wrap: wrap;
  gap: 1px; padding: 8px 10px; font-size: 12px;
  border-bottom: 1px solid var(--border-soft); color: var(--text-dim);
}
.crumb-seg {
  cursor: pointer; padding: 2px 5px; border-radius: 5px;
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumb-seg:hover { background: var(--bg); color: var(--text); }
.crumb-sep { color: var(--text-muted); }

/* Сетка плиток-«иконок» (как вид «крупные значки» в проводнике) */
#files-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 6px; padding: 10px; align-content: start;
}
#files-grid.hidden { display: none; }
.fs-tile {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 2px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.fs-tile:hover { background: var(--bg); border-color: var(--border-soft); }
.fs-glyph {
  width: 100%; aspect-ratio: 1 / 1; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; line-height: 1; overflow: hidden;
  background: var(--bg); border: 1px solid var(--border-soft);
}
.fs-glyph img { width: 100%; height: 100%; object-fit: cover; }
.fs-tile.dir .fs-glyph { border: none; background: transparent; }
.fs-label {
  font-size: 11px; line-height: 1.2; color: var(--text); text-align: center;
  width: 100%; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.fs-size { font-size: 10px; color: var(--text-muted); }
#files-empty {
  padding: 24px 16px;
  font-size: 13px; color: var(--text-muted); text-align: center;
}

/* ── GENERATION SETTINGS PANEL ──────────────────────────────────────────── */
#gen-settings-panel {
  position: absolute; top: 52px; right: 12px;
  z-index: 180;
  width: 340px;
  max-height: calc(100vh - 72px); overflow-y: auto;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 18px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
  animation: fade-in .12s ease-out;
}
.gs-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 14px; }
.gs-note { font-size: 11px; color: var(--text-faint); font-weight: 400; }
.gs-row {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-dim); margin-bottom: 12px; cursor: default;
}
.gs-row b { color: var(--accent); }
.gs-row input[type=range] {
  width: 100%; accent-color: var(--accent); cursor: pointer; height: 4px;
}
/* чекбокс-строка («Не сжимать контекст»): чекбокс + подпись в один ряд, а не
   столбиком (по умолчанию .gs-row — column). */
.gs-row.gs-toggle { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.gs-row.gs-toggle input[type=checkbox] {
  width: 16px; height: 16px; margin: 0; flex-shrink: 0; accent-color: var(--accent); cursor: pointer;
}
.gs-row.gs-toggle span { color: var(--text-dim); }
#gs-reset {
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-dim); font-size: 12px; padding: 5px 14px; cursor: pointer;
  transition: background .1s;
}
#gs-reset:hover { background: var(--bg-hover); color: var(--text); }
#gs-debug {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text-dim); font-size: 12px; padding: 5px 14px;
  text-decoration: none; cursor: pointer; transition: background .1s, color .1s;
}
#gs-debug:hover { background: var(--bg-hover); color: var(--text); }
#gs-debug svg { opacity: 0.5; flex-shrink: 0; }
#gs-debug:hover svg { opacity: 0.8; }
#topbar { position: relative; }

/* ── EDIT FORM (inline message editing) ─────────────────────────────────── */
.edit-form {
  display: flex; flex-direction: column; gap: 10px;
  width: 100%;
}
.edit-textarea {
  width: 100%; box-sizing: border-box;
  min-height: 72px;
  background: var(--bg-soft); border: 1.5px solid var(--accent);
  border-radius: 12px; padding: 12px 16px;
  color: var(--text); font-size: 15px; font-family: inherit; line-height: 1.55;
  resize: vertical; outline: none;
  box-shadow: 0 0 0 3px rgba(88,166,255,.08);
  transition: border-color .15s;
}
.edit-textarea:focus { border-color: var(--accent); }
.edit-bottom {
  display: flex; align-items: flex-start; gap: 10px;
}
.edit-hint {
  flex: 1; display: flex; align-items: flex-start; gap: 6px;
  font-size: 12px; color: var(--text-dim); line-height: 1.5;
}
.edit-btn-row {
  display: flex; gap: 8px; flex-shrink: 0; align-items: center;
}
.edit-btn-cancel {
  padding: 7px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  color: var(--text); font-size: 13.5px; cursor: pointer;
  transition: background .1s;
}
.edit-btn-cancel:hover { background: var(--panel); }
.edit-btn-save {
  padding: 7px 16px; border-radius: 8px; border: none;
  background: #e6edf3; color: #0d1117;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background .1s;
}
.edit-btn-save:hover { background: #fff; }

/* ── DROP OVERLAY ────────────────────────────────────────────────────────── */
#drop-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0, 0, 0, .75);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; pointer-events: none;
  animation: fade-in .12s ease-out;
}
#drop-overlay span {
  color: rgba(255, 255, 255, .9); font-size: 20px; font-weight: 500;
}

/* ── ATTACHED IMAGES (input area) ────────────────────────────────────────── */
#attached-images {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px 2px;
}
#attached-images:empty { display: none; }

.attach-thumb {
  position: relative;
  width: 72px; height: 72px; border-radius: 8px; overflow: hidden;
  flex-shrink: 0; cursor: pointer;
}
.attach-thumb img {
  width: 72px; height: 72px; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--border); display: block;
  transition: filter .12s;
}
.attach-thumb:hover img { filter: brightness(.85); }
.attach-thumb-remove {
  position: absolute; top: 4px; left: 4px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,.65); border: none; color: #fff;
  font-size: 14px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-weight: 700; z-index: 10;
}
.attach-thumb:hover .attach-thumb-remove { display: flex; }

/* ── IMG MODAL CAPTION ───────────────────────────────────────────────────── */
#img-modal-caption {
  position: absolute; bottom: 28px; left: 0; right: 0;
  text-align: center; color: rgba(255,255,255,.7);
  font-size: 13px; pointer-events: none;
}

/* ── SCROLLBARS ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #3d444d; }

/* ── MODEL FILES: inline preview + cards ─────────────────────────────────── */
/* Текстовый файл (txt/md/csv/py/cs/…) — превью прямо в сообщении. */
.file-embed {
  margin-top: 8px; align-self: flex-start; max-width: 560px; width: 100%;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-soft); overflow: hidden;
}
.fe-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.fe-icon { font-size: 14px; flex-shrink: 0; }
.fe-name {
  font-size: 13px; font-weight: 600; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fe-spacer { flex: 1; }
.fe-act, .fm-act {
  flex-shrink: 0; width: 26px; height: 26px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted); font-size: 14px; cursor: pointer; text-decoration: none;
  transition: background .12s, color .12s, border-color .12s;
}
.fe-act:hover, .fm-act:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border); }
.fe-body { max-height: 420px; overflow: auto; }
.fe-pre {
  margin: 0; padding: 12px 14px; background: var(--bg); white-space: pre; tab-size: 4;
  font-family: 'SF Mono', SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5; color: var(--text);
}
.fe-body .md-body { padding: 12px 14px; }
.fe-note { padding: 8px 12px; font-size: 12px; color: var(--text-muted); }
.fe-note a { color: var(--accent); }
.fe-tablewrap { overflow: auto; max-width: 100%; }
.fe-table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.fe-table th, .fe-table td {
  border: 1px solid var(--border); padding: 5px 9px;
  text-align: left; white-space: nowrap; color: var(--text);
}
.fe-table th { background: var(--panel); font-weight: 600; position: sticky; top: 0; }
.fe-table tr:nth-child(even) td { background: rgba(255,255,255,.02); }

/* Нечитаемый инлайн файл (pdf/docx/xlsx/zip/…) — компактная карточка. */
.file-card {
  margin-top: 8px; align-self: flex-start;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; min-width: 220px; max-width: 360px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg-soft);
}
.file-card.clickable { cursor: pointer; }
.file-card.clickable:hover { background: var(--bg-hover); border-color: var(--accent); }
.fc-icon { font-size: 22px; flex-shrink: 0; }
.fc-meta { flex: 1; min-width: 0; }
.fc-name {
  font-size: 13px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fc-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.fc-act {
  flex-shrink: 0; width: 30px; height: 30px; border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 15px; text-decoration: none;
  transition: background .12s, color .12s, border-color .12s;
}
.fc-act:hover { background: var(--accent-2); color: #fff; border-color: var(--accent-2); }

/* Превью-модалка файла (кнопка «развернуть» + панель «Файлы»). */
#file-modal {
  position: fixed; inset: 0; z-index: 200; padding: 40px;
  background: rgba(0,0,0,.85); animation: fade-in .15s ease-out;
  display: flex; align-items: center; justify-content: center;
}
.fm-box {
  display: flex; flex-direction: column; width: min(900px, 100%); max-height: 100%;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.fm-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.fm-name {
  font-size: 14px; font-weight: 600; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fm-spacer { flex: 1; }
.fm-act { width: 30px; height: 30px; font-size: 15px; }
.fm-body { overflow: auto; background: var(--bg); }
.fm-body .md-body { padding: 16px 18px; }
.fm-body .fe-table { font-size: 13px; }
.fm-pdf { width: 100%; height: 78vh; border: 0; background: #fff; display: block; }
