/* ============================================================================
   PeremenaChat — единая лента диалога «клиент ↔ психолог»
   (REQ-2026-12-02-chat-psychologist, R16/R17). Подключают /booking/ и /pro/
   вместе с chat.js: ленту рисует движок, страница даёт только контейнер.

   Размеры и отступы .pm-chat-* — копия ленты поддержки клиента
   (frontend/booking/index.html): .sup-msg, .sup-bubble, .sup-message-author,
   .sup-meta, .sup-day, .sup-composer, .sup-input-row, .sup-round-btn,
   .sup-hint. Каждое значение задано целиком — включая те, что у поддержки
   приходят из элементных правил textarea и сброса `*`: движок выглядит
   одинаково в любом приложении-хосте (у /pro/ свои textarea и свои .sup-*).

   Изменение файла — с поднятием ?v= во всех приложениях, где он подключён
   (прод-nginx держит /assets/ в кэше 7 дней).
   ========================================================================== */

/* Корень движка: заполняет контейнер хоста (у контейнера должна быть
   определённая высота — фиксированный экран или flex-пункт с min-height:0;
   процентная высота от auto-родителя даёт 0px при «живом» DOM). */
.pm-chat {
    display: flex; flex-direction: column; flex: 1 1 auto;
    height: 100%; min-height: 0;
    font-family: 'Manrope', sans-serif; color: #262626;
}

/* --- лента: внутренний скрол сообщений (как #supThreadMsgs) --- */
.pm-chat-feed {
    flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain; overflow-anchor: none;
}
/* без якорения прокрутки: когда поле ввода растёт, WebKit сам сдвигает прокрутку
   ленты на величину перестройки — последняя строка уходила под край */
.pm-chat-feed * { overflow-anchor: none; }
.pm-chat-feed, .pm-chat-bubble, .pm-chat-meta {
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
/* короткая переписка стоит вплотную к полю ввода, а не растягивается по высоте */
.pm-chat-list { display: flex; flex-direction: column; min-height: 100%; padding-bottom: 4px; }
.pm-chat-list::before { content: ''; flex: 1; }
/* сообщения лежат в блочной обёртке (как блоки обращений у поддержки): вертикальные
   отступы «сообщение → разделитель дня → сообщение» схлопываются так же, как там */
.pm-chat-flow { display: block; }

/* подгрузка старых сообщений */
.pm-chat-earlier {
    align-self: center; margin: 4px 0 8px; padding: 8px 16px;
    border: 1.5px solid rgba(168, 165, 242, 0.5); border-radius: 100px;
    background: transparent; color: #262626;
    font-family: 'Rubik', sans-serif; font-weight: 600; font-size: 13px; line-height: 1.2;
    cursor: pointer;
}
.pm-chat-earlier:disabled { opacity: 0.45; cursor: default; }
/* сбой подгрузки старых: строка под кнопкой, повтор — новым нажатием */
.pm-chat-earlier-error { margin: -4px 0 8px; color: #c0392b; text-align: center; font-size: 12.5px; line-height: 1.4; }

.pm-chat-day {
    margin: 10px 0 12px; color: #6c6573; text-align: center;
    font-size: 12px; font-weight: 600;
}

/* --- сообщения: свои справа, собеседника слева --- */
.pm-chat-msg { display: flex; margin-bottom: 8px; }
.pm-chat-msg.mine { justify-content: flex-end; }
.pm-chat-msg.theirs { justify-content: flex-start; }
.pm-chat-msg.continued { margin-top: -4px; }
.pm-chat-bubble {
    max-width: 83%; border: 1px solid transparent; border-radius: 18px;
    padding: 9px 12px 7px; color: #262626;
    font-size: 15px; line-height: 1.4; overflow-wrap: anywhere;
}
.pm-chat-msg.mine .pm-chat-bubble { background: #e4daf9; border-bottom-right-radius: 6px; }
.pm-chat-msg.theirs .pm-chat-bubble { background: #fff; border-color: #eee8f4; border-bottom-left-radius: 6px; }
.pm-chat-text { white-space: pre-wrap; }
.pm-chat-author { margin-bottom: 3px; color: #31274a; font-size: 12px; font-weight: 600; }
.pm-chat-meta {
    display: block; margin-top: 4px; color: #645b70; font-size: 11px; text-align: right;
    font-variant-numeric: tabular-nums;
}
/* короткое сообщение без переносов: время в той же строке */
.pm-chat-bubble.compact .pm-chat-line {
    display: flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end;
    gap: 0 10px;
}
.pm-chat-bubble.compact .pm-chat-text { margin-inline-end: auto; }
.pm-chat-bubble.compact .pm-chat-meta { flex: none; margin-top: 0; }

/* --- пустая переписка --- */
.pm-chat-empty {
    display: flex; min-height: 100%; flex-direction: column; justify-content: center;
    align-items: center; gap: 10px; padding: 8px 0 16px; text-align: center;
}
.pm-chat-empty p { max-width: 284px; margin: 0; color: #55505c; font-size: 15px; line-height: 1.45; }

/* --- загрузка / сбой открытия (на месте ленты) --- */
.pm-chat-state {
    display: flex; min-height: 100%; flex-direction: column; justify-content: center;
    align-items: center; gap: 12px; padding: 8px 16px 16px; text-align: center;
    color: #55505c; font-size: 15px; line-height: 1.45;
}
.pm-chat-retry {
    padding: 10px 20px; border: 1.5px solid rgba(168, 165, 242, 0.5); border-radius: 100px;
    background: transparent; color: #262626;
    font-family: 'Rubik', sans-serif; font-weight: 600; font-size: 14px; line-height: 1.2;
    cursor: pointer;
}

/* --- сообщение об ошибке над полем ввода (как .result-message.error) --- */
.pm-chat-notice {
    flex: none; margin: 0 0 8px; padding: 10px 16px; border-radius: 14px;
    background: rgba(236, 87, 87, 0.12); color: #c0392b;
    font-size: 13.5px; font-weight: 500; line-height: 1.4; text-align: center;
}

/* --- поле ввода и отправка (как .sup-composer / .sup-input-row / .sup-round-btn) --- */
.pm-chat-composer { flex: none; margin-top: 8px; }
.pm-chat-input-row { position: relative; display: flex; align-items: flex-end; gap: 8px; }
.pm-chat-input {
    flex: 1; min-width: 0; width: 100%; min-height: 44px; max-height: min(132px, 36vh);
    margin: 0; padding: 10px 14px; overflow-y: auto; overscroll-behavior: contain;
    border: 2px solid rgba(168, 165, 242, 0.35); border-radius: 22px;
    background: #fff; color: #262626; outline: none; resize: none;
    font-family: 'Manrope', sans-serif; font-size: 16px; font-weight: 400; line-height: 1.35;
    caret-color: #3f8ae0; box-sizing: border-box; scrollbar-width: none;
}
.pm-chat-input:focus { border-color: #a8a5f2; background: #ffffff; }
.pm-chat-input::placeholder { color: #746c80; opacity: 0.7; text-indent: 2px; }
.pm-chat-send {
    display: grid; place-items: center; flex: 0 0 auto; flex-shrink: 0;
    width: 44px; height: 44px; margin: 0; padding: 0;
    border: none; border-radius: 50%; background: #a8a5f2; color: #31274a; cursor: pointer;
}
.pm-chat-send:active { transform: scale(.94); }
.pm-chat-send:disabled { background: #e8e0f3; color: #716781; cursor: default; }
/* «лифт» длинного текста в поле: виден только при прокрутке, когда текст не вмещается */
.pm-chat-scroll-hint {
    position: absolute; top: 6px; bottom: 6px; right: 56px; width: 3px; border-radius: 2px;
    background: rgba(38, 38, 38, 0.22); opacity: 0; transition: opacity .25s ease;
    pointer-events: none;
}
.pm-chat-scroll-hint.on { opacity: 1; }
.pm-chat-hint { margin: 7px 0 0; color: #685b91; text-align: center; font-size: 12px; line-height: 1.4; }

/* --- диалог только для чтения: вместо поля ввода --- */
.pm-chat-locked {
    flex: none; margin-top: 8px; padding: 12px 16px; border-radius: 14px;
    background: #efecfa; color: #595463; text-align: center; font-size: 14px; line-height: 1.45;
}
.pm-chat-locked-title { color: #5551b9; font-weight: 600; }
.pm-chat-locked-title + .pm-chat-locked-note { margin-top: 3px; }

.pm-chat-notice[hidden], .pm-chat-composer[hidden], .pm-chat-locked[hidden] { display: none; }
