/* ========================================
   ULTRA RESPONSIVE MOBILE DESIGN
   ======================================== */

/* Mobile Ultra-Responsive - Base Styles */
@media (max-width: 480px) {
    /* Enhanced Typography */
    html {
        font-size: 13px; /* Plus petit pour plus de contenu */
    }
    
    body {
        font-size: 0.9rem;
        line-height: 1.5;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    h1 { font-size: 1.5rem; margin-bottom: 0.75rem; }
    h2 { font-size: 1.3rem; margin-bottom: 0.6rem; }
    h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
    h4 { font-size: 1rem; margin-bottom: 0.4rem; }
    
    /* Ultra-Compact Navigation */
    .navbar {
        padding: 0.4rem 0.75rem;
        height: auto;
        min-height: 50px;
        position: sticky;
        top: 0;
        z-index: 10000;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(10px);
    }
    
    .navbar-brand h1 {
        font-size: 1rem;
        line-height: 1.2;
    }
    
    .navbar-brand h1 span {
        display: none; /* Cacher le texte long sur mobile */
    }
    
    .navbar-actions {
        gap: 0.25rem;
        margin-right: 0.5rem;
    }
    
    .btn {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
        border-radius: 6px;
        min-height: 36px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .btn-sm {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
        min-height: 32px;
    }
    
    .btn i {
        font-size: 0.9em;
    }
    
    /* Enhanced Sidebar */
    .sidebar {
        width: 100%;
        max-width: 280px;
        transform: translateX(-100%);
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 99999;
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-toggle {
        display: block !important;
        position: fixed;
        top: 8px;
        left: 8px;
        z-index: 100000;
        background: var(--primary-color);
        color: white;
        border: none;
        padding: 0.4rem;
        border-radius: 6px;
        cursor: pointer;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    
    .sidebar-toggle:hover {
        background: var(--primary-dark);
        transform: scale(1.05);
    }
    
    /* Overlay for sidebar */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99998;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    /* Main Content */
    .main-content {
        margin-left: 0;
        width: 100%;
    }
    
    .content {
        padding: 0.5rem;
        margin-top: 50px;
        min-height: calc(100vh - 50px);
    }
    
    /* Ultra-Compact Grids */
    .stats-grid,
    .dashboard-grid,
    .features-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
    
    /* Compact Cards */
    .card,
    .stat-card {
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        border-radius: 8px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    .stat-value {
        font-size: 1.25rem;
        font-weight: 700;
        margin-bottom: 0.25rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
        opacity: 0.8;
    }
    
    /* Enhanced Forms */
    .form-group {
        margin-bottom: 0.75rem;
    }
    
    .form-row {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 0.6rem;
        border-radius: 6px;
        min-height: 44px; /* Touch target size */
    }
    
    .form-control:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }
    
    select.form-control {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23333' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.6rem center;
        padding-right: 2rem;
    }
    
    /* Enhanced Buttons */
    .btn-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-group .btn {
        width: 100%;
        min-height: 44px;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .action-buttons .btn {
        width: 100%;
        justify-content: center;
    }
    
    /* Compact Tables */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }
    
    table {
        font-size: 0.8rem;
        min-width: 500px;
    }
    
    th, td {
        padding: 0.4rem 0.3rem;
        white-space: nowrap;
        vertical-align: middle;
    }
    
    /* Enhanced Modals */
    .modal {
        padding: 0.5rem;
    }
    
    .modal-content {
        margin: 0;
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
    
    .modal-header {
        padding: 0.75rem;
        border-bottom: 1px solid #e0e0e0;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
    }
    
    .modal-body {
        padding: 0.75rem;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 0.75rem;
        border-top: 1px solid #e0e0e0;
        position: sticky;
        bottom: 0;
        background: white;
    }
    
    /* Compact Notifications */
    .notification,
    .alert {
        padding: 0.6rem;
        margin: 0.25rem;
        font-size: 0.85rem;
        border-radius: 6px;
    }
    
    /* Enhanced Dashboard Sections */
    .dashboard-section {
        padding: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .dashboard-header {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
        padding: 0.75rem;
    }
    
    .dashboard-header-left {
        text-align: center;
    }
    
    .dashboard-header h2 {
        font-size: 1.3rem;
        margin-bottom: 0.25rem;
    }
    
    .welcome-message {
        font-size: 0.9rem;
        opacity: 0.8;
    }
    
    /* Compact Filters */
    .filter-tabs {
        flex-wrap: wrap;
        gap: 0.25rem;
        margin-bottom: 0.75rem;
    }
    
    .filter-tab {
        font-size: 0.75rem;
        padding: 0.3rem 0.6rem;
        border-radius: 4px;
        min-height: 32px;
    }
    
    .filter-select {
        font-size: 0.85rem;
        padding: 0.5rem;
        min-height: 36px;
    }
    
    /* Enhanced Chat */
    .chat-container {
        height: calc(100vh - 100px);
        display: flex;
        flex-direction: column;
    }
    
    .chat-messages {
        flex: 1;
        padding: 0.5rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .message-bubble {
        max-width: 80%;
        padding: 0.5rem 0.75rem;
        margin-bottom: 0.5rem;
        border-radius: 12px;
        font-size: 0.85rem;
    }
    
    .chat-input {
        position: sticky;
        bottom: 0;
        padding: 0.5rem;
        background: white;
        border-top: 1px solid #e0e0e0;
    }
    
    .chat-input-container {
        display: flex;
        gap: 0.5rem;
        align-items: center;
    }
    
    .chat-input input {
        flex: 1;
        min-height: 40px;
    }
    
    /* Profile Sections */
    .profile-header {
        text-align: center;
        padding: 1rem 0.5rem;
    }
    
    .profile-avatar {
        width: 60px;
        height: 60px;
        margin: 0 auto 0.75rem;
        border-radius: 50%;
    }
    
    /* Compact Stats */
    .stats-section {
        padding: 0.75rem;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }
    
    .section-header h2 {
        font-size: 1.2rem;
    }
    
    /* Enhanced Forms */
    .demande-form {
        padding: 0.75rem;
    }
    
    .form-section {
        margin-bottom: 1rem;
        padding: 0.75rem;
        border-radius: 8px;
        background: #f8f9fa;
    }
    
    .form-section h3 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .form-actions {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .form-actions .btn {
        width: 100%;
        min-height: 44px;
    }
    
    /* Hide elements on mobile */
    .hide-mobile,
    .desktop-only,
    .tablet-only {
        display: none !important;
    }
    
    /* Show mobile elements */
    .mobile-only {
        display: block !important;
    }
    
    /* Enhanced Touch Targets */
    .clickable {
        min-height: 44px;
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Safe Area for notched phones */
    @supports (padding: max(0px)) {
        .navbar {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
        }
        
        .content {
            padding-left: max(0.5rem, env(safe-area-inset-left));
            padding-right: max(0.5rem, env(safe-area-inset-right));
        }
    }
    
    /* Enhanced Scrolling */
    .scrollable {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    /* Prevent text selection on touch */
    .no-select {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
    
    /* Enhanced Loading States */
    .loading-spinner {
        width: 20px;
        height: 20px;
        border-width: 2px;
    }
    
    /* Compact Empty States */
    .empty-state {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .empty-state i {
        font-size: 2rem;
        margin-bottom: 0.75rem;
    }
    
    .empty-state h4 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }
    
    .empty-state p {
        font-size: 0.85rem;
        margin-bottom: 1rem;
    }
}

/* Small Mobile (≤360px) - Ultra Compact */
@media (max-width: 360px) {
    html {
        font-size: 12px;
    }
    
    .navbar {
        padding: 0.3rem 0.5rem;
        min-height: 45px;
    }
    
    .navbar-brand h1 {
        font-size: 0.9rem;
    }
    
    .btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
        min-height: 32px;
    }
    
    .sidebar-toggle {
        width: 32px;
        height: 32px;
        top: 6px;
        left: 6px;
    }
    
    .content {
        padding: 0.4rem;
        margin-top: 45px;
    }
    
    .card,
    .stat-card {
        padding: 0.5rem;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .form-control {
        padding: 0.5rem;
        min-height: 40px;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 0.8rem;
    }
}

/* Large Mobile (481px-568px) - Optimized */
@media (min-width: 481px) and (max-width: 568px) {
    .navbar {
        padding: 0.5rem 1rem;
        min-height: 55px;
    }
    
    .navbar-brand h1 {
        font-size: 1.1rem;
    }
    
    .content {
        padding: 0.75rem;
        margin-top: 55px;
    }
    
    .stats-grid {
        gap: 1rem;
    }
    
    .card,
    .stat-card {
        padding: 1rem;
    }
    
    .stat-value {
        font-size: 1.4rem;
    }
    
    .form-control {
        padding: 0.75rem;
        min-height: 48px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }
    
    .card:hover {
        transform: none;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }
    
    /* Add active states for touch */
    .btn:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    .card:active {
        transform: scale(0.99);
        transition: transform 0.1s ease;
    }
}

/* Landscape Mobile Optimizations */
@media (max-width: 768px) and (orientation: landscape) {
    .navbar {
        min-height: 45px;
    }
    
    .content {
        margin-top: 45px;
    }
    
    .modal-content {
        max-height: 90vh;
    }
    
    .chat-container {
        height: calc(100vh - 90px);
    }
    
    .dashboard-section {
        padding: 0.5rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
}

/* High DPI Mobile Devices */
@media (-webkit-min-device-pixel-ratio: 2) and (max-width: 768px) {
    .btn {
        border-width: 0.5px;
    }
    
    .card {
        border-width: 0.5px;
    }
    
    .form-control {
        border-width: 0.5px;
    }
}

/* Dark Mode Mobile */
@media (prefers-color-scheme: dark) and (max-width: 768px) {
    .navbar {
        background: rgba(30, 30, 30, 0.98);
        color: white;
    }
    
    .content {
        background: #1a1a1a;
        color: white;
    }
    
    .card,
    .stat-card {
        background: #2a2a2a;
        color: white;
        border-color: #444;
    }
    
    .form-control {
        background: #333;
        color: white;
        border-color: #555;
    }
    
    .modal-content {
        background: #2a2a2a;
        color: white;
    }
}

/* Reduced Motion Mobile */
@media (prefers-reduced-motion: reduce) and (max-width: 768px) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .sidebar {
        transition: none;
    }
    
    .sidebar-overlay {
        transition: none;
    }
}

/* ========================================
   MOBILE ADAPTIVE COMPONENTS
   ======================================== */

/* Adaptive Navigation Menu */
@media (max-width: 480px) {
    .nav-menu {
        position: fixed;
        top: 50px;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        max-height: calc(100vh - 50px);
        overflow-y: auto;
        z-index: 9999;
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .nav-menu.active {
        transform: translateY(0);
    }
    
    .nav-menu li {
        border-bottom: 1px solid #f0f0f0;
    }
    
    .nav-menu a {
        display: block;
        padding: 1rem;
        color: #333;
        text-decoration: none;
        font-size: 0.9rem;
    }
    
    .nav-menu a:hover {
        background: #f8f9fa;
    }
}

/* Adaptive Cards */
@media (max-width: 480px) {
    .card-stack {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .card-horizontal {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .card-horizontal .card-image {
        width: 100%;
        height: 150px;
        object-fit: cover;
        border-radius: 6px;
    }
    
    .card-horizontal .card-content {
        padding: 0;
    }
}

/* Adaptive Lists */
@media (max-width: 480px) {
    .list-item {
        padding: 0.75rem;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .list-item:last-child {
        border-bottom: none;
    }
    
    .list-item-title {
        font-size: 0.9rem;
        font-weight: 600;
        margin-bottom: 0.25rem;
    }
    
    .list-item-description {
        font-size: 0.8rem;
        opacity: 0.7;
        line-height: 1.4;
    }
    
    .list-item-meta {
        font-size: 0.75rem;
        opacity: 0.6;
        margin-top: 0.25rem;
    }
}

/* Adaptive Tables */
@media (max-width: 480px) {
    .table-mobile {
        border: none;
    }
    
    .table-mobile thead {
        display: none;
    }
    
    .table-mobile tbody {
        display: block;
    }
    
    .table-mobile tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        padding: 0.75rem;
    }
    
    .table-mobile td {
        display: block;
        text-align: right;
        padding: 0.25rem 0;
        border: none;
    }
    
    .table-mobile td::before {
        content: attr(data-label) ": ";
        float: left;
        font-weight: 600;
        color: #666;
    }
}

/* Adaptive Progress Bars */
@media (max-width: 480px) {
    .progress-bar {
        height: 8px;
        border-radius: 4px;
    }
    
    .progress-label {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }
    
    .progress-value {
        font-size: 0.7rem;
        margin-top: 0.25rem;
    }
}

/* Adaptive Charts */
@media (max-width: 480px) {
    .chart-container {
        padding: 0.5rem;
    }
    
    .chart-canvas {
        max-height: 200px;
    }
    
    .chart-legend {
        font-size: 0.75rem;
        margin-top: 0.5rem;
    }
    
    .chart-legend-item {
        margin-bottom: 0.25rem;
    }
}

/* ========================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ======================================== */

@media (max-width: 480px) {
    /* Optimize images */
    img {
        max-width: 100%;
        height: auto;
        loading: lazy;
    }
    
    /* Optimize animations */
    .animate-on-scroll {
        opacity: 0;
        transform: translateY(20px);
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
    
    .animate-on-scroll.visible {
        opacity: 1;
        transform: translateY(0);
    }
    
    /* Optimize scrolling */
    .smooth-scroll {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Optimize fonts */
    .font-optimized {
        font-display: swap;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}
