/* ==========================================
   BUSYA AI - MOBILE ADAPTATION & RESPONSIVE
   ========================================== */

/* --- Глобальные переменные для мобильных --- */
:root {
    --mobile-header-height: 60px;
    --mobile-input-height: 80px; /* Минимальная высота */
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Кнопка закрытия сайдбара --- */
.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 20px;
    right: 20px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #fff);
    font-size: 18px;
    cursor: pointer;
    z-index: 10001;
    transition: all 0.2s ease;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.1);
}

/* --- Адаптивное окно авторизации --- */
@media (max-width: 600px) {
    .auth-modal {
        padding: 16px;
        align-items: flex-start;
        padding-top: 40px;
    }
    
    .auth-content {
        padding: 24px 20px;
        max-width: 100%;
        width: 100%;
        border-radius: 16px;
        max-height: calc(100vh - 80px);
        overflow-y: auto;
    }
    
    .auth-header {
        margin-bottom: 20px;
    }
    
    .auth-header h2 {
        font-size: 20px;
    }
    
    .auth-header p {
        font-size: 14px;
    }
    
    .close-auth-btn {
        top: -8px;
        right: -8px;
        width: 36px;
        height: 36px;
        font-size: 18px;
        background: rgba(255, 255, 255, 0.15);
    }
    
    .auth-logo .logo-icon {
        font-size: 28px;
    }
    
    .auth-logo .logo-text {
        font-size: 24px;
    }
    
    .auth-benefits {
        padding: 16px;
        margin-bottom: 20px;
    }
    
    .auth-benefits h3 {
        font-size: 16px;
    }
    
    .auth-benefits li {
        font-size: 13px;
    }
    
    .auth-buttons {
        gap: 12px;
        margin-bottom: 20px;
    }
    
    .auth-btn {
        padding: 14px 20px;
        font-size: 15px;
    }
    
    .google-btn-content {
        padding: 12px 20px;
    }
    
    .google-btn-text {
        font-size: 14px;
    }
    
    .auth-status {
        padding: 12px;
        font-size: 13px;
    }
}

/* Очень маленькие экраны */
@media (max-width: 380px) {
    .auth-content {
        padding: 20px 16px;
    }
    
    .auth-header h2 {
        font-size: 18px;
    }
    
    .auth-logo .logo-text {
        font-size: 20px;
    }
    
    .auth-benefits {
        padding: 12px;
    }
    
    .auth-benefits h3 {
        font-size: 14px;
    }
    
    .auth-benefits li {
        font-size: 12px;
        margin-bottom: 6px;
    }
}

/* --- Базовая адаптация (Планшеты и Телефоны) --- */
@media (max-width: 1024px) {
    .app {
        height: 100dvh; /* Dynamic viewport height для мобильных браузеров */
        overflow: hidden;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100%;
        height: 100dvh;
        position: relative;
    }

    /* Кнопка закрытия сайдбара видна на мобильных */
    .sidebar-close-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Сайдбар */
    .sidebar {
        width: 280px;
        transform: translateX(-100%);
        z-index: 10000; /* Поверх всего */
        box-shadow: 2px 0 20px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Затемнение фона при открытом сайдбаре */
    .sidebar.open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 280px;
        right: -100vw;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: -1;
        backdrop-filter: blur(2px);
    }

    .sidebar-toggle {
        top: 12px;
        left: 12px;
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    /* Убираем сдвиг контента при открытии меню на мобильных */
    .sidebar.open ~ .main-content {
        margin-left: 0; 
    }
}

/* --- Телефоны и планшеты (Portrait & Landscape) --- */
@media (max-width: 1024px) {
    /* Область чата */
    .chat-container {
        padding-bottom: calc(var(--mobile-input-height) + 20px); /* Отступ под полем ввода */
    }

    .chat-messages {
        padding: 16px 12px 100px 12px; /* Доп. отступ снизу */
    }

    .message {
        max-width: 92%;
    }

    .message-content {
        padding: 14px;
    }

    /* --- ПЛАВАЮЩАЯ СТРОКА ВВОДА (Фикс для всех браузеров) --- */
    .input-container {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        z-index: 9999;
        padding: 12px 12px calc(12px + var(--safe-area-bottom)) 12px;
        background: rgba(26, 26, 26, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid rgba(255,255,255,0.1);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.3);
    }

    .input-area {
        border-radius: 20px;
        background: rgba(40, 40, 40, 0.6);
        box-shadow: none; /* Убираем тяжелые тени */
    }

    .input-wrapper {
        flex-direction: column;
        padding: 10px;
        gap: 10px;
        min-height: auto;
    }

    /* Текстовое поле */
    #message-input {
        min-height: 40px;
        max-height: 120px;
        font-size: 16px; /* 16px предотвращает зум на iOS при фокусе */
        padding: 0 4px;
    }

    /* Нижняя панель с кнопками */
    .input-right-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        gap: 8px;
    }

    /* Селектор модели - компактный */
    .input-model-selector {
        flex: 1;
        min-width: 0; /* Разрешаем сжиматься */
    }

    .input-selector-btn {
        padding: 6px 10px;
        width: 100%;
        min-width: auto;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 12px;
        height: 36px;
    }
    
    .selector-text {
        display: inline-block;
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
    }

    /* Кнопки действий */
    .input-actions {
        display: flex;
        gap: 6px;
        flex-shrink: 0;
    }

    .input-actions .action-btn, .send-btn {
        width: 36px;
        height: 36px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Скрываем текст кнопок, оставляем иконки если нужно */
    .input-actions .action-btn span {
        display: none;
    }

    /* Меню выбора модели на мобильных */
    .input-selector-menu {
        position: fixed;
        bottom: 80px;
        left: 10px;
        right: 10px;
        top: auto;
        max-height: 50vh;
        width: auto;
    }
}

/* --- Маленькие телефоны (iPhone SE, старые Android) --- */
@media (max-width: 380px) {
    .selector-text {
        max-width: 60px;
    }
    
    .input-actions .action-btn:not(#send-btn):not(#file-btn) {
        display: none; /* Скрываем лишние кнопки на микро-экранах */
    }
    
    /* Возвращаем кнопку голоса если она важна */
    .input-actions #voice-btn {
        display: flex;
    }
}

/* --- Ландшафтная ориентация на телефонах --- */
@media (max-height: 500px) and (orientation: landscape) {
    .input-container {
        padding: 6px 12px;
    }
    
    .input-wrapper {
        flex-direction: row;
        align-items: center;
    }
    
    #message-input {
        height: 36px !important;
        min-height: 36px;
    }
    
    .sidebar-toggle {
        top: 6px;
        left: 6px;
    }
}

/* --- Исправления для Safari iOS --- */
@supports (-webkit-touch-callout: none) {
    .app {
        height: -webkit-fill-available;
    }
    
    .input-container {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}
