/* =============================================================
   Back Market style comparison system — tray, modal, and the
   compare checkbox overlay on product cards.
   Class prefix: .bm-compare-*
   ============================================================= */

:root {
    --bmc-ink:       #1a1d24;
    --bmc-muted:     #57617c;
    --bmc-line:      #e8eaf0;
    --bmc-surface:   #ffffff;
    --bmc-bg:        #f6f7fa;
    --bmc-pink:      #c20056;
    --bmc-shadow-md: 0 12px 32px -12px rgba(15, 18, 22, 0.18);
    --bmc-shadow-lg: 0 24px 60px -20px rgba(15, 18, 22, 0.24);
    --bmc-tr:        220ms cubic-bezier(.2,.7,.2,1);
}

/* -------------------------------------------------------------
   1. COMPARE CHECKBOX OVERLAY (top-right of every product card)
   ------------------------------------------------------------- */
/* Used by:
   - the existing `onclick="addToCompare(id)"` buttons (upgraded by JS), and
   - explicit `<span class="bm-compare-overlay" data-compare-overlay>` markup
     in custom product cards (e.g. renewed/obsolete page). */
.bm-compare-overlay {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #d6d8df;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 4;
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 160ms ease, transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
/* Hover-reveal on every common card container */
.position-relative:hover > .bm-compare-overlay,
.card:hover > .bm-compare-overlay,
[class*="product"]:hover .bm-compare-overlay,
.rn-card:hover .bm-compare-overlay,
.rn-card-media:hover .bm-compare-overlay,
.aiz-card-box:hover .bm-compare-overlay,
.product-card:hover .bm-compare-overlay,
[class*="product_box"]:hover .bm-compare-overlay {
    opacity: 1;
    transform: translateY(0);
}
/* Active state is always visible, regardless of hover */
.bm-compare-overlay.is-active,
.bm-compare-overlay[data-compare-checked="1"] {
    opacity: 1 !important;
    transform: translateY(0) !important;
}
/* Touch devices: no hover, so always visible */
@media (hover: none) {
    .bm-compare-overlay {
        opacity: 1;
        transform: translateY(0);
    }
}
.bm-compare-overlay:hover {
    background: #fff;
    border-color: var(--bmc-ink);
}
.bm-compare-overlay svg {
    width: 14px;
    height: 14px;
    color: transparent;
    transition: color 160ms ease;
}
.bm-compare-overlay.is-active,
.bm-compare-overlay[data-compare-checked="1"] {
    opacity: 1;
    transform: translateY(0);
    background: var(--bmc-ink);
    border-color: var(--bmc-ink);
}
.bm-compare-overlay.is-active svg,
.bm-compare-overlay[data-compare-checked="1"] svg {
    color: #fff;
}
.bm-compare-overlay-label {
    position: absolute;
    right: 36px;
    top: 50%;
    transform: translateY(-50%);
    background: #fff;
    border: 1px solid #d6d8df;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--bmc-ink);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 160ms ease;
}
.bm-compare-overlay:hover .bm-compare-overlay-label { opacity: 1; }

/* -------------------------------------------------------------
   2. BOTTOM TRAY
   ------------------------------------------------------------- */
.bm-compare-tray {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 1040;
    background: var(--bmc-surface);
    border: 1px solid var(--bmc-line);
    border-radius: 16px;
    box-shadow: var(--bmc-shadow-lg);
    transform: translateY(120%);
    opacity: 0;
    visibility: hidden;
    transition: opacity 220ms ease, transform 260ms cubic-bezier(.2,.7,.2,1), visibility 0s linear 260ms;
}
.bm-compare-tray.is-visible {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
    transition: opacity 220ms ease, transform 260ms cubic-bezier(.2,.7,.2,1), visibility 0s linear 0s;
}
.bm-compare-tray-inner {
    display: grid;
    grid-template-columns: minmax(220px, auto) 1fr minmax(220px, auto);
    gap: 24px;
    align-items: center;
    padding: 16px 20px;
}
.bm-compare-tray-head {
    display: flex;
    align-items: center;
    gap: 12px;
}
.bm-compare-tray-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--bmc-bg);
    color: var(--bmc-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.bm-compare-tray-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--bmc-ink);
    line-height: 1.2;
}
.bm-compare-tray-sub {
    font-size: 13px;
    color: var(--bmc-muted);
    line-height: 1.2;
    margin-top: 2px;
}
.bm-compare-tray-slots {
    display: grid;
    grid-template-columns: repeat(var(--cmp-slots, 4), minmax(0, 1fr));
    gap: 12px;
}
.bm-compare-tray[data-compare-max="2"] .bm-compare-tray-slots { --cmp-slots: 2; }
.bm-compare-tray[data-compare-max="3"] .bm-compare-tray-slots { --cmp-slots: 3; }
.bm-compare-tray[data-compare-max="4"] .bm-compare-tray-slots { --cmp-slots: 4; }

.bm-compare-slot {
    position: relative;
    height: 72px;
    border: 1px solid var(--bmc-line);
    border-radius: 12px;
    background: var(--bmc-surface);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}
.bm-compare-slot.is-empty {
    color: var(--bmc-muted);
    background: var(--bmc-bg);
    border-style: dashed;
    justify-content: flex-start;
    font-size: 13px;
    line-height: 1.3;
}
.bm-compare-slot-plus {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    background: #e5e7ec;
    color: var(--bmc-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}
.bm-compare-slot-empty-text {
    font-weight: 500;
}
.bm-compare-slot-thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    background: var(--bmc-bg);
    overflow: hidden;
    flex-shrink: 0;
}
.bm-compare-slot-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.bm-compare-slot-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--bmc-ink);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.bm-compare-slot-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 0;
    background: #fff;
    color: var(--bmc-ink);
    box-shadow: 0 2px 6px rgba(15, 18, 22, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: background 140ms ease;
}
.bm-compare-slot-remove:hover { background: #f0f0f3; }

.bm-compare-tray-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    justify-content: flex-end;
}
.bm-compare-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 44px;
    padding: 0 22px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    background: transparent;
    transition: background var(--bmc-tr), color var(--bmc-tr), border-color var(--bmc-tr), opacity var(--bmc-tr);
}
.bm-compare-btn--ghost {
    background: transparent;
    color: var(--bmc-ink);
    border-color: transparent;
}
.bm-compare-btn--ghost:hover { background: var(--bmc-bg); }
.bm-compare-btn--primary {
    background: var(--bmc-ink);
    color: #fff;
}
.bm-compare-btn--primary:hover { background: #000; }
.bm-compare-btn[disabled],
.bm-compare-btn.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* -------------------------------------------------------------
   3. MODAL
   ------------------------------------------------------------- */
.bm-compare-modal {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: none;
}
.bm-compare-modal.is-open { display: block; }
.bm-compare-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 18, 22, 0.45);
    opacity: 0;
    transition: opacity 220ms ease;
}
.bm-compare-modal.is-open .bm-compare-modal-overlay { opacity: 1; }
.bm-compare-modal-wrap {
    position: absolute;
    inset: 32px 32px;
    background: var(--bmc-surface);
    border-radius: 18px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--bmc-shadow-lg);
    max-width: 1200px;
    margin: 0 auto;
    transform: translateY(20px);
    opacity: 0;
    transition: opacity 220ms ease, transform 260ms cubic-bezier(.2,.7,.2,1);
}
/* The AJAX-loaded content host must also be a flex column so head stays
   pinned and body actually scrolls — without this, content overflows
   the wrap silently and only the top (images) ends up visible. */
#bm-compare-modal-content {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.bm-compare-modal.is-open .bm-compare-modal-wrap {
    transform: translateY(0);
    opacity: 1;
}
.bm-compare-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 24px 28px;
    border-bottom: 1px solid var(--bmc-line);
    background: #fff;
}
.bm-compare-modal-title-area {
    display: flex;
    align-items: center;
    gap: 14px;
}
.bm-compare-modal-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bmc-bg);
    color: var(--bmc-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.bm-compare-modal-title {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
    color: var(--bmc-ink);
    letter-spacing: -0.01em;
}
.bm-compare-modal-sub {
    margin: 4px 0 0;
    font-size: 13.5px;
    color: var(--bmc-muted);
}
.bm-compare-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: transparent;
    border: 0;
    color: var(--bmc-ink);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 160ms ease;
}
.bm-compare-modal-close:hover { background: var(--bmc-bg); }

.bm-compare-modal-head {
    flex-shrink: 0;
}
.bm-compare-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px 40px;
    background: #fff;
    scrollbar-width: thin;
}
.bm-compare-modal-body::-webkit-scrollbar { width: 8px; }
.bm-compare-modal-body::-webkit-scrollbar-track { background: transparent; }
.bm-compare-modal-body::-webkit-scrollbar-thumb {
    background: #d6d8df;
    border-radius: 4px;
}
.bm-compare-modal-body::-webkit-scrollbar-thumb:hover { background: #b8bcc7; }

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

/* Product cards row — scrolls naturally with the rest of the modal content
   (user wants single scroll flow, not sticky cards) */
.bm-compare-products-sticky {
    padding: 4px 0 16px;
    margin: 0 0 20px;
    border-bottom: 1px solid var(--bmc-line);
}
.bm-compare-products {
    display: grid;
    grid-template-columns: repeat(var(--cmp-cols, 4), minmax(0, 1fr));
    gap: 12px;
}
.bm-compare-product {
    position: relative;
    background: var(--bmc-surface);
    border: 1px solid var(--bmc-line);
    border-radius: 10px;
    padding: 10px 10px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
}
.bm-compare-product-remove {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 26px;
    height: 26px;
    border: 1px solid var(--bmc-line);
    border-radius: 999px;
    background: #fff;
    color: var(--bmc-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.bm-compare-product-remove:hover { background: var(--bmc-bg); }
.bm-compare-product-thumb {
    display: block;
    width: 100%;
    max-width: 110px;
    aspect-ratio: 1 / 1;
    background: var(--bmc-bg);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}
.bm-compare-product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    padding: 6px;
}
.bm-compare-product-meta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    text-align: center;
}
.bm-compare-product-brand {
    font-size: 10.5px;
    font-weight: 700;
    color: var(--bmc-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.bm-compare-product-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--bmc-ink) !important;
    text-decoration: none !important;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.bm-compare-product-name:hover { color: var(--bmc-ink) !important; text-decoration: none !important; }
.bm-compare-product-cat {
    font-size: 11.5px;
    color: var(--bmc-muted);
}
.bm-compare-product-pricing {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    margin-top: 2px;
}
.bm-compare-product-starting {
    font-size: 11px;
    color: var(--bmc-muted);
}
.bm-compare-product-price {
    font-size: 15px;
    font-weight: 700;
    color: var(--bmc-ink);
}
.bm-compare-product-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 34px;
    background: var(--bmc-ink);
    color: #fff !important;
    border-radius: 8px;
    font-weight: 700;
    font-size: 12.5px;
    text-decoration: none !important;
    margin-top: 4px;
    transition: background 160ms ease;
}
.bm-compare-product-cta:hover { background: #000; color: #fff !important; }

/* Sections */
.bm-compare-sections { display: flex; flex-direction: column; gap: 20px; }
.bm-compare-section {
    background: var(--bmc-surface);
    border-top: 1px solid var(--bmc-line);
    padding-top: 16px;
}
.bm-compare-sections + .bm-compare-sections { margin-top: 4px; }
.bm-compare-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--bmc-ink);
    margin: 0 0 10px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.bm-compare-row.bm-compare-row-long .bm-compare-cell {
    align-items: flex-start;
    font-size: 13px;
    line-height: 1.5;
    color: var(--bmc-muted);
    white-space: normal;
    text-align: left;
}
.bm-compare-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.bm-compare-tag-chip {
    display: inline-block;
    padding: 3px 8px;
    background: #eef0f5;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--bmc-ink);
    line-height: 1.3;
}
.bm-compare-row {
    display: grid;
    grid-template-columns: repeat(var(--cmp-cols, 4), minmax(0, 1fr));
    gap: 12px;
    background: var(--bmc-bg);
    border-radius: 10px;
    padding: 14px;
}
.bm-compare-cell {
    font-size: 14px;
    color: var(--bmc-ink);
    line-height: 1.4;
    word-break: break-word;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 160ms ease;
}
/* Highlight cells whose values differ across the row — Back Market parity */
.bm-compare-cell.is-different {
    background: #fff7d6;
    color: #1a1d24;
    font-weight: 600;
    box-shadow: inset 0 0 0 1px #f4d27a;
}
.bm-compare-muted {
    color: var(--bmc-muted);
    font-style: italic;
    font-size: 13px;
}
.bm-compare-value-strong {
    font-weight: 700;
    font-size: 15px;
}
.bm-compare-bar-num {
    margin-left: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--bmc-muted);
    flex-shrink: 0;
}
.bm-compare-subrow {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}
.bm-compare-sublabel {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--bmc-muted);
    text-transform: none;
}

/* Rating stars */
.bm-compare-stars {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.bm-compare-rating-num {
    margin-left: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--bmc-ink);
}

/* Color dots */
.bm-compare-colors {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.bm-compare-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 1px solid rgba(15, 18, 22, 0.15);
    display: inline-block;
}
.bm-compare-color-more {
    font-size: 12px;
    color: var(--bmc-muted);
    font-weight: 600;
}

/* Score bars */
.bm-compare-bar {
    width: 100%;
    height: 8px;
    background: #e5e7ec;
    border-radius: 999px;
    overflow: hidden;
}
.bm-compare-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #2b6cff 0%, #2cd6a4 100%);
    border-radius: 999px;
    transition: width 480ms cubic-bezier(.2,.7,.2,1);
}

/* -------------------------------------------------------------
   Responsive
   ------------------------------------------------------------- */
@media (max-width: 1199px) {
    .bm-compare-tray-inner {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    .bm-compare-tray-actions { justify-content: stretch; }
    .bm-compare-tray-actions .bm-compare-btn { flex: 1; }
}
@media (max-width: 767px) {
    .bm-compare-tray {
        left: 8px;
        right: 8px;
        bottom: 8px;
        border-radius: 12px;
    }
    .bm-compare-tray-inner { padding: 12px; }
    .bm-compare-tray[data-compare-max="4"] .bm-compare-tray-slots { --cmp-slots: 2; }
    .bm-compare-modal-wrap { inset: 0; border-radius: 0; max-width: none; }
    .bm-compare-modal-body { padding: 16px; }
    .bm-compare-products { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bm-compare-product { padding: 14px; }
}
@media (max-width: 480px) {
    .bm-compare-tray[data-compare-max="3"] .bm-compare-tray-slots,
    .bm-compare-tray[data-compare-max="4"] .bm-compare-tray-slots {
        --cmp-slots: 2;
    }
    .bm-compare-slot-empty-text { font-size: 11.5px; }
}

/* =========================================================================
   Back Market-style visible Compare pill on every product card (bm-pcard)
   ========================================================================= */
.bm-pcard {
    position: relative;
}
.bm-pcard-compare.bm-compare-overlay {
    /* override the default tiny circle overlay — make it a visible pill */
    position: absolute;
    top: 10px;
    right: 10px;
    width: auto;
    height: 32px;
    padding: 0 6px 0 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d6d8df;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    z-index: 4;
    opacity: 0;                       /* hidden by default — reveal on card hover */
    transform: translateY(-4px);
    color: #0a1230;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 200ms ease, opacity 200ms ease, box-shadow 160ms ease;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.06);
}
.bm-pcard:hover .bm-pcard-compare.bm-compare-overlay,
.bm-pcard:focus-within .bm-pcard-compare.bm-compare-overlay {
    opacity: 1;
    transform: translateY(0);
}
.bm-pcard-compare.bm-compare-overlay:hover {
    background: #ffffff;
    border-color: #0a1230;
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(15, 23, 42, 0.12);
}
/* Touch devices: hover never fires — always reveal */
@media (hover: none) {
    .bm-pcard-compare.bm-compare-overlay {
        opacity: 1;
        transform: none;
    }
}
.bm-pcard-compare-label {
    display: inline-block;
    pointer-events: none;
    user-select: none;
    letter-spacing: -0.005em;
}
.bm-pcard-compare-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 1.6px solid #c4c7cf;
    background: #ffffff;
    transition: background 160ms ease, border-color 160ms ease;
}
.bm-pcard-compare-check {
    color: transparent;
    transition: color 160ms ease;
}
/* Active state — pill becomes solid dark, circle fills, checkmark appears.
   Always visible (regardless of hover) so user knows the product is currently in the tray. */
.bm-pcard-compare.bm-compare-overlay.is-active,
.bm-pcard-compare.bm-compare-overlay[data-compare-checked="1"],
.bm-pcard:hover .bm-pcard-compare.bm-compare-overlay.is-active,
.bm-pcard:hover .bm-pcard-compare.bm-compare-overlay[data-compare-checked="1"] {
    background: #0a1230 !important;
    border-color: #0a1230 !important;
    color: #ffffff;
    opacity: 1 !important;
    transform: none !important;
}
.bm-pcard-compare.is-active .bm-pcard-compare-circle,
.bm-pcard-compare[data-compare-checked="1"] .bm-pcard-compare-circle {
    background: #ffffff;
    border-color: #ffffff;
}
.bm-pcard-compare.is-active .bm-pcard-compare-check,
.bm-pcard-compare[data-compare-checked="1"] .bm-pcard-compare-check {
    color: #0a1230;
}

@media (max-width: 575px) {
    .bm-pcard-compare.bm-compare-overlay {
        height: 28px;
        padding: 0 4px 0 10px;
        font-size: 11.5px;
        gap: 6px;
    }
    .bm-pcard-compare-circle { width: 18px; height: 18px; }
    /* On very narrow cards, hide label to save space */
    .bm-pcard-compare-label { display: none; }
    .bm-pcard-compare.bm-compare-overlay { padding: 0 6px; width: 30px; }
}

