/* 
 * Tom Select Custom Theme - Royal Violet (Dark/Light)
 * Replaces Choices.js for better stability and formatting.
 */

/* 1. Wrapper & Control (Input Box) */
.ts-wrapper {
    width: 100%;
}

/* Neutralize form-input/form-control/form-select styles on the wrapper to prevent double-borders and inherited arrows */
.ts-wrapper.form-input,
.ts-wrapper.form-control,
.ts-wrapper.form-select,
.ts-wrapper select,
.ts-wrapper select.form-input {
    padding: 0 !important;
    background: none !important;
    border: none !important;
    height: auto !important;
    min-height: 0 !important;
    box-shadow: none !important;
    appearance: none !important;
    -webkit-appearance: none !important;
}

/* The main input element - UNIVERSAL RESET */
.ts-wrapper .ts-control,
.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    background: var(--bg-secondary) !important;
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 0.75rem !important;
    min-height: 46px !important;
    height: auto !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 3rem 0 1rem !important; /* Standard padding: Left 1rem, Right 3rem for arrow */
    font-size: 0.95rem !important;
    font-weight: 500 !important;
    color: var(--text-primary) !important;
    transition: all 0.2s ease !important;
    box-shadow: none !important;
    text-align: left !important; /* Enforce left align */
    flex-wrap: nowrap !important; /* Prevent input from wrapping to second line */
    overflow: hidden !important;
}

/* Explicit Dark Mode Override for Control - HIGHEST SPECIFICITY */
html[data-theme="dark"] .ts-wrapper .ts-control,
html[data-theme="dark"] .ts-wrapper.single .ts-control,
html[data-theme="dark"] .ts-wrapper.multi .ts-control {
    background: var(--bg-secondary) !important;
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

/* Focus state */
.ts-wrapper.focus .ts-control {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1) !important;
} 

[data-theme="dark"] .ts-wrapper.focus .ts-control {
    background-color: var(--bg-secondary) !important;
}

/* Standard left padding for icons */
.select-wrapper .ts-wrapper .ts-control,
.select-wrapper .ts-control,
.choices-wrapper .ts-wrapper .ts-control,
.choices-wrapper .ts-control {
    padding-left: 3.2rem !important; /* Adjusted for better balance */
}

.select-wrapper, .choices-wrapper {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    width: 100% !important;
    min-width: 200px !important; /* Prevent overlap by ensuring enough space */
}

.select-wrapper .ts-control .item,
.select-wrapper .ts-control .placeholder,
.choices-wrapper .ts-control .item,
.choices-wrapper .ts-control .placeholder {
    padding-left: 0 !important;
    margin-left: 0 !important;
}

/* 2b. Icon Styling for Wrappers */
.select-wrapper .icon-left,
.choices-wrapper .icon-left {
    position: absolute !important;
    left: 1.25rem !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 1001 !important; /* Higher than ts-wrapper.dropdown-active (1000) */
    pointer-events: none !important;
    color: var(--accent) !important;
    font-size: 1.1rem !important;
}

/* 3. Text & Placeholder Styling */
.ts-control > input {
    color: var(--text-primary) !important;
    font-weight: 500 !important;
    background-color: transparent !important;
    flex: 1 1 auto !important;
    min-width: 4px !important;
    width: auto !important;
}

/* Hide cursor/input for No-Search dropdowns */
.ts-no-search .ts-control > input {
    opacity: 0 !important;
    width: 0 !important;
    min-width: 0 !important;
    position: absolute !important;
    pointer-events: none !important;
}

/* Ensure control box doesn't show cursor when focused in no-search mode */
.ts-no-search.focus .ts-control {
    cursor: default !important;
}

.ts-control .item,
.ts-control .placeholder {
    color: var(--text-primary) !important;
    text-align: left !important;
    opacity: 1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    max-width: fit-content !important;
}

/* 4. Dropdown Menu */
.ts-wrapper .ts-dropdown {
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 14px !important;
    margin-top: 10px !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4) !important;
    padding: 0 !important;
    z-index: 9999 !important; /* High z-index to fix table overlap */
    overflow: hidden !important;
    text-align: left !important;
}

/* Dark mode specific override for dropdown background */
[data-theme="dark"] .ts-wrapper .ts-dropdown {
    background-color: var(--bg-secondary) !important;
    color: var(--text-primary) !important;
    border-color: var(--border) !important;
}

/* Ensure z-index is high enough for modals */
.ts-wrapper .ts-dropdown {
    z-index: 2000 !important;
}

/* 4b. Search Input inside Dropdown (Plugin) */
.ts-dropdown .ts-dropdown-input {
    background: var(--bg-secondary) !important;
    border-bottom: 1px solid var(--border) !important;
    padding: 10px 15px !important;
    font-size: 0.95rem !important;
    color: var(--text-primary) !important;
}

.ts-dropdown .ts-dropdown-input input {
    background: var(--bg-secondary) !important; 
    background-color: var(--bg-secondary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 8px !important;
    padding: 8px 12px !important;
    color: var(--text-primary) !important;
    font-weight: 500 !important;
}

/* 5. Dropdown Options */
.ts-dropdown .option {
    padding: 12px 20px !important;
    font-size: 0.95rem !important;
    color: var(--text-primary) !important;
    cursor: pointer !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05) !important;
    text-align: left !important; /* Enforce */
}

.ts-dropdown .option:last-child {
    border-bottom: none !important;
}

/* Hover/Active Option */
.ts-dropdown .option.active,
.ts-dropdown .option:hover {
    background-color: var(--bg-secondary) !important;
    color: var(--accent) !important;
}

/* Selected Option */
.ts-dropdown .option.selected {
    background-color: var(--accent) !important;
    color: white !important;
    font-weight: 600 !important;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

/* Add checkmark to selected item */
.ts-dropdown .option.selected::before {
    content: "✓";
    margin-right: 8px;
    font-weight: bold;
}

/* 6. Arrow / Caret */
/* Hide default arrow */
.ts-wrapper.single .ts-control::after {
    border: none !important;
    content: " ";
    display: block;
    width: 20px;
    height: 20px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%23b4b4b4' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    transition: transform 0.2s ease;
}

/* Rotate arrow when open */
.ts-wrapper.single.dropdown-active .ts-control::after {
    transform: translateY(-50%) rotate(180deg);
}

/* 7. Hide "remove" button for single selects to look cleaner */
.ts-wrapper.single .ts-control .item .remove {
    display: none !important;
}

/* 8. Input (Search) Visibility */
/* Ensure search input doesn't break layout */
.ts-control input {
    font-size: 0.95rem !important;
}

/* 9. Fix Z-Index Context */
.ts-wrapper.dropdown-active {
    z-index: 1000 !important;
}
