/* Everlast HR System - Mobile Responsive Styles - Comprehensive Fix */

/* Mobile-first approach with progressive enhancement */

/* Base mobile styles - Fix all common mobile UI issues */
@media (max-width: 991.98px) {
    /* ===== Layout & Container Fixes ===== */
    .page-wrapper {
        flex-direction: column;
        overflow-x: hidden;
        width: 100%;
        max-width: 100%;
    }
    
    .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .content-wrapper {
        margin-left: 0 !important;
        padding: 0.75rem !important;
        min-height: 100vh;
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden;
    }
    
    /* ===== Sidebar Mobile Enhancements ===== */
    .sidebar {
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1050;
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        height: 100vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }
    
    .sidebar.mobile-show,
    .sidebar.show,
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
    }
    
    /* ===== Mobile Header Fixes ===== */
    .mobile-header,
    .header,
    .navbar {
        position: sticky !important;
        top: 0 !important;
        z-index: 1040 !important;
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%) !important;
        border-bottom: 1px solid #e2e8f0;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        padding: 0.75rem 1rem !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .mobile-menu-toggle,
    .menu-toggle,
    .hamburger-menu {
        background: linear-gradient(135deg, #005d99 0%, #0066b3 100%) !important;
        color: white !important;
        border: none !important;
        border-radius: 0.5rem !important;
        padding: 0.75rem !important;
        font-size: 1.25rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        transition: all 0.3s ease;
        box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
        cursor: pointer;
    }
    
    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:active {
        transform: translateY(-1px);
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    }
    
    /* ===== Mobile Overlay ===== */
    .mobile-overlay,
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 1049;
        display: none;
        transition: all 0.3s ease;
    }
    
    .mobile-overlay.active,
    .sidebar-overlay.active {
        display: block;
    }
    
    /* ===== Navigation Improvements ===== */
    .sidebar .nav-menu {
        padding: 0.5rem 0;
    }
    
    .sidebar .nav-item {
        margin: 0.125rem 0;
    }
    
    .sidebar .nav-link {
        padding: 0.875rem 1rem !important;
        margin: 0.125rem 0.75rem;
        border-radius: 0.75rem;
        font-size: 0.9rem;
        font-weight: 500;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
    }
    
    .sidebar .nav-link.active {
        background: linear-gradient(135deg, #005d99 0%, #0066b3 100%);
        color: white;
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    }
    
    .sidebar .nav-icon {
        font-size: 1.1rem;
        margin-right: 0.75rem;
        width: 20px;
        text-align: center;
        min-width: 20px;
    }
    
    /* ===== Page Title & Headers ===== */
    .page-title,
    h1 {
        font-size: 1.5rem !important;
        font-weight: 700;
        margin-bottom: 0.75rem;
        color: #1f2937;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .page-subtitle,
    .employee-page-subtitle {
        font-size: 0.9rem !important;
        color: #6b7280;
        margin-bottom: 1.5rem;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .employee-page-title {
        font-size: 1.75rem !important;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* ===== Card Improvements ===== */
    .card,
    .employee-card {
        border: none !important;
        border-radius: 1rem !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08) !important;
        margin-bottom: 1.5rem !important;
        overflow: hidden;
        transition: all 0.3s ease;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .card-header,
    .employee-card-header {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
        border-bottom: 1px solid #e5e7eb !important;
        padding: 1rem 1.25rem !important;
    }
    
    .card-header h3,
    .card-header h4,
    .card-header h5,
    .card-title {
        font-size: 1.1rem !important;
        font-weight: 600;
        margin: 0;
        color: #1f2937;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .card-body,
    .employee-card-body {
        padding: 1rem 1.25rem !important;
        overflow-x: hidden;
    }
    
    /* ===== Form Improvements ===== */
    .form-label {
        font-size: 0.9rem !important;
        font-weight: 600;
        color: #374151;
        margin-bottom: 0.5rem;
    }
    
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.875rem !important;
        border: 2px solid #e5e7eb !important;
        border-radius: 0.75rem !important;
        transition: all 0.3s ease;
        background-color: #ffffff;
        min-height: 44px !important; /* Touch-friendly */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .form-control:focus,
    .form-select:focus {
        border-color: #005d99 !important;
        box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
        outline: none !important;
    }
    
    .form-control.is-invalid,
    .form-select.is-invalid {
        border-color: #ef4444 !important;
        box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1) !important;
    }
    
    /* ===== Button Improvements ===== */
    .btn,
    .employee-btn {
        padding: 0.875rem 1.25rem !important;
        font-size: 0.9rem !important;
        font-weight: 600 !important;
        border-radius: 0.75rem !important;
        transition: all 0.3s ease !important;
        border: none !important;
        min-height: 44px !important; /* Touch-friendly */
        min-width: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        white-space: nowrap;
        word-wrap: break-word;
    }
    
    .btn-primary,
    .employee-btn-primary {
        background: linear-gradient(135deg, #005d99 0%, #0066b3 100%) !important;
        color: white !important;
        box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3) !important;
    }
    
    .btn-success {
        background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
        color: white !important;
    }
    
    .btn-danger {
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
        color: white !important;
    }
    
    .btn-warning {
        background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
        color: white !important;
    }
    
    .btn-info {
        background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%) !important;
        color: white !important;
    }
    
    .btn-sm {
        padding: 0.625rem 1rem !important;
        font-size: 0.85rem !important;
        min-height: 36px !important;
    }
    
    /* Button groups - stack on mobile */
    .btn-group,
    .btn-group-vertical,
    .action-buttons,
    .employee-action-buttons {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        width: 100% !important;
    }
    
    .btn-group .btn,
    .action-buttons .btn,
    .employee-action-buttons .btn,
    .employee-action-buttons .employee-btn {
        width: 100% !important;
        margin-bottom: 0 !important;
    }
    
    /* ===== Table Improvements ===== */
    .table-responsive {
        border-radius: 0.75rem;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        overflow-x: auto !important;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
        width: 100% !important;
        max-width: 100% !important;
        display: block !important;
    }
    
    .table {
        font-size: 0.85rem !important;
        margin-bottom: 0;
        width: 100% !important;
        min-width: 600px; /* Minimum width for horizontal scroll */
    }
    
    .table thead th {
        background: linear-gradient(135deg, #1e40af 0%, #1e3a8a 100%) !important;
        color: #ffffff !important;
        border: none !important;
        padding: 1rem 0.75rem !important;
        font-weight: 600 !important;
        text-transform: uppercase !important;
        font-size: 0.75rem !important;
        letter-spacing: 0.05em !important;
        white-space: nowrap;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .table tbody td {
        padding: 0.875rem 0.75rem !important;
        vertical-align: middle;
        border-color: #f3f4f6;
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 200px;
    }
    
    .table tbody tr:hover {
        background-color: #f8f9fa;
    }
    
    /* ===== Modal Improvements ===== */
    .modal-dialog {
        margin: 0.75rem !important;
        max-width: calc(100% - 1.5rem) !important;
        width: calc(100% - 1.5rem) !important;
    }
    
    .modal-content {
        border: none !important;
        border-radius: 1rem !important;
        box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
        max-height: 90vh !important;
        overflow-y: auto !important;
    }
    
    .modal-header {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%) !important;
        border-bottom: 1px solid #e5e7eb !important;
        padding: 1rem 1.25rem !important;
        border-radius: 1rem 1rem 0 0 !important;
    }
    
    .modal-title {
        font-size: 1.1rem !important;
        font-weight: 600;
        color: #1f2937;
        word-wrap: break-word;
    }
    
    .modal-body {
        padding: 1rem 1.25rem !important;
        max-height: calc(90vh - 120px);
        overflow-y: auto;
    }
    
    .modal-footer {
        background: #f8fafc !important;
        border-top: 1px solid #e5e7eb !important;
        padding: 1rem 1.25rem !important;
        border-radius: 0 0 1rem 1rem !important;
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    .modal-footer .btn {
        width: 100% !important;
        margin: 0 !important;
    }
    
    /* ===== Stats Cards ===== */
    .stats-card {
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
        border: none;
        border-radius: 1rem;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
        margin-bottom: 1rem;
        overflow: hidden;
        transition: all 0.3s ease;
        width: 100% !important;
    }
    
    .stats-card .card-body {
        padding: 1.5rem;
        text-align: center;
    }
    
    .stats-number {
        font-size: 1.75rem !important;
        font-weight: 700;
        color: #1f2937;
        margin-bottom: 0.5rem;
    }
    
    .stats-label {
        font-size: 0.9rem;
        color: #6b7280;
        font-weight: 500;
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    
    /* ===== Alert Improvements ===== */
    .alert {
        border: none !important;
        border-radius: 0.75rem !important;
        padding: 1rem 1.25rem !important;
        margin-bottom: 1rem !important;
        font-size: 0.9rem !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        word-wrap: break-word;
    }
    
    /* ===== Badge Improvements ===== */
    .badge {
        font-size: 0.75rem !important;
        padding: 0.5rem 0.75rem !important;
        border-radius: 0.5rem !important;
        font-weight: 600 !important;
        display: inline-block;
        word-wrap: break-word;
    }
    
    /* ===== Employee Page Header Fixes ===== */
    .employee-page-header {
        padding: 1.5rem 1rem !important;
        margin-bottom: 1.5rem !important;
        border-radius: 1rem !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: hidden;
    }
    
    .employee-page-header .d-flex {
        flex-direction: column !important;
        gap: 1rem !important;
    }
    
    /* ===== Date Range Form Fixes ===== */
    .date-range-form .row {
        margin: 0 !important;
    }
    
    .date-range-form .col-auto {
        padding: 0.5rem !important;
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* ===== Pagination Improvements ===== */
    .pagination {
        justify-content: center;
        margin-top: 1.5rem;
        flex-wrap: wrap;
    }
    
    .page-link {
        border: none !important;
        border-radius: 0.5rem !important;
        margin: 0 0.25rem !important;
        padding: 0.75rem 1rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
        color: #6b7280;
        background: #f8fafc;
        transition: all 0.3s ease;
    }
    
    .page-link:hover {
        background: #005d99;
        color: white;
        transform: translateY(-2px);
    }
    
    .page-item.active .page-link {
        background: #005d99;
        color: white;
        box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    }
    
    /* ===== Utility Classes ===== */
    .hide-on-mobile {
        display: none !important;
    }
    
    .show-on-mobile {
        display: block !important;
    }
    
    /* ===== Fix overflow issues ===== */
    * {
        max-width: 100%;
    }
    
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* ===== Fix text overflow ===== */
    p, span, div, h1, h2, h3, h4, h5, h6 {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
    }
}

/* Extra small devices (phones, 576px and down) */
@media (max-width: 576px) {
    .content-wrapper {
        padding: 0.5rem !important;
    }
    
    .mobile-header {
        padding: 0.75rem !important;
    }
    
    .page-title,
    h1 {
        font-size: 1.25rem !important;
    }
    
    .employee-page-title {
        font-size: 1.5rem !important;
    }
    
    .card-header {
        padding: 0.75rem 1rem !important;
    }
    
    .card-body {
        padding: 0.75rem 1rem !important;
    }
    
    .form-control,
    .form-select {
        padding: 0.75rem !important;
        font-size: 16px !important;
    }
    
    .btn {
        padding: 0.75rem 1rem !important;
        font-size: 0.85rem !important;
    }
    
    .table {
        font-size: 0.8rem !important;
        min-width: 500px;
    }
    
    .table th,
    .table td {
        padding: 0.5rem 0.375rem !important;
        font-size: 0.75rem !important;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .stats-number {
        font-size: 1.5rem !important;
    }
    
    .employee-page-header {
        padding: 1rem 0.75rem !important;
    }
}

/* Landscape orientation adjustments */
@media (max-width: 991.98px) and (orientation: landscape) {
    .sidebar {
        width: 250px;
    }
    
    .content-wrapper {
        padding: 0.5rem !important;
    }
    
    .mobile-header {
        padding: 0.5rem 0.75rem !important;
    }
    
    .page-title {
        font-size: 1.25rem !important;
    }
    
    .modal-content {
        max-height: 85vh !important;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .sidebar .nav-icon,
    .mobile-menu-toggle {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover,
    .nav-link:hover {
        transform: none;
    }
    
    .btn:active,
    .nav-link:active {
        transform: scale(0.98);
        opacity: 0.9;
    }
}
