/*
   ==========================================================================
   MOBILE-FIRST RESPONSIVE DESIGN
   ==========================================================================
   Breakpoints:
   - Mobile: 0 - 640px
   - Tablet: 641px - 1024px
   - Desktop: 1025px+
*/

/* ========================================
   1. MOBILE MENU TOGGLE
   ======================================== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 200;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s, background 0.3s;
}

.mobile-menu-toggle:hover {
    transform: scale(1.1);
}

.mobile-menu-toggle.active {
    background: #ef4444;
}

.mobile-menu-toggle ion-icon {
    transition: transform 0.3s;
}

.mobile-menu-toggle.active ion-icon {
    transform: rotate(90deg);
}

/* ========================================
   2. SIDEBAR OVERLAY
   ======================================== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ========================================
   3. BASE MOBILE STYLES (Default)
   ======================================== */

/* Hide scrollbars but keep functionality */
.hide-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.hide-scrollbar::-webkit-scrollbar {
    display: none;
}

/* Dropdown overlay - hidden by default on desktop */
.dropdown-overlay {
    display: none;
}

/* Mobile page title - hidden by default */
.mobile-page-title {
    display: none;
}

/* ========================================
   4. MOBILE (max-width: 640px)
   ======================================== */
@media (max-width: 640px) {
    /* === SAFETY NET ULTIME : empêche TOUT débordement horizontal === */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    /* Tous les conteneurs principaux respectent la largeur de l'écran */
    .dashboard-layout,
    .main-content,
    .container,
    .container-fluid,
    .premium-container,
    main,
    section,
    article {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Toute image, vidéo, iframe : ne peut pas déborder */
    img, video, iframe, embed, object {
        max-width: 100% !important;
        height: auto !important;
    }

    /* Body & Layout */
    body {
        font-size: 14px;
    }

    .dashboard-layout {
        padding: 0.75rem;
        gap: 0;
        flex-direction: column;
    }

    /* Sidebar - Hidden slide-in menu */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        border-radius: 0 24px 24px 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 100;
        padding: 1.5rem 1rem;
        flex-direction: column;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar .nav-item {
        width: 100%;
        height: auto;
        padding: 0.75rem 1rem;
        border-radius: 12px;
        justify-content: flex-start;
        gap: 0.75rem;
    }

    .sidebar .nav-item::after {
        display: none;
    }

    .sidebar .logo-bubble {
        margin-bottom: 1rem;
    }

    /* Show mobile menu toggle */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Main Content */
    .main-content {
        padding: 0;
        width: 100%;
        min-width: 0;
    }

    /* Topbar adjustments */
    .topbar-layout {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 0;
        margin-bottom: 1rem;
    }

    /* Mobile page title */
    .mobile-page-title {
        display: block;
        order: 0;
    }

    .mobile-page-title h1 {
        font-size: 1.5rem;
        font-weight: 700;
        color: var(--text-main, #1e293b);
        margin: 0;
        line-height: 1.2;
    }

    /* Pill menu visible sur mobile — navigation principale */
    .top-nav {
        display: flex;
        order: 1;
        width: 100%;
        justify-content: center;
    }

    .top-nav .pill-menu {
        padding: 0.3rem;
        gap: 0.2rem;
        width: 100%;
        justify-content: space-between;
    }

    .top-nav .pill-link {
        padding: 0.5rem 0.8rem;
        font-size: 0.78rem;
        flex: 1;
        text-align: center;
    }

    /* Sidebar drawer plus nécessaire comme nav principale → cacher le toggle flottant */
    .mobile-menu-toggle {
        display: none !important;
    }

    /* Header actions - compact row */
    .header-actions {
        order: 2;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 0.5rem;
    }

    /* Mobile search - expandable */
    .search-pill {
        flex: 1;
        width: auto;
        min-width: 0;
        padding: 0.5rem 1rem;
        background: white;
        border-radius: 25px;
    }

    .search-pill input {
        font-size: 0.9rem;
    }

    .search-pill input::placeholder {
        font-size: 0.85rem;
    }

    /* Circle buttons - touch friendly */
    .circle-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        font-size: 1.2rem;
    }

    /* Hide residence name on mobile */
    .residence-name {
        display: none !important;
    }

    .residence-selector-btn {
        padding: 0.6rem;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        justify-content: center;
    }

    .residence-selector-btn .chevron {
        display: none;
    }

    /* Notification wrapper : DOIT rester relative en mobile pour que le badge
       rouge (position:absolute; top:-4px; right:-4px) reste sur la cloche.
       Avant: static → le badge remontait coller en haut de la page.
       Le dropdown est forcé en position:fixed plus bas, donc pas de souci. */
    .notification-wrapper {
        position: relative;
    }

    /* Badge plus compact sur mobile */
    .notif-badge {
        min-width: 16px !important;
        height: 16px !important;
        font-size: 0.58rem !important;
        padding: 0 4px !important;
        border-width: 1.5px !important;
        top: -3px !important;
        right: -3px !important;
    }

    /* Dropdowns sur mobile : positionnés sous la topbar, alignés à droite */
    .notification-dropdown,
    .profile-dropdown,
    .residence-dropdown {
        position: fixed !important;
        top: 70px !important;
        right: 8px !important;
        bottom: auto !important;
        left: auto !important;
        width: calc(100vw - 16px) !important;
        max-width: 360px !important;
        border-radius: 16px !important;
        max-height: 80vh;
        overflow-y: auto;
        transform: translateY(-8px) scale(0.97) !important;
        opacity: 0 !important;
        visibility: hidden;
    }

    .notification-dropdown.show,
    .profile-dropdown.show,
    .residence-dropdown.show {
        transform: translateY(0) scale(1) !important;
        opacity: 1 !important;
        visibility: visible;
    }

    /* Pas de poignée (plus de bottom sheet) */
    .notification-dropdown::before,
    .profile-dropdown::before,
    .residence-dropdown::before {
        content: none;
    }

    /* Overlay for bottom sheets */
    .dropdown-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s;
    }

    .dropdown-overlay.show {
        opacity: 1;
        visibility: visible;
    }

    /* Page Headers */
    .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .header-row .header-actions,
    .header-row > div:last-child {
        width: 100%;
    }

    .page-title {
        font-size: 1.5rem !important;
    }

    /* Stats Grid */
    .stats-row {
        grid-template-columns: 1fr !important;
        gap: 0.75rem;
    }

    .stat-bubble-card {
        padding: 1rem;
        border-radius: 16px;
    }

    .stat-icon-circle {
        width: 44px;
        height: 44px;
        font-size: 1.2rem;
    }

    .stat-info .value {
        font-size: 1.25rem;
    }

    .stat-info .label {
        font-size: 0.75rem;
    }

    /* Cards */
    .clay-card {
        padding: 1rem;
        border-radius: 20px;
        margin-bottom: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .card-header h2,
    .card-header h3 {
        font-size: 1.1rem;
    }

    .card-header .card-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    /* Grids - Single column on mobile */
    .rooms-grid-soft,
    .residences-grid-soft,
    .reports-grid,
    .settings-grid,
    .grid-cols-2,
    .grid-cols-3,
    .lg\:grid-cols-2,
    .lg\:grid-cols-3,
    .md\:grid-cols-2,
    .md\:grid-cols-3 {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    /* =============================================
       SELECT / INPUTS - Fix mobile
       ============================================= */
    select,
    select.form-control,
    select.input-premium {
        /* Style custom compact — pas de picker natif plein écran */
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        appearance: none !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 0.9rem center !important;
        background-size: 1.1em !important;
        padding-right: 2.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        cursor: pointer;
    }

    /* Tous les champs de saisie restent dans leur conteneur */
    input,
    input.form-control,
    input.input-premium,
    textarea,
    textarea.form-control {
        max-width: 100% !important;
        box-sizing: border-box !important;
        width: 100% !important;
    }

    /* Conteneurs de formulaires : pas de débordement horizontal */
    .clay-card,
    .glass-panel,
    .form-group,
    .settings-form,
    form {
        max-width: 100% !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* Stats grid - 2 columns on mobile for compact view */
    .stats-row {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }

    .stat-bubble-card {
        padding: 0.875rem;
        border-radius: 16px;
        flex-direction: column;
        text-align: center;
    }

    .stat-bubble-card .stat-icon-circle {
        margin-bottom: 0.5rem;
    }

    .stat-bubble-card .stat-info {
        text-align: center;
    }

    .stat-bubble-card .stat-info .value {
        font-size: 1.25rem;
    }

    .stat-bubble-card .stat-info .label {
        font-size: 0.7rem;
    }

    /* Room Cards - Compact */
    .room-card-soft {
        padding: 1rem;
        border-radius: 16px;
    }

    .room-card-soft .room-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }

    .room-number {
        font-size: 1.5rem;
    }

    .room-type-badge {
        font-size: 0.7rem;
        padding: 0.2rem 0.5rem;
    }

    .room-pricing {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .price-tag {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }

    .room-status {
        margin-top: 0.75rem;
    }

    /* Residence Cards */
    .residence-card-soft {
        padding: 1rem;
    }

    .residence-card-soft .residence-header {
        gap: 0.75rem;
    }

    .residence-card-soft .residence-logo {
        width: 48px;
        height: 48px;
    }

    /* Client Cards */
    .client-card {
        padding: 1rem;
    }

    .client-avatar {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    /* Invoice Cards */
    .invoice-card {
        padding: 1rem;
    }

    .invoice-amount {
        font-size: 1.1rem;
    }

    /* Alert Cards */
    .alert-card {
        padding: 0.875rem;
        border-radius: 12px;
    }

    /* Empty State Cards */
    .empty-state-card {
        padding: 2rem 1rem;
    }

    .empty-icon-bubble {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }

    .empty-state-card p {
        font-size: 0.9rem;
    }

    /* Timeline and list items */
    .timeline-item,
    .history-item {
        padding: 0.875rem;
    }

    /* Flex utilities on mobile */
    .flex-col-mobile {
        flex-direction: column !important;
    }

    .gap-sm-mobile {
        gap: 0.5rem !important;
    }

    /* Spacing utilities */
    .mb-6 {
        margin-bottom: 1.5rem !important;
    }

    .mt-6 {
        margin-top: 1.5rem !important;
    }

    .p-6 {
        padding: 1rem !important;
    }

    .gap-6 {
        gap: 1rem !important;
    }

    /* Text sizes */
    .text-2xl {
        font-size: 1.25rem !important;
    }

    .text-xl {
        font-size: 1.1rem !important;
    }

    .text-lg {
        font-size: 1rem !important;
    }

    /* Tables - Horizontal scroll with indicators */
    .table-responsive,
    .soft-table-wrapper,
    .data-table-wrapper {
        position: relative;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
        scrollbar-width: thin;
        scrollbar-color: #cbd5e1 transparent;
    }

    /* Scroll shadow indicators */
    .table-responsive::before,
    .soft-table-wrapper::before,
    .data-table-wrapper::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
        opacity: 0;
        transition: opacity 0.2s;
    }

    .table-responsive::after,
    .soft-table-wrapper::after,
    .data-table-wrapper::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to left, rgba(255,255,255,0.9), transparent);
        pointer-events: none;
        z-index: 1;
    }

    .soft-table,
    .data-table {
        min-width: 600px;
        border-collapse: separate;
        border-spacing: 0;
    }

    .soft-table th,
    .soft-table td,
    .data-table th,
    .data-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    /* Sticky first column for important data */
    .table-sticky-first .soft-table th:first-child,
    .table-sticky-first .soft-table td:first-child,
    .table-sticky-first .data-table th:first-child,
    .table-sticky-first .data-table td:first-child {
        position: sticky;
        left: 0;
        background: white;
        z-index: 2;
        box-shadow: 2px 0 4px rgba(0,0,0,0.05);
    }

    .table-sticky-first .soft-table th:first-child,
    .table-sticky-first .data-table th:first-child {
        background: #f8fafc;
    }

    /* Table actions column - compact */
    .soft-table .actions-cell,
    .data-table .actions-cell {
        display: flex;
        gap: 0.25rem;
    }

    .soft-table .actions-cell .icon-btn-soft,
    .data-table .actions-cell .icon-btn-soft {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    /* Mobile Card View for tables (optional class) */
    .table-as-cards .soft-table,
    .table-as-cards .data-table,
    .table-as-cards.premium-table,
    .table-as-cards .premium-table {
        min-width: 0 !important;
    }

    .table-as-cards .soft-table thead,
    .table-as-cards .data-table thead,
    .table-as-cards.premium-table thead,
    .table-as-cards .premium-table thead {
        display: none !important;
    }

    .table-as-cards .soft-table tbody,
    .table-as-cards .data-table tbody,
    .table-as-cards.premium-table tbody,
    .table-as-cards .premium-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .table-as-cards .soft-table tr,
    .table-as-cards .data-table tr,
    .table-as-cards.premium-table tr,
    .table-as-cards .premium-table tr {
        display: flex !important;
        flex-direction: column !important;
        background: white !important;
        border-radius: 16px !important;
        padding: 1.25rem !important;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05) !important;
        border: 1px solid #f1f5f9 !important;
        margin-bottom: 0.5rem !important;
    }

    .table-as-cards .soft-table td,
    .table-as-cards .data-table td,
    .table-as-cards.premium-table td,
    .table-as-cards .premium-table td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.75rem 0 !important;
        border-bottom: 1px solid #f8fafc !important;
        white-space: normal !important;
        text-align: right !important;
        width: 100% !important;
    }

    .table-as-cards .soft-table td:last-child,
    .table-as-cards .data-table td:last-child,
    .table-as-cards.premium-table td:last-child,
    .table-as-cards .premium-table td:last-child {
        border-bottom: none !important;
        margin-top: 0.5rem !important;
        padding-top: 1rem !important;
    }

    .table-as-cards .soft-table td::before,
    .table-as-cards .data-table td::before,
    .table-as-cards.premium-table td::before,
    .table-as-cards .premium-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.75rem;
        color: #64748b;
        text-transform: uppercase;
    }

    /* Icon buttons in mobile tables */
    .icon-btn-soft {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 1rem;
    }

    /* Buttons */
    .action-btn-pill {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    .action-btn-pill.small {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    .btn-pill {
        padding: 0.6rem 1.2rem;
        font-size: 0.85rem;
    }

    /* Forms */
    .form-control {
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
        height: 44px;
    }

    .form-group {
        margin-bottom: 1rem;
    }

    .form-row,
    .filter-grid {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-grid .col {
        width: 100%;
        min-width: 0;
    }

    /* Filter Pills */
    .filter-pills-row {
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }

    .filter-pill {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
    }

    /* Empty States */
    .empty-state-card {
        padding: 2rem 1rem;
    }

    .empty-icon-bubble {
        width: 60px;
        height: 60px;
        font-size: 1.8rem;
    }

    /* Modals & Dropdowns */
    .notification-dropdown,
    .profile-dropdown,
    .residence-dropdown {
        position: fixed !important;
        top: auto !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 80vh;
    }

    /* Invoice Print - hide on mobile */
    @media print {
        .sidebar, .topbar-layout, .mobile-menu-toggle {
            display: none !important;
        }
    }
}

/* ========================================
   5. TABLET (641px - 1024px)
   ======================================== */
@media (min-width: 641px) and (max-width: 1024px) {
    .dashboard-layout {
        display: flex !important;
        flex-direction: row !important;
        padding: 1rem;
        gap: 1rem;
    }

    /* Sidebar - Compact rail - VISIBLE on tablet */
    .sidebar {
        display: flex !important;
        position: sticky !important;
        top: 1rem;
        left: auto !important;
        width: 70px !important;
        height: calc(100vh - 2rem);
        padding: 1rem 0.5rem;
        transform: none !important;
        flex-shrink: 0 !important;
        background: var(--bg-surface, #ffffff);
        border-radius: var(--radius-pill, 100px);
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Hide mobile elements on tablet */
    .mobile-menu-toggle {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }

    /* Main content takes remaining space */
    .main-content {
        flex: 1;
        min-width: 0;
    }

    .sidebar .nav-item {
        width: 44px;
        height: 44px;
    }

    .logo-bubble {
        width: 42px;
        height: 42px;
        font-size: 1.2rem;
    }

    /* Topbar */
    .topbar-layout {
        grid-template-columns: 1fr auto;
        gap: 0.75rem;
    }

    .top-nav {
        grid-column: 1 / -1;
        order: 2;
    }

    .header-actions {
        grid-column: 2;
        order: 1;
    }

    .search-pill {
        width: 180px;
    }

    /* Grids */
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .rooms-grid-soft,
    .residences-grid-soft {
        grid-template-columns: repeat(2, 1fr);
    }

    .reports-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Cards */
    .clay-card {
        padding: 1.5rem;
    }

    /* Tables */
    .soft-table th,
    .soft-table td {
        padding: 1rem 0.75rem;
    }
}

/* ========================================
   6. DESKTOP (1025px+)
   ======================================== */
@media (min-width: 1025px) {
    .dashboard-layout {
        display: flex !important;
        flex-direction: row !important;
        padding: 1.5rem;
        gap: 2rem;
    }

    /* Full sidebar visible - EXPLICIT desktop styles */
    .sidebar {
        display: flex !important;
        position: sticky !important;
        top: 1.5rem;
        left: auto !important;
        width: var(--sidebar-width, 80px) !important;
        height: calc(100vh - 3rem);
        transform: none !important;
        flex-shrink: 0 !important;
        background: var(--bg-surface, #ffffff);
        border-radius: var(--radius-pill, 100px);
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Main content takes remaining space */
    .main-content {
        flex: 1;
        min-width: 0;
    }

    /* Full topbar */
    .topbar-layout {
        grid-template-columns: 1fr auto 1fr;
    }

    /* Stats row - 3 or 4 columns */
    .stats-row {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    /* Hide mobile elements on desktop */
    .mobile-menu-toggle {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ========================================
   7. UTILITY RESPONSIVE CLASSES
   ======================================== */

/* Hide/Show by breakpoint */
.hide-mobile {
    display: block;
}
.show-mobile {
    display: none;
}

@media (max-width: 640px) {
    .hide-mobile {
        display: none !important;
    }
    .show-mobile {
        display: block !important;
    }
}

.hide-tablet {
    display: block;
}
.show-tablet {
    display: none;
}

@media (min-width: 641px) and (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
    .show-tablet {
        display: block !important;
    }
}

/* Stack on mobile */
.stack-mobile {
    display: flex;
    gap: 1rem;
}

@media (max-width: 640px) {
    .stack-mobile {
        flex-direction: column;
    }
}

/* Full width on mobile */
.full-mobile {
    width: auto;
}

@media (max-width: 640px) {
    .full-mobile {
        width: 100% !important;
    }
}

/* Text alignment on mobile */
@media (max-width: 640px) {
    .text-center-mobile {
        text-align: center !important;
    }
}

/* ========================================
   8. TOUCH OPTIMIZATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .nav-item,
    .icon-btn-soft,
    .circle-btn,
    .filter-pill {
        min-width: 44px;
        min-height: 44px;
    }

    /* Remove hover effects on touch */
    .room-card-soft:hover,
    .stat-bubble-card:hover,
    .clay-card:hover {
        transform: none;
    }

    /* SIDEBAR NAV ITEMS - Fix hover/active on touch */
    .sidebar .nav-item {
        transform: none !important;
        transition: background 0.15s ease;
    }

    .sidebar .nav-item:hover {
        transform: none !important;
        background: rgba(99, 102, 241, 0.08);
    }

    .sidebar .nav-item:active {
        background: rgba(99, 102, 241, 0.15) !important;
        transform: scale(0.98) !important;
    }

    .sidebar .nav-item.active {
        background: linear-gradient(135deg, #eef2ff, #e0e7ff) !important;
        color: var(--primary) !important;
    }

    .sidebar .nav-item.active .nav-label {
        color: var(--primary);
        font-weight: 600;
    }

    /* Ensure text is always readable */
    .sidebar .nav-item .nav-label {
        color: inherit;
        opacity: 1;
    }

    /* Tap highlight */
    a, button {
        -webkit-tap-highlight-color: rgba(99, 102, 241, 0.1);
    }
}

/* ========================================
   9. SAFE AREAS (Notch/Home indicator)
   ======================================== */
@supports (padding: max(0px)) {
    .dashboard-layout {
        padding-left: max(0.75rem, env(safe-area-inset-left));
        padding-right: max(0.75rem, env(safe-area-inset-right));
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }

    .mobile-menu-toggle {
        bottom: max(1.5rem, calc(env(safe-area-inset-bottom) + 0.5rem));
        right: max(1.5rem, env(safe-area-inset-right));
    }

    .sidebar {
        padding-bottom: max(2rem, calc(env(safe-area-inset-bottom) + 1rem));
    }
}

/* ========================================
   10. INLINE GRID OVERRIDES (Page-specific responsive)
   ======================================== */
@media (max-width: 768px) {

    /* ── CATCH-ALL : toute grille inline → 1 colonne ── */
    /* Couvre toutes les variantes d'espacement sans lister chaque pattern */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 0.85rem !important;
    }

    /* Inputs / selects / textareas : pleine largeur + iOS zoom fix */
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="file"]):not([type="color"]),
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important;
    }

    /* Bouton submit pleine largeur dans les formulaires */
    button[type="submit"],
    input[type="submit"] {
        width: 100% !important;
        justify-content: center !important;
    }
    /* Sauf si dans une barre d'actions compacte */
    .premium-actions button[type="submit"],
    .header-actions button[type="submit"] {
        width: auto !important;
    }

    /* Sticky → static pour libérer le layout */
    [style*="position:sticky"],
    [style*="position: sticky"] {
        position: static !important;
        top: auto !important;
    }

    /* Flex containers wrap sur mobile */
    .checkbox-card,
    .ic-checkbox-card,
    [class*="checkbox-card"] {
        flex-wrap: wrap !important;
        min-width: 0 !important;
    }

    /* Div enfant flex : ne déborde pas */
    .checkbox-card > div,
    .ic-checkbox-card > div,
    [class*="checkbox-card"] > div {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }

    /* Collapse all common inline 2-col grid patterns */
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 2fr 1fr"],
    [style*="grid-template-columns:2fr 1fr"],
    [style*="grid-template-columns: 1fr 2fr"],
    [style*="grid-template-columns:1fr 2fr"],
    [style*="grid-template-columns: 3fr 1fr"],
    [style*="grid-template-columns:3fr 1fr"],
    [style*="grid-template-columns: 1fr 3fr"],
    [style*="grid-template-columns:1fr 3fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Collapse 3-col inline grids */
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr 1fr"],
    [style*="grid-template-columns: repeat(2,"],
    [style*="grid-template-columns: repeat(3,"],
    [style*="grid-template-columns: repeat(4,"],
    [style*="grid-template-columns: repeat(2, 1fr)"],
    [style*="grid-template-columns: repeat(3, 1fr)"],
    [style*="grid-template-columns: repeat(4, 1fr)"] {
        grid-template-columns: 1fr !important;
    }

    /* display:inline-grid → block sur mobile */
    [style*="display: inline-grid"],
    [style*="display:inline-grid"] {
        display: block !important;
    }

    /* min-width fixes élevées qui cassent le layout mobile */
    [style*="min-width: 400px"],
    [style*="min-width:400px"],
    [style*="min-width: 450px"],
    [style*="min-width:450px"],
    [style*="min-width: 500px"],
    [style*="min-width:500px"],
    [style*="min-width: 550px"],
    [style*="min-width:550px"],
    [style*="min-width: 600px"],
    [style*="min-width:600px"] {
        min-width: 0 !important;
        width: 100% !important;
    }

    /* Large minmax values that overflow mobile viewport */
    [style*="minmax(350px"],
    [style*="minmax(360px"],
    [style*="minmax(380px"],
    [style*="minmax(400px"],
    [style*="minmax(420px"],
    [style*="minmax(450px"],
    [style*="minmax(500px"] {
        grid-template-columns: 1fr !important;
    }

    /* Fixed-pixel column grids (sidebar-style layouts) */
    [style*="grid-template-columns: 320px"],
    [style*="grid-template-columns:320px"],
    [style*="grid-template-columns: 350px"],
    [style*="grid-template-columns:350px"],
    [style*="grid-template-columns: 300px"],
    [style*="grid-template-columns:300px"],
    [style*="grid-template-columns: 280px"],
    [style*="grid-template-columns:280px"],
    [style*="grid-template-columns: 1fr 400px"],
    [style*="grid-template-columns:1fr 400px"],
    [style*="grid-template-columns: 1fr 350px"],
    [style*="grid-template-columns:1fr 350px"],
    [style*="grid-template-columns: 1fr 380px"],
    [style*="grid-template-columns:1fr 380px"],
    [style*="grid-template-columns: 1fr 300px"],
    [style*="grid-template-columns:1fr 300px"],
    [style*="grid-template-columns: 1fr 340px"],
    [style*="grid-template-columns:1fr 340px"],
    [style*="grid-template-columns: 1fr 360px"],
    [style*="grid-template-columns:1fr 360px"] {
        grid-template-columns: 1fr !important;
    }

    /* Reset grid-column spans that break single-col layout */
    [style*="grid-column: span 2"],
    [style*="grid-column:span 2"],
    [style*="grid-column: 1 / span 2"],
    [style*="grid-column: span 1 / span 2"],
    [style*="grid-column: 1/span 2"] {
        grid-column: 1 !important;
    }

    /* Flex row → column for common layout patterns */
    [style*="display: flex"][style*="justify-content: space-between"],
    [style*="display:flex"][style*="justify-content:space-between"] {
        flex-wrap: wrap !important;
        gap: 0.75rem !important;
    }

    /* Large font sizes → smaller on mobile */
    [style*="font-size: 2"],
    [style*="font-size:2"],
    [style*="font-size: 3"],
    [style*="font-size:3"] {
        font-size: 1.25rem !important;
    }

    /* Page header flex containers */
    .page-header-flex,
    .d-flex.justify-content-between.align-items-center {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    /* Glass panels and cards — full width, less padding */
    .glass-panel,
    .glass-panel-sm,
    .glass-card {
        padding: 1rem !important;
    }

    /* Stats grid override */
    .stats-grid,
    .stats-grid-2,
    .stats-grid-3,
    .stats-grid-4 {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.75rem !important;
    }

    /* Action buttons row → column */
    .action-buttons-row,
    .btn-group-actions {
        flex-direction: column !important;
        width: 100% !important;
    }
    .action-buttons-row .btn,
    .btn-group-actions .btn {
        width: 100% !important;
    }

    /* Tables: horizontal scroll */
    .table-responsive-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Form rows → single column */
    .form-row-2col {
        grid-template-columns: 1fr !important;
    }
    .form-row-2col .span-2 {
        grid-column: 1 !important;
    }

    /* Amount display */
    .amount-huge,
    .amount-display-large {
        font-size: 2rem !important;
    }

    /* Totals card */
    .totals-card {
        padding: 1rem !important;
    }
    .totals-card .total-line {
        flex-wrap: wrap !important;
    }

    /* Action card premium */
    .action-card-premium .action-buttons {
        flex-direction: column !important;
    }
    .action-card-premium .action-buttons .btn {
        width: 100% !important;
    }

    /* Residence cards stats grid */
    .residence-stats-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 0.5rem !important;
        padding: 1rem !important;
    }

    /* Badge/tag overflow */
    .badge-list,
    .tag-list {
        flex-wrap: wrap !important;
    }

    /* Modal dialogs */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
    }

    /* Print/invoice specific */
    .invoice-header-grid {
        grid-template-columns: 1fr !important;
    }
    .invoice-amounts-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    /* Tous les form-groups empilés */
    .form-group,
    .form-group-inline {
        width: 100% !important;
        min-width: 0 !important;
    }

    /* Labels lisibles */
    label, .form-label, .form-label-premium {
        font-size: 0.85rem !important;
        margin-bottom: 0.35rem !important;
    }

    /* Textareas : resize vertical seulement */
    textarea { resize: vertical !important; }

    /* Extra small: single col stats */
    .stats-grid,
    .stats-grid-2,
    .stats-grid-3,
    .stats-grid-4 {
        grid-template-columns: 1fr !important;
    }

    /* Shrink buttons further */
    .btn {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.75rem !important;
    }

    /* Cards — minimal padding */
    .card,
    .glass-panel {
        padding: 0.75rem !important;
    }
}

/* ========================================
   11. ANIMATIONS (Reduced motion)
   ======================================== */
/* ========================================
   12. CUSTOM SELECT COMPONENT (mobile)
   ======================================== */
@media (max-width: 900px) {

    /* wrapper inline-block pour que le trigger prenne la place du select */
    .cs-wrapper {
        position: relative;
        width: 100%;
        display: block;
    }

    /* trigger : ressemble au form-control natif */
    .cs-trigger {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 0.5rem;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .cs-val {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.9rem;
    }

    .cs-arrow {
        flex-shrink: 0;
        width: 16px;
        height: 16px;
        color: var(--text-secondary, #64748b);
        transition: transform 0.2s;
    }

    /* panel flottant — rattaché au <body> via JS → jamais découpé.
       Structure interne : .cs-search (sticky top, padding) + .cs-list (scroll) */
    .cs-panel {
        position: fixed !important;
        z-index: 99999;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.10);
        border: 1px solid #e2e8f0;
        overscroll-behavior: contain;
        overflow: hidden; /* le scroll est sur .cs-list interne */
        /* display:none par défaut, JS bascule sur 'flex' quand ouvert */
    }
    .cs-panel .cs-list {
        flex: 1 1 auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .cs-item {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
        color: var(--text-main, #1e293b);
        cursor: pointer;
        border-bottom: 1px solid #f1f5f9;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cs-item:last-child { border-bottom: none; }

    .cs-item:hover,
    .cs-item:active { background: #f0f4ff; }

    .cs-item.cs-item-active {
        background: #eef2ff;
        font-weight: 600;
        color: var(--primary, #4f46e5);
    }
}

/* ========================================
   14. MOBILE OVERRIDES — Styles inline récalcitrants
   ======================================== */
@media (max-width: 640px) {
    /* Titres avec font-size inline — force une taille lisible sur mobile.
       Couvre h1/h2/h3 même sans classe .gradient-text/.page-title */
    h1[style*="font-size"],
    h1.gradient-text,
    h1.page-title {
        font-size: 1.5rem !important;
        line-height: 1.25 !important;
    }

    h2[style*="font-size"],
    h2.gradient-text {
        font-size: 1.25rem !important;
        line-height: 1.3 !important;
    }

    h3[style*="font-size"],
    h3.gradient-text {
        font-size: 1.1rem !important;
        line-height: 1.3 !important;
    }

    /* Grids inline avec colonnes fixes (ex: 1fr 400px, 2fr 1fr) — forcer 1 colonne */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Filtres en flex horizontal avec min-width par enfant — forcer colonne pleine largeur */
    form[style*="display: flex"] > div[style*="min-width"],
    form[style*="display:flex"]  > div[style*="min-width"] {
        min-width: 100% !important;
        flex: 1 1 100% !important;
    }

    /* Padding excessif inline sur cartes */
    .clay-card[style*="padding: 2.5rem"],
    .clay-card[style*="padding:2.5rem"],
    .glass-panel[style*="padding: 2.5rem"],
    .glass-panel[style*="padding:2.5rem"] {
        padding: 1rem !important;
    }

    /* Max-width inline sur conteneurs — éviter qu'elles restent étroites ou débordent */
    .clay-card[style*="max-width"],
    .glass-panel[style*="max-width"],
    .settings-wrapper[style*="max-width"],
    div[style*="max-width: 800px"],
    div[style*="max-width:800px"],
    div[style*="max-width: 900px"],
    div[style*="max-width:900px"],
    div[style*="max-width: 1000px"],
    div[style*="max-width:1000px"] {
        max-width: 100% !important;
    }

    /* Modals custom avec max-width fixe inline */
    [class*="modal-"][style*="max-width"],
    div[style*="max-width: 420px"][style*="border-radius"],
    div[style*="max-width:420px"][style*="border-radius"],
    div[style*="max-width: 440px"][style*="border-radius"],
    div[style*="max-width:440px"][style*="border-radius"],
    div[style*="max-width: 480px"][style*="border-radius"],
    div[style*="max-width:480px"][style*="border-radius"],
    div[style*="max-width: 500px"][style*="border-radius"],
    div[style*="max-width:500px"][style*="border-radius"],
    div[style*="max-width: 600px"][style*="border-radius"],
    div[style*="max-width:600px"][style*="border-radius"] {
        max-width: calc(100vw - 1.5rem) !important;
        width: calc(100vw - 1.5rem) !important;
    }

    /* Padding excessif inline sur empty states / cartes (4rem, 5rem) */
    [style*="padding: 4rem"],
    [style*="padding:4rem"],
    [style*="padding: 5rem"],
    [style*="padding:5rem"],
    [style*="padding: 3rem"],
    [style*="padding:3rem"] {
        padding: 2rem 1rem !important;
    }

    /* Export sections avec flex justify-content:space-between — wrap */
    .export-item-premium {
        flex-wrap: wrap;
        gap: 0.75rem !important;
    }

    /* Search pill étroit qui prend toute la largeur */
    [style*="max-width: 300px"][style*="flex"],
    [style*="max-width:300px"][style*="flex"] {
        max-width: 100% !important;
    }

    /* Page header flex → colonne (défensif) */
    .page-header-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
    }

    .premium-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .premium-actions > * {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* Réduire typographie très petite (illisible) */
    [style*="font-size:0.65rem"],
    [style*="font-size: 0.65rem"] {
        font-size: 0.75rem !important;
    }

    /* ====================================================
       FORMULAIRES & CHAMPS — fixes mobile complets
       ==================================================== */

    /* Inputs/selects/textareas: width 100% + box-sizing safe */
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="file"]):not([type="color"]),
    select,
    textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        font-size: 16px !important; /* Évite le zoom auto iOS sur focus */
    }

    /* Hauteur tactile minimale (Apple recommande 44px, Google 48px) */
    input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="color"]),
    select,
    .form-control,
    .input-premium,
    .search-input-glass {
        min-height: 44px !important;
    }

    /* Icônes absolues à droite : décaler pour ne pas chevaucher le texte */
    div[style*="position: relative"] > ion-icon[style*="right:"],
    div[style*="position:relative"] > ion-icon[style*="right:"] {
        right: 0.6rem !important;
        font-size: 1.1rem !important;
    }

    /* Inputs avec padding-right (pour faire de la place à une icon droite) */
    input[style*="padding-right: 2.5rem"],
    input[style*="padding-right:2.5rem"],
    select[style*="padding-right: 2.5rem"],
    select[style*="padding-right:2.5rem"] {
        padding-right: 2.75rem !important;
    }

    /* Auto-fit grids avec minmax trop grand → 1 colonne */
    [style*="repeat(auto-fit, minmax(2"],
    [style*="repeat(auto-fit,minmax(2"],
    [style*="repeat(auto-fill, minmax(2"],
    [style*="repeat(auto-fill,minmax(2"],
    [style*="repeat(auto-fit, minmax(3"],
    [style*="repeat(auto-fit,minmax(3"],
    [style*="repeat(auto-fill, minmax(3"],
    [style*="repeat(auto-fill,minmax(3"],
    [style*="repeat(auto-fit, minmax(4"],
    [style*="repeat(auto-fit,minmax(4"],
    [style*="repeat(auto-fill, minmax(4"],
    [style*="repeat(auto-fill,minmax(4"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Sticky panels (récap, sidebar) → static sur mobile pour libérer la largeur */
    [style*="position:sticky"],
    [style*="position: sticky"] {
        position: static !important;
        top: auto !important;
    }

    /* Textarea : pas de resize horizontal qui dépasse l'écran */
    textarea,
    textarea[style*="resize"] {
        resize: vertical !important;
        max-height: 60vh !important;
    }

    /* Color picker wrapper en colonne sur mobile */
    .color-picker-wrapper {
        flex-direction: column !important;
        gap: 0.5rem !important;
        align-items: stretch !important;
    }

    /* Filters form : les form-group passent en pleine largeur */
    .filters-form,
    form.filters-form {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .filters-form .form-group,
    .filters-form .form-row {
        width: 100% !important;
        flex: 1 1 100% !important;
    }

    .filters-form .form-group[style*="align-self"] {
        align-self: stretch !important;
    }

    .filters-form button,
    .filters-form .btn-premium {
        width: 100% !important;
    }

    /* Form-row inline : passe en colonne */
    .form-row {
        flex-direction: column !important;
        gap: 0.75rem !important;
    }

    .form-row > .form-group,
    .form-row > * {
        width: 100% !important;
        flex: 1 1 100% !important;
    }

    /* Input de type number : assez large pour les spinners natifs */
    input[type="number"] {
        min-width: 80px !important;
    }

    /* Search input avec bouton overlaid : padding-right large */
    .search-input-premium,
    input.search-input-premium {
        padding-right: 110px !important;
    }

    /* Boutons à l'intérieur d'un form en position absolue : compacts mobile */
    form button[style*="position: absolute"],
    form button[style*="position:absolute"] {
        font-size: 0.85rem !important;
        padding: 0.5rem 0.75rem !important;
        right: 0.4rem !important;
    }

    /* Tabs scroll horizontal : ne casse pas le layout */
    .tabs-scroll-container,
    .nav-tabs,
    [class*="-tabs"] {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none;
    }

    .tabs-scroll-container::-webkit-scrollbar,
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    /* Form group : marge verticale uniforme */
    .form-group {
        margin-bottom: 1rem;
    }

    /* Labels lisibles sur petit écran */
    label,
    .form-label,
    .form-label-premium {
        font-size: 0.9rem !important;
        margin-bottom: 0.4rem !important;
        display: block;
    }

    /* Petites labels inline forcées trop petites */
    label[style*="font-size:0.75rem"],
    label[style*="font-size: 0.75rem"],
    .form-label-premium[style*="font-size:0.75rem"],
    .form-label-premium[style*="font-size: 0.75rem"] {
        font-size: 0.85rem !important;
    }

    /* Date / time / datetime-local : padding suffisant pour l'icon native */
    input[type="date"],
    input[type="time"],
    input[type="datetime-local"],
    input[type="month"] {
        padding-left: 0.85rem !important;
    }

    /* Custom select panel (custom-select.js) en bottom sheet sur mobile */
    .cs-panel {
        max-width: calc(100vw - 1rem) !important;
        max-height: 60vh !important;
    }

    /* Checkbox / radio : taille tactile correcte */
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 18px !important;
        min-height: 18px !important;
    }

    /* Bouton Submit dans un form : pleine largeur sur mobile */
    button[type="submit"],
    input[type="submit"] {
        width: 100% !important;
        margin-top: 0.5rem;
    }

    /* Exception : boutons inline dans une barre d'actions reste auto */
    .premium-actions button[type="submit"],
    .header-actions button[type="submit"],
    [class*="action-bar"] button[type="submit"],
    div[style*="display:flex"] > button[type="submit"],
    div[style*="display: flex"] > button[type="submit"] {
        width: auto !important;
    }
}

/* ========================================
   15. TRÈS PETIT MOBILE (max-width: 480px)
   ======================================== */
@media (max-width: 480px) {
    /* Padding 2.5rem inline → 1rem */
    [style*="padding: 2.5rem"],
    [style*="padding:2.5rem"] {
        padding: 1rem !important;
    }

    /* Padding-left 2.5rem (pour icon gauche) → 2.25rem (icon plus près du bord) */
    input[style*="padding-left: 2.5rem"],
    input[style*="padding-left:2.5rem"],
    select[style*="padding-left: 2.5rem"],
    select[style*="padding-left:2.5rem"] {
        padding-left: 2.25rem !important;
    }

    div[style*="position: relative"] > ion-icon[style*="left:"],
    div[style*="position:relative"] > ion-icon[style*="left:"] {
        left: 0.6rem !important;
        font-size: 1.1rem !important;
    }

    /* Réduire encore les titres */
    h1[style*="font-size"],
    h1.gradient-text,
    h1.page-title {
        font-size: 1.35rem !important;
    }

    /* Container fluid : padding minimal */
    .container-fluid,
    .premium-container {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* Tablette : garder le grid 1fr 400px mais éviter débordement sur largeur moyenne */
@media (min-width: 641px) and (max-width: 1024px) {
    [style*="grid-template-columns: 1fr 400px"],
    [style*="grid-template-columns:1fr 400px"] {
        grid-template-columns: 1fr !important;
        gap: 1.5rem !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   11. STAYS sub-pages — Mobile aggressive overrides
   Le user signalait que les sous-pages stays (extend, transfer, release,
   confirm, cancel, expiring, expired, unpaid, reservations, transfers)
   gardaient un padding desktop énorme (2.5rem) en mobile.
   ======================================== */
@media (max-width: 768px) {
    /* Conteneurs glass-panel inline padding 2-3rem → 1.25rem */
    .glass-panel[style*="padding: 2.5rem"],
    .glass-panel[style*="padding:2.5rem"],
    .glass-panel[style*="padding: 3rem"],
    .glass-panel[style*="padding:3rem"],
    .glass-panel[style*="padding: 2rem"],
    .glass-panel[style*="padding:2rem"] {
        padding: 1.25rem !important;
        border-radius: 18px !important;
    }

    /* Cartes claire avec padding desktop */
    .clay-panel[style*="padding: 2.5rem"],
    .clay-panel[style*="padding:2.5rem"],
    .clay-panel[style*="padding: 2rem"],
    .clay-panel[style*="padding:2rem"] {
        padding: 1.25rem !important;
        border-radius: 18px !important;
    }

    /* card-v2 avec padding inline desktop */
    .card-v2[style*="padding: 2rem"],
    .card-v2[style*="padding:2rem"],
    .card-v2[style*="padding: 2.5rem"],
    .card-v2[style*="padding:2.5rem"] {
        padding: 1.25rem !important;
    }

    /* Hero sections avec padding désordonné */
    [style*="padding: 2.5rem"][class*="preview-card"],
    [style*="padding: 2rem"][class*="preview-box"] {
        padding: 1.5rem !important;
    }

    /* Boîtes de prévisualisation/résumé large → réduire */
    .preview-box,
    .preview-card-glow {
        padding: 1.5rem !important;
        margin-bottom: 1.5rem !important;
    }

    /* Containers principaux qui gardaient padding 2rem 0 */
    .premium-container[style*="padding: 2rem"] {
        padding: 1rem 0 !important;
    }

    /* Headers de page : titre h2/h3 trop grand */
    .glass-panel h2[style*="font-size: 2rem"],
    .glass-panel h2[style*="font-size:2rem"] {
        font-size: 1.4rem !important;
    }
    .glass-panel h2[style*="font-size: 2.5rem"],
    .glass-panel h2[style*="font-size:2.5rem"] {
        font-size: 1.6rem !important;
    }

    /* Icônes décoratives 70px+ trop grosses sur mobile */
    [style*="width: 70px"][style*="height: 70px"],
    [style*="width:70px"][style*="height:70px"],
    [style*="width: 80px"][style*="height: 80px"],
    [style*="width:80px"][style*="height:80px"] {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.5rem !important;
    }

    /* Boutons en pleine largeur dans formulaires modaux/centrés */
    .glass-panel button[type="submit"],
    .glass-panel .btn-premium[type="submit"] {
        width: 100% !important;
        justify-content: center !important;
    }

    /* gap réduit pour les grilles internes */
    [style*="gap: 1.5rem"][style*="grid-template-columns"] {
        gap: 1rem !important;
    }
    [style*="gap: 2rem"][style*="grid-template-columns"] {
        gap: 1rem !important;
    }
}

@media (max-width: 480px) {
    .glass-panel,
    .clay-panel,
    .card-v2 {
        padding: 1rem !important;
        border-radius: 14px !important;
    }
    .premium-container {
        padding: 0.5rem 0.5rem 2rem !important;
    }
    /* Icônes décoratives encore plus petites */
    [style*="width: 70px"][style*="height: 70px"],
    [style*="width: 80px"][style*="height: 80px"] {
        width: 42px !important;
        height: 42px !important;
        font-size: 1.2rem !important;
    }
}

/* ================================================================
   MOBILE-FIRST FORMS — correctifs globaux formulaires
   S'applique sur tous les appareils ≤ 768px
   Ne modifie aucun fichier PHP — tout passe par ce CSS global
   ================================================================ */

/* ── 1. INPUTS & SELECTS : taille tactile correcte ───────────────
   Apple recommande 44px, Google 48px.
   font-size 16px = évite le zoom automatique iOS au focus.
   ----------------------------------------------------------------- */
@media (max-width: 768px) {

    /* Inputs et textareas : hauteur min tactile */
    input.input-premium,
    textarea.input-premium,
    input.form-control,
    textarea.form-control,
    .input-premium:not(select),
    .form-control:not(select) {
        min-height: 48px !important;
        font-size: 16px !important;
        padding: 0.75rem 1rem !important;
        border-radius: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Selects : hauteur FIXE 48px */
    select.input-premium,
    select.form-control {
        height: 48px !important;
        font-size: 16px !important;
        padding: 0 2.5rem 0 1rem !important;
        border-radius: 10px !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Inputs avec icône à gauche : garder le padding-left */
    .input-premium[style*="padding-left"],
    .form-control[style*="padding-left"] {
        padding-left: 2.5rem !important;
    }

    /* Textarea : pas de min-height fixe, mais raisonnable */
    textarea.input-premium,
    textarea.form-control {
        min-height: 80px !important;
    }

    /* ── 2. SELECT : conserver le style custom (même look que la recherche client) ──
       On NE force PAS le picker natif OS (trop intrusif plein écran).
       Le select reste compact et inline, stylisé comme les autres champs.
       ----------------------------------------------------------------- */
    select,
    select.input-premium,
    select.form-control {
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        appearance: none !important;
        cursor: pointer;
        padding-right: 2.5rem !important;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
        background-repeat: no-repeat !important;
        background-position: right 0.9rem center !important;
        background-size: 1.1em !important;
    }

    /* ── 3. LABELS ───────────────────────────────────────────────── */
    .form-label-premium,
    .form-label,
    label.form-label-premium {
        font-size: 0.82rem !important;
        font-weight: 700 !important;
        margin-bottom: 0.4rem !important;
        display: block !important;
    }

    /* ── 4. CHECKBOXES & RADIOS : zone de tap suffisante ─────────
       Minimum 24px pour les deux — zone cliquable agrandie via padding.
       ------------------------------------------------------------ */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
        min-height: 20px !important;
        cursor: pointer;
        flex-shrink: 0 !important;
        accent-color: #3b82f6;
    }

    /* ── 5. GRILLES 2 colonnes → 1 colonne sur mobile ────────────
       Cible les grilles inline (auto-fit / minmax) et les classes
       personnalisées. Garanti sans débordement.
       ------------------------------------------------------------ */
    [style*="grid-template-columns: repeat(auto-fit"],
    [style*="grid-template-columns:repeat(auto-fit"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr 1fr"],
    .ic-grid-2,
    .loc-grid {
        grid-template-columns: 1fr !important;
        gap: 0.85rem !important;
    }

    /* Exception : les grilles dans la topbar restent flexibles */
    .topbar-layout [style*="grid-template-columns"] {
        grid-template-columns: unset !important;
    }

    /* ── 6. BOUTONS de formulaire ────────────────────────────────── */
    .btn-premium {
        min-height: 48px !important;
        font-size: 0.92rem !important;
        padding: 0.75rem 1.25rem !important;
        justify-content: center !important;
    }

    /* Bouton submit principal → pleine largeur */
    form button[type="submit"]:not(.inline-btn),
    form input[type="submit"] {
        width: 100% !important;
        margin-top: 0.5rem !important;
    }

    /* ── 7. GLASS PANEL dans les formulaires ─────────────────────── */
    form .glass-panel,
    .glass-panel form {
        padding: 1.1rem !important;
    }

    /* ── 8. ESPACEMENTS formulaire ───────────────────────────────── */
    .form-group,
    .ic-form-group {
        margin-bottom: 1rem !important;
    }

    /* Réduire les marges des titres de section dans les formulaires */
    form h3,
    .glass-panel h3 {
        font-size: 0.95rem !important;
        margin-bottom: 1rem !important;
    }

    /* ── 9. ICÔNES décoratives dans les labels ────────────────────── */
    form .glass-panel > div:first-child > div[style*="width: 50px"],
    form .glass-panel > div:first-child > div[style*="width: 54px"],
    form .glass-panel > div:first-child > div[style*="width:50px"],
    form .glass-panel > div:first-child > div[style*="width:54px"] {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.2rem !important;
        flex-shrink: 0 !important;
    }

    /* ── 10. PREMIUM-ACTIONS en bas de formulaire ─────────────────── */
    .page-header-flex .premium-actions {
        width: 100% !important;
    }

    .page-header-flex .premium-actions a,
    .page-header-flex .premium-actions button {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* ── Petits mobiles (≤ 380px) : réduction supplémentaire ───────── */
/* ============================================================
   CORRECTIONS UX GLOBALES MOBILE
   ============================================================ */

/* Empty states : padding 5rem trop grand sur mobile */
@media (max-width: 768px) {
    [style*="padding: 5rem"],
    [style*="padding:5rem"] {
        padding: 2rem 1rem !important;
    }
    [style*="padding: 5rem 2rem"],
    [style*="padding:5rem 2rem"] {
        padding: 2rem 1rem !important;
    }

    /* clients/show.php : avatar trop grand */
    [style*="width:90px"][style*="height:90px"],
    [style*="width: 90px"][style*="height: 90px"] {
        width: 60px !important;
        height: 60px !important;
        font-size: 1.5rem !important;
    }

    /* Titres h1 trop grands sur profils */
    [style*="font-size: 2.4rem"],
    [style*="font-size:2.4rem"] {
        font-size: 1.5rem !important;
    }

    /* Icon buttons dans les tables : taille tactile correcte */
    .icon-btn-soft {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
    }
}

@media (max-width: 380px) {
    .input-premium,
    .form-control {
        font-size: 15px !important;
        padding: 0.65rem 0.9rem !important;
    }

    .form-label-premium,
    .form-label {
        font-size: 0.78rem !important;
    }

    .btn-premium {
        font-size: 0.85rem !important;
        padding: 0.7rem 1rem !important;
    }
}
