: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; }

/* 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); }

/* 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%; }

    /* 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; }
.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 {
    padding: 1rem 1.5rem;
    text-align: right;
    color: var(--muted);
    font-size: .8rem;
    border-top: 1px solid var(--surface-2);
}

/* 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 {
    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); }

/* 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;
}
.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); }

/* ===== 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%; }

/* 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);
}
.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);
}

.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); }

/* 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; }

/* 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); }

/* 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;
}
.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; }

/* 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; }

/* 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; }
.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; }

/* 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; }
