/**
 * Mobile Responsiveness Stylesheet
 * 
 * Provides mobile-first responsive design for AWYAD MES application.
 * Includes breakpoints for phones, tablets, and desktop displays.
 * Optimizes navigation, tables, forms, and charts for touch screens.
 * 
 * @author AWYAD MES Team
 * @since 2.4.0
 */

/* ============================================
   MOBILE-FIRST BASE STYLES
   ============================================ */

/* Hide mobile-only elements on desktop by default */
.mobile-menu-toggle,
.sidebar-backdrop {
    display: none;
}

/* Show mobile menu toggle only on mobile/tablet */
@media (max-width: 991.98px) {
    .mobile-menu-toggle {
        display: block;
    }
}

/* Touch-friendly base settings */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

/* Touch-friendly minimum sizes on mobile only */
@media (max-width: 991.98px) {
    button, .btn, a.btn {
        min-height: 44px;
        min-width: 44px;
    }
    
    input, select, textarea {
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* IMPORTANT: Only apply mobile sidebar styles below 992px */

/* Extra small devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    /* Sidebar - Overlay mode on mobile */
    .sidebar {
        position: fixed !important;
        top: 0;
        left: -280px !important; /* Hidden by default */
        width: 280px !important;
        height: 100vh;
        z-index: 1050;
        transition: left 0.3s ease !important;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        transform: none !important; /* Override inline styles */
        min-width: 280px !important;
        max-width: 280px !important;
    }
    
    .sidebar.show {
        left: 0;
    }
    
    /* Mobile overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1049;
    }
    
    .sidebar-overlay.show {
        display: block;
    }
    
    /* Main content - Full width on mobile */
    #content-area {
        margin-left: 0 !important;
        width: 100% !important;
        flex: 1 !important;
    }
    
    /* Mobile header with hamburger */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem;
        background: #fff;
        border-bottom: 1px solid #dee2e6;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    .hamburger-btn {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 30px;
        height: 25px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
    }
    
    .hamburger-btn span {
        width: 100%;
        height: 3px;
        background: #333;
        border-radius: 2px;
        transition: all 0.3s;
    }
    
    .hamburger-btn.active span:nth-child(1) {
        transform: rotate(45deg) translate(8px, 8px);
    }
    
    .hamburger-btn.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger-btn.active span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }
    
    /* Summary cards - Stack vertically */
    .row > [class*='col-'] {
        margin-bottom: 1rem;
    }
    
    /* Tables - Horizontal scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        min-width: 800px; /* Force horizontal scroll */
    }
    
    /* Alternative: Card-based table view */
    .table-card-view {
        display: none;
    }
    
    @media (max-width: 575.98px) {
        .table-card-view {
            display: block;
        }
        
        .table-standard-view {
            display: none;
        }
    }
    
    .table-card {
        border: 1px solid #dee2e6;
        border-radius: 0.375rem;
        padding: 1rem;
        margin-bottom: 1rem;
        background: #fff;
    }
    
    .table-card-header {
        font-weight: 600;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
        border-bottom: 1px solid #e9ecef;
    }
    
    .table-card-row {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border-bottom: 1px solid #f8f9fa;
    }
    
    .table-card-row:last-child {
        border-bottom: none;
    }
    
    .table-card-label {
        font-weight: 500;
        color: #6c757d;
        font-size: 0.875rem;
    }
    
    .table-card-value {
        text-align: right;
    }
    
    /* Charts - Reduce height on mobile */
    canvas {
        max-height: 250px !important;
    }
    
    .card .card-body canvas {
        height: 250px !important;
    }
    
    /* Forms - Full width inputs */
    .form-control, .form-select {
        width: 100%;
    }
    
    /* Buttons - Stack vertically */
    .btn-toolbar .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    /* Page header - Smaller on mobile */
    .page-header h1 {
        font-size: 1.75rem;
    }
    
    .page-header .subtitle {
        font-size: 0.875rem;
    }
    
    /* Action buttons - Smaller on mobile */
    .page-header .btn {
        font-size: 0.875rem;
        padding: 0.375rem 0.75rem;
    }
    
    /* Pagination - Compact */
    .pagination {
        font-size: 0.875rem;
    }
    
    .pagination .page-link {
        padding: 0.375rem 0.75rem;
    }
    
    /* Modal - Full screen on mobile */
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: 100vh;
    }
    
    .modal-content {
        height: 100%;
        border-radius: 0;
    }
    
    /* Filter toolbar - Stack vertically */
    .filter-toolbar .row > div {
        margin-bottom: 1rem;
    }
    
    /* Summary cards - Larger text on mobile */
    .summary-card .value {
        font-size: 2rem;
    }
    
    /* Hide desktop-only elements */
    .desktop-only {
        display: none !important;
    }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .sidebar {
        position: fixed !important;
        width: 220px !important;
        left: -220px !important;
        min-width: 220px !important;
        max-width: 220px !important;
        z-index: 1050;
        transform: none !important;
    }
    
    .sidebar.show {
        left: 0 !important;
    }
    
    #content-area {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Tables - Still use horizontal scroll */
    .table-responsive {
        overflow-x: auto;
    }
    
    canvas {
        max-height: 300px !important;
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .sidebar {
        position: fixed !important;
        width: 240px !important;
        left: -240px !important;
        min-width: 240px !important;
        max-width: 240px !important;
        z-index: 1050;
        transform: none !important;
    }
    
    .sidebar.show {
        left: 0 !important;
    }
    
    #content-area {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Two columns for summary cards */
    .row > [class*='col-md-3'] {
        flex: 0 0 50%;
        max-width: 50%;
    }
    
    canvas {
        max-height: 350px !important;
    }
    
    /* Tables - Allow normal width */
    table {
        min-width: auto;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    /* Hide mobile-only elements */
    .mobile-header,
    .mobile-menu-toggle,
    .sidebar-backdrop,
    .sidebar-overlay {
        display: none !important;
    }
    
    .mobile-only {
        display: none !important;
    }
    
    /* Ensure desktop sidebar is NOT affected by mobile CSS */
    /* Don't override inline styles on desktop */
}

/* ============================================
   TOUCH OPTIMIZATIONS
   ============================================ */

/* Swipe gestures indicator */
.swipe-indicator {
    position: relative;
}

.swipe-indicator::after {
    content: '← Swipe →';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    color: #6c757d;
    opacity: 0.5;
    pointer-events: none;
}

/* Touch-friendly spacing */
.mobile-spacing {
    padding: 1rem;
}

@media (min-width: 768px) {
    .mobile-spacing {
        padding: 1.5rem;
    }
}

/* Touch-friendly list items */
.list-group-item {
    min-height: 56px;
    display: flex;
    align-items: center;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .sidebar,
    .mobile-header,
    .btn,
    .pagination,
    .sidebar-overlay {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    .card {
        page-break-inside: avoid;
    }
    
    canvas {
        max-height: 400px !important;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Focus indicators for keyboard navigation */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #0d6efd;
    color: #fff;
    padding: 0.5rem 1rem;
    text-decoration: none;
    z-index: 10000;
}

.skip-to-main:focus {
    top: 0;
}

/* ============================================
   LANDSCAPE ORIENTATION
   ============================================ */

@media (max-width: 767.98px) and (orientation: landscape) {
    /* Reduce header size in landscape */
    .mobile-header {
        padding: 0.5rem 1rem;
    }
    
    .page-header h1 {
        font-size: 1.5rem;
    }
    
    /* Reduce chart height in landscape */
    canvas {
        max-height: 200px !important;
    }
    
    /* Compact sidebar in landscape */
    .sidebar {
        width: 200px;
    }
}

/* ============================================
   DARK MODE SUPPORT (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
    /* Add dark mode styles here if needed */
}

/* ============================================
   REDUCED MOTION (Accessibility)
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
