/**
 * Глобальные оптимизации для мобильных устройств
 * Touch-friendly элементы, оптимизация форм, предотвращение зума
 */

/* Оптимизация форм для мобильных устройств */
@media (max-width: 768px) {
    /* Предотвращение зума на iOS при фокусе на input */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="search"],
    textarea,
    select {
        font-size: 16px !important;
    }
    
    /* Специальные стили для input[type="file"] на мобильных */
    input[type="file"] {
        font-size: 16px !important;
        min-height: 44px !important;
        padding: 0.75rem !important;
        width: 100% !important;
        touch-action: auto !important;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1) !important;
        cursor: pointer !important;
        /* Убеждаемся, что input доступен для взаимодействия */
        pointer-events: auto !important;
        position: relative !important;
        z-index: 1 !important;
    }
    
    /* Улучшаем видимость input[type="file"] на мобильных */
    input[type="file"]::-webkit-file-upload-button {
        min-height: 44px !important;
        padding: 0.75rem 1.5rem !important;
        font-size: 16px !important;
        cursor: pointer !important;
    }
    
    /* Улучшаем размеры кнопок для touch */
    .btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0.75rem 1.5rem;
        font-size: 16px;
    }
    
    .btn-sm {
        min-height: 36px;
        min-width: 36px;
        padding: 0.5rem 1rem;
        font-size: 14px;
    }
    
    .btn-lg {
        min-height: 48px;
        min-width: 48px;
        padding: 1rem 2rem;
        font-size: 18px;
    }
    
    /* Улучшаем размеры ссылок для touch */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    /* Оптимизация модальных окон */
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 10px;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 1rem;
    }
    
    /* Убеждаемся, что input[type="file"] в модальном окне доступен */
    .modal-body input[type="file"] {
        position: relative;
        z-index: 10;
        pointer-events: auto !important;
        touch-action: auto !important;
    }
    
    /* Улучшаем размеры элементов формы */
    .form-control,
    .form-select {
        min-height: 44px;
        padding: 0.75rem;
    }
    
    .form-label {
        font-size: 14px;
        margin-bottom: 0.5rem;
    }
    
    /* Улучшаем размеры чекбоксов и радиокнопок */
    .form-check-input {
        width: 20px;
        height: 20px;
        margin-top: 0.25rem;
    }
    
    .form-check-label {
        font-size: 14px;
        padding-left: 0.5rem;
    }
    
    /* Улучшаем размеры dropdown */
    .dropdown-toggle {
        min-height: 44px;
        min-width: 44px;
    }
    
    .dropdown-item {
        min-height: 44px;
        padding: 0.75rem 1rem;
        font-size: 14px;
    }
}

/* Дополнительные оптимизации для очень маленьких экранов */
@media (max-width: 480px) {
    .btn {
        padding: 0.6rem 1.2rem;
        font-size: 15px;
    }
    
    .modal-dialog {
        margin: 0.25rem;
        max-width: calc(100% - 0.5rem);
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 0.75rem;
    }
    
    .form-control,
    .form-select {
        padding: 0.6rem;
    }
}

/* Аватары: не сжимать в овал на мобильных (всегда круг) */
@media (max-width: 768px) {
    .avatar-with-status {
        flex-shrink: 0 !important;
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }
    .avatar-with-status.small { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
    .avatar-with-status.medium { width: 48px; height: 48px; min-width: 48px; min-height: 48px; }
    .avatar-with-status.large { width: 64px; height: 64px; min-width: 64px; min-height: 64px; }
    .avatar-with-status.xs { width: 32px; height: 32px; min-width: 32px; min-height: 32px; }
    .avatar-with-status.header { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
    .avatar-with-status img,
    .avatar-with-status > .rounded-circle {
        width: 100% !important;
        height: 100% !important;
        min-width: 100%;
        min-height: 100%;
        aspect-ratio: 1 !important;
        object-fit: cover !important;
        border-radius: 50% !important;
    }
}

/* Оптимизация для touch-устройств */
@media (hover: none) and (pointer: coarse) {
    /* Убираем hover эффекты на touch-устройствах */
    *:hover {
        /* Сохраняем hover для элементов, которые должны его иметь */
    }
    
    /* Добавляем активные состояния для touch */
    .btn:active,
    a:active,
    .nav-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
        transition: transform 0.1s, opacity 0.1s;
    }
    
    /* Улучшаем обратную связь при касании (исключаем input[type="file"]) */
    input:not([type="file"]):active,
    textarea:active,
    select:active {
        border-color: #5B61FF;
    }
    
    /* Улучшаем обратную связь для ссылок */
    a:active {
        opacity: 0.7;
    }
    
    /* Специальная обработка для input[type="file"] на touch-устройствах */
    input[type="file"]:active {
        opacity: 0.8;
    }
}

/* Предотвращение выделения текста при двойном тапе (для кнопок) */
.btn,
.nav-btn,
button,
a.btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Оптимизация прокрутки на мобильных */
@media (max-width: 768px) {
    * {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Улучшаем прокрутку для модальных окон */
    .modal-body {
        -webkit-overflow-scrolling: touch;
        overflow-y: auto;
    }
}

/* Оптимизация изображений для мобильных */
@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Предотвращение переполнения */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Улучшение читаемости текста на мобильных */
@media (max-width: 768px) {
    body {
        -webkit-text-size-adjust: 100%;
        -moz-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }
    
    /* Улучшаем межстрочный интервал для читаемости */
    p {
        line-height: 1.6;
    }
    
    h1, h2, h3, h4, h5, h6 {
        line-height: 1.3;
    }
}

/* Оптимизация для landscape ориентации на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-dialog {
        max-height: 90vh;
    }
    
    .modal-body {
        max-height: calc(90vh - 120px);
        overflow-y: auto;
    }
}

/* Улучшение производительности на мобильных */
@media (max-width: 768px) {
    /* Используем transform вместо изменения размеров для анимаций */
    * {
        will-change: auto;
    }
    
    /* Оптимизация анимаций */
    * {
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}
