/* ============================================================
   server/public/css/style.css
   Структура:
     1. Переменные (дизайн-токены)
     2. Сброс и база
     3. Общие компоненты (кнопки, поля)
     4. Логин
     5. Мессенджер: layout, sidebar, chat, composer
     6. Сообщения
     7. Модалка
     8. Оверлей звонка
     9. Индикатор соединения
    10. Toast
    11. Медиа-запросы (адаптив, hover/touch, reduced-motion)
   ============================================================ */

/* ------------------------------------------------------------
   1. Переменные (дизайн-токены)
   ------------------------------------------------------------ */
:root {
    /* --- Цвета: база --- */
    --bg: #0f1115;
    --surface: #1a1d23;
    --surface-2: #232730;
    --surface-hover: #2d323d;
    --text: #e6e8eb;
    --text-muted: #9aa0a6;

    /* --- Цвета: акценты --- */
    --primary: #4c8dff;
    --primary-hover: #3a7aeb;
    --danger: #e5484d;
    --danger-hover: #f5585d;
    --success: #22c55e;
    --warn: #f0b429;

    /* --- Кнопка отправки --- */
    --sendBtn: #38bdf8;
    --sendBtn-hover: #5cc9fa;
    --sendBtn-active: #0ea5e9;
    --sendBtn-disabled: #1e3a52;
    --sendBtn-sent: #2dd4bf;
    --sendBtn-shadow: rgba(56, 189, 248, 0.35);
    --sendBtn-shadow-hover: rgba(56, 189, 248, 0.5);
    --sendBtn-shadow-sent: rgba(45, 212, 191, 0.45);

    /* --- Логин --- */
    --login-bg: #17212b;
    --login-field-bg: #0e1621;
    --login-border: #243447;
    --login-muted: #8a9aa9;
    --login-accent: #3f8cff;
    --login-accent-hover: #2f7ae5;
    --login-error: #ff6b6b;

    /* --- Оверлей звонка --- */
    --call-overlay-bg: #000;
    --call-overlay-status-bg: rgba(0, 0, 0, 0.6);
    --call-overlay-cam-label-bg: rgba(0, 0, 0, 0.65);
    --call-overlay-scope-bg: rgba(0, 0, 0, 0.55);
    --call-overlay-stats-text: #22c55e;

    /* --- Модалка / toast --- */
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --toast-bg: var(--surface-2);
    --toast-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    --toast-border: var(--primary);
    --toast-border-warn: var(--warn);
    --toast-border-error: var(--danger);

    /* --- Градиенты --- */
    --avatar-gradient: linear-gradient(135deg, #4c8dff, #8b5cf6);

    /* --- Радиусы --- */
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 12px;
    --radius-pill: 999px;
    --radius-circle: 50%;

    /* --- Отступы / gap --- */
    --gap: 16px;
    --gap-sm: 8px;
    --gap-xs: 4px;
    --pad-sm: 10px;
    --pad-md: 12px;
    --pad-lg: 16px;
    --pad-xl: 20px;

    /* --- Размеры компонентов --- */
    /* Аватар */
    --avatar-size: 40px;
    --avatar-size-sm: 36px;
    --avatar-size-lg: 64px;

    /* Кнопки-иконки */
    --btn-ghost-size: 36px;
    --btn-ghost-icon: 20px;
    --btn-ghost-size-mobile: 40px;
    --btn-ghost-icon-mobile: 22px;

    /* Кнопка отправки */
    --send-size: 44px;
    --send-icon: 20px;
    --send-size-mobile: 48px;
    --send-icon-mobile: 22px;

    /* Кнопки оверлея звонка */
    --call-btn-size: 60px;
    --call-btn-icon: 24px;
    --call-btn-size-mobile: 64px;
    --call-btn-icon-mobile: 28px;

    /* PiP */
    --pip-width: 180px;
    --pip-width-mobile: 130px;
    --pip-max-height: 40vh;
    --pip-max-height-mobile: 35vh;
    --pip-right: 16px;
    --pip-right-mobile: 10px;
    --pip-bottom: 110px;
    --pip-bottom-mobile: 96px;

    /* Осциллограмма */
    --scope-w: 120px;
    --scope-h: 36px;
    --scope-w-mobile: 90px;
    --scope-h-mobile: 28px;
    --scope-w-small: 100px;
    --scope-h-small: 28px;
    --scope-w-small-mobile: 80px;
    --scope-h-small-mobile: 22px;

    /* Оверлей звонка */
    --call-status-top: 20px;

    /* Layout */
    --sidebar-width: 320px;
    --modal-max-width: 380px;
    --login-card-max-width: 380px;

    /* Иконки в разных контекстах */
    --icon-sm: 12px;
    --icon-md: 20px;
    --icon-lg: 24px;
    --icon-xl: 28px;

    /* --- z-index слои --- */
    --z-modal: 200;
    --z-call: 300;
    --z-toast: 500;

    /* --- Тени --- */
    --shadow-send: 0 4px 14px var(--sendBtn-shadow);
    --shadow-send-hover: 0 6px 18px var(--sendBtn-shadow-hover);
    --shadow-send-sent: 0 4px 14px var(--sendBtn-shadow-sent);
    --shadow-modal: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-login: 0 10px 40px rgba(0, 0, 0, 0.35);
    --shadow-conn-on: 0 0 6px rgba(34, 197, 94, 0.6);
    --shadow-conn-off: 0 0 6px rgba(229, 72, 77, 0.6);

    /* --- Анимации --- */
    --ease-out: cubic-bezier(0.4, 0, 0.6, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-jelly: cubic-bezier(0.22, 1, 0.36, 1);
    --dur-fast: .15s;
    --dur-md: .25s;
    --dur-slow: .3s;
    --dur-call: .55s;

    /* --- Типографика --- */
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 14px;
    --fs-md: 15px;
    --fs-lg: 16px;
    --fs-xl: 18px;
    --fs-2xl: 20px;
    --fs-3xl: 22px;
    --fs-4xl: 24px;

    --chat-typing-bg: var(--surface);

    font-family: var(--font);
}

/* ------------------------------------------------------------
   2. Сброс и база
   ------------------------------------------------------------ */
* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--text);
}

[hidden] {
    display: none !important;
}

/* ------------------------------------------------------------
   3. Общие компоненты
   ------------------------------------------------------------ */

/* --- Кнопки --- */
.btn {
    border: none;
    border-radius: var(--radius);
    padding: var(--pad-md) var(--pad-xl);
    font-size: var(--fs-lg);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--dur-fast), opacity var(--dur-fast);
}

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

.btn--primary {
    background: var(--primary);
    color: #fff;
}

.btn--primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

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

.btn--secondary:hover:not(:disabled) {
    background: var(--surface-hover);
}

.btn--ghost {
    background: transparent;
    border: 0;
    padding: 0;
    width: var(--btn-ghost-size);
    height: var(--btn-ghost-size);
    border-radius: var(--radius-circle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--dur-fast), color var(--dur-fast);
}

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

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

.btn--ghost .icon {
    width: var(--btn-ghost-icon);
    height: var(--btn-ghost-icon);
}

/* --- Поля --- */
.input {
    flex: 1;
    min-width: 0;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: var(--pad-md) 14px;
    color: var(--text);
    font-size: 0.95rem;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ------------------------------------------------------------
   4. Логин
   ------------------------------------------------------------ */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: var(--login-card-max-width);
    background: var(--login-bg);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow-login);
}

.login-title {
    margin: 0;
    font-size: var(--fs-3xl);
    color: #fff;
}

.login-sub {
    margin: 0 0 6px;
    color: var(--login-muted);
    font-size: var(--fs-base);
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: var(--fs-base);
    color: var(--login-muted);
}

.login-field input {
    background: var(--login-field-bg);
    border: 1px solid var(--login-border);
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: var(--pad-md) 14px;
    font-size: var(--fs-lg);
    outline: none;
    transition: border-color var(--dur-fast);
}

.login-field input:focus {
    border-color: var(--login-accent);
}

.login-btn {
    background: var(--login-accent);
    color: #fff;
    border: 0;
    padding: var(--pad-md) 16px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-lg);
    font-weight: 600;
    cursor: pointer;
    transition: background var(--dur-fast);
}

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

.login-btn:disabled {
    opacity: .6;
    cursor: default;
}

.login-error {
    min-height: 18px;
    color: var(--login-error);
    font-size: var(--fs-base);
}

.login-back {
    background: transparent;
    border: 0;
    color: var(--login-muted);
    font-size: var(--fs-base);
    cursor: pointer;
    text-decoration: underline;
    padding: var(--gap-xs) 0;
}

.login-back:hover {
    color: var(--text);
}

/* ------------------------------------------------------------
   5. Мессенджер
   ------------------------------------------------------------ */

body.app {
    display: block;
    padding: 0;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
}

.app-layout {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--surface-2);
}

.sidebar__header {
    display: flex;
    align-items: center;
    gap: var(--pad-sm);
    padding: var(--pad-md);
    border-bottom: 1px solid var(--surface-2);
    flex-shrink: 0;
}

.sidebar__me {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar__me-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar__logout {
    background: transparent;
    border: 0;
    padding: 0;
    color: var(--text-muted);
    font-size: var(--fs-sm);
    cursor: pointer;
    text-align: left;
    width: fit-content;
}

.sidebar__logout:hover {
    color: var(--danger);
}

.sidebar__new {
    width: var(--avatar-size-sm);
    height: var(--avatar-size-sm);
    border-radius: var(--radius-circle);
    border: 0;
    background: var(--primary);
    color: #fff;
    font-size: var(--fs-2xl);
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background var(--dur-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar__new:hover {
    background: var(--primary-hover);
}

.sidebar__list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sidebar__empty {
    padding: 24px var(--pad-lg);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--fs-base);
    line-height: 1.6;
}

.conv {
    display: flex;
    align-items: center;
    gap: var(--pad-sm);
    padding: var(--pad-sm) var(--pad-md);
    border-bottom: 1px solid var(--surface-2);
    cursor: pointer;
    transition: background .1s;
}

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

.conv--active {
    background: var(--surface-2);
}

.conv--active .conv__name {
    color: var(--primary);
}

.conv__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.conv__name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv__preview {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--gap-xs);
    flex-shrink: 0;
}

.conv__time {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

.conv__badge {
    background: var(--primary);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* --- Аватар --- */
.avatar {
    width: var(--avatar-size);
    height: var(--avatar-size);
    flex-shrink: 0;
    border-radius: var(--radius-circle);
    background: var(--avatar-gradient);
    color: #fff;
    font-weight: 600;
    font-size: var(--fs-base);
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.avatar .icon {
    width: var(--icon-lg);
    height: var(--icon-lg);
}

/* --- Chat --- */
.chat {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--bg);
}

/* Состояния .chat:
   - .chat--not-selected — чат не выбран (#chat-empty виден, #chat-pane скрыт)
   - .chat--empty        — чат выбран, сообщений нет (#messages-wrap скрыт, #messages-empty виден)
   - .chat--typing       — собеседник печатает (#typing-indicator виден)
   Без --not-selected/--empty — чат выбран, сообщения есть.
*/

/* Не выбран: только заглушка */
.chat__empty {
    display: none;
}
.chat__pane  {
    display: none;
}
.chat--not-selected .chat__empty {
    display: flex;
}
.chat--not-selected .chat__pane  {
    display: none;
}

/* Выбран: pane виден */
.chat:not(.chat--not-selected) .chat__pane  {
    display: flex;
}
.chat:not(.chat--not-selected) .chat__empty {
    display: none;
}

/* Пустой чат: messages-wrap скрыт, messages__empty виден (см. секцию 6) */

/* «Печатает…» — желейный балун с тремя точками */
.chat__typing {
    position: absolute;
    left: var(--pad-lg);
    bottom: 76px;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 4px;
    width: fit-content;
    padding: 8px 12px;
    background: var(--chat-typing-bg);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: var(--gap-xs);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.5);
    transform-origin: left bottom;
    transition:
        opacity var(--dur-fast) ease,
        transform var(--dur-md) var(--ease-spring),
        visibility 0s linear var(--dur-md);
}

.chat--typing .chat__typing {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    transition:
        opacity var(--dur-fast) ease,
        transform var(--dur-md) var(--ease-spring),
        visibility 0s linear 0s;
    animation: typing-pop var(--dur-md) var(--ease-spring);
}

@keyframes typing-pop {
    0%   {
        transform: scale(0.5);
    }
    60%  {
        transform: scale(1.08);
    }
    100% {
        transform: scale(1);
    }
}

.chat__typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.5;
    flex-shrink: 0;
}

.chat--typing .chat__typing-dot {
    animation: typing-dot 1.2s ease-in-out infinite;
}

.chat--typing .chat__typing-dot:nth-child(1) {
    animation-delay: 0s;
}
.chat--typing .chat__typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}
.chat--typing .chat__typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typing-dot {
    0%, 60%, 100% {
        opacity: 0.5;
        transform: translateY(0);
    }
    30%           {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* Загрузка сообщений */
.chat--loading .messages-wrap   {
    display: none;
}
.chat--loading .messages__empty {
    display: none;
}
.chat--loading .messages__loading {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat__empty {
    flex: 1;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: var(--fs-md);
    padding: 24px;
    text-align: center;
}

.chat__pane {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative; /* для absolute .chat__typing */
}

.chat__header {
    display: flex;
    align-items: center;
    gap: var(--pad-sm);
    padding: var(--pad-sm) 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-2);
    flex-shrink: 0;
}

.chat__back {
    display: none;
    background: transparent;
    border: 0;
    color: var(--text);
    font-size: var(--fs-2xl);
    cursor: pointer;
    padding: var(--gap-xs) 6px;
}

.chat__back .icon {
    width: var(--icon-md);
    height: var(--icon-md);
}

.chat__peer {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat__peer-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat__peer-status {
    font-size: var(--fs-sm);
    color: var(--text-muted);
}

.chat__peer-status--online {
    color: var(--success);
}

.chat__actions {
    display: flex;
    gap: var(--gap-xs);
    flex-shrink: 0;
}

.chat__actions .icon {
    width: var(--icon-md);
    height: var(--icon-md);
}

.chat__body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: var(--pad-lg);
}

/* --- Composer --- */
.chat__composer {
    display: flex;
    gap: var(--gap-sm);
    padding: var(--pad-sm) 14px;
    background: var(--surface);
    border-top: 1px solid var(--surface-2);
    flex-shrink: 0;
}

.chat__composer .btn {
    flex-shrink: 0;
}

.chat__composer .input:disabled,
.chat__composer .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Кнопка отправки --- */
.chat__send {
    position: relative;
    flex-shrink: 0;
    width: var(--send-size);
    height: var(--send-size);
    border-radius: var(--radius-circle);
    border: 0;
    background: var(--sendBtn);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: background var(--dur-md), transform .12s, opacity var(--dur-md), box-shadow var(--dur-md);
    box-shadow: var(--shadow-send);
}

.chat__send .icon {
    width: var(--send-icon);
    height: var(--send-icon);
    transform: translateX(1px);
    transition: transform var(--dur-md), opacity var(--dur-md);
}

.chat__send:hover:not(:disabled) {
    background: var(--sendBtn-hover);
    box-shadow: var(--shadow-send-hover);
}

.chat__send:active:not(:disabled) {
    background: var(--sendBtn-active);
    transform: scale(0.92);
}

.chat__send:disabled {
    background: var(--sendBtn-disabled);
    color: rgba(255, 255, 255, 0.55);
    cursor: default;
    box-shadow: none;
}

.chat__send--sent {
    background: var(--sendBtn-sent) !important;
    box-shadow: var(--shadow-send-sent) !important;
}

.chat__send--sent .icon {
    animation: send-pop .35s ease;
}

@keyframes send-pop {
    0%   {
        transform: scale(0.6) translateX(0);
        opacity: 0;
    }
    50%  {
        transform: scale(1.15) translateX(0);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateX(1px);
        opacity: 1;
    }
}

.chat__send-ripple {
    position: absolute;
    border-radius: var(--radius-circle);
    background: rgba(255, 255, 255, 0.55);
    transform: scale(0);
    animation: send-ripple .55s ease-out forwards;
    pointer-events: none;
}

@keyframes send-ripple {
    to {
        transform: scale(3);
        opacity: 0;
    }
}

/* ------------------------------------------------------------
   6. Сообщения
   ------------------------------------------------------------ */
.messages-wrap {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0;
}

.messages[hidden] {
    display: none !important;
}

.messages__empty {
    display: none;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--fs-base);
    text-align: center;
    padding: 24px;
}

/* Пустой чат: контейнер сообщений скрыт, «Пока нет сообщений» показан */
.chat--empty .messages-wrap  {
    display: none;
}
.chat--empty .messages__empty {
    display: flex;
    align-items: center;
    justify-content: center;
}

.messages__loading {
    display: none;
    height: 100%;
    color: var(--text-muted);
    font-size: var(--fs-base);
    padding: 24px;
}

.messages__divider {
    align-self: center;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    padding: var(--gap-xs) var(--pad-md);
    border-radius: var(--radius-lg);
    margin: var(--pad-md) 0 6px;
}

.message {
    max-width: 72%;
    padding: var(--gap-sm) var(--pad-md);
    border-radius: var(--radius-lg);
    word-wrap: break-word;
    white-space: pre-wrap;
    position: relative;
    line-height: 1.35;
}

.message + .message {
    margin-top: 2px;
}

.message--mine {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: var(--gap-xs);
}

.message--peer {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text);
    border-bottom-left-radius: var(--gap-xs);
}

.message--grouped {
    margin-top: -2px;
    border-top-left-radius: var(--radius-sm);
}

.message--grouped.message--mine {
    border-top-right-radius: var(--radius-sm);
    border-top-left-radius: var(--radius-lg);
}

.message--grouped.message--peer {
    border-top-left-radius: var(--radius-sm);
}

.message__text {
    display: inline;
}

.message__meta {
    display: inline-flex;
    align-items: baseline;
    gap: var(--gap-xs);
    margin-left: var(--gap-sm);
    font-size: var(--fs-xs);
    opacity: 0.75;
    white-space: nowrap;
    vertical-align: bottom;
}

.message__time {
    font-size: var(--fs-xs);
}

.message__ticks {
    display: inline-flex;
    align-items: center;
}

.message__ticks .icon {
    width: var(--icon-sm);
    height: var(--icon-sm);
}

.message__ticks--read {
    color: #9ad4ff;
}

.message--peer .message__ticks,
.message--peer .message__ticks--read {
    color: var(--text-muted);
}

.message__failed {
    display: block;
    margin-top: var(--gap-xs);
    font-size: var(--fs-xs);
    color: #ffd1d1;
    font-weight: 500;
}

/* Индикатор «печатает…» */
/*.chat__typing {
    padding: var(--gap-xs) var(--pad-lg);
    font-size: var(--fs-sm);
    color: var(--text-muted);
    font-style: italic;
    flex-shrink: 0;
    min-height: 18px;
}*/

/* ------------------------------------------------------------
   7. Модалка
   ------------------------------------------------------------ */
.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--pad-xl);
    background: var(--modal-overlay);
    z-index: var(--z-modal);
}

.modal__card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--pad-xl);
    width: 100%;
    max-width: var(--modal-max-width);
    display: flex;
    flex-direction: column;
    gap: var(--pad-md);
    box-shadow: var(--shadow-modal);
}

.modal__title {
    margin: 0;
    font-size: var(--fs-xl);
}

.modal__error {
    min-height: 18px;
    color: var(--danger);
    font-size: 13px;
}

.modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--gap-sm);
}

/* ------------------------------------------------------------
   8. Оверлей звонка
   ------------------------------------------------------------ */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: var(--z-call);
    display: flex;
    flex-direction: column;
    color: #fff;

    opacity: 0;
    visibility: hidden;
    transform-origin: 50% 50%;
    transform: scale(0.6);
    background-color: transparent;
    transition:
        opacity var(--dur-slow) ease,
        transform .4s var(--ease-out),
        background-color var(--dur-slow) ease,
        visibility 0s linear .4s;
}

.call-overlay[data-state="outgoing"],
.call-overlay[data-state="incoming"],
.call-overlay[data-state="connecting"],
.call-overlay[data-state="active"],
.call-overlay[data-state="ended"] {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
    background-color: var(--call-overlay-bg);
    transition:
        opacity var(--dur-slow) ease,
        transform var(--dur-call) var(--ease-spring),
        background-color var(--dur-slow) ease,
        visibility 0s linear 0s;
}

/* «Желейный» прыжок + мягкий лист по краям.
   Класс вешаем только на время появления и снимаем
   по animationend в JS — чтобы полноэкранный фильтр
   не жёг GPU весь звонок. */
.call-overlay--jelly {
    filter: url(#call-jelly);
    animation: call-pop .8s var(--ease-jelly);
}

@keyframes call-pop {
    0%   {
        transform: scale(0.2) rotate(-4deg);
        opacity: 0;
    }
    25%  {
        transform: scale(1.08) rotate(3deg);
        opacity: 1;
    }
    45%  {
        transform: scale(0.93) rotate(-2deg);
    }
    62%  {
        transform: scale(1.04) rotate(1.2deg);
    }
    78%  {
        transform: scale(0.985) rotate(-0.6deg);
    }
    90%  {
        transform: scale(1.008) rotate(0.3deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

.call-overlay[hidden] {
    display: none !important;
}

/* --- Внутренние элементы оверлея --- */
.call__stage {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.call__stats {
    position: absolute;
    top: var(--pad-md);
    left: var(--pad-md);
    background: var(--call-overlay-status-bg);
    color: var(--call-overlay-stats-text);
    padding: var(--gap-sm) var(--pad-md);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.5;
    pointer-events: none;
    z-index: 5;
    white-space: pre;
}

.call__remote-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: var(--call-overlay-bg);
}

.call__initials {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(3rem, 10vw, 7rem);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--avatar-gradient);
    color: #fff;
}

.call__initials .icon {
    width: clamp(3rem, 10vw, 7rem);
    height: clamp(3rem, 10vw, 7rem);
}

.call__initials[hidden] {
    display: none !important;
}

.call__status {
    position: absolute;
    top: var(--call-status-top);
    left: 50%;
    transform: translateX(-50%);
    background: var(--call-overlay-status-bg);
    color: #fff;
    padding: 6px var(--pad-lg);
    border-radius: 16px;
    font-size: var(--fs-base);
    white-space: nowrap;
    z-index: 2;
    pointer-events: none;
}

.call__cam-label {
    position: absolute;
    left: 6px;
    right: 6px;
    bottom: 6px;
    background: var(--call-overlay-cam-label-bg);
    color: #fff;
    font-size: var(--fs-xs);
    line-height: 1.2;
    padding: var(--gap-xs) var(--gap-sm);
    border-radius: var(--radius-sm);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity var(--dur-md) ease, transform var(--dur-md) ease;
    z-index: 4;
}

.call__cam-label--visible {
    opacity: 1;
    transform: translateY(0);
}

.call__self {
    position: absolute;
    right: var(--pip-right);
    bottom: var(--pip-bottom);
    width: var(--pip-width);
    max-height: var(--pip-max-height);
    background: var(--call-overlay-bg);
    border-radius: var(--radius);
    overflow: hidden;
    border: 2px solid var(--surface);
    z-index: 3;
}

.call__self[hidden] {
    display: none !important;
}

.call__self-video {
    display: block;
    width: 100%;
    height: auto;
    max-height: var(--pip-max-height);
    object-fit: contain;
    background: var(--call-overlay-bg);
    transform: scaleX(-1);
}

.call__self-initials {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 600;
    background: var(--avatar-gradient);
    color: #fff;
    text-transform: uppercase;
}

.call__self-initials .icon {
    width: 2rem;
    height: 2rem;
}

.call__self-initials[hidden] {
    display: none !important;
}

.call__scope {
    position: absolute;
    top: var(--pad-md);
    right: var(--pad-md);
    width: var(--scope-w);
    height: var(--scope-h);
    background: var(--call-overlay-scope-bg);
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    box-sizing: content-box;
    opacity: 0;
    transition: opacity var(--dur-fast);
    pointer-events: none;
    z-index: 2;
}

.call__scope--active {
    opacity: 1;
}

.call__scope--small {
    width: var(--scope-w-small);
    height: var(--scope-h-small);
    top: auto;
    bottom: 6px;
    right: 6px;
}

/* --- Панель кнопок оверлея --- */
.call__controls {
    flex-shrink: 0;
    padding: var(--pad-xl) var(--pad-lg) calc(var(--pad-xl) + env(safe-area-inset-bottom, 0));
    background: var(--call-overlay-bg);
    display: flex;
    justify-content: center;
    gap: 1em;
}

.call__controls-row {
    display: flex;
    gap: var(--gap);
}

.call__btn {
    width: var(--call-btn-size);
    height: var(--call-btn-size);
    border-radius: var(--radius-circle);
    border: 0;
    font-size: var(--fs-3xl);
    background: var(--surface-2);
    color: #fff;
    cursor: pointer;
    transition: background var(--dur-fast), transform .05s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.call__btn:active {
    transform: scale(0.96);
}

.call__btn--off {
    background: var(--danger);
    color: #fff;
}

.call__btn--accept {
    background: var(--success);
    color: #fff;
}

.call__btn--decline {
    background: var(--danger);
    color: #fff;
}

.call__btn .icon {
    width: var(--call-btn-icon);
    height: var(--call-btn-icon);
}

/* --- Внутренние анимации оверлея (статус, кнопки) --- */
.call-overlay .call__status {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
    transition: opacity var(--dur-md) ease .08s, transform var(--dur-slow) var(--ease-spring) .08s;
}

.call-overlay .call__controls {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity var(--dur-md) ease .08s, transform var(--dur-slow) var(--ease-spring) .08s;
}

.call-overlay[data-state="outgoing"] .call__status,
.call-overlay[data-state="incoming"] .call__status,
.call-overlay[data-state="connecting"] .call__status,
.call-overlay[data-state="active"] .call__status,
.call-overlay[data-state="ended"] .call__status {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.call-overlay[data-state="outgoing"] .call__controls,
.call-overlay[data-state="incoming"] .call__controls,
.call-overlay[data-state="connecting"] .call__controls,
.call-overlay[data-state="active"] .call__controls,
.call-overlay[data-state="ended"] .call__controls {
    opacity: 1;
    transform: translateY(0);
}

.call-overlay[data-state="idle"] .call__status {
    transition: opacity var(--dur-fast) ease, transform var(--dur-fast) ease;
    transform: translateX(-50%) translateY(12px);
}

.call-overlay[data-state="idle"] .call__controls {
    transition: opacity var(--dur-fast) ease, transform var(--dur-fast) ease;
    transform: translateY(12px);
}

/* ------------------------------------------------------------
   9. Индикатор соединения
   ------------------------------------------------------------ */
.conn-dot {
    display: inline-block;
    width: var(--gap-sm);
    height: var(--gap-sm);
    border-radius: var(--radius-circle);
    margin-right: 6px;
    vertical-align: middle;
    background: var(--success);
    box-shadow: var(--shadow-conn-on);
    transition: background var(--dur-fast), box-shadow var(--dur-fast);
}

.conn-dot--off {
    background: var(--danger);
    box-shadow: var(--shadow-conn-off);
}

/* ------------------------------------------------------------
   10. Toast
   ------------------------------------------------------------ */
.toast-container {
    position: fixed;
    right: var(--gap);
    bottom: var(--gap);
    display: flex;
    flex-direction: column;
    gap: var(--gap-sm);
    z-index: var(--z-toast);
    pointer-events: none;
    max-width: min(360px, calc(100vw - 32px));
}

.toast {
    pointer-events: auto;
    padding: var(--pad-sm) 14px;
    border-radius: var(--radius-sm);
    font-size: var(--fs-base);
    line-height: 1.35;
    color: #fff;
    background: var(--toast-bg);
    box-shadow: var(--toast-shadow);
    border-left: 3px solid var(--toast-border);
    transform: translateY(8px);
    opacity: 0;
    animation: toast-in var(--dur-md) ease forwards;
    word-break: break-word;
}

.toast--info  {
    border-left-color: var(--toast-border);
}
.toast--warn  {
    border-left-color: var(--toast-border-warn);
}
.toast--error {
    border-left-color: var(--toast-border-error);
}

.toast--out {
    animation: toast-out var(--dur-md) ease forwards;
}

@keyframes toast-in {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes toast-out {
    to {
        transform: translateY(8px);
        opacity: 0;
    }
}

/* ------------------------------------------------------------
   11. Медиа-запросы
   ------------------------------------------------------------ */

/* --- Мобильная адаптация --- */
@media (max-width: 680px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .chat {
        display: none;
    }

    body.app--chat-open .sidebar {
        display: none;
    }

    body.app--chat-open .chat {
        display: flex;
    }

    .chat__back {
        display: block;
    }

    .btn--ghost {
        width: var(--btn-ghost-size-mobile);
        height: var(--btn-ghost-size-mobile);
    }

    .btn--ghost .icon {
        width: var(--btn-ghost-icon-mobile);
        height: var(--btn-ghost-icon-mobile);
    }

    .chat__send {
        width: var(--send-size-mobile);
        height: var(--send-size-mobile);
    }

    .chat__send .icon {
        width: var(--send-icon-mobile);
        height: var(--send-icon-mobile);
    }

    .call__self {
        width: var(--pip-width-mobile);
        bottom: var(--pip-bottom-mobile);
        right: var(--pip-right-mobile);
        max-height: var(--pip-max-height-mobile);
    }

    .call__self-video {
        max-height: var(--pip-max-height-mobile);
    }

    .call__btn {
        width: var(--call-btn-size-mobile);
        height: var(--call-btn-size-mobile);
        font-size: var(--fs-4xl);
    }

    .call__btn .icon {
        width: var(--call-btn-icon-mobile);
        height: var(--call-btn-icon-mobile);
    }

    .call__scope {
        width: var(--scope-w-mobile);
        height: var(--scope-h-mobile);
        top: var(--gap-sm);
        right: var(--gap-sm);
    }

    .call__scope--small {
        width: var(--scope-w-small-mobile);
        height: var(--scope-h-small-mobile);
    }

    .toast-container {
        right: var(--pad-sm);
        bottom: calc(var(--pad-sm) + env(safe-area-inset-bottom, 0));
        left: var(--pad-sm);
        max-width: none;
    }
    .chat__typing {
        bottom: 80px;
    }


}

/* --- Hover только для устройств с мышью --- */
@media (any-hover: hover) {
    .chat__send:hover:not(:disabled) {
        background: var(--sendBtn-hover);
    }
    .btn--ghost:hover {
        background: var(--surface-2);
    }
}

/* --- Touch: убираем «залипающий» фокус --- */
@media (any-hover: none) {
    /* Убираем системный tap-highlight на мобильных */
    .btn,
    .btn--ghost,
    .chat__send,
    .call__btn,
    .sidebar__new,
    .sidebar__logout,
    .chat__back,
    .chat__send,
    .modal__actions .btn,
    .login-btn,
    .login-back {
        outline: none;
        -webkit-tap-highlight-color: transparent;
    }

}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
    .call-overlay,
    .call-overlay .call__status,
    .call-overlay .call__controls {
        transition: none !important;
    }

    .call-overlay--jelly {
        animation: none !important;
        filter: none !important;
    }

    .chat--typing .chat__typing {
        animation: none !important;
    }

    .chat--typing .chat__typing-dot {
        animation: none !important;
    }
}

.chat__body, .sidebar__list {
    scrollbar-width: thin;
    scrollbar-color: var(--surface-hover) transparent;
}

.chat__body::-webkit-scrollbar,
.sidebar__list::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.chat__body::-webkit-scrollbar-track,
.sidebar__list::-webkit-scrollbar-track {
    background: transparent;
}

.chat__body::-webkit-scrollbar-thumb,
.sidebar__list::-webkit-scrollbar-thumb {
    background: var(--surface-hover);
    border-radius: var(--radius-pill);
    border: 2px solid transparent;
    background-clip: padding-box;
}

.chat__body::-webkit-scrollbar-thumb:hover,
.sidebar__list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
    background-clip: padding-box;
}

