/* =============================================================================
   Pickup Search Component - Production Ready Styles
   Leveraging design patterns from production pickup.css
   ============================================================================= */

:root { --pickup-icon-size: 16px; }

/* Design Tokens & CSS Variables */
.pickup-search-wrapper {
    --pickup-icon-size: 16px;
    --pickup-border: #e5e7eb;
    --pickup-radius: 8px;
    --pickup-shadow: 0 10px 25px -5px rgba(0,0,0,.1), 0 10px 10px -5px rgba(0,0,0,.04);
    --pickup-primary: #324fbe;
    --pickup-success: #10b981;
    --pickup-text: #111827;
    --pickup-text-muted: #6b7280;
    --pickup-bg-hover: #f9fafb;
    --pickup-bg-selected: #dbeafe;
    --pickup-transition: 0.15s ease;
    --pickup-z-dropdown: 9999;

    /* Add standard design system variables for compatibility */
    --space-md: 1rem;
    --border-color: #e5e7eb;

    position: relative;
    width: 100%;
    contain: layout style;
}

/* enable only if QA reports a tiny baseline drift in Safari zoom */
/*
@supports (translate: 0) {
  .pickup-change-link .pickup-change-icon { translate: 0 .5px; }
}
*/

/* Input Container with Icon */
.pickup-search-wrapper .autoComplete_wrapper { position: relative; display: block; z-index: 1000; }
.pickup-search-input-wrapper { position: relative; }

.pickup-search-wrapper .pickup-status-message {
    margin-top: 8px;
    font-size: 13px;
    color: var(--pickup-text-muted);
}

/* Search Input - Production Spec */
.pickup-search-wrapper input[type="search"],
.pickup-search-wrapper .pickup-search__input {
    --pickup-suffix-width: 72px; /* Clear-only */
    width: 100%;
    height: 48px;
    padding: 12px 16px;
    padding-inline-end: calc(var(--pickup-suffix-width) + 8px);
    padding-inline-start: calc(var(--pickup-icon-size) + 24px);
    border: 1px solid var(--pickup-border);
    border-radius: var(--pickup-radius);
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    color: var(--pickup-text);
    transition: border-color var(--pickup-transition), box-shadow var(--pickup-transition);
    background: #fff;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

/* Input prefix pin icon */
.pickup-search-icon {
    position: absolute;
    inset-inline-start: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--pickup-icon-size);
    line-height: 1;
    color: var(--bs-secondary-color, #6c757d);
    pointer-events: none;
    z-index: 2;
}

/* Always hide native cancel; custom clear button provided */
.pickup-search-wrapper input[type="search"]::-webkit-search-cancel-button {
    -webkit-appearance: none;
    display: none !important;
}


/* Focus States */
.pickup-search-wrapper input[type="search"]:focus,
.pickup-search-wrapper .pickup-search__input:focus {
    outline: none;
    border-color: var(--pickup-primary);
    box-shadow: 0 0 0 3px rgba(50, 79, 190, 0.1);
}

.pickup-search-wrapper input[type="search"]:focus-visible,
.pickup-search-wrapper .pickup-search__input:focus-visible {
    outline: 2px solid var(--pickup-primary);
    outline-offset: 2px;
}

/* Disabled State */
.pickup-search-wrapper input[type="search"]:disabled,
.pickup-search-wrapper .pickup-search__input:disabled {
    background-color: #f8f9fa;
    cursor: not-allowed;
    opacity: 0.5;
    color: var(--pickup-text-muted);
}

/* Placeholder */
.pickup-search-wrapper input::placeholder {
    color: #9ca3af;
    font-weight: 400;
    font-size: 14px;
}

/* Suffix slot to host spinner + clear */
.pickup-suffix {
    position: absolute;
    inset-inline-end: 8px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    min-width: var(--pickup-suffix-width);
    z-index: 1;
}

.pickup-clear-btn {
    all: unset;
    display: inline-block;
    color: var(--bs-secondary-color, #6c757d);
    font-size: .875rem; /* 14px */
    line-height: 1;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    padding: 10px;     /* bigger hit area */
    margin: -10px;     /* keep visual small */
    border-radius: 4px;
    visibility: hidden;
    pointer-events: none;
}

/* Show Clear when there is value/selection; support production wrapper */
:is(.pickup-search-wrapper, .pickup-search-wrapper-production).is-selected .pickup-clear-btn,
:is(.pickup-search-wrapper, .pickup-search-wrapper-production).has-value .pickup-clear-btn {
    visibility: visible;
    pointer-events: auto;
}

:is(.pickup-search-wrapper, .pickup-search-wrapper-production):not(.is-selected):not(.has-value) .pickup-clear-btn {
    visibility: hidden;
    pointer-events: none;
}

/* Hide Clear if input disabled */
:is(.pickup-search-wrapper, .pickup-search-wrapper-production) input:disabled ~ .pickup-suffix .pickup-clear-btn {
    visibility: hidden;
    pointer-events: none;
}

/* spinner removed – skeletons provide loading feedback */

/* Autocomplete Results Dropdown - Enhanced popover styling */
.pickup-search-results,
.autoComplete_result {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.02);
    max-height: 320px;
    overflow: hidden;
    overscroll-behavior: contain;
    z-index: var(--pickup-z-dropdown);
    animation: slideDown 0.2s ease;
}

/* Scrollable content area */
.pickup-search-results {
    overflow-y: auto;
}

/* More compact for initial suggestions without header */
.pickup-search-results:not(:has(.results-info)) {
    max-height: 280px;
    box-shadow: 0 8px 25px rgba(0,0,0,.06);
}

/* Fallback for browsers without :has() support */
.no-css-has .pickup-search-results:not(.has-results-info) {
    max-height: 280px;
    box-shadow: 0 8px 25px rgba(0,0,0,.06);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Custom Scrollbar */
.pickup-search-results::-webkit-scrollbar {
    width: 6px;
}

.pickup-search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.pickup-search-results::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.pickup-search-results::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Result Header Info - Lighter and more subtle */
.results-info {
    padding: 8px 16px;
    font-size: 11px;
    color: #9ca3af;
    background: #fefefe;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 400;
    text-transform: lowercase;
}

.results-info.results-info--message {
    color: var(--pickup-text-muted);
    text-transform: none;
}

.no-results {
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--pickup-text-muted);
    font-style: italic;
}

/* Result Items - Tighter spacing and better interaction */
.pickup-result-item {
    padding: 12px 16px;
    cursor: pointer;
    transition: background-color var(--pickup-transition);
    border-bottom: 1px solid #e2e2e2;
    position: relative;
    background: #ffffff;
}

/* Change link alignment */
.pickup-change-link { display: inline-flex; align-items: center; gap: 8px; line-height: 1.25; }
.pickup-change-icon { font-size: var(--pickup-icon-size); line-height: 1; vertical-align: middle; }

/* Skeleton rows for loading */
.pickup-skeleton {
    padding: 12px 16px;
}

.pickup-skeleton .skeleton-line {
    height: 12px;
    width: 60%;
    border-radius: 6px;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 37%, #f3f4f6 63%);
    background-size: 400% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
}

/* More compact styling for initial suggestions (no header) */
.pickup-search-results:not(:has(.results-info)) .pickup-result-item {
    padding: 10px 16px;
}

.pickup-search-results:not(:has(.results-info)) .pickup-result-item:first-child {
    border-radius: 12px 12px 0 0;
}

.pickup-search-results:not(:has(.results-info)) .pickup-result-item:last-child {
    border-radius: 0 0 12px 12px;
    border-bottom: none;
}

/* First item after header */
.pickup-search-results .results-info + .pickup-result-item {
    border-top: none;
}

.pickup-result-item:last-child {
    border-bottom: none;
}

.pickup-result-item:hover {
    background-color: var(--pickup-bg-hover);
}

.pickup-result-item[aria-selected="true"] {
    background-color: var(--pickup-bg-selected);
}

.pickup-result-item:focus-visible {
    outline: 2px solid var(--pickup-primary);
    outline-offset: -2px;
}

/* Highlighted Match - Better readability without spacing issues */
.pickup-result-item .autoComplete_highlighted,
.pickup-result-item mark {
    background: #fff8c5;
    color: inherit;
    font-weight: inherit;
    padding: 0 2px;
    border-radius: 3px;
    letter-spacing: normal;
    word-spacing: normal;
}

/* Result Main Content - Grid layout for better alignment */
.pickup-result-main {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
}

/* More compact for initial suggestions */
.pickup-search-results:not(:has(.results-info)) .pickup-result-main {
    gap: 6px;
}

.pickup-result-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--pickup-text);
    line-height: 1.3;
}

/* Slightly smaller for initial suggestions */
.pickup-search-results:not(:has(.results-info)) .pickup-result-title {
    font-size: 13px;
    line-height: 1.2;
}

/* Fee Badge - Toned down and better contrast */
.pickup-result-fee {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    background: #e8f8f2;
    color: #13795b;
    border: 1px solid #cdeee3;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    white-space: nowrap;
    line-height: 1;
}

.pickup-result-fee.is-free {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #dbeafe;
}

/* Time Pills Container */
.pickup-result-times {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    align-items: center;
}

/* Time Pills - More clickable and accessible */
.pickup-time-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #e8f8f2;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    color: #258164;
    cursor: pointer;
    transition: all var(--pickup-transition);
    white-space: nowrap;
    position: relative;
    min-height: 32px;
    box-sizing: border-box;
}

/* Clock Icon for Time - Better sizing and positioning */
.pickup-time-pill::before {
    content: "🕐";
    font-size: 11px;
    opacity: 0.8;
    margin-right: -2px;
}

.pickup-time-pill:hover {
    background: #d4f2e5;
    border-color: #d1d5db;
}

.pickup-time-pill:focus-visible {
    outline: 2px solid #3c72dc;
    outline-offset: 2px;
}

.pickup-time-pill:active,
.pickup-time-pill[aria-pressed="true"] {
    border-color: #3c72dc;
    background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(60,114,220,.15);
}

.pickup-time-pill:hover::before {
    opacity: 1;
}

.pickup-time-pill:active {
    transform: none;
}

/* Selection display inherits styles from production pickup.css */
/* The .pickup-selected and .pickup-summary classes are already styled in the main CSS */

/* Ensure proper animation when showing/hiding */
.booking-widget-instant .pickup-search-selection {
    animation: fadeIn 0.3s ease;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Removed duplicate summary display styles - using PHP-rendered selection card instead */

/* Error State */
.pickup-search-wrapper.has-error input {
    border-color: #ef4444;
}

.pickup-search-error {
    margin-top: 4px;
    font-size: 12px;
    color: #ef4444;
}

/* Screen Reader Only Content */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Accessibility - Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .pickup-search-results,
    .pickup-result-item,
    .pickup-time-pill,
    .pickup-summary-card,
    .pickup-summary-check,
    .pickup-selection-card {
        animation: none;
        transition: none;
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .pickup-search-wrapper input[type="search"],
    .pickup-search-wrapper .pickup-search__input {
        font-size: 16px; /* Prevent zoom on iOS */
        height: 44px;
    }

    .pickup-search-results {
        max-height: 60vh;
    }

    .pickup-result-item {
        padding: 10px 12px;
    }

    /* More compact initial suggestions on mobile */
    .pickup-search-results:not(:has(.results-info)) .pickup-result-item {
        padding: 8px 12px;
    }

    .pickup-time-pill {
        padding: 6px 10px;
        min-height: 28px;
        font-size: 11px;
    }

    .pickup-result-main {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .pickup-result-title {
        width: 100%;
    }

    .pickup-time-pill {
        padding: 6px 10px;
        font-size: 12px;
    }

    .pickup-selection-details {
        flex-direction: column;
        gap: 6px;
    }

    .pickup-selection-details span {
        display: block;
        width: fit-content;
    }
}


/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .pickup-search-wrapper input[type="search"]:focus,
    .pickup-search-wrapper .pickup-search__input:focus {
        outline: 3px solid currentColor;
        outline-offset: 0;
    }

    .pickup-time-pill:focus,
    .pickup-result-item:focus-visible {
        outline: 3px solid currentColor;
    }
}
