/**
 * CSS для мобильной оптимизации
 * Touch-интерфейсы, жесты, адаптивность
 */

/* ==================== TOUCH-ИНТЕРФЕЙСЫ ==================== */

/* Улучшаем touch-цели */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    padding: 12px;
    margin: 4px;
    border-radius: 8px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Активное состояние для touch — без сужения */
.touch-active {
    transform: none;
    opacity: 0.9;
    transition: all 0.1s ease;
}

/* Кнопки с улучшенной touch-областью */
.btn-touch {
    position: relative;
    min-height: 48px;
    min-width: 48px;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.btn-touch:active {
    transform: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* ==================== СВАЙПАЕМЫЕ КАРТОЧКИ ==================== */

.swipeable-card {
    position: relative;
    transition: all 0.3s ease;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    touch-action: pan-y;
}

.swipeable-card:active {
    cursor: grabbing;
}

.swipeable-card.swipe-left {
    transform: translateX(-100%);
    opacity: 0;
}

.swipeable-card.swipe-right {
    transform: translateX(100%);
    opacity: 0;
}

/* Индикаторы свайпа */
.swipe-indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 24px;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: 10;
}

.swipe-indicator.left {
    left: 20px;
    color: #dc3545;
}

.swipe-indicator.right {
    right: 20px;
    color: #28a745;
}

.swipeable-card.swipe-left .swipe-indicator.left,
.swipeable-card.swipe-right .swipe-indicator.right {
    opacity: 1;
}

/* ==================== ГАЛЕРЕЯ ИЗОБРАЖЕНИЙ ==================== */

.image-gallery {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: #f8f9fa;
}

.gallery-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gallery-image.active {
    opacity: 1;
}

.gallery-indicators {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.gallery-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255,255,255,0.5);
    transition: all 0.3s ease;
    cursor: pointer;
}

.gallery-indicator.active {
    background: white;
    transform: scale(1.2);
}

/* ==================== МАСШТАБИРУЕМЫЕ ИЗОБРАЖЕНИЯ ==================== */

.zoomable-image {
    transition: transform 0.3s ease;
    cursor: zoom-in;
    max-width: 100%;
    height: auto;
}

.zoomable-image.zoomed {
    cursor: zoom-out;
}

/* ==================== КОНТЕКСТНОЕ МЕНЮ ==================== */

.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 10000;
    overflow: hidden;
    animation: contextMenuAppear 0.2s ease;
}

@keyframes contextMenuAppear {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-item {
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background: #f8f9fa;
}

.context-menu-item:active {
    background: #e9ecef;
}

/* ==================== ЛЕНИВАЯ ЗАГРУЗКА ==================== */

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
    background: #f8f9fa;
    background-image: 
        linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.lazy-image.loaded {
    opacity: 1;
    background: none;
}

/* Плейсхолдер для ленивой загрузки */
.lazy-placeholder {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ==================== МОБИЛЬНАЯ НАВИГАЦИЯ ==================== */

.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-around;
    padding: 8px 0;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 12px;
    text-decoration: none;
    color: #666;
    transition: color 0.2s ease;
    min-width: 60px;
}

.mobile-nav-item.active {
    color: #007bff;
}

.mobile-nav-item i {
    font-size: 20px;
    margin-bottom: 4px;
}

.mobile-nav-item span {
    font-size: 12px;
    font-weight: 500;
}

/* ==================== ПУЛЛ-ТУ-РЕФРЕШ ==================== */

.pull-to-refresh {
    position: relative;
    overflow: hidden;
}

.pull-to-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    color: #666;
    font-size: 14px;
    transition: top 0.3s ease;
}

.pull-to-refresh-indicator.active {
    top: 20px;
}

.pull-to-refresh-indicator i {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== МОДАЛЬНЫЕ ОКНА ДЛЯ МОБИЛЬНЫХ ==================== */

.mobile-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: flex-end;
    animation: modalAppear 0.3s ease;
}

.mobile-modal-content {
    background: white;
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalAppear {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* ==================== АДАПТИВНЫЕ КАРТОЧКИ ==================== */

.mobile-card {
    background: white;
    border-radius: 16px;
    padding: 16px;
    margin: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}

.mobile-card:active {
    transform: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.mobile-card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.mobile-card-title {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

.mobile-card-subtitle {
    font-size: 14px;
    color: #666;
    margin: 4px 0 0 0;
}

/* ==================== МОБИЛЬНЫЕ ФОРМЫ ==================== */

.mobile-form {
    padding: 20px;
}

.mobile-form .form-group {
    margin-bottom: 20px;
}

.mobile-form .form-control {
    height: 48px;
    font-size: 16px;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    padding: 12px 16px;
    transition: border-color 0.2s ease;
}

.mobile-form .form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

.mobile-form .btn {
    height: 48px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 12px;
    padding: 12px 24px;
}

/* ==================== МОБИЛЬНЫЕ ТАБЛИЦЫ ==================== */

.mobile-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-table table {
    min-width: 600px;
}

.mobile-table th,
.mobile-table td {
    padding: 12px 8px;
    white-space: nowrap;
}

/* ==================== МОБИЛЬНЫЕ УВЕДОМЛЕНИЯ ==================== */

.mobile-notification {
    position: fixed;
    top: 20px;
    left: 20px;
    right: 20px;
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 10000;
    animation: notificationSlideDown 0.3s ease;
}

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

/* ==================== МЕДИА-ЗАПРОСЫ ==================== */

@media (max-width: 768px) {
    /* Скрываем элементы, не нужные на мобильных */
    .desktop-only {
        display: none !important;
    }
    
    /* Показываем мобильные элементы */
    .mobile-only {
        display: block !important;
    }
    
    /* Улучшаем touch-цели */
    .btn, .nav-link, .dropdown-toggle {
        min-height: 44px;
        min-width: 44px;
        padding: 12px;
    }
    
    /* Адаптируем карточки */
    .card {
        margin: 8px;
        border-radius: 16px;
    }
    
    /* Улучшаем формы */
    .form-control {
        font-size: 16px; /* Предотвращает зум на iOS */
    }
}

@media (max-width: 480px) {
    /* Дополнительные стили для маленьких экранов */
    .container {
        padding: 0 16px;
    }
    
    .mobile-card {
        margin: 4px;
        padding: 12px;
    }
    
    .mobile-nav-item {
        padding: 6px 8px;
        min-width: 50px;
    }
    
    .mobile-nav-item i {
        font-size: 18px;
    }
    
    .mobile-nav-item span {
        font-size: 10px;
    }
}

/* ==================== ПОДДЕРЖКА ТЕМНОЙ ТЕМЫ ==================== */

@media (prefers-color-scheme: dark) {
    .mobile-card {
        background: #2d2d2d;
        color: white;
    }
    
    .mobile-modal-content {
        background: #2d2d2d;
        color: white;
    }
    
    .context-menu {
        background: #2d2d2d;
        color: white;
    }
    
    .context-menu-item {
        border-bottom-color: #404040;
    }
    
    .context-menu-item:hover {
        background: #404040;
    }
}

/* ==================== АНИМАЦИИ ПРОИЗВОДИТЕЛЬНОСТИ ==================== */

/* Используем transform и opacity для плавных анимаций */
.smooth-transition {
    transition: transform 0.3s ease, opacity 0.3s ease;
    will-change: transform, opacity;
}

/* Оптимизируем анимации для мобильных */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Отключаем «сужение» при тапе по всей мобильной версии */
@media (max-width: 768px) {
    .mobile-card:active,
    .btn-touch:active {
        transform: none !important;
    }
    body.page-create-tournament main *:not(input):not(textarea):not(select):not(.scroll-to-top-btn):active,
    body.page-club-register main *:not(input):not(textarea):not(select):not(.scroll-to-top-btn):active,
    body.page-signup main *:not(input):not(textarea):not(select):not(.scroll-to-top-btn):active {
        transform: none !important;
    }
}
