/* Стили шаренной разметки чата console_shell/_chat.html. Используются
   и в LK 1С code console, и в admin dev-task workspace — должны жить
   рядом с partial, чтобы не зависеть от страницы-хоста. */

.chat-bubble-assistant {
    background: var(--app-chat-assistant-surface);
    border-color: var(--app-chat-assistant-border);
    color: var(--app-console-text-body);
}
.chat-bubble-user {
    background: var(--app-chat-user-surface);
    border-color: var(--app-chat-user-border);
    color: var(--app-chat-user-text);
}

.chat-form-answer-bubble {
    box-sizing: border-box;
    width: fit-content;
    max-width: 85%;
    min-width: 0;
    padding: 0.75rem;
    border: 1px solid var(--app-console-answer-border);
    border-radius: 1rem;
    background: var(--app-console-success-surface);
    color: var(--app-account-text-interface);
    font-size: 0.85rem;
    line-height: 1.625;
    overflow-wrap: anywhere;
}
.chat-form-answer .chat-form-answer-header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; min-height: 0; height: auto; }
.chat-form-answer-header h3 { flex: 1 1 auto; min-width: 0; font-size: inherit; font-weight: 600; }
.chat-form-answer-status { color: var(--app-success-text); font-size: 0.8125rem; }
.chat-form-answer-rows { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
.chat-form-answer-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 0.25rem 0.75rem; border-top: 1px solid var(--app-console-border-default); padding-top: 0.5rem; }
.chat-form-answer-row dt { color: var(--app-account-text-secondary); }
.chat-form-answer-row dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.5rem; min-width: 0; white-space: pre-wrap; }
.chat-form-answer-chip { max-width: 100%; padding: 0.25rem 0.625rem; border-radius: 0.5rem; background: var(--app-console-surface-chip); line-height: 1.4; }
.chat-form-answer-details summary { width: fit-content; margin-top: 0.5rem; color: var(--app-account-text-body); cursor: pointer; }
.chat-form-answer-details summary:focus-visible { outline: 2px solid var(--app-console-focus-ring); outline-offset: 2px; }
@media (max-width: 640px), (pointer: coarse) {
    .chat-form-answer .chat-form-answer-details summary { min-height: 44px; min-width: 44px; align-content: center; }
}
@media (max-width: 480px) {
    .chat-form-answer-row { grid-template-columns: minmax(0, 1fr); }
}

/* Карточка ответа располагается под сообщением, вне поверхности пузыря. */
.chat-user-form {
    --user-form-control-border: var(--app-console-border-input);
    --user-form-invalid-border: var(--app-account-danger);
    --user-form-focus-ring: var(--app-console-focus-ring);
    container-type: inline-size;
    width: 100%;
    min-width: 0;
    margin-top: 0.75rem;
}
.chat-user-form-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 1px solid var(--app-console-border-default);
    border-left: 2px solid var(--app-console-form-attention-border);
    border-radius: 1rem;
    background: var(--app-console-surface-subtle);
    overflow-wrap: anywhere;
}
.chat-user-form .chat-user-form-header { display: grid; gap: 0.25rem; min-height: 0; height: auto; }
.chat-user-form-header h3 { color: var(--app-account-text-interface); font-size: 0.875rem; font-weight: 600; }
.chat-user-form-header p, .chat-user-form-help, .chat-user-form-note {
    color: var(--app-account-text-secondary);
    font-size: 0.75rem;
    line-height: 1.5;
}
.chat-user-form-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; min-width: 0; }
.chat-user-form-field { display: flex; flex-direction: column; gap: 0.375rem; min-width: 0; }
.chat-user-form-field-wide { grid-column: 1 / -1; }
.chat-user-form-label { color: var(--app-account-text-body); font-size: 0.8125rem; font-weight: 500; }
.chat-user-form-required { color: var(--app-account-text-secondary); }
.chat-user-form .chat-user-form-control {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 36px;
    padding: 0.375rem 0.75rem;
    line-height: 1.25;
    border: 1px solid var(--user-form-control-border);
    border-radius: 0.75rem;
    background: var(--app-console-input-surface);
    color: var(--app-account-text-interface);
    font-size: 0.875rem;
    color-scheme: var(--app-scheme);
}
.chat-user-form-toggle { display: flex; align-items: center; gap: 0.5rem; min-height: 32px; width: fit-content; padding-right: 0.5rem; cursor: pointer; color: var(--app-account-text-interface); font-size: 0.875rem; }
.chat-user-form-toggle input { appearance: none; display: grid; place-content: center; width: 18px; height: 18px; flex: none; margin: 0; border: 1px solid var(--app-account-accent); border-radius: 4px; background: var(--app-console-input-surface); cursor: inherit; }
.chat-user-form-toggle input:checked { background: var(--app-account-accent); }
.chat-user-form-toggle input::after { content: ''; width: 10px; height: 6px; border-left: 2px solid var(--app-console-checked-control-foreground); border-bottom: 2px solid var(--app-console-checked-control-foreground); transform: translateY(-1px) rotate(-45deg); visibility: hidden; }
.chat-user-form-toggle input:checked::after { visibility: visible; }
.chat-user-form-toggle input[type="radio"] { border-radius: 50%; }
.chat-user-form-toggle input[type="radio"]::after { width: 8px; height: 8px; border: 0; border-radius: 50%; background: var(--app-console-checked-control-foreground); transform: none; }
.chat-user-form-toggle:hover { background: var(--app-console-surface-subtle); }
.chat-user-form-select .agent-select-trigger { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; border-color: var(--app-console-select-border); background: var(--app-console-select-surface); text-align: left; cursor: pointer; font-size: 0.875rem; }
.chat-user-form-select .agent-select-trigger span { min-width: 0; white-space: normal; overflow-wrap: anywhere; line-height: 1.5; }
.chat-user-form-select .agent-select-trigger i { width: 8px; height: 8px; flex: none; border-right: 1.5px solid var(--app-accent-hover); border-bottom: 1.5px solid var(--app-accent-hover); transform: translateY(-2px) rotate(45deg); }
.chat-user-form-select .agent-select-trigger[aria-expanded="true"] { border-color: var(--app-console-select-expanded-border); background: var(--app-console-select-expanded-surface); }
.chat-user-form-select .agent-select-trigger[aria-expanded="true"] i { transform: translateY(2px) rotate(225deg); }
/* Телепорт в body выводит меню из обрезающего контейнера чата. */
.chat-user-form-select-menu { position: fixed; z-index: 140; box-sizing: border-box; overflow-y: auto; overscroll-behavior: contain; margin: 0; padding: 4px; list-style: none; border: 1px solid var(--app-console-select-menu-border); border-radius: 12px; background: var(--app-account-panel-background); color: var(--app-account-text-interface); font-size: 0.8125rem; }
.chat-user-form-select-menu li { display: flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 8px; border-radius: 8px; cursor: pointer; overflow-wrap: anywhere; }
.chat-user-form-select-menu li::before { content: ''; width: 14px; flex: none; }
.chat-user-form-select-menu li[aria-selected="true"] { background: var(--app-console-accent-surface); color: var(--app-account-action-text-hover); }
.chat-user-form-select-menu li[aria-selected="true"]::before { content: '✓'; color: var(--app-accent-hover); }
.chat-user-form-select-menu li.is-active { outline: 2px solid var(--app-console-focus-ring); outline-offset: -2px; background: var(--app-console-surface-hover); }
@media (forced-colors: active) {
    .chat-user-form-toggle input { appearance: auto; }
    .chat-user-form-toggle input::after { display: none; }
}
.chat-user-form .chat-user-form-choices { min-width: 0; margin: 0; padding: 0; border: 0; }
.chat-user-form-choices legend { padding: 0; }
.chat-user-form-choice-list {
    display: grid;
    gap: 0.25rem;
    padding: 0.25rem;
    scroll-padding-block: 0.25rem;
}
.chat-user-form-choice-list.is-scrollable { max-height: 20rem; overflow-y: auto; }
.chat-user-form-choice-list .chat-user-form-toggle { box-sizing: border-box; align-items: flex-start; width: 100%; padding: 0.375rem 0.5rem; line-height: 1.5; border-radius: 0.5rem; }
.chat-user-form-choice-list .chat-user-form-toggle input { margin-top: 0.25rem; }
.chat-user-form-choice-list .chat-user-form-toggle span { min-width: 0; overflow-wrap: anywhere; }
.chat-user-form-choices .chat-user-form-toggle { width: auto; max-width: 100%; min-width: 44px; }
.chat-user-form-choices input[aria-invalid="true"] { outline: 1px solid var(--user-form-invalid-border); }
.chat-user-form .chat-user-form-control:focus, .chat-user-form-toggle input:focus-visible,
.chat-user-form button:focus-visible, .chat-user-form-status:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--user-form-focus-ring);
}
.chat-user-form .is-invalid { border-color: var(--user-form-invalid-border); }
.chat-user-form .source-file-drop { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 12px; border: 1px dashed var(--user-form-control-border); border-radius: 0.75rem; background: var(--app-console-input-surface); cursor: pointer; transition: border-color .15s, background .15s, box-shadow .15s; }
.chat-user-form .source-file-drop:hover, .chat-user-form .source-file-drop.is-dragging { border-color: var(--app-console-select-expanded-border); background: var(--app-console-select-expanded-surface); }
.chat-user-form .source-file-drop.is-dragging, .chat-user-form .source-file-drop:focus-within { border-style: solid; border-color: var(--app-console-select-expanded-border); box-shadow: 0 0 0 2px var(--user-form-focus-ring); }
.chat-user-form .source-file-drop.has-file { border-style: solid; }
.chat-user-form .source-file-drop-icon { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--app-console-border-default); background: var(--app-console-surface-chip); color: var(--app-accent-hover); }
.chat-user-form .source-file-drop-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-user-form .source-file-drop-body b { color: var(--app-account-text-interface); font-size: 0.8125rem; font-weight: 500; line-height: 1.35; }
.chat-user-form .source-file-drop-body u { color: var(--app-accent-hover); text-decoration: none; }
.chat-user-form .source-file-drop:hover .source-file-drop-body u { text-decoration: underline; }
.chat-user-form .source-file-drop-body small { color: var(--app-account-text-secondary); font-size: 0.7rem; line-height: 1.3; }
.chat-user-form .source-file-drop-selected { min-width: 0; flex: 1; display: flex; align-items: center; }
.chat-user-form .source-file-chip { max-width: 100%; display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 10px; border: 1px solid var(--app-console-border-default); border-radius: 999px; background: var(--app-console-surface-chip); color: var(--app-account-text-interface); font-size: 0.75rem; }
.chat-user-form .source-file-chip svg { flex: none; color: var(--app-accent-hover); }
.chat-user-form .source-file-chip b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.chat-user-form .source-file-clear { width: 22px; height: 22px; flex: none; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: var(--app-console-surface-hover); color: var(--app-account-text-secondary); font-size: 14px; line-height: 1; cursor: pointer; }
.chat-user-form .source-file-clear:hover { color: var(--app-danger-text); }
.chat-user-form-error { color: var(--app-error-text); font-size: 0.75rem; line-height: 1.5; }
.chat-user-form-footer { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding-top: 0.5rem; border-top: 1px solid var(--app-console-border-default); }
.chat-user-form-note { flex: 1 1 12rem; }
.chat-user-form-footer button { min-height: 36px; padding-block: 0.375rem; flex: none; }
@media (pointer: coarse), (max-width: 480px) {
    .chat-user-form .chat-user-form-control, .chat-user-form-toggle, .chat-user-form-footer button,
    .chat-user-form-select-menu li { min-height: 44px; }
    .chat-user-form .chat-user-form-control { font-size: 1rem; }
}
.chat-user-form-fields:disabled { opacity: 0.6; }
.chat-user-form-status { width: fit-content; border-left: 2px solid var(--app-console-success-status-border); padding: 0.25rem 0.75rem; color: var(--app-success-text); font-size: 0.8125rem; }
@container (min-width: 560px) {
    .chat-user-form-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Заполнение контекста последнего вызова LLM: тонкая полоска над полем ввода. */
.chat-context {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 2px;
}

.chat-context-track {
    position: relative;
    flex: 1 1 auto;
    height: 3px;
    border-radius: 9999px;
    background: var(--app-console-context-track);
    overflow: hidden;
}

.chat-context-track i {
    position: absolute;
    inset: 0 auto 0 0;
    background: var(--app-account-accent);
    border-radius: inherit;
}

.chat-context-label {
    flex: 0 0 auto;
    font-size: 10px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--app-console-context-label);
}

.chat-model-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    color: var(--app-account-text-body);
}

.chat-model-btn svg {
    width: 1.25rem;
    height: 1.25rem;
}

.chat-model-menu {
    position: relative;
}

.chat-model-menu > div,
.chat-model-mobile-list {
    display: flex;
    flex-direction: column;
    max-width: min(24rem, calc(100vw - 2.5rem));
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--app-console-border-default);
    border-radius: 0.75rem;
    background: var(--app-console-surface-raised);
}

.chat-model-menu > div {
    position: absolute;
    left: calc(100% + 0.5rem);
    bottom: 0;
    z-index: 20;
}

.chat-model-menu button,
.chat-model-mobile-list button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 100%;
    padding: 0.5rem 0.75rem;
    color: var(--app-console-text-body);
    font-size: 12px;
    text-align: left;
}

.chat-model-option {
    display: flex;
    min-width: 0;
    align-items: baseline;
    gap: 0.35rem;
}

.chat-model-option b {
    flex: none;
    font-weight: 500;
}

.chat-model-option em {
    min-width: 0;
    overflow: hidden;
    color: var(--app-account-text-secondary);
    font-style: normal;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-model-option em::before { content: "("; }
.chat-model-option em::after { content: ")"; }

.chat-model-option em span + span::before { content: " · "; }

.chat-model-menu i,
.chat-model-mobile-list i {
    color: var(--app-account-accent);
}

@media (max-width: 767px) {
    .chat-model-menu { display: none; }
}

/* Мобильный пункт модели внутри меню «+»: сам список свёрнут, пока не нажали шеврон. */
.chat-model-mobile {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    width: 100%;
}

.chat-model-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    color: var(--app-console-mobile-menu-text);
    font-size: 14px;
    text-align: left;
}

.chat-model-mobile-toggle span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-model-mobile-toggle svg {
    width: 1rem;
    height: 1rem;
    flex: none;
    color: var(--app-account-text-secondary);
    transition: transform 0.15s ease;
}

.chat-model-mobile.open .chat-model-mobile-toggle svg {
    transform: rotate(180deg);
}

.chat-model-mobile-list {
    width: 100%;
}


/* ----- Markdown: чат и превью редактора (#code-preview) ----- */
/* Tailwind preflight сбрасывает списки/заголовки — типографику задаём явно. */
.markdown-content {
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.65;
    color: var(--app-console-text-body);
}
.markdown-content > :first-child { margin-top: 0; }
.markdown-content > :last-child { margin-bottom: 0; }

.md-mermaid {
    margin: 0.75rem 0;
    overflow: hidden;
    border: 1px solid var(--app-console-diagram-border);
    border-radius: 0.75rem;
    background: var(--app-console-code-surface);
}
.md-mermaid-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.25rem;
    padding: 0.4rem;
    border-bottom: 1px solid var(--app-console-border-subtle);
}
.md-mermaid-toolbar button {
    padding: 0.22rem 0.48rem;
    border-radius: 0.35rem;
    color: var(--app-account-text-secondary);
    font-size: 0.7rem;
}
.md-mermaid-toolbar button:hover { color: var(--app-console-text-body); background: var(--app-console-surface-skeleton); }
.md-mermaid-canvas { overflow: auto; padding: 0.75rem; }
.md-mermaid-canvas svg { display: block; max-width: 100%; height: auto; margin: auto; }
.md-mermaid-source { margin: 0; border: 0; border-radius: 0; }
.md-mermaid-error { margin: 0; padding: 0.5rem 0.75rem; color: var(--app-error-text); font-size: 0.75rem; }
.md-mermaid-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--app-console-diagram-overlay);
}
.md-mermaid-lightbox > button {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    background: var(--app-console-surface-hover);
    color: var(--app-console-overlay-close-foreground);
    font-size: 1.6rem;
}
.md-mermaid-lightbox > div { width: min(96vw, 1200px); max-height: 92vh; overflow: auto; }
.md-mermaid-lightbox svg { width: 100%; height: auto; }

.markdown-content h1,
.markdown-content h2,
.markdown-content h3,
.markdown-content h4 {
    font-weight: 600;
    color: var(--app-console-text-heading);
    line-height: 1.3;
}
.markdown-content h1 { font-size: 1.35rem; margin: 1.25rem 0 0.65rem; }
.markdown-content h2 { font-size: 1.15rem; margin: 1.1rem 0 0.55rem; }
.markdown-content h3 { font-size: 1rem; margin: 0.95rem 0 0.45rem; }
.markdown-content h4 { font-size: 0.92rem; margin: 0.85rem 0 0.4rem; }
.markdown-content p { margin: 0.55rem 0; }
.markdown-content ul,
.markdown-content ol {
    margin: 0.55rem 0;
    padding-left: 1.35rem;
}
.markdown-content ul { list-style: disc; }
.markdown-content ol { list-style: decimal; }
.markdown-content li { margin: 0.2rem 0; }
.markdown-content li > ul,
.markdown-content li > ol { margin: 0.2rem 0; }
.markdown-content blockquote {
    margin: 0.75rem 0;
    padding: 0.35rem 0 0.35rem 0.85rem;
    border-left: 3px solid var(--app-console-quote-border);
    color: var(--app-account-text-secondary);
}
.markdown-content hr {
    margin: 1rem 0;
    border: 0;
    border-top: 1px solid var(--app-console-border-default);
}
.markdown-content a {
    color: var(--app-accent-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.markdown-content a:hover { color: var(--app-accent-text); }
.markdown-content code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
    font-size: 0.875em;
}
.markdown-content :not(pre) > code {
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
    background: var(--app-console-code-inline-surface);
    border: 1px solid var(--app-console-border-subtle);
    white-space: normal;
    overflow-wrap: anywhere;
}
.markdown-content pre {
    margin: 0.75rem 0;
    padding: 0.85rem 1rem;
    border-radius: 0.5rem;
    background: var(--app-console-code-surface);
    border: 1px solid var(--app-console-border-default);
    overflow-x: auto;
    white-space: pre;
}
.markdown-content pre code {
    display: block;
    min-width: max-content;
    padding: 0;
    border: none;
    background: transparent;
    font-size: 0.8125rem;
    line-height: 1.55;
}
/* Таблица заворачивается в .md-table-wrap рендерером (markdown.js): на узких экранах
   скроллится вбок сама, а не распирает сообщение и страницу целиком. */
.md-table-wrap {
    max-width: 100%;
    margin: 0.75rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.markdown-content table {
    width: 100%;
    min-width: max-content;
    margin: 0;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.markdown-content th,
.markdown-content td {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--app-console-border-default);
    text-align: left;
    white-space: nowrap;
}
.markdown-content th {
    background: var(--app-console-surface-subtle);
    font-weight: 600;
}
.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
}

.chat-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 9999px;
    background: linear-gradient(135deg, var(--app-console-send-gradient-start), var(--app-console-send-gradient-end));
    color: var(--app-console-send-text);
    transition: transform 0.08s ease, filter 0.15s ease, opacity 0.15s ease;
}
.chat-send-btn:hover { filter: brightness(1.08); }
.chat-send-btn:active { transform: translateY(1px); }
.chat-send-btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.chat-attach-btn,
.chat-voice-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--app-console-border-control);
    border-radius: 9999px;
    background: var(--app-console-attach-surface);
    color: var(--app-account-text-body);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chat-attach-btn:hover,
.chat-voice-btn:hover {
    background: var(--app-console-attach-hover-surface);
    color: var(--app-account-text-interface);
    border-color: var(--app-console-attach-border-hover);
}
.chat-attach-btn:disabled,
.chat-voice-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.chat-voice-btn { flex-shrink: 0; }
.chat-voice-btn span { display: flex; }
.chat-voice-btn.is-recording,
.chat-voice-btn.is-processing {
    color: var(--app-account-action-text-hover);
    background: var(--app-console-accent-surface);
    border-color: var(--app-console-accent-border-hover);
    opacity: 1;
}
.chat-voice-btn:focus-visible { outline: 2px solid var(--app-console-accent-border-hover); outline-offset: 2px; }
.chat-voice-spinner {
    width: 16px;
    height: 16px;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: voice-spin 0.8s linear infinite;
}
.chat-voice-track {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    height: 2.6rem;
    padding: 0 12px;
    overflow: hidden;
    border: 1px solid var(--app-console-accent-border-hover);
    border-radius: 12px;
    background: var(--app-console-accent-surface);
    color: var(--app-account-action-text-hover);
}
.chat-voice-wave { display: flex; align-items: center; gap: 3px; width: 100%; height: 28px; }
.chat-voice-wave i {
    flex: 1;
    min-width: 1px;
    height: var(--level);
    border-radius: 9999px;
    background: currentColor;
    transition: height 65ms linear;
}
.chat-voice-track.is-processing .chat-voice-wave i {
    height: 16px;
    animation: voice-process 1s ease-in-out infinite;
    animation-delay: var(--delay);
}
@keyframes voice-spin { to { transform: rotate(360deg); } }
@keyframes voice-process { 0%, 100% { transform: scaleY(.2); opacity: .35; } 50% { transform: scaleY(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .chat-voice-wave i { transition: none; }
    .chat-voice-track.is-processing .chat-voice-wave i { animation: none; height: 3px; }
    .chat-voice-spinner { animation: none; }
}

/* Скроллбар истории чата убран — нет дёрганья при появлении. */
.chat-scroll-area {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chat-scroll-area::-webkit-scrollbar { display: none; }

/* Основной текст сообщений и вариантов формы использует общую типографику. */
.chat-scroll-area .markdown-content:not(.progress-info-markdown),
.chat-user-form .chat-user-form-toggle,
.chat-user-form .chat-user-form-select .agent-select-trigger,
.chat-user-form .chat-user-form-select .agent-select-trigger span,
.chat-user-form-select-menu {
    font-size: 0.85rem;
    line-height: 1.625;
}

/* Markdown внутри пузыря чата не должен расширять сообщение шире колонки. */
.chat-scroll-area .markdown-content {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
}
.chat-scroll-area .markdown-content pre {
    max-width: 100%;
    overflow-x: auto;
    white-space: pre;
    border-radius: 0.5rem;
    background: var(--app-console-chat-code-surface);
}
.chat-scroll-area .markdown-content pre code {
    display: block;
    min-width: max-content;
}
.chat-scroll-area .markdown-content :not(pre) > code {
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Размышление агента использует общий markdown-рендерер, но остаётся компактным
   элементом дерева прогресса до явного раскрытия пользователем. */
.progress-info-markdown {
    position: relative;
    font-size: 0.6875rem;
    line-height: 1.45;
}
.progress-info-markdown.is-collapsed {
    max-height: 4.35em;
    overflow: hidden;
}
.progress-info-markdown.is-collapsed::after {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 3rem;
    height: 1.45em;
    background: linear-gradient(to right, transparent, var(--app-console-progress-fade-surface) 75%);
    content: '';
    pointer-events: none;
}
.chat-scroll-area .progress-info-markdown h1,
.chat-scroll-area .progress-info-markdown h2,
.chat-scroll-area .progress-info-markdown h3,
.chat-scroll-area .progress-info-markdown h4 {
    margin: 0.45rem 0 0.2rem;
    font-size: 0.75rem;
    line-height: 1.35;
}
.chat-scroll-area .progress-info-markdown p,
.chat-scroll-area .progress-info-markdown ul,
.chat-scroll-area .progress-info-markdown ol,
.chat-scroll-area .progress-info-markdown blockquote,
.chat-scroll-area .progress-info-markdown pre,
.chat-scroll-area .progress-info-markdown .md-table-wrap {
    margin: 0.3rem 0;
}
.chat-scroll-area .progress-info-markdown ul,
.chat-scroll-area .progress-info-markdown ol {
    padding-left: 1rem;
}
.chat-scroll-area .progress-info-markdown li {
    margin: 0.1rem 0;
}
.chat-scroll-area .progress-info-markdown strong {
    font-weight: 600;
    color: var(--app-account-text-interface);
}
.chat-scroll-area .progress-info-markdown :not(pre) > code {
    padding: 0 0.15rem;
    border: 0;
    border-radius: 0.2rem;
    background: var(--app-console-workspace-hover);
    color: var(--app-account-text-body);
    font-size: 0.95em;
    line-height: inherit;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}
.chat-scroll-area .progress-info-markdown pre {
    padding: 0.45rem 0.55rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.chat-scroll-area .progress-info-markdown pre code {
    min-width: 0;
    white-space: inherit;
    font-size: 0.625rem;
}
.chat-scroll-area .progress-info-markdown table {
    font-size: 0.625rem;
}

/* Кнопка «вложения и режимы», пункт вложения в ней и чипы включённых режимов —
   только для узкого экрана: на широком видны отдельная скрепка и строка переключателей. */
button.chat-plus-btn,
button.chat-modes-attach,
div.chat-mode-chips {
    display: none;
}

/* ===== Мобильная адаптация (< lg): крупнее тач-таргеты, компактнее типографика ===== */
@media (max-width: 1023px) {
    /* Кнопки отправки/аттача — палец должен попадать уверенно. */
    .chat-send-btn,
    .chat-voice-btn,
    .chat-attach-btn {
        width: 2.75rem;
        height: 2.75rem;
        border-radius: 999px;
    }
    /* Заголовки в чате чуть меньше, чтобы не съедали узкий экран. */
    .markdown-content h1 { font-size: 1.2rem; }
    .markdown-content h2 { font-size: 1.05rem; }
    .markdown-content h3 { font-size: 0.98rem; }
    /* Тонкий видимый скроллбар для кода — на тач-экране полосу проще ухватить. */
    .chat-scroll-area .markdown-content pre {
        scrollbar-width: thin;
    }
}

@media (max-width: 640px) {
    /* Tailwind-утилиты подключаются рантаймом после файла, поэтому селекторы усилены тегом. */
    div.chat-bubble-assistant, div.chat-form-answer-bubble { width: 100%; max-width: 100%; }
    div.chat-bubble-user { max-width: 100%; }

    .chat-scroll-area .chat-progress-step {
        display: grid;
        grid-template-columns: 12px minmax(0, 1fr) auto;
        gap: 2px 8px;
        padding-block: 3px;
        line-height: 16px;
    }
    .chat-progress-step > div { grid-column: 2 / -1; }
    .chat-progress-step > .chat-progress-model { grid-column: 2; grid-row: 2; overflow-wrap: anywhere; }
    .chat-progress-step > span:last-child { grid-column: 3; grid-row: 2; }
    .chat-progress-step > div > div.truncate { white-space: normal; overflow-wrap: anywhere; }
    .chat-scroll-area .progress-info-markdown > :first-child { margin-top: 0; }
    .chat-scroll-area .progress-info-markdown > :last-child { margin-bottom: 0; }
    /* На узком экране лента важнее полей формы: вертикальные поля композера ужаты. */
    form.chat-composer {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    /* Меньше 16px мобильный Safari трактует как повод зазумить страницу при фокусе. */
    textarea.chat-message-input {
        font-size: 16px;
        line-height: 1.35;
        border-radius: 1.25rem;
    }

    /* Вложения и режимы живут в меню кнопки «+»: в строке остаются поле и отправка. */
    div.chat-modes {
        display: none;
    }

    div.chat-modes.open {
        position: absolute;
        left: 0.75rem;
        bottom: calc(100% - 0.5rem);
        z-index: 30;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 14px;
        width: max-content;
        max-width: calc(100vw - 1.5rem);
        min-width: 13rem;
        padding: 12px 14px;
        border-radius: 14px;
        border: 1px solid var(--app-console-border-control);
        background: var(--app-console-surface-raised);
        box-shadow: 0 16px 38px var(--app-console-menu-shadow);
    }

    div.chat-modes.open > label > span:last-child {
        font-size: 14px;
        color: var(--app-console-mobile-menu-text);
    }

    button.chat-modes-attach {
        display: inline-flex;
        align-items: center;
        gap: 10px;
        color: var(--app-console-mobile-menu-text);
        font-size: 14px;
    }

    button.chat-modes-attach svg {
        width: 1.05rem;
        height: 1.05rem;
        color: var(--app-account-text-secondary);
    }

    div.chat-modes.open .chat-model-mobile {
        display: flex;
        min-width: 0;
        max-width: 100%;
        width: 100%;
    }

    button.chat-plus-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.5rem;
        height: 2.5rem;
        flex: none;
        border-radius: 999px;
        color: var(--app-account-text-secondary);
        background: var(--app-console-surface-subtle);
    }

    button.chat-plus-btn svg {
        width: 1.3rem;
        height: 1.3rem;
    }

    button.chat-plus-btn.open {
        color: var(--app-console-text-body);
        background: var(--app-console-surface-active);
        transform: rotate(45deg);
    }

    /* Включённый режим виден без раскрытия меню. */
    button.chat-plus-btn.active {
        color: var(--app-accent-hover);
        background: var(--app-console-mode-active-surface);
    }

    /* Отдельная скрепка не нужна — она пунктом в меню «+». */
    button.chat-attach-btn {
        display: none;
    }

    div.chat-mode-chips {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    div.chat-mode-chips button {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 3px 8px 3px 10px;
        border-radius: 8px;
        border: 1px solid var(--app-console-mode-border);
        background: var(--app-console-accent-surface);
        color: var(--app-account-action-text-hover);
        font-size: 12px;
    }

    div.chat-mode-chips button svg {
        width: 12px;
        height: 12px;
        color: var(--app-console-chip-dismiss-text);
    }

    /* Пустое поле: кнопка отправки остаётся на виду, но приглушена и не нажимается —
       так понятно, куда отправлять, а пустое сообщение уйти не может. Появляется текст
       или вложение — кнопка становится активной. */
    form:not(.has-text) button.chat-send-btn {
        display: inline-flex;
        opacity: 0.45;
        pointer-events: none;
    }
}

/* ===== Изображения сообщений: превью-сетка и полноэкранный просмотр ===== */
.chat-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.chat-image-grid button {
    width: 108px;
    height: 108px;
    overflow: hidden;
    border: 1px solid var(--app-console-border-default);
    border-radius: 10px;
    background: var(--app-console-chat-code-surface);
    transition: border-color 0.15s ease, filter 0.15s ease;
}

.chat-image-grid button:hover {
    border-color: var(--app-console-accent-border-hover);
    filter: brightness(1.07);
}

.chat-image-grid img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
}

/* Картинки внутри markdown кликабельны и не растягивают ленту сообщений. */
.chat-scroll-area .markdown-content img {
    max-height: 18rem;
    width: auto;
    border: 1px solid var(--app-console-border-default);
    border-radius: 0.5rem;
    cursor: zoom-in;
    transition: border-color 0.15s ease, filter 0.15s ease;
}

.chat-scroll-area .markdown-content img:hover {
    border-color: var(--app-console-focus-ring);
    filter: brightness(1.08);
}

.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
    background: var(--app-console-image-overlay);
    backdrop-filter: blur(8px);
    user-select: none;
}

.chat-lightbox-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 56px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    border-bottom: 1px solid var(--app-console-border-default);
}

.chat-lightbox-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 999px;
    color: var(--app-account-text-body);
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-lightbox-btn:hover {
    background: var(--app-console-surface-hover);
    color: var(--app-console-text-strong);
}

.chat-lightbox-btn svg {
    width: 20px;
    height: 20px;
}

.chat-lightbox-stage {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
}

.chat-lightbox-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 24px 60px var(--app-console-image-shadow);
}

.chat-lightbox-nav {
    position: absolute;
    top: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    transform: translateY(-50%);
    border: 1px solid var(--app-console-border-default);
    border-radius: 999px;
    background: var(--app-console-code-inline-surface);
    color: var(--app-account-text-body);
    backdrop-filter: blur(4px);
}

.chat-lightbox-nav:hover {
    background: var(--app-console-image-navigation-hover-surface);
    color: var(--app-console-text-strong);
}

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

.chat-lightbox-nav.prev { left: 12px; }
.chat-lightbox-nav.next { right: 12px; }

/* На тач-экране листаем свайпом, стрелки нужны только на мыши. */
@media (min-width: 641px) {
    .chat-lightbox-nav { display: inline-flex; }
}

.chat-lightbox-strip {
    flex: none;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--app-console-border-default);
    scrollbar-width: thin;
}

.chat-lightbox-strip > div {
    display: flex;
    gap: 8px;
    width: max-content;
    margin: 0 auto;
}

.chat-lightbox-strip button {
    width: 56px;
    height: 56px;
    flex: none;
    overflow: hidden;
    border: 1px solid var(--app-console-border-default);
    border-radius: 10px;
    opacity: 0.55;
    transition: opacity 0.15s ease, border-color 0.15s ease;
}

.chat-lightbox-strip button.active {
    border-color: var(--app-console-thumbnail-active-border);
    opacity: 1;
}

.chat-lightbox-strip img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== Хештеги-уточнения ===== */
.chat-hashtag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chat-hashtag-chips.message {
    margin-top: 8px;
}

.chat-hashtag-chips span {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px 2px 8px;
    border: 1px solid var(--app-console-hashtag-border);
    border-radius: 8px;
    background: var(--app-console-accent-surface);
    color: var(--app-account-action-text-hover);
    font-size: 11.5px;
}

.chat-hashtag-chips.message span {
    padding: 2px 8px;
}

.chat-hashtag-chips button {
    display: grid;
    place-items: center;
    width: 18px;
    height: 18px;
    border-radius: 5px;
    color: var(--app-console-chip-dismiss-text);
}

.chat-hashtag-chips button:hover {
    color: var(--app-danger-text);
}

.chat-hashtag-chips svg {
    width: 11px;
    height: 11px;
}

.chat-hashtag-menu {
    position: absolute;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(100% - 0.5rem);
    z-index: 30;
    max-width: 28rem;
    overflow: hidden;
    border: 1px solid var(--app-console-border-default);
    border-radius: 12px;
    background: var(--app-console-suggestion-surface);
    box-shadow: 0 18px 40px var(--app-console-suggestion-shadow);
    backdrop-filter: blur(6px);
}

.chat-hashtag-menu > div {
    max-height: 16rem;
    overflow-y: auto;
    padding: 4px;
    scrollbar-width: thin;
}

.chat-hashtag-menu button {
    display: flex;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    padding: 7px 10px;
    border-radius: 8px;
    color: var(--app-console-text-body);
    text-align: left;
}

.chat-hashtag-menu button.active {
    background: var(--app-console-suggestion-active-surface);
    box-shadow: inset 0 0 0 1px var(--app-console-suggestion-active-border);
}

.chat-hashtag-menu button b {
    flex: none;
    font-size: 13px;
    font-weight: 600;
}

.chat-hashtag-menu button span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--app-console-suggestion-text-muted);
    font-size: 12px;
}

.chat-hashtag-menu p {
    padding: 8px 10px;
    color: var(--app-console-suggestion-text-muted);
    font-size: 12px;
}

/* ----- Панель регламентов агента в шапке чата ----- */
.console-chat-header { position: relative; }
.chat-sched { display: inline-flex; }
.chat-sched .tb-icon { position: relative; }
.chat-sched .tb-icon.active { background: var(--app-console-surface-hover); color: var(--app-account-text-interface); }

.chat-sched-count {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 14px;
    padding: 0 3px;
    border: 2px solid var(--app-account-panel-background);
    border-radius: 9999px;
    background: var(--app-account-accent);
    color: var(--app-accent-ink);
    font-size: 9px;
    font-weight: 600;
    line-height: 12px;
    text-align: center;
}

.chat-sched-panel {
    position: fixed;
    top: 120px;
    right: 16px;
    width: min(440px, calc(100vw - 32px));
    z-index: 50;
    max-height: min(560px, 70vh);
    overflow-y: auto;
    border: 1px solid var(--app-console-border-default);
    border-radius: 16px;
    background: var(--app-account-panel-background);
}

.chat-sched-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    border-bottom: 1px solid var(--app-console-border-default);
}

.chat-sched-title { color: rgb(var(--app-heading-rgb)); font-size: 16px; font-weight: 600; }

.chat-sched-total {
    flex: none;
    padding: 3px 12px;
    border-radius: 9999px;
    background: var(--app-console-surface-chip);
    color: var(--app-account-text-body);
    font-size: 13px;
}

.chat-sched-list { padding: 0 16px; }

.chat-sched-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid var(--app-console-border-default);
}
.chat-sched-item:last-child { border-bottom: 0; }

.chat-sched-item-main { display: flex; flex-direction: column; min-width: 0; }
.chat-sched-name { overflow: hidden; color: var(--app-account-text-interface); font-size: 14px; font-weight: 600; line-height: 1.4; text-overflow: ellipsis; white-space: nowrap; }
.chat-sched-schedule { margin-top: 4px; color: var(--app-account-text-secondary); font-size: 13px; }
.chat-sched-facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chat-sched-facts > span { display: inline-flex; align-items: center; gap: 6px; color: var(--app-account-text-meta); font-size: 12px; }
.chat-sched-facts svg { flex: none; color: var(--app-account-text-meta); }
.chat-sched-facts i { width: 6px; height: 6px; border-radius: 9999px; background: var(--app-account-text-meta); }
.chat-sched-facts .status-ok { padding: 3px 12px; border: 1px solid var(--app-console-success-border); border-radius: 9999px; background: var(--app-console-success-surface); color: var(--app-success-text); }
.chat-sched-facts .status-ok i { background: var(--app-account-success); }
.chat-sched-facts .status-error, .chat-sched-facts .status-no_access { padding: 3px 12px; border: 1px solid var(--app-console-error-border); border-radius: 9999px; background: var(--app-console-error-surface); color: var(--app-error-text); }
.chat-sched-facts .status-error i, .chat-sched-facts .status-no_access i { background: var(--app-account-danger); }
.chat-sched-facts .status-silent { padding: 3px 12px; border: 1px solid var(--app-console-info-border); border-radius: 9999px; background: var(--app-console-info-surface); color: var(--app-info-text); }
.chat-sched-facts .status-silent i { background: var(--app-console-info-indicator); }

.chat-sched-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--app-account-text-secondary);
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.chat-sched-delete:hover { background: var(--app-console-surface-hover); color: var(--app-account-text-interface); }
.chat-sched-delete:disabled { cursor: wait; opacity: 0.5; }

.chat-sched-empty { padding: 32px; color: var(--app-account-text-body); font-size: 14px; text-align: center; }
.chat-sched-loading { display: flex; gap: 8px; justify-content: center; padding: 32px; }
.chat-sched-loading span { width: 40px; height: 8px; border-radius: 6px; background: var(--app-console-surface-skeleton); animation: pulse 1.6s cubic-bezier(.4,0,.6,1) infinite; }

.chat-sched .tb-icon:focus-visible,
.chat-sched-delete:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--app-console-focus-ring);
}

.chat-sched-delete {
    width: 44px;
    height: 44px;
    margin: -6px;
}

@media (max-width: 640px) {
    .chat-sched-panel {
        position: fixed;
        top: auto;
        left: 8px;
        right: 8px;
        width: auto;
        bottom: calc(8px + env(safe-area-inset-bottom));
        z-index: 50;
        max-height: 72dvh;
    }
}

.chat-document-chips { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.chat-document-chip { display:inline-flex; min-width:0; max-width:16rem; align-items:center; border:1px solid var(--app-console-border-default); border-radius:8px; background:var(--app-console-document-chip-surface); color:var(--app-console-text-body); font-size:11px; }
.chat-document-chip a { display:flex; min-width:0; align-items:center; gap:6px; padding:4px 8px; color:inherit; }
.chat-document-chip a span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.chat-document-chip > button { padding:4px 7px; color:var(--app-account-text-secondary); }
@media (max-width: 640px) { .chat-image-grid button { width:84px; height:84px; } .chat-document-chip { max-width:13rem; } }

.chat-sched-history { padding: 16px; border-top: 1px solid var(--app-console-border-default); }
.chat-sched-history summary { cursor: pointer; color: var(--app-account-text-secondary); font-size: 13px; }
