/*
   Global Search UI/UX Enhancements
   Professional Administrative Style
   Color Theme: Primary Red
*/

.nav-global-search {
    display: flex;
    align-items: center;
    margin-right: 20px;
    height: 100%;
}

.global-search-mobile-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    margin: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #ffffff;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
}

.global-search-mobile-toggle:hover,
.global-search-mobile-toggle:focus-visible {
    background-color: rgba(255, 255, 255, 0.12);
    outline: none;
}

.global-search-mobile-toggle i {
    font-size: 22px;
    line-height: 1;
}

/*
 * Must stay BELOW .header-top (z-index: 9988 in theme) so the fixed search panel and
 * its dropdown stay above this layer; otherwise taps on results hit the backdrop.
 */
.global-search-mobile-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9970;
    background: rgba(0, 0, 0, 0.35);
}

.global-search-mobile-backdrop.global-search-mobile-backdrop--visible {
    display: block;
}

.global-search-container {
    position: relative;
    width: 280px; /* Optimal width for admin nav */
}

.global-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

#globalSearchInput {
    box-sizing: border-box;
    width: 100%;
    height: 38px;
    padding: 8px 15px 8px 40px; /* Icon on the left */
    border: 2px solid #ff4d4f; /* Primary red border */
    border-radius: 20px; /* Fully rounded */
    font-size: 13.5px;
    font-weight: 500;
    color: #272b41;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: #ffffff;
}

#globalSearchInput:focus {
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 4px rgba(255, 77, 79, 0.15); /* Soft red focus glow */
    width: 320px; /* Subtle expansion on focus */
}

/* Ensure container allows expansion without shifting other elements */
.nav-global-search:focus-within {
    z-index: 1001;
}

.search-icon {
    position: absolute;
    left: 14px; /* Inside the input on the left */
    color: #ff4d4f; /* Match red theme */
    pointer-events: none;
    font-size: 18px;
    display: flex;
    align-items: center;
}

.search-loading {
    position: absolute;
    right: 15px;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 77, 79, 0.1);
    border-top: 2px solid #ff4d4f;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Prediction Window (Dropdown) */
.global-search-results {
    position: absolute;
    top: calc(100% + 12px); /* Space between input and dropdown */
    left: 0;
    width: 350px; /* Fixed maximum width for cards */
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    padding: 10px;
    border: 1px solid #f0f0f0;
    overflow: hidden;
}

/* Result Card Styles */
.search-result-item {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    text-decoration: none !important;
    border: 1px solid transparent;
}

.search-result-item:last-child {
    margin-bottom: 0;
}

.search-result-item:hover {
    background: #fff1f0; /* Very soft red background */
    border-color: #ffa39e;
    transform: translateY(-1px);
}

.search-result-title {
    font-size: 14px;
    font-weight: 700;
    color: #1f1f1f;
    margin-bottom: 3px;
    display: flex;
    align-items: center;
}

.search-result-subtitle {
    font-size: 12px;
    color: #8c8c8c;
    line-height: 1.4;
}

/* Category Badge inside card (optional enhancement) */
.result-type-badge {
    font-size: 9px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
    background: #f5f5f5;
    color: #595959;
    margin-right: 8px;
    font-weight: 600;
}

.search-no-results, .search-error {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: #bfbfbf;
    background: #fafafa;
    border-radius: 8px;
}

/* Responsive adjustments */
@media (min-width: 1250px) and (max-width: 1600px) {
    .global-search-container {
        width: 200px;
    }
    #globalSearchInput:focus {
        width: 240px;
    }
}

@media (max-width: 1200px) {
    .global-search-container {
        width: 220px;
    }
    #globalSearchInput:focus {
        width: 260px;
    }
}

@media (max-width: 991px) {
    .nav-global-search {
        margin-right: 10px;
    }
    .global-search-container {
        width: 180px;
    }
    #globalSearchInput:focus {
        width: 200px;
    }
    .global-search-results {
        width: 280px;
    }
}

@media (min-width: 768px) {
    .global-search-mobile-toggle {
        display: none !important;
    }
}

/*
 * Mobile: icon opens a fixed panel below the header so the bar does not crowd the hamburger.
 */
@media (max-width: 767px) {
    .nav-global-search {
        margin-right: 4px;
        position: relative;
        z-index: 9991;
    }

    .global-search-mobile-toggle {
        display: flex !important;
    }

    .nav-global-search .global-search-container {
        display: none;
        position: fixed;
        top: 50px;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: none;
        margin: 0;
        padding: 10px 12px 14px;
        background: var(--main-color, #272b41);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
        z-index: 9990;
    }

    .nav-global-search.global-search-panel--open .global-search-container {
        display: block;
    }

    #globalSearchInput {
        width: 100% !important;
        max-width: none;
    }

    #globalSearchInput:focus {
        width: 100% !important;
        max-width: none;
    }

    .global-search-results {
        position: absolute;
        left: 12px;
        right: 12px;
        width: auto;
        max-height: min(70vh, 420px);
        overflow-y: auto;
        z-index: 2;
        -webkit-overflow-scrolling: touch;
    }

    .global-search-results .search-result-item {
        position: relative;
        z-index: 1;
        touch-action: manipulation;
    }

    .nav-global-search:focus-within {
        z-index: 9991;
    }
}
