/**
 * Global Search Component — Header Autocomplete
 * TASK-HP-1B: Klook-style search bar + mobile overlay
 * Dependencies: design-system.css (tokens)
 */

/* ============================================
   0. Header Layout Fix (TASK-HP-BUGFIX-V2)
   ============================================ */
.bravo_header .content .header-left {
    display: flex;
    align-items: center;
    flex-wrap: nowrap !important;
}

/* Logo sizing — match production site */
.bravo_header .bravo-logo {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.bravo_header .bravo-logo img {
    height: 52px;
    width: auto;
    max-width: 180px;
    object-fit: contain;
}

@media (max-width: 768px) {
    .bravo_header .bravo-logo img {
        height: 40px;
        max-width: 140px;
    }
}

.bravo_header .bravo-menu {
    flex-shrink: 0;
}

/* ============================================
   1. Desktop Search Bar (in .header-left)
   ============================================ */
.gs-search-wrap {
    position: relative;
    margin: 0 12px;
    flex: 0 1 380px;
    min-width: 180px;
    z-index: 100;
}

.gs-search-form {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 42px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    transition: all 0.25s ease;
}

.gs-search-form:focus-within {
    background: #fff;
    border-color: var(--color-border, #E5E7EB);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.gs-search-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 100%;
    color: rgba(255, 255, 255, 0.7);
    font-size: 15px;
    flex-shrink: 0;
    cursor: pointer;  /* FIX-4: 可点击 */
    transition: color 0.2s ease;
}

.gs-search-icon:hover {
    color: #fff;  /* FIX-4: 悬停变色 */
}

.gs-search-form:focus-within .gs-search-icon {
    color: var(--color-text-muted, #6B7280);
}

.gs-search-form:focus-within .gs-search-icon:hover {
    color: #FF6B35;  /* FIX-4: 聚焦时悬停变色 */
}

.gs-search-input {
    flex: 1;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body, "DM Sans");
    font-size: 14px;
    color: #fff;
    padding-right: 12px;
}

.gs-search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
    font-size: 13px;
}

.gs-search-form:focus-within .gs-search-input {
    color: var(--color-text, #1F2937);
}

.gs-search-form:focus-within .gs-search-input::placeholder {
    color: var(--color-text-light, #9CA3AF);
}

.gs-search-clear {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 100%;
    cursor: pointer;
    color: var(--color-text-muted, #6B7280);
    font-size: 13px;
    flex-shrink: 0;
    border: none;
    background: none;
    padding: 0;
}

.gs-search-clear.visible {
    display: flex;
}

/* ============================================
   2. Dropdown Panel
   ============================================ */
.gs-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: 480px;
    max-height: 520px;
    overflow-y: auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 1000;
}

.gs-dropdown.open {
    display: block;
}

/* Scrollbar */
.gs-dropdown::-webkit-scrollbar {
    width: 5px;
}

.gs-dropdown::-webkit-scrollbar-thumb {
    background: var(--color-border, #E5E7EB);
    border-radius: 3px;
}

/* Loading / Empty states */
.gs-state {
    padding: 32px 20px;
    text-align: center;
    color: var(--color-text-muted, #6B7280);
    font-size: 14px;
}

.gs-state .gs-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--color-border, #E5E7EB);
    border-top-color: #FF6B35;
    border-radius: 50%;
    animation: gs-spin 0.6s linear infinite;
    margin-bottom: 8px;
}

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

/* Section group */
.gs-group {
    padding: 8px 0;
}

.gs-group + .gs-group {
    border-top: 1px solid var(--color-border-light, #F3F4F6);
}

.gs-group-title {
    padding: 6px 16px 4px;
    font-family: var(--font-body, "DM Sans");
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted, #6B7280);
}

/* ============================================
   3. Result Items
   ============================================ */
.gs-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.gs-item:hover {
    background: var(--color-bg-alt, #f8f9fa);
    text-decoration: none;
    color: inherit;
}

/* Thumbnail */
.gs-item-img {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--color-bg-alt, #f8f9fa);
}

.gs-item-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gs-item-img .gs-icon-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--color-text-light, #9CA3AF);
}

/* Text info */
.gs-item-info {
    flex: 1;
    min-width: 0;
}

.gs-item-title {
    font-family: var(--font-heading, "DM Sans");
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text, #1F2937);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gs-item-title .gs-hl {
    color: #FF6B35;
    font-weight: 600;
}

.gs-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    font-size: 12px;
    color: var(--color-text-muted, #6B7280);
}

/* Type badge */
.gs-type-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.gs-type-hotel    { background: #DBEAFE; color: #1D4ED8; }
.gs-type-tour     { background: #D1FAE5; color: #047857; }
.gs-type-event    { background: #FEE2E2; color: #DC2626; }
.gs-type-dining   { background: #FEF3C7; color: #D97706; }
.gs-type-boat     { background: #E0E7FF; color: #4338CA; }
.gs-type-location { background: #F3F4F6; color: #4B5563; }

/* Price */
.gs-item-price {
    flex-shrink: 0;
    font-family: var(--font-heading, "DM Sans");
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text, #1F2937);
    white-space: nowrap;
}

.gs-item-price .gs-currency {
    font-size: 11px;
    font-weight: 500;
}

/* Location service count */
.gs-service-count {
    font-size: 12px;
    color: var(--color-text-muted, #6B7280);
}

/* ============================================
   4. Mobile Search Icon (in header-right)
   ============================================ */
.gs-mobile-trigger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    margin-right: 8px;
}

/* ============================================
   5. Mobile Full-Screen Overlay
   ============================================ */
.gs-mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    z-index: 9999;
    flex-direction: column;
}

.gs-mobile-overlay.open {
    display: flex;
}

.gs-mobile-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border, #E5E7EB);
    flex-shrink: 0;
}

.gs-mobile-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    height: 44px;
    background: var(--color-bg-alt, #f8f9fa);
    border-radius: 8px;
    border: 1px solid var(--color-border, #E5E7EB);
    padding: 0 12px;
}

.gs-mobile-input-wrap .gs-m-icon {
    color: var(--color-text-muted, #6B7280);
    font-size: 15px;
    margin-right: 8px;
    flex-shrink: 0;
}

.gs-mobile-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body, "DM Sans");
    font-size: 15px;
    color: var(--color-text, #1F2937);
    height: 100%;
}

.gs-mobile-input::placeholder {
    color: var(--color-text-light, #9CA3AF);
}

.gs-mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 22px;
    color: var(--color-text-secondary, #4B5563);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}

.gs-mobile-results {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Mobile result items - full width cards */
.gs-mobile-results .gs-item {
    padding: 12px 16px;
}

.gs-mobile-results .gs-item-img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
}

.gs-mobile-results .gs-item-title {
    font-size: 15px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================
   6. Responsive Breakpoints
   ============================================ */

/* Desktop: show search bar, hide mobile trigger */
@media (min-width: 769px) {
    .gs-search-wrap {
        display: block;
    }

    .gs-mobile-trigger {
        display: none !important;
    }
}

/* Tablet */
@media (max-width: 1200px) {
    .gs-search-wrap {
        max-width: 280px;
        min-width: 180px;
    }

    .gs-dropdown {
        width: 420px;
    }
}

@media (max-width: 1024px) {
    .gs-search-wrap {
        max-width: 220px;
        min-width: 160px;
        margin: 0 12px;
    }

    .gs-search-input::placeholder {
        font-size: 12px;
    }

    .gs-dropdown {
        width: 380px;
    }
}

/* Mobile: hide desktop search, show trigger icon */
@media (max-width: 768px) {
    .gs-search-wrap {
        display: none !important;
    }

    .gs-mobile-trigger {
        display: flex !important;
        min-width: 44px; /* TASK-HP-4: Touch target */
        min-height: 44px;
    }
}

/* ============================================
   TASK-HP-4 M-1: Mobile search overlay enhancements
   ============================================ */
@media (max-width: 768px) {
    .gs-mobile-overlay {
        /* Prevent iOS keyboard pushing content */
        overscroll-behavior: contain;
    }

    .gs-mobile-overlay.open {
        display: flex;
        animation: gs-overlay-in 0.2s ease;
    }

    @keyframes gs-overlay-in {
        from { opacity: 0; transform: translateY(-10px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .gs-mobile-header {
        padding: 12px 12px;
        gap: 8px;
    }

    .gs-mobile-input-wrap {
        height: 44px; /* TASK-HP-4: Touch target */
    }

    .gs-mobile-input {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .gs-mobile-close {
        width: 44px; /* TASK-HP-4: Touch target */
        height: 44px;
    }

    /* Mobile results full-bleed */
    .gs-mobile-results .gs-item {
        padding: 12px 16px;
    }

    .gs-mobile-results .gs-item-title {
        font-size: 15px;
        line-height: 1.4;
    }
}
