/* Геометрия и цвета сняты с финальных правил макета chat.css (17.10.2026).
   Отдельный слой не меняет обработчики отправки, вложений и камеры. */
#chat-section .input-wrapper {
    display: flex; position: relative; transform: none;
    box-sizing: border-box; width: min(calc(100% - var(--composer-desktop-gutter) * 2), var(--composer-max-width));
    max-width: var(--composer-max-width); margin: var(--space-2) auto var(--space-3); min-height: 0; padding: var(--composer-inset);
    align-items: flex-end; gap: var(--composer-inset); border: 0; border-radius: var(--ui-radius);
    background: var(--composer-surface); box-shadow: none; font-size: var(--font-base); line-height: var(--composer-menu-line);
}
#chat-section .input-wrapper:focus-within { border: 0; box-shadow: none; }
#chat-section .message-input-container { display: contents; }
#chat-section .message-input {
    display: block; flex: 1; min-width: 0; box-sizing: border-box; resize: none;
    min-height: var(--composer-control); max-height: min(25svh, var(--composer-text-cap));
    padding: calc((var(--composer-control) - 1lh) / 2) var(--space-2); border: 0; border-radius: 0;
    background: transparent; color: var(--composer-text-ink); font-family: var(--font-sans);
    font-size: var(--font-label); line-height: var(--composer-text-line); outline: none; box-shadow: none;
    overflow-wrap: anywhere;
}
#chat-section .message-input:focus, #chat-section .message-input:focus-visible { background: transparent; box-shadow: none; }
#chat-section .message-input::placeholder { color: var(--composer-placeholder); opacity: 1; }
#chat-section .input-actions-inline { display: flex; flex-shrink: 0; gap: var(--composer-inset); align-self: flex-end; position: static; margin: 0; padding: 0; }
#chat-section :is(.hint-icon, .btn-voice, .btn-send) {
    display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-sizing: border-box;
    width: var(--composer-control); height: var(--composer-control); min-width: var(--composer-control);
    padding: 0; border: 0; border-radius: 50%; box-shadow: none; cursor: pointer; color: var(--composer-icon-ink);
    background: transparent; transform: none; opacity: 1; font-family: var(--font-sans); font-size: var(--font-base); line-height: var(--composer-button-line);
}
#chat-section .hint-icon { margin-left: calc(-1 * var(--composer-inset)); }
#chat-section .hint-icon:hover, #chat-section .hint-icon[aria-expanded="true"], #chat-section .btn-voice:hover { color: var(--primary); transform: none; opacity: 1; }
#chat-section .btn-send, body.dark-theme #chat-section .btn-send { color: var(--composer-send-ink); background: var(--primary); }
#chat-section .btn-voice.listening { color: var(--error); }
#chat-section :is(.composer-attach-icon, .composer-voice-icon, .composer-send-icon) {
    display: block; width: var(--space-5); height: var(--space-5); flex-shrink: 0; background: currentColor;
    mask: var(--composer-icon) center / contain no-repeat; -webkit-mask: var(--composer-icon) center / contain no-repeat;
}
.composer-attach-icon { --composer-icon: url('/static/images/icons/attach.svg'); }
.composer-voice-icon { --composer-icon: url('/static/images/icons/microphone.svg'); }
.composer-send-icon { --composer-icon: url('/static/images/icons/send.svg'); }
#chat-section .btn-all-features { position: static; transform: none; margin: var(--space-3) auto 0; height: var(--composer-link-height); min-height: var(--composer-link-height); line-height: var(--composer-menu-line); color: var(--composer-icon-ink); flex-shrink: 0; }
#upload-modal.upload-popover {
    box-sizing: border-box; width: max-content; min-width: 0; max-width: calc(100vw - var(--composer-menu-inset) * 2);
    max-height: calc(100svh - var(--composer-menu-inset) * 2); overflow-y: auto;
    padding: var(--space-2); border: var(--hairline) solid var(--composer-menu-border); border-radius: var(--ui-radius);
    background: var(--composer-menu-surface); box-shadow: var(--composer-menu-shadow);
    backdrop-filter: none; -webkit-backdrop-filter: none; animation: none; color: var(--composer-text-ink);
}
#upload-modal .upload-buttons { display: block; }
#upload-modal .upload-btn {
    display: block; box-sizing: border-box; width: 100%; min-height: var(--control-height);
    padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--ui-radius);
    background: transparent; color: var(--composer-text-ink); font-family: var(--font-sans);
    font-size: var(--font-base); line-height: var(--composer-menu-line); font-weight: 400; text-align: left;
}
#upload-modal .upload-btn:hover, #upload-modal .upload-btn:focus-visible { background: var(--composer-surface); }
#upload-modal .upload-btn:active { transform: none; }
@media (max-width: 768px) {
    #chat-section .input-wrapper { width: calc(100% - var(--space-2) * 2); gap: 0; margin-bottom: var(--space-2); }
    #chat-section .message-input { min-height: var(--composer-phone-control); max-height: min(25svh, var(--composer-phone-cap)); padding: calc((var(--composer-phone-control) - 1lh) / 2) var(--composer-inset); font-size: var(--font-base); line-height: var(--composer-phone-line); }
    #chat-section :is(.hint-icon, .btn-voice, .btn-send) { width: var(--composer-phone-control); height: var(--composer-phone-control); min-width: var(--composer-phone-control); }
}

/* Состояния диктовки и вложений используют те же поверхности, что и поле. */
#chat-section .btn-voice.listening { background: var(--composer-surface); animation: none; box-shadow: none; }
#chat-section .btn-voice.listening .composer-voice-icon { mask: none; -webkit-mask: none; width: var(--space-3); height: var(--space-3); border-radius: var(--hairline); }
#chat-section .btn-voice:disabled { opacity: var(--composer-disabled-opacity); cursor: not-allowed; }
.composer-status { width: min(calc(100% - var(--space-4) * 2), var(--composer-max-width)); margin: var(--space-2) auto 0; box-sizing: border-box; padding: var(--space-2) var(--space-3); border-radius: var(--ui-radius); background: var(--composer-surface); color: var(--text-secondary); font-size: var(--font-label); overflow-wrap: anywhere; }
.composer-status[hidden] { display: none; }
.composer-status.is-error { color: var(--error); }
#chat-section .attached-files-container { width: min(calc(100% - var(--space-2) * 2), var(--composer-max-width)); flex-wrap: wrap; gap: var(--space-2); }
#chat-section .attached-file-item { flex: 0 1 auto; min-width: 0; gap: var(--space-2); padding: var(--space-2) var(--space-3); background: var(--composer-surface); animation: none; transition: none; font-size: var(--font-label); }
#chat-section .attached-file-item:hover { background: var(--composer-surface); border-color: transparent; }
#chat-section .file-name { max-width: none; }
#chat-section .file-size { font-size: var(--font-caption); }
#chat-section .file-remove-btn { width: var(--control-compact); height: var(--control-compact); min-width: var(--control-compact); min-height: var(--control-compact); border-radius: var(--ui-radius); color: var(--text-secondary); font-size: var(--space-5); }
#chat-section .file-remove-btn:hover { background: var(--bg-hover); color: var(--text); }
/* Заголовок занимает доступную ширину: Контекст всегда у правого края. */
.main-content.chat-active .chat-heading { flex: 1; }
.main-content.chat-active .chat-current-title { flex: 1; min-width: 0; }
.chat-context-btn { margin-left: auto; min-height: var(--control-compact); padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--ui-radius); background: var(--primary); color: var(--on-primary); font-family: var(--font-sans); font-size: var(--font-label); }
.chat-context-btn:hover { background: var(--primary); color: var(--on-primary); }
@media (max-width: 768px) {
    .chat-context-btn { padding-inline: var(--space-2); font-size: var(--font-caption); }
}

/* Контекст: компактное чтение и отдельная форма, как signal-context-dialog макета. */
.app-dialog.signal-context { box-sizing: border-box; width: min(var(--signal-context-width), calc(100vw - var(--space-4) * 2)); max-height: calc(100svh - var(--space-4) * 2); padding: var(--space-4); background: var(--composer-menu-surface); border: var(--hairline) solid var(--composer-menu-border); border-radius: var(--ui-radius); color: var(--text); overflow-y: auto; }
.signal-context-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.signal-context-head .app-dialog-title { margin: 0; font-size: var(--font-lead); font-weight: 500; color: var(--primary); }
.signal-context-close { display: grid; place-items: center; flex-shrink: 0; width: var(--signal-context-control); height: var(--signal-context-control); padding: 0; border: 0; border-radius: var(--ui-radius); background: transparent; color: var(--text-secondary); font: inherit; font-size: var(--space-5); cursor: pointer; }
.signal-context .app-dialog-text { margin: 0 0 var(--space-3); color: var(--text-secondary); font-size: var(--font-label); line-height: var(--composer-menu-line); }
.signal-context-readout { display: grid; gap: var(--space-3); }
.signal-context-readout section { padding: var(--space-3); border-radius: var(--ui-radius); background: var(--composer-surface); }
.signal-context-readout h3 { margin: 0 0 var(--space-2); color: var(--primary); font-size: var(--font-label); font-weight: 500; }
.signal-context-readout p { margin: 0; font-size: var(--font-label); line-height: var(--composer-menu-line); white-space: pre-wrap; overflow-wrap: anywhere; }
.signal-context-readout .is-empty { color: var(--text-secondary); }
.signal-context-edit { min-height: var(--signal-context-control); padding: 0; border: 0; background: transparent; color: var(--primary); font: inherit; font-size: var(--font-caption); cursor: pointer; }
.signal-context-field { margin-top: var(--space-3); gap: var(--space-2); color: var(--text-secondary); font-weight: 400; }
.signal-context-field textarea { min-height: var(--signal-context-field-height); max-height: 40svh; padding: var(--space-3); border: 0; background: var(--composer-surface); color: var(--text); font-size: var(--font-base); line-height: var(--composer-text-line); outline: none; box-shadow: none; }
.signal-context-field textarea::placeholder { color: var(--composer-placeholder); opacity: 1; }
.signal-context-field textarea:focus-visible { outline: none; box-shadow: none; }
.signal-context .app-dialog-actions { margin-top: var(--space-3); gap: var(--space-2); justify-content: flex-end; flex-wrap: nowrap; }
.signal-context .app-dialog-btn { min-height: var(--signal-context-control); padding: var(--space-2) var(--space-3); font-size: var(--font-label); border: 0; background: var(--composer-surface); }
.signal-context .app-dialog-btn.is-primary { background: var(--primary); color: var(--on-primary); }
.signal-context [hidden] { display: none !important; }

/* Камера — только мобильное системное действие; на ПК пункт отсутствует. */
@media (min-width: 769px){#upload-modal .upload-btn--camera{display:none}}

/* Контекст сигнала использует согласованную оболочку формы. */
.app-dialog.signal-context{width:min(var(--app-dialog-width),100%);padding:var(--space-3);border:0;box-shadow:none;border-radius:var(--ui-radius);background:var(--modal-form-surface)}
.signal-context-head{gap:var(--space-3);margin-bottom:var(--space-4)}
.signal-context-head .app-dialog-title{font-size:var(--space-5);font-weight:600;line-height:var(--text-title-lh);margin:0;color:var(--primary)}
.signal-context-close{width:var(--co-button-height);height:var(--co-button-height);display:grid;place-items:center}
.signal-context-close svg{width:var(--icon-size);height:var(--icon-size)}
.signal-context-readout{gap:var(--space-4);margin-block:var(--space-4)}
.signal-context-readout section{padding:var(--space-3);background:var(--modal-form-field)}
.signal-context .signal-context-edit{width:100%;height:var(--co-button-height);padding-inline:var(--space-3);border-radius:var(--ui-radius);background:var(--bg-card);color:var(--text);font-size:var(--font-label);font-weight:400}
.signal-context .signal-context-edit:is(:hover,:focus-visible){color:var(--primary)}
.signal-context-field{display:grid;gap:var(--space-2);margin-top:var(--space-4)}
.signal-context-field textarea{box-sizing:border-box;width:100%;min-height:var(--control-height);max-height:none;padding:var(--space-3);border-radius:var(--ui-radius);background:var(--modal-form-field);resize:none;font-size:var(--font-label);overflow:hidden}
.signal-context-field textarea:is(:hover,:focus){background:var(--modal-form-field-hover)}
.signal-context-field textarea::placeholder{color:var(--text-muted);opacity:.25}
.signal-context .app-dialog-actions{margin-top:var(--space-4)}
.signal-context .app-dialog-btn.is-primary{width:100%;height:var(--co-button-height);padding-inline:var(--space-3);border:0;font-size:var(--font-label);font-weight:600;color:var(--on-primary)}
.signal-context .app-dialog-btn.is-primary:is(:hover,:active,:focus-visible){background:var(--primary-light);color:var(--on-primary)}
@media(max-width:768px){.signal-context-head .app-dialog-title{line-height:1.15}}

/* Прокрутка всего длинного окна, поля растут по содержимому. */
.app-dialog-overlay:has(.signal-context){overflow-y:auto;align-items:flex-start}
.app-dialog-overlay>.signal-context{height:auto;max-height:none;overflow:visible;flex-shrink:0;margin-block:auto}

/* Выбор базы расположен в том же ряду, что прикрепление файла. */
#chat-section .composer-source {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 var(--composer-control); width: var(--composer-control); height: var(--composer-control);
  padding: 0; border: 0; border-radius: 50%; background: transparent;
  color: var(--composer-icon-ink); cursor: pointer;
}
#chat-section .composer-source + .hint-icon { margin-left: 0; }
#chat-section .composer-source:hover,
#chat-section .composer-source[aria-expanded="true"] { color: var(--primary); }
.composer-sources {
  position: fixed; z-index: 1200; box-sizing: border-box;
  width: min(280px, calc(100vw - 16px)); padding: 6px;
  overflow-y: auto; border-radius: 16px;
  background: var(--action-menu-surface); color: var(--composer-text-ink);
  box-shadow: 0 3px 12px #0001; overscroll-behavior: contain;
}
.composer-sources > strong { display: block; padding: 8px 10px 4px; font-size: 13px; line-height: 1.4; }
.composer-source-option {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  border: 0; border-radius: 10px; padding: 8px 10px; min-height: 40px;
  color: inherit; background: transparent; text-align: left;
  font-family: var(--font-sans); font-size: 14px; line-height: 1.4; font-weight: 400;
  overflow-wrap: anywhere; cursor: pointer;
}
.composer-source-option::after {
  content: ''; margin-left: auto; flex: 0 0 3px; height: 18px;
  border-radius: 2px; background: transparent;
}
.composer-source-option[aria-checked="true"]::after { background: var(--primary); }
.composer-source-option { transition: background-color 150ms ease; }
.composer-source-option:focus-visible { background: var(--action-menu-hover); }
@media (hover: hover) {
  .composer-source-option:hover { background: var(--action-menu-hover); }
  body.dark-theme .composer-source-option:not(.is-readonly):hover { background: color-mix(in srgb, var(--action-menu-surface) 85%, white); }
}
body.dark-theme .composer-source-option:not(.is-readonly):focus-visible { background: color-mix(in srgb, var(--action-menu-surface) 85%, white); }
@media (prefers-reduced-motion: reduce) { .composer-source-option { transition: none; } }
@media (max-width: 768px) {
  #chat-section .composer-source { flex-basis: var(--composer-phone-control); width: var(--composer-phone-control); height: var(--composer-phone-control); }
}

#chat-section .composer-source svg { width: var(--space-5); height: var(--space-5); }

/* Компактное пустое состояние меню источников. */
.composer-sources.is-empty { width: min(248px, calc(100vw - 16px)); padding: 6px; border-radius: 16px; }
.composer-sources.is-empty .composer-sources-empty { margin: 0; padding: 8px 10px 6px; color: var(--text-secondary); font-size: 13px; font-weight: 400; line-height: 1.4; }
.composer-sources.is-empty .composer-sources-connect { display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: 100%; min-height: 40px; margin: 0; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--composer-text-ink); font-family: var(--font-sans); font-size: var(--font-label); font-weight: 400; line-height: 1.4; text-align: left; cursor: pointer; }
.composer-sources-connect svg { width: 18px; height: 18px; flex: 0 0 18px; }
.composer-sources.is-empty .composer-sources-connect:hover, .composer-sources.is-empty .composer-sources-connect:focus-visible { background: var(--action-menu-hover); }

.composer-sources.is-readonly { width: min(280px, calc(100vw - 16px)); padding: 6px; border-radius: 16px; }
.composer-sources.is-readonly > strong { font-size: 13px; line-height: 1.4; padding: 8px 10px 4px; }
.composer-sources .composer-source-option.is-readonly { font-size: 14px; line-height: 1.4; padding: 8px 10px; cursor: default; background: transparent; }
.composer-source-option.is-readonly::after { display: none; }
.composer-sources.is-readonly .composer-sources-empty { margin: 0; padding: 6px 10px 8px; font-size: 13px; line-height: 1.4; color: var(--text-secondary); }

.composer-source-logo { width: 20px; height: 20px; flex: 0 0 20px; object-fit: contain; }
.composer-source-name { min-width: 0; overflow-wrap: anywhere; }

.composer-source-group { padding: var(--space-2) var(--space-3); font-size: var(--font-caption); color: var(--text-secondary); font-weight: 500; }

.composer-source-notice {
    position: fixed;
    z-index: 1200;
    transform: translateX(-50%);
    width: max-content;
    max-width: min(360px, calc(100vw - 24px));
    box-sizing: border-box;
    padding: 10px 14px;
    border-radius: 14px;
    background: var(--bg-card);
    color: var(--text);
    box-shadow: var(--shadow-card);
    font-size: 13px;
    line-height: 1.45;
    pointer-events: none;
}

.composer-source-notice {
    animation: composer-source-notice-fade 5500ms ease-in-out both;
}
@keyframes composer-source-notice-fade {
    0%, 100% { opacity: 0; transform: translate(-50%, 5px); }
    8%, 90% { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .composer-source-notice { animation: none; }
}

/* Выбор подключений: спокойная подсветка всей строки без отдельного значка. */
.composer-source-option::after { display: none; }
.composer-source-option[aria-checked="true"] {
  background: color-mix(in srgb, var(--primary) 13%, var(--action-menu-surface));
  color: var(--primary);
}
.composer-source-option[aria-checked="true"]:focus-visible {
  background: color-mix(in srgb, var(--primary) 20%, var(--action-menu-surface));
}
@media (hover: hover) {
  .composer-source-option[aria-checked="true"]:hover,
  body.dark-theme .composer-source-option[aria-checked="true"]:not(.is-readonly):hover {
    background: color-mix(in srgb, var(--primary) 20%, var(--action-menu-surface));
  }
}
body.dark-theme .composer-source-option[aria-checked="true"]:not(.is-readonly):focus-visible {
  background: color-mix(in srgb, var(--primary) 20%, var(--action-menu-surface));
}

.message-actions { flex-wrap: wrap; }
.message-answer-sources { font-size: 12px; line-height: 1.4; color: var(--text-secondary); font-weight: 400; min-width: 0; overflow-wrap: anywhere; padding: 4px 6px; max-width: 100%; }

/* Панель ответа сохраняет место, чтобы при появлении не двигать переписку. */
.has-answer-actions > .message-actions { width:100%; opacity:0; pointer-events:none; transition:opacity 240ms ease; }
.has-answer-actions.show-answer-actions > .message-actions,
.has-answer-actions:focus-within > .message-actions { opacity:1; pointer-events:auto; }
@media (hover:hover) { .has-answer-actions:hover > .message-actions { opacity:1; pointer-events:auto; } }
.message-answer-sources { margin-left:auto; display:flex; justify-content:flex-end; align-items:center; flex-wrap:wrap; gap:4px 7px; flex:1; text-align:right; }
.message-answer-source { display:inline-flex; align-items:center; gap:4px; min-width:0; overflow-wrap:anywhere; }
.message-answer-source img { width:16px; height:16px; object-fit:contain; flex-shrink:0; }
@media(max-width:480px) { .message-answer-sources { flex-basis:calc(100% - 120px); font-size:11px; } }
@media(prefers-reduced-motion:reduce) { .has-answer-actions > .message-actions { transition:none; } }

.message-sources-mobile { display:none; }
@media(max-width:600px) {
  .message-actions > .message-answer-sources { display:none; }
  .message-sources-mobile { display:block; margin-left:auto; min-width:0; }
  .message-sources-mobile summary { display:flex; align-items:center; justify-content:flex-end; gap:5px; padding:8px 0 8px 4px; color:var(--text-secondary); font-size:11px; line-height:1.4; cursor:pointer; list-style:none; white-space:nowrap; }
  .message-sources-mobile summary::-webkit-details-marker { display:none; }
  .message-sources-mobile img { width:14px; height:14px; object-fit:contain; flex-shrink:0; }
  .message-sources-list { position:absolute; z-index:20; bottom:100%; right:0; box-sizing:border-box; width:min(280px,100%); max-height: min(260px,45dvh); overflow:auto; padding:10px; border-radius:14px; background:var(--action-menu-surface,var(--bg-card)); box-shadow:0 6px 24px #0003; text-align:left; }
  .message-sources-list .message-answer-source { display:flex; gap:8px; padding:7px 4px; color:var(--text-secondary); font-size:12px; line-height:1.4; }
  .has-answer-actions:has(.message-sources-mobile[open]) > .message-actions { opacity:1; pointer-events:auto; }
}

@media(max-width:600px) {
  .message-sources-mobile { max-width:100%; }
  .message-sources-mobile summary { flex-wrap:wrap; }
  .message-sources-mobile summary > span { white-space:nowrap; }
}

/* Телефон: текст занимает всю ширину, инструменты находятся под ним. */
@media(max-width:768px) {
  #chat-section .input-wrapper.is-expanded { display:grid; grid-template-columns:auto auto 1fr auto; grid-template-rows:auto auto; align-content:end; column-gap:0; row-gap:4px; padding:var(--composer-inset); }
  #chat-section .input-wrapper.is-expanded .message-input { grid-row:1; grid-column:1 / -1; width:100%; min-height:40px; max-height:min(25svh,144px); padding:8px; line-height:24px; font-size:16px; }
  #chat-section .input-wrapper.is-expanded .composer-source { grid-row:2; grid-column:1; }
  #chat-section .input-wrapper.is-expanded .hint-icon { grid-row:2; grid-column:2; margin:0; }
  #chat-section .input-wrapper.is-expanded .input-actions-inline { grid-row:2; grid-column:4; }
}
