/* =========================================================================
   TOKENS
   ========================================================================= */
:root {
  --brand-1: #4f7cff;
  --brand-2: #6f4bff;
  --brand-3: #00c2ff;
  --brand-rgb: 79, 124, 255;
  --brand-gradient: linear-gradient(135deg, #4f7cff 0%, #6f4bff 50%, #00c2ff 120%);
  --brand-soft: linear-gradient(135deg, rgba(79,124,255,.14), rgba(111,75,255,.08));

  --bg-app: #eef1f8;
  --surface-0: #ffffff;
  --surface-2: #eef1f8;
  --surface-glass: rgba(255,255,255,.72);
  --surface-border: rgba(16, 24, 40, .08);
  --surface-hover: rgba(16, 24, 40, .04);

  /* Синонимы имён, которые использует разметка, но которые никогда не были
     определены. Без них фон карточек, модалок и таблиц не отрисовывался:
     неопределённый var() даёт прозрачность. Здесь объявляем один раз,
     вместо правки всех мест использования. */
  --bg-1: var(--surface-0);
  --bg-2: var(--surface-2);
  --surface-1: var(--surface-0);
  --border: var(--surface-border);

  --text-1: #0b1220;
  --text-2: #4a5568;
  --text-3: #8a94a6;

  --success: #10b981;
  --warning: #f59e0b;
  --danger:  #ef4444;

  --shadow-xs: 0 1px 2px rgba(16,24,40,.05);
  --shadow-sm: 0 2px 8px rgba(16,24,40,.06), 0 1px 2px rgba(16,24,40,.04);
  --shadow-md: 0 10px 28px rgba(16,24,40,.09), 0 3px 8px rgba(16,24,40,.05);
  --shadow-lg: 0 24px 56px rgba(16,24,40,.14), 0 8px 20px rgba(16,24,40,.07);
  --shadow-glow: 0 8px 26px rgba(var(--brand-rgb), .32);
  --shadow-inset: inset 0 1px 0 rgba(255,255,255,.6);

  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 30px;
  --r-pill: 999px;

  --ease: cubic-bezier(.4,0,.2,1);
  --ease-bounce: cubic-bezier(.21,1.02,.73,1);

  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-theme="dark"] {
  --bg-app: #06080f;
  --surface-0: #0f1420;
  --surface-2: #151b28;
  --surface-glass: rgba(20,26,40,.72);
  --surface-border: rgba(255,255,255,.08);
  --surface-hover: rgba(255,255,255,.05);
  --text-1: #eef2fb;
  --text-2: #a3adc2;
  --text-3: #6b7688;
  --brand-1: #7aa0ff;
  --brand-2: #9a7bff;
  --brand-rgb: 122, 160, 255;
  --shadow-glow: 0 8px 26px rgba(var(--brand-rgb), .38);
}
[data-theme="dark"] .topbar { background: rgba(15,20,32,0.6); }
[data-theme="dark"] .composer-wrap { background: rgba(15,20,32,0.7); }
[data-theme="dark"] .statusbar { background: rgba(15,20,32,0.55); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(107,118,136,0.4); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(107,118,136,0.7); }
[data-theme="dark"] .conv-item.is-active { border-color: rgba(122,160,255,0.3); }
[data-theme="dark"] .btn-soft:hover { border-color: rgba(122,160,255,0.45); }
[data-theme="dark"] .icon-picker-grid button.is-selected { border-color: rgba(122,160,255,0.45); }

/* =========================================================================
   BASE
   ========================================================================= */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--text-1);
  background: var(--bg-app);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color .3s var(--ease), color .3s var(--ease);
}
body::before {
  content: "";
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  background:
    radial-gradient(1000px 620px at 8% -10%, rgba(var(--brand-rgb), .18), transparent 60%),
    radial-gradient(900px 520px at 105% 5%, rgba(111,75,255,.14), transparent 62%),
    radial-gradient(700px 500px at 50% 120%, rgba(0,194,255,.10), transparent 60%);
  pointer-events: none;
  z-index: 0;
}
[data-theme="dark"] body::before {
  background:
    radial-gradient(1000px 620px at 8% -10%, rgba(var(--brand-rgb), .14), transparent 60%),
    radial-gradient(900px 520px at 105% 5%, rgba(154,123,255,.12), transparent 62%);
}
a { color: var(--brand-1); text-decoration: none; }
a:hover { color: var(--brand-2); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: rgba(138,148,166,0.4);
  background: color-mix(in srgb, var(--text-3) 40%, transparent);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-pill);
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(138,148,166,0.7);
  background: color-mix(in srgb, var(--text-3) 70%, transparent);
  background-clip: content-box;
}
::-webkit-scrollbar-track { background: transparent; }

.min-w-0 { min-width: 0; }

/* =========================================================================
   APP — главный flex-контейнер, фиксированная высота 100dvh
   ========================================================================= */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  height: 100dvh;
  padding: 12px;
  gap: 12px;
  overflow: hidden;
}

.panel {
  position: relative;
  background: var(--surface-0);
  background: var(--surface-glass);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
}

/* =========================================================================
   SIDEBAR
   ========================================================================= */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  transition: width .3s var(--ease), flex-basis .3s var(--ease), opacity .2s var(--ease);
}
.sidebar.is-collapsed {
  width: 0; flex-basis: 0; opacity: 0; pointer-events: none; border-width: 0;
}

.sidebar-header {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
}

.logo {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 13px;
  background: var(--brand-gradient);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-glow), var(--shadow-inset);
}
.logo svg { width: 22px; height: 22px; }

.logo-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.logo-text b { font-size: .95rem; font-weight: 700; }
.logo-text span { font-size: .72rem; color: var(--text-3); font-weight: 500; }

.conversation-list {
  flex: 1 1 auto; min-height: 0;
  padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
}

.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text-2);
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.conv-item:hover { background: var(--surface-hover); color: var(--text-1); }
.conv-item.is-active {
  background: var(--brand-soft);
  color: var(--text-1);
  border-color: rgba(79,124,255,0.3);
  border-color: color-mix(in srgb, var(--brand-1) 30%, transparent);
}
.conv-item .conv-icon {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: .78rem;
}
.conv-item.is-active .conv-icon {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.conv-item .conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; }
.conv-item .conv-title[data-title]:hover { overflow: visible; z-index: 10; }
.conv-item .conv-title input {
  width: 100%; border: 0; background: transparent; color: inherit;
  font: inherit; padding: 0; margin: 0; outline: 0;
}
.conv-item .conv-meta { font-size: .7rem; color: var(--text-3); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--surface-border);
  flex-shrink: 0;
}

/* =========================================================================
   BUTTONS
   ========================================================================= */
.btn-reset { border: 0; background: transparent; padding: 0; cursor: pointer; font: inherit; color: inherit; }

.btn-icon {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  font-size: .95rem;
  cursor: pointer;
  transition: background-color .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease), transform .12s var(--ease);
  position: relative;
}
.btn-icon:hover { background: var(--surface-hover); color: var(--text-1); border-color: var(--surface-border); }
.btn-icon:active { transform: scale(.94); }

.btn-icon.has-badge::after {
  content: "";
  position: absolute; top: 6px; right: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--surface-0);
}

.btn-soft {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 11px;
  border: 1px solid var(--surface-border);
  background: var(--surface-0);
  color: var(--text-2);
  font-weight: 500;
  font-size: .84rem;
  cursor: pointer;
  transition: all .18s var(--ease);
}
.btn-soft:hover {
  color: var(--brand-1);
  border-color: rgba(79,124,255,0.45);
  border-color: color-mix(in srgb, var(--brand-1) 45%, transparent);
  background: var(--brand-soft);
}

.btn-ghost, .btn-ghost-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  font-weight: 500;
  font-size: .82rem;
  cursor: pointer;
  transition: all .18s var(--ease);
}
.btn-ghost-danger:hover {
  color: var(--danger);
  background: rgba(239,68,68,0.1);
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border-color: rgba(239,68,68,0.25);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
}
.btn-ghost:hover {
  color: var(--text-1);
  background: var(--surface-hover);
  border-color: var(--surface-border);
}

/* =========================================================================
   TOOLTIP (fixed, через JS)
   ========================================================================= */
.app-tooltip {
  position: fixed;
  z-index: 5000;
  background: var(--text-1);
  color: var(--surface-0);
  font-size: .72rem;
  font-weight: 500;
  line-height: 1.2;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .14s var(--ease);
  box-shadow: var(--shadow-md);
  max-width: 260px;
}
.app-tooltip.is-visible { opacity: 1; }
.app-tooltip::after {
  content: "";
  position: absolute;
  width: 8px; height: 8px;
  background: inherit;
  transform: rotate(45deg);
  border-radius: 1px;
}
.app-tooltip.pos-top::after    { left: 50%; bottom: -4px; margin-left: -4px; }
.app-tooltip.pos-bottom::after { left: 50%; top: -4px;    margin-left: -4px; }
.app-tooltip.pos-left::after   { right: -4px; top: 50%;   margin-top: -4px; }
.app-tooltip.pos-right::after  { left: -4px;  top: 50%;   margin-top: -4px; }

/* =========================================================================
   MAIN PANEL — ключевое: height: 100%, flex-колонка, БЕЗ overflow: hidden
   ========================================================================= */
.main-panel {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
}

.main-panel > .main-inner {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  border-radius: inherit;
}
.main-panel > .admin-inner { overflow-y: auto; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--surface-border);
  flex-wrap: wrap;
  flex-shrink: 0;
  background: rgba(255,255,255,0.6);
  background: color-mix(in srgb, var(--surface-0) 60%, transparent);
}

.topbar-group { display: flex; align-items: center; gap: 6px; }
.topbar-divider {
  width: 1px; height: 24px;
  background: var(--surface-border);
  margin: 0 4px;
}

.model-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  border-radius: 11px;
  border: 1px solid var(--surface-border);
  background: var(--surface-2);
  color: var(--text-1);
  font-size: .82rem;
  font-weight: 600;
  user-select: none;
}
.model-badge .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.25);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 25%, transparent);
}

.search-input {
  flex: 1; min-width: 0;
  height: 38px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid var(--surface-border);
  background: var(--surface-2);
  color: var(--text-1);
  font-size: .85rem;
  font-family: inherit;
  outline: 0;
  transition: all .18s var(--ease);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus {
  background: var(--surface-0);
  border-color: var(--brand-1);
  box-shadow: 0 0 0 4px rgba(var(--brand-rgb), .14);
}

.search-panel {
  display: none;
  align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
}
.search-panel.is-open { display: flex; }

.search-highlight {
  background: #f7dc6f;
  color: #1a1a2e;
  border-radius: 2px;
  padding: 0 1px;
}
.search-highlight.current {
  background: #f39c12;
  color: #fff;
}

/* =========================================================================
   CHAT — РАСТЯГИВАЕТСЯ и СКРОЛЛИТСЯ
   ========================================================================= */
.chat {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 32px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 26px;
  scrollbar-gutter: stable;
}

.msg {
  display: flex; gap: 14px;
  align-items: flex-start;
  animation: msgRise .35s var(--ease-bounce) both;
  flex-shrink: 0;
}
@keyframes msgRise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.is-user { flex-direction: row-reverse; }

.msg-avatar {
  width: 40px; height: 40px; flex: 0 0 40px;
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: .78rem; font-weight: 700;
  border: 1px solid var(--surface-border);
  background: var(--surface-2);
  color: var(--text-2);
  box-shadow: var(--shadow-xs);
}
.msg-avatar svg { width: 20px; height: 20px; }
.msg-avatar-img { width: 40px; height: 40px; border-radius: 13px; object-fit: cover; }
.msg.is-user .msg-avatar {
  background: var(--brand-gradient);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-glow);
}

.msg-body {
  display: flex; flex-direction: column;
  max-width: 78%;
  max-width: min(78%, 800px);
  min-width: 0;
}
.msg.is-user .msg-body { align-items: flex-end; }

.msg-head {
  display: flex; align-items: center; gap: 8px;
  font-size: .74rem;
  color: var(--text-3);
  margin-bottom: 5px;
  padding: 0 4px;
}
.msg-author { font-weight: 600; color: var(--text-2); }

.bubble {
  padding: 14px 18px;
  border-radius: var(--r-lg);
  font-size: .92rem;
  line-height: 1.65;
  word-wrap: break-word;
  white-space: pre-wrap;
  border: 1px solid transparent;
}
.msg.is-user .bubble {
  background: var(--brand-gradient);
  color: #fff;
  border-bottom-right-radius: 8px;
  box-shadow: var(--shadow-glow);
}
.msg.is-user .bubble code {
  background: rgba(255,255,255,.22);
  color: #fff;
  padding: 2px 7px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: .85em;
}
.msg.is-ai .bubble {
  background: var(--surface-0);
  border: 1px solid var(--surface-border);
  border-bottom-left-radius: 8px;
  box-shadow: var(--shadow-sm);
}
.bubble .content { white-space: normal; }
.bubble pre {
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  font-family: var(--font-mono);
  font-size: .84rem;
  line-height: 1.6;
}
.bubble pre code { background: none; padding: 0; color: inherit; font-family: inherit; }
.bubble pre code.hljs { padding: 14px 16px; display: block; overflow-x: auto; font-family: var(--font-mono); font-size: .84rem; line-height: 1.6; }
.bubble pre code.hljs { padding: 0; }
.bubble pre.mermaid { background: transparent; border: none; padding: 8px 0; overflow-x: auto; font-size: .84rem; }
.bubble :last-child { margin-bottom: 0; }

.bubble .content { word-break: break-word; }
.bubble .content h1,
.bubble .content h2,
.bubble .content h3,
.bubble .content h4 { margin: 14px 0 8px; font-weight: 700; line-height: 1.3; }
.bubble .content h1 { font-size: 1.35rem; }
.bubble .content h2 { font-size: 1.18rem; }
.bubble .content h3 { font-size: 1.05rem; }
.bubble .content p { margin: 8px 0; }
.bubble .content ul,
.bubble .content ol { margin: 8px 0; padding-left: 22px; }
.bubble .content li { margin: 4px 0; }
.bubble .content a { color: var(--brand-1); text-decoration: underline; }
.bubble .content blockquote { margin: 10px 0; padding: 6px 14px; border-left: 3px solid var(--brand-1); background: var(--surface-2); border-radius: 6px; color: var(--text-2); }
.bubble .content hr { border: none; border-top: 1px solid var(--surface-border); margin: 12px 0; }
.bubble .content table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: .88rem; }
.bubble .content th,
.bubble .content td { border: 1px solid var(--surface-border); padding: 6px 10px; text-align: left; }
.bubble .content th { background: var(--surface-2); font-weight: 600; }
.bubble .content img { max-width: 100%; border-radius: 8px; }
.bubble .content > :first-child { margin-top: 0; }
.bubble .content > :last-child { margin-bottom: 0; }

.msg-actions {
  display: flex; align-items: center; gap: 2px;
  margin-top: 6px;
  padding: 0 2px;
  opacity: 0;
  transition: opacity .2s var(--ease);
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px;
  border: 0; background: transparent;
  color: var(--text-3);
  font-size: .78rem;
  cursor: pointer;
  transition: all .15s var(--ease);
}
.msg-action:hover { background: var(--surface-hover); color: var(--brand-1); }

/* =========================================================================
   REASONING BLOCK (рассуждение модели)
   ========================================================================= */
.bubble-reasoning {
  margin: 0 0 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  overflow: hidden;
  font-size: .84rem;
}
.bubble-reasoning summary {
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-2);
  font-size: .78rem;
  user-select: none;
}
.bubble-reasoning summary::marker { color: var(--text-3); }
.bubble-reasoning summary::-webkit-details-marker { color: var(--text-3); }
.bubble-reasoning .content {
  padding: 4px 14px 12px;
  white-space: normal;
  font-size: .84rem;
  color: var(--text-2);
  line-height: 1.6;
}
.bubble-reasoning .content p { margin: 4px 0; }

/* Reasoning visibility toggle via .show-reasoning on <html> */
html:not(.show-reasoning) .bubble-reasoning:not(.bubble-tool) { display: none; }

/* ===== Панель результата поиска (srch-*) =====
   Тулза отдаёт готовый HTML: запросы и счётчики сверху, ниже группы по
   конфигурациям, внутри — каждый фрагмент отдельным раскрывающимся списком. */
.srch-h {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 6px;
  font-size: .74rem;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.srch-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: var(--brand-soft);
  color: var(--brand-1);
  font-size: .68rem;
  font-weight: 700;
  text-align: center;
}

.srch-queries {
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.srch-q-item {
  padding: 5px 10px;
  border-left: 2px solid var(--brand-1);
  border-radius: 0 var(--r-xs) var(--r-xs) 0;
  background: var(--surface-hover);
  color: var(--text-2);
  font-size: .78rem;
  line-height: 1.45;
}

.srch-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 10px;
  padding: 8px 12px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  background: var(--surface-hover);
}
.srch-meta-row {
  display: flex;
  gap: 10px;
  font-size: .75rem;
  line-height: 1.45;
}
.srch-meta-key {
  flex: 0 0 128px;
  color: var(--text-3);
}
.srch-meta-val { min-width: 0; color: var(--text-2); word-break: break-word; }
.srch-of { color: var(--text-3); }

.srch-counts {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 12px;
}
.srch-cnt-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: .74rem;
}
.srch-cnt-q {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-3);
}
.srch-cnt-n {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text-2);
}

.srch-config {
  margin-bottom: 8px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.srch-config-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--surface-hover);
  cursor: pointer;
  user-select: none;
}
.srch-config-head i { color: var(--brand-1); font-size: .78rem; }
.srch-config-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  font-size: .78rem;
  color: var(--text-1);
}
.srch-config-head::marker { color: var(--text-3); }
.srch-config-head::-webkit-details-marker { color: var(--text-3); }
.srch-config-body { padding: 4px 8px 8px; }

.srch-frag {
  margin: 4px 0;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-xs);
  background: var(--surface-0);
  overflow: hidden;
}
.srch-frag-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  cursor: pointer;
  user-select: none;
  font-size: .76rem;
}
.srch-frag-head::marker { color: var(--text-3); }
.srch-frag-head::-webkit-details-marker { color: var(--text-3); }
.srch-frag-num {
  flex: 0 0 auto;
  min-width: 20px;
  padding: 0 5px;
  border-radius: var(--r-xs);
  background: var(--surface-2);
  color: var(--text-3);
  font-size: .68rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.srch-frag-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-weight: 500;
}
.srch-frag-body {
  padding: 6px 12px 10px;
  border-top: 1px solid var(--surface-border);
  font-size: .78rem;
  line-height: 1.6;
  color: var(--text-2);
}
.srch-frag-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: .7rem;
  color: var(--text-3);
}
.srch-frag-src {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.srch-frag-link { flex: 0 0 auto; color: var(--brand-1); text-decoration: none; }
.srch-frag-link:hover { text-decoration: underline; }
.srch-frag-text p { margin: 4px 0; }
.srch-frag-text h1, .srch-frag-text h2,
.srch-frag-text h3, .srch-frag-text h4 { margin: 8px 0 4px; font-size: .82rem; }
.srch-frag-text pre {
  margin: 6px 0;
  padding: 8px 10px;
  border-radius: var(--r-xs);
  overflow-x: auto;
  font-size: .72rem;
}
.srch-frag-text table { width: 100%; border-collapse: collapse; margin: 6px 0; font-size: .72rem; }
.srch-frag-text th, .srch-frag-text td {
  padding: 4px 6px;
  border: 1px solid var(--surface-border);
  text-align: left;
}
.srch-frag-img {
  display: block;
  max-width: 100%;
  margin-top: 8px;
  border: 1px solid var(--surface-border);
  border-radius: var(--r-xs);
  cursor: zoom-in;
}

.srch-empty {
  padding: 12px;
  border: 1px dashed var(--surface-border);
  border-radius: var(--r-sm);
  color: var(--text-3);
  font-size: .78rem;
}
.srch-empty-reason { margin: 6px 0 0; color: var(--text-2); }

/* =========================================================================
   DOT ANIMATION для статусов "думает..." / "печатает..."
   ========================================================================= */
@keyframes dotPulse {
  0%, 20% { opacity: 0; }
  40% { opacity: 1; }
  100% { opacity: 1; }
}
.msg-head .status-dots {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: 2px;
}
.msg-head .status-dots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: dotPulse 1.4s infinite;
}
.msg-head .status-dots span:nth-child(2) { animation-delay: .2s; }
.msg-head .status-dots span:nth-child(3) { animation-delay: .4s; }

/* =========================================================================
   COMPOSER — всегда виден внизу
   ========================================================================= */
.composer-wrap {
  flex-shrink: 0;
  padding: 12px 20px 18px;
  border-top: 1px solid var(--surface-border);
  background: rgba(255,255,255,0.7);
  background: color-mix(in srgb, var(--surface-0) 70%, transparent);
}
.composer-inner { max-width: 940px; margin: 0 auto; }

.attached-files {
  display: none;
  flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
}
.attached-files.is-open { display: flex; }

.attached-file-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 5px 8px;
  background: var(--surface-0);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  font-size: 12px;
}

/* Миниатюра в композере: 40px, а не натуральный размер картинки */
.attached-file-thumb {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
}
.attached-file-icon { flex: 0 0 auto; font-size: 16px; line-height: 1; }

.attached-file-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attached-file-size {
  flex: 0 0 auto;
  color: var(--text-2);
  font-size: 11px;
}
.attached-file-remove {
  flex: 0 0 auto;
  cursor: pointer;
  color: var(--text-2);
  border: none;
  background: transparent;
  padding: 0 2px;
  font-size: 14px;
  line-height: 1;
  transition: color .15s var(--ease);
}
.attached-file-remove:hover { color: var(--danger); }

/* Вложения под отправленным сообщением */
.msg-attached {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--surface-border);
}
.msg-attached-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 4px 8px;
  background: rgba(127,127,127,.08);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-sm);
  font-size: 12px;
  color: var(--text-2);
}
.msg-attached-thumb {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  cursor: zoom-in;
  background: var(--surface-2);
}
.msg-attached-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface-0);
  border: 1.5px solid var(--surface-border);
  border-radius: var(--r-xl);
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.composer-box:focus-within {
  border-color: var(--brand-1);
  box-shadow: 0 0 0 5px rgba(var(--brand-rgb), .12), var(--shadow-md);
}

.composer-input {
  flex: 1; min-width: 0;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  border: 0; outline: 0;
  box-shadow: none;
  background: transparent;
  color: var(--text-1);
  font-size: .93rem;
  line-height: 1.55;
  padding: 8px 0;
  font-family: inherit;
}
.composer-input::placeholder { color: var(--text-3); }

.btn-attach {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 13px;
  border: 0; background: transparent;
  color: var(--text-3);
  font-size: 1.05rem;
  cursor: pointer;
  transition: all .2s var(--ease);
  flex-shrink: 0;
}
.btn-attach:hover {
  background: var(--surface-2);
  color: var(--brand-1);
  transform: rotate(-12deg);
}

.btn-send {
  width: 44px; height: 44px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0;
  border-radius: 14px;
  background: var(--brand-gradient);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-glow), var(--shadow-inset);
  transition: transform .15s var(--ease), filter .2s var(--ease), box-shadow .2s var(--ease);
}
.btn-send:hover { box-shadow: 0 12px 32px rgba(var(--brand-rgb), .45); }
.btn-send:active { transform: scale(.94); }

.composer-input:disabled { opacity: .35; }
.btn-attach:disabled { opacity: .3; cursor: default; pointer-events: none; }

.composer-hint {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  padding: 0 6px;
  font-size: .72rem;
  color: var(--text-3);
}
.kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  font-family: var(--font-mono);
  font-size: .68rem;
  color: var(--text-2);
}

/* =========================================================================
   STATUS BAR — всегда виден внизу
   ========================================================================= */
.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 10px 20px;
  font-size: .76rem;
  color: var(--text-3);
  border-top: 1px solid var(--surface-border);
  background: rgba(255,255,255,0.55);
  background: color-mix(in srgb, var(--surface-0) 55%, transparent);
  flex-shrink: 0;
}
.status-item { display: flex; align-items: center; gap: 8px; }
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.22);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 22%, transparent);
}
.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  border: 1px solid var(--surface-border);
  font-family: var(--font-mono);
  font-size: .72rem;
  color: var(--text-2);
}
.status-chip b { color: var(--brand-1); font-weight: 600; }

/* =========================================================================
   FORMAT MENU
   ========================================================================= */
.format-menu {
  position: fixed; z-index: 2000;
  background: var(--surface-0);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  min-width: 210px;
}
.format-menu.is-hidden { display: none; }
.format-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%; text-align: left;
  padding: 9px 12px;
  border: 0; background: transparent;
  border-radius: 10px;
  color: var(--text-1);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.format-btn:hover { background: var(--surface-2); }
.format-btn .format-icon {
  width: 30px; height: 30px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-1);
  font-size: .8rem;
  flex-shrink: 0;
}
.format-btn .format-meta { display: flex; flex-direction: column; line-height: 1.25; }
.format-btn .format-meta b { font-weight: 600; font-size: .84rem; }
.format-btn .format-meta span { font-size: .7rem; color: var(--text-3); }

/* =========================================================================
   ICON PICKER
   ========================================================================= */
.icon-picker {
  position: fixed; z-index: 2000;
  background: var(--surface-0);
  border: 1px solid var(--surface-border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 10px;
  min-width: 250px;
}
.icon-picker.is-hidden { display: none; }
.icon-picker-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-size: .84rem; font-weight: 600; color: var(--text-1);
}
.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}
.icon-picker-grid button {
  height: auto; min-height: 42px;
  aspect-ratio: 1;
  border: 1px solid var(--surface-border);
  background: var(--surface-1);
  border-radius: 9px;
  color: var(--text-2);
  font-size: .95rem;
  cursor: pointer;
  transition: background-color .12s var(--ease), color .12s var(--ease), border-color .12s var(--ease);
}
.icon-picker-grid button:hover { background: var(--surface-2); color: var(--brand-1); }
.icon-picker-grid button.is-selected {
  background: var(--brand-soft);
  color: var(--brand-1);
  border-color: rgba(79,124,255,0.45);
  border-color: color-mix(in srgb, var(--brand-1) 45%, transparent);
}

/* =========================================================================
   FILE VIEWER
   ========================================================================= */
.file-viewer {
  width: 0;
  flex: 0 0 auto;
  display: flex; flex-direction: column;
  overflow: hidden;
  height: 100%;
  opacity: 0;
  pointer-events: none;
  transition: width .32s var(--ease), opacity .2s var(--ease);
}
.file-viewer.is-open {
  width: 46%;
  min-width: 400px;
  opacity: 1;
  pointer-events: auto;
}

.fv-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 16px 18px;
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
}
.fv-title { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fv-icon {
  width: 36px; height: 36px; flex: 0 0 36px;
  border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-1);
  font-size: .9rem;
}
.fv-name {
  font-size: .92rem; font-weight: 600;
  margin: 0; color: var(--text-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fv-sub { font-size: .72rem; color: var(--text-3); font-family: var(--font-mono); }

.fv-toolbar {
  display: flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-bottom: 1px solid var(--surface-border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.fv-search {
  display: none;
  align-items: center; gap: 6px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
}
.fv-search.is-open { display: flex; }

.fv-content { flex: 1 1 0; min-height: 0; background: var(--surface-0); overflow-y: auto; }
.fv-placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 16px; height: 100%;
  padding: 40px; text-align: center;
  color: var(--text-3);
}
.fv-placeholder-icon {
  width: 76px; height: 76px;
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft);
  color: var(--brand-1);
  font-size: 1.9rem;
}

/* =========================================================================
   MOBILE OVERLAY
   ========================================================================= */
.mobile-overlay {
  display: none;
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(6, 10, 20, .5);
  backdrop-filter: blur(3px);
  z-index: 1049;
}
.mobile-overlay.is-active { display: block; }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 1100px) {
  .file-viewer.is-open { width: 55%; min-width: 340px; }
}

@media (max-width: 991.98px) {
  .file-viewer.is-open {
    position: fixed;
    top: 12px; right: 12px; bottom: 12px; left: auto;
    width: auto; min-width: 0;
    max-width: calc(100vw - 24px);
    z-index: 1040;
  }
}

@media (max-width: 767.98px) {
  .app { padding: 8px; gap: 8px; }
  .sidebar {
    position: fixed;
    top: 8px; right: auto; bottom: 8px; left: 8px;
    width: 284px; flex-basis: 284px;
    z-index: 1050;
    transform: translateX(calc(-100% - 16px));
    transition: transform .3s var(--ease), opacity .2s var(--ease);
    opacity: 0;
  }
  .sidebar.is-mobile-open { transform: translateX(0); opacity: 1; }
  .sidebar.is-collapsed { width: 284px; flex-basis: 284px; opacity: 0; }

  .chat { padding: 20px 14px 12px; gap: 20px; }
  .msg-body { max-width: 88%; }
  .composer-wrap { padding: 10px 12px 14px; }
  .topbar { padding: 10px 12px; }
  .statusbar { padding: 8px 14px; }
  .logo-text span { display: none; }
}

/* =========================================================================
   IE11 / NO-FLEX-GAP FALLBACK (1С-браузер)
   ========================================================================= */
.no-flex-gap .app > :not(:last-child)         { margin-right: 12px; }
.no-flex-gap .topbar > :not(:last-child)      { margin-right: 10px; }
.no-flex-gap .topbar-group > :not(:last-child) { margin-right: 6px; }
.no-flex-gap .model-badge > :not(:last-child) { margin-right: 8px; }
.no-flex-gap .sidebar-header > :not(:last-child) { margin-right: 12px; }
.no-flex-gap .conv-item > :not(:last-child)   { margin-right: 10px; }
.no-flex-gap .msg > :not(:last-child)         { margin-right: 14px; }
.no-flex-gap .msg-head > :not(:last-child)    { margin-right: 8px; }
.no-flex-gap .msg-actions > :not(:last-child) { margin-right: 2px; }
.no-flex-gap .composer-box > :not(:last-child){ margin-right: 8px; }
.no-flex-gap .statusbar > :not(:last-child)   { margin-right: 12px; }
.no-flex-gap .status-item > :not(:last-child) { margin-right: 8px; }
.no-flex-gap .status-chip > :not(:last-child) { margin-right: 6px; }
.no-flex-gap .chat > :not(:last-child)        { margin-bottom: 26px; }
.no-flex-gap .conversation-list > :not(:last-child) { margin-bottom: 4px; }
.no-flex-gap .search-panel > :not(:last-child)  { margin-right: 8px; }
.no-flex-gap .format-btn > :not(:last-child)    { margin-right: 12px; }
.no-flex-gap .fv-header > :not(:last-child)    { margin-right: 10px; }
.no-flex-gap .fv-toolbar > :not(:last-child)   { margin-right: 6px; }
.no-flex-gap .fv-placeholder > :not(:last-child) { margin-bottom: 16px; }

/* IE11 fixes: убираем flex полностью из чата — IE ломает selection
   при любой вложенности flex. Переход на float-лейаут. */
.no-flex-gap .chat { display: block; }
.no-flex-gap .msg { display: block; overflow: hidden; }
.no-flex-gap .msg-avatar { float: left; margin-right: 14px; width: 40px; height: 40px; }
.no-flex-gap .msg-body { display: block; margin-left: 54px; }
.no-flex-gap .msg.is-user .msg-avatar { float: right; margin-right: 0; margin-left: 14px; }
.no-flex-gap .msg.is-user .msg-body { float: right; margin-left: 0; }
.no-flex-gap .msg.is-user .msg-body .msg-head { flex-direction: row-reverse; }
.no-flex-gap .msg.is-user .msg-actions { justify-content: flex-end; }

/* IE11 не поддерживает CSS-переменные → font-family: var(--font-ui), var(--font-mono)
   сбрасываются в дефолтный Times New Roman / Courier New. Задаём явный шрифт. */
.no-flex-gap body,
.no-flex-gap .bubble,
.no-flex-gap .bubble .content,
.no-flex-gap .bubble pre,
.no-flex-gap .bubble code,
.no-flex-gap .bubble pre code.hljs,
.no-flex-gap .composer-input,
.no-flex-gap .kbd,
.no-flex-gap .status-chip,
.no-flex-gap .fv-sub { font-family: "Segoe UI", Roboto, Arial, sans-serif; }

/* IE11 line-height fix: px вместо unitless — IE рисует selection
   по фактической высоте строки. */
.no-flex-gap .bubble { line-height: 23px; }
.no-flex-gap .bubble .content { line-height: 23px; display: block; }
.no-flex-gap .composer-input { line-height: 22px; }

/* icon-picker-grid: grid → flex fallback (IE не поддерживает grid) */
.no-flex-gap .icon-picker-grid {
  display: flex; flex-wrap: wrap;
}
.no-flex-gap .icon-picker-grid button {
  flex: 0 0 calc(16.666% - 6px);
  width: auto; height: 42px;
}

.emoji-replace {
  display: inline-block;
  width: 1.2em;
  height: 1.2em;
  vertical-align: -0.2em;
  line-height: 1;
}
.emoji-replace img {
  display: inline;
  width: 1.2em;
  height: 1.2em;
  vertical-align: middle;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}

/* Source reference links — numbered circles like DeepSeek */
.sup.source-ref,
.source-ref-link sup.source-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.3em;
  height: 1.3em;
  padding: 0 0.15em;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.7em;
  font-weight: 600;
  vertical-align: super;
  line-height: 1;
  cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
  text-decoration: none !important;
}
.sup.source-ref:hover,
.source-ref-link sup.source-ref:hover {
  background: var(--brand-1);
  color: #fff;
}
a.source-ref-link {
  text-decoration: none !important;
}

/* Image viewer overlay */
.img-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.75);
  cursor: zoom-out;
  align-items: center;
  justify-content: center;
}
.img-viewer.is-open {
  display: flex;
}
.img-viewer img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: 8px;
  box-shadow: 0 24px 56px rgba(0,0,0,.4);
}
.mermaid-viewer {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0,0,0,.75);
  align-items: center;
  justify-content: center;
}
.mermaid-viewer.is-open {
  display: flex;
}
.mermaid-viewer-content {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  width: calc(100vw - 24px);
  height: calc(100vh - 24px);
  max-width: none;
  max-height: none;
  position: relative;
  gap: 0;
  box-shadow: 0 24px 56px rgba(0,0,0,.4);
}
.mermaid-viewer-viewport {
  flex: 1 1 auto;
  overflow: hidden;
  position: relative;
  cursor: grab;
  min-height: 200px;
}
.mermaid-viewer-viewport:active {
  cursor: grabbing;
}
.mermaid-viewer-svg {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}
.mermaid-viewer-svg svg {
  display: block;
}
.mermaid-viewer-zoom {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.mermaid-viewer-zoom .btn-soft {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}
.mermaid-viewer-zoom-lbl {
  font-size: 12px;
  color: #666;
  padding: 0 4px;
  min-width: 38px;
  text-align: center;
  user-select: none;
}
.mermaid-viewer-src {
  display: none;
  flex: 0 0 auto;
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: 8px;
  margin-top: 12px;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.5;
}
.mermaid-viewer-src.is-open {
  display: block;
}
.mermaid-viewer-toolbar {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.mermaid-viewer-toolbar .btn-soft {
  margin: 0;
}