/* ==========================================================================
   Universal Excel-Style Table Styles (Resizing, Formula Bar, Cell Inspector)
   ========================================================================== */

/* Table Container & Table Layout */
.excel-table-card,
.card:has(table.dataTable),
.card:has(table.table-inv) {
    border: 1px solid #ebeef0;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
}

#datatable_wrapper,
.dataTables_wrapper {
    position: relative;
}

#datatable_wrapper .table-responsive,
.dataTables_wrapper .table-responsive {
    overflow-x: auto;
    position: relative;
    min-height: 250px;
}

table.dataTable,
#datatable,
.table-inv {
    table-layout: fixed !important;
    width: max-content !important;
    min-width: 100% !important;
    border-collapse: separate !important;
    border-spacing: 0 !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

/* Headers */
table.dataTable thead th,
#datatable thead th,
.table-inv thead th {
    position: relative;
    background-color: #f5f5f9 !important;
    color: #566a7f !important;
    font-weight: 600;
    font-size: 0.8125rem;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    vertical-align: middle !important;
    padding: 8px 12px !important;
    border-bottom: 2px solid #d9dee3 !important;
    border-right: 1px solid #e7e7e8 !important;
    user-select: none;
}

table.dataTable thead th:last-child,
#datatable thead th:last-child,
.table-inv thead th:last-child {
    border-right: none !important;
}

/* Data Cells */
table.dataTable tbody td,
#datatable tbody td,
.table-inv tbody td {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    vertical-align: middle !important;
    padding: 6px 10px !important;
    font-size: 0.8125rem;
    line-height: 1.25;
    border-right: 1px solid #f0f0f2 !important;
    border-bottom: 1px solid #ebeef0 !important;
    cursor: cell !important;
}

table.dataTable tbody td:last-child,
#datatable tbody td:last-child,
.table-inv tbody td:last-child {
    border-right: none !important;
}

table.dataTable tbody td.actions-cell,
table.dataTable tbody td:has(.btn, a, button, .dropdown),
#datatable tbody td:has(.btn, a, button, .dropdown) {
    cursor: default !important;
}

/* Column Resizer Handle */
.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 8px;
    bottom: 0;
    cursor: col-resize;
    user-select: none;
    z-index: 20;
    background: transparent;
}

.col-resizer::after {
    content: '';
    position: absolute;
    top: 20%;
    bottom: 20%;
    right: 1px;
    width: 2px;
    background-color: #d9dee3;
    transition: all 0.15s ease;
}

.col-resizer:hover::after,
.col-resizer.resizing::after {
    background-color: #696cff !important;
    width: 3px;
    top: 0;
    bottom: 0;
}

/* Active Cell Selection (Excel style) */
table.dataTable tbody td.cell-selected,
#datatable tbody td.cell-selected,
.table-inv tbody td.cell-selected {
    outline: 2px solid #696cff !important;
    outline-offset: -2px !important;
    background-color: #f2f3ff !important;
}

/* Excel Formula / Info Bar (Preserves fixed blank space when unselected) */
.excel-formula-bar {
    display: flex;
    align-items: center;
    padding: 5px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid #ebeef0;
    font-size: 0.8125rem;
    min-height: 42px;
    height: 42px;
    box-sizing: border-box;
}

.excel-formula-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    visibility: hidden;
}

.excel-formula-bar.active .excel-formula-inner {
    visibility: visible;
}

.excel-formula-label {
    font-weight: 600;
    color: #696cff;
    background: #e7e7ff;
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.excel-formula-content {
    flex-grow: 1;
    background: #ffffff;
    border: 1px solid #d9dee3;
    border-radius: 4px;
    padding: 4px 10px;
    min-height: 29px;
    max-height: 32px;
    overflow-y: auto;
    color: #384551;
    font-family: inherit;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Floating Cell Information Popover */
.cell-inspect-popover {
    position: fixed;
    z-index: 1060;
    background: #ffffff;
    border: 1px solid #696cff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    padding: 10px 14px;
    max-width: 420px;
    min-width: 220px;
    font-size: 0.8125rem;
    color: #384551;
    word-break: break-word;
    white-space: normal;
    display: none;
}

.cell-inspect-popover-header {
    font-weight: 600;
    color: #696cff;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    border-bottom: 1px solid #f0f0f2;
    padding-bottom: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cell-inspect-popover-body {
    line-height: 1.4;
    max-height: 200px;
    overflow-y: auto;
}

/* DataTables pagination & compact headers */
.dataTables_wrapper .card-header,
#datatable_wrapper .card-header {
    padding: 0.5rem 1rem !important;
    border-bottom: 1px solid #ebeef0;
    background-color: transparent;
}

.dataTables_wrapper .card-footer,
#datatable_wrapper .card-footer {
    padding: 0.4rem 1rem !important;
    border-top: 1px solid #ebeef0;
    background-color: transparent;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    flex-wrap: wrap !important;
    gap: 0.5rem;
}

.dataTables_wrapper .dataTables_info,
#datatable_wrapper .dataTables_info {
    font-size: 0.75rem !important;
    padding: 0 !important;
    margin: 0 !important;
    color: #8592a3 !important;
    line-height: 1.5;
    display: block !important;
}

.dataTables_wrapper .dataTables_paginate,
#datatable_wrapper .dataTables_paginate {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
}

.dataTables_wrapper .dataTables_paginate ul.pagination,
#datatable_wrapper .dataTables_paginate ul.pagination {
    margin: 0 !important;
    display: flex !important;
    gap: 2px !important;
}

.dataTables_wrapper .dataTables_paginate .page-link,
#datatable_wrapper .dataTables_paginate .page-link {
    padding: 0.15rem 0.45rem !important;
    font-size: 0.725rem !important;
    min-width: 26px !important;
    height: 26px !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 4px !important;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
#datatable_wrapper .dataTables_length,
#datatable_wrapper .dataTables_filter {
    margin: 0 !important;
}

.dataTables_wrapper .dataTables_filter label,
.dataTables_wrapper .dataTables_length label,
#datatable_wrapper .dataTables_filter label,
#datatable_wrapper .dataTables_length label {
    margin-bottom: 0 !important;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
}

.dataTables_wrapper .dataTables_filter input,
#datatable_wrapper .dataTables_filter input {
    margin-left: 0 !important;
    height: 32px;
    font-size: 0.8125rem;
    padding: 0.2rem 0.5rem;
}

.dataTables_wrapper .dataTables_length select,
#datatable_wrapper .dataTables_length select {
    height: 32px;
    font-size: 0.8125rem;
    padding: 0.2rem 1.6rem 0.2rem 0.5rem;
}

/* Reset Widths button styling */
.btn-reset-col-widths,
#btnResetColWidths {
    font-size: 0.8125rem;
}

.btn-reset-col-widths:focus,
.btn-reset-col-widths:active,
.btn-reset-col-widths:focus-visible,
#btnResetColWidths:focus,
#btnResetColWidths:active,
#btnResetColWidths:focus-visible {
    box-shadow: none !important;
    outline: none !important;
    background-color: transparent !important;
    color: #8592a3 !important;
    border-color: #8592a3 !important;
}

.btn-reset-col-widths:hover,
#btnResetColWidths:hover {
    background-color: #8592a3 !important;
    color: #fff !important;
}
