/* Нейронум — AI-подбор (ai.html): лента подборки слева, диалог с помощником справа.
   Карточки шаблонов, кнопки, бейджи и сообщения чата — из base.css; здесь раскладка рабочей страницы,
   компактное поле ввода и интерактивные элементы диалога. */

@property --ai-angle {
  syntax: "<angle>";
  initial-value: 0deg;
  inherits: false;
}

/* Рабочая страница на высоту экрана: сама страница не прокручивается, прокрутка — только в ленте подборки и в диалоге.
   Ширину диалога человек меняет, потянув за его левый край; значение хранится в cookie ai_chat_w
   и ставится в --ai-chat-w ещё до отрисовки (скрипт в <head> ai.html). */
.page-ai { --chat-w: 420px; --chat-min: 320px; --chat-max: 760px; --results-min: 560px; height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column; background: #f7f7fa; }
.page-ai .site-header { flex: none; }
/* Шапка рабочей страницы — просто белая, без полупрозрачности и размытия */
.page-ai .site-header::before { background: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
.ai-app { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(var(--chat-min), var(--ai-chat-w, var(--chat-w)), min(var(--chat-max), calc(100vw - var(--results-min)))); }

/* ---------- Лента подборки ---------- */
.ai-results { position: relative; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 28px 48px 0; isolation: isolate; container: ai-results / inline-size; scrollbar-width: thin; scrollbar-color: #cfced8 transparent; }
.ai-bg { position: absolute; z-index: -1; left: 0; right: 0; top: 0; height: 440px; overflow: hidden; pointer-events: none; }
.ai-bg::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(to right, rgba(17,17,17,.05) 1px, transparent 1px), linear-gradient(to bottom, rgba(17,17,17,.05) 1px, transparent 1px); background-size: 64px 64px; -webkit-mask-image: linear-gradient(to bottom, #000, transparent 90%); mask-image: linear-gradient(to bottom, #000, transparent 90%); }
.ai-bg::after { content: ""; position: absolute; width: 640px; height: 360px; left: -120px; top: -160px; border-radius: 50%; background: radial-gradient(closest-side, rgba(158,85,207,.16), rgba(54,137,207,.08) 60%, transparent); filter: blur(20px); }

.ai-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.ai-head-main { min-width: 0; }
.ai-kicker { margin-top: 22px; display: inline-flex; align-items: center; gap: 7px; min-height: 28px; padding: 0 11px; border-radius: 999px; border: 1px solid rgba(117,105,212,.28); background: rgba(117,105,212,.09); color: #5b48c2; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.ai-kicker svg { color: #7569d4; }
.ai-head h1 { margin-top: 12px; font-size: clamp(28px, 2.6vw, 38px); letter-spacing: -.035em; }
.ai-query { margin-top: 8px; max-width: 720px; color: var(--muted); font-size: 15px; line-height: 1.5; }
.ai-query q { color: var(--ink-2); font-weight: 600; }
.ai-head-side { flex: none; display: flex; align-items: center; gap: 10px; }
.ai-sort .select { min-height: 42px; width: 214px; padding-left: 14px; border-radius: 11px; font-size: 14px; font-weight: 600; background-color: #fff; background-position: right 12px center; }

/* Что учёл помощник: теги подборки, каждый можно снять */
.ai-tags { margin-top: 18px; display: flex; flex-wrap: wrap; gap: 8px; min-height: 34px; }
.ai-tag { display: inline-flex; align-items: center; gap: 4px; min-height: 34px; padding: 0 5px 0 13px; border-radius: 999px; background: #fff; border: 1px solid rgba(117,105,212,.3); color: #4b3db0; font-size: 14px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(117,105,212,.08); animation: ai-pop .35s cubic-bezier(.22,1,.36,1) both; }
.ai-tag button { width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; color: #8a80d6; transition: background .15s ease, color .15s ease; }
.ai-tag button:hover { background: rgba(117,105,212,.12); color: #4b3db0; }
.ai-tag-add { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 13px; border-radius: 999px; border: 1px dashed #c4c3bc; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; transition: border-color .2s ease, color .2s ease, background .2s ease; }
.ai-tag-add:hover { border-color: #7569d4; color: #4b3db0; background: rgba(255,255,255,.7); }

/* Просмотр одной из прошлых подборок */
.ai-back { margin-top: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 10px 10px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line-soft); font-size: 14px; color: var(--muted); box-shadow: var(--shadow-sm); }
.ai-back[hidden] { display: none; }
.ai-back b { color: var(--ink); font-weight: 650; }

.ai-grid { margin-top: 28px; gap: 36px 24px; }
/* Превью рисуются сразу: opacity/transform-анимация карточек в scroll-контейнере
   может оставлять изображения пустыми в Chromium до взаимодействия с карточкой. */
.tcard-match { gap: 4px; padding: 0 9px; color: #4b3db0; }
.tcard-match svg { color: #9e55cf; }
.tcard-over .ai-like { width: 38px; padding: 0; }

.ai-divider { grid-column: 1 / -1; display: flex; align-items: center; gap: 16px; margin: 8px 0 -8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.ai-divider::before, .ai-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.ai-divider svg { color: #7569d4; }

/* Скелетоны загрузки */
.ai-skel { pointer-events: none; }
.ai-skel .tcard-media, .ai-skel-line { background: linear-gradient(100deg, #ebeaf2 30%, #f7f6fc 50%, #ebeaf2 70%); background-size: 220% 100%; animation: ai-shimmer 1.3s linear infinite; }
.ai-skel .tcard-media { border-color: transparent; box-shadow: none; }
.ai-skel-line { display: block; height: 13px; border-radius: 6px; margin-top: 16px; width: 58%; }
.ai-skel-line + .ai-skel-line { margin-top: 10px; width: 36%; height: 11px; }
.ai-skel .ai-skel-line { margin-left: 20px; }
.ai-skel .ai-skel-line:last-child { margin-bottom: 20px; }
@keyframes ai-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
.ai-shimmer-text { background: linear-gradient(90deg, var(--ink) 0%, var(--ink) 35%, #9e55cf 48%, #3689cf 56%, var(--ink) 70%, var(--ink) 100%); background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent; animation: ai-shimmer 2s linear infinite; }

.ai-empty { grid-column: 1 / -1; padding: 48px 24px; border-radius: 20px; border: 1px dashed #cfcec7; text-align: center; color: var(--muted); }
.ai-empty b { display: block; font-family: var(--display); font-size: 20px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.ai-end { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 36px 24px; border-radius: 20px; background: #fff; border: 1px solid var(--line-soft); text-align: center; }
.ai-end p { color: var(--muted); font-size: 15px; max-width: 460px; }
.ai-end b { font-family: var(--display); font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.ai-sentinel { height: 1px; }
.ai-foot { margin-top: 64px; padding: 24px 0 28px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 24px; color: var(--muted); font-size: 13px; }
.ai-foot nav { display: flex; flex-wrap: wrap; gap: 6px 20px; }
.ai-foot a:hover { color: var(--ink); }

/* ---------- Диалог с помощником ---------- */
.ai-chat { position: relative; min-height: 0; display: flex; flex-direction: column; background: #fff; border-left: 1px solid var(--line-soft); box-shadow: -20px 0 50px -40px rgba(40,30,90,.25); }
/* Внутри панели два экрана: переписка и список чатов */
.ai-view { flex: 1; min-height: 0; display: flex; flex-direction: column; animation: ai-view-in .28s cubic-bezier(.22,1,.36,1) both; }
.ai-view[hidden] { display: none; }
@keyframes ai-view-in { from { opacity: 0; transform: translateX(10px); } }
.ai-view-list { animation-name: ai-view-in-list; }
@keyframes ai-view-in-list { from { opacity: 0; transform: translateX(-10px); } }
.ai-chat-head { flex: none; display: flex; align-items: center; gap: 6px; min-height: 60px; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.ai-chat-name { flex: 1; min-width: 0; padding: 0 4px; font-size: 16px; font-weight: 600; letter-spacing: -.015em; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-icon-btn { width: 38px; height: 38px; flex: none; padding: 0; display: grid; place-items: center; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink-2); transition: background .15s ease, color .15s ease, border-color .15s ease; }
.ai-icon-btn:hover { background: var(--paper); border-color: var(--line-soft); color: var(--ink); }

/* Список чатов пользователя */
.ai-sessions { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 10px; display: flex; flex-direction: column; gap: 2px; scrollbar-width: thin; scrollbar-color: #dcdbe4 transparent; }
.ai-session { width: 100%; min-height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 14px; border: 0; border-radius: 12px; background: transparent; text-align: left; transition: background .15s ease; }
.ai-session:hover { background: #f4f4f7; }
.ai-session.is-current { background: #f0eff5; }
.ai-session-title { flex: 1; min-width: 0; font-size: 14.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-session time { flex: none; font-size: 13px; color: var(--muted); }
.ai-sessions-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 14px; }

.ai-thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 18px 16px; display: flex; flex-direction: column; gap: 18px; scrollbar-width: thin; scrollbar-color: #dcdbe4 transparent; }
.msg { display: flex; gap: 10px; animation: ai-msg-in .4s cubic-bezier(.22,1,.36,1) both; }
@keyframes ai-msg-in { from { opacity: 0; transform: translateY(10px); } }
.msg-user { flex-direction: column; align-items: flex-end; gap: 6px; }
.ai-thread.is-static .msg { animation: none; }
.msg-body { min-width: 0; flex: 1; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.msg .bubble { font-size: 14.5px; line-height: 1.5; padding: 10px 14px; border-radius: 16px; }
.msg .bubble-user { max-width: 86%; border-bottom-right-radius: 5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .bubble-ai { max-width: 100%; background: #f6f6f9; border-color: #ecebf1; border-bottom-left-radius: 5px; }
.msg .bubble-ai p + p { margin-top: 6px; }
.msg .bubble-ai b { color: var(--ink); font-weight: 650; }
/* Ответ печатается: пульсирующая точка в конце текста */
.ai-caret { display: inline-block; width: 8px; height: 8px; margin-left: 4px; border-radius: 50%; background: #7569d4; vertical-align: 1px; animation: ai-caret 1s ease-in-out infinite; }
@keyframes ai-caret { 50% { opacity: .3; transform: scale(.7); } }
.msg-note { font-size: 12px; color: var(--muted-2); padding-left: 2px; }

/* Файлы в сообщении */
.msg-files { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 90%; }
.file-chip { display: inline-flex; align-items: center; gap: 8px; max-width: 220px; min-height: 40px; padding: 4px 10px 4px 4px; border-radius: 11px; background: #fff; border: 1px solid var(--line); font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.file-chip-ico { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--paper); color: #7569d4; overflow: hidden; }
.file-chip-ico img { width: 100%; height: 100%; object-fit: cover; }
.file-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip-name small { display: block; font-size: 11px; font-weight: 500; color: var(--muted-2); }
.file-chip button { width: 22px; height: 22px; flex: none; margin-left: -2px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; color: var(--muted); }
.file-chip button:hover { background: var(--soft); color: var(--ink); }

/* Карточка подборки в сообщении: открывает результаты этого шага */
.ai-set { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 10px; border-radius: 14px; border: 1px solid var(--line-soft); background: #fff; box-shadow: var(--shadow-sm); text-align: left; transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease, background .2s ease; }
.ai-set:hover { border-color: rgba(117,105,212,.45); box-shadow: 0 10px 26px rgba(117,105,212,.14); transform: translateY(-1px); }
.ai-set-thumbs { position: relative; width: 76px; height: 46px; flex: none; }
.ai-set-thumbs img { position: absolute; top: 6px; width: 48px; height: 34px; object-fit: cover; object-position: top; border-radius: 6px; border: 2px solid #fff; box-shadow: 0 4px 10px rgba(17,17,17,.14); }
.ai-set-thumbs img:nth-child(1) { left: 0; z-index: 3; }
.ai-set-thumbs img:nth-child(2) { left: 14px; top: 2px; z-index: 2; rotate: 5deg; }
.ai-set-thumbs img:nth-child(3) { left: 28px; top: 8px; z-index: 1; rotate: 9deg; }
.ai-set-text { min-width: 0; flex: 1; }
.ai-set-text b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; font-weight: 650; line-height: 1.3; }
.ai-set-text small { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-set-go { flex: none; display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 0 11px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 12.5px; font-weight: 700; white-space: nowrap; transition: background .2s ease; }
.ai-set:hover .ai-set-go { background: var(--accent-hover); }
.ai-set.is-active { background: #faf9ff; border-color: rgba(117,105,212,.38); box-shadow: none; transform: none; }
.ai-set.is-active .ai-set-go { background: transparent; color: #5b48c2; padding: 0 4px; }
.ai-set.is-active .ai-set-go::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #7569d4; box-shadow: 0 0 0 3px rgba(117,105,212,.18); animation: ai-pulse 1.8s ease-in-out infinite; }
.ai-set.is-active .ai-set-go svg { display: none; }
@keyframes ai-pulse { 50% { box-shadow: 0 0 0 6px rgba(117,105,212,0); } }

/* Кнопки-рекомендации */
.ai-suggs { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-sugg { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(117,105,212,.28); background: rgba(117,105,212,.06); color: #4b3db0; font-size: 13px; font-weight: 600; white-space: nowrap; transition: background .2s ease, border-color .2s ease, transform .2s ease; }
.ai-sugg svg { color: #7569d4; }
.ai-sugg:hover { background: rgba(117,105,212,.13); border-color: rgba(117,105,212,.5); transform: translateY(-1px); }
.ai-sugg-plain { border-color: var(--line); background: #fff; color: var(--ink-2); }
.ai-sugg-plain:hover { background: var(--paper); border-color: #b9b8b1; }

/* Помощник думает */
.ai-typing { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13.5px; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: #7569d4; animation: ai-dot 1s ease-in-out infinite; }
.ai-dots i:nth-child(2) { animation-delay: .15s; background: #8b5fd1; }
.ai-dots i:nth-child(3) { animation-delay: .3s; background: #3689cf; }
@keyframes ai-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ---------- Компактное поле ввода ---------- */
.ai-compose { flex: none; padding: 8px 14px 12px; background: #fff; }
.ai-prompt { position: relative; display: flex; flex-direction: column; min-height: 96px; padding: 12px 8px 8px 14px; border: 1.5px solid transparent; border-radius: 18px; background: linear-gradient(#fff, #fff) padding-box, linear-gradient(rgba(17,17,17,.1), rgba(17,17,17,.1)) border-box; box-shadow: 0 14px 34px -22px rgba(17,17,17,.3), 0 3px 10px rgba(17,17,17,.04); transition: box-shadow .25s ease; }
/* Та же бегущая градиентная окантовка, что у поля на главной, — только в фокусе */
.ai-prompt:focus-within { background: linear-gradient(#fff, #fff) padding-box, conic-gradient(from var(--ai-angle), rgba(117,105,212,.25) 0deg, #9e55cf 70deg, #7569d4 120deg, #3689cf 170deg, rgba(117,105,212,.25) 240deg, rgba(117,105,212,.25) 360deg) border-box; animation: ai-spin 6s linear infinite; box-shadow: 0 0 0 4px rgba(117,105,212,.08), 0 14px 34px -22px rgba(17,17,17,.3); }
@keyframes ai-spin { to { --ai-angle: 360deg; } }
.ai-prompt textarea { display: block; width: 100%; min-height: 42px; max-height: 168px; padding: 0 4px 0 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--ink); font-size: 15px; line-height: 1.45; }
.ai-prompt textarea::placeholder { color: #8b8b87; opacity: 1; }
.ai-files { display: flex; flex-wrap: wrap; gap: 6px; margin: -2px 0 10px; }
.ai-files[hidden] { display: none; }
.ai-prompt-actions { display: flex; align-items: center; justify-content: space-between; margin-top: auto; padding-top: 6px; }
.ai-prompt-right { display: flex; align-items: center; gap: 4px; }
.ai-prompt button.ai-pbtn { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; border-radius: 50%; }
.ai-attach { border: 1px solid rgba(17,17,17,.1); background: #fff; color: var(--ink-2); transition: background .2s ease, border-color .2s ease; }
.ai-attach:hover { background: var(--paper); border-color: rgba(17,17,17,.18); }
.ai-mic { border: 0; background: transparent; color: var(--muted); transition: color .2s ease, background .2s ease; }
.ai-mic:hover { color: var(--ink); background: var(--paper); }
.ai-mic.is-recording { color: var(--danger); background: #fdecec; animation: ai-rec 1.4s ease-in-out infinite; }
@keyframes ai-rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.28); } 50% { box-shadow: 0 0 0 7px rgba(220,38,38,0); } }
/* Отправка: серая, пока поле пустое; чёрная, когда появился текст или файл (как в AI-виджете). */
.ai-prompt button.ai-send { width: 36px; height: 36px; border: 0; background: #ececea; color: var(--ink); box-shadow: none; transition: background .25s ease, color .25s ease, box-shadow .25s ease, transform .2s ease, opacity .2s ease; }
.ai-send:hover { transform: scale(1.06); }
.ai-prompt:not(.has-value) button.ai-send:hover { background: #e2e2df; }
.ai-prompt.has-value button.ai-send { background: var(--ink); color: #fff; box-shadow: 0 6px 14px rgba(17,17,17,.22); }
.ai-prompt.is-busy .ai-send { opacity: .45; pointer-events: none; }
.ai-hint { margin-top: 8px; text-align: center; font-size: 11.5px; color: var(--muted-2); min-height: 17px; transition: color .2s ease; }
.ai-hint.is-alert { color: #b45309; }
.ai-hint:empty { display: none; }
.ai-chat.is-drag .ai-prompt { background: linear-gradient(#faf9ff, #faf9ff) padding-box, linear-gradient(#7569d4, #7569d4) border-box; }
.ai-chat.is-drag .ai-prompt::after { content: "Отпустите файл, чтобы прикрепить"; position: absolute; inset: 0; display: grid; place-items: center; border-radius: 16px; background: rgba(250,249,255,.94); color: #4b3db0; font-size: 14px; font-weight: 650; }

/* Граница диалога: тянется мышью или стрелками с клавиатуры, двойной клик — ширина по умолчанию */
.ai-resize { position: absolute; z-index: 5; left: -6px; top: 0; bottom: 0; width: 12px; padding: 0; border: 0; background: transparent; cursor: col-resize; touch-action: none; }
.ai-resize::before { content: ""; position: absolute; left: 5px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background .2s ease; }
.ai-resize::after { content: ""; position: absolute; left: 2px; top: 50%; width: 8px; height: 40px; margin-top: -20px; border-radius: 999px; background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(17,17,17,.08); opacity: 0; transition: opacity .2s ease, border-color .2s ease; }
.ai-resize:hover::before, .ai-resize:focus-visible::before, .is-resizing .ai-resize::before { background: linear-gradient(to bottom, #9e55cf, #7569d4 50%, #3689cf); }
.ai-resize:hover::after, .ai-resize:focus-visible::after, .is-resizing .ai-resize::after { opacity: 1; border-color: rgba(117,105,212,.5); }
.ai-resize:focus-visible { outline: 0; }
.is-resizing, .is-resizing * { cursor: col-resize !important; user-select: none !important; }
.is-resizing .ai-results { pointer-events: none; }


/* Вкладки «Результаты / Чат» — только на узких экранах */
.ai-tabs-bar { display: none; }

@keyframes ai-pop { from { opacity: 0; transform: scale(.92); } }

/* ---------- Адаптив ---------- */
/* Колонки ленты считаются от ширины самой ленты — она меняется, когда тянут границу диалога */
@container ai-results (min-width: 1500px) { .ai-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container ai-results (max-width: 980px) { .ai-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container ai-results (max-width: 760px) { .ai-head { flex-direction: column; align-items: flex-start; gap: 16px; } }
@media (max-width: 1320px) {
  .page-ai { --chat-w: 380px; }
  .ai-results { padding-inline: 36px; }
}
@media (max-width: 1180px) {
  .page-ai { --chat-w: 360px; }
  .ai-results { padding-inline: 28px; }
}
@media (max-width: 991px) {
  /* Узкие экраны: прокручивается сама страница. Шапка прячется при прокрутке вниз и выезжает при прокрутке вверх
     (класс header-hidden ставит ai.js), а переключатель «Результаты / Чат» — нижняя панель, как в приложениях */
  .page-ai { height: auto; overflow: visible; display: block; }
  .page-ai .site-header { position: sticky; top: 0; transition: top .3s cubic-bezier(.22,1,.36,1), box-shadow .3s ease; }
  .page-ai.page-scrolled .site-header { box-shadow: 0 8px 24px -16px rgba(17,17,17,.25); }
  .page-ai.header-hidden .site-header { top: calc(-1 * var(--header-h) - 2px); box-shadow: none; }
  .tab-chat .site-header { display: none; } /* у чата своя шапка: «Назад», название, «Новый чат» */
  .ai-app { display: block; }
  .ai-resize { display: none; }
  .ai-tabs-bar { position: fixed; z-index: 56; left: 0; right: 0; bottom: 0; display: block; padding: 10px 16px max(18px, calc(env(safe-area-inset-bottom) + 8px)); border-top: 1px solid var(--line-soft); background: rgba(255,255,255,.94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
  .ai-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px; border-radius: 12px; background: #ebeaf0; }
  .ai-tab { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 0 10px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 15px; font-weight: 650; transition: background .2s ease, color .2s ease, box-shadow .2s ease; }
  .ai-tab[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(17,17,17,.12), 0 1px 1px rgba(17,17,17,.04); }
  .ai-tab svg { color: #7569d4; }
  .ai-tab-count { font-size: 12.5px; font-weight: 700; color: var(--muted-2); }
  .ai-tab-count:empty { display: none; }
  .ai-tab-dot { display: none; width: 7px; height: 7px; margin-left: -2px; border-radius: 50%; background: #f43f5e; }
  .ai-tab.has-unread .ai-tab-dot { display: inline-block; }
  .page-ai:not(.tab-chat) .ai-chat, .tab-chat .ai-results, .tab-chat .scroll-to-top { display: none; }
  .ai-results { overflow: visible; padding: 8px 20px var(--ai-tabs-h, 70px); }
  .scroll-to-top { bottom: calc(var(--ai-tabs-h, 70px) + 14px); }
  .ai-grid { gap: 32px 20px; }
  /* Чат — на весь экран над нижней панелью */
  .ai-chat { height: calc(100vh - var(--ai-tabs-h, 65px)); height: calc(var(--ai-vh, 100dvh) - var(--ai-tabs-h, 65px)); border-left: 0; box-shadow: none; overflow: hidden; } /* сдвиг при смене экранов чата не должен расширять страницу */
  .ai-foot { margin-top: 48px; }
}
@media (max-width: 560px) {
  .ai-results { padding-inline: 16px; }
  .ai-head h1 { font-size: 28px; }
  .ai-head-side, .ai-sort, .ai-sort .select { width: 100%; }
  .ai-tags { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding: 2px 16px; }
  .ai-tags::-webkit-scrollbar { display: none; }
  .ai-back { flex-direction: column; align-items: flex-start; }
  .ai-thread { padding-inline: 14px; }
  .ai-compose { padding-inline: 10px; }
  .ai-prompt textarea { font-size: 16px; } /* без автозума в iOS */
}
@container ai-results (max-width: 540px) { .ai-grid { grid-template-columns: minmax(0, 1fr); } }
@media (prefers-reduced-motion: reduce) {
  .ai-prompt:focus-within, .ai-skel .tcard-media, .ai-skel-line, .ai-shimmer-text, .ai-dots i, .ai-mic.is-recording, .ai-caret { animation: none; }
}
