/* ============================================================
   mobile.css — Полная мобильная адаптация UgolTech CloudStorage
   Брейкпоинты: ≤768px (мобильный), 769–1024px (планшет)
   ============================================================ */

/* ─── ПЕРЕМЕННЫЕ ─────────────────────────────────────────────── */
:root {
    --mobile-navbar-height: 60px;
    --mobile-topbar-height: 56px;
    --drawer-width: 280px;
}

/* ─── ПЛАНШЕТ (769–1024px) ───────────────────────────────────── */
@media (max-width: 1024px) and (min-width: 769px) {
    .sidebar {
        width: 68px !important;
        min-width: 68px !important;
    }
    .logo-text,
    .nav-text,
    .btn-text,
    .sidebar-user-info,
    .storage-info,
    .nav-subheader {
        display: none !important;
    }
    .nav-item {
        justify-content: center !important;
        padding: 12px !important;
    }
    .btn-upload-sidebar {
        justify-content: center !important;
        padding: 12px !important;
    }
    .sidebar-user {
        justify-content: center !important;
    }
}

/* ─── МОБИЛЬНЫЙ (≤768px) ─────────────────────────────────────── */
@media (max-width: 768px) {

    /* Убираем десктопный сайдбар */
    .sidebar { display: none !important; }

    /* Корневой контейнер */
    .app-container {
        flex-direction: column;
        height: 100dvh; /* dvh — правильная высота на iOS (без адресной строки) */
    }

    /* Главная область занимает весь экран */
    .main-area {
        flex: 1;
        margin: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
        min-height: 0;
        padding-bottom: var(--mobile-navbar-height);
    }

    /* ─── TOPBAR ──────────────────────────────────────────────── */
    .topbar {
        height: var(--mobile-topbar-height) !important;
        padding: 0 12px !important;
        gap: 8px;
    }
    
    /* Кнопка-гамбургер вместо toggle */
    #sidebar-toggle-btn {
        display: flex !important; /* показываем и используем как open-drawer */
    }

    /* Поиск — на всю ширину но компактный */
    .unified-search-bar {
        max-width: unset !important;
        height: 36px !important;
        font-size: 14px;
    }

    /* Скрываем менее важные кнопки */
    #view-toggle-btn { display: none !important; }
    .btn-sort span:not(.material-symbols-rounded) { display: none !important; }
    #empty-trash-btn span:not(.material-symbols-rounded) { display: none !important; }

    /* ─── КОНТЕНТ ─────────────────────────────────────────────── */
    .content {
        padding: 16px !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .content-header {
        margin-bottom: 16px !important;
    }

    /* ─── FILE GRID — 2 колонки на телефоне ──────────────────── */
    .file-grid.view-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    /* На маленьких экранах (≤400px) — 1 колонка */
    @media (max-width: 400px) {
        .file-grid.view-grid {
            grid-template-columns: 1fr !important;
        }
    }

    /* Карточка файла — немного компактнее */
    .file-card {
        padding: 12px !important;
    }
    .file-card .file-icon-box .material-symbols-rounded { font-size: 32px !important; }
    .file-card .file-icon-box { width: 48px !important; height: 48px !important; }
    .file-card .file-name { font-size: 12px !important; }

    /* ─── НИЖНИЙ ТАБ-БАР (Mobile Navigation) ────────────────── */
    .mobile-navbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: var(--mobile-navbar-height);
        background: var(--bg-surface);
        border-top: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: space-around;
        z-index: 900;
        padding: 0 4px;
        padding-bottom: env(safe-area-inset-bottom); /* iPhone notch */
        box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
    }

    .mobile-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        flex: 1;
        padding: 8px 4px;
        border: none;
        background: none;
        cursor: pointer;
        color: var(--text-muted);
        border-radius: 12px;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
        font-family: inherit;
        position: relative;
    }

    .mobile-nav-item .material-symbols-rounded {
        font-size: 24px;
        transition: all 0.2s ease;
        font-variation-settings: 'FILL' 0, 'wght' 400, 'opsz' 24;
    }

    .mobile-nav-item .nav-label {
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.2px;
        white-space: nowrap;
    }

    /* Активный таб */
    .mobile-nav-item.active {
        color: var(--primary-color);
    }

    .mobile-nav-item.active .material-symbols-rounded {
        font-variation-settings: 'FILL' 1, 'wght' 600, 'opsz' 24;
    }

    /* Пилюля под активным табом */
    .mobile-nav-item.active::before {
        content: '';
        position: absolute;
        top: 4px;
        width: 32px;
        height: 32px;
        background: var(--primary-container);
        border-radius: 10px;
        z-index: -1;
        animation: tabPop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    @keyframes tabPop {
        from { transform: scale(0.7); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }

    /* ─── КНОПКА "СОЗДАТЬ" (FAB) ─────────────────────────────── */
    .mobile-fab {
        width: 52px;
        height: 52px;
        border-radius: 16px;
        background: var(--primary-color);
        color: var(--bg-main);
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 4px 16px rgba(0,0,0,0.2);
        transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }

    .mobile-fab:active {
        transform: scale(0.9);
    }

    .mobile-fab .material-symbols-rounded {
        font-size: 26px;
        font-variation-settings: 'FILL' 1, 'wght' 600, 'opsz' 24;
    }

    /* ─── DRAWER (Полное меню) ───────────────────────────────── */
    .mobile-drawer-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
        backdrop-filter: blur(2px);
    }

    .mobile-drawer-overlay.open {
        display: block;
        opacity: 1;
    }

    .mobile-drawer {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: var(--drawer-width);
        background: var(--bg-surface);
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
        box-shadow: 4px 0 24px rgba(0,0,0,0.15);
        overflow-y: auto;
    }

    .mobile-drawer.open {
        transform: translateX(0);
    }

    .mobile-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 20px 20px 12px;
        border-bottom: 1px solid var(--border-color);
    }

    .mobile-drawer-logo {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 15px;
        font-weight: 700;
        color: var(--text-main);
        letter-spacing: -0.3px;
    }

    .mobile-drawer-logo img {
        width: 28px;
        height: 28px;
        border-radius: 8px;
        object-fit: contain;
    }

    .mobile-drawer-close {
        background: none;
        border: none;
        cursor: pointer;
        color: var(--text-muted);
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-drawer-nav {
        flex: 1;
        padding: 16px 12px;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .mobile-drawer-item {
        display: flex;
        align-items: center;
        gap: 14px;
        padding: 12px 14px;
        border-radius: 12px;
        border: none;
        background: none;
        cursor: pointer;
        color: var(--text-main);
        font-size: 14px;
        font-weight: 500;
        font-family: inherit;
        text-align: left;
        width: 100%;
        transition: all 0.18s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-drawer-item:hover,
    .mobile-drawer-item:active {
        background: var(--bg-surface-hover);
    }

    .mobile-drawer-item.active {
        background: var(--primary-container);
        color: var(--on-primary-container);
        font-weight: 600;
    }

    .mobile-drawer-item .material-symbols-rounded {
        font-size: 22px;
        flex-shrink: 0;
        font-variation-settings: 'FILL' 0, 'wght' 400, 'opsz' 24;
    }

    .mobile-drawer-item.active .material-symbols-rounded {
        font-variation-settings: 'FILL' 1, 'wght' 600, 'opsz' 24;
    }

    .mobile-drawer-divider {
        height: 1px;
        background: var(--border-color);
        margin: 8px 14px;
    }

    .mobile-drawer-subheader {
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.8px;
        padding: 8px 14px 4px;
    }

    /* Нижняя часть drawer (профиль + хранилище) */
    .mobile-drawer-footer {
        padding: 16px;
        border-top: 1px solid var(--border-color);
    }

    .mobile-drawer-user {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px;
        border-radius: 12px;
        cursor: pointer;
        transition: background 0.2s;
        margin-bottom: 12px;
    }

    .mobile-drawer-user:active { background: var(--bg-surface-hover); }

    .mobile-drawer-user img {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        flex-shrink: 0;
    }

    .mobile-drawer-user-info .name {
        font-size: 14px;
        font-weight: 600;
        color: var(--text-main);
    }

    .mobile-drawer-user-info .email {
        font-size: 12px;
        color: var(--text-muted);
    }

    /* Строка хранилища в drawer */
    .mobile-storage-bar {
        padding: 0 4px;
    }

    .mobile-storage-bar .storage-label-row {
        display: flex;
        justify-content: space-between;
        font-size: 12px;
        color: var(--text-muted);
        margin-bottom: 6px;
    }

    .mobile-storage-bar .storage-progress-bar {
        height: 4px;
        background: var(--bg-surface-active);
        border-radius: 2px;
        overflow: hidden;
    }

    .mobile-storage-bar .storage-progress-fill {
        height: 100%;
        background: var(--primary-color);
        border-radius: 2px;
        transition: width 0.5s ease;
    }

    /* ─── КОНТЕКСТНОЕ МЕНЮ — ниже пальца ────────────────────── */
    .context-menu {
        /* На мобиле меню открывается снизу как bottom sheet */
        max-height: 60vh;
        overflow-y: auto;
    }

    /* ─── UPLOAD QUEUE — более компактный ───────────────────── */
    #upload-panel {
        bottom: calc(var(--mobile-navbar-height) + 12px) !important;
        right: 12px !important;
        left: 12px !important;
        width: auto !important;
    }

    /* ─── МОДАЛЬНЫЕ ОКНА — на всю ширину ────────────────── */
    .modal-wrapper {
        padding: 12px !important;
        align-items: flex-end !important; /* slide up from bottom */
    }

    .modal-box {
        border-radius: 20px 20px 12px 12px !important;
        width: 100% !important;
        max-width: 100% !important;
        animation: slideUpModal 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    @keyframes slideUpModal {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    /* ─── ПАНЕЛИ ПРОФИЛЯ / НАСТРОЕК ─────────────────────────── */
    .side-panel {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        top: auto !important;
        bottom: 0 !important;
        height: 85vh !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    /* ─── ЗАМЕТКИ — полная ширина ────────────────────────────── */
    .notes-layout {
        flex-direction: column !important;
    }

    .notes-sidebar {
        width: 100% !important;
        height: auto !important;
        max-height: 35vh !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-color) !important;
    }
}
