/*
 * Registra — coque du back-office.
 *
 * Origine : sections sidebar / header / recherche / responsive de
 *   homeospirits-landing/project/main/static/css/admin.css (lignes 347-508,
 *   873-1130 et 1289-1510), portees telles quelles. Le reste d'admin.css
 *   appartient au registre « vitrine » (serif creme/or) qui est proscrit en
 *   gestion — il n'est pas repris.
 *
 * Ce fichier ne porte QUE la coque : enveloppe, sidebar, header, etats de
 * navigation, formulaires nus, messages. Tout le vocabulaire de donnees
 * (tableaux, pipeline, figures, cartes, chips, boutons) vit dans kit.css,
 * scope `.bm` — meme langage que le back-office de HoméoSpirits, et garde a
 * l'identique pour rester diffable avec lui.
 *
 * Aucun pipeline de build : CSS structurel ecrit a la main. Decision figee
 * (cf. memoire `feedback-tailwind-fige-en-dev`) — on ne melange pas les deux.
 */

/* ============================================================
 * 1. Tokens et socle
 * ============================================================ */

:root {
    /* Papier chaud — memes valeurs que les tokens --bm-* du kit */
    --rg-ground: #f6f2ea;
    --rg-surface: #fffdf9;
    --rg-ink: #211c17;
    --rg-ink-soft: #574e40;
    --rg-muted: #8f836c;
    --rg-line: #e8e1d3;
    --rg-line-soft: #f2ecde;
    --rg-accent: #926e3c;
    --rg-accent-ink: #6f5326;

    /* Sidebar (sombre) */
    --rg-sb-bg: #1e1813;
    --rg-sb-gold: #c79a5c;
    --rg-sb-text: #f6f2ea;

    /* Etats semantiques — promus en tokens (ils etaient disperses dans le kit) */
    --rg-ok: #2f6b45;
    --rg-ok-wash: #eaf3ed;
    --rg-warn: #8a6d1d;
    --rg-warn-wash: #f8f1dd;
    --rg-danger: #b0392b;
    --rg-danger-wash: #fbeceb;
    --rg-info: #1f4e5f;
    --rg-info-wash: #e8f0f3;
    --rg-neutral: #8f836c;
    --rg-neutral-wash: #f2ecde;

    /* Comptabilite : le debit et le credit ne sont pas une humeur, ils ont
       une couleur stable dans tout le logiciel. */
    --rg-debit: #1f4e5f;
    --rg-credit: #8a4b1d;

    /* Coque */
    --sb-w: 15rem;
    --sb-off: var(--sb-w);
    --sb-ease: cubic-bezier(0.4, 0, 0.2, 1);
    --hdr-h: 3.25rem;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--rg-ground);
    color: var(--rg-ink);
    font-family: "Poppins", system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; color: var(--rg-ink); font-weight: 600; }
p { margin: 0 0 0.75rem; }
a { color: var(--rg-accent-ink); }
img, svg, video, canvas { max-width: 100%; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(179, 139, 83, 0.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
 * 2. Enveloppe
 * ============================================================ */

.coque { display: flex; min-height: 100vh; }

.admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    width: var(--sb-w);
    background-color: var(--rg-sb-bg);
    border-right: 1px solid rgba(199, 154, 92, 0.12);
    transform: translateX(0);
    transition: transform 0.28s var(--sb-ease), box-shadow 0.28s var(--sb-ease);
    will-change: transform;
}

.admin-main {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--sb-off);
    transition: margin-left 0.28s var(--sb-ease);
}

html.sb-no-anim .admin-sidebar,
html.sb-no-anim .admin-main { transition: none !important; }

/* Repli desktop → plein ecran */
html.sb-collapsed { --sb-off: 0px; }
html.sb-collapsed .admin-sidebar { transform: translateX(-100%); }

.admin-content {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.5rem 1.75rem;
}

.sb-backdrop {
    position: fixed;
    inset: 0;
    z-index: 49;
    background: rgba(20, 16, 12, 0.55);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s var(--sb-ease);
}

/* ============================================================
 * 3. Sidebar — marque, groupes repliables, pied de profil
 * ============================================================ */

.sb-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sb-mark {
    width: 32px; height: 32px;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px;
    background: rgba(199, 154, 92, 0.16);
    color: var(--rg-sb-gold);
    font-size: 0.95rem;
}
.sb-brand .bt { line-height: 1.15; min-width: 0; }
.sb-brand .bt b {
    display: block;
    font-size: 0.84rem; font-weight: 600;
    color: var(--rg-sb-text);
}
.sb-brand .bt span {
    font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase;
    color: rgba(199, 154, 92, 0.8);
}

/* Selecteur d'entreprise — le cloisonnement est la premiere information
   de l'ecran : on sait toujours dans quelle comptabilite on ecrit. */
.sb-ent {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sb-ent-cur {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 9px;
    border-radius: 8px;
    background: rgba(199, 154, 92, 0.1);
    border: 1px solid rgba(199, 154, 92, 0.22);
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s;
}
.sb-ent-cur:hover { background: rgba(199, 154, 92, 0.18); border-color: rgba(199, 154, 92, 0.4); }
.sb-ent-cur i { color: var(--rg-sb-gold); font-size: 0.72rem; flex-shrink: 0; }
.sb-ent-cur .nm {
    flex: 1; min-width: 0;
    font-size: 0.74rem; font-weight: 600; color: var(--rg-sb-text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sb-ent-cur .sw { font-size: 0.6rem; color: rgba(199, 154, 92, 0.75); }

.sb-nav { flex: 1; overflow-y: auto; padding: 8px 8px 12px; }

.sbv-group { margin-bottom: 2px; }
.sbv-head {
    width: 100%;
    display: flex; align-items: center; gap: 9px;
    padding: 8px 10px;
    background: none; border: none; cursor: pointer;
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.69rem; font-weight: 600;
    letter-spacing: 0.1em; text-transform: uppercase;
    color: rgba(246, 242, 234, 0.55);
    transition: all 0.15s ease;
}
.sbv-head:hover { background: rgba(199, 154, 92, 0.1); color: var(--rg-sb-text); }
.sbv-head-ico { width: 15px; text-align: center; font-size: 0.78rem; color: var(--rg-sb-gold); opacity: 0.85; }
.sbv-head-title { flex: 1; text-align: left; }
.sbv-count { font-size: 0.62rem; font-weight: 600; letter-spacing: 0; color: rgba(246, 242, 234, 0.3); }
.sbv-chevron { font-size: 0.6rem; opacity: 0.6; transition: transform 0.22s ease; }
.sbv-group.is-open .sbv-chevron { transform: rotate(90deg); }

.sbv-body { overflow: hidden; max-height: 0; opacity: 0; transition: max-height 0.26s ease, opacity 0.2s ease; }
.sbv-group.is-open .sbv-body { max-height: 420px; opacity: 1; }

.sbv-link {
    display: flex; align-items: center; gap: 10px;
    padding: 7px 10px 7px 30px;
    margin: 1px 0;
    border-radius: 7px;
    font-size: 0.79rem; font-weight: 500;
    color: rgba(246, 242, 234, 0.55);
    text-decoration: none;
    transition: all 0.14s ease;
}
.sbv-link:hover { background: rgba(199, 154, 92, 0.1); color: var(--rg-sb-text); }
.sbv-link.active { background: rgba(199, 154, 92, 0.18); color: var(--rg-sb-text); box-shadow: inset 2px 0 0 var(--rg-sb-gold); }
.sbv-link i { width: 14px; text-align: center; font-size: 0.74rem; opacity: 0.7; }
.sbv-link.active i { opacity: 1; color: var(--rg-sb-gold); }

.sbv-badge {
    margin-left: auto;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px;
    background: #b38b53; color: #231d17;
    font-size: 0.64rem; font-weight: 700; line-height: 18px;
    text-align: center; flex-shrink: 0;
}
.sbv-link.active .sbv-badge { background: #d4a857; }

.sb-foot { border-top: 1px solid rgba(255, 255, 255, 0.06); padding: 11px 14px; }
.sb-foot-id { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.sb-ava {
    width: 30px; height: 30px; border-radius: 50%;
    background: rgba(199, 154, 92, 0.2); color: var(--rg-sb-gold);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.66rem; font-weight: 600; flex-shrink: 0;
}
.sb-foot .ft { line-height: 1.2; min-width: 0; }
.sb-foot .ft b { display: block; font-size: 0.74rem; font-weight: 500; color: var(--rg-sb-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-foot .ft span { font-size: 0.62rem; color: rgba(199, 154, 92, 0.8); }
.sb-foot-actions { display: flex; gap: 6px; }
.sb-foot-actions a {
    flex: 1; text-align: center; padding: 6px;
    border-radius: 6px;
    font-size: 0.7rem; color: rgba(246, 242, 234, 0.6);
    text-decoration: none; transition: all 0.14s ease;
}
.sb-foot-actions a:hover { background: rgba(255, 255, 255, 0.05); color: var(--rg-sb-text); }
.sb-foot-actions a.logout { color: rgba(248, 113, 113, 0.7); }
.sb-foot-actions a.logout:hover { background: rgba(239, 68, 68, 0.1); color: #fca5a5; }

/* ============================================================
 * 4. Header — fil d'Ariane, recherche, actions
 * ============================================================ */

.admin-header {
    position: sticky; top: 0; z-index: 30;
    min-height: var(--hdr-h);
    background: rgba(253, 250, 245, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid rgba(179, 139, 83, 0.15);
    padding: 0.75rem 1.75rem;
    display: flex; align-items: center; gap: 1rem;
}

.sb-toggle {
    flex-shrink: 0;
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 8px;
    border: 1px solid rgba(179, 139, 83, 0.28);
    background: transparent;
    color: rgba(35, 29, 23, 0.7);
    cursor: pointer; font-size: 0.9rem;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.sb-toggle:hover { background: rgba(179, 139, 83, 0.1); color: var(--rg-ink); border-color: rgba(179, 139, 83, 0.5); }
.sb-toggle:focus-visible { outline: 2px solid #b38b53; outline-offset: 2px; }
.sb-toggle .ico-mob, .sb-toggle .ico-mob-x { display: none; }
.sb-toggle .ico-desk { display: inline-block; transition: transform 0.28s var(--sb-ease); }
html.sb-collapsed .sb-toggle .ico-desk { transform: scaleX(-1); }

.sb-close { display: none; }
.hdr-brand { display: none; }

.crumb {
    display: flex; align-items: center;
    min-width: 0; flex: 1 1 auto;
    overflow: hidden; white-space: nowrap;
    font-size: 0.75rem; color: #8a7d65;
}
.crumb > a, .crumb > span { flex-shrink: 0; }
.crumb a { color: #8a7d65; text-decoration: none; transition: color 0.15s; }
.crumb a:hover { color: var(--rg-ink); }
.crumb i { font-size: 0.55rem; margin: 0 0.5rem; opacity: 0.4; }
.crumb .crumb-current { color: var(--rg-ink); font-weight: 500; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.hdr-actions { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

.admin-search { position: relative; }
.admin-search input {
    width: 18rem;
    padding: 0.4rem 0.75rem 0.4rem 2rem;
    font-family: inherit; font-size: 0.8rem;
    background: var(--rg-ground);
    border: 1px solid rgba(179, 139, 83, 0.2);
    border-radius: 0.375rem;
    color: var(--rg-ink);
    transition: all 0.15s;
}
.admin-search input:focus {
    outline: none;
    border-color: rgba(179, 139, 83, 0.5);
    box-shadow: 0 0 0 3px rgba(179, 139, 83, 0.12);
}
.admin-search .search-icon {
    position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%);
    font-size: 0.7rem; color: rgba(35, 29, 23, 0.4); pointer-events: none;
}
.admin-search-toggle { display: none; }

/* Exercice actif : rappele en permanence, parce qu'une saisie sur le mauvais
   exercice est une erreur qu'on ne voit qu'a la cloture. */
.hdr-exo {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    border: 1px solid rgba(179, 139, 83, 0.25);
    background: var(--rg-surface);
    font-size: 0.68rem; font-weight: 600; color: var(--rg-ink-soft);
}
.hdr-exo i { font-size: 0.62rem; color: var(--rg-accent); }
.hdr-exo.clos { border-color: rgba(176, 57, 43, 0.3); background: var(--rg-danger-wash); color: var(--rg-danger); }
.hdr-exo.clos i { color: var(--rg-danger); }

/* ============================================================
 * 5. Messages (django.contrib.messages)
 * ============================================================ */

.rg-messages { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.1rem; }
.rg-msg {
    display: flex; align-items: flex-start; gap: 0.6rem;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    border: 1px solid var(--rg-line);
    background: var(--rg-surface);
    font-size: 0.8rem; color: var(--rg-ink-soft);
}
.rg-msg i { font-size: 0.82rem; margin-top: 0.1rem; flex-shrink: 0; }
.rg-msg.success { border-color: rgba(47, 107, 69, 0.3); background: var(--rg-ok-wash); color: #1f4a2f; }
.rg-msg.success i { color: var(--rg-ok); }
.rg-msg.warning { border-color: rgba(138, 109, 29, 0.3); background: var(--rg-warn-wash); color: #6b5415; }
.rg-msg.warning i { color: var(--rg-warn); }
.rg-msg.error { border-color: rgba(176, 57, 43, 0.3); background: var(--rg-danger-wash); color: #8b2c21; }
.rg-msg.error i { color: var(--rg-danger); }
.rg-msg.info { border-color: rgba(31, 78, 95, 0.25); background: var(--rg-info-wash); color: #184050; }
.rg-msg.info i { color: var(--rg-info); }

/* ============================================================
 * 6. Formulaires nus (hors kit : login, ecrans d'authentification)
 * ============================================================ */

.rg-auth {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    padding: 2rem 1rem;
    background: var(--rg-sb-bg);
}
.rg-auth-card {
    width: 100%; max-width: 25rem;
    background: var(--rg-surface);
    border: 1px solid var(--rg-line);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(20, 16, 12, 0.45);
    padding: 2rem 1.75rem;
}
.rg-auth-mark {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 12px;
    background: rgba(146, 110, 60, 0.12);
    color: var(--rg-accent);
    font-size: 1.15rem;
    margin-bottom: 1rem;
}
.rg-auth-card h1 { font-size: 1.3rem; letter-spacing: -0.01em; }
.rg-auth-card .sub { font-size: 0.78rem; color: var(--rg-muted); margin: 0.3rem 0 1.5rem; }

.rg-field { margin-bottom: 0.9rem; }
.rg-field > label {
    display: block;
    font-size: 0.66rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--rg-muted);
    margin-bottom: 0.3rem;
}
.rg-field input[type="text"], .rg-field input[type="email"],
.rg-field input[type="password"], .rg-field input[type="number"],
.rg-field input[type="date"], .rg-field input[type="file"],
.rg-field select, .rg-field textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    font-family: inherit; font-size: 0.85rem;
    color: var(--rg-ink);
    background: #fff;
    border: 1px solid var(--rg-line);
    border-radius: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.rg-field input:focus, .rg-field select:focus, .rg-field textarea:focus {
    outline: none;
    border-color: var(--rg-accent);
    box-shadow: 0 0 0 3px rgba(146, 110, 60, 0.12);
}
.rg-field .help { font-size: 0.7rem; color: var(--rg-muted); margin-top: 0.25rem; }
.rg-field .err { font-size: 0.72rem; color: var(--rg-danger); margin-top: 0.25rem; }
.rg-field.has-error input, .rg-field.has-error select, .rg-field.has-error textarea { border-color: var(--rg-danger); }

/* ============================================================
 * 7. Tableaux : wrapper de defilement pose par coque.js
 * ============================================================ */

.tbl-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
}
.tbl-scroll > table { width: 100%; }
.tbl-scroll .bm-mono { white-space: nowrap; }

/* ============================================================
 * 8. Tablette / mobile — un seul point de rupture structurel
 * ============================================================ */

@media (max-width: 1023.98px) {
    :root { --sb-off: 0px; }

    .admin-sidebar {
        width: min(var(--sb-w), 86vw);
        transform: translateX(-100%);
        box-shadow: none;
        padding-bottom: env(safe-area-inset-bottom);
    }
    html.sb-open .admin-sidebar { transform: translateX(0); box-shadow: 24px 0 64px rgba(20, 16, 12, 0.45); }
    html.sb-open .sb-backdrop { opacity: 1; pointer-events: auto; }
    html.sb-open body { overflow: hidden; }
    .admin-main { margin-left: 0 !important; }

    .sb-toggle .ico-desk { display: none; }
    .sb-toggle .ico-mob { display: inline-block; }
    html.sb-open .sb-toggle .ico-mob { display: none; }
    html.sb-open .sb-toggle .ico-mob-x { display: inline-block; }

    .sb-brand { position: relative; padding-right: 44px; }
    .sb-close {
        display: inline-flex;
        position: absolute; top: 50%; right: 10px; transform: translateY(-50%);
        width: 32px; height: 32px;
        align-items: center; justify-content: center;
        border-radius: 7px; border: none;
        background: rgba(255, 255, 255, 0.05);
        color: rgba(246, 242, 234, 0.7);
        font-size: 0.9rem; cursor: pointer;
    }
    .sb-close:hover { background: rgba(255, 255, 255, 0.1); color: var(--rg-sb-text); }

    /* Cibles tactiles plus genereuses */
    .sbv-head { padding: 11px 10px; font-size: 0.72rem; }
    .sbv-link { padding: 10px 10px 10px 30px; font-size: 0.86rem; }
    .sbv-group.is-open .sbv-body { max-height: 520px; }
    .sb-foot-actions a { padding: 9px; font-size: 0.8rem; }

    .hdr-brand { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; text-decoration: none; color: var(--rg-ink); font-weight: 600; font-size: 0.8rem; }
    .admin-header { padding: 0.55rem 1rem; gap: 0.6rem; }
    .admin-content { padding: 1rem 1rem 1.5rem; }
    .hdr-exo { display: none; }

    /* Recherche : icone qui deploie un champ pleine largeur sous le header */
    .admin-search-toggle { display: inline-flex; }
    .admin-search {
        display: none;
        position: absolute; left: 0; right: 0; top: 100%;
        padding: 8px 12px 10px;
        background: #fdfaf5;
        border-bottom: 1px solid rgba(179, 139, 83, 0.2);
        box-shadow: 0 10px 24px rgba(35, 29, 23, 0.08);
    }
    .admin-header.is-search-open .admin-search { display: block; }
    .admin-search input { width: 100%; font-size: 16px; padding-left: 2.2rem; } /* 16px : evite le zoom iOS */
    .admin-search .search-icon { left: 1.5rem; }

    /* Largeur minimale selon le nombre de colonnes → defilement horizontal */
    .tbl-scroll.tbl-lg > table { min-width: 640px; }
    .tbl-scroll.tbl-xl > table { min-width: 880px; }

    /* Grilles « 1fr » du kit : empecher l'elargissement au contenu
       (min-width:auto des items → la piste 1fr s'etire sur la largeur d'un tableau) */
    .admin-main .bm-cols > *, .admin-main .bm-xpanel > *, .admin-main .bm-card,
    .admin-main .bm-card-b, .admin-main .bm-panel,
    .admin-main [style*="grid-template-columns"] > * { min-width: 0; max-width: 100%; }
    .admin-main .bm-cols { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (max-width: 767.98px) {
    .admin-main .bm-card-b[style*="grid-template-columns"],
    .admin-main .bm-card [style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
    .rg-cols-2, .rg-cols-3 { grid-template-columns: minmax(0, 1fr) !important; }
}

@media (max-width: 639.98px) {
    /* Fil d'Ariane : ne garder que les 3 derniers noeuds (parent › courant) */
    .crumb > * { display: none; }
    .crumb > *:nth-last-child(-n+3) { display: inline-block; }
    .crumb > *:nth-last-child(3) { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .admin-content { padding: 0.85rem 0.8rem 1.5rem; }
    .sb-toggle, .admin-search-toggle { width: 36px; height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
    .admin-sidebar, .admin-main, .sb-backdrop, .sb-toggle .ico-desk { transition: none !important; }
}

/* ============================================================
 * 9. Grilles d'agencement (le kit porte les composants, pas la page)
 * ============================================================ */

.rg-cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.rg-cols-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.rg-cols-side { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 1rem; align-items: start; }
@media (max-width: 1023.98px) { .rg-cols-side { grid-template-columns: minmax(0, 1fr); } }

/* Montants : le debit et le credit se lisent a la couleur, pas au libelle */
.rg-debit { color: var(--rg-debit); }
.rg-credit { color: var(--rg-credit); }

/* ============================================================
 * 10. Vocabulaire propre a Registra
 *
 * Le kit (kit.css) est garde byte-pour-byte identique a sa source pour
 * rester diffable. Les etats dont Registra a besoin — qui ne sont pas des
 * etats de commande — vivent donc ici, construits sur les memes tokens.
 * ============================================================ */

/* Etats semantiques : on nomme la SIGNIFICATION, pas la couleur, pour qu'un
   changement de palette n'oblige pas a relire les templates. */
.bm .bm-st-ok      { color: #2f7d4f; background: rgba(47, 125, 79, 0.12); }
.bm .bm-st-info    { color: #2563a8; background: rgba(37, 99, 168, 0.11); }
.bm .bm-st-warn    { color: #9a6a12; background: rgba(196, 140, 30, 0.12); }
.bm .bm-st-danger  { color: #b0392b; background: rgba(176, 57, 43, 0.10); }
.bm .bm-st-neutre  { color: #7a6f5c; background: rgba(122, 111, 92, 0.14); }
/* Donnee absente (SIREN vide, rien a afficher) : meme gris que le neutre,
   nomme a part parce qu'il dit « manquant » et non « sans etat ». */
.bm .bm-st-sans    { color: #7a6f5c; background: rgba(122, 111, 92, 0.14); }

/* Journaux comptables : la lettre du journal est une donnee, pas une etiquette
   d'etat — fond neutre, mono, largeur fixe pour que la colonne s'aligne. */
.bm .bm-jrn {
    display: inline-block; min-width: 2.1rem; text-align: center;
    padding: 0.14rem 0.4rem;
    border: 1px solid var(--bm-line);
    border-radius: 6px;
    background: var(--bm-wash);
    font-family: "JetBrains Mono", monospace;
    font-size: 0.68rem; font-weight: 600;
    color: var(--bm-ink-soft);
}

/* Numero de compte : toujours mono et jamais coupe, c'est une cle de lecture. */
.bm .bm-cpt { font-family: "JetBrains Mono", monospace; font-size: 0.78rem; color: var(--bm-ink-soft); white-space: nowrap; }
.bm .bm-cpt b { color: var(--bm-ink); font-weight: 600; }

/* Debit / credit : couleur stable dans tout le logiciel. Un zero ne s'ecrit
   pas — une cellule vide se lit plus vite qu'un « 0,00 » a ignorer. */
.bm .bm-table td.deb { text-align: right; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; color: var(--rg-debit); }
.bm .bm-table td.cre { text-align: right; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; color: var(--rg-credit); }
.bm .bm-table tr.tot td { background: var(--bm-wash); font-weight: 700; border-top: 1px solid var(--bm-line); border-bottom: none; }
.bm .bm-table tr.tot td.deb, .bm .bm-table tr.tot td.cre { font-weight: 700; }

/* Regroupement d'une piece sur plusieurs lignes : un liseré relie les lignes
   d'une meme ecriture, sinon un journal de 200 lignes est illisible. */
.bm .bm-table tr.piece-head td { border-top: 1px solid var(--bm-line); }
.bm .bm-table td.piece-cell { box-shadow: inset 2px 0 0 var(--bm-accent); background: color-mix(in srgb, var(--bm-wash) 55%, var(--bm-surface)); }

/* Controle d'equilibre : une balance fausse doit se voir depuis l'autre bout
   de la piece, pas se deviner en comparant deux nombres. */
.bm .bm-equ {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.7rem 0.9rem; margin-bottom: 1rem;
    border-radius: 10px;
    border: 1px solid rgba(47, 125, 79, 0.3);
    background: rgba(47, 125, 79, 0.07);
    font-size: 0.78rem; color: #26633f;
}
.bm .bm-equ i { font-size: 0.9rem; }
.bm .bm-equ.ko { border-color: rgba(176, 57, 43, 0.35); background: #fdf3f1; color: #8e2e22; }

/* Tuile de KPI avec courbe — le chiffre d'abord, la tendance ensuite. */
.bm-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; margin-bottom: 1.4rem; }
@media (max-width: 1023.98px) { .bm-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 479.98px) { .bm-kpis { grid-template-columns: minmax(0, 1fr); } }
.bm .bm-kpi {
    position: relative; overflow: hidden;
    padding: 0.8rem 0.95rem 0.5rem;
    background: var(--bm-surface);
    border: 1px solid var(--bm-line);
    border-radius: var(--bm-radius);
    box-shadow: var(--bm-shadow);
}
.bm .bm-kpi .k { display: flex; align-items: center; gap: 0.4rem; font-size: 0.62rem; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--bm-muted); }
.bm .bm-kpi .k i { color: var(--bm-accent); font-size: 0.68rem; }
.bm .bm-kpi .v { margin-top: 0.3rem; font-family: "JetBrains Mono", monospace; font-variant-numeric: tabular-nums; font-size: 1.35rem; font-weight: 700; line-height: 1.1; color: var(--bm-ink); }
.bm .bm-kpi .n { font-size: 0.68rem; color: var(--bm-muted); }
.bm .bm-kpi .spark { margin: 0.35rem -0.95rem -0.5rem; height: 42px; }

/* Cadre de graphique */
.bm .bm-graph { padding: 0.4rem 0.6rem 0.2rem; }
.bm .bm-graph-tall { min-height: 300px; }

/* Choix de l'entreprise — premier ecran apres la connexion quand on a acces
   a plusieurs comptabilites. */
.rg-ent-choix { display: flex; flex-direction: column; gap: 0.5rem; }
.rg-ent-choix a {
    display: grid; grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center; gap: 0.7rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--rg-line);
    border-radius: 10px;
    background: #fff;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.rg-ent-choix a:hover {
    border-color: var(--rg-accent);
    box-shadow: 0 4px 14px rgba(33, 28, 23, 0.07);
    transform: translateY(-1px);
}
.rg-ent-choix .ic {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px;
    background: rgba(146, 110, 60, 0.1);
    color: var(--rg-accent);
    font-size: 0.85rem;
}
.rg-ent-choix .tx { min-width: 0; }
.rg-ent-choix .tx b { display: block; font-size: 0.86rem; font-weight: 600; color: var(--rg-ink); }
.rg-ent-choix .tx small { font-size: 0.7rem; color: var(--rg-muted); }
.rg-ent-choix .go { font-size: 0.7rem; color: var(--rg-muted); }

/* ============================================================
 * 11. Champs — complements au kit
 *
 * Le kit habille deja tout champ nu dans `.bm` (`width: 100% !important`),
 * ce qui est le bon defaut pour un formulaire en carte : les widgets Django
 * n'ont aucune classe, et ils sont corrects sans qu'on y touche.
 *
 * Mais une barre d'outils n'est pas un formulaire : un filtre doit faire la
 * largeur de son contenu. Ces regles sont donc chargees APRES le kit et
 * portent le meme !important, faute de quoi elles ne gagneraient pas.
 * ============================================================ */

.bm .bm-toolbar > select, .bm .bm-toolbar > input, .bm .bm-toolbar > .bm-select,
.bm .bm-filtre > select, .bm .bm-filtre > input {
    width: auto !important;
    flex: 0 0 auto;
    min-width: 9rem;
}
.bm .bm-toolbar > input[type="date"], .bm .bm-filtre > input[type="date"] { min-width: 8.5rem; }

/* Libelle de champ : le kit le rend en minuscules douces ; en saisie
   comptable on veut un sur-titre, plus court a balayer en colonne. */
.bm .bm-field > label, .bm .bm-filtre > label {
    display: block;
    font-size: 0.62rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.07em !important;
    text-transform: uppercase !important;
    color: var(--bm-muted) !important;
    margin-bottom: 0.25rem;
}
.bm .bm-filtre { display: flex; flex-direction: column; gap: 0.1rem; }
.bm .bm-filtre > label { margin-bottom: 0; }
.bm .bm-field .err { font-size: 0.7rem; color: #b0392b; margin-top: 0.2rem; }
.bm .bm-field .aide { font-size: 0.7rem; color: var(--bm-muted); margin-top: 0.2rem; }
.bm .has-error input, .bm .has-error select, .bm .has-error textarea { border-color: #b0392b !important; }

/* Un champ de saisie numerique se lit en colonne : chiffres tabulaires. */
.bm input[type="number"], .bm input[type="date"] {
    font-family: "JetBrains Mono", ui-monospace, monospace !important;
    font-variant-numeric: tabular-nums;
}
.bm .bm-table input[type="number"] { text-align: right; }

/* Choix de l'entreprise — premier ecran apres la connexion quand on a acces
   a plusieurs comptabilites. */
.rg-ent-choix { display: flex; flex-direction: column; gap: 0.5rem; }
.rg-ent-choix a {
    display: grid; grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center; gap: 0.7rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--rg-line);
    border-radius: 10px;
    background: #fff;
    text-decoration: none;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.rg-ent-choix a:hover {
    border-color: var(--rg-accent);
    box-shadow: 0 4px 14px rgba(33, 28, 23, 0.07);
    transform: translateY(-1px);
}
.rg-ent-choix .ic {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 9px;
    background: rgba(146, 110, 60, 0.1);
    color: var(--rg-accent);
    font-size: 0.85rem;
}
.rg-ent-choix .tx { min-width: 0; }
.rg-ent-choix .tx b { display: block; font-size: 0.86rem; font-weight: 600; color: var(--rg-ink); }
.rg-ent-choix .tx small { font-size: 0.7rem; color: var(--rg-muted); }
.rg-ent-choix .go { font-size: 0.7rem; color: var(--rg-muted); }

/* ============================================================
 * 11. Champs Django rendus sans classe
 *
 * Les widgets Django n'ont aucune classe CSS. Plutot que d'ajouter un
 * `attrs={"class": ...}` sur chaque champ de chaque formulaire — qu'on
 * oubliera un jour — on habille les champs nus dans le scope du kit. Les
 * composants explicites du kit (.bm-search input, .bm-select) portent des
 * !important et gagnent donc sur ces regles.
 * ============================================================ */

.bm input[type="text"], .bm input[type="email"], .bm input[type="password"],
.bm input[type="number"], .bm input[type="date"], .bm input[type="search"],
.bm input[type="tel"], .bm input[type="url"], .bm input[type="file"],
.bm select, .bm textarea {
    padding: 0.45rem 0.6rem;
    font-family: "Poppins", system-ui, sans-serif;
    font-size: 0.8rem;
    color: var(--bm-ink);
    background: var(--bm-field);
    border: 1px solid var(--bm-line);
    border-radius: 9px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    max-width: 100%;
}
.bm input[type="number"], .bm input[type="date"] {
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-variant-numeric: tabular-nums;
}
.bm input:focus, .bm select:focus, .bm textarea:focus {
    border-color: var(--bm-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--bm-accent) 15%, transparent);
}
.bm select { cursor: pointer; }
.bm textarea { min-height: 5rem; line-height: 1.5; resize: vertical; }
.bm input[aria-invalid="true"], .bm .has-error input, .bm .has-error select { border-color: #b0392b; }
.bm input::placeholder, .bm textarea::placeholder { color: var(--bm-muted); }

/* Un champ etiquete, hors tableau. Le kit fournit .bm-field pour l'espacement ;
   ceci fournit le libelle. */
.bm .bm-field > label {
    display: block;
    font-size: 0.64rem; font-weight: 600;
    letter-spacing: 0.07em; text-transform: uppercase;
    color: var(--bm-muted);
    margin-bottom: 0.25rem;
}
.bm .bm-field > input, .bm .bm-field > select, .bm .bm-field > textarea { width: 100%; }
.bm .bm-field .err { font-size: 0.7rem; color: #b0392b; margin-top: 0.2rem; }
.bm .bm-field .aide { font-size: 0.7rem; color: var(--bm-muted); margin-top: 0.2rem; }

/* Barre de filtres : un champ etiquete qui reste sur une ligne. */
.bm .bm-filtre { display: flex; flex-direction: column; gap: 0.15rem; }
.bm .bm-filtre > label {
    font-size: 0.58rem; font-weight: 600;
    letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--bm-muted);
}

/* Retard, niveau 2 de la convention : liseré de ligne. Le kit ne le pose que
   sur `.bm-row` (lignes dépliables) ; en comptabilité les lignes en retard ne
   sont pas dépliables, d'où cette règle. */
.bm .bm-table tr.late > td:first-child { box-shadow: inset 3px 0 0 #b0392b; }
.bm .bm-table tr.late .bm-mono { font-weight: 600; }

/* ============================================================
 * 12. Matrice de permissions
 *
 * Vingt-et-une cases à cocher à plat sont illisibles. On les pose en grille,
 * groupées par domaine, chacune avec son libellé métier, son explication et
 * son code technique — ce dernier parce qu'il apparaît dans les journaux et
 * dans les messages de refus.
 * ============================================================ */

.bm .rg-perms {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(21rem, 1fr));
    gap: 0.55rem 1.1rem;
}
.bm .rg-perm {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.6rem;
    align-items: start;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--bm-line-soft);
    border-radius: 9px;
    background: var(--bm-surface);
    cursor: pointer;
    transition: border-color 0.14s, background 0.14s;
    margin-bottom: 0;
}
.bm .rg-perm:hover { border-color: var(--bm-line); background: var(--bm-wash); }
.bm .rg-perm input[type="checkbox"] {
    width: auto !important;
    margin-top: 0.15rem;
    accent-color: var(--bm-accent);
    cursor: pointer;
}
.bm .rg-perm > span { display: block; min-width: 0; }
.bm .rg-perm b {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--bm-ink);
    line-height: 1.25;
}
.bm .rg-perm em {
    display: block;
    font-style: normal;
    font-size: 0.7rem;
    color: var(--bm-muted);
    line-height: 1.35;
    margin-top: 0.1rem;
}
.bm .rg-perm code {
    display: inline-block;
    margin-top: 0.25rem;
    font-family: "JetBrains Mono", ui-monospace, monospace;
    font-size: 0.62rem;
    color: var(--bm-muted);
    background: var(--bm-wash);
    border-radius: 4px;
    padding: 0.05rem 0.3rem;
}

/* Un droit qui écrit se distingue à l'œil : on ne le coche pas par distraction. */
.bm .rg-perm-ecriture b { color: var(--rg-credit); }
.bm .rg-perm-ecriture:has(input:checked) {
    border-color: color-mix(in srgb, var(--rg-credit) 45%, var(--bm-line));
    background: color-mix(in srgb, var(--rg-credit) 5%, var(--bm-surface));
}
.bm .rg-perm:has(input:checked) {
    border-color: color-mix(in srgb, var(--bm-accent) 45%, var(--bm-line));
    background: var(--bm-wash);
}

/* Liste des droits d'un rôle, en consultation (fiche d'un membre). */
.bm .rg-droits { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.2rem; }
.bm .rg-droits li {
    font-size: 0.74rem;
    color: var(--bm-ink-soft);
    padding-left: 0.95rem;
    position: relative;
}
.bm .rg-droits li::before {
    content: "";
    position: absolute;
    left: 0; top: 0.42rem;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--bm-muted);
}
.bm .rg-droits li.ecriture::before { background: var(--rg-credit); }

/* Un formulaire réduit à un bouton, posé dans une cellule de tableau.
   (`.bm-inline-form` du kit est autre chose : une barre de saisie en grille.) */
.bm .rg-form-cell { display: inline-block; margin: 0; }

/* Le lien de retour ne doit pas coller au sur-titre de la page. */
.bm .bm-back { margin-bottom: 0.55rem; }

/* Les boutons d'action d'une ligne restent sur une ligne : repliés, ils
   doublent la hauteur de la rangée et cassent le balayage du tableau. */
.bm .bm-table td .bm-actions-inline { flex-wrap: nowrap; justify-content: flex-end; }

/* Avertissement non bloquant : un etat a connaitre qui n'est pas une erreur.
   Le kit n'a que `danger` (rouge), qui dirait a tort qu'il y a une faute —
   une plateforme non encore raccordee n'est pas une faute. */
.bm .bm-hint.warn { border-color: color-mix(in srgb, #c48c1e 35%, var(--bm-line)); background: #fdf9ef; color: #7e5a10; }

/* Deux colonnes de meme poids. `.bm-cols` du kit est asymetrique (contenu +
   colonne laterale de 330px) : il ne convient pas a deux panneaux de meme
   importance, comme l'etat d'un document et son cycle de vie. */
.bm .bm-duo { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
@media (max-width: 1100px) { .bm .bm-duo { grid-template-columns: 1fr; } }

/* Bloc de code / XML. Monospace, scroll contenu, cesure sur les longues
   chaines : un XML CII a des lignes de plusieurs centaines de caracteres et
   ferait deborder la page sans `overflow-x`. */
.bm .bm-pre {
    margin: 0; padding: 0.85rem 1rem;
    background: var(--bm-wash);
    border-top: 1px solid var(--bm-line-soft);
    font-family: "JetBrains Mono", monospace;
    font-size: 0.72rem; line-height: 1.5;
    color: var(--bm-ink-soft);
    white-space: pre; overflow: auto;
}

/* Empreinte (SHA-256, cle d'idempotence) : 64 caracteres qui doivent pouvoir
   se couper, sinon la cellule impose sa largeur a tout le tableau. */
.bm .bm-hash { font-family: "JetBrains Mono", monospace; font-size: 0.68rem; color: var(--bm-muted); word-break: break-all; }

/* --- Vague banque : rapprochement ---------------------------------------
   Un montant d'encaissement et un montant de décaissement ne se lisent pas de
   la même façon dans une colonne : sans distinction visuelle, on confond un
   virement reçu avec un prélèvement du même montant, et le rapprochement se
   fait à l'envers. Les deux classes existaient déjà pour la boutique, elles
   sont reprises telles quelles — cette section n'ajoute que ce qui manque.    */

/* Ligne de tableau portant un total ou un sous-total : le rapprochement a
   deux lignes de synthèse (écart expliqué, reste inexpliqué) qui doivent se
   détacher des lignes de décomposition. */
.bm .bm-table tr.bm-t-strong > td {
  font-weight: 600;
  background: var(--bm-wash, rgba(0, 0, 0, .025));
  border-top: 1px solid var(--bm-line, rgba(0, 0, 0, .1));
}

/* Formulaire en ligne dans un en-tête de carte : le bouton « défaire le
   rapprochement » vit à droite du titre, pas sur sa propre ligne. */
.bm .bm-card-h .bm-inline-form { display: inline-flex; margin: 0; }

/* --- Vague pilotage : tuiles d'indicateurs ------------------------------
   Une rangée de tuiles qui se réorganise seule plutôt qu'une grille à
   nombre de colonnes figé : le tableau de bord en porte sept, et une
   grille de quatre colonnes laisserait trois tuiles orphelines sur une
   seconde ligne à moitié vide.

   Écrit à la main dans la coque et non en utilitaires Tailwind : Registra
   n'a pas de pipeline Tailwind (décision figée, cf. CLAUDE.md racine).     */

.bm .pil-tuiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}

/* La tuile est une carte sans en-tête : le libellé est l'eyebrow, la valeur
   le contenu. Un bm-card-h ici ajouterait une bordure pour trois mots. */
.bm .pil-tuile {
  padding: 0.85rem 0.95rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

/* La valeur est en mono tabulaire : sept tuiles côte à côte dont les
   chiffres ne s'alignent pas se comparent à l'œil, mal. */
.bm .pil-tuile-v {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 1.22rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--bm-ink);
}

/* La courbe de tendance n'a ni axe ni grille : elle donne une direction, pas
   une valeur. Une hauteur fixe l'empêche de pousser la tuile au survol. */
.bm .pil-spark {
  height: 42px;
  margin: 0.2rem -0.35rem -0.3rem;
}

/* Un bm-hint dans une tuile reste un avertissement, mais il ne doit pas
   peser autant que dans une carte pleine largeur. */
.bm .pil-tuile .bm-hint {
  margin: 0.45rem 0 0;
  padding: 0.45rem 0.55rem;
  font-size: 0.7rem;
  line-height: 1.35;
}

/* Les graphiques ApexCharts : une largeur contrainte au conteneur, sinon un
   graphique à barres horizontales déborde de la carte sur petit écran. */
.bm .bm-card-b > [id^="g-"] {
  max-width: 100%;
  overflow: hidden;
}
