/**
 * File:    assets/css/cart.css
 * Purpose: Cart drawer, delivery nudge bar, floating cart button,
 *          and checkout page — all visual states for the cart UI.
 *
 * Class system (Implementation B — authoritative as of v3.2.13):
 *   .dd-cart-drawer-overlay   — full-screen dim backdrop
 *   .dd-cart-drawer           — slide-in panel (right on desktop, up on mobile)
 *   .dd-cart-drawer--open     — toggled by JS to reveal panel
 *   .dd-cart-drawer__header   — panel header bar
 *   .dd-cart-drawer__items    — scrollable item list
 *   .dd-cart-drawer__nudge    — delivery progress bar section
 *   .dd-cart-drawer__footer   — subtotal row + checkout button
 *   .dd-cart-btn              — fixed floating trigger (desktop only)
 *   .dd-cart-btn__count       — item count badge on floating button
 *
 * Enqueued by:
 *   modules/template/class-dd-template-module.php → enqueue_frontend_assets()
 *
 * Depends on CSS variables from inject_global_header_styles():
 *   --brand, --brand-dark, --dd-line, --dd-surface
 *
 * Last modified: v3.2.13
 */

/* ── Local variables ────────────────────────────────────────── */
:root {
    --dd-cart-red:     #65040d;
    --dd-cart-accent:  #E8832A;
    --dd-cart-border:  #EAD9CE;
    --dd-cart-bg:      #FBF7F1;
    --dd-cart-text:    #221B19;
    --dd-cart-muted:   #7A6558;
    --dd-cart-danger:  #c0392b;
    --dd-cart-success: #2e7d52;
    --dd-cart-radius:  14px;
    --dd-cart-shadow:  0 8px 40px rgba(0, 0, 0, 0.18);
}

/* ── Overlay ────────────────────────────────────────────────── */
.dd-cart-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.dd-cart-drawer-overlay--visible {
    opacity: 1;
    pointer-events: all;
}

/* ── Drawer — Desktop: slides in from right ─────────────────── */
.dd-cart-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 100vw;
    height: 100%;
    background: #fff;
    z-index: 9200;
    display: flex;
    flex-direction: column;
    transform: translateX(110%);
    transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 48px rgba(0, 0, 0, 0.16);
}

.dd-cart-drawer--open {
    transform: translateX(0);
}

/* Prevent body scroll when drawer is open */
body.dd-cart-open {
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────── */
.dd-cart-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.4rem;
    background: var(--dd-cart-red);
    color: #fff;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

.dd-cart-drawer__title {
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.dd-cart-drawer__close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    position: relative;
    z-index: 10;
    pointer-events: all;
}

.dd-cart-drawer__close:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* ── Items list ─────────────────────────────────────────────── */
.dd-cart-drawer__items {
    flex: 1;
    overflow-y: auto;
    padding: 0 !important;
    display: flex;
    flex-direction: column;
}

.dd-cart-drawer__empty {
    text-align: center;
    color: var(--dd-cart-muted);
    font-size: 0.92rem;
    padding: 3.5rem 1rem;
    line-height: 1.6;
}

.dd-cart-drawer__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px !important;
    border-bottom: 1px solid var(--dd-cart-border);
    min-height: unset;
    height: auto;
}

.dd-cart-drawer__item:last-child {
    border-bottom: none;
}

.dd-cart-drawer__item-img {
    width: 56px;
    height: 56px;
    min-width: 56px;
    object-fit: cover;
    border-radius: 8px;
    flex-shrink: 0;
}

.dd-cart-drawer__item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    height: auto;
}

.dd-cart-drawer__item-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--dd-cart-text);
    line-height: 1.4;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}

.dd-cart-drawer__item-qty {
    font-size: 0.78rem;
    color: var(--dd-cart-muted);
}

.dd-cart-drawer__item-price {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--dd-cart-accent);
    flex-shrink: 0;
    white-space: nowrap;
}

/* ── Delivery nudge bar ─────────────────────────────────────── */
.dd-cart-drawer__nudge {
    padding: 12px 20px;
    background: #fdf6ee;
    border-top: 1px solid var(--dd-cart-border);
    border-radius: 10px;
    margin: 0 16px 8px;
    flex-shrink: 0;
}

.dd-nudge__label {
    font-size: 0.82rem;
    color: var(--dd-cart-text);
    margin: 0 0 0.55rem;
    line-height: 1.4;
}

.dd-nudge__label--success {
    color: var(--dd-cart-success);
    font-weight: 700;
}

.dd-nudge__bar {
    height: 7px;
    background: #EAD9CE;
    border-radius: 999px;
    overflow: hidden;
}

.dd-nudge__fill {
    height: 100%;
    background: var(--dd-cart-accent);
    border-radius: 999px;
    transition: width 0.4s ease;
}

/* ── Footer: subtotal + checkout ────────────────────────────── */
.dd-cart-drawer__footer {
    border-top: 1px solid #f0e8df;
    padding: 16px 20px 24px;
    background: var(--dd-cart-bg);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dd-cart-drawer__subtotal {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.dd-cart-drawer__subtotal-label {
    font-size: 0.88rem;
    color: var(--dd-cart-muted);
}

.dd-cart-drawer__subtotal-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--dd-cart-text);
}

.dd-cart-drawer__checkout {
    display: block;
    width: 100%;
    background: var(--dd-cart-red);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.9rem 1rem;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    box-sizing: border-box;
}

.dd-cart-drawer__checkout:hover:not(.dd-cart-drawer__checkout--disabled) {
    background: #e37401;
    color: #fff;
    text-decoration: none;
}

.dd-cart-drawer__checkout--disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

/* ── Floating cart button (desktop only) ────────────────────── */
.dd-cart-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--dd-cart-red);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 0.75rem 1.3rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    box-shadow: 0 6px 24px rgba(101, 4, 13, 0.35);
    z-index: 9000;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    line-height: 1;
}

.dd-cart-btn:hover {
    background: #4a0209;
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(101, 4, 13, 0.45);
}

.dd-cart-btn__count {
    background: #fff;
    color: var(--dd-cart-red);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    min-width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
}

/* ── Mobile: cart slides up from bottom ─────────────────────── */
@media (max-width: 768px) {

    .dd-cart-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 85vh;
        max-height: 85vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
        z-index: 10001 !important; /* above mobile-app (9999) and bottom-nav (10000) */
    }

    .dd-cart-drawer--open {
        transform: translateY(0);
    }

    /* Sticky header keeps close button anchored while items scroll */
    .dd-cart-drawer__header {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--dd-cart-red); /* explicit bg prevents content bleeding through */
    }

    /* Close button — large tap target on mobile */
    .dd-cart-drawer__close {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        font-size: 20px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        min-width: 44px;
        min-height: 44px;
    }

    /* Overlay — covers everything behind the panel */
    .dd-cart-drawer-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 10000 !important; /* above mobile-app (9999) and bottom-nav (10000), below cart (10001) */
    }

    /* Floating button hidden on mobile — bottom nav handles it */
    .dd-cart-btn {
        display: none !important;
    }
}

/* ── Checkout page ──────────────────────────────────────────── */
.dd-checkout-wrap {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 2rem;
    max-width: 1000px;
    margin: 2rem auto;
    padding: 0 1rem;
    font-family: inherit;
}

.dd-checkout-form h2 {
    font-size: 1.25rem;
    color: var(--dd-cart-text);
    margin: 0 0 1.25rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--dd-cart-border);
}

.dd-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.dd-form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.dd-form-group label {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--dd-cart-muted);
}

.dd-form-group input,
.dd-form-group select,
.dd-form-group textarea {
    padding: 0.65rem 0.9rem;
    border: 2px solid var(--dd-cart-border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
    outline: none;
    background: #fff;
}

.dd-form-group input:focus,
.dd-form-group select:focus,
.dd-form-group textarea:focus {
    border-color: var(--dd-cart-red);
}

/* Order type radio buttons */
.dd-order-types {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.dd-order-type-btn {
    flex: 1;
    border: 2px solid var(--dd-cart-border);
    border-radius: 10px;
    padding: 0.75rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fff;
}

.dd-order-type-btn input { display: none; }

.dd-order-type-btn:has(input:checked),
.dd-order-type-btn--active {
    border-color: var(--dd-cart-red);
    background: #fdf0f0;
}

.dd-order-type-btn__icon { font-size: 1.4rem; display: block; margin-bottom: 0.25rem; }
.dd-order-type-btn__label { font-size: 0.78rem; font-weight: 700; color: var(--dd-cart-text); }

/* Submit button */
.dd-submit-btn {
    width: 100%;
    background: var(--dd-cart-red);
    color: #fff;
    border: none;
    border-radius: 999px;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 0.5rem;
    font-family: inherit;
}

.dd-submit-btn:hover { background: #4a0209; }
.dd-submit-btn:disabled { background: #ccc; cursor: not-allowed; }

/* Order summary sidebar */
.dd-checkout-summary {
    background: var(--dd-cart-bg);
    border: 1px solid var(--dd-cart-border);
    border-radius: var(--dd-cart-radius);
    padding: 1.5rem;
    height: fit-content;
    position: sticky;
    top: 1rem;
}

.dd-checkout-summary h3 {
    font-size: 1.05rem;
    color: var(--dd-cart-text);
    margin: 0 0 1rem;
}

.dd-checkout-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.88rem;
    color: var(--dd-cart-muted);
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--dd-cart-border);
}

.dd-checkout-item:last-of-type { border-bottom: none; }

.dd-checkout-total-row {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--dd-cart-text);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 2px solid var(--dd-cart-border);
}

/* Notices */
.dd-notice {
    padding: 0.85rem 1.1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.dd-notice--success { background: #eaf7ef; color: #1e5e38; border: 1px solid #a8dfc0; }
.dd-notice--error   { background: #fdecea; color: #7d1919; border: 1px solid #f5b7b1; }

/* Checkout page responsive */
@media (max-width: 768px) {
    .dd-checkout-wrap        { grid-template-columns: 1fr; }
    .dd-checkout-summary     { position: static; }
    .dd-form-row             { grid-template-columns: 1fr; }
}

/* ── Cart item stepper + remove ─────────────────────────── */
.dd-cart-drawer__item-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
    height: auto;
}

.dd-cart-stepper {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1.5px solid var(--dd-cart-border, #f0e8df);
    border-radius: 20px;
    overflow: hidden;
    height: 30px;
}

.dd-cart-stepper__btn {
    width: 30px;
    height: 30px;
    border: none;
    background: transparent;
    font-size: 16px;
    cursor: pointer;
    color: #65040d;
    display: grid;
    place-items: center;
    transition: background .15s;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.dd-cart-stepper__btn:hover {
    background: #fdf0f0;
}

.dd-cart-stepper__qty {
    min-width: 28px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: #2b1d12;
}

.dd-cart-remove {
    border: none;
    background: none;
    color: #c0a090;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color .15s;
    line-height: 1;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.dd-cart-remove:hover {
    color: #65040d;
}

.dd-cart-drawer__item-img--placeholder {
    display: grid;
    place-items: center;
    background: #f5efe6;
    border-radius: 10px;
    font-size: 24px;
}

/* Prevent mobile app from intercepting cart touches */
body.dd-cart-open .dd-mobile-app {
    pointer-events: none !important;
}
body.dd-cart-open .dd-bottom-nav {
    pointer-events: none !important;
}

/* =============================================
   CART DRAWER — MULTI-PANEL SYSTEM (v3.2.43)
   ============================================= */

/* Panel container — drawer is a flex column; panels fill it */
#ddCartDrawer {
    display: flex;
    flex-direction: column;
    overflow: hidden; /* clips hidden panels, prevents outer scroll */
}

.dd-cart-panel {
    width: 100%;
    transition: opacity 0.22s ease, transform 0.22s ease;
    flex-shrink: 0;
}

.dd-cart-panel--hidden {
    display: none !important;
}

/* ── Cart panel fills remaining drawer height ── */
#ddPanelCart {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* lets flex children shrink below content size */
    overflow: hidden;
}

/* Cart items scroll inside the panel, not the whole drawer */
#ddCartItems {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── Checkout panel layout ── */
#ddPanelCheckout {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* critical — lets flex children shrink below content size */
    overflow: hidden;
}

/* ── Confirmation panel layout ── */
#ddPanelConfirmation {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.dd-checkout-panel__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
    flex-shrink: 0;
}

.dd-checkout-panel__back {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--dd-accent, #E8832A);
    padding: 4px 0;
    font-weight: 600;
}

.dd-checkout-panel__back:hover {
    text-decoration: underline;
}

.dd-checkout-panel__title {
    font-weight: 700;
    font-size: 17px;
}

.dd-checkout-panel__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    -webkit-overflow-scrolling: touch;
}

.dd-checkout-panel__footer {
    border-top: 1px solid rgba(0,0,0,0.08);
    padding: 16px 20px;
    flex-shrink: 0;
    background: #fff;
}

/* ── Order summary strip ── */
.dd-checkout-summary-strip {
    background: #F5EFE6;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #555;
    line-height: 1.6;
}

/* ── Form fields ── */
.dd-cform-group {
    margin-bottom: 16px;
}

.dd-cform-group label,
.dd-cform-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: #333;
}

.dd-cform-group label span {
    color: #c0392b;
}

.dd-cform-group input[type="text"],
.dd-cform-group input[type="tel"] {
    width: 100%;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
    background: #fafafa;
    box-sizing: border-box;
    transition: border-color 0.15s;
    -webkit-appearance: none;
}

.dd-cform-group input:focus {
    outline: none;
    border-color: var(--dd-accent, #E8832A);
    background: #fff;
}

.dd-cform-group input.dd-field-error {
    border-color: #c0392b;
}

.dd-cform-error {
    display: block;
    font-size: 12px;
    color: #c0392b;
    margin-top: 4px;
    min-height: 16px;
}

/* ── Payment method options ── */
.dd-payment-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.dd-payment-option {
    cursor: pointer;
}

.dd-payment-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.dd-payment-option__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 8px;
    border: 2px solid #ddd;
    border-radius: 10px;
    transition: border-color 0.15s, background 0.15s;
    background: #fafafa;
    text-align: center;
}

.dd-payment-option input:checked + .dd-payment-option__card {
    border-color: var(--dd-accent, #E8832A);
    background: #fff8f2;
}

.dd-payment-option__icon {
    font-size: 22px;
}

.dd-payment-option__text {
    font-size: 12px;
    font-weight: 600;
    color: #333;
}

/* ── Footer totals + place order ── */
.dd-checkout-total-line,
.dd-checkout-delivery-line {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    margin-bottom: 4px;
}

.dd-checkout-total-line {
    font-weight: 700;
    font-size: 16px;
    margin-bottom: 2px;
}

.dd-checkout-delivery-line {
    color: #777;
    font-size: 13px;
    margin-bottom: 12px;
}

.dd-checkout-place-order {
    width: 100%;
    background: var(--dd-accent, #E8832A);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}

.dd-checkout-place-order:hover {
    opacity: 0.9;
}

.dd-checkout-place-order:active {
    transform: scale(0.98);
}

.dd-checkout-place-order:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dd-checkout-eta {
    text-align: center;
    font-size: 12px;
    color: #888;
    margin: 8px 0 0;
}

/* ── Confirmation panel ── */
.dd-confirm-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    height: 100%;
    box-sizing: border-box;
}

.dd-confirm-panel__icon {
    font-size: 56px;
    margin-bottom: 16px;
}

.dd-confirm-panel__title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 10px;
}

.dd-confirm-panel__order-num {
    font-size: 14px;
    color: #555;
    margin: 0 0 6px;
}

.dd-confirm-panel__eta {
    font-size: 13px;
    color: #888;
    margin: 0 0 28px;
}

.dd-confirm-panel__close {
    background: var(--dd-accent, #E8832A);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 40px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

/* Scroll fade hint — shows content continues below */
.dd-checkout-panel__body {
    position: relative;
}

.dd-checkout-panel__body::after {
    content: '';
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    height: 32px;
    display: block;
    background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.95));
    pointer-events: none;
    flex-shrink: 0;
}

/* ── Online payment confirmation page ─────────────────────── */
.dd-payment-confirmed {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 60vh;
    padding: 40px 20px;
}

.dd-payment-confirmed .dd-confirm-panel {
    max-width: 400px;
    width: 100%;
    text-align: center;
    background: #fff;
    border-radius: 16px;
    padding: 40px 24px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
