/*
 * Чат AI — кастомные стили
 * Цвета взяты из дизайн-токенов проекта:
 *   --brand совпадает с .bg-brand: rgb(226 132 31) из base.css
 *   --bg-page совпадает с background: #efefef из base.css
 */

:root {
  --brand: #E2841F;
  --brand-rgb: rgb(226, 132, 31);
  --brand-dark: #c5731a;
  --brand-light: rgba(226, 132, 31, 0.10);
  --brand-faint: rgba(226, 132, 31, 0.04);

  --bg-page: #ffffff; /*#101010;  ;*/
  --bg-white: #fff;   /* #303030;  */
  --bg-surface: #fff;
  --bg-user-msg: #f7f8fc; /* #rgb(209, 213, 219);*/
  --bg-ai-msg: #ffffff;  /* #101010; */

  --text-primary: #1d1d1f; /* rgb(20 20 19); */
  --text-body: #1d1d1f;
  --text-muted: #1d1d1f;
  --text-subtle: #9CA3AF;
  --text-faint: #B0B7C3;

  --border: #E2841F;
  --border-light: #F0F0F0;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
}

/* ── Тёмная тема ──────────────────────────────── */
[data-theme="dark"] {
  --bg-page: #101010;
  --bg-white: #1e1e1e;
  --bg-surface: #181818;
  --bg-user-msg: #262626;
  --bg-ai-msg: #101010;

  --text-primary: #f0f0f0;
  --text-body: #e0e0e0;
  --text-muted: #d1d5db;
  --text-subtle: #7a8291;
  --text-faint: #555e6e;

  --border: #E2841F;
  --border-light: #2a2a2a;
}

[data-theme="dark"] main {
  background-color: #161616 !important;
}

[data-theme="dark"] .sb-btn:hover {
  background: #2e2e2e;
}

[data-theme="dark"] .session-item:hover {
  background: #221c10;
}

[data-theme="dark"] .folder-header:hover {
  background: rgba(255, 255, 255, .04);
}

[data-theme="dark"] .si-menu-btn:hover {
  background: rgba(255, 255, 255, .08);
}

[data-theme="dark"] .msg-action-btn:hover {
  background: rgba(255, 255, 255, .08);
  color: var(--text-body);
}

[data-theme="dark"] .msg-bubble code {
  background: rgba(255, 255, 255, .1);
}

/* base.css содержит `h2, h3... { color: #1e2939 }` как глобальный селектор */
[data-theme="dark"] h1,
[data-theme="dark"] h2,
[data-theme="dark"] h3,
[data-theme="dark"] h4,
[data-theme="dark"] h5,
[data-theme="dark"] h6,
[data-theme="dark"] strong {
  color: var(--text-primary);
}

[data-theme="dark"] .sb-list::-webkit-scrollbar-thumb,
[data-theme="dark"] .sp::-webkit-scrollbar-thumb,
[data-theme="dark"] .messages-wrap::-webkit-scrollbar-thumb {
  background: #3a3a3a;
}

[data-theme="dark"] .modal-tabs {
  border-bottom-color: #2a2a2a;
}

[data-theme="dark"] .modal-tab:not(.active):hover {
  background: #2a2a2a;
  color: var(--text-primary);
}


[data-theme="dark"] .chat-expand-btn:hover {
  background: rgba(255, 255, 255, .07);
}

[data-theme="dark"] .sp-theme-btn {
  border-color: #333;
}

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

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
}

@supports (height: 100dvh) {
  html, body {
    height: 100dvh;
  }
}

/* ── Sidebar ──────────────────────────────────── */
.sb {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-page);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sb-top {
  padding: 20px 12px 10px;
  flex-shrink: 0;
}

/* Кнопки действий */
.sb-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.sb-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}

.sb-btn:hover {
  background: #f0f0f0;
}

/* "Новый чат" — залитая оранжевая */
.sb-btn-new {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.sb-btn-new:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

/* Поиск */
.sb-search {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.sb-search svg {
  flex-shrink: 0;
  color: var(--text-subtle);
}

.sb-search input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
}

.sb-search input::placeholder {
  color: var(--text-subtle);
}

.sb-section-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 6px;
}

.sb-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-subtle);
  text-transform: uppercase;
}

.sb-select-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-subtle);
  border-radius: var(--radius-sm);
  transition: color .12s, background .12s;
}

.sb-select-btn:hover {
  color: var(--brand);
  background: var(--brand-faint);
}

.sb-select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px;
  border-top: 1px solid var(--border-light);
  margin-top: 2px;
  gap: 6px;
}

.sb-select-count {
  font-size: 11px;
  color: var(--text-subtle);
  flex: 1;
}

.sb-select-actions {
  display: flex;
  gap: 4px;
}

.sb-select-delete {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: none;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.sb-select-delete:disabled {
  background: #D1D5DB;
  color: #9CA3AF;
  cursor: not-allowed;
}

.sb-select-delete:not(:disabled):hover {
  background: #dc2626;
}

.sb-select-cancel {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: none;
  color: var(--text-subtle);
  font-size: 11px;
  cursor: pointer;
  transition: border-color .12s;
}

.sb-select-cancel:hover {
  border-color: var(--text-subtle);
}

.sb-date-group {
  margin-top: 6px;
}

.sb-date-group:first-of-type {
  margin-top: 0;
}

.sb-date-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 12px 4px;
}

.sb-date-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--text-subtle);
  text-transform: uppercase;
}

.sb-group-select {
  display: none;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.sb.sb-select-mode .sb-group-select {
  display: flex;
}

.sb-group-checkbox {
  width: 13px;
  height: 13px;
  accent-color: var(--brand);
  cursor: pointer;
}

.folder-sessions .sb-date-group {
  margin-top: 4px;
}

.folder-sessions .sb-date-group:first-child {
  margin-top: 0;
}

.folder-sessions .sb-date-group-header {
  padding: 2px 12px 4px 28px;
}

.folder-sessions .sb-date-group-label {
  font-size: 9px;
}

.session-item.selected {
  background: var(--brand-faint);
  border-left-color: var(--brand);
}

.si-checkbox {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--brand);
  cursor: pointer;
}

/* Список сессий */
.sb-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 8px;
}

.sb-list::-webkit-scrollbar {
  width: 3px;
}

.sb-list::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px 5px 12px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-body);
  cursor: pointer;
  transition: background .12s;
  user-select: none;
  position: relative;
  border-left: 3px solid transparent;
}

.session-item:hover {
  background: #f4f0ec;
  border-left: 3px solid transparent;
}

/* Активный чат — левая оранжевая полоска */
.session-item.active {
  border-left-color: var(--brand);
  background: var(--brand-faint);
  color: var(--text-primary);
  font-weight: 600;
  padding-left: 9px;
  /* 12px - 3px border */
}

.session-item .si-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Кнопка меню "..." на сессии */
.si-actions {
  display: none;
  flex-shrink: 0;
  position: relative;
}

.session-item:hover .si-actions {
  display: flex;
}

.si-menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 3px 4px;
  color: var(--text-subtle);
  border-radius: var(--radius-sm);
  line-height: 0;
}

.si-menu-btn:hover {
  color: var(--text-body);
  background: rgba(0, 0, 0, .06);
}

/* Выпадающее меню сессии */
.si-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .12);
  min-width: 140px;
  z-index: 200;
  overflow: hidden;
}

.si-dropdown.open {
  display: block;
}

.si-dropdown button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-body);
  text-align: left;
  transition: background .1s;
}

.si-dropdown button:hover {
  background: var(--bg-surface);
}

.si-dropdown .si-dropdown-danger {
  color: #ef4444;
}

.si-dropdown .si-dropdown-danger:hover {
  background: rgba(239, 68, 68, .06);
}

/* Папки */
.folder-item {
  margin-bottom: 2px;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
  transition: background .12s;
  text-transform: uppercase;
  letter-spacing: .02em;
}

.folder-header:hover {
  background: rgba(0, 0, 0, .03);
}

.folder-icon {
  flex-shrink: 0;
}

.folder-name {
  flex: 1;
}

.folder-chevron {
  transition: transform .2s;
  color: var(--text-subtle);
}

.folder-chevron.open {
  transform: rotate(180deg);
}

.folder-sessions {
  display: none;
}

.folder-sessions.open {
  display: block;
}

/* Вложенные сессии папки — с отступом */
.folder-sessions .session-item {
  padding-left: 28px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-primary);
}

.folder-sessions .session-item.active {
  padding-left: 25px;
  color: var(--text-primary);
  font-weight: 600;
}

/* ── Нижняя панель пользователя ───────────────── */
.sb-bottom {
  flex-shrink: 0;
  padding: 10px 10px 12px;
  position: relative;
}

/* Карточка с пользователем */
.sb-user-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px 8px 12px;
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.sb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #E2E8F0;
}

.sb-avatar-placeholder {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #9CA3AF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.sb-user-info {
  flex: 1;
  overflow: hidden;
}

.sb-username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Баланс — оранжевым */
.sb-balance {
  font-size: 11px;
  font-weight: 600;
  color: var(--brand);
}

/* Кнопка настроек — полная ширина */
/* Кнопка-шестерёнка в карточке пользователя */
.sb-gear-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-subtle);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.sb-gear-btn:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--text-primary);
}

[data-theme="dark"] .sb-gear-btn:hover {
  background: rgba(255, 255, 255, .08);
}

/* Popup-меню пользователя */
.sb-user-menu {
  display: none;
  flex-direction: column;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 10px;
  right: 10px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 6px;
  z-index: 200;
}

.sb-user-menu.open {
  display: flex;
}

.sb-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text-body);
  text-decoration: none;
  cursor: pointer;
  transition: background .1s;
}

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

.sb-menu-item svg {
  flex-shrink: 0;
  color: var(--text-subtle);
}

.sb-menu-item:hover svg {
  color: var(--text-primary);
}

.sb-menu-item-danger {
  color: #ef4444;
}

.sb-menu-item-danger svg {
  color: #ef4444;
}

.sb-menu-item-danger:hover {
  background: rgba(239, 68, 68, .08);
  color: #ef4444;
}

.sb-menu-item-danger:hover svg {
  color: #ef4444;
}

.sb-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 4px;
}

[data-theme="dark"] .sb-user-menu {
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}

/* ── Main chat ─────────────────────────────────── */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  background: var(--bg-page);
}

.messages-wrap::-webkit-scrollbar {
  width: 4px;
}

.messages-wrap::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.messages-inner {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Messages ─────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  margin-bottom: 6px;
}

/* User message */
.msg-user {
  align-items: flex-end;
}

.msg-user .msg-bubble {
  background: var(--bg-user-msg);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
  max-width: 72%;
}

/* AI message */
.msg-ai-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.msg-ai-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #1d1d1f;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-ai .msg-bubble {
  background: var(--bg-ai-msg);
  border-radius: var(--radius-sm) var(--radius-xl) var(--radius-xl) var(--radius-xl);
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  word-break: break-word;
  max-width: 100%;
}

/* Bubble content — общие */
.msg-bubble p {
  margin-bottom: 6px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble strong {
  font-weight: 700;
}

.msg-bubble em {
  font-style: italic;
}

/* Bubble content — только AI (markdown) */
.msg-ai .msg-bubble h1,
.msg-ai .msg-bubble h2,
.msg-ai .msg-bubble h3,
.msg-ai .msg-bubble h4,
.msg-ai .msg-bubble h5,
.msg-ai .msg-bubble h6 {
  font-weight: 700;
  line-height: 1.35;
  margin-top: 14px;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.msg-ai .msg-bubble h1 { font-size: 20px; }
.msg-ai .msg-bubble h2 { font-size: 17px; }
.msg-ai .msg-bubble h3 { font-size: 15px; }
.msg-ai .msg-bubble h4,
.msg-ai .msg-bubble h5,
.msg-ai .msg-bubble h6 { font-size: 14px; }

.msg-ai .msg-bubble ul,
.msg-ai .msg-bubble ol {
  margin: 6px 0 6px 20px;
}

.msg-ai .msg-bubble ul {
  list-style: disc;
}

.msg-ai .msg-bubble ol {
  list-style: decimal;
}

.msg-ai .msg-bubble li {
  margin-bottom: 3px;
  line-height: 1.55;
}

.msg-ai .msg-bubble li > p {
  margin-bottom: 2px;
}

.msg-ai .msg-bubble blockquote {
  border-left: 3px solid var(--brand);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-muted);
  font-style: italic;
}

.msg-ai .msg-bubble hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 10px 0;
}

.msg-ai .msg-bubble a {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-ai .msg-bubble a:hover {
  color: var(--brand-dark);
}

.msg-ai .msg-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 8px 0;
  font-size: 13px;
}

.msg-ai .msg-bubble th,
.msg-ai .msg-bubble td {
  border: 1px solid var(--border-light);
  padding: 6px 10px;
  text-align: left;
}

.msg-ai .msg-bubble th {
  background: var(--bg-surface);
  font-weight: 600;
}

.msg-bubble pre {
  position: relative;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 15px;
  margin: 6px 0;
  line-height: 1.5;
}

.copy-code-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, .18);
  color: #444;
  border: none;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s;
  z-index: 10;
  line-height: 1.4;
}

[data-theme="dark"] .copy-code-btn {
  background: rgba(255, 255, 255, .12);
  color: #ccc;
}

.msg-bubble pre:hover .copy-code-btn {
  opacity: 1;
}

.copy-code-btn.copied {
  color: #7ec8a0;
}

.msg-bubble pre .hljs {
  border-radius: var(--radius);
  font-size: 15px;
}

[data-theme="dark"] .msg-bubble pre .hljs {
  background: #282828;
}

:root:not([data-theme="dark"]) .msg-bubble pre .hljs {
  background: #f0f2f4;
}

.msg-bubble code {
  font-family: monospace;
  font-size: 15px;
  background: rgba(0, 0, 0, .07);
  padding: 1px 4px;
  border-radius: 3px;
}

.msg-bubble pre code {
  background: none;
  padding: 0;
}

/* Message actions */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 3px;
  padding: 2px 0;
}

.msg-ai .msg-actions {
  padding-left: 0;
}

.msg-user .msg-actions {
  justify-content: flex-end;
}

.msg-user.streaming .msg-action-btn {
  display: none;
}

.msg-user.editing .msg-bubble {
  width: 100%;
}

.msg-user.editing .msg-action-btn {
  display: none;
}

.msg-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-subtle);
  transition: background .12s, color .12s;
}

.msg-action-btn:hover {
  background: rgba(0, 0, 0, .06);
  color: var(--text-body);
}

.msg-time {
  font-size: 12px;
  color: var(--text-faint);
  margin-left: 4px;
}

.msg-cost {
  font-size: 12px;
  color: var(--text-faint);
  margin-left: 2px;
}

.msg-cost-aborted {
  opacity: 0.5;
  font-style: italic;
}

.msg-version-nav {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-right: 4px;
}

.msg-ver-counter {
  font-size: 11px;
  color: var(--text-faint);
  min-width: 26px;
  text-align: center;
}

.msg-ver-prev:disabled,
.msg-ver-next:disabled {
  opacity: 0.3;
  cursor: default;
}

.msg-model-name {
  font-size: 12px;
  color: var(--text-subtle);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  font-weight: 500;
  line-height: 1.4;
}

/* Иконка в model-option (выпадающий список) */
.model-option {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-option-icon {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.model-option-icon-default {
  display: flex;
  align-items: center;
  color: var(--text-subtle);
  flex-shrink: 0;
}

/* Summary message */
.msg-summary-wrap {
  align-self: stretch;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-faint);
  padding: 10px 14px;
  margin: 8px 0;
}

.msg-summary-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 5px;
}

.msg-summary-text {
  font-size: 13px;
  color: var(--text-body);
  line-height: 1.6;
}

/* Context reset divider */
.msg-context-reset {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.msg-context-reset-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.msg-context-reset-text {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}

/* Typing indicator */
.typing-indicator {
  display: none;
  align-self: flex-start;
  padding: 8px 14px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-subtle);
  animation: typing-pulse 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: .2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: .4s;
}

@keyframes typing-pulse {

  0%,
  100% {
    opacity: .3;
    transform: scale(.8);
  }

  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.ti-phrase {
  display: none;
  font-size: 13px;
  color: var(--text-subtle);
  font-style: italic;
  animation: phrase-fade-in .35s ease;
}

@keyframes phrase-fade-in {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

.ti-reasoning-badge {
  display: none;
  font-size: 11px;
  color: var(--text-subtle);
  background: var(--bg-sidebar);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1px 8px;
  margin-left: 4px;
}

.msg-tool-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-subtle);
  padding: 4px 2px 6px;
}

.msg-tool-indicator .typing-dots span {
  width: 5px;
  height: 5px;
}

/* ── Input area ───────────────────────────────── */
.chat-input-area {
  flex-shrink: 0;
  background: var(--bg-page);
  padding: 8px 16px 10px;
  padding-bottom: max(10px, calc(10px + env(safe-area-inset-bottom, 0px)));
}

.chat-input-inner {
  max-width: 768px;
  margin: 0 auto;
}

.chat-queue-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  margin-bottom: 4px;
  background: var(--bg-user-msg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-subtle);
  line-height: 1.3;
}

.chat-queue-text {
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.chat-input-wrap {
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: border-color .15s, box-shadow .15s;
}

.chat-input-wrap:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}

#chatInput {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: 'Inter', sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.55;
  min-height: 52px;
  max-height: 130px;
  overflow-y: auto;
  padding: 12px 14px 4px;
  transition: max-height .2s ease;
}

#chatInput.expanded {
  max-height: 260px;
  min-height: 120px;
}

#chatInput::placeholder {
  color: var(--text-subtle);
}

/* Тулбар над полем ввода */
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  gap: 8px;
}

.chat-toolbar-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: border-color .12s, color .12s;
  white-space: nowrap;
}

.model-selector:hover {
  border-color: var(--brand);
  color: var(--brand);
}

#modelLabel {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 110px;
}

.assistant-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: border-color .12s, color .12s;
  white-space: nowrap;
}

.assistant-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* Нижняя панель внутри поля */
.chat-input-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 6px;
}

.chat-input-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-subtle);
  transition: color .12s, background .12s;
}

.chat-expand-btn:hover {
  background: rgba(0, 0, 0, .05);
  color: var(--text-body);
}

.chat-expand-btn.active {
  color: var(--brand);
}

.chat-input-tools {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-subtle);
  transition: color .12s;
}

.chat-attach-btn:hover {
  color: var(--text-body);
}

.chat-tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-subtle);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .12s;
}

.chat-tool-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.chat-tool-btn.active {
  border-color: var(--brand);
  background: var(--brand-faint);
  color: var(--brand);
}

[data-theme="dark"] .chat-tool-btn.active {
  background: rgba(255, 140, 0, .15);
}

.chat-send-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  background: var(--brand);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background .12s;
}

.chat-send-btn:hover {
  background: var(--brand-dark);
}

.chat-send-btn:disabled {
  background: #D1D5DB;
  color: #9CA3AF;
  cursor: not-allowed;
}

.attachment-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px 0;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px 3px 8px;
  font-size: 12px;
  color: var(--text-body);
  max-width: 200px;
}

.attach-chip-icon {
  flex-shrink: 0;
  color: var(--text-subtle);
}

.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-chip-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-faint);
  padding: 2px;
  display: flex;
  align-items: center;
  border-radius: 3px;
  transition: color .12s, background .12s;
}

.attach-chip-remove:hover {
  color: var(--text-body);
  background: rgba(0,0,0,.06);
}

/* Attach dropdown */
.attach-dropdown-wrap {
  position: relative;
}

.attach-dropdown {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 140px;
  z-index: 100;
  padding: 4px;
}

.attach-dropdown-item {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 6px 10px;
  border: none;
  background: none;
  border-radius: 5px;
  color: var(--text-body);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background .1s;
}

.attach-dropdown-item:hover {
  background: var(--brand-faint);
}

.attach-dropdown-item.disabled {
  opacity: .4;
  cursor: not-allowed;
}

.attach-dropdown-item.disabled:hover {
  background: none;
}

/* Image thumbnail in input preview chip */
.attach-chip-thumb {
  width: 22px;
  height: 22px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}

.attach-chip-has-thumb {
  padding: 3px 6px 3px 4px;
}

/* Attachments in user message bubble */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}

.msg-attach-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0,0,0,.08);
  border-radius: 6px;
  padding: 3px 8px 3px 4px;
  font-size: 12px;
  color: inherit;
  max-width: 180px;
}

[data-theme="dark"] .msg-attach-chip {
  background: rgba(255,255,255,.1);
}

.msg-attach-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.msg-attach-icon {
  flex-shrink: 0;
  opacity: .7;
}

.msg-attach-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-stop-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  background: var(--brand);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  transition: background .12s;
}

.chat-stop-btn:hover {
  background: var(--brand-dark);
}

.chat-status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 5px;
  gap: 10px;
  font-size: 11px;
  color: var(--text-faint);
}

.chat-cost-sep {
  opacity: .4;
}

.token-price-bar {
  display: flex;
  align-items: center;
  gap: 5px;
}

.token-price-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.token-price-sep {
  opacity: .4;
}

.token-price-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--text-faint);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  background: transparent;
  color: var(--text-faint);
  padding: 0;
  margin-left: 2px;
  transition: border-color .15s, color .15s;
}

.token-price-help:hover {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}



/* Pricing info modal */
.modal.modal-pricing-info {
  max-width: 420px;
}

.pricing-modal-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.pricing-modal-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: 8px;
  font-size: 13px;
}

.pricing-modal-row-label {
  color: var(--text-secondary);
}

.pricing-modal-row-val {
  font-weight: 600;
  color: var(--text-primary);
}

.pricing-modal-explanation {
  font-size: 12px;
  color: var(--text-subtle);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  margin-bottom: 14px;
}

.pricing-modal-note {
  margin-top: 4px;
  color: var(--text-faint);
}

.pricing-modal-section-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--text-faint);
  margin: 14px 0 6px;
  text-transform: uppercase;
}

.pricing-modal-context-box {
  background: var(--bg-surface);
  border-radius: 8px;
  overflow: hidden;
}

.pricing-modal-context-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
}

.pricing-modal-context-row:last-child {
  border-bottom: none;
}

.pricing-modal-context-row--total {
  font-weight: 600;
  color: var(--text-primary);
}

.token-total-wrap {
  display: flex;
  align-items: center;
}

.token-total-inner {
  opacity: .7;
}

.chat-ctx-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: border-color .12s, color .12s;
  white-space: nowrap;
}

.chat-ctx-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* Редактирование сообщений */
.msg-edit-textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.55;
  padding: 8px 10px;
  resize: none;
  min-height: 36px;
  max-height: 300px;
  overflow-y: auto;
  outline: none;
  display: block;
}

.msg-edit-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.msg-edit-save {
  padding: 5px 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.msg-edit-save:hover {
  background: var(--brand-dark);
}

.msg-edit-cancel {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-body);
  font-size: 12px;
  cursor: pointer;
  transition: border-color .12s;
}

.msg-edit-cancel:hover {
  border-color: var(--brand);
}

/* ── Theme toggle ─────────────────────────────── */
.sp-top-actions {
  display: flex;
  justify-content: flex-end;
  padding: 8px 8px 0;
  flex-shrink: 0;
}

.sp-theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  background: none;
  border: 1px solid var(--border-light);
  cursor: pointer;
  color: var(--text-subtle);
  transition: color .12s, background .12s, border-color .12s;
}

.sp-theme-btn:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--brand-faint);
}

/* ── Settings panel ───────────────────────────── */
.sp {
  width: 270px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow-y: auto;
}

.sp::-webkit-scrollbar {
  width: 3px;
}

.sp::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

.sp-spacer {
  flex: 1;
}

/* Карточка с оранжевым бордером */
.sp-card {
  border: 1px solid var(--brand);
  border-radius: 10px;
  background: var(--bg-white);
  overflow: hidden;
  flex-shrink: 0;
}

/* Режим редактирования промпта — карточка растягивается на весь экран */
.sp.editing {
  overflow: hidden;
}

.sp.editing .sp-spacer {
  flex: 0;
}

.sp.editing .sp-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  cursor: pointer;
  user-select: none;
  color: var(--brand);
  border-bottom: 1px solid var(--brand-light);
}

.sp-header:hover {
  background: var(--brand-faint);
}

.sp-header-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.sp-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--brand);
}

.sp-chevron {
  color: var(--brand);
  transition: transform .2s;
}

.sp.collapsed .sp-chevron {
  transform: rotate(180deg);
}

.sp.collapsed .sp-content {
  display: none;
}

.sp.collapsed .sp-header {
  border-bottom: none;
}

.sp-content {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.sp-section {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 16px;
}

.sp-section:last-child {
  margin-bottom: 0;
}

.sp-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-body);
}

.sp-info-icon {
  color: var(--text-faint);
  cursor: help;
  flex-shrink: 0;
}

.sp-tip {
  display: inline-flex;
  align-items: center;
  cursor: help;
  flex-shrink: 0;
}

#spFloatTooltip {
  position: fixed;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 11px;
  line-height: 1.45;
  padding: 5px 9px;
  border-radius: 5px;
  max-width: 220px;
  pointer-events: none;
  z-index: 9999;
  display: none;
  white-space: normal;
}

.sp-select-btn {
  width: 100%;
  padding: 8px 12px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.sp-select-btn:hover {
  background: var(--brand-dark);
}

.sp-prompt-text {
  font-size: 12px;
  color: var(--text-body);
  line-height: 1.55;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-right: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: 8px 10px;
  max-height: 90px;
  overflow-y: auto;
}

.sp-upload-btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: border-color .12s, color .12s;
}

.sp-upload-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.sp-checkbox-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 0;
}

.sp-checkbox-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-body);
}

.sp-checkbox {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--brand);
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Toggle switch */
.sp-toggle {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 19px;
  flex-shrink: 0;
}

.sp-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.sp-toggle-track {
  position: absolute;
  inset: 0;
  background: #c0c0c0;
  border-radius: 19px;
  transition: background .2s;
  cursor: pointer;
}

[data-theme="dark"] .sp-toggle-track {
  background: #555;
}

.sp-toggle-track::after {
  content: '';
  position: absolute;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform .2s;
}

.sp-toggle input:checked + .sp-toggle-track {
  background: var(--brand);
}

.sp-toggle input:checked + .sp-toggle-track::after {
  transform: translateX(15px);
}

/* Select в панели настроек */
.sp-select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}

.sp-select:focus {
  border-color: var(--brand);
}

[data-theme="dark"] .sp-select {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.sp-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.sp-slider-wrap:last-child {
  margin-bottom: 0;
}

.sp-slider-header {
  display: flex;
  align-items: flex-start;
}

.sp-slider-val {
  font-size: 11px;
  color: var(--brand);
  font-weight: 600;
  text-align: right;
}

.sp-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #F3D5B3;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}

.sp-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(226, 132, 31, .2);
}

.sp-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  border: none;
}

/* Кнопка сброса — оранжевый бордер */
.sp-reset-btn {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--brand);
  border-radius: 10px;
  background: var(--bg-white);
  color: var(--brand);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background .12s;
  flex-shrink: 0;
}

.sp-reset-btn:hover {
  background: var(--brand-faint);
}

/* Prompt editor */
.sp-prompt-editor {
  display: none;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.sp-prompt-editor.open {
  display: flex;
}

.sp-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sp-back-link {
  font-size: 13px;
  color: var(--brand);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.sp-back-link:hover {
  text-decoration: underline;
}

.sp-prompt-textarea {
  width: 100%;
  flex: 1;
  min-height: 200px;
  border: 1px solid var(--border);
  border-right: 3px solid var(--brand);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.6;
  resize: none;
  font-family: 'Inter', sans-serif;
  background: var(--bg-white);
}

.sp-prompt-textarea:focus {
  outline: none;
  border-color: var(--brand);
  border-right-color: var(--brand);
}

/* ── Modals ───────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal {
  background: var(--bg-white);
  border-radius: var(--radius-xl);
  box-shadow: 0 20px 60px -12px rgba(0, 0, 0, .22);
  display: flex;
  flex-direction: column;
  max-height: 92vh;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  color: var(--text-subtle);
  border-radius: var(--radius-sm);
  font-size: 22px;
  line-height: 1;
  transition: color .12s;
}

.modal-close:hover {
  color: var(--text-primary);
}

/* Tabs */
.modal-tabs {
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 4px;
  flex-shrink: 0;
  border-bottom: 1px solid #F3F4F6;
}

.modal-tab {
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 8px;
  transition: background .12s, color .12s;
}

.modal-tab.active {
  background: var(--brand);
  color: #fff;
}

.modal-tab:not(.active):hover {
  color: var(--text-primary);
  background: #F3F4F6;
}

/* Modal search bar */
.modal-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  flex-shrink: 0;
}

.modal-search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
}

.modal-search input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--text-primary);
  background: transparent;
}

.modal-search input::placeholder {
  color: var(--text-subtle);
}

.modal-sort {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-size: 13px;
  color: var(--text-body);
  cursor: pointer;
}

.modal-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 24px 12px;
}

.modal-filter {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  font-size: 13px;
  color: var(--text-body);
  cursor: pointer;
  flex: 0 0 auto;
  max-width: 180px;
}

.modal-add-btn {
  padding: 8px 14px;
  background: var(--brand);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
}

.modal-add-btn:hover {
  background: var(--brand-dark);
}

/* Modal body */
.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 24px;
}

#modalPrompts .modal {
  overflow: hidden;
}

#promptsListView {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

#promptsListBody {
  min-height: 0;
}

.modal-body::-webkit-scrollbar {
  width: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 2px;
}

/* Prompt cards */
.prompts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding-top: 16px;
}

.prompt-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  background: var(--bg-white);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color .15s, box-shadow .15s;
  cursor: default;
}

.prompt-card:hover {
  border-color: var(--brand);
  box-shadow: 0 2px 10px rgba(var(--brand-rgb), .12);
}

/* Шапка карточки: аватар + имя + дата */
.pc-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pc-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #E2E8F0;
  flex-shrink: 0;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-subtle);
}

.pc-meta {
  flex: 1;
  overflow: hidden;
}

.pc-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pc-date {
  font-size: 11px;
  color: var(--text-subtle);
  margin-top: 1px;
}

/* Бейдж модели */
.pc-model-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  background: #F3E8FF;
  color: #7C3AED;
  font-size: 11px;
  font-weight: 500;
  align-self: flex-start;
}

/* Заголовок и описание */
.pc-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.pc-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* Теги */
.pc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pc-tag {
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

.pc-tag-lang {
  background: #FEF9C3;
  color: #854D0E;
}

.pc-tag-cat {
  background: #DBEAFE;
  color: #1E40AF;
}

.pc-tag-role {
  background: #FCE7F3;
  color: #9D174D;
}

/* Подвал: кнопка + метрики */
.pc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 4px;
}

.pc-select-btn {
  padding: 7px 16px;
  background: var(--brand);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .03em;
  cursor: pointer;
  transition: background .12s;
  text-transform: uppercase;
}

.pc-select-btn:hover {
  background: var(--brand-dark);
}

.pc-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pc-stat {
  font-size: 11px;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 3px;
}

.pc-footer-btns {
  display: flex;
  gap: 6px;
}

.pc-open-btn {
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-body);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .12s, color .12s;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.pc-open-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

/* Prompt detail view */
.pd-view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px 24px 24px;
  overflow: hidden;
}

.pd-meta-row {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pd-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.pd-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pd-content-wrap {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 16px;
}

.pd-content {
  margin: 0;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-body);
  white-space: pre-wrap;
  word-break: break-word;
}

.pd-actions {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
}

.pd-select-btn {
  padding: 10px 24px;
  font-size: 13px;
}

.pd-back-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: none;
  color: var(--text-subtle);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
  transition: color .12s;
}

.pd-back-btn:hover {
  color: var(--text-primary);
}

/* Assistants grid */
.assistants-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  padding-top: 16px;
}

.assistant-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-white);
  transition: border-color .15s, box-shadow .15s;
  cursor: pointer;
}

.assistant-card:hover {
  border-color: var(--brand);
  box-shadow: 0 2px 8px rgba(var(--brand-rgb), .15);
}

.ac-image {
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  background: #E2E8F0;
}

.ac-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ac-fav-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, .4);
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ac-body {
  padding: 10px 12px;
}

.ac-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.ac-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 8px;
}

.ac-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ac-likes {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 3px;
}

.ac-select-btn {
  padding: 4px 10px;
  background: var(--brand);
  border: none;
  border-radius: 5px;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.ac-select-btn:hover {
  background: var(--brand-dark);
}

.ac-agent-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .05em;
  background: var(--text-primary);
  color: #fff;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

/* Assistant detail modal */
.modal-detail {
  width: 860px;
}

.modal-detail-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.modal-detail-img {
  width: 320px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  background: #E2E8F0;
}

.modal-detail-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-detail-img::before,
.modal-detail-img::after {
  content: '';
  position: absolute;
  width: 56px;
  height: 56px;
  border: 2px solid var(--brand);
  pointer-events: none;
}

.modal-detail-img::before {
  top: 0;
  left: 0;
  border-right: none;
  border-bottom: none;
}

.modal-detail-img::after {
  bottom: 0;
  right: 0;
  border-left: none;
  border-top: none;
}

.modal-detail-info {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-detail-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  line-height: 1.2;
}

.modal-detail-desc {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.65;
}

.modal-detail-quote {
  background: #F3F3F3;
  border-left: 3px solid var(--brand);
  border-radius: 2px;
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-body);
  line-height: 1.6;
  font-style: italic;
}

.modal-detail-authors {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-detail-author {
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-detail-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #E2E8F0;
}

.modal-detail-meta {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.modal-detail-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-detail-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid #F3F4F6;
  flex-shrink: 0;
}

.modal-fav-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--brand);
  background: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--brand);
  transition: background .12s;
}

.modal-fav-btn:hover {
  background: var(--brand-light);
}

.modal-choose-btn {
  padding: 11px 28px;
  background: var(--brand);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.modal-choose-btn:hover {
  background: var(--brand-dark);
}

/* Create folder modal */
.modal-folder {
  width: 400px;
}

.modal-folder-body {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.mf-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-body);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 4px;
}

.mf-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-surface);
  outline: none;
  transition: border-color .12s;
}

.mf-input:focus {
  border-color: var(--brand);
  background: var(--bg-white);
}

.mf-color-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  gap: 8px;
}

.mf-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--brand);
}

.mf-colors {
  display: flex;
  gap: 8px;
}

.mf-color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color .12s;
}

.mf-color-btn.selected {
  border-color: var(--text-primary);
}

.mf-create-btn {
  padding: 11px;
  background: var(--brand);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  cursor: pointer;
  text-transform: uppercase;
}

.mf-create-btn:hover {
  background: var(--brand-dark);
}

/* Модал подтверждения удаления */
.modal-confirm {
  width: 380px;
}

.modal-confirm-body {
  padding: 0 24px 24px;
}

.modal-confirm-text {
  font-size: 14px;
  color: var(--text-body);
  line-height: 1.5;
  margin: 0 0 20px;
}

.modal-confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.mc-cancel-btn {
  padding: 9px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-white);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: background .12s;
}

.mc-cancel-btn:hover {
  background: var(--bg-surface);
}

.mc-delete-btn {
  padding: 9px 20px;
  border-radius: var(--radius);
  border: none;
  background: #ef4444;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.mc-delete-btn:hover {
  background: #dc2626;
}

.mc-ok-btn {
  padding: 9px 20px;
  border-radius: var(--radius);
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.mc-ok-btn:hover {
  background: var(--brand-dark);
}

/* ── Папка: меню действий (три точки) ─────────── */
.folder-actions {
  display: flex;
  visibility: hidden;
  position: relative;
  margin-left: auto;
  margin-right: 2px;
  flex-shrink: 0;
}

.folder-header:hover .folder-actions {
  visibility: visible;
}

.folder-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-subtle);
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s, color .12s;
}

.folder-menu-btn:hover {
  background: rgba(0, 0, 0, .08);
  color: var(--text-primary);
}

[data-theme="dark"] .folder-menu-btn:hover {
  background: rgba(255, 255, 255, .1);
}

/* ── Модал удаления папки: опции ──────────────── */
.fd-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.fd-option {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13.5px;
  color: var(--text-body);
  cursor: pointer;
  line-height: 1.4;
}

.fd-option input[type="radio"] {
  accent-color: var(--brand);
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
}

.fd-target-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13px;
  margin-bottom: 16px;
  outline: none;
  cursor: pointer;
  transition: border-color .15s;
}

.fd-target-select:focus {
  border-color: var(--brand);
}

[data-theme="dark"] .fd-target-select {
  background: var(--bg-surface);
  color: var(--text-primary);
}

/* Модал редактора промпта */
.modal-prompt-textarea {
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  border-right: 3px solid var(--brand);
  background: var(--bg-surface);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.6;
  padding: 12px 14px;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}

.modal-prompt-textarea:focus {
  border-color: var(--brand);
}

.modal-cancel-btn {
  padding: 9px 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-white);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: background .12s;
}

.modal-cancel-btn:hover {
  background: var(--bg-surface);
}

.modal-save-btn {
  padding: 9px 20px;
  border-radius: var(--radius);
  border: none;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
}

.modal-save-btn:hover {
  background: var(--brand-dark);
}

/* Модал перемещения в папку */
.modal-move {
  width: 340px;
}

.modal-move-body {
  padding: 0 8px 12px;
}

.mf-folder-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-body);
  text-align: left;
  border-radius: var(--radius);
  transition: background .1s;
}

.mf-folder-option:hover {
  background: var(--bg-surface);
}

/* Model dropdown */
.model-dropdown {
  display: none;
  position: fixed;
  z-index: 500;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .12);
  padding: 6px;
  min-width: 180px;
}

.model-dropdown-label {
  font-size: 11px;
  color: var(--text-subtle);
  padding: 4px 8px 6px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
}

.model-option {
  padding: 6px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background .1s;
}

.model-option:hover {
  background: var(--bg-page);
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--text-primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 9999;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

.toast.error {
  background: #ef4444;
}

[data-theme="dark"] .toast {
  background: #e5e7eb;
  color: #111827;
}

[data-theme="dark"] .toast.error {
  background: #ef4444;
  color: #fff;
}

/* ── Гостевой экран (незарегистрированный пользователь) ───── */
.guest-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 24px;
  gap: 24px;
}

.guest-ai-bubble {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 420px;
  width: 100%;
}

.guest-ai-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1d1d1f;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}

[data-theme="dark"] .guest-ai-icon {
  background: #e5e7eb;
  color: #111;
}

.guest-ai-text {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 4px 14px 14px 14px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text-body);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.guest-auth-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
}

.guest-login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guest-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.guest-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-subtle);
}

.guest-field input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
}

.guest-field input:focus {
  border-color: var(--brand);
}

.guest-error {
  font-size: 12px;
  color: #ef4444;
}

.guest-submit-btn {
  margin-top: 4px;
  padding: 10px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  font-family: inherit;
}

.guest-submit-btn:hover {
  opacity: .88;
}

.guest-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 12px;
  font-size: 12px;
  color: var(--text-subtle);
}

.guest-divider::before,
.guest-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.guest-social-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.guest-social-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-body);
  font-size: 13px;
  text-decoration: none;
  transition: background .12s;
}

.guest-social-btn:hover {
  background: var(--bg-surface);
}

.guest-signup-link {
  margin-top: 16px;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-subtle);
}

.guest-signup-link a {
  color: var(--brand);
  text-decoration: none;
}

.guest-signup-link a:hover {
  text-decoration: underline;
}

/* Кнопка "Войти в аккаунт" в сайдбаре для гостя */
.sb-guest-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-white);
  color: var(--text-body);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .12s;
}

.sb-guest-login-btn:hover {
  background: var(--bg-surface);
}

/* ── Мобильная адаптивность ───────────────────────────── */
.chat-mobile-topbar {
  display: none;
}

.chat-mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 40;
}

.chat-mobile-overlay.active {
  display: block;
}

@media (max-width: 767px) {

  .chat-mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-page);
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
    position: relative;
    z-index: 10;
  }

  .chat-mobile-topbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius);
    transition: background .12s;
    flex-shrink: 0;
  }

  .chat-mobile-topbar-btn:hover {
    background: var(--bg-surface);
  }

  .chat-mobile-topbar-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    padding: 0 8px;
  }

  .chat-mobile-topbar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .chat-mobile-model-label {
    font-size: 11px;
    font-weight: 400;
    color: var(--brand);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .sb {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
  }

  .sb.mobile-open {
    transform: translateX(0);
  }

  .sp {
    position: fixed;
    right: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    transform: translateX(100%);
    transition: transform .22s ease;
    background: var(--bg-page);
    border-left: 1px solid var(--border-light);
    box-shadow: -4px 0 16px rgba(0, 0, 0, .12);
  }

  .sp.mobile-open {
    transform: translateX(0);
  }

  .prompts-grid {
    grid-template-columns: 1fr;
  }

  .chat-input-area {
    padding-bottom: max(20px, calc(20px + env(safe-area-inset-bottom, 0px)));
  }
}

/* ── Колонка модели (между сайдбаром и чатом) ──────── */
.chat-meta-col {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

@media (max-width: 1300px) {
  .chat-meta-col {
    display: none;
  }
}

/* ── Блок текущей модели внутри колонки ─────────────── */
.model-bar {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-bar-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  background: var(--bg-white);
  border: 1px solid var(--brand);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  transition: background .12s;
  width: 100%;
}

.model-bar-btn:hover {
  background: var(--brand-faint);
}

.model-bar-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-subtle);
}

.model-bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: left;
}

/* Карточка описания (block, не absolute) */
.model-bar-desc {
  display: none;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-page);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px;
}

.model-bar-desc.open {
  display: flex;
}

.model-bar-desc-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.model-bar-desc-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.model-bar-desc-icon-default {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-white);
  color: var(--text-subtle);
  flex-shrink: 0;
}

.model-bar-desc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.model-bar-desc-text {
  font-size: 12px;
  color: var(--text-subtle);
  line-height: 1.5;
}

/* ── Кнопки действий в панели настроек ─────────────── */
.sp-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sp-act-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-white);
  border: 1px solid var(--brand);
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-body);
  cursor: pointer;
  transition: background .12s, color .12s;
  text-align: left;
}

.sp-act-btn:hover {
  background: var(--brand-faint);
  color: var(--brand);
}

.sp-act-btn svg {
  flex-shrink: 0;
  color: var(--brand);
}

.sp-act-btn:hover svg {
  color: var(--brand);
}

/* ── Модал выбора модели ─────────────────────────────── */
.ms-modal {
  width: 820px;
  max-width: calc(100vw - 32px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.ms-body {
  padding: 0 24px 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ms-tabs {
  display: flex;
  gap: 6px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.ms-tab {
  padding: 6px 18px;
  border: 1px solid var(--border-light);
  border-radius: 20px;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-subtle);
  cursor: pointer;
  transition: border-color .12s, color .12s, background .12s;
}

.ms-tab.active,
.ms-tab:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-faint);
}

.ms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  overflow-y: auto;
  padding-right: 4px;
}

.ms-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  cursor: pointer;
  transition: border-color .12s, background .12s;
}

.ms-card:hover {
  border-color: var(--brand);
  background: var(--brand-faint);
}

.ms-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  object-fit: cover;
  flex-shrink: 0;
}

.ms-card-icon-default {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  background: var(--bg-page);
  color: var(--text-subtle);
  flex-shrink: 0;
}

.ms-card-icon-default svg {
  width: 28px;
  height: 28px;
}

.ms-card-body {
  flex: 1;
  min-width: 0;
  padding-top: 2px;
}

.ms-card-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ms-card-desc {
  font-size: 12px;
  color: var(--text-subtle);
  margin-top: 5px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ms-note {
  font-size: 12px;
  color: var(--text-subtle);
  margin-bottom: 14px;
}

.ms-card-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.ms-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  line-height: 1.6;
}

.ms-badge-vision { background: #dbeafe; color: #1d4ed8; }
.ms-badge-reasoning { background: #ede9fe; color: #6d28d9; }
.ms-badge-search { background: #dcfce7; color: #15803d; }

.ms-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-subtle);
  font-size: 13px;
  padding: 32px 0;
}
/* ── Generate Prompt Modal ───────────────────────────────────────────────── */
.gp-modal {
  width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.gp-body {
  padding: 0 24px 24px;
  overflow-y: auto;
}

.gp-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.gp-field { display: flex; flex-direction: column; gap: 4px; }

.gp-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gp-select, .gp-textarea {
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--bg-white);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.gp-select:focus, .gp-textarea:focus { border-color: var(--brand); }
.gp-textarea { resize: vertical; min-height: 80px; font-family: inherit; }

.gp-counter {
  font-size: 11px;
  color: var(--text-subtle);
  text-align: right;
  margin-top: 2px;
}

.gp-btn-primary {
  font-size: 13px; font-weight: 600;
  padding: 8px 16px; border-radius: 6px;
  background: var(--brand); color: #fff; border: none;
  cursor: pointer; transition: background 0.15s;
}
.gp-btn-primary:hover:not(:disabled) { background: #ff4d00; }
.gp-btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.gp-btn-secondary {
  font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 6px;
  background: var(--bg-white); color: var(--text-primary);
  border: 1px solid var(--border); cursor: pointer; transition: border-color 0.15s;
}
.gp-btn-secondary:hover { border-color: var(--brand); color: var(--brand); }

.gp-btn-use {
  font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: 6px;
  background: var(--bg-surface); color: var(--text-primary);
  border: 1px solid var(--border); cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.gp-btn-use:hover { background: var(--brand-light); border-color: var(--brand); color: var(--brand); }

/* ── Кнопки под сгенерированным промптом в чате ── */
.gp-prompt-actions {
  display: flex;
  gap: 8px;
  padding: 6px 0 2px;
  flex-wrap: wrap;
}
.gp-prompt-actions .gp-btn-primary,
.gp-prompt-actions .gp-btn-secondary {
  font-size: 12px;
  padding: 5px 12px;
}

@media (max-width: 600px) {
  .gp-modal { width: 98vw; }
  .gp-row { grid-template-columns: 1fr; }
}

/* ── KaTeX — формулы ─────────────────────────────────────── */
.msg-bubble .katex-display {
  margin: 0.6em 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.msg-bubble .katex {
  font-size: 1.05em;
}

.katex-error {
  color: #ef4444;
  font-family: monospace;
  font-size: 0.9em;
}

[data-theme="dark"] .msg-bubble .katex {
  color: var(--text-primary);
}
