/* ===================================
   Mobile Responsive Enhancements
   MBA Paglaum Insurance Management
   ================================== */

/* Mobile Navigation Toggle */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-gradient);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 1, 114, 0.4);
    cursor: pointer;
    font-size: 1.5rem;
    transition: var(--transition);
}

.mobile-menu-toggle:hover {
    transform: scale(1.1);
}

/* Mobile Navigation Close Button */
.nav-close-btn {
    display: none;
}

@media (max-width: 768px) {
    .nav-close-btn {
        display: block;
        position: absolute;
        top: 20px;
        right: 20px;
        width: 40px;
        height: 40px;
        background: var(--gray-100);
        border: 1px solid var(--gray-300);
        border-radius: 50%;
        color: var(--gray-700);
        font-size: 1.25rem;
        cursor: pointer;
        transition: all 0.3s ease;
        z-index: 1000;
    }
    
    .nav-close-btn:hover {
        background: var(--danger);
        color: white;
        border-color: var(--danger);
    }
    
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Override default navigation styles for mobile */
    .main-navigation {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 80% !important;
        max-width: 320px !important;
        height: 100vh !important;
        background: white !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
        z-index: 999 !important;
        padding: 80px 20px 20px !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
        flex-direction: column !important;
        display: flex !important;
        gap: 0.5rem !important;
        margin: 0 !important;
        pointer-events: auto !important;
        touch-action: auto !important;
    }
    
    .main-navigation.active {
        left: 0 !important;
    }
    
    .main-navigation a {
        background: var(--gray-50) !important;
        border: 1px solid var(--gray-200) !important;
        color: var(--gray-800) !important;
        margin-bottom: 0.5rem !important;
        display: flex !important;
        width: 100% !important;
        justify-content: flex-start !important;
        padding: 1rem 1.5rem !important;
        font-size: 0.9375rem !important;
        border-radius: 0.5rem !important;
        text-decoration: none !important;
        position: relative !important;
        z-index: 1001 !important;
        pointer-events: auto !important;
        cursor: pointer !important;
    }
    
    .main-navigation a:hover,
    .main-navigation a.active {
        background: var(--primary-gradient) !important;
        color: white !important;
        border-color: transparent !important;
    }
    
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 998;
    }
    
    .mobile-overlay.active {
        display: block;
    }
}

/* Responsive Tables - Card View on Mobile */
@media (max-width: 768px) {
    .responsive-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Alternative: Stack table data as cards */
    .table-mobile-card {
        display: none;
    }
    
    @media (max-width: 640px) {
        .table-mobile-card {
            display: block;
        }
        
        .table-mobile-card table,
        .table-mobile-card thead,
        .table-mobile-card tbody,
        .table-mobile-card tr,
        .table-mobile-card th,
        .table-mobile-card td {
            display: block;
            width: 100%;
        }
        
        .table-mobile-card thead {
            display: none;
        }
        
        .table-mobile-card tr {
            margin-bottom: 1rem;
            border: 1px solid var(--gray-200);
            border-radius: var(--radius);
            padding: 1rem;
            background: white;
            box-shadow: var(--shadow-sm);
        }
        
        .table-mobile-card td {
            border: none;
            padding: 0.5rem 0;
            position: relative;
            padding-left: 50%;
            text-align: right;
        }
        
        .table-mobile-card td:before {
            content: attr(data-label);
            position: absolute;
            left: 0;
            width: 45%;
            padding-right: 10px;
            font-weight: 700;
            text-align: left;
            color: var(--gray-700);
        }
    }
}

/* Responsive Grid System */
.responsive-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

@media (min-width: 640px) {
    .responsive-grid-sm-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .responsive-grid-md-2 {
        grid-template-columns: repeat(2, 1fr);
    }
    .responsive-grid-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1024px) {
    .responsive-grid-lg-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    .responsive-grid-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Mobile-friendly form inputs */
@media (max-width: 768px) {
    /* Prevent zoom on iOS */
    input[type="text"],
    input[type="email"],
    input[type="tel"],
    input[type="number"],
    input[type="date"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Stack form fields */
    .form-row {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
    
    /* Full width buttons on mobile */
    .button-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .button-group button,
    .button-group a {
        width: 100%;
    }
}

/* Sticky header on scroll (mobile) */
@media (max-width: 768px) {
    .site-header {
        position: sticky;
        top: 0;
        z-index: 100;
        backdrop-filter: blur(10px);
    }
}

/* Mobile-optimized modal */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: var(--radius);
    }
}

/* Touch-friendly spacing */
@media (hover: none) and (pointer: coarse) {
    /* Increase spacing between clickable elements */
    .action-links {
        gap: 0.5rem;
    }
    
    /* Larger checkboxes and radio buttons */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px;
        height: 20px;
    }
    
    /* Better tap targets for links */
    a {
        padding: 0.25rem 0;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    .site-header {
        padding: 0.5rem 1rem;
    }
    
    .site-header h1 {
        font-size: 1.25rem;
    }
    
    .main-navigation a {
        padding: 0.5rem 1rem;
    }
}

/* Safe area insets for notched devices (iPhone X+) */
@supports (padding: env(safe-area-inset-left)) {
    .site-container {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
    
    .site-header {
        padding-top: env(safe-area-inset-top);
    }
    
    .site-footer {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* High DPI / Retina displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Optimize images and icons for retina */
    img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Dark mode support (respects system preference) */
@media (prefers-color-scheme: dark) {
    /* Optional: Add dark mode styles here */
    /* Uncomment when ready to implement dark mode
    :root {
        --gray-50: #1f2937;
        --gray-100: #111827;
        --background: #0f172a;
    }
    
    body {
        background: var(--background);
        color: #f9fafb;
    }
    */
}

/* Reduced 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;
        scroll-behavior: auto !important;
    }
}

/* Loading states for slow connections */
.loading-skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Offline indicator */
.offline-indicator {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
    z-index: 9999;
    display: none;
}

.offline-indicator.show {
    display: block;
}

/* PWA Install prompt */
.pwa-install-prompt {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    display: none;
    z-index: 1000;
}

.pwa-install-prompt.show {
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
}

/* Responsive utilities */
.hide-mobile {
    display: block;
}

.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
}

.hide-tablet {
    display: block;
}

@media (min-width: 769px) and (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
}

.hide-desktop {
    display: block;
}

@media (min-width: 1025px) {
    .hide-desktop {
        display: none !important;
    }
}
