/* ============ AIuzbek — тёмная тема One Dark, фиолетовый акцент ============ */

:root {
  --bg: #1d2127;
  --bg-elev: #262b33;
  --bg-elev2: #2d323c;
  --bg-input: #2b303a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #d7dae0;
  --text-dim: #abb2bf;
  --text-faint: #7f8591;
  --accent: #8b5cf6;
  --accent-strong: #7c3aed;
  --accent-hover: #a78bfa;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --accent-border: rgba(139, 92, 246, 0.35);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.55);
  --font: 'Onest', -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* Атрибут hidden всегда сильнее любого display (иначе экран входа
   и другие элементы с display:flex не скрывались) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.6;
  color: var(--text);
  background:
    radial-gradient(900px 480px at 75% -10%, rgba(139, 92, 246, 0.07), transparent 60%),
    radial-gradient(700px 420px at -10% 110%, rgba(139, 92, 246, 0.04), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ============ Фоновая анимация-абстракция ============ */
/* Десктоп: canvas-aurora (js/bg-fx.js). Мобилка: CSS-пятна. */

.bg-fx {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-fx canvas {
  width: 100%;
  height: 100%;
  display: block;
  filter: blur(26px) saturate(1.2);
}

.bg-fx__blobs { position: absolute; inset: 0; }

.bg-fx__blobs i {
  position: absolute;
  width: 58vmax;
  height: 58vmax;
  border-radius: 50%;
  filter: blur(52px);
  opacity: 0.16;
  will-change: transform;
}

.bg-fx__blobs i:nth-child(1) {
  top: -20%;
  left: -14%;
  background: radial-gradient(circle at 35% 35%, #8b5cf6, transparent 65%);
  animation: blob-a 34s ease-in-out infinite alternate;
}

.bg-fx__blobs i:nth-child(2) {
  top: 6%;
  right: -20%;
  background: radial-gradient(circle at 60% 40%, #6366f1, transparent 65%);
  animation: blob-b 42s ease-in-out infinite alternate;
}

.bg-fx__blobs i:nth-child(3) {
  bottom: -24%;
  left: 20%;
  background: radial-gradient(circle at 50% 50%, #22d3ee, transparent 65%);
  opacity: 0.11;
  animation: blob-c 38s ease-in-out infinite alternate;
}

@keyframes blob-a {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(24vw, 16vh, 0) scale(1.25); }
}

@keyframes blob-b {
  from { transform: translate3d(0, 0, 0) scale(1.1); }
  to { transform: translate3d(-22vw, 24vh, 0) scale(0.9); }
}

@keyframes blob-c {
  from { transform: translate3d(0, 0, 0) scale(0.95); }
  to { transform: translate3d(18vw, -20vh, 0) scale(1.2); }
}

@media (min-width: 769px) { .bg-fx__blobs { display: none; } }

@media (max-width: 768px) { .bg-fx canvas { display: none; } }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

textarea, input { font-family: inherit; }

svg { display: block; }

::selection { background: rgba(139, 92, 246, 0.35); }

/* Скроллбары */
* { scrollbar-width: thin; scrollbar-color: rgba(139, 92, 246, 0.4) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.35); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.5); }

/* ============ Каркас ============ */

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 55;
}

/* ============ Иконочные кнопки ============ */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn svg { width: 19px; height: 19px; }

.icon-btn:hover {
  background: var(--bg-elev2);
  color: var(--text);
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.icon-btn:disabled:hover { background: none; color: var(--text-dim); }

/* ============ Сайдбар ============ */

.sidebar {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(38, 43, 51, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  gap: 12px;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .sidebar { background: var(--bg-elev); }
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.2px;
}

.logo__icon {
  width: 24px;
  height: 24px;
  color: var(--accent);
  filter: drop-shadow(0 0 10px rgba(139, 92, 246, 0.55));
}

.sidebar-close { display: none; }

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 4px 18px rgba(124, 58, 237, 0.35);
  transition: filter 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.new-chat-btn svg { width: 17px; height: 17px; }

.new-chat-btn:hover {
  filter: brightness(1.12);
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.5);
}

.new-chat-btn:active { transform: scale(0.98); }

/* Список чатов */

.chat-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 0 8px;
}

.chat-group {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  padding: 14px 8px 6px;
}

.chat-group:first-child { padding-top: 4px; }

.chat-group--pinned {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-hover);
}

.chat-group--pinned svg { width: 13px; height: 13px; }

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius-sm);
  padding: 0 4px 0 0;
  transition: background 0.12s ease;
}

.chat-item:hover, .chat-item:focus-within { background: var(--bg-elev2); }

.chat-item.active {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}

.chat-item__btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  text-align: left;
  padding: 10px 8px 10px 12px;
  font-size: 16px;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.chat-item.active .chat-item__btn { color: var(--text); }

.chat-item__btn > span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item__menu-btn {
  display: none;
  width: 28px;
  height: 28px;
  margin-right: 4px;
  flex-shrink: 0;
}

.chat-item__menu-btn svg { width: 16px; height: 16px; }

.chat-item:hover .chat-item__menu-btn,
.chat-item:focus-within .chat-item__menu-btn { display: inline-flex; }

.chat-item__pinmark {
  display: inline-flex;
  align-items: center;
  width: 13px;
  height: 13px;
  margin-right: 7px;
  color: var(--accent-hover);
  flex-shrink: 0;
}

.chat-item__pinmark svg { width: 13px; height: 13px; }

/* Скелетон генерации названия темы */
.chat-title-skeleton {
  display: inline-block;
  vertical-align: middle;
  width: 75%;
  max-width: 160px;
  height: 13px;
  border-radius: 7px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06) 25%,
    rgba(139, 92, 246, 0.25) 50%,
    rgba(255, 255, 255, 0.06) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (hover: none) {
  .chat-item__menu-btn { display: inline-flex; }
}

.chat-item__rename {
  flex: 1;
  min-width: 0;
  background: var(--bg-input);
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  padding: 7px 10px;
  margin: 2px 4px 2px 8px;
  outline: none;
}

.chat-item__confirm {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
  white-space: nowrap;
}

.chat-item.confirm .chat-item__btn,
.chat-item.confirm .chat-item__menu-btn { display: none; }
.chat-item.confirm .chat-item__confirm { display: flex; }

.chat-item__confirm button {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
}

.chat-item__confirm-yes { background: var(--danger-soft); color: var(--danger); }
.chat-item__confirm-yes:hover { background: rgba(248, 113, 113, 0.22); }
.chat-item__confirm-no:hover { background: var(--bg-elev2); }

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--border);
}

.sidebar-foot__user {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 8px 10px;
  margin: 0 -10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-foot__user:hover { background: var(--bg-elev2); color: var(--text); }

.sidebar-foot__user svg {
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: transform 0.4s ease;
}

.sidebar-foot__user:hover svg { color: var(--accent); transform: rotate(90deg); }

.sidebar-foot__user span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-faint);
  transition: background 0.15s ease, color 0.15s ease;
}

.logout-btn:hover { background: var(--bg-elev2); color: var(--danger); }
.logout-btn svg { width: 16px; height: 16px; }

/* ============ Основная область ============ */

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(29, 33, 39, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  min-height: 58px;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .topbar { background: rgba(29, 33, 39, 0.92); }
}

.menu-btn { display: none; }

.topbar-title {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: 300px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.model-btn:hover {
  border-color: var(--accent-border);
  background: var(--bg-elev2);
}

.model-btn__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-btn__icon { display: none; }
.model-btn__icon svg { width: 17px; height: 17px; color: var(--accent); }

.model-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.model-btn svg { width: 15px; height: 15px; color: var(--text-faint); }

/* ============ Лента сообщений ============ */

.messages-wrap {
  flex: 1;
  position: relative;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.messages {
  max-width: 800px;
  margin: 0 auto;
  padding: 78px 20px 170px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.msg {
  display: flex;
  gap: 14px;
  animation: msg-in 0.22s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--user {
  flex-direction: column;
  align-items: flex-end;
}

.msg--user .msg-bubble {
  max-width: 78%;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  border-radius: 16px 16px 4px 16px;
  padding: 11px 15px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg--assistant { flex-direction: column; gap: 6px; }

.msg-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 2px 12px rgba(124, 58, 237, 0.4);
  margin-bottom: 2px;
}

.msg-avatar svg { width: 18px; height: 18px; color: #fff; }

.assistant-row {
  display: flex;
  gap: 14px;
}

.assistant-body {
  flex: 1;
  min-width: 0;
}

.msg-content { word-break: break-word; font-size: 18px; line-height: 1.65; }

.msg--error .msg-content {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
}

.msg-meta {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.msg:hover .msg-meta, .msg-meta:focus-within { opacity: 1; }

@media (hover: none) {
  .msg-meta { opacity: 1; }
}

.msg-copy {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  padding: 5px 8px;
  border-radius: 8px;
}

.msg-copy:hover { background: var(--bg-elev2); color: var(--text-dim); }
.msg-copy svg { width: 14px; height: 14px; }

.msg-usage,
.composer-stats {
  font-size: 11.5px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.msg-usage {
  padding: 5px 6px;
  white-space: nowrap;
  align-self: center;
}

/* Курсор печати */

.cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--accent);
  border-radius: 2px;
  animation: blink 0.9s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* Вложения в сообщении */

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.att-thumb {
  max-width: 200px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  display: block;
}

.att-audio {
  width: 280px;
  max-width: 100%;
  height: 40px;
}

.att-video {
  max-width: 320px;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  display: block;
}

.att-file {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text-dim);
  font-size: 16px;
  text-decoration: none;
  max-width: 100%;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.att-file:hover { border-color: var(--accent-border); color: var(--text); }
.att-file svg { width: 17px; height: 17px; color: var(--accent); flex-shrink: 0; }
.att-file span {
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ Markdown ============ */

.msg-content > *:first-child { margin-top: 0; }
.msg-content > *:last-child { margin-bottom: 0; }

.msg-content p { margin: 0 0 14px; }

.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 20px 0 10px;
  line-height: 1.3;
}

.msg-content h1 { font-size: 1.35em; }
.msg-content h2 { font-size: 1.2em; }
.msg-content h3 { font-size: 1.08em; }

.msg-content ul, .msg-content ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.msg-content li { margin: 4px 0; }

.msg-content a {
  color: var(--accent-hover);
  text-decoration: none;
  border-bottom: 1px solid rgba(167, 139, 250, 0.4);
}

.msg-content a:hover { border-bottom-color: var(--accent-hover); }

.msg-content blockquote {
  margin: 0 0 12px;
  padding: 4px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(139, 92, 246, 0.06);
  border-radius: 0 8px 8px 0;
  color: var(--text-dim);
}

.msg-content code:not(pre code) {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.18);
  padding: 1.5px 6px;
  border-radius: 6px;
}

.msg-content table {
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}

.msg-content th, .msg-content td {
  border: 1px solid var(--border-strong);
  padding: 7px 12px;
  text-align: left;
}

.msg-content th { background: var(--bg-elev2); font-weight: 600; }

.msg-content hr {
  border: none;
  border-top: 1px solid var(--border-strong);
  margin: 18px 0;
}

.msg-content img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* Блоки кода */

.code-wrap {
  position: relative;
  margin: 0 0 14px;
}

.code-wrap pre {
  margin: 0;
  padding: 14px 16px;
  padding-top: 40px;
  background: #1b1e24;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.code-wrap code {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  background: none !important;
  padding: 0 !important;
}

.code-wrap__bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  pointer-events: none;
}

.code-wrap__lang {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
  text-transform: lowercase;
}

.code-copy {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 4px 8px;
  border-radius: 7px;
}

.code-copy:hover { background: var(--bg-elev2); color: var(--text-dim); }
.code-copy svg { width: 13px; height: 13px; }

/* ============ Пустое состояние ============ */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 12px;
  animation: msg-in 0.3s ease;
}

.empty-state__orb {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 8px 40px rgba(124, 58, 237, 0.45);
  margin-bottom: 8px;
}

.empty-state__orb svg { width: 36px; height: 36px; color: #fff; }

.empty-state h1 {
  margin: 0;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: -0.5px;
  text-align: center;
  background: linear-gradient(90deg, #e6e9ef 30%, var(--accent-hover));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.empty-state p {
  margin: 0 0 14px;
  color: var(--text-faint);
  font-size: 17px;
  text-align: center;
}

/* ============ Композер ============ */

.composer-zone {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: 10px 20px calc(16px + env(safe-area-inset-bottom));
  background: transparent;
  pointer-events: none;
}

.composer-zone .chips,
.composer-zone .composer,
.composer-zone .rec-panel {
  pointer-events: auto;
}

.composer-max {
  max-width: 800px;
  margin: 0 auto;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 240px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  font-size: 13px;
  color: var(--text-dim);
  animation: msg-in 0.18s ease;
}

.chip--warn { border-color: rgba(248, 113, 113, 0.5); background: var(--danger-soft); }

.chip__thumb {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 7px;
  flex-shrink: 0;
}

.chip__icon { width: 17px; height: 17px; color: var(--accent); flex-shrink: 0; }

.chip__name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.chip__size { color: var(--text-faint); flex-shrink: 0; }

.chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.chip__remove:hover { background: var(--bg-elev2); color: var(--danger); }
.chip__remove svg { width: 13px; height: 13px; }

.chip--uploading { opacity: 0.55; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 9px 9px 9px 6px;
  border-radius: 18px;
  border: 1px solid var(--border-strong);
  background: rgba(43, 48, 58, 0.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .composer { background: rgba(43, 48, 58, 0.94); }
}

.composer:focus-within {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12), 0 4px 24px rgba(0, 0, 0, 0.3);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  line-height: 1.5;
  padding: 8px 4px;
  max-height: 172px;
}

.composer textarea::placeholder { color: var(--text-faint); }

.send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 3px 14px rgba(124, 58, 237, 0.4);
  transition: filter 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.send-btn svg { width: 18px; height: 18px; }

.send-btn:hover:not(:disabled) { filter: brightness(1.15); }

.send-btn:active:not(:disabled) { transform: scale(0.94); }

.send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

.send-btn--stop {
  background: var(--bg-elev2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  box-shadow: none;
}

/* Голосовой ввод: панель записи вместо композера */

.composer--away { animation: comp-away 0.16s ease forwards; }

.composer--in { animation: comp-in 0.24s ease; }

@keyframes comp-away {
  to { transform: translateY(130%); opacity: 0; }
}

@keyframes comp-in {
  from { transform: translateY(24px); opacity: 0; }
}

.rec-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px 10px;
  border-radius: 18px;
  border: 1px solid var(--accent-border);
  background: rgba(43, 48, 58, 0.6);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .rec-panel { background: rgba(43, 48, 58, 0.94); }
}

.rec-panel--in { animation: comp-in 0.24s ease; }

.rec-panel--out { animation: comp-away 0.16s ease forwards; }

.rec-panel__main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.rec-panel__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  animation: rec-blink 1.4s ease-in-out infinite;
}

@keyframes rec-blink {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
  50% { opacity: 0.55; box-shadow: 0 0 0 6px rgba(248, 113, 113, 0); }
}

.rec-panel__wave {
  flex: 1;
  min-width: 0;
  height: 44px;
  overflow: hidden;
  border-radius: 10px;
  background: rgba(15, 17, 21, 0.35);
}

.rec-panel__wave canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.rec-panel__time {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text-dim);
  min-width: 44px;
  text-align: right;
  flex-shrink: 0;
}

.rec-panel__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.rec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.rec-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.rec-btn:hover:not(:disabled) { border-color: var(--accent); background: var(--bg-elev2); }

.rec-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.rec-btn--soft { color: var(--accent-hover); }

.rec-btn--accent {
  color: #fff;
  border: none;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 3px 14px rgba(124, 58, 237, 0.4);
}

.rec-btn--accent:hover:not(:disabled) { filter: brightness(1.15); background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%); }

.rec-btn--accent svg { width: 17px; height: 17px; }

.rec-panel.is-busy .rec-panel__wave { opacity: 0.35; }
.rec-panel.is-busy .rec-panel__dot { animation: none; opacity: 0.6; }
.rec-panel.is-busy .rec-panel__time::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  border: 2px solid var(--text-faint);
  border-top-color: var(--accent-hover);
  border-radius: 50%;
  vertical-align: -1px;
  animation: rec-spin 0.9s linear infinite;
}

@keyframes rec-spin { to { transform: rotate(360deg); } }

@media (max-width: 520px) {
  .rec-btn span { display: none; }
  .rec-btn { padding: 8px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .composer--away, .composer--in, .rec-panel--in, .rec-panel--out, .rec-panel__dot {
    animation: none;
  }
}

.composer-stats {
  text-align: center;
  padding: 8px 0 0;
  opacity: 0.75;
}

/* Кнопка «вниз» */

.scroll-down {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev2);
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  box-shadow: var(--shadow-pop);
  z-index: 25;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.scroll-down:hover { color: var(--accent-hover); border-color: var(--accent-border); }
.scroll-down svg { width: 18px; height: 18px; }

/* ============ Дровер выбора модели ============ */

.drawer {
  position: fixed;
  inset: 0;
  z-index: 70;
  pointer-events: none;
  visibility: hidden;
}

.drawer.open {
  pointer-events: auto;
  visibility: visible;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.drawer.open .drawer-backdrop { opacity: 1; }

.drawer-panel {
  position: absolute;
  top: 66px;
  right: 16px;
  width: 400px;
  max-width: calc(100vw - 32px);
  max-height: min(70vh, 620px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
  transform: scale(0.96) translateY(-6px);
  transform-origin: top right;
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
  overflow: hidden;
}

.drawer.open .drawer-panel {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.drawer-handle { display: none; }

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 10px 10px 18px;
  flex-shrink: 0;
}

.drawer-title { font-size: 15px; font-weight: 700; }

.drawer-count {
  color: var(--text-faint);
  font-weight: 500;
  font-size: 13px;
}

.drawer-search {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 14px 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  flex-shrink: 0;
  transition: border-color 0.15s ease;
}

.drawer-search:focus-within { border-color: var(--accent-border); }

.drawer-search svg { width: 16px; height: 16px; color: var(--text-faint); flex-shrink: 0; }

.drawer-search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14.5px;
}

.drawer-search input::placeholder { color: var(--text-faint); }

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

.drawer-group {
  padding: 10px 6px 4px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-faint);
}

.drawer-group:first-child { padding-top: 2px; }

.model-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.model-item:hover { background: var(--bg-elev2); }

.model-item.selected {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.model-item--off { opacity: 0.45; cursor: not-allowed; }

.model-item__body {
  flex: 1;
  min-width: 0;
}

.model-item__name {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-item__id {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-item__badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.22);
  color: var(--accent-hover);
}

.badge--off {
  background: var(--danger-soft);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--danger);
}

.model-item__check {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--accent);
  opacity: 0;
}

.model-item.selected .model-item__check { opacity: 1; }

.drawer-empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13.5px;
}

.drawer-empty a {
  color: var(--accent-hover);
  font-weight: 600;
  display: inline-block;
  margin-top: 8px;
}

/* ============ Popover-меню (действия чата, режимы) ============ */

.menu-pop {
  position: fixed;
  z-index: 80;
  min-width: 230px;
  max-width: min(320px, calc(100vw - 16px));
  padding: 5px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  display: flex;
  flex-direction: column;
  gap: 1px;
  animation: menu-in 0.14s ease;
}

.menu-pop--up { animation-name: menu-in-up; }

@keyframes menu-in {
  from { opacity: 0; transform: translateY(5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes menu-in-up {
  from { opacity: 0; transform: translateY(-5px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.menu-pop__caption {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-faint);
  padding: 7px 10px 5px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-dim);
  transition: background 0.12s ease, color 0.12s ease;
}

.menu-item:hover { background: var(--bg-elev2); color: var(--text); }

.menu-item:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.menu-item:disabled:hover { background: none; color: var(--text-dim); }

.menu-item__icon {
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
  display: inline-flex;
}

.menu-item__icon svg { width: 16px; height: 16px; }

.menu-item__label { min-width: 0; }

.menu-item__state {
  width: 16px;
  margin-left: auto;
  color: var(--accent);
  display: inline-flex;
  flex-shrink: 0;
}

.menu-item__state svg { width: 15px; height: 15px; }

.menu-item--danger { color: var(--danger); }
.menu-item--danger .menu-item__icon { color: var(--danger); }
.menu-item--danger:hover { background: var(--danger-soft); color: var(--danger); }

.menu-item__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.menu-item__hint {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-faint);
}

.menu-item__switch {
  width: 34px;
  height: 20px;
  flex-shrink: 0;
  border-radius: 20px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.menu-item__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: transform 0.15s ease, background 0.15s ease;
}

.menu-item.is-on .menu-item__switch {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.menu-item.is-on .menu-item__knob {
  transform: translateX(14px);
  background: var(--accent);
}

.menu-item--warn.is-on .menu-item__switch {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.4);
}

.menu-item--warn.is-on .menu-item__knob { background: #f59e0b; }

/* ============ Тосты ============ */

.toasts {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 24px));
}

.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-elev2);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-pop);
  font-size: 16px;
  color: var(--text);
  animation: toast-in 0.22s ease;
}

.toast--error { border-color: rgba(248, 113, 113, 0.45); background: #2f2327; color: #fca5a5; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.hide { opacity: 0; transition: opacity 0.3s ease; }

/* ============ Мобильная версия ============ */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(360px, 88vw);
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    box-shadow: none;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-pop);
  }

  .sidebar-close { display: inline-flex; }

  .menu-btn { display: inline-flex; }

  .chat-item__btn { font-size: 14.5px; }

  .chat-item__rename { font-size: 13px; }

  .new-chat-btn { font-size: 16px; }

  .topbar { padding: 8px 10px; min-height: 54px; }

  .topbar-title { font-size: 16px; }

  .model-btn {
    max-width: none;
    padding: 8px;
    gap: 5px;
  }

  .model-btn__name { display: none; }

  .model-btn__icon { display: inline-flex; }

  .model-btn > svg { width: 12px; height: 12px; }

  .messages { padding: 70px 12px 150px; gap: 18px; }

  .msg--user .msg-bubble { max-width: 88%; font-size: 16px; }

  .assistant-row { gap: 10px; }

  .msg-avatar { width: 28px; height: 28px; }

  .msg-content { font-size: 16px; }

  .msg-skills { gap: 6px; margin-bottom: 8px; }

  .clarify { max-width: 100%; }

  .clarify__hint-wrap { padding: 7px 10px 0; }

  .clarify__hint { font-size: 11.5px; }

  .clarify__options { flex-direction: column; align-items: stretch; gap: 7px; padding: 8px 10px 10px; }

  .clarify__btn { width: 100%; min-height: 42px; }

  .reasoning,
  .skill-group { max-width: 100%; }

  .reasoning summary,
  .skill-group__head { padding: 8px 10px; }

  .reasoning__text { max-height: 200px; font-size: 13px; }

  .skill-row { flex-wrap: wrap; padding: 6px 10px; gap: 7px; }

  .skill-row__dur { margin-left: auto; padding-left: 6px; }

  .skill-group__status { font-size: 11px; }

  .empty-state h1 { font-size: 22px; }

  .empty-state p { font-size: 15px; }

  .composer-zone { padding: 8px 10px calc(10px + env(safe-area-inset-bottom)); }

  .composer textarea { font-size: 16px; }

  .menu-pop { min-width: 210px; }

  /* Дровер моделей: bottom-sheet на 70% экрана, не меньше */
  .drawer-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 70vh;
    min-height: 70vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(105%);
    transform-origin: bottom center;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .drawer.open .drawer-panel { transform: translateY(0); }

  .drawer-handle {
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 4px;
    background: var(--border-strong);
    margin: 10px auto 0;
    flex-shrink: 0;
  }

  .drawer-head { padding-top: 10px; }

  .scroll-down { bottom: 100px; }
}

/* ============ Кнопка и меню режимов ============ */

.modes-btn {
  position: relative;
  color: var(--text-faint);
}

.modes-btn svg { width: 20px; height: 20px; }

.modes-btn.has-on { color: var(--accent); }

.modes-btn.has-on:hover { color: var(--accent-hover); }

.modes-btn__dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(139, 92, 246, 0.8);
}

/* ============ Раскрывающиеся панели (размышления, навыки) ============ */
/* Единая конструкция: панель → шапка (иконка, заголовок, статус, шеврон)
   → grid-обёртка (анимация 0fr→1fr) → вьюпорт (overflow:hidden) → контент. */

.reasoning,
.skill-group {
  max-width: min(480px, 100%);
  min-width: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: rgba(38, 43, 51, 0.72);
  overflow: hidden;
  font-size: 13px;
}

.reasoning { margin-bottom: 10px; }

.reasoning summary,
.skill-group__head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.reasoning summary { list-style: none; }

.reasoning summary::-webkit-details-marker { display: none; }

.reasoning summary:focus-visible,
.skill-group__head:focus-visible {
  outline: 2px solid var(--accent-border);
  outline-offset: -2px;
}

.reasoning summary .r-ic,
.skill-group__icon {
  display: flex;
  width: 15px;
  height: 15px;
  color: var(--accent);
  flex-shrink: 0;
}

.reasoning summary .r-ic svg,
.skill-group__icon svg { width: 100%; height: 100%; }

.reasoning .r-label,
.skill-group__title {
  min-width: 0;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reasoning--live .r-label,
.skill-group.is-run .skill-group__title {
  animation: think 1.2s ease infinite;
  color: var(--accent-hover);
}

@keyframes think { 50% { opacity: 0.45; } }

.reasoning .chev,
.skill-group__chev {
  display: flex;
  width: 14px;
  height: 14px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: transform 0.25s ease;
}

.reasoning .chev { margin-left: auto; }

.reasoning .chev svg,
.skill-group__chev svg { width: 100%; height: 100%; }

.reasoning[open] summary .chev,
.skill-group.is-open .skill-group__chev { transform: rotate(180deg); }

/* Анимация раскрытия: grid-трюк 0fr ↔ 1fr.
   Паддинги живут на контенте, вьюпорт строго без них. */

.reasoning__wrap,
.skill-group__items {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.28s ease;
}

.reasoning__wrap.is-collapsed,
.skill-group__items.is-collapsed { grid-template-rows: 0fr; }

.reasoning__body,
.skill-group__inner {
  min-height: 0;
  overflow: hidden;
}

.reasoning__text {
  padding: 8px 12px 10px;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

/* ============ Страницы входа/регистрации ============ */

body.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
  background:
    radial-gradient(700px 420px at 70% -10%, rgba(139, 92, 246, 0.12), transparent 60%),
    var(--bg);
}

.auth-card {
  position: relative;
  z-index: 1;
  width: min(400px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 28px 26px 26px;
  box-shadow: var(--shadow-pop);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.2px;
  margin-bottom: 14px;
}

.auth-orb {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 6px 26px rgba(124, 58, 237, 0.45);
}

.auth-orb svg { width: 22px; height: 22px; color: #fff; }

.auth-title {
  margin: 0 0 18px;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.auth-field { margin-bottom: 14px; }

.auth-field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.auth-field input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-field input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.auth-field input::placeholder { color: var(--text-faint); }

.auth-error {
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 13.5px;
  color: #fca5a5;
  margin-bottom: 14px;
}

.auth-submit {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  box-shadow: 0 4px 18px rgba(124, 58, 237, 0.35);
  transition: filter 0.15s ease, transform 0.1s ease;
}

.auth-submit:hover { filter: brightness(1.12); }
.auth-submit:active { transform: scale(0.99); }

.auth-switch {
  display: block;
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-faint);
  text-decoration: none;
  transition: color 0.15s ease;
}

.auth-switch:hover { color: var(--accent-hover); }

/* ============ Страница настроек ============ */

.settings-body {
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}

.settings-app {
  display: flex;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* Сайдбар / меню разделов (как в чате) */

.settings-nav {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: rgba(38, 43, 51, 0.55);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  gap: 12px;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .settings-nav { background: var(--bg-elev); }
}

.settings-nav__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px;
  min-height: 36px;
}

.settings-nav__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.2px;
}

.settings-nav__close {
  display: none;
}

.settings-menu {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
}

.settings-menu__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  transition: background 0.12s ease, color 0.12s ease;
}

.settings-menu__item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-faint);
  transition: color 0.12s ease;
}

.settings-menu__item:hover {
  background: var(--bg-elev2);
  color: var(--text);
}

.settings-menu__item:hover svg {
  color: var(--text-dim);
}

.settings-menu__item.is-active {
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 3px 0 0 var(--accent);
}

.settings-menu__item.is-active svg {
  color: var(--accent);
}

.settings-nav__foot {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 4px 0;
  border-top: 1px solid var(--border);
}

.settings-nav__foot-link,
.settings-nav__foot-user {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
}

.settings-nav__foot-link svg,
.settings-nav__foot-user svg {
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.settings-nav__foot-link:hover,
.settings-nav__foot-user:hover {
  background: var(--bg-elev2);
  color: var(--text);
}

.settings-nav__foot-link:hover svg,
.settings-nav__foot-user:hover svg {
  color: var(--accent);
}

/* Основная колонка */

.settings-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  height: 100dvh;
  background: var(--bg);
}

/* Топбар */

.settings-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  min-height: 58px;
  border-bottom: 1px solid var(--border);
  background: rgba(29, 33, 39, 0.65);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  z-index: 20;
  flex-shrink: 0;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .settings-topbar { background: rgba(29, 33, 39, 0.94); }
}

.settings-topbar__left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.settings-menu-btn {
  display: none;
}

.settings-topbar__title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.settings-topbar__back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.settings-topbar__back svg {
  width: 15px;
  height: 15px;
}

.settings-topbar__back:hover {
  background: var(--bg-elev2);
  border-color: var(--accent-border);
  color: var(--text);
}

/* Скролл и центрированный контент */

.settings-scroll {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.settings-content {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 20px 48px;
  display: flex;
  flex-direction: column;
}

.settings-lead {
  margin: 0 0 28px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-dim);
}

.settings-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 20px;
}

.settings-info {
  margin: 0;
  display: flex;
  flex-direction: column;
}

.settings-info__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.settings-info__row:last-child {
  border-bottom: none;
}

.settings-info__row dt {
  font-size: 14px;
  color: var(--text-dim);
}

.settings-info__row dd {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  overflow-wrap: anywhere;
}

.settings-form {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}

.settings-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  gap: 12px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.settings-cards--fonts {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
}

.settings-label {
  display: block;
  padding: 0;
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
}

.settings-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  min-height: 74px;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.settings-option:hover:not(.settings-option--disabled) {
  border-color: var(--accent);
  background: var(--bg-elev2);
}

.settings-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.settings-option input[type='radio'] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  flex-shrink: 0;
}

.settings-option--disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.settings-option__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.settings-option__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.settings-option__name:has(+ .settings-option__desc) {
  line-height: 1.35;
}

.settings-option__desc {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.settings-preview {
  margin-top: 24px;
  padding: 20px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.settings-preview__label {
  margin: 0 0 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
}

.settings-preview__bubble {
  line-height: 1.65;
  font-size: 18px;
  transition: font-size 0.15s ease;
}

.settings-form textarea {
  width: 100%;
  max-width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 14px 16px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--mono);
  line-height: 1.55;
  outline: none;
  resize: vertical;
  min-height: 240px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.settings-form textarea:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.settings-form textarea::placeholder {
  color: var(--text-faint);
}

.settings-form .auth-field {
  margin-bottom: 20px;
}

.settings-form .auth-field:last-child {
  margin-bottom: 0;
}

.settings-form .auth-field input {
  min-width: 0;
  min-height: 48px;
}

.settings-field-hint {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--text-dim);
}

/* Числовое поле (шаги агентского цикла на странице «Модель») */

.settings-number-field {
  margin-top: 24px;
}

.settings-number-field input[type='number'] {
  width: 120px;
  min-height: 48px;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.settings-number-field input[type='number']:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

/* Страница «Модели»: аккордеон провайдеров + чекбоксы моделей */

.models-acc {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  overflow: hidden;
}

.models-acc + .models-acc { margin-top: 14px; }

.models-acc__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.models-acc__head::-webkit-details-marker { display: none; }

.models-acc__chev { color: var(--text-faint); display: inline-flex; }

.models-acc__chev svg {
  width: 18px;
  height: 18px;
  transition: transform 0.15s ease;
}

.models-acc[open] > .models-acc__head .models-acc__chev svg { transform: rotate(180deg); }

.models-acc__title { font-size: 16px; font-weight: 700; }

.models-acc__meta {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.models-key-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  padding: 3px 10px;
  border-radius: 20px;
  font-family: var(--mono);
}

.models-key-badge.is-on {
  color: var(--accent-hover);
  border-color: rgba(139, 92, 246, 0.35);
  background: rgba(139, 92, 246, 0.08);
}

.models-acc__count {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-hover);
  background: rgba(139, 92, 246, 0.12);
  border: 1px solid rgba(139, 92, 246, 0.25);
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.models-acc__count:empty { display: none; }

.models-acc__body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
}

.models-acc__hint { margin: 0; }

.provider-key__row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.provider-key__row input {
  flex: 1;
  min-width: 220px;
  min-height: 46px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--mono);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.provider-key__row input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.provider-key__row input[type='number'] { max-width: 180px; }

.provider-key__clear {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
}

.provider-key__clear input { accent-color: var(--danger); }

.models-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.models-toolbar .drawer-search {
  flex: 1;
  min-width: 200px;
  margin: 0;
}

.models-bulk {
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.models-bulk:hover { border-color: var(--accent); color: var(--text); }

.models-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 430px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: var(--bg);
}

.model-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.model-check:hover { background: var(--bg-elev2); }

.model-check input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
  margin: 3px 0 0;
  flex-shrink: 0;
}

.model-check[hidden] { display: none; }

.model-check__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.model-check__name { font-size: 14px; font-weight: 600; }

.model-check__prov {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-hover);
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 1px 8px;
  border-radius: 12px;
  margin-left: 4px;
  vertical-align: 1px;
}

.model-check__meta {
  font-size: 12px;
  color: var(--text-faint);
  font-family: var(--mono);
  overflow-wrap: anywhere;
}

.model-check--stale { opacity: 0.7; }
.model-check--stale .model-check__name { color: var(--text-dim); }

.models-list--stale { max-height: none; margin-bottom: 0; }

.models-empty {
  padding: 16px;
  font-size: 14px;
  color: var(--text-dim);
}

.models-empty--page {
  padding: 18px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.models-empty--page a { color: var(--accent-hover); }

.settings-locked {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 480px;
  padding: 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.settings-locked__text {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--text-dim);
}

.settings-locked__btn {
  display: inline-block;
  width: auto;
  align-self: flex-start;
  min-width: 200px;
  padding: 11px 18px;
  text-align: center;
  text-decoration: none;
}

.settings-option__prov {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent-hover);
  border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 1px 8px;
  border-radius: 12px;
  margin-left: 6px;
  vertical-align: 1px;
  text-transform: capitalize;
}

/* Липкая нижняя панель действий (как composer-zone) */

.settings-actions-zone {
  flex-shrink: 0;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(29, 33, 39, 0.65);
  -webkit-backdrop-filter: blur(18px) saturate(1.5);
  backdrop-filter: blur(18px) saturate(1.5);
  z-index: 10;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .settings-actions-zone { background: rgba(29, 33, 39, 0.94); }
}

.settings-actions-max {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.settings-actions__hint {
  font-size: 13px;
  color: var(--text-dim);
}

.settings-actions__submit {
  width: auto;
  min-width: 170px;
  min-height: 46px;
  padding: 12px 24px;
  box-shadow: none;
}

.settings-body :is(a, button, input, textarea, [tabindex]):focus-visible,
.settings-option:has(input:focus-visible) {
  outline: 2px solid var(--accent-hover);
  outline-offset: 3px;
}

/* Размер текста сообщений (настройка «Внешний вид») */

body[data-font='compact'] .msg-content { font-size: 16px; }
body[data-font='large'] .msg-content { font-size: 20px; }

@media (max-width: 768px) {
  body[data-font='compact'] .msg-content { font-size: 15px; }
  body[data-font='large'] .msg-content { font-size: 18px; }
}

.profile-banner {
  margin-bottom: 24px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid;
}

.profile-banner--success {
  background: rgba(74, 222, 128, 0.1);
  border-color: rgba(74, 222, 128, 0.35);
  color: #6ee7a0;
}

.profile-banner--error,
.profile-banner--warning {
  background: var(--danger-soft);
  border-color: rgba(248, 113, 113, 0.35);
  color: #fca5a5;
}

/* ============ Адаптивность настроек ============ */

@media (max-width: 768px) {
  .settings-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 60; /* выше .backdrop (55), иначе меню затемняется и размывается под ним */
    transform: translateX(-105%);
    transition: transform 0.24s ease;
    box-shadow: none;
  }

  .settings-nav.open {
    transform: translateX(0);
    box-shadow: var(--shadow-pop);
  }

  .settings-nav__close {
    display: inline-flex;
  }

  .settings-menu-btn {
    display: inline-flex;
  }

  .settings-topbar {
    padding: 8px 12px;
    min-height: 54px;
  }

  .settings-topbar__title {
    font-size: 17px;
  }

  .settings-topbar__back span {
    display: none;
  }

  .settings-topbar__back {
    padding: 7px 9px;
  }

  .settings-content {
    padding: 20px 14px 32px;
  }

  .settings-lead {
    margin-bottom: 20px;
    font-size: 14px;
  }

  .settings-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-cards--fonts {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-info__row {
    padding: 14px 0;
  }

  .settings-actions-zone {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .settings-actions-max {
    flex-direction: column-reverse;
    align-items: stretch;
    gap: 8px;
  }

  .settings-actions__hint {
    text-align: center;
    font-size: 12px;
    display: none;
  }

  .settings-actions__submit {
    width: 100%;
    min-width: 0;
    min-height: 48px;
  }
}


/* ---------- Источники веб-поиска ---------- */

.msg-sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.msg-sources__label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-faint);
  margin-bottom: 8px;
}

.msg-sources__label svg { width: 14px; height: 14px; color: var(--accent); }

.msg-sources__list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13.5px;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.source-chip:hover {
  border-color: var(--accent-border);
  color: var(--text);
}

.source-chip__domain {
  font-weight: 700;
  color: var(--accent-hover);
  flex-shrink: 0;
}

.source-chip__title {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-chip svg { width: 13px; height: 13px; color: var(--text-faint); flex-shrink: 0; }
.source-chip:hover svg { color: var(--accent-hover); }


/* ---------- Группа вызовов навыков ---------- */
/* Панель, шапка и анимация раскрытия — в общей секции выше */

.msg-skills {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.skill-group { transition: border-color 0.2s ease; }

.skill-group.is-run { border-color: var(--accent-border); }
.skill-group.is-err { border-color: rgba(248, 113, 113, 0.35); }

.skill-group__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 400;
  white-space: nowrap;
  flex-shrink: 0;
}

.skill-group.is-err .skill-group__status { color: var(--danger); }

.skill-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 12px;
  min-width: 0;
}

.skill-row + .skill-row { border-top: 1px solid var(--border); }

.skill-row__state {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  margin-top: 2px;
  color: var(--text-faint);
  flex-shrink: 0;
}

.skill-row__state svg { width: 100%; height: 100%; }
.skill-row.is-ok .skill-row__state { color: var(--accent); }
.skill-row.is-err .skill-row__state { color: var(--danger); }

.skill-row__body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.skill-row__fn {
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.skill-row__args {
  color: var(--text-dim);
  font-size: 11.5px;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.skill-row__dur {
  margin-top: 2px;
  margin-left: auto;
  padding-left: 8px;
  color: var(--text-faint);
  font-size: 11.5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.skill-row.is-err .skill-row__dur { color: var(--danger); }

.skill-spin {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: skill-spin 0.8s linear infinite;
}

@keyframes skill-spin { to { transform: rotate(360deg); } }

/* ---------- Уточняющие вопросы ---------- */
/* Карточка в стиле панелей reasoning/skill-group: вопрос уже в тексте
   сообщения, здесь — подсказка и варианты ответа кнопками. */

.clarify {
  max-width: min(480px, 100%);
  margin: 12px 0 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: rgba(38, 43, 51, 0.72);
  overflow: hidden;
  animation: clarify-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

@keyframes clarify-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to { opacity: 1; transform: none; }
}

/* Подсказка: после ответа сворачивается (грид-трюк 1fr -> 0fr) */
.clarify__hint-wrap {
  display: grid;
  grid-template-rows: 1fr;
  padding: 8px 12px 0;
  transition: grid-template-rows 0.3s ease, padding 0.3s ease, opacity 0.25s ease;
}

.clarify.is-closed .clarify__hint-wrap { grid-template-rows: 0fr; padding-top: 0; opacity: 0; }

.clarify__hint {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 0;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 12px;
  user-select: none;
  white-space: nowrap;
}

.clarify__hint svg {
  width: 13px;
  height: 13px;
  color: var(--accent);
  flex-shrink: 0;
}

.clarify__options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px 12px;
}

.clarify__btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease,
    transform 0.16s ease, box-shadow 0.16s ease, opacity 0.25s ease;
}

/* Волна появления кнопок — только у живого (не закрытого) вопроса */
.clarify:not(.is-closed) .clarify__btn {
  animation: clarify-btn-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards;
  animation-delay: calc(var(--i, 0) * 50ms);
}

@keyframes clarify-btn-in {
  from { opacity: 0; transform: translateY(7px) scale(0.97); }
  to { opacity: 1; transform: none; }
}

.clarify__btn:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.22);
}

.clarify__btn:active { transform: translateY(0) scale(0.98); }

.clarify__btn:focus-visible {
  outline: 2px solid var(--accent-border);
  outline-offset: 2px;
}

/* Галочка выбранного варианта */
.clarify__check {
  display: none;
  width: 14px;
  height: 14px;
  color: #fff;
  flex-shrink: 0;
  animation: clarify-pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
}

.clarify__check svg { width: 100%; height: 100%; }

.clarify__btn.is-selected {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 3px 16px rgba(124, 58, 237, 0.38);
  cursor: default;
}

.clarify__btn.is-selected .clarify__check { display: flex; }

@keyframes clarify-pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Стрим ещё идёт: кнопки «дышат», кликов нет */
.clarify.is-wait .clarify__btn {
  pointer-events: none;
  animation: clarify-btn-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) backwards,
    clarify-breathe 1.6s ease-in-out calc(var(--i, 0) * 50ms + 0.45s) infinite;
}

@keyframes clarify-breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Вопрос закрыт: варианты гаснут, выбранный остаётся подсвеченным */
.clarify.is-closed .clarify__btn {
  pointer-events: none;
  opacity: 0.45;
  transform: none;
  box-shadow: none;
}

.clarify.is-closed .clarify__btn.is-selected { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .messages-wrap { scroll-behavior: auto; }
}

/* Страница «Память»: переключатель, пересборка, факты по разделам */

.memory-toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  margin-bottom: 24px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.memory-toggle:hover {
  border-color: var(--accent);
  background: var(--bg-elev2);
}

.memory-toggle:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}

.memory-toggle input[type='checkbox'] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  margin: 3px 0 0;
  flex-shrink: 0;
}

.memory-toggle__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.memory-toggle__name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.memory-toggle__desc {
  font-size: 12.5px;
  color: var(--text-dim);
}

.memory-rebuild {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.memory-rebuild .settings-field-hint {
  margin: 0;
}

.memory-facts {
  margin-top: 28px;
}

.memory-facts > .settings-label {
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-size: 12px;
  color: var(--text-faint);
}

.memory-add {
  margin: 14px 0 20px;
}

.memory-add__row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.memory-add__row select {
  max-width: 260px;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.memory-add__row input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.memory-add__row input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12);
}

.memory-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  overflow: hidden;
}

.memory-group + .memory-group { margin-top: 14px; }

.memory-group__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}

.memory-group__title {
  font-size: 14px;
  font-weight: 700;
}

.memory-group__count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 2px 10px;
}

.memory-fact {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 18px;
}

.memory-fact + .memory-fact {
  border-top: 1px solid var(--border);
}

.memory-fact__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.memory-fact__text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  overflow-wrap: anywhere;
}

.memory-fact__meta {
  font-size: 12px;
  color: var(--text-faint);
}

.memory-fact__del { flex-shrink: 0; }

.memory-fact__del-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-faint);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.memory-fact__del-btn:hover {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.08);
}

.memory-fact__del-btn svg { width: 15px; height: 15px; }
