/* ============================================================
   TABLE-RESPONSIVE.CSS — AssoRock 100%
   ============================================================ */

/* ─── 1. LAYOUT PLEINE PAGE ─────────────────────────────── */
body {
    display: flex;
    min-height: 100vh;
    overflow: hidden;
    height: 100vh;
}

.main-content {
    flex: 1 1 0%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.content-area {
    flex: 1 1 0%;
    overflow-y: auto !important;
    overflow-x: hidden;
    padding: 24px;
    box-sizing: border-box;
    width: 100%;
    height: 0;
}

/* ── MOBILE : scroll naturel sur tout le contenu ── */
@media (max-width: 900px) {
    body {
        height: auto !important;
        min-height: 100svh !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }
    .main-content {
        height: auto !important;
        min-height: 100svh !important;
        overflow: visible !important;
    }
    .content-area {
        height: auto !important;
        overflow: visible !important;
        overflow-y: visible !important;
        padding: 12px !important;
        padding-bottom: 60px !important;
    }
    .content-section,
    .content-section.active {
        height: auto !important;
        overflow: visible !important;
        min-height: auto !important;
    }
    .modal-content {
        -webkit-overflow-scrolling: touch !important;
    }
}

.sidebar { flex-shrink: 0; }

.top-bar { flex-shrink: 0; }


.content-section {
    width: 100%;
    max-width: none !important;
    box-sizing: border-box;
}

/* ─── 2. CONTENEUR SCROLLABLE ────────────────────────────── */
.table-container,
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

/* ─── 3. TABLEAUX ────────────────────────────────────────── */
.data-table {
    width: 100%;
    table-layout: auto;
    border-collapse: collapse;
    font-size: 0.83rem;
    white-space: nowrap;
}

.data-table th,
.data-table td {
    padding: 10px 12px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table th {
    font-size: 0.74rem;
    letter-spacing: .05em;
    white-space: nowrap;
}

.data-table td:has(.email-cell) {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── 4. LARGEURS MINIMALES ─────────────────────────────── */
#tableMembres { min-width: 780px; }
#tableAdhesions { min-width: 700px; }

/* ─── 5. BOUTONS D'ACTION ────────────────────────────────── */
.action-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    min-width: 30px;
    padding: 0;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.05);
    transition: background 0.15s, border-color 0.15s;
    vertical-align: middle;
}

.btn-icon:hover {
    background: rgba(212,175,55,0.18);
    border-color: rgba(212,175,55,0.45);
}
.btn-icon.btn-delete:hover {
    background: rgba(239,68,68,0.18);
    border-color: rgba(239,68,68,0.45);
}
.btn-icon.btn-more {
    font-size: 1.15rem;
    font-weight: bold;
}

/* ─── 6. DROPDOWN ────────────────────────────────────────── */
.dropdown-actions {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 9999;
    min-width: 165px;
    background: var(--black-secondary, #1c1c1c);
    border: 1px solid var(--gold-border, rgba(212,175,55,0.3));
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0,0,0,.65);
    overflow: hidden;
}

.dropdown-menu.active { display: block; }

.dropdown-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    font-size: 0.82rem;
    background: transparent;
    border: none;
    color: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.dropdown-menu button:hover { background: rgba(212,175,55,0.12); }

/* ─── 7. SECTION HEADER ──────────────────────────────────── */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.section-header > div {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

/* ─── 8. FILTRES ─────────────────────────────────────────── */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

.filters input,
.filters select {
    flex: 1 1 130px;
    min-width: 110px;
    max-width: 210px;
    padding: 7px 10px;
    font-size: 0.82rem;
    border-radius: 6px;
    box-sizing: border-box;
}

/* ─── 9. RESPONSIVE ≤ 768px ──────────────────────────────── */
@media (max-width: 768px) {
    .content-area { padding: 14px; }
    .data-table   { font-size: 0.76rem; }
    .data-table th,
    .data-table td { padding: 8px 7px; }

    .section-header         { flex-direction: column; align-items: flex-start; }
    .section-header > div   { width: 100%; }
    .section-header > div .btn-primary,
    .section-header > div .btn-secondary { flex: 1 1 auto; }

    .filters input,
    .filters select { max-width: 100%; flex: 1 1 100%; }
}

/* ─── CONTACTS ─── */
#tableMembres td:nth-child(3) {
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── ADHÉSIONS ─── */
#tableAdhesions {
    table-layout: fixed;
    width: 100%;
    min-width: unset;
}

#tableAdhesions th:nth-child(1),
#tableAdhesions td:nth-child(1) { width: 32px; text-align: center; padding: 9px 4px; }

#tableAdhesions th:nth-child(2),
#tableAdhesions td:nth-child(2) { width: 18%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 0; }

#tableAdhesions th:nth-child(3),
#tableAdhesions td:nth-child(3) { width: 80px; }

#tableAdhesions th:nth-child(4),
#tableAdhesions td:nth-child(4) { width: 90px; }

#tableAdhesions th:nth-child(5),
#tableAdhesions td:nth-child(5) { width: 90px; }

#tableAdhesions th:nth-child(6),
#tableAdhesions td:nth-child(6) { width: 75px; }

#tableAdhesions th:nth-child(7),
#tableAdhesions td:nth-child(7) { width: 70px; text-align: center; }

#tableAdhesions th:nth-child(8),
#tableAdhesions td:nth-child(8) { width: 100px; text-align: center; }

#tableAdhesions th:nth-child(9),
#tableAdhesions td:nth-child(9) { width: 90px; text-align: center; overflow: visible; white-space: nowrap; max-width: none; }

#tableAdhesions th,
#tableAdhesions td { padding: 9px 5px; font-size: 0.79rem; }

/* ─── DONS ─── */
#tableDons {
    table-layout: auto;
    width: 100%;
    min-width: 650px;
}

#tableDons td:last-child {
    overflow: visible;
    white-space: nowrap;
    width: 1%;
}

#tableDons th,
#tableDons td { padding: 9px 8px; }

/* ══════════════════════════════════════════════════════
   TABLETTE (max 992px)
══════════════════════════════════════════════════════ */
@media (max-width: 992px) {

    .sidebar {
        transform: translateX(-100%);
        position: fixed;
        z-index: 1000;
        height: 100vh;
        transition: transform 0.3s ease;
        width: 260px !important;
    }
    .sidebar.active { transform: translateX(0); }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: all;
    }

    .sidebar-toggle-mobile { display: flex !important; }

    #dashMid {
        grid-template-columns: 1fr 1fr !important;
    }
    #dashMid > div:last-child {
        grid-column: 1 / -1;
    }

    #dashKPIs {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ══════════════════════════════════════════════════════
   MOBILE (max 768px)
══════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    .content-area { padding: 12px !important; }

    .top-bar {
        padding: 8px 12px !important;
        gap: 8px;
    }
    .search-bar { display: none; }
    .user-menu .user-name { font-size: 0.75rem; }

    .section-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    .section-header h2 { font-size: 1.3rem !important; }
    .section-header div {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        width: 100%;
    }
    .section-header .btn-primary,
    .section-header .btn-secondary {
        font-size: 0.75rem !important;
        padding: 7px 12px !important;
        flex: 1;
        min-width: 120px;
        text-align: center;
    }

    .filters {
        flex-direction: column !important;
        gap: 8px !important;
    }
    .filters input,
    .filters select,
    .filters button {
        width: 100% !important;
        font-size: 0.82rem !important;
    }

    .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-scroll    { overflow-x: auto; min-width: 100%; }
    .data-table      { min-width: 500px; font-size: 0.78rem !important; }
    .data-table th,
    .data-table td   { padding: 8px 10px !important; }

    #dashKPIs {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    #dashMid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    #section-dashboard > div:last-child,
    #section-dashboard [style*="grid-template-columns:1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px;
    }

    .stats-grid,
    .stats-container {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
    .stat-card { padding: 12px !important; }
    .stat-number { font-size: 1.4rem !important; }

    .compta-summary {
        flex-direction: column !important;
        gap: 10px !important;
    }
    .compta-card { min-width: unset !important; }

    .facturation-menu,
    .compta-menu,
    .rh-menu,
    .caisse-menu,
    .commercial-menu,
    .projets-menu {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }
    .facturation-tab,
    .compta-tab,
    .rh-tab,
    .caisse-tab,
    .commercial-tab,
    .projets-tab {
        font-size: 0.72rem !important;
        padding: 6px 10px !important;
        flex: 1;
        min-width: 80px;
        text-align: center;
    }

    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        margin: 10px auto !important;
        max-height: 92vh;
        overflow-y: auto;
    }
    .modal-header { padding: 12px 16px !important; }
    .modal-body   { padding: 12px 16px !important; }

    .form-group { margin-bottom: 12px !important; }
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 0.9rem !important;
        padding: 9px 12px !important;
    }

    .modal-body [style*="grid-template-columns:1fr 1fr"],
    .modal-body [style*="grid-template-columns: 1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 0 !important;
    }

    .membre-search-results {
        max-height: 200px !important;
        font-size: 0.82rem !important;
    }

    .pos-container {
        flex-direction: column !important;
        height: auto !important;
    }
    .pos-produits {
        height: 300px !important;
        overflow-y: auto;
    }
    .pos-panier {
        width: 100% !important;
        height: auto !important;
    }
    .produits-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    #dashActions button {
        padding: 7px 10px !important;
        font-size: 0.75rem !important;
    }

    .badge, span[style*="border-radius:20px"] {
        font-size: 0.65rem !important;
        padding: 2px 7px !important;
    }

    .action-buttons {
        display: flex;
        gap: 4px;
        flex-wrap: nowrap;
    }
    .btn-icon {
        width: 30px !important;
        height: 30px !important;
        font-size: 0.8rem !important;
    }

    .chart-card canvas {
        max-height: 180px !important;
    }

    .sub-tabs {
        flex-wrap: wrap !important;
        gap: 5px !important;
    }
    .sub-tab {
        font-size: 0.72rem !important;
        padding: 5px 8px !important;
    }

    /* ── CONTACTS : masquer tableau, afficher cartes ── */
    #section-membres .table-container { display: none !important; }
    #membreCardsContainer { display: flex !important; flex-direction: column; gap: 10px; }
}

/* ══════════════════════════════════════════════════════
   PETIT MOBILE (max 480px)
══════════════════════════════════════════════════════ */
@media (max-width: 480px) {

    .stats-grid,
    .stats-container {
        grid-template-columns: 1fr !important;
    }

    .data-table { font-size: 0.72rem !important; min-width: 420px; }
    .data-table th,
    .data-table td { padding: 6px 8px !important; }

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

    .section-header .btn-primary,
    .section-header .btn-secondary {
        width: 100% !important;
        font-size: 0.72rem !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 12px 12px 0 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0 !important;
        max-height: 90vh;
    }
    .modal {
        align-items: flex-end !important;
    }

    .produits-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
    }
    .produit-card { padding: 8px !important; }
    .produit-card .produit-nom { font-size: 0.72rem !important; }
    .produit-card .produit-prix { font-size: 0.85rem !important; }

    .top-bar { padding: 6px 10px !important; }
    .sidebar-toggle-mobile { width: 36px !important; height: 36px !important; }

    .dropdown-menu {
        right: 0 !important;
        left: auto !important;
        min-width: 150px !important;
    }
}

/* ══════════════════════════════════════════════════════
   DESKTOP : cacher les cartes
══════════════════════════════════════════════════════ */
@media (min-width: 769px) {
    #membreCardsContainer { display: none !important; }
}

/* ══════════════════════════════════════════════════════
   UTILITAIRES MOBILE
══════════════════════════════════════════════════════ */
* { -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
    input, select, textarea { font-size: 16px !important; }
    .form-group input,
    .form-group select,
    .form-group textarea { font-size: 16px !important; }
}

@media (max-width: 480px) {
    .modal.active .modal-content {
        animation: slideUpModal 0.3s ease-out;
    }
    @keyframes slideUpModal {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
}

/* ══════════════════════════════════════════════════════
   CARTES MEMBRES MOBILE
══════════════════════════════════════════════════════ */
.membre-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid rgba(212,175,55,.15);
    border-radius: 12px;
    padding: 14px 16px;
}

.membre-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.membre-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(108,142,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #6C8EFF;
}

.membre-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid rgba(255,255,255,.06);
    padding-top: 10px;
    margin-top: 2px;
}

@media (max-width: 900px) {
    /* Section caisse — scroll libre */
#section-caisse.active {
    height: auto !important;
    min-height: auto !important;
    overflow: visible !important;
}
    .caisse-content,
    .caisse-content.active {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
    }

    /* POS container — colonne unique */
    .pos-container {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        overflow: visible !important;
        gap: 12px !important;
    }

    /* Grille produits — hauteur limitée + scroll */
    .pos-produits {
        height: auto !important;
        max-height: 45vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* Panier — hauteur auto, tout visible */
    .pos-panier {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* Articles du panier — scroll interne */
    .pos-articles {
        max-height: 200px !important;
        overflow-y: auto !important;
    }

    /* Cartes produits */
    .produit-card {
        overflow: visible !important;
        min-height: 90px !important;
    }
    .produit-emoji { font-size: 1.2rem !important; }
    .produit-nom   { font-size: 0.60rem !important; }
    .produit-prix  { font-size: 0.75rem !important; }
}

/* ── Modal mobile ── */
@media (max-width: 768px) {
    .modal {
        padding: 0 !important;
        align-items: flex-end !important;
    }
    .modal.active {
        padding: 0 !important;
        align-items: flex-end !important;
        padding-top: 0 !important;
    }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 88vh !important;
        border-radius: 20px 20px 0 0 !important;
        overflow-y: auto !important;
        margin: 0 !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .modal-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background: var(--bg-card) !important;
    }
    .modal-body {
        padding: 16px !important;
        overflow-y: visible !important;
    }
    /* Grille emoji+nom en colonne sur mobile */
    .modal-body [style*="grid-template-columns: 80px"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
}

/* ── Menus à onglets — grille 2 colonnes sur mobile ── */
@media (max-width: 768px) {
    .commercial-menu,
    .rh-menu,
    .compta-menu,
    .projets-menu {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px !important;
        padding: 8px !important;
    }

    .commercial-tab,
    .rh-tab,
    .compta-tab,
    .projets-tab {
        font-size: 0.72rem !important;
        padding: 8px 6px !important;
        text-align: center !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        border-radius: 8px !important;
    }
}

/* ── Caisse — flex wrap ── */
@media (max-width: 768px) {
    .caisse-menu {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 5px !important;
        padding: 6px !important;
    }
    .caisse-tab {
        flex: 1 1 auto !important;
        min-width: 70px !important;
        font-size: 0.68rem !important;
        padding: 6px 8px !important;
        text-align: center !important;
    }
}