/* Mobile-specific styles - Complete rewrite to fix layout issues */

@media (max-width: 767.98px) {
    /* Critical layout fixes */
    * {
        box-sizing: border-box;
    }
    
    body {
        overflow-x: hidden;
    }
    
    /* Container fixes */
    .container, .container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        width: 100%;
        max-width: 100%;
    }
    
    /* Row and column fixes */
    .row {
        margin-left: 0;
        margin-right: 0;
        width: 100%;
    }
    
    /* Force all columns to full width on mobile */
    .col-12, .col-md-3, .col-md-4, .col-md-6, .col-md-8, .col-md-9, .col-lg-3, .col-lg-4, .col-lg-6, .col-lg-8, .col-lg-9 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        margin-bottom: 1rem;
    }
    
    /* Card improvements */
    .card {
        margin-bottom: 1rem;
        border-radius: 0.75rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .card-body {
        padding: 1rem;
    }
    
    .card-header {
        padding: 0.75rem 1rem;
    }
    
    /* Button improvements */
    .btn {
        min-height: 44px;
        font-size: 1rem;
        padding: 0.625rem 1.25rem;
        margin-bottom: 0.5rem;
    }
    
    .btn.w-100 {
        width: 100% !important;
    }
    
    /* Typography adjustments */
    h1, h2, h3, h4, h5, h6 {
        word-wrap: break-word;
    }
    
    h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }
    
    .lead {
        font-size: 1rem;
        margin-bottom: 1rem;
    }
    
    /* Stats cards mobile layout */
    .stat-card {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        text-align: center;
    }
    
    .stat-card h5 {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .stat-card h3 {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }
    
    /* Mobile card view for tables */
    .mobile-card-view {
        display: block;
    }
    
    .table-responsive {
        display: none;
    }
    
    /* Navigation improvements */
    .navbar-nav .dropdown-menu {
        position: static;
        float: none;
        width: auto;
        margin-top: 0;
        background-color: transparent;
        border: 0;
        box-shadow: none;
    }
    
    /* Form improvements */
    .form-control {
        font-size: 1rem;
        padding: 0.625rem 1rem;
        min-height: 44px;
        border-radius: 0.5rem;
    }
    
    .form-group, .mb-3 {
        margin-bottom: 1.25rem;
    }
    
    /* Icon sizing */
    .fa-2x {
        font-size: 1.5rem !important;
    }
    
    /* Alert improvements */
    .alert {
        margin-bottom: 1rem;
        border-radius: 0.75rem;
        padding: 1rem;
    }
    
    /* Hide problematic elements completely */
    .quick-access-menu,
    .quick-access-trigger,
    .quick-access-grid {
        display: none !important;
    }
    
    /* Spacing improvements */
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }
    
    .p-3 {
        padding: 1rem !important;
    }
    
    /* Fix any overflow issues */
    .overflow-hidden {
        overflow: hidden !important;
    }
}

/* Ultra-small screens */
@media (max-width: 375px) {
    .container, .container-fluid {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    .btn {
        font-size: 0.9rem;
        padding: 0.5rem 1rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
}

/* ===== SKELETON LOADING ANIMATIONS ===== */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1em;
    margin-bottom: 0.5em;
    width: 100%;
}

.skeleton-text.short { width: 60%; }
.skeleton-text.medium { width: 80%; }

.skeleton-circle {
    border-radius: 50%;
}

.skeleton-card {
    padding: 16px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.skeleton-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-btn {
    height: 44px;
    border-radius: 8px;
}

/* ===== LAZY LOADING IMAGE STYLES ===== */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img[loading="lazy"].loaded,
img[loading="lazy"]:not([src=""]) {
    opacity: 1;
}

.lazy-image-container {
    position: relative;
    background: #f5f5f5;
    overflow: hidden;
}

.lazy-image-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

.lazy-image-container img.loaded + .lazy-placeholder,
.lazy-image-container img:not([src=""]) ~ .lazy-placeholder {
    display: none;
}

/* ===== LOADING SPINNER ===== */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 102, 0, 0.3);
    border-radius: 50%;
    border-top-color: #FF6600;
    animation: spin 0.8s linear infinite;
}

.loading-spinner.lg {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

.loading-spinner.sm {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.btn-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.8;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

/* ===== ENHANCED TOUCH TARGETS ===== */
@media (max-width: 767.98px) {
    .touch-target {
        min-height: 48px;
        min-width: 48px;
        padding: 12px;
    }
    
    .list-group-item {
        padding: 16px;
        min-height: 56px;
    }
    
    .form-check-input {
        width: 24px;
        height: 24px;
        margin-top: 0;
    }
    
    .form-check-label {
        padding-left: 8px;
        line-height: 24px;
    }
    
    /* Larger clickable areas for cards */
    .action-card, .stat-card {
        min-height: 80px;
    }
    
    /* Better spacing for mobile forms */
    .form-floating > label {
        padding: 16px 12px;
    }
    
    .form-floating > .form-control {
        padding: 24px 12px 8px;
    }
}

/* ===== CONTENT FADE IN ===== */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== PULL TO REFRESH INDICATOR ===== */
.pull-refresh-indicator {
    position: fixed;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: #FF6600;
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 9999;
    transition: top 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pull-refresh-indicator.visible {
    top: 20px;
}