/**
 * SAW Admin - Table Toolbar (Tabs + Search + Filters)
 * @package SAW_Visitors
 * @version 10.1.0 - FIXED: Toolbar top position changed from 16px to 0
 * 
 * CHANGELOG v10.1.0:
 * - Fixed: Toolbar top: 0 instead of 16px (was causing 16px overlap on first row)
 * - Fixed: Border-radius adjusted for flush top positioning
 */

/* ============================================
   TOOLBAR - CSS STICKY
   ============================================ */
.sa-table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--saw-space-4, 16px);
    padding: 12px var(--saw-space-4, 16px);
    
    /* Pozadí - světle modrý gradient pro záložky */
    background: linear-gradient(180deg, #e0f2fe 0%, #dbeafe 100%) !important;
    
    /* Zaoblení pro hezčí vzhled */
    border-radius: var(--saw-radius-lg, 8px) var(--saw-radius-lg, 8px) 0 0;
    
    /* Jemný spodní okraj */
    border-bottom: 1px solid rgba(59, 130, 246, 0.15);
    
    /* STICKY POSITIONING - top: 0 pro správné zarovnání */
    position: sticky !important;
    top: 0 !important;
    z-index: 100 !important;
    
    /* Prevent shrinking in flex */
    flex-shrink: 0;
    
    /* Min height pro konzistenci */
    min-height: 54px;
}

/* Když je toolbar přilepen nahoře */
.sa-table-toolbar.is-stuck {
    border-radius: var(--saw-radius-md, 6px);
}

/* ============================================
   TABS CONTAINER
   ============================================ */
.sa-table-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}

.sa-table-tabs::-webkit-scrollbar {
    display: none;
}

/* ============================================
   SINGLE TAB
   ============================================ */
.sa-table-tab {
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
    padding: 10px 16px;
    font-size: var(--saw-text-sm, 0.875rem);
    font-weight: var(--saw-font-medium, 500);
    color: var(--saw-text-secondary, #64748b);
    background: transparent;
    border: none;
    border-radius: var(--saw-radius-md, 6px);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--saw-transition-fast, 0.15s);
    text-decoration: none;
}

.sa-table-tab:hover {
    background: var(--saw-bg-tertiary, #f1f5f9);
    color: var(--saw-text-primary, #0f172a);
}

.sa-table-tab--active {
    background: var(--saw-brand-50, #eff6ff);
    color: var(--saw-brand-700, #1d4ed8);
}

/* Tab components */
.sa-table-tab-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.sa-table-tab-label {
    flex: 1;
    white-space: nowrap;
}

.sa-table-tab-count {
    padding: 2px 8px;
    font-size: 11px;
    font-weight: var(--saw-font-semibold, 600);
    background: var(--saw-bg-secondary, #f1f5f9);
    border-radius: var(--saw-radius-full, 9999px);
    color: var(--saw-text-secondary, #64748b);
}

.sa-table-tab--active .sa-table-tab-count {
    background: var(--saw-brand-100, #dbeafe);
    color: var(--saw-brand-700, #1d4ed8);
}

/* ============================================
   SEARCH CONTAINER
   ============================================ */
.sa-table-search {
    flex-shrink: 0;
    min-width: 200px;
    max-width: 300px;
}

/* ============================================
   SEARCH FORM
   ============================================ */
.sa-table-search-form {
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
    background: var(--saw-bg-secondary, #f1f5f9);
    border: 1px solid var(--saw-border-color, #e2e8f0);
    border-radius: var(--saw-radius-lg, 8px);
    padding: 4px 4px 4px 12px;
    transition: all var(--saw-transition-fast, 0.15s);
}

.sa-table-search-form:focus-within {
    background: #ffffff;
    border-color: var(--saw-brand-500, #3b82f6);
    box-shadow: 0 0 0 3px var(--saw-brand-50, rgba(59, 130, 246, 0.1));
}

.sa-table-search-input {
    flex: 1;
    min-width: 0;
    padding: 6px 0;
    font-size: var(--saw-text-sm, 0.875rem);
    color: var(--saw-text-primary, #0f172a);
    background: transparent;
    border: none;
    outline: none;
}

.sa-table-search-input::placeholder {
    color: var(--saw-text-light, #94a3b8);
}

.sa-table-search-form .sa-btn--icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--saw-brand-600, #2563eb);
    color: #ffffff;
    border: none;
    border-radius: var(--saw-radius-md, 6px);
    cursor: pointer;
    transition: background var(--saw-transition-fast, 0.15s);
}

.sa-table-search-form .sa-btn--icon:hover {
    background: var(--saw-brand-700, #1d4ed8);
}

.sa-table-search-form .sa-btn--icon svg {
    width: 16px;
    height: 16px;
}

/* ============================================
   SEARCH BADGE (active search indicator)
   ============================================ */
.sa-table-search-badge {
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
    padding: 6px 8px 6px 12px;
    background: var(--saw-brand-50, #eff6ff);
    border: 1px solid var(--saw-brand-200, #bfdbfe);
    border-radius: var(--saw-radius-lg, 8px);
    color: var(--saw-brand-700, #1d4ed8);
    font-size: var(--saw-text-sm, 0.875rem);
}

.sa-table-search-badge-text {
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
}

.sa-table-search-badge-text .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    color: var(--saw-brand-500, #3b82f6);
}

.sa-table-search-badge-term {
    font-weight: var(--saw-font-semibold, 600);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sa-table-search-badge-clear,
.sa-table-search-badge-edit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--saw-radius-md, 6px);
    cursor: pointer;
    color: var(--saw-brand-600, #2563eb);
    transition: all var(--saw-transition-fast, 0.15s);
    text-decoration: none;
}

.sa-table-search-badge-clear:hover {
    background: var(--saw-danger-light, #fef2f2);
    color: var(--saw-danger, #ef4444);
}

.sa-table-search-badge-edit:hover {
    background: var(--saw-brand-100, #dbeafe);
    color: var(--saw-brand-700, #1d4ed8);
}

.sa-table-search-badge-clear .dashicons,
.sa-table-search-badge-edit .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

/* ============================================
   FILTERS CONTAINER
   ============================================ */
.sa-table-filters {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
}

/* ============================================
   FILTERS WRAPPER & DROPDOWN
   ============================================ */
.sa-table-filters-wrapper {
    position: relative;
}

.sa-table-filter-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 40px;
    height: 40px;
    padding: 0;
    background: var(--saw-bg-secondary, #f1f5f9);
    border: 1px solid var(--saw-border-color, #e2e8f0);
    border-radius: var(--saw-radius-md, 6px);
    color: var(--saw-text-secondary, #64748b);
    cursor: pointer;
    transition: all var(--saw-transition-fast, 0.15s);
}

.sa-table-filter-btn:hover {
    background: var(--saw-bg-tertiary, #e2e8f0);
    color: var(--saw-text-primary, #0f172a);
}

.sa-table-filter-btn--active {
    background: var(--saw-brand-50, #eff6ff);
    border-color: var(--saw-brand-200, #bfdbfe);
    color: var(--saw-brand-600, #2563eb);
}

.sa-table-filter-btn svg {
    width: 18px;
    height: 18px;
}

.sa-table-filter-btn .sa-badge--count {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: var(--saw-font-semibold, 600);
    line-height: 18px;
    text-align: center;
    background: var(--saw-brand-600, #2563eb);
    color: #ffffff;
    border-radius: 9px;
}

/* Filters Dropdown - HIDDEN by default */
.sa-dropdown--filters {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: var(--saw-z-dropdown, 1000);
    min-width: 280px;
    padding: var(--saw-space-4, 16px);
    background: #ffffff;
    border: 1px solid var(--saw-border-color, #e2e8f0);
    border-radius: var(--saw-radius-lg, 8px);
    box-shadow: var(--saw-shadow-lg, 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1));
    
    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity var(--saw-transition-fast, 0.15s), 
                visibility var(--saw-transition-fast, 0.15s),
                transform var(--saw-transition-fast, 0.15s);
}

/* Show dropdown when open */
.sa-dropdown--filters.sa-dropdown--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sa-table-filters-form {
    display: flex;
    flex-direction: column;
    gap: var(--saw-space-4, 16px);
}

.sa-table-filters-form .sa-form-group {
    display: flex;
    flex-direction: column;
    gap: var(--saw-space-2, 8px);
}

.sa-table-filters-form .sa-form-label {
    font-size: var(--saw-text-sm, 0.875rem);
    font-weight: var(--saw-font-medium, 500);
    color: var(--saw-text-secondary, #64748b);
}

.sa-table-filters-form .sa-select {
    width: 100%;
    padding: 10px 40px 10px 14px;
    font-size: var(--saw-text-sm, 0.875rem);
    color: var(--saw-text-primary, #0f172a);
    background: #ffffff;
    border: 1px solid var(--saw-border-color, #e2e8f0);
    border-radius: var(--saw-radius-md, 6px);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    cursor: pointer;
    transition: border-color var(--saw-transition-fast, 0.15s), 
                box-shadow var(--saw-transition-fast, 0.15s);
}

.sa-table-filters-form .sa-select:focus {
    outline: none;
    border-color: var(--saw-brand-500, #3b82f6);
    box-shadow: 0 0 0 3px var(--saw-brand-50, rgba(59, 130, 246, 0.1));
}

.sa-table-filters-form .sa-select--has-value {
    border-color: var(--saw-brand-300, #93c5fd);
    background-color: var(--saw-brand-50, #eff6ff);
}

.sa-table-filters-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: var(--saw-space-3, 12px);
    border-top: 1px solid var(--saw-border-color, #e2e8f0);
    margin-top: var(--saw-space-2, 8px);
}

.sa-table-filters-actions .sa-btn--ghost {
    padding: 8px 16px;
    font-size: var(--saw-text-sm, 0.875rem);
    color: var(--saw-text-secondary, #64748b);
    background: transparent;
    border: none;
    border-radius: var(--saw-radius-md, 6px);
    cursor: pointer;
    text-decoration: none;
    transition: all var(--saw-transition-fast, 0.15s);
}

.sa-table-filters-actions .sa-btn--ghost:hover {
    background: var(--saw-bg-tertiary, #f1f5f9);
    color: var(--saw-text-primary, #0f172a);
}

/* ============================================
   TOOLBAR ACTIONS (right side)
   ============================================ */
.sa-table-actions {
    display: flex;
    align-items: center;
    gap: var(--saw-space-2, 8px);
    margin-left: auto;
    flex-shrink: 0;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sa-table-toolbar {
        flex-wrap: wrap;
        padding: var(--saw-space-2, 8px) var(--saw-space-3, 12px);
        gap: var(--saw-space-2, 8px);
        min-height: auto;
    }
    
    .sa-table-tabs {
        order: 1;
        width: 100%;
        flex: none;
    }
    
    .sa-table-search {
        order: 2;
        flex: 1;
        min-width: 0;
        max-width: none;
    }
    
    .sa-table-filters {
        order: 3;
    }
    
    .sa-table-actions {
        order: 4;
        margin-left: 0;
    }
    
    .sa-table-tab {
        padding: 8px 12px;
        font-size: var(--saw-text-xs, 0.75rem);
    }
    
    /* Search responsive */
    .sa-table-search-form {
        padding: 3px 3px 3px 10px;
    }
    
    .sa-table-search-input {
        font-size: var(--saw-text-xs, 0.75rem);
    }
    
    .sa-table-search-form .sa-btn--icon {
        width: 28px;
        height: 28px;
    }
    
    .sa-table-search-badge {
        padding: 4px 6px 4px 10px;
        font-size: var(--saw-text-xs, 0.75rem);
    }
    
    .sa-table-search-badge-term {
        max-width: 100px;
    }
    
    /* Filter dropdown responsive */
    .sa-dropdown--filters {
        min-width: 240px;
        right: 0;
        left: auto;
    }
}