/*
 * When the bar is shown (.visible), it covers the lower viewport. Without extra
 * space, the footer's last row (copyright, legal links) sits behind it.
 * Bootstrap's footer uses .py-4 → padding-bottom: 1.5rem !important, so this
 * rule MUST use !important or it never wins.
 * body.floating-cart-bar-visible is toggled in cart-floating-bar.js (reliable
 * in all browsers); :has() is a progressive enhancement.
 */
/*
 * scroll-padding + extra footer padding fight embedded TikTok fixed chrome: toggling them on scroll
 * reads as the whole UI "jumping". Skip these rules when #tiktok-embedded-header exists (beta / embedded).
 */
html:has(#floating-cart-bar.floating-cart-bar.visible):not(:has(#tiktok-embedded-header)),
html.floating-cart-bar-visible:not(:has(#tiktok-embedded-header)) {
    scroll-padding-bottom: max(5.5rem, calc(72px + env(safe-area-inset-bottom, 0px))) !important;
}
body:has(#floating-cart-bar.floating-cart-bar.visible):not(:has(#tiktok-embedded-header)) footer,
body.floating-cart-bar-visible:not(:has(#tiktok-embedded-header)) footer {
    /* Match .py-4 top (1.5rem) but clear bar (~48px) + fat inner padding + home indicator */
    padding-bottom: max(6.5rem, calc(1.5rem + 72px + env(safe-area-inset-bottom, 0px))) !important;
}

/* Toasts must appear above the floating cart bar and drawer */
#toastContainer {
    z-index: 12000 !important;
}

/* When floating bar is present: back-to-top sits above the bar, square with rounded corners */
.back-to-top-btn {
    bottom: 68px !important; /* Above the ~48px bar + gap */
    border-radius: 12px !important;
    z-index: 11010 !important; /* Above floating bar (11000) */
}

.back-to-top-btn:hover {
    transform: translateY(-2px);
}

/* Customer chat FAB: above fixed cart bar + TikTok chrome; below full-screen TikTok modal (15000) */
#chat-bubble-widget.chat-enabled {
    z-index: 14000 !important;
    pointer-events: auto !important;
    isolation: isolate;
}
html:has(#floating-cart-bar.visible) #chat-bubble-widget.chat-enabled,
#floating-cart-bar.visible ~ #chat-bubble-widget.chat-enabled,
html.floating-cart-bar-visible #chat-bubble-widget.chat-enabled,
body.floating-cart-bar-visible #chat-bubble-widget.chat-enabled {
    bottom: max(5.75rem, calc(96px + env(safe-area-inset-bottom, 0px))) !important;
}

/* Hide the floating cart bubble when the floating bar is present (bar is the cart entry point) */
#floatingCartButton {
    display: none !important;
}

/**
 * Floating cart bar - thin bar at bottom, slides up when cart has items (logo red).
 */
#floating-cart-bar.floating-cart-bar:not(.visible) {
    pointer-events: none !important;
}
#floating-cart-bar.floating-cart-bar.visible {
    pointer-events: none !important;
}
#floating-cart-bar.floating-cart-bar.visible:not(.floating-cart-bar-beta) .floating-cart-bar-btn,
#floating-cart-bar.floating-cart-bar.visible:not(.floating-cart-bar-beta) a.floating-cart-bar-btn {
    pointer-events: auto !important;
}
#floating-cart-bar.floating-cart-bar-beta.floating-cart-bar.visible .floating-cart-bar-inner,
#floating-cart-bar.floating-cart-bar-beta.floating-cart-bar.visible .floating-cart-bar-left,
#floating-cart-bar.floating-cart-bar-beta.floating-cart-bar.visible .floating-cart-bar-right {
    pointer-events: none !important;
}
#floating-cart-bar.floating-cart-bar-beta.floating-cart-bar.visible .floating-cart-bar-arrow,
#floating-cart-bar.floating-cart-bar-beta.floating-cart-bar.visible .announcement-mobile-button-bar {
    pointer-events: auto !important;
}

.floating-cart-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 11000;
    background: var(--primary-color, #DC143C);
    color: #fff;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.2);
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    min-height: 44px;
    max-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.floating-cart-bar.visible {
    transform: translateY(0);
}

.floating-cart-bar-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.4rem 1rem;
    padding-bottom: max(0.75rem, calc(0.4rem + env(safe-area-inset-bottom, 0px)), 12px);
    width: 100%;
    max-width: 600px;
}

.floating-cart-bar-summary {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.floating-cart-bar-summary i {
    font-size: 1rem;
}

.floating-cart-bar-sep {
    opacity: 0.85;
    padding: 0 0.15rem;
}

.floating-cart-bar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.85rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    white-space: nowrap;
}

.floating-cart-bar-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    color: #fff;
}

.floating-cart-bar-btn-checkout {
    background: #fff;
    color: var(--primary-color, #DC143C);
    border-color: #fff;
}

.floating-cart-bar-btn-checkout:hover {
    filter: brightness(1.05);
    color: var(--primary-color, #DC143C);
}

/* Beta bar: equal flex on left + right so chevron + bullhorn sit in the horizontal center as a group */
.floating-cart-bar-beta .floating-cart-bar-inner {
    justify-content: flex-start;
    gap: 0.5rem;
    max-width: 100%;
    width: 100%;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
}

.floating-cart-bar-left {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.88rem;
    font-weight: 600;
    flex: 1 1 0;
    min-width: 0;
}

.floating-cart-bar-left i {
    font-size: 0.95rem;
}

.floating-cart-bar-arrow {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.floating-cart-bar-arrow:hover {
    background: rgba(255, 255, 255, 0.32);
}

.floating-cart-bar-arrow.open {
    animation: floating-arrow-bounce-open 0.45s ease-out forwards;
}

@keyframes floating-arrow-bounce-open {
    0%, 100% { transform: rotate(180deg) translateY(0); }
    50% { transform: rotate(180deg) translateY(3px); }
}

.floating-cart-bar-arrow i {
    font-size: 1.1rem;
}

.floating-cart-bar-right {
    font-size: 1rem;
    font-weight: 700;
    flex: 0 0 auto;
    text-align: right;
    min-width: 4rem;
}

.floating-cart-bar-beta .floating-cart-bar-right {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}

/* Prevent page scroll when floating cart drawer / express modal is open */
html.floating-cart-drawer-open,
body.floating-cart-drawer-open {
    overflow: hidden;
    touch-action: none;
}

html.express-checkout-modal-open,
body.express-checkout-modal-open {
    overflow: hidden;
    touch-action: none;
}

body.express-vehicle-modal-open {
    overflow: hidden;
    touch-action: none;
}

.floating-cart-drawer {
    position: fixed;
    bottom: 48px;
    left: 0;
    right: 0;
    z-index: 10990;
    max-height: calc(70vh - 48px);
    background: #1a1a1a;
    color: #e8e8e8;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.5);
    border-radius: 16px 16px 0 0;
    transform: translateY(100vh);
    transition: transform 0.35s ease-out;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.floating-cart-drawer.open {
    transform: translateY(0);
}

.floating-cart-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10985;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.floating-cart-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.floating-cart-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.floating-cart-drawer-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    flex-shrink: 0;
    color: #fff;
}

.floating-cart-drawer-close {
    border: 0;
    background: transparent;
    color: #ccc;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
}

.floating-cart-drawer-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.floating-cart-drawer-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 1rem 1rem;
}

.floating-cart-drawer-items {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.floating-cart-drawer-item {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.5rem;
    border-radius: 10px;
    background: #252525;
    font-size: 0.9rem;
}

.floating-cart-drawer-item-special {
    outline: 1px solid rgba(255, 193, 7, 0.65);
    background: rgba(255, 193, 7, 0.08);
}

.floating-cart-drawer-item-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.floating-cart-drawer-item-qty {
    color: #aaa;
    font-weight: 600;
}

.floating-cart-drawer-item-price {
    font-weight: 700;
    color: #fff;
}

.floating-cart-drawer-item-remove {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #888;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.floating-cart-drawer-item-remove:hover {
    color: #f87171;
    background: rgba(248, 113, 113, 0.12);
}

.floating-cart-drawer-totals {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #333;
}

.floating-cart-drawer-savings {
    color: #4ade80;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.floating-cart-drawer-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.floating-cart-drawer-total-row {
    font-size: 1.05rem;
    font-weight: 700;
    margin-top: 0.35rem;
}

.floating-cart-drawer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid #333;
}

.floating-cart-drawer-actions .floating-cart-bar-btn {
    flex: 1 1 auto;
    min-width: 0;
    justify-content: center;
}

.floating-cart-drawer-btn-cart,
.floating-cart-drawer-btn-checkout,
.floating-cart-drawer-btn-express {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 0.85rem;
    white-space: nowrap;
}

.floating-cart-drawer-btn-cart {
    background: #3a3a3a;
    color: #fff;
    border-color: #555;
}

.floating-cart-drawer-btn-cart:hover {
    background: #444;
    color: #fff;
    border-color: #666;
}

.floating-cart-drawer-btn-checkout {
    background: var(--primary-color, #DC143C);
    color: #fff;
    border-color: var(--primary-color, #DC143C);
}

.floating-cart-drawer-btn-checkout:hover {
    background: #c41238;
    color: #fff;
    filter: brightness(1.05);
}

.floating-cart-drawer-btn-express {
    background: #2d2d2d;
    color: #fff;
    border-color: #444;
}

.floating-cart-drawer-btn-express:hover:not(.disabled) {
    background: #383838;
}

.floating-cart-drawer-btn-express.disabled,
.floating-cart-drawer-btn-express:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* Quick checkout + vehicle modals */
.express-checkout-modal {
    position: fixed;
    inset: 0;
    z-index: 11050;
    display: none;
    align-items: flex-end;
    justify-content: center;
}

.express-checkout-modal.open {
    display: flex;
}

.express-checkout-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.62);
}

.express-checkout-modal-dialog {
    position: relative;
    width: 100%;
    max-width: 520px;
    max-height: min(88vh, 640px);
    margin: 0 auto;
    z-index: 1;
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
}

.express-checkout-modal.open .express-checkout-modal-dialog {
    transform: translateY(0);
}

.express-checkout-modal-content {
    background: #1a1a1d;
    color: #e8e8e8;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    max-height: inherit;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}

.express-checkout-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.express-checkout-modal-back {
    border: 0;
    background: transparent;
    color: #93c5fd;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
}

.express-checkout-modal-back:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #bfdbfe;
}

.express-checkout-modal-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    text-align: center;
    flex: 1 1 auto;
}

.express-checkout-modal-close {
    border: 0;
    background: transparent;
    color: #94a3b8;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    line-height: 1;
}

.express-checkout-modal-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.08);
}

.express-checkout-modal-body {
    padding: 1rem 1.1rem 1.25rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1 1 auto;
    min-height: 0;
}

.express-checkout-modal-hint {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.express-checkout-field {
    margin-bottom: 0.85rem;
}

.express-checkout-field label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #cbd5e1;
    margin-bottom: 0.35rem;
}

.express-checkout-field select,
.express-checkout-card-select {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    border: 1px solid #444;
    background: #252529;
    color: #f1f5f9;
    font-size: 0.9rem;
}

.express-checkout-field select:focus,
.express-checkout-card-select:focus {
    outline: none;
    border-color: var(--primary-color, #DC143C);
    box-shadow: 0 0 0 2px rgba(220, 20, 60, 0.25);
}

.express-checkout-fee-row,
.express-checkout-amount-row,
.express-checkout-vehicle-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.express-checkout-amount-value {
    font-weight: 700;
    color: #fff;
}

.express-checkout-fee-waived-note {
    width: 100%;
    margin-top: 0.25rem;
}

.express-checkout-vehicle-edit-btn {
    margin-left: auto;
    border: 0;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
}

.express-checkout-vehicle-edit-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.express-checkout-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.express-checkout-modal-actions .floating-cart-bar-btn {
    width: 100%;
    text-align: center;
}

.express-checkout-modal-actions .floating-cart-bar-btn-checkout {
    width: 100%;
}

.express-vehicle-modal .express-checkout-modal-content {
    border-radius: 16px 16px 0 0;
}

.express-vehicle-modal .express-vehicle-input {
    background: #252529;
    border-color: #444;
    color: #f1f5f9;
}
