/**
 * Excel-style column header menus (SLS).
 * Loaded from includes/header.php — do not copy into page <style> blocks.
 */

/* BUG-011: keep th as table-cell (display:flex on th collapses columns).
   Reserve inline-end padding and pin the filter chevron so it never clips. */
:where(thead th.sls-col-menu-host) {
    position: relative;
    white-space: nowrap;
    vertical-align: middle;
    box-sizing: border-box;
    padding-inline-end: 1.75rem !important;
}

:where(thead th.sls-col-menu-host > .sort-link),
:where(thead th.sls-col-menu-host > .ja-sort),
:where(thead th.sls-col-menu-host > .fp-ledger-th-sort),
:where(thead th.sls-col-menu-host > .zk-th-sort),
:where(thead th.sls-col-menu-host > button.zk-th-sort) {
    width: auto !important;
    max-width: calc(100% - 0.15rem);
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

:where(thead th .sls-col-menu-btn) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset-inline-end: 0.2rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.25rem;
    height: 1.25rem;
    margin: 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 0.35rem;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    flex-shrink: 0;
    vertical-align: middle;
    line-height: 0;
    z-index: 2;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

:where(thead th .sls-col-menu-btn:hover),
:where(thead th .sls-col-menu-btn:focus-visible) {
    background: #f1f5f9;
    color: #0f766e;
    border-color: #cbd5e1;
    outline: none;
}

:where(thead th .sls-col-menu-btn[aria-expanded="true"]),
:where(thead th .sls-col-menu-btn.is-active) {
    background: #ccfbf1;
    color: #0f766e;
    border-color: #99f6e4;
}

/* Excel-style “filter applied” — funnel + arrow on a pressed square.
   Not wrapped in :where() so it beats page header button utilities. */
thead th .sls-col-menu-btn.is-filtered {
    width: 1.4rem !important;
    height: 1.4rem !important;
    background: #d6e3f3 !important;
    color: #1e3a5f !important;
    border-color: #8fa3bf !important;
    border-radius: 0.2rem !important;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

thead th .sls-col-menu-btn.is-filtered:hover,
thead th .sls-col-menu-btn.is-filtered:focus-visible {
    background: #c5d8ef !important;
    color: #0f2744 !important;
    border-color: #6f89ab !important;
}

thead th .sls-col-menu-btn.is-filtered[aria-expanded="true"],
thead th .sls-col-menu-btn.is-filtered.is-active {
    background: #b7cce6 !important;
    color: #0f2744 !important;
    border-color: #5b7699 !important;
}

thead th.sls-col-filtered {
    background-image: linear-gradient(to bottom, rgba(214, 227, 243, 0.55), rgba(214, 227, 243, 0.2));
}

:where(thead th .sls-col-menu-btn svg) {
    width: 10px;
    height: 10px;
    display: block;
}

thead th .sls-col-menu-btn.is-filtered svg,
thead th .sls-col-menu-btn .sls-col-menu-btn__glyph--filter {
    width: 13px !important;
    height: 12px !important;
}

.sls-col-menu {
    position: fixed;
    z-index: 2147483400;
    box-sizing: border-box;
    display: none;
    flex-direction: column;
    min-width: 300px;
    width: min(380px, calc(100vw - 16px));
    max-width: calc(100vw - 16px);
    max-height: min(88vh, calc(100vh - 12px));
    overflow: hidden;
    padding: 0;
    margin: 0;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.16), 0 2px 8px rgba(15, 23, 42, 0.06);
    font-size: 0.8125rem;
    color: #0f172a;
}

.sls-col-menu.is-open {
    display: flex;
}

.sls-col-menu__chrome {
    flex: 0 0 auto;
    flex-shrink: 0;
    padding: 0.4rem 0 0;
}

/* Excel: "Search this column" stays fixed while the value / date tree scrolls */
.sls-col-menu__search-pin {
    flex: 0 0 auto;
    flex-shrink: 0;
    padding: 0.45rem 0.75rem 0.5rem;
    border-top: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    background: #fff;
    z-index: 2;
}

/*
 * BUG-017: Value list sizes to its checkboxes — never force a tall empty box
 * inside the bordered checklist. placeMenu locks menu height to content (or
 * viewport) so short lists do not leave a cramped strip under a stretched shell.
 * BUG-282: Scroll pane must use flex:1 1 0% + min-height:0 so it can shrink
 * under chrome/search/footer and actually overflow:auto. A min-height floor
 * (e.g. 8rem) prevented shrink → Cancel/OK painted over the last values and
 * the checklist looked unscrollable.
 */
.sls-col-menu__scroll {
    flex: 1 1 0%;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.sls-col-menu__autofilter-body {
    padding: 0.35rem 0.75rem 0.5rem;
}

.sls-col-menu__foot {
    flex: 0 0 auto;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    padding: 0.45rem 0.75rem 0.55rem;
}

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

.sls-col-menu__title {
    margin: 0;
    padding: 0.35rem 0.85rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
}

.sls-col-menu__item {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    padding: 0.45rem 0.85rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: start;
    cursor: pointer;
    line-height: 1.25;
}

.sls-col-menu__item:hover,
.sls-col-menu__item:focus-visible {
    background: #f0fdfa;
    color: #0f766e;
    outline: none;
}

.sls-col-menu__item.is-on {
    background: #ccfbf1;
    color: #0f766e;
}

.sls-col-menu__item:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.sls-col-menu__item i,
.sls-col-menu__item .sls-col-menu__ico {
    width: 1rem;
    text-align: center;
    color: #64748b;
    flex-shrink: 0;
}

.sls-col-menu__item.is-on i,
.sls-col-menu__item.is-on .sls-col-menu__ico,
.sls-col-menu__item:hover i,
.sls-col-menu__item:hover .sls-col-menu__ico {
    color: #0f766e;
}

.sls-col-menu__divider {
    height: 1px;
    margin: 0.35rem 0;
    background: #e2e8f0;
    border: 0;
}

.sls-col-menu__search-label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.7rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sls-col-menu__search-row {
    display: flex;
    gap: 0.35rem;
    align-items: stretch;
}

.sls-col-menu__search-input {
    flex: 1;
    min-width: 0;
    padding: 0.4rem 0.55rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    font: inherit;
    color: #0f172a;
    background: #fff;
}

.sls-col-menu__search-input:focus {
    outline: 2px solid #99f6e4;
    border-color: #14b8a6;
}

.sls-col-menu__search-btn {
    padding: 0.35rem 0.65rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    background: #f8fafc;
    color: #0f172a;
    font: inherit;
    font-weight: 700;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

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

.sls-col-menu__search-btn--primary {
    background: #0d9488;
    border-color: #0f766e;
    color: #fff;
}

.sls-col-menu__search-btn--primary:hover {
    background: #0f766e;
    color: #fff;
}

.sls-col-menu__search-input--full {
    width: 100%;
    margin-bottom: 0.35rem;
}

.sls-col-menu__check--opt {
    margin: 0 0 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
}

.sls-col-menu__check--all {
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 0.15rem;
    padding-bottom: 0.4rem;
    font-weight: 700;
}

.sls-col-menu__value-list {
    max-height: none;
    min-height: 0;
    overflow: visible;
    margin: 0;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    background: #fff;
    padding: 0.2rem 0;
}

/* Excel-style Year → Month → Day date tree */
.sls-col-menu__value-list--tree {
    padding: 0.15rem 0 0.25rem;
}
.sls-col-menu__tree-row {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    padding-block: 0.05rem;
    padding-inline-start: calc(0.35rem + (var(--sls-tree-depth, 0) * 1.05rem));
    padding-inline-end: 0.4rem;
    min-height: 1.55rem;
}
.sls-col-menu__tree-row--year {
    font-weight: 700;
}
.sls-col-menu__tree-row--month {
    font-weight: 600;
}
.sls-col-menu__tree-row--day,
.sls-col-menu__tree-row--blank {
    font-weight: 500;
}
.sls-col-menu__tree-twisty,
.sls-col-menu__tree-twisty-spacer {
    flex: 0 0 1.1rem;
    width: 1.1rem;
    height: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.sls-col-menu__tree-twisty {
    appearance: none;
    border: 0;
    background: transparent;
    color: #64748b;
    border-radius: 0.25rem;
    padding: 0;
    cursor: pointer;
    transition: color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.sls-col-menu__tree-twisty:hover,
.sls-col-menu__tree-twisty:focus-visible {
    color: #0f766e;
    background: #f0fdfa;
    outline: none;
}
.sls-col-menu__tree-twisty.is-open {
    transform: rotate(90deg);
}
.sls-col-menu__tree-twisty svg {
    display: block;
}
.sls-col-menu__tree-check {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    padding: 0.1rem 0.2rem;
    gap: 0.4rem;
}
.sls-col-menu[dir="rtl"] .sls-col-menu__tree-twisty.is-open {
    transform: rotate(-90deg);
}
html[data-theme="dark"] .sls-col-menu__tree-twisty {
    color: #94a3b8;
}
html[data-theme="dark"] .sls-col-menu__tree-twisty:hover,
html[data-theme="dark"] .sls-col-menu__tree-twisty:focus-visible {
    color: #5eead4;
    background: rgba(15, 118, 110, 0.2);
}

.sls-col-menu__autofilter {
    display: block;
    padding: 0.15rem 0.75rem 0.35rem;
}

.sls-col-menu__value-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.sls-col-menu__value-text.is-blank {
    font-style: italic;
    color: #94a3b8;
}

.sls-col-menu__filter-footer {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-top: 0.15rem;
}

.sls-col-menu__filter-spacer {
    flex: 1 1 auto;
    min-width: 0.5rem;
}

.sls-col-menu__panel {
    border-top: 1px solid #e2e8f0;
    margin-top: 0.25rem;
    padding-top: 0.35rem;
}

.sls-col-menu__panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.25rem 0.85rem 0.4rem;
}

.sls-col-menu__panel-title {
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
}

.sls-col-menu__panel-search {
    width: calc(100% - 1.7rem);
    margin: 0 0.85rem 0.45rem;
    padding: 0.35rem 0.55rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.5rem;
    font: inherit;
}

.sls-col-menu__check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.85rem;
    cursor: pointer;
    font-weight: 600;
}

.sls-col-menu__check:hover {
    background: #f8fafc;
}

.sls-col-menu__check input {
    accent-color: #0d9488;
    flex-shrink: 0;
}

.sls-col-menu__check.is-locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.sls-col-menu__empty {
    margin: 0;
    padding: 0.6rem 0.85rem;
    color: #94a3b8;
    font-weight: 600;
}

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

html[data-theme="dark"] :where(thead th .sls-col-menu-btn[aria-expanded="true"]),
html[data-theme="dark"] :where(thead th .sls-col-menu-btn.is-active) {
    background: rgba(45, 212, 191, 0.18);
    color: #2dd4bf;
    border-color: rgba(45, 212, 191, 0.4);
}

html[data-theme="dark"] thead th .sls-col-menu-btn.is-filtered {
    background: #334155 !important;
    color: #e2e8f0 !important;
    border-color: #64748b !important;
}

html[data-theme="dark"] thead th.sls-col-filtered {
    background-image: linear-gradient(to bottom, rgba(51, 65, 85, 0.65), rgba(51, 65, 85, 0.25));
}

html[data-theme="dark"] .sls-col-menu {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] .sls-col-menu__search-pin,
html[data-theme="dark"] .sls-col-menu__foot {
    background: #0f172a;
    border-color: #334155;
}

html[data-theme="dark"] .sls-col-menu__title,
html[data-theme="dark"] .sls-col-menu__search-label,
html[data-theme="dark"] .sls-col-menu__panel-title {
    color: #94a3b8;
}

html[data-theme="dark"] .sls-col-menu__item:hover,
html[data-theme="dark"] .sls-col-menu__item:focus-visible,
html[data-theme="dark"] .sls-col-menu__item.is-on {
    background: rgba(45, 212, 191, 0.12);
    color: #2dd4bf;
}

html[data-theme="dark"] .sls-col-menu__divider,
html[data-theme="dark"] .sls-col-menu__panel {
    border-color: #334155;
    background-color: transparent;
}

html[data-theme="dark"] .sls-col-menu__divider {
    background: #334155;
}

html[data-theme="dark"] .sls-col-menu__search-input,
html[data-theme="dark"] .sls-col-menu__panel-search,
html[data-theme="dark"] .sls-col-menu__search-btn {
    background: #1e293b;
    border-color: #475569;
    color: #e2e8f0;
}

html[data-theme="dark"] .sls-col-menu__value-list {
    background: #1e293b;
    border-color: #475569;
}

html[data-theme="dark"] .sls-col-menu__check--all {
    border-color: #475569;
}

html[data-theme="dark"] .sls-col-menu__value-text.is-blank {
    color: #64748b;
}

html[data-theme="dark"] .sls-col-menu__search-btn--primary {
    background: #0d9488;
    border-color: #14b8a6;
    color: #fff;
}

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