/* ============================================================
   Biblio · feuille de style
   Esthétique : papier crème, encre profonde, serif éditorial.
   ============================================================ */

/* ---------- Variables ---------- */
:root {
    /* Palette papier/encre */
    --paper:        #f4ede0;
    --paper-deep:   #ebe1cf;
    --paper-edge:   #d9cdb4;
    --ink:          #1a1612;
    --ink-soft:     #3a342c;
    --ink-mute:     #6b6358;
    --ink-faint:    #9a9180;

    /* Accents */
    --accent:       #8b2e1f;   /* rouge bordeaux */
    --accent-2:     #4a5c3a;   /* vert reliure */
    --accent-soft:  #c89b6a;   /* doré patiné */
    --danger:       #b03a2e;

    /* Surfaces */
    --surface:      #fffaf0;
    --surface-soft: rgba(255,250,240,0.65);
    --line:         rgba(26,22,18,0.12);
    --line-soft:    rgba(26,22,18,0.06);

    /* Typographie */
    --font-display: 'Fraunces', 'Cormorant Garamond', Georgia, serif;
    --font-body:    'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Géométrie */
    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(26,22,18,0.06), 0 2px 6px rgba(26,22,18,0.04);
    --shadow:    0 2px 8px rgba(26,22,18,0.10), 0 8px 24px rgba(26,22,18,0.06);
    --shadow-lg: 0 8px 32px rgba(26,22,18,0.18), 0 32px 64px rgba(26,22,18,0.10);

    /* Espacement */
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top:    env(safe-area-inset-top, 0px);
    --nav-h:       72px;
    --top-h:       60px;
}

/* ---------- Reset doux ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overscroll-behavior-y: none;
}
body::before {
    /* Texture grain papier */
    content: '';
    position: fixed; inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.35;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.10  0 0 0 0 0.085  0 0 0 0 0.07  0 0 0 0.5 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/></svg>");
    mix-blend-mode: multiply;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* Typo display */
.display {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.6rem, 5vw, 2.3rem);
    line-height: 1.05;
    letter-spacing: -0.01em;
    margin: 0;
    /* Variations Fraunces : optical size + soft */
    font-variation-settings: 'opsz' 96, 'SOFT' 50;
}

.muted { color: var(--ink-mute); font-size: 0.92rem; }

/* ============================================================
   BOOT
   ============================================================ */
.boot {
    position: fixed; inset: 0;
    display: grid; place-items: center;
    background: var(--paper);
    z-index: 999;
}
.boot-mark {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 4rem;
    color: var(--ink);
    animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 0.4; transform: scale(0.96); }
    50%      { opacity: 1;   transform: scale(1); }
}

/* ============================================================
   AUTH
   ============================================================ */
.auth-screen {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 1.25rem;
    position: relative;
    z-index: 1;
}
.auth-bg {
    position: absolute; inset: 0;
    z-index: -1;
    background:
      radial-gradient(circle at 15% 10%, rgba(139,46,31,0.10), transparent 50%),
      radial-gradient(circle at 90% 85%, rgba(74,92,58,0.10), transparent 55%),
      var(--paper);
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 2rem 1.5rem;
    box-shadow: var(--shadow-lg);
    position: relative;
}
.auth-card::before {
    content: '';
    position: absolute;
    inset: 6px;
    border: 1px solid var(--line-soft);
    border-radius: calc(var(--radius-lg) - 4px);
    pointer-events: none;
}

.brand {
    display: flex; align-items: center; gap: 0.85rem;
    margin-bottom: 1.75rem;
}
.brand-mark {
    width: 52px; height: 52px;
    border-radius: var(--radius);
    background: var(--ink);
    color: var(--paper);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.8rem;
    display: grid; place-items: center;
    box-shadow: 2px 2px 0 var(--accent);
}
.brand-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.9rem;
    margin: 0;
    line-height: 1;
    letter-spacing: -0.02em;
}
.brand-sub {
    margin: 0.2rem 0 0;
    font-style: italic;
    color: var(--ink-mute);
    font-size: 0.88rem;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--line);
}
.auth-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 0.7rem 0;
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--ink-mute);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
}
.auth-tab.is-active {
    color: var(--ink);
    border-bottom-color: var(--accent);
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-label {
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-mute);
}
.field input,
.field textarea,
.field select {
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    font-size: 1rem;
    transition: border-color 0.15s, background 0.15s;
}
.field input:focus,
.field textarea:focus,
.field select:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface);
}

.form-error {
    background: rgba(176,58,46,0.08);
    color: var(--danger);
    border: 1px solid rgba(176,58,46,0.25);
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
}

.auth-foot {
    text-align: center;
    margin-top: 1.5rem;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--ink-faint);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 1px solid transparent;
    padding: 0.7rem 1.15rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    transition: transform 0.05s ease, box-shadow 0.15s, background 0.15s, border-color 0.15s;
    background: transparent;
    color: var(--ink);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--ink);
    color: var(--paper);
    box-shadow: 2px 2px 0 var(--accent);
}
.btn-primary:hover { box-shadow: 3px 3px 0 var(--accent); }

.btn-ghost {
    background: transparent;
    border-color: var(--line);
}
.btn-ghost:hover { background: var(--paper-deep); }

.btn-ghost[title] {
    display: flex;
    align-items: center;
    gap: 4px;
}
/* Animation de rotation quand on clique (via JS si vous voulez) */
.refresh-spin {
    animation: spin 1s linear infinite;
}
@keyframes spin { 100% { transform:rotate(360deg); } }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: rgba(176,58,46,0.3);
}
.btn-danger:hover { background: rgba(176,58,46,0.08); }

.btn-block { width: 100%; }
.btn-sm { padding: 0.45rem 0.8rem; font-size: 0.85rem; }

/* ============================================================
   SHELL : topbar + main + bottom-nav
   ============================================================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface-soft);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border-bottom: 1px solid var(--line);
    padding-top: var(--safe-top);
}
.topbar-inner {
    height: var(--top-h);
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.topbar-title { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.topbar-mark {
    width: 32px; height: 32px;
    border-radius: 6px;
    background: var(--ink);
    color: var(--paper);
    display: grid; place-items: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.1rem;
    flex: 0 0 auto;
}
.topbar-name {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-actions { display: flex; gap: 0.25rem; }

.icon-btn {
    width: 38px; height: 38px;
    display: grid; place-items: center;
    border: none;
    background: transparent;
    border-radius: 50%;
    color: var(--ink-soft);
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--paper-deep); color: var(--ink); }
.icon-btn:active { transform: scale(0.94); }

.search-bar {
    padding: 0.5rem 1rem 0.75rem;
    display: flex; gap: 0.5rem;
    border-top: 1px solid var(--line-soft);
    background: var(--surface);
}
.search-bar input {
    flex: 1;
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.85rem;
    font-size: 0.95rem;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--accent);
}

.view {
    position: relative;
    z-index: 1;
    padding: 1.25rem 1rem calc(var(--nav-h) + var(--safe-bottom) + 1.5rem);
    min-height: calc(100vh - var(--top-h));
    min-height: calc(100dvh - var(--top-h));
}

/* Bottom nav */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 50;
    height: calc(var(--nav-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--surface-soft);
    backdrop-filter: blur(14px) saturate(150%);
    -webkit-backdrop-filter: blur(14px) saturate(150%);
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
}
.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 0;
    color: var(--ink-mute);
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.is-active { color: var(--ink); }
.nav-item.is-active svg { stroke: var(--accent); }

.nav-fab {
    background: var(--ink);
    color: var(--paper);
    border: none;
    width: 54px; height: 54px;
    border-radius: 50%;
    margin: -10px auto 0;
    display: grid; place-items: center;
    box-shadow: 0 4px 14px rgba(26,22,18,0.30), 2px 2px 0 var(--accent);
    transition: transform 0.1s;
}
.nav-fab:active { transform: scale(0.94); }
.nav-fab svg { width: 26px; height: 26px; }

/* ============================================================
   LIBRARY
   ============================================================ */
.library-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.filters {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
    margin-bottom: 1rem;
}
.chip {
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--ink-soft);
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.chip.is-active {
    background: var(--ink);
    color: var(--paper);
    border-color: var(--ink);
}

.grid.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1.1rem 0.85rem;
}

@media (min-width: 600px) {
    .grid.books-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
}

/* Book card */
.book-card {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    -webkit-tap-highlight-color: transparent;
}
.book-cover {
    aspect-ratio: 2/3;
    background: var(--paper-edge);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    box-shadow:
        inset -2px 0 0 rgba(0,0,0,0.10),
        inset 2px 0 0 rgba(255,255,255,0.20),
        0 1px 2px rgba(26,22,18,0.18),
        0 6px 14px rgba(26,22,18,0.10);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.book-card:hover .book-cover {
    transform: translateY(-3px);
    box-shadow:
        inset -2px 0 0 rgba(0,0,0,0.10),
        inset 2px 0 0 rgba(255,255,255,0.20),
        0 4px 8px rgba(26,22,18,0.18),
        0 14px 24px rgba(26,22,18,0.14);
}
.book-cover img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.book-fallback {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    padding: 1rem;
    background: linear-gradient(135deg, var(--ink-soft), var(--ink));
    color: var(--paper);
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.2;
    text-align: center;
}

.book-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.98rem;
    line-height: 1.2;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    letter-spacing: -0.01em;
}
.book-authors {
    margin: 0;
    font-size: 0.82rem;
    color: var(--ink-mute);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.book-meta {
    margin: 0;
    font-size: 0.75rem;
    color: var(--ink-faint);
    font-style: italic;
}

/* Empty state */
.empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--ink-mute);
}
.empty-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.empty h3 {
    font-family: var(--font-display);
    margin: 0.5rem 0;
    font-size: 1.3rem;
    color: var(--ink);
}
.empty p { margin: 0 0 1.2rem; }

/* ============================================================
   SERIES
   ============================================================ */
.series-items {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.series-row {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: transform 0.08s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.series-row:hover {
    transform: translateX(2px);
    box-shadow: var(--shadow-sm);
    border-color: var(--accent-soft);
}
.series-row .series-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 1.05rem;
    margin: 0;
    line-height: 1.2;
}
.series-row .series-count {
    color: var(--ink-faint);
    font-size: 0.8rem;
    font-style: italic;
    margin-top: 2px;
}
.series-row svg {
    color: var(--ink-faint);
    flex: 0 0 auto;
}

/* Series detail */
.back-link {
    background: none;
    border: none;
    color: var(--ink-mute);
    padding: 0;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}
.series-head {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--line);
}
.series-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.series-books {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.series-book-row {
    display: grid;
    grid-template-columns: 36px 56px 1fr auto;
    align-items: center;
    gap: 0.85rem;
    padding: 0.6rem 0.5rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}
.series-book-row:hover { background: var(--paper-deep); }
.series-book-row .order-num {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent);
    text-align: center;
    line-height: 1;
}
.series-book-row .order-num.is-empty {
    color: var(--ink-faint);
    font-size: 1.1rem;
}
.series-book-row .mini-cover {
    aspect-ratio: 2/3;
    background: var(--paper-edge);
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.series-book-row .mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.series-book-row .row-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.98rem;
    line-height: 1.2;
    margin: 0;
}
.series-book-row .row-sub {
    font-size: 0.8rem;
    color: var(--ink-mute);
    margin: 2px 0 0;
}

/* ============================================================
   SCANNER
   ============================================================ */
.scanner h2 { margin-bottom: 0.4rem; }
.scanner > .muted { margin-bottom: 1rem; }

.scan-mode {
    margin: 1rem 0 1.25rem;
}
.switch {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.9rem;
}
.switch input { display: none; }
.switch-knob {
    width: 38px; height: 22px;
    background: var(--paper-edge);
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
}
.switch-knob::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    background: var(--surface);
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-knob { background: var(--accent); }
.switch input:checked + .switch-knob::after { transform: translateX(16px); }

.scan-stage {
    position: relative;
    /* 16:9 — bande utile plus large pour EAN (Firefox + ZXing / vidéo) */
    aspect-ratio: 16 / 9;
    width: 100%;
    min-height: 180px;
    margin: 0 auto 0.75rem;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    /* Couche composite : évite saccades / décalage vidéo sur Firefox */
    isolation: isolate;
}
.scan-region {
    width: 100%;
    height: 100%;
    position: relative;
    min-height: 0;
    min-width: 0;
}
.scan-region video,
.scan-region canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    object-fit: cover !important;
    display: block !important;
    vertical-align: top;
    background: #000;
    /* Firefox : forcer calque GPU pour synchro avec la mire */
    transform: translateZ(0);
    will-change: transform;
}

/* ── Correctifs html5-qrcode (fallback Firefox / sans BarcodeDetector) ──
   La lib injecte des div intermédiaires avec des styles inline qu'il faut
   écraser pour que le flux vidéo remplisse bien le conteneur.            */
.scan-region > div {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}
/* Conteneur interne du flux vidéo créé par html5-qrcode */
[id$="__scan_region"] {
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
}
[id$="__scan_region"] video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
}
/* Masquer la section de contrôles native de html5-qrcode
   (on gère start/stop nous-mêmes dans l'UI) */
[id$="__dashboard"] {
    display: none !important;
}

/* ── Mire de visée ── */
.scan-aim {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    /* Fond foncé autour de la zone active */
    background:
        linear-gradient(rgba(0,0,0,0.4) 0%, transparent 28%),
        linear-gradient(transparent 72%, rgba(0,0,0,0.4) 100%);
}
/* Cadre de détection : bande horizontale ~36% de hauteur, 90% de largeur */
.aim-box {
    position: relative;
    width: 70%;
    height: 45%;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}
/* Coins colorés */
.aim-corner {
    position: absolute;
    width: 22px; height: 22px;
    border-color: rgba(255, 200, 60, 0.92);
    border-style: solid;
}
.aim-corner.c-tl { top:-1px; left:-1px;  border-width:3px 0 0 3px; border-radius:4px 0 0 0; }
.aim-corner.c-tr { top:-1px; right:-1px; border-width:3px 3px 0 0; border-radius:0 4px 0 0; }
.aim-corner.c-bl { bottom:-1px; left:-1px;  border-width:0 0 3px 3px; border-radius:0 0 0 4px; }
.aim-corner.c-br { bottom:-1px; right:-1px; border-width:0 3px 3px 0; border-radius:0 0 4px 0; }
/* Ligne de scan animée */
.aim-line {
    position: absolute;
    left: 6px; right: 6px;
    height: 3px;
    background: linear-gradient(90deg, transparent, #ffc83c, transparent);
    box-shadow: 0 0 8px rgba(255,200,60,0.6);
    animation: aim-sweep 1.5s ease-in-out infinite;
    border-radius: 1px;
}
@keyframes aim-sweep {
    0%   { top: 4px;  opacity: 0.3; }
    50%  { top: calc(100% - 6px); opacity: 1; }
    100% { top: 4px;  opacity: 0.3; }
}
.aim-label {
    margin-top: 10px;
    color: rgba(255,255,255,0.75);
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 4px rgba(0,0,0,0.7);
}

/* ── Bouton lampe torche (overlay) ── */
.torch-btn {
    position: absolute;
    top: 10px; right: 10px;
    z-index: 20;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background 0.15s, border-color 0.15s;
}
.torch-btn.is-on {
    background: rgba(255, 210, 60, 0.9);
    border-color: transparent;
    color: #1a1612;
}
.torch-btn:hover { background: rgba(255,255,255,0.15); }
.torch-btn.is-on:hover { background: rgba(255, 210, 60, 0.75); }

.scan-controls {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 1rem;
}

.scan-feedback {
    text-align: center;
    padding: 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.scan-feedback.is-success {
    background: rgba(74,92,58,0.10);
    color: var(--accent-2);
    border: 1px solid rgba(74,92,58,0.25);
}
.scan-feedback.is-error {
    background: rgba(176,58,46,0.10);
    color: var(--danger);
    border: 1px solid rgba(176,58,46,0.25);
}

.scan-batch {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
}
.scan-batch h3 {
    margin: 0 0 0.75rem;
    font-family: var(--font-display);
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.badge {
    display: inline-block;
    background: var(--accent);
    color: var(--paper);
    font-family: var(--font-body);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    min-width: 22px;
    text-align: center;
}
.scan-batch ul {
    list-style: none;
    padding: 0;
    margin: 0 0 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.batch-item {
    display: grid;
    grid-template-columns: 38px 1fr auto;
    align-items: center;
    gap: 0.7rem;
    padding: 0.5rem;
    background: var(--paper-deep);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}
.batch-item.is-pending { opacity: 0.7; }
.batch-item.is-error { background: rgba(176,58,46,0.10); }
.batch-item .mini-cover {
    aspect-ratio: 2/3;
    background: var(--paper-edge);
    border-radius: 2px;
    overflow: hidden;
}
.batch-item .mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.batch-item .item-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.batch-item .item-sub {
    font-size: 0.78rem;
    color: var(--ink-mute);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.batch-item button {
    background: none; border: none;
    color: var(--ink-faint);
    padding: 4px 6px;
    font-size: 1.1rem;
    line-height: 1;
}
.batch-item button:hover { color: var(--danger); }
.scan-batch-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ============================================================
   ACCOUNT
   ============================================================ */
.account-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    margin: 1rem 0;
}
.account-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line-soft);
}
.account-row:last-child { border-bottom: none; }

.account-section-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.35rem;
}
.wa-cred-list {
    list-style: none;
    margin: 0 0 0.75rem;
    padding: 0;
    font-size: 0.88rem;
}
.wa-cred-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--line-soft);
}
.wa-cred-list li:last-child { border-bottom: none; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(26,22,18,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    display: grid;
    place-items: end center;
    animation: fadeIn 0.18s ease;
}
@media (min-width: 720px) {
    .modal-backdrop { place-items: center; }
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
    background: var(--surface);
    width: 100%;
    max-width: 546px;
    max-height: 92vh;
    overflow-x: hidden;
    overflow-y: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    padding: 1.25rem;
    padding-bottom: calc(1.25rem + var(--safe-bottom));
    animation: slideUp 0.25s cubic-bezier(0.2, 0.8, 0.3, 1);
    min-width: 0;
}
@media (min-width: 720px) {
    .modal {
        border-radius: var(--radius-lg);
        max-height: 88vh;
    }
}
@keyframes slideUp {
    from { transform: translateY(40px); opacity: 0.6; }
    to   { transform: translateY(0);     opacity: 1; }
}
.modal-handle {
    width: 40px; height: 4px;
    background: var(--paper-edge);
    border-radius: 2px;
    margin: -0.25rem auto 0.75rem;
}
.modal h2 {
    font-family: var(--font-display);
    font-size: 1.4rem;
    margin: 0 0 1rem;
    letter-spacing: -0.01em;
}
.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

/* Détail livre dans modal */
.book-detail {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 1.1rem;
    align-items: start;
    margin-bottom: 1.1rem;
}
.book-detail .book-cover { box-shadow: 0 4px 14px rgba(0,0,0,0.20); }
.book-detail .detail-info h3 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin: 0 0 0.3rem;
    line-height: 1.15;
}
.book-detail .detail-info .authors {
    color: var(--ink-soft);
    font-size: 0.95rem;
    margin: 0 0 0.4rem;
    font-style: italic;
}
.book-detail .detail-info .meta {
    font-size: 0.85rem;
    color: var(--ink-mute);
    margin: 0;
}
.book-description {
    line-height: 1.55;
    color: var(--ink-soft);
    font-size: 0.93rem;
    max-height: 240px;
    overflow-y: auto;
    padding-right: 0.4rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--line);
    padding-top: 0.85rem;
}

/* Form-grid */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.85rem;
    min-width: 0;
}
.form-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-mute);
    margin: 0.35rem 0 0;
}
.cover-upload-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}
.book-status-badge {
    margin: 0.25rem 0 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent);
}
.book-status-detail {
    margin: 0.75rem 0 0;
    padding: 0.65rem 0.85rem;
    background: var(--paper-deep);
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    font-size: 0.88rem;
}
.book-status-detail .status-line {
    margin: 0.25rem 0;
    color: var(--ink-soft);
}
.book-status-detail .status-line:first-child { margin-top: 0; }
.book-status-detail .status-line:last-child { margin-bottom: 0; }
.form-grid textarea {
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}
.form-grid textarea:focus {
    outline: none; border-color: var(--accent); background: var(--surface);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    min-width: 0;
}
.form-row > .field {
    min-width: 0;
}
.form-row .field input,
.form-row .field select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.form-row-3 {
    grid-template-columns: 1fr 1fr 1fr;
}
@media (max-width: 640px) {
    .form-row-3 {
        grid-template-columns: 1fr;
    }
}
/* Ajout pour le responsive mobile */
@media (max-width: 480px) {
    .form-row {
        grid-template-columns: 1fr; /* On passe sur une seule colonne sur mobile */
    }
}

/* ============================================================
   TOASTS
   ============================================================ */
.toasts {
    position: fixed;
    left: 50%;
    top: calc(var(--safe-top) + 1rem);
    transform: translateX(-50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    pointer-events: none;
    width: min(90vw, 420px);
}
.toast {
    background: var(--ink);
    color: var(--paper);
    padding: 0.7rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    box-shadow: var(--shadow);
    animation: toastIn 0.2s ease, toastOut 0.3s ease 2.7s forwards;
    border-left: 3px solid var(--accent);
}
.toast.is-error { border-left-color: var(--danger); }
.toast.is-success { border-left-color: var(--accent-2); }
@keyframes toastIn { from { transform: translateY(-12px); opacity: 0; } }
@keyframes toastOut { to { transform: translateY(-12px); opacity: 0; } }

/* ============================================================
   UTILITIES
   ============================================================ */
[hidden] { display: none !important; }
.hidden  { display: none !important; }

/* ── Saisie manuelle intégrée dans la vue scanner ── */
.scan-manual {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.scan-manual input {
    flex: 1;
    padding: 0.65rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper-deep);
    color: var(--ink);
    font-size: 0.95rem;
    font-family: ui-monospace, 'Menlo', monospace;
    letter-spacing: 0.04em;
}
.scan-manual input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ============================================================
   FEEDBACK VISUEL DU SCANNER
   Ajouté pour : flash sur le scan-stage + overlay ✓ / ⚠ / ✕
   ============================================================ */

/* ── Variante warning du toast (doublon, lot mixte) ── */
.toast.is-warning {
    border-left-color: var(--accent-soft);
}

/* ── Variante warning du bandeau de feedback du scanner ── */
.scan-feedback.is-warning {
    background: rgba(200, 155, 106, 0.14);
    color: #7d5a2d;
    border: 1px solid rgba(200, 155, 106, 0.40);
}

/* ── Flash de bordure sur le scan-stage à chaque détection ── */
.scan-stage {
    transition: box-shadow 0.2s ease;
}
@keyframes scanFlashSuccess {
    0%   { box-shadow: var(--shadow), inset 0 0 0 0 rgba(74, 92, 58, 0); }
    25%  { box-shadow: var(--shadow), inset 0 0 0 4px rgba(74, 92, 58, 0.95),
                       0 0 28px 4px rgba(74, 92, 58, 0.45); }
    100% { box-shadow: var(--shadow), inset 0 0 0 0 rgba(74, 92, 58, 0); }
}
@keyframes scanFlashDuplicate {
    0%   { box-shadow: var(--shadow), inset 0 0 0 0 rgba(200, 155, 106, 0); }
    25%  { box-shadow: var(--shadow), inset 0 0 0 4px rgba(200, 155, 106, 0.95),
                       0 0 28px 4px rgba(200, 155, 106, 0.50); }
    100% { box-shadow: var(--shadow), inset 0 0 0 0 rgba(200, 155, 106, 0); }
}
@keyframes scanFlashError {
    0%   { box-shadow: var(--shadow), inset 0 0 0 0 rgba(176, 58, 46, 0); }
    25%  { box-shadow: var(--shadow), inset 0 0 0 4px rgba(176, 58, 46, 0.95),
                       0 0 28px 4px rgba(176, 58, 46, 0.45); }
    100% { box-shadow: var(--shadow), inset 0 0 0 0 rgba(176, 58, 46, 0); }
}
.scan-stage.flash-success   { animation: scanFlashSuccess 900ms ease-out; }
.scan-stage.flash-duplicate { animation: scanFlashDuplicate 900ms ease-out; }
.scan-stage.flash-error     { animation: scanFlashError 900ms ease-out; }

/* ── Overlay ✓ / ⚠ / ✕ injecté dynamiquement dans le scan-stage ── */
.scan-overlay {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.18s ease, transform 0.22s cubic-bezier(.2, .9, .3, 1.4);
}
.scan-overlay.is-visible {
    opacity: 1;
    transform: scale(1);
}
.scan-overlay-icon {
    width: 86px;
    height: 86px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
    line-height: 1;
    color: #fff;
    font-weight: 700;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}
.scan-overlay-text {
    font-family: var(--font-display);
    font-size: 1.05rem;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    letter-spacing: 0.01em;
    text-align: center;
    padding: 0 1rem;
}
.scan-overlay.is-success .scan-overlay-icon {
    background: var(--accent-2);   /* vert reliure */
}
.scan-overlay.is-duplicate .scan-overlay-icon {
    background: var(--accent-soft); /* doré patiné */
    color: #2d1f0f;
}
.scan-overlay.is-error .scan-overlay-icon {
    background: var(--danger);
}

/* ── État "doublon" pour les items de lot ── */
.batch-item.is-duplicate {
    background: rgba(200, 155, 106, 0.12);
    border: 1px dashed rgba(200, 155, 106, 0.45);
    opacity: 0.85;
}
.batch-item.is-duplicate .item-title::before {
    content: "⚠ ";
    color: var(--accent-soft);
    font-weight: 700;
}
.batch-item.is-duplicate .item-sub {
    color: #7d5a2d;
    font-style: italic;
}

/* ── Petit pulse au moment où un item est ajouté au lot ── */
@keyframes batchItemIn {
    0%   { transform: translateY(-4px); opacity: 0; }
    100% { transform: translateY(0);    opacity: 1; }
}
.batch-item {
    animation: batchItemIn 0.25s ease-out;
}

/* ── Respect du paramètre "réduire les animations" ── */
@media (prefers-reduced-motion: reduce) {
    .scan-stage.flash-success,
    .scan-stage.flash-duplicate,
    .scan-stage.flash-error,
    .batch-item {
        animation: none !important;
    }
    .scan-overlay { transition: opacity 0.1s linear; }
}

/* ============================================================
   ADMINISTRATION (gestion des comptes utilisateurs)
   ============================================================ */

/* Bannière sur l'écran d'auth lors du tout premier lancement */
.auth-bootstrap {
    margin: 0 0 1rem;
    padding: 0.75rem 0.9rem;
    background: rgba(74, 92, 58, 0.10);
    border-left: 3px solid var(--accent-2);
    border-radius: var(--radius-sm);
    font-size: 0.86rem;
    color: var(--ink-soft);
    line-height: 1.45;
}

/* Note discrète sous l'écran de connexion en mode verrouillé */
.auth-note {
    color: var(--ink-mute);
    font-size: 0.82rem;
    text-align: center;
}

/* Section admin dans la vue Compte */
.admin-panel {
    margin: 1.5rem 0;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.admin-title {
    margin: 0 0 0.4rem;
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--ink);
}

.admin-users {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.admin-user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.65rem 0.8rem;
    background: var(--paper-deep);
    border-radius: var(--radius-sm);
}
.admin-user-meta {
    min-width: 0;
    flex: 1;
}
.admin-user-name {
    margin: 0 0 0.2rem;
    font-weight: 600;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
    font-size: 0.95rem;
}
.admin-user-stats {
    margin: 0;
    font-size: 0.78rem;
    color: var(--ink-mute);
}

.admin-badge,
.me-badge {
    display: inline-block;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 1px 7px;
    border-radius: 999px;
    line-height: 1.5;
}
.admin-badge {
    background: var(--accent);
    color: var(--paper);
}
.me-badge {
    background: var(--paper-edge);
    color: var(--ink-soft);
}

/* ============================================================
   IMPORT / EXPORT CSV
   ============================================================ */

.import-export-panel {
    background: var(--paper-deep);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1rem;
}

.import-export-title {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 0.25rem;
}

/* ── Résultats d'import ── */
.import-results {
    margin-top: 0.75rem;
}

.import-summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
    border: 1px solid transparent;
}
.import-summary.is-success {
    background: rgba(74, 92, 58, 0.12);
    border-color: rgba(74, 92, 58, 0.35);
    color: #3a5a2e;
}
.import-summary.is-warning {
    background: rgba(200, 155, 106, 0.12);
    border-color: rgba(200, 155, 106, 0.35);
    color: #7d5a2d;
}
.import-summary.is-error {
    background: rgba(176, 58, 46, 0.10);
    border-color: rgba(176, 58, 46, 0.30);
    color: var(--danger);
}
.import-icon {
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
}

.import-errors {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}
.import-errors li {
    font-size: 0.8rem;
    color: var(--danger);
    padding: 0.2rem 0.5rem;
    background: rgba(176, 58, 46, 0.06);
    border-radius: var(--radius-sm);
}
.import-errors li.muted { color: var(--ink-mute); background: none; }

/* ============================================================
   ZONE DE DROP — Import CSV
   ============================================================ */
.csv-drop-zone {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    border: 1.5px dashed var(--line);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
    background: var(--paper);
}
.csv-drop-zone:hover,
.csv-drop-zone:focus-within {
    border-color: var(--accent);
    background: rgba(200, 155, 106, 0.06);
}
.csv-drop-zone.is-over {
    border-color: var(--accent-2);
    background: rgba(74, 92, 58, 0.08);
}
.csv-drop-zone.is-loading {
    opacity: 0.7;
    pointer-events: none;
    border-style: solid;
}
.csv-drop-icon {
    font-size: 1.35rem;
    line-height: 1;
    flex-shrink: 0;
}
.csv-drop-label {
    font-size: 0.83rem;
    color: var(--ink-soft);
    flex: 1;
}

@media (prefers-reduced-motion: reduce) {
    .csv-drop-zone { transition: none; }
}
