/* ============================================
   MSFG Dashboard - Table Styles
   Data tables, sorting, filtering
   ============================================ */

/* ========================================
   TABLE FILTERS BAR
======================================== */
.table-filters {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    flex-wrap: wrap;
}

/* ========================================
   TABLE CONTAINER
======================================== */
.table-container {
    overflow-x: auto;
}

/* Scrollable table body with sticky headers */
.table-scroll {
    max-height: 600px;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
}

.table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--bg-tertiary);
    box-shadow: 0 1px 0 var(--border-color);
}

/* ========================================
   DATA TABLE
======================================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
}

/* Table Header */
.data-table thead {
    background: var(--bg-tertiary);
    position: sticky;
    top: 0;
}

.data-table th {
    padding: var(--spacing-md);
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}

/* Sortable Headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    color: var(--green-bright);
}

.data-table th .sort-icon {
    margin-left: var(--spacing-sm);
    opacity: 0.5;
}

.data-table th.sorted .sort-icon {
    opacity: 1;
    color: var(--green-bright);
}

.data-table th.sorted-asc .sort-icon::before {
    content: '\f0de'; /* fa-sort-up */
}

.data-table th.sorted-desc .sort-icon::before {
    content: '\f0dd'; /* fa-sort-down */
}

/* Table Body */
.data-table td {
    padding: 0.875rem var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Sticky first column on Pre-Approvals / Pipeline / Funded Loans tables */
#preApprovalsTable thead th:first-child,
#pipelineTable thead th:first-child,
#fundedLoansTable thead th:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--bg-tertiary);
}
#preApprovalsTable tbody td:first-child,
#pipelineTable tbody td:first-child,
#fundedLoansTable tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--bg-primary);
    box-shadow: 1px 0 0 var(--border-color);
}
#preApprovalsTable tbody tr:hover td:first-child,
#pipelineTable tbody tr:hover td:first-child,
#fundedLoansTable tbody tr:hover td:first-child {
    background: var(--bg-tertiary);
}

/* Notes Cell (truncated with tooltip) */
.notes-cell {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.notes-cell:hover {
    color: var(--green-bright);
}

/* ========================================
   TABLE RESPONSIVE WRAPPER
======================================== */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md, 8px);
    position: relative;
}

/* Always-visible scrollbar for all data tables */
.table-responsive::-webkit-scrollbar {
    height: 12px;
    display: block;
}
.table-responsive::-webkit-scrollbar-track {
    background: var(--bg-secondary, #f1f1f1);
    border-radius: 6px;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: var(--green-bright, #22c55e);
    border-radius: 6px;
    min-width: 40px;
    border: 2px solid var(--bg-secondary, #f1f1f1);
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: var(--green-dark, #1a9c4a);
}

/* Firefox scrollbar */
.table-responsive {
    scrollbar-width: auto;
    scrollbar-color: var(--green-bright, #22c55e) var(--bg-secondary, #f1f1f1);
}

/* Ensure scrollbar always appears when content overflows */
.table-responsive {
    overflow-x: scroll;
    padding-bottom: 2px;
}

/* No-wrap helper for date cells */
.nowrap {
    white-space: nowrap;
}

/* All data tables: prevent cells from wrapping so horizontal scroll works */
#pipelineTable th,
#pipelineTable td,
#preApprovalsTable th,
#preApprovalsTable td,
#fundedLoansTable th,
#fundedLoansTable td {
    white-space: nowrap;
    padding: 0.6rem 0.75rem;
}
#pipelineTable th,
#preApprovalsTable th,
#fundedLoansTable th {
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted, #666);
    border-bottom: 2px solid var(--border-color, #ddd);
}
/* First column header must sit above both sticky header row and sticky first column */
#pipelineTable thead th:first-child,
#preApprovalsTable thead th:first-child,
#fundedLoansTable thead th:first-child {
    z-index: 5;
    background: var(--bg-tertiary);
}

/* Currency alignment */
.currency {
    font-variant-numeric: tabular-nums;
}

/* Pipeline badge styles are now unified in components.css */

/* ========================================
   PINNED FIRST COLUMN (Client Name)
======================================== */
.table-scroll td:first-child,
.table-scroll th:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--bg-secondary);
}
.table-scroll thead th:first-child {
    z-index: 4;
    background: var(--bg-tertiary);
}
.table-scroll td:first-child::after,
.table-scroll th:first-child::after {
    content: '';
    position: absolute;
    top: 0;
    right: -6px;
    bottom: 0;
    width: 6px;
    background: linear-gradient(to right, rgba(0,0,0,0.06), transparent);
    pointer-events: none;
}

/* Empty state inside tables */
.empty-state {
    text-align: center;
    padding: 3rem 2rem !important;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
    opacity: 0.4;
}

.empty-state-enhanced {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state-enhanced svg {
    width: 120px;
    height: 120px;
    margin: 0 auto 1.25rem;
    display: block;
    opacity: 0.5;
}

.empty-state-enhanced h4 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    font-weight: 600;
}

.empty-state-enhanced p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.5;
}

.empty-state-enhanced .btn {
    margin-top: 0.5rem;
}

/* ========================================
   SYNC STATUS BAR
======================================== */
.sync-status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.sync-status-bar i {
    color: var(--green-bright, #22c55e);
}

/* ========================================
   PIPELINE SECTION ACTIONS
======================================== */
#pipelineSection .section-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

#pipelineSection .search-input {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.8rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    width: 180px;
}

#pipelineSection .filter-select {
    width: auto;
    min-width: 160px;
}

#pipelineSection .search-input::placeholder {
    color: var(--text-muted);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

/* ========================================
   RESPONSIVE TABLE
======================================== */
@media (max-width: 1200px) {
    .data-table {
        font-size: 0.8rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.75rem;
    }
}
