:root {
    --bg: #0f1115;
    --surface: #1a1d24;
    --surface-2: #232733;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #ff7a18;
    --ok: #3ecf8e;
    --ko: #ff5d5d;
    --radius: 10px;
    --max-width: 1100px;
}

* { box-sizing: border-box; }

/* Réserve la gouttière de scrollbar en permanence : quand une modale verrouille
   le défilement (overflow:hidden), la page ne se décale plus latéralement. */
html { scrollbar-gutter: stable; }

/* L'attribut hidden doit toujours l'emporter sur les display des classes
   (sinon un panneau en display:flex resterait visible alors qu'il est hidden). */
[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Accessibilité : focus visible au clavier */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Lien d'évitement (masqué jusqu'au focus clavier) */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 100;
    padding: .6rem 1rem;
    background: var(--accent);
    color: #1a1206;
    border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; text-decoration: none; }

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem 1rem;
    flex-wrap: wrap;
    padding: 1rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--surface-2);
}

.brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--text);
}

.site-nav {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .6rem 1.1rem;
}

.site-nav a { color: var(--muted); }
.site-nav a:hover { color: var(--text); }

/* Tag « Admin » à côté du nom du site : lien discret vers le back-office */
a.admin-tag-link { text-decoration: none; cursor: pointer; }
a.admin-tag-link:hover { filter: brightness(1.08); }

/* Bouton de déconnexion réduit à une icône */
.logout-btn { display: inline-flex; align-items: center; padding: 0; line-height: 0; color: var(--muted); }
.logout-btn:hover { color: var(--text); text-decoration: none; }
.logout-btn svg { display: block; }

/* Sous-menu déroulant de « Mon compte » (Référentiels = réglages) */
.nav-group { position: relative; display: inline-flex; align-items: center; gap: .15rem; }
.nav-group-toggle { display: inline-flex; align-items: center; }
/* Case à cocher cachée qui pilote l'ouverture du sous-menu sur mobile */
.nav-sub-cb { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
/* Chevron : purement décoratif sur desktop (le survol gère l'ouverture) */
.nav-sub-toggle { display: inline-flex; align-items: center; pointer-events: none; }
.nav-caret { font-size: .7em; line-height: 1; }
.nav-sub {
    position: absolute;     /* overlay : n'allonge pas la page */
    top: 100%;
    right: 0;               /* ancré sur le côté droit, sous « Mon compte » */
    min-width: 170px;
    display: none;
    flex-direction: column;
    gap: .1rem;
    margin-top: .35rem;
    padding: .4rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
    z-index: 1000;
}
/* Pont invisible pour garder le survol entre le bouton et le panneau */
.nav-group::after { content: ''; position: absolute; top: 100%; right: 0; width: 170px; height: .5rem; }
.nav-group:not(:hover):not(:focus-within)::after { display: none; }
.nav-group:hover .nav-sub,
.nav-group:focus-within .nav-sub { display: flex; }
.nav-sub a { padding: .45rem .6rem; border-radius: 6px; white-space: nowrap; }
.nav-sub a:hover { background: var(--surface-2); color: var(--text); }

/* Bouton hamburger (masqué sur desktop) */
.nav-toggle-cb { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.nav-toggle { display: none; }

/* Lien réel dans une cellule de tableau (accessibilité clavier) */
.row-link { color: var(--text); font-weight: 600; }
.row-link:hover { color: var(--accent); }

@media (max-width: 640px) {
    .site-header { padding: .8rem 1rem; gap: .5rem; }
    .site-main { padding: 1.25rem 1rem; }

    /* Hamburger visible */
    .nav-toggle {
        display: inline-flex;
        flex-direction: column;
        justify-content: center;
        gap: 5px;
        width: 42px;
        height: 42px;
        margin-left: auto;
        padding: 9px;
        border: 1px solid var(--surface-2);
        border-radius: 8px;
        cursor: pointer;
        background: var(--bg);
    }
    .nav-toggle span {
        display: block;
        height: 2px;
        width: 100%;
        background: var(--text);
        border-radius: 2px;
        transition: transform .2s, opacity .2s;
    }
    .nav-toggle-cb:focus-visible ~ .nav-toggle { outline: 2px solid var(--accent); outline-offset: 2px; }

    /* Menu déroulant en colonne, pleine largeur */
    .site-nav {
        order: 3;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height .25s ease;
    }
    .nav-toggle-cb:checked ~ .site-nav { max-height: 80vh; }

    .site-nav a,
    .site-nav .inline-form .link-btn {
        display: block;
        width: 100%;
        padding: .85rem .25rem;
        border-top: 1px solid var(--surface-2);
        text-align: left;
    }
    .site-nav .inline-form { display: block; width: 100%; }

    /* Sous-menu : REPLIÉ par défaut, ouvert au tap du chevron (case à cocher) */
    .nav-group { display: block; }
    .nav-group::after { display: none; }            /* pas de pont de survol sur mobile */
    .nav-sub {
        position: static;
        display: none;                              /* fermé par défaut */
        min-width: 0;
        margin-top: 0;
        padding: 0;
        border: 0;
        box-shadow: none;
        background: transparent;
    }
    /* Le survol ne doit pas ouvrir sur mobile : seul l'état coché ouvre */
    .nav-group:hover .nav-sub,
    .nav-group:focus-within .nav-sub { display: none; }
    .nav-sub-cb:checked ~ .nav-sub { display: flex; }
    .nav-sub a { padding-left: 1.5rem; }
    /* Chevron : vraie cible tactile à droite de « Mon compte » */
    .nav-sub-toggle {
        position: absolute;
        top: 0;
        right: 0;
        width: 3rem;
        height: 2.9rem;
        justify-content: center;
        pointer-events: auto;
        cursor: pointer;
        color: var(--muted);
    }
    .nav-sub-cb:checked ~ .nav-sub-toggle .nav-caret { transform: rotate(180deg); }

    /* Croix animée quand ouvert */
    .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
    .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(2) { opacity: 0; }
    .nav-toggle-cb:checked ~ .nav-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

    .lang-switch {
        border-left: 0;
        padding-left: .25rem;
        padding-top: .85rem;
        padding-bottom: .25rem;
        border-top: 1px solid var(--surface-2);
        gap: 1rem;
    }
}

.lang-switch {
    display: inline-flex;
    gap: .5rem;
    padding-left: 1rem;
    border-left: 1px solid var(--surface-2);
}
.lang-switch a { font-size: .85rem; }
.lang-switch a.active { color: var(--accent); font-weight: 700; }

.site-main {
    flex: 1;
    width: 100%;
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.hero h1 { margin: 0 0 .25rem; font-size: 2rem; }
.hero .tagline { color: var(--muted); margin: 0 0 1rem; }
.hero-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1.5rem; }

/* ===== Tableau de bord ===== */
.stat-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin-bottom: 1.5rem;
}
.stat {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.stat-value { font-size: 1.6rem; font-weight: 700; white-space: nowrap; }
/* Devise en petit, alignée en bas de ligne (évite les retours à la ligne) */
.cur { font-size: .5em; font-weight: 600; color: var(--muted); margin-left: .25em; vertical-align: baseline; }

/* Bouton « Filtres ✕ » (effacer les filtres) : rouge très foncé, même
   gabarit que les selects de la barre de filtres. */
.filter-clear {
    display: inline-flex;
    align-items: center;
    padding: .5rem .7rem;
    border: 1px solid #6e1d1d;
    border-radius: 8px;
    font-size: inherit;
    line-height: 1.5;
    background: #4a1212;
    color: #f3c9c9;
}
.filter-clear:hover { background: #5e1717; border-color: #8a2525; color: #fff; text-decoration: none; }
.filter-clear .x-red { color: #ff9b9b; font-weight: 700; margin-left: .2em; }
.stat-label { color: var(--muted); font-size: .85rem; }
.stat-sub { color: var(--muted); font-size: .75rem; }

.dash-cols {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: 1fr 1fr;
    align-items: start;
}
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.rank-list li {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 0;
    border-top: 1px solid var(--surface-2);
}
.rank-list li:first-child { border-top: 0; }
.rank-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
a.rank-name:hover { color: var(--accent); }
.rank-stat { white-space: nowrap; }

@media (max-width: 640px) {
    .dash-cols { grid-template-columns: 1fr; }
}

.status-card {
    margin-top: 2rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.status-card h2 { margin-top: 0; font-size: 1.1rem; }
.status-card ul { list-style: none; margin: 0; padding: 0; }
.status-card li { padding: .25rem 0; }
.status-card li.ok::before  { content: "● "; color: var(--ok); }
.status-card li.ko::before  { content: "● "; color: var(--ko); }

.site-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem 1rem;
    padding: 1rem 1.5rem;
    color: var(--muted);
    font-size: .8rem;
    border-top: 1px solid var(--surface-2);
}
.footer-right { display: inline-flex; align-items: center; gap: 1rem; }
/* Sélecteur de langue par drapeaux (SVG) dans le footer */
.footer-lang { display: inline-flex; align-items: center; gap: .5rem; }
.footer-lang a { display: inline-flex; opacity: .45; border-radius: 2px; transition: opacity .15s ease; }
.footer-lang a:hover { opacity: .85; }
.footer-lang a.active { opacity: 1; outline: 1.5px solid var(--accent); outline-offset: 1px; }
.footer-lang img { display: block; height: 14px; width: auto; border-radius: 1px; }

/* Formulaire de déconnexion inline dans la nav */
.inline-form { display: inline; margin: 0; }
.link-btn {
    background: none;
    border: 0;
    padding: 0;
    color: var(--muted);
    font: inherit;
    cursor: pointer;
}
.link-btn:hover { color: var(--text); text-decoration: underline; }

/* Messages flash */
.flash-zone { margin-bottom: 1.5rem; display: grid; gap: .5rem; }
.flash {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
}
.flash-success { background: rgba(62, 207, 142, .12); border-color: var(--ok); color: var(--ok); }
.flash-error   { background: rgba(255, 93, 93, .12); border-color: var(--ko); color: var(--ko); }
.flash-text { flex: 1 1 auto; }
.flash-link {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 700;
    color: inherit;
    text-decoration: underline;
}
.flash-close {
    flex: 0 0 auto;
    background: none;
    border: 0;
    color: inherit;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    opacity: .7;
    padding: 0 .15rem;
}
.flash-close:hover { opacity: 1; }

/* Cartes & formulaires */
.muted { color: var(--muted); }

.auth-card {
    max-width: 420px;
    margin: 1rem auto;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.auth-card h1 { margin-top: 0; }
.auth-alt { margin-top: 1rem; color: var(--muted); font-size: .9rem; }

.form { display: grid; gap: 1rem; }
.form label { display: grid; gap: .35rem; }
.form label > span { font-size: .85rem; color: var(--muted); }
.form input,
.form select {
    width: 100%;
    padding: .6rem .75rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.form input:focus,
.form select:focus { outline: none; border-color: var(--accent); }

.btn {
    display: inline-block;
    padding: .6rem 1.1rem;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn-primary { background: var(--accent); color: #1a1206; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--ko); color: #2a0a0a; }
.btn-danger:hover { filter: brightness(1.08); }

.account-grid {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    align-items: start;
}
/* Espacement régulier entre les grandes sections de la page Mon compte */
.account > .card,
.account > .account-grid { margin-bottom: 1.25rem; }
.account > .card:last-child { margin-bottom: 0; }
/* En-tête de carte : titre + description courte */
.card-head { margin-bottom: 1rem; }
.card-head h2 { margin: 0; }
.card-desc { margin: .25rem 0 0; }
/* Formulaire « danger » sur une ligne : champ + bouton alignés en bas */
.form-inline-end { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .9rem; }
.form-inline-end > label { flex: 1 1 220px; }
.form-inline-end .btn { flex: 0 0 auto; }
.card {
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }
.card-danger { border-color: rgba(255, 93, 93, .4); }

/* ===== Clés d'API ===== */
.api-key-new {
    border: 1px solid var(--primary, #6c8cff);
    border-radius: var(--radius);
    background: rgba(108, 140, 255, .08);
    padding: .9rem 1rem;
    margin-bottom: 1rem;
}
.api-key-new > p { margin: 0 0 .4rem; }
.api-key-reveal { position: relative; }
.api-key-secret {
    width: 100%;
    padding: .6rem 5.5rem .6rem .75rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .85rem;
    cursor: pointer;
    text-overflow: ellipsis;
}
.api-key-secret:focus { outline: none; border-color: var(--accent); }
/* Indice « Copier » dans le champ ; passe en « Copié » après le clic (classe .copied). */
.api-key-copy-hint {
    position: absolute;
    top: 50%;
    right: .6rem;
    transform: translateY(-50%);
    pointer-events: none;
    font-size: .8rem;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.api-key-reveal.copied .api-key-copy-hint { color: var(--muted); }
.api-key-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.api-key-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem .9rem;
    padding: .7rem 0;
    border-top: 1px solid var(--surface-2);
}
.api-key-item:first-child { border-top: 0; }
.api-key-info { display: flex; flex-wrap: wrap; align-items: baseline; gap: .35rem .6rem; min-width: 0; }
.api-key-label { font-weight: 600; }
.api-key-prefix { font-size: .8rem; opacity: .85; }
.api-key-empty { margin-top: 0; }

/* ===== 2FA & passkeys ===== */
.twofa-backup-count { margin: .2rem 0 1rem; }
.twofa-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.twofa-action-form { display: none; }           /* ne porte que des champs cachés (soumis via la popup) */
.pwd-panel { text-align: left; }
.pwd-panel h2 { margin: 0; font-size: 1.05rem; }
/* En-tête de la zone des codes de secours : titre + bouton « Copier » */
.backup-codes-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.backup-codes-head p { margin: 0; }
/* Passkeys : liste + ajout (même structure visuelle que les clés d'API) */
.passkey-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.passkey-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .5rem .9rem;
    padding: .7rem 0;
    border-top: 1px solid var(--surface-2);
}
.passkey-item:first-child { border-top: 0; }
.passkey-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.passkey-label { font-weight: 600; }
.passkey-empty { margin: 0 0 1rem; }
.passkey-error { color: var(--ko); margin: 0 0 .75rem; }
/* Formulaire d'ajout : séparé de la liste, aligné en bas (champ + bouton) */
.passkey-add { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--surface-2); }
.passkey-add + p { margin: .6rem 0 0; }
/* Connexion par passkey : séparateur « ou » + bouton pleine largeur */
.passkey-login { margin-top: 1.25rem; }
.btn-block { display: block; width: 100%; text-align: center; }
.auth-sep {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: .85rem;
}
.auth-sep::before, .auth-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--surface-2);
}
/* Pastille de statut à côté du titre d'une carte (2FA activé/désactivé, « bientôt »…) */
.head-badge {
    display: inline-block;
    margin-left: .5rem;
    padding: .1rem .5rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    vertical-align: middle;
}
.head-badge.badge-soon,
.head-badge.badge-off { background: var(--surface-2); color: var(--muted); }
.head-badge.badge-on { background: rgba(62, 207, 142, .18); color: var(--ok); }
.backup-codes-new ul.backup-codes {
    list-style: none;
    margin: .6rem 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: .35rem .75rem;
}
.backup-codes code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .9rem;
    letter-spacing: .04em;
}
/* Popup 2FA (réutilise .confirm-modal/.confirm-panel pour le positionnement) */
.twofa-panel { width: min(460px, 100%); text-align: left; }
.twofa-panel h2 { margin: 0; font-size: 1.15rem; }
.twofa-steps { margin: 0; padding-left: 1.2rem; display: grid; gap: .25rem; }
.twofa-qr { display: flex; justify-content: center; }
.twofa-qr svg { width: 200px; height: auto; max-width: 100%; border-radius: 8px; }
.twofa-secret-line { margin: 0; text-align: center; }
.twofa-secret {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    letter-spacing: .12em;
    user-select: all;
}
.twofa-error { color: var(--ko); }

/* ===== Référentiels ===== */
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { margin: 0 0 .25rem; }
.page-head .muted { margin: 0; }

/* Barre d'onglets */
.tab-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    border-bottom: 1px solid var(--surface-2);
    margin-bottom: 1.25rem;
}
.tab-link {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .65rem 1rem;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    border-radius: 8px 8px 0 0;
}
.tab-link:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.tab-link.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
.tab-count {
    font-size: .72rem;
    min-width: 1.4rem;
    padding: .05rem .35rem;
    text-align: center;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
}
.tab-link.active .tab-count { background: var(--accent); color: #1a1206; }

/* Sans JS : les panneaux s'affichent empilés avec un titre. */
.tab-panel { margin-bottom: 2rem; }
.tab-panel::before {
    content: attr(aria-label);
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: .75rem;
}
/* Avec JS : mode onglets, un seul panneau visible, sans titre redondant. */
.js-tabs .tab-panel { display: none; margin-bottom: 0; }
.js-tabs .tab-panel.active { display: block; }
.js-tabs .tab-panel::before { display: none; }

/* Barre d'ajout */
.add-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}
.field { display: grid; gap: .3rem; }
.field > span { font-size: .8rem; color: var(--muted); }
.field input {
    padding: .55rem .7rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }
.field-name { flex: 1 1 12rem; }
.field-weight { flex: 0 0 8rem; }
.field-weight input { width: 100%; }
/* Sélecteur de poids cible : liste déroulante custom + saisie « Personnalisé » */
.field-target { flex: 0 0 10rem; }
.weight-select { position: relative; width: 100%; }

/* Déclencheur (mode quantité) façon menu déroulant */
.weight-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem .7rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.weight-trigger:hover { border-color: #3a4254; }
.weight-trigger:focus { outline: none; border-color: var(--accent); }
.weight-trigger-label { font-weight: 600; }
.weight-trigger .weight-chev { margin-left: auto; color: var(--muted); }

/* Saisie libre : la flèche vit DANS le champ (à droite) et rouvre la liste */
.weight-custom { position: relative; display: block; }
.weight-custom .weight-input { width: 100%; padding-right: 2.2rem; }
.weight-back {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 2.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: none;
    border: 0;
    color: var(--muted);
    cursor: pointer;
}
.weight-back:hover { color: var(--text); }

.weight-chev { width: 1.1em; height: 1.1em; flex: 0 0 auto; transition: transform .15s ease; }
.weight-trigger[aria-expanded="true"] .weight-chev,
.weight-back[aria-expanded="true"] .weight-chev { transform: rotate(180deg); }

/* Liste déroulante : position « fixed » calculée en JS pour passer DEVANT la
   modale d'édition (qui a overflow-y:auto) sans la redimensionner ni être rognée. */
.weight-list {
    position: fixed;
    z-index: 1100;
    margin: 0;
    padding: .35rem;
    list-style: none;
    background: var(--surface-2);
    border: 1px solid #2f3545;
    border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
.weight-opt {
    width: 100%;
    display: block;
    padding: .45rem .6rem;
    background: none;
    border: 0;
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.weight-opt:hover,
.weight-opt.active { background: rgba(255, 255, 255, .07); }
.weight-opt.is-current { color: var(--accent); font-weight: 600; }

/* Liste des éléments */
.ref-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.ref-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: .65rem 1rem;
}
.ref-item-name { font-weight: 600; }
.badge {
    font-size: .75rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
}
.badge-archived { margin-left: .5rem; vertical-align: middle; }
/* Pastilles de poids (types de bobine) : icône + valeur, plus lisibles */
.badge-weight {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    background: var(--surface-2);
    color: var(--text);
    font-weight: 600;
}
.badge-ico { width: 1em; height: 1em; flex: 0 0 auto; opacity: .85; }
/* Pastille « carton » : même forme que les poids, teinte kraft discrète */
.badge-cardboard { background: #3a3022; color: #e6cfa6; }
/* Case « bobine en carton » : toggle encadré avec case personnalisée (la case
   native est masquée). Même hauteur que les champs, aligné en bas dans la barre
   d'ajout et propre en ligne dans le formulaire d'édition. */
.field-check {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    align-self: end;
    width: max-content;
    padding: .55rem .7rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.field-check:hover { border-color: #3a4254; }
/* La case native pilote l'état mais reste invisible (accessible au clavier). */
.field-check input[type="checkbox"] { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.field-check-box {
    flex: none;
    width: 1.15rem;
    height: 1.15rem;
    border: 1.5px solid var(--surface-2);
    border-radius: 5px;
    background: var(--surface);
    position: relative;
    transition: background .12s ease, border-color .12s ease;
}
.field-check-box::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 46%;
    width: .3rem;
    height: .58rem;
    border: solid #1a1206;
    border-width: 0 2px 2px 0;
    transform: translate(-50%, -50%) rotate(45deg);
    opacity: 0;
    transition: opacity .1s ease;
}
.field-check input:checked + .field-check-box { background: var(--accent); border-color: var(--accent); }
.field-check input:checked + .field-check-box::after { opacity: 1; }
.field-check:has(input:checked) { border-color: var(--accent); }
.field-check input:focus-visible + .field-check-box { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Onglet « types de bobine » : beaucoup de champs → on resserre pour tenir sur une ligne. */
.add-bar-dense .field-name { flex: 1 1 6rem; min-width: 0; }
.add-bar-dense .field-name input { min-width: 0; }
.add-bar-dense .field-weight { flex: 0 0 6.5rem; }
.add-bar-dense .field-target { flex: 0 0 9rem; }
/* Référentiels système affichés côté utilisateur (lecture seule) */
.ref-sub { margin: 1.25rem 0 .5rem; font-size: .85rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
/* Référentiels système atténués. On dégrade le nom + les pastilles plutôt que
   tout le <li> : un opacity sur le conteneur créerait un contexte d'empilement
   qui piégerait la pop d'édition (modale) derrière les lignes suivantes. */
.ref-item-system > .ref-item-name,
.ref-item-system > .badge { opacity: .8; }
/* Référentiels système désactivés (masqués des sélections) : plus estompés. */
.ref-list-disabled { margin-top: .5rem; }
.ref-item-disabled > .ref-item-name,
.ref-item-disabled > .badge { opacity: .5; }
/* Modale d'avertissement avant désactivation : liste des bobines + actions. */
.disable-spool-list { margin: .25rem 0 .5rem; padding-left: 1.1rem; display: grid; gap: .2rem; max-height: 40vh; overflow-y: auto; }
.disable-spool-list a { color: var(--accent); }
.pop-actions { display: flex; justify-content: flex-end; gap: .5rem; align-items: center; margin-top: .25rem; }
.badge-default { background: var(--accent); color: #1a1206; }
.ref-item-actions { margin-left: auto; display: flex; gap: .4rem; align-items: center; }

/* Édition repliée (élément <details>) */
.edit-pop { position: relative; }
.edit-pop > summary {
    list-style: none;
    cursor: pointer;
    user-select: none;
}
.edit-pop > summary::-webkit-details-marker { display: none; }
.edit-form {
    position: absolute;
    right: 0;
    top: calc(100% + .4rem);
    z-index: 10;
    display: grid;
    gap: .6rem;
    width: max-content;
    min-width: 14rem;
    background: var(--surface-2);
    border: 1px solid #2f3545;
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 12px 30px rgba(0, 0, 0, .4);
}

/* Popover d'édition/fusion présenté en modale centrée avec voile sombre. */
.edit-pop[open]::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    z-index: 1000;
    animation: confirm-fade .16s ease both;
}
.edit-pop[open] > .edit-form {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    z-index: 1001;
    width: min(420px, 92vw);
    max-height: 85vh;
    overflow-y: auto;
    animation: edit-pop-in .2s cubic-bezier(.2, .8, .25, 1) both;
}
/* L'animation conserve le centrage par translate (sinon transform:none décale le panneau). */
@keyframes edit-pop-in {
    from { opacity: 0; transform: translate(-50%, -50%) scale(.96); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}
body.pop-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) {
    .edit-pop[open]::before, .edit-pop[open] > .edit-form { animation: none; }
}

.empty-state {
    color: var(--muted);
    text-align: center;
    padding: 1.5rem;
    border: 1px dashed var(--surface-2);
    border-radius: var(--radius);
}

/* Boutons compacts / fantômes */
.btn-small { padding: .4rem .75rem; font-size: .85rem; }
.btn-ghost {
    background: transparent;
    border: 1px solid var(--surface-2);
    color: var(--muted);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger-ghost:hover { color: var(--ko); border-color: var(--ko); }

@media (max-width: 560px) {
    .ref-item-actions { margin-left: 0; width: 100%; justify-content: flex-end; }
    .edit-form { left: 0; right: auto; }
}

/* ===== Filaments ===== */
.page-head-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.head-actions { display: flex; gap: .4rem; align-items: center; }

/* Formulaire */
.field select {
    width: 100%;
    padding: .55rem .7rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.field select:focus { outline: none; border-color: var(--accent); }
.field input[type="color"] {
    width: 100%;
    height: 2.6rem;
    padding: .2rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
}
.field input[type="file"] { color: var(--muted); font-size: .9rem; }

.field-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.form-actions { display: flex; justify-content: flex-end; gap: .5rem; }
.current-photo { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.photo-thumb {
    width: 84px; height: 84px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--surface-2);
}
.checkbox { display: inline-flex; align-items: center; gap: .4rem; color: var(--muted); }

/* Case à cocher dans un .form : ligne case + libellé (et non la grille verticale
   héritée de .form label, ni l'input pleine largeur). */
.form label.checkbox { display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.form .checkbox input[type="checkbox"] { width: auto; margin: 0; flex: none; accent-color: var(--accent); }

/* Grille de cartes */
.filament-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.filament-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--text);
    transition: border-color .15s, transform .15s;
}
.filament-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-2px); }
.filament-visual {
    position: relative;
    aspect-ratio: 1 / 1;
    background: var(--swatch, #444);
    background-size: cover;
    background-position: center;
    overflow: hidden;
}
/* Image en absolu : la hauteur de la zone vient du ratio, jamais de l'image.
   La vignette garde donc la même taille en mode Images et en mode Couleur. */
.filament-visual .visual-photo {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Pastille de couleur dans le coin (mode images) */
.color-dot {
    position: absolute;
    top: .5rem;
    right: .5rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .85);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
.color-dot-lg { width: 1.75rem; height: 1.75rem; top: .75rem; right: .75rem; }

/* Pastille d'identifiant sur la vignette (lisible sur photo ET fond couleur) */
.fil-id-badge {
    position: absolute;
    top: .5rem;
    left: .5rem;
    z-index: 1;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 700;
    font-size: .75rem;
    line-height: 1;
    padding: .25rem .4rem;
    border-radius: 6px;
    color: #fff;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(2px);
}

/* Surlignage de la carte/ligne ciblée au retour depuis une fiche (#fil-{id}) */
.filament-card, .data-table tbody tr { scroll-margin-top: 1rem; }
.filament-card:target { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.data-table tbody tr:target { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Bascule Images / Couleur */
.view-toggle {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1rem;
}
.segmented {
    display: inline-flex;
    border: 1px solid var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}
.segmented button {
    background: var(--surface);
    border: 0;
    color: var(--muted);
    font: inherit;
    padding: .4rem .9rem;
    cursor: pointer;
}
.segmented button.active { background: var(--accent); color: #1a1206; font-weight: 600; }

/* Mode couleur : on masque la photo (le fond --swatch reste visible) et la pastille */
.mode-color .visual-photo,
.mode-color .color-dot { display: none; }

/* Barre de filtres */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin-bottom: 1rem;
}
.filter-bar input[type="search"],
.filter-bar select {
    padding: .5rem .7rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.filter-bar input[type="search"]:focus,
.filter-bar select:focus { outline: none; border-color: var(--accent); }
.filter-search { flex: 1 1 12rem; min-width: 0; }

@media (max-width: 560px) {
    .filter-bar { gap: .5rem; }
    .filter-search { flex: 1 1 100%; }
    .filter-bar select { flex: 1 1 45%; min-width: 0; }
    .list-toolbar { gap: .75rem; }
    .list-toolbar .segmented { flex: 1 1 auto; }
    .list-toolbar .segmented a { flex: 1 1 0; text-align: center; }
}

/* Filtre par couleur */
.color-filter {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    align-items: center;
    margin-bottom: 1rem;
}
.color-chip {
    font-size: .8rem;
    color: var(--muted);
    padding: .25rem .6rem;
    border: 1px solid var(--surface-2);
    border-radius: 999px;
}
.color-chip.active { color: var(--text); border-color: var(--accent); }
.color-swatch {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid transparent;
    box-shadow: 0 0 0 1px var(--surface-2);
}
.color-swatch.active { border-color: var(--text); }

/* Sélecteur de couleurs groupé par famille */
.color-fam {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font: inherit;
    font-size: .8rem;
    color: var(--muted);
    background: transparent;
    padding: .25rem .6rem;
    border: 1px solid var(--surface-2);
    border-radius: 999px;
    cursor: pointer;
}
.color-fam:hover { color: var(--text); text-decoration: none; }
.color-fam.active { color: var(--text); border-color: var(--accent); background: rgba(255, 122, 24, .12); }
.color-fam .fam-dot {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--surface-2);
}
.color-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-bottom: 1rem;
}

/* Toolbar (commutateur cartes/tableau + bascule images/couleur) */
.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.list-toolbar .toolbar-left { display: flex; align-items: center; gap: .6rem; }
.segmented a {
    background: var(--surface);
    color: var(--muted);
    padding: .4rem .9rem;
}
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.active { background: var(--accent); color: #1a1206; font-weight: 600; }

/* Bouton (icône case à cocher) qui active/désactive le mode sélection en bloc */
.bulk-toggle-btn {
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: 999px;
    color: var(--muted);
    cursor: pointer;
}
.bulk-toggle-btn:hover { color: var(--text); border-color: var(--muted); }
.bulk-toggle-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #1a1206;
}

/* Vue tableau */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--surface-2); }
.data-table { width: 100%; border-collapse: collapse; min-width: 520px; }
.data-table th,
.data-table td { padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--surface-2); }
.data-table thead th { color: var(--muted); font-size: .8rem; font-weight: 600; background: var(--surface); }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--surface); }
.data-table .num { text-align: right; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .inline-form { display: inline; }
.row-actions .btn { margin-left: .25rem; }

/* Tableau → cartes empilées sur mobile (pas de défilement horizontal) */
@media (max-width: 640px) {
    .table-wrap { border: 0; overflow: visible; }
    .data-table { min-width: 0; }
    .data-table thead { display: none; }
    .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
    .data-table tr {
        background: var(--surface);
        border: 1px solid var(--surface-2);
        border-radius: var(--radius);
        padding: .35rem .9rem;
        margin-bottom: .6rem;
    }
    .data-table td {
        border: 0;
        padding: .35rem 0;
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        text-align: right;
    }
    .data-table td.num { text-align: right; }
    .data-table td[data-label]::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: .8rem;
        text-align: left;
        flex: 0 0 auto;
    }
    .data-table td.cell-swatch { display: none; }
}

/* Liste de consommations (historique d'impression) — sans tableau */
.log-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.log-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: .65rem .9rem;
}
.log-item .swatch-inline { flex: none; margin: 0; }
.log-main { flex: 1 1 12rem; min-width: 0; }
.log-name { font-weight: 600; color: var(--text); }
.log-name:hover { color: var(--accent); }
.log-sub { font-size: .8rem; }
.log-figures { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.log-grams { font-weight: 600; }
.log-actions { display: flex; gap: .4rem; align-items: center; }
.log-actions .inline-form { display: inline; }

@media (max-width: 560px) {
    .log-figures { flex-direction: row; gap: .6rem; align-items: baseline; }
    .log-actions { width: 100%; justify-content: flex-end; border-top: 1px solid var(--surface-2); padding-top: .5rem; }
}
.filament-body { padding: .85rem 1rem 1rem; display: grid; gap: .4rem; }
.filament-name { margin: 0; font-size: 1rem; }
.small { font-size: .8rem; margin: 0; }

/* Barre de progression */
.bar {
    height: 8px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}
.bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #ffb169);
    border-radius: 999px;
}
.bar-lg { height: 12px; margin-bottom: .75rem; }
.filament-stats { display: flex; gap: .75rem; align-items: baseline; margin: 0; font-weight: 600; }
.filament-stats .muted { font-weight: 400; }
.filament-pct { margin-left: auto; }

/* Fiche détail */
.detail-grid {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
    align-items: start;
}
.detail-visual {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    border: 1px solid var(--surface-2);
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    overflow: hidden;
}
.swatch-inline {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border-radius: 4px;
    border: 1px solid var(--surface-2);
    vertical-align: -2px;
    margin-right: .35rem;
}
.color-cell { display: flex; align-items: center; }
.detail-visual img { width: 100%; height: 100%; object-fit: cover; }
.hex-label {
    margin: .5rem;
    padding: .15rem .5rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, .45);
    font-size: .8rem;
}
.detail-remaining { margin: 0 0 1rem; display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; }
.detail-remaining strong { font-size: 1.5rem; }
.detail-list { margin: 0; display: grid; gap: .1rem; }
.detail-list > div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem 0;
    border-top: 1px solid var(--surface-2);
}
.detail-list dt { color: var(--muted); margin: 0; }
.detail-list dd { margin: 0; font-weight: 600; text-align: right; }

@media (max-width: 640px) {
    .detail-grid { grid-template-columns: 1fr; }
    .detail-visual { aspect-ratio: 16 / 10; }
}

/* ===== Décompte d'impression ===== */
.section-title { font-size: 1.05rem; margin: 0 0 1rem; }
.print-form { max-width: 560px; margin-bottom: 2rem; }
.detail-grid-2 { grid-template-columns: 1fr 1fr; margin-top: 1.5rem; }
/* Bobine archivée : pas de zone d'impression, la carte QR occupe toute la largeur. */
.detail-grid-solo { grid-template-columns: 1fr; margin-top: 1.5rem; }
.consume-form { display: grid; gap: 1rem; }
.consume-form .btn { justify-self: start; }
.history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.history-list li {
    display: flex;
    gap: .6rem;
    align-items: baseline;
    flex-wrap: wrap;
    padding: .4rem 0;
    border-top: 1px solid var(--surface-2);
}
.history-list li:first-child { border-top: 0; }

/* Historique sur 2 colonnes (fiche filament), pleine largeur sous le QR/impression */
.history-card { margin-top: 1.5rem; }
.history-2col {
    grid-template-columns: 1fr 1fr;
    column-gap: 2rem;
}
.history-2col li:nth-child(2) { border-top: 0; }
@media (max-width: 560px) {
    .history-2col { grid-template-columns: 1fr; }
    .history-2col li:nth-child(2) { border-top: 1px solid var(--surface-2); }
}

@media (max-width: 640px) {
    .detail-grid-2 { grid-template-columns: 1fr; }
}

/* ===== Combobox (sélecteur de filament) ===== */
.combobox { position: relative; }
.combobox-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .7rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.combobox-toggle:focus { outline: none; border-color: var(--accent); }
.combobox-toggle .cb-name { font-weight: 600; }
.combobox-toggle .cb-caret { margin-left: auto; color: var(--muted); }
.cb-placeholder { color: var(--muted); }

.combobox-panel {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + .3rem);
    display: flex;
    flex-direction: column;
    max-height: 320px;
    padding: .5rem;
    background: var(--surface-2);
    border: 1px solid #2f3545;
    border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
.combobox-search {
    width: 100%;
    padding: .5rem .6rem;
    margin-bottom: .4rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
}
.combobox-search:focus { outline: none; border-color: var(--accent); }
.combobox-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.combobox-option {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: .6rem;
    align-items: center;
    padding: .5rem;
    border-radius: 6px;
    cursor: pointer;
}
.combobox-option:hover,
.combobox-option.active { background: rgba(255, 255, 255, .07); }
.cb-swatch {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--surface-2);
    flex: none;
}
.cb-swatch-empty { background: repeating-linear-gradient(45deg, #444, #444 3px, #555 3px, #555 6px); }
.cb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-gamme { color: var(--muted); font-size: .85rem; }
.cb-weight { color: var(--muted); font-size: .85rem; white-space: nowrap; }
/* Menu personnalisé du type de bobine : nom + pastilles (style Référentiels) */
.combobox-badges .combobox-option { grid-template-columns: 1fr auto; gap: .5rem; }
.combobox-badges .combobox-panel { right: auto; min-width: 100%; width: max-content; max-width: 24rem; }
.cb-badges { display: inline-flex; gap: .3rem; flex-wrap: wrap; align-items: center; }

/* Filament dans l'historique d'impression */
.hist-filament { display: inline-flex; align-items: center; gap: .5rem; }
.hist-filament .swatch-inline { margin: 0; flex: none; }
.hist-name { display: block; font-weight: 600; }
.hist-filament .small { display: block; }

/* Lien de retour */
.back-link { margin: 0 0 1rem; }
.back-link a { color: var(--muted); font-size: .9rem; }
.back-link a:hover { color: var(--text); }

/* QR code (fiche filament) */
.qr-card { text-align: center; }
.qr-img {
    width: 160px;
    height: 160px;
    background: #fff;
    border-radius: 8px;
    padding: 6px;
}
.qr-actions { display: flex; gap: .4rem; justify-content: center; flex-wrap: wrap; margin-top: .85rem; }

/* Ajustement rapide du poids (page publique) */
.adjust-form {
    display: flex;
    gap: .6rem;
    align-items: flex-end;
    margin-top: 1.25rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--surface-2);
    flex-wrap: wrap;
}
.adjust-form .field { flex: 1 1 12rem; }

/* ===== Modale d'impression Bluetooth (Niimbot) ===== */
.bt-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.bt-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .6);
}
.bt-modal-panel {
    position: relative;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    display: grid;
    gap: 1rem;
}
body.bt-modal-open { overflow: hidden; }

.bt-modal-head {
    display: flex;
    align-items: center;
    gap: .75rem;
}
.bt-modal-head .section-title { margin: 0; flex: 1 1 auto; }
.bt-close {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .25rem;
}
.bt-close:hover { color: var(--text); }

.bt-status {
    font-size: .8rem;
    padding: .2rem .6rem;
    border-radius: 999px;
    border: 1px solid var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}
.bt-status[data-state="on"] { color: var(--ok); border-color: rgba(62, 207, 142, .5); }
.bt-status[data-state="busy"] { color: var(--accent); border-color: rgba(255, 122, 24, .5); }
.bt-status[data-state="off"] { color: var(--ko); border-color: rgba(255, 93, 93, .4); }

.bt-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr 1fr;
    align-items: start;
}
@media (max-width: 560px) { .bt-grid { grid-template-columns: 1fr; } }

.bt-fields { display: grid; gap: .75rem; }
.bt-row { display: flex; gap: .6rem; }
.bt-row > .field { flex: 1 1 0; min-width: 0; }

.bt-eyebrow { font-size: .8rem; color: var(--muted); margin: 0 0 .4rem; }
.bt-preview-wrap {
    background: repeating-linear-gradient(45deg, #202531 0 8px, #1c212b 8px 16px);
    border-radius: 8px;
    padding: .6rem;
    display: flex;
    justify-content: center;
}
#bt-canvas {
    width: 100%;
    max-width: 320px;
    height: auto;
    background: #fff;
    border-radius: 3px;
    image-rendering: pixelated;
}

.bt-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.bt-actions .btn { flex: 1 1 auto; text-align: center; }

.bt-log {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: .75rem;
    line-height: 1.5;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    padding: .6rem;
    max-height: 150px;
    overflow-y: auto;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}
.bt-log-line { display: block; }
.bt-log .bt-ok { color: var(--ok); }
.bt-log .bt-warn { color: var(--accent); }
.bt-log .bt-err { color: var(--ko); }
.bt-log .bt-info { color: var(--muted); }
.bt-log .bt-data { color: #4d8dff; }

/* Identifiant unique de filament */
.fil-id {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-weight: 700;
    letter-spacing: .04em;
}

/* ===== Bouton icône (ex. appareil photo près de la couleur) ===== */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .45rem;
    line-height: 0;
}
.color-row { display: flex; align-items: center; gap: .5rem; }
/* Annule le width:100% global des inputs de .form pour laisser la place à l'icône. */
.color-row input[type="color"] {
    flex: 0 0 auto;
    width: 3.5rem;
    height: 2.5rem;
    padding: .2rem;
}
.color-row .btn-icon { flex: 0 0 auto; }

/* ===== Prélèvement couleur depuis photo ===== */
.cam-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.cam-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.cam-panel {
    position: relative;
    width: min(640px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    display: grid;
    gap: .85rem;
}
body.cam-modal-open { overflow: hidden; }

.cam-instr { margin: 0; color: var(--muted); font-size: .9rem; }
.cam-canvas-wrap {
    background: repeating-linear-gradient(45deg, #202531 0 8px, #1c212b 8px 16px);
    border-radius: 8px;
    padding: .5rem;
    display: flex;
    justify-content: center;
}
#cam-canvas {
    max-width: 100%;
    max-height: 60vh;
    height: auto;
    border-radius: 4px;
    cursor: crosshair;
    touch-action: none;            /* le glissé prélève, ne fait pas défiler */
}
.cam-foot { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.cam-foot .cam-spacer { flex: 1 1 auto; }
.cam-swatch {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--surface-2);
    background: transparent;
    flex: 0 0 auto;
}
.cam-foot code { font-family: ui-monospace, Menlo, Consolas, monospace; }

/* ===== Édition en bloc des filaments ===== */
.bulk-bar {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
    padding: .6rem .9rem;
    margin-bottom: 1rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
}
.bulk-bar .bulk-all { display: inline-flex; align-items: center; gap: .4rem; }
.bulk-bar-spacer { flex: 1 1 auto; }

/* Cases de sélection : masquées hors mode bloc. pointer-events:none -> le clic
   traverse vers la carte/ligne, c'est le JS qui bascule la sélection (évite le
   conflit toggle natif + preventDefault qui annulait le cochage). */
.bulk-check { display: none; pointer-events: none; }
.filament-card { position: relative; }
.bulk-active .filament-card .bulk-check {
    display: block;
    position: absolute;
    top: .5rem;
    right: .5rem;
    z-index: 3;
    width: 1.4rem;
    height: 1.4rem;
    accent-color: var(--accent);
}
.bulk-active .data-table .cell-swatch .bulk-check {
    display: inline-block;
    width: 1.1rem;
    height: 1.1rem;
    margin-right: .4rem;
    vertical-align: middle;
    accent-color: var(--accent);
}
.bulk-active .filament-card, .bulk-active .data-table tbody tr { cursor: pointer; }
.bulk-active .filament-card:has(.bulk-check:checked) {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 2px var(--accent);
}
.bulk-active .data-table tbody tr:has(.bulk-check:checked) {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

/* Panneau modal d'édition en bloc */
.bulk-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.bulk-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); }
.bulk-panel {
    position: relative;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    display: grid;
    gap: .85rem;
}
body.bulk-modal-open { overflow: hidden; }
.bulk-panel-head { display: flex; align-items: center; gap: .75rem; }
.bulk-panel-head .section-title { margin: 0; flex: 1 1 auto; }

.bulk-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: .6rem;
}
.bulk-field {
    display: grid;
    gap: .35rem;
    padding: .6rem;
    border: 1px solid var(--surface-2);
    border-radius: 8px;
}
.bulk-toggle { display: flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--muted); }
.bulk-toggle input { accent-color: var(--accent); }
.bulk-field input:not([type="checkbox"]),
.bulk-field select { width: 100%; padding: .5rem .6rem; background: var(--bg); border: 1px solid var(--surface-2); border-radius: 8px; color: var(--text); font: inherit; }
.bulk-field input:disabled, .bulk-field select:disabled { opacity: .45; cursor: not-allowed; }

/* Champ sensible (poids actuel, photo) : avertissement orange quand activé */
.bulk-warn-icon { display: none; margin-left: auto; color: #f2a900; font-weight: 700; }
.bulk-field.bulk-warn { border-color: #f2a900; background: rgba(242, 169, 0, .08); }
.bulk-field.bulk-warn .bulk-warn-icon { display: inline; }
.bulk-field.bulk-warn .bulk-toggle { color: #f2a900; }

.bulk-form-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* Page impression : onglets grammes / nouveau poids + panneau dessous */
.mode-tabs {
    display: flex;
    border: 1px solid var(--surface-2);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
}
.mode-tabs input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.mode-tabs label {
    flex: 1 1 0;
    text-align: center;
    padding: .7rem 1rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border-right: 1px solid var(--surface-2);
    transition: background .15s, color .15s;
}
.mode-tabs label:last-of-type { border-right: 0; }
.mode-tabs label:hover { color: var(--text); }
.mode-tabs input:checked + label { background: var(--accent); color: #1a1206; }
.mode-tabs input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: -2px; }

.mode-panel {
    display: grid;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--surface-2);
    border-radius: 0 0 8px 8px;
    background: var(--surface);
}
.mode-panel [data-amount] { font-size: 1.1rem; }

/* Sur la fiche filament, la zone d'impression s'aligne sur la taille de police
   du reste de la page (la page impression dédiée garde son rendu plus grand). */
.consume-form .mode-panel [data-amount] { font-size: 1rem; }
.consume-form .mode-tabs label { padding: .5rem .8rem; font-size: .85rem; }
.consume-form .mode-panel { padding: .8rem; }

/* Carte abonnement (page Mon compte) */
.plan-current { margin: .4rem 0 1rem; }
/* Bandeau d'avertissement quota dépassé (compte gratuit) */
.plan-warn {
    margin: 0 0 1rem;
    padding: .65rem .9rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: rgba(255, 122, 24, .12);
    color: var(--text);
    font-size: .9rem;
}
.plan-quota-over .bar span { background: var(--ko); }

/* Bouton « Désarchiver » bloqué (surcharge + délai de grâce dépassé) :
   fond bordeaux discret et hachuré pour le repérer sans crier. */
.btn-blocked {
    color: #e9c3c9;
    border: 1px solid #5a2230;
    background-color: #4a1c28;
    background-image: repeating-linear-gradient(
        45deg,
        rgba(0, 0, 0, .25) 0,
        rgba(0, 0, 0, .25) 5px,
        transparent 5px,
        transparent 10px
    );
    cursor: not-allowed;
}
.btn-blocked:hover { background-color: #4a1c28; color: #e9c3c9; }

/* Modale de confirmation générique */
.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.confirm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    animation: confirm-fade .16s ease both;
}
.confirm-panel {
    position: relative;
    width: min(420px, 100%);
    display: grid;
    gap: 1.1rem;
    animation: confirm-pop .2s cubic-bezier(.2, .8, .25, 1) both;
}
.confirm-msg { margin: 0; font-size: 1rem; line-height: 1.5; }
.confirm-danger { color: var(--ko); font-weight: 700; }
.confirm-actions { display: flex; justify-content: flex-end; gap: .5rem; }
body.confirm-open { overflow: hidden; }

@keyframes confirm-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes confirm-pop {
    from { opacity: 0; transform: translateY(10px) scale(.96); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .confirm-backdrop, .confirm-panel { animation: none; }
}

/* ===== Tableau de bord admin ===== */
.admin-section-title {
    margin: 1.5rem 0 .75rem;
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
}
.admin-dashboard > .admin-section-title:first-of-type { margin-top: .5rem; }
.admin-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.admin-stat {
    position: relative;
    display: grid;
    gap: .15rem;
    padding: 1rem 1.1rem;
    background: var(--surface);
    border: 1px solid var(--surface-2);
    border-left: 3px solid var(--c, var(--accent));
    border-radius: var(--radius);
}
.admin-stat-icon {
    position: absolute;
    top: .9rem;
    right: .9rem;
    color: var(--c, var(--accent));
    opacity: .85;
    line-height: 0;
}
.admin-stat-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.admin-stat-value .cur, .admin-stat-value .unit { font-size: .8rem; font-weight: 600; color: var(--muted); }
.admin-stat-label { color: var(--muted); font-size: .85rem; }
.admin-stat-sub { color: var(--c, var(--muted)); font-size: .78rem; font-weight: 600; }

.admin-offers { margin-bottom: 1.5rem; }
.split-bar {
    display: flex;
    height: 14px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--surface-2);
}
.split-free { background: var(--muted); }
.split-premium { background: var(--accent); }
.split-legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: .6rem; font-size: .85rem; }
.split-legend .dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; vertical-align: middle; margin-right: .25rem; }
.dot-free { background: var(--muted); }
.dot-premium { background: var(--accent); }

.admin-charts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.25rem;
}
.bar-chart { display: grid; gap: .85rem; }
.bar-row { display: grid; grid-template-columns: 1fr; gap: .25rem; }
.bar-name { font-weight: 600; font-size: .9rem; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #ffb35c); border-radius: 999px; }
.bar-val { font-size: .8rem; color: var(--text); }

/* ===== Administration ===== */
/* En-tête distinct du back-office (séparé du site public) */
.admin-header {
    background: #15171d;
    border-bottom: 2px solid var(--accent);
}
.admin-tag {
    display: inline-block;
    margin-left: .35rem;
    padding: .05rem .5rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 600;
    background: var(--accent);
    color: #1a1206;
    vertical-align: middle;
}
.header-left { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.admin-header .admin-back { border-color: var(--accent); color: var(--accent); }
.admin-header .admin-back:hover { background: rgba(255, 122, 24, .12); }
.admin-create-card { max-width: 32rem; }

.impersonation-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: .6rem 1rem;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: rgba(255, 122, 24, .14);
    font-size: .9rem;
}
.badge-admin {
    display: inline-block;
    margin-left: .4rem;
    padding: .05rem .5rem;
    border-radius: 999px;
    font-size: .72rem;
    background: var(--accent);
    color: #1a1206;
    vertical-align: middle;
}
/* Lignes utilisateurs de hauteur uniforme : 2 lignes de contenu par cellule,
   centrées verticalement. */
.admin-users td { vertical-align: middle; height: 64px; }
.admin-users .u-sub { min-height: 1.15em; }
.admin-users .u-email { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.admin-actions { display: flex; gap: .4rem; align-items: center; }
.admin-actions .btn-icon { padding: .4rem; }
/* Couleurs des actions : vert = voir, jaune = admin, rouge = supprimer. */
.act-view   { color: var(--ok); border-color: var(--ok); }
.act-view:hover   { background: rgba(62, 207, 142, .14); color: var(--ok); }
.act-admin  { color: #e8b339; border-color: #e8b339; }
.act-admin:hover  { background: rgba(232, 179, 57, .14); color: #e8b339; }
.act-delete { color: var(--ko); border-color: var(--ko); }
.act-delete:hover { background: rgba(255, 93, 93, .14); color: var(--ko); }
.admin-plan-form { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; }
.admin-plan-form .btn-icon { padding: .35rem; }
/* Mêmes contrôles que le reste du site (sinon rendu HTML par défaut). */
.admin-plan-form select,
.admin-plan-form input {
    padding: .35rem .55rem;
    background: var(--bg);
    border: 1px solid var(--surface-2);
    border-radius: 8px;
    color: var(--text);
    font: inherit;
}
.admin-plan-form input { width: 5rem; }
.admin-plan-form select:focus,
.admin-plan-form input:focus { outline: none; border-color: var(--accent); }
.admin-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.plan-badge {
    display: inline-block;
    padding: .1rem .55rem;
    border-radius: 999px;
    font-size: .85rem;
}
.plan-badge.plan-free { background: var(--surface-2); color: var(--muted); }
.plan-badge.plan-premium { background: var(--accent); color: #1a1206; }
.plan-quota { margin-bottom: 1rem; }
.plan-quota .bar { margin-bottom: .3rem; }
.plan-compare {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.plan-col {
    border: 1px solid var(--surface-2);
    border-radius: var(--radius);
    padding: .8rem 1rem;
}
.plan-col-premium { border-color: var(--accent); }
.plan-col h3 { margin: 0 0 .5rem; font-size: 1rem; }
.plan-col ul { margin: 0; padding-left: 1.1rem; }
.plan-col li { margin: .2rem 0; }
.plan-upgrade-note { margin-top: 1rem; }
@media (max-width: 560px) { .plan-compare { grid-template-columns: 1fr; } }
