/* =============================================================================
 *  LIRE À GOGO — Administration
 *  Même identité que la boutique : papier crème, terracotta, encre.
 * ========================================================================== */

:root {
    --bg:          #f4f1ec;
    --surface:     #ffffff;
    --ink:         #2a2521;
    --muted:       #736a5e;
    --line:        #e6dfd4;
    --primary:     #c2410c;
    --primary-600: #a8380a;
    --primary-50:  #fdf1ea;
    --success:     #2e7d32;
    --danger:      #b32d2e;
    --danger-50:   #fbeaea;
    --radius:      14px;
    --shadow-sm:   0 1px 3px rgba(42,37,33,.06);
    --shadow-md:   0 10px 30px rgba(42,37,33,.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, 'Segoe UI', sans-serif;
    background: var(--bg); color: var(--ink);
    line-height: 1.55; -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: 'Fraunces', Georgia, serif; letter-spacing: -.01em; font-weight: 600; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ===================== ÉCRAN D'ATTENTE (anti-clignotement) ===================== */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot[hidden] { display: none; }
.boot-spinner {
    width: 30px; height: 30px; border-radius: 50%;
    border: 3px solid var(--line); border-top-color: var(--primary);
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================= ÉCRAN DE CONNEXION ========================= */
.lock-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.lock-screen[hidden] { display: none; }

.lock-card {
    background: var(--surface); width: min(400px, 100%);
    padding: 36px 30px 28px; border-radius: 18px;
    border: 1px solid var(--line); box-shadow: var(--shadow-md);
    text-align: center;
}
.lock-logo {
    display: block; width: 190px; height: auto;
    margin: 0 auto 20px;
}
.lock-card h1 { font-size: 1.25rem; margin-bottom: 6px; }
.lock-sub { color: var(--muted); font-size: .88rem; margin-bottom: 20px; }
.lock-card input {
    width: 100%; padding: 13px 14px; margin-bottom: 12px;
    border: 1px solid var(--line); border-radius: 10px;
    font-size: 16px; font-family: inherit; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.lock-card input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.lock-back {
    display: inline-block; margin-top: 18px;
    color: var(--muted); font-size: .82rem; text-decoration: none;
}
.lock-back:hover { color: var(--ink); }
.form-error {
    color: var(--danger); background: var(--danger-50);
    padding: 9px 12px; border-radius: 9px;
    font-size: .84rem; font-weight: 600; margin-top: 10px;
}
.form-error[hidden] { display: none; }

/* ============================== LAYOUT ============================== */
.admin { max-width: 1240px; margin: 0 auto; padding: 20px clamp(12px, 3vw, 24px) 60px; }
.admin[hidden] { display: none; }

.topbar {
    display: flex; justify-content: space-between; align-items: center;
    gap: 16px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--line);
    padding: 15px 20px; border-radius: var(--radius);
    box-shadow: var(--shadow-sm); margin-bottom: 18px;
}
.topbar-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-logo {
    height: 38px; width: auto; display: block;
    padding-right: 14px; border-right: 1px solid var(--line);
}
.topbar-title { font-size: 1.2rem; }
.topbar-actions { display: flex; gap: 9px; flex-wrap: wrap; }

/* ============================== STATS ============================== */
.stats {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 12px; margin-bottom: 18px;
}
.stat {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.stat-label { display: block; font-size: .74rem; color: var(--muted); font-weight: 600; }
.stat-value {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.7rem; font-weight: 600; color: var(--primary-600);
}
.stat-dark { background: var(--ink); border-color: var(--ink); }
.stat-dark .stat-label { color: rgba(255,255,255,.6); }
.stat-dark .stat-value { color: #4ade80; }

.grid { display: grid; grid-template-columns: 1.65fr 1fr; gap: 18px; align-items: start; }
.col-main, .col-side { min-width: 0; display: flex; flex-direction: column; gap: 18px; }

/* ============================== CARTES ============================== */
.card {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm);
}
.card-title {
    font-size: 1.12rem; padding-bottom: 11px; margin-bottom: 15px;
    border-bottom: 1px solid var(--line);
}

/* ============================ FORMULAIRES ============================ */
.field { margin-bottom: 13px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.hint { font-weight: 400; color: var(--muted); font-size: .72rem; }

.field input, .field textarea, .toolbar input, .cat-form input {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: 10px;
    font-family: inherit; font-size: .93rem; color: var(--ink);
    background: #fff; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field textarea:focus, .toolbar input:focus, .cat-form input:focus {
    border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50);
}
.field textarea { resize: vertical; }
.field input[type=file] { padding: 8px; background: #faf7f2; font-size: .85rem; }

.form-actions { display: flex; gap: 9px; margin-top: 6px; }
.form-actions .btn { flex: 1; }

/* ========================== BLOC COUVERTURE ========================== */
.cover-box {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 12px 14px 4px; margin-bottom: 14px; background: #fdfbf8;
}
.cover-box legend { font-size: .8rem; font-weight: 600; color: var(--ink); padding: 0 6px; }
.cover-layout { display: flex; gap: 14px; align-items: flex-start; }
.cover-inputs { flex: 1; min-width: 0; }

.cover-preview { position: relative; width: 84px; flex: none; }
.cover-preview img {
    width: 84px; height: 112px; object-fit: cover;
    border-radius: 8px; border: 1px solid var(--line); background: #f1ece4; display: block;
}
.cover-clear {
    position: absolute; top: -7px; right: -7px;
    width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid #fff; background: var(--danger); color: #fff;
    font-size: 14px; line-height: 1; cursor: pointer; padding: 0;
}
.cover-clear[hidden] { display: none; }

.cover-or {
    text-align: center; margin: 8px 0; position: relative;
    font-size: .72rem; color: var(--muted); text-transform: uppercase; font-weight: 600;
}
.cover-or::before {
    content: ''; position: absolute; top: 50%; left: 0; right: 0;
    height: 1px; background: var(--line);
}
.cover-or span { position: relative; background: #fdfbf8; padding: 0 8px; }
.cover-hint { margin-top: 5px; line-height: 1.4; }

/* ============================== BOUTONS ============================== */
.btn {
    border: none; padding: 11px 16px; border-radius: 10px;
    font-family: inherit; font-size: .9rem; font-weight: 600;
    cursor: pointer; text-decoration: none; text-align: center;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .18s, opacity .18s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 13px; font-size: .83rem; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-600); }
.btn-ghost { background: var(--primary-50); color: var(--primary-600); }
.btn-ghost:hover:not(:disabled) { background: #f9e5d9; }
.btn-neutral { background: #6b6357; color: #fff; }
.btn-neutral:hover:not(:disabled) { background: #564f45; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .9; }
.btn-soft-danger { background: var(--danger-50); color: var(--danger); }
.btn-soft-danger:hover:not(:disabled) { background: #f6dada; }

/* ============================== IMPORT ============================== */
.card-import { border: 2px dashed var(--primary); background: var(--primary-50); }
.import-help { font-size: .78rem; color: var(--muted); margin-bottom: 8px; }
.import-help code {
    background: #fff; padding: 1px 6px; border-radius: 5px;
    border: 1px solid var(--line); font-size: .95em;
}
.import-note { border-left: 3px solid var(--primary); padding-left: 9px; }
.import-progress { margin-top: 12px; font-size: .84rem; font-weight: 600; color: var(--primary-600); }
.import-progress[hidden] { display: none; }
.bar { height: 7px; background: #f0ddd0; border-radius: 999px; overflow: hidden; margin-bottom: 6px; }
.bar-fill { height: 100%; width: 0; background: var(--primary); border-radius: 999px; transition: width .25s ease; }

/* ============================== TOOLBAR ============================== */
.toolbar { margin-bottom: 12px; }
.bulk-bar {
    display: flex; align-items: center; gap: 13px; flex-wrap: wrap;
    background: #faf7f2; border: 1px solid var(--line);
    padding: 10px 12px; border-radius: 10px; margin-bottom: 12px;
}
.bulk-bar[hidden] { display: none; }
.check { display: flex; align-items: center; gap: 7px; font-size: .86rem; font-weight: 600; cursor: pointer; }
.check input { width: 17px; height: 17px; cursor: pointer; accent-color: var(--primary); }
.selected-count { font-size: .82rem; color: var(--muted); margin-right: auto; }

/* =========================== LISTE LIVRES =========================== */
.products-list { display: flex; flex-direction: column; }
.product-row {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 0; border-bottom: 1px solid var(--line);
}
.product-row:last-child { border-bottom: none; }
.product-row input[type=checkbox] { width: 17px; height: 17px; cursor: pointer; flex: none; accent-color: var(--primary); }
.row-cover { width: 42px; height: 56px; border-radius: 6px; object-fit: cover; flex: none; border: 1px solid var(--line); }
.row-info { flex: 1; min-width: 0; }
.row-title {
    font-weight: 600; font-size: .92rem; line-height: 1.3;
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}
.row-tag {
    font-size: .64rem; font-weight: 600; text-transform: uppercase;
    background: #f1ece4; color: var(--muted);
    padding: 2px 7px; border-radius: 999px;
}
.row-meta { font-size: .77rem; color: var(--muted); margin-top: 2px; }
.row-price { font-weight: 700; color: var(--primary-600); }
.row-warn { color: var(--danger); font-weight: 600; }
.row-actions { display: flex; gap: 7px; flex: none; }

.list-more { text-align: center; padding-top: 14px; }
.list-more[hidden] { display: none; }
.list-empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: .9rem; }

/* ============================ CATÉGORIES ============================ */
.cat-form { display: flex; gap: 8px; margin-bottom: 13px; }
.cat-form input { flex: 1; }
.cat-badges { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-badge {
    display: inline-flex; align-items: center; gap: 7px;
    background: var(--primary-50); color: var(--primary-600);
    padding: 6px 11px; border-radius: 999px;
    font-size: .8rem; font-weight: 600;
}
.cat-badge button {
    border: none; background: none; color: var(--danger);
    font-size: 1rem; line-height: 1; cursor: pointer; padding: 0;
}
.cat-badge button:hover { opacity: .65; }

/* ============================== VENTES ============================== */
.side-note { font-size: .76rem; color: var(--muted); margin-bottom: 12px; }
.sales-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; }
.sale {
    border: 1px solid var(--line); border-radius: 10px;
    padding: 11px; background: #faf7f2; font-size: .82rem;
}
.sale-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; }
.sale-client { font-weight: 700; }
.sale-date { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.sale-books { color: var(--muted); line-height: 1.45; }
.sale-total { margin-top: 5px; font-weight: 700; color: var(--success); }

/* ============================== TOAST ============================== */
.toast {
    position: fixed; left: 50%; bottom: 28px;
    transform: translateX(-50%) translateY(18px);
    background: var(--ink); color: #fff;
    padding: 12px 22px; border-radius: 11px;
    font-size: .9rem; font-weight: 600;
    box-shadow: var(--shadow-md);
    opacity: 0; pointer-events: none; z-index: 3000;
    transition: opacity .25s, transform .25s;
    max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.is-warn { background: var(--danger); }
.toast.is-ok { background: var(--success); }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 980px) {
    .grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
    .admin { padding: 12px 12px 40px; }
    .card { padding: 16px; }
    .topbar-logo { height: 30px; padding-right: 10px; }
    .topbar-title { font-size: 1rem; }
    .lock-logo { width: 160px; }
    .field-row { grid-template-columns: 1fr; gap: 0; }
    .stats { gap: 9px; }
    .stat-value { font-size: 1.4rem; }
    .row-actions { flex-direction: column; }
}

a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
