/* Tom Select Dark Theme - Complete styles for Aisles */

/* Base wrapper styles */
.ts-wrapper {
    position: relative;
    --ts-pr-clear-button: 0;
    flex: 1 1 0%;
    min-width: 0;
}

.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background-color: var(--color-surface-700);
    border: 1px solid var(--color-surface-400);
    border-radius: 0.75rem;
    color: var(--color-surface-50);
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    font-weight: 500;
    cursor: text;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem;
    width: 100%;
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ts-control > input {
    flex: 1 1 auto;
    min-width: 2rem;
    display: inline-block;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    color: var(--color-surface-50);
    font-size: inherit;
    line-height: inherit;
}

/* Caret for single select */
.ts-wrapper.single .ts-control::after {
    content: '';
    display: block;
    position: absolute;
    top: 50%;
    right: 1.125rem;
    width: 0;
    height: 0;
    margin-top: -3px;
    border-style: solid;
    border-width: 5px 5px 0 5px;
    border-color: var(--color-surface-300) transparent transparent transparent;
    transition: transform 0.15s ease;
}

.ts-wrapper.single.dropdown-active .ts-control::after {
    transform: rotate(180deg);
    margin-top: -2px;
}

/* Focus state */
.ts-wrapper.focus .ts-control,
.ts-wrapper .ts-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(91, 75, 245, 0.3);
    outline: none;
}

/* Placeholder text */
.ts-wrapper .ts-control input::placeholder,
.ts-wrapper .ts-control > input::placeholder {
    color: var(--color-surface-300);
}

/* Dropdown */
.ts-dropdown {
    position: absolute;
    z-index: 1000;
    background-color: var(--color-surface-700);
    border: 1px solid var(--color-surface-400);
    border-radius: 0.75rem;
    box-shadow: 0 8px 32px -8px rgba(0, 0, 0, 0.6);
    margin-top: 0.25rem;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.ts-dropdown-content {
    max-height: 240px;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.375rem;
    scroll-padding: 0.375rem;
}

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

.ts-dropdown-content::-webkit-scrollbar-track {
    background: var(--color-surface-600);
    border-radius: 3px;
}

.ts-dropdown-content::-webkit-scrollbar-thumb {
    background: var(--color-surface-400);
    border-radius: 3px;
}

.ts-dropdown-content::-webkit-scrollbar-thumb:hover {
    background: var(--color-surface-300);
}

/* Options */
.ts-dropdown .option,
.ts-dropdown [data-selectable] {
    padding: 0.5rem 0.75rem;
    color: var(--color-surface-100);
    background-color: transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.35;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.ts-dropdown .option small,
.ts-dropdown [data-selectable] small {
    line-height: 1.3;
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active,
.ts-dropdown [data-selectable]:hover {
    background-color: var(--color-surface-600);
    color: var(--color-surface-50);
}

.ts-dropdown .option.selected {
    background-color: var(--color-primary);
    color: white;
}

/* No results */
.ts-dropdown .no-results {
    padding: 0.75rem;
    color: var(--color-surface-300);
    text-align: center;
    font-size: 0.875rem;
}

/* Loading indicator */
.ts-wrapper.loading .ts-control::after {
    background-image: none;
    width: 1rem;
    height: 1rem;
    margin-top: -0.5rem;
    border: 2px solid var(--color-surface-400);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: ts-spinner 0.6s linear infinite;
}

@keyframes ts-spinner {
    to { transform: rotate(360deg); }
}

/* Multi-select items (tags/pills) */
.ts-wrapper.multi .ts-control > .item {
    background-color: var(--color-surface-500);
    border: none;
    border-radius: 9999px;
    color: var(--color-surface-100);
    padding: 0.25rem 0.5rem;
    margin: 0.125rem;
    font-size: 0.75rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    max-width: 100%;
    cursor: default;
}

/* Remove button on multi-select items */
.ts-wrapper.multi .ts-control > .item .remove {
    color: var(--color-surface-300);
    border: none;
    background: none;
    padding: 0 0.25rem;
    margin-left: 0.125rem;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease;
}

.ts-wrapper.multi .ts-control > .item .remove:hover {
    color: var(--color-surface-50);
    background: none;
}

/* Single select - selected item display */
.ts-wrapper.single .ts-control > .item {
    color: var(--color-surface-50);
    max-width: calc(100% - 2.5rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Optgroup headers */
.ts-dropdown .optgroup-header {
    padding: 0.5rem 0.75rem;
    color: var(--color-surface-300);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Disabled state */
.ts-wrapper.disabled .ts-control {
    opacity: 0.5;
    background-color: var(--color-surface-700);
    cursor: not-allowed;
}

.ts-wrapper.disabled .ts-control * {
    cursor: not-allowed;
}

/* Create option */
.ts-dropdown .create {
    padding: 0.5rem 0.75rem;
    color: var(--color-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.ts-dropdown .create:hover {
    background-color: var(--color-surface-600);
}

/* Single select clear button (remove_button plugin) */
.ts-wrapper.plugin-remove_button.single .item .remove {
    color: var(--color-surface-300);
    border: none;
    background: none;
    padding: 0 0.25rem;
    margin-left: 0.25rem;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease;
}

.ts-wrapper.plugin-remove_button.single .item .remove:hover {
    color: var(--color-surface-50);
    background: none;
}

/* Plugin: dropdown_input */
.ts-dropdown .dropdown-input-wrap {
    padding: 0.5rem;
    border-bottom: 1px solid var(--color-surface-500);
}

.ts-dropdown .dropdown-input {
    background-color: var(--color-surface-600);
    border: 1px solid var(--color-surface-400);
    border-radius: 0.5rem;
    color: var(--color-surface-50);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    width: 100%;
}

.ts-dropdown .dropdown-input:focus {
    border-color: var(--color-primary);
    outline: none;
}

.ts-dropdown .dropdown-input::placeholder {
    color: var(--color-surface-300);
}

/* Spinner/loading state in dropdown */
.ts-dropdown .spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ts-dropdown .spinner::after {
    content: '';
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--color-surface-400);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: ts-spinner 0.6s linear infinite;
}

/* Hide the original select element - tom-select adds 'tomselected' class */
.tomselected,
select.tomselected,
input.tomselected,
.ts-wrapper > select,
.ts-wrapper > input {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Full-width dropdown positioning */
.ts-wrapper.full .ts-dropdown {
    left: 0;
    right: 0;
}

/* Remove double border when tom-select is inside a simple_form .input wrapper */
.tom-select-typeahead .input {
    border: none !important;
}

/* Hide native select before TomSelect initializes */
select[data-controller~="tom-select"] {
    display: none !important;
}

/* Skeleton placeholder shown while TomSelect loads */
.ts-skeleton {
    background-color: var(--color-surface-700);
    border: 1px solid var(--color-surface-400);
    border-radius: 0.75rem;
    height: 2.625rem;
    width: 100%;
    animation: ts-skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes ts-skeleton-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
