/* =============================================
   VARIABLES & RESET
============================================= */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Palette principale */
    --bleu:           #2563eb;
    --bleu-hover:     #1d4ed8;
    --bleu-clair:     #eff6ff;
    --bleu-border:    #bfdbfe;

    /* Statuts */
    --vert:           #16a34a;
    --vert-clair:     #dcfce7;
    --vert-border:    #bbf7d0;
    --rouge:          #dc2626;
    --rouge-clair:    #fee2e2;
    --rouge-border:   #fecaca;
    --orange:         #d97706;
    --orange-clair:   #fef3c7;

    /* Neutres */
    --bandeau-bg:     #1e293b;
    --bandeau-sub:    #334155;
    --bandeau-text:   #f1f5f9;
    --bandeau-muted:  #94a3b8;

    --blanc:          #ffffff;
    --fond:           #f8fafc;
    --fond-hover:     #f1f5f9;
    --fond-active:    #eff6ff;

    --texte:          #0f172a;
    --texte-muted:    #64748b;
    --texte-light:    #94a3b8;

    --border:         rgba(0,0,0,0.08);
    --border-md:      rgba(0,0,0,0.12);

    /* Géométrie */
    --radius-sm:      6px;
    --radius-md:      8px;
    --radius-lg:      12px;
    --radius-xl:      16px;

    /* Ombres */
    --shadow-sm:      0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:      0 4px 12px rgba(0,0,0,0.08);

    /* Transitions */
    --transition:     all 0.15s ease;

    /* Tailles */
    --font-sm:        0.8125rem;
    --font-base:      0.9rem;
    --font-md:        1rem;
    --font-lg:        1.125rem;
    --font-xl:        1.25rem;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--fond);
    color: var(--texte);
    font-size: var(--font-base);
    line-height: 1.6;
}

/* =============================================
   BANDEAU
============================================= */
.bandeau {
    background-color: var(--bandeau-bg);
    color: var(--bandeau-text);
    padding: 0 24px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.bandeau .logo img {
    height: 44px;
    border-radius: var(--radius-sm);
    display: block;
}

.bandeau .titre h1 {
    font-size: var(--font-lg);
    font-weight: 500;
    color: var(--bandeau-text);
    letter-spacing: -0.01em;
}

/* =============================================
   LAYOUT
============================================= */
.container {
    display: flex;
    min-height: calc(100vh - 60px);
}

/* =============================================
   SIDEBAR
============================================= */
.sidebar {
    width: 220px;
    background-color: var(--blanc);
    border-right: 1px solid var(--border);
    padding: 12px 8px;
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
    overflow-y: auto;
    flex-shrink: 0;
}

/* Nav container */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Lien de base */
.nav-link {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    color: var(--texte-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: var(--transition);
    font-size: var(--font-sm);
    font-weight: 400;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-link i {
    font-size: 14px;
    width: 15px;
    flex-shrink: 0;
}

.nav-link:hover {
    background-color: var(--fond-hover);
    color: var(--texte);
}

.nav-link.active {
    background-color: var(--fond-active);
    color: var(--bleu);
    font-weight: 500;
}

.nav-link.active i {
    color: var(--bleu);
}

.nav-link-logout {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}

/* Groupe avec sous-menu (details/summary) */
.nav-group {
    border: none;
}

.nav-group-toggle {
    list-style: none;
    justify-content: space-between;
}

.nav-group-toggle::-webkit-details-marker { display: none; }
.nav-group-toggle::marker { display: none; }

.nav-chevron {
    font-size: 10px !important;
    width: auto !important;
    color: var(--texte-light);
    transition: transform 0.2s ease;
    margin-left: auto;
}

details[open] .nav-chevron {
    transform: rotate(180deg);
}

/* Sous-liens */
.nav-sub {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 2px 0 4px 10px;
    margin-top: 1px;
}

.nav-sub-link {
    font-size: 0.78rem;
    padding: 6px 10px;
    color: var(--texte-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-sub-link i:first-child {
    font-size: 13px;
    width: 14px;
    flex-shrink: 0;
}

/* =============================================
   CONTENU PRINCIPAL
============================================= */
.main-content {
    flex: 1;
    padding: 24px;
    min-width: 0;
}

/* =============================================
   EN-TÊTES DE PAGE
============================================= */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.page-header h2,
.main-content > h2 {
    font-size: var(--font-xl);
    font-weight: 500;
    color: var(--texte);
    letter-spacing: -0.01em;
}

/* =============================================
   BOUTONS
============================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: var(--font-sm);
    font-weight: 500;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn i {
    font-size: 14px;
}

.btn-primary {
    background-color: var(--bleu);
    color: var(--blanc);
    border-color: var(--bleu);
}

.btn-primary:hover {
    background-color: var(--bleu-hover);
    border-color: var(--bleu-hover);
}

.btn-secondary {
    background-color: var(--blanc);
    color: var(--texte-muted);
    border-color: var(--border-md);
}

.btn-secondary:hover {
    background-color: var(--fond-hover);
    color: var(--texte);
}

.btn-danger {
    background-color: var(--blanc);
    color: var(--rouge);
    border-color: var(--rouge-border);
}

.btn-danger:hover {
    background-color: var(--rouge-clair);
}

.btn-sm {
    padding: 4px 9px;
    font-size: 0.775rem;
    border-radius: var(--radius-sm);
}

.btn-outline-pdf {
    background-color: transparent;
    color: var(--rouge);
    border-color: var(--rouge-border);
}

.btn-outline-pdf:hover {
    background-color: var(--rouge-clair);
}

/* =============================================
   FILTRES
============================================= */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin-bottom: 16px;
    padding: 14px 16px;
    background-color: var(--blanc);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--texte-muted);
}

.filters select,
.filter-group select {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-md);
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    background-color: var(--blanc);
    color: var(--texte);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 28px;
    cursor: pointer;
}

.filters select:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--bleu);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.filters form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    width: 100%;
}

/* =============================================
   TABLEAUX
============================================= */
.table-wrap {
    background-color: var(--blanc);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table th {
    background-color: var(--fond);
    color: var(--texte-muted);
    font-weight: 500;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

table td {
    padding: 10px 12px;
    font-size: var(--font-sm);
    color: var(--texte);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    height: 48px;
}

table tr:last-child td {
    border-bottom: none;
}

table tbody tr {
    transition: background-color 0.1s;
}

table tbody tr:hover {
    background-color: var(--fond-hover);
}

table tr.pinte {
    background-color: rgba(22,163,74,0.04);
}

table tfoot tr th {
    background-color: var(--fond);
    color: var(--texte);
    font-size: var(--font-sm);
    text-transform: none;
    letter-spacing: 0;
}

/* Montants */
table .recette,
.montant-pos {
    color: var(--vert);
    font-weight: 500;
    text-align: right;
    white-space: nowrap;
}

table .depense,
.montant-neg {
    color: var(--rouge);
    font-weight: 500;
    text-align: right;
    white-space: nowrap;
}

table td strong {
    display: block;
    font-weight: 500;
    color: var(--texte-muted);
    font-size: 0.78rem;
    margin-bottom: 1px;
}

/* Cellule catégorie sur 2 lignes : aligner verticalement */
.td-categorie {
    vertical-align: middle;
    line-height: 1.3;
}

.td-categorie .cat-parent {
    font-size: 0.72rem;
    color: var(--texte-light);
    display: block;
    line-height: 1.2;
}

.td-categorie .cat-enfant {
    font-size: var(--font-sm);
    color: var(--texte);
    display: block;
    line-height: 1.3;
}

/* Badges type recette/dépense */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-recette {
    background-color: var(--vert-clair);
    color: var(--vert);
    border: 1px solid var(--vert-border);
}

.badge-depense {
    background-color: var(--rouge-clair);
    color: var(--rouge);
    border: 1px solid var(--rouge-border);
}

.badge-info {
    background-color: var(--bleu-clair);
    color: var(--bleu);
    border: 1px solid var(--bleu-border);
}

/* =============================================
   SOLDES
============================================= */
.soldes-container {
    margin-bottom: 16px;
}

.soldes-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.solde-card {
    flex: 1;
    min-width: 140px;
    background-color: var(--blanc);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.soldes-title {
    font-weight: 500;
    color: var(--texte);
    margin-bottom: 12px;
    font-size: var(--font-md);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.soldes-title small {
    font-size: var(--font-sm);
    font-weight: 400;
    color: var(--texte-muted);
}

.solde-compte-name {
    font-size: 0.75rem;
    color: var(--texte-muted);
    margin-bottom: 6px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.solde-montant {
    font-size: 1.15rem;
    font-weight: 500;
    color: var(--vert);
    margin-bottom: 2px;
}

.solde-a-venir {
    font-size: 0.72rem;
    color: var(--texte-light);
    font-style: italic;
}

.solde-total-card {
    background-color: var(--bleu-clair);
    border: 1px solid var(--bleu-border);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    text-align: center;
    width: 100%;
}

.solde-total-card .solde-compte-name {
    color: var(--bleu);
    font-weight: 600;
}

.solde-total-card .solde-montant {
    color: var(--bleu);
    font-size: 1.3rem;
}

/* =============================================
   FORMULAIRES
============================================= */
.form-container {
    max-width: 820px;
    margin: 0 auto;
    background-color: var(--blanc);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    padding: 28px;
    box-shadow: var(--shadow-sm);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: var(--font-sm);
    color: var(--texte);
}

.form-group label i {
    color: var(--bleu);
    font-size: 15px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-md);
    border-radius: var(--radius-md);
    font-size: var(--font-base);
    color: var(--texte);
    background-color: var(--blanc);
    transition: var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--bleu);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.form-group textarea {
    height: 90px;
    resize: vertical;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Grille formulaire */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}

.full-width {
    grid-column: 1 / -1;
}

.form-group-narrow {
    max-width: 160px;
}

/* Boutons radio stylisés */
.btn-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.btn-radio {
    position: relative;
    padding: 7px 14px;
    background-color: var(--fond);
    border: 1px solid var(--border-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    flex: 1 1 auto;
    text-align: center;
    min-width: 0;
    font-size: var(--font-sm);
}

.btn-radio input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.btn-radio span {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-radio.active,
.btn-radio:hover {
    background-color: var(--bleu);
    color: var(--blanc);
    border-color: var(--bleu);
}

.btn-radio.active i,
.btn-radio:hover i {
    color: var(--blanc) !important;
}

/* Champ montant */
.input-montant {
    display: flex;
    align-items: center;
}

.input-montant input {
    flex: 1;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    border-right: none;
}

.input-montant span {
    padding: 8px 12px;
    background-color: var(--fond);
    border: 1px solid var(--border-md);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    color: var(--texte-muted);
    font-size: var(--font-sm);
}

/* Exercice dans les formulaires */
.exercice-actif {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    color: var(--texte);
    font-size: var(--font-md);
    font-weight: 500;
    padding: 12px 16px;
    background-color: var(--fond);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    margin-bottom: 20px;
}

.exercice-actif i {
    color: var(--bleu);
}

/* =============================================
   ALERTES & MESSAGES
============================================= */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
    font-size: var(--font-sm);
    border: 1px solid transparent;
}

.alert-success {
    background-color: var(--vert-clair);
    color: var(--vert);
    border-color: var(--vert-border);
}

.alert-danger,
.alert {
    background-color: var(--rouge-clair);
    color: var(--rouge);
    border-color: var(--rouge-border);
}

.alert-info {
    background-color: var(--bleu-clair);
    color: var(--bleu);
    border-color: var(--bleu-border);
}

/* =============================================
   LOGIN
============================================= */
.login-container {
    max-width: 380px;
    margin: 60px auto;
    background-color: var(--blanc);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.login-container h2 {
    font-size: var(--font-xl);
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--texte);
}

.login-container .login-sub {
    font-size: var(--font-sm);
    color: var(--texte-muted);
    margin-bottom: 24px;
}

.login-icon {
    width: 48px;
    height: 48px;
    background-color: var(--bleu-clair);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.login-icon i {
    font-size: 22px;
    color: var(--bleu);
}

/* =============================================
   ONGLETS
============================================= */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tabs button {
    padding: 8px 16px;
    border: none;
    background: transparent;
    font-size: var(--font-sm);
    color: var(--texte-muted);
    cursor: pointer;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: var(--transition);
    font-weight: 400;
}

.tabs button:hover {
    color: var(--texte);
    background-color: var(--fond-hover);
}

.tabs button.active {
    color: var(--bleu);
    border-bottom-color: var(--bleu);
    font-weight: 500;
    background-color: transparent;
}

.tab-content {
    display: none;
    padding: 20px;
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    background-color: var(--blanc);
}

.tab-content.active {
    display: block;
}

/* =============================================
   POINTAGE
============================================= */
.btn-pointer {
    color: var(--texte-light);
    font-size: 1rem;
    cursor: pointer;
    transition: var(--transition);
    background: none;
    border: none;
    padding: 2px;
}

.btn-pointer.pinte {
    color: var(--vert);
}

.btn-pointer.non-pinte {
    color: var(--texte-light);
}

.btn-pointer:hover {
    transform: scale(1.15);
}

/* =============================================
   ACTIONS DANS LES TABLEAUX
============================================= */
.actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

.actions a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--texte-muted);
    text-decoration: none;
    transition: var(--transition);
    border: 1px solid transparent;
}

.actions a:hover {
    background-color: var(--fond-hover);
    color: var(--texte);
    border-color: var(--border);
}

/* =============================================
   BILAN
============================================= */

/* Accordéon bilan — desktop : tout ouvert, résumé et chevron cachés */
.bilan-accordeon-body { display: block !important; }
.bilan-accordeon-resume { display: none !important; }
.bilan-accordeon-chevron { display: none !important; }
.bilan-accordeon-header { cursor: default; }
.bilan-activite {
    margin-bottom: 28px;
    background-color: var(--blanc);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.bilan-title {
    font-size: var(--font-md);
    font-weight: 500;
    color: var(--texte);
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background-color: var(--fond);
}

.bilan-global {
    margin-top: 20px;
    background-color: var(--bleu-clair);
    border: 1px solid var(--bleu-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.positif { color: var(--vert); font-weight: 500; }
.negatif { color: var(--rouge); font-weight: 500; }
.text-right { text-align: right; }

/* =============================================
   CAISSE
============================================= */
.compteur-especes {
    max-width: 420px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--blanc);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.ligne-compteur {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.ligne-compteur:last-of-type {
    border-bottom: none;
}

.ligne-compteur label {
    flex: 1;
    font-size: var(--font-sm);
    color: var(--texte-muted);
}

.ligne-compteur input {
    width: 70px;
    text-align: center;
    padding: 5px 8px;
    border: 1px solid var(--border-md);
    border-radius: var(--radius-sm);
    font-size: var(--font-sm);
}

.total {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 2px solid var(--bleu-border);
    font-size: 1.15rem;
    font-weight: 500;
    text-align: center;
}

#total-value { color: var(--vert); }

/* =============================================
   TOM SELECT
============================================= */
.ts-control {
    border: 1px solid var(--border-md) !important;
    border-radius: var(--radius-md) !important;
    padding: 5px 8px !important;
    min-height: 38px !important;
    background-color: var(--blanc) !important;
    font-size: var(--font-sm) !important;
    transition: var(--transition) !important;
}

.ts-control:focus-within {
    border-color: var(--bleu) !important;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12) !important;
}

.ts-dropdown {
    border: 1px solid var(--border-md) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-md) !important;
    font-size: var(--font-sm) !important;
}

.ts-dropdown .active {
    background-color: var(--bleu-clair) !important;
    color: var(--bleu) !important;
}

.ts-dropdown .selected {
    background-color: var(--bleu) !important;
    color: var(--blanc) !important;
}

.ts-dropdown .optgroup-header {
    font-weight: 600;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--texte-muted);
    background-color: var(--fond);
    padding: 6px 10px 4px;
}

.ts-dropdown .option {
    padding: 6px 10px 6px 20px;
}

/* =============================================
   TOOLTIPS
============================================= */
[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--texte);
    color: var(--blanc);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    white-space: nowrap;
    z-index: 200;
    box-shadow: var(--shadow-sm);
    pointer-events: none;
}

[title] {
    position: relative;
}

/* =============================================
   UTILITAIRES
============================================= */
.text-muted { color: var(--texte-muted); }
.text-small { font-size: var(--font-sm); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }

/* =============================================
   RESPONSIVE — TABLETTES ET MOBILES
============================================= */

/* ---- Bouton hamburger (mobile) ---- */
.btn-hamburger {
    display: none;
    background: none;
    border: none;
    color: var(--bandeau-text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    margin-right: 4px;
    flex-shrink: 0;
}

/* Overlay pour fermer le menu sur mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 98;
}

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

/* ---- TABLETTE (≤ 1024px) ---- */
@media (max-width: 1024px) {

    .sidebar {
        width: 200px;
    }

    .main-content {
        padding: 16px;
    }

    /* Tableaux : scroll horizontal */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 700px;
    }

    /* Grilles formulaires */
    .form-grid {
        grid-template-columns: 1fr;
    }

    /* Grilles soldes */
    .soldes-grid {
        flex-wrap: wrap;
    }

    .solde-card {
        min-width: calc(50% - 10px);
    }

    /* Synthèse bilan */
    .bilan-synthese-grid {
        grid-template-columns: 1fr 1fr;
    }
}

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

    /* Bandeau */
    .bandeau {
        padding: 0 12px;
        height: 54px;
    }

    .bandeau .logo img {
        height: 36px;
    }

    .bandeau .titre h1 {
        font-size: 0.95rem;
    }

    /* Bouton hamburger visible */
    .btn-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sidebar : cachée par défaut, s'ouvre en drawer */
    .container {
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 54px;
        left: 0;
        height: calc(100vh - 54px);
        width: 260px;
        z-index: 99;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-md);
    }

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

    /* Contenu pleine largeur */
    .main-content {
        padding: 12px;
        width: 100%;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        margin-bottom: 14px;
    }

    .page-header h2 {
        font-size: 1.1rem;
    }

    .page-header .btn {
        width: 100%;
        justify-content: center;
    }

    /* Formulaires */
    .form-container {
        padding: 16px;
        border-radius: var(--radius-lg);
    }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Boutons radio groupés */
    .btn-group {
        flex-wrap: wrap;
    }

    /* Filtres */
    .filters form {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        min-width: 100%;
    }

    .filters .btn {
        width: 100%;
        justify-content: center;
    }

    /* Soldes */
    .soldes-grid {
        flex-direction: column;
    }

    .solde-card {
        min-width: 100%;
    }

    /* Cartes synthèse bilan */
    .bilan-synthese-grid {
        grid-template-columns: 1fr;
    }

    /* Bilan type total */
    .bilan-type-total {
        grid-template-columns: 1fr;
        gap: 4px;
        text-align: center;
    }

    .bilan-type-total span:not(:first-child) {
        min-width: auto;
        text-align: center;
    }

    /* Section bilan */
    .bilan-section {
        padding: 14px 16px;
    }

    /* Entête bilan */
    .bilan-entete {
        flex-direction: column;
        text-align: center;
        padding: 20px 16px;
        gap: 12px;
    }

    .bilan-entete-date {
        text-align: center;
    }

    .bilan-doc-titre {
        font-size: 1.2rem;
    }

    /* Login */
    .login-container {
        margin: 20px 12px;
        padding: 24px 16px;
    }

    /* Tabs */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 2px;
        padding-bottom: 1px;
    }

    .tabs button {
        padding: 8px 10px;
        font-size: 0.78rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Grille gestion utilisateurs */
    div[style*="grid-template-columns:1fr 1.6fr"],
    div[style*="grid-template-columns:1fr 1.5fr"],
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Upload zone */
    .upload-zone {
        padding: 16px;
    }

    /* Table actions compactes */
    .actions a {
        width: 32px;
        height: 32px;
    }

    /* Alertes */
    .alert {
        font-size: 0.82rem;
    }

    /* ---- Accordéon bilan ---- */
    .bilan-accordeon-header {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        user-select: none;
    }

    .bilan-accordeon-resume {
        display: flex;
        gap: 6px;
        font-size: 0.78rem;
        font-weight: 500;
        margin-left: auto;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .bilan-accordeon-chevron {
        font-size: 0.75rem;
        color: var(--texte-light);
        transition: transform 0.2s ease;
        flex-shrink: 0;
    }

    .bilan-accordeon-body {
        display: none;
    }

    .bilan-accordeon-body.open {
        display: block;
    }

    .bilan-accordeon-body.open table {
        display: block !important;
        width: 100%;
        overflow-x: auto;
    }
}

/* ---- TRÈS PETIT MOBILE (≤ 400px) ---- */
@media (max-width: 400px) {

    .bandeau .titre h1 {
        display: none;
    }

    table {
        font-size: 0.78rem;
    }

    table th, table td {
        padding: 7px 8px;
    }
}

/* =============================================
   CARTES ENREGISTREMENTS (mobile)
============================================= */

/* Masqué sur desktop */
.enr-cartes {
    display: none;
}

@media (max-width: 768px) {

    /* Masquer les tableaux sur mobile */
    .table-wrap,
    table.enregistrements,
    .bilan-accordeon-body table {
        display: none;
    }

    /* Afficher les cartes */
    .enr-cartes {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .enr-carte {
        background: var(--blanc);
        border-radius: var(--radius-lg);
        border: 1px solid var(--border);
        padding: 12px 14px;
        box-shadow: var(--shadow-sm);
    }

    .enr-carte-pointee {
        border-left: 3px solid var(--vert);
    }

    .enr-carte-header {
        display: flex;
        align-items: center;
        gap: 8px;
        margin-bottom: 8px;
    }

    .enr-carte-date {
        font-size: 0.78rem;
        color: var(--texte-muted);
        font-weight: 500;
        flex-shrink: 0;
    }

    .enr-carte-montant {
        margin-left: auto;
        font-size: 1rem;
        font-weight: 600;
        white-space: nowrap;
    }

    .enr-carte-activite {
        font-size: 0.85rem;
        font-weight: 500;
        color: var(--texte);
        margin-bottom: 6px;
        display: flex;
        flex-wrap: wrap;
        gap: 4px;
        align-items: center;
    }

    .enr-carte-meta {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        font-size: 0.75rem;
        color: var(--texte-muted);
        margin-bottom: 6px;
    }

    .enr-carte-meta span {
        display: flex;
        align-items: center;
        gap: 3px;
    }

    .enr-carte-commentaire {
        font-size: 0.78rem;
        color: var(--texte-muted);
        font-style: italic;
        margin-bottom: 8px;
        display: flex;
        gap: 5px;
        align-items: flex-start;
    }

    .enr-carte-actions {
        display: flex;
        gap: 6px;
        align-items: center;
        flex-wrap: wrap;
        padding-top: 8px;
        border-top: 1px solid var(--border);
    }

    .enr-carte-actions .btn-pointer {
        font-size: 1.1rem;
    }
}

/* =============================================
   FOOTER
============================================= */
.app-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    border-top: 1px solid var(--border);
    background: var(--blanc);
    font-size: 0.75rem;
    color: var(--texte-muted);
}

.app-footer a {
    color: var(--bleu);
    text-decoration: none;
    font-weight: 500;
}

.app-footer a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .app-footer {
        flex-direction: column;
        gap: 4px;
        font-size: 0.7rem;
        padding: 10px 16px;
    }
}
