/**
 * Mobile Responsiveness Fixes - Phase 3.5
 * Comprehensive fixes for mobile responsiveness issues
 * Created: 2025-09-17
 */

/* =============================================
   1. CORE MOBILE FOUNDATION
   ============================================= */

/* Ensure viewport respects mobile devices */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Prevent horizontal overflow */
body, html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Box-sizing for all elements */
*, *::before, *::after {
    box-sizing: border-box;
}

/* =============================================
   2. USER AVATAR DROPDOWN - MOBILE FIX
   ============================================= */

@media (max-width: 768px) {
    /* Allow navbar to show dropdown properly */
    .modern-navbar,
    .navbar-container {
        overflow: visible !important;
    }

    /* Shift avatar left to prevent edge clipping */
    .navbar-actions {
        margin-right: 35px !important;
        position: relative;
        z-index: 1002;
    }

    /* Ensure avatar container is fully visible and clickable */
    .user-avatar-container {
        margin-right: 4px;
        position: relative;
        z-index: 1003;
    }

    /* Remove pointer-events blocking from initials */
    .user-avatar-initials {
        pointer-events: auto !important;
    }

    /* Ensure avatar button is fully clickable with proper touch target */
    .user-avatar-btn {
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 4px !important;
        touch-action: manipulation;
        cursor: pointer !important;
        pointer-events: auto !important;
        position: relative;
        z-index: 1004;
        -webkit-tap-highlight-color: transparent;
    }

    /* Ensure avatar circle is clickable */
    .user-avatar {
        pointer-events: auto !important;
        cursor: pointer !important;
    }

    /* Dropdown z-index hierarchy */
    .user-dropdown {
        z-index: 10004 !important;
        pointer-events: auto !important;
    }

    .user-dropdown-backdrop {
        z-index: 10000 !important;
    }
}

/* =============================================
   3. ADMIN AVAILABILITY TOGGLE - MOBILE FIX
   ============================================= */

/* Hide admin availability status text on mobile, keep only the traffic light */
@media (max-width: 768px) {
    .availability-toggle .availability-status {
        display: none !important;
    }

    /* Ensure the toggle button doesn't push avatar off screen */
    .availability-toggle {
        padding: 4px !important;
        min-width: auto !important;
    }

    /* Make sure the traffic light icon is visible and properly sized */
    .availability-toggle .availability-icon {
        font-size: 1.2rem;
        display: inline-block;
    }
}

/* =============================================
   4. RESPONSIVE IMAGES AND MEDIA
   ============================================= */

/* Make all images responsive by default */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Responsive videos */
video {
    max-width: 100%;
    height: auto;
}

/* SVG responsiveness */
svg {
    max-width: 100%;
    height: auto;
}

/* =============================================
   5. FORM ELEMENTS - MOBILE OPTIMIZED
   ============================================= */

/* Prevent zoom on iOS forms - 16px minimum */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="number"],
textarea,
select {
    font-size: 16px; /* Prevents iOS zoom */
    line-height: 1.4;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #ccc;
    width: 100%;
    max-width: 100%;
    -webkit-appearance: none;
    appearance: none;
}

/* Focus states for accessibility */
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
    border-color: #007bff;
}

/* Mobile-friendly buttons */
button,
.btn,
input[type="submit"],
input[type="button"],
[role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 16px;
    line-height: 1.4;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.2s ease;
}

/* Button hover states */
button:hover,
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

/* Button active states */
button:active,
.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* =============================================
   6. TOUCH TARGET IMPROVEMENTS
   ============================================= */

/* Ensure all clickable elements meet 44px minimum */
a,
button,
[onclick],
[role="button"],
input[type="checkbox"],
input[type="radio"],
.clickable {
    min-height: 44px;
    min-width: 44px;
    position: relative;
}

/* Expand touch area for small elements */
a:not(.btn)::before,
[onclick]:not(.btn):not(button)::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    right: -8px;
    bottom: -8px;
    min-width: 44px;
    min-height: 44px;
    z-index: 1;
}

/* =============================================
   7. TYPOGRAPHY - MOBILE OPTIMIZED
   ============================================= */

/* Base font size for readability */
body {
    font-size: 16px;
    line-height: 1.6;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* Responsive headings */
h1 { font-size: clamp(1.5rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.25rem, 3.5vw, 2rem); }
h3 { font-size: clamp(1.125rem, 3vw, 1.75rem); }
h4 { font-size: clamp(1rem, 2.5vw, 1.5rem); }
h5 { font-size: clamp(0.9rem, 2vw, 1.25rem); }
h6 { font-size: clamp(0.85rem, 1.5vw, 1.125rem); }

/* Paragraph spacing */
p {
    margin-bottom: 1rem;
    max-width: 75ch; /* Optimal reading width */
}

/* =============================================
   8. LAYOUT FIXES
   ============================================= */

/* Container responsiveness */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px;
}

/* Flex layout improvements */
.d-flex {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Grid responsiveness */
.grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

/* =============================================
   9. MOBILE BREAKPOINTS
   ============================================= */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .container {
        padding: 0 20px;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    .container {
        padding: 0 24px;
    }

    /* Show desktop elements */
    .d-md-block {
        display: block !important;
    }

    .d-md-none {
        display: none !important;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .container {
        padding: 0 32px;
    }
}

/* Mobile-only styles */
@media (max-width: 767.98px) {
    /* Hide desktop-only elements */
    .d-md-block {
        display: none !important;
    }

    .d-md-none {
        display: block !important;
    }

    /* Full-width mobile elements */
    .btn-block-mobile {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Stack navigation items - REMOVED to prevent conflict with ModernNavbar */
    /* ModernNavbar-CSP.js handles all navbar styling */

    /* Mobile table responsiveness */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 600px;
    }

    /* Card stacking */
    .card-deck {
        flex-direction: column;
    }

    .card {
        margin-bottom: 1rem;
    }
}

/* =============================================
   10. MODAL AND OVERLAY FIXES
   ============================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1050;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-dialog {
    width: calc(100% - 32px);
    max-width: 500px;
    margin: 16px auto;
    position: relative;
}

@media (max-width: 767.98px) {
    .modal-dialog {
        width: calc(100% - 16px);
        margin: 8px auto;
    }

    .modal-content {
        border-radius: 12px 12px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* =============================================
   11. NAVIGATION IMPROVEMENTS
   ============================================= */

@media (max-width: 767.98px) {
    /* Mobile navigation styles REMOVED - ModernNavbar-CSP.js handles all navbar styling */
    /* This prevents CSS conflicts with the modern navbar implementation */
}

/* =============================================
   12. FORM IMPROVEMENTS
   ============================================= */

@media (max-width: 767.98px) {
    .form-group {
        margin-bottom: 1.5rem;
    }

    .form-control {
        font-size: 16px; /* Prevent zoom */
        padding: 0.75rem;
    }

    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
        display: block;
    }

    /* Button groups */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        border-radius: 8px;
        margin-bottom: 0.5rem;
    }
}

/* =============================================
   13. ACCESSIBILITY ENHANCEMENTS
   ============================================= */

/* High contrast focus indicators */
@media (max-width: 767.98px) {
    *:focus {
        outline: 3px solid #005fcc;
        outline-offset: 2px;
    }

    /* Skip links for screen readers */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 6px;
        background: #000;
        color: white;
        padding: 8px;
        text-decoration: none;
        z-index: 9999;
        border-radius: 4px;
    }

    .skip-link:focus {
        top: 6px;
    }
}

/* =============================================
   14. PERFORMANCE OPTIMIZATIONS
   ============================================= */

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* Hardware acceleration for animations */
.animated,
.transition,
[data-bs-toggle] {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform;
}

/* Touch action optimization */
.scrollable {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* =============================================
   15. PRINT STYLES
   ============================================= */

@media print {
    /* Hide non-essential elements */
    .modern-navbar, /* Updated to target ModernNavbar specifically */
    .btn,
    .modal,
    .floating-action,
    .sidebar {
        display: none !important;
    }

    /* Optimize text for printing */
    body {
        font-size: 12pt;
        line-height: 1.4;
        color: black;
        background: white;
    }

    /* Page breaks */
    h1, h2, h3 {
        page-break-after: avoid;
    }

    img {
        max-width: 100% !important;
    }
}

/* =============================================
   16. DARK MODE SUPPORT
   ============================================= */

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --text-primary: #ffffff;
        --text-secondary: #cccccc;
        --border-color: #404040;
    }
}

/* =============================================
   17. REDUCED MOTION SUPPORT
   ============================================= */

@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;
    }
}