/* =========================================================================
   Tom Select — Modern Theme
   Consistent, clean, modern styling for all selects across the app.
   Replaces tom-select.bootstrap5.css.
   ========================================================================= */

/* ── Hidden accessible (hides original <select> while keeping it focusable) ── */
.ts-hidden-accessible {
    border: 0 !important;
    clip: rect(0 0 0 0) !important;
    -webkit-clip-path: inset(50%) !important;
    clip-path: inset(50%) !important;
    height: 1px !important;
    overflow: hidden !important;
    margin: -1px !important;
    padding: 0 !important;
    position: absolute !important;
    width: 1px !important;
    white-space: nowrap !important;
}

/* ── Container ─────────────────────────────────────────────────────────── */
.ts-wrapper {
    position: relative;
    width: 100%;
}

/* ── Control (the visible box) ─────────────────────────────────────────── */
.ts-control {
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    background-color: #fff;
    /* Override any inherited theme chevron so only the TomSelect ::after arrow shows (no double arrows) */
    background-image: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    box-sizing: border-box;
    flex-wrap: wrap;
    overflow: hidden;
    padding: 0.5rem 0.75rem;
    position: relative;
    width: 100%;
    z-index: 1;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    min-height: 40px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.ts-wrapper.focus .ts-control {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
    outline: none;
}

.ts-wrapper.disabled .ts-control {
    background-color: #f3f4f6;
    cursor: not-allowed;
    opacity: 0.7;
}

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

.ts-wrapper.multi.has-items .ts-control {
    padding: calc(0.5rem - 2px) 0.75rem calc(0.5rem - 6px);
}

.ts-control > * {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

/* ── Input (search field inside control) ──────────────────────────────── */
.ts-control > input {
    background: none !important;
    border: 0 !important;
    box-shadow: none !important;
    display: inline-block !important;
    flex: 1 1 auto;
    line-height: inherit !important;
    margin: 0 !important;
    max-height: none !important;
    max-width: 100% !important;
    min-height: 0 !important;
    min-width: 7rem;
    padding: 0 !important;
    text-indent: 0 !important;
    user-select: auto !important;
    font-size: 0.875rem;
}

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

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

.ts-control > input::placeholder {
    color: #9ca3af;
}

/* ── Single select ────────────────────────────────────────────────────── */
.ts-wrapper.single .ts-control {
    padding-right: 2rem;
    font-size: 0.875rem;
    line-height: 1;
}

.ts-wrapper.single .ts-control > .item {
    display: inline-flex;
    align-items: center;
    margin: 0;
    padding: 0;
    line-height: 1;
    align-self: center;
}

.ts-wrapper.single .ts-control > input {
    line-height: normal !important;
    padding: 0 !important;
    margin: 0 !important;
}

.ts-wrapper.single .ts-control::after {
    content: "";
    position: absolute;
    right: 0.75rem;
    top: 50%;
    margin-top: -2px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 5px solid #6b7280;
    transition: transform 0.15s ease;
}

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

/* ── Multi select — tag items ─────────────────────────────────────────── */
.ts-wrapper.multi .ts-control > div {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #4338ca;
    cursor: default;
    margin: 0 4px 4px 0;
    padding: 2px 8px;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    transition: background 0.1s ease, border-color 0.1s ease;
}

.ts-wrapper.multi .ts-control > div.active {
    background: #6366f1;
    border-color: #6366f1;
    color: #fff;
}

.ts-wrapper.multi.disabled .ts-control > div,
.ts-wrapper.multi.disabled .ts-control > div.active {
    background: #e5e7eb;
    border-color: #d1d5db;
    color: #9ca3af;
}

/* ── Tag remove button ──────────────────────────────────────────────── */
.ts-wrapper.multi .ts-control > div .remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 2px;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    color: #6366f1;
    background: transparent;
    transition: background 0.1s ease, color 0.1s ease;
    cursor: pointer;
}

.ts-wrapper.multi .ts-control > div .remove:hover {
    background: #6366f1;
    color: #fff;
}

.ts-wrapper.multi .ts-control > div.active .remove {
    color: #fff;
}

.ts-wrapper.multi .ts-control > div.active .remove:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* ── Clear button ─────────────────────────────────────────────────────── */
.ts-wrapper .clear-button {
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #9ca3af;
    cursor: pointer;
    transition: color 0.1s ease, background 0.1s ease;
    z-index: 2;
}

.ts-wrapper .clear-button:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

/* ── Dropdown ─────────────────────────────────────────────────────────── */
.ts-dropdown {
    position: absolute !important;
    left: 0;
    right: 0;
    top: 100%;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08), 0 4px 10px rgba(0, 0, 0, 0.04);
    margin-top: 2px;
    max-height: 280px;
    overflow: hidden;
}

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

/* ── Dropdown options ─────────────────────────────────────────────────── */
.ts-dropdown .option {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    line-height: 1.4;
    color: #1f2937;
    transition: background 0.08s ease;
}

.ts-dropdown .option.active {
    background: #eef2ff;
    color: #4338ca;
}

.ts-dropdown .option.selected {
    background: #6366f1;
    color: #fff;
}

.ts-dropdown .option.selected.active {
    background: #4f46e5;
}

.ts-dropdown .option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Dropdown when positioned above ──────────────────────────────────── */
.ts-dropdown.ts-dropdown-up {
    border-radius: 0.5rem;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-top: 0;
    margin-bottom: 2px;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.08), 0 -4px 10px rgba(0, 0, 0, 0.04);
}

/* ── No results / create message ──────────────────────────────────────── */
.ts-dropdown .no-results {
    padding: 0.75rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.8125rem;
}

.ts-dropdown .create {
    padding: 0.5rem 0.75rem;
    color: #6366f1;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    border-radius: 0.375rem;
}

.ts-dropdown .create:hover {
    background: #eef2ff;
}

/* ── Notify / spinner ─────────────────────────────────────────────────── */
.ts-dropdown .spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.ts-dropdown .spinner::after {
    content: "";
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: ts-spin 0.6s linear infinite;
}

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

/* ── Dropdown input plugin ────────────────────────────────────────────── */
.ts-dropdown .dropdown-input-wrap {
    padding: 4px;
    border-bottom: 1px solid #e5e7eb;
}

.ts-dropdown .dropdown-input-wrap input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    outline: none;
}

.ts-dropdown .dropdown-input-wrap input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.15);
}

/* ── Focus state when dropdown is open ────────────────────────────────── */
.ts-wrapper.dropdown-active .ts-control {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.ts-wrapper.dropdown-active.ts-dropdown-up .ts-control {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}

/* ── Scrollbar styling ────────────────────────────────────────────────── */
.ts-dropdown-content::-webkit-scrollbar {
    width: 6px;
}

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

.ts-dropdown-content::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

.ts-dropdown-content::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* ── Invalid / error state ────────────────────────────────────────────── */
.ts-wrapper.invalid .ts-control {
    border-color: #ef4444;
}

.ts-wrapper.invalid.focus .ts-control {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

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

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

/* ── Z-index ──────────────────────────────────────────────────────────── */
.ts-dropdown {
    z-index: 1000;
}

/* Inside modals — stay above modal backdrop (z-index 1050) */
.modal .ts-wrapper,
.custom-modal .ts-wrapper {
    z-index: 1060;
}

.modal .ts-dropdown,
.custom-modal .ts-dropdown {
    z-index: 1070;
}

/* ── Prevent native select styling leak ───────────────────────────────── */
.ts-wrapper select {
    display: none !important;
}

/* ── Input hidden (for single selects) ────────────────────────────────── */
.input-hidden .ts-control > input {
    left: -10000px;
    opacity: 0;
    position: absolute;
}
