/**
 * Global Columns toolbar (Students pattern).
 * Loaded from includes/header.php — do not copy into page <style> blocks.
 */

.sls-columns-toolbar {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    flex: 0 0 auto;
}

/* Trigger must never stretch to the open menu height (flex default stretch). */
.sls-columns-toolbar > button,
.sls-columns-toolbar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    align-self: center;
    flex: 0 0 auto;
    height: auto;
}

/*
 * Menu must be absolutely positioned under the trigger.
 * Without this, pages that lack local .dropdown-menu rules render the panel
 * as a flex sibling and stretch the Columns button system-wide.
 */
.sls-columns-toolbar > .dropdown-menu,
.sls-columns-toolbar > .col-dropdown-menu,
.sls-columns-toolbar .col-dropdown-menu {
    position: absolute;
    inset-inline-end: 0;
    inset-inline-start: auto;
    top: calc(100% + 0.35rem);
    display: none;
    box-sizing: border-box;
    min-width: 280px;
    max-width: min(22rem, calc(100vw - 1.5rem));
    max-height: 400px;
    overflow-x: hidden;
    overflow-y: auto;
    margin: 0;
    padding: 0.5rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    box-shadow:
        0 16px 32px rgba(15, 23, 42, 0.12),
        0 6px 16px rgba(15, 23, 42, 0.06);
    z-index: 2147483200;
}

.sls-columns-toolbar.open > .dropdown-menu,
.sls-columns-toolbar.open > .col-dropdown-menu,
.sls-columns-toolbar.open .col-dropdown-menu,
.dropdown.sls-columns-toolbar.open > .dropdown-menu,
.dropdown.sls-columns-toolbar.open > .col-dropdown-menu {
    display: block;
}

[dir="rtl"] .sls-columns-toolbar > .dropdown-menu,
[dir="rtl"] .sls-columns-toolbar > .col-dropdown-menu,
[dir="rtl"] .sls-columns-toolbar .col-dropdown-menu {
    inset-inline-end: 0;
    inset-inline-start: auto;
}

.sls-columns-host {
    width: 100%;
}

.col-reorder-hint {
    padding: 0.35rem 0.625rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.01em;
}

.col-dropdown-menu {
    z-index: 2147483200;
}

.col-dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.5rem;
    color: #334155;
    border-radius: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background-color 0.15s ease;
}

.col-dropdown-item:hover {
    background: #f1f5f9;
}

.sls-col-menu-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    color: #94a3b8;
    cursor: grab;
    border-radius: 0.35rem;
    flex-shrink: 0;
    touch-action: none;
    user-select: none;
}

.sls-col-menu-drag-handle:hover {
    color: #0f766e;
    background: #ecfdf5;
}

.sls-col-menu-drag-handle:active {
    cursor: grabbing;
}

/* Header drag handles (Students pattern — all reorderable tables) */
table.sls-columns-reorderable thead th[data-col],
table.sls-columns-reorderable thead th.sls-col-drag-host {
    position: relative;
}

table.sls-columns-reorderable thead th .sls-col-drag-handle,
.sls-col-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    margin-inline-end: 0.35rem;
    color: #94a3b8;
    cursor: grab;
    border-radius: 0.25rem;
    vertical-align: middle;
    flex-shrink: 0;
    touch-action: none;
    user-select: none;
}

table.sls-columns-reorderable thead th .sls-col-drag-handle:hover,
.sls-col-drag-handle:hover {
    color: #0f766e;
    background: #ecfdf5;
}

table.sls-columns-reorderable thead th .sls-col-drag-handle:active,
.sls-col-drag-handle:active {
    cursor: grabbing;
}

table.sls-columns-reorderable thead th.sls-col-drag-chosen {
    background: #ecfdf5 !important;
    box-shadow: inset 0 0 0 2px #14b8a6;
}

table.sls-columns-reorderable thead th.sls-col-drag-ghost {
    opacity: 0.55;
    background: #ccfbf1 !important;
}

table.sls-columns-reorderable thead th.sls-col-drag-dragging {
    cursor: grabbing;
    background: #f0fdfa !important;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

/* Sortable forceFallback ghost (needed under .ff-zoom-wrap transforms) */
.sortable-fallback.col-dropdown-item,
.sortable-fallback.sls-col-menu-drag-dragging {
    opacity: 0.95;
    background: #f0fdfa !important;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    list-style: none;
}

.col-dropdown-item.sls-col-menu-drag-chosen {
    background: #ecfdf5;
    box-shadow: inset 0 0 0 1px #99f6e4;
}

.col-dropdown-item.sls-col-menu-drag-ghost {
    opacity: 0.55;
    background: #ccfbf1;
}

.col-dropdown-item.sls-col-menu-drag-dragging {
    cursor: grabbing;
    background: #f0fdfa;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
}

.col-dropdown-check {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex: 1 1 auto;
    min-width: 0;
    cursor: pointer;
}

.col-dropdown-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-dropdown-item input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: #0d9488;
    flex-shrink: 0;
}

.col-order-controls {
    display: inline-flex;
    flex-direction: column;
    gap: 0.125rem;
    flex-shrink: 0;
}

.col-move-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.1rem;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 0.25rem;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    line-height: 1;
    font-size: 0.65rem;
}

.col-move-btn:hover {
    background: #f0fdfa;
    border-color: #99f6e4;
    color: #0f766e;
}

.col-move-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.col-move-btn:focus-visible {
    outline: 2px solid #0d9488;
    outline-offset: 1px;
}

.sls-columns-toolbar__empty {
    margin: 0;
    padding: 0.6rem 0.75rem;
    color: #94a3b8;
    font-weight: 600;
    font-size: 0.8125rem;
}

[dir="rtl"] .col-dropdown-item {
    text-align: right;
}

html[data-theme="dark"] .sls-columns-toolbar > .dropdown-menu,
html[data-theme="dark"] .sls-columns-toolbar > .col-dropdown-menu,
html[data-theme="dark"] .sls-columns-toolbar .col-dropdown-menu {
    background: var(--color-card, #1e293b);
    border-color: var(--color-border, #334155);
    box-shadow:
        0 16px 32px rgba(0, 0, 0, 0.45),
        0 6px 16px rgba(0, 0, 0, 0.3);
    color: var(--color-text-primary, #f1f5f9);
}

html[data-theme="dark"] .sls-columns-toolbar .col-dropdown-menu .sticky,
html[data-theme="dark"] .sls-columns-toolbar .col-dropdown-menu .bg-white {
    background: var(--color-card, #1e293b) !important;
}

html[data-theme="dark"] .sls-columns-toolbar .col-dropdown-menu input[type="text"],
html[data-theme="dark"] .sls-columns-toolbar .col-dropdown-menu input[type="search"] {
    background: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

html[data-theme="dark"] .col-reorder-hint {
    color: #94a3b8;
}

html[data-theme="dark"] .col-dropdown-item {
    color: #e2e8f0;
}

html[data-theme="dark"] .col-dropdown-item:hover {
    background: rgba(148, 163, 184, 0.1);
}

html[data-theme="dark"] .col-move-btn {
    background: #1e293b;
    border-color: #475569;
    color: #94a3b8;
}

html[data-theme="dark"] .col-move-btn:hover {
    background: rgba(45, 212, 191, 0.12);
    border-color: rgba(45, 212, 191, 0.35);
    color: #2dd4bf;
}

html[data-theme="dark"] .sls-col-menu-drag-handle:hover {
    color: #2dd4bf;
    background: rgba(45, 212, 191, 0.12);
}
