/* ==========================================================================
   Selectize – School Management System Theme (Bootstrap 5 harmonised)
   ========================================================================== */
:root {
    --sz-border: #dbe2ea;
    --sz-border-hover: #b9c4d2;
    --sz-focus: #6366f1;
    --sz-focus-ring: rgba(99, 102, 241, 0.18);
    --sz-radius: 0.6rem;
    --sz-bg: #ffffff;
    --sz-text: #1e293b;
    --sz-muted: #94a3b8;
    --sz-active-bg: #eef2ff;
    --sz-active-text: #3730a3;
    --sz-selected-bg: linear-gradient(135deg, #6366f1, #4f46e5);
    --sz-chip-bg: #e0e7ff;
    --sz-chip-text: #3730a3;
    --sz-danger: #dc3545;
}

/* Keep the original <select> in the layout flow for native "required" validation,
   but visually hidden. */
select.selectized {
    display: block !important;
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    border: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0);
}

/* Neutralise Bootstrap .form-select styles copied to the wrapper */
.selectize-control,
.selectize-control.form-select,
.selectize-control.form-control {
    display: block;
    width: 100%;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    height: auto !important;
    min-height: 0 !important;
    position: relative;
    font-family: inherit;
}

.selectize-control .selectize-input {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    width: 100%;
    min-height: calc(1.5em + 0.75rem + 2px);
    padding: 0.375rem 2.25rem 0.375rem 0.75rem !important;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--sz-text);
    background: var(--sz-bg) !important;
    border: 1px solid var(--sz-border) !important;
    border-radius: var(--sz-radius) !important;
    box-shadow: none !important;
    cursor: pointer;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease;
}

.selectize-control .selectize-input:hover {
    border-color: var(--sz-border-hover) !important;
}

.selectize-control .selectize-input.focus,
.selectize-control .selectize-input.input-active {
    border-color: var(--sz-focus) !important;
    box-shadow: 0 0 0 0.22rem var(--sz-focus-ring) !important;
}

.selectize-control .selectize-input > input {
    font-size: inherit !important;
    color: var(--sz-text) !important;
    min-width: 2rem;
    flex: 1 1 auto;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 1.5 !important;
}

.selectize-control .selectize-input > input::placeholder {
    color: var(--sz-muted);
}

.selectize-control.selectize-no-search .selectize-input > input {
    caret-color: transparent;
    cursor: pointer;
}

/* Chevron */
.selectize-control.single .selectize-input::after,
.selectize-control.multi .selectize-input::after {
    content: '' !important;
    position: absolute;
    top: 50% !important;
    right: 0.85rem !important;
    width: 10px !important;
    height: 10px !important;
    margin: 0 !important;
    border: 0 !important;
    transform: translateY(-50%);
    background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2.2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") no-repeat center / 10px 10px;
    transition: transform 0.2s ease;
    display: block !important;
}

.selectize-control .selectize-input.dropdown-active::after {
    transform: translateY(-50%) rotate(180deg) !important;
}

.selectize-control.single .selectize-input > .item {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Multi-select chips */
.selectize-control.multi .selectize-input > div.item,
.selectize-control.multi .selectize-input > div.item.active {
    display: inline-flex !important;
    align-items: center;
    margin: 0 !important;
    padding: 2px 4px 2px 10px !important;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--sz-chip-text) !important;
    background: var(--sz-chip-bg) !important;
    border: 0 !important;
    border-radius: 50rem !important;
    box-shadow: none !important;
    text-shadow: none !important;
}

.selectize-control.multi .selectize-input > div.item.active {
    background: #c7d2fe !important;
}

.selectize-control.plugin-remove_button .item .remove {
    position: static !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 6px !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 50%;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--sz-chip-text) !important;
    background: rgba(55, 48, 163, 0.08);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.selectize-control.plugin-remove_button .item .remove:hover {
    background: #4f46e5;
    color: #fff !important;
}

/* Small variant (form-select-sm) */
.selectize-control.selectize-sm .selectize-input {
    min-height: calc(1.5em + 0.5rem + 2px);
    padding: 0.25rem 2rem 0.25rem 0.6rem !important;
    font-size: 0.85rem;
    border-radius: 0.5rem !important;
}

.selectize-control.selectize-sm .selectize-input::after {
    right: 0.7rem !important;
}

/* Large variant */
.selectize-control.selectize-lg .selectize-input {
    min-height: calc(1.5em + 1rem + 2px);
    padding: 0.5rem 2.5rem 0.5rem 1rem !important;
    font-size: 1.1rem;
}

/* Validation */
.selectize-control.is-invalid .selectize-input {
    border-color: var(--sz-danger) !important;
}

.selectize-control.is-invalid .selectize-input.focus {
    box-shadow: 0 0 0 0.22rem rgba(220, 53, 69, 0.18) !important;
}

/* Disabled */
.selectize-control .selectize-input.disabled,
.selectize-control .selectize-input.disabled * {
    cursor: not-allowed !important;
    background-color: #f1f5f9 !important;
    opacity: 1 !important;
    color: #64748b;
}

/* Input-group integration */
.input-group > .selectize-control {
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}

.input-group > .selectize-control:not(:last-child) .selectize-input {
    border-top-right-radius: 0 !important;
    border-bottom-right-radius: 0 !important;
}

.input-group > .selectize-control:not(:first-child) .selectize-input {
    border-top-left-radius: 0 !important;
    border-bottom-left-radius: 0 !important;
}

/* Dropdown */
.selectize-dropdown {
    z-index: 2000 !important;
    margin-top: 6px !important;
    padding: 4px !important;
    background: #fff !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: var(--sz-radius) !important;
    box-shadow: 0 14px 34px -8px rgba(15, 23, 42, 0.22), 0 4px 10px -4px rgba(15, 23, 42, 0.08) !important;
    font-size: 0.92rem;
    color: var(--sz-text);
    animation: szFadeIn 0.14s ease-out;
    overflow: hidden;
}

.modal .selectize-dropdown {
    z-index: 1065 !important;
}

@keyframes szFadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.selectize-dropdown .selectize-dropdown-content {
    max-height: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0 !important;
}

.selectize-dropdown .option,
.selectize-dropdown .create,
.selectize-dropdown .optgroup-header {
    padding: 0.5rem 0.75rem !important;
    border-radius: 0.45rem;
    cursor: pointer;
    line-height: 1.35;
}

.selectize-dropdown .optgroup-header {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--sz-muted);
    cursor: default;
}

.selectize-dropdown .option.active,
.selectize-dropdown .create.active {
    background: var(--sz-active-bg) !important;
    color: var(--sz-active-text) !important;
}

.selectize-dropdown .option.selected {
    background: var(--sz-selected-bg) !important;
    color: #fff !important;
    font-weight: 600;
}

.selectize-dropdown .option[data-value=""] {
    color: var(--sz-muted);
    font-style: italic;
}

.selectize-dropdown .highlight {
    background: rgba(250, 204, 21, 0.45) !important;
    border-radius: 2px;
    color: inherit;
}

.selectize-dropdown .no-results {
    cursor: default;
}

/* Mobile: larger touch targets, prevent iOS zoom */
@media (max-width: 767.98px) {
    .selectize-control .selectize-input,
    .selectize-control .selectize-input > input {
        font-size: 16px !important;
    }
    .selectize-control.selectize-sm .selectize-input {
        min-height: 38px;
    }
    .selectize-dropdown .option,
    .selectize-dropdown .create {
        padding: 0.7rem 0.85rem !important;
    }
    .selectize-dropdown .selectize-dropdown-content {
        max-height: 50vh;
    }
}
