/**
 * LIM Pickup Dropdown - Modern responsive UI (proxy over legacy <select>)
 * BEM prefix: .lim-nd
 *
 * The original <select> stays in DOM as source of truth for RnB.
 * The legacy Chosen.js container is hidden visually; our UI renders
 * beside it inside #pickupLocationPreview (or .redq-pick-up-location).
 */

/* ===== Hide legacy Chosen container (scoped to pickup location only) ===== */

/* RnB / themes sometimes render the pickup-location select outside of
   #pickupLocationPreview (in modals, mobile clones, hidden forms). To
   guarantee only ONE visible picker on the page — our custom .lim-nd —
   we hide every native select[name="pickup_location"] regardless of where
   it lives in the DOM, and every Chosen container that sits next to one. */
select[name="pickup_location"],
select.pickup_location {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Chosen creates a sibling .chosen-container right after the select */
select[name="pickup_location"] + .chosen-container,
select.pickup_location + .chosen-container {
    display: none !important;
}

/* Some themes wrap the select — catch those Chosen containers too. */
#pickupLocationPreview .chosen-container,
.redq-pick-up-location .chosen-container {
    display: none !important;
}

/* ===== Root container ===== */

.lim-nd {
    position: relative;
    width: 100%;
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    color: #222;
    box-sizing: border-box;
}

.lim-nd *,
.lim-nd *::before,
.lim-nd *::after {
    box-sizing: border-box;
}

/* ===== Trigger button (closed state) ===== */

.lim-nd__trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 10px 14px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    font: inherit;
    color: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.lim-nd__trigger:hover {
    border-color: #9a9a9a;
}

.lim-nd__trigger:focus-visible {
    outline: none;
    border-color: #e4007f;
    box-shadow: 0 0 0 3px rgba(228, 0, 127, 0.18);
}

.lim-nd[data-open="true"] .lim-nd__trigger {
    border-color: #e4007f;
    box-shadow: 0 0 0 3px rgba(228, 0, 127, 0.18);
}

.lim-nd__trigger-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lim-nd__trigger-label--placeholder {
    color: #888;
}

.lim-nd__trigger-label strong {
    font-weight: 600;
}

.lim-nd__trigger-arrow {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-right: 2px solid #666;
    border-bottom: 2px solid #666;
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform 0.2s ease;
}

.lim-nd[data-open="true"] .lim-nd__trigger-arrow {
    transform: rotate(-135deg) translate(-2px, -2px);
}

/* ===== Panel (open state) ===== */

.lim-nd__panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 9999;
    max-height: 340px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
    /* Smooth native scroll on iOS */
    -webkit-overflow-scrolling: touch;
}

.lim-nd[data-open="true"] .lim-nd__panel {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0s;
}

/* Overlay for bottom-sheet mode (only visible on narrow screens) */
.lim-nd__overlay {
    display: none;
}

/* ===== Option ===== */

.lim-nd__option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background-color 0.12s ease;
    border-bottom: 1px solid #f2f2f2;
}

.lim-nd__option:last-child {
    border-bottom: none;
}

.lim-nd__option:hover,
.lim-nd__option[data-active="true"] {
    background-color: #f7f7f7;
}

.lim-nd__option[aria-selected="true"] {
    background-color: #fff4f9;
}

.lim-nd__option[aria-selected="true"][data-active="true"],
.lim-nd__option[aria-selected="true"]:hover {
    background-color: #fde8f2;
}

.lim-nd__option-left {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    color: #222;
    word-break: break-word;
}

.lim-nd__option-left strong {
    font-weight: 600;
    color: #111;
}

.lim-nd__option-right {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}

/* Status badges */

.lim-nd__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.4;
}

.lim-nd__badge::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: currentColor;
    flex-shrink: 0;
}

.lim-nd__badge--green {
    color: #2e7d32;
    background: #e8f5e9;
}

.lim-nd__badge--orange {
    color: #ef6c00;
    background: #fff4e5;
}

.lim-nd__badge--red {
    color: #c62828;
    background: #fdecea;
}

/* Delivery price shown without dot-badge, just bold text */
.lim-nd__price {
    font-weight: 700;
    color: #111;
    font-size: 14px;
}

/* ===== Screen-reader-only helper ===== */

.lim-nd__sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== Responsive: mobile (<768px) ===== */

@media (max-width: 768px) {
    .lim-nd__trigger {
        min-height: 52px;
        padding: 12px 16px;
        font-size: 16px; /* Prevent iOS zoom on focus */
    }

    .lim-nd__option {
        min-height: 52px;
        padding: 12px 16px;
    }

    .lim-nd__option-left {
        font-size: 15px;
    }

    .lim-nd__option-right {
        font-size: 13px;
    }

    .lim-nd__panel {
        max-height: 60vh;
    }
}

/* ===== Responsive: bottom-sheet on very narrow screens (<=480px) ===== */

@media (max-width: 480px) {
    .lim-nd[data-open="true"] .lim-nd__overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 99998;
        opacity: 1;
        transition: opacity 0.2s ease;
    }

    /* Floating sheet lifted above pinned UI (chat widgets, language picker etc.) */
    .lim-nd__panel {
        position: fixed;
        top: auto;
        /* Clearance above typical pinned widgets (~60-70px) + safe-area for iPhone home indicator */
        bottom: calc(88px + env(safe-area-inset-bottom, 0px));
        left: 8px;
        right: 8px;
        max-height: 65vh;
        border-radius: 14px;
        padding: 8px 0;
        /* Slide fully off-screen when closed: own height + offset from bottom */
        transform: translateY(calc(100% + 96px + env(safe-area-inset-bottom, 0px)));
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
        z-index: 99999;
    }

    .lim-nd[data-open="true"] .lim-nd__panel {
        transform: translateY(0);
    }

    /* Small drag indicator at top of sheet */
    .lim-nd__panel::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        margin: 4px auto 10px;
        background: #d6d6d6;
        border-radius: 2px;
    }

    .lim-nd__option {
        min-height: 56px;
        padding: 14px 18px;
    }
}

/* ===== Reduce motion (accessibility) ===== */

@media (prefers-reduced-motion: reduce) {
    .lim-nd__trigger,
    .lim-nd__trigger-arrow,
    .lim-nd__panel,
    .lim-nd__option,
    .lim-nd__overlay {
        transition: none !important;
    }
}
