/* ==============================================
   МОБИЛЬНАЯ ОПТИМИЗАЦИЯ ДЛЯ BLA BLA VAZ
   ============================================== */

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

/* Hamburger menu button */
.mobile-menu-toggle {
    display: none;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: background 0.3s var(--transition);
}

.mobile-menu-toggle:active {
    opacity: 0.9;
}

.mobile-menu-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text-color);
    border-radius: 2px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    transition: all 0.3s var(--transition);
}

.mobile-menu-toggle span:nth-child(1) {
    top: 13px;
}

.mobile-menu-toggle span:nth-child(2) {
    top: 21px;
}

.mobile-menu-toggle span:nth-child(3) {
    top: 29px;
}

/* Анимация hamburger → X */
.mobile-menu-toggle.active span:nth-child(1) {
    top: 21px;
    transform: translateX(-50%) rotate(45deg);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    top: 21px;
    transform: translateX(-50%) rotate(-45deg);
}

/* Mobile menu overlay */
.mobile-menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.7);
    backdrop-filter: blur(8px);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.3s var(--transition);
}

.mobile-menu-overlay.active {
    display: block;
    opacity: 1;
}

/* Mobile menu panel */
.mobile-menu-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(320px, 85vw);
    background: var(--surface-strong);
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.35s var(--transition);
    z-index: 1000;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.mobile-menu-panel.active {
    transform: translateX(0);
}

.mobile-menu-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mobile-menu-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}

.mobile-menu-close {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
    border-radius: 999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.mobile-menu-items {
    flex: 1;
    padding: 1rem 0;
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    color: var(--text-color);
    cursor: pointer;
    transition: background 0.2s var(--transition);
    border-left: 3px solid transparent;
}

.mobile-menu-item:active {
    background: rgba(99, 102, 241, 0.1);
}

.mobile-menu-item.active {
    background: rgba(99, 102, 241, 0.12);
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.mobile-menu-item-icon {
    font-size: 1.3rem;
    width: 28px;
    text-align: center;
}

.mobile-menu-item-text {
    font-size: 0.95rem;
}

.mobile-menu-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
}

/* ============= TOUCH-FRIENDLY ЭЛЕМЕНТЫ ============= */

/* Увеличенные области касания для всех кнопок */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px;
        padding: 0.9rem 1.8rem;
    }

    .btn-small {
        min-height: 40px;
        padding: 0.7rem 1.3rem;
    }

    .form-control,
    input,
    select,
    textarea {
        min-height: 48px;
        padding: 1rem 1.2rem;
        font-size: 16px; /* Предотвращает zoom на iOS */
    }

    /* Увеличенные чекбоксы и радиокнопки */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
        margin-right: 0.5rem;
    }

    /* Touch-friendly navbar buttons */
    .nav-button {
        min-height: 44px;
        padding: 0.7rem 1.4rem;
    }

    /* Увеличенные иконки действий */
    .location-btn,
    .remove-waypoint-btn {
        min-width: 48px;
        min-height: 48px;
    }
}

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

@media (max-width: 768px) {
    .modal {
        padding: 0;
        align-items: flex-end;
        justify-content: flex-end;
    }

    .modal-content {
        width: 100%;
        max-height: 95vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin-bottom: 0;
        padding: 1.5rem;
        overflow-y: auto;
    }

    /* Полноэкранная карта на мобильных */
    #mapPickerModal .modal-content {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        padding: 0;
    }

    #mapPickerContainer {
        height: calc(100vh - 180px) !important;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: var(--surface-strong);
        padding: 1rem;
        margin: 0 -1.5rem -1.5rem;
    }
}

/* ============= КАРТОЧКИ И СЕТКИ ============= */

@media (max-width: 768px) {
    .glass-card {
        padding: 1.25rem;
    }

    .card,
    .surface-card {
        padding: 1rem;
    }

    /* Убираем тени на мобильных для производительности */
    body::before,
    body::after {
        filter: blur(60px);
        opacity: 0.3;
    }

    .shadow-soft,
    .glass-card,
    .card {
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.1);
    }
}

/* ============= УЛУЧШЕНИЯ ФОРМ ============= */

@media (max-width: 768px) {
    .form-section {
        padding: 1.2rem !important;
    }

    .datetime-input {
        grid-template-columns: 1fr !important;
    }

    .location-input {
        grid-template-columns: 1fr auto;
        gap: 0.5rem;
    }

    .quick-routes {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5rem;
    }

    .quick-routes .btn {
        width: 100%;
        font-size: 0.85rem;
        padding: 0.7rem 1rem;
    }

    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
    }

    .form-actions .btn {
        width: 100%;
    }

    /* Увеличенные checkbox labels для лучшего касания */
    .checkbox-label {
        padding: 0.75rem;
        background: rgba(255, 255, 255, 0.3);
        border-radius: var(--radius-sm);
        cursor: pointer;
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .checkbox-label input[type="checkbox"] {
        margin: 0;
    }
}

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

@media (max-width: 768px) {
    /* Скрываем desktop nav links */
    .nav-links {
        display: none !important;
    }

    /* Показываем hamburger menu */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Компактная navbar */
    .navbar {
        top: 12px;
        margin: 12px auto 0;
        width: calc(100% - 24px);
    }

    .nav-container {
        padding: 0.8rem 1rem;
    }

    .nav-brand h1 {
        font-size: 1.15rem;
    }

    /* Sticky bottom navigation (опционально) */
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--surface-strong);
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        padding: 0.5rem 0;
        z-index: 90;
    }

    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.25rem;
        padding: 0.5rem;
        color: var(--text-muted);
        font-size: 0.75rem;
        cursor: pointer;
        transition: color 0.2s var(--transition);
    }

    .bottom-nav-item.active {
        color: var(--primary-color);
    }

    .bottom-nav-item-icon {
        font-size: 1.3rem;
    }
}

/* ============= ТЕКСТ И ТИПОГРАФИКА ============= */

@media (max-width: 768px) {
    .page-title {
        font-size: clamp(1.75rem, 6vw, 2.4rem);
    }

    .page-subtitle {
        font-size: 0.95rem;
    }

    .hero-gradient h1 {
        font-size: clamp(2rem, 7vw, 2.8rem);
    }

    .hero-gradient p {
        font-size: 0.95rem;
    }

    .hero-gradient {
        padding: 1.75rem;
    }
}

/* ============= СПИСОК ПОЕЗДОК ============= */

@media (max-width: 768px) {
    .ride-card {
        padding: 1rem !important;
    }

    .ride-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .ride-price {
        font-size: 1.3rem;
    }

    .ride-actions {
        flex-direction: column;
        width: 100%;
    }

    .ride-actions .btn {
        width: 100%;
    }
}

/* ============= СТРАНИЦА ПРОФИЛЯ ============= */

@media (max-width: 768px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }

    .profile-avatar {
        margin: 0 auto;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
}

/* ============= ЧАТ ============= */

@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - 140px);
    }

    .chat-messages {
        padding: 1rem;
    }

    .chat-input-container {
        padding: 0.75rem 1rem;
    }
}

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

@media (max-width: 768px) {
    /* Отключаем анимации для экономии батареи */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }

    /* Упрощаем blur для производительности */
    .modal {
        backdrop-filter: blur(8px);
    }

    .glass-card,
    .navbar {
        backdrop-filter: blur(12px);
    }
}

/* ============= LANDSCAPE ORIENTATION ============= */

@media (max-width: 900px) and (orientation: landscape) {
    .navbar {
        top: 8px;
        margin-top: 8px;
    }

    .nav-container {
        padding: 0.6rem 1rem;
    }

    #mapPickerContainer {
        height: calc(100vh - 120px) !important;
    }

    .modal-content {
        max-height: 85vh;
    }
}

/* ============= ОЧЕНЬ МАЛЕНЬКИЕ ЭКРАНЫ (< 375px) ============= */

@media (max-width: 374px) {
    .container,
    .page-shell {
        width: calc(100% - 16px);
    }

    .navbar {
        width: calc(100% - 16px);
    }

    .btn {
        padding: 0.75rem 1.2rem;
        font-size: 0.9rem;
    }

    .mobile-menu-panel {
        width: 90vw;
    }
}

/* ============= БЕЗОПАСНАЯ ЗОНА ДЛЯ NOTCH ============= */

@supports (padding: max(0px)) {
    .navbar {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .bottom-nav {
        padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
    }

    .mobile-menu-panel {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============= PWA DISPLAY MODE ============= */

@media (display-mode: standalone) {
    /* Приложение запущено как PWA */
    .navbar {
        top: max(16px, env(safe-area-inset-top));
    }

    body {
        padding-top: env(safe-area-inset-top);
    }
}

/* ============= DARK MODE ADJUSTMENTS ============= */

[data-theme="dark"] {
    @media (max-width: 768px) {
        .mobile-menu-panel {
            background: var(--background-mid);
        }

        .bottom-nav {
            background: var(--surface-strong);
            border-top-color: var(--border-strong);
        }
    }
}

/* ============= ACCESSIBILITY: УВЕЛИЧЕННЫЙ ТЕКСТ ============= */

@media (min-width: 320px) {
    html {
        font-size: 16px;
    }
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

/* Поддержка крупного текста системы */
@media (prefers-color-scheme: no-preference) {
    :root {
        font-size: 16px;
    }
}
