/* ==========================================================
   MOBILE & TABLET EXCLUSIVE CSS
   Breakpoints: 1024px → 900px → 768px → 480px
   ========================================================== */

/* ==========================================================
   1. BASE TABLET SETTINGS (Max 1024px)
   ========================================================== */
@media (max-width: 1024px) {

    /* Optimize header spacing for medium screens */
    .header-container { 
        gap: 0.5rem; 
    }
    
    /* Adjust navigation link size for tablet */
    nav a { 
        padding: 0.5rem 0.8rem; 
        font-size: 0.9rem; 
    }

    /* Scale hero title dynamically */
    .hero h1 { 
        font-size: clamp(2rem, 5vw, 3.5rem) !important; 
    }

    /* Tighten grid gaps to prevent horizontal overflow */
    .services-grid,
    .cities-grid,
    .category-grid,
    .offers-grid,
    .reviews-grid { 
        gap: 1.5rem; 
    }

    /* Admin items: Ensure a clean 2-column layout on tablet */
    .admin-items {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 1.5rem;
    }

    /* Footer: 2 columns on tablet for better readability */
    .footer-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 2.5rem;
    }

    /* City cards: Slightly shorter to keep content visible without excessive scrolling */
    .city-card { 
        height: 400px; 
    }
    
    .city-name { 
        font-size: 2.2rem; 
    }

    /* Add comfortable padding inside text-heavy sections */
    .about-text { 
        padding: 2.5rem; 
    }

    /* Adjust page headers for sub-pages */
    .page-header { 
        padding: 5rem 2rem 3rem; 
    }

    /* Standardize vertical spacing across all major sections */
    .services-section,
    .category-section,
    .offers-section,
    .cities-section,
    .reviews-section { 
        padding: 5rem 1.5rem; 
    }

    /* iOS Bug Prevention: 
       background-attachment: fixed causes severe rendering bugs (blur/glitch) on Safari iOS.
       This resets it to standard scrolling behavior for mobile devices. */
    .services-section,
    .category-section,
    .offers-section,
    .about-content {
        background-attachment: scroll !important;
    }
}

/* ==========================================================
   2. TRANSITION TO MOBILE NAV (Max 900px)
   ========================================================== */
@media (max-width: 900px) {

    /* Hide the admin button from the main header to save space */
    .btn-admin { 
        display: none !important; 
    }

    /* Restructure the header to fit the logo, language selector, and burger menu */
    .header-container {
        position: static !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0 !important;
    }

    /* Position language dropdown to the left */
    .lang-dropdown {
        order: 1;
        flex: 0 0 auto;
        z-index: 10;
        margin: 0 !important;
    }

    /* Language Dropdown Direction Control */
    /* Forces the dropdown to open inward toward the screen center to avoid clipping off-screen */
    [dir="ltr"] .lang-menu {
        right: auto !important;
        left: 0 !important;
    }
    
    [dir="rtl"] .lang-menu {
        left: auto !important;
        right: 0 !important;
    }

    /* Center the logo */
    .logo {
        order: 2;
        flex: 1 1 auto !important;
        position: static !important;
        display: flex !important;
        justify-content: center !important;
        margin: 0 !important;
        z-index: 10;
    }

    /* Position the hamburger menu to the right */
    .menu-toggle {
        display: flex !important;
        align-items: center !important;
        order: 3;
        flex: 0 0 auto;
        z-index: 10;
        margin: 0 !important;
    }

    /* Mobile Dropdown Navigation styling */
    nav {
        order: 10;
        flex: 0 0 100%;
        width: 100%;
        flex-direction: column;
        text-align: center;
        background: var(--primary-dark);
        padding: 0;
        margin-top: 0.6rem;
        border-radius: 10px;
        /* Start with 0 height for CSS transition */
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out;
    }

    /* Class added by JS to open the menu */
    nav.active {
        max-height: 500px;
        padding: 1rem 0;
    }

    /* Ensure touch targets inside the menu are large enough */
    nav a {
        padding: 1rem !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        display: block;
    }

    nav a:last-child { 
        border-bottom: none; 
    }
}

/* ==========================================================
   3. MAIN MOBILE VIEW (Max 768px)
   ========================================================== */
@media (max-width: 768px) {

    /* Exactly matches the header's physical height to eliminate the white gap */
    main { 
        margin-top: 55px !important; 
    }

    /* ── Header Optimization ── */
    header { 
        padding: 0.6rem 1rem !important; 
    }
    
    .logo-image { 
        height: 35px !important; 
        width: auto !important; 
    }
    
    .logo-text { 
        font-size: 1.4rem !important; 
    }
    
    .lang-dropdown .lang-btn { 
        padding: 6px 12px !important; 
        font-size: 0.9rem !important; 
    }

    /* iOS scroll fix repeated for strict 768px bounds */
    .services-section,
    .category-section,
    .offers-section,
    .about-content {
        background-attachment: scroll !important;
    }

    /* ── Floating WhatsApp Button ── */
    .btn-whatsapp,
    .header-actions .btn-whatsapp {
        position: fixed !important;
        bottom: 20px !important;
        right: 20px !important;
        z-index: 9999 !important;
        padding: 14px 20px !important;
        border-radius: 50px !important;
        box-shadow: 0 5px 20px rgba(37, 211, 102, 0.4) !important;
        font-size: 1.1rem !important;
    }

    /* ── Force Single Column Grids ── */
    .services-grid,
    .cities-grid,
    .category-grid,
    .offers-grid,
    .reviews-grid {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }

    /* ── Form Standardization ── */
    .form-row {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.2rem !important;
        margin-bottom: 0 !important;
    }

    .form-group { 
        width: 100% !important; 
        margin-bottom: 1.2rem !important; 
    }
    
    .form-group label {
        font-size: 0.95rem !important;
        margin-bottom: 0.4rem !important;
    }

    /* iOS Zoom Prevention: Input font-size MUST be at least 16px. */
    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important; 
        padding: 1rem !important;
        border-radius: 10px !important;
        min-height: 50px !important; 
    }

    /* ── Modals & Popups ── */
    .modal-overlay {
        align-items: flex-start !important;
        padding: 1rem !important;
        padding-top: 4rem !important;
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 85vh !important;
        overflow-y: auto !important;
        padding: 1.5rem !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
        border-radius: 16px !important;
    }

    .modal-buttons { 
        flex-direction: column !important; 
        gap: 1rem !important; 
        margin-top: 1.5rem !important;
    }
    
    /* Full width buttons inside modals */
    .modal-btn { 
        width: 100% !important; 
        min-height: 50px !important;
    }

    /* Prevents top-header close buttons from stretching to 100% width */
    .modal > div:first-child[style*="flex"] .modal-btn,
    .modal > div:first-child[style*="justify-content"] .modal-btn {
        width: auto !important;
        min-height: 40px !important;
        flex: 0 0 auto !important;
        padding: 0.5rem 1rem !important;
    }

/* ── CRITICAL FIX: The City Modal Anti-Overlap Protocol ── */
    /* Transforms the City Modal into a strict structural column */
    #city-modal .modal {
        display: flex !important;
        flex-direction: column !important;
        max-height: 85vh !important;
        overflow: hidden !important; 
        padding-bottom: 1rem !important;
    }

    /* REVERTED TO DISPLAY: BLOCK. 
       This completely bypasses the Flexbox height-calculation bugs.
       Standard block flow is indestructible and scrolls natively. */
    #city-offers-container {
        display: block !important;
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important; /* Smooth iOS momentum scroll */
        margin-bottom: 1rem !important;
        padding-right: 0.5rem !important; 
    }

    /* Target the bottom div holding the close button in the city modal */
    #city-modal .modal > div:last-child {
        flex: 0 0 auto !important;
        margin-top: auto !important;
        border-top: 1px solid var(--border);
        padding-top: 1rem;
        background: var(--card); 
    }

    /* Protects the cards from collapsing and adds spacing since we removed flex gap */
    #city-offers-container .offer-card {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        margin-bottom: 1.5rem !important; /* Replaces the flex gap */
        break-inside: avoid !important;
    }

    .offer-thumb, 
    .offer-image { 
        height: 180px !important; 
        flex-shrink: 0 !important; 
    }

    /* ── Hero Section ── */
    .hero { 
        min-height: 60vh; 
        padding-top: 20px; 
    }
    
    .hero h1 { 
        font-size: 2.2rem !important; 
    }
    
    .hero p { 
        font-size: 1rem !important; 
        margin-bottom: 2rem !important; 
    }
    
    .btn-book {
        padding: 1rem 2rem !important;
        font-size: 1.1rem !important;
        width: 100% !important;
        justify-content: center !important;
    }

    /* ── General Section Spacing ── */
    .section-title { 
        font-size: 1.8rem !important; 
        margin-bottom: 2rem !important; 
    }

    .services-section,
    .category-section,
    .offers-section,
    .cities-section,
    .reviews-section { 
        padding: 3rem 1rem !important; 
    }

    /* ── Standardized Card Heights & Padding ── */
    .service-card-image,
    .category-image { 
        height: 200px !important; 
    }
    
    .service-content,
    .category-content,
    .offer-content,
    .city-content { 
        padding: 1.5rem !important; 
    }

    /* ── Offer Card Layout ── */
    .offer-actions {
        flex-direction: column !important;
        gap: 0.8rem !important;
        padding: 1.2rem !important;
    }
    
    /* Ensure action buttons are full width and easy to tap */
    .btn-whatsapp-offer,
    .btn-card-explore { 
        width: 100% !important; 
        justify-content: center !important; 
        min-height: 44px !important;
    }

    /* ── City Cards ── */
    .city-card { 
        height: 320px !important; 
    }
    
    .city-name { 
        font-size: 1.8rem !important; 
    }
    
    .city-desc { 
        font-size: 0.95rem !important; 
    }
    
    .city-overlay { 
        padding: 1.5rem !important; 
    }

    /* ── Page Headers (Sub-pages) ── */
    .page-header { 
        padding: 4.5rem 1.2rem 2.5rem !important; 
    }
    
    .page-header h1 { 
        font-size: 2rem !important; 
    }
    
    .page-header p { 
        font-size: 1rem !important; 
    }

    /* ── Navigation Actions ── */
    .back-btn {
        padding: 0.8rem 1.4rem !important;
        font-size: 0.95rem !important;
        margin-bottom: 1.5rem !important;
    }

    /* ── About Text Block ── */
    .about-text {
        padding: 1.8rem !important;
        font-size: 1rem !important;
        border-radius: 12px !important;
    }

    /* ── Customer Reviews ── */
    .review-card { 
        padding: 1.5rem !important; 
    }

    /* ── Footer Elements ── */
    footer { 
        padding: 3.5rem 1.2rem 2rem !important; 
    }
    
    .footer-container {
        grid-template-columns: 1fr !important;
        gap: 2rem !important;
    }
    
    .footer-section h3 { 
        font-size: 1.3rem !important; 
        margin-bottom: 1.2rem !important; 
    }
    
    .footer-bottom { 
        margin-top: 2rem !important; 
        font-size: 0.9rem !important; 
    }

    /* ── Admin Dashboard Overrides ── */
    .admin-dashboard { 
        padding: 2rem 1rem !important; 
    }
    
    .admin-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem !important;
    }
    
    .admin-header h2 { 
        font-size: 1.6rem !important; 
    }
    
    /* Allow admin tabs to scroll horizontally if they overflow */
    .admin-tabs {
        padding: 0.6rem !important;
        gap: 0.5rem !important;
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .admin-tab { 
        padding: 0.8rem 1.2rem !important; 
        font-size: 0.95rem !important; 
        white-space: nowrap; 
    }
    
    .admin-form { 
        padding: 1.5rem !important; 
        border-radius: 12px !important; 
    }
    
    .admin-form h3 { 
        font-size: 1.3rem !important; 
    }
    
    .admin-items {
        grid-template-columns: 1fr !important;
        gap: 1.2rem !important;
    }
    
    .admin-item { 
        padding: 1.5rem !important; 
        border-radius: 12px !important; 
    }
    
    .btn-add {
        width: 100% !important;
        padding: 1rem !important;
        font-size: 1.1rem !important;
    }
    
    .upload-area { 
        padding: 1.5rem !important; 
    }

    /* ── Login Interface ── */
    .login-card {
        padding: 2.5rem 1.5rem !important;
        border-radius: 16px !important;
    }
    
    .login-card h2 { 
        font-size: 1.8rem !important; 
        margin-bottom: 1.8rem !important; 
    }
    
    .role-btn { 
        padding: 1rem !important; 
        font-size: 0.95rem !important; 
    }

    /* ── Modal Gallery Tweaks ── */
    .gallery-main {
        min-height: 200px !important;
        max-height: 280px !important;
        border-radius: 10px !important;
    }
    
    .gallery-nav-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 0.9rem !important;
    }
    
    .story-strip { 
        gap: 10px !important; 
        min-height: 80px !important; 
    }
    
    .story-thumb { 
        width: 100px !important; 
        height: 65px !important; 
    }
    
    #offer-modal-desc { 
        max-height: 180px !important; 
        font-size: 0.95rem !important; 
    }
}

/* ==========================================================
   4. SMALL PHONE VIEW (Max 480px)
   ========================================================== */
@media (max-width: 480px) {

    /* Tighten header for very small screens */
    .logo-text { 
        font-size: 1.2rem !important; 
    }
    
    .menu-toggle { 
        font-size: 1.5rem !important; 
    }

    /* Hero section scaling */
    .hero { 
        min-height: 55vh !important; 
    }
    
    .hero h1 { 
        font-size: 1.8rem !important; 
        line-height: 1.3 !important; 
    }

    /* Typography scaling */
    .section-title { 
        font-size: 1.5rem !important; 
        margin-bottom: 1.5rem !important; 
    }

    /* Card scaling */
    .service-card-image,
    .category-image { 
        height: 180px !important; 
    }
    
    .service-content,
    .category-content,
    .offer-content { 
        padding: 1.2rem !important; 
    }

    /* City scaling */
    .city-card { 
        height: 280px !important; 
    }
    
    .city-name { 
        font-size: 1.5rem !important; 
    }

    /* Keep floating button safe from bottom system bars */
    .btn-whatsapp,
    .header-actions .btn-whatsapp {
        bottom: 15px !important;
        right: 15px !important;
        padding: 12px 16px !important;
        font-size: 1rem !important;
    }

    /* Modal padding reduction to maximize screen real estate */
    .modal {
        padding: 1.2rem 1rem !important;
        max-height: 85vh !important;
    }
    
    .modal h3 { 
        font-size: 1.3rem !important; 
    }
    
    /* Ensure form elements maintain legibility */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important; /* Retained to prevent iOS zoom */
        padding: 0.8rem !important;
    }

    /* Admin layout specific tight spacing */
    .admin-dashboard { 
        padding: 1.5rem 0.5rem !important; 
    }
    
    .admin-form { 
        padding: 1.2rem !important; 
    }
    
    .admin-item { 
        padding: 1.2rem !important; 
    }

    /* Gallery tweaks for narrow screens */
    .gallery-main { 
        min-height: 180px !important; 
        max-height: 240px !important; 
    }
    
    .story-thumb { 
        width: 80px !important; 
        height: 55px !important; 
    }
}


/* ==========================================================
   CRITICAL FIX: SCROLL BLEED & BACKGROUND LOCK
   ========================================================== */

/* This class is dynamically applied to the <body> by ui.js when any modal opens.
   It completely freezes the background page. */
body.modal-open {
    overflow: hidden !important;
}

/* overscroll-behavior: contain traps the scroll momentum inside the modal.
   It tells the browser: "Do not pass the scroll action to the parent container." */
.modal-overlay, 
.modal, 
#city-offers-container, 
#offer-modal-desc,
.offer-gallery {
    overscroll-behavior: contain !important;
}