/* =============================================================================
 *  LIRE À GOGO — Boutique
 *  Thème « librairie chaleureuse » : papier crème, terracotta, encre.
 *  Le vert est réservé à l'action WhatsApp (commander).
 * ========================================================================== */

:root {
    --bg:          #f6f3ee;
    --surface:     #ffffff;
    --ink:         #2a2521;
    --muted:       #736a5e;
    --line:        #e8e1d6;
    --primary:     #c2410c;
    --primary-600: #a8380a;
    --primary-50:  #fdf1ea;
    --wa:          #25d366;
    --wa-600:      #1eb257;
    --danger:      #b32d2e;
    --success:     #2e7d32;
    --radius:      16px;
    --shadow-sm:   0 1px 3px rgba(42,37,33,.06);
    --shadow-md:   0 8px 24px rgba(42,37,33,.09);
    --shadow-lg:   0 24px 50px rgba(42,37,33,.2);
    --maxw:        1240px;
}

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

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

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

/* ============================== NAVBAR ============================== */
.navbar {
    position: sticky; top: 0; z-index: 50;
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    padding: 10px clamp(16px, 5vw, 56px);
    /* Blanc opaque : le logo a un fond blanc, il se fond ainsi parfaitement
       dans la barre (un fond semi-transparent ferait apparaître son rectangle). */
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand-logo {
    height: 44px; width: auto; display: block;
    transition: opacity .2s;
}
.brand:hover .brand-logo { opacity: .82; }

.nav-actions { display: flex; align-items: center; gap: 10px; }
.admin-link {
    display: inline-flex; align-items: center; gap: 7px;
    text-decoration: none; color: var(--muted);
    font-size: .9rem; font-weight: 500;
    padding: 9px 14px; border-radius: 10px;
    transition: background .2s, color .2s;
}
.admin-link svg { width: 17px; height: 17px; }
.admin-link:hover { background: #f0ebe3; color: var(--ink); }

.cart-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: 46px; height: 46px;
    border: 1px solid var(--line); background: var(--surface);
    border-radius: 12px; color: var(--ink); cursor: pointer;
    transition: border-color .2s, box-shadow .2s, transform .1s;
}
.cart-btn svg { width: 21px; height: 21px; }
.cart-btn:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.cart-btn:active { transform: scale(.96); }
.cart-count {
    position: absolute; top: -7px; right: -7px;
    min-width: 20px; height: 20px; padding: 0 5px;
    display: grid; place-items: center;
    background: var(--primary); color: #fff;
    font-size: .72rem; font-weight: 700;
    border-radius: 999px; border: 2px solid var(--surface);
}

/* =============================== HERO =============================== */
.hero {
    max-width: var(--maxw); margin: 0 auto; text-align: center;
    padding: clamp(34px, 6vw, 62px) clamp(16px, 5vw, 56px) 6px;
}
.hero-eyebrow {
    display: inline-block; font-size: .82rem; font-weight: 600;
    color: var(--primary-600); background: var(--primary-50);
    padding: 6px 14px; border-radius: 999px; margin-bottom: 18px;
}
.hero h1 {
    font-family: 'Fraunces', Georgia, serif; font-weight: 600;
    font-size: clamp(2rem, 5vw, 3.3rem); line-height: 1.1; letter-spacing: -.02em;
}
.hero h1 em { color: var(--primary); font-style: italic; }
.hero-sub { color: var(--muted); margin-top: 14px; font-size: 1.02rem; }

.search-box {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); border: 1px solid var(--line);
    padding: 6px 18px; border-radius: 999px;
    box-shadow: var(--shadow-md);
    width: min(560px, 100%); margin: 26px auto 0;
    transition: border-color .2s, box-shadow .2s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }
.search-ico { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search-box input {
    flex: 1; border: none; outline: none; background: none;
    font-size: 1rem; font-family: inherit; color: var(--ink); padding: 11px 0;
}

/* ============================== LAYOUT ============================== */
.container {
    max-width: var(--maxw); margin: 0 auto;
    display: grid; grid-template-columns: 220px 1fr; gap: 34px;
    padding: 30px clamp(16px, 5vw, 56px) 70px;
}

.sidebar { position: sticky; top: 84px; align-self: start; }
.sidebar-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: 1.1rem; font-weight: 600; margin-bottom: 12px;
}
.category-list { display: flex; flex-direction: column; gap: 3px; }
.cat-item {
    width: 100%; text-align: left;
    background: none; border: none; outline: none;
    font-family: inherit; font-size: .92rem;
    padding: 10px 14px; border-radius: 10px; cursor: pointer;
    color: var(--muted);
    transition: background .18s, color .18s, padding .18s;
}
.cat-item:hover { background: #efe9e0; color: var(--ink); padding-left: 18px; }
.cat-item.is-active { background: var(--primary-50); color: var(--primary-600); font-weight: 600; }

/* ============================= PRODUITS ============================= */
.products-section { min-width: 0; }
.results-bar { margin-bottom: 16px; }
.results-count { color: var(--muted); font-size: .9rem; }

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 20px;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    display: flex; flex-direction: column;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: #dcd3c6;
}

.cover-wrap {
    position: relative;
    aspect-ratio: 3 / 4;
    border-radius: 11px; overflow: hidden;
    background: #f1ece4; margin-bottom: 13px;
}
.cover-img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s ease; }
.product-card:hover .cover-img { transform: scale(1.04); }

.badge {
    position: absolute; top: 9px; left: 9px;
    background: rgba(42,37,33,.72); color: #fff;
    padding: 4px 10px; border-radius: 999px;
    font-size: .66rem; font-weight: 600; letter-spacing: .03em;
    backdrop-filter: blur(4px); text-transform: uppercase;
}
.badge-out {
    position: absolute; inset: 0;
    display: grid; place-items: center;
    background: rgba(42,37,33,.55); color: #fff;
    font-weight: 700; font-size: .85rem; letter-spacing: .04em;
}

.product-title {
    font-family: 'Fraunces', Georgia, serif;
    font-size: .99rem; font-weight: 600; line-height: 1.25;
    margin-bottom: 3px;
}
.product-author { font-size: .78rem; color: var(--muted); margin-bottom: 8px; }
.product-stock { font-size: .74rem; font-weight: 600; margin-bottom: 10px; }
.in-stock  { color: var(--success); }
.low-stock { color: var(--primary-600); }
.no-stock  { color: var(--danger); }

.price-row {
    margin-top: auto; margin-bottom: 11px;
    font-weight: 700; font-size: 1.12rem; color: var(--primary-600);
}
.price-na { font-size: .85rem; font-weight: 600; color: var(--muted); }

.btn-add {
    width: 100%; padding: 11px; border: none; border-radius: 10px;
    background: var(--primary); color: #fff;
    font-family: inherit; font-size: .87rem; font-weight: 600;
    cursor: pointer; box-shadow: var(--shadow-sm);
    transition: background .2s, transform .1s;
}
.btn-add:hover:not(:disabled) { background: var(--primary-600); }
.btn-add:active:not(:disabled) { transform: scale(.98); }
.btn-add:disabled { background: #cfc7bb; cursor: not-allowed; box-shadow: none; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ========================== PAGINATION ========================== */
.pagination {
    display: flex; flex-wrap: wrap; justify-content: center; align-items: center;
    gap: 6px; margin-top: 36px;
}
.pagination[hidden] { display: none; }

.page-btn {
    min-width: 40px; height: 40px; padding: 0 12px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--line); background: var(--surface);
    border-radius: 10px; cursor: pointer;
    font-family: inherit; font-size: .9rem; font-weight: 600; color: var(--ink);
    transition: background .18s, border-color .18s, color .18s, transform .1s;
}
.page-btn:hover:not(:disabled):not(.is-current) {
    background: var(--primary-50); border-color: var(--primary); color: var(--primary-600);
}
.page-btn:active:not(:disabled) { transform: scale(.96); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

.page-num.is-current {
    background: var(--primary); border-color: var(--primary); color: #fff;
    cursor: default;
}
.page-nav { font-weight: 500; }
.page-ellipsis {
    min-width: 24px; text-align: center; color: var(--muted); user-select: none;
}

/* ========================== PANIER (tiroir) ========================== */
.cart-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(42,37,33,.5); backdrop-filter: blur(2px);
    display: flex; justify-content: flex-end;
    animation: fade .2s ease;
}
.cart-overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.cart-drawer {
    background: var(--surface);
    width: min(430px, 100%); height: 100%;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slide .28s cubic-bezier(.22,.61,.36,1);
}
@keyframes slide { from { transform: translateX(40px); opacity: .4 } to { transform: none; opacity: 1 } }

.cart-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 22px 24px; border-bottom: 1px solid var(--line);
}
.cart-head h2 { font-family: 'Fraunces', Georgia, serif; font-size: 1.4rem; font-weight: 600; }
.icon-btn {
    width: 34px; height: 34px; border: none; background: none;
    font-size: 26px; line-height: 1; color: var(--muted);
    border-radius: 8px; cursor: pointer;
    transition: background .2s, color .2s;
}
.icon-btn:hover { background: #f0ebe3; color: var(--ink); }

.cart-items { flex: 1; overflow-y: auto; padding: 18px 24px; }
.cart-empty { text-align: center; color: var(--muted); padding: 40px 0; }

.cart-line {
    display: flex; gap: 12px; align-items: center;
    padding: 12px 0; border-bottom: 1px dashed var(--line);
}
.cart-line-cover { width: 44px; height: 58px; border-radius: 6px; object-fit: cover; flex: none; }
.cart-line-info { flex: 1; min-width: 0; }
.cart-line-title { font-weight: 600; font-size: .88rem; line-height: 1.3; }
.cart-line-price { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.qty { display: flex; align-items: center; gap: 6px; flex: none; }
.qty button {
    width: 26px; height: 26px; border: 1px solid var(--line);
    background: #faf7f2; border-radius: 7px; cursor: pointer;
    font-weight: 700; color: var(--ink); line-height: 1;
    transition: background .15s, border-color .15s;
}
.qty button:hover:not(:disabled) { background: #f0ebe3; border-color: #d8cfc2; }
.qty button:disabled { opacity: .4; cursor: not-allowed; }
.qty span { min-width: 20px; text-align: center; font-weight: 700; font-size: .88rem; }

.cart-foot { border-top: 1px solid var(--line); padding: 18px 24px 22px; background: #fdfbf8; }
.cart-total {
    display: flex; justify-content: space-between; align-items: baseline;
    font-size: 1.05rem; margin-bottom: 16px;
}
.cart-total strong { font-size: 1.3rem; color: var(--primary-600); }

.checkout-form label { display: block; font-size: .78rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.checkout-form input {
    width: 100%; padding: 11px 12px; margin-bottom: 12px;
    border: 1px solid var(--line); border-radius: 10px;
    font-family: inherit; font-size: .95rem; outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.checkout-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-50); }

.btn-whatsapp {
    width: 100%; display: flex; align-items: center; justify-content: center; gap: 9px;
    padding: 13px; border: none; border-radius: 10px;
    background: var(--wa); color: #fff;
    font-family: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
    transition: background .2s, transform .1s;
}
.btn-whatsapp svg { width: 19px; height: 19px; }
.btn-whatsapp:hover:not(:disabled) { background: var(--wa-600); }
.btn-whatsapp:active:not(:disabled) { transform: scale(.99); }
.btn-whatsapp:disabled { opacity: .6; cursor: not-allowed; }
.checkout-note { font-size: .72rem; color: var(--muted); text-align: center; margin-top: 9px; }

/* ============================== TOAST ============================== */
.toast {
    position: fixed; left: 50%; bottom: 30px;
    transform: translateX(-50%) translateY(20px);
    background: var(--ink); color: #fff;
    padding: 13px 24px; border-radius: 12px;
    font-size: .92rem; font-weight: 600;
    box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; z-index: 2000;
    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); }

.footer { text-align: center; padding: 30px 16px 40px; color: var(--muted); font-size: .85rem; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 900px) {
    .container { grid-template-columns: 1fr; gap: 18px; }
    .sidebar {
        position: static;
        /* Indispensable : sans min-width:0, un élément de grille prend la largeur
           de son contenu (min-width:auto par défaut). Les chips de catégories
           élargiraient alors toute la page au lieu de défiler horizontalement. */
        min-width: 0;
        background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius); padding: 14px 16px;
    }
    .sidebar-title { margin-bottom: 10px; }
    .category-list {
        flex-direction: row; flex-wrap: nowrap;
        overflow-x: auto; gap: 8px; padding-bottom: 4px;
    }
    .cat-item { width: auto; white-space: nowrap; border: 1px solid var(--line); padding: 8px 14px; }
    .cat-item:hover, .cat-item.is-active { padding-left: 14px; }
}

@media (max-width: 560px) {
    .brand-logo { height: 34px; }
    .admin-link span { display: none; }
    .admin-link { padding: 9px; }
    .products-grid { grid-template-columns: repeat(auto-fill, minmax(144px, 1fr)); gap: 13px; }
    .product-card { padding: 10px; }
    .cart-drawer { width: 100%; }
    /* Sur mobile, les boutons de navigation ne gardent que la flèche */
    .page-label { display: none; }
    .page-btn { min-width: 38px; height: 38px; padding: 0 9px; }
}

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