/**
 * DATA TABLES - PharmData Design System v2.0
 * Tabelas densas para dados farmacêuticos
 *
 * Padrões para:
 * - Tabelas de listagem (medicamentos, substâncias)
 * - Tabelas de comparação
 * - Tabelas com ações inline
 * - Colunas fixas (sticky)
 * - Ordenação e paginação
 */

/* ===================
   TABLE BASE
   =================== */

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--text-sm);
    background: var(--cloud, #F5F8FA);
    border: 1px solid var(--border-strong, rgba(11, 45, 42, 0.15));
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.table th,
.table td {
    padding: var(--cell-padding-md, var(--space-3) var(--space-4));
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.2));
}

.table th {
    font-weight: 600;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--soft-steel, #374151);
    background: var(--arctic-mist, #E9ECEF);
    white-space: nowrap;
}

.table td {
    color: var(--graphite-depth, #1F2937);
}

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

/* ===================
   TABLE VARIANTS
   =================== */

/* Striped rows */
.table-striped tbody tr:nth-child(even) {
    background: rgba(183, 228, 213, 0.04);
}

/* Hoverable rows */
.table-hover tbody tr {
    transition: background-color var(--transition-fast, 0.15s);
}

.table-hover tbody tr:hover {
    background: rgba(183, 228, 213, 0.08);
}

/* Bordered table */
.table-bordered th,
.table-bordered td {
    border: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.2));
}

/* Compact table */
.table-compact th,
.table-compact td {
    padding: var(--cell-padding-sm, var(--space-2) var(--space-3));
    font-size: var(--text-xs);
}

/* Spacious table */
.table-spacious th,
.table-spacious td {
    padding: var(--cell-padding-lg, var(--space-4) var(--space-6));
}

/* ===================
   STICKY COLUMNS
   =================== */

.table-sticky-first th:first-child,
.table-sticky-first td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background: inherit;
    box-shadow: 2px 0 4px rgba(11, 45, 42, 0.05);
}

.table-sticky-first tbody tr:hover td:first-child {
    background: rgba(183, 228, 213, 0.08);
}

.table-sticky-last th:last-child,
.table-sticky-last td:last-child {
    position: sticky;
    right: 0;
    z-index: 10;
    background: inherit;
    box-shadow: -2px 0 4px rgba(11, 45, 42, 0.05);
}

/* Sticky header */
.table-sticky-header {
    overflow: auto;
    max-height: 70vh;
}

.table-sticky-header thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 0 var(--border-subtle, rgba(183, 228, 213, 0.2));
}

/* ===================
   SORTABLE COLUMNS
   =================== */

.table th[data-sortable] {
    cursor: pointer;
    user-select: none;
    transition: background-color var(--transition-fast, 0.15s);
}

.table th[data-sortable]:hover {
    background: rgba(42, 161, 152, 0.08);
}

.table th[data-sortable]::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: var(--space-2);
    vertical-align: middle;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid var(--soft-steel, #374151);
    opacity: 0.3;
    transition: opacity var(--transition-fast, 0.15s), transform var(--transition-fast, 0.15s);
}

.table th[data-sortable]:hover::after {
    opacity: 0.6;
}

.table th[data-sort="asc"]::after {
    opacity: 1;
    border-top: none;
    border-bottom: 5px solid var(--teal-intense, #2AA198);
}

.table th[data-sort="desc"]::after {
    opacity: 1;
    border-top: 5px solid var(--teal-intense, #2AA198);
}

/* ===================
   SELECTABLE ROWS
   =================== */

.table-selectable tbody tr {
    cursor: pointer;
}

.table-selectable tbody tr.selected {
    background: rgba(42, 161, 152, 0.1);
}

.table-selectable tbody tr.selected td:first-child {
    box-shadow: inset 3px 0 0 var(--teal-intense, #2AA198);
}

/* Checkbox column */
.table .col-checkbox {
    width: 3rem;
    text-align: center;
    padding-left: var(--space-3);
    padding-right: var(--space-2);
}

.table .col-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
}

/* ===================
   ACTION COLUMNS
   =================== */

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

.table .col-actions .btn {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
}

.table .col-actions .btn + .btn {
    margin-left: var(--space-1);
}

/* Action buttons visible on hover */
.table-hover-actions .col-actions {
    opacity: 0;
    transition: opacity var(--transition-fast, 0.15s);
}

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

/* ===================
   CELL CONTENT TYPES
   =================== */

/* Numeric cells */
.table .cell-number {
    font-family: var(--font-mono, 'IBM Plex Mono', monospace);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Date cells */
.table .cell-date {
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

/* Status cells with drops */
.table .cell-status {
    width: 8rem;
}

/* Truncated text with tooltip */
.table .cell-truncate {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Code/ID cells */
.table .cell-code {
    font-family: var(--font-mono, 'IBM Plex Mono', monospace);
    font-size: var(--text-xs);
    color: var(--soft-steel, #374151);
}

/* ===================
   ROW STATES
   =================== */

/* Highlighted row */
.table tbody tr.row-highlight {
    background: rgba(42, 161, 152, 0.05);
}

/* Warning row */
.table tbody tr.row-warning {
    background: rgba(255, 167, 38, 0.08);
}

/* Error row */
.table tbody tr.row-error {
    background: rgba(239, 83, 80, 0.08);
}

/* Success row */
.table tbody tr.row-success {
    background: rgba(76, 175, 80, 0.08);
}

/* Disabled row */
.table tbody tr.row-disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ===================
   PAGINATION
   =================== */

.table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--arctic-mist, #E9ECEF);
    border-top: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.2));
    font-size: var(--text-sm);
}

.table-pagination-info {
    color: var(--soft-steel, #374151);
}

.table-pagination-info strong {
    color: var(--graphite-depth, #1F2937);
}

.table-pagination-controls {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.table-pagination-controls .btn {
    min-width: 2rem;
    height: 2rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.3));
    background: var(--cloud, #F5F8FA);
    color: var(--soft-steel, #374151);
    transition: all var(--transition-fast, 0.15s);
}

.table-pagination-controls .btn:hover:not(:disabled) {
    border-color: var(--teal-intense, #2AA198);
    color: var(--teal-intense, #2AA198);
}

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

.table-pagination-controls .btn.active {
    background: var(--emerald-abyss, #0B2D2A);
    color: white;
    border-color: var(--emerald-abyss, #0B2D2A);
}

/* Per page selector */
.table-per-page {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.table-per-page select {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-sm);
    border: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.3));
    border-radius: var(--radius-md);
    background: var(--cloud, #F5F8FA);
}

/* ===================
   EMPTY STATE
   =================== */

.table-empty {
    padding: var(--space-12) var(--space-6);
    text-align: center;
    color: var(--soft-steel, #374151);
}

.table-empty-icon {
    font-size: var(--icon-3xl, 2.5rem);
    color: var(--mint-signal, #B7E4D5);
    margin-bottom: var(--space-4);
}

.table-empty-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--graphite-depth, #1F2937);
    margin-bottom: var(--space-2);
}

.table-empty-description {
    font-size: var(--text-sm);
    max-width: 320px;
    margin: 0 auto;
}

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

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

/* Fade indicator for horizontal scroll */
.table-responsive::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 40px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.8));
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition-fast, 0.15s);
}

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

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

    .table-stack-mobile tbody tr {
        display: block;
        padding: var(--space-3);
        margin-bottom: var(--space-2);
        border: 1px solid var(--border-subtle, rgba(183, 228, 213, 0.2));
        border-radius: var(--radius-md);
    }

    .table-stack-mobile tbody td {
        display: flex;
        justify-content: space-between;
        padding: var(--space-2) 0;
        border-bottom: 1px dashed var(--border-subtle, rgba(183, 228, 213, 0.15));
    }

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

    .table-stack-mobile tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: var(--text-xs);
        text-transform: uppercase;
        color: var(--soft-steel, #374151);
    }
}

/* ===================
   LOADING STATE
   =================== */

.table-loading {
    position: relative;
}

.table-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 30;
}

.table-loading tbody {
    opacity: 0.5;
}
