/* ===== Alfred Web Demo — тёмная и светлая темы ===== */
:root {
  --bg: #07070f;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.09);
  --text: #e8eaf2;
  --muted: #9aa0b4;
  --blue: #3b82f6;
  --violet: #8b5cf6;
  --grad: linear-gradient(135deg, var(--blue), var(--violet));
  --pill: #18181d;   /* пилюля ввода */
  --menu: #16161f;   /* меню, поповеры, модалки */
  --chat-row: #111119;         /* строки чатов в списке */
  --chat-row-hover: #1b1b28;   /* плотные: прячут красную подложку свайпа */
}

/* светлая тема «прохладный серый»: те же переменные, светлые значения.
   Класс light вешается на <html> (theme.js / инлайн-скрипт в head) */
:root.light {
  --bg: #f7f8fa;
  --panel: #eef0f4;
  --panel-2: #e4e7ec;
  --border: #dde1e8;
  --text: #111827;
  --muted: #6b7280;
  --pill: #ffffff;
  --menu: #ffffff;
  --chat-row: #ffffff;
  --chat-row-hover: #e4e7ec;
}


* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Inter", "Manrope", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text); height: 100vh; height: 100dvh; overflow: hidden;
}

.app { display: flex; height: 100vh; height: 100dvh; position: relative; }

/* ===== Сайдбар ===== */
.sidebar {
  width: 300px; min-width: 300px; display: flex; flex-direction: column; gap: 14px;
  padding: 18px 14px; background: var(--panel); border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: margin-left 0.28s ease;  /* мягкое выдвижение (ПК) */
}
/* свёрнутая уезжает влево, чат плавно занимает место (instant-версия — display:none — не анимируется) */
.sidebar.collapsed { margin-left: -300px; pointer-events: none; }
[dir="rtl"] .sidebar.collapsed { margin-left: 0; margin-right: -300px; }

/* ===== Линейные иконки (inline SVG) ===== */
.ic { width: 18px; height: 18px; flex: none; }
.ic-s { width: 15px; height: 15px; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 36px; height: 36px; }
.brand-name { font-size: 20px; font-weight: 700; }
.brand .icon-btn { margin-left: auto; }

.btn-primary {
  background: var(--grad); color: #fff; border: none; border-radius: 12px;
  padding: 11px 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover { filter: brightness(1.1); }

.icon-btn {
  background: transparent; border: none; color: var(--muted); font-size: 16px;
  cursor: pointer; padding: 6px; border-radius: 8px;
  /* иконка строго по центру кнопки: без этого svg на базовой линии
     висит на 2px выше центра — и выглядит смещённой в пузыре нажатия */
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }

/* запись голоса (Gemini/ChatGPT-стиль): в поле — эквалайзер, микрофон → стоп */
#btn-mic .ic-stopmic { display: none; }
#btn-mic.recording .ic-stopmic { display: block; }
#btn-mic.recording .ic-mic { display: none; }
#btn-mic.recording { color: var(--text); }
.wave { display: none; }
.composer-box.recording .wave {
  display: flex; flex: 1; align-items: center;
  justify-content: space-between;   /* полоски на всю ширину поля */
  height: 28px; padding: 0 8px;
}
.composer-box.recording #chat-input { display: none; }
.wave span {
  flex: none; width: 3px; height: 100%; border-radius: 2px;
  background: var(--text);   /* белый (в светлой теме — тёмный сам собой) */
  transform: scaleY(0.12);
}
/* анализ звука недоступен (Safari/мобильный http запрещают getUserMedia) —
   мягкая перекатывающаяся волна: живо, но спокойнее настоящего бара */
.wave.fallback span { animation: wave-roll 1.6s ease-in-out infinite; }
@keyframes wave-roll {
  0%, 100% { transform: scaleY(0.2); }
  50% { transform: scaleY(0.55); }
}
/* отправка недоступна во время записи голоса */
.send-btn:disabled { opacity: 0.35; cursor: default; filter: grayscale(0.4); }

.search-box {
  display: flex; align-items: center; gap: 8px; padding: 9px 9px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--muted); font-size: 13px;
}
.search-box input { flex: 1; background: none; border: none; outline: none; color: var(--text); }
.search-box input:disabled { cursor: not-allowed; }
.kbd { font-size: 11px; border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; }

.chats-header { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 4px; padding-left: 10px; }
.chats-list { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
/* «Показать все (+N)» под списком — когда чатов больше 14; компактная,
   чтобы не отнимать высоту у списка */
.chats-more {
  flex: none; display: block; width: 100%; padding: 3px 8px; margin-top: 1px;
  background: none; border: none; border-radius: 8px;
  color: var(--muted); font: inherit; font-size: 12px; text-align: center; cursor: pointer;
}
.chats-more:hover { background: var(--panel-2); color: var(--text); }
.chats-more[hidden] { display: none; }
/* разделитель закреплённых чатов от обычных */
.chats-divider { height: 1px; background: var(--border); margin: 6px 10px; flex: none; }
.chat-item {
  display: flex; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 10px;
  font-size: 13px; color: var(--muted); cursor: pointer; border: none; background: none;
  text-align: left; width: 100%;
}
.chat-item:hover, .chat-item.active { background: var(--panel-2); color: var(--text); }
/* свёрнутый список (14 строк): строки растягиваются ровно на высоту панели —
   ни прокрутки, ни пустого хвоста; размер подстраивается под экран */
.chats-list.capped .chat-swipe { flex: 1 1 0; min-height: 0; max-height: 64px; }
.chats-list.capped .chat-swipe .chat-item { height: 100%; }
.chats-list.capped .chats-divider { flex: none; }
/* «Показать все»: остальные чаты открываются С ТЕМ ЖЕ размером строк
   (--row-h запоминает высоту в момент клика), список мотается */
.chats-list.expanded .chat-swipe { flex: none; height: var(--row-h, 34px); }
.chats-list.expanded .chat-swipe .chat-item { height: 100%; }
.chat-item .ci-ic { display: inline-flex; }  /* вровню с центром названия */
.chat-item .ci-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* дата прижата к правому краю; фиксированная ширина — заголовок не прыгает,
   когда при наведении её место занимают значки */
.chat-item .ci-date {
  font-size: 11px; color: var(--muted); min-width: 46px; text-align: right;
}
.chat-item .ic { color: var(--muted); }

/* значки всплывают ПОВЕРХ места даты при наведении (absolute — не толкают её) */
.chat-item .ci-pin, .chat-item .ci-del {
  position: absolute; top: 50%; transform: translateY(-50%);
  display: flex; color: var(--muted); opacity: 0; padding: 2px; border-radius: 6px;
  transition: right 0.22s ease, opacity 0.18s ease;  /* булавка плавно уезжает, корзина проявляется */
}
/* значок при наведении заливается НАСЫЩЕННО — своим же цветом (не пузырь позади) */
.chat-item .ci-pin svg, .chat-item .ci-del svg { fill: transparent; transition: fill 0.15s ease; }
.chat-item .ci-del { right: 8px; }    /* корзина — самый край */
.chat-item .ci-pin { right: 36px; }   /* булавка — левее корзины */
/* закрепление: булавка у закреплённых живёт у САМОГО КРАЯ (на месте даты) */
.chat-item.pinned .ci-pin { right: 8px; opacity: 0.9; color: #c4b5fd; }

/* всё курсорное — ТОЛЬКО на устройствах с курсором: тач при зажатии
   эмулирует :hover (iOS/Android), и булавка «дёргалась» без мыши */
@media (hover: hover) {
  .chat-item:hover .ci-del { opacity: 1; transition-delay: 0.05s; }  /* булавка стартует первой — потом край занимает корзина */
  /* при наведении булавка проявляется, а закреплённая — уступает край
     корзине и плавно уезжает влево, на своё «рабочее» место */
  .chat-item:hover .ci-pin { opacity: 1; }
  .chat-item.pinned:hover .ci-pin { right: 36px; }
  .chat-item:hover .ci-date { visibility: hidden; }   /* место для булавки и корзины */
  /* наведение на сам значок: заливается своим цветом (пузыря позади нет) */
  .chat-item .ci-del:hover svg, .chat-item .ci-pin:hover svg { fill: currentColor; }
}
.chat-item.pinned .ci-date { visibility: hidden; }  /* на её месте живёт булавка */
@media (hover: none) {
  .chat-item .ci-del { display: none; }  /* на таче чат удаляют свайпом влево */
  .chat-item:not(.pinned) .ci-pin { display: none; }  /* булавка — только у закреплённых */
  /* на телефоне анимации булавки нет: она просто стоит у края (right:8px выше);
     слайд и проявление — только для курсора, на ноутбуке */
  .chat-item .ci-pin, .chat-item .ci-del { transition: none; }
}

/* свайп-удаление: красная плашка с корзиной прячется за строкой чата.
   Пока свайпа нет — она полностью невидима (visibility), иначе по краям
   скруглённых углов просвечивают тонкие красные полоски. */
.chat-swipe { position: relative; border-radius: 10px; }
.chat-swipe .swipe-back {
  position: absolute; inset: 0; display: flex; align-items: stretch;
  justify-content: flex-end; border-radius: 10px; overflow: hidden;
  visibility: hidden;  /* гаснут мгновенно: строка возвращается по чистому фону */
}
.chat-swipe .swipe-back .swipe-pin, .chat-swipe .swipe-back .swipe-del {
  width: 64px; border: none; cursor: pointer; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.chat-swipe .swipe-back .swipe-pin { background: #3b82f6; }
.chat-swipe .swipe-back .swipe-del { background: #dc2626; }
.chat-swipe .swipe-back .ic { width: 20px; height: 20px; }
.chat-swipe.revealed .swipe-back { visibility: visible; }
.chat-swipe .swipe-back .ic { width: 20px; height: 20px; }
.chat-swipe .chat-item {
  position: relative; z-index: 1; width: 100%;
  background: var(--chat-row);  /* плотный: скрывает красную, пока не свайпнули */
  transition: transform 0.18s ease;
  touch-action: pan-y;  /* вертикаль — скролл списка, горизонталь — наш свайп */
}
.chat-swipe .chat-item:hover, .chat-swipe .chat-item.active { background: var(--chat-row-hover); }
/* строка под курсором поднимается над соседями (у всех z-index:1): иначе
   подсказка булавки/корзины проваливается под следующие строки */
.chat-swipe .chat-item:hover { z-index: 2; }
/* строка-подтверждение «удалить этот чат? ✓ ✕»: обычное содержимое прячем
   классом (не удалением) — так подтверждение можно снять мгновенно */
.chat-item.confirming { background: var(--panel-2); color: var(--text); }
.chat-item.confirming > :not(.ci-confirm):not(.ci-yes):not(.ci-no) { display: none; }
.chat-item .ci-confirm {
  flex: 1; font-size: 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-item .ci-yes, .chat-item .ci-no { display: flex; padding: 2px; border-radius: 6px; }
.chat-item .ci-yes { color: #f87171; }
.chat-item .ci-no { color: var(--muted); }

/* результаты поиска: заголовок чата + строка-выдержка с подсветкой */
.chat-item.hit { align-items: flex-start; }
.chat-item.hit .ci-ic { margin-top: 2px; }
.chat-item .ci-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-item .ci-snip {
  font-size: 12px; color: var(--muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.chat-item .ci-snip mark {
  background: none; color: var(--text); font-weight: 600;
  text-decoration: underline; text-decoration-color: var(--blue);
  text-underline-offset: 2px;
}
.search-empty { font-size: 12px; color: var(--muted); padding: 10px 12px; }

/* подсветка сообщения, к которому прыгнули из поиска */
@keyframes msg-flash {
  0% { background: rgba(59, 130, 246, 0.22); }
  100% { background: transparent; }
}
.msg.flash { animation: msg-flash 1.8s ease; border-radius: 12px; }

.search-icon { display: flex; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 10px;
  font-size: 13px; color: var(--muted); text-decoration: none;
  background: none; border: none; width: 100%; font: inherit; text-align: left; cursor: default;
}
.side-item:hover { background: var(--panel-2); }

/* аватар с ником — низ сайдбара (бывшее место переключателя темы) */
.side-user {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; border-radius: 12px; background: none; border: none;
  font: inherit; color: var(--text); text-align: left; cursor: pointer;
}
.side-user:hover { background: var(--panel-2); }
.side-user .avatar { width: 28px; height: 28px; font-size: 13px; flex: none; }
.su-name {
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13.5px; color: var(--text);
}

/* ===== Основная область ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

/* фиксированная высота: кнопка «открыть панель» то появляется, то прячется —
   без min-height верхняя панель меняла высоту и весь чат съезжал вверх/вниз.
   Полоса снизу — граница, панель читается как отдельная секция */
.topbar {
  display: flex; justify-content: flex-end; align-items: center; gap: 12px;
  padding: 14px 20px; min-height: 62px; box-sizing: border-box;
  border-bottom: 1px solid var(--border);
}
#sidebar-open:not([hidden]) { animation: fade-in 0.25s ease; }
@keyframes fade-in { from { opacity: 0; } }
/* слева: кнопка панели + имя «Alfred» (в открытом чате) */
.topbar-left { margin-right: auto; display: flex; align-items: center; gap: 10px; }
.topbar-title { font-size: 18px; font-weight: 700; }
/* иконки верхней панели чуть крупнее базовых — вровень с заголовком
   (:not(.ic-s) — мелкие стрелки поиска в той же панели не трогаем) */
.topbar .icon-btn { padding: 7px; }
.topbar .icon-btn .ic:not(.ic-s) { width: 20px; height: 20px; }

/* ===== Верхняя панель: действия открытого чата ===== */
.topbar-actions { display: flex; align-items: center; gap: 2px; }
/* display:flex перебивает атрибут hidden — возвращаем ему силу */
.topbar-actions[hidden], .chat-search[hidden], .chat-menu[hidden] { display: none; }
/* поиск открыт: строка занимает панель целиком, остальные иконки пропадают */
.topbar.search-on > *:not(.chat-search) { display: none; }
.chat-menu-wrap { position: relative; }
/* меню «⋮»: в стиле поповера настроек, раскрывается из-под кнопки */
.chat-menu {
  position: absolute; top: calc(100% + 10px); inset-inline-end: 0; z-index: 70;
  min-width: 218px; padding: 5px; display: flex; flex-direction: column;
  background: var(--menu); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.5);
}
.chat-menu:not([hidden]) { animation: spop-in 0.16s cubic-bezier(.16, .84, .3, 1); }
.chat-menu.closing { animation: spop-out 0.14s ease-in forwards; pointer-events: none; }
.cm-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: none; border-radius: 9px; background: none;
  color: var(--text); font: inherit; font-size: 13.5px; cursor: pointer; text-align: start;
}
.cm-item:hover { background: var(--panel-2); }
.cm-item .ic { color: var(--muted); }
.cm-item.cm-danger, .cm-item.cm-danger .ic { color: #f87171; }
.cm-item.cm-danger.confirming { background: rgba(248, 113, 113, 0.13); }

/* поиск по открытому чату: занимает верхнюю панель, тянется от правого края */
.chat-search {
  display: flex; align-items: center; gap: 8px;
  flex: none; width: 100%; max-width: 560px; margin-inline-start: auto;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 8px 7px 14px; color: var(--muted); overflow: hidden;
}
/* вытягивается справа налево и так же втягивается обратно — не спеша */
@keyframes cs-in { from { max-width: 0; opacity: 0; } }
@keyframes cs-out { to { max-width: 0; opacity: 0; } }
.chat-search:not([hidden]) { animation: cs-in 0.4s cubic-bezier(.22, .68, .26, 1); }
.chat-search.closing { animation: cs-out 0.22s ease-in forwards; pointer-events: none; }
.chat-search input {
  flex: 1; min-width: 0; background: none; border: none; outline: none;
  color: var(--text); font: inherit; font-size: 14px;
}
.chat-search .icon-btn { padding: 5px; }
.cs-count { font-size: 12px; color: var(--muted); min-width: 42px; text-align: center; }
/* стрелки «вверх/вниз» — одна функция, стоят рядом; крестик чуть в стороне */
.cs-nav { display: flex; gap: 2px; }
.chat-search #cs-close { margin-inline-start: 4px; }
/* совпадения в тексте чата */
.cs-mark { background: rgba(251, 191, 36, 0.28); color: inherit; border-radius: 3px; }
.cs-mark.cur { background: #fbbf24; color: #17171f; }
/* эмодзи в ответах ИИ → тонкие иконки в стиле интерфейса (только веб);
   цвет наследуется у текста, размер — кегль строки */
.eicon { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.16em; }
.eicon svg { width: 100%; height: 100%; display: block; }
/* флаги стран: шире строки, пропорция 3:2, свои цвета (заливка, не контур) */
.eicon.eflag { width: 1.5em; height: 1em; vertical-align: -0.15em; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--grad);
  display: flex; align-items: center; justify-content: center; font-size: 14px; color: #fff;
}

.chat-area {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  /* текст тает ПОД панелью ввода (она лежит поверх чата): маска гасит
     текст в нижней зоне — к середине пилюли его уже не видно. Маска, а не
     градиент-заливка: фон и его свечение не трогаются — линии не появляется */
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 140px), transparent calc(100% - 60px));
  mask-image: linear-gradient(to bottom, #000 calc(100% - 140px), transparent calc(100% - 60px));
}

.welcome { margin: auto; text-align: center; max-width: 760px; padding: 20px 20px 150px; }
.hero-logo { width: 128px; height: 128px; }
.welcome h1 { font-size: 40px; margin: 14px 0 10px; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; }
.welcome p { color: var(--muted); line-height: 1.5; margin-bottom: 28px; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; text-align: left; color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; gap: 10px; font-size: 13px;
}
.card:hover { background: var(--panel-2); border-color: rgba(139, 92, 246, 0.4); }
.card-icon { color: var(--blue); }
.card-icon .ic { width: 20px; height: 20px; }
.card-arrow { align-self: flex-end; background: var(--panel-2); border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; }

/* ===== Сообщения ===== */
/* снизу запас больше: последнее сообщение и кнопки-подсказки отдыхают
   НАД панелью ввода (она поверх чата) и зоной затухания */
.messages { max-width: 800px; width: 100%; margin: 0 auto; padding: 20px 20px 170px; display: flex; flex-direction: column; gap: 14px; }
.messages[hidden] { display: none; }
.msg { max-width: 82%; padding: 12px 16px; border-radius: 16px; font-size: 16px; line-height: 1.6; word-wrap: break-word; white-space: pre-wrap; }
/* сообщение юзера: контейнер-колонка; пузырь — внутри, фото — над пузырём */
.msg.user {
  align-self: flex-end; padding: 0; background: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
.msg.user .msg-bubble {
  /* тот же градиент, но на тон темнее (кнопки/аватары остаются ярче) */
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff;
  padding: 12px 16px; border-radius: 16px; border-bottom-right-radius: 4px;
  font-size: 16px; line-height: 1.6; word-wrap: break-word; white-space: pre-wrap;
  max-width: 100%;  /* гигантское неразрывное слово не должно распирать пузырь
                       мимо родителя — иначе текст срезается краем экрана (22.11.2026) */
}
/* фото над пузырём — НЕ внутри него */
.msg.user .msg-photos { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.msg.user .msg-photos img {
  display: block; max-width: min(260px, 100%); max-height: 320px;
  border-radius: 14px; object-fit: cover;
}
/* Ответ ИИ — как у ChatGPT/Gemini: просто текст на фоне, без пузыря */
.msg.bot {
  align-self: stretch; max-width: none;
  background: none; border: none;
  padding: 4px 0;
  margin-left: -20px;  /* ответ левее — вровень с краем пилюли ввода */
}
/* «Думает»: пульсирующая градиентная точка, пока ответ пустой */
/* микро-радость отправки (25.11): свой пузырь чуть поднимается и проявляется.
   Класс вешает JS только на живое отправленное — история чата не анимируется */
.msg-in { animation: msg-in 0.45s cubic-bezier(0.16, 0.84, 0.3, 1); }
@keyframes msg-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
}
.msg.bot.typing::before {
  content: "";
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--grad);
  animation: think 1.15s ease-in-out infinite;
}
@keyframes think {
  0%   { transform: scale(0.75); opacity: 0.5;  box-shadow: 0 0 0 0 rgba(139, 92, 246, 0.35); }
  50%  { transform: scale(1.15); opacity: 1;    box-shadow: 0 0 14px 3px rgba(139, 92, 246, 0.22); }
  100% { transform: scale(0.75); opacity: 0.5;  box-shadow: 0 0 0 0 rgba(139, 92, 246, 0); }
}

/* Стримится: мягкий курсор на конце растущего текста. Живёт СПАНОМ в конце
   последнего блока ответа (app.js placeCaret) — ответ теперь HTML, и ::after
   родителя повисал бы под всем сообщением */
.caret-b::after {
  content: "▍";
  margin-left: 1px;
  color: var(--violet);
  animation: caret-blink 0.9s infinite;
}
@keyframes caret-blink { 50% { opacity: 0.15; } }
/* стрим «материализации» (25.11): свежие символы ответа проявляются
   с прозрачности. Спан живёт одну дельту (следующая перерисовка его сносит),
   так что анимация не копится и старый текст не мигает */
.st-fade { animation: st-fade-in 0.9s ease-out; }
@keyframes st-fade-in { from { opacity: 0; } }

/* ===== Маркдаун-ответы (сервер рендерит в .md) ===== */
/* .md выключает pre-wrap родителя (он нужен легаси-сообщениям и ошибкам) */
.msg .md { white-space: normal; }
.md p { margin: 0 0 0.65em; }
.md > :last-child, .md > :last-child > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 1.05em 0 0.45em; line-height: 1.3; font-weight: 700;
}
.md > h1:first-child, .md > h2:first-child, .md > h3:first-child,
.md > h4:first-child, .md > h5:first-child, .md > h6:first-child { margin-top: 0.25em; }
.md h1 { font-size: 1.5em; }
.md h2 { font-size: 1.35em; }
.md h3 { font-size: 1.2em; }
.md h4 { font-size: 1.05em; }
.md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0.2em 0 0.65em; padding-left: 1.35em; }
.md li { margin: 0.22em 0; }
.md li::marker { color: var(--muted); }
.md code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.86em; background: var(--panel-2);
  border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px;
}
.md pre {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin: 0.2em 0 0.7em; overflow-x: auto;
}
.md pre code { background: none; border: none; padding: 0; }
.md blockquote {
  border-left: 3px solid var(--blue); padding: 2px 0 2px 10px;
  margin: 0.2em 0 0.7em; color: var(--muted);
}
.md a { color: var(--blue); text-decoration: none; border-bottom: 1px solid rgba(59, 130, 246, 0.35); }
.md a:hover { border-bottom-color: var(--blue); }
.md table { border-collapse: collapse; margin: 0.2em 0 0.7em; font-size: 0.93em; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.md th { background: var(--panel-2); font-weight: 600; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.md del { color: var(--muted); }
.md img { max-width: 100%; border-radius: 10px; }

/* «Копировать ответ» — под каждым сообщением ИИ */
.copy-btn {
  display: flex; align-items: center; gap: 6px; width: fit-content;
  margin-top: 8px; padding: 5px 8px; border-radius: 8px;
  background: none; border: none; color: var(--muted);
  font: inherit; font-size: 12px; cursor: pointer;
  transition: background .15s, color .15s;
}
.copy-btn:hover { background: var(--panel-2); color: var(--text); }
.copy-btn .ck, .copy-btn .copy-ok { display: none; }
.copy-btn.done { color: #4ade80; }
.copy-btn.done .cp { display: none; }
.copy-btn.done .ck { display: block; }
.copy-btn.done .copy-ok { display: inline; }

/* строка действий ответа ИИ: копирование и 👍/👎 — в ОДНУ линию */
.msg-actions { display: flex; align-items: center; gap: 2px; margin-top: 8px; }
.msg-actions .copy-btn { margin-top: 0; }  /* отступ держит ряд, не кнопки */
/* у СВОИХ сообщений ряд прижат вправо — пузырь юзера у правого края */
.msg.user .msg-actions { justify-content: flex-end; }

/* 👍/👎 под ответом ИИ — рядом с копированием (спека 23.11.2026) */
.vote-btns {
  display: flex; align-items: center; gap: 4px;
}
.vote-btn {
  display: flex; align-items: center; padding: 5px 7px; border-radius: 8px;
  background: none; border: none; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.vote-btn:hover { background: var(--panel-2); color: var(--text); }
/* выбранная оценка: контурная иконка красится в цвет целиком
   (заливку убрали: с ней манжета-«частичка» сливалась со сплошным пятном) */
.vote-btn.active.up { color: #4ade80; }
.vote-btn.active.down { color: #f87171; }
@media (prefers-reduced-motion: reduce) { .vote-btn { transition: none; } }

/* правка своего сообщения: карандаш + инлайн-редактор (спека 23.11.2026) */
.edit-btn {
  display: flex; padding: 5px 7px; border-radius: 8px;
  background: none; border: none; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
}
.edit-btn:hover { background: var(--panel-2); color: var(--text); }
/* с курсором весь ряд действий (копирование + карандаш) появляется по
   наведению на сообщение; во время правки ряд держим видимым (кнопка
   «Отменить» не должна пропадать, если увести курсор); на таче — всегда */
@media (hover: hover) {
  .msg.user .msg-actions { opacity: 0; }
  .msg.user:hover .msg-actions,
  .msg.user:has(.edit-box) .msg-actions { opacity: 1; }
}
.edit-box { display: flex; flex-direction: column; gap: 6px; align-self: stretch; }
.edit-box textarea {
  background: var(--pill); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 15px;
  resize: vertical; min-height: 60px; outline: none;
}
.edit-row { display: flex; gap: 8px; justify-content: flex-end; }
.edit-cancel {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 8px 14px; border-radius: 10px; font: inherit; font-size: 13px;
}
.edit-cancel:hover { color: var(--text); background: var(--panel-2); }
.edit-save { padding: 8px 16px; font-size: 13px; }
.edit-save:disabled { opacity: 0.5; cursor: default; }
@media (prefers-reduced-motion: reduce) { .edit-btn { transition: none; } }

.followups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.followup {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 12.5px; cursor: pointer;
}
.followup:hover { color: var(--text); border-color: rgba(139, 92, 246, 0.5); }

/* карточка места (метка на карте) — в духе edit-box/followup */
.place-card {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--pill); padding: 10px 12px; margin: 8px 0; max-width: 420px;
}
.pc-pin { display: flex; flex-shrink: 0; color: #8b5cf6; }
.pc-pin .ic { width: 20px; height: 20px; }
.pc-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pc-name { font-weight: 600; font-size: 14px; }
.pc-addr {
  color: var(--muted); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pc-addr:empty { display: none; }
.pc-btn {
  flex-shrink: 0; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); border-radius: 999px; padding: 7px 12px;
  font-size: 12.5px; text-decoration: none; white-space: nowrap;
}
/* кнопка — это <a> внутри .md: правило «.md a» синит её и даёт подчёркивающую
   полосу (border-bottom). Перебиваем специфичностью — кнопка статичная,
   обычная тёмная пилюля, без синего и без подсветки на ховере. */
.md .pc-btn { color: var(--text); border-bottom: none; }
.md .pc-btn:hover { border-bottom: none; background: var(--panel-2); }

/* ===== цитирование (спека 24.11.2026) ===== */
/* цитата в пузыре юзера: полоса слева, бледный текст, максимум 3 строки */
.msg-quote {
  align-self: stretch; max-width: 100%;
  border-left: 3px solid var(--violet); border-radius: 8px;
  background: var(--panel); color: var(--muted);
  font-size: 12.5px; line-height: 1.45; padding: 6px 10px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
/* плашка активной цитаты — ВНУТРИ пилюли ввода (Gemini-стиль, 24.11):
   flex 1 1 100% + flex-wrap у .composer-box дают ей свою строку над полем */
.quote-bar {
  flex: 1 1 100%;
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 6px; padding: 7px 10px;
  /* чуть светлее пилюли — отдельная «чипса», но часть того же блока */
  background: var(--panel-2); border-radius: 12px;
  overflow: hidden;  /* при анимации высоты содержимое срезается, а не распирает */
  animation: qb-in 0.22s ease;  /* появление: снизу вверх, разворачиваясь */
}
.quote-bar[hidden] { display: none; }
/* появление: выезжает снизу вверх и раскрывается по высоте */
@keyframes qb-in {
  from { opacity: 0; transform: translateY(10px); max-height: 0; padding-top: 0; padding-bottom: 0; margin-bottom: 0; }
  to   { opacity: 1; transform: none; max-height: 60px; padding-top: 7px; padding-bottom: 7px; margin-bottom: 6px; }
}
/* закрытие (класс вешает JS, по концу прячет): уходит вниз и схлопывается */
.quote-bar.closing { animation: qb-out 0.16s ease forwards; pointer-events: none; }
@keyframes qb-out {
  from { opacity: 1; transform: none; max-height: 60px; padding-top: 7px; padding-bottom: 7px; margin-bottom: 6px; }
  to   { opacity: 0; transform: translateY(10px); max-height: 0; padding-top: 0; padding-bottom: 0; margin-bottom: 0; }
}
.qb-ic { display: flex; flex: none; color: var(--muted); }
.qb-text {
  flex: 1; min-width: 0; color: var(--muted); font-size: 12.5px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-word;
}
.quote-bar .qb-x { padding: 2px; }
/* кнопка «↩ ответить» — в стиле vote/edit кнопок того же ряда */
.reply-btn {
  display: flex; padding: 5px 7px; border-radius: 8px;
  background: none; border: none; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.reply-btn:hover { background: var(--panel-2); color: var(--text); }
/* плавающая кнопка «Цитировать» у выделенного текста */
.quote-pop {
  position: fixed; z-index: 80;
  display: flex; align-items: center; gap: 6px;
  /* фон — ЗАМЕТНО светлее фона чата и сплошной: плашка летает поверх текста,
     а --menu ≈ цвет чата — с ним она сливалась и выглядела «прозрачной» */
  background: #2b2b3a;
  border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 999px;
  color: var(--text); font: inherit; font-size: 12.5px;
  padding: 7px 12px; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
:root.light .quote-pop { background: #ffffff; border-color: var(--border); }
.quote-pop:hover { background: #38384a; }
:root.light .quote-pop:hover { background: var(--panel-2); }
@media (prefers-reduced-motion: reduce) { .reply-btn { transition: none; } }

/* ===== Композер ===== */
/* «к последним сообщениям»: плавающая кнопка по центру, привязана к ВЕРХНЕЙ
   кромке обёртки композера (bottom: 100%) — растущая панель ввода несёт её
   наверх с собой; видна только когда чат отмотан вверх (класс .vis от JS) */
.scroll-down {
  position: absolute; left: 50%; bottom: calc(100% + 10px); z-index: 3;
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--menu); border: 1px solid var(--border); color: var(--muted);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35); cursor: pointer;
  opacity: 0; transform: translateX(-50%) translateY(8px); pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease, color 0.15s ease;
}
.scroll-down.vis { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.scroll-down[hidden] { display: flex; }  /* display гоняет .vis, не hidden */
.scroll-down:hover { color: var(--text); }
:root.light .scroll-down { box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15); }
@media (prefers-reduced-motion: reduce) { .scroll-down { transition: none; } }
/* панель ввода лежит ПОВЕРХ чата (текст уходит под неё и тает маской).
   Клики по прозрачным краям обёртки проходят в чат — ловит только панель */
.composer-wrap {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  pointer-events: none;
}
.composer-wrap .composer { pointer-events: auto; }
.composer { padding: 10px 20px 20px; max-width: 840px; width: 100%; margin: 0 auto; }
.composer-box {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px;
  flex-wrap: wrap;  /* цитата (flex-basis 100%) встаёт своей строкой над полем */
  /* плотный цвет (эквивалент прежнего полупрозрачного над фоном): панель
     лежит поверх чата и должна ПОЛНОСТЬЮ закрывать текст под собой */
  background: var(--pill); border: 1px solid var(--border); border-radius: 28px;
  /* НЕ 999px: радиус больше половины высоты (~29px) всё равно обрезается,
     а переход 999→18 визуально «простаивает» до последних миллисекунд и углы
     дёргаются в конце. 28px — тот же вид пилюли, но переход 28→18 плавный */
  transition: border-radius 0.2s ease;  /* пилюля → скруглённый прямоугольник */
}
.composer-box.multiline { border-radius: 18px; }
/* с цитатой внутри — тоже прямоугольник, иначе чипса упирается в круглый край */
.composer-box:has(.quote-bar:not([hidden])) { border-radius: 18px; }
/* скрепка и микрофон: иконки отцентрованы в кнопках глобально (см. .icon-btn),
   кнопки стоят в общем ряду поля ввода — без дополнительных сдвигов */
.composer-box:focus-within { border-color: rgba(139, 92, 246, 0.55); }
#chat-input {
  flex: 1; background: none; border: none; outline: none; color: var(--text);
  font-size: 14px; resize: none; max-height: 7.5em; font-family: inherit; line-height: 1.5;
  /* 7.5em = ровно 5 строк при line-height 1.5; дальше — прокрутка внутри */
  overflow-y: auto;
  transition: height 0.2s ease;  /* рост поля — в такт растягиванию углов */
}
.send-btn {
  background: var(--grad); border: none; color: #fff; width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; position: relative; flex: none;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}
/* пустое поле — кнопка серая и явно не кликабельная
   (:not(.stop) — во время ответа это кнопка «стоп», она активна) */
.send-btn:not(.ready):not(.stop) {
  background: var(--panel-2); color: var(--muted); cursor: default;
}
/* превращение: кольцо «жду» ↔ стрелка вверх (когда есть текст) */
.send-btn .ic-idle, .send-btn .ic-go {
  position: absolute;
  transition: opacity 0.18s ease,
              transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.send-btn .ic-go { opacity: 0; transform: translateY(10px) scale(0.4); }
.send-btn.ready .ic-go { opacity: 1; transform: translateY(0) scale(1); }
.send-btn.ready .ic-idle { opacity: 0; transform: scale(0.4) rotate(90deg); }
/* пока идёт ответ, кнопка = «стоп» (квадрат): клик обрывает генерацию */
.send-btn .ic-stop { width: 20px; height: 20px; opacity: 0; transform: scale(0.4); }
.send-btn.stop .ic-stop { opacity: 1; transform: scale(1); }
.send-btn.stop .ic-idle, .send-btn.stop .ic-go { opacity: 0; transform: scale(0.4); }
/* короткий пульс в момент отправки (класс вешает JS на ~0.3с) */
.send-btn.sent { animation: send-pop 0.3s ease; }
@keyframes send-pop { 40% { transform: scale(1.15); } }

/* недописанный (остановленный) ответ — слегка приглушён */
.msg.bot.stopped { opacity: 0.75; }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.composer-hint { text-align: center; font-size: 11px; color: var(--muted); margin-top: 8px; }

/* ===== Адаптив ===== */
/* затемнение основного экрана при открытой панели — только на телефоне */
.sidebar-backdrop { display: none; }
@media (max-width: 900px) {
  /* затемнение основного экрана, пока панель-шторка открыта */
  .sidebar-backdrop {
    display: block;
    position: absolute; inset: 0; z-index: 9;  /* под панелью (z-index: 10) */
    background: rgba(0, 0, 0, 0.68);
    opacity: 0; pointer-events: none;
    transition: opacity 0.28s ease;
  }
  .sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }
  /* мобильная панель — шторка поверх чата: анимируем transform, не отступ */
  .sidebar {
    position: absolute; z-index: 10; height: 100%; background: var(--bg);
    margin-left: 0; margin-right: 0;
    transition: transform 0.28s ease;
  }
  .sidebar.collapsed { margin-left: 0; transform: translateX(-100%); }
  [dir="rtl"] .sidebar.collapsed { margin: 0; transform: translateX(100%); }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .welcome h1 { font-size: 30px; }
}
/* Мобильный: карточки-подсказки — компактные чипы в 2 колонки (иконка+текст в строку) */
@media (max-width: 560px) {
  .cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .card {
    flex-direction: row; align-items: center; gap: 8px;
    padding: 10px 12px; font-size: 12px;
  }
  .card-icon .ic { width: 16px; height: 16px; }
  .card-arrow { display: none; }
  .hero-logo { width: 88px; height: 88px; }
  .welcome p { margin-bottom: 16px; }
  .msg { max-width: 95%; }
}

@media (prefers-reduced-motion: reduce) {
  .msg.bot.typing::before { animation: none; }
  .caret-b::after { animation: none; }
  .sidebar { transition: none; }
  .sidebar-backdrop { transition: none; }
  .send-btn .ic-idle, .send-btn .ic-go { transition: none; }
  #sidebar-open:not([hidden]) { animation: none; }
  .composer-box, #chat-input { transition: none; }
  .quote-bar, .quote-bar.closing { animation: none; }
  .msg-in, .send-btn.sent { animation: none; }
  .st-fade { animation: none; }
  .wave.fallback span { animation: none; transform: scaleY(0.35); }
  .auth-glider, .auth-tab { transition: none; }
}

/* ===== Модалка настроек ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(420px, calc(100vw - 32px));
  /* непрозрачная плашка: текст не просвечивает сквозь окно */
  background: var(--menu); border: 1px solid var(--border); border-radius: 18px;
  padding: 20px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 17px; font-weight: 700; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
/* hidden обязан побеждать display:flex (авторский стиль перебивает UA-правило [hidden]) */
.field[hidden] { display: none; }
.attach-thumb[hidden], .attach-bar[hidden] { display: none; }

/* плашка-тост внизу экрана (микрофон и прочие сообщения) */
.toast {
  position: fixed; bottom: 96px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  /* тост всегда тёмный — читается на любой теме */
  background: #16161f; border: 1px solid rgba(255, 255, 255, 0.12); color: #e8eaf2;
  font-size: 13px; padding: 9px 16px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0; pointer-events: none; z-index: 90;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.field input, .field select {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font: inherit; padding: 9px 12px; outline: none;
  transition: border-color 0.15s ease;
}
.field input:focus, .field select:focus { border-color: rgba(139, 92, 246, 0.55); }
/* селекты — как поле имени: убираем нативную стрелку, рисуем свой шеврон */
.field select {
  appearance: none; -webkit-appearance: none; cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa0b4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
.field select:hover, .field input:hover { border-color: rgba(139, 92, 246, 0.35); }
.danger-zone {
  border-top: 1px solid var(--border); padding-top: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}

/* карточка памяти (как /memory в Telegram) */
.mem-box {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.mem-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mem-empty-hint { font-size: 12px; color: var(--muted); }
.mem-title { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.mem-clear {
  background: none; border: none; color: #f87171; font: inherit; font-size: 12px;
  cursor: pointer; padding: 3px 6px; border-radius: 6px;
}
.mem-clear:hover { background: rgba(248, 113, 113, 0.12); }
.mem-list { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.mem-empty { font-size: 12px; color: var(--muted); padding: 2px 2px; }
.mem-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 8px 6px 10px;
}
.mem-fact { flex: 1; word-break: break-word; }
.mem-x { background: none; border: none; color: var(--muted); cursor: pointer; display: flex; padding: 2px; border-radius: 5px; }
.mem-x:hover { color: #f87171; }
.mem-add { display: flex; gap: 8px; }
.mem-add input {
  flex: 1; background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font: inherit; padding: 8px 12px; outline: none;
  transition: border-color 0.15s ease;
}
.mem-add input:focus { border-color: rgba(139, 92, 246, 0.55); }
.mem-add-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  font: inherit; font-size: 13px; border-radius: 10px; padding: 8px 14px; cursor: pointer;
}
.mem-add-btn:hover { border-color: rgba(139, 92, 246, 0.45); }
.danger-text { font-size: 12px; color: var(--muted); }
.btn-danger {
  background: transparent; border: 1px solid rgba(239, 68, 68, 0.5); color: #f87171;
  border-radius: 10px; padding: 8px 12px; font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); }

/* ===== Вложения: превью ===== */
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 8px 8px; }
.attach-bar[hidden] { display: none; }
.attach-thumb {
  position: relative; width: 56px; height: 56px;
  border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); background: var(--panel-2);
}
.attach-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-thumb .at-del {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 10px; line-height: 1;
}
.attach-chip {
  display: flex; align-items: center; gap: 8px; height: 56px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px; font-size: 12.5px; color: var(--muted); max-width: 260px;
}
.attach-chip .ac-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attach-chip .ac-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px; }
.attach-chip .ac-del:hover { color: #f87171; }

/* ===== Вложения в сообщении ===== */
.msg-att { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg-att img {
  width: 140px; height: 140px; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--border); display: block;
}
.msg-att .att-pdf {
  display: flex; align-items: center; gap: 8px; height: 40px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 4px 12px; font-size: 12.5px; color: var(--muted); max-width: 240px;
}
.att-pdf .ac-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Аккаунт: аватар, модалка, поповер (спека 18.11.2026) ===== */
#user-btn { cursor: pointer; user-select: none; }
#user-btn:hover { filter: brightness(1.15); }

.auth-tabs { position: relative; display: flex; gap: 6px; background: var(--panel); border-radius: 10px; padding: 4px; }
/* «пузырь» активной вкладки: отдельный элемент, который плавно переползает
   между «Регистрация» и «Вход» (раньше градиент просто прыгал через .active) */
.auth-glider {
  position: absolute; top: 4px; left: 4px; bottom: 4px;
  width: calc(50% - 7px);          /* ширина одной вкладки: (100% - 2*4px паддинг - 6px gap) / 2 */
  background: var(--grad); border-radius: 8px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;            /* не перехватывает клики по вкладкам */
}
.auth-tabs.mode-login .auth-glider { transform: translateX(calc(100% + 6px)); }  /* своя ширина + gap */
/* причина, по которой всплыло окно входа (лимит гостя): вверху, заметно.
   Строгая: глухой однотонный графит, без градиента и полупрозрачности */
.auth-reason {
  background: #22222c;
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 3px;
}
:root.light .auth-reason { background: #eceef2; }  /* в светлой теме — светло-серая плашка */
.auth-reason[hidden] { display: none; }  /* display:flex выше перебивает атрибут hidden (как у .field) */
.auth-reason .ar-title { font-size: 14px; font-weight: 700; color: var(--text); }
.auth-reason .ar-text { font-size: 12.5px; color: var(--muted); }
.auth-tab {
  position: relative; z-index: 1;  /* текст поверх глайдера */
  flex: 1; background: transparent; border: none; color: var(--muted);
  border-radius: 8px; padding: 8px 0; font: inherit; font-size: 13px; cursor: pointer;
  transition: color 0.25s;
}
.auth-tab.active { color: #fff; }  /* фон теперь рисует .auth-glider, здесь только цвет текста */
.auth-switch {
  background: none; border: none; color: var(--muted); font-size: 12.5px;
  cursor: pointer; padding: 0; width: 100%; text-align: center;
}
.auth-switch:hover { color: var(--text); }
.field-error { color: #f87171; font-size: 12px; }
.field-error[hidden] { display: none; }

.user-pop {
  position: fixed; bottom: 64px; left: 14px; z-index: 60;
  background: var(--menu); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; min-width: 200px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
}
[dir="rtl"] .user-pop { left: auto; right: 14px; }
.user-pop[hidden] { display: none; }
.user-pop .up-email { font-size: 13px; color: var(--text); word-break: break-all; }
.user-pop .up-name { font-size: 12px; color: var(--muted); }

/* ===== Страница настроек (/settings): меню слева, панели справа ===== */
.settings-body { overflow-y: auto; height: auto; min-height: 100vh; min-height: 100dvh; }
.settings-shell { max-width: 860px; margin: 0 auto; padding: 20px 20px 60px; }
/* тонкая полоса с кнопкой-меню — видна только на телефоне */
.sp-topbar { display: none; }
/* голова панели: «назад» + заголовок «Настройки» */
.sp-nav-head { display: flex; align-items: center; gap: 10px; padding: 2px 6px 10px; }
.sp-back { text-decoration: none; }
.sp-nav-title { font-size: 19px; font-weight: 700; color: var(--text); }
.settings-cols { display: flex; gap: 20px; align-items: flex-start; }

/* меню-вкладки */
.sp-nav {
  display: flex; flex-direction: column; gap: 4px; width: 240px; flex: none;
  position: sticky; top: 16px;
}
.sp-tab {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 12px; border: none; background: none;
  font: inherit; font-size: 13.5px; color: var(--muted); text-align: left; cursor: pointer;
}
.sp-tab .ic { color: var(--muted); flex: none; }
.sp-tab:hover { background: var(--panel-2); color: var(--text); }
.sp-tab.active { background: var(--panel-2); color: var(--text); }
.sp-tab.active .ic { color: #c4b5fd; }
.sp-tab-pro { color: #c4b5fd; }
.sp-tab-pro .ic { color: #c4b5fd; }

/* панели */
.sp-content { flex: 1; min-width: 0; }
.sp-panel { display: none; flex-direction: column; gap: 14px; }
.sp-panel.active { display: flex; }
.settings-body .field, .settings-body .profile-box, .settings-body .danger-zone {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px;
}
.sp-save { margin-top: 4px; }

/* смена пароля: поля не слипаются (внутренняя колонка со своим gap) */
#pass-box, #pop-pass-box { display: flex; flex-direction: column; gap: 12px; }
/* кнопки «в покое»: серые, пока форма не заполнена */
.btn-primary:disabled { opacity: 0.45; cursor: default; filter: grayscale(0.5); }

/* карточка Pro */
.sp-pro-card {
  background: linear-gradient(160deg, rgba(139, 92, 246, 0.14), rgba(59, 130, 246, 0.08));
  border: 1px solid rgba(139, 92, 246, 0.35); border-radius: 18px; padding: 22px;
  display: flex; flex-direction: column; gap: 14px; align-items: flex-start;
}
.pro-head { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.pro-head .ic { width: 24px; height: 24px; color: #c4b5fd; }
.pro-feats { list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.pro-feats li { display: flex; align-items: center; gap: 8px; }
.pro-feats li::before { content: "✓"; color: #a78bfa; font-weight: 700; }
.pro-soon { font-size: 12px; color: var(--muted); }

/* на телефоне меню — выдвижная панель слева (как чаты на главной) */
.sp-menu-btn { display: none; }
.sp-backdrop { display: none; }
@media (max-width: 700px) {
  .sp-topbar { display: flex; align-items: center; padding: 8px 6px; min-height: 46px; }
  .sp-topbar .sp-menu-btn { display: flex; }  /* кнопка меню видна только тут */
  /* в колонке flex-start сжимал панели под контент — тянем на всю ширину */
  .settings-cols { flex-direction: column; align-items: stretch; }
  .sp-nav {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 110;
    width: min(280px, 84vw); flex-direction: column; gap: 6px;
    background: var(--menu); border-right: 1px solid var(--border);
    padding: 18px 12px; overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
  }
  .sp-nav.open { transform: translateX(0); }
  [dir="rtl"] .sp-nav { left: auto; right: 0; border-right: none; border-left: 1px solid var(--border); transform: translateX(100%); }
  [dir="rtl"] .sp-nav.open { transform: translateX(0); }
  .sp-backdrop {
    display: block; position: fixed; inset: 0; z-index: 100;
    background: rgba(0, 0, 0, 0.68);
    opacity: 0; pointer-events: none; transition: opacity 0.28s;
  }
  .sp-backdrop.visible { opacity: 1; pointer-events: auto; }
  .sp-tab { width: 100%; white-space: nowrap; padding: 11px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .sp-nav { transition: none; }
  .sp-backdrop { transition: none; }
}

/* ---------- профиль в настройках ---------- */
.profile-box {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--panel);
}
.profile-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.profile-row .pr-k { color: var(--muted); display: flex; align-items: center; gap: 6px; flex: none; }
.profile-box .btn-danger { display: flex; gap: 7px; align-items: center; justify-content: center; }
.profile-row .pr-v { color: var(--text); text-align: right; word-break: break-all; }
.profile-note { font-size: 12px; color: var(--muted); }

/* ===== RTL (арабский интерфейс) ===== */
[dir="rtl"] .msg.user { align-self: flex-start; align-items: flex-start; }   /* юзер слева при RTL */
[dir="rtl"] .msg.bot  { align-self: stretch; text-align: right; }
[dir="rtl"] #sidebar-open { margin-right: 0; margin-left: auto; }

/* iOS Safari сам приближает экран к полю с текстом мельче 16px — на телефоне
   все поля ввода держим ровно 16px. ВАЖНО: правило обязано стоять В КОНЦЕ
   файла — при равной специфичности оно должно перебить базовые размеры. */
@media (max-width: 900px) {
  #chat-input, .field input, .field select,
  .mem-add input, .search-box input, .chat-search input { font-size: 16px; }
  /* на телефоне ответ ЛЛМ стоит как раньше — сдвиг влево только десктопу */
  .msg.bot { margin-left: 0; }
}

/* ===== Полноэкранный просмотр фото ===== */
.msg-photos img, .attach-thumb img { cursor: zoom-in; }
.photo-viewer {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(5, 5, 12, 0.93);
  display: flex; align-items: center; justify-content: center;
}
.photo-viewer[hidden] { display: none; }
.photo-viewer img {
  max-width: 92vw; max-height: 88vh; border-radius: 12px;
  object-fit: contain; cursor: zoom-out;
}
.photo-viewer .pv-close {
  position: absolute; top: 14px; right: 16px;
  background: rgba(255, 255, 255, 0.08); color: #fff; border: none;
  width: 38px; height: 38px; border-radius: 50%; font-size: 16px; cursor: pointer;
}
.photo-viewer .pv-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.08); color: #fff; border: none;
  width: 44px; height: 56px; font-size: 30px; line-height: 1; cursor: pointer;
}
.photo-viewer .pv-prev { left: 12px; border-radius: 12px; }
.photo-viewer .pv-next { right: 12px; border-radius: 12px; }
.photo-viewer .pv-close:hover, .photo-viewer .pv-nav:hover { background: rgba(255, 255, 255, 0.18); }

/* ===== Панель настроек (десктоп, Gemini-стиль): карточка у кнопки ===== */
/* позицию (left/top) ставит JS — левый верхний угол у правого края кнопки настроек */
.spop {
  position: fixed; z-index: 90;
  width: min(340px, calc(100vw - 24px)); max-height: min(72vh, 620px); overflow-y: auto;
  background: var(--menu); border: 1px solid var(--border); border-radius: 18px;
  padding: 8px; box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column;
  transition: width .18s ease;
}
.spop.narrow { width: min(288px, calc(100vw - 24px)); }  /* режим списка — компактнее */
.spop[hidden] { display: none; }
/* открытие: панель «вырастает» из кнопки настроек (transform-origin ставит JS) */
@keyframes spop-in {
  from { opacity: 0; transform: scale(.55); }
  to { opacity: 1; transform: none; }
}
.spop:not([hidden]) { animation: spop-in .18s cubic-bezier(.16, .84, .3, 1); }
/* закрытие: просто растворяется, без сжатия (правило после :not([hidden]) — перекрывает его) */
@keyframes spop-out {
  from { opacity: 1; }
  to { opacity: 0; }
}
.spop.closing {
  animation: spop-out .14s ease-in forwards;
  pointer-events: none;  // тающая панель не перехватывает клики
}
.spop-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 12px; border-radius: 12px; border: none; background: none;
  font: inherit; font-size: 13.5px; color: var(--text); text-align: left; cursor: pointer;
}
.spop-item:hover { background: var(--panel-2); }
.spop-item .ic { color: var(--muted); flex: none; }
.spop-item > span:not(.spop-ch) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spop-item .spop-ch { margin-left: auto; color: var(--muted); font-size: 16px; }
.spop-item-pro { color: #c4b5fd; }
.spop-item-pro .ic { color: #c4b5fd; }
.spop-view { display: flex; flex-direction: column; gap: 12px; padding: 4px; }
.spop-view[hidden] { display: none; }
.spop-back {
  display: flex; align-items: center; gap: 6px; border: none; background: none;
  font: inherit; font-size: 13px; color: var(--muted); cursor: pointer;
  padding: 6px 8px; border-radius: 8px; align-self: flex-start;
}
.spop-back:hover { background: var(--panel-2); color: var(--text); }
.spop-sec { display: flex; flex-direction: column; gap: 10px; }
.spop-sec[hidden] { display: none; }

/* ===== светлые полировки ===== */
:root.light .composer-box { box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08); }
:root.light .eicon { filter: brightness(0.9) saturate(1.15); }  /* иконки-эмодзи чуть тише на белом */

/* ===== Тема: ползунок в сайдбаре ===== */
.theme-row .theme-switch {
  margin-left: auto; flex: none; width: 34px; height: 20px;
  border-radius: 999px; background: var(--panel-2);
  border: 1px solid var(--border); position: relative;
  transition: background 0.2s ease;
}
.theme-row .theme-knob {
  position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--muted);
  transition: left 0.2s ease, background 0.2s ease;
}
:root.light .theme-row .theme-switch { background: rgba(59, 130, 246, 0.25); }
:root.light .theme-row .theme-knob { left: 16px; background: var(--blue); }
#btn-theme .ic-sun { display: none; }             /* в тёмной показываем солнце */
:root:not(.light) #btn-theme .ic-sun { display: block; }
:root:not(.light) #btn-theme .ic-moon { display: none; }

/* ===== подсказки к кнопкам: title → data-tip (app.js / settings.js) ===== */
/* Своя плашка вместо системной — с мягким появлением. ТОЛЬКО для курсора:
   на таче title снимается при касании, чтобы не всплывал при зажатии. */
@media (hover: hover) {
  .icon-btn[data-tip], .send-btn[data-tip], .copy-btn[data-tip],
  .cm-item[data-tip], .sp-back[data-tip], .auth-switch[data-tip],
  .edit-btn[data-tip], .reply-btn[data-tip], .vote-btn[data-tip] {
    position: relative;  /* якорь для плашки (у Absolute-иконок чатов свой уже есть) */
  }
  /* подписанные текстом строки сайдбара/настроек: плашка не нужна (имя и так
     видно), а сайдбар с overflow-y:auto ещё и обрезал бы её краем */
  .side-item[data-tip]:hover::after, .side-user[data-tip]:hover::after,
  .sp-tab[data-tip]:hover::after { content: none; }
  [data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute; top: calc(100% + 9px); left: 50%; translate: -50% 0;
    max-width: 230px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: var(--menu); color: var(--text); border: 1px solid var(--border);
    font-size: 13.5px; line-height: 1.3; font-weight: 500; letter-spacing: 0;
    padding: 9px 13px; border-radius: 9px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    pointer-events: none; z-index: 130;
    opacity: 0; animation: tip-in 0.18s ease 0.3s forwards;  /* пауза: пробегаешь мимо — не мигает */
  }
  :root.light [data-tip]:hover::after { box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18); }
  /* у правого края экрана плашку прижимаем вправо — не уезжает за край */
  .topbar-actions [data-tip]:hover::after, .chat-search [data-tip]:hover::after,
  .brand [data-tip]:hover::after, .composer-box [data-tip]:hover::after {
    left: auto; right: 0; translate: 0 0;
  }
  /* мусорка и булавка: плашка тянется ВЛЕВО от иконки (центрированная
     упёрлась бы в край сайдбара и обрезалась) */
  .chat-item .ci-del[data-tip]:hover::after, .chat-item .ci-pin[data-tip]:hover::after {
    left: auto; right: 0; translate: 0 0;
  }
  /* ряд действий у правого края чата (свои сообщения): плашки прижимаем вправо */
  .msg.user .msg-actions [data-tip]:hover::after {
    left: auto; right: 0; translate: 0 0;
  }
  /* кнопки нижней панели: плашка НАД кнопкой (снизу — край экрана) */
  .composer-box [data-tip]:hover::after, .scroll-down[data-tip]:hover::after {
    top: auto; bottom: calc(100% + 9px); animation-name: tip-in-up;
  }
  @keyframes tip-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
  @keyframes tip-in-up { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}
/* кнопка «к последним сообщениям» — исключение: якорь-список тултипов ставит
   relative всем [data-tip], а ей нужен absolute (правило ПОСЛЕ того блока) */
.scroll-down[data-tip] { position: absolute; }
