/**
 * CariKolektor - Mobile Responsive Utilities
 * Ensures mobile-first design with proper breakpoints for mobile, tablet, desktop.
 * Addresses: touch targets, filter bottom sheet, fixed apply button, sidebar collapse.
 * Requirements: 27.1, 27.2, 27.3, 27.4, 27.5
 */

/* ==========================================================================
   1. GLOBAL TOUCH TARGET ENFORCEMENT (Min 44x44px)
   Requirement 27.5
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Ensure all buttons meet 44px min touch target */
    .btn,
    .nav-link,
    .dropdown-item,
    .form-check-input,
    .page-link,
    .mobilenav ul li a {
        min-height: 44px;
        min-width: 44px;
    }

    /* Form elements touch targets */
    .form-control,
    .form-select {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 16px; /* Prevents iOS zoom on focus */
    }

    /* Checkbox and radio touch targets */
    .form-check {
        padding-top: 6px;
        padding-bottom: 6px;
    }

    .form-check-input {
        width: 22px;
        height: 22px;
        margin-top: 0.1em;
    }

    .form-check-label {
        padding-left: 6px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Pagination touch targets */
    .pagination .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 8px 12px;
    }

    /* Nav links touch targets */
    .navbar-nav .nav-link {
        padding: 12px 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Dropdown items touch targets */
    .dropdown-menu .dropdown-item {
        padding: 12px 16px;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* ==========================================================================
   2. JOB SEARCH PAGE - FILTER BOTTOM SHEET (Mobile)
   Requirement 27.2
   ========================================================================== */

@media (max-width: 767.98px) {
    /* Filter toggle button styling */
    .job-search-filter-toggle {
        min-height: 48px;
        font-size: 16px;
        font-weight: 500;
        border-radius: 8px;
    }

    /* Bottom sheet / overlay filter styling */
    .filter-sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        max-height: 85vh;
        z-index: 1060;
        background: #fff;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        padding: 0;
        overflow-y: auto;
        animation: slideUp 0.3s ease-out;
    }

    .filter-sidebar::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #dee2e6;
        border-radius: 2px;
        margin: 12px auto 8px;
    }

    .filter-sidebar .card {
        border: none;
        box-shadow: none;
        border-radius: 0;
        max-height: none;
    }

    .filter-sidebar .card-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 10;
        border-bottom: 1px solid #eee;
        padding: 12px 20px;
    }

    .filter-sidebar .card-body {
        padding: 16px 20px 100px;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    /* Overlay background when filters are open */
    .filter-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1055;
    }
}

/* ==========================================================================
   3. JOB DETAIL PAGE - FIXED APPLY BUTTON (Mobile)
   Requirement 27.3
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Fixed bottom apply bar */
    .mobile-apply-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #fff;
        padding: 12px 16px;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
        z-index: 1040;
    }

    .mobile-apply-bar .btn-apply {
        min-height: 48px;
        font-size: 16px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        gap: 8px;
    }

    /* Add bottom padding to content so it doesn't hide behind the fixed bar */
    .section {
        padding-bottom: 100px;
    }
}

/* ==========================================================================
   4. DASHBOARD SIDEBAR - HAMBURGER MENU (Mobile)
   Requirement 27.4
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Dashboard sidebar off-canvas */
    #dashboardSidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 1050;
        background: #fff;
        overflow-y: auto;
        transition: left 0.3s ease-in-out;
        padding: 20px 15px;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }

    #dashboardSidebar.sidebar-open {
        left: 0;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
        transition: opacity 0.3s ease;
    }

    /* Sidebar toggle button styling */
    #sidebarToggle {
        min-width: 44px;
        min-height: 44px;
        padding: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar navigation items - touch targets */
    .usernavwrap .usernav li a,
    .usernavwrap .nav-link {
        min-height: 44px;
        padding: 12px 16px;
        display: flex;
        align-items: center;
    }

    /* Close button in sidebar for mobile */
    .sidebar-close-btn {
        position: absolute;
        top: 12px;
        right: 12px;
        width: 44px;
        height: 44px;
        border: none;
        background: #f8f9fa;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
        color: #666;
        cursor: pointer;
    }

    .sidebar-close-btn:hover {
        background: #e9ecef;
    }
}

/* ==========================================================================
   5. ADMIN PANEL RESPONSIVE FIXES
   Requirement 27.4
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Admin panel responsive menu toggler */
    .page-header .responsive-toggler {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Admin sidebar items touch targets */
    .page-sidebar .page-sidebar-menu > li > a {
        min-height: 44px;
        padding: 12px 15px;
    }

    .page-sidebar .page-sidebar-menu > li > a > .title {
        font-size: 14px;
    }
}

/* ==========================================================================
   6. COMPANY DIRECTORY - MOBILE ADJUSTMENTS
   ========================================================================== */

@media (max-width: 767.98px) {
    /* Stack filter fields on mobile */
    .company-filters .row > [class*="col-"] {
        margin-bottom: 8px;
    }

    /* Show "Lihat Profil" link on mobile as full-width button below card content */
    .company-card .flex-shrink-0.d-none.d-md-block {
        display: block !important;
        margin-top: 12px;
        width: 100%;
    }

    .company-card .flex-shrink-0 .btn {
        width: 100%;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Adjust company card layout for mobile */
    .company-card .card-body .d-flex {
        flex-wrap: wrap;
    }

    .company-card .flex-grow-1 {
        min-width: 0;
        flex-basis: calc(100% - 76px);
    }

    .company-meta span {
        display: block;
        margin-bottom: 4px;
    }
}

/* ==========================================================================
   7. MOBILE BOTTOM NAVIGATION ENHANCEMENTS
   ========================================================================== */

@media (max-width: 991.98px) {
    /* Ensure mobile bottom nav doesn't overlap fixed apply button */
    .mobilenav {
        z-index: 1030;
    }

    /* When mobile-apply-bar is present, add margin to mobile nav */
    body:has(.mobile-apply-bar) .mobilenav {
        display: none;
    }

    /* Mobile nav items touch targets */
    .mobilenav ul li {
        min-width: 44px;
    }

    .mobilenav ul li a {
        min-height: 56px;
        padding: 8px 4px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    /* Prevent mobile bottom nav from overlapping footer copyright text */
    .copyright {
        padding-bottom: 80px;
    }
}

/* ==========================================================================
   8. TABLET BREAKPOINT ADJUSTMENTS (768px - 991px)
   ========================================================================== */

@media (min-width: 768px) and (max-width: 991.98px) {
    /* Job cards - maintain readability */
    .job-card .job-meta span {
        font-size: 12px;
    }

    /* Dashboard - allow sidebar as collapsed icons */
    .container-fluid .row > .col-lg-3 {
        flex: 0 0 auto;
        width: 100%;
    }

    .container-fluid .row > .col-lg-9 {
        flex: 0 0 auto;
        width: 100%;
    }
}

/* ==========================================================================
   9. GENERAL MOBILE-FIRST IMPROVEMENTS
   Requirement 27.1
   ========================================================================== */

/* Ensure text doesn't overflow on small screens */
@media (max-width: 575.98px) {
    .job-title,
    .company-name,
    h1, h2, h3 {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .job-detail-header .job-title {
        font-size: 1.2rem;
    }

    .job-meta {
        flex-direction: column;
        gap: 8px;
    }

    .job-meta-item {
        font-size: 0.85rem;
    }

    /* Full-width buttons on extra small screens */
    .btn-apply {
        font-size: 15px;
        padding: 14px 16px;
    }

    /* Stack breadcrumb items */
    .breadcrumb {
        font-size: 13px;
    }

    /* Cards padding reduction */
    .card-body {
        padding: 16px;
    }

    .job-section {
        padding: 16px;
        margin-bottom: 12px;
    }

    .sidebar-card {
        padding: 16px;
    }
}

/* Prevent horizontal scroll — only on body to avoid modal backdrop issues */
body {
    overflow-x: hidden;
}

/* Fix Bootstrap modal - remove fade animation to prevent blink */
.modal.fade {
    transition: none !important;
}
.modal.fade .modal-dialog {
    transition: none !important;
    transform: none !important;
}
.modal-backdrop.fade {
    transition: none !important;
}
.modal-backdrop.show {
    opacity: 0.5;
}

/* Smooth scrolling on iOS */
* {
    -webkit-overflow-scrolling: touch;
}

/* Prevent font size auto-adjustment on orientation change */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}
