/* =====================================================================
   Kodelis Balance — charte graphique (CLAUDE.md §9)
   Thème crème chaud, accent terracotta. Clair (défaut) + sombre (html.dark).
   Aucun framework CSS. Police : Public Sans (chargée dans <head>).
   ===================================================================== */

/* ---------- 9.2 Variables — thème clair (défaut) ---------- */
:root {
    /* Fonds */
    --bg-page:       #FDF8F3;   /* fond général crème chaud */
    --bg-surface:    #F5EDE0;   /* barres, en-têtes de tableau */
    --bg-card:       #FFFFFF;   /* cartes, tableaux */
    --bg-border:     #E8D5B8;   /* bordure douce */
    --sidebar-bg:    #2C2520;   /* sidebar : toujours sombre (clair & sombre) */

    /* Accent principal */
    --accent:        #C47A3A;
    --accent-light:  #F0E4D0;
    --accent-border: rgba(196,122,58,0.25);

    /* Sémantique */
    --credit:        #2D7D5A;
    --credit-light:  #E4F2EB;
    --debit:         #C0392B;
    --debit-light:   #FCECEA;
    --warn:          #C47A3A;
    --warn-light:    #FFF3E0;
    --info:          #2D5F9A;
    --info-light:    #EEF4FF;

    /* Texte */
    --text-primary:  #2C2520;
    --text-muted:    #8A7E77;
    --text-light:    #B0A49C;

    /* Composants */
    --border:        0.5px solid var(--bg-border);
    --radius-sm:     6px;
    --radius-md:     10px;
    --radius-lg:     14px;
    --radius-pill:   20px;
}

/* ---------- 9.3 Variables — thème sombre ---------- */
html.dark {
    --bg-page:       #1E1A17;
    --bg-surface:    #2A2420;
    --bg-card:       #312B27;
    --bg-border:     #4A3F37;

    --accent:        #D4894A;
    --accent-light:  #3D2E1F;
    --accent-border: rgba(212,137,74,0.3);

    --credit:        #4CAF82;
    --credit-light:  #1A3328;
    --debit:         #E05C50;
    --debit-light:   #3D1A18;
    --warn:          #D4894A;
    --warn-light:    #3D2E1F;
    --info:          #5B8FD4;
    --info-light:    #1A2840;

    --text-primary:  #F0E8DF;
    --text-muted:    #9A8E86;
    --text-light:    #6A5E58;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { color-scheme: light; }
html.dark { color-scheme: dark; }

body {
    margin: 0;
    font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px;       /* corps de texte (9.4) */
    font-weight: 400;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-page);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

h1, h2, h3 { font-weight: 500; color: var(--text-primary); }

/* ---------- 9.1.1 Layout global : sidebar fixe + contenu ---------- */
.app-layout {
    display: flex;
    min-height: 100vh;
}
.sidebar {
    width: 220px;
    min-width: 220px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
}
.main-content {
    flex: 1;
    min-width: 0;
    background: var(--bg-page);
    display: flex;
    flex-direction: column;
}
.page-content {
    padding: 24px;
    flex: 1;
}

/* ---------- 9.1.2 Sidebar (toujours sombre, identique clair/sombre) ---------- */
.sidebar-header { padding: 18px 18px 14px; }
.sidebar-brand {
    display: block;
    font-size: 15px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}
.sidebar-subtitle {
    font-size: 11px;
    color: rgba(255,255,255,0.35);
    margin-top: 2px;
}
.sidebar-nav { flex: 1; padding: 4px 10px 10px; }
.section-label {
    color: rgba(255,255,255,0.25);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 14px 10px 6px;
}
.nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 10px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    color: rgba(255,255,255,0.55);
    text-decoration: none;
    font-size: 13px;
    transition: background .15s, color .15s;
}
.nav-item:hover:not(.active) {
    background: rgba(255,255,255,0.05);
    color: rgba(255,255,255,0.8);
}
.nav-item.active {
    background: rgba(196,122,58,0.15);
    color: #C47A3A;
    font-weight: 500;
}
.nav-badge {
    font-size: 10px;
    font-weight: 500;
    line-height: 1;
    padding: 3px 7px;
    border-radius: var(--radius-pill);
    color: #fff;
}
.nav-badge-danger { background: var(--debit); }
.nav-badge-warn   { background: var(--accent); }

/* Pied de sidebar : avatar + identité + toggle thème */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
}
.sidebar-avatar {
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 500;
}
.sidebar-identity { min-width: 0; line-height: 1.25; }
.sidebar-name {
    font-size: 13px;
    color: rgba(255,255,255,0.85);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-role { font-size: 11px; color: rgba(255,255,255,0.4); }

/* ---------- Barre mobile (header_bar.php) + overlay ---------- */
.header-bar { display: none; }
.burger {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}
.header-bar-brand {
    font-size: 15px;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
}
.sidebar-backdrop { display: none; }

/* ---------- Toggle thème (switch pill, dans la sidebar sombre) ---------- */
.theme-switch {
    position: relative;
    width: 46px;
    height: 24px;
    border-radius: var(--radius-pill);
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.18);
    cursor: pointer;
    padding: 0;
    flex: none;
}
.theme-switch .theme-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    line-height: 1;
}
.theme-icon-light { left: 6px; }   /* lune : visible en clair (=> passer en sombre) */
.theme-icon-dark  { right: 6px; }  /* soleil : visible en sombre (=> passer en clair) */
.theme-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    transition: transform .2s ease;
}
html.dark .theme-switch::after { transform: translateX(22px); }
html:not(.dark) .theme-icon-dark { display: none; }
html.dark .theme-icon-light { display: none; }

/* ---------- Contenu ---------- */
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.page-head h1 { font-size: 22px; font-weight: 500; margin: 0; }

.card {
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 500; }
.card-narrow { max-width: 520px; }

/* ---------- Cartes métriques ---------- */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0;
    padding: 12px 14px;
}
.stat-label { font-size: 11px; color: var(--text-muted); }
.stat-value { font-size: 20px; font-weight: 500; color: var(--text-primary); }
.stat-value.warn { color: var(--warn); }
.stat-link { font-size: 12px; color: var(--accent); text-decoration: none; }
.stat-link:hover { text-decoration: underline; }

/* ---------- Tableaux ---------- */
.table-search { margin-bottom: 14px; }
.table-search input { max-width: 340px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th, .table td {
    padding: 9px 12px;
    text-align: left;
    border-bottom: var(--border);
    vertical-align: middle;
}
.table thead th {
    background: var(--bg-surface);
    color: var(--text-muted);
    font-weight: 500;
    font-size: 12px;
}
.table tbody tr:hover { background: var(--bg-surface); }
.table tfoot td { font-weight: 500; background: var(--bg-page); }
.table-total-cell { font-size: 12px; color: var(--text-muted); padding: 8px 12px; border-top: var(--border); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.label-cell { max-width: 360px; }
.label-link { color: var(--text-primary); text-decoration: none; }
.label-link:hover { color: var(--accent); text-decoration: underline; }
.td-check { width: 36px; min-width: 36px; padding: 0 4px 0 10px; text-align: center; }
.td-check input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }

/* Tableau « Écritures » en lecture seule — colonnes fixes (charte §9) */
.table-ecritures { table-layout: fixed; }
.table-ecritures .col-check   { width: 36px; }
.table-ecritures .col-date    { width: 95px; }
.table-ecritures .col-amount  { width: 120px; }
.table-ecritures .col-tva     { width: 55px; }
.table-ecritures .col-status  { width: 140px; }
.table-ecritures .col-benef   { width: 110px; }
.table-ecritures .label-cell  { max-width: none; overflow-wrap: anywhere; }
.table-ecritures .td-assoc    { overflow-wrap: anywhere; }
.table-ecritures .td-tva      { text-align: center; }
.table-ecritures .td-amount .amount-line,
.table-ecritures .td-amount .amount-ht { display: block; }
.table-ecritures .td-amount .amount-ht { font-weight: 400; }
.amount-income { color: var(--credit); }
/* Indicateur de note : icône accent + infobulle native (title) au survol du libellé */
.note-flag { display: inline-flex; vertical-align: middle; margin-left: 6px; color: var(--accent); cursor: help; }
.note-flag svg { display: block; }

/* Barre d'actions groupées */
.bulk-actions-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    background: var(--bg-card);
    border: 1px solid var(--accent-border);
    border-radius: var(--radius-md);
    padding: 8px 14px;
    margin-bottom: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.bulk-count { font-size: 13px; font-weight: 500; color: var(--accent); white-space: nowrap; }
.bulk-sep   { color: var(--text-light); }
.bulk-actions-bar select { font-size: 13px; }

/* === Barre de filtres (charte CLAUDE.md §9). Tout est scopé sous .filter-bar pour
   ne PAS entrer en conflit avec le .tag badge global (clients/commissions/associés). === */
.filter-bar { display: flex; flex-direction: column; border-radius: var(--radius-lg); padding: 16px 18px; }
.filter-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.filter-line + .filter-line { margin-top: 14px; padding-top: 14px; border-top: 0.5px solid var(--bg-border); }

/* Base commune des tags de filtre — CLASSE UNIQUE .filter-tag, utilisable dans
   OU hors .filter-bar (ecritures, dev_notes, dev_features, synthèse). */
.filter-tag {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 13px; border-radius: 20px; font-size: 12px; font-weight: 500;
    text-decoration: none; white-space: nowrap; cursor: pointer;
    color: var(--text-muted); background: var(--bg-surface); border: 0.5px solid var(--bg-border);
    transition: all 0.15s;
}
.filter-tag:hover { color: var(--text-primary); border-color: var(--accent-border); }
/* État actif par défaut (sous-statuts, associé, dev_notes, dev_features, synthèse) */
.filter-tag.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Sens (exclusif) — couleurs sémantiques débit/crédit */
.filter-tag.t-all.active    { background: #2C2520;       border-color: #2C2520;       color: #fff; }
.filter-tag.t-debit.active  { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-tag.t-credit.active { background: #2D7D5A;       border-color: #2D7D5A;       color: #fff; }

/* Toggle « À traiter » (rouge) */
.filter-tag.t-todo { background: transparent; border-color: var(--debit); color: var(--debit); }
.filter-tag.t-todo:hover { border-color: var(--debit); color: var(--debit); }
.filter-tag.t-todo.active { background: var(--debit); border-color: var(--debit); color: #fff; }

/* Toggle « À vérifier » (orange) — betafeature #67 */
.filter-tag.t-verify { background: transparent; border-color: #F59E0B; color: #F59E0B; }
.filter-tag.t-verify:hover { border-color: #F59E0B; color: #F59E0B; }
.filter-tag.t-verify.active { background: #F59E0B; border-color: #F59E0B; color: #fff; }

/* Séparateur vertical avant « À traiter » */
.filter-bar .tag-sep { width: 0.5px; align-self: stretch; min-height: 20px; background: var(--bg-border); margin: 0 8px; }

/* Ligne 3 — Libellés + groupes */
.filter-bar .filter-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-right: 2px; }
.filter-bar .tag-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Ligne 3 — Navigateur d'années ‹ 2026 › (boutons 24px + pill année) */
.filter-bar .year-nav { gap: 6px; }
.filter-bar .year-arrow {
    width: 24px; height: 24px; display: inline-grid; place-items: center;
    border-radius: 20px; text-decoration: none; font-size: 15px; line-height: 1;
    color: var(--text-primary); background: var(--bg-surface); border: 0.5px solid var(--bg-border);
    transition: all 0.15s;
}
.filter-bar .year-arrow:hover { border-color: var(--accent); color: var(--accent); }
.filter-bar .year-arrow.disabled { color: var(--text-light); background: transparent; border-color: transparent; cursor: default; pointer-events: none; }
.filter-bar .year-current {
    min-width: 52px; text-align: center; padding: 5px 13px; border-radius: 20px;
    background: var(--bg-surface); border: 0.5px solid var(--bg-border);
    font-size: 12px; font-weight: 500; color: var(--text-primary);
}

/* Ligne 3 — Recherche (champ flex + loupe) */
.filter-bar .filter-search {
    flex: 1; min-width: 200px; display: inline-flex; align-items: center; gap: 6px;
    background: var(--bg-card); border: 0.5px solid var(--bg-border); border-radius: 20px;
    padding: 4px 14px; transition: all 0.15s;
}
.filter-bar .filter-search:focus-within { border-color: var(--accent); }
.filter-bar .filter-search .loupe { display: inline-flex; align-items: center; color: var(--text-muted); line-height: 0; }
.filter-bar .filter-search input { flex: 1; border: 0; background: transparent; outline: none; font-size: 12px; color: var(--text-primary); padding: 3px 0; }

/* Ligne 3 — Réinitialiser (discret, à droite) */
.filter-bar .filter-reset { margin-left: auto; color: var(--text-light); font-size: 12px; text-decoration: none; transition: all 0.15s; }
.filter-bar .filter-reset:hover { color: var(--accent); }

/* Ligne « moyenne » / pied de balance */
.table-balance tfoot td { color: var(--text-muted); }

.table-preview td, .table-preview th { font-size: 12px; white-space: nowrap; }
.row-dup     { background: var(--warn-light) !important; }
.row-invalid { background: var(--debit-light) !important; color: var(--text-muted); }
.row-ignored { background: var(--bg-surface) !important; color: var(--text-muted); }
.row-inactive { opacity: .6; }
.row-current  { background: var(--accent-light); }

/* Aperçu de commission (classification des entrées) */
.commission-value { color: var(--info); font-weight: 500; white-space: nowrap; }

/* Avatars associés (cercle initiales) */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    background: var(--accent);
}

/* Écarts colorés */
.gap-credit  { color: var(--credit); font-weight: 500; }
.gap-deficit { color: var(--debit);  font-weight: 500; }
.gap-neutral { color: var(--text-muted); }

/* ---------- 9.5 Badges / pastilles ---------- */
.pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}
.pill-credit  { background: var(--credit-light); color: var(--credit); }
.pill-deficit { background: var(--debit-light);  color: var(--debit); }
.pill-warn    { background: var(--warn-light);   color: var(--warn); }
.pill-info    { background: var(--info-light);   color: var(--info); }
.pill-neutral { background: var(--bg-surface);   color: var(--text-muted); }

.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-surface);
    color: var(--text-muted);
}
.tag-admin { background: var(--accent); color: #fff; }

.count-badge {
    background: var(--bg-surface);
    color: var(--text-muted);
    border-radius: var(--radius-pill);
    padding: 3px 12px;
    font-size: 12px;
    font-weight: 500;
}

/* ---------- 9.5 Formulaires ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12px; color: var(--text-muted); }
.field-inline { flex-direction: column; }
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}
.filters .grow, .inline-form .grow { flex: 1; min-width: 180px; }

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%;
    padding: 7px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-sm);
}
/* Neutralise l'apparence native (coins arrondis / icône loupe) du champ de recherche. */
input[type=search] { -webkit-appearance: none; appearance: none; }
input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border: 1px solid var(--accent);
    box-shadow: 0 0 0 3px var(--accent-border);
}
input[type=file] { padding: 7px; font-size: 13px; }
select:disabled { background: var(--bg-surface); color: var(--text-light); }
/* Champ verrouillé : montant non éditable (valeur bancaire importée) */
.field-locked { display: flex; align-items: center; gap: 8px; padding: 7px 12px; font-size: 14px; font-weight: 500; color: var(--text-primary); background: var(--bg-surface); border: var(--border); border-radius: var(--radius-sm); }
.field-locked .lock-ico { font-size: 12px; opacity: .55; cursor: help; }
::placeholder { color: var(--text-light); }

.inline-form, .inline { display: inline-flex; gap: 10px; align-items: flex-end; margin: 0; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions-cell { white-space: nowrap; }

/* ---------- 9.5 Boutons ---------- */
.btn {
    display: inline-block;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.3;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    /* Secondaire par défaut */
    background: var(--bg-card);
    color: var(--text-primary);
    border: var(--border);
    transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.97); }
.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; border: 1px solid transparent; }
.btn-danger  { background: var(--debit);  color: #fff; border: 1px solid transparent; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid transparent; }
.btn-ghost:hover { background: var(--bg-surface); color: var(--text-primary); }

/* ---------- Messages flash ---------- */
.flash {
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 13px;
    border: 1px solid transparent;
}
.flash-success { background: var(--credit-light); color: var(--credit); }
.flash-error   { background: var(--debit-light);  color: var(--debit); }
.flash-info    { background: var(--info-light);   color: var(--info); }

/* ---------- Divers ---------- */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty { text-align: center; color: var(--text-muted); padding: 24px; }
.summary-list { list-style: none; padding: 0; display: flex; gap: 24px; flex-wrap: wrap; }
.summary-list .warn { color: var(--warn); }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; }
code {
    background: var(--bg-surface);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 16px; }
.page-link {
    padding: 5px 12px;
    border: var(--border);
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-card);
}
.page-link:hover { color: var(--text-primary); }
.page-link.is-active { background: var(--accent); color: #fff; border: 1px solid transparent; }

/* ---------- Onglets (classification : dépenses / entrées) ---------- */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: var(--border);
    margin-bottom: 16px;
}
.tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    margin-bottom: -1px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text-primary); }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-count {
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    background: var(--bg-surface);
    color: var(--text-muted);
}
.tab.is-active .tab-count { background: var(--accent-light); color: var(--accent); }

/* ---------- Pied de page ---------- */
.site-footer {
    border-top: var(--border);
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 12px;
    background: var(--bg-surface);
}

/* ---------- Page de connexion ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-page);
    padding: 20px;
}
.login-card {
    background: var(--bg-card);
    border: var(--border);
    border-radius: var(--radius-lg);
    padding: 32px 30px;
    width: 100%;
    max-width: 380px;
}
.login-title { margin: 0 0 4px; color: var(--accent); font-size: 20px; font-weight: 500; }
.login-subtitle { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }

/* ---------- Responsive (mobile < 768px, §9.1) ---------- */
@media (max-width: 768px) {
    /* Barre horizontale en haut avec logo + burger */
    .header-bar {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 14px;
        background: var(--bg-surface);
        border-bottom: var(--border);
        position: sticky;
        top: 0;
        z-index: 30;
    }
    /* Sidebar masquée par défaut, affichée en overlay */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 2px 0 16px rgba(0,0,0,0.3);
    }
    body.nav-open .sidebar { transform: translateX(0); }
    /* Voile derrière la sidebar ouverte */
    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 40;
    }
    body.nav-open .sidebar-backdrop { display: block; }
    .page-content { padding: 16px; }
    .page-head h1 { font-size: 20px; }

    /* Tableaux empilés en cartes (.table-stack) : chaque ligne devient une carte,
       chaque cellule affiche son intitulé via data-label. Réutilisable sur toute
       table porteuse de data-label (betanote #63). Les autres tables conservent
       le défilement horizontal de .table-wrap. */
    .table-stack { table-layout: auto; }
    .table-stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr {
        background: var(--bg-card);
        border: var(--border);
        border-radius: var(--radius-md);
        padding: 6px 12px;
        margin-bottom: 10px;
    }
    .table-stack tr:hover { background: var(--bg-card); }
    .table-stack td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 6px 0;
        border: none;
        border-bottom: 0.5px solid var(--bg-border);
        text-align: right;
        white-space: normal;
    }
    .table-stack tr td:last-child { border-bottom: none; }
    .table-stack td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: 11px;
        font-weight: 500;
        color: var(--text-muted);
        text-align: left;
    }
    .table-stack td.num { white-space: nowrap; }
    .table-stack .label-cell { max-width: none; }
}

/* =====================================================================
   Système de classification IA (classifier.php + classify.php)
   ===================================================================== */

/* Carte validation rapide IA */
.card-ai-validation {
    border-left: 3px solid var(--info);
}
.card-ai-validation .card-header-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.card-ai-validation h2 {
    margin: 0;
}

/* Compteur dans le titre de la section */
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: var(--info);
    color: #fff;
    font-size: 11px;
    font-weight: 500;
    border-radius: var(--radius-pill);
    vertical-align: middle;
}

/* Badges de confiance IA */
.conf-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 500;
}
.conf-high {
    background: var(--credit-light);
    color: var(--credit);
}
.conf-med {
    background: var(--warn-light);
    color: var(--warn);
}

/* Indice IA (hint) dans les libellés de la liste normale */
.ai-hint {
    display: block;
    font-style: italic;
    margin-top: 2px;
}
.ai-reason {
    font-style: italic;
}

/* Champ avec bouton révéler (clé API) */
.input-reveal-wrap {
    display: flex;
    gap: 6px;
    align-items: center;
}
.input-reveal-wrap input {
    flex: 1;
    font-family: monospace;
}
.field-hint {
    display: block;
    margin-top: 4px;
    font-size: 12px;
}
.field-hint.credit { color: var(--credit); }

/* Tableau de statut dans settings.php */
.settings-status-table td { padding: 8px 12px; vertical-align: middle; }
.settings-status-table td:first-child { font-weight: 500; width: 220px; }

/* Ligne inactive (règle désactivée) */
.row-muted td {
    opacity: 0.5;
}

/* Couleur danger pour les boutons de suppression */
.text-danger {
    color: var(--debit);
}

/* Grille de champs en ligne (formulaire règles) */
.form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.form-row .field {
    flex: 1;
    min-width: 160px;
}

/* Actions compactes dans un tableau */
.actions-row-sm {
    flex-wrap: nowrap;
    gap: 4px;
}
.actions-row-sm .btn {
    padding: 4px 8px;
    font-size: 12px;
}

/* =====================================================================
   Import progression SSE
   ===================================================================== */
.plog {
    max-height: 420px;
    overflow-y: auto;
    padding: 4px 0;
    font-size: 13px;
    line-height: 1.5;
}
.plog-entry {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 3px 0;
}
.plog-entry + .plog-entry {
    border-top: var(--border);
}
.plog-icon {
    min-width: 16px;
    text-align: center;
    font-style: normal;
    flex-shrink: 0;
}
.plog-entry.info    .plog-icon { color: var(--credit); }
.plog-entry.pending .plog-icon { color: var(--info);   animation: spin 1.2s linear infinite; display: inline-block; }
.plog-entry.warning .plog-icon { color: var(--warn);   }
.plog-entry.done    .plog-icon { color: var(--credit); }
.plog-entry.done    { font-weight: 500; }

@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.progress-done-panel {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* =====================================================================
   Classes extraites des attributs style="" inline (audit/nettoyage CSS)
   Convention du projet : aucun style inline dans le HTML, SAUF les valeurs
   calculées dynamiquement par PHP (couleurs de palette d'associé, nombre
   de colonnes de grille…), qui restent en inline.
   ===================================================================== */

/* ---- Utilitaires fonctionnels ---- */
.nowrap        { white-space: nowrap; }
.inline-action { display: inline; }          /* form d'1 bouton qui reste en ligne (à côté d'un lien) */
.is-hidden     { display: none !important; } /* état masqué piloté par JS (classList.toggle) */
.mt-20         { margin-top: 20px; }
.mb-20         { margin-bottom: 20px; }

/* ---- Cartes de formulaire (saisie / édition d'écriture, apporteurs) ---- */
.card-form { max-width: 680px; }

/* ---- Largeurs de champs de formulaire ---- */
.field-w160 { max-width: 160px; }
.field-w180 { max-width: 180px; }
.field-w200 { max-width: 200px; }
.field-w220 { max-width: 220px; }
.field-w280 { max-width: 280px; }
.field-w340 { max-width: 340px; }

/* ---- Ligne « Montant + TVA + aperçu HT » : alignée en haut, gap large ---- */
.form-row-top { gap: 16px; align-items: flex-start; }
.ht-preview   { padding-top: 24px; }   /* aperçu HT aligné sur la base des champs */

/* ---- Barre d'actions de formulaire (Enregistrer / Annuler) ---- */
.form-actions { margin-top: 24px; display: flex; gap: 10px; align-items: center; }

/* ---- Barre d'actions groupées : champ « Année facture » ---- */
.bulk-year-input { width: 170px; }

/* ---- Liste de cases à cocher empilées (paramètres : drapeaux dev) ---- */
.check-stack { display: flex; align-items: center; gap: 8px; margin: 8px 0; }

/* ---- Paragraphes / notes / listes resserrés ---- */
.note-tight  { margin-top: 0; }
.note-flush  { margin: 0; }
.form-intro  { margin: 0 0 16px; }
.dn-hint     { margin: 0 0 10px; }
.legend-list { margin: 0; padding-left: 18px; }

/* ---- Formulaire de suppression d'une note de dev (aligné à droite) ---- */
.dn-delete-form { margin-top: 4px; text-align: right; }

/* ---- Carte « zone dangereuse » (purge) ---- */
.card-danger  { border: 2px solid var(--debit); background: var(--debit-light); }
.danger-title { color: var(--debit); font-weight: 500; margin-bottom: 12px; }

/* =====================================================================
 * Formulaire de ventilation (betafeature #69 / betanotes #70 #73)
 * --------------------------------------------------------------------
 * Layout cible par ligne de ventilation :
 *   Libellé    : pleine largeur (seul)
 *   Montants   : Montant TTC (150px) | TVA (100px) | HT calculé (auto)
 *   Classif.   : Classification (flex:1) | Bénéficiaire (flex:1)
 *   Charge     : Type de charge (100%) — visible uniquement si company_expense
 *   Actions    : bouton Supprimer aligné à droite
 *
 * Responsive < 768px : tout en colonne unique.
 * Toutes les classes sont préfixées .vent-* pour éviter les collisions.
 * ===================================================================== */
.vent-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.vent-line {
    border: var(--border); border-radius: var(--radius-md); background: var(--bg-card);
    padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}
.vent-line.is-error { border-color: var(--debit); background: var(--debit-light); }

/* Lignes internes : 3 grilles distinctes + un footer flex pour l'action. */
.vent-row-label    { display: block; }
.vent-row-amounts  { display: grid; grid-template-columns: 150px 100px 1fr; gap: 10px; align-items: end; }
.vent-row-classify { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.vent-row-charge   { display: block; }
.vent-row-actions  { display: flex; justify-content: flex-end; margin-top: 2px; }

/* Cellule = mini-label + contrôle. La cellule remplit toute sa colonne de grille. */
.vent-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.vent-field-label {
    font-size: 10px; font-weight: 500; color: var(--text-light);
    letter-spacing: 0.04em; text-transform: uppercase;
}
.vent-field input, .vent-field select { width: 100%; box-sizing: border-box; }

/* HT calculé : zone en lecture seule alignée à droite, look discret. */
.vent-ht-preview {
    padding: 7px 12px; color: var(--text-muted); font-variant-numeric: tabular-nums;
    text-align: right; background: var(--bg-page); border: var(--border);
    border-radius: var(--radius-sm); min-width: 0;
}

/* Libellé : input pleine largeur (sans cellule = pas de mini-label décoratif). */
.vent-label-input { width: 100%; box-sizing: border-box; }

/* Bouton « supprimer cette ligne ». */
.vent-del-btn {
    background: transparent; border: var(--border); color: var(--debit);
    cursor: pointer; font-size: 13px; padding: 6px 14px; border-radius: var(--radius-sm);
}
.vent-del-btn:hover { background: var(--debit); color: #fff; border-color: var(--debit); }

/* État vide + erreurs + barre d'actions globales. */
.vent-empty {
    color: var(--text-muted); font-style: italic; padding: 16px; text-align: center;
    border: 1px dashed var(--bg-border); border-radius: var(--radius-md);
}
.vent-errors {
    background: var(--debit-light); color: var(--debit);
    border: 1px solid var(--debit); border-radius: var(--radius-sm);
    padding: 8px 12px; margin: 10px 0; font-size: 13px;
}
.vent-errors ul { margin: 4px 0 0 0; padding-left: 18px; }
.vent-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.vent-control {
    display: inline-flex; gap: 8px; align-items: center; margin-left: auto;
    font-size: 13px; font-weight: 500; padding: 5px 10px; border-radius: var(--radius-sm);
}
.vent-control.ok   { background: var(--credit-light); color: var(--credit); }
.vent-control.warn { background: var(--warn-light);   color: var(--warn); }
.vent-control.err  { background: var(--debit-light);  color: var(--debit); }
.vent-note { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* Responsive mobile : on retombe en colonne unique pour les grilles. */
@media (max-width: 768px) {
    .vent-row-amounts,
    .vent-row-classify { grid-template-columns: 1fr; }
    .vent-row-actions  { justify-content: stretch; }
    .vent-del-btn      { width: 100%; }
}
