/**
 * AUTOCORE360 Admin Panel - Tables
 * Modern responsive tables inspired by MANDIAG Panel
 * DataTables integration, mobile-first responsive design
 */

/* ============ TABLE CONTAINER (MANDIAG Style) ============ */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow);
}

/* Subtle gradient top border */
.table-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.table-container:hover::before {
    opacity: 1;
}

/* Table wrapper for horizontal scroll */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============ BASE TABLE (MANDIAG Style) ============ */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table th {
    background: linear-gradient(180deg, var(--background) 0%, rgba(0,0,0,0.02) 100%);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: none; /* Removed uppercase for better readability */
    letter-spacing: normal;
    font-size: var(--text-sm, 0.875rem);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border);
}

[data-theme="dark"] .table th {
    background: linear-gradient(180deg, var(--background) 0%, rgba(255,255,255,0.02) 100%);
}

.table th:first-child {
    padding-left: 1.5rem;
}

.table th:last-child {
    padding-right: 1.5rem;
}

.table td:first-child {
    padding-left: 1.5rem;
}

.table td:last-child {
    padding-right: 1.5rem;
}

/* Table body rows */
.table tbody tr {
    transition: background-color 0.15s ease;
}

.table tbody tr:hover {
    background: rgba(var(--primary-rgb, 37, 99, 235), 0.04);
}

@media (prefers-color-scheme: dark) {
    .table tbody tr:hover {
        background: rgba(var(--primary-rgb, 220, 38, 38), 0.06);
    }
}

[data-theme="dark"] .table tbody tr:hover {
    background: rgba(99, 102, 241, 0.06);
}

/* Clickable row styling */
.table tbody tr[onclick],
.table tbody tr[style*="cursor: pointer"] {
    cursor: pointer;
}

.table tbody tr[onclick]:hover,
.table tbody tr[style*="cursor: pointer"]:hover {
    background: rgba(37, 99, 235, 0.06);
}

/* Alternating row colors */
.table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] .table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.015);
}

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

/* Table cell variations */
.table td.text-center,
.table th.text-center {
    text-align: center;
}

.table td.text-right,
.table th.text-right {
    text-align: right;
}

.table td.text-muted {
    color: var(--text-muted);
}

/* Table actions column */
.table-actions {
    display: flex;
    gap: 0.375rem;
    justify-content: flex-end;
}

.table-actions .btn {
    padding: 0.375rem 0.5rem;
}

/* Compact table variant */
.table-compact th,
.table-compact td {
    padding: 0.625rem 1rem;
}

/* ============ STATUS BADGES ============ */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    transition: all 0.2s ease;
}

.status-badge:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.status-active,
.status-badge--active {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.status-trial,
.status-badge--trial {
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-expired,
.status-badge--expired {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-disabled,
.status-badge--disabled {
    background: rgba(100, 116, 139, 0.1);
    color: #64748b;
    border: 1px solid rgba(100, 116, 139, 0.2);
}

.status-pending,
.status-badge--pending {
    background: rgba(6, 182, 212, 0.1);
    color: #06b6d4;
    border: 1px solid rgba(6, 182, 212, 0.2);
}

/* ============ DATATABLES CUSTOMIZATION (MANDIAG Style) ============ */

/* Main DataTables wrapper */
.dataTables_wrapper {
    padding: 0;
    width: 100%;
    position: relative;
}

/* Header controls area */
.dataTables_wrapper .row:first-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    margin: 0;
}

/* DataTables Length (entries per page) */
.dataTables_length {
    margin: 0;
}

.dataTables_length label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0;
}

.dataTables_length select {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text);
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.dataTables_length select:hover {
    border-color: var(--primary);
}

.dataTables_length select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

/* DataTables Filter (search) */
.dataTables_filter {
    margin: 0;
}

.dataTables_filter label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    margin: 0;
}

.dataTables_filter input {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--background);
    color: var(--text);
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    font-size: 0.8125rem;
    min-width: 200px;
    transition: all 0.2s ease;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.75rem center;
}

.dataTables_filter input::placeholder {
    color: var(--text-muted);
}

.dataTables_filter input:hover {
    border-color: var(--primary);
}

.dataTables_filter input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

/* DataTables Table */
table.dataTable {
    width: 100% !important;
    margin: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
}

table.dataTable thead th {
    background: linear-gradient(180deg, var(--background) 0%, rgba(0,0,0,0.02) 100%);
    padding: 0.875rem 1.25rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.6875rem;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: relative;
}

[data-theme="dark"] table.dataTable thead th {
    background: linear-gradient(180deg, var(--background) 0%, rgba(255,255,255,0.02) 100%);
}

table.dataTable thead th:first-child {
    padding-left: 1.5rem;
}

table.dataTable thead th:last-child {
    padding-right: 1.5rem;
}

table.dataTable tbody td {
    padding: 1rem 1.25rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 0.875rem;
}

table.dataTable tbody td:first-child {
    padding-left: 1.5rem;
}

table.dataTable tbody td:last-child {
    padding-right: 1.5rem;
}

/* Row hover effect */
table.dataTable tbody tr {
    transition: all 0.15s ease;
}

table.dataTable.hover tbody tr:hover,
table.dataTable tbody tr:hover {
    background-color: rgba(37, 99, 235, 0.04);
}

[data-theme="dark"] table.dataTable.hover tbody tr:hover,
[data-theme="dark"] table.dataTable tbody tr:hover {
    background-color: rgba(99, 102, 241, 0.06);
}

/* Alternating row colors */
table.dataTable tbody tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.015);
}

[data-theme="dark"] table.dataTable tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.015);
}

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

/* Footer controls area */
.dataTables_wrapper .row:last-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    margin: 0;
}

/* DataTables Info */
.dataTables_info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin: 0;
    padding: 0;
}

/* DataTables Pagination */
.dataTables_paginate {
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.dataTables_paginate .paginate_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.625rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text) !important;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none !important;
}

.dataTables_paginate .paginate_button:hover:not(.disabled):not(.current) {
    background: var(--background);
    border-color: var(--primary);
    color: var(--primary) !important;
    transform: translateY(-1px);
}

.dataTables_paginate .paginate_button.current {
    background: var(--primary-gradient);
    color: white !important;
    border-color: transparent;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.dataTables_paginate .paginate_button.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.dataTables_paginate .paginate_button.previous,
.dataTables_paginate .paginate_button.next {
    padding: 0 0.75rem;
}

/* Ellipsis for pagination */
.dataTables_paginate .ellipsis {
    padding: 0 0.5rem;
    color: var(--text-muted);
}

/* DataTables sorting icons - Modern chevron style */
table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
    cursor: pointer;
    position: relative;
    padding-right: 1.75rem !important;
    user-select: none;
}

table.dataTable thead .sorting:hover,
table.dataTable thead .sorting_asc:hover,
table.dataTable thead .sorting_desc:hover {
    color: var(--primary);
}

table.dataTable thead .sorting::before,
table.dataTable thead .sorting::after,
table.dataTable thead .sorting_asc::before,
table.dataTable thead .sorting_asc::after,
table.dataTable thead .sorting_desc::before,
table.dataTable thead .sorting_desc::after {
    position: absolute;
    right: 0.625rem;
    font-family: 'Font Awesome 6 Free', 'Font Awesome 5 Free', sans-serif;
    font-weight: 900;
    font-size: 0.5rem;
    opacity: 0.3;
    transition: opacity 0.15s ease, color 0.15s ease;
}

table.dataTable thead .sorting::before,
table.dataTable thead .sorting_asc::before,
table.dataTable thead .sorting_desc::before {
    top: calc(50% - 6px);
    content: "\f077"; /* fa-chevron-up */
}

table.dataTable thead .sorting::after,
table.dataTable thead .sorting_asc::after,
table.dataTable thead .sorting_desc::after {
    top: calc(50% + 2px);
    content: "\f078"; /* fa-chevron-down */
}

table.dataTable thead .sorting_asc::before {
    opacity: 1;
    color: var(--primary);
}

table.dataTable thead .sorting_desc::after {
    opacity: 1;
    color: var(--primary);
}

/* Processing indicator */
.dataTables_processing {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 1rem 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    color: var(--text);
    z-index: 100;
}

/* Empty table message */
.dataTables_empty {
    text-align: center;
    padding: 3rem 1rem !important;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ============ TABLE TOOLBAR (Custom Controls) ============ */
.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.table-toolbar__left,
.table-toolbar__right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.table-toolbar__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-toolbar__title i {
    color: var(--primary);
}

.table-toolbar__search {
    position: relative;
    min-width: 200px;
}

.table-toolbar__search input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--background);
    color: var(--text);
    font-size: 0.8125rem;
    transition: all 0.2s ease;
}

.table-toolbar__search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

.table-toolbar__search i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.75rem;
}

.table-toolbar__filter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.table-toolbar__filter select {
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--background);
    color: var(--text);
    font-size: 0.8125rem;
    cursor: pointer;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
}

.table-toolbar__filter select:hover,
.table-toolbar__filter select:focus {
    border-color: var(--primary);
}

.table-toolbar__filter select:focus {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

/* Table footer */
.table-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.table-footer__info {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.table-footer__pagination {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ============ ADVANCED TABLE FEATURES ============ */

/* Sortable columns */
.table th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.75rem;
}

.table th.sortable::after {
    content: '';
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--text-muted);
    opacity: 0.4;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.table th.sortable:hover::after {
    opacity: 0.7;
}

.table th.sortable.asc::after {
    opacity: 1;
    border-top: none;
    border-bottom: 5px solid var(--primary);
}

.table th.sortable.desc::after {
    opacity: 1;
    border-top: 5px solid var(--primary);
}

/* Row selection */
.table-selectable tbody tr {
    cursor: pointer;
}

.table-selectable tbody tr.selected {
    background: rgba(99, 102, 241, 0.08);
}

.table-selectable tbody tr.selected:hover {
    background: rgba(99, 102, 241, 0.12);
}

/* Row checkbox */
.table-checkbox {
    width: 40px;
    text-align: center;
}

.table-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* Bulk actions bar */
.bulk-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    animation: slideDown 0.2s ease;
}

.bulk-actions-count {
    font-weight: 600;
    font-size: 0.875rem;
}

.bulk-actions-buttons {
    display: flex;
    gap: 0.5rem;
    margin-left: auto;
}

.bulk-actions .btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
}

.bulk-actions .btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

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

/* Expandable rows */
.table-expandable tbody tr.expandable {
    cursor: pointer;
}

.table-expandable .expand-toggle {
    width: 40px;
    text-align: center;
}

.table-expandable .expand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-sm);
    background: var(--surface-hover);
    transition: transform 0.15s ease, background 0.15s ease;
}

.table-expandable .expand-icon i {
    font-size: 0.625rem;
    color: var(--text-muted);
}

.table-expandable tr.expanded .expand-icon {
    transform: rotate(90deg);
    background: var(--primary);
}

.table-expandable tr.expanded .expand-icon i {
    color: white;
}

.table-expand-content {
    display: none;
    background: var(--background);
}

.table-expand-content.active {
    display: table-row;
}

.table-expand-content td {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
}

/* Row hover actions */
.table-hover-actions .table-actions {
    opacity: 0;
    transition: opacity 0.15s ease;
}

.table-hover-actions tbody tr:hover .table-actions {
    opacity: 1;
}

/* Sticky first column */
.table-sticky-col th:first-child,
.table-sticky-col td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 5;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
}

.table-sticky-col tbody tr:hover td:first-child {
    background: var(--surface-hover);
}

/* Table loading overlay */
.table-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

[data-theme="dark"] .table-loading-overlay {
    background: rgba(17, 24, 39, 0.8);
}

/* Table empty row */
.table-empty td {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.table-empty-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

/* Row highlight variants */
.table tbody tr.row-success,
.table tbody tr.highlight-row {
    background: rgba(16, 185, 129, 0.05);
    animation: highlightFade 3s ease;
}

.table tbody tr.row-warning {
    background: rgba(245, 158, 11, 0.05);
}

.table tbody tr.row-danger {
    background: rgba(239, 68, 68, 0.05);
}

.table tbody tr.row-info {
    background: rgba(6, 182, 212, 0.05);
}

@keyframes highlightFade {
    0% { background: rgba(16, 185, 129, 0.15); }
    100% { background: rgba(16, 185, 129, 0.05); }
}

/* Striped table variant */
.table-striped tbody tr:nth-child(odd) {
    background: var(--surface);
}

.table-striped tbody tr:nth-child(even) {
    background: var(--background);
}

/* Bordered table */
.table-bordered th,
.table-bordered td {
    border: 1px solid var(--border);
}

/* ============ TABLE CELL COMPONENTS ============ */

/* Cell with avatar */
.table-cell-avatar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.table-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: #fff;
    flex-shrink: 0;
}

.table-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.table-cell-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.table-cell-primary,
.table-cell-title {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-cell-secondary,
.table-cell-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Table progress bar */
.table-progress {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.table-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.table-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, #8b5cf6 100%);
    border-radius: 3px;
    transition: width 0.5s ease;
}

.table-progress-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 40px;
    text-align: right;
}

/* Table action buttons */
.table-action-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.table-action-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.table-action-btn.edit:hover {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
}

.table-action-btn.delete:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.table-action-btn.view:hover {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

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

/* Tablet adjustments */
@media (max-width: 992px) {
    .table th,
    .table td {
        padding: 0.875rem 1rem;
    }

    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_length {
        float: none !important;
        text-align: left;
    }

    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: center;
    }
}

/* Mobile improvements */
@media (max-width: 768px) {
    /* Table container */
    .table-container {
        border-radius: var(--radius);
        margin: 0 -0.5rem;
        width: calc(100% + 1rem);
    }

    .table-container:hover {
        transform: none;
    }

    /* Make sure DataTables are responsive */
    .dataTables_wrapper {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table th,
    .table td {
        padding: 0.75rem;
        font-size: 0.8125rem;
    }

    .table th {
        font-size: 0.625rem;
    }

    /* DataTables controls */
    .dataTables_filter,
    .dataTables_length {
        margin-bottom: 0.75rem;
    }

    .dataTables_filter label,
    .dataTables_length label {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .dataTables_filter input,
    .dataTables_length select {
        margin-left: 0;
        width: 100%;
    }

    .dataTables_info,
    .dataTables_paginate {
        text-align: center;
        float: none !important;
        margin-top: 1rem;
    }

    .dataTables_paginate .paginate_button {
        padding: 0.5rem 0.625rem;
        margin: 0.125rem;
        font-size: 0.8125rem;
    }

    /* Table actions */
    .table-actions {
        flex-wrap: wrap;
        gap: 0.25rem;
    }

    .table-actions .btn {
        padding: 0.25rem 0.375rem;
        font-size: 0.75rem;
    }

    /* Hide less important columns on mobile */
    .table .hide-mobile {
        display: none;
    }
}

/* Small mobile */
@media (max-width: 576px) {
    .table-container {
        margin: 0 -1rem;
        width: calc(100% + 2rem);
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .table th,
    .table td {
        padding: 0.625rem 0.75rem;
        font-size: 0.75rem;
    }

    .table th {
        font-size: 0.5625rem;
    }

    /* Stackable table - converts to card-like layout on mobile */
    .table-stack-mobile {
        display: block;
    }

    .table-stack-mobile thead {
        display: none;
    }

    .table-stack-mobile tbody {
        display: block;
    }

    .table-stack-mobile tbody tr {
        display: block;
        padding: 1rem;
        margin-bottom: 0.75rem;
        background: var(--surface);
        border-radius: var(--radius);
        border: 1px solid var(--border);
        box-shadow: var(--shadow-sm);
    }

    .table-stack-mobile tbody tr:hover {
        background: var(--surface);
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }

    .table-stack-mobile tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--border);
        text-align: right;
    }

    .table-stack-mobile tbody td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .table-stack-mobile tbody td:first-child {
        padding-top: 0;
    }

    .table-stack-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.6875rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        text-align: left;
        flex-shrink: 0;
        margin-right: 1rem;
    }

    .table-stack-mobile tbody td .table-actions {
        width: 100%;
        justify-content: center;
        padding-top: 0.5rem;
    }

    /* Status badges on mobile */
    .status-badge {
        padding: 0.25rem 0.5rem;
        font-size: 0.625rem;
    }

    /* DataTables pagination mobile */
    .dataTables_paginate .paginate_button {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .dataTables_paginate .paginate_button.previous,
    .dataTables_paginate .paginate_button.next {
        padding: 0.375rem 0.625rem;
    }
}

/* Very small screens */
@media (max-width: 400px) {
    .dataTables_paginate .paginate_button {
        padding: 0.375rem;
        min-width: 32px;
    }

    /* Hide page numbers, show only prev/next */
    .dataTables_paginate .paginate_button:not(.previous):not(.next):not(.current) {
        display: none;
    }
}

/* ============ DATATABLES RESPONSIVE DETAILS ============ */
/* Styles for responsive column expansion on mobile */
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control {
    position: relative;
    padding-left: 2rem;
    cursor: pointer;
}

table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before,
table.dataTable.dtr-inline.collapsed > tbody > tr > th.dtr-control::before {
    content: '+';
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    transition: all 0.2s ease;
}

table.dataTable.dtr-inline.collapsed > tbody > tr.parent > td.dtr-control::before,
table.dataTable.dtr-inline.collapsed > tbody > tr.parent > th.dtr-control::before {
    content: '-';
    background: var(--danger, #ef4444);
}

/* Responsive details row */
table.dataTable > tbody > tr.child {
    background: var(--background);
}

table.dataTable > tbody > tr.child:hover {
    background: var(--background);
}

table.dataTable > tbody > tr.child ul.dtr-details {
    display: block;
    list-style: none;
    margin: 0;
    padding: 0.75rem 1rem;
}

table.dataTable > tbody > tr.child ul.dtr-details > li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
}

table.dataTable > tbody > tr.child ul.dtr-details > li:last-child {
    border-bottom: none;
}

table.dataTable > tbody > tr.child ul.dtr-details .dtr-title {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

table.dataTable > tbody > tr.child ul.dtr-details .dtr-data {
    text-align: right;
    color: var(--text);
    font-size: 0.8125rem;
}

/* Custom DTR control header styling */
.dt-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0 0.5rem;
}

.dt-search,
.dt-length {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dt-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.5rem;
    border-top: 1px solid var(--border);
}

.dt-info {
    font-size: 0.875rem;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .dt-header,
    .dt-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .dt-search,
    .dt-length {
        width: 100%;
    }

    .dt-search input,
    .dt-length select {
        width: 100%;
    }

    .dt-info,
    .dt-pagination {
        text-align: center;
    }

    /* Responsive details on mobile */
    table.dataTable > tbody > tr.child ul.dtr-details {
        padding: 0.5rem;
    }

    table.dataTable > tbody > tr.child ul.dtr-details > li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    table.dataTable > tbody > tr.child ul.dtr-details .dtr-data {
        text-align: left;
        width: 100%;
    }
}

/* ============ PREMIUM TABLE (Tickets, etc.) ============ */
.table-premium-container {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    overflow: hidden;
}

.table-premium {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.875rem;
}

.table-premium th,
.table-premium td {
    padding: 1rem 1.25rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table-premium th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.6875rem;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border);
}

.table-premium tbody tr {
    transition: all 0.15s ease;
}

.table-premium tbody tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

[data-theme="dark"] .table-premium tbody tr:hover {
    background: rgba(99, 102, 241, 0.08);
}

/* Table hover lift modifier */
.table-hover-lift tbody tr {
    transition: all 0.15s ease;
}

.table-hover-lift tbody tr:hover {
    transform: translateX(3px);
    background: rgba(37, 99, 235, 0.05);
}

/* Table cell title and subtitle */
.table-cell-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.125rem;
    line-height: 1.4;
}

.table-cell-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Mobile responsive for premium tables */
@media (max-width: 768px) {
    .table-premium th,
    .table-premium td {
        padding: 0.75rem 0.875rem;
        font-size: 0.8125rem;
    }

    .table-premium th {
        font-size: 0.625rem;
    }

    .table-hover-lift tbody tr:hover {
        transform: none;
    }
}

/* ============================================
   UI/UX AUDIT FIXES - January 2026
   ============================================ */

/* Issue #14: Products Table - Long Names Wrapping Excessively */
.table td.product-name,
.table td:nth-child(2):not(.table-actions) {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .table td.product-name,
    .table td:nth-child(2):not(.table-actions) {
        max-width: none;
        white-space: normal;
        word-break: break-word;
    }
}

/* Issue #15: Customers Table - Long HWID Breaking Layout */
.hwid-cell,
td[data-label="HWID"],
.table td code,
.table td .monospace {
    max-width: 150px;
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.75rem;
    background: var(--surface-secondary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-xs, 0.25rem);
}

/* Issue #16: Tables - Missing Responsive Indicators (Scroll Hint) */
.table-scroll-wrapper {
    position: relative;
}

.table-scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to left, var(--surface), transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 5;
}

.table-scroll-wrapper.has-scroll::after {
    opacity: 1;
}

/* Visual scroll indicator for tables */
.table-container.scrollable::after {
    content: '';
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
    width: 6px;
    height: 40px;
    background: var(--border);
    border-radius: 3px;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 20;
}

.table-container.scrollable:hover::after {
    opacity: 0.5;
}

/* ============ PRINT STYLES ============ */
@media print {
    .table-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }

    .table-container::before {
        display: none;
    }

    .table-actions,
    .dataTables_filter,
    .dataTables_length,
    .dataTables_paginate {
        display: none !important;
    }

    .table th,
    .table td {
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .table tbody tr:hover {
        background: none;
    }
}
