/**
 * Table Component - Sistema Prenotazioni RSA
 * Design system compliant tables with responsive behavior
 */

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

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-size-sm);
    color: var(--color-text-primary);
}

/* ==========================================================================
   TABLE HEADER
   ========================================================================== */

.table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.table th {
    padding: var(--spacing-3);
    background: var(--color-bg-tertiary);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: var(--letter-spacing-wide);
    color: var(--color-text-secondary);
    text-align: left;
    border-bottom: 2px solid var(--color-border-medium);
    white-space: nowrap;
}

/* ==========================================================================
   TABLE BODY
   ========================================================================== */

.table td {
    padding: var(--spacing-3);
    border-bottom: 1px solid var(--color-border-light);
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color var(--transition-fast);
}

/* ==========================================================================
   HOVER STATE
   ========================================================================== */

.table--hover tbody tr:hover {
    background: rgba(59, 89, 152, 0.04);
    cursor: pointer;
}

/* ==========================================================================
   STRIPED VARIANT
   ========================================================================== */

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

.table--striped.table--hover tbody tr:nth-child(even):hover {
    background: rgba(59, 89, 152, 0.06);
}

/* ==========================================================================
   COMPACT VARIANT
   ========================================================================== */

.table--compact th,
.table--compact td {
    padding: var(--spacing-2);
}

/* ==========================================================================
   RESPONSIVE WRAPPER
   ========================================================================== */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   MOBILE RESPONSIVE (< 768px)
   ========================================================================== */

@media (max-width: 767px) {
    .table-responsive {
        border: 1px solid var(--color-border-light);
    }

    .table thead {
        display: none;
    }

    .table tbody tr {
        display: block;
        margin-bottom: var(--spacing-4);
        border: 1px solid var(--color-border-light);
        border-radius: var(--radius-md);
        background: var(--color-bg-primary);
        box-shadow: var(--shadow-xs);
    }

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

    .table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--spacing-3);
        border-bottom: 1px solid var(--color-border-light);
        text-align: right;
    }

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

    .table td::before {
        content: attr(data-label);
        font-weight: var(--font-weight-semibold);
        color: var(--color-text-secondary);
        text-transform: uppercase;
        font-size: var(--font-size-xs);
        letter-spacing: var(--letter-spacing-wide);
        flex-shrink: 0;
        margin-right: var(--spacing-3);
    }

    /* Actions column full width on mobile */
    .table td[data-label="Azioni"] {
        flex-direction: column;
        align-items: stretch;
    }

    .table td[data-label="Azioni"]::before {
        margin-bottom: var(--spacing-2);
    }

    .table td[data-label="Azioni"] .btn {
        width: 100%;
    }
}

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

.table-empty {
    text-align: center;
    padding: var(--spacing-8);
    color: var(--color-text-muted);
}

.table-empty i {
    font-size: var(--font-size-3xl);
    margin-bottom: var(--spacing-3);
    opacity: 0.5;
}

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

.table--loading {
    opacity: 0.6;
    pointer-events: none;
}

.table--loading tbody tr {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ==========================================================================
   BADGE INTEGRATION (for status columns)
   ========================================================================== */

.table .badge {
    font-size: var(--font-size-xs);
    padding: var(--spacing-1) var(--spacing-2);
    border-radius: var(--radius-sm);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

.table th[scope="col"] {
    cursor: default;
}

.table tbody tr:focus-within {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* ==========================================================================
   PRINT STYLES
   ========================================================================== */

@media print {
    .table-responsive {
        overflow: visible;
        box-shadow: none;
    }

    .table {
        border: 1px solid #000;
    }

    .table th,
    .table td {
        border: 1px solid #000;
    }

    .table--hover tbody tr:hover {
        background: transparent;
    }
}
