/**
 * SAW Admin - Table Element (<table>, <thead>, <tbody>, <tr>, <td>)
 * @package SAW_Visitors
 * @version 9.1.0 - FIXED: Thead sticky top position
 * 
 * CHANGELOG v9.1.0:
 * - Fixed: Thead top changed from calc(16px + var) to just var(--saw-toolbar-height)
 * - Fixed: scroll-margin-top updated accordingly
 * - Fixed: Removed extra padding-top on first row (no longer needed)
 */

/* ============================================
   TABLE BASE
   ============================================ */
.sa-table-element {
    width: 100%;
    /* Na PC žádný min-width - tabulka je 100% a sloupce poměrové */
    /* Min-width se aplikuje pouze na mobilu v _table-responsive.css */
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
}

@media (min-width: 1025px) {
    .sa-table-element--fixed {
        table-layout: fixed !important;
        width: 100% !important;
    }
}

/* Na mobilu a tabletu vždy auto layout */
@media (max-width: 1024px) {
    .sa-table-element--fixed {
        table-layout: auto !important;
        width: auto !important;
    }
}

/* ============================================
   THEAD - CSS STICKY
   ============================================ */
.sa-table-thead {
    display: table-header-group;
}

.sa-table-thead .sa-table-row,
.sa-table-thead tr {
    display: table-row;
}

/* TH elementy - STICKY pod toolbarem */
.sa-table-thead th,
.sa-table-th {
    display: table-cell;
    
    /* STICKY POSITIONING */
    /* Toolbar je na top: 0, takže thead je pouze výška toolbaru */
    position: sticky !important;
    top: 0 !important;
    z-index: 99 !important;
    
    /* Pozadí - velmi světle modrý pro záhlaví tabulky */
    background: linear-gradient(180deg, #f0f9ff 0%, #e8f4fc 100%) !important;
    
    /* Styling */
    padding: 10px var(--saw-space-4, 16px);
    font-size: var(--saw-text-xs, 0.75rem);
    font-weight: var(--saw-font-semibold, 600);
    text-align: left;
    color: var(--saw-text-secondary, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.3;
    border-bottom: 2px solid rgba(59, 130, 246, 0.2);
    white-space: nowrap;
}

.sa-table-thead th:first-child,
.sa-table-th:first-child {
    border-left: none;
}

.sa-table-thead th:last-child,
.sa-table-th:last-child {
    border-right: none;
}

/* Sortable header styling */
.sa-table-sortable {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: color var(--saw-transition-fast, 0.15s);
}

.sa-table-sortable:hover {
    color: var(--saw-brand-600, #2563eb);
}

.sa-table-sortable svg {
    width: 14px;
    height: 14px;
    opacity: 0.5;
}

.sa-table-sortable.active svg {
    opacity: 1;
    color: var(--saw-brand-600, #2563eb);
}

/* ============================================
   TBODY
   ============================================ */
.sa-table-tbody {
    display: table-row-group;
}

.sa-table-tbody .sa-table-row,
.sa-table-tbody tr {
    display: table-row;
    transition: background var(--saw-transition-fast, 0.15s);
    /* Scroll margin pro správnou viditelnost pod sticky header */
    /* Toolbar (67px) + thead (~40px) + malá rezerva */
    scroll-margin-top: calc(var(--saw-toolbar-height, 67px) + 50px);
    /* Bílé pozadí pro normální řádky - zabraňuje prosvítání pozadí .sa-table-split */
    background: #ffffff;
}

/* První řádek - standardní padding (extra padding již není potřeba) */
.sa-table-tbody .sa-table-row:first-child .sa-table-cell,
.sa-table-tbody tr:first-child td {
    padding-top: 12px;
}

.sa-table-tbody .sa-table-row:hover {
    background: var(--saw-bg-secondary, #f8fafc);
}

.sa-table-tbody .sa-table-row td {
    border-bottom: 1px solid var(--saw-border-color, #e2e8f0);
}

/* ============================================
   ROW STATES
   ============================================ */
.sa-table-row--selected {
    background: var(--saw-brand-50, #eff6ff);
}

.sa-table-row--active {
    background: var(--saw-brand-50, #eff6ff) !important;
    border-left: 3px solid var(--saw-brand-600, #2563eb) !important;
}

.sa-table-row--active td {
    background: var(--saw-brand-50, #eff6ff) !important;
}

.sa-table-row--clickable {
    cursor: pointer;
}

/* ============================================
   CELLS
   ============================================ */
.sa-table-cell {
    display: table-cell;
    padding: 12px var(--saw-space-4, 16px);
    font-size: var(--saw-text-sm, 0.875rem);
    color: var(--saw-text-primary, #0f172a);
    vertical-align: middle;
    /* GLOBÁLNÍ ZAROVNÁNÍ DOLEVA - přepíše inline styly z PHP */
    text-align: left !important;
    /* Na PC žádný min-width - sloupce se přizpůsobí poměrově */
}

/* POZOR: Tyto třídy jsou nyní potlačeny globálním text-align: left
   Pokud potřebujete center/right, použijte inline styl s !important */
.sa-table-cell--center {
    text-align: center;
}

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

/* Bold cell variant */
.sa-table-cell-bold,
.saw-table-cell-bold {
    font-weight: var(--saw-font-semibold, 600);
}

/* ============================================
   CELL CONTENT TYPES
   ============================================ */
.sa-table-cell-image-wrapper {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sa-table-cell-image {
    max-width: 40px;
    max-height: 40px;
    border-radius: var(--saw-radius-md, 6px);
    object-fit: cover;
}

.sa-table-cell-image-placeholder {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--saw-bg-tertiary, #f1f5f9);
    border-radius: var(--saw-radius-md, 6px);
    color: var(--saw-text-muted, #94a3b8);
}

/* ============================================
   SORTABLE HEADERS
   ============================================ */
.sa-sort-icon {
    font-size: 0.75rem;
    opacity: 0.5;
}

.sa-sort-icon--active {
    opacity: 1;
    color: var(--saw-brand-600, #2563eb);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sa-table-thead th,
    .sa-table-th {
        /* Mobile: používá mobilní toolbar height proměnnou */
        top: var(--saw-toolbar-height-mobile, var(--saw-toolbar-height, 80px)) !important;
        padding: 8px var(--saw-space-3, 12px);
        font-size: 0.65rem;
    }
    
    /* První řádek na mobilu */
    .sa-table-tbody .sa-table-row:first-child .sa-table-cell,
    .sa-table-tbody tr:first-child td {
        padding-top: 10px;
    }
    
    .sa-table-cell {
        padding: var(--saw-space-2, 8px) var(--saw-space-3, 12px);
        font-size: var(--saw-text-xs, 0.75rem);
    }
    
    .sa-table-cell-image-wrapper,
    .sa-table-cell-image,
    .sa-table-cell-image-placeholder {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 480px) {
    .sa-table-thead th,
    .sa-table-th {
        padding: 6px var(--saw-space-2, 8px);
        font-size: 0.6rem;
    }
    
    .sa-table-cell {
        padding: var(--saw-space-2, 8px);
        font-size: 0.7rem;
    }
    
    .sa-table-cell-image-wrapper,
    .sa-table-cell-image,
    .sa-table-cell-image-placeholder {
        width: 32px;
        height: 32px;
    }
}