﻿/* =========================================
   Typeahead v2 — Premium Enhanced Edition
   ========================================= */

/* ---- CSS Variables for Easy Customization ---- */
:root {
    --typeahead-transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --typeahead-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --typeahead-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12), 0 4px 8px rgba(0, 0, 0, 0.08);
    --typeahead-border-width: 2px;
}

/* ---- Input field ---- */
.typeahead,
.tt-query,
.tt-hint {
    width: 100%;
    height: 48px;
    padding: 12px 16px;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    border: var(--typeahead-border-width) solid var(--bs-border-color, #dee2e6);
    border-radius: var(--bs-border-radius-lg, 0.5rem);
    background-color: var(--bs-body-bg, #fff);
    color: var(--bs-body-color, #212529);
    transition: var(--typeahead-transition);
    outline: none;
    position: relative;
}

    .typeahead:hover {
        border-color: var(--bs-gray-400, #adb5bd);
        box-shadow: var(--typeahead-shadow-sm);
    }

    .typeahead:focus {
        border-color: var(--bs-primary);
        background-color: var(--bs-body-bg, #fff);
        box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.15), var(--typeahead-shadow-sm);
        transform: translateY(-1px);
    }

/* Enhanced hint (placeholder overlay) */
.tt-hint {
    color: var(--bs-secondary-color, #adb5bd);
    opacity: 0.5;
    pointer-events: none;
    font-style: italic;
}

/* ---- Dropdown container with glass morphism ---- */
.tt-menu {
    position: absolute;
    width: 100%;
    margin-top: 8px;
    padding: 8px 0;
    border-radius: var(--bs-border-radius-lg, 0.5rem);
    background: rgba(var(--bs-body-bg-rgb, 255, 255, 255), 0.98);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: var(--typeahead-shadow-lg);
    overflow: hidden;
    z-index: 1060;
    animation: tt-slide-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Smooth dropdown animation */
@keyframes tt-slide-in {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ---- Suggestion items with refined interactions ---- */
.tt-suggestion {
    padding: 12px 18px;
    font-size: 0.975rem;
    color: var(--bs-body-color, #212529);
    background: transparent;
    cursor: pointer;
    transition: var(--typeahead-transition);
    position: relative;
    overflow: hidden;
}

    .tt-suggestion::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 3px;
        height: 100%;
        background: var(--bs-primary);
        transform: scaleY(0);
        transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        transform-origin: top;
    }

    .tt-suggestion + .tt-suggestion {
        border-top: 1px solid rgba(0, 0, 0, 0.04);
    }

    .tt-suggestion:hover,
    .tt-suggestion.tt-cursor {
        background: linear-gradient(90deg, rgba(var(--bs-primary-rgb), 0.12) 0%, rgba(var(--bs-primary-rgb), 0.06) 100%);
        color: var(--bs-primary);
        padding-left: 22px;
        font-weight: 500;
    }

        .tt-suggestion:hover::before,
        .tt-suggestion.tt-cursor::before {
            transform: scaleY(1);
        }

    /* Active state with ripple effect */
    .tt-suggestion:active {
        background: rgba(var(--bs-primary-rgb), 0.18);
        transform: scale(0.99);
    }

/* ---- Enhanced highlighted match ---- */
.tt-highlight {
    display: inline-block;
    font-weight: 700;
    color: purple;
    text-decoration: underline purple;
    transition: var(--typeahead-transition);
}

.tt-suggestion:hover .tt-highlight,
.tt-suggestion.tt-cursor .tt-highlight {
    text-decoration: underline purple;
    color: purple;
    transform: translateY(-1px);
}

/* ---- Empty message with icon support ---- */
.tt-empty-message {
    padding: 20px 16px;
    text-align: center;
    font-size: 0.925rem;
    color: var(--bs-secondary-color, #6c757d);
    font-style: italic;
}

    .tt-empty-message::before {
        content: '🔍';
        display: block;
        font-size: 2rem;
        margin-bottom: 8px;
        opacity: 0.4;
    }

/* ---- Scrollable variant with custom scrollbar ---- */
#scrollable-dropdown-menu .tt-menu {
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--bs-primary-rgb), 0.3) transparent;
}

    #scrollable-dropdown-menu .tt-menu::-webkit-scrollbar {
        width: 6px;
    }

    #scrollable-dropdown-menu .tt-menu::-webkit-scrollbar-track {
        background: transparent;
        margin: 8px 0;
    }

    #scrollable-dropdown-menu .tt-menu::-webkit-scrollbar-thumb {
        background: rgba(var(--bs-primary-rgb), 0.3);
        border-radius: 10px;
        transition: background 0.2s ease;
    }

        #scrollable-dropdown-menu .tt-menu::-webkit-scrollbar-thumb:hover {
            background: rgba(var(--bs-primary-rgb), 0.5);
        }

/* ---- Loading state ---- */
.tt-menu.tt-loading {
    pointer-events: none;
}

    .tt-menu.tt-loading::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 2px;
        background: linear-gradient(90deg, transparent, var(--bs-primary), transparent);
        animation: tt-loading 1.5s infinite;
    }

@keyframes tt-loading {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(200%);
    }
}

/* ---- Dataset headers (if used) ---- */
.tt-dataset-header {
    padding: 8px 18px 4px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--bs-secondary);
    background: rgba(0, 0, 0, 0.02);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

/* ---- Keyboard navigation indicator ---- */
.tt-suggestion.tt-cursor::after {
    content: '→';
    position: absolute;
    right: 18px;
    opacity: 0.4;
    animation: tt-cursor-pulse 1.5s ease-in-out infinite;
}

@keyframes tt-cursor-pulse {
    0%, 100% {
        opacity: 0.4;
        transform: translateX(0);
    }

    50% {
        opacity: 0.8;
        transform: translateX(4px);
    }
}

/* ---- Dark mode support ---- */
@media (prefers-color-scheme: dark) {
    .tt-menu {
     
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 4px 8px rgba(0, 0, 0, 0.3);
    }

    .tt-suggestion + .tt-suggestion {
        border-color: rgba(255, 255, 255, 0.08);
    }
}

/* ---- Responsive adjustments ---- */
@media (max-width: 576px) {
    .typeahead,
    .tt-query,
    .tt-hint {
        height: 44px;
        font-size: 0.95rem;
    }

    .tt-suggestion {
        padding: 10px 14px;
        font-size: 0.925rem;
    }

    #scrollable-dropdown-menu .tt-menu {
        max-height: 200px;
    }
}

/* ---- Accessibility improvements ---- */
.tt-suggestion:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
