/* 📱 ОПТИМИЗИРОВАННЫЕ МОБИЛЬНЫЕ СТИЛИ */
/* Все media queries объединены для лучшей производительности */
:root {
    --safe-area-top: env(safe-area-inset-top);
    --safe-area-bottom: env(safe-area-inset-bottom);
    --safe-area-left: env(safe-area-inset-left);
    --safe-area-right: env(safe-area-inset-right);
}
/* ============================================
   🍔 КНОПКА БУРГЕР-МЕНЮ (вне media query)
   ============================================ */

.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    z-index: 1001;
    transition: all 0.3s ease;
}

.mobile-menu-btn span {
    width: 100%;
    height: 3px;
    background: var(--primary-color);
    border-radius: 10px;
    transition: all 0.3s ease;
}

.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

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

.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* ============================================
   📱 ВЫДВИЖНОЕ БОКОВОЕ МЕНЮ (вне media query)
   ============================================ */

.mobile-menu {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    height: 100dvh;
    background: white;
    z-index: 1002;
    transition: left 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
}

.mobile-menu.active {
    left: 0;
}

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

.mobile-menu-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.mobile-menu-close {
    width: 36px;
    height: 36px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.mobile-menu-close:active {
    background: rgba(0, 0, 0, 0.05);
    transform: scale(0.95);
}

.mobile-menu-items {
    list-style: none;
    padding: 1rem 0;
    margin: 0;
    flex: 1;
}

.mobile-menu-items li {
    margin: 0;
}

.mobile-menu-items a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.mobile-menu-items a:active {
    background: var(--background-light);
    border-left-color: var(--primary-color);
}

.mobile-menu-items .menu-icon {
    font-size: 1.5rem;
    width: 32px;
    text-align: center;
}

.menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 1.5rem;
}

.mobile-menu-cta {
    background: var(--gradient-primary) !important;
    color: white !important;
    border-radius: 12px;
    margin: 0.5rem 1rem;
    font-weight: 600;
}

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

.mobile-lang-selector {
    display: flex;
    flex-direction: column;
}

.mobile-lang-btn {
    padding: 0.75rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
}

.mobile-lang-btn.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.mobile-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   🌐 ГОСТЕВАЯ ПАНЕЛЬ В HEADER (язык + войти)
   Работает на ВСЕХ устройствах (десктоп + мобильные)
   ======================================== */

.guest-header-actions {
    display: none;
    align-items: center;
    gap: 0.75rem;
}

.guest-lang-btn {
    position: relative;
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 0.6rem 1rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    min-width: 60px;
    justify-content: center;
}

.guest-lang-btn:hover {
    background: rgba(0, 201, 167, 0.1);
}

.guest-lang-btn:active {
    transform: scale(0.95);
    background: rgba(0, 201, 167, 0.15);
}

.guest-lang-dropdown {
    position: absolute;
    top: calc(100% + 0.75rem);
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    min-width: 180px;
    display: none;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1100;
}

.guest-lang-dropdown.show {
    display: block;
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.guest-lang-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.guest-lang-option:hover {
    background: var(--background-light);
}

.guest-lang-option:active {
    background: var(--background-light);
}

.guest-lang-option.active {
    background: var(--gradient-primary);
    color: white;
}

.btn-guest-login {
    background: var(--gradient-primary);
    color: white;
    padding: 0.6rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    display: inline-block;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0, 201, 167, 0.3);
}

.btn-guest-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 201, 167, 0.4);
}

.btn-guest-login:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px rgba(0, 201, 167, 0.4);
}

/* ============================================
   📱 ОСНОВНЫЕ МОБИЛЬНЫЕ СТИЛИ (max-width: 768px)
   ВСЕ ОБЪЕДИНЕНО В ОДИН БЛОК!
   ============================================ */

@media (max-width: 768px) {
    
    /* ========================================
       HEADER
       ======================================== */
    
    header {
        padding: 0.75rem 0;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 1000 !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(10px) !important;
    }

    .header-content {
        padding: 0 1rem;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
    }

    .logo {
        font-size: 1.2rem;
        flex-shrink: 0;
    }

    .mobile-menu-btn {
        display: flex;
        flex-shrink: 0;
    }

    .desktop-nav {
        display: none !important;
    }

    /* Мобильные переопределения для гостевой панели */
    .guest-header-actions {
        display: flex;
        gap: 0.5rem;
    }

    .guest-lang-btn {
        padding: 0.4rem 0.6rem;
        font-size: 0.9rem;
        gap: 0.25rem;
        min-width: 50px;
    }

    .guest-lang-dropdown {
        min-width: 160px;
    }

    .btn-guest-login {
        padding: 0.5rem 1.25rem;
        font-size: 0.9rem;
        box-shadow: 0 2px 8px rgba(0, 201, 167, 0.3);
    }

    .btn-guest-login:active {
        transform: scale(0.95);
        box-shadow: 0 1px 4px rgba(0, 201, 167, 0.4);
    }

    /* ========================================
       MAIN КОНТЕНТ
       ======================================== */
    
    main {
        padding: 0rem !important;
        margin-top: 60px !important; /* Отступ от header */
        margin-bottom: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 0 !important;
    }

    .container {
        padding: 0 0.5rem;
    }

    /* ========================================
       HERO СЕКЦИЯ (Главная страница)
       ======================================== */
    
    .hero {
        padding: 2.5rem 1rem !important;
        margin-bottom: 2rem;
        border-radius: 12px !important;
    }

    .hero::before {
        display: none;
    }

    .hero-content {
        grid-template-columns: 1fr !important;
        gap: 2rem;
        text-align: center;
    }

    .hero-text {
        padding: 0;
    }

    .hero-text h1 {
        font-size: 1.85rem !important;
        line-height: 1.3 !important;
        margin-bottom: 1rem !important;
    }

    .hero-text h1 br {
        display: none;
    }

    .hero-text p {
        font-size: 1rem !important;
        line-height: 1.6 !important;
        margin-bottom: 1.5rem !important;
    }

    .hero-buttons {
        flex-direction: column;
        gap: 0.75rem;
        justify-content: center;
        width: 100%;
    }

    .hero-image {
        display: none;
    }

    /* ========================================
       КНОПКИ
       ======================================== */
    
    .btn {
        width: 100%;
        padding: 1rem 1.5rem !important;
        font-size: 1rem !important;
        text-align: center;
        justify-content: center;
    }

    .btn-large {
        padding: 1.125rem 1.5rem !important;
        font-size: 1.05rem !important;
    }

    .btn-outline {
        border-width: 2px;
    }

    /* Ripple эффект при нажатии */
    .btn::after,
    .mobile-menu-items a::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        transition: width 0.3s, height 0.3s;
    }

    .btn:active::after,
    .mobile-menu-items a:active::after {
        width: 100px;
        height: 100px;
    }

    /* ========================================
       КАРТОЧКИ
       ======================================== */
    
    .card-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .card {
        padding: 1.5rem !important;
        margin: 0 !important;
    }

    .card h3 {
        font-size: 1.3rem !important;
    }

    .card p {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    /* ========================================
       СЕКЦИИ
       ======================================== */
    
    section {
        padding: 2.5rem 1rem !important;
    }

    section h2 {
        font-size: 1.75rem !important;
        margin-bottom: 1.5rem !important;
    }

    section p {
        font-size: 0.95rem !important;
        line-height: 1.6 !important;
    }

    /* ========================================
       ФУТЕР
       ======================================== */
    
    footer {
        padding: 2rem 1rem !important;
    }

    footer .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 2rem;
    }

    footer h4 {
        font-size: 1.1rem !important;
    }

    /* ========================================
       ФОРМЫ
       ======================================== */
    
    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px !important; /* Предотвращает zoom на iOS */
        padding: 0.875rem !important;
    }

    /* ========================================
       ЧАТ
       ======================================== */
    
    .chat-container {
        max-height: 400px !important;
        padding: 1rem !important;
    }

    .message-bubble {
        max-width: 85% !important;
        padding: 0.875rem 1.125rem !important;
        font-size: 0.95rem !important;
    }

    /* ========================================
       ДАШБОРД
       ======================================== */
    
    .dashboard-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .stat-card {
        padding: 1.25rem !important;
    }

    .stat-card h3 {
        font-size: 2rem !important;
    }

    /* ========================================
       МЕДИЦИНСКАЯ АНКЕТА
       ======================================== */
    
    #medical-view-mode .info-grid,
    #medical-edit-mode .info-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    #medical-view-mode .info-row,
    #medical-edit-mode .info-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    #medical-view-mode p,
    #medical-edit-mode p {
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    #medical-view-mode strong,
    #medical-edit-mode strong {
        font-size: 0.85rem !important;
        color: #4a5568 !important;
    }
    
    #medical-view-mode span,
    #medical-edit-mode span {
        font-size: 1rem !important;
        color: #1a202c !important;
        font-weight: 600 !important;
    }
    
    #medical-edit-mode input,
    #medical-edit-mode select {
        width: 100% !important;
        padding: 0.75rem !important;
        font-size: 16px !important;
        border: 2px solid #e2e8f0 !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
    }
    
    #medical-edit-mode textarea {
        width: 100% !important;
        min-height: 100px !important;
        padding: 0.75rem !important;
        font-size: 16px !important;
        border: 2px solid #e2e8f0 !important;
        border-radius: 8px !important;
        box-sizing: border-box !important;
        resize: vertical !important;
    }
    
    .card button[style*="display: flex"] {
        width: 100% !important;
        justify-content: center !important;
    }

    /* ========================================
       UTILITY КЛАССЫ
       ======================================== */
    
    .text-center {
        text-align: center !important;
    }

    .mb-4 {
        margin-bottom: 2rem !important;
    }

    /* ========================================
       TOUCH-FRIENDLY ЭЛЕМЕНТЫ
       ======================================== */
    
    a, button, input[type="submit"], .btn {
        min-height: 44px;
        min-width: 44px;
    }

    nav ul {
        gap: 1.5rem;
    }

    /* ========================================
       УБИРАЕМ HOVER ЭФФЕКТЫ НА TOUCH
       ======================================== */
    
    .btn:hover,
    .card:hover,
    .stat-card:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .card:active,
    .stat-card:active {
        transform: translateY(2px);
    }

    /* ========================================
       ОТКЛЮЧАЕМ ВЫДЕЛЕНИЕ ДЛЯ UI
       ======================================== */
    
    .mobile-menu-btn,
    .mobile-menu-items a,
    .btn,
    header {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* ========================================
       SMOOTH SCROLLING ДЛЯ iOS
       ======================================== */
    
    body {
        -webkit-overflow-scrolling: touch;
        margin: 0;
        padding: 0;
    }

    .mobile-menu {
        height: 100vh;
        height: -webkit-fill-available;
    }

    /* ========================================
       ДОПОЛНИТЕЛЬНЫЕ УЛУЧШЕНИЯ
       ======================================== */
    
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    img {
        max-width: 100%;
        height: auto;
    }

    .sensitive-data {
        -webkit-user-select: none;
        user-select: none;
    }

    * {
        -webkit-overflow-scrolling: touch;
    }

    /* Отключаем анимации при системных настройках */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* ============================================
   📱 ОЧЕНЬ МАЛЕНЬКИЕ ЭКРАНЫ (max-width: 375px)
   ============================================ */

@media (max-width: 375px) {
    .hero-text h1 {
        font-size: 1.6rem !important;
    }

    .logo-text {
        font-size: 1rem !important;
    }

    .btn {
        padding: 0.925rem 1.25rem !important;
        font-size: 0.95rem !important;
    }

    .card {
        padding: 1.25rem !important;
    }

    .card h3 {
        font-size: 1.2rem !important;
    }

    section[style*="padding: 4rem 2rem"] h2 {
        font-size: 1.5rem !important;
    }

    /* На очень маленьких экранах медицинская анкета в 1 колонку */
    #medical-view-mode .info-row,
    #medical-edit-mode .info-row,
    div[style*="display: flex"][style*="gap: 2rem"] {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   📱 ПЛАНШЕТЫ (768px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    .hero-text h1 {
        font-size: 2.25rem;
    }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }

    main {
        padding: 2rem;
    }

    .hero {
        padding: 3rem 2rem;
    }
}

/* ============================================
   🌙 DARK MODE SUPPORT
   ============================================ */

@media (max-width: 768px) and (prefers-color-scheme: dark) {
    .mobile-menu {
        background: #1a202c;
        color: #f7fafc;
    }

    .mobile-menu-items a {
        color: #e2e8f0;
    }

    .mobile-menu-header {
        background: #2d3748;
        border-bottom-color: #4a5568;
    }

    .mobile-menu-overlay {
        background: rgba(0, 0, 0, 0.7);
    }
}