/* Mobile Responsive Styles for Meet Oscar - COMPREHENSIVE FIX */

/* 1. RESET AND BASE STYLES */
* {
    box-sizing: border-box;
}

html {
    height: 100%;
    /* Fix for mobile browsers with dynamic viewport */
    height: -webkit-fill-available;
}

body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    height: -webkit-fill-available;
    overflow-x: hidden !important; /* Prevent horizontal scroll globally */
    font-family: 'Poppins', sans-serif;
}

/* 2. MOBILE HAMBURGER BUTTON STYLING */
.mobile-menu-btn {
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.mobile-menu-btn:hover {
    background-color: #f3f4f6;
    transform: scale(1.05);
}

.mobile-menu-btn:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.mobile-menu-btn svg {
    transition: all 0.2s ease;
}

/* 3. MOBILE-SPECIFIC OVERRIDES */
@media (max-width: 767px) {

    /* CRITICAL: Reset all desktop layout rules that break mobile */
    .main {
        padding-left: 0 !important;
        margin-left: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        height: -webkit-fill-available !important;
        overflow-x: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        position: relative !important;
    }

    /* Main content area - CRITICAL FIXES */
    .main-1content {
        padding: 16px !important;
        margin-left: 0 !important;
        padding-top: 70px !important; /* Space for floating hamburger button */
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        flex: 1 !important;
        box-sizing: border-box !important;
        background-color: #F4F4F4 !important;
    }

    /* Hide desktop header completely on mobile */
    .header {
        display: none !important;
    }

    /* Show mobile hamburger button */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        z-index: 1001 !important;
        background: white !important;
        border: none !important;
        border-bottom: 1px solid #e5e7eb !important;
        border-right: 1px solid #e5e7eb !important;
        border-radius: 0 0 8px 0 !important;
        padding: 12px !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
    }

    /* Mobile sidebar positioning and behavior */
    .side-menu {
        position: fixed !important;
        left: -280px !important; /* Off-screen by default */
        top: 0 !important;
        height: 100vh !important;
        height: -webkit-fill-available !important;
        width: 280px !important;
        z-index: 1002 !important;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        background-color: #202A35 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
        border-right: 1px solid #374151;
        display: block !important;
    }

    /* Show sidebar when mobile menu is open */
    body.mobile-menu-open .side-menu {
        left: 0 !important;
    }

    /* Mobile sidebar content styling */
    .mobile-sidebar {
        padding: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .mobile-nav-header {
        padding: 24px 20px;
        border-bottom: 1px solid #374151;
        display: flex;
        align-items: center;
        gap: 12px;
        color: white;
    }

    .mobile-nav-links {
        flex: 1;
        padding: 16px 0;
    }

    .mobile-nav-item {
        display: flex;
        align-items: center;
        gap: 16px;
        padding: 12px 20px;
        color: #A0AEC0;
        text-decoration: none;
        transition: all 0.2s ease;
        min-height: 48px; /* Touch-friendly */
        border: none;
        background: none;
    }

    .mobile-nav-item:hover,
    .mobile-nav-item:focus {
        background-color: #2D3748;
        color: #FFFFFF;
        text-decoration: none;
    }

    .mobile-nav-item img {
        width: 24px;
        height: 24px;
        flex-shrink: 0;
    }

    .mobile-nav-item span {
        font-size: 16px;
        font-weight: 500;
    }

    /* Mobile overlay */
    .mobile-nav-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        background: rgba(0, 0, 0, 0.5) !important;
        z-index: 1001 !important; /* Below sidebar, above content */
        transition: opacity 0.3s ease !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    .mobile-nav-overlay.open {
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* Prevent body scroll when menu is open */
    body.mobile-menu-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
    }

    /* Hamburger icon states */
    .mobile-menu-btn .mobile-close-icon {
        display: none;
    }

    body.mobile-menu-open .mobile-menu-btn .mobile-menu-icon {
        display: none;
    }

    body.mobile-menu-open .mobile-menu-btn .mobile-close-icon {
        display: block;
    }

    /* Make hamburger button more prominent when menu is open */
    body.mobile-menu-open .mobile-menu-btn {
        background-color: #fff !important;
        border-color: #e5e7eb !important;
        transform: scale(1.05) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
    }

    /* LAYOUT FIXES */
    .myContainer,
    .app-container {
        width: 100vw !important;
        height: 100vh !important;
        height: -webkit-fill-available !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow-x: hidden !important;
    }

    /* Grid and layout responsive fixes */
    .grid-rows-\[243px_150px_1fr\] {
        grid-template-rows: auto auto 1fr !important;
    }

    .xl\:grid-cols-\[3fr_1fr\] {
        grid-template-columns: 1fr !important;
    }

    .lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }

    .md\:pl-\[80px\] {
        padding-left: 0 !important;
    }

    /* Remove any desktop padding/margins that break mobile */
    .h-\[100dvh\].w-\[100dvw\] {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }

    /* CONTENT IMPROVEMENTS */
    /* Text scaling for mobile readability */
    .text-2xl {
        font-size: 1.25rem !important;
        line-height: 1.75rem !important;
    }

    .text-xl {
        font-size: 1.125rem !important;
        line-height: 1.75rem !important;
    }

    /* Image sizing fixes */
    .w-16.h-16 {
        width: 4rem !important;
        height: 4rem !important;
    }

    .w-14.h-14 {
        width: 3.5rem !important;
        height: 3.5rem !important;
    }

    /* Button improvements for touch */
    .default-button {
        padding: 12px 16px !important;
        border-radius: 8px !important;
        font-weight: 600 !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
    }

    /* Touch-friendly interaction targets */
    .touch-target {
        min-height: 44px !important;
        min-width: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* Scrolling improvements */
    .overflow-y-auto {
        -webkit-overflow-scrolling: touch !important;
    }

    /* Fix any elements that might cause horizontal scroll */
    .main-content,
    main,
    section,
    div {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Profile and dashboard specific fixes */
    main {
        padding: 1rem !important;
        gap: 1rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Welcome banner mobile optimization */
    .bg-cover {
        background-size: cover !important;
        background-position: center right !important;
    }

    /* Card hover effects for mobile */
    .bg-gray-50:hover {
        background-color: #f3f4f6;
        border-color: #d1d5db;
    }

    /* FLOATING ACTION BUTTON */
    .fixed.bottom-6.right-6 {
        position: fixed !important;
        bottom: 1.5rem !important;
        right: 1.5rem !important;
        z-index: 40 !important;
        width: 3.5rem !important;
        height: 3.5rem !important;
        background-color: #2563eb !important;
        color: white !important;
        border-radius: 50% !important;
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
        border: none !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.2s ease !important;
    }

    .fixed.bottom-6.right-6:hover {
        background-color: #1d4ed8 !important;
        transform: scale(1.05) !important;
        box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
    }

    /* SAFE AREA ADJUSTMENTS FOR iOS DEVICES */
    .mobile-menu-btn {
        top: max(16px, env(safe-area-inset-top)) !important;
        left: max(16px, env(safe-area-inset-left)) !important;
    }

    .main-1content {
        padding-bottom: max(1rem, env(safe-area-inset-bottom)) !important;
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
    }

    .fixed.bottom-6.right-6 {
        bottom: max(1.5rem, env(safe-area-inset-bottom)) !important;
        right: max(1.5rem, env(safe-area-inset-right)) !important;
    }

    /* Prevent zoom on input focus (iOS Safari) */
    input, select, textarea {
        font-size: 16px !important;
    }

    /* PAYMENT MODAL MOBILE FIXES */
    #paymentModal {
        padding: 0 !important;
        margin: 0 !important;
    }

    #paymentModal .custom-modal-dialog {
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
        padding: 16px !important;
        border-radius: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        overflow: hidden !important;
    }

    #paymentModal .custom-modal-dialog > div:last-child {
        max-height: calc(100vh - 32px) !important;
        height: calc(100vh - 32px) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    #paymentModal .custom-modal-dialog > div:last-child > div {
        padding: 0 !important;
        height: 100% !important;
    }

    #paymentModal #checkout {
        height: auto !important;
        min-height: 100% !important;
    }
}

/* 4. TABLET ADJUSTMENTS (768px to 1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .mobile-menu-btn {
        display: none !important;
    }

    .mobile-nav-overlay {
        display: none !important;
    }

    .side-menu {
        display: none !important;
    }

    /* Show desktop header on tablet */
    .header {
        display: flex !important;
    }

    /* Tablet grid adjustments */
    .sm\:grid-cols-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Adjust padding for tablet */
    main {
        padding: 1.5rem !important;
    }

    .main-1content {
        padding: 24px !important;
        padding-top: 24px !important;
    }
}


/* 6. ANIMATIONS AND TRANSITIONS */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile card animations */
@media (max-width: 767px) {
    .space-y-4 > div {
        animation: slideInUp 0.3s ease-out forwards;
    }

    .space-y-4 > div:nth-child(1) { animation-delay: 0ms; }
    .space-y-4 > div:nth-child(2) { animation-delay: 100ms; }
    .space-y-4 > div:nth-child(3) { animation-delay: 200ms; }
    .space-y-4 > div:nth-child(4) { animation-delay: 300ms; }
}

/* 7. LOADING STATES */
.mobile-card.loading {
    opacity: 0.6;
    pointer-events: none;
}

.mobile-card.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 8. ACCESSIBILITY AND TOUCH IMPROVEMENTS */
@media (max-width: 767px) {
    /* Touch feedback */
    .touch-target:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    /* Focus states */
    button:focus,
    a:focus {
        outline: 2px solid #3b82f6;
        outline-offset: 2px;
    }

    .mobile-nav-item:active {
        background-color: #e5e7eb;
    }

    .bg-white:active {
        background-color: #f9fafb;
    }
}

/* 9. SMOOTH TRANSITIONS */
.transition-all {
    transition: all 0.2s ease;
}

.transition-colors {
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
}

.transition-transform {
    transition: transform 0.15s ease-in-out;
}

/* 10. EMERGENCY HORIZONTAL SCROLL PREVENTION */
@media (max-width: 767px) {
    * {
        max-width: 100vw !important;
    }

    *:not(.mobile-nav-overlay):not(.side-menu) {
        overflow-x: hidden !important;
    }

    /* Ensure no transforms break layout */
    .main * {
        transform: none !important;
    }
}
