/* ========================================
   MOBILE v31.0 (DESKTOP ROW FIX + MOBILE SAFE)
   ======================================== */

/* --- МОБИЛЬНАЯ ВЕРСИЯ (до 768px) --- */
@media (max-width: 768px) {
    
    /* 1. ГЛОБАЛЬНЫЕ НАСТРОЙКИ */
    * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
    
    html, body {
        width: 100%;
        overflow-x: hidden !important;
        margin: 0;
        padding: 0;
        background-color: #ffffff;
    }

    .header .container, 
    .header-inner-wrapper {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 2. ШАПКА И СЛАЙДЕР (ЗАФИКСИРОВАНЫ) */
    .header {
        position: sticky; top: 0; z-index: 2000;
        background: white; width: 100%;
        box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        padding: 0; margin-bottom: 10px;
    }
    .header-inner {
        width: 100% !important; height: 60px !important;
        display: flex; flex-direction: row; align-items: center; 
        justify-content: space-between;
        padding: 0 10px !important; margin: 0 !important;
        background: white; box-shadow: none !important;
    }
    .logo { 
        order: 1; font-size: 1.1rem; margin: 0 !important; 
        margin-left: 5px !important; white-space: nowrap; color: #1e293b;
        display: flex; align-items: center; gap: 8px;
    }
    .logo-icon { width: 32px !important; height: 32px !important; }
    .btn-add-org { display: none; }
    .header-inner::after {
        content: '\f0c9'; font-family: "Font Awesome 6 Free"; font-weight: 900;
        order: 3; font-size: 24px; color: #334155; padding: 10px;
        margin-right: 5px !important; cursor: pointer; display: block; z-index: 2001;
    }
    .nav {
        position: fixed; top: 0; right: 0; width: 85%; max-width: 300px; height: 100vh;
        background: white; flex-direction: column; align-items: stretch;
        padding: 80px 20px 20px; gap: 10px; transform: translateX(100%);
        transition: transform 0.3s ease; z-index: 2000;
        box-shadow: -5px 0 25px rgba(0,0,0,0.15); overflow-y: auto; display: flex !important;
    }
    .nav.menu-open { transform: translateX(0); }
    .nav-overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.5); z-index: 1999;
        opacity: 0; visibility: hidden; transition: 0.3s;
    }
    .nav-overlay.active { opacity: 1; visibility: visible; }
    .nav-link {
        width: 100%; padding: 14px 16px; background: #f8fafc;
        border-radius: 12px; font-size: 16px; font-weight: 500;
        color: #334155; text-align: left; text-decoration: none;
    }
    .nav-link.active { background: #eff6ff; color: #2563eb; }
    .nav-dropdown { width: 100%; margin-top: 5px; }
    .nav-dropdown-toggle {
        width: 100%; text-align: left; padding: 14px 16px;
        background: #f1f5f9; border-radius: 12px; border: none;
        font-size: 16px; font-weight: 600; color: #475569;
        display: flex; justify-content: space-between;
    }
    .nav-dropdown-menu { display: none; margin-top: 5px; padding-left: 10px; }
    .nav-dropdown.open .nav-dropdown-menu { display: block; }
    .dropdown-item { display: block; padding: 12px 16px; color: #64748b; }
    .hero-slider-wrapper { width: 100%; display: block !important; margin: 0; padding: 0 16px; }
    .hero-slider-container {
        width: 100% !important; margin: 0 !important; height: 220px !important;
        border-radius: 20px; position: relative; display: block !important;
        overflow: hidden; background: #e2e8f0; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    }
    .hero-slide {
        position: absolute; top: 0; left: 0; width: 100%; height: 100%;
        opacity: 0; transition: opacity 0.5s; display: block !important;
    }
    .hero-slide.active { opacity: 1; z-index: 2; }
    .hero-slide-bg { width: 100%; height: 100%; background-size: cover !important; background-position: center !important; }
    .hero-slide-overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); z-index: 2; }
    .hero-slide-content {
        position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
        width: 100%; text-align: center; z-index: 3; padding: 0 10px;
    }
    .hero-title { font-size: 1.2rem !important; color: white; margin-bottom: 10px; text-shadow: 0 2px 4px rgba(0,0,0,0.5); font-weight: 700; }
    .hero-search { width: 95% !important; height: 44px; margin: 0 auto; background: white; border-radius: 22px; display: flex; align-items: center; padding: 0 5px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); }
    .hero-search input { border: none; outline: none; flex-grow: 1; padding-left: 15px; font-size: 14px; }
    .hero-search button { background: #2563eb; color: white; border: none; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; }
    .hero-subtitle { font-size: 0.75rem; color: white; margin-top: 8px; text-shadow: 0 1px 2px rgba(0,0,0,0.5); opacity: 0.9; }
    .slider-prev, .slider-next {
        position: absolute; top: 50%; transform: translateY(-50%);
        z-index: 10; background: rgba(255,255,255,0.2); border: none; backdrop-filter: blur(4px);
        width: 32px; height: 32px; border-radius: 50%; color: white;
        display: flex; align-items: center; justify-content: center;
    }
    .slider-prev { left: 10px; } .slider-next { right: 10px; }
    .slider-dots {
        position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%);
        display: flex; gap: 6px; z-index: 10;
    }
    .slider-dot { width: 6px; height: 6px; background: rgba(255,255,255,0.5); border-radius: 50%; transition: 0.3s; }
    .slider-dot.active { background: white; width: 18px; border-radius: 3px; }

    /* 3. КАТЕГОРИИ МОБИЛЬНЫЕ (4x2) */
    body.is-mobile .categories-section .white-card {
        padding: 15px 0 !important;
        width: 100% !important;
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
    }
    body.is-mobile .section-header { 
        padding: 0 16px !important; margin-bottom: 15px !important; 
        display: flex !important; justify-content: space-between !important; 
        align-items: baseline !important; 
    }
    body.is-mobile .section-title { 
        font-size: 1.3rem !important; font-weight: 800 !important; 
        color: #1e293b !important; margin: 0 !important; 
    }
    body.is-mobile .categories-count { 
        font-size: 0.85rem !important; color: #94a3b8 !important; 
        font-weight: 500 !important; 
    }
    body.is-mobile .categories-grid-responsive {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        padding: 0 16px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        background: transparent !important;
        border: none !important;
    }
    body.is-mobile .category-card {
        min-width: 0 !important; width: 100% !important; height: auto !important;
        display: flex !important; flex-direction: column !important;
        align-items: center !important; justify-content: center !important;
        background: transparent !important; border: none !important;
        box-shadow: none !important; border-radius: 0 !important;
        padding: 10px 2px !important; text-decoration: none !important;
    }
    body.is-mobile .category-card:active {
        opacity: 0.7 !important; transform: scale(0.95) !important;
    }
    body.is-mobile .category-icon {
        width: 42px !important; height: 42px !important; min-width: 42px !important;
        margin-bottom: 6px !important; margin-right: 0 !important;
        background: transparent !important; border-radius: 0 !important;
        display: flex !important; align-items: center !important; justify-content: center !important;
    }
    body.is-mobile .category-icon i { font-size: 24px !important; color: #475569 !important; }
    body.is-mobile .category-name {
        font-size: 11px !important; font-weight: 500 !important; color: #475569 !important;
        text-align: center !important; line-height: 1.2 !important; width: 100% !important;
        display: -webkit-box !important; -webkit-line-clamp: 2 !important;
        -webkit-box-orient: vertical !important; overflow: hidden !important;
        word-break: break-word !important;
    }
    body.is-mobile .show-all-wrapper { padding: 0 16px; margin-top: 15px; }
    body.is-mobile .btn-show-all {
        width: 100%; padding: 12px; background: white;
        border: 1px solid #e2e8f0; border-radius: 12px;
        font-weight: 600; color: #475569; font-size: 14px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    }

    /* 4. ОСТАЛЬНОЕ МОБИЛЬНОЕ */
    .companies-section .container { padding: 0 16px !important; }
    .section-subtitle { font-size: 1.3rem; font-weight: 800; color: #1e293b; margin-bottom: 15px; }
    .companies-grid { grid-template-columns: 1fr !important; gap: 16px; }
    .company-card { width: 100% !important; border-radius: 16px; overflow: hidden; background: white; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
    .company-image-wrapper { height: 180px !important; }
    .company-content { padding: 16px; }
    .news-layout { grid-template-columns: 1fr !important; }
    .news-card-horizontal { flex-direction: column; padding: 0 !important; border-radius: 16px; margin-bottom: 16px; background: white; overflow: hidden; }
    .news-card-image { width: 100% !important; height: 200px !important; }
}

/* --- ДЕСКТОПНАЯ ВЕРСИЯ (от 769px и выше) --- */
/* Эти стили применяются ТОЛЬКО на больших экранах и не ломают мобильную версию */
@media (min-width: 769px) {
    
    /* Категории в одну строку (8 колонок) */
    .categories-grid-responsive {
        display: grid !important;
        grid-template-columns: repeat(8, 1fr) !important; /* 8 в ряд */
        gap: 15px !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-sizing: border-box !important;
    }

    /* Карточки категорий на десктопе */
    .categories-grid-responsive .category-card {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        min-width: 0 !important;
        padding: 10px 5px !important;
    }

    /* Иконки на десктопе */
    .categories-grid-responsive .category-icon {
        width: 60px !important;
        height: 60px !important;
        margin-bottom: 10px !important;
        margin-right: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .categories-grid-responsive .category-icon img {
        max-width: 100%;
        max-height: 100%;
        object-fit: contain;
    }

    /* Текст на десктопе */
    .categories-grid-responsive .category-name {
        font-size: 13px !important;
        line-height: 1.3 !important;
        display: block !important;
        -webkit-line-clamp: unset !important; /* Разрешаем многострочность если нужно */
        overflow: visible !important;
    }
}