/* ==========================================================================
   BharatSeva Admin Portal - Excel Table System (Polished & Smooth UI)
   ========================================================================== */

/* 🚫 COMPLETELY REMOVE DEFAULT DATATABLES SORTING ARROWS & GLYPHS */
.dt-column-order,
span.dt-column-order,
span[class*="dt-column-order"],
table.dataTable thead th .dt-column-order,
table.dataTable thead td .dt-column-order,
table.dataTable thead th svg,
table.dataTable thead th:before,
table.dataTable thead th:after,
table.dataTable thead td:before,
table.dataTable thead td:after,
.dataTables_wrapper thead th:before,
.dataTables_wrapper thead th:after,
.dataTables_wrapper thead td:before,
.dataTables_wrapper thead td:after,
.dt-container thead th:before,
.dt-container thead th:after,
.dt-container thead td:before,
.dt-container thead td:after,
table.dataTable thead th.sorting:before,
table.dataTable thead th.sorting:after,
table.dataTable thead th.sorting_asc:before,
table.dataTable thead th.sorting_asc:after,
table.dataTable thead th.sorting_desc:before,
table.dataTable thead th.sorting_desc:after,
table.dataTable thead th.dt-orderable-asc:before,
table.dataTable thead th.dt-orderable-asc:after,
table.dataTable thead th.dt-orderable-desc:before,
table.dataTable thead th.dt-orderable-desc:after,
table.dataTable thead th.dt-orderable-none:before,
table.dataTable thead th.dt-orderable-none:after,
table.dataTable thead .dt-column-order,
table.dataTable thead .dt-column-order:before,
table.dataTable thead .dt-column-order:after {
    display: none !important;
    content: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
}

/* Remove default forced sorting padding-right and background arrow images */
table.dataTable thead th,
table.dataTable thead td,
table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc,
table.dataTable thead th.dt-orderable-asc,
table.dataTable thead th.dt-orderable-desc,
table.dataTable thead th.dt-orderable-none {
    background-image: none !important;
    padding-right: 10px !important;
    cursor: default !important;
    position: relative;
    user-select: none;
}

/* 🎯 Column Header Excel Filter Trigger & Layout */
.excel-th-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    position: relative;
    gap: 8px;
}

.excel-th-title {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
    font-size: 11px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #475569;
}

.excel-trigger-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Modern sleek filter button */
.excel-filter-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    background: #ffffff;
    color: #64748b;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.excel-filter-trigger:hover {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}

.excel-filter-trigger:active {
    transform: translateY(0);
}

/* Filter active state (bright blue) */
.excel-filter-trigger.has-filter {
    background: #2563eb !important;
    border-color: #2563eb !important;
    color: #ffffff !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35) !important;
}

.excel-filter-trigger.has-filter i {
    color: #ffffff !important;
    animation: filterPulse 2.4s infinite ease-in-out;
}

@keyframes filterPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* Active sort badge indicator beside funnel */
.excel-sort-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 20px;
    padding: 0 6px;
    border-radius: 6px;
    font-size: 9px;
    font-weight: 700;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    gap: 3px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.excel-sort-badge:hover {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1e40af;
    transform: translateY(-1px);
}

.excel-sort-badge i {
    font-size: 9px;
}

/* 🪟 Excel Filter Popover */
.excel-filter-popover {
    position: fixed !important;
    z-index: 99999999 !important;
    width: 280px !important;
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100vh - 24px) !important;
    box-sizing: border-box !important;
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 12px !important;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22), 0 4px 16px rgba(15, 23, 42, 0.08) !important;
    padding: 12px 14px !important;
    display: none;
    flex-direction: column !important;
    gap: 8px !important;
    font-size: 13px !important;
    color: #334155 !important;
    overflow: hidden !important;
    animation: excelPopoverSlide 0.15s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

.excel-filter-popover * {
    box-sizing: border-box;
}

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

.excel-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0 !important;
}

.excel-popover-header .col-title {
    font-weight: 700;
    color: #0f172a;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.excel-popover-header .col-title i {
    color: #2563eb;
    font-size: 11px;
}

.excel-popover-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.excel-popover-close:hover {
    color: #0f172a;
    background: #f1f5f9;
}

/* Sort actions inside popover */
.excel-popover-sort-section {
    flex-shrink: 0 !important;
}

.excel-popover-sort {
    display: flex;
    gap: 6px;
}

.excel-popover-sort-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 500;
    color: #475569;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.excel-popover-sort-btn:hover {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
    transform: translateY(-1px);
}

.excel-popover-sort-btn:active {
    transform: translateY(0);
}

.excel-popover-sort-btn.active {
    background: #2563eb !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}

.excel-popover-sort-btn.active i {
    color: #ffffff !important;
}

/* Condition & Search inside popover */
.excel-popover-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.excel-popover-input-wrapper {
    position: relative;
}

.excel-popover-input-wrapper i.search-icon {
    position: absolute;
    left: 9px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 11px;
    pointer-events: none;
}

.excel-popover-search {
    width: 100%;
    padding: 6px 26px 6px 28px !important;
    font-size: 12px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    background-color: #ffffff !important;
    color: #0f172a !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.excel-popover-search:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15) !important;
    outline: none !important;
}

.excel-popover-clear-input {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 13px;
    display: none;
    line-height: 1;
}

.excel-popover-clear-input:hover {
    color: #0f172a;
}

/* Distinct values list */
.excel-popover-body {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

.excel-popover-val-box {
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    background: #f8fafc !important;
    padding: 6px 4px !important;
    max-height: min(140px, calc(100vh - 280px)) !important;
    min-height: 48px !important;
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
    scrollbar-width: thin !important;
    scrollbar-color: #94a3b8 #f1f5f9 !important;
    box-sizing: border-box !important;
}

.excel-popover-val-box::-webkit-scrollbar {
    width: 6px !important;
    height: 6px !important;
    display: block !important;
}
.excel-popover-val-box::-webkit-scrollbar-track {
    background: #f1f5f9 !important;
    border-radius: 6px !important;
}
.excel-popover-val-box::-webkit-scrollbar-thumb {
    background: #94a3b8 !important;
    border-radius: 6px !important;
    border: 1px solid #f1f5f9 !important;
}
.excel-popover-val-box::-webkit-scrollbar-thumb:hover {
    background: #64748b !important;
}

.excel-popover-val-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 6px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 11px;
    user-select: none;
    transition: background-color 0.12s ease;
    margin-bottom: 1px;
}

.excel-popover-val-item:hover {
    background-color: #e2e8f0;
}

.excel-popover-val-item input[type="checkbox"] {
    accent-color: #2563eb;
    cursor: pointer;
    width: 13px;
    height: 13px;
    margin: 0;
}

.excel-popover-val-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1e293b;
}

.excel-popover-val-count {
    font-size: 9px;
    color: #64748b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    padding: 0 5px;
}

/* Footer buttons */
.excel-popover-footer {
    display: flex;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
    margin-top: auto !important;
    flex-shrink: 0 !important;
}

.excel-popover-footer .btn {
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 8px;
}

.excel-popover-apply {
    flex: 1;
    background: linear-gradient(135deg, #2563eb, #1d4ed8) !important;
    border: none !important;
    color: #ffffff !important;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25) !important;
    transition: all 0.15s ease;
}

.excel-popover-apply:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af) !important;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35) !important;
    transform: translateY(-1px);
}

.excel-popover-apply:active {
    transform: translateY(0);
}

.excel-popover-clear {
    background: #ffffff !important;
    border: 1px solid #cbd5e1 !important;
    color: #64748b !important;
    font-weight: 500;
    transition: all 0.15s ease;
}

.excel-popover-clear:hover {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-color: #94a3b8 !important;
}

/* 🏷️ Active Filters Bar */
.active-filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 12px;
    color: #475569;
    animation: barSlideDown 0.2s ease-out;
}

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

.active-filters-bar .filters-label {
    font-weight: 600;
    color: #334155;
    display: flex;
    align-items: center;
    gap: 6px;
}

.active-filters-bar .filters-label i {
    color: #2563eb;
}

.active-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: #ffffff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
    border-radius: 999px;
    font-weight: 500;
    box-shadow: 0 1px 3px rgba(30, 64, 175, 0.06);
    transition: all 0.15s ease;
}

.active-filter-chip:hover {
    border-color: #93c5fd;
    background: #f0f7ff;
}

.active-filter-chip .chip-col {
    color: #64748b;
    font-weight: 400;
}

.active-filter-chip .chip-remove {
    cursor: pointer;
    color: #93c5fd;
    font-size: 13px;
    line-height: 1;
    border-radius: 50%;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.active-filter-chip .chip-remove:hover {
    color: #ef4444;
    background: #fee2e2;
}

.active-filters-clear-all {
    margin-left: auto;
    background: none;
    border: none;
    color: #ef4444;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 6px;
    transition: background-color 0.15s ease;
}

.active-filters-clear-all:hover {
    background-color: #fee2e2;
}

/* 📊 Export to Excel Button */
.btn-export-excel {
    background: linear-gradient(135deg, #107c41, #0c5e31) !important;
    border: 1px solid #0c5e31 !important;
    color: #ffffff !important;
    font-weight: 600 !important;
    font-size: 12px !important;
    border-radius: 8px !important;
    padding: 6px 14px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 6px !important;
    box-shadow: 0 2px 6px rgba(16, 124, 65, 0.22) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none !important;
}

.btn-export-excel:hover {
    background: linear-gradient(135deg, #0e6d39, #094a26) !important;
    color: #ffffff !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 124, 65, 0.32) !important;
}

.btn-export-excel:active {
    transform: translateY(0);
}

.btn-export-excel i {
    font-size: 13px;
}

/* 🎛️ Proper Pagination & Controls Enhancement */
.dt-toolbar-flex {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.dt-length-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #64748b;
}

.dt-length-wrapper select,
.dataTables_length select,
.dt-length select {
    border: 1px solid #cbd5e1 !important;
    border-radius: 8px !important;
    padding: 4px 8px !important;
    font-size: 12px !important;
    color: #334155 !important;
    background-color: #ffffff !important;
    cursor: pointer;
    outline: none !important;
    transition: border-color 0.15s ease;
}

.dt-length-wrapper select:focus,
.dataTables_length select:focus,
.dt-length select:focus {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15) !important;
}

/* DataTables pagination controls polish */
.dataTables_paginate,
.dt-paging {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 14px;
}

.dataTables_paginate .paginate_button,
.dt-paging .dt-paging-button {
    padding: 5px 11px !important;
    font-size: 12px !important;
    border-radius: 8px !important;
    border: 1px solid #e2e8f0 !important;
    background: #ffffff !important;
    color: #475569 !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
    text-decoration: none !important;
}

.dataTables_paginate .paginate_button:hover:not(.disabled):not(.current),
.dt-paging .dt-paging-button:hover:not(.disabled):not(.current) {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
}

.dataTables_paginate .paginate_button.current,
.dt-paging .dt-paging-button.current {
    background: #2563eb !important;
    color: #ffffff !important;
    border-color: #2563eb !important;
    font-weight: 600 !important;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25) !important;
}

.dataTables_paginate .paginate_button.disabled,
.dt-paging .dt-paging-button.disabled {
    opacity: 0.45 !important;
    cursor: not-allowed !important;
    background: #f8fafc !important;
}

/* Table container polish */
.table-wrapper table thead th {
    user-select: none;
    vertical-align: middle;
}

/* Toast notifications */
.excel-toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.excel-toast {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: #0f172a;
    color: #ffffff;
    padding: 12px 18px;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    font-size: 13px;
    pointer-events: auto;
    animation: toastSlideIn 0.25s ease-out forwards;
}

.excel-toast.success {
    background: #065f46;
    border-left: 4px solid #10b981;
}

.excel-toast.error {
    background: #991b1b;
    border-left: 4px solid #ef4444;
}

.excel-toast i {
    font-size: 16px;
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}
