/* ==========================================================================
   MULTISELECT DROPDOWN COMPONENT
   ========================================================================== */

.ms-wrap {
    position: relative;
    display: inline-block;
}

/* Trigger button */
.ms-trigger {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px 3px 10px;
    height: 26px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}
.ms-trigger:hover {
    border-color: var(--border);
    background: var(--gray-50);
    color: var(--text);
}
.ms-wrap.open .ms-trigger,
.ms-wrap.has-value .ms-trigger {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light, #eef2ff);
}
.ms-chevron {
    opacity: 0.5;
    flex-shrink: 0;
    transition: transform 0.15s;
}
.ms-wrap.open .ms-chevron {
    transform: rotate(180deg);
    opacity: 1;
}
.ms-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    font-size: 0.68rem;
    font-weight: 700;
    background: var(--primary);
    color: #fff;
    line-height: 1;
}

/* Panel */
.ms-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 200;
    min-width: 200px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.10), 0 2px 6px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}
.ms-wrap.open .ms-panel {
    display: block;
}

/* Search */
.ms-search-wrap {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.ms-search {
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.82rem;
    color: var(--text);
    width: 100%;
    min-width: 0;
}
.ms-search::placeholder { color: var(--text-secondary); }

/* Options list */
.ms-options {
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
}
.ms-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text);
    user-select: none;
    transition: background 0.1s;
}
.ms-option:hover { background: var(--gray-100); }
.ms-option.hidden { display: none; }
.ms-option input[type="checkbox"] {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    accent-color: var(--primary);
    cursor: pointer;
    margin: 0;
}

/* Empty state */
.ms-empty {
    padding: 10px 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

/* Footer (clear link) */
.ms-footer {
    border-top: 1px solid var(--border);
    padding: 6px 8px;
    display: flex;
    justify-content: flex-end;
}
.ms-clear-btn {
    background: none;
    border: none;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
}
.ms-clear-btn:hover { color: var(--error); background: var(--gray-100); }

/* Inside table header — align text with cell data */
.table thead th:has(.ms-wrap) {
    padding: 0;
}
.table thead th .ms-wrap {
    display: inline-block;
}
.table thead th .ms-trigger {
    padding: var(--space-3);
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

/* Allow panel to escape overflow:auto clipping while a dropdown is open */
.table-container.ms-open {
    overflow: visible;
}

/* Restore rounded corners lost when overflow:visible disables border-radius clipping */
.table-container.ms-open thead tr:first-child th:first-child {
    border-top-left-radius: var(--radius);
}
.table-container.ms-open thead tr:first-child th:last-child {
    border-top-right-radius: var(--radius);
}

/* Ensure open thead floats above tbody rows */
.table-container.ms-open thead {
    position: relative;
    z-index: 5;
}
