/* ------------------------------------------------------------------------- */
/* MODERN TOM SELECT THEME (Vanilla CSS - No Build Step Required)            */
/* ------------------------------------------------------------------------- */

/* --- Keyframes for Spinner --- */
@keyframes ts-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* --- Plugin: Drag & Drop --- */
.ts-wrapper.plugin-drag_drop.multi > .ts-control > div.ui-sortable-placeholder {
    visibility: visible;
    border: 2px dashed oklch(87.2% 0.01 258.338);
    background: oklch(98.5% 0.002 247.839);
    border-radius: 9999px; /* rounded-full */
}

.ts-wrapper.plugin-drag_drop .ui-sortable-placeholder::after {
    content: "!";
    visibility: hidden;
}

/* --- Plugin: Checkbox Options --- */
.plugin-checkbox_options .option input {
    margin-right: 0.5rem;
    vertical-align: middle;
    accent-color: oklch(44.6% 0.03 256.802);
}

/* --- Plugin: Clear Button --- */
.plugin-clear_button .clear-button {
    opacity: 0;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    cursor: pointer;
    color: oklch(70.7% 0.022 261.325);
    transition: opacity 0.2s, color 0.2s;
}

.plugin-clear_button .clear-button:hover {
    color: #ef4444; /* red-500 */
}

.plugin-clear_button.single .clear-button {
    right: 0.75rem;
}

.plugin-clear_button.focus.has-items .clear-button,
.plugin-clear_button:hover.has-items .clear-button {
    opacity: 1;
}

/* --- Plugin: Dropdown Input --- */
.plugin-dropdown_input .dropdown-input {
    display: block;
    padding: 0.5rem;
    box-shadow: none;
    width: 100%;
    background: transparent;
    border-bottom: 1px solid oklch(92.8% 0.006 264.531);
    outline: none;
    font-size: 0.875rem; /* text-sm */
}

.plugin-dropdown_input .dropdown-input::placeholder {
    color: #94a3b8;
}

/* --- Plugin: Autogrow --- */
.ts-wrapper.plugin-input_autogrow.has-items .ts-control > input {
    min-width: 0;
}

.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input {
    display: flex;
    min-width: 4px;
}

.ts-wrapper.plugin-input_autogrow.has-items.focus .ts-control > input::placeholder {
    color: transparent;
}

/* --- Plugin: Optgroup Columns --- */
.ts-dropdown.plugin-optgroup_columns .ts-dropdown-content {
    display: flex;
}

.ts-dropdown.plugin-optgroup_columns .optgroup {
    flex-grow: 1;
    flex-basis: 0;
    min-width: 0;
    border-top: 0;
    border-right: 1px solid #e2e8f0;
}

.ts-dropdown.plugin-optgroup_columns .optgroup:last-child {
    border-right: 0;
}

.ts-dropdown.plugin-optgroup_columns .optgroup:before {
    display: none;
}

.ts-dropdown.plugin-optgroup_columns .optgroup-header {
    border-top: 0;
}

/* --- Plugin: Remove Button --- */
.ts-wrapper.plugin-remove_button .item {
    display: inline-flex;
    align-items: center;
    padding-right: 0 !important;
}

.ts-wrapper.plugin-remove_button .item .remove {
    color: inherit;
    text-decoration: none;
    vertical-align: middle;
    display: inline-block;
    padding: 0 0.375rem;
    border-left: 1px solid oklch(87.2% 0.01 258.338);
    border-radius: 0 9999px 9999px 0;
    box-sizing: border-box;
    margin-left: 0.5rem;
    transition: background 0.2s, color 0.2s;
    cursor: pointer;
}

.ts-wrapper.plugin-remove_button .item .remove:hover {
    background: #fee2e2; /* red-100 */
    color: #dc2626; /* red-600 */
}

.ts-wrapper.plugin-remove_button .item.active .remove {
    border-left-color: #94a3b8;
}

.ts-wrapper.plugin-remove_button.disabled .item .remove:hover {
    background: none;
}

.ts-wrapper.plugin-remove_button.disabled .item .remove {
    border-left-color: #ffffff;
}

/* --- Core Wrapper --- */
.ts-wrapper {
    position: relative;
    font-family: inherit;
}

/* --- Typography Base --- */
.ts-dropdown,
.ts-control,
.ts-control input {
    color: oklch(37.3% 0.034 259.733);
    font-family: inherit;
    font-size: 0.875rem; /* 14px */
    line-height: 1.25rem;
}

/* --- Control Input Container --- */
.ts-control {
    border: 1px solid oklch(87.2% 0.01 258.338);
    padding: 0.5rem 0.75rem;
    width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 10;
    box-sizing: border-box;
    background-color: #ffffff;
    border-radius: 0.5rem; /* rounded-lg */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05); /* shadow-sm */
    transition: all 0.2s ease-in-out;
}

/* Focus State (The "Glow") */
.ts-wrapper.focus .ts-control {
    border-color: oklch(92.8% 0.006 264.531);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2), 0 4px 6px -1px rgb(0 0 0 / 0.1);
    outline: none;
}

.ts-wrapper.single.input-active .ts-control {
    cursor: text;
}

/* Compact padding when items exist */
.ts-wrapper.multi.has-items .ts-control {
    padding: 0.375rem 0.5rem;
}

.full .ts-control {
    background-color: #ffffff;
}

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

.disabled .ts-control {
    opacity: 0.6;
    background-color: oklch(98.5% 0.002 247.839);
}

/* --- Items inside Control --- */
.ts-control > * {
    vertical-align: baseline;
    display: inline-block;
}

/* Multi-Select Chips (Pills) */
.ts-wrapper.multi .ts-control > div {
    cursor: pointer;
    margin: 0.25rem 0.25rem 0.25rem 0;
    padding: 0.25rem 0.75rem;
    background-color: oklch(96.7% 0.003 264.542);
    color: oklch(27.8% 0.033 256.848);
    border: 1px solid oklch(92.8% 0.006 264.531);
    border-radius: 9999px; /* rounded-full */
    font-weight: 500;
    user-select: none;
}

.ts-wrapper.multi .ts-control > div.active {
    background-color: oklch(96.7% 0.003 264.542);
    color: oklch(37.3% 0.034 259.733);
    border-color: oklch(92.8% 0.006 264.531);
}

.ts-wrapper.multi.disabled .ts-control > div,
.ts-wrapper.multi.disabled .ts-control > div.active {
    color: oklch(55.1% 0.027 264.364);
    background-color: #ffffff;
    border-color: oklch(92.8% 0.006 264.531);
}

/* --- Text Input Field --- */
.ts-control > input {
    display: inline-block !important;
    padding: 0 !important;
    min-height: 0 !important;
    max-height: none !important;
    max-width: 100% !important;
    margin: 0 !important;
    text-indent: 0 !important;
    border: 0 !important;
    background: transparent !important;
    line-height: inherit !important;
    user-select: auto !important;
    box-shadow: none !important;
    flex-grow: 1;
    min-width: 7rem;
}

.cfw-user-switch-modal .ts-control {
    display: flex;
    align-items: center;
    height: var(--has-height, var(--theme-form-field-height, 40px));
    min-height: var(--has-height, var(--theme-form-field-height, 40px));
    padding: 0 0.75rem;
    box-sizing: border-box;
}

.cfw-user-switch-modal .ts-control > input {
    height: auto !important;
    line-height: 1.25rem !important;
}

.ts-control > input::placeholder {
    color: #94a3b8;
}

.ts-control > input::-ms-clear {
    display: none;
}

.ts-control > input:focus {
    outline: none !important;
}

.has-items .ts-control > input {
    margin: 0 4px !important;
}

/* --- RTL Support --- */
.ts-control.rtl {
    text-align: right;
}

.ts-control.rtl.single .ts-control:after {
    left: 1rem;
    right: auto;
}

.ts-control.rtl .ts-control > input {
    margin: 0 4px 0 -2px !important;
}

/* Hidden Input Accessibility */
.input-hidden .ts-control > input {
    opacity: 0;
    position: absolute;
    left: -10000px;
}

.ts-hidden-accessible {
    border: 0;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    padding: 0;
    position: absolute;
    width: 1px;
    white-space: nowrap;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
}

/* --- Dropdown Menu --- */
.ts-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 100; /* High z-index to float over modal */

    background-color: #ffffff;
    border: 1px solid oklch(92.8% 0.006 264.531);
    border-radius: 0.5rem; /* rounded-lg */

    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1); /* shadow-xl */
    box-sizing: border-box;
    overflow: hidden;
}

.cfw-switcher-dropdown {
    z-index: 10000;
}

.ts-wrapper .dropdown-header {
    position: relative;
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    background-color: #f8fafc;
    font-weight: 600;
    color: oklch(44.6% 0.03 256.802);
}

.ts-wrapper .dropdown-header-close {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.4;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.ts-wrapper .dropdown-header-close:hover {
    color: #000000;
    opacity: 1;
}

/* Dropdown Content */
.ts-dropdown-content {
    background-color: #ffffff; /* Ensure white background */
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 250px;
    padding: 0.25rem;
    scroll-behavior: smooth;
}

/* --- Dropdown Options --- */
.ts-dropdown .option {
    position: relative;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: oklch(37.3% 0.034 259.733);
    border-radius: 0.375rem; /* rounded-md */
}

.ts-dropdown .option[data-selectable] {
    overflow: hidden;
}

/* Disabled Options */
.ts-dropdown .option[data-disabled],
.ts-dropdown .option[data-disabled][data-selectable] {
    cursor: inherit;
    opacity: 0.5;
}

/* Hover & Active States */
.ts-dropdown .option.active,
.ts-dropdown .option:hover {
    background-color: oklch(96.7% 0.003 264.542);
    color: oklch(37.3% 0.034 259.733);
}

/* Highlighted Text (Search matches) */
.ts-dropdown [data-selectable] .highlight {
    background-color: oklch(92.4% 0.12 95.746);
    border-radius: 2px;
    font-weight: 600;
}

/* Optgroups */
.ts-dropdown .optgroup:first-child .optgroup-header {
    border-top: 0;
}

.ts-dropdown .optgroup-header {
    color: oklch(70.7% 0.022 261.325);
    background-color: #ffffff;
    cursor: default;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.25rem 0.75rem;
    position: sticky;
    top: 0;
}

/* Create New Item */
.ts-dropdown .create {
    color: #64748b;
    padding: 0.5rem 0.75rem;
}

.ts-dropdown .create:hover,
.ts-dropdown .create.active {
    color: oklch(37.3% 0.034 259.733);
    background-color: oklch(92.8% 0.006 264.531);
}

/* --- Spinner --- */
.ts-dropdown .spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    margin: 0.5rem;
    border: 2px solid oklch(92.8% 0.006 264.531);
    border-top-color: oklch(55.1% 0.027 264.364);
    border-radius: 50%;
    animation: ts-spin 1s linear infinite;
}

.ts-dropdown .spinner:after {
    display: none;
}

/* ------------------------------------------------------------------------- */
/* DARK MODE SUPPORT                                                         */
/* (Assumes a parent class of 'dark' on html or body)                        */
/* ------------------------------------------------------------------------- */

.dark .ts-control {
    background-color: #0f172a; /* slate-900 */
    border-color: #334155; /* slate-700 */
}

.dark .ts-control > input {
    color: #e2e8f0; /* slate-200 */
}

.dark .ts-control > input::placeholder {
    color: #64748b;
}

.dark .ts-wrapper.focus .ts-control {
    border-color: #6366f1;
}

/* Dark Mode Multi Chips */
.dark .ts-wrapper.multi .ts-control > div {
    background-color: #1e293b; /* slate-800 */
    color: #e2e8f0;
    border-color: #334155;
}

.dark .ts-wrapper.multi .ts-control > div.active {
    background-color: rgba(49, 46, 129, 0.5);
    color: #c7d2fe;
    border-color: #4338ca;
}

.dark .ts-wrapper.plugin-remove_button .item .remove {
    border-left-color: #475569;
}

.dark .ts-wrapper.plugin-remove_button .item .remove:hover {
    background-color: rgba(127, 29, 29, 0.5); /* red-900/50 */
    color: #fca5a5;
}

/* Dark Mode Dropdown */
.dark .ts-dropdown {
    background-color: #0f172a; /* slate-900 */
    border-color: #334155;
}

.dark .ts-dropdown-content {
    background-color: #0f172a;
}

.dark .ts-wrapper .dropdown-header {
    background-color: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

.dark .ts-dropdown .option {
    color: #e2e8f0;
}

.dark .ts-dropdown .option.active,
.dark .ts-dropdown .option:hover {
    background-color: rgba(49, 46, 129, 0.5);
    color: #c7d2fe;
}

.dark .ts-dropdown [data-selectable] .highlight {
    background-color: rgba(217, 119, 6, 0.5);
    color: #ffffff;
}

.dark .ts-dropdown .optgroup-header {
    background-color: #0f172a;
    color: #64748b;
}

.dark .plugin-dropdown_input .dropdown-input {
    border-bottom-color: #334155;
    color: #e2e8f0;
}
