/* Table Styles */

.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    /* Prevent table from forcing container to overflow */
    max-width: 100%;
    table-layout: auto;
}

.table th,
.table td {
    padding: 0.75rem;
    border-bottom: 1px solid #ddd;
}

.table th {
    background: #f8f9fa;
    font-weight: var(--font-weight-semibold);
    color: #555;
    text-align: left;
    /* Sticky positioning for headers - works for vertical scrolling */
    position: sticky;
    top: 0;
    z-index: 10;
}


.table td {
    text-align: left;
}

.table tr:hover {
    background: #f8f9fa;
}

.table tr.error-row {
    background: #fde8e8;
}

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

/* Table sorting buttons */
.table th button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: var(--font-size-sm);
    margin-left: 0.25rem;
    padding: 0.125rem 0.25rem;
    border-radius: 2px;
    transition: background-color 0.2s;
    color: #667eea;
    font-weight: var(--font-weight-bold);
}

.table th button:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Table responsive wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Make all table containers scrollable on all screen sizes */
[id*="-table-container"],
[id*="-standings-container"],
[id^="team-scores-"],
.team-scores-section,
#venue-gaps-container,
.table-responsive {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
    scrollbar-width: thin;
}

/* Scrollbar styling for webkit browsers on all screen sizes */
[id*="-table-container"]::-webkit-scrollbar,
[id*="-standings-container"]::-webkit-scrollbar,
[id^="team-scores-"]::-webkit-scrollbar,
.team-scores-section::-webkit-scrollbar,
#venue-gaps-container::-webkit-scrollbar,
.table-responsive::-webkit-scrollbar {
    height: 8px;
}

[id*="-table-container"]::-webkit-scrollbar-track,
[id*="-standings-container"]::-webkit-scrollbar-track,
[id^="team-scores-"]::-webkit-scrollbar-track,
.team-scores-section::-webkit-scrollbar-track,
#venue-gaps-container::-webkit-scrollbar-track,
.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

[id*="-table-container"]::-webkit-scrollbar-thumb,
[id*="-standings-container"]::-webkit-scrollbar-thumb,
[id^="team-scores-"]::-webkit-scrollbar-thumb,
.team-scores-section::-webkit-scrollbar-thumb,
#venue-gaps-container::-webkit-scrollbar-thumb,
.table-responsive::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 10px;
}

[id*="-table-container"]::-webkit-scrollbar-thumb:hover,
[id*="-standings-container"]::-webkit-scrollbar-thumb:hover,
[id^="team-scores-"]::-webkit-scrollbar-thumb:hover,
.team-scores-section::-webkit-scrollbar-thumb:hover,
#venue-gaps-container::-webkit-scrollbar-thumb:hover,
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* On small viewports, add additional styling */
@media (max-width: 768px) {

    /* Make table containers scrollable - use a more general approach */
    [id*="-table-container"],
    [id*="-standings-container"],
    [id^="team-scores-"],
    .team-scores-section,
    #venue-gaps-container,
    .table-responsive {
        scrollbar-width: thin;
    }

    /* Ensure tables maintain minimum width to enable scrolling */
    [id*="-table-container"] .table,
    [id*="-standings-container"] .table,
    [id^="team-scores-"] .table,
    .team-scores-section .table,
    #venue-gaps-container .table,
    .table-responsive .table {
        min-width: 600px;
        display: table;
        border-collapse: separate;
        border-spacing: 0;
        overflow: visible !important;
        /* CRITICAL for sticky */
        border-radius: 0;
    }

    /* Restore borders with separate model */
    [id*="-table-container"] .table th,
    [id*="-standings-container"] .table th,
    [id^="team-scores-"] .table th,
    .team-scores-section .table th,
    #venue-gaps-container .table th,
    .table-responsive .table th,
    [id*="-table-container"] .table td,
    [id*="-standings-container"] .table td,
    [id^="team-scores-"] .table td,
    .team-scores-section .table td,
    #venue-gaps-container .table td,
    .table-responsive .table td {
        border-bottom: 1px solid #ddd;
    }

    [id*="-table-container"] .table th:not(:last-child),
    [id*="-standings-container"] .table th:not(:last-child),
    [id^="team-scores-"] .table th:not(:last-child),
    .team-scores-section .table th:not(:last-child),
    #venue-gaps-container .table th:not(:last-child),
    .table-responsive .table th:not(:last-child) {
        border-right: 1px solid #ddd;
    }

    [id*="-table-container"] .table td:not(:last-child),
    [id*="-standings-container"] .table td:not(:last-child),
    [id^="team-scores-"] .table td:not(:last-child),
    .team-scores-section .table td:not(:last-child),
    #venue-gaps-container .table td:not(:last-child),
    .table-responsive .table td:not(:last-child) {
        border-right: 1px solid #ddd;
    }

    /* CRITICAL: Make header row sticky - override base styles with higher specificity */
    [id*="-table-container"] .table thead th,
    [id*="-standings-container"] .table thead th,
    [id^="team-scores-"] .table thead th,
    .team-scores-section .table thead th,
    #venue-gaps-container .table thead th,
    .table-responsive .table thead th {
        position: -webkit-sticky !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        background: #f8f9fa !important;
        background-color: #f8f9fa !important;
        box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1) !important;
        white-space: nowrap;
    }

    /* Ensure thead and tr also have background for full coverage */
    [id*="-table-container"] .table thead,
    [id*="-standings-container"] .table thead,
    [id^="team-scores-"] .table thead,
    .team-scores-section .table thead,
    #venue-gaps-container .table thead,
    .table-responsive .table thead {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 999;
        display: table-header-group;
    }

    [id*="-table-container"] .table thead tr,
    [id*="-standings-container"] .table thead tr,
    [id^="team-scores-"] .table thead tr,
    .team-scores-section .table thead tr,
    #venue-gaps-container .table thead tr,
    .table-responsive .table thead tr {
        background: #f8f9fa !important;
        background-color: #f8f9fa !important;
    }

    /* Sticky Action Column */
    .table th.table-actions,
    .table td.table-actions {
        position: -webkit-sticky !important;
        position: sticky !important;
        right: 0 !important;
        background-clip: padding-box;
        /* Fix for borders in sticky cells */
    }

    .table td.table-actions {
        z-index: 10 !important;
        /* Above scrollable content */
        background-color: #fff !important;
        box-shadow: -4px 0 6px -2px rgba(0, 0, 0, 0.15) !important;
    }

    .table tr:hover td.table-actions {
        background-color: #f8f9fa !important;
        /* Match row hover */
    }

    .table th.table-actions {
        z-index: 2000 !important;
        /* Above scrolling headers */
        background-color: #f8f9fa !important;
        box-shadow: -4px 0 6px -2px rgba(0, 0, 0, 0.15) !important;
    }
}

/* Table striped rows */
.table-striped tbody tr:nth-of-type(odd) {
    background-color: rgba(0, 0, 0, 0.02);
}

.table-striped tbody tr:hover {
    background-color: #f8f9fa;
}

/* Table bordered */
.table-bordered {
    border: 1px solid #dee2e6;
}

.table-bordered th,
.table-bordered td {
    border: 1px solid #dee2e6;
}

/* Table condensed */
.table-condensed th,
.table-condensed td {
    padding: 0.5rem;
}

/* Table with fixed header */
.table-fixed-header {
    position: relative;
}

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

/* Table cell alignment */
.table th.text-center,
.table td.text-center {
    text-align: center;
}

.table th.text-right,
.table td.text-right {
    text-align: right;
}

/* Table cell width utilities */
.table th.w-25,
.table td.w-25 {
    width: 25%;
}

.table th.w-50,
.table td.w-50 {
    width: 50%;
}

.table th.w-75,
.table td.w-75 {
    width: 75%;
}

.table th.w-100,
.table td.w-100 {
    width: 100%;
}

/* Table actions column */
.table-actions {
    white-space: nowrap;
    width: 1%;
}

.table-actions .btn {
    margin-right: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: var(--font-size-sm);
}

.table-actions .btn:last-child {
    margin-right: 0;
}

/* Icon buttons for table actions */
.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.375rem;
    margin-right: 0.25rem;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    color: #6c757d;
}

.icon-btn:hover {
    background-color: #f8f9fa;
    transform: scale(1.05);
    color: #495057;
}

.icon-btn.danger {
    color: #dc3545;
}

.icon-btn.danger:hover {
    background-color: #f8d7da;
    color: #721c24;
}

/* Lucide icon styling */
.icon-btn i[data-lucide] {
    width: 16px;
    height: 16px;
    stroke-width: 1.5;
}

.icon-btn:last-child {
    margin-right: 0;
}

/* Table status indicators */
.table-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
}

.table-status.active {
    background-color: #28a745;
}

.table-status.inactive {
    background-color: #6c757d;
}

.table-status.pending {
    background-color: #ffc107;
}

.table-status.error {
    background-color: #dc3545;
}

/* Table with icons */
.table-icon {
    margin-right: 0.5rem;
    font-size: 1.1em;
}

/* Table row selection */
.table tbody tr.selectable {
    cursor: pointer;
    transition: background-color 0.2s;
}

.table tbody tr.selectable:hover {
    background-color: #e3f2fd;
}

.table tbody tr.selected {
    background-color: #bbdefb;
}

.table tbody tr.selected:hover {
    background-color: #90caf9;
}

/* Table empty state */
.table-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
    font-style: italic;
}

.table-empty-icon {
    font-size: var(--font-size-4xl);
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Table loading state */
.table-loading {
    text-align: center;
    padding: 2rem;
    color: #6c757d;
}

.table-loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 0.5rem;
}

/* Table pagination */
.table-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 1rem 0;
}

.table-pagination-info {
    color: #6c757d;
    font-size: var(--font-size-sm);
}

.table-pagination-controls {
    display: flex;
    gap: 0.25rem;
}

.table-pagination-controls button {
    padding: 0.375rem 0.75rem;
    border: 1px solid #dee2e6;
    background: white;
    color: #495057;
    cursor: pointer;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

.table-pagination-controls button:hover:not(:disabled) {
    background: #e9ecef;
    border-color: #adb5bd;
}

/* button:disabled and .active are styled globally in main.css to avoid duplication */

/* Grand Prix counting races - greenish transparent background */
.table td.gp-counting {
    background-color: rgba(40, 167, 69, 0.15) !important;
    font-weight: var(--font-weight-semibold);
}