/* ================================================
   MOBILE-FIRST RESPONSIVE DASHBOARD STYLES
   Optimized for mobile devices (320px - 768px)
   ================================================ */

/* ===== BASE & ROOT VARIABLES ===== */
:root {
    --mobile-padding: 12px;
    --mobile-margin: 8px;
    --mobile-radius: 12px;
    --touch-target: 44px;
    --mobile-font: 14px;
    --mobile-header-height: 60px;
}

/* ===== RESET & BASE MOBILE STYLES ===== */
* {
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    overflow-x: hidden;
}

body {
    font-size: var(--mobile-font);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== MOBILE CONTAINER ===== */
@media (max-width: 768px) {
    .container-fluid {
        padding-left: var(--mobile-padding) !important;
        padding-right: var(--mobile-padding) !important;
    }
    
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    [class*="col-"] {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }
}

/* ===== MOBILE NAVIGATION ===== */
@media (max-width: 768px) {
    .navbar {
        min-height: var(--mobile-header-height) !important;
        padding: 8px 12px !important;
    }
    
    .navbar-brand {
        font-size: 0.95rem !important;
        padding: 0 !important;
    }
    
    .brand-icon {
        width: 36px !important;
        height: 36px !important;
        padding: 6px !important;
    }
    
    .brand-icon i {
        font-size: 1rem !important;
    }
}

/* ===== NEW MOBILE MENU BUTTON - FLOATING ===== */
/* Hide sidebar on mobile and show menu button instead */
@media (max-width: 992px) {
    /* COMPLETELY HIDE SIDEBAR ON MOBILE */
    .sidebar {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    /* Floating Menu Button - Bottom Right */
    .mobile-menu-btn {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 9999;
        width: 60px;
        height: 60px;
        background: linear-gradient(135deg, #667eea, #764ba2);
        border: none;
        border-radius: 50%;
        box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: all 0.3s ease;
        animation: pulse 2s infinite;
    }
    
    .mobile-menu-btn:active {
        transform: scale(0.95);
    }
    
    .mobile-menu-btn i {
        color: white;
        font-size: 24px;
    }
    
    @keyframes pulse {
        0% {
            box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
        }
        50% {
            box-shadow: 0 6px 35px rgba(102, 126, 234, 0.8);
        }
        100% {
            box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
        }
    }
    
    /* Adjust main content to account for hidden sidebar */
    .col-md-9.ms-sm-auto.col-lg-10 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-left: 0 !important;
    }
}

/* ===== MOBILE TYPOGRAPHY ===== */
@media (max-width: 768px) {
    h1, .h1 { font-size: 1.75rem !important; line-height: 1.3; }
    h2, .h2 { font-size: 1.5rem !important; line-height: 1.3; }
    h3, .h3 { font-size: 1.3rem !important; line-height: 1.3; }
    h4, .h4 { font-size: 1.15rem !important; line-height: 1.3; }
    h5, .h5 { font-size: 1.05rem !important; line-height: 1.3; }
    h6, .h6 { font-size: 0.95rem !important; line-height: 1.3; }
    
    small, .small { font-size: 0.85rem !important; }
    .text-xs { font-size: 0.75rem !important; }
}

/* ===== MOBILE CARDS ===== */
@media (max-width: 768px) {
    .card {
        margin-bottom: 1rem !important;
        border-radius: var(--mobile-radius) !important;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08) !important;
    }
    
    .card:hover {
        transform: none !important;
    }
    
    .card-header {
        padding: 12px 16px !important;
        border-radius: var(--mobile-radius) var(--mobile-radius) 0 0 !important;
    }
    
    .card-body {
        padding: 16px !important;
    }
    
    .card-title {
        font-size: 1.1rem !important;
        margin-bottom: 0.5rem !important;
    }
}

/* ===== MOBILE STATS CARDS ===== */
@media (max-width: 768px) {
    .stats-card,
    [class*="border-left-"] {
        margin-bottom: 1rem !important;
    }
    
    .stats-card .card-body,
    [class*="border-left-"] .card-body {
        padding: 16px !important;
    }
    
    /* Stack stats vertically on small screens */
    .col-xl-3.col-md-6 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
    
    .stats-card .h5,
    [class*="border-left-"] .h5 {
        font-size: 1.8rem !important;
    }
    
    .stats-card .fa-2x,
    [class*="border-left-"] .fa-2x {
        font-size: 2rem !important;
    }
}

/* ===== MOBILE BUTTONS ===== */
@media (max-width: 768px) {
    .btn {
        padding: 12px 20px !important;
        font-size: 0.95rem !important;
        border-radius: 10px !important;
        min-height: var(--touch-target);
        font-weight: 600 !important;
    }
    
    .btn-sm {
        padding: 8px 14px !important;
        font-size: 0.85rem !important;
        min-height: 36px;
    }
    
    .btn-lg {
        padding: 14px 24px !important;
        font-size: 1.05rem !important;
        min-height: 52px;
    }
    
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .btn-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    
    .btn-toolbar .btn-group {
        margin-bottom: 8px;
    }
    
    /* Mobile quick action buttons */
    .d-grid.gap-2 .btn {
        margin-bottom: 12px;
    }
}

/* ===== MOBILE TABLES ===== */
@media (max-width: 768px) {
    .table-responsive {
        border-radius: var(--mobile-radius);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }
    
    .table {
        font-size: 0.85rem !important;
        margin-bottom: 0;
    }
    
    .table thead th {
        white-space: nowrap;
        padding: 10px 8px !important;
        font-size: 0.8rem !important;
        font-weight: 700 !important;
        background: rgba(102, 126, 234, 0.1) !important;
        position: sticky;
        top: 0;
        z-index: 10;
    }
    
    .table tbody td {
        padding: 10px 8px !important;
        white-space: nowrap;
        font-size: 0.85rem !important;
    }
    
    .table .btn {
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
        min-height: 32px;
    }
    
    /* Mobile table card view */
    .table-mobile-card {
        display: block !important;
    }
    
    .table-mobile-card thead {
        display: none !important;
    }
    
    .table-mobile-card tbody {
        display: block !important;
    }
    
    .table-mobile-card tr {
        display: block !important;
        margin-bottom: 12px;
        padding: 12px;
        background: white;
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.08);
        border: 1px solid rgba(0,0,0,0.05);
    }
    
    .table-mobile-card td {
        display: flex !important;
        justify-content: space-between;
        padding: 8px 0 !important;
        border: none !important;
        white-space: normal !important;
    }
    
    .table-mobile-card td::before {
        content: attr(data-label);
        font-weight: 700;
        color: #667eea;
        margin-right: 12px;
        flex-shrink: 0;
    }
    
    .table-mobile-card td:last-child {
        border-bottom: none !important;
    }
}

/* ===== MOBILE MAP ===== */
@media (max-width: 768px) {
    .map-container {
        height: 300px !important;
        border-radius: var(--mobile-radius);
        margin-bottom: 1rem;
    }
    
    /* Map info window */
    .gm-style .gm-style-iw-c {
        max-width: 280px !important;
        border-radius: 10px !important;
    }
    
    .gm-style .gm-style-iw-d {
        max-height: 300px !important;
    }
}

/* ===== MOBILE MODALS ===== */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 8px !important;
        max-width: calc(100% - 16px) !important;
    }
    
    .modal-content {
        border-radius: var(--mobile-radius) !important;
    }
    
    .modal-header {
        padding: 16px !important;
        border-radius: var(--mobile-radius) var(--mobile-radius) 0 0 !important;
    }
    
    .modal-body {
        padding: 16px !important;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: 12px 16px !important;
        border-radius: 0 0 var(--mobile-radius) var(--mobile-radius) !important;
    }
    
    .modal-footer .btn {
        flex: 1;
        margin: 4px !important;
    }
}

/* ===== MOBILE FORMS ===== */
@media (max-width: 768px) {
    .form-control,
    .form-select {
        padding: 12px 16px !important;
        font-size: 1rem !important;
        border-radius: 10px !important;
        min-height: var(--touch-target);
    }
    
    .form-label {
        font-size: 0.95rem !important;
        font-weight: 600 !important;
        margin-bottom: 8px !important;
    }
    
    .input-group-text {
        padding: 12px 16px !important;
        font-size: 1rem !important;
    }
    
    textarea.form-control {
        min-height: 120px !important;
    }
}

/* ===== MOBILE BADGES & PILLS ===== */
@media (max-width: 768px) {
    .badge {
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
        border-radius: 8px !important;
        font-weight: 600 !important;
    }
    
    .status-badge {
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
        border-radius: 8px !important;
    }
}

/* ===== MOBILE ALERTS ===== */
@media (max-width: 768px) {
    .alert {
        padding: 12px 16px !important;
        font-size: 0.9rem !important;
        border-radius: var(--mobile-radius) !important;
        margin-bottom: 12px !important;
    }
    
    .alert .btn-close {
        padding: 12px !important;
    }
}

/* ===== MOBILE DROPDOWNS ===== */
@media (max-width: 768px) {
    .dropdown-menu {
        min-width: 220px !important;
        border-radius: 12px !important;
        box-shadow: 0 8px 24px rgba(0,0,0,0.15) !important;
    }
    
    .dropdown-item {
        padding: 12px 16px !important;
        font-size: 0.95rem !important;
        min-height: var(--touch-target);
    }
    
    .dropdown-item i {
        width: 24px;
        text-align: center;
    }
}

/* ===== MOBILE WORKER CARDS ===== */
@media (max-width: 768px) {
    .worker-card {
        margin-bottom: 12px !important;
        border-radius: 10px !important;
    }
    
    .worker-card .card-body {
        padding: 12px !important;
    }
    
    .worker-card h6 {
        font-size: 1rem !important;
        margin-bottom: 4px !important;
    }
    
    .performance-bar {
        height: 6px !important;
        border-radius: 3px !important;
    }
}

/* ===== MOBILE PENDING WORKERS ===== */
@media (max-width: 768px) {
    .border-bottom {
        padding: 12px !important;
    }
    
    .border-bottom .d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .border-bottom .flex-grow-1 {
        width: 100%;
        margin-bottom: 12px;
    }
    
    .border-bottom .d-flex.flex-column {
        flex-direction: row !important;
        width: 100%;
        gap: 8px;
    }
    
    .border-bottom .btn {
        flex: 1;
        padding: 10px 16px !important;
        font-size: 0.9rem !important;
    }
}

/* ===== MOBILE PAGE HEADER ===== */
@media (max-width: 768px) {
    .d-flex.justify-content-between.flex-wrap {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .d-flex.justify-content-between.flex-wrap > div {
        width: 100%;
        margin-bottom: 12px;
    }
    
    .border-bottom {
        padding-bottom: 12px !important;
        margin-bottom: 16px !important;
    }
}

/* ===== MOBILE UTILITIES ===== */
@media (max-width: 768px) {
    .mb-4 { margin-bottom: 1rem !important; }
    .mb-3 { margin-bottom: 0.75rem !important; }
    .mb-2 { margin-bottom: 0.5rem !important; }
    
    .pb-3 { padding-bottom: 0.75rem !important; }
    .pt-3 { padding-top: 0.75rem !important; }
    
    .me-2 { margin-right: 8px !important; }
    .me-3 { margin-right: 12px !important; }
    
    /* Hide elements on mobile */
    .d-md-block { display: none !important; }
    .d-md-inline { display: none !important; }
    .d-md-inline-block { display: none !important; }
}

/* ===== MOBILE SCROLLING ===== */
@media (max-width: 768px) {
    /* Smooth scrolling */
    html {
        scroll-behavior: smooth;
    }
    
    /* Custom scrollbar for mobile */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-track {
        background: rgba(0,0,0,0.05);
    }
    
    ::-webkit-scrollbar-thumb {
        background: rgba(102, 126, 234, 0.5);
        border-radius: 2px;
    }
}

/* ===== MOBILE ANIMATIONS ===== */
@media (max-width: 768px) {
    /* Reduce motion for better performance */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    
    /* Touch feedback */
    .btn:active,
    .card:active,
    a:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* ===== MOBILE LOADING STATES ===== */
@media (max-width: 768px) {
    .loading {
        width: 24px !important;
        height: 24px !important;
        border-width: 3px !important;
    }
}

/* ===== MOBILE TOAST NOTIFICATIONS ===== */
@media (max-width: 768px) {
    .toast-container {
        padding: 12px !important;
        width: calc(100% - 24px) !important;
        left: 12px !important;
        right: 12px !important;
        top: calc(var(--mobile-header-height) + 12px) !important;
    }
    
    .toast {
        border-radius: 10px !important;
        font-size: 0.9rem !important;
    }
    
    .toast-body {
        padding: 12px 16px !important;
    }
}

/* ===== MOBILE-SPECIFIC CLASSES ===== */
@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .mobile-stack {
        flex-direction: column !important;
    }
    
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-padding {
        padding: var(--mobile-padding) !important;
    }
    
    .mobile-margin {
        margin: var(--mobile-margin) !important;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATION ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .map-container {
        height: 200px !important;
    }
    
    .modal-body {
        max-height: calc(100vh - 150px) !important;
    }
}

/* ===== VERY SMALL SCREENS (320px - 375px) ===== */
@media (max-width: 375px) {
    html { font-size: 13px; }
    
    .btn { padding: 10px 16px !important; }
    
    .card-body { padding: 12px !important; }
    
    .stats-card .h5 { font-size: 1.5rem !important; }
    
    .mobile-menu-toggle {
        width: 52px;
        height: 52px;
        font-size: 1.3rem;
    }
}

/* ===== ORDER DETAILS PAGE MOBILE STYLES ===== */
@media (max-width: 768px) {
    .order-detail-card {
        border-radius: 12px !important;
        margin-bottom: 15px !important;
    }
    
    .order-header {
        padding: 20px 15px !important;
        border-radius: 12px 12px 0 0 !important;
    }
    
    .order-header h2 {
        font-size: 1.4rem !important;
        margin-bottom: 10px !important;
    }
    
    .order-header .badge {
        font-size: 0.85rem !important;
        padding: 6px 12px !important;
        margin-bottom: 8px !important;
    }
    
    .back-button {
        width: 100%;
        margin-top: 15px;
    }
    
    .info-card {
        padding: 15px !important;
        margin-bottom: 15px !important;
        border-radius: 10px !important;
    }
    
    .info-card strong {
        font-size: 0.95rem !important;
    }
    
    .contact-item {
        padding: 12px !important;
        margin-bottom: 12px !important;
        flex-direction: row !important;
        border-radius: 10px !important;
    }
    
    .contact-icon {
        width: 45px !important;
        height: 45px !important;
        font-size: 1.2rem !important;
        margin-right: 12px !important;
        flex-shrink: 0;
    }
    
    .contact-item small {
        font-size: 0.8rem !important;
    }
    
    .contact-item strong {
        font-size: 1rem !important;
    }
    
    .stat-card {
        padding: 20px 15px !important;
        margin-bottom: 15px !important;
    }
    
    .stat-card i {
        font-size: 2.5rem !important;
    }
    
    .stat-card h2 {
        font-size: 1.8rem !important;
    }
    
    .stat-card h6 {
        font-size: 0.9rem !important;
    }
    
    #orderMap {
        height: 250px !important;
        border-radius: 10px !important;
    }
    
    .d-grid.gap-3 {
        gap: 12px !important;
    }
    
    .d-grid.gap-3 .btn {
        padding: 14px 20px !important;
        font-size: 1rem !important;
    }
}

/* ===== ORDER DETAILS PAGE LANDSCAPE MODE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .order-header {
        padding: 15px !important;
    }
    
    .order-header h2 {
        font-size: 1.3rem !important;
    }
    
    #orderMap {
        height: 200px !important;
    }
    
    .stat-card {
        padding: 15px !important;
    }
    
    .stat-card i {
        font-size: 2rem !important;
    }
    
    .stat-card h2 {
        font-size: 1.5rem !important;
    }
}

/* ===== ORDER DETAILS PAGE EXTRA SMALL SCREENS ===== */
@media (max-width: 375px) {
    .order-header h2 {
        font-size: 1.2rem !important;
    }
    
    .order-header .badge {
        font-size: 0.75rem !important;
        padding: 5px 10px !important;
    }
    
    .contact-icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 1rem !important;
    }
    
    .stat-card h2 {
        font-size: 1.6rem !important;
    }
}
