/**
 * RESPONSIVE — Gestion Association
 * Couche mobile-first pour desktop, laptop, tablette et smartphone
 * Sans modifier les fonctionnalités — UI/UX uniquement
 */

/* ── Safe areas (iPhone notch, barre d'accueil) ── */
:root {
    --app-topbar-height: 60px;
    --app-sidebar-width: 260px;
    --app-sidebar-width-mobile: min(320px, 100vw);
    --app-fab-size: 52px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ── Shell application ── */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

.app-shell > .container-fluid {
    padding-left: 0;
    padding-right: 0;
}

.app-shell > .container-fluid > .row {
    margin-left: 0;
    margin-right: 0;
}

/* Overlay / FAB hors du flux flex */
.app-shell .sidebar-overlay,
.app-shell .sidebar-toggle {
    flex: none;
    width: auto;
    max-width: none;
}

@media (min-width: 992px) {
    .app-shell > .container-fluid > .row {
        flex-wrap: nowrap;
    }
}

.main-content {
    min-width: 0;
    flex: 1 1 auto;
    position: relative;
}

/* Éviter le contenu caché sous le FAB sidebar */
@media (max-width: 991.98px) {
    .main-content {
        padding-bottom: calc(2rem + var(--app-fab-size) + var(--safe-bottom)) !important;
    }
}

/* ── Topbar ── */
.topbar {
    padding-top: calc(0.35rem + var(--safe-top)) !important;
    padding-bottom: 0.35rem !important;
    min-height: auto;
}

.topbar-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: nowrap;
    max-width: 100%;
    padding: 0 clamp(0.5rem, 2vw, 2rem);
    min-height: 48px;
}

.topbar-brand {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.topbar-brand span,
.topbar-brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
    flex-wrap: nowrap;
}

.topbar-nav-links {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

/* Barre compacte mobile */
.topbar-nav-mobile {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.topbar-link-compact {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.35rem 0.55rem !important;
    border-radius: 8px !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    line-height: 1.2;
    white-space: nowrap;
    min-height: 36px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.topbar-link-compact i {
    font-size: 0.9375rem !important;
    margin: 0 !important;
}

.topbar-link-compact .topbar-compact-label {
    display: inline;
    color: #fff !important;
    font-size: 0.6875rem !important;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.topbar-link-compact.topbar-link-logout {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.35);
}

.topbar-link-compact.topbar-link-logout:hover {
    background: rgba(239, 68, 68, 0.4) !important;
}

/* Tablette large : liens compacts */
@media (max-width: 1199.98px) and (min-width: 992px) {
    .topbar-link {
        padding: 0.45rem 0.65rem !important;
        font-size: 0.875rem !important;
    }

    .topbar-brand-text {
        max-width: 28vw;
    }
}

/* Mobile & tablette : masquer nav desktop (Bootstrap d-lg-flex gère l'affichage) */
@media (max-width: 991.98px) {
    .topbar {
        --app-topbar-height: 48px;
    }

    .topbar-brand-text {
        max-width: 38vw;
        font-size: 0.8125rem !important;
    }

    .topbar-brand i {
        font-size: 1.125rem;
        flex-shrink: 0;
    }
}

@media (max-width: 575.98px) {
    .topbar-container {
        min-height: 44px;
        gap: 0.35rem;
    }

    /* Nom app : icône seule sur très petit écran */
    .topbar-brand-text {
        display: none !important;
    }

    .topbar-link-compact {
        padding: 0.3rem 0.45rem !important;
        min-height: 34px;
        min-width: 34px;
    }

    .topbar-link-compact .topbar-compact-label {
        display: none !important;
    }
}

@media (max-width: 399.98px) {
    .topbar-container {
        padding: 0 0.4rem;
    }

    .topbar-nav-mobile {
        gap: 0.25rem;
    }
}

/* ── Sidebar mobile ── */
@media (max-width: 991.98px) {
    .association-sidebar {
        width: var(--app-sidebar-width-mobile) !important;
        max-width: 100vw;
        padding-top: calc(1rem + var(--safe-top)) !important;
        padding-bottom: calc(1rem + var(--safe-bottom)) !important;
        top: 0 !important;
    }

    .sidebar-toggle {
        bottom: calc(16px + var(--safe-bottom)) !important;
        left: calc(16px + var(--safe-left)) !important;
        width: var(--app-fab-size);
        height: var(--app-fab-size);
        min-width: 44px;
        min-height: 44px;
    }

    .main-content.col-md-9,
    .main-content.col-lg-10 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        margin-left: 0 !important;
        padding-left: clamp(0.75rem, 3vw, 1.25rem) !important;
        padding-right: clamp(0.75rem, 3vw, 1.25rem) !important;
    }
}

@media (max-width: 575.98px) {
    .association-sidebar {
        width: 100% !important;
    }
}

/* ── En-têtes de page ── */
.main-content > .d-flex.justify-content-between.flex-wrap,
.main-content > .d-flex.justify-content-between.flex-md-nowrap {
    gap: 0.75rem;
}

.main-content > .d-flex.justify-content-between .btn-toolbar,
.main-content > .d-flex.justify-content-between .btn-group {
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 767.98px) {
    .main-content > .d-flex.justify-content-between.flex-wrap,
    .main-content > .d-flex.justify-content-between.flex-md-nowrap {
        flex-direction: column;
        align-items: stretch !important;
    }

    .main-content > .d-flex.justify-content-between h1,
    .main-content > .d-flex.justify-content-between .h1,
    .main-content > .d-flex.justify-content-between h2,
    .main-content > .d-flex.justify-content-between .h2 {
        font-size: 1.375rem !important;
    }

    .main-content > .d-flex.justify-content-between .btn-toolbar,
    .main-content > .d-flex.justify-content-between > .btn,
    .main-content > .d-flex.justify-content-between > div:last-child {
        width: 100%;
    }

    .main-content > .d-flex.justify-content-between .btn {
        flex: 1 1 auto;
    }
}

/* ── Cartes & statistiques ── */
@media (max-width: 991.98px) {
    .card:hover {
        transform: none;
    }

    .stat-card:hover {
        transform: none;
    }
}

@media (max-width: 767.98px) {
    .row > [class*="col-"] {
        margin-bottom: 0.75rem;
    }

    .stat-card,
    .stats-card {
        margin-bottom: 0.75rem;
    }

    .stat-card .stat-icon {
        width: 48px;
        height: 48px;
        font-size: 1.35rem;
    }

    .stat-card .stat-value,
    .stat-card h3 {
        font-size: 1.375rem !important;
    }
}

/* ── Onglets ── */
@media (max-width: 767.98px) {
    .main-content .nav-tabs,
    .finance-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 0.35rem;
        padding-bottom: 2px;
    }

    .main-content .nav-tabs::-webkit-scrollbar,
    .finance-tabs::-webkit-scrollbar {
        display: none;
    }

    .main-content .nav-tabs .nav-link,
    .finance-tabs .nav-link {
        white-space: nowrap;
        padding: 0.625rem 1rem !important;
        font-size: 0.875rem !important;
    }
}

/* ── Tableaux ── */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
}

@media (max-width: 767.98px) {
    .table thead th {
        font-size: 0.75rem !important;
        padding: 0.625rem 0.75rem !important;
    }

    .table tbody td {
        font-size: 0.8125rem !important;
        padding: 0.625rem 0.75rem !important;
    }

    /* Finance tables — autoriser le retour à la ligne */
    .finance-table thead th {
        white-space: normal !important;
        font-size: 0.6875rem !important;
    }

    .finance-cell-date,
    .finance-badge,
    .finance-amount {
        white-space: normal !important;
    }

    .finance-cell-desc {
        min-width: 120px !important;
    }

    .finance-table-summary {
        flex-direction: column;
        align-items: flex-start !important;
        text-align: left;
    }

    .finance-summary-value {
        font-size: 1.125rem !important;
        width: 100%;
    }

    .finance-actions .btn {
        min-width: 36px;
        min-height: 36px;
    }

    .finance-table-card-header h5 {
        font-size: 0.9375rem !important;
    }
}

/* DataTables mobile */
@media (max-width: 767.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        width: 100%;
        text-align: left !important;
    }

    .dataTables_wrapper .dataTables_length label,
    .dataTables_wrapper .dataTables_filter label {
        flex-direction: column;
        align-items: flex-start !important;
        width: 100%;
        gap: 0.35rem;
    }

    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        min-width: 0 !important;
        margin-left: 0 !important;
    }

    .dataTables_wrapper .dataTables_length select {
        width: 100%;
        max-width: 120px;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        width: 100%;
        text-align: center !important;
    }

    .dataTables_wrapper .dataTables_paginate {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }

    .finance-dt-toolbar,
    .finance-dt-footer {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }
}

/* ── Formulaires ── */
@media (max-width: 767.98px) {
    .modal .row > [class*="col-"],
    .main-content form .row > [class*="col-"] {
        margin-bottom: 0.5rem;
    }

    .form-control,
    .form-select {
        font-size: 16px !important; /* évite le zoom iOS */
    }

    .input-group {
        flex-wrap: wrap;
    }

    .input-group > .form-control,
    .input-group > .form-select {
        min-width: 0;
        flex: 1 1 100%;
    }
}

/* ── Modales — mobile : plein écran scrollable ── */
@media (max-width: 767.98px) {
    .modal {
        padding: 0 !important;
        overflow: hidden !important;
    }

    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        height: 100% !important;
        max-height: 100dvh !important;
    }

    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        max-width: 100% !important;
    }

    .modal-content {
        height: 100% !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }

    .modal-header {
        padding: 0.875rem 1rem !important;
    }

    .modal-body {
        padding: 1rem !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        flex: 1 1 auto;
        min-height: 0;
    }

    .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.75rem 1rem !important;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
        box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.08);
        background: #f8fafc !important;
    }

    .modal-footer .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 0.5rem);
        min-height: 44px;
    }
}

@media (max-width: 575.98px) {
    .modal-footer .btn {
        min-width: 100%;
    }

    /* Champs du formulaire modal — une colonne sur petit écran */
    .modal-body .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ── Boutons tactiles ── */
@media (max-width: 991.98px) {
    .btn,
    .page-link,
    .association-sidebar .nav-link {
        min-height: 44px;
    }

    .topbar-link-compact {
        min-height: 36px;
    }

    .btn-sm {
        min-height: 38px;
    }
}

/* ── Alerts ── */
@media (max-width: 575.98px) {
    .alert {
        font-size: 0.875rem !important;
        padding: 0.875rem !important;
    }
}

/* ── Footer site ── */
@media (max-width: 767.98px) {
    footer.bg-light {
        padding: 1rem 0 !important;
        margin-top: 1.5rem !important;
        padding-bottom: calc(1rem + var(--safe-bottom)) !important;
    }

    footer.bg-light .row {
        text-align: center;
    }

    footer.bg-light .col-md-6.text-md-end {
        text-align: center !important;
        margin-top: 0.5rem;
    }
}

body.sidebar-open {
    overflow: hidden;
    touch-action: none;
}

body.modal-open {
    overflow: hidden;
}

body.modal-open .modal-body {
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

/* Desktop : sidebar dans la grille */
@media (min-width: 992px) {
    .association-sidebar {
        display: block !important;
        position: sticky !important;
        left: auto !important;
        width: auto !important;
        height: auto !important;
        min-height: calc(100vh - var(--app-topbar-height));
        z-index: 100 !important;
    }

    .main-content {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        width: auto !important;
        max-width: none !important;
    }

    .sidebar-toggle,
    .sidebar-overlay {
        display: none !important;
    }
}

/* ── Login ── */
@media (max-width: 991.98px) {
    .login-page .main-content,
    .login-page-inner {
        padding: 1rem !important;
    }

    .login-card {
        border-radius: var(--border-radius-md) !important;
    }
}

@media (max-width: 575.98px) {
    .login-page .card-body {
        padding: 1.25rem !important;
    }

    .login-page .btn-lg {
        width: 100%;
    }
}

/* Désactiver les effets hover sur écrans tactiles */
@media (hover: none) and (pointer: coarse) {
    .card:hover,
    .stat-card:hover,
    .btn:hover {
        transform: none !important;
    }
}

/* Contrôles de filtre — largeur fluide */
@media (max-width: 767.98px) {
    .main-content .input-group,
    .main-content .d-flex.gap-2,
    .main-content .d-flex.gap-3 {
        flex-wrap: wrap !important;
    }

    .main-content select.form-select,
    .main-content input.form-control {
        max-width: 100%;
    }
}

@media (max-width: 767.98px) {
    .filter-bar,
    .toolbar-row,
    .card-header .d-flex,
    .presidents-filters .form-select,
    .presidents-filters .form-control {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem;
        min-width: 0 !important;
        width: 100% !important;
    }

    .filter-bar .form-select,
    .filter-bar .form-control,
    .filter-bar .btn {
        width: 100% !important;
        min-width: 0 !important;
    }
}

/* ── Breadcrumb ── */
@media (max-width: 575.98px) {
    .breadcrumb {
        padding: 0.75rem 1rem !important;
        font-size: 0.8125rem;
        flex-wrap: wrap;
    }
}

/* ── Impression ── */
@media print {
    .topbar,
    .association-sidebar,
    .sidebar-toggle,
    .sidebar-overlay,
    footer.bg-light {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    .card {
        break-inside: avoid;
    }
}
