/**
 * Mobile UX Improvements - 2025
 * Enhanced touch targets, gestures, and mobile-specific features
 */

/* ===================================
   Z-INDEX HIERARCHY (Consistent Scale)
   =================================== */
:root {
    --z-sticky: 100;          /* Sticky elements, FAB */
    --z-header: 1000;         /* Site header */
    --z-drawer: 9000;         /* Side drawers, filters */
    --z-overlay: 9500;        /* Overlays, backdrops */
    --z-mobile-menu: 9999;    /* Mobile menu */
    --z-modal: 10000;         /* Modals, dialogs */
    --z-toast: 10500;         /* Notifications, toasts */
}

/* ===================================
   MOBILE MENU TRIGGER BUTTON
   =================================== */
.mobile-menu-trigger {
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 48px;
    min-height: 48px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.mobile-menu-trigger:hover {
    background: rgba(0, 0, 0, 0.05);
}

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

.mobile-menu-trigger .material-icons {
    font-size: 28px;
    color: #212121;
}

/* ===================================
   MOBILE MENU OVERLAY (Updated Z-Index)
   =================================== */
#mobile-menu-overlay {
    z-index: var(--z-overlay);
}

#mobile-menu {
    z-index: var(--z-mobile-menu);
}

/* ===================================
   MOBILE MENU LIST & LINKS
   =================================== */
.mobile-menu-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.mobile-menu-link {
    display: flex !important;
    align-items: center;
    justify-content: flex-start !important;
    gap: 12px;
    padding: 14px 20px !important;
    color: #212121 !important;
    text-decoration: none;
    font-weight: 500;
    font-size: 15px;
    transition: background-color 0.2s ease;
    min-height: 52px !important; /* Exceeds 48px minimum */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.mobile-menu-link:active {
    background: rgba(0, 0, 0, 0.1);
}

.mobile-menu-link .material-icons {
    font-size: 22px;
    flex-shrink: 0;
}

.mobile-menu-divider {
    height: 8px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    margin: 0;
}

.mobile-menu-action {
    padding: 16px 20px;
    border: none !important;
    background: transparent !important;
}

.mobile-menu-action .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    width: 100%;
}

/* ===================================
   BOTTOM NAVIGATION BAR
   =================================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: var(--z-sticky);
    padding-bottom: env(safe-area-inset-bottom);
    display: none; /* Show on mobile */
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
    }

    /* Add bottom padding to body when bottom nav is visible */
    body.has-bottom-nav {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

.bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 8px 4px;
    min-height: 56px;
    text-decoration: none;
    color: #6B7280;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.bottom-nav-item:active {
    background: rgba(0, 0, 0, 0.05);
}

.bottom-nav-item .material-icons {
    font-size: 24px;
    margin-bottom: 4px;
}

.bottom-nav-item.active {
    color: #FFD93D;
}

.bottom-nav-item.active .material-icons {
    color: #FFC700;
}

/* Badge for notifications */
.bottom-nav-item .badge {
    position: absolute;
    top: 6px;
    right: calc(50% - 18px);
    background: #EF4444;
    color: white;
    font-size: 10px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

/* ===================================
   SAFE AREA INSETS (iPhone Notch Support)
   =================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .safe-area-top {
        padding-top: env(safe-area-inset-top);
    }

    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .safe-area-left {
        padding-left: env(safe-area-inset-left);
    }

    .safe-area-right {
        padding-right: env(safe-area-inset-right);
    }

    /* Apply to header */
    header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }

    /* Apply to mobile menu */
    #mobile-menu {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ===================================
   IMPROVED TOUCH TARGETS
   =================================== */
@media (max-width: 768px) {
    /* Ensure all interactive elements meet minimum size */
    button, .btn, a.button,
    input[type="submit"],
    input[type="button"] {
        min-height: 44px;
        min-width: 44px;
        padding: 12px 20px;
    }

    /* Filter buttons */
    .filter-btn, .filter-toggle-btn {
        min-width: 48px;
        min-height: 48px;
    }

    /* Icon-only buttons need more padding */
    button.icon-only,
    .icon-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 12px;
    }
}

/* ===================================
   MOBILE HEADER IMPROVEMENTS
   =================================== */
@media (max-width: 768px) {
    header {
        min-height: 56px;
        position: sticky;
        top: 0;
        z-index: var(--z-header);
    }

    .header-container {
        padding: 12px 16px;
        min-height: 56px;
    }

    /* Header shrink on scroll */
    header.scrolled {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }
}

/* ===================================
   FILTER DRAWER Z-INDEX FIX
   =================================== */
.filter-drawer {
    z-index: var(--z-drawer) !important;
}

.filter-overlay {
    z-index: calc(var(--z-drawer) - 1) !important;
}

/* ===================================
   STICKY ELEMENTS Z-INDEX FIX
   =================================== */
.sticky-contact-buttons {
    z-index: var(--z-sticky) !important;
}

.filter-toggle-btn {
    z-index: calc(var(--z-sticky) + 1) !important;
}

/* ===================================
   PULL-TO-REFRESH INDICATOR
   =================================== */
.pull-to-refresh {
    position: fixed;
    top: -60px;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease;
    z-index: calc(var(--z-header) + 1);
}

.pull-to-refresh.active {
    transform: translateY(60px);
}

.pull-to-refresh .spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #FFD93D;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ===================================
   SWIPE INDICATOR
   =================================== */
.swipe-indicator {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 80px;
    background: rgba(255, 217, 61, 0.5);
    border-radius: 0 4px 4px 0;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    z-index: var(--z-overlay);
}

.swipe-indicator.visible {
    opacity: 1;
}

/* ===================================
   FORM IMPROVEMENTS FOR MOBILE
   =================================== */
@media (max-width: 768px) {
    /* Stack form fields vertically */
    .form-row {
        flex-direction: column;
    }

    .form-row > * {
        width: 100% !important;
    }

    /* Larger input fields */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="password"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 14px 16px !important;
        min-height: 48px !important;
        border-radius: 8px;
    }

    /* Larger checkboxes and radios */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }

    /* Better spacing */
    .form-group {
        margin-bottom: 20px;
    }

    label {
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 8px;
        display: block;
    }
}

/* ===================================
   PERFORMANCE OPTIMIZATIONS
   =================================== */
/* Hardware acceleration for animations */
#mobile-menu,
#mobile-menu-overlay,
.bottom-nav,
.pull-to-refresh {
    will-change: transform;
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===================================
   DARK MODE SUPPORT (Future)
   =================================== */
@media (prefers-color-scheme: dark) {
    /* Will be implemented in future update */
}
