/**
 * Responsive Improvements CSS
 * Mobile-only responsive fixes - Does NOT change desktop design
 * @format
 */

/* ============================================
   Mobile Only - Header & Navigation Fixes
   ============================================ */
@media (max-width: 768px) {
    /* Mobile icon buttons */
    #showModal,
    #toggle-sidebar {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        min-width: 44px !important;
        min-height: 44px !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #showModal i,
    #toggle-sidebar i {
        display: inline-block !important;
        visibility: visible !important;
        font-size: 1.5rem !important;
    }

    /* Hide center navigation on mobile */
    .header-nav-center {
        display: none !important;
    }

    /* Hide text navigation links on mobile (legacy support) */
    .header-menu > a.header-menu__item[href$=".html"],
    .header-menu > a.header-menu__item#showMaintenanceModal {
        display: none !important;
    }

    /* Keep these visible: language dropdown, admin icon, user icon, hamburger */
    .header-menu .language-dropdown,
    .header-menu #admin-panel-link {
        display: flex !important;
        align-items: center;
    }

    /* Navbar layout fix */
    .navbar-header {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        padding: 8px 0;
    }

    /* Logo sizing */
    .header-logo {
        flex-shrink: 0;
        max-width: 100px;
    }

    .header-logo img {
        width: 100%;
        height: auto;
        object-fit: contain;
    }

    /* Header menu items alignment */
    .header-menu {
        display: flex !important;
        align-items: center !important;
        gap: 4px;
        margin-left: auto !important;
    }

    /* Touch-friendly icon buttons */
    .header-menu #showModal,
    .header-menu #toggle-sidebar,
    .header-menu #admin-panel-link,
    .header-menu .language-dropdown > a,
    #showModal,
    #toggle-sidebar {
        min-width: 44px;
        min-height: 44px;
        display: flex !important;
        align-items: center;
        justify-content: center;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Ensure icons inside are visible */
    #showModal i,
    #toggle-sidebar i,
    #showModal .bi,
    #toggle-sidebar .bi {
        display: inline-block !important;
        visibility: visible !important;
        font-size: 1.4rem;
        color: white;
    }

    .main-header-nav.scrolled #showModal i,
    .main-header-nav.scrolled #toggle-sidebar i {
        color: #333;
    }

    /* Language dropdown - visible and clickable */
    .language-dropdown,
    #languageDropdown {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative;
        z-index: 1000;
    }

    .language-dropdown > a {
        display: flex !important;
        align-items: center;
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
    }

    .language-dropdown .lang-text {
        font-size: 12px;
        margin-left: 4px;
    }

    /* Language options dropdown - hidden by default */
    .language-dropdown .language-options,
    #languageDropdown .language-options {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        left: auto;
        min-width: 120px;
        background: white;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        z-index: 9999;
    }

    /* Styling for #langOptions when visible */
    #langOptions {
        position: absolute !important;
        top: 100% !important;
        right: 0 !important;
        background: white !important;
        min-width: 150px !important;
        border-radius: 8px !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3) !important;
        z-index: 9999 !important;
        padding: 8px 0 !important;
    }

    #langOptions[data-hidden="false"] {
        display: block !important;
    }

    #langOptions a {
        display: flex !important;
        align-items: center !important;
        padding: 12px 16px !important;
        color: #333 !important;
        text-decoration: none !important;
        background: white !important;
        font-size: 14px !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #langOptions a:active,
    #langOptions a:hover {
        background: #f5f5f5 !important;
    }

    #langOptions a span {
        display: inline-block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Show dropdown when active */
    .language-dropdown.active .language-options,
    #languageDropdown.active .language-options {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    .language-options a {
        display: flex !important;
        align-items: center;
        padding: 12px 16px;
        color: #333;
        text-decoration: none;
        background: white;
    }

    .language-options a:hover,
    .language-options a:active {
        background: #f5f5f5;
    }

    .language-options svg {
        width: 24px;
        height: 24px;
        margin-right: 10px;
        flex-shrink: 0;
    }

    /* Header container padding */
    .main-header-nav .container {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
}

/* ============================================
   Mobile Only - Sidebar Improvements
   ============================================ */
@media (max-width: 768px) {
    /* Sidebar slide-in from right */
    #sidebar-component .sidebar,
    .sidebar-component .sidebar {
        position: fixed;
        top: 0;
        right: -100%;
        width: 280px;
        max-width: 85vw;
        height: 100vh;
        height: 100dvh;
        background: white;
        z-index: 2100;
        transition: right 0.3s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #sidebar-component .sidebar.open,
    .sidebar-component .sidebar.open,
    #sidebar-component .sidebar.sidebar-open,
    .sidebar-component .sidebar.sidebar-open,
    .sidebar.sidebar-open {
        right: 0 !important;
        width: 280px !important;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 2050;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Sidebar menu items touch-friendly */
    .sidebar-menu a,
    .sidebar-menu .menu-item {
        min-height: 48px;
        display: flex;
        align-items: center;
        padding: 12px 16px;
    }
}

/* ============================================
   Mobile Only - Filter Popup Fixes
   ============================================ */
@media (max-width: 768px) {
    /* Filter popup as bottom sheet */
    .filter-popup-mobile {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        max-height: 85vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 16px 16px 0 0;
    }

    .filter-popup-header {
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        padding: 16px;
        border-bottom: 1px solid #eee;
    }

    .filter-popup-footer {
        position: sticky;
        bottom: 0;
        background: white;
        padding: 16px;
        border-top: 1px solid #eee;
    }

    /* Filter button touch-friendly */
    .open-filter-btn-mobile {
        min-height: 44px;
        padding: 10px 16px;
    }

    /* Filter selects touch-friendly */
    .filter-popup-body select {
        min-height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* ============================================
   Mobile Only - Cards & Grid Layout Fixes
   ============================================ */
@media (max-width: 576px) {
    /* Single column on small phones */
    .nihomes-grid,
    .buildings {
        display: grid;
        grid-template-columns: 1fr;
        gap: 16px;
        padding: 0 12px;
    }

    /* Card improvements */
    .building-card,
    .apartment-card,
    .nihome-item {
        border-radius: 12px;
        overflow: hidden;
    }

    /* Card image aspect ratio */
    .building-card .thumbnails-carousel,
    .apartment-card .thumbnails-carousel {
        aspect-ratio: 16/10;
    }
}

@media (min-width: 576px) and (max-width: 768px) {
    /* Two columns for larger phones */
    .nihomes-grid,
    .buildings {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
        padding: 0 12px;
    }
}

/* ============================================
   Mobile Only - Buttons & Touch Targets
   ============================================ */
@media (max-width: 768px) {
    /* Ensure minimum touch target size */
    .btn,
    button:not(.btn-icon-only),
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
    }

    /* Primary buttons full width on mobile */
    .btn-primary,
    .btn-mvillage,
    .primary-btn {
        width: 100%;
        padding: 12px 24px;
    }
}

/* ============================================
   Mobile Only - Forms
   ============================================ */
@media (max-width: 768px) {
    /* Inputs touch-friendly */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    input[type="search"],
    select,
    textarea {
        min-height: 48px;
        font-size: 16px; /* Prevents auto-zoom on iOS */
        padding: 12px;
    }

    /* Search input in mobile filter */
    .mobile-only input {
        min-height: 44px;
        font-size: 16px;
    }
}

/* ============================================
   Mobile Only - Pagination Touch Targets
   ============================================ */
@media (max-width: 768px) {
    .pagination {
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
        padding: 16px 0;
    }

    .pagination .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
    }
}

/* ============================================
   Mobile Only - Sections & Spacing
   ============================================ */
@media (max-width: 768px) {
    /* Section titles */
    .nso-title,
    .section-title {
        font-size: 1.5rem;
        padding: 0 16px;
        margin-bottom: 16px;
    }

    /* Section descriptions */
    .nso-desc,
    .section-desc {
        font-size: 14px;
        padding: 0 16px;
        line-height: 1.6;
    }

    /* Container padding */
    .container {
        padding-left: 16px;
        padding-right: 16px;
    }
}

/* ============================================
   Mobile Only - Footer Improvements
   ============================================ */
@media (max-width: 768px) {
    footer .footer-content {
        flex-direction: column;
        gap: 24px;
    }

    footer .footer-section {
        text-align: center;
        width: 100%;
    }

    footer .footer-logo {
        max-width: 120px;
        margin: 0 auto 16px;
    }

    footer .social-links {
        justify-content: center;
        gap: 16px;
    }

    footer .social-links a {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   Mobile Only - Hotline Button
   ============================================ */
@media (max-width: 768px) {
    .hotline-btn-wrapper {
        position: fixed;
        bottom: 20px;
        right: 16px;
        z-index: 1000;
    }

    .hotline-btn-wrapper a {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* ============================================
   Mobile Only - Prevent Horizontal Scroll
   ============================================ */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    img,
    video,
    iframe {
        max-width: 100%;
    }

    /* Fix any overflow elements */
    .container,
    .container-fluid,
    .row {
        max-width: 100%;
        overflow-x: hidden;
    }
}

/* ============================================
   Mobile Only - Modal Improvements
   ============================================ */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 16px;
        max-width: calc(100% - 32px);
    }

    .modal-content {
        border-radius: 16px;
    }

    .modal-header,
    .modal-footer {
        padding: 16px;
    }

    .modal-body {
        padding: 16px;
        max-height: 70vh;
        overflow-y: auto;
    }
}

/* ============================================
   Mobile Only - Safe Area Insets (iPhone X+)
   ============================================ */
@media (max-width: 768px) {
    @supports (padding: env(safe-area-inset-bottom)) {
        .filter-popup-mobile {
            padding-bottom: env(safe-area-inset-bottom);
        }

        .hotline-btn-wrapper {
            bottom: calc(20px + env(safe-area-inset-bottom));
        }

        footer {
            padding-bottom: calc(24px + env(safe-area-inset-bottom));
        }

        .modal-dialog {
            margin-bottom: calc(16px + env(safe-area-inset-bottom));
        }
    }
}

/* ============================================
   Mobile Only - Smooth Scrolling
   ============================================ */
@media (max-width: 768px) {
    html {
        scroll-behavior: smooth;
    }

    /* Smooth momentum scrolling for iOS */
    .sidebar,
    .filter-popup-mobile,
    .modal-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
    .hotline-btn-wrapper,
    .filter-popup-mobile,
    .open-filter-btn-mobile,
    .sidebar-component,
    #toggle-sidebar {
        display: none !important;
    }
}
