/* =========================================================
   USER APP — TABLES
   File: user_app/assets/css/tables.css
   Purpose: Shared table styles for the complete User App
   ========================================================= */


/* =========================================================
   1. TABLE WRAPPER
   ========================================================= */

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    border: 1px solid var(--color-border, #e5e7eb);
    border-radius: var(--radius-lg, 10px);
    background: var(--color-surface, #ffffff);
}

.table-wrapper > table {
    margin: 0;
}


/* =========================================================
   2. BASE TABLE
   ========================================================= */

.table {
    width: 100%;
    min-width: 680px;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--color-text, #111827);
    background: var(--color-surface, #ffffff);
    font-size: var(--font-size-sm, 14px);
    line-height: 1.5;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--color-border, #e5e7eb);
}

.table th {
    font-weight: 600;
    color: var(--color-text-secondary, #4b5563);
    background: var(--color-surface-secondary, #f9fafb);
    white-space: nowrap;
}

.table td {
    color: var(--color-text, #111827);
    background: var(--color-surface, #ffffff);
}

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


/* =========================================================
   3. TABLE CAPTION
   ========================================================= */

.table caption {
    padding: 12px 16px;
    color: var(--color-text-secondary, #6b7280);
    font-size: var(--font-size-sm, 14px);
    text-align: left;
    caption-side: bottom;
}


/* =========================================================
   4. TABLE HEADER
   ========================================================= */

.table thead th {
    position: relative;
    z-index: 1;
}

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

.table thead tr:first-child th:last-child {
    border-top-right-radius: var(--radius-lg, 10px);
}


/* =========================================================
   5. HOVER TABLE
   ========================================================= */

.table-hover tbody tr {
    transition:
        background-color 0.15s ease,
        box-shadow 0.15s ease;
}

.table-hover tbody tr:hover td {
    background: var(--color-surface-hover, #f8fafc);
}


/* =========================================================
   6. STRIPED TABLE
   ========================================================= */

.table-striped tbody tr:nth-child(even) td {
    background: var(--color-surface-secondary, #f9fafb);
}

.table-striped.table-hover tbody tr:hover td {
    background: var(--color-surface-hover, #f3f4f6);
}


/* =========================================================
   7. BORDERED TABLE
   ========================================================= */

.table-bordered {
    border: 1px solid var(--color-border, #e5e7eb);
}

.table-bordered th,
.table-bordered td {
    border-right: 1px solid var(--color-border, #e5e7eb);
}

.table-bordered th:last-child,
.table-bordered td:last-child {
    border-right: 0;
}


/* =========================================================
   8. COMPACT TABLE
   ========================================================= */

.table-compact th,
.table-compact td {
    padding: 8px 12px;
    font-size: var(--font-size-xs, 13px);
}


/* =========================================================
   9. LARGE TABLE
   ========================================================= */

.table-lg th,
.table-lg td {
    padding: 16px 20px;
}


/* =========================================================
   10. ALIGNMENT
   ========================================================= */

.table .text-left {
    text-align: left;
}

.table .text-center {
    text-align: center;
}

.table .text-right {
    text-align: right;
}

.table .align-top {
    vertical-align: top;
}

.table .align-middle {
    vertical-align: middle;
}

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


/* =========================================================
   11. COLUMN HELPERS
   ========================================================= */

.table .col-checkbox {
    width: 48px;
    min-width: 48px;
    text-align: center;
}

.table .col-id {
    width: 80px;
    white-space: nowrap;
}

.table .col-status {
    width: 120px;
    white-space: nowrap;
}

.table .col-actions {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.table .col-date {
    width: 140px;
    white-space: nowrap;
}

.table .col-number {
    text-align: right;
    white-space: nowrap;
}


/* =========================================================
   12. CHECKBOX / SELECT COLUMN
   ========================================================= */

.table th.checkbox-cell,
.table td.checkbox-cell {
    width: 48px;
    min-width: 48px;
    padding-left: 12px;
    padding-right: 12px;
    text-align: center;
}

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


/* =========================================================
   13. TABLE ACTIONS
   ========================================================= */

.table-actions {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    white-space: nowrap;
}

.table-actions .btn {
    flex-shrink: 0;
}


/* =========================================================
   14. TABLE ACTION BUTTON
   ========================================================= */

.table-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md, 8px);
    background: transparent;
    color: var(--color-text-secondary, #6b7280);
    cursor: pointer;
    transition:
        background-color 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease;
}

.table-action:hover {
    background: var(--color-surface-hover, #f3f4f6);
    color: var(--color-text, #111827);
}

.table-action:focus-visible {
    outline: 2px solid var(--color-primary, #2563eb);
    outline-offset: 2px;
}

.table-action:disabled,
.table-action[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}


/* =========================================================
   15. TABLE ACTION VARIANTS
   ========================================================= */

.table-action-primary:hover {
    color: var(--color-primary, #2563eb);
}

.table-action-success:hover {
    color: var(--color-success, #16a34a);
}

.table-action-danger:hover {
    color: var(--color-danger, #dc2626);
}

.table-action-warning:hover {
    color: var(--color-warning, #d97706);
}


/* =========================================================
   16. SORTABLE TABLE
   ========================================================= */

.table-sortable th[data-sort] {
    cursor: pointer;
    user-select: none;
}

.table-sortable th[data-sort]:hover {
    background: var(--color-surface-hover, #f3f4f6);
}

.table-sortable th[data-sort]::after {
    content: "↕";
    display: inline-block;
    margin-left: 6px;
    color: var(--color-text-muted, #9ca3af);
    font-size: 12px;
    opacity: 0.8;
}

.table-sortable th[data-sort="asc"]::after {
    content: "↑";
    color: var(--color-primary, #2563eb);
}

.table-sortable th[data-sort="desc"]::after {
    content: "↓";
    color: var(--color-primary, #2563eb);
}


/* =========================================================
   17. TABLE STATUS
   ========================================================= */

.table-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
}

.table-status-active,
.table-status-success,
.table-status-completed {
    background: var(--color-success-light, #dcfce7);
    color: var(--color-success-dark, #166534);
}

.table-status-pending,
.table-status-warning {
    background: var(--color-warning-light, #fef3c7);
    color: var(--color-warning-dark, #92400e);
}

.table-status-danger,
.table-status-failed,
.table-status-rejected {
    background: var(--color-danger-light, #fee2e2);
    color: var(--color-danger-dark, #991b1b);
}

.table-status-info {
    background: var(--color-info-light, #dbeafe);
    color: var(--color-info-dark, #1e40af);
}

.table-status-inactive,
.table-status-disabled {
    background: var(--color-muted-light, #f3f4f6);
    color: var(--color-muted-dark, #4b5563);
}


/* =========================================================
   18. TABLE USER / PROFILE CELL
   ========================================================= */

.table-user {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.table-user-avatar {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    overflow: hidden;
    border-radius: 50%;
    background: var(--color-surface-secondary, #f3f4f6);
}

.table-user-avatar img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.table-user-info {
    min-width: 0;
}

.table-user-name {
    display: block;
    overflow: hidden;
    color: var(--color-text, #111827);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-user-meta {
    display: block;
    overflow: hidden;
    margin-top: 2px;
    color: var(--color-text-muted, #6b7280);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* =========================================================
   19. TABLE LINK
   ========================================================= */

.table-link {
    color: var(--color-primary, #2563eb);
    font-weight: 500;
    text-decoration: none;
}

.table-link:hover {
    color: var(--color-primary-hover, #1d4ed8);
    text-decoration: underline;
}

.table-link:focus-visible {
    outline: 2px solid var(--color-primary, #2563eb);
    outline-offset: 2px;
    border-radius: 3px;
}


/* =========================================================
   20. TABLE MUTED CONTENT
   ========================================================= */

.table-muted {
    color: var(--color-text-muted, #6b7280) !important;
}

.table-empty-value {
    color: var(--color-text-muted, #9ca3af);
    font-style: italic;
}


/* =========================================================
   21. TABLE FOOTER
   ========================================================= */

.table tfoot th,
.table tfoot td {
    padding: 12px 16px;
    border-top: 1px solid var(--color-border, #e5e7eb);
    border-bottom: 0;
    background: var(--color-surface-secondary, #f9fafb);
    font-weight: 600;
}


/* =========================================================
   22. TABLE TOOLBAR
   ========================================================= */

.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.table-toolbar-left,
.table-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.table-toolbar-title {
    margin: 0;
    color: var(--color-text, #111827);
    font-size: 16px;
    font-weight: 600;
}


/* =========================================================
   23. TABLE PAGINATION
   ========================================================= */

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border, #e5e7eb);
    background: var(--color-surface, #ffffff);
    flex-wrap: wrap;
}

.table-pagination-info {
    color: var(--color-text-secondary, #6b7280);
    font-size: 13px;
}

.table-pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}


/* =========================================================
   24. TABLE LOADING STATE
   ========================================================= */

.table-loading {
    position: relative;
    min-height: 160px;
}

.table-loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(
            90deg,
            transparent,
            rgba(255, 255, 255, 0.65),
            transparent
        );
    animation: table-loading-shimmer 1.4s infinite;
    pointer-events: none;
}

.table-loading-row td {
    color: transparent;
}

.table-loading-cell {
    height: 16px;
    border-radius: 4px;
    background: var(--color-surface-secondary, #f3f4f6);
    animation: table-pulse 1.4s ease-in-out infinite;
}

@keyframes table-loading-shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(100%);
    }
}

@keyframes table-pulse {
    0%,
    100% {
        opacity: 0.55;
    }

    50% {
        opacity: 1;
    }
}


/* =========================================================
   25. TABLE EMPTY STATE
   ========================================================= */

.table-empty {
    padding: 40px 20px !important;
    text-align: center !important;
    color: var(--color-text-secondary, #6b7280) !important;
}

.table-empty-title {
    margin-bottom: 4px;
    color: var(--color-text, #111827);
    font-size: 15px;
    font-weight: 600;
}

.table-empty-text {
    color: var(--color-text-muted, #6b7280);
    font-size: 13px;
}


/* =========================================================
   26. TABLE ERROR STATE
   ========================================================= */

.table-error {
    padding: 32px 20px !important;
    text-align: center !important;
    color: var(--color-danger, #dc2626) !important;
}

.table-error-title {
    margin-bottom: 4px;
    font-weight: 600;
}

.table-error-text {
    color: var(--color-text-secondary, #6b7280);
    font-size: 13px;
}


/* =========================================================
   27. RESPONSIVE TABLE — CARD MODE
   ========================================================= */

.table-responsive-card {
    width: 100%;
}

.table-responsive-card table {
    width: 100%;
}


/* =========================================================
   28. STICKY HEADER
   ========================================================= */

.table-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--color-surface-secondary, #f9fafb);
}


/* =========================================================
   29. STICKY FIRST COLUMN
   ========================================================= */

.table-sticky-first th:first-child,
.table-sticky-first td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--color-surface, #ffffff);
}

.table-sticky-first thead th:first-child {
    z-index: 6;
    background: var(--color-surface-secondary, #f9fafb);
}


/* =========================================================
   30. STICKY ACTION COLUMN
   ========================================================= */

.table-sticky-actions th:last-child,
.table-sticky-actions td:last-child {
    position: sticky;
    right: 0;
    z-index: 2;
    background: var(--color-surface, #ffffff);
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.04);
}

.table-sticky-actions thead th:last-child {
    z-index: 6;
    background: var(--color-surface-secondary, #f9fafb);
}


/* =========================================================
   31. ROW STATES
   ========================================================= */

.table tbody tr.is-selected td {
    background: var(--color-primary-light, #eff6ff);
}

.table tbody tr.is-disabled {
    opacity: 0.55;
}

.table tbody tr.is-disabled td {
    cursor: not-allowed;
}

.table tbody tr.is-danger td {
    background: var(--color-danger-light, #fef2f2);
}

.table tbody tr.is-warning td {
    background: var(--color-warning-light, #fffbeb);
}

.table tbody tr.is-success td {
    background: var(--color-success-light, #f0fdf4);
}


/* =========================================================
   32. TABLE DENSITY
   ========================================================= */

.table-dense th,
.table-dense td {
    padding: 6px 10px;
}

.table-spacious th,
.table-spacious td {
    padding: 18px 20px;
}


/* =========================================================
   33. NO WRAP
   ========================================================= */

.table-nowrap th,
.table-nowrap td {
    white-space: nowrap;
}


/* =========================================================
   34. TEXT TRUNCATION
   ========================================================= */

.table-truncate {
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* =========================================================
   35. TABLE DESCRIPTION
   ========================================================= */

.table-description {
    max-width: 420px;
    color: var(--color-text-secondary, #4b5563);
    line-height: 1.45;
}


/* =========================================================
   36. TABLE ICON
   ========================================================= */

.table-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md, 8px);
    background: var(--color-surface-secondary, #f3f4f6);
    color: var(--color-text-secondary, #6b7280);
}


/* =========================================================
   37. TABLE MOBILE
   ========================================================= */

@media (max-width: 768px) {

    .table-wrapper {
        border-radius: var(--radius-md, 8px);
    }

    .table {
        min-width: 620px;
        font-size: 13px;
    }

    .table th,
    .table td {
        padding: 10px 12px;
    }

    .table-toolbar {
        align-items: stretch;
    }

    .table-toolbar-left,
    .table-toolbar-right {
        width: 100%;
    }

    .table-toolbar-right {
        justify-content: flex-start;
    }

    .table-pagination {
        align-items: flex-start;
        flex-direction: column;
    }

    .table-user {
        min-width: 160px;
    }

    .table-user-avatar {
        width: 34px;
        height: 34px;
    }
}


/* =========================================================
   38. VERY SMALL DEVICES
   ========================================================= */

@media (max-width: 480px) {

    .table {
        min-width: 560px;
    }

    .table th,
    .table td {
        padding: 8px 10px;
    }

    .table-action {
        width: 32px;
        height: 32px;
    }

    .table-pagination {
        padding: 10px 12px;
    }
}


/* =========================================================
   39. REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

    .table-hover tbody tr,
    .table-action {
        transition: none;
    }

    .table-loading::after,
    .table-loading-cell {
        animation: none;
    }
}


/* =========================================================
   40. PRINT
   ========================================================= */

@media print {

    .table-wrapper {
        overflow: visible;
        border: 0;
        box-shadow: none;
    }

    .table {
        min-width: 0;
        width: 100%;
        color: #000;
        background: #fff;
    }

    .table th,
    .table td {
        border-color: #999;
        background: #fff !important;
        color: #000 !important;
    }

    .table-actions,
    .table-pagination,
    .table-toolbar {
        display: none !important;
    }

    .table-sticky-header thead th,
    .table-sticky-first th:first-child,
    .table-sticky-first td:first-child,
    .table-sticky-actions th:last-child,
    .table-sticky-actions td:last-child {
        position: static;
        box-shadow: none;
    }
}