/* Mobile App Styles - Enhanced Ergonomics v2 */

/* Safe area pour iPhone X+ et appareils avec encoche */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Touch highlight désactivé pour une sensation native */
* {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    box-sizing: border-box;
}

/* Prevent pull-to-refresh sur iOS (sauf si nécessaire) */
body.no-pull-refresh {
    overscroll-behavior-y: contain;
}

/* Empêcher le débordement horizontal global */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ============================================
   MOBILE STYLES - max-width: 768px
   ============================================ */
@media (max-width: 768px) {
    body {
        font-size: 15px;
        line-height: 1.5;
    }

    /* Containers - padding adaptatif */
    main,
    .container,
    .max-w-4xl,
    .max-w-5xl,
    .max-w-6xl,
    .max-w-7xl,
    .max-w-8xl {
        padding-left: 12px !important;
        padding-right: 12px !important;
        max-width: 100% !important;
        overflow-x: hidden;
    }

    /* Titres responsives */
    h1 {
        font-size: 1.4rem !important;
        line-height: 1.3;
        margin-bottom: 0.75rem;
    }
    h2 {
        font-size: 1.2rem !important;
        margin-bottom: 0.5rem;
    }
    h3 {
        font-size: 1.05rem !important;
        margin-bottom: 0.4rem;
    }

    /* Cartes - padding et espacement optimisés */
    .bg-white.rounded-xl,
    .bg-white.rounded-lg,
    .bg-white.shadow-sm,
    .bg-white.shadow-lg,
    .bg-white.shadow-md,
    .card,
    .main-card-3d {
        padding: 14px !important;
        margin-bottom: 12px;
        border-radius: 12px !important;
        overflow: hidden;
    }

    /* Grilles - 1 ou 2 colonnes max sur mobile */
    .grid {
        gap: 10px !important;
    }
    
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4,
    .sm\:grid-cols-2,
    .sm\:grid-cols-3,
    .sm\:grid-cols-4,
    .md\:grid-cols-2,
    .md\:grid-cols-3,
    .md\:grid-cols-4,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .lg\:grid-cols-4,
    .xl\:grid-cols-4,
    .xl\:grid-cols-6 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    
    .grid-cols-1 {
        grid-template-columns: 1fr !important;
    }

    /* Tables lisibles avec scroll horizontal */
    table {
        font-size: 13px;
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    table th,
    table td {
        padding: 10px 12px;
    }
    
    .overflow-x-auto,
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        overflow-x: auto;
        margin: 0 -12px;
        padding: 0 12px;
    }

    /* Boutons - taille tactile minimale */
    button,
    .btn,
    a.btn,
    [type="submit"],
    [type="button"],
    .px-6.py-3,
    .px-4.py-3,
    .px-4.py-2,
    .px-3.py-2 {
        min-height: 44px !important;
        padding: 10px 16px !important;
        font-size: 0.9rem !important;
        border-radius: 10px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Boutons dans les cartes - full width sur mobile */
    .card button,
    .card .btn,
    .bg-white button:not(.inline-btn),
    .bg-white .btn:not(.inline-btn) {
        width: 100%;
    }

    /* Forms - Inputs touchables */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    textarea,
    select {
        min-height: 48px !important;
        font-size: 16px !important; /* Empêche le zoom auto sur iOS */
        padding: 12px 14px !important;
        border-radius: 10px !important;
        width: 100% !important;
    }

    /* Labels des formulaires */
    label {
        font-size: 0.85rem;
        margin-bottom: 6px;
        display: block;
    }

    /* Espacement des groupes de formulaire */
    .form-group,
    .mb-4,
    .space-y-4 > * {
        margin-bottom: 14px !important;
    }

    /* Cartes de statistiques */
    .stat-card,
    .stat-card-glass,
    .square-card,
    .dashboard-stat-card,
    .quick-stats .stat-card {
        display: flex;
        flex-direction: row !important;
        align-items: center;
        padding: 12px 14px !important;
        border-radius: 12px !important;
        font-size: 0.9rem;
        min-height: 60px;
        gap: 12px;
    }

    .stat-card .stat-icon,
    .stat-card-glass .stat-icon {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0;
    }
    
    .stat-card .stat-icon svg,
    .stat-card-glass .stat-icon svg {
        width: 20px !important;
        height: 20px !important;
    }

    .stat-card .stat-content,
    .stat-card-glass .stat-content {
        flex: 1;
        min-width: 0;
    }

    .stat-card .stat-value {
        font-size: 1.25rem !important;
        font-weight: 700;
    }

    .stat-card .stat-label {
        font-size: 0.75rem !important;
        color: #6b7280;
    }

    /* Hero sections - réduire la hauteur */
    .dashboard-hero,
    .presta-hero,
    [class*="hero"] {
        padding: 24px 0 !important;
    }

    .hero-content,
    .presta-hero-content {
        padding: 0 12px;
    }

    /* Avatars */
    .avatar-container,
    .avatar-image,
    .avatar-placeholder {
        width: 56px !important;
        height: 56px !important;
    }

    .user-name {
        font-size: 1.1rem !important;
    }

    .user-role,
    .user-since {
        font-size: 0.8rem !important;
    }

    /* Filtres - empilés sur mobile */
    .presta-filter-grid,
    .filter-grid,
    [class*="filter"] .grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* Badges et tags */
    .badge,
    .tag,
    .rounded-full.px-3,
    .rounded-full.px-2 {
        font-size: 0.7rem !important;
        padding: 4px 8px !important;
        white-space: nowrap;
    }

    /* Pagination mobile */
    .pagination,
    nav[role="navigation"] {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
    }

    .pagination a,
    .pagination span,
    nav[role="navigation"] a,
    nav[role="navigation"] span {
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 6px 10px !important;
        font-size: 0.85rem !important;
    }

    /* Modals - plein écran sur mobile */
    .modal,
    .modal-content,
    [x-show*="modal"],
    [x-show*="Modal"],
    [x-data*="modal"] > div[x-show] {
        max-width: 100vw !important;
        width: 100% !important;
        max-height: 90vh !important;
        border-radius: 16px 16px 0 0 !important;
        margin: auto 0 0 0 !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    /* Dropdown menus */
    .dropdown-menu,
    [x-show*="dropdown"],
    [x-show*="open"] {
        min-width: 200px;
        max-width: calc(100vw - 24px);
        border-radius: 12px;
    }

    /* Bottom navigation spacing */
    main {
        padding-bottom: 90px !important;
    }

    /* Images adaptatives */
    img {
        max-width: 100%;
        height: auto;
    }

    /* Galeries d'images */
    .image-gallery,
    .gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    /* Breadcrumb - caché sur mobile, utiliser le back button */
    nav[aria-label="Breadcrumb"],
    .breadcrumb {
        display: none !important;
    }

    /* Boutons sticky en bas */
    .form-actions-sticky,
    .sticky-bottom-actions {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 100;
        display: flex;
        gap: 12px;
    }

    .form-actions-sticky button,
    .form-actions-sticky .btn,
    .sticky-bottom-actions button,
    .sticky-bottom-actions .btn {
        flex: 1;
    }

    /* Cards avec actions - stack vertical */
    .card-actions,
    .flex.gap-2.mt-4,
    .flex.space-x-2 {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .card-actions > *,
    .flex.gap-2.mt-4 > * {
        width: 100% !important;
    }

    /* Texte tronqué avec ellipsis */
    .truncate-mobile,
    .card h3,
    .card h4,
    .card-title {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }

    /* Tabs sur mobile - scroll horizontal */
    .tabs,
    [role="tablist"],
    .tab-list {
        display: flex;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
        padding-bottom: 4px;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar,
    [role="tablist"]::-webkit-scrollbar,
    .tab-list::-webkit-scrollbar {
        display: none;
    }

    .tabs button,
    [role="tab"],
    .tab-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 10px 16px !important;
        font-size: 0.85rem !important;
    }

    /* Progress bars */
    .progress-bar,
    [role="progressbar"] {
        height: 8px !important;
        border-radius: 4px;
    }

    /* Alerts et notifications inline */
    .alert,
    [role="alert"],
    .notification-item {
        padding: 12px 14px !important;
        font-size: 0.9rem !important;
        border-radius: 10px !important;
    }

    /* Sidebar - cachée par défaut, overlay sur mobile */
    .sidebar,
    aside {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: 85vw;
        max-width: 320px;
        z-index: 1000;
        transition: left 0.3s ease;
    }

    .sidebar.open,
    aside.open {
        left: 0;
    }

    /* Overlay pour sidebar */
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Loading spinners */
    .spinner,
    .loading {
        width: 32px !important;
        height: 32px !important;
    }

    /* Empty states */
    .empty-state,
    .no-results {
        padding: 32px 20px !important;
        text-align: center;
    }

    .empty-state svg,
    .empty-state i {
        width: 48px !important;
        height: 48px !important;
        margin-bottom: 12px;
    }

    /* Flex wrap pour éviter overflow */
    .flex:not(.flex-col):not(.flex-nowrap) {
        flex-wrap: wrap;
    }

    /* Prix et montants */
    .price,
    .amount,
    [class*="price"],
    [class*="amount"] {
        font-size: 1.1rem !important;
        font-weight: 700;
    }

    /* Horaires et dates */
    .time,
    .date,
    [class*="time"],
    [class*="date"] {
        font-size: 0.85rem;
    }

    /* Action icons en ligne */
    .action-icons,
    .icon-buttons {
        display: flex;
        gap: 8px;
    }

    .action-icons button,
    .icon-buttons button {
        width: 40px !important;
        height: 40px !important;
        padding: 0 !important;
        min-height: 40px !important;
    }

    /* Texte secondaire plus petit */
    .text-sm,
    .text-xs,
    small,
    .secondary-text,
    .meta {
        font-size: 0.8rem !important;
    }

    /* Espacement entre sections */
    section,
    .section {
        margin-bottom: 20px !important;
    }

    /* Rating stars */
    .rating,
    .stars {
        font-size: 0.9rem !important;
    }

    /* Chips/Pills selection */
    .chip,
    .pill,
    [class*="chip"],
    [class*="pill"] {
        padding: 8px 14px !important;
        font-size: 0.85rem !important;
        min-height: 36px;
    }
}

/* ============================================
   TRÈS PETITS ÉCRANS - max-width: 375px
   ============================================ */
@media (max-width: 375px) {
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 1.25rem !important;
    }

    h2 {
        font-size: 1.1rem !important;
    }

    main,
    .container {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .grid-cols-2,
    .md\:grid-cols-2,
    .sm\:grid-cols-2 {
        grid-template-columns: 1fr !important;
    }

    button,
    .btn {
        padding: 10px 12px !important;
        font-size: 0.85rem !important;
    }

    .stat-card .stat-value {
        font-size: 1.1rem !important;
    }

    .avatar-container,
    .avatar-image,
    .avatar-placeholder {
        width: 48px !important;
        height: 48px !important;
    }
}

/* ============================================
   LANDSCAPE MOBILE
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .dashboard-hero,
    .presta-hero,
    [class*="hero"] {
        padding: 16px 0 !important;
    }

    main {
        padding-bottom: 60px !important;
    }

    .grid-cols-2,
    .md\:grid-cols-2 {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

/* ============================================
   DARK MODE SUPPORT (si implémenté)
   ============================================ */
@media (prefers-color-scheme: dark) {
    .form-actions-sticky,
    .sticky-bottom-actions {
        background: #1f2937;
        border-top: 1px solid #374151;
    }
}