/* Inter - лежит у нас, не тянется с Google на каждой загрузке.
   Один переменный файл на начертание 100-900, подмножества латиницы и
   кириллицы. Обновлять - скриптом из истории этапа 2. */
/* cyrillic-ext */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/static/fonts/inter-cyrillic-ext.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* cyrillic */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/static/fonts/inter-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* latin-ext */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/static/fonts/inter-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/static/fonts/inter-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Fira Sans - основной шрифт интерфейса, лежит локально в
   static/fonts/fira-sans/. Веса 400/500/600/700, подмножества латиницы
   и кириллицы. Файлы - статические WOFF2 из Google Fonts (v18, дизайн
   Mozilla Foundation / Telefonica, лицензия OFL 1.1 рядом: OFL.txt).
   Inter выше оставлен нетронутым. Внешних font URL нет. */
/* Fira Sans 400 cyrillic-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-400-cyrillic-ext.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* Fira Sans 400 cyrillic */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-400-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* Fira Sans 400 latin-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-400-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Fira Sans 400 latin */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Fira Sans 500 cyrillic-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-500-cyrillic-ext.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* Fira Sans 500 cyrillic */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-500-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* Fira Sans 500 latin-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-500-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Fira Sans 500 latin */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-500-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Fira Sans 600 cyrillic-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-600-cyrillic-ext.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* Fira Sans 600 cyrillic */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-600-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* Fira Sans 600 latin-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-600-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Fira Sans 600 latin */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-600-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Fira Sans 700 cyrillic-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-700-cyrillic-ext.woff2) format('woff2');
  unicode-range: U+0460-052F, U+1C80-1C8A, U+20B4, U+2DE0-2DFF, U+A640-A69F, U+FE2E-FE2F;
}
/* Fira Sans 700 cyrillic */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-700-cyrillic.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
/* Fira Sans 700 latin-ext */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-700-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Fira Sans 700 latin */
@font-face {
  font-family: 'Fira Sans';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/static/fonts/fira-sans/fira-sans-700-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Палитра. Тёмная тема — база (значения по умолчанию в :root),
   светлая включается атрибутом data-theme="light" на <html>.
   Атрибут ставится ещё в <head> из localStorage, см. templates/index.html. */
:root {
    color-scheme: dark;

    --bg: #0f1115;
    --bg-2: #14161c;
    --surface: #1a1d24;
    --surface-2: #1d2028;
    --border: #23262f;
    --border-2: #2a2e37;

    --text: #e8e8e8;
    --text-2: #c7cad1;
    --text-muted: #8a8f98;
    --text-faint: #565b66;

    --accent: #5b8def;
    --accent-hover: #4a7be0;
    --accent-soft: #26304a;
    --accent-soft-2: #2f3b5c;
    --accent-soft-border: #3d4d78;

    --danger: #f28b82;
    --danger-2: #e05a5a;
    --danger-bg: #3a1f1f;
    --danger-bg-strong: #7a2b2b;
    --danger-bg-stronger: #8f3333;
    --danger-border: #6b2b2b;

    --success: #4ebf7a;
    --warning: #e5a50a;

    --shadow: rgba(0, 0, 0, 0.4);
    --star-opacity: 0.5;
}

:root[data-theme="light"] {
    color-scheme: light;

    /* Фон - очень светлая лаванда; поверхности кнопок на пару тонов
       насыщеннее фона, чтобы кнопка читалась без обводки. */
    --bg: #f3f1fb;
    --bg-2: #faf9fe;
    --surface: #eae6f8;
    --surface-2: #e1dbf4;
    --border: #ded8f1;
    --border-2: #cec6e9;

    --text: #14121d;
    --text-2: #3a3450;
    --text-muted: #6b6386;
    --text-faint: #9d95b6;

    --accent: #7c3aed;
    --accent-hover: #6d28d9;
    --accent-soft: #e8e0fc;
    --accent-soft-2: #dbcffa;
    --accent-soft-border: #c2adf3;

    --danger: #c0392b;
    --danger-2: #c0392b;
    --danger-bg: #fdecea;
    --danger-bg-strong: #d9534f;
    --danger-bg-stronger: #c9433f;
    --danger-border: #f1b8b3;

    --success: #1e8e4a;
    --warning: #a8760a;

    --shadow: rgba(40, 24, 84, 0.14);
    --star-opacity: 0;
}

/* Выбранное в светлой теме заливается ярким фиолетовым с белым текстом -
   в тёмной для этого хватает мягкой подложки. */
:root[data-theme="light"] .nav-item.active {
    background: var(--accent);
    color: #fff;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: "Fira Sans", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.65;
    background: var(--bg);
    color: var(--text);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-repeat: repeat;
    background-size: 220px 200px;
    background-image:
        radial-gradient(1px 1px at 18px 24px, rgba(255, 255, 255, 0.55), transparent 100%),
        radial-gradient(1px 1px at 64px 92px, rgba(255, 255, 255, 0.35), transparent 100%),
        radial-gradient(1.5px 1.5px at 112px 18px, rgba(255, 255, 255, 0.5), transparent 100%),
        radial-gradient(1px 1px at 150px 130px, rgba(255, 255, 255, 0.3), transparent 100%),
        radial-gradient(1px 1px at 190px 60px, rgba(255, 255, 255, 0.45), transparent 100%),
        radial-gradient(1.5px 1.5px at 40px 150px, rgba(255, 255, 255, 0.4), transparent 100%),
        radial-gradient(1px 1px at 100px 175px, rgba(255, 255, 255, 0.3), transparent 100%),
        radial-gradient(1px 1px at 205px 110px, rgba(255, 255, 255, 0.55), transparent 100%);
    opacity: var(--star-opacity);
}

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

/* Sidebar */

/* Панель - отдельный блок: своя подложка, рамка и скруглённые углы, отбитые
   от края и от рабочей области. */
.sidebar {
    width: 288px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 10px 0 10px 10px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 10px;
    overflow: hidden;
    transition: width 150ms ease, padding 150ms ease;
}

.sidebar-top {
    padding-bottom: 10px;
}

.brand {
    font-size: 18px;
    font-weight: 700;
    padding: 8px 10px 4px;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 6px;
    color: var(--text);
    text-decoration: none;
}

.sidebar .brand:hover .brand-name {
    color: var(--accent);
}

/* Развёрнутая шапка: логотип+название слева, кнопка сворачивания справа. */
.brand-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 4px 8px 6px;
}

.brand-row .brand {
    padding: 0;
}

/* Кнопка сворачивания видна только в развёрнутом состоянии (в свёрнутом
   вся шапка brand-row скрыта). */
.sidebar-collapse-btn {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-2);
    cursor: pointer;
}

.sidebar-collapse-btn:hover {
    background: var(--surface-2);
    border-color: var(--border-2);
}

.sidebar-collapse-icon {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.85;
}

/* Свёрнутая шапка: тот же круглый логотип, на hover/focus заменяется
   иконкой разворачивания. Обе фигуры лежат в одной клетке и сменяют друг
   друга прозрачностью — без JS-таймера, ничего не прыгает. */
.sidebar-expand-brand {
    position: relative;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: center;
    margin: 4px 8px 6px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-2);
    cursor: pointer;
}

.sidebar-expand-brand:hover {
    background: var(--surface-2);
    border-color: var(--border-2);
}

.sidebar-expand-brand .brand-logo,
.sidebar-expand-brand .sidebar-expand-icon {
    position: absolute;
    margin: auto;
    inset: 0;
    transition: opacity 120ms ease;
}

.sidebar-expand-brand .brand-logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
    opacity: 1;
}

.sidebar-expand-brand .sidebar-expand-icon {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0;
}

.sidebar-expand-brand:hover .brand-logo,
.sidebar-expand-brand:focus-visible .brand-logo {
    opacity: 0;
}

.sidebar-expand-brand:hover .sidebar-expand-icon,
.sidebar-expand-brand:focus-visible .sidebar-expand-icon {
    opacity: 1;
}

.brand-logo {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
}

.user-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 10px 14px;
    font-size: 12px;
    color: var(--text-muted);
}

.user-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--text-2);
}

.user-link {
    color: var(--accent);
    text-decoration: none;
}

.user-link:hover {
    text-decoration: underline;
}

.theme-toggle {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: 50%;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
}

.theme-toggle:hover {
    background: var(--surface-2);
    border-color: var(--accent);
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    background: transparent;
    border: none;
    border-radius: 10px;
    padding: 5px 12px;
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

/* Значки штриховые: цвет берут у текста пункта, поэтому на залитой активной
   плашке сами становятся белыми. */
.nav-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.85;
}

.nav-label {
    flex: 1;
}

button.nav-item:hover {
    background: var(--surface-2);
}

.nav-item.active {
    background: var(--accent-soft);
    font-weight: 600;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

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

.history-block {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}.history-group-title {
    padding: 4px 10px 1px;
    font-size: 12px;
    color: var(--text-muted);
}

.history-group-title:first-child {
    padding-top: 0;
}

.history-list {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
}.history-empty {
    font-size: 12px;
    color: var(--text-faint);
    padding: 4px 10px;
}

.history-item {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 2px;
    border-radius: 6px;
    padding: 1px 4px 1px 10px;
    color: var(--text);
}

.history-item:hover {
    background: var(--surface-2);
}

.history-item.active {
    background: var(--accent-soft);
}

.history-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    text-align: left;
    padding: 0;
    font: inherit;
}

.history-title {
    font-size: 13px;
    font-weight: 600;
    line-height: 1.05;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.history-meta {
    font-size: 11px;
    line-height: 1.1;
    color: var(--text-muted);
}

.history-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.history-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 4px 7px;
    border-radius: 6px;
}

.history-menu-btn:hover,
.history-menu-btn.active {
    background: var(--border);
    color: var(--text);
}

.history-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 150px;
    z-index: 10;
    box-shadow: 0 8px 24px var(--shadow);
}

.history-menu[hidden] {
    display: none;
}

.history-menu-item {
    background: transparent;
    border: none;
    color: var(--text);
    text-align: left;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.history-menu-item:hover {
    background: var(--border);
}

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

.history-menu-item.danger:hover {
    background: var(--danger-bg);
}

/* Chat panel */

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

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.chat-header-titles {
    min-width: 0;
}

.sidebar-toggle-btn {
    display: none;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    color: var(--text-2);
    font-size: 16px;
    cursor: pointer;
}

.sidebar-toggle-btn:hover {
    background: var(--surface-2);
}

.sidebar-backdrop {
    display: none;
}

.toolbar-logo {
    display: none;
}

/* Заголовок раздела на пустом экране совпадает краями с полем ввода. Две
   колонки держат название и пояснение рядом без двойного пустого отступа. */
.section-intro {
    position: absolute;
    left: 50%;
    top: calc(56% - 150px);
    transform: translate(-50%, -50%);
    /* У composer шириной 748px по 24px внутреннего отступа с каждой стороны:
       видимое поле и intro поэтому имеют одинаковую полезную ширину 700px. */
    width: min(700px, calc(100% - 48px));
    display: grid;
    grid-template-columns: minmax(0, 40fr) minmax(0, 60fr);
    align-items: center;
    pointer-events: none;
}

/* В изображениях поле и сетка шире текстовой колонки. Заголовок следует за
   шириной поля, а не за одним жёстким размером для всех разделов. */
.app.section-image .section-intro {
    width: min(852px, calc(100% - 48px));
}

.section-intro[hidden] {
    display: none;
}

.section-intro-title {
    margin: 0;
    padding-right: 12px;
    font-size: 32px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.01em;
}

.section-intro-title > span {
    display: block;
    white-space: nowrap;
}

.section-intro-lead {
    margin: 0;
    padding-left: 12px;
    border-left: 1px solid var(--border-2);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text-muted);
}

/* Подпись под полем ввода. */
.composer-note {
    margin: 0;
    padding: 0 24px 12px;
    text-align: center;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-faint);
}

.chat-title {
    font-size: 16px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.ghost-btn {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--border-2);
    color: var(--text-2);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
}

.ghost-btn:hover {
    background: var(--surface-2);
}

.chat-body {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* Колонка текста - не шире 700px (у .msg-row 720px это ширина за вычетом
   собственных отступов строки). Читать длинные строки во всю ширину экрана
   тяжело, поэтому лента держится середины, а не краёв. */
.messages {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 24px 24px 12px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message-context-menu {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 4px;
    min-width: 140px;
    z-index: 50;
    box-shadow: 0 8px 24px var(--shadow);
}

.message-context-menu[hidden] {
    display: none;
}

.message-context-menu .history-menu-item {
    width: 100%;
}

.msg-row {
    display: flex;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 4px 10px;
    border-radius: 12px;
    cursor: default;
}

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

.msg-row.from-bot {
    justify-content: flex-start;
}

.msg-row.selected {
    background: rgba(91, 141, 239, 0.16);
    outline: 1px solid rgba(91, 141, 239, 0.4);
}

.msg-content {
    display: block;
    width: fit-content;
    max-width: 78%;
}

/* Ответ модели читают, а не разглядывают: он занимает всю колонку. */
.from-bot .msg-content {
    width: 100%;
    max-width: 100%;
}

.bubble {
    padding: 11px 16px;
    border-radius: 16px;
    font-size: 16px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Вопрос - в спокойном сером пузыре: он короткий и служебный, кричать ему
   незачем. Ярким остаётся только то, на что нажимают. */
.from-user .bubble {
    background: var(--surface-2);
    color: var(--text);
    border-bottom-right-radius: 6px;
}

/* Ответ модели - свободный текст во всю колонку, без рамки и подложки.
   Его читают целыми абзацами, и рамка вокруг длинного текста только мешает. */
.from-bot .bubble {
    background: transparent;
    border: none;
    padding: 2px 0;
}

.bubble img {
    max-width: 100%;
    border-radius: 10px;
    display: block;
}

.bubble audio {
    max-width: 100%;
    display: block;
}

/* ---------------------------------------------------------------------------
   Кодовые блоки Markdown в ответах моделей: ```язык ... ``` разбирается в
   app.js (renderMessageText). Карточка = заголовок (язык + кнопка
   «Копировать») и pre>code с содержимым через textContent; внутри блока
   ничего не исполняется. Оформление - только тема-переменные, обе темы
   поддерживаются без отдельных правил.
--------------------------------------------------------------------------- */
.code-block {
    margin: 10px 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-2);
    overflow: hidden;
}

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

.code-block-lang {
    font-size: 12px;
    letter-spacing: 0.04em;
    color: var(--text-faint);
}

.code-block-copy {
    background: transparent;
    border: none;
    color: var(--text-faint);
    font-size: 13px;
    line-height: 1;
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 6px;
}

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

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

.code-block-pre {
    margin: 0;
    padding: 10px 12px;
    overflow-x: auto;
    white-space: pre;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-2);
}

.speech-panel {
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.speech-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.speech-result { margin-top: 10px; }
/* Настоящий программный код (code/pre) - только локальный системный
   monospace-стек, без загрузки веб-шрифтов. Сейчас таких элементов в
   разметке нет: сообщения, включая раздел «Кодинг», рендерятся обычным
   текстом через textContent в .bubble, markdown-парсера нет. Правило
   защитное - на случай появления code/pre в будущем. */
code, pre {
    font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", "Courier New", monospace;
}
/* Расшифровка аудио - обычный текст, pre сохраняет только переносы.
   Шрифт - шрифт интерфейса (Fira Sans через inherit от body), а не
   monospace: селектор с классом специфичнее правила выше и побеждает. */
.speech-result pre { white-space: pre-wrap; margin: 0 0 8px; font: inherit; font-family: inherit; }
.section-transcription .input-shell,
.section-transcription .composer-note { display: none; }

/* ---------------------------------------------------------------------------
   Раздел изображений. Картинки рассматривают, а не читают, поэтому результаты
   стоят сеткой по 2-3 в ряд, а не лентой сообщений. Карточки складываются в
   одну сетку, пока идут подряд: одна отправка - один ряд.
--------------------------------------------------------------------------- */
/* Сетке нужна ширина: колонка текста ей мала. Просьба человека и поле ввода
   держатся той же ширины, что и сетка, - иначе левые края разъедутся. */
.app.section-image .composer,
.app.section-image .msg-row {
    max-width: 900px;
}

.image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    align-items: start;
    gap: 16px;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
}

/* Карточка в сетке шириной со свою ячейку - ограничения колонки
   на неё не распространяются. */
.image-grid .image-card {
    max-width: none;
    margin: 0;
    padding: 0;
}

.image-card .msg-content {
    width: 100%;
    max-width: 100%;
}

.image-card .bubble {
    padding: 0;
}

/* Карточка в сетке может растянуться на всю ширину ряда (900px, см. выше) -
   без верхней границы 16:9 при такой ширине не помещался по высоте на
   экране. Ограничиваем реальные width/max-width/max-height (не transform:
   scale - он не подвинул бы соседей и оставил бы пустое место в разметке),
   картинка остаётся с исходными пропорциями и просто центрируется в ячейке.
   Скачивание и сохранённый файл берут src напрямую - их эти правила не
   касаются. */
.image-card .bubble img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(100%, 780px);
    max-height: 55vh;
    object-fit: contain;
    margin: 0 auto;
}

/* Компактные превью вложений и карточки результатов - только в разделе
   изображений. Каждое правило скоуплено классом рубрики на корне #app
   (section-{{ section }} в templates/index.html), поэтому общий композер
   и остальные рубрики не затрагиваются. */
.app.section-image .attach-thumb {
    width: 88px;
    height: 88px;
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    border-radius: 8px;
}

/* Кнопка удаления крупнее базовой: крупное превью даёт ей место.
   Позиционирование остаётся из базового правила. Это только геометрия -
   удобство и доступность проверим в браузере. */
.app.section-image .attach-thumb-remove {
    width: 28px;
    height: 28px;
    font-size: 12px;
}

/* Карточки держат коридор 320-380px, ряды переносятся сами (auto-fit:
   пустые треки схлопываются, одиночная картинка занимает один трек).
   Минимум min(100%, 320px) не даёт треку превысить рабочую область -
   например, при раскрытом сайдбаре: окно шире 768px, а колонка уже 320px.
   Одиночная картинка не растягивается на всю ширину: трек не шире 380px,
   а сам ряд центрируется. */
.app.section-image .image-grid {
    grid-template-columns: repeat(
        auto-fit,
        minmax(min(100%, 320px), 380px)
    );
    justify-content: center;
    gap: 12px;
}

/* Карточка - самостоятельная плитка: фон, граница и радиус из палитры темы,
   поэтому светлая и тёмная темы работают без отдельных правил. */
.app.section-image .image-grid .image-card {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
}

.app.section-image .image-grid .image-card:hover {
    border-color: var(--accent-soft-border);
}

/* Картинка целиком и без искажения пропорций: object-fit: contain только
   уменьшает, пределы высоты не двигают соседей. Скачивание и сохранённый
   файл берут src напрямую - эти правила их не касаются. */
.app.section-image .image-card .bubble img {
    max-width: 100%;
    max-height: min(55vh, 420px);
    object-fit: contain;
    border-radius: 8px;
}

/* Узкий экран: одна колонка шириной не больше min(100%, 380px) - карточка
   не выходит за доступную область; центрирование наследуется от основного
   image-правила (justify-content там не переопределяется). Картина
   по-прежнему целиком. */
@media (max-width: 768px) {
    .app.section-image .image-grid {
        grid-template-columns: minmax(0, min(100%, 380px));
        gap: 10px;
    }

    .app.section-image .image-card .bubble img {
        max-height: min(50vh, 340px);
    }
}

.media-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 6px;
}

.media-actions .copy-btn,
.media-actions .download-btn,
.media-actions .repeat-btn {
    margin-top: 0;
}

.copy-btn,
.download-btn,
.repeat-btn {
    display: block;
    margin-top: 4px;
    background: transparent;
    border: none;
    color: var(--text-faint);
    font-size: 13px;
    line-height: 1;
    padding: 2px 6px;
    cursor: pointer;
    border-radius: 6px;
    text-decoration: none;
    width: fit-content;
}

.copy-btn:hover,
.download-btn:hover,
.repeat-btn:hover {
    background: var(--surface-2);
    color: var(--text-2);
}

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

#statusBar {
    min-height: 20px;
    padding: 0 24px;
    font-size: 13px;
    color: var(--text-muted);
}

#statusBar.error {
    color: var(--danger);
}

/* Поле ввода встаёт ровно под колонку текста: 748px за вычетом отступов -
   те же 700px, что и у сообщений. */
.composer {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 748px;
    width: 100%;
    margin: 0 auto;
    padding: 16px 24px 20px;
}

.composer.centered {
    position: absolute;
    top: 56%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 0 24px;
}

/* Скрепка живёт внутри поля ввода, слева от остальных кнопок: margin-right
   разводит её и правую группу (модель, микрофон, отправка) по краям. */
.attach-btn {
    flex-shrink: 0;
    margin-right: auto;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Модели, которые не принимают картинку на вход, прячут скрепку через
   свойство hidden - без этого правила display:flex его перебивал, и кнопка
   оставалась на экране. */
.attach-btn[hidden] {
    display: none;
}

.attach-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}

.attach-icon {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.composer-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* Общая строка панели параметров изображений и подрубрики чата. Каждый блок
   сам управляет видимостью в зависимости от активного раздела. */
.image-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 2px 2px 4px;
}

.image-controls[hidden] {
    display: none;
}

.image-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 0;
}

.image-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.image-options .opt-short {
    display: none;
}

.image-options select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-2);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.image-options select:focus {
    outline: none;
    border-color: var(--accent);
}

/* Превью вложений живёт внутри .input-shell, над textarea - в границах той
   же рамки, что и остальное поле, а не отдельной полосой над ним. */
.attach-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px 0;
}

.attach-warning {
    margin: 8px 14px 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--danger);
}

.attach-preview-list[hidden],
.attach-warning[hidden],
.image-options[hidden],
.chat-filter-tabs[hidden] {
    display: none;
}

/* Подрубрика раздела «Чат»: «Все» / «Здоровье». На десктопе прижата вправо,
   на мобильном переносится по правилам общего ряда .image-controls. */
.chat-filter-tabs {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    padding: 0;
    margin-left: auto;
}

.chat-filter-tab {
    flex: 0 0 auto;
    padding: 5px 12px;
    border-radius: 999px;
    border: 1px solid var(--border-2);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
}

.chat-filter-tab:hover {
    background: var(--surface-2);
    color: var(--text);
}

.chat-filter-tab.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.attach-thumb {
    position: relative;
    width: 68px;
    height: 68px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-2);
    background: var(--surface-2);
    flex-shrink: 0;
}

.attach-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.attach-thumb-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(15, 17, 21, 0.85);
    border: none;
    color: #fff;
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.attach-thumb-remove:hover {
    background: var(--danger);
    color: var(--surface);
}

.input-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: 10px;
}

.input-shell:focus-within {
    border-color: var(--accent);
}

.input-shell textarea {
    width: 100%;
    resize: none;
    min-height: 64px;
    max-height: 380px;
    overflow-y: auto;
    background: transparent;
    color: var(--text);
    border: none;
    padding: 12px 14px 6px;
    /* 16px, как и текст сообщений. Заодно iOS не увеличивает страницу при
       попадании в поле - он делает это, только если шрифт мельче 16px. */
    font-size: 16px;
    font-family: inherit;
}

.input-shell textarea:focus {
    outline: none;
}

.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 4px 10px 10px;
}

/* Выбор модели. Это не <select>, а свой дропдаун: нативный список
   не умеет показывать описание второй строкой под названием модели. */
.model-select {
    position: relative;
    flex-shrink: 0;
}

.model-select-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 220px;
    height: 40px;
    background: var(--bg-2);
    color: var(--text);
    border: 1px solid var(--border-2);
    border-radius: 10px;
    padding: 0 8px;
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
}

.model-select-btn:hover,
.model-select-btn:focus,
.model-select.open .model-select-btn {
    outline: none;
    border-color: var(--accent);
}

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

.model-select-caret {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 10px;
}

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

.model-select-menu {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    z-index: 30;
    width: 300px;
    max-width: min(300px, calc(100vw - 32px));
    max-height: 320px;
    overflow-y: auto;
    background: var(--bg-2);
    border: 1px solid var(--border-2);
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 8px 24px var(--shadow);
}

.model-option {
    width: 100%;
    display: block;
    text-align: left;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
}

.model-option:hover {
    background: var(--surface-2);
}

.model-option.selected {
    background: var(--accent-soft);
}

.model-option-name {
    display: inline;
    font-size: 13px;
    font-weight: 600;
}

/* Явная отметка платной модели рядом с бесплатными в одном списке (например,
   Gemini 3 Flash Preview в чате), чтобы её не выбрали по ошибке вместо
   бесплатной. */
.model-option-paid {
    display: inline-block;
    margin-left: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--danger);
}

.mic-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-btn:hover {
    background: var(--accent-hover);
}

.mic-btn.listening {
    background: var(--danger-bg-strong);
    border-color: var(--danger);
    color: #fff;
    animation: mic-pulse 1.2s infinite;
}

.mic-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

@keyframes mic-pulse {
    0% { box-shadow: 0 0 0 0 rgba(242, 139, 130, 0.5); }
    70% { box-shadow: 0 0 0 8px rgba(242, 139, 130, 0); }
    100% { box-shadow: 0 0 0 0 rgba(242, 139, 130, 0); }
}

.send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn.stop-mode {
    background: var(--danger-bg-strong);
}

.send-btn.stop-mode:hover {
    background: var(--danger-bg-stronger);
}

/* Auth pages (login / admin) */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 340px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    display: flex;
    flex-direction: column;
}

.auth-card .brand {
    text-align: center;
}

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

.auth-card label,
.add-user-form label {
    font-size: 13px;
    color: var(--text-muted);
    margin: 10px 0 6px;
}

.auth-card input,
.add-user-form input[type="text"],
.add-user-form input[type="password"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-2);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
}

.password-field {
    position: relative;
}

.password-field input[type="password"],
.password-field input[type="text"] {
    width: 100%;
    padding-right: 40px;
}

.password-field .password-toggle {
    position: absolute;
    top: 50%;
    right: 4px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    line-height: 1;
    padding: 6px 8px;
    cursor: pointer;
    margin-top: 0;
}

.password-field .password-toggle:hover {
    background: transparent;
    color: var(--text);
}

.auth-card input:focus,
.add-user-form input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-card button,
.add-user-form button {
    margin-top: 18px;
    padding: 11px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.auth-card button:hover,
.add-user-form button:hover {
    background: var(--accent-hover);
}

.auth-error {
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    margin-bottom: 14px;
}

.admin-card {
    width: 100%;
    max-width: 620px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    /* Центрирование без обрезки верха: auto-поля поглощают свободное место
       до align-items и приоритетнее него - карточка выше вьюпорта
       прижимается к верху, а не уходит за границу прокрутки
       (fix классического overflow-бага .auth-body). */
    margin: auto 0;
}

/* ===== Компактная админ-панель с левым меню (только страница /admin) ===== */

.admin-page {
    width: 100%;
    max-width: 1240px;
    /* Тот же fix переполнения, что у .admin-card: auto-поля поглощают
       свободное место до align-items у .auth-body и приоритетнее него -
       панель выше вьюпорта не уходит вверх за границу прокрутки. */
    margin: auto 0;
}

.admin-shell {
    display: flex;
    align-items: flex-start;
    gap: 24px;
}

.admin-sidebar {
    flex: 0 0 220px;
    width: 220px;
    position: sticky;
    top: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 16px;
}

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

.admin-brand-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: -8px;
}

.admin-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.admin-nav-item {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    color: var(--text-muted);
    text-decoration: none;
}

.admin-nav-item:hover {
    background: var(--surface);
    color: var(--text);
}

.admin-nav-item.active {
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
}

.admin-nav-exit {
    margin-top: auto;
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: none;
}

.admin-nav-exit:hover {
    color: var(--text);
}

.admin-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px 20px;
}

.admin-topbar h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.admin-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
}

.admin-section h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.admin-section h3 {
    margin: 4px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.admin-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.admin-metric {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
}

.admin-metric-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.admin-metric-value {
    font-size: 20px;
    font-weight: 600;
}

.admin-metric-time {
    font-size: 15px;
    font-weight: 600;
}

.admin-table-wrap {
    overflow-x: auto;
}

.admin-table-wrap .user-table {
    margin-bottom: 8px;
    min-width: 560px;
}

.admin-empty {
    margin: 0;
    font-size: 14px;
    color: var(--text-muted);
}

.admin-add-user {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

@media (max-width: 900px) {
    .admin-shell {
        flex-direction: column;
    }

    .admin-sidebar {
        position: static;
        width: 100%;
        flex: none;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .admin-brand-sub {
        margin-top: 0;
    }

    .admin-nav {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .admin-nav-exit {
        margin-top: 0;
        margin-left: auto;
    }
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.admin-header .brand {
    padding: 0;
}

.spend-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.spend-stat {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 16px;
}

.spend-stat-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.spend-stat-value {
    font-size: 20px;
    font-weight: 600;
}

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

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

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

.models-checked-at {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 8px;
}

.model-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.model-badge-ok {
    background: rgba(78, 191, 122, 0.15);
    color: var(--success);
}

.model-badge-bad {
    background: rgba(224, 90, 90, 0.15);
    color: var(--danger-2);
}

.add-user-form {
    display: flex;
    flex-direction: column;
}

.add-user-form h2 {
    font-size: 15px;
    margin: 0 0 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    font-size: 13px;
    color: var(--text-2);
}

.checkbox-label input {
    width: auto;
}

/* Сворачиваемая боковая панель — только на десктопе. На телефоне панель
   выезжает оверлеем через .open, её ширина и поведение не зависят от
   data-sidebar, поэтому все правила спрятаны под min-width: 769px. */
@media (min-width: 769px) {
    :root[data-sidebar="collapsed"] .sidebar {
        width: 60px;
        padding: 12px 6px;
    }

    :root[data-sidebar="collapsed"] .brand-row,
    :root[data-sidebar="collapsed"] .user-bar,
    :root[data-sidebar="collapsed"] .sidebar-divider,
    :root[data-sidebar="collapsed"] .history-block {
        display: none;
    }

    :root[data-sidebar="collapsed"] .sidebar-expand-brand {
        display: flex;
    }

    :root[data-sidebar="collapsed"] .nav-item {
        justify-content: center;
        padding: 9px 0;
        gap: 0;
    }

    :root[data-sidebar="collapsed"] .nav-label {
        display: none;
    }
}

/* Mobile layout */

@media (max-width: 768px) {
    .sidebar-toggle-btn {
        display: flex;
    }

    /* Кнопки сворачивания/разворачивания — только десктоп; на телефоне
       панель управляется burger-кнопкой и оверлеем. */
    .sidebar-collapse-btn,
    .sidebar-expand-brand {
        display: none;
    }

    /* На телефоне заголовок раздела разворачивается в столбик: черта из
       вертикальной становится горизонтальной. */
    .section-intro {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        top: calc(50% - 130px);
        width: calc(100% - 28px);
    }

    .section-intro-title {
        padding-right: 0;
        max-width: 100%;
        font-size: 26px;
    }

    .section-intro-lead {
        padding: 12px 0 0;
        border-left: none;
        border-top: 1px solid var(--border-2);
        font-size: 14px;
    }

    .app.section-image .section-intro {
        width: calc(100% - 28px);
    }

    .composer-note {
        padding: 0 14px 10px;
        font-size: 11px;
    }

    /* Выехавшая панель занимает всю высоту экрана - рамка и отступы,
       которые делают из неё отдельный блок, здесь только мешают. */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 200;
        width: 82vw;
        max-width: 300px;
        margin: 0;
        border: none;
        border-right: 1px solid var(--border);
        border-radius: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 4px 0 24px var(--shadow);
    }

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

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 150;
    }

    .sidebar-backdrop[hidden] {
        display: none;
    }

    .chat {
        width: 100%;
        min-width: 0;
    }

    .chat-header {
        padding: 12px 14px;
    }

    .chat-title {
        font-size: 15px;
    }

    .messages {
        padding: 14px;
    }

    .msg-content {
        max-width: 88%;
    }

    .bubble {
        font-size: 15px;
    }

    .image-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        gap: 10px;
    }

    .composer {
        padding: 12px 14px 14px;
        gap: 6px;
    }

    .attach-btn {
        width: 32px;
        height: 32px;
    }

    .attach-thumb {
        width: 54px;
        height: 54px;
    }

    /* The three image controls wrapped onto two or three lines here. Forbid
       wrapping: labels hold their width, the selects absorb the shrinking, so
       the row fits without needing exact text metrics. (The -42px pull that
       used to compensate for the attach button outside the field went away
       with the button itself - it now sits inside the input.) */
    /* Панель параметров изображений занимает всю ширину и не переносит
       отдельные селекты внутри строки. */
    .image-controls {
        gap: 8px;
    }

    .image-options {
        flex: 1 1 100%;
        flex-wrap: nowrap;
        gap: 8px;
        font-size: 11px;
    }

    .image-options label {
        flex: 1 1 auto;
        min-width: 0;
        gap: 4px;
        font-size: 11px;
        white-space: nowrap;
    }

    .image-options select {
        flex: 1 1 auto;
        min-width: 0;
        font-size: 11px;
    }

    .image-options .opt-full {
        display: none;
    }

    .image-options .opt-short {
        display: inline;
    }

    .model-select-btn {
        max-width: min(220px, calc(100vw - 140px));
        font-size: 12px;
    }

    .toolbar-logo {
        display: block;
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        object-fit: cover;
    }

    .mic-btn,
    .send-btn {
        width: 36px;
        height: 36px;
    }

    .input-toolbar {
        position: relative;
        gap: 6px;
        padding: 4px 6px 8px;
    }

    /* The menu is right-anchored. Hanging it off .model-select left it only
       100vw - 104px of room (send + mic buttons and their gaps sit to its
       right), so a 300px menu ran off the LEFT edge below ~404px - and being
       off-screen to the left, no scrollbar could reach it. Anchoring to the
       toolbar instead puts its right edge ~14px from the viewport, which is
       what the existing calc(100vw - 32px) cap already assumed. */
    .model-select {
        position: static;
    }

    #statusBar {
        padding: 0 14px;
    }

    .composer.centered {
        top: 50%;
        padding: 0 14px;
    }
}

/* ---------------------------------------------------------------------------
   Раздел без моделей (пока — только /video). Переписки и поля ввода нет,
   на экране остаётся заголовок раздела с пояснением.
--------------------------------------------------------------------------- */
.app.section-video .chat-body,
.app.section-video .composer,
.app.section-video .composer-note,
.app.section-video #statusBar {
    display: none;
}

/* ---------------------------------------------------------------------------
   Публичная главная (/). Открыта без входа - это единственная страница,
   которую видит незалогиненный человек и поисковик.
--------------------------------------------------------------------------- */
.home-body {
    height: auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

.home-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2);
}

.home-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
    font-size: 18px;
}

.home-logo img {
    width: 30px;
    height: 30px;
}

.home-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.home-nav a {
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-2);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
}

.home-nav a:hover {
    background: var(--surface);
    color: var(--text);
}

.home-nav .home-login-btn {
    margin-left: 6px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.home-nav .home-login-btn:hover {
    background: var(--accent-hover);
    color: #fff;
}

.home-main {
    flex: 1;
    width: 100%;
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 20px 64px;
}

/* Первый экран помещается в экран целиком: шапка, логотип, название,
   переключатель задачи и поле ввода. Всё остальное - ниже, за
   стрелкой. 72px - высота шапки. */
.hero {
    position: relative;
    min-height: calc(100vh - 72px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 0 72px;
}

@supports (height: 100dvh) {
    /* На телефонах адресная строка съедает часть 100vh - dvh считает честно. */
    .hero {
        min-height: calc(100dvh - 72px);
    }
}

.scroll-down {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-2);
    border-radius: 50%;
    background: var(--surface);
    color: var(--text-2);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.scroll-down:hover {
    background: var(--surface-2);
    color: var(--text);
}

.home-rest {
    padding-bottom: 8px;
}

.hero-logo {
    width: 76px;
    height: 76px;
    margin-bottom: 18px;
}

.hero-title {
    margin: 0;
    font-size: 64px;
    line-height: 1.1;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

/* Переключатель задачи и поле запроса */
.starter {
    width: 100%;
    max-width: 720px;
    margin-top: 20px;
}

.starter-tasks {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.starter-task {
    padding: 9px 20px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

.starter-task:hover {
    background: var(--surface-2);
    color: var(--text);
}

.starter-task.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Поиск и Кодинг в этом ряду - только на мобильном, где помещаются все 6
   рубрик; на десктопе ряд остаётся из 4, как был. */
.starter-task-mobile {
    display: none;
}

.starter-task .label-short {
    display: none;
}

.starter-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 8px 8px 18px;
    border: 1px solid var(--border-2);
    border-radius: 999px;
    background: var(--bg-2);
    box-shadow: 0 2px 10px var(--shadow);
}

.starter-input input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 16px;
    padding: 8px 0;
}

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

.starter-input .mic-btn {
    width: 38px;
    height: 38px;
    font-size: 15px;
}

.home-model-select {
    position: relative;
    flex: 0 1 auto;
    min-width: 0;
}

.home-model-select-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 170px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-2);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
}

#homeModelSelectValue {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.home-model-select-caret {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 10px;
}

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

.home-model-select-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 40;
    width: 260px;
    max-width: calc(100vw - 32px);
    max-height: 300px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid var(--border-2);
    border-radius: 12px;
    background: var(--bg-2);
    box-shadow: 0 8px 24px var(--shadow);
}

.home-model-option {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
}

.home-model-option:hover,
.home-model-option.selected {
    background: var(--accent-soft);
}

.starter-submit {
    border: none;
    border-radius: 999px;
    padding: 11px 24px;
    background: var(--accent);
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

.starter-submit:hover {
    background: var(--accent-hover);
}

.starter-submit:disabled,
.starter-input input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.starter-note {
    margin: 10px 0 0;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
}

/* Плитки разделов */
.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    padding-top: 24px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-2);
    text-decoration: none;
    color: var(--text);
}

.tile:hover {
    border-color: var(--accent-soft-border);
    background: var(--surface);
}

.tile-title {
    font-size: 18px;
    font-weight: 600;
}

.tile-desc {
    font-size: 15px;
    line-height: 1.5;
    color: var(--text-muted);
}

.tile-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
    font-size: 14px;
}

.tile-count {
    color: var(--text-faint);
}

.tile-price {
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-2);
}

.tile-price-free {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Рассказ о сервисе - колонка не шире 700px, как договорились */
.about {
    max-width: 700px;
    margin: 56px auto 0;
}

.about h2 {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 600;
}

.about p {
    margin: 0 0 14px;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-2);
}

.home-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 24px;
    border-top: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 14px;
}

.home-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.home-footer a:hover {
    color: var(--text);
}

@media (max-width: 768px) {
    .home-header {
        padding: 10px 14px;
        flex-wrap: nowrap;
    }

    /* Компактный логотип по образцу принципа мобильной шапки DeepAI - свой
       текст, свой шрифт, просто чуть меньше, чем на десктопе. */
    .home-logo {
        gap: 8px;
        font-size: 16px;
    }

    .home-logo img {
        width: 26px;
        height: 26px;
    }

    /* Список рубрик и логин-кнопка в шапке уходят под гамбургер - иначе не
       помещаются в ряд и наезжают на логотип (см. плашку .home-mobile-menu
       ниже). Кнопка темы - обычный button, .home-nav a её не трогает. */
    .home-nav {
        flex-wrap: nowrap;
        gap: 8px;
    }

    .home-nav a {
        display: none;
    }

    .home-mobile-menu {
        display: flex;
        flex-direction: column;
        position: fixed;
        inset: 0;
        z-index: 300;
        padding: 20px;
        background: var(--bg-2);
    }

    .home-mobile-menu[hidden] {
        display: none;
    }

    .home-mobile-menu-close {
        align-self: flex-end;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-bottom: 20px;
        border: 1px solid var(--border-2);
        border-radius: 8px;
        background: transparent;
        color: var(--text-2);
        font-size: 18px;
        cursor: pointer;
    }

    .home-mobile-menu-close:hover {
        background: var(--surface-2);
    }

    .home-mobile-menu a {
        padding: 16px 4px;
        border-bottom: 1px solid var(--border);
        color: var(--text);
        text-decoration: none;
        font-size: 20px;
        font-weight: 600;
    }

    .home-mobile-menu a:last-of-type {
        border-bottom: none;
    }

    .hero {
        padding: 24px 0 64px;
    }

    .hero-title {
        font-size: 44px;
    }

    .hero-logo {
        width: 60px;
        height: 60px;
    }

    /* Все 6 рубрик в один ряд: подписи короче (label-short вместо label-full),
       таблетки уже. Ширина промерена реальным шрифтом Inter (вес 500,
       inter-cyrillic.woff2): при font-size 11px / padding 6px 8px / gap 4px
       сумма ширин - 305.5px против 335px доступных на экране 375px (запас
       ~30px), перенос и горизонтальная прокрутка не нужны. */
    .starter-task-mobile {
        display: inline-flex;
    }

    .starter-tasks {
        flex-wrap: nowrap;
        gap: 4px;
    }

    .starter-task {
        flex: 0 0 auto;
        padding: 6px 8px;
        font-size: 11px;
        white-space: nowrap;
    }

    .starter-task .label-full {
        display: none;
    }

    .starter-task .label-short {
        display: inline;
    }

    .starter-input {
        padding-left: 14px;
    }

    .home-model-select-btn {
        max-width: 112px;
        padding: 0 8px;
        font-size: 12px;
    }

    .home-model-select {
        position: static;
    }

    .starter-input {
        position: relative;
    }

    .starter-submit {
        padding: 10px 16px;
    }

    .about {
        margin-top: 40px;
    }
}

/* ---------------------------------------------------------------------------
   Карточка модели на пустом экране раздела: /chat/<модель> и подобные.
--------------------------------------------------------------------------- */
.model-intro {
    max-width: 700px;
    margin: 40px auto 0;
    padding: 0 16px;
    text-align: center;
}

.model-intro-name {
    font-size: 30px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.model-intro-desc {
    margin: 10px 0 14px;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-muted);
}

.model-intro-price {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 14px;
    cursor: help;
}

.model-intro-price.free {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

/* Логотип на форме входа - ссылка на публичную главную. */
.auth-brand {
    display: block;
    text-align: center;
    text-decoration: none;
    color: var(--text);
}

/* ---------------------------------------------------------------------------
   «Директорат»: кнопка заседания над полем ввода, подтверждение и карточки
   участников в ленте. Карточки раскрыты по умолчанию, сворачиваются вручную.
--------------------------------------------------------------------------- */
.directorate-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.directorate-panel[hidden],
.directorate-editor[hidden] {
    display: none;
}

.directorate-btn {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

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

.directorate-btn:disabled {
    background: var(--surface);
    border-color: var(--border-2);
    color: var(--text-faint);
    cursor: default;
}

/* Редактор черновика поручения: над полем ввода, внутри той же колонки.
   Textarea редактируемая; «Утвердить и запустить» - единственный путь к
   заседанию. */
.directorate-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 4px 0 10px;
    padding: 10px 12px;
    border: 1px solid var(--accent-soft-border);
    border-radius: 12px;
    background: var(--accent-soft);
}

.directorate-editor-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.directorate-editor-text {
    width: 100%;
    min-height: 180px;
    max-height: 50vh;
    resize: vertical;
    padding: 10px 12px;
    border: 1px solid var(--border-2);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
}

.directorate-editor-text:focus {
    outline: none;
    border-color: var(--accent);
}

.directorate-editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.directorate-editor-actions .ghost-btn {
    padding: 6px 12px;
    font-size: 12px;
}

.directorate-stage {
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.directorate-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.directorate-card {
    border: 1px solid var(--border-2);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
}

.directorate-card.failed {
    border-color: var(--danger-border);
}

.directorate-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
}

.directorate-card-title {
    font-weight: 600;
}

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

.directorate-card-caret {
    margin-left: auto;
    color: var(--text-faint);
    transition: transform 0.15s;
}

.directorate-card.collapsed .directorate-card-caret {
    transform: rotate(-90deg);
}

.directorate-card-body {
    padding: 10px 14px 12px;
}

.directorate-card.collapsed .directorate-card-body {
    display: none;
}

/* Внутри карточки .bubble ответа модели уже без фона (см. .from-bot .bubble);
   здесь только чуть меньше кегль, чтобы пять карточек читались как сводка. */
.directorate-card-text {
    font-size: 15px;
}

.directorate-card.failed .directorate-card-text {
    color: var(--danger);
}

.directorate-note {
    margin-top: 8px;
    font-size: 13px;
    color: var(--warning);
}

/* Редакторы пакета авторам и итога: поля, фотография, подтверждение. */
.directorate-field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
}

.directorate-editor-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-2);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}

.directorate-editor-input:focus {
    outline: none;
    border-color: var(--accent);
}

.directorate-editor .directorate-editor-text[rows="2"],
.directorate-editor .directorate-editor-text[rows="5"] {
    min-height: 60px;
}

.directorate-editor .directorate-editor-text[rows="8"] {
    min-height: 120px;
}

.directorate-photo-preview img,
.directorate-publication-image img {
    display: block;
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
    border: 1px solid var(--border-2);
}

.directorate-publication-image {
    margin-bottom: 10px;
}

.directorate-confirm {
    margin-top: 4px;
    padding: 10px 12px;
    border: 1px solid var(--warning);
    border-radius: 10px;
    background: var(--surface);
}

.directorate-confirm[hidden],
.directorate-photo-preview[hidden] {
    display: none;
}

.directorate-confirm-text {
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

/* Карточки материалов разведки (structured sources) с кнопкой выбора. */
.directorate-materials {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 13px;
}

.directorate-material {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.directorate-material-title {
    font-weight: 600;
}

.directorate-material-meta,
.directorate-material-snippet {
    color: var(--text-muted);
    font-size: 12px;
}

.directorate-material-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
}

.directorate-material-link {
    color: var(--accent);
    text-decoration: underline;
    font-size: 13px;
    word-break: break-all;
}

.directorate-pick {
    padding: 5px 12px;
}

/* Источники разведчика (тот же renderSearchSources, что и в «Поиске»). */
.directorate-card .search-sources {
    margin-top: 10px;
    font-size: 13px;
}

.directorate-card .sources-header {
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-2);
}

.directorate-card .sources-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.directorate-card .source-item {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.directorate-card .source-title {
    font-weight: 600;
}

.directorate-card .source-domain,
.directorate-card .source-snippet {
    color: var(--text-muted);
    font-size: 12px;
}

.directorate-card .sources-warning {
    color: var(--warning);
}

/* ---------------------------------------------------------------------------
   «Директорат», рабочий экран авторов: открывается поверх ленты после
   «Передать авторам». Сверху компактная панель пакета (инфоповод, источник,
   миниатюра фотографии, возврат), под ней три одинаковые колонки в одну
   строку - по одной на автора. Колонка: закреплённая шапка (роль, модель,
   статус), тело со своей вертикальной прокруткой и кнопка выбора внизу.
   Уже 3×300px колонки не сжимаются, а прокручиваются по горизонтали
   (планшет); на телефоне одна колонка на всю ширину и вкладки.
--------------------------------------------------------------------------- */
.directorate-workspace {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 4px;
    background: var(--bg);
}

.directorate-workspace[hidden] {
    display: none;
}

/* Верхняя строка - одна тонкая полоса (~34px): возврат, миниатюра,
   инфоповод и источник в одну строку с многоточием, стадия, кнопка разбора.
   Всё остальное место отдано колонкам. */
.directorate-ws-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-height: 34px;
    padding: 3px 8px;
    border: 1px solid var(--border-2);
    border-radius: 10px;
    background: var(--surface);
}

.directorate-ws-photo {
    flex-shrink: 0;
}

.directorate-ws-photo[hidden] {
    display: none;
}

.directorate-ws-photo img {
    display: block;
    width: 26px;
    height: 26px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border-2);
}

.directorate-ws-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.directorate-ws-topic {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.directorate-ws-source {
    flex-shrink: 0;
    max-width: 28%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--accent);
    text-decoration: underline;
}

.directorate-ws-source[hidden] {
    display: none;
}

.directorate-ws-stage {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.directorate-ws-back,
.directorate-ws-chair-btn {
    padding: 4px 10px;
    font-size: 12px;
    white-space: nowrap;
}

.directorate-ws-chair-btn[hidden] {
    display: none;
}

/* Вкладки «Автор 1 / 2 / 3» нужны только телефону (см. медиазапрос ниже). */
.directorate-ws-tabs {
    display: none;
}

/* Разбор председателя - всплывающее окно поверх колонок по кнопке в верхней
   строке: читается рядом с вариантами, высоту у колонок не отнимает. */
.directorate-ws-chair {
    position: absolute;
    top: 50px;
    right: 12px;
    z-index: 7;
    display: flex;
    flex-direction: column;
    width: min(640px, calc(100% - 24px));
    max-height: min(60vh, 640px);
    border: 1px solid var(--border-2);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: 0 12px 32px var(--shadow);
    overflow: hidden;
}

.directorate-ws-chair[hidden] {
    display: none;
}

.directorate-ws-chair.failed {
    border-color: var(--danger-border);
}

.directorate-ws-chair-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 13px;
}

.directorate-ws-chair-close {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border: 1px solid var(--border-2);
    border-radius: 8px;
    background: transparent;
    color: var(--text-2);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.directorate-ws-chair-close:hover {
    background: var(--surface);
}

.directorate-ws-chair-text {
    overflow-y: auto;
    padding: 10px 14px 12px;
    font-size: 14px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.directorate-ws-chair.failed .directorate-ws-chair-text {
    color: var(--danger);
}

/* Три колонки одной строкой. Ряд ровно в высоту контейнера (minmax(0, 1fr)),
   иначе колонки вытянулись бы по содержимому и тело перестало бы
   прокручиваться. При нехватке места на три по 300px - горизонтальная
   прокрутка карточек, а не сжатие. */
.directorate-cols {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(300px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    padding-bottom: 2px;
}

.directorate-col {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border: 1px solid var(--border-2);
    border-radius: 12px;
    background: var(--surface);
    overflow: hidden;
    scroll-snap-align: start;
}

.directorate-col.is-error,
.directorate-col.is-timeout {
    border-color: var(--danger-border);
}

.directorate-col.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

/* Шапка закреплена: она вне прокручиваемого тела. */
.directorate-col-head {
    flex-shrink: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 8px;
    row-gap: 2px;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.directorate-col-role {
    grid-column: 1;
    grid-row: 1;
    font-size: 14px;
    font-weight: 600;
}

.directorate-col-model {
    grid-column: 1;
    grid-row: 2;
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.directorate-col-status {
    grid-column: 2;
    grid-row: 1 / 3;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border: 1px solid var(--border-2);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.directorate-col-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.is-pending .directorate-col-status {
    color: var(--warning);
}

.is-pending .directorate-col-status::before {
    animation: directorate-pulse 1.2s ease-in-out infinite;
}

.is-ready .directorate-col-status {
    color: var(--success);
}

.is-error .directorate-col-status,
.is-timeout .directorate-col-status {
    color: var(--danger);
}

@keyframes directorate-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.directorate-col-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
}

.directorate-col-pending {
    padding: 24px 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-muted);
}

.directorate-col-error {
    font-size: 14px;
    line-height: 1.5;
    color: var(--danger);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Пять блоков ответа: подпись, промпт, пост, проверка, источник. Состав у
   всех трёх колонок одинаковый - пустой раздел подписан, а не пропущен. */
.directorate-block {
    padding: 6px 10px 8px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-2);
}

.directorate-block-title {
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.directorate-block-text {
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.directorate-block-text.empty {
    color: var(--text-faint);
    font-style: italic;
}

.directorate-block-caption .directorate-block-text {
    font-weight: 600;
}

.directorate-block-muse_prompt .directorate-block-text {
    font-size: 13px;
    color: var(--text-2);
}

.directorate-block-post {
    border-color: var(--accent-soft-border);
}

.directorate-block-post .directorate-block-text {
    font-size: 15px;
    line-height: 1.6;
}

.directorate-block.attention {
    border-color: var(--warning);
}

.directorate-block.attention .directorate-block-title {
    color: var(--warning);
}

.directorate-col-full {
    font-size: 13px;
}

.directorate-col-full summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-muted);
}

.directorate-col-full-text {
    margin-top: 6px;
    padding: 8px 10px;
    border: 1px dashed var(--border-2);
    border-radius: 10px;
    line-height: 1.55;
    color: var(--text-2);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Кнопка выбора всегда внизу колонки, вне прокрутки. */
.directorate-col-foot {
    flex-shrink: 0;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

.directorate-col-foot .directorate-pick {
    width: 100%;
    padding: 8px 14px;
    font-size: 13px;
}

/* Сводная карточка этапа в ленте: статусы авторов и кнопка открытия экрана. */
.directorate-summary-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
}

.directorate-summary-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

/* Режим сравнения (класс на .app, пока экран открыт): на компьютере всё,
   что отнимает высоту у колонок, прячется - шапка разговора, статусная
   строка, панель «Подготовить поручение», подпись под полем; поле ввода
   становится компактной полосой ~105px во всю ширину. Данные и логика не
   трогаются - после закрытия экрана класс снимается и всё возвращается. */
@media (min-width: 769px) {
    .app.directorate-compare .chat-header,
    .app.directorate-compare #statusBar,
    .app.directorate-compare .composer-note,
    .app.directorate-compare .image-controls {
        display: none;
    }

    .app.directorate-compare .composer {
        max-width: none;
        padding: 4px 12px 10px;
    }

    .app.directorate-compare .input-shell textarea {
        min-height: 34px;
        max-height: 44px;
        padding: 8px 14px 2px;
    }

    .app.directorate-compare .input-toolbar {
        padding: 2px 8px 6px;
    }
}

@media (max-width: 768px) {
    .directorate-workspace {
        gap: 8px;
        padding: 10px 12px;
    }

    /* Панель переносится: миниатюра и текст в первой строке, кнопка возврата
       отдельной строкой во всю ширину. */
    .directorate-ws-bar {
        flex-wrap: wrap;
        gap: 8px 10px;
        padding: 8px 10px;
    }

    .directorate-ws-photo img {
        width: 36px;
        height: 36px;
    }

    .directorate-ws-info {
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
    }

    .directorate-ws-source {
        max-width: 100%;
    }

    /* Стадия - отдельной строкой, кнопки разбора и возврата - последней. */
    .directorate-ws-stage {
        order: 5;
        flex-basis: 100%;
        white-space: normal;
    }

    .directorate-ws-chair-btn {
        order: 6;
        flex: 1;
    }

    .directorate-ws-back {
        order: 7;
        flex: 1;
        white-space: normal;
    }

    .directorate-ws-chair {
        top: 12px;
        right: 12px;
        left: 12px;
        width: auto;
        max-height: calc(100% - 24px);
    }

    /* Одна колонка на всю ширину и вкладки со статусами остальных авторов. */
    .directorate-ws-tabs {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 6px;
        flex-shrink: 0;
    }

    .directorate-ws-tab {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        min-width: 0;
        padding: 6px 4px;
        border: 1px solid var(--border-2);
        border-radius: 10px;
        background: var(--surface);
        color: var(--text-2);
        font-family: inherit;
        cursor: pointer;
    }

    .directorate-ws-tab.active {
        border-color: var(--accent);
        background: var(--accent-soft);
        color: var(--text);
    }

    .directorate-ws-tab-role {
        font-size: 13px;
        font-weight: 600;
    }

    .directorate-ws-tab-status {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
    }

    .directorate-ws-tab.is-pending .directorate-ws-tab-status {
        color: var(--warning);
    }

    .directorate-ws-tab.is-ready .directorate-ws-tab-status {
        color: var(--success);
    }

    .directorate-ws-tab.is-error .directorate-ws-tab-status,
    .directorate-ws-tab.is-timeout .directorate-ws-tab-status {
        color: var(--danger);
    }

    .directorate-cols {
        display: block;
        overflow: hidden;
        padding-bottom: 0;
    }

    .directorate-col {
        display: none;
        height: 100%;
    }

    .directorate-col.active {
        display: flex;
    }

    .directorate-col-head {
        padding: 8px 12px;
    }

    .directorate-col-body {
        padding: 10px 12px;
    }

}

/* ===== «Арена ИИ»: три колонки - три модели ============================== */
#app[data-section="arena"] .chat-header,
#app[data-section="arena"] .section-intro {
    display: none;
}

#app[data-section="arena"] .chat {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#app[data-section="arena"] .chat-body {
    flex: 1;
    min-height: 0;
}
#app[data-section="arena"] .composer-note {
    display: none;
}


.arena-panel { padding: 8px 12px 0; overflow: hidden; flex: 1; min-height: 0;
    display: flex; }
.arena-panel[hidden] { display: none !important; }

/* Арена: «Арена ИИ — Выберите по модели...» одной компактной строкой
   над колонками; карточка модели не занимает место сверху. */
#app[data-section="arena"] .model-intro { display: none; }
#app[data-section="arena"] .section-intro {
    position: static;
    padding: 8px 16px 0;
    margin: 0;
    text-align: left;
}
#app[data-section="arena"] .section-intro-title,
#app[data-section="arena"] .section-intro-lead {
    display: inline;
    font-size: 15px;
    margin: 0 8px 0 0;
}

/* Корень проблемы: .chat-body не был flex-контейнером, поэтому flex:1
   арена-панели не работал - панель росла контентом вниз, растягивая
   страницу и наезжая на поле ввода. Для арены chat-body становится
   flex-колонкой: панель упирается в экран, скролл - внутри колонок,
   композер - тонкая полоса на всю ширину снизу, как в ChatHub. */
#app[data-section="arena"] .chat-body {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#app[data-section="arena"] .arena-panel { flex: 1; min-height: 0; }
#app[data-section="arena"] .arena-columns {
    height: 100%;
    max-width: none;
}
#app[data-section="arena"] .composer {
    max-width: none;
    padding: 6px 16px 10px;
    flex-shrink: 0;
}
#app[data-section="arena"] .composer textarea {
    max-height: 72px;
}

/* Арена: тонкая полоса ввода на всю ширину внизу, под колонками.
   textarea не раздувается на полстраницы при длинном диктованном
   тексте: максимум ~3 строки, дальше внутренний скролл. */
#app[data-section="arena"] .composer { max-height: none; }
#app[data-section="arena"] .composer textarea {
    max-height: 96px;
    overflow-y: auto;
    resize: none;
}

/* Заголовок раздела в арене - одна строка, без разбивки на спаны. */
#app[data-section="arena"] .section-intro-title { display: inline; }
.arena-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
    width: 100%; max-width: 1400px; margin: 0 auto; align-items: stretch;
    flex: 1; min-height: 0; }
.arena-col { display: flex; flex-direction: column; gap: 8px;
    border: 1px solid rgba(128,128,128,.25); border-radius: 14px; padding: 10px;
    min-width: 0; min-height: 0; overflow: hidden; }
.arena-col-head { display: flex; flex-direction: column; gap: 4px; }
.arena-col-title { font-size: 12px; font-weight: 600; opacity: .7;
    text-transform: uppercase; letter-spacing: .04em; }
.arena-model-select { width: 100%; padding: 8px 10px; border-radius: 10px;
    border: 1px solid rgba(128,128,128,.4); background: var(--bg, #fff); color: inherit;
    font-size: 13px; }
.arena-answer { display: flex; flex-direction: column; gap: 8px; font-size: 14px;
    flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px;
    overflow-wrap: anywhere; word-break: break-word;
    flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }
.arena-prompt { align-self: flex-end; max-width: 85%; padding: 8px 12px;
    overflow-wrap: anywhere; word-break: break-word;
    border-radius: 12px 12px 2px 12px; background: rgba(128,128,128,.15); }
.arena-msg.assistant { display: flex; }
.arena-bubble { max-width: 100%; padding: 10px 12px; border-radius: 12px 12px 12px 2px;
    background: rgba(128,128,128,.1); white-space: pre-wrap; overflow-wrap: break-word;
    line-height: 1.55; }
.arena-bubble.arena-error { color: #c0392b; }
.arena-cost { margin-top: 6px; font-size: 11px; opacity: .6; }
@media (max-width: 900px) { .arena-columns { grid-template-columns: 1fr; } }

/* арена: добавка-каркас (легко откатить) */
/* Точечная добавка: .app держит экран, у колонок разрешено
   сжиматься, прокрутка уходит в .arena-answer. Ничего не удаляет. */
#app[data-section="arena"] { height: 100vh; overflow: hidden; }
#app[data-section="arena"] .arena-col { min-height: 0; }
#app[data-section="arena"] .arena-answer { flex: 1; min-height: 0; overflow-y: auto; }

/* Arena: compact column headers and composer */
#app[data-section="arena"] .arena-col-title {
    display: none;
}
#app[data-section="arena"] #statusBar:empty {
    display: none;
}
#app[data-section="arena"] .composer textarea {
    min-height: 40px;
    max-height: 64px;
    padding: 8px 14px 4px;
    overflow-y: auto;
}

/* Arena: answer actions */
#app[data-section="arena"] .arena-col-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
}
#app[data-section="arena"] .arena-clear-btn {
    margin: 0;
}
#app[data-section="arena"] .arena-msg.assistant {
    flex-direction: column;
    align-items: flex-start;
}
#app[data-section="arena"] .arena-bubble {
    min-width: 0;
}
