/* Jida Panier : panier latéral (reprend goya-child/assets/css/sidecart.css).
   Nouveautés : barre d'activité fine au lieu du voile de chargement, lignes fantômes au
   premier chargement, ligne qui se replie quand on la retire, message d'erreur par ligne. */

:root {
    --jsc-green:       #254636;
    --jsc-green-light: #2e5542;
    --jsc-orange:      #e8601c;
    --jsc-beige:       #f5efe6;
    --jsc-beige-dark:  #ece4d8;
    --jsc-text:        #1a1a1a;
    --jsc-muted:       #6b6660;
    --jsc-white:       #ffffff;
    --jsc-red:         #c0391b;
    --jsc-radius:      14px;
    --jsc-width:       380px;
}

/* ── Désactiver le sidecart natif Goya ─────────────────── */
/* Garder le panier natif disponible jusqu'à l'initialisation du remplacement. */
body.jm-sidecart-ready #side-cart { display: none !important; }

/* ── Overlay ────────────────────────────────────────────── */
#jm-cart-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 99998;
    transition: background 0.3s ease;
}
#jm-cart-overlay.is-open {
    background: rgba(0,0,0,0.45);
}

/* ── Panel ──────────────────────────────────────────────── */
#jm-cart {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: var(--jsc-width);
    max-width: 100vw;
    background: var(--jsc-beige);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    transform: translateX(110%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 40px rgba(0,0,0,0.15);
}
#jm-cart.is-open {
    transform: translateX(0);
}

/* ── Header ─────────────────────────────────────────────── */
#jm-cart-header {
    position: relative;
    background: var(--jsc-green);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
#jm-cart-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--jsc-white);
    display: flex;
    align-items: center;
    gap: 10px;
}
#jm-cart-count {
    background: var(--jsc-orange);
    color: var(--jsc-white);
    font-size: 11px;
    font-weight: 800;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    line-height: 1;
}
#jm-cart-close {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 8px;
    color: var(--jsc-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    padding: 0;
}
#jm-cart-close:hover { background: rgba(255,255,255,0.25); }
#jm-cart-close svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

/* ── Body scrollable ────────────────────────────────────── */
#jm-cart-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

/* ── État vide ──────────────────────────────────────────── */
#jm-cart-empty {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 12px;
    color: var(--jsc-muted);
    text-align: center;
    padding: 40px 20px;
}
#jm-cart-empty svg {
    width: 48px;
    height: 48px;
    stroke: var(--jsc-beige-dark);
    fill: none;
    stroke-width: 1.5;
}
#jm-cart-empty p {
    font-size: 14px;
    font-weight: 500;
    color: var(--jsc-muted);
    margin: 0;
}

/* ── Accès de secours et erreurs ───────────────────────── */
#jm-cart-safety { flex-shrink: 0; padding: 10px 16px; background: #fff; font-size: 13px; }
#jm-cart-safety a { color: #254636; text-decoration: underline; }
#jm-cart-error { margin-top: 8px; color: #922b21; }
#jm-cart-retry { margin-top: 8px; padding: 7px 12px; cursor: pointer; }
#jm-cart [hidden] { display: none !important; }

/* ── Item card ──────────────────────────────────────────── */
.jm-cart-item {
    background: var(--jsc-white);
    border-radius: var(--jsc-radius);
    border: 1px solid var(--jsc-beige-dark);
    padding: 12px;
    display: grid;
    grid-template-columns: 64px 1fr;
    gap: 12px;
    animation: jm-fadeIn 0.2s ease both;
}
@keyframes jm-fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Thumbnail */
.jm-cart-item-img {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--jsc-beige);
    flex-shrink: 0;
}
.jm-cart-item-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Contenu */
.jm-cart-item-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* Ligne titre + bouton supprimer */
.jm-cart-item-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6px;
}
.jm-cart-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--jsc-text);
    line-height: 1.3;
    text-decoration: none;
    flex: 1;
    min-width: 0;
}
.jm-cart-item-remove {
    width: 22px;
    height: 22px;
    background: var(--jsc-beige-dark);
    border: none;
    border-radius: 50%;
    color: var(--jsc-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    font-size: 14px;
    line-height: 1;
}
.jm-cart-item-remove:hover {
    background: #fde8e0;
    color: var(--jsc-orange);
}
.jm-cart-item-remove svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2.5; }

/* Prix unitaire */
.jm-cart-item-unit-price {
    font-size: 11px;
    color: var(--jsc-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}
.jm-cart-item-unit-price .original {
    text-decoration: line-through;
    opacity: 0.7;
}
.jm-cart-item-unit-price .discounted {
    color: var(--jsc-orange);
    font-weight: 700;
}
.jm-cart-item-discount-badge {
    display: inline-flex;
    align-items: center;
    background: #e8f5ec;
    color: #1a5c30;
    border: 1px solid #c3e6cc;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 20px;
}

/* Ligne qty + sous-total */
.jm-cart-item-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Contrôle qty */
.jm-cart-qty {
    display: flex;
    align-items: center;
    background: var(--jsc-beige);
    border: 1.5px solid var(--jsc-beige-dark);
    border-radius: 8px;
    overflow: hidden;
    height: 32px;
}
.jm-cart-qty-btn {
    width: 30px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--jsc-green);
    font-size: 18px;
    font-weight: 300;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.12s;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}
.jm-cart-qty-btn:active { background: var(--jsc-beige-dark); }
.jm-cart-qty-val {
    min-width: 28px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--jsc-text);
    user-select: none;
}

/* Sous-total ligne */
.jm-cart-item-subtotal {
    font-size: 15px;
    font-weight: 800;
    color: var(--jsc-text);
    white-space: nowrap;
}

/* ── Footer ─────────────────────────────────────────────── */
#jm-cart-footer {
    background: var(--jsc-white);
    border-top: 1px solid var(--jsc-beige-dark);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

/* Récap remises */
#jm-cart-discounts {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.jm-cart-discount-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #1a5c30;
    background: #e8f5ec;
    border-radius: 6px;
    padding: 4px 10px;
}
.jm-cart-discount-line span:last-child {
    font-weight: 700;
}

/* Total */
#jm-cart-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#jm-cart-total-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--jsc-muted);
}
#jm-cart-total-amount {
    font-size: 22px;
    font-weight: 800;
    color: var(--jsc-green);
}

/* Barre de progression */
#jm-cart-progress {
    background: var(--jsc-beige);
    border-radius: 10px;
    padding: 10px 12px;
}
#jm-cart-progress-text {
    font-size: 12px;
    color: var(--jsc-text);
    margin-bottom: 7px;
    line-height: 1.4;
}
#jm-cart-progress-text strong { color: var(--jsc-orange); }
#jm-cart-progress-rail {
    height: 5px;
    background: var(--jsc-beige-dark);
    border-radius: 3px;
    overflow: hidden;
}
#jm-cart-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--jsc-green), var(--jsc-orange));
    border-radius: 3px;
    transition: width 0.4s ease;
    width: 0%;
}

/* CTA */
#jm-cart-cta {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.jm-cart-btn {
    width: 100%;
    height: 50px;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    border: none;
    -webkit-tap-highlight-color: transparent;
}
.jm-cart-btn svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 2; flex-shrink: 0; }
.jm-cart-btn--secondary {
    background: transparent;
    color: var(--jsc-green);
    border: 2px solid var(--jsc-green);
    height: 44px;
}
.jm-cart-btn--secondary:hover { background: var(--jsc-beige-dark); }
.jm-cart-btn--primary {
    background: var(--jsc-green);
    color: var(--jsc-white);
    box-shadow: 0 3px 14px rgba(37,70,54,0.28);
}
.jm-cart-btn--primary:hover { background: var(--jsc-green-light); }
.jm-cart-btn--primary:active { transform: scale(0.98); }


/* ── Jida Panier ────────────────────────────────────────── */
#jm-cart-lines { display: flex; flex-direction: column; gap: 10px; }
#jm-cart-body { overscroll-behavior: contain; }
#jm-cart-close:focus-visible,
#jm-cart .jm-cart-qty-btn:focus-visible,
#jm-cart .jm-cart-item-remove:focus-visible { outline: 2px solid var(--jsc-orange); outline-offset: 2px; }

/* Barre d'activité : le panneau reste utilisable pendant l'enregistrement. */
#jpan-busy {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 3px;
    overflow: hidden;
    opacity: 0;
    transition: opacity .2s;
}
#jpan-busy::before {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 35%;
    background: var(--jsc-orange);
    border-radius: 2px;
    animation: jpan-slide 1s ease-in-out infinite;
}
#jm-cart.is-busy #jpan-busy { opacity: 1; transition-delay: .25s; }
@keyframes jpan-slide { from { left: -35%; } to { left: 100%; } }

/* Lignes fantômes (premier chargement uniquement). */
#jpan-skeleton { display: flex; flex-direction: column; gap: 10px; }
.jpan-sk {
    height: 90px;
    border-radius: var(--jsc-radius);
    background: linear-gradient(90deg, #fff 0%, var(--jsc-beige) 50%, #fff 100%) 0 0 / 200% 100%;
    border: 1px solid var(--jsc-beige-dark);
    animation: jpan-shimmer 1.2s linear infinite;
}
@keyframes jpan-shimmer { to { background-position: -200% 0; } }

/* Ligne retirée : repli immédiat, confirmation en arrière-plan. */
.jm-cart-item { transition: opacity .18s ease, transform .18s ease; }
.jm-cart-item.is-removing { display: none; }
.jm-cart-item-img { display: block; }
.jm-cart-item-name:hover { text-decoration: underline; }
.jm-cart-qty-btn:disabled { opacity: .35; cursor: not-allowed; }
.jm-cart-item-error {
    grid-column: 1 / -1;
    margin: 2px 0 0;
    font-size: 12px;
    line-height: 1.35;
    color: #922b21;
}

/* Départ vers la page panier pendant un enregistrement. */
#jm-cart.is-leaving .jm-cart-btn--primary { opacity: .75; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
    #jm-cart, #jm-cart-overlay, .jm-cart-item, #jm-cart-progress-bar { transition: none; }
    .jm-cart-item, #jpan-busy::before, .jpan-sk { animation: none; }
}

/* Produit ajouté depuis une carte, en attente de confirmation (0.1.1). */
.jm-cart-item.is-provisional .jm-cart-qty,
.jm-cart-item.is-provisional .jm-cart-item-subtotal { opacity: .55; }
.jm-cart-item.is-provisional .jm-cart-item-remove { visibility: hidden; }
