/* ==========================================================================
   Excel-like Data Grid Filter & Sort System for ERP Tables
   ========================================================================== */

/* Header flex layout */
.excel-th-container {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
    min-height: 20px;
    box-sizing: border-box;
}
.text-right .excel-th-container,
th.text-right .excel-th-container {
    justify-content: flex-end;
}
.text-center .excel-th-container,
th.text-center .excel-th-container {
    justify-content: center;
}

.excel-th-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: none;
}

/* Filter trigger button on header */
.excel-filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 19px;
    height: 19px;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    margin-left: 4px;
    flex-shrink: 0;
    vertical-align: middle;
}
.excel-filter-btn:hover {
    background-color: #e2e8f0;
    color: #0f2b48;
    border-color: #cbd5e1;
}
.dark .excel-filter-btn {
    color: #64748b;
}
.dark .excel-filter-btn:hover {
    background-color: #1e293b;
    color: #f1f5f9;
    border-color: #334155;
}

/* Active filter state on column header */
.excel-filter-btn.is-active {
    background-color: #10b981 !important;
    color: #ffffff !important;
    border-color: #059669 !important;
    box-shadow: 0 1px 3px rgba(16, 185, 129, 0.4);
}
.excel-filter-btn.is-sorted {
    color: #2563eb !important;
}
.dark .excel-filter-btn.is-sorted {
    color: #60a5fa !important;
}

/* Filter Dropdown Popup (Excel Dialog) */
.excel-filter-popup {
    position: fixed;
    z-index: 9999;
    width: 270px;
    background-color: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.18), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    font-family: inherit;
    font-size: 12px;
    color: #1e293b;
    overflow: hidden;
    animation: excelPopupIn 0.12s cubic-bezier(0.16, 1, 0.3, 1);
}
.dark .excel-filter-popup {
    background-color: #0d1627;
    border-color: #334155;
    color: #f1f5f9;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.7);
}

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

/* Popup Header */
.excel-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}
.dark .excel-popup-header {
    background-color: #1e293b;
    border-bottom-color: #334155;
}
.excel-popup-title {
    font-weight: 800;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #475569;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 210px;
}
.dark .excel-popup-title {
    color: #cbd5e1;
}
.excel-popup-close {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 4px;
    border-radius: 4px;
}
.excel-popup-close:hover {
    color: #ef4444;
    background-color: #fee2e2;
}
.dark .excel-popup-close:hover {
    background-color: #450a0a;
}

/* Sort Section */
.excel-sort-group {
    padding: 5px 6px;
    border-bottom: 1px solid #f1f5f9;
}
.dark .excel-sort-group {
    border-bottom-color: #1e293b;
}
.excel-sort-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 5px 8px;
    background: none;
    border: none;
    border-radius: 6px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: background-color 0.1s;
}
.dark .excel-sort-btn {
    color: #cbd5e1;
}
.excel-sort-btn:hover {
    background-color: #f1f5f9;
    color: #0f172a;
}
.dark .excel-sort-btn:hover {
    background-color: #1e293b;
    color: #ffffff;
}
.excel-sort-btn.active-sort {
    background-color: #eff6ff;
    color: #2563eb;
    font-weight: 800;
}
.dark .excel-sort-btn.active-sort {
    background-color: rgba(37, 99, 235, 0.2);
    color: #60a5fa;
}

/* Clear filter action link */
.excel-clear-col-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 12px;
    background: none;
    border: none;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: #ef4444;
    cursor: pointer;
}
.dark .excel-clear-col-btn {
    border-bottom-color: #1e293b;
    color: #f87171;
}
.excel-clear-col-btn:hover {
    background-color: #fef2f2;
}
.dark .excel-clear-col-btn:hover {
    background-color: #450a0a;
}

/* Search Box inside Popup */
.excel-search-wrap {
    padding: 6px 10px;
    border-bottom: 1px solid #f1f5f9;
}
.dark .excel-search-wrap {
    border-bottom-color: #1e293b;
}
.excel-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 8px;
    font-size: 11px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background-color: #f8fafc;
    color: #0f172a;
    outline: none;
    transition: border-color 0.15s;
}
.excel-search-input:focus {
    border-color: #10b981;
    background-color: #ffffff;
}
.dark .excel-search-input {
    background-color: #1e293b;
    border-color: #334155;
    color: #ffffff;
}
.dark .excel-search-input:focus {
    border-color: #10b981;
    background-color: #0f172a;
}

/* Checkbox Items List */
.excel-values-list {
    max-height: 190px;
    overflow-y: auto;
    padding: 4px 6px;
    scrollbar-width: thin;
}
.excel-value-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    font-size: 11px;
    color: #334155;
}
.dark .excel-value-item {
    color: #cbd5e1;
}
.excel-value-item:hover {
    background-color: #f1f5f9;
}
.dark .excel-value-item:hover {
    background-color: #1e293b;
}
.excel-value-item input[type="checkbox"] {
    accent-color: #10b981;
    width: 14px;
    height: 14px;
    cursor: pointer;
    flex-shrink: 0;
}
.excel-val-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.excel-val-count {
    color: #94a3b8;
    font-size: 10px;
    font-family: monospace;
    margin-left: auto;
}

/* Popup Footer */
.excel-popup-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 8px 10px;
    background-color: #f8fafc;
    border-top: 1px solid #e2e8f0;
}
.dark .excel-popup-footer {
    background-color: #1e293b;
    border-top-color: #334155;
}
.excel-btn-cancel {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
}
.dark .excel-btn-cancel {
    border-color: #475569;
    color: #94a3b8;
}
.excel-btn-cancel:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}
.dark .excel-btn-cancel:hover {
    background-color: #334155;
    color: #ffffff;
}
.excel-btn-apply {
    padding: 4px 14px;
    font-size: 11px;
    font-weight: 700;
    color: #ffffff;
    background-color: #10b981;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(16, 185, 129, 0.3);
}
.excel-btn-apply:hover {
    background-color: #059669;
}

/* Global Excel Filter Banner above table */
.excel-active-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px 12px;
    background-color: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 600;
    color: #065f46;
}
.dark .excel-active-bar {
    background-color: rgba(6, 78, 59, 0.25);
    border-color: rgba(5, 150, 105, 0.4);
    color: #6ee7b7;
}
.excel-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background-color: #ffffff;
    border: 1px solid #6ee7b7;
    border-radius: 9999px;
    color: #065f46;
    font-size: 10px;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.dark .excel-filter-tag {
    background-color: #064e3b;
    border-color: #059669;
    color: #a7f3d0;
}
.excel-tag-remove {
    background: none;
    border: none;
    color: #059669;
    cursor: pointer;
    font-size: 12px;
    font-weight: bold;
    padding: 0 2px;
    line-height: 1;
}
.excel-tag-remove:hover {
    color: #ef4444;
}
.excel-btn-reset-all {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background-color: #ef4444;
    color: #ffffff;
    border: none;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 800;
    cursor: pointer;
    transition: background-color 0.15s;
}
.excel-btn-reset-all:hover {
    background-color: #dc2626;
}
