/* Мобильная адаптация для Q-Market Shop */

/* === БАЗОВЫЕ МОБИЛЬНЫЕ СТИЛИ === */
@media (max-width: 768px) {
    /* Улучшенная типографика для мобильных */
    body {
        font-size: 16px; /* Предотвращаем авто-зум на iOS */
        -webkit-text-size-adjust: 100%;
        touch-action: manipulation; /* Отключаем задержку тапа */
    }
    
    /* Контейнеры */
    .container {
        width: 100% !important;
        padding: 0 16px !important;
        margin: 16px auto 40px !important;
    }
    
    /* Заголовки */
    h1 {
        font-size: 24px !important;
    }
    
    h2 {
        font-size: 20px !important;
    }
    
    /* Хедер */
    header {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 12px 0 !important;
    }
    
    /* Навигация */
    .nav, nav {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
    
    .nav a, nav a {
        padding: 8px 12px;
        font-size: 14px;
    }
}

/* === АДАПТАЦИЯ ГЛАВНОЙ СТРАНИЦЫ === */
@media (max-width: 768px) {
    /* Бренд */
    .brand {
        font-size: clamp(32px, 10vw, 48px) !important;
        padding: 32px 16px 8px !important;
    }
    
    .subtitle {
        font-size: 14px;
        margin-top: 8px;
    }
    
    /* Hero секция */
    .hero {
        margin-top: 16px !important;
        padding: 16px !important;
        border-radius: 12px !important;
    }
    
    /* Сетка */
    .grid2 {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    /* Панели */
    .panel {
        padding: 12px !important;
    }
    
    /* Статистика */
    .stats {
        flex-direction: column;
        gap: 16px;
    }
    
    .stat {
        width: 100%;
        text-align: center;
    }
}

/* === АДАПТАЦИЯ МАГАЗИНА === */
@media (max-width: 768px) {
    /* Сетка товаров */
    .grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        padding: 0 !important;
    }
    
    /* Карточка товара */
    .card {
        width: 100% !important;
        height: auto !important;
        margin-bottom: 12px;
    }
    
    .thumb {
        height: 200px !important;
    }
    
    .content {
        padding: 12px !important;
    }
    
    .title {
        font-size: 16px !important;
    }
    
    .description {
        font-size: 14px !important;
        line-height: 1.5 !important;
    }
    
    .price {
        font-size: 20px !important;
    }
    
    /* Кнопки в товарах */
    .card .btn {
        width: 100%;
        padding: 12px !important;
        font-size: 16px !important;
    }
}

/* === АДАПТАЦИЯ КОРЗИНЫ === */
@media (max-width: 768px) {
    /* Элементы корзины */
    .cart-item {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
        border-radius: 8px;
        background: rgba(255,255,255,0.03);
        margin-bottom: 12px;
    }
    
    .cart-item .thumb {
        width: 100%;
        height: 150px;
    }
    
    /* Количество товара */
    .qty-controls {
        display: flex;
        justify-content: center;
        gap: 16px;
        margin: 8px 0;
    }
    
    .qty-controls button {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
    
    /* Итого */
    .cart-summary {
        position: sticky;
        bottom: 0;
        background: var(--bg1);
        padding: 16px;
        border-top: 1px solid rgba(255,255,255,0.1);
        margin: 0 -16px;
    }
}

/* === АДАПТАЦИЯ ФОРМ === */
@media (max-width: 768px) {
    /* Поля ввода */
    input, textarea, select {
        width: 100% !important;
        padding: 12px !important;
        font-size: 16px !important; /* Предотвращаем зум на iOS */
        border-radius: 8px !important;
    }
    
    /* Кнопки */
    .btn, button {
        min-height: 44px; /* Минимальный размер для тапа по Apple HIG */
        padding: 12px 24px !important;
        font-size: 16px !important;
    }
    
    /* Формы */
    form {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    .form-row {
        flex-direction: column !important;
        gap: 8px !important;
    }
}

/* === АДАПТАЦИЯ АДМИНКИ === */
@media (max-width: 768px) {
    /* Боковая панель */
    .side {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 80%;
        max-width: 300px;
        z-index: 1000;
        transition: left 0.3s;
        box-shadow: 2px 0 20px rgba(0,0,0,0.5);
    }
    
    .side.mobile-open {
        left: 0;
    }
    
    /* Кнопка меню */
    .mobile-menu-btn {
        display: block !important;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 1001;
        width: 44px;
        height: 44px;
        background: var(--accent);
        border: none;
        border-radius: 8px;
        color: white;
        font-size: 24px;
        cursor: pointer;
    }
    
    /* Контент админки */
    .main {
        margin-left: 0 !important;
        padding: 60px 16px 16px !important;
    }
    
    /* Таблицы */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
    
    table {
        min-width: 600px;
    }
    
    /* Карточки метрик */
    .metric-cards {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}

/* === СПЕЦИФИЧНЫЕ СТИЛИ ДЛЯ iOS === */
@supports (-webkit-touch-callout: none) {
    /* Фиксы для iOS Safari */
    body {
        -webkit-font-smoothing: antialiased;
    }
    
    /* Безопасные зоны для iPhone X+ */
    .container {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .cart-summary {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* === УЛУЧШЕНИЯ ПРОИЗВОДИТЕЛЬНОСТИ === */
@media (max-width: 768px) {
    /* Отключаем декоративную анимацию сканлинии на мобильных */
    /* НЕ скрываем .grid - он используется как layout-контейнер в account, orders, rewards и др. */
    .scan {
        display: none !important;
    }

    /* Упрощаем тени только для карточек (не трогаем focus-стили и другие элементы) */
    .card {
        box-shadow: 0 2px 8px rgba(0,0,0,0.2) !important;
    }

    /* Упрощаем анимации только для пользователей с prefers-reduced-motion */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation: none !important;
            transition: none !important;
        }
    }
}

/* === МОДАЛЬНЫЕ ОКНА === */
@media (max-width: 768px) {
    .modal {
        width: 90% !important;
        max-width: none !important;
        margin: 20px !important;
    }
    
    .modal-content {
        padding: 16px !important;
    }
    
    /* Оверлей для мобильного меню */
    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
    }
    
    .mobile-overlay.active {
        display: block;
    }
}

/* === КНОПКИ ДЕЙСТВИЙ === */
@media (max-width: 768px) {
    /* Плавающая кнопка корзины */
    .floating-cart {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        background: var(--accent);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        z-index: 100;
    }
    
    .floating-cart .badge {
        position: absolute;
        top: -4px;
        right: -4px;
        background: var(--magenta);
        color: white;
        width: 24px;
        height: 24px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 12px;
        font-weight: bold;
    }
}

/* === ОПТИМИЗАЦИЯ ИЗОБРАЖЕНИЙ === */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Lazy loading индикатор */
    .img-loading {
        background: linear-gradient(90deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0.1) 100%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }
    
    @keyframes shimmer {
        0% { background-position: -200% 0; }
        100% { background-position: 200% 0; }
    }
}
