/* ==========================================
   Data Table Component Styles
   Reusable table with search, pagination, actions
   ========================================== */

/* ==========================================
   Search Bar
   ========================================== */

.table-search-bar {
    margin-bottom: 20px;
}

.table-search-input {
    width: 100%;
    max-width: 400px;
    padding: 12px 16px;
    font-size: var(--font-size-body, 1rem);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: var(--dark-bg-tertiary);
    color: var(--text-primary);
    transition: var(--transition-smooth);
}

.table-search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(34, 199, 224, 0.1);
}

.table-search-input::placeholder {
    color: var(--text-secondary);
}

/* ==========================================
   Table Wrapper
   ========================================== */

.table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    background: var(--dark-bg-tertiary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-small, 0.875rem);
}

/* ==========================================
   Table Header
   ========================================== */

.data-table thead {
    background: linear-gradient(135deg, rgba(34, 199, 224, 0.1), rgba(77, 240, 255, 0.05));
    border-bottom: 2px solid rgba(34, 199, 224, 0.3);
}

.data-table th {
    padding: 16px 20px;
    text-align: left;
    font-weight: var(--font-weight-semibold, 600);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    /* The column name, not the data. It was --text-primary while the cells below it were
       --text-secondary, so the heading outranked its own contents; a reader scanning a column
       met the label first and the values as a murmur underneath. Grey here and white below is
       the way round it was meant to be. */
    color: var(--text-secondary);
    white-space: nowrap;
}

.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: var(--transition-smooth);
}

.data-table th.sortable:hover {
    background: rgba(34, 199, 224, 0.15);
}

.data-table th.sortable .sort-icon {
    margin-left: 8px;
    opacity: 0.4;
    font-size: 0.75rem;
}

.data-table th.sortable:hover .sort-icon {
    opacity: 1;
}

.data-table th.actions-column {
    text-align: center;
    width: 200px;
}

/* ==========================================
   Table Body
   ========================================== */

.data-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: var(--transition-smooth);
}

.data-table tbody tr:hover {
    background: rgba(34, 199, 224, 0.05);
}

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

.data-table td {
    padding: 16px 20px;
    /* THE rule behind "why is everything grey". Every cell of every table in the portal came
       through here at --text-secondary (#9AA0AA); only cells that set a colour of their own —
       a badge, a type tag, a link — came out legible. Data is what a table is for, so it is
       --text-primary and anything quieter has to say so: .null-value for an absent value, an
       explicit .text-muted for a subordinate second line. */
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table td[data-label] {
    position: relative;
}

/* ==========================================
   Cell Values
   ========================================== */

.null-value {
    color: var(--text-secondary);
    opacity: 0.5;
    font-style: normal;
}

/* Badges are defined once, in portal-common.css — every page that loads table.css
   loads that too. This file used to carry a second, differently-styled .badge and
   the winner was decided by <link> order. */

/* ==========================================
   Action Buttons
   ========================================== */

.actions-cell {
    text-align: center;
}

.actions-cell .action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.action-btn {
    padding: 8px 12px;
    font-size: var(--font-size-small, 0.875rem);
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    background: var(--dark-bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.action-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
    transform: translateY(-2px);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.delete-btn {
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.action-btn.delete-btn:hover {
    background: #ef4444;
    border-color: #ef4444;
    color: white;
}

/* ==========================================
   Loading State
   ========================================== */

.table-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 15px;
    color: var(--text-secondary);
}

.table-loading .loader {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(34, 199, 224, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;   /* @keyframes spin: base.css */
}

/* ==========================================
   Empty State
   ========================================== */

.table-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: var(--font-size-body, 1rem);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: var(--dark-bg-tertiary);
}

/* ==========================================
   Error State
   ========================================== */

.error-cell {
    padding: 40px 20px !important;
    text-align: center;
    color: #ef4444;
}

.error-icon {
    font-size: var(--font-size-h3, 1.5rem);
    margin-right: 8px;
}

/* ==========================================
   Pagination
   ========================================== */

.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    padding: 16px 0;
    flex-wrap: wrap;
    gap: 16px;
}

.pagination-info {
    color: var(--text-secondary);
    font-size: var(--font-size-small, 0.875rem);
}

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

.pagination-page {
    color: var(--text-primary);
    font-weight: 600;
    font-size: var(--font-size-small, 0.875rem);
    min-width: 80px;
    text-align: center;
}

.pagination-btn {
    padding: 10px 18px;
    font-size: var(--font-size-small, 0.875rem);
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    background: var(--dark-bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.pagination-btn:not(:disabled):hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==========================================
   Responsive Design
   ========================================== */

@media (max-width: 968px) {
    .table-wrapper {
        border-radius: 0;
        margin: 0 -20px;
    }

    .data-table {
        font-size: var(--font-size-small, 0.875rem);
    }

    .data-table th,
    .data-table td {
        padding: 12px 16px;
    }

    .actions-cell .action-buttons {
        flex-direction: column;
        gap: 6px;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 640px) {
    /* Stack table for mobile */
    .data-table thead {
        display: none;
    }

    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table tr {
        margin-bottom: 16px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        border-radius: 8px;
        padding: 12px;
        background: var(--dark-bg-secondary);
    }

    .data-table td {
        padding: 8px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        text-align: right;
        display: flex;
        justify-content: space-between;
    }

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

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-primary);
        margin-right: 16px;
        text-align: left;
        flex: 1;
    }

    .data-table td.actions-cell {
        text-align: center;
        display: block;
        padding-top: 12px;
        margin-top: 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .data-table td.actions-cell::before {
        display: none;
    }

    .pagination-controls {
        width: 100%;
        justify-content: space-between;
    }

    .pagination-btn {
        flex: 1;
        max-width: 120px;
    }
}
