/* ===== CSS Variables (ChatGPT light palette) ===== */
:root {
    --bg: #ffffff;
    --bg-secondary: #f9f9f9;
    --bg-elevated: #f4f4f4;

    --text: #0d0d0d;
    --text-muted: #6e6e6e;

    --border: #ececec;

    --accent: #0d0d0d;
    --accent-text: #ffffff;
    --danger: #ef4146;

    --bubble-user: #f4f4f4;
    --bubble-assistant: transparent;

    --bg-code: #f3f3f3;

    --tooltip-bg: #2a2a2a;
    --tooltip-text: #ffffff;

    --font-sans: -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, Menlo, "Liberation Mono", monospace;
}

/* ===== ChatGPT dark palette ===== */
[data-theme="dark"] {
    --bg: #212121;
    --bg-secondary: #171717;
    --bg-elevated: #2f2f2f;

    --text: #ececec;
    --text-muted: #afafaf;

    --border: #303030;

    --accent: #ffffff;
    --accent-text: #0d0d0d;
    --danger: #ef4146;

    --bubble-user: #2f2f2f;
    --bubble-assistant: transparent;

    --bg-code: #1e1e1e;

    --tooltip-bg: #ececec;
    --tooltip-text: #0d0d0d;
}

/* ===== Scrollbar (тонкий, без стрелок) ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

::-webkit-scrollbar-button {
    display: none;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* ===== Base ===== */
html {
    overscroll-behavior: none;
}

body {
    margin: 0;
    /* 100vh на мобильных считается от "большого" viewport, без учёта
       адресной строки/клавиатуры — из-за этого sticky-композер уезжал
       вниз за пределы видимого экрана. 100dvh отслеживает реальный
       видимый viewport (современные браузеры); 100vh — фолбэк для старых. */
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    display: flex;
    flex-direction: column;
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* ===== Layout (sidebar + main) ===== */
.layout {
    display: flex;
    flex: 1;
    min-height: 0;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    box-sizing: border-box;
    /* Сайдбар — слой выше основного контента, иначе выпадающие меню/флайауты,
       выходящие за его правый край, перекрываются основной областью справа. */
    position: relative;
    z-index: 30;
}

.sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 12px 4px;
    padding: 6px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
}

.sidebar-new-chat:hover {
    background: var(--bg-elevated);
}

.sidebar-new-chat-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.sidebar-new-chat:hover .sidebar-new-chat-icon {
    color: var(--text);
}

.sidebar h3 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    margin: 8px 20px 4px;
}

/* Сворачиваемый заголовок раздела «Проекты»: выглядит как h3, но кликабелен. */
.sidebar-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: calc(100% - 24px);
    margin: 8px 12px 4px;
    padding: 2px 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-radius: 6px;
}

.sidebar-section-toggle:hover {
    background: var(--bg-elevated);
}

.sidebar-section-caret {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    transition: transform 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-projects.collapsed .sidebar-section-caret,
.sidebar-chats.collapsed .sidebar-section-caret {
    transform: rotate(-90deg);
}

/* Плавное сворачивание незакреплённых проектов через grid 1fr→0fr
   (закреплённые в отдельном блоке — их не трогаем). Плавная кривая + fade
   содержимого делают анимацию мягче. */
.sidebar-projects-list {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-projects.collapsed .sidebar-projects-list {
    grid-template-rows: 0fr;
}

.sidebar-projects-list-inner {
    overflow: hidden;
    min-height: 0;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.sidebar-projects.collapsed .sidebar-projects-list-inner {
    opacity: 0;
}

/* Раздел «Чаты» — сворачивается так же, как «Проекты» (закреплённые остаются). */
.sidebar-chats-list {
    display: grid;
    grid-template-rows: 1fr;
    transition: grid-template-rows 0.38s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-chats.collapsed .sidebar-chats-list {
    grid-template-rows: 0fr;
}

.sidebar-chats-list-inner {
    overflow: hidden;
    min-height: 0;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.sidebar-chats.collapsed .sidebar-chats-list-inner {
    opacity: 0;
}

/* Пока стартовое свёрнутое состояние выставляется из localStorage —
   переходы выключены, иначе секция «схлопывается» на глазах при каждой
   загрузке страницы. Класс снимается на следующем кадре (см. base.html). */
.sidebar-projects.no-anim .sidebar-section-caret,
.sidebar-projects.no-anim .sidebar-projects-list,
.sidebar-projects.no-anim .sidebar-projects-list-inner,
.sidebar-chats.no-anim .sidebar-section-caret,
.sidebar-chats.no-anim .sidebar-chats-list,
.sidebar-chats.no-anim .sidebar-chats-list-inner {
    transition: none;
}

/* Пустой список закреплённых чатов не должен оставлять зазор. */
.sidebar-chats-pinned:empty {
    display: none;
}

/* У закреплённого проекта вместо иконки-папки показываем булавку. */
.sidebar-project-pin-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--text-muted);
    display: none;
}

.sidebar-project.pinned .sidebar-project-pin-icon {
    display: block;
}

.sidebar-project.pinned .sidebar-project-icon {
    display: none;
}

/* Проекты + чаты прокручиваются вместе; футер закреплён снаружи (снизу).
   Так нижние проекты/чаты не уходят под панель профиля. */
.sidebar-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: none;
}

.sidebar ul {
    list-style: none;
    padding: 0 12px 6px;
    margin: 0;
}

.sidebar-chat {
    position: relative;
    border-radius: 6px;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
}

.sidebar-chat:hover,
.sidebar-chat.active,
.sidebar-chat.menu-open {
    background: var(--bg-elevated);
}

/* Активный (открытый) чат — чуть плотнее фон + средний вес текста. */
.sidebar-chat.active {
    background: color-mix(in srgb, var(--text) 4%, var(--bg-elevated));
}

.sidebar-chat.active .sidebar-chat-link {
    font-weight: 500;
}

.sidebar-chat-link {
    flex: 1;
    min-width: 0;
    display: block;
    padding: 6px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-chat-menu-btn {
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 8px;
    margin-right: 4px;
    border-radius: 4px;
    font-size: 16px;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s;
}

.sidebar-chat:hover .sidebar-chat-menu-btn,
.sidebar-chat.menu-open .sidebar-chat-menu-btn {
    opacity: 1;
}

.sidebar-chat-menu-btn:hover {
    color: var(--text);
}

.sidebar-chat-menu {
    /* position: fixed + координаты из JS — чтобы меню не обрезалось скроллом
       сайдбара (.sidebar-scroll overflow:auto) у нижних чатов/проектов. */
    position: fixed;
    z-index: 200;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    padding: 0;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    /* НЕ использовать transform для анимации: любой transform на меню делает его
       containing-block для position: fixed дочернего флайаута «Переместить»,
       и его координаты (от окна) уезжают. Анимируем только opacity + max-height. */
    transition: opacity 0.15s ease-out, visibility 0.15s, max-height 0.15s ease-out;
}

.sidebar-chat-menu > *:not(:last-child) {
    border-bottom: 1px solid var(--border);
}

.sidebar-chat-menu.open {
    max-height: 400px;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sidebar-chat-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: 0;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font: inherit;
    font-size: 14px;
}

.sidebar-chat-menu-item:hover {
    background: var(--bg-elevated);
}

.sidebar-chat-menu-item.danger {
    color: var(--danger);
}

.sidebar-chat-menu-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.sidebar-chat-menu-item:hover .sidebar-chat-menu-icon {
    color: var(--text);
}

.sidebar-chat-menu-item.danger .sidebar-chat-menu-icon,
.sidebar-chat-menu-item.danger:hover .sidebar-chat-menu-icon {
    color: var(--danger);
}

.sidebar-chat-delete-form,
.sidebar-chat-pin-form,
.sidebar-chat-rename-form {
    margin: 0;
}

/* Контейнер пункта «Переместить» + его флайаут со списком проектов. */
.sidebar-chat-submenu {
    position: relative;
}

.sidebar-chat-move-caret {
    width: 14px;
    height: 14px;
    margin-left: auto;
    color: var(--text-muted);
}

/* Список проектов — отдельный выпадающий список сбоку. position: fixed, чтобы
   выйти из-под обрезки скролл-контейнера сайдбара (.sidebar ul overflow-y:auto
   обрезает и по горизонтали). Координаты ставит JS рядом с пунктом. */
.sidebar-chat-move {
    position: fixed;
    z-index: 60;
    min-width: 180px;
    max-height: 260px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.14);
    display: none;
    flex-direction: column;
}

.sidebar-chat-submenu.submenu-open > .sidebar-chat-move {
    display: flex;
}

.sidebar-chat-move form {
    margin: 0;
}

.sidebar-chat-move-item {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
    display: block;
}

.sidebar-chat-move-item:disabled {
    color: var(--text-muted);
    cursor: default;
}

.sidebar-chat-pin-icon {
    width: 14px;
    height: 14px;
    margin-right: 6px;
    color: var(--text-muted);
    vertical-align: -2px;
    display: none;
}

.sidebar-chat.pinned .sidebar-chat-pin-icon {
    display: inline-block;
}

.token-icon {
    width: 15px;
    height: 15px;
    color: var(--text-muted);
    vertical-align: -3px;
    margin-right: 3px;
}

.sidebar-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 8px 10px;
}

.sidebar-project {
    /* Боковой отступ 12px = как у списка чатов (ul padding), чтобы иконка-папка
       встала ровно там, где у чатов появляется булавка-закрепление. */
    margin: 0 12px 1px;
}

.sidebar-project-row {
    position: relative;
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.sidebar-project-row:hover,
.sidebar-project.menu-open .sidebar-project-row,
.sidebar-project.active .sidebar-project-row {
    background: var(--bg-elevated);
}

/* Активный (открытый) проект — так же чуть плотнее фон + средний вес. */
.sidebar-project.active .sidebar-project-row {
    background: color-mix(in srgb, var(--text) 4%, var(--bg-elevated));
}

.sidebar-project.active .sidebar-project-name {
    font-weight: 500;
}

.sidebar-project-link {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
}

.sidebar-project-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    color: var(--text-muted);
}


.sidebar-project-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-project-row:hover .sidebar-project-menu-btn,
.sidebar-project.menu-open .sidebar-project-menu-btn {
    opacity: 1;
}

.chat-container.project-page {
    max-width: 736px;
    padding-top: 112px;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    position: relative;
    box-sizing: border-box;
}

/* Градиент-затемнение снизу — чаты «исчезают» под ним при прокрутке списка. */
.chat-container.project-page::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 48px;
    background: linear-gradient(to top, var(--bg), transparent);
    pointer-events: none;
}

.project-page-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.project-page-icon {
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    color: var(--text-muted);
}

/* Иконка-эмодзи в шапке страницы агента. */
.agent-page-icon {
    font-size: 28px;
    line-height: 1;
    flex-shrink: 0;
}

/* Бейдж агента в шапке чата с агентом. */
.chat-agent-badge {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* ===== Каталог агентов (/agents/) ===== */
.agents-page {
    max-width: none;
    padding-top: 24px;
}

.agents-page-title {
    margin: 0 0 4px;
    font-size: 24px;
}

.agents-page-hint {
    margin: 0 0 20px;
    color: var(--text-muted);
}

.agents-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.agent-card {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 18px 20px;
    height: 120px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.agent-card:hover {
    border-color: var(--text-muted);
    background: var(--bg-elevated);
}

.agent-card-head {
    display: flex;
    align-items: center;
    gap: 14px;
}

.agent-card-icon {
    font-size: 48px;
    line-height: 1;
    flex: none;
}

.agent-card-name {
    font-size: 18px;
    font-weight: 600;
}

.agent-card-desc {
    margin-top: 6px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-muted);
}

.project-page-title {
    margin: 0;
    font-size: 22px;
}

.project-page-cost {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 3px 12px;
    border-radius: 999px;
    white-space: nowrap;
}

.project-tabs {
    display: inline-flex;
    gap: 8px;
    margin-bottom: 22px;
}

.project-tab {
    border: 1px solid var(--border);
    background: transparent;
    padding: 6px 16px;
    border-radius: 999px;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}

.project-tab:hover {
    color: var(--text);
    background: var(--bg-secondary);
}

.project-tab.active {
    color: var(--text);
    background: var(--bg-elevated);
    border-color: var(--text-muted);
}

/* Шапка/композер/вкладки фиксированы, прокручивается только активная панель. */
.project-page-header,
.project-composer,
.project-tabs {
    flex-shrink: 0;
}

.project-tab-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-bottom: 28px;
    box-sizing: border-box;
}

.project-section {
    margin-bottom: 30px;
}

.project-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.project-section-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.project-section-hint {
    margin: 0 0 14px;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

.project-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 18px;
    padding: 7px 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s, border-color 0.15s;
}

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

.project-btn-primary {
    background: var(--accent);
    color: var(--accent-text);
}

.project-btn-primary:hover {
    opacity: 0.9;
}

.project-btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.project-btn-ghost:hover {
    background: var(--bg-elevated);
}

.project-memory-form {
    margin: 0;
}

.project-memory-edit {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    min-height: 92px;
    max-height: 320px;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px 16px;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.6;
    background: var(--bg-elevated);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.project-memory-edit::placeholder {
    color: var(--text-muted);
}

.project-memory-edit:focus {
    outline: none;
    background: var(--bg);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.project-memory-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 10px;
}

.project-file-form {
    margin: 0;
}

.project-file-list {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.project-file {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    border-radius: 12px;
    background: var(--bg-secondary);
    transition: background 0.15s;
}

.project-file:hover {
    background: var(--bg-elevated);
}

.project-file-icon {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 9px;
    background: var(--bg-elevated);
    color: var(--text-muted);
}

.project-file:hover .project-file-icon {
    background: var(--bg);
}

.project-file-icon svg {
    width: 18px;
    height: 18px;
}

.project-file-link {
    flex: 1;
    min-width: 0;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-file-cost {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.project-file-link:hover {
    text-decoration: underline;
}

.project-file-delete-form {
    margin: 0;
}

.project-file-delete {
    display: grid;
    place-items: center;
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.project-file-delete svg {
    width: 16px;
    height: 16px;
}

.project-file:hover .project-file-delete,
.project-file:focus-within .project-file-delete {
    opacity: 1;
}

.project-file-delete:hover {
    color: var(--danger);
    background: var(--bg);
}

@media (hover: none) {
    .project-file-delete {
        opacity: 1;
    }
}

.project-file-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 6px 2px;
}

/* На странице проекта свой оверлей-разделитель — общий оверлей композера прячем. */
body:has(.project-drop) .drop-overlay {
    display: none !important;
}

.project-drop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    flex-direction: column;
}

.project-drop.open {
    display: flex;
}

.project-drop-half {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: color-mix(in srgb, var(--bg) 86%, transparent);
    backdrop-filter: blur(3px);
    transition: background 0.12s;
}

.project-drop-half + .project-drop-half {
    border-top: 2px dashed var(--border);
}

.project-drop-half.active {
    background: color-mix(in srgb, var(--accent) 14%, var(--bg));
}

.project-drop-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 28px 56px;
    border: 2px dashed var(--text-muted);
    border-radius: 18px;
    color: var(--text);
    font-size: 18px;
    font-weight: 500;
    pointer-events: none;
    transition: border-color 0.12s, color 0.12s;
}

.project-drop-half.active .project-drop-card {
    border-color: var(--accent);
    color: var(--accent);
}

.project-drop-card svg {
    width: 46px;
    height: 46px;
    color: var(--text-muted);
    transition: color 0.12s;
}

.project-drop-half.active .project-drop-card svg {
    color: var(--accent);
}

.project-composer {
    margin-bottom: 24px;
}

.project-chat-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.project-chat-list .sidebar-chat {
    flex-direction: column;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 12px;
    gap: 2px;
}

.project-chat-list .sidebar-chat-link {
    padding: 0;
    padding-right: 22px;
}

/* Вся карточка чата в проекте кликабельна: ссылка-заголовок растягивается на
   весь .sidebar-chat (он position: relative). Текст/мета под ней ведут на чат. */
.project-chat-list .sidebar-chat-link::after {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
}

.project-chat-list .sidebar-chat-menu-btn {
    position: absolute;
    top: 6px;
    right: 6px;
    margin: 0;
    /* Над растянутой ссылкой, иначе «⋯» перестанет нажиматься. */
    z-index: 2;
}

.sidebar-chat-meta {
    font-size: 12px;
    color: var(--text-muted);
    padding-right: 22px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-empty {
    color: var(--text-muted);
    font-size: 14px;
    padding: 20px 2px;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px;
}

.sidebar-footer-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    color: var(--text);
    text-decoration: none;
    border-radius: 8px;
    font-weight: 500;
    min-width: 0;
}

.sidebar-footer-profile:hover {
    background: var(--bg-elevated);
}

.sidebar-footer-avatar {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.sidebar-footer-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer form {
    margin: 4px 0 0;
}

.sidebar-footer-logout {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: 0;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    font: inherit;
}

.sidebar-footer-logout:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.sidebar-footer-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sidebar-footer-logout:hover .sidebar-footer-icon {
    color: var(--text);
}

/* ===== Mobile header (виден только на мобилке) ===== */
.mobile-header {
    display: none;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

.burger-btn {
    background: none;
    border: 0;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 10px;
    color: var(--text);
    border-radius: 6px;
}

.burger-btn:hover {
    background: var(--bg-elevated);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 50;
}

.sidebar-overlay.visible {
    opacity: 1;
}

/* ===== Мобильная адаптация (≤ 768px) ===== */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s;
        z-index: 100;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        pointer-events: none;
    }

    .sidebar-overlay.visible {
        pointer-events: auto;
    }

    .main-scroll {
        padding: 8px 8px 0;
    }

    .chat-container {
        max-width: 100%;
    }

    .main-top {
        padding: 0 8px;
    }
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.main-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 0;
    scrollbar-gutter: stable;
    min-height: 0;
}

/* ===== Утилиты ===== */
.text-muted {
    color: var(--text-muted);
}

.chat-totals {
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Chat container (центральная колонка контента) ===== */
.chat-container {
    max-width: 920px;
    margin: 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* ===== Сообщения user/assistant ===== */
.message-wrapper {
    margin: 16px 0;
}

.message-wrapper.user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.msg-user {
    display: inline-block;
    background: var(--bubble-user);
    padding: 10px 16px;
    border-radius: 18px;
    max-width: 80%;
    text-align: left;
    white-space: pre-wrap;
    margin: 0;
}

.msg-assistant {
    background: var(--bubble-assistant);
    max-width: 90%;
}

.msg-assistant pre code.hljs {
    background: var(--bg-code);
}

/* ===== Code block wrapper (lang header + copy btn) ===== */
.msg-assistant .code-block {
    border-radius: 12px;
    margin: 12px 0;
    background: var(--bg-code);
}

.msg-assistant .code-block pre {
    margin: 0;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border);
}

.code-block-lang {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
    font-family: var(--font-mono);
}

.code-block-lang svg {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.code-block-copy {
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: color 0.15s, background 0.15s;
}

.code-block-copy svg {
    width: 18px;
    height: 18px;
}

.code-block-copy:hover {
    color: var(--text);
    background: var(--bg-elevated);
}

.code-block-copy.copied {
    color: var(--accent);
}

/* Tooltip для code-block-copy (тот же паттерн, что у message buttons) */
.code-block-copy[data-tooltip]::after,
.code-block-copy[data-tooltip]::before {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.code-block-copy[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.code-block-copy[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--tooltip-bg);
}

.code-block-copy[data-tooltip]:hover::after,
.code-block-copy[data-tooltip]:hover::before,
.code-block-copy[data-tooltip]:focus-visible::after,
.code-block-copy[data-tooltip]:focus-visible::before {
    opacity: 1;
    transition-delay: 0.5s;
}

.message-wrapper > button {
    background: none;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    margin-right: 4px;
    opacity: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.message-wrapper > button svg {
    width: 16px;
    height: 16px;
}

.message-wrapper:hover > button {
    opacity: 1;
}

.message-wrapper > button:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.message-wrapper .copy-btn.copied {
    color: var(--accent);
    opacity: 1;
}

/* ===== Tooltip (custom, заменяет native title) ===== */
.message-wrapper > button[data-tooltip] {
    position: relative;
}

.message-wrapper > button[data-tooltip]::after,
.message-wrapper > button[data-tooltip]::before {
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.message-wrapper > button[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--tooltip-bg);
    color: var(--tooltip-text);
    padding: 5px 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.message-wrapper > button[data-tooltip]::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 1px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--tooltip-bg);
}

.message-wrapper > button[data-tooltip]:hover::after,
.message-wrapper > button[data-tooltip]:hover::before,
.message-wrapper > button[data-tooltip]:focus-visible::after,
.message-wrapper > button[data-tooltip]:focus-visible::before {
    opacity: 1;
    transition-delay: 0.5s;
}

/* ===== Composer (форма ввода сообщения) ===== */
.chat-composer {
    margin-top: auto;
    margin-bottom: 12px;
    position: sticky;
    bottom: 12px;
    background: var(--bg-elevated);
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.chat-composer form {
    margin: 0;
}

/* Док композера на странице чата — как .image-composer-dock в галерее:
   сплошная подложка фона прячет сообщения за скруглёнными углами и в зазоре
   снизу, а градиент сверху плавно растворяет их перед композером. */
.chat-composer-dock {
    margin-top: auto;
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding-bottom: 12px;
}

.chat-composer-dock .chat-composer {
    margin: 0;
    position: static;
    bottom: auto;
}

.chat-composer-dock::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 36px;
    background: linear-gradient(to bottom, transparent, var(--bg));
    pointer-events: none;
}

/* ===== Кнопка "вниз" над композером ===== */
.scroll-to-bottom {
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg);
    border: 1.5px solid var(--border);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    padding: 0;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.4s,
        transform 0.5s cubic-bezier(0.22, 1, 0.36, 1),
        background 0.15s;
    z-index: 5;
}

.scroll-to-bottom.visible {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.scroll-to-bottom:hover {
    background: var(--bg-elevated);
}

.scroll-to-bottom svg {
    width: 24px;
    height: 24px;
}

/* ===== Centered composer (страница нового чата + начало FLIP) ===== */
.chat-container--centered,
html.chat-entering .chat-container {
    justify-content: center;
}

.chat-welcome {
    text-align: center;
    margin-bottom: 24px;
}

.chat-welcome-title {
    font-size: 30px;
    font-weight: 600;
    margin: 0;
    color: var(--text);
}

.chat-container--centered .chat-composer,
html.chat-entering .chat-composer {
    margin-top: 0;
    margin-bottom: 0;
    position: static;
    bottom: auto;
}

/* В стартовой точке FLIP композер по центру — док ведёт себя как обычный блок. */
html.chat-entering .chat-composer-dock {
    margin-top: 0;
    position: static;
    padding-bottom: 0;
    background: transparent;
}

html.chat-entering .chat-composer-dock::before {
    display: none;
}

/* Начальное состояние перехода home → chat: история и заголовок прячутся, FLIP их проявит */
html.chat-entering .chat-container .message-wrapper,
html.chat-entering .chat-header {
    opacity: 0;
}

.composer-textarea-wrap {
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--bg);
    overflow: hidden;
    transition: border-color 0.15s;
}

.composer-textarea-wrap:focus-within {
    border-color: var(--text);
}

.drop-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(4px);
    pointer-events: none;
}

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

.drop-overlay-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 72px;
    border: 2px dashed var(--text-muted);
    border-radius: 20px;
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 18px;
    font-weight: 500;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.drop-overlay-box svg {
    width: 56px;
    height: 56px;
    color: var(--text-muted);
}

.composer-textarea {
    width: 100%;
    min-height: 44px;
    max-height: 200px;
    padding: 14px 18px;
    border: 0;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    outline: none;
    resize: none;
    overflow-y: hidden;
    box-sizing: border-box;
    display: block;
}

.composer-details {
    margin-bottom: 4px;
}

.composer-details-summary {
    display: flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: 0;
    padding: 4px 0;
    cursor: pointer;
    color: var(--text-muted);
    font: inherit;
    font-size: 13px;
    user-select: none;
}

.composer-details-summary:hover {
    color: var(--text);
}

.composer-details-caret {
    display: inline-block;
    transition: transform 0.2s ease;
    font-size: 10px;
}

.composer-details.open .composer-details-caret {
    transform: rotate(90deg);
}

.composer-details-content {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    transition: max-height 0.4s cubic-bezier(0.32, 0.72, 0, 1),
                opacity 0.4s cubic-bezier(0.32, 0.72, 0, 1),
                margin-top 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

.composer-details.open .composer-details-content {
    opacity: 1;
    margin-top: 6px;
}

.composer-details-content textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    font-family: inherit;
    font-size: 13px;
    color: var(--text);
    outline: none;
    box-sizing: border-box;
    resize: vertical;
    display: block;
}

.composer-details-content textarea:focus {
    border-color: var(--text);
}

.composer-instructions-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}

.composer-instructions-status {
    font-size: 12px;
    color: var(--text-muted);
}

.composer-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.composer-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.composer-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
}

.composer-attach:hover {
    background: var(--bg-elevated);
}

.composer-attach svg {
    width: 18px;
    height: 18px;
}

.composer-attachments {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}

.composer-attach-images,
.composer-attach-files {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.composer-attachment {
    position: relative;
    width: 140px;
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.composer-attachment img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.composer-attachment-file {
    width: auto;
    height: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 200px;
    padding: 10px 30px 10px 12px;
    background: var(--bg-elevated);
}

.composer-file-icon svg {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
}

.composer-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text);
}

.composer-attachment-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-images {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}

.message-image {
    display: block;
    max-width: 320px;
    max-height: 320px;
    border-radius: 12px;
    cursor: pointer;
}

.message-video {
    display: block;
    max-width: 360px;
    max-height: 360px;
    border-radius: 12px;
    background: #000;
}

/* Картинки, сгенерированные моделью в чате: слева (сторона ассистента),
   крупнее пользовательских миниатюр, с мягким появлением. */
.message-wrapper.assistant .message-images {
    justify-content: flex-start;
    margin: 6px 0;
}

.message-images-generated .message-image {
    max-width: min(420px, 100%);
    max-height: 420px;
    border-radius: 14px;
    border: 1px solid var(--border);
}

.message-image-in {
    animation: message-image-in 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

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

.message-files {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-bottom: 6px;
}

.message-images:empty,
.message-files:empty {
    display: none;
    margin: 0;
}

.message-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 260px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elevated);
    color: var(--text);
    text-decoration: none;
}

.message-file svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--text-muted);
}

/* Чип-плейсхолдер вложения, импортированного из ChatGPT (сам файл не перенесён). */
.att-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 10px;
    margin: 2px 2px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-size: 0.85em;
    vertical-align: middle;
}

.message-file span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Файлы у ответа модели (сгенерированные) выравниваем по левому краю,
   как и сам текст ассистента (у пользователя — по правому). */
.message-wrapper.assistant .message-files {
    align-items: flex-start;
}

/* Сгенерированный моделью файл — акцентная карточка-«скачать». */
.message-file-generated {
    border-color: var(--accent);
    cursor: pointer;
}

.message-file-generated svg {
    color: var(--accent);
}

.message-file-generated:hover {
    background: var(--bg-secondary);
}

/* Лайтбокс — просмотр картинки на весь экран */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.85);
}

.lightbox.open {
    display: flex;
}

.lightbox img {
    max-width: 95vw;
    max-height: 95vh;
    object-fit: contain;
    border-radius: 8px;
    cursor: default;
}

/* Коллаж при нескольких картинках (как в мессенджерах / ChatGPT) */
.message-images:has(.message-image:nth-child(2)) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    width: 320px;
    max-width: 100%;
}

.message-images:has(.message-image:nth-child(2)) .message-image {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    max-width: none;
    max-height: none;
}

/* Нечётная последняя (1 из 1 уже обработана выше, 3 из 3) — на всю ширину */
.message-images:has(.message-image:nth-child(2)) .message-image:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    aspect-ratio: 16 / 9;
}

.composer-model {
    position: relative;
    font-size: 13px;
}

.composer-model-locked {
    display: flex;
    align-items: center;
    padding: 6px 10px;
    color: var(--text-muted);
    cursor: default;
}

.composer-model-trigger {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 0;
    padding: 6px 10px;
    color: var(--text);
    cursor: pointer;
    border-radius: 8px;
    font: inherit;
    font-size: 13px;
}

.composer-model-trigger:hover {
    background: var(--bg-elevated);
}

.composer-model-caret {
    color: var(--text-muted);
    font-size: 10px;
    transition: transform 0.15s;
}

.composer-model.open .composer-model-caret {
    transform: rotate(180deg);
}

.composer-model-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    z-index: 20;
    min-width: 300px;
    max-width: 340px;
    max-height: min(60vh, 420px);
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transform-origin: bottom left;
    animation: composer-model-in 0.15s ease-out;
}

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

.composer-model-option {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text);
    font: inherit;
    font-size: 13px;
}

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

.composer-model-option.active {
    background: var(--bg-elevated);
}

.composer-model-option.active .composer-model-option-name {
    font-weight: 600;
}

.composer-model-option-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.composer-model-option-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.composer-model-option-name {
    color: var(--text);
    font-weight: 500;
}

.composer-model-option-tagline {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.35;
    font-variant-numeric: tabular-nums;
}

.composer-model-option-check {
    flex-shrink: 0;
    width: 15px;
    height: 15px;
    margin-top: 2px;
    color: var(--text);
    opacity: 0;
}

.composer-model-option.active .composer-model-option-check {
    opacity: 1;
}

/* ===== "Мощность" модели — деления сигнала вместо цвета (1-3) ===== */
.model-power {
    display: inline-flex;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
    height: 12px;
    margin-top: 1px;
}

.model-power i {
    display: block;
    width: 3px;
    border-radius: 1px;
    background: var(--border);
}

.model-power i:nth-child(1) { height: 5px; }
.model-power i:nth-child(2) { height: 8px; }
.model-power i:nth-child(3) { height: 12px; }

.model-power[data-power="1"] i:nth-child(1),
.model-power[data-power="2"] i:nth-child(1),
.model-power[data-power="2"] i:nth-child(2),
.model-power[data-power="3"] i:nth-child(1),
.model-power[data-power="3"] i:nth-child(2),
.model-power[data-power="3"] i:nth-child(3) {
    background: var(--text);
}

.model-badge-new {
    display: inline-flex;
    align-items: center;
    padding: 1px 6px;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    flex-shrink: 0;
    line-height: 1.5;
}

@keyframes composer-model-in {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.composer-submit {
    padding: 8px 16px;
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 18px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    font-size: 14px;
}

.composer-submit:hover:not(:disabled) {
    opacity: 0.9;
}

.composer-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Примерная стоимость генерации — рядом с кнопкой "Сгенерировать". */
.image-cost-estimate {
    margin-left: auto;
    margin-right: 12px;
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ===== Индикатор "Модель печатает..." ===== */
#typing-indicator {
    color: var(--text-muted);
    font-style: italic;
    margin: 12px 0;
}

.loading-dot {
    display: inline-block;
    font-size: 0.55em;
    color: var(--text-muted);
    margin: 0 1px;
    animation: blink 1.4s infinite;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

/* ===== Auth-страницы (signup / login / profile) ===== */
.auth-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    box-sizing: border-box;
}

.auth-card {
    width: 100%;
    max-width: 480px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 40px 32px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    box-sizing: border-box;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 24px;
}

.auth-logo {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.auth-logo img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.auth-brand-name {
    font-size: 18px;
    font-weight: 600;
}

.auth-card h1 {
    font-size: 26px;
    text-align: center;
    margin: 0 0 8px;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 24px;
}

.auth-alert {
    background: rgba(239, 65, 70, 0.08);
    border: 1px solid rgba(239, 65, 70, 0.35);
    color: var(--danger);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    margin: 0 0 18px;
}

.auth-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin: 14px 0 6px;
}

.auth-card input[type=password],
.auth-card input[type=text] {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text);
    box-sizing: border-box;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.auth-card input[type=password]:focus,
.auth-card input[type=text]:focus {
    outline: none;
    border-color: var(--text);
    box-shadow: 0 0 0 3px var(--border);
}

.auth-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: 6px 2px 0;
}

.auth-field-error {
    font-size: 13px;
    color: var(--danger);
    margin: 6px 2px 0;
}

.auth-submit {
    width: 100%;
    margin-top: 22px;
    padding: 12px 22px;
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    transition: opacity 0.15s;
}

.auth-submit:hover {
    opacity: 0.85;
}

.auth-alt {
    text-align: center;
    font-size: 14px;
    margin: 20px 0 4px;
}

.auth-alt a {
    color: var(--text);
    font-weight: 600;
    text-underline-offset: 3px;
}

.auth-back {
    text-align: center;
    font-size: 13px;
    margin: 8px 0 0;
}

.auth-back a {
    color: var(--text-muted);
    text-decoration: none;
}

.auth-back a:hover {
    color: var(--text);
    text-decoration: underline;
}

/* ===== Welcome card (главная для гостя) ===== */
.welcome-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    box-sizing: border-box;
}

.welcome-card {
    width: 100%;
    max-width: 480px;
    text-align: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 48px 32px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    box-sizing: border-box;
}

.welcome-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
}

.welcome-logo {
    display: block;
    width: 48px;
    height: 48px;
}

.welcome-card h1 {
    font-size: 32px;
    margin: 0 0 12px;
}

.welcome-brand h1 {
    margin: 0;
}

.welcome-card .welcome-tagline {
    color: var(--text-muted);
    margin: 0 0 28px;
    line-height: 1.5;
}

.welcome-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

.welcome-btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 999px;
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: opacity 0.15s, background 0.15s;
}

.welcome-btn.primary {
    background: var(--accent);
    color: var(--accent-text);
}

.welcome-btn.primary:hover {
    opacity: 0.85;
}

.welcome-btn.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.welcome-btn.secondary:hover {
    background: var(--bg-elevated);
}

.key-info {
    background: var(--bg-elevated);
    padding: 12px;
    border-radius: 6px;
    font-family: monospace;
}

/* ===== Toast-уведомления (Django messages) ===== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 240px;
    max-width: 360px;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    font-size: 14px;
    animation: toast-in 0.2s ease-out;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.fading {
    opacity: 0;
    transform: translateY(-8px);
}

.toast-success {
    background: #d1e7dd;
    border: 1px solid #a3cfbb;
    color: #0a3622;
}

.toast-error {
    background: #f8d7da;
    border: 1px solid #f1aeb5;
    color: #58151c;
}

.toast-warning {
    background: #fff3cd;
    border: 1px solid #ffe69c;
    color: #856404;
}

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

/* ===== Top контейнер (баннер + chat-header) — вне scroll-области ===== */
.main-top {
    background: var(--bg);
    padding: 0 16px;
}

.no-key-banner {
    max-width: 600px;
    margin: 12px auto;
    padding: 10px 14px;
    background: #fff3cd;
    border: 1px solid #ffe69c;
    border-radius: 8px;
    color: #856404;
    text-align: center;
    font-size: 14px;
}

.no-key-banner a {
    color: #856404;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

/* ===== Chat header (название + токены) — sticky-friendly ===== */
.chat-header {
    position: relative;
    max-width: 920px;
    margin: 0 auto;
    padding: 12px 0 8px;
    border-bottom: 1px solid var(--border);
}

.chat-title-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.chat-crumb-project {
    flex: none;
    max-width: 45%;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-crumb-project:hover {
    color: var(--text);
    text-decoration: underline;
}

.chat-crumb-sep {
    flex: none;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-muted);
}

.chat-header h2 {
    min-width: 0;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header .chat-totals {
    margin: 4px 0 0;
}

/* ===== Modal (профиль ChatGPT-style) ===== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-card {
    position: relative;
    background: var(--bg);
    border-radius: 12px;
    padding: 24px 28px;
    max-width: 480px;
    width: calc(100% - 32px);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 12px;
    background: none;
    border: 0;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 6px;
}

.modal-close:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.modal-card h2 {
    margin: 0 0 12px;
    font-size: 20px;
}

.modal-card h3 {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 20px 0 6px;
    letter-spacing: 0.5px;
}

.modal-label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.modal-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0 8px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.modal-checkbox input {
    accent-color: var(--accent);
    cursor: pointer;
}

.modal-input {
    width: 100%;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 14px;
    background: var(--bg-elevated);
    color: var(--text);
}

.modal-input option {
    background: var(--bg-elevated);
    color: var(--text);
}

/* ===== Fancy select (общий анимированный dropdown — тема, дефолтная модель) ===== */
.fancy-select {
    position: relative;
}

.fancy-select-trigger {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.fancy-select-trigger:hover {
    border-color: var(--text-muted);
}

.fancy-select-caret {
    color: var(--text-muted);
    transition: transform 0.15s;
}

.fancy-select.open .fancy-select-caret {
    transform: rotate(180deg);
}

.fancy-select-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transform-origin: top center;
    animation: fancy-select-in 0.15s ease-out;
}

.fancy-select-dropdown[hidden] {
    display: none;
}

.fancy-select-option {
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.fancy-select-option:hover {
    background: var(--bg-elevated);
}

.fancy-select-option.active {
    background: var(--bg-elevated);
    font-weight: 500;
}

@keyframes fancy-select-in {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg);
}

.modal-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.modal-save {
    padding: 8px 18px;
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 18px;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}

.modal-save:hover {
    opacity: 0.9;
}

.modal-delete {
    margin-top: 14px;
    padding: 6px 12px;
    background: none;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}

.modal-delete:hover {
    background: var(--danger);
    color: #fff;
}

/* ===== Confirm modal (единое окно подтверждения удаления) ===== */
/* Поверх настроек (z-index 1000), т.к. удаление ключа/аккаунта зовётся из них. */
#confirm-modal {
    z-index: 1100;
}

.confirm-card {
    max-width: 400px;
    animation: confirm-pop 0.18s ease-out;
}

@keyframes confirm-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.confirm-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

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

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

.confirm-cancel {
    padding: 8px 16px;
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.confirm-cancel:hover {
    background: var(--border);
}

.confirm-ok {
    padding: 8px 18px;
    background: var(--danger);
    color: #fff;
    border: 0;
    border-radius: 18px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.confirm-ok:hover {
    opacity: 0.9;
}

/* Кнопка создания/сохранения проекта — чёрная (в тёмной теме инвертируется). */
.name-ok {
    background: var(--text);
    color: var(--bg);
}

/* ===== Settings modal (расширенный layout с sidebar) ===== */
.modal-card--settings {
    max-width: 760px;
    width: calc(100% - 32px);
    height: 520px;
    max-height: calc(100vh - 64px);
    padding: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.settings-header h2 {
    margin: 0;
    font-size: 16px;
}

.modal-card--settings .modal-close {
    position: static;
    font-size: 22px;
}

.settings-body {
    display: flex;
    flex: 1;
    min-height: 0;
}

.settings-sidebar {
    width: 200px;
    flex-shrink: 0;
    padding: 12px;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.settings-nav-item {
    text-align: left;
    background: none;
    border: 0;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.settings-nav-item:hover {
    background: var(--bg-elevated);
}

.settings-nav-item.active {
    background: var(--bg-elevated);
    font-weight: 500;
}

.settings-content {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    min-width: 0;
}

/* Заголовок = начало секции: разделитель сверху отбивает блоки друг от друга
   (только прямые дети панели — h3 внутри форм не трогаем). */
.settings-panel > h3 {
    margin-top: 28px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.settings-panel h3:first-child,
.settings-panel > h3:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

/* ===== Выбор моделей в настройках: сетка карточек-переключателей ===== */
.model-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin: 12px 0 4px;
}

.model-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 30px 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elevated);
    cursor: pointer;
    transition: border-color 0.15s ease, opacity 0.15s ease;
}

.model-card:hover {
    border-color: var(--text-muted);
}

.model-card:has(.model-card-checkbox:checked) {
    border-color: var(--accent);
}

.model-card:not(:has(.model-card-checkbox:checked)) {
    opacity: 0.6;
}

.model-card-checkbox {
    position: absolute;
    top: 14px;
    right: 12px;
    accent-color: var(--accent);
    cursor: pointer;
}

.model-card-top {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.model-card-name {
    font-weight: 500;
    color: var(--text);
    font-size: 14px;
}

.model-card-tagline {
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.4;
}

.model-card-price {
    font-size: 12px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.fancy-select-option--model {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Кнопка «Настроить список доступных моделей» — открывает мини-модалку с сеткой карточек. */
.models-manage-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}

.models-manage-btn:hover {
    border-color: var(--text-muted);
}

/* Мини-модалка со списком моделей открывается поверх модалки настроек. */
.models-modal {
    z-index: 1100;
}

.models-modal .modal-card {
    max-width: 560px;
}

.models-modal-header {
    position: sticky;
    top: -24px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -24px -28px 12px;
    padding: 24px 28px 8px;
    background: var(--bg);
}

.models-modal-header h2 {
    margin: 0;
}

.models-modal-header .modal-close {
    position: static;
}

@media (max-width: 640px) {
    .model-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Usage (вкладка "Расход") ===== */
.usage-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 8px;
}

.usage-tokens {
    display: flex;
    gap: 12px;
}

.usage-tokens .usage-card {
    flex: 1;
    min-width: 0;
}

.usage-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.usage-card-label {
    font-size: 12px;
    color: var(--text-muted);
}

.usage-card-value {
    font-size: 18px;
    font-weight: 600;
}

.usage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 8px;
}

.usage-table th,
.usage-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.usage-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.usage-table td:not(:first-child),
.usage-table th:not(:first-child) {
    text-align: right;
}

@media (max-width: 640px) {
    .modal-card--settings {
        height: calc(100vh - 32px);
    }

    .settings-body {
        flex-direction: column;
    }

    .settings-sidebar {
        width: auto;
        flex-direction: row;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .settings-nav-item {
        flex-shrink: 0;
    }
}

/* Пункт сайдбара: Генерация */
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 12px 4px;
    padding: 6px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    /* Сброс дефолтов <button> (кнопка «Новый проект» использует этот же класс). */
    box-sizing: border-box;
    width: calc(100% - 24px);
    border: 0;
    background: none;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}

.sidebar-nav-item:hover {
    background: var(--bg-elevated);
}

.sidebar-nav-item.active,
.sidebar-new-chat.active {
    background: color-mix(in srgb, var(--text) 4%, var(--bg-elevated));
    font-weight: 500;
}

.sidebar-nav-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: var(--text-muted);
}

.sidebar-nav-item:hover .sidebar-nav-icon,
.sidebar-nav-item.active .sidebar-nav-icon {
    color: var(--text);
}

/* Страница генерации картинок — повторяет логику чата:
   галерея растёт сверху, композер прижат вниз (margin-top:auto + sticky);
   пустое состояние (--centered) ставит композер по центру. */
.image-page {
    max-width: 920px;
    margin: 0 auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

.image-page--centered {
    justify-content: center;
}

/* Композер генерации использует классы чатового композера
   (.chat-composer / .composer-*), поэтому базовый вид наследуется.
   Здесь — только специфика страницы генерации. */

/* Вариант 4: «док» — прилипшая обёртка композера со сплошной подложкой фона.
   Композер и подписи карточек используют один цвет (--bg-elevated) и сливались,
   а у композера скруглённые углы и зазор снизу — сквозь них просвечивали карточки.
   Док заливает фон страницы (--bg) за композером (углы, нижний зазор) и прячет
   уезжающие карточки, а сверху — градиент-затухание для плавного перехода. */
.image-composer-dock {
    margin-top: auto;          /* прижать композер к низу колонки */
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding-bottom: 12px;      /* зазор под композером, как был у sticky bottom:12px */
}

/* Внутри дока за позицию отвечает сам док — композер делаем обычным блоком. */
.image-composer-dock .image-composer {
    margin: 0;
    position: static;
    bottom: auto;
}

/* Градиентная полоса над доком: карточки растворяются в подложке перед композером. */
.image-composer-dock::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    height: 36px;
    background: linear-gradient(to bottom, transparent, var(--bg));
    pointer-events: none;
}

/* Центрированный экран "Что нарисуем?": галереи нет — док не липнет и без затухания. */
.image-page--centered .image-composer-dock {
    margin-top: 0;
    position: static;
    bottom: auto;
    padding-bottom: 0;
}

.image-page--centered .image-composer-dock::before {
    display: none;
}

/* Размер/качество — компактные транспарентные селекторы, как выбор модели в чате. */
.image-fancy-select {
    font-size: 13px;
}

.image-fancy-select .fancy-select-trigger {
    width: auto;
    padding: 6px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 13px;
}

.image-fancy-select .fancy-select-trigger:hover {
    background: var(--bg-elevated);
}

/* Композер прижат вниз — выпадашку раскрываем вверх,
   иначе она уходит за нижний край экрана. */
.image-fancy-select .fancy-select-dropdown {
    top: auto;
    bottom: calc(100% + 6px);
    left: 0;
    right: auto;
    min-width: 200px;
    transform-origin: bottom center;
    animation-name: fancy-select-in-up;
}

@keyframes fancy-select-in-up {
    from {
        opacity: 0;
        transform: translateY(6px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ===== Стили генерации: карточка-превью (общая для ленты и панели в чате) ===== */
.style-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 5px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: none;
    font: inherit;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.style-card:hover {
    background: var(--bg-elevated);
}

.style-card.active {
    border-color: var(--accent);
    color: var(--text);
}

.style-card-preview {
    display: block;
    width: 56px;
    margin: 0 auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 8px;
    background: var(--bg-elevated);
}

.style-card-label {
    max-width: 82px;
    font-size: 10.5px;
    line-height: 1.2;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Лента стилей в композере библиотеки — всегда на виду, скроллится по X. */
.style-strip {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 2px 2px 8px;
}

/* ===== Кнопка «Сгенерировать изображение» в чате: панель стилей + чип режима ===== */
.imagegen {
    position: relative;
}

.imagegen .composer-attach.active {
    color: var(--accent);
}

.imagegen-panel {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    z-index: 30;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
    transform-origin: bottom left;
    animation: fancy-select-in-up 0.15s ease-out;
}

.imagegen-panel[hidden] {
    display: none;
}

.imagegen-title {
    margin: 0 0 8px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.imagegen-cards {
    display: grid;
    grid-template-columns: repeat(3, 88px);
    gap: 6px;
}

.imagegen-cards .style-card-preview {
    width: 100%;
}

.imagegen-cards .style-card-label {
    max-width: none;
}

/* Чип активного режима — над полем ввода, снимается крестиком или уходит
   вместе с отправленным сообщением. */
.imagegen-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
    padding: 5px 6px 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
    border-radius: 999px;
}

.imagegen-chip[hidden] {
    display: none;
}

.imagegen-chip svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.imagegen-chip-remove {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--accent);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.imagegen-chip-remove:hover {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
}

/* ===== Библиотека: шапка страницы (заголовок + суммарные траты) ===== */
.lib-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0 4px;
}

.lib-title {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.lib-total {
    font-size: 13px;
    color: var(--text-muted);
}

.lib-total strong {
    color: var(--text);
    font-weight: 600;
}

/* ===== Сетка-плитка: чистые картинки, мета появляется на hover ===== */
.lib-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 12px;
    padding: 12px 0 24px;
}

.lib-tile {
    position: relative;
    margin: 0;
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-elevated);
    aspect-ratio: 1 / 1;
}

/* Появление новой плитки (лоадер и готовая картинка) */
.lib-tile--in,
.lib-tile:not(.lib-tile--loading) {
    animation: lib-tile-in 0.4s ease-out;
}

@keyframes lib-tile-in {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.lib-tile-open {
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
}

.lib-tile-open img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.lib-tile:hover .lib-tile-open img {
    transform: scale(1.045);
}

/* Градиент с промптом снизу плитки — только на hover */
.lib-tile-overlay {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 28px 12px 10px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.lib-tile:hover .lib-tile-overlay {
    opacity: 1;
}

.lib-tile-prompt {
    margin: 0;
    font-size: 12px;
    line-height: 1.35;
    color: #fff;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Бейдж «сгенерировано в чате» */
.lib-tile-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
}

.lib-tile-badge svg {
    width: 13px;
    height: 13px;
}

/* Быстрые действия (скачать/удалить) — сверху справа, на hover */
.lib-tile-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.lib-tile:hover .lib-tile-actions {
    opacity: 1;
    transform: none;
}

.lib-tile-actions form {
    margin: 0;
}

.lib-tile-action {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    transition: background 0.15s ease;
}

.lib-tile-action svg {
    width: 15px;
    height: 15px;
}

.lib-tile-action:hover {
    background: rgba(0, 0, 0, 0.78);
}

.lib-tile-action-danger:hover {
    background: var(--danger);
}

/* Скелетон-плейсхолдер во время генерации:
   мерцающий градиент (shimmer) + поднимающиеся частицы + пульсирующая искра. */
.lib-tile-skeleton {
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        110deg,
        var(--bg-elevated) 30%,
        color-mix(in srgb, var(--accent) 22%, var(--bg-elevated)) 50%,
        var(--bg-elevated) 70%
    );
    background-size: 200% 100%;
    animation: image-shimmer 1.6s ease-in-out infinite;
}

/* Центральная искра — мягко пульсирует и покачивается */
.image-loader-spark {
    width: 40px;
    height: 40px;
    color: var(--accent);
    filter: drop-shadow(0 0 8px color-mix(in srgb, var(--accent) 60%, transparent));
    animation: image-spark 1.8s ease-in-out infinite;
    z-index: 2;
}

@keyframes image-shimmer {
    0% { background-position: 150% 0; }
    100% { background-position: -50% 0; }
}

@keyframes image-spark {
    0%, 100% { transform: scale(0.85) rotate(-6deg); opacity: 0.65; }
    50% { transform: scale(1.12) rotate(6deg); opacity: 1; }
}

/* Текст «Генерирую…» с бегущим по буквам бликом + мигающие точки */
.image-loader-text {
    position: relative;
    z-index: 2;
    margin: 0;
    display: inline-flex;
    align-items: flex-end;
    font-size: 14px;
    font-weight: 500;
    background: linear-gradient(
        90deg,
        var(--text-muted) 0%,
        var(--text-muted) 35%,
        var(--text) 50%,
        var(--text-muted) 65%,
        var(--text-muted) 100%
    );
    background-size: 220% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: image-text-shimmer 1.8s linear infinite;
}

@keyframes image-text-shimmer {
    0% { background-position: 120% 0; }
    100% { background-position: -120% 0; }
}

.image-loader-dots span {
    animation: image-dot-blink 1.4s infinite;
}

.image-loader-dots span:nth-child(2) { animation-delay: 0.2s; }
.image-loader-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes image-dot-blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

/* Частицы — всплывают снизу вверх, растворяясь */
.image-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

.image-particle {
    position: absolute;
    bottom: -8px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
    animation: image-particle-rise 2.8s ease-in infinite;
}

@keyframes image-particle-rise {
    0% { transform: translateY(0) scale(0.4); opacity: 0; }
    15% { opacity: 0.9; }
    70% { opacity: 0.7; }
    100% { transform: translateY(-140px) scale(1); opacity: 0; }
}

.image-particle:nth-child(1)  { left: 8%;  animation-delay: 0s;    animation-duration: 2.6s; }
.image-particle:nth-child(2)  { left: 18%; animation-delay: 0.9s;  animation-duration: 3.1s; }
.image-particle:nth-child(3)  { left: 27%; animation-delay: 1.6s;  animation-duration: 2.4s; }
.image-particle:nth-child(4)  { left: 36%; animation-delay: 0.4s;  animation-duration: 2.9s; }
.image-particle:nth-child(5)  { left: 45%; animation-delay: 2.0s;  animation-duration: 3.3s; }
.image-particle:nth-child(6)  { left: 54%; animation-delay: 1.1s;  animation-duration: 2.5s; }
.image-particle:nth-child(7)  { left: 63%; animation-delay: 0.2s;  animation-duration: 3.0s; }
.image-particle:nth-child(8)  { left: 72%; animation-delay: 1.8s;  animation-duration: 2.7s; }
.image-particle:nth-child(9)  { left: 81%; animation-delay: 0.7s;  animation-duration: 3.2s; }
.image-particle:nth-child(10) { left: 90%; animation-delay: 1.4s;  animation-duration: 2.6s; }
.image-particle:nth-child(11) { left: 32%; animation-delay: 2.3s;  animation-duration: 2.8s; }
.image-particle:nth-child(12) { left: 68%; animation-delay: 2.5s;  animation-duration: 3.0s; }
.image-particle:nth-child(13) { left: 13%; animation-delay: 1.3s;  animation-duration: 2.7s; }
.image-particle:nth-child(14) { left: 23%; animation-delay: 0.5s;  animation-duration: 3.2s; }
.image-particle:nth-child(15) { left: 41%; animation-delay: 2.1s;  animation-duration: 2.5s; }
.image-particle:nth-child(16) { left: 50%; animation-delay: 0.8s;  animation-duration: 3.1s; }
.image-particle:nth-child(17) { left: 59%; animation-delay: 1.9s;  animation-duration: 2.6s; }
.image-particle:nth-child(18) { left: 77%; animation-delay: 0.3s;  animation-duration: 3.0s; }
.image-particle:nth-child(19) { left: 86%; animation-delay: 1.5s;  animation-duration: 2.4s; }
.image-particle:nth-child(20) { left: 95%; animation-delay: 2.2s;  animation-duration: 2.9s; }
.image-particle:nth-child(21) { left: 4%;  animation-delay: 0.6s;  animation-duration: 3.3s; }
.image-particle:nth-child(22) { left: 48%; animation-delay: 2.7s;  animation-duration: 2.6s; }
.image-particle:nth-child(23) { left: 64%; animation-delay: 1.0s;  animation-duration: 3.1s; }
.image-particle:nth-child(24) { left: 88%; animation-delay: 2.4s;  animation-duration: 2.8s; }

/* Уважение к настройке reduce-motion: оставляем только мягкий shimmer */
@media (prefers-reduced-motion: reduce) {
    .image-particle,
    .image-loader-spark,
    .image-loader-text,
    .image-loader-dots span {
        animation: none;
    }
    .image-loader-spark {
        opacity: 0.8;
    }
    .image-loader-text {
        -webkit-background-clip: border-box;
        background-clip: border-box;
        background: none;
        color: var(--text-muted);
    }
}

/* ===== Просмотрщик изображений: fullscreen, картинка + панель справа =====
   Иммерсивный режим (как у ChatGPT/фото-приложений): тёмный размытый фон,
   крупная картинка по центру, вся мета и действия — в панели. */

/* У элементов с display:flex/grid атрибут hidden сам по себе не работает
   (наш display перебивает браузерный [hidden]) — возвращаем ему силу. */
.lib-head[hidden],
.lib-grid[hidden],
.viewer-nav[hidden],
.viewer-chat-link[hidden],
.viewer-inputs[hidden] {
    display: none;
}

.viewer {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
}

.viewer.open {
    display: flex;
}

.viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 9, 12, 0.92);
    backdrop-filter: blur(8px);
}

.viewer-stage {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.viewer-canvas {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 72px;
    box-sizing: border-box;
}

.viewer-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    transition: opacity 0.25s ease;
}

.viewer-img--loading,
.viewer-img--busy {
    opacity: 0.35;
}

.viewer-loader {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    pointer-events: none;
}

.viewer-loader[hidden] {
    display: none;
}

/* Точки выносим из потока, чтобы по центру стояло само слово «Генерирую»
   ровно под искрой, а не блок «слово + точки» (точки сдвигали центр вправо) */
.viewer-loader .image-loader-text {
    position: relative;
    color: #fff;
}

.viewer-loader .image-loader-dots {
    position: absolute;
    left: 100%;
}

/* Кнопки на тёмной сцене: закрыть (слева сверху) и стрелки листания */
.viewer-close,
.viewer-nav {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    transition: background 0.15s ease;
}

.viewer-close:hover,
.viewer-nav:hover {
    background: rgba(255, 255, 255, 0.2);
}

.viewer-close {
    top: 14px;
    left: 14px;
    width: 38px;
    height: 38px;
}

.viewer-close svg {
    width: 18px;
    height: 18px;
}

.viewer-nav {
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
}

.viewer-nav svg {
    width: 20px;
    height: 20px;
}

.viewer-nav-prev {
    left: 16px;
}

.viewer-nav-next {
    right: 16px;
}

/* Панель с метой: промпт, чипы, действия, правка, версии */
.viewer-side {
    position: relative;
    z-index: 1;
    width: 340px;
    flex-shrink: 0;
    background: var(--bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.viewer-side-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.viewer-label-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.viewer-label {
    margin: 0 0 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.viewer-copy {
    margin: -6px -6px 0 0;
    padding: 6px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}

.viewer-copy svg {
    width: 14px;
    height: 14px;
    display: block;
}

.viewer-copy:hover {
    background: var(--bg-elevated);
    color: var(--text);
}

.viewer-copy.copied {
    color: var(--accent);
}

.viewer-prompt {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    max-height: 132px;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

.viewer-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.viewer-chip {
    padding: 3px 9px;
    font-size: 11px;
    border-radius: 999px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.viewer-chat-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 10px;
    padding: 5px 10px;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.viewer-chat-link svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.viewer-chat-link span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.viewer-chat-link:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

/* Референсы, приложенные к активной версии */
.viewer-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.viewer-input-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}

.viewer-input-thumb:hover {
    transform: scale(1.05);
    border-color: var(--accent);
}

.viewer-input-file {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px 10px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
}

.viewer-input-file:hover {
    border-color: var(--accent);
}

/* Действия: «Скачать» (главное) + удалить (вторичное) */
.viewer-actions {
    display: flex;
    gap: 8px;
}

.viewer-download {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.viewer-download svg {
    width: 16px;
    height: 16px;
}

.viewer-download:hover {
    opacity: 0.9;
}

.viewer-delete {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.viewer-delete svg {
    width: 16px;
    height: 16px;
}

.viewer-delete:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* Форма правки внутри панели */
.viewer-edit-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-elevated);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    margin-bottom: 8px;
}

.viewer-edit-input:focus {
    outline: none;
    border-color: var(--text);
}

/* Строка действий формы правки: скрепка слева, кнопка «Изменить» тянется. */
.viewer-edit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-edit-submit {
    flex: 1;
    padding: 8px 16px;
    background: var(--accent);
    color: var(--accent-text);
    border: 0;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.viewer-edit-submit:hover:not(:disabled) {
    opacity: 0.9;
}

.viewer-edit-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Превью вложений в узкой панели делаем компактнее, чем в композере. */
#image-edit-attachments .composer-attachment {
    width: 84px;
    height: 84px;
}

/* Подсветка панели, когда над просмотрщиком тащат файл (drag & drop в правку). */
.viewer--drop .viewer-side {
    outline: 2px dashed var(--accent);
    outline-offset: -6px;
}

/* Версии — горизонтальная лента миниатюр (визуально, а не текстом) */
.viewer-version-count {
    color: var(--text-muted);
    text-transform: none;
    letter-spacing: 0;
}

.viewer-versions {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 2px;
}

.viewer-version {
    position: relative;
    flex-shrink: 0;
}

.viewer-version-thumb {
    position: relative;
    display: block;
    width: 64px;
    height: 64px;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-elevated);
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.viewer-version-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.viewer-version:hover .viewer-version-thumb {
    border-color: var(--text-muted);
}

.viewer-version.active .viewer-version-thumb {
    border-color: var(--accent);
}

.viewer-version-num {
    position: absolute;
    bottom: 3px;
    left: 3px;
    padding: 1px 6px;
    font-size: 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    pointer-events: none;
}

.viewer-version-delete {
    position: absolute;
    top: 2px;
    right: 2px;
    z-index: 1;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(0, 0, 0, 0.55);
    border: 0;
    border-radius: 50%;
    color: #fff;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.viewer-version:hover .viewer-version-delete {
    opacity: 1;
}

.viewer-version-delete:hover {
    background: var(--danger);
}

.viewer-date {
    margin: 8px 0 0;
    font-size: 11px;
}

.input-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.input-lightbox.open {
    display: flex;
}

.input-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(3px);
}

.input-lightbox-img {
    position: relative;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.input-lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    z-index: 1;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.input-lightbox-close:hover {
    background: rgba(0, 0, 0, 0.75);
}

@media (max-width: 768px) {
    /* На телефоне просмотрщик раскладывается столбиком: картинка сверху,
       панель — нижним листом с собственным скроллом. */
    .viewer {
        flex-direction: column;
    }

    .viewer-stage {
        flex: 1;
        min-height: 0;
    }

    .viewer-canvas {
        padding: 60px 14px 14px;
    }

    .viewer-side {
        width: auto;
        max-height: 46vh;
        border-left: 0;
        border-top: 1px solid var(--border);
        border-radius: 16px 16px 0 0;
    }

    .viewer-side-scroll {
        padding: 16px;
        gap: 16px;
    }

    .viewer-nav {
        width: 36px;
        height: 36px;
    }

    .viewer-nav-prev {
        left: 8px;
    }

    .viewer-nav-next {
        right: 8px;
    }

    /* Композер: на телефоне прижимаем кнопку отправки вправо. */
    .composer-submit {
        margin-left: auto;
    }

    /* Оценку стоимости генерации выносим на отдельную строку над кнопками:
       её длинный текст («≈ $… за картинку») иначе распирает ряд. */
    .image-cost-estimate {
        order: -1;
        width: 100%;
        margin: 0;
        white-space: normal;
    }

    /* Композер генерации на телефоне: формат, качество и «Сгенерировать» — в одну строку.
       Селекторы тянутся и при нехватке места ужимаются с многоточием, кнопка не сжимается.
       Только для .image-composer — чатовый композер не трогаем. */
    .image-composer .composer-left {
        flex: 1;
        min-width: 0;
        flex-wrap: nowrap;
    }

    .image-composer .composer-submit {
        flex-shrink: 0;
    }

    .image-composer .image-fancy-select {
        flex: 1;
        min-width: 0;
    }

    .image-composer .image-fancy-select .fancy-select-trigger {
        width: 100%;
        min-width: 0;
    }

    .image-composer .image-fancy-select .fancy-select-current {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Панель стилей в чате на телефоне — лист во всю ширину над композером,
       иначе absolute-позиция от кнопки уводит её за край экрана. */
    .imagegen-panel {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: 96px;
    }

    .imagegen-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    /* На телефоне плитки поменьше, чтобы в ряд влезало 2-3 штуки.
       ВАЖНО: блок должен идти ПОСЛЕ базового .lib-grid, иначе при равной
       специфичности победит базовое правило (минимум 210px). */
    .lib-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
    }

    .lib-head {
        flex-direction: column;
        gap: 2px;
    }

    /* На телефоне 3 колонки агентов не помещаются — раскладываем в одну.
       Блок ПОСЛЕ базового .agents-grid (repeat(3,1fr)), иначе при равной
       специфичности победит базовое правило. */
    .agents-grid {
        grid-template-columns: 1fr;
    }

    /* Auth-карточка на телефоне — компактнее отступы, мельче заголовок. */
    .auth-card {
        padding: 32px 20px;
    }

    .auth-card h1 {
        font-size: 23px;
    }
}
