/**
 * CUEBES - Tom Select Autocomplete Styles
 *
 * Custom styling for autocomplete fields to match CUEBES liquid glass design.
 */

/* Base Tom Select overrides */
.ts-wrapper {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 10px 14px;
    min-height: 44px;
    font-size: 14px;
    color: var(--text-primary, #ffffff);
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.ts-wrapper.single .ts-control:hover,
.ts-wrapper.multi .ts-control:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.1);
}

.ts-wrapper.focus .ts-control {
    border-color: var(--accent-blue, #0066ff);
    box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.15);
    background: rgba(255, 255, 255, 0.12);
}

/* Fix white background when item is selected and focused */
.ts-wrapper.single.has-items .ts-control,
.ts-wrapper.single.has-items.focus .ts-control {
    background: rgba(255, 255, 255, 0.08);
}

.ts-wrapper.single.has-items.focus .ts-control {
    background: rgba(255, 255, 255, 0.12);
}

/* Input field */
.ts-control input {
    color: var(--text-primary, #ffffff) !important;
    font-size: 14px;
}

.ts-control input::placeholder {
    color: var(--text-tertiary, rgba(255, 255, 255, 0.4));
}

/* Dropdown */
.ts-dropdown {
    background: rgba(30, 30, 40, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    margin-top: 4px;
    box-shadow:
        0 4px 6px rgba(0, 0, 0, 0.3),
        0 10px 40px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    overflow: hidden;
    z-index: 10000 !important;
}

/* Ensure dropdown escapes parent overflow constraints */
.ts-wrapper {
    position: relative;
    z-index: 1;
}

.ts-wrapper.dropdown-active {
    z-index: 9999 !important;
}

/* Allow dropdown to escape overflow:hidden parents */
.has-autocomplete,
.input-group.has-autocomplete {
    overflow: visible !important;
    position: relative;
}

/* When dropdown is active, ensure all parent containers allow overflow */
.ts-wrapper.dropdown-active,
.ts-wrapper.dropdown-active ~ *,
.has-autocomplete:has(.ts-wrapper.dropdown-active) {
    z-index: 9998 !important;
}

/* Ensure parent cards don't clip the dropdown when active */
.profile-edit-card:has(.ts-wrapper.dropdown-active),
.glass:has(.ts-wrapper.dropdown-active),
.glass--subtle:has(.ts-wrapper.dropdown-active),
.field-with-visibility:has(.ts-wrapper.dropdown-active) {
    overflow: visible !important;
    z-index: 9997 !important;
}

/* Fallback for browsers without :has() - always allow overflow on autocomplete containers */
.profile-edit-card .has-autocomplete,
.glass .has-autocomplete {
    overflow: visible !important;
}

/* Ensure visibility selectors don't overlap dropdowns */
.visibility-selector,
.visibility-dropdown {
    z-index: 100 !important;
}

/* Tom Select dropdown must be highest */
.ts-dropdown {
    z-index: 10000 !important;
    position: absolute !important;
}

/* JavaScript-toggled class for when dropdown is open */
.has-open-dropdown {
    overflow: visible !important;
    z-index: 9990 !important;
}

.ts-dropdown-content {
    max-height: 280px;
    overflow-y: auto;
    padding: 6px;
}

/* Custom scrollbar for dropdown */
.ts-dropdown-content::-webkit-scrollbar {
    width: 6px;
}

.ts-dropdown-content::-webkit-scrollbar-track {
    background: transparent;
}

.ts-dropdown-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.ts-dropdown-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Options */
.ts-dropdown .option {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text-primary, #ffffff);
    cursor: pointer;
    transition: all 0.15s ease;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background: rgba(255, 255, 255, 0.08);
}

.ts-dropdown .option.selected {
    background: rgba(0, 102, 255, 0.15);
    color: var(--accent-blue, #0066ff);
}

/* Custom option rendering */
.autocomplete-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.autocomplete-option .option-main {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #ffffff);
}

.autocomplete-option .option-meta {
    font-size: 12px;
    color: var(--text-tertiary, rgba(255, 255, 255, 0.5));
}

/* Highlighted text in search */
.ts-dropdown .highlight {
    background: rgba(0, 102, 255, 0.3);
    color: inherit;
    border-radius: 2px;
    padding: 0 2px;
}

/* Selected items */
.ts-control .item {
    background: rgba(0, 102, 255, 0.15);
    border: 1px solid rgba(0, 102, 255, 0.3);
    color: var(--text-primary, #ffffff);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 13px;
    margin: 2px;
}

/* Multi-select items with remove button */
.ts-wrapper.plugin-remove_button .item {
    padding-right: 28px;
}

.ts-wrapper.plugin-remove_button .item .remove {
    color: rgba(255, 255, 255, 0.5);
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    width: 24px;
    font-size: 16px;
    transition: all 0.15s ease;
}

.ts-wrapper.plugin-remove_button .item .remove:hover {
    color: #ff4d4d;
    background: rgba(255, 77, 77, 0.1);
}

/* Clear button */
.ts-wrapper.single.has-items .ts-control::after {
    display: none;
}

/* Caret/arrow */
.ts-control::after {
    border-color: rgba(255, 255, 255, 0.4) transparent transparent transparent;
}

.ts-wrapper.dropdown-active .ts-control::after {
    border-color: transparent transparent rgba(255, 255, 255, 0.4) transparent;
}

/* No results message */
.ts-dropdown .no-results {
    padding: 12px;
    text-align: center;
    color: var(--text-tertiary, rgba(255, 255, 255, 0.5));
    font-size: 13px;
}

/* Create option */
.ts-dropdown .create {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--accent-blue, #0066ff);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ts-dropdown .create::before {
    content: '+';
    font-size: 16px;
    font-weight: 600;
}

.ts-dropdown .create:hover {
    background: rgba(0, 102, 255, 0.1);
}

/* Loading state */
.ts-wrapper.loading .ts-control::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--accent-blue, #0066ff);
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* Disabled state */
.ts-wrapper.disabled .ts-control {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Error state */
.ts-wrapper.has-error .ts-control {
    border-color: #ff4d4d;
}

.ts-wrapper.has-error.focus .ts-control {
    box-shadow: 0 0 0 3px rgba(255, 77, 77, 0.15);
}

/* Light mode support (if needed in future) */
@media (prefers-color-scheme: light) {
    .ts-wrapper.single .ts-control,
    .ts-wrapper.multi .ts-control {
        background: rgba(0, 0, 0, 0.04);
        border-color: rgba(0, 0, 0, 0.1);
        color: #1a1a1a;
    }

    .ts-dropdown {
        background: rgba(255, 255, 255, 0.98);
        border-color: rgba(0, 0, 0, 0.08);
    }

    .ts-dropdown .option {
        color: #1a1a1a;
    }

    .autocomplete-option .option-main {
        color: #1a1a1a;
    }

    .autocomplete-option .option-meta {
        color: rgba(0, 0, 0, 0.5);
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .ts-wrapper.single .ts-control,
    .ts-wrapper.multi .ts-control {
        min-height: 48px;
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .ts-dropdown {
        position: fixed !important;
        left: 16px !important;
        right: 16px !important;
        bottom: 0 !important;
        top: auto !important;
        max-height: 50vh;
        border-radius: 16px 16px 0 0;
        margin-top: 0;
    }

    .ts-dropdown-content {
        max-height: calc(50vh - 20px);
    }
}

/* Form integration */
.form-field.has-autocomplete {
    position: relative;
}

.form-field.has-autocomplete .form-label {
    margin-bottom: 8px;
}

.form-field.has-autocomplete .form-hint {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-tertiary, rgba(255, 255, 255, 0.5));
}

/* Skills tag style (for multi-select skills) */
.ts-wrapper.skills-input .item {
    background: linear-gradient(135deg, rgba(0, 102, 255, 0.2), rgba(0, 200, 255, 0.15));
    border-color: rgba(0, 150, 255, 0.3);
}

/* Industry badge style */
.ts-wrapper.industry-input .item {
    background: linear-gradient(135deg, rgba(100, 200, 100, 0.2), rgba(50, 150, 50, 0.15));
    border-color: rgba(100, 200, 100, 0.3);
}

/* Location style */
.ts-wrapper.location-input .item {
    background: linear-gradient(135deg, rgba(255, 150, 0, 0.2), rgba(255, 100, 0, 0.15));
    border-color: rgba(255, 150, 0, 0.3);
}
