/* Единый контракт областей чата. Все правила ограничены адаптером LibreChat. */
:root {
  --mtk-chat-target: 48px;
  --mtk-chat-gap: .5rem;
  --mtk-chat-radius: .75rem;
  --mtk-chat-visible-height: 100dvh;
  --mtk-chat-visible-top: 0px;
  --mtk-chat-root-height: 100dvh;
}
html.mtk-chat-active, .mtk-chat-active body { height: 100%; overflow: hidden; }
.mtk-chat-active #root {
  box-sizing: border-box;
  height: var(--mtk-chat-root-height);
  padding-top: var(--mtk-chat-visible-top);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.mtk-chat-active #root > .mtk-chat-app { flex: 1 1 0; min-height: 0; }
.mtk-chat-main.mtk-chat-main { min-height: 0; min-width: 0; overflow: hidden; }
.mtk-chat-layout.mtk-chat-layout { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; }
.mtk-chat-header.mtk-chat-header {
  position: relative;
  height: auto;
  min-height: calc(var(--mtk-chat-target) + 2 * var(--mtk-chat-gap));
  padding: max(var(--mtk-chat-gap), env(safe-area-inset-top)) max(var(--mtk-chat-gap), env(safe-area-inset-right)) var(--mtk-chat-gap) max(var(--mtk-chat-gap), env(safe-area-inset-left));
  gap: var(--mtk-chat-gap);
  background: var(--presentation, var(--surface-primary, #fff));
}
.mtk-chat-header .mtk-chat-title-path { flex: 1 1 0; min-width: 0; max-width: none; overflow: visible; }
.mtk-chat-header > .mtk-chat-title-path { width: 0; }
.mtk-chat-header [data-testid="model-selector-button"] { min-width: 0; max-width: 100%; }
.mtk-chat-header [data-testid="model-selector-button"] > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mtk-chat-header button, .mtk-chat-header a { flex-shrink: 0; }
.mtk-chat-body.mtk-chat-body { min-height: 0; min-width: 0; height: auto; overflow: hidden; }
.mtk-chat-message-region.mtk-chat-message-region { min-height: 0; min-width: 0; overflow: hidden; flex: 1 1 0; }
.mtk-chat-message-frame { display: grid; grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.mtk-chat-messages { grid-area: 1 / 1; min-height: 0; overscroll-behavior-y: contain; overflow-x: hidden; }
.mtk-chat-scroll-action.mtk-chat-scroll-action { position: static; grid-row: 2; grid-column: 1 / -1; width: 100%; max-width: none; padding-inline: var(--mtk-chat-gap); }
.mtk-chat-scroll-action .premium-scroll-button { min-width: var(--mtk-chat-target); min-height: var(--mtk-chat-target); margin: 0; }
@media (min-width: 768px) {
  .mtk-chat-message-frame:has(> nav[aria-keyshortcuts="Shift+Alt+M"]) { grid-template-columns: minmax(0, 1fr) var(--mtk-chat-target); }
  .mtk-chat-message-frame > nav[aria-keyshortcuts="Shift+Alt+M"] { position: static; grid-area: 1 / 2; align-self: center; justify-self: center; transform: none; max-height: 100%; }
}
.mtk-chat-message-content.mtk-chat-message-content { padding-top: var(--mtk-chat-gap); overflow-wrap: anywhere; }
.mtk-chat-composer { min-width: 0; flex: 0 0 auto; padding-bottom: env(safe-area-inset-bottom); }
.mtk-chat-toolbar { display: flex; flex: none; align-items: center; gap: var(--mtk-chat-gap); }
.mtk-chat-toolbar #mtk-collab-import-button { position: static; }
#mtk-chat-actions-button { display: none; }
.mtk-chat-compact #mtk-chat-actions-button {
  position: relative; display: grid; place-items: center;
  width: var(--mtk-chat-target); height: var(--mtk-chat-target);
  border: 1px solid var(--border-light, #d8e0df); border-radius: var(--mtk-chat-radius);
  background: var(--surface-primary, #fff); color: var(--text-primary, #17383a); cursor: pointer;
}
.mtk-chat-compact #open-sidebar-button, .mtk-chat-compact [data-testid="model-selector-button"] { min-height: var(--mtk-chat-target); height: var(--mtk-chat-target); margin-block: 0; }
.mtk-chat-compact #open-sidebar-button { min-width: var(--mtk-chat-target); width: var(--mtk-chat-target); padding: 0; }
.mtk-chat-compact #open-sidebar-button svg, .mtk-chat-compact [data-testid="model-selector-button"] svg { flex-shrink: 0; width: 24px; height: 24px; }
.mtk-chat-compact .mtk-chat-title-path { gap: var(--mtk-chat-gap); padding-inline: 0; margin-inline: 0; }
.mtk-chat-compact [data-testid="model-selector-button"] { font-size: 1rem; justify-content: flex-start; }
/* Родные триггеры остаются у React. Их прямоугольник — якорь для Ariakit;
 * доступное меню вызывает прежний обработчик. display:none дал бы якорь (0,0). */
.mtk-chat-compact .mtk-chat-action-source {
  position: absolute; inset-inline-end: 0; top: 0;
  width: var(--mtk-chat-target); height: var(--mtk-chat-target);
  opacity: 0; pointer-events: none;
}
.mtk-chat-has-unread::after { content: ''; position: absolute; right: 8px; top: 8px; width: 8px; height: 8px; border-radius: 50%; background: #b87800; }
.mtk-chat-actions {
  position: fixed; z-index: 40; box-sizing: border-box;
  width: min(22rem, calc(100vw - 1rem)); overflow: auto; overscroll-behavior: contain;
  padding: .25rem; border-radius: var(--mtk-chat-radius);
  background: var(--surface-primary, #fff); color: var(--text-primary, #17383a);
  box-shadow: 0 12px 32px rgb(0 0 0 / .22);
}
.mtk-chat-actions button {
  display: block; width: 100%; min-height: var(--mtk-chat-target); padding: .75rem;
  border: 0; border-radius: .5rem; background: transparent; color: inherit;
  font: inherit; line-height: 1.4; text-align: start; overflow-wrap: anywhere; cursor: pointer;
}
.mtk-chat-actions button:hover, .mtk-chat-actions button:focus-visible { background: var(--surface-hover, #edf4f3); }
.mtk-chat-actions button:disabled { opacity: .5; cursor: not-allowed; }
#mtk-chat-actions-button:focus-visible, .mtk-chat-actions button:focus-visible { outline: 2px solid var(--text-primary, #17383a); outline-offset: -3px; }
.mtk-chat-active [role="menu"], .mtk-chat-active [role="dialog"] { max-width: calc(100vw - 1rem); overflow-wrap: anywhere; }
.mtk-chat-active .mtk-notifications-panel { display: flex; flex-direction: column; max-height: calc(var(--mtk-chat-visible-height) - 1rem); }
.mtk-chat-active .mtk-notifications-panel-head, .mtk-chat-active .mtk-notifications-telegram { flex: none; }
.mtk-chat-active .mtk-notifications-list { min-height: 0; max-height: none; overflow: auto; }
@media (max-width: 1024px) {
  .mtk-chat-form.mtk-chat-form { margin-bottom: 0; }
  .mtk-chat-form [data-testid="text-input"] { font-size: 1rem; max-height: min(12rem, calc(var(--mtk-chat-visible-height) * .3)); }
  .mtk-chat-form [data-testid="text-input"]:placeholder-shown { max-height: 3.25rem; white-space: nowrap; }
  .mtk-chat-active #mtk-cost-toolbar button { min-height: var(--mtk-chat-target); }
  .mtk-chat-input-actions { align-items: center; gap: .25rem; }
  .mtk-chat-input-actions button { min-width: var(--mtk-chat-target); min-height: var(--mtk-chat-target); flex-shrink: 0; }
  .mtk-chat-input-actions > * { min-width: 0; }
  .mtk-chat-active .mtk-ci-overlay { top: var(--mtk-chat-visible-top); bottom: auto; height: var(--mtk-chat-visible-height); padding: max(.5rem, env(safe-area-inset-top)) .5rem max(.5rem, env(safe-area-inset-bottom)); }
  .mtk-chat-active .mtk-ci-dialog { max-height: 100%; padding: 1rem; font-size: 1rem; }
  .mtk-chat-active .mtk-ci-dialog input, .mtk-chat-active .mtk-ci-dialog select, .mtk-chat-active .mtk-ci-dialog button { min-height: var(--mtk-chat-target); }
  .mtk-chat-active .mtk-ci-actions button { max-width: 100%; white-space: normal; }
}
