/* =============================================================================
   Better Add to Cart – Frontend Styles
   Desktop: centered modal popup
   Mobile (< --batc-breakpoint): slide-up bottom sheet
   Colors are driven by CSS custom properties injected inline by PHP.
   ============================================================================= */

/* CSS custom property defaults (overridden inline by PHP) */
:root {
    --batc-accent:    #c4732a;
    --batc-btn-color: #c4732a;
    --batc-radius:    16px;
    --batc-overlay-bg: rgba(0, 0, 0, 0.5);
    --batc-bg: #ffffff;
    --batc-shadow: 0 20px 60px rgba(0,0,0,0.18);
    --batc-transition: 280ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Overlay ─────────────────────────────────────────────────────────────── */
.batc-overlay {
    position: fixed;
    inset: 0;
    z-index: 99998;
    background: var(--batc-overlay-bg);
    display: flex !important;          /* overrides inline style:none via JS class */
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--batc-transition), visibility var(--batc-transition);
    /* prevent body scroll bleed */
    -webkit-tap-highlight-color: transparent;
}

.batc-overlay.batc-open {
    opacity: 1;
    visibility: visible;
}

/* ── Popup (Desktop) ─────────────────────────────────────────────────────── */
.batc-popup {
    position: relative;
    background: var(--batc-bg);
    border-radius: var(--batc-radius);
    box-shadow: var(--batc-shadow);
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px 28px 24px;
    box-sizing: border-box;
    transform: scale(0.92) translateY(8px);
    transition: transform var(--batc-transition);
    /* smooth scroll on iOS */
    -webkit-overflow-scrolling: touch;
}

.batc-overlay.batc-open .batc-popup {
    transform: scale(1) translateY(0);
}

/* ── Bottom Sheet (Mobile) ───────────────────────────────────────────────── */
.batc-overlay.batc-is-mobile {
    align-items: flex-end;
    justify-content: stretch;
}

.batc-overlay.batc-is-mobile .batc-popup {
    max-width: 100%;
    width: 100%;
    border-radius: var(--batc-radius) var(--batc-radius) 0 0;
    max-height: 90dvh;         /* dynamic viewport height for mobile browsers */
    max-height: 90vh;
    transform: translateY(100%);
    padding: 20px 20px 32px;  /* extra bottom padding above home indicator */
}

.batc-overlay.batc-is-mobile.batc-open .batc-popup {
    transform: translateY(0);
}

/* ── Close Button ────────────────────────────────────────────────────────── */
.batc-close {
    position: absolute;
    margin: 0;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    min-height: fit-content;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: #555;
    padding: 0;
    line-height: 1;
    transition: background 0.2s;
}
.batc-close:hover {
    background: #e0e0e0;
    color: #111;
}

/* ── Header (image + name + price) ──────────────────────────────────────── */
.batc-header {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
    padding-right: 36px; /* avoid overlap with close button */
}

.batc-product-img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
    background: #f5f5f5;
    transition: opacity 180ms ease, transform 220ms ease, filter 220ms ease;
    transform-origin: center;
    will-change: opacity, transform, filter;
}

.batc-product-img.batc-image-changing {
    opacity: 0.35;
    transform: scale(0.985);
    filter: saturate(0.92) blur(0.3px);
}

.batc-product-info {
    flex: 1;
    min-width: 0;
}

.batc-product-name {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.4;
    margin: 0 0 6px;
    color: #111;
    word-break: break-word;
}

.batc-price {
    font-size: 15px;
    font-weight: 600;
    color: var(--batc-accent);
    line-height: 1.3;
}

.batc-price del {
    color: #aaa;
    font-weight: 400;
    margin-right: 4px;
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.batc-divider {
    border: none;
    border-top: 1px solid #ebebeb;
    margin: 0 0 20px;
}

/* ── Variations Container ────────────────────────────────────────────────── */
.batc-variations {
    margin-bottom: 24px;
}

/* Attribute group */
.batc-attr-group {
    margin-bottom: 20px;
}

.batc-attr-group:last-child {
    margin-bottom: 0;
}

.batc-attr-label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: #333;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Pill / Chip Buttons ─────────────────────────────────────────────────── */
.batc-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.batc-pill {
    margin: 0;
    border: 1.5px solid #ddd;
    border-radius: 100px;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    transition: border-color 0.18s, color 0.18s, background 0.18s;
    white-space: nowrap;
    user-select: none;
}

.batc-pill:hover {
    border-color: var(--batc-accent);
    color: var(--batc-accent);
}

.batc-pill.selected {
    border-color: var(--batc-accent);
    background: var(--batc-accent);
    color: #fff;
}

.batc-pill.unavailable {
    opacity: 0.38;
    cursor: not-allowed;
    text-decoration: line-through;
    pointer-events: none;
}

/* ── Dropdown style ──────────────────────────────────────────────────────── */
.batc-dropdown {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: #fff;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
    transition: border-color 0.18s;
}

.batc-dropdown:focus {
    outline: none;
    border-color: var(--batc-accent);
}

/* ── Footer (qty + button) ───────────────────────────────────────────────── */
.batc-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    /* Stick to bottom of scrollable popup so ATC is always reachable */
    bottom: 0;
    z-index: 2;
    background: var(--batc-bg);
    /* Extend background flush with popup edges to cover scrolled content */
    margin: 0 -28px -24px;
    padding: 16px 28px 24px;
    /* Subtle upward shadow hint */
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.07);
}

/* Quantity stepper */
.batc-qty-wrap {
    display: flex;
    align-items: center;
    border: 1.5px solid #e2e2e2;
    border-radius: 100px;
    overflow: hidden;
    flex-shrink: 0;
    height: 52px;
    background: #f6f6f6;
}

.batc-qty-btn {
    width: 44px;
    height: 100%;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #444;
    transition: background 0.15s, color 0.15s;
    padding: 0;
    flex-shrink: 0;
    margin: 0;
}

.batc-qty-btn:hover {
    background: #ebebeb;
    color: #111;
}

.batc-qty-btn:active {
    background: #e0e0e0;
}

.batc-qty {
    width: 40px!important;
    height: 100%;
    margin: 0;
    text-align: center;
    border: none !important;
    border-left: 1px solid #e2e2e2 !important;
    border-right: 1px solid #e2e2e2 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    font-size: 15px;
    font-weight: 600;
    color: #111;
    background: #f6f6f6 !important;
    padding: 0;
    /* hide number input spin buttons */
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.batc-qty::-webkit-inner-spin-button,
.batc-qty::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.batc-qty:focus {
    outline: none;
}

/* Add to Cart button */
.batc-atc-btn {
    flex: 1;
    height: 52px;
    background: var(--batc-btn-color);
    color: #fff;
    border: none;
    margin: 0;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: opacity 0.2s, transform 0.18s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

/* Subtle inner highlight for depth */
.batc-atc-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, rgba(255,255,255,0.14), transparent 55%);
    border-radius: inherit;
    pointer-events: none;
}

.batc-atc-btn:hover:not(:disabled) {
    opacity: 0.92;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.24);
    transform: translateY(-1px);
}

.batc-atc-btn:active:not(:disabled) {
    transform: scale(0.97) translateY(0);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    opacity: 1;
}

.batc-atc-btn:disabled {
    background: #d0d0d0;
    cursor: not-allowed;
    box-shadow: none;
}

/* Cart icon inside button */
.batc-cart-icon {
    flex-shrink: 0;
}

/* ── Loading Spinner ─────────────────────────────────────────────────────── */
.batc-spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: batc-spin 0.7s linear infinite;
    flex-shrink: 0;
}

.batc-atc-btn.batc-loading .batc-spinner {
    display: block;
}

.batc-atc-btn.batc-loading .batc-cart-icon,
.batc-atc-btn.batc-loading .batc-atc-label {
    display: none;
}

@keyframes batc-spin {
    to { transform: rotate(360deg); }
}

/* ── Full-page Loading State (fetching product) ──────────────────────────── */
.batc-popup.batc-fetching {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.batc-popup.batc-fetching > *:not(.batc-close) {
    opacity: 0;
    pointer-events: none;
}

.batc-popup.batc-fetching::after {
    content: '';
    position: absolute;
    width: 36px;
    height: 36px;
    border: 3px solid #eee;
    border-top-color: var(--batc-accent);
    border-radius: 50%;
    animation: batc-spin 0.7s linear infinite;
}

/* ── Success Flash ───────────────────────────────────────────────────────── */
.batc-atc-btn.batc-success {
    background: #2e7d32;
}

/* ── Mobile-specific Adjustments ────────────────────────────────────────── */
@media (max-width: 540px) {
    .batc-popup {
        padding: 20px 16px 28px;
    }

    .batc-product-img {
        width: 64px;
        height: 64px;
    }

    .batc-product-name {
        font-size: 15px;
    }

    .batc-footer {
        gap: 8px;
        /* Adjust edge compensation for mobile popup padding */
        margin: 0 -16px -28px;
        padding: 14px 16px 28px;
    }
}

/* ── Prevent body scroll when popup is open ──────────────────────────────── */
body.batc-noscroll {
    overflow: hidden;
    /* preserve scroll position on iOS */
    position: fixed;
    width: 100%;
}
