/* mobile.css: адаптация под телефоны и планшеты */
:root {
    --sat: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
    --sab: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
    --sal: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
    --sar: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
}
body:has(#app) { overflow: hidden; overscroll-behavior: none; }
.app { height: var(--app-h, 100dvh); }
.messages, .chat-list, .settings-body, .gs-results, .emoji-grid, .sticker-grid {
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.chat-list, .messages-wrap { min-height: 0; }
.chat-top-info { min-width: 0; }
.chat-title, .chat-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== ПЛАНШЕТЫ ===== */
@media (min-width: 769px) and (max-width: 1100px) {
    .sidebar { width: 300px; }
    .msg { max-width: min(520px, 78%); }
    .media-panel { width: 320px; }
    .modal-card { max-width: 560px; }
    .composer { gap: 6px; padding-left: 10px; padding-right: 10px; }
    .composer .icon-btn, .send-btn { width: 38px; height: 38px; }
    .composer textarea { min-width: 0; }
    .icon-btn { min-width: 40px; min-height: 40px; }
}

/* ===== ТЕЛЕФОНЫ ===== */
@media (max-width: 768px) {
    html, body { height: 100%; }
    .app {
        position: fixed !important; top: 0; left: 0; right: 0; bottom: auto;
        height: var(--app-h, 100dvh) !important; min-height: 0;
        overflow: hidden; will-change: auto !important;
        transform: none !important; filter: none !important;
        backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
        padding: 0 !important; border-radius: 0 !important;
    }
    .sidebar, .main {
        position: fixed !important; top: 0; left: 0; right: 0; bottom: auto !important;
        width: 100% !important; max-width: none !important; margin: 0 !important;
        height: var(--app-h, 100dvh) !important; border-radius: 0 !important;
        box-sizing: border-box;
    }
    .sidebar {
        background: var(--bg) !important; z-index: 20;
        padding-top: var(--sat); padding-left: var(--sal); padding-right: var(--sar);
        backdrop-filter: none !important;
    }
    .main {
        background-color: var(--bg-soft) !important; z-index: 30;
        padding: 0 !important; backdrop-filter: none !important;
        transform: translateX(100%); visibility: hidden;
        transition: transform .25s ease, visibility 0s .25s;
    }
    .app.mobile-chat-open .main {
        transform: none; visibility: visible;
        transition: transform .25s ease, visibility 0s;
    }
    .app.mobile-chat-open .sidebar {
        transform: translateX(-20%); opacity: 0; visibility: hidden; pointer-events: none;
        transition: transform .25s ease, opacity .25s ease, visibility 0s .25s;
    }
    .empty-state { display: none !important; }
    .chat-view:not(.hidden) { display: flex; flex-direction: column; height: 100%; min-height: 0; }

    .chat-top {
        padding-top: calc(8px + var(--sat)) !important;
        padding-left: calc(8px + var(--sal)) !important;
        padding-right: calc(8px + var(--sar)) !important;
    }
    .messages { padding-left: calc(8px + var(--sal)); padding-right: calc(8px + var(--sar)); }

    /* поле ввода: 1 строка = текст + микрофон + отправить; 2 строка = инструменты */
    .composer {
        flex-wrap: wrap; align-items: center; gap: 4px 6px;
        padding: 8px calc(10px + var(--sar)) calc(8px + var(--sab)) calc(10px + var(--sal)) !important;
    }
    .composer textarea {
        order: 1; flex: 1 1 calc(100% - 104px); min-width: 0; width: auto;
        font-size: 16px; max-height: 96px; padding: 10px 14px;
    }
    .composer #btn-mic, .composer .send-btn { order: 2; width: 42px; height: 42px; flex: 0 0 42px; }
    .composer > .icon-btn:not(#btn-mic) {
        order: 3; flex: 1 1 32px; max-width: 48px; min-width: 0; min-height: 0;
        width: auto; height: 36px;
    }
    .composer > .icon-btn:not(#btn-mic) svg { width: 20px; height: 20px; }

    .emoji-panel, .sticker-panel, .quick-reply-popup { bottom: calc(104px + var(--sab)) !important; }
    .reaction-popup { bottom: calc(110px + var(--sab)) !important; }
    .notif-toast { bottom: calc(10px + var(--sab)); }

    .modal { padding-top: var(--sat); }
    .modal-card { max-height: calc(var(--app-h, 100dvh) - var(--sat) - 12px) !important; }
    .modal-card.modal-settings { max-height: calc(var(--app-h, 100dvh) - var(--sat) - 12px) !important; }
    input, select, textarea { font-size: 16px; }
    .btn { min-height: 44px; }
    .settings-tabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
    .settings-tab { flex-shrink: 0; }
    .call-card { padding-bottom: calc(20px + var(--sab)); }
}

/* ===== ТЕЛЕФОН В ЛАНДШАФТЕ ===== */
@media (max-height: 480px) and (orientation: landscape) {
    .chat-top { padding-top: calc(4px + var(--sat)) !important; padding-bottom: 4px; }
    .composer textarea { max-height: 56px; }
    .emoji-panel, .sticker-panel { max-height: 55dvh; }
}
