/* ============================================
   BRICK PLATFORM - МОБИЛЬНАЯ АДАПТАЦИЯ v1.0
   Подключать: <link rel="stylesheet" href="mobile-app.css">
   ============================================ */

/* === 1. CSS-ПЕРЕМЕННЫЕ === */
:root {
    --mobile: 768px;
    --small: 480px;
    --primary: #2c3e50;
    --success: #27ae60;
    --danger: #e74c3c;
    --info: #3498db;
    --warning: #f39c12;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #333333;
    --text-secondary: #7f8c8d;
    --border: #dee2e6;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --safe-bottom: env(safe-area-inset-bottom, 20px);
}

/* === 2. БАЗОВЫЕ УЛУЧШЕНИЯ ДЛЯ ВСЕХ СТРАНИЦ === */

/* Плавный скролл */
html {
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

/* Улучшенный touch для всех интерактивных элементов */
button, a, .menu-item, .client-card, .tab {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Минимальная ширина кликабельных элементов 44px (Apple HIG) */
button, .btn, .tab {
    min-height: 44px;
}

/* === 3. АДАПТИВНЫЙ HEADER === */
@media (max-width: 768px) {
    .header {
        padding: 12px 15px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .header h1 {
        font-size: 16px !important;
        width: 100%;
        text-align: center;
    }
    
    .header .user-info {
        width: 100%;
        justify-content: center;
        font-size: 13px;
    }
    
    .header .user-info button {
        padding: 4px 10px !important;
        font-size: 12px !important;
    }
}

/* === 4. АДАПТИВНЫЙ КОНТЕЙНЕР === */
@media (max-width: 768px) {
    .container {
        padding: 12px !important;
    }
}

/* === 5. НИЖНЯЯ НАВИГАЦИЯ (БУРГЕР-МЕНЮ) === */
.bottom-nav {
    display: none;
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #e2e8f0;
        padding: 8px 12px;
        padding-bottom: calc(8px + var(--safe-bottom));
        z-index: 999;
        justify-content: space-around;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
    }
    
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: #7f8c8d;
        font-size: 10px;
        gap: 2px;
        padding: 4px 8px;
        border-radius: 8px;
        transition: all 0.2s;
    }
    
    .bottom-nav a.active {
        color: var(--primary);
        background: #f0f2f5;
    }
    
    .bottom-nav a .nav-icon {
        font-size: 20px;
    }
    
    /* Отступ снизу для контента */
    body {
        padding-bottom: 70px !important;
    }
}

/* === 6. ГРИД МЕНЮ (DASHBOARD) === */
@media (max-width: 480px) {
    .menu-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    
    .menu-item {
        padding: 16px 8px !important;
        font-size: 12px !important;
    }
    
    .menu-item .icon {
        font-size: 24px !important;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }
    
    .stat-card {
        padding: 12px 8px !important;
    }
    
    .stat-card .number {
        font-size: 18px !important;
    }
    
    .stat-card .label {
        font-size: 10px !important;
    }
}

/* === 7. КАРТОЧКИ КЛИЕНТОВ (МОБИЛЬНЫЙ ВИД) === */
@media (max-width: 768px) {
    .clients-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    
    .client-card {
        padding: 16px !important;
        border-radius: 16px !important;
        position: relative;
        overflow: hidden;
    }
    
    /* Левая цветная полоса */
    .client-card::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 4px;
        background: var(--info);
        border-radius: 4px 0 0 4px;
    }
    
    .client-card .name {
        font-size: 16px !important;
        padding-left: 8px;
    }
    
    .client-card .info {
        padding-left: 8px;
    }
    
    .client-card .card-actions {
        flex-direction: row !important;
        gap: 6px !important;
    }
    
    .client-card .card-actions button {
        padding: 10px 12px !important;
        font-size: 13px !important;
        border-radius: 10px !important;
    }
}

/* === 8. КНОПКИ В СТОЛБИК НА МОБИЛЬНЫХ === */
@media (max-width: 480px) {
    .btn-add {
        float: none !important;
        width: 100% !important;
        margin-top: 8px !important;
        padding: 12px !important;
        font-size: 14px !important;
        border-radius: 12px !important;
    }
    
    .btn-back {
        width: 100% !important;
        justify-content: center !important;
        padding: 12px !important;
        margin-bottom: 12px !important;
    }
}

/* === 9. ФОРМЫ И МОДАЛЬНЫЕ ОКНА === */
@media (max-width: 768px) {
    .modal {
        margin: 12px !important;
        padding: 20px !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 85vh !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: auto !important;
        max-width: none !important;
        animation: slideUpMobile 0.3s ease !important;
    }
    
    @keyframes slideUpMobile {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    
    .modal-overlay {
        align-items: flex-end !important;
    }
    
    .modal .modal-header h3 {
        font-size: 18px !important;
    }
    
    .form-group label {
        font-size: 13px !important;
    }
    
    .form-group input,
    .form-group select {
        padding: 12px !important;
        font-size: 16px !important; /* Предотвращает зум на iOS */
        border-radius: 10px !important;
    }
    
    .btn-primary,
    .btn-danger {
        padding: 14px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
    }
    
    /* Кнопка закрытия модалки - больше для пальца */
    .modal .modal-close {
        width: 36px;
        height: 36px;
        font-size: 22px !important;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50% !important;
        background: #f0f2f5;
    }
}

/* === 10. ТАБЫ В МОБИЛЬНОЙ ВЕРСИИ === */
@media (max-width: 480px) {
    .tabs {
        border-radius: 12px !important;
        overflow: hidden;
    }
    
    .tabs .tab {
        font-size: 11px !important;
        padding: 10px 6px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* === 11. КАРТОЧКИ ДЕТАЛЕЙ КЛИЕНТА === */
@media (max-width: 480px) {
    .card {
        padding: 14px !important;
        border-radius: 16px !important;
        margin-bottom: 12px !important;
    }
    
    .card h2 {
        font-size: 16px !important;
        margin-bottom: 10px !important;
    }
    
    .info-row {
        flex-direction: column !important;
        gap: 4px !important;
        padding: 8px 0 !important;
    }
    
    .info-row .label {
        font-size: 12px !important;
        color: var(--text-secondary) !important;
    }
    
    .info-row .value {
        font-size: 14px !important;
    }
    
    /* Индикатор для swipe */
    .card .swipe-indicator {
        display: block;
        width: 40px;
        height: 4px;
        background: #dee2e6;
        border-radius: 2px;
        margin: 0 auto 12px;
    }
}

/* === 12. ФОТО-ГРИД ДЛЯ МОБИЛЬНЫХ === */
@media (max-width: 480px) {
    .photos-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
    }
    
    .photos-grid img {
        height: 90px !important;
        border-radius: 10px !important;
    }
}

/* === 13. TOAST-УВЕДОМЛЕНИЯ === */
@media (max-width: 480px) {
    .toast {
        bottom: 80px !important;
        left: 16px !important;
        right: 16px !important;
        transform: none !important;
        text-align: center;
        font-size: 13px !important;
        padding: 12px 16px !important;
        border-radius: 12px !important;
    }
}

/* === 14. ПОИСКОВАЯ СТРОКА === */
@media (max-width: 480px) {
    .search-bar {
        padding: 12px 16px !important;
        font-size: 16px !important;
        border-radius: 12px !important;
        margin-bottom: 12px !important;
    }
}

/* === 15. УЛУЧШЕНИЯ ДЛЯ СТРАНИЦЫ КЛИЕНТА (client-page.html) === */
@media (max-width: 480px) {
    .header p {
        font-size: 11px !important;
    }
    
    .note-item {
        padding: 14px !important;
        margin-bottom: 10px !important;
        border-radius: 12px !important;
    }
    
    .form-group textarea {
        border-radius: 12px !important;
        padding: 12px !important;
        font-size: 16px !important;
    }
    
    .btn {
        padding: 10px 14px !important;
        border-radius: 10px !important;
        font-size: 13px !important;
    }
}

/* === 16. АНИМАЦИИ И МИКРОВЗАИМОДЕЙСТВИЯ === */

/* Эффект нажатия */
@media (hover: none) {
    .menu-item:active,
    .client-card:active,
    button:active,
    .tab:active {
        transform: scale(0.97) !important;
        transition: transform 0.1s !important;
    }
}

/* Пульсация для кнопки создания */
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(39, 174, 96, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(39, 174, 96, 0); }
}

@media (max-width: 480px) {
    .menu-item.create {
        animation: pulse 2s infinite;
    }
}

/* === 17. БЕЗОПАСНАЯ ЗОНА ДЛЯ iPHONE X+ === */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .bottom-nav {
            padding-bottom: max(8px, env(safe-area-inset-bottom));
        }
        
        .container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}

/* === 18. ТЁМНАЯ ТЕМА (ОПЦИОНАЛЬНО) === */
@media (prefers-color-scheme: dark) {
    /* Раскомментируйте для авто-тёмной темы */
    /*
    body {
        background: #1a1a2e;
        color: #e0e0e0;
    }
    .card, .client-card, .stat-card, .menu-item {
        background: #16213e;
        color: #e0e0e0;
    }
    */
}

/* === 19. SPINNER УЛУЧШЕННЫЙ === */
@media (max-width: 480px) {
    .loading .spinner {
        width: 32px !important;
        height: 32px !important;
    }
}

/* === 20. ПУСТЫЕ СОСТОЯНИЯ === */
@media (max-width: 480px) {
    .empty-state {
        padding: 40px 20px !important;
    }
    
    .empty-state .icon {
        font-size: 40px !important;
    }
    
    .empty-state p {
        font-size: 14px !important;
    }
}