/**
 * Digiclose Table Component
 *
 * Centralized table styles for consistent UI across the application.
 * Based on: dashboard-design.zip (Final Design System)
 * CSS Variables: public/css/vars.css
 *
 * Table Classes:
 * - .table              : Base table styling
 * - .table-bordered     : Add borders
 * - .table-hover        : Hover effect on rows
 * - .table-striped      : Alternating row colors
 *
 * Utility Classes:
 * - .table-checkbox-cell    : Fixed width checkbox column (20px)
 * - .table-action-cell      : Right-aligned action buttons
 * - .table-nowrap           : Prevent text wrapping
 * - .table-compact          : Reduced padding
 * - .table-border-top       : 2px top border separator
 *
 * Row States:
 * - .table-highlight   : Highlighted row (cyan)
 * - .table-blocked     : Blocked/inactive row (red)
 * - .table-info        : Info row (blue)
 * - .table-success     : Success row (green)
 * - .table-warning     : Warning row (yellow)
 * - .table-danger      : Danger row (red)
 *
 * Updated: 2025-01-08
 */

/* ===========================================
   BASE TABLE STYLES
   Uses CSS variables from vars.css
   =========================================== */

.table {
    --bs-table-bg: var(--theme-table-bg);
    --bs-table-color: var(--theme-table-color);
    --bs-table-border-color: var(--theme-table-border-color);

    width: 100%;
    margin-bottom: 1rem;
    vertical-align: middle;
    border-color: var(--theme-table-border-color);
}

.table > :not(caption) > * > * {
    background-color: var(--theme-table-bg);
    color: var(--theme-table-color);
    border-color: var(--theme-table-border-color);
}

/* ===========================================
   TABLE HEADER
   =========================================== */

.table > thead {
    vertical-align: bottom;
}

.table > thead > tr > th {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--theme-muted-foreground, var(--theme-subtle-foreground));
    background-color: var(--theme-tertiary-bg);
    padding: 0.75rem 1rem;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--theme-border-color);
}

/* Sortable header styling */
.table > thead > tr > th.sorting,
.table > thead > tr > th.sorting_asc,
.table > thead > tr > th.sorting_desc {
    cursor: pointer;
    position: relative;
    padding-right: 1.5rem;
}

.table > thead > tr > th.sorting::after,
.table > thead > tr > th.sorting_asc::after,
.table > thead > tr > th.sorting_desc::after {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
}

.table > thead > tr > th.sorting_asc::after {
    content: "↑";
    opacity: 1;
}

.table > thead > tr > th.sorting_desc::after {
    content: "↓";
    opacity: 1;
}

/* ===========================================
   TABLE BODY
   =========================================== */

.table > tbody > tr > td {
    font-size: var(--text-sm);
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--theme-border-color);
}

/* Last row has no bottom border */
.table > tbody > tr:last-child > td {
    border-bottom: none;
}

/* ===========================================
   TABLE CELL UTILITIES
   =========================================== */

/* Checkbox column - standardized to 20px */
.table-checkbox-cell,
.table th.checkbox-col,
.table td.checkbox-col,
.table th:has(> .form-check-input:only-child),
.table td:has(> .form-check-input:only-child) {
    width: 20px;
    min-width: 20px;
    max-width: 40px;
    padding-left: 1rem;
    padding-right: 0.5rem;
    text-align: center;
}

.table-checkbox-cell .form-check,
.checkbox-col .form-check {
    margin: 0;
    padding: 0;
    min-height: auto;
}

.table-checkbox-cell .form-check-input,
.checkbox-col .form-check-input {
    margin: 0;
    float: none;
}

/* Action column - right aligned, no wrap */
.table-action-cell,
.table th.action-col,
.table td.action-col {
    width: auto;
    text-align: right;
    white-space: nowrap;
    padding-right: 1rem;
}

.table-action-cell .btn,
.action-col .btn {
    margin-left: 0.25rem;
}

.table-action-cell .btn:first-child,
.action-col .btn:first-child {
    margin-left: 0;
}

/* No wrap utility */
.table-nowrap,
.table-nowrap td,
.table-nowrap th {
    white-space: nowrap;
}

/* Compact table - reduced padding */
.table-compact > thead > tr > th,
.table-compact > tbody > tr > td {
    padding: 0.5rem 0.75rem;
}

/* ===========================================
   BORDER UTILITIES
   =========================================== */

/* Top border separator (used above footer rows) */
.table-border-top,
.table tr.border-top-2 {
    border-top: 2px solid var(--theme-border-color) !important;
}

.table-border-top > td {
    border-top: 2px solid var(--theme-border-color) !important;
}

/* Bordered table */
.table-bordered {
    border: 1px solid var(--theme-border-color);
}

.table-bordered > thead > tr > th,
.table-bordered > tbody > tr > td {
    border: 1px solid var(--theme-border-color);
}

/* Borderless table */
.table-borderless > thead > tr > th,
.table-borderless > tbody > tr > td {
    border: none;
}

/* ===========================================
   HOVER & STRIPED VARIANTS
   =========================================== */

.table-hover > tbody > tr:hover > * {
    --bs-table-hover-bg: var(--theme-table-hover-bg);
    background-color: var(--theme-table-hover-bg);
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: var(--theme-subtle-background);
}

/* ===========================================
   ROW STATUS CLASSES
   All use CSS variables from vars.css
   =========================================== */

/* Highlighted row */
.table-highlight,
tr.table-highlight > td {
    --theme-table-bg: var(--theme-table-highlight-bg) !important;
    --theme-table-color: var(--theme-table-highlight-color) !important;
    background-color: var(--theme-table-highlight-bg) !important;
    color: var(--theme-table-highlight-color) !important;
    border-color: var(--theme-table-highlight-border-color) !important;
}

/* Blocked/Inactive row */
.table-blocked,
tr.table-blocked > td {
    --theme-table-bg: var(--theme-table-blocked-bg) !important;
    --theme-table-color: var(--theme-table-blocked-color) !important;
    background-color: var(--theme-table-blocked-bg) !important;
    color: var(--theme-table-blocked-color) !important;
    border-color: var(--theme-table-blocked-border-color) !important;
}

/* Info row */
.table-info,
tr.table-info > td {
    --theme-table-bg: var(--theme-table-info-bg) !important;
    --theme-table-color: var(--theme-table-info-color) !important;
    background-color: var(--theme-table-info-bg) !important;
    color: var(--theme-table-info-color) !important;
    border-color: var(--theme-table-info-border-color) !important;
}

/* Success row */
.table-success,
tr.table-success > td {
    --theme-table-bg: var(--theme-table-success-bg) !important;
    --theme-table-color: var(--theme-table-success-color) !important;
    background-color: var(--theme-table-success-bg) !important;
    color: var(--theme-table-success-color) !important;
    border-color: var(--theme-table-success-border-color) !important;
}

/* Warning row */
.table-warning,
tr.table-warning > td {
    --theme-table-bg: var(--theme-table-warning-bg) !important;
    --theme-table-color: var(--theme-table-warning-color) !important;
    background-color: var(--theme-table-warning-bg) !important;
    color: var(--theme-table-warning-color) !important;
    border-color: var(--theme-table-warning-border-color) !important;
}

/* Danger row */
.table-danger,
tr.table-danger > td {
    --theme-table-bg: var(--theme-table-danger-bg) !important;
    --theme-table-color: var(--theme-table-danger-color) !important;
    background-color: var(--theme-table-danger-bg) !important;
    color: var(--theme-table-danger-color) !important;
    border-color: var(--theme-table-danger-border-color) !important;
}

/* ===========================================
   RESPONSIVE TABLE
   =========================================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive > .table {
    margin-bottom: 0;
}

/* ===========================================
   DATATABLES INTEGRATION
   Standardized DataTables overrides
   =========================================== */

/* DataTables wrapper */
.dataTables_wrapper {
    padding: 0;
}

/* DataTables length select */
.dataTables_wrapper .dataTables_length {
    margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_length select {
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    font-size: var(--text-sm);
    border: 1px solid var(--theme-border-color);
    border-radius: var(--border-radius);
    background-color: var(--theme-input-bg);
    color: var(--theme-foreground);
}

/* DataTables search */
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 1rem;
}

.dataTables_wrapper .dataTables_filter input {
    padding: 0.375rem 0.75rem;
    font-size: var(--text-sm);
    border: 1px solid var(--theme-border-color);
    border-radius: var(--border-radius);
    background-color: var(--theme-input-bg);
    color: var(--theme-foreground);
    margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_filter input:focus {
    outline: none;
    border-color: var(--theme-interactive);
    box-shadow: 0 0 0 2px rgba(var(--theme-interactive-rgb), 0.2);
}

/* DataTables info */
.dataTables_wrapper .dataTables_info {
    font-size: var(--text-sm);
    color: var(--theme-muted-foreground, var(--theme-subtle-foreground));
    padding-top: 1rem;
}

/* DataTables pagination */
.dataTables_wrapper .dataTables_paginate {
    padding-top: 1rem;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.375rem 0.75rem;
    margin-left: 0.25rem;
    font-size: var(--text-sm);
    border: 1px solid var(--theme-border-color);
    border-radius: var(--border-radius);
    background-color: var(--theme-background);
    color: var(--theme-foreground);
    cursor: pointer;
    transition: all 0.15s ease;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: var(--theme-subtle-background);
    border-color: var(--theme-border-color-strong);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--theme-primary-btn-bg);
    border-color: var(--theme-primary-btn-border-color);
    color: var(--theme-primary-btn-color);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* DataTables empty row */
.dataTables_wrapper .dataTables_empty {
    text-align: center;
    padding: 2rem;
    color: var(--theme-muted-foreground, var(--theme-subtle-foreground));
}

/* ===========================================
   SPECIAL TABLE LAYOUTS
   =========================================== */

/* Card-style table (no outer borders, rounded) */
.table-card {
    border-radius: var(--border-radius-lg);
    overflow: hidden;
    border: 1px solid var(--theme-border-color);
}

.table-card > thead > tr > th:first-child {
    border-top-left-radius: var(--border-radius-lg);
}

.table-card > thead > tr > th:last-child {
    border-top-right-radius: var(--border-radius-lg);
}

.table-card > tbody > tr:last-child > td:first-child {
    border-bottom-left-radius: var(--border-radius-lg);
}

.table-card > tbody > tr:last-child > td:last-child {
    border-bottom-right-radius: var(--border-radius-lg);
}

/* Inline table (for embedded tables without margins) */
.table-inline {
    margin-bottom: 0;
}

/* Clickable rows */
.table-clickable > tbody > tr {
    cursor: pointer;
}

.table-clickable > tbody > tr:hover {
    background-color: var(--theme-table-hover-bg);
}

/* ===========================================
   DARK MODE
   Automatically handled by CSS variables
   =========================================== */

/* Dark mode specific adjustments if needed */
.dark .dataTables_wrapper .dataTables_filter input,
.dark .dataTables_wrapper .dataTables_length select {
    background-color: var(--theme-input-bg);
    border-color: var(--theme-border-color);
    color: var(--theme-foreground);
}

.dark .dataTables_wrapper .dataTables_paginate .paginate_button {
    background-color: var(--theme-background-secondary-bg);
    border-color: var(--theme-border-color);
    color: var(--theme-foreground);
}

.dark .dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background-color: var(--theme-tertiary-bg);
}

/* ===========================================
   ENHANCED HOVER & SUMMARY STYLES
   Based on: /home/cneise/design
   =========================================== */

/* Subtler hover effect */
.table-hover > tbody > tr:hover > * {
    --bs-table-hover-bg: rgba(0, 0, 0, 0.015);
    background-color: rgba(0, 0, 0, 0.015);
}

.dark .table-hover > tbody > tr:hover > * {
    --bs-table-hover-bg: rgba(255, 255, 255, 0.03);
    background-color: rgba(255, 255, 255, 0.03);
}

/* Summary Row styling */
.table > tbody > tr.table-summary > td {
    background-color: var(--theme-muted, var(--theme-subtle-background));
    font-weight: 600;
    border-top: 2px solid var(--theme-border-color);
}

/* Auto-detect summary rows by inline border-top style */
.table > tbody > tr:last-child > td[style*="border-top: 2px"] {
    background-color: var(--theme-muted, var(--theme-subtle-background));
}

/* Table Links */
.table a:not(.btn):not(.dropdown-item):not(.nav-link) {
    color: var(--theme-interactive);
    text-decoration: none;
    transition: color 0.15s ease;
}

.table a:not(.btn):not(.dropdown-item):not(.nav-link):hover {
    color: var(--theme-interactive-hover);
    text-decoration: underline;
}
