﻿/**
 * Enterprise Autocomplete System v2.0 - Styles
 * Scalable, maintainable, and accessible styling
 */

/* ==========================================================================
   CSS CUSTOM PROPERTIES - Centralized theming
   ========================================================================== */

:root {
    /* Autocomplete specific variables */
    --ac-border-radius: 8px;
    --ac-border-color: var(--bs-border-color-translucent);
    --ac-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    --ac-item-padding: 8px 12px;
    --ac-max-height: 300px;
    --ac-animation-duration: 0.15s;
    --ac-z-index-dropdown: 1060;
    --ac-z-index-modal: 1061;
    /* Colors */
    --ac-highlight-bg: var(--bs-warning);
    --ac-highlight-color: var(--bs-dark);
    --ac-hover-bg: var(--bs-primary-bg-subtle);
    --ac-active-bg: var(--bs-primary);
    --ac-active-color: white;
    --ac-loading-color: var(--bs-text-muted);
    /* Spacing */
    --ac-spacing-xs: 4px;
    --ac-spacing-sm: 8px;
    --ac-spacing-md: 12px;
    --ac-spacing-lg: 16px;
    --ac-spacing-xl: 24px;
    /* Typography */
    --ac-font-size-sm: 12px;
    --ac-font-size-base: 14px;
    --ac-font-size-lg: 16px;
    --ac-font-weight-normal: 400;
    --ac-font-weight-medium: 500;
    --ac-font-weight-semibold: 600;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --ac-border-color: rgba(255, 255, 255, 0.1);
        --ac-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
        --ac-highlight-bg: var(--bs-warning);
        --ac-hover-bg: rgba(255, 255, 255, 0.1);
    }
}

/* ==========================================================================
   AUTOCOMPLETE DROPDOWN - Core styles with contact picker aesthetics
   ========================================================================== */

.autocomplete-dropdown,
.dropdown-menu.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 2px;
    padding: 4px 0;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: 8px;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: var(--ac-z-index-dropdown);
    /* Animation */
    opacity: 0;
    transform: translateY(-5px);
    pointer-events: none;
    transition: opacity var(--ac-animation-duration) ease, transform var(--ac-animation-duration) ease;
}

    /* Show state */
    .autocomplete-dropdown.show {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }

    /* Results container */
    .autocomplete-dropdown .ac-results {
        padding: 0;
    }

/* Container positioning context */
.autocomplete-container {
    position: relative;
}

/* Ensure proper z-index in modals */
.modal .autocomplete-dropdown {
    z-index: var(--ac-z-index-modal);
}

/* ==========================================================================
   DROPDOWN ITEMS - Contact picker inspired styling
   ========================================================================== */

.autocomplete-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--bs-body-color);
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--ac-animation-duration) ease;
    position: relative;
    min-height: 52px;
}

    /* Hover state - subtle blue background */
    .autocomplete-dropdown .dropdown-item:hover {
        background-color: var(--bs-primary-bg-subtle) !important;
    }

    /* Active/selected state (keyboard navigation) */
    .autocomplete-dropdown .dropdown-item.active,
    .autocomplete-dropdown .dropdown-item[aria-selected="true"] {
        background-color: var(--bs-primary-bg-subtle) !important;
        color: var(--bs-body-color);
        box-shadow: none;
    }

    /* Focus state for accessibility */
    .autocomplete-dropdown .dropdown-item:focus {
        background-color: var(--bs-primary-bg-subtle) !important;
        outline: none;
        box-shadow: none;
    }

    .autocomplete-dropdown .dropdown-item:focus-visible {
        outline: 2px solid var(--bs-primary);
        outline-offset: -2px;
    }

    /* Left side content container */
    .autocomplete-dropdown .dropdown-item .flex-grow-1 {
        display: flex;
        flex-direction: column;
        min-width: 0;
        padding-right: 12px;
    }

    /* Primary text (main option) */
    .autocomplete-dropdown .ac-item-primary,
    .autocomplete-dropdown .dropdown-item .fw-medium {
        font-weight: 500;
        font-size: 14px;
        color: var(--bs-body-color);
        margin-bottom: 2px;
        line-height: 1.4;
    }

    /* Secondary text (description/email) */
    .autocomplete-dropdown .text-muted,
    .autocomplete-dropdown .dropdown-item small {
        font-size: 12px;
        color: var(--bs-text-muted);
        line-height: 1.3;
    }

    /* Active state text adjustments */
    .autocomplete-dropdown .dropdown-item.active .text-muted,
    .autocomplete-dropdown .dropdown-item[aria-selected="true"] .text-muted {
        color: var(--bs-text-muted) !important;
    }

/* ==========================================================================
   LOADING & STATUS STATES
   ========================================================================== */

.autocomplete-dropdown .ac-loading,
.autocomplete-dropdown .ac-no-results {
    padding: var(--ac-spacing-lg);
    text-align: center;
    color: var(--ac-loading-color);
    font-size: var(--ac-font-size-base);
}

.autocomplete-dropdown .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

/* ==========================================================================
   SEARCH HIGHLIGHTING
   ========================================================================== */

.autocomplete-dropdown mark {
    background-color: var(--ac-highlight-bg);
    color: var(--ac-highlight-color);
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: var(--ac-font-weight-medium);
}

/* Active item highlighting */
.autocomplete-dropdown .dropdown-item.active mark,
.autocomplete-dropdown .dropdown-item[aria-selected="true"] mark {
    background-color: rgba(255, 255, 255, 0.3);
    color: inherit;
}

/* ==========================================================================
   GLOBAL SEARCH SPECIFIC STYLES
   ========================================================================== */

.global-search-item {
    padding: var(--ac-spacing-md);
    border-bottom: 1px solid var(--bs-border-color);
}

    .global-search-item:last-child {
        border-bottom: none;
    }

    .global-search-item .badge {
        font-size: 10px;
        font-weight: var(--ac-font-weight-semibold);
        padding: 2px 6px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    /* Score display for debugging */
    .global-search-item[data-score]::after {
        content: attr(data-score);
        position: absolute;
        top: var(--ac-spacing-xs);
        right: var(--ac-spacing-xs);
        font-size: 10px;
        color: var(--bs-text-muted);
        opacity: 0;
        transition: opacity var(--ac-animation-duration) ease;
    }

    .global-search-item:hover[data-score]::after {
        opacity: 0.5;
    }

/* ==========================================================================
   BADGE STYLES - Right-aligned category badges
   ========================================================================== */

.autocomplete-dropdown .badge {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    margin-left: auto;
    flex-shrink: 0;
    align-self: center;
    transition: all var(--ac-animation-duration) ease;
}

    /* Different badge colors for categories */
    .autocomplete-dropdown .badge.bg-primary {
        background-color: #0d6efd !important;
    }

    .autocomplete-dropdown .badge.bg-secondary {
        background-color: #6c757d !important;
    }

    .autocomplete-dropdown .badge.bg-info {
        background-color: #0dcaf0 !important;
    }

    .autocomplete-dropdown .badge.bg-warning {
        background-color: #ffc107 !important;
        color: #000 !important;
    }

    .autocomplete-dropdown .badge.bg-danger {
        background-color: #dc3545 !important;
    }

    .autocomplete-dropdown .badge.bg-success {
        background-color: #198754 !important;
    }

/* Badge in active/hover items - maintain colors */
.autocomplete-dropdown .dropdown-item:hover .badge,
.autocomplete-dropdown .dropdown-item.active .badge,
.autocomplete-dropdown .dropdown-item[aria-selected="true"] .badge {
    opacity: 0.95;
}

/* ==========================================================================
   FORM CONTROL ENHANCEMENTS
   ========================================================================== */

.form-control[data-autocomplete] {
    position: relative;
}

    .form-control[data-autocomplete]:focus {
        border-color: var(--bs-primary);
        box-shadow: 0 0 0 0.25rem rgba(var(--bs-primary-rgb), 0.25);
    }

    /* Loading indicator on input */
    .form-control[data-autocomplete].loading {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cstyle%3E@keyframes spin{to{transform:rotate(360deg)}}%3C/style%3E%3Cg style='animation:spin 1s linear infinite;transform-origin:center'%3E%3Ccircle cx='12' cy='12' r='10' fill='none' stroke='%23dee2e6' stroke-width='2'/%3E%3Cpath d='M12 2 A10 10 0 0 1 22 12' fill='none' stroke='%230d6efd' stroke-width='2' stroke-linecap='round'/%3E%3C/g%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 0.75rem center;
        background-size: 1.5rem;
        padding-right: 3rem;
    }

/* ==========================================================================
   SCROLLBAR STYLING
   ========================================================================== */

.autocomplete-dropdown::-webkit-scrollbar {
    width: 6px;
}

.autocomplete-dropdown::-webkit-scrollbar-track {
    background: transparent;
}

.autocomplete-dropdown::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.autocomplete-dropdown:hover::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.3);
}

/* Firefox scrollbar */
.autocomplete-dropdown {
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Tablet and below */
@media (max-width: 768px) {
    .autocomplete-dropdown {
        --ac-max-height: 250px;
        --ac-item-padding: 10px 12px;
    }
}

/* Mobile */
@media (max-width: 576px) {
    .autocomplete-dropdown {
        --ac-max-height: 200px;
        --ac-font-size-base: 13px;
        --ac-font-size-sm: 11px;
    }

        .autocomplete-dropdown .badge {
            font-size: 9px;
            padding: 2px 6px;
        }

    /* Full-width dropdown on mobile */
    .autocomplete-dropdown {
        position: fixed;
        left: var(--ac-spacing-sm);
        right: var(--ac-spacing-sm);
        width: auto;
    }
}

/* ==========================================================================
   ACCESSIBILITY ENHANCEMENTS
   ========================================================================== */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .autocomplete-dropdown {
        border-width: 2px;
    }

        .autocomplete-dropdown .dropdown-item.active {
            background-color: Highlight !important;
            color: HighlightText !important;
            forced-color-adjust: none;
        }

        .autocomplete-dropdown .dropdown-item:focus {
            outline-width: 3px;
        }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .autocomplete-dropdown,
    .autocomplete-dropdown .dropdown-item,
    .autocomplete-dropdown .badge {
        transition: none;
    }

    .autocomplete-dropdown {
        animation: none;
    }
}

/* Focus visible for keyboard navigation */
.autocomplete-dropdown .dropdown-item:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

/* Screen reader only content */
.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;
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .autocomplete-dropdown {
        display: none !important;
    }
}

/* ==========================================================================
   PERFORMANCE OPTIMIZATIONS
   ========================================================================== */

/* Hardware acceleration for animations */
.autocomplete-dropdown {
    will-change: opacity, transform;
}

    .autocomplete-dropdown.show {
        will-change: auto;
    }

    /* Optimize repaints during scroll */
    .autocomplete-dropdown .ac-results {
        contain: layout style paint;
    }

/* ==========================================================================
   UTILITY CLASSES
   ========================================================================== */

/* Hide element but keep in DOM */
.ac-hidden {
    display: none !important;
}

/* Visually hidden but accessible to screen readers */
.ac-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Prevent text selection */
.ac-no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Truncate text with ellipsis */
.ac-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
