/* ==========================================================================
   Admin Tables — KundividiCMS
   Design system table overrides for IndexAdmin views
   ========================================================================== */

/* --- Table Container --- */
.admin-table-wrapper {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius-lg);
    overflow: hidden;
}

/* --- Search & Filter Bar --- */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--admin-border);
    flex-wrap: wrap;
}

.table-toolbar .search-input {
    flex: 1;
    min-width: 200px;
    max-width: 360px;
}

.table-toolbar .filter-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* --- Base Table --- */
.table-admin {
    margin-bottom: 0;
    font-size: 0.875rem;
    color: var(--admin-text);
}

.table-admin thead th {
    background: var(--admin-bg);
    color: var(--admin-text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--admin-border);
    border-top: none;
    white-space: nowrap;
    user-select: none;
}

.table-admin thead th.sortable {
    cursor: pointer;
    transition: color 0.15s ease;
}

.table-admin thead th.sortable:hover {
    color: var(--admin-primary);
}

.table-admin thead th.sortable::after {
    content: '\2195';
    margin-left: 0.35rem;
    opacity: 0.3;
    font-size: 0.7rem;
}

.table-admin thead th.sort-asc::after {
    content: '\2191';
    opacity: 0.8;
    color: var(--admin-primary);
}

.table-admin thead th.sort-desc::after {
    content: '\2193';
    opacity: 0.8;
    color: var(--admin-primary);
}

.table-admin tbody td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--admin-border-light, #f1f5f9);
}

.table-admin tbody tr {
    transition: background-color 0.15s ease;
}

.table-admin tbody tr:hover {
    background-color: var(--admin-primary-light);
}

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

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

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

/* --- Bulk Action Toolbar --- */
.bulk-action-bar {
    display: none;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    background: var(--admin-primary-light);
    border-bottom: 1px solid var(--admin-primary);
    font-size: 0.875rem;
    color: var(--admin-primary);
    font-weight: 500;
    animation: slideDown 0.2s ease;
}

.bulk-action-bar.show {
    display: flex;
}

.bulk-action-bar .selected-count {
    font-weight: 600;
}

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

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

/* --- Action Buttons in Rows --- */
.table-admin .action-cell {
    white-space: nowrap;
    text-align: right;
    width: 1%;
}

.table-admin .btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--admin-text-muted);
    border-radius: var(--admin-radius);
    transition: all 0.15s ease;
    cursor: pointer;
}

.table-admin .btn-action:hover {
    background: var(--admin-bg);
    color: var(--admin-primary);
}

.table-admin .btn-action.btn-action-danger:hover {
    background: rgba(239, 68, 68, 0.08);
    color: var(--admin-danger, #ef4444);
}

/* --- Inline Edit --- */
.table-admin .inline-edit-cell {
    position: relative;
}

.table-admin .inline-edit-cell .cell-display {
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--admin-radius);
    transition: background-color 0.15s ease;
}

.table-admin .inline-edit-cell .cell-display:hover {
    background: var(--admin-primary-light);
}

.table-admin .inline-edit-cell .cell-edit {
    display: none;
}

.table-admin .inline-edit-cell.editing .cell-display {
    display: none;
}

.table-admin .inline-edit-cell.editing .cell-edit {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.table-admin .inline-edit-cell .cell-edit input {
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--admin-primary);
    border-radius: var(--admin-radius);
    outline: none;
    box-shadow: 0 0 0 3px var(--admin-primary-light);
}

/* --- Status Badges in Tables --- */
.table-admin .badge-status {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 9999px;
    letter-spacing: 0.01em;
}

.badge-status-active {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.badge-status-inactive {
    background: rgba(107, 114, 128, 0.1);
    color: #6b7280;
}

.badge-status-pending {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
}

.badge-status-error {
    background: rgba(239, 68, 68, 0.1);
    color: #dc2626;
}

/* --- Empty State --- */
.table-empty {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--admin-text-muted);
}

.table-empty i {
    font-size: 2.5rem;
    opacity: 0.3;
    margin-bottom: 0.75rem;
    display: block;
}

.table-empty p {
    margin: 0;
    font-size: 0.9375rem;
}

/* --- Pagination Override --- */
.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--admin-border);
    font-size: 0.8125rem;
    color: var(--admin-text-muted);
}

.table-pagination .page-info {
    font-weight: 500;
}

/* --- Responsive: Card View for Mobile --- */
@media (max-width: 768px) {
    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .table-toolbar .search-input {
        max-width: 100%;
    }

    .admin-table-wrapper.responsive-cards .table-admin thead {
        display: none;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody tr {
        display: block;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--admin-border);
        position: relative;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.375rem 0;
        border-bottom: none;
        font-size: 0.8125rem;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--admin-text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        margin-right: 1rem;
        flex-shrink: 0;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td.action-cell {
        justify-content: flex-end;
        padding-top: 0.5rem;
        margin-top: 0.25rem;
        border-top: 1px solid var(--admin-border-light, #f1f5f9);
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td.action-cell::before {
        display: none;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td.row-checkbox {
        position: absolute;
        top: 0.75rem;
        right: 1rem;
    }

    .admin-table-wrapper.responsive-cards .table-admin tbody td.row-checkbox::before {
        display: none;
    }
}
