/* ============================================
   LineupIQ Tables & Grids
   ============================================ */

/* Slates Table */
.slates-table {
    width: 100%;
    border-collapse: collapse;
    border: none;
}

    .slates-table thead {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--liq-bg-tertiary);
    }

    .slates-table th {
        text-align: left;
        padding: 0.75rem;
        background: var(--liq-bg-tertiary);
        color: var(--liq-text-secondary);
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.03em;
        border: none;
        border-bottom: 1px solid var(--liq-border-color);
    }

    .slates-table td {
        text-align: left;
        padding: 0.75rem;
        color: var(--liq-text-primary);
        border: none;
        border-bottom: 1px solid rgba(128, 128, 128, 0.08);
    }

    .slates-table tbody tr {
        cursor: pointer;
        transition: background 0.15s ease;
    }

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

        .slates-table tbody tr:hover {
            background: var(--liq-accent-green-hover);
        }

        .slates-table tbody tr.slate-selected {
            background: var(--liq-accent-green-active);
            border-left: 3px solid var(--liq-accent-green);
        }

        .slates-table tbody tr.slate-unavailable {
            opacity: 0.5;
            background-color: var(--liq-bg-tertiary);
            cursor: not-allowed;
        }

            .slates-table tbody tr.slate-unavailable:hover {
                background-color: var(--liq-bg-tertiary);
                cursor: not-allowed;
            }

            .slates-table tbody tr.slate-unavailable td {
                color: var(--liq-text-secondary);
            }

/* Site Badge for tables */
.site-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

    .site-badge .site-logo {
        height: 18px;
        width: auto;
        object-fit: contain;
        display: block;
    }

    .site-badge .site-badge-text {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--liq-text-primary);
    }

/* Contest Data Indicator */
.slates-table .contests-col {
    text-align: center;
}

.contest-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

    .contest-indicator.available {
        color: var(--liq-accent-green);
    }

    .contest-indicator.unavailable {
        color: var(--liq-text-secondary);
        opacity: 0.4;
    }

/* AG Grid Theme Overrides */
#playerGrid,
#lineupGrid {
    height: 100%;
    width: 100%;
}

.ag-theme-quartz,
.ag-theme-quartz-dark {
    --ag-background-color: var(--liq-bg-secondary);
    --ag-header-background-color: var(--liq-bg-tertiary);
    --ag-odd-row-background-color: var(--liq-bg-secondary);
    --ag-even-row-background-color: var(--liq-bg-secondary);
    --ag-row-hover-color: var(--liq-bg-hover);
    --ag-selected-row-background-color: transparent;
    --ag-border-color: var(--liq-border-color);
    --ag-header-foreground-color: var(--liq-text-secondary);
    --ag-foreground-color: var(--liq-text-primary);
    --ag-secondary-foreground-color: var(--liq-text-secondary);
    --ag-row-border-color: var(--liq-border-color);
    --ag-cell-horizontal-border: solid var(--liq-border-color);
    --ag-header-column-separator-color: var(--liq-border-color);
    --ag-header-column-separator-display: block;
    --ag-input-focus-border-color: var(--liq-accent-green);
    --ag-range-selection-border-color: transparent;
    --ag-range-selection-background-color: transparent;
    --ag-checkbox-checked-color: var(--liq-accent-green);
    --ag-font-family: inherit;
    --ag-font-size: 14px;
    --ag-grid-size: 6px;
    --ag-list-item-height: 32px;
    --ag-row-height: 42px;
    --ag-header-height: 48px;
    --ag-border-radius: 0;
}

    .ag-theme-quartz .ag-root-wrapper,
    .ag-theme-quartz-dark .ag-root-wrapper {
        border: none;
        border-radius: 0;
    }

    .ag-theme-quartz .ag-center-header .ag-header-cell-label,
    .ag-theme-quartz-dark .ag-center-header .ag-header-cell-label {
        justify-content: center;
    }

    .ag-theme-quartz .ag-header-cell-text,
    .ag-theme-quartz-dark .ag-header-cell-text {
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.8rem;
        letter-spacing: 0.02em;
    }

    .ag-theme-quartz .checkbox-header .ag-header-cell-comp-wrapper,
    .ag-theme-quartz-dark .checkbox-header .ag-header-cell-comp-wrapper {
        justify-content: center;
    }

    .ag-theme-quartz .ag-pinned-left-header,
    .ag-theme-quartz .ag-pinned-left-cols-container,
    .ag-theme-quartz-dark .ag-pinned-left-header,
    .ag-theme-quartz-dark .ag-pinned-left-cols-container {
        box-shadow: 2px 0 4px var(--liq-shadow);
    }

    .ag-theme-quartz .ag-row-selected,
    .ag-theme-quartz-dark .ag-row-selected {
        background-color: var(--liq-bg-secondary);
        opacity: 1;
    }

    /* Dim unselected rows in player grid */
    .ag-theme-quartz .ag-row:not(.ag-row-selected),
    .ag-theme-quartz-dark .ag-row:not(.ag-row-selected) {
        opacity: 0.6;
        background-color: var(--liq-bg-primary);
    }

/* Contest builds: keep player grid rows at full opacity */
.contest-build-workspace #playerGrid .ag-theme-quartz .ag-row,
.contest-build-workspace #playerGrid .ag-theme-quartz-dark .ag-row,
.contest-build-workspace #playerGrid.ag-theme-quartz .ag-row,
.contest-build-workspace #playerGrid.ag-theme-quartz-dark .ag-row {
    opacity: 1;
    background-color: var(--liq-bg-secondary);
}

/* Contest entries view styling */
.contest-entries-view .ag-theme-quartz .ag-row:not(.ag-row-selected),
.contest-entries-view .ag-theme-quartz-dark .ag-row:not(.ag-row-selected) {
    opacity: 1;
    background-color: var(--liq-bg-secondary);
}

/* Lineup grid should show rows at full opacity */
#lineupGrid .ag-theme-quartz .ag-row,
#lineupGrid .ag-theme-quartz-dark .ag-row,
#lineupGrid.ag-theme-quartz .ag-row,
#lineupGrid.ag-theme-quartz-dark .ag-row {
    opacity: 1;
    background-color: var(--liq-bg-secondary);
}

    .ag-theme-quartz .ag-row-hover,
    .ag-theme-quartz-dark .ag-row-hover {
        background-color: var(--liq-bg-hover) !important;
    }

    /* Cell focus */
    .ag-theme-quartz .ag-cell-focus,
    .ag-theme-quartz .ag-cell-focus:focus-within,
    .ag-theme-quartz-dark .ag-cell-focus,
    .ag-theme-quartz-dark .ag-cell-focus:focus-within {
        outline: none !important;
        box-shadow: none !important;
        border: 1px solid transparent !important;
        border-right: 1px solid var(--liq-border-color) !important;
    }

    /* Checkbox focus */
    .ag-theme-quartz .ag-checkbox-input-wrapper:focus-within,
    .ag-theme-quartz .ag-checkbox-input-wrapper:focus,
    .ag-theme-quartz-dark .ag-checkbox-input-wrapper:focus-within,
    .ag-theme-quartz-dark .ag-checkbox-input-wrapper:focus {
        outline: none !important;
        box-shadow: none !important;
    }

    .ag-theme-quartz .ag-checkbox-input:focus,
    .ag-theme-quartz-dark .ag-checkbox-input:focus {
        outline: none !important;
        box-shadow: none !important;
    }

.ag-header-cell-resize {
    opacity: 0;
    transition: opacity 0.2s;
}

.ag-header-cell:hover .ag-header-cell-resize {
    opacity: 1;
}

/* Editable Column Highlights */
.ag-theme-quartz .highlight-fpts.ag-cell {
    background: rgba(0, 0, 0, 0.03);
}

.ag-theme-quartz-dark .highlight-fpts.ag-cell {
    background: rgba(0, 0, 0, 0.25);
}

/* Ownership column highlight */
.ag-theme-quartz .highlight-ownership.ag-cell {
    background: rgba(0, 0, 0, 0.03);
}

.ag-theme-quartz-dark .highlight-ownership.ag-cell {
    background: rgba(0, 0, 0, 0.25);
}

.ag-theme-quartz .highlight-exposure-start.ag-cell,
.ag-theme-quartz .highlight-exposure-end.ag-cell {
    background: rgba(0, 0, 0, 0.03);
}

.ag-theme-quartz-dark .highlight-exposure-start.ag-cell,
.ag-theme-quartz-dark .highlight-exposure-end.ag-cell {
    background: rgba(0, 0, 0, 0.25);
}

/* Remove highlights in contest builds */
.contest-build-workspace .ag-theme-quartz .highlight-fpts.ag-cell,
.contest-build-workspace .ag-theme-quartz .highlight-exposure-start.ag-cell,
.contest-build-workspace .ag-theme-quartz .highlight-exposure-end.ag-cell,
.contest-build-workspace .ag-theme-quartz .highlight-ownership.ag-cell,
.contest-build-workspace .ag-theme-quartz-dark .highlight-fpts.ag-cell,
.contest-build-workspace .ag-theme-quartz-dark .highlight-exposure-start.ag-cell,
.contest-build-workspace .ag-theme-quartz-dark .highlight-exposure-end.ag-cell,
.contest-build-workspace .ag-theme-quartz-dark .highlight-ownership.ag-cell {
    background: transparent;
}

/* AG Grid cell wrapper fix for custom renderers */
.ag-theme-quartz .ag-cell-wrapper,
.ag-theme-quartz-dark .ag-cell-wrapper {
    height: 100%;
    width: 100%;
}

.ag-theme-quartz [col-id="minExposure"] .ag-cell-value,
.ag-theme-quartz [col-id="maxExposure"] .ag-cell-value,
.ag-theme-quartz [col-id="projectedFpts"] .ag-cell-value,
.ag-theme-quartz [col-id="projOwn"] .ag-cell-value,
.ag-theme-quartz-dark [col-id="minExposure"] .ag-cell-value,
.ag-theme-quartz-dark [col-id="maxExposure"] .ag-cell-value,
.ag-theme-quartz-dark [col-id="projectedFpts"] .ag-cell-value,
.ag-theme-quartz-dark [col-id="projOwn"] .ag-cell-value {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0 2px;
}

/* Ownership Header with Dropdown */
.ownership-header-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 2px;
}

.ownership-header-main {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s ease;
}

    .ownership-header-main:hover {
        background-color: var(--liq-bg-hover);
    }

.ownership-header-text {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.02em;
}

.ownership-header-sort-trigger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease;
}

    .ownership-header-sort-trigger:hover {
        background-color: var(--liq-bg-hover);
    }

.ownership-header-caret {
    font-size: 10px;
    opacity: 0.4;
    transition: opacity 0.15s ease;
}

    .ownership-header-caret.sorted {
        opacity: 0.9;
        color: var(--liq-accent-green);
    }

.ownership-header-sort-trigger:hover .ownership-header-caret {
    opacity: 0.8;
}

/* Dropdown */
.ownership-header-dropdown {
    position: fixed;
    min-width: 180px;
    background: var(--liq-bg-secondary);
    border: 1px solid var(--liq-border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: none;
    overflow: hidden;
}

.ownership-header-container.open .ownership-header-dropdown {
    display: block;
}

.ownership-dropdown-item {
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    cursor: pointer;
    transition: background 0.15s ease;
    border-bottom: 1px solid var(--liq-border-color);
}

    .ownership-dropdown-item:last-child {
        border-bottom: none;
    }

    .ownership-dropdown-item:hover {
        background: var(--liq-bg-hover);
    }

    .ownership-dropdown-item.active {
        background: var(--liq-accent-green-active);
    }

        .ownership-dropdown-item.active .ownership-dropdown-label {
            color: var(--liq-accent-green);
        }

.ownership-dropdown-label {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--liq-text-primary);
}

.ownership-dropdown-desc {
    font-size: 0.75rem;
    color: var(--liq-text-secondary);
    margin-top: 2px;
}

/* Editable Cells */
.editable-cell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    box-sizing: border-box;
    padding: 0 6px;
}

.editable-input {
    width: 100%;
    height: 28px;
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    text-align: center;
    font-size: 13px;
    background: var(--bs-body-bg);
    color: inherit;
    margin: 0;
    padding: 0;
    line-height: 26px;
    box-sizing: border-box;
}

    .editable-input:hover {
        border-color: var(--bs-secondary);
    }

    .editable-input:focus {
        outline: none;
        border-color: var(--bs-primary);
    }

    .editable-input.modified {
        border-color: var(--bs-primary);
        background: rgba(var(--bs-primary-rgb), 0.05);
    }

.editable-reset {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    cursor: pointer;
    color: var(--bs-secondary);
    border-radius: 50%;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.15s;
}

.editable-cell:hover .editable-reset:not(.hidden) {
    opacity: 1;
}

.editable-reset:hover {
    color: var(--bs-danger);
    background: rgba(var(--bs-danger-rgb), 0.1);
}

.editable-reset.hidden {
    display: none;
}

/* Hide spinner buttons */
.editable-input::-webkit-outer-spin-button,
.editable-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.editable-input[type=number] {
    -moz-appearance: textfield;
}

/* Condensed Lineup View */
.condensed-lineup {
    font-size: 0.8rem;
    line-height: 1.6;
    padding: 4px 0;
}

    .condensed-lineup .condensed-slot {
        white-space: nowrap;
    }

        .condensed-lineup .condensed-slot strong {
            color: var(--liq-text-secondary);
            font-weight: 600;
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 0.02em;
        }

.condensed-view-active .ag-row {
    min-height: 52px;
}

.condensed-lineup-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
    align-items: center;
}

/* Duplicate Count */
.dupe-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}

    .dupe-count.unique {
        background: transparent;
        color: var(--liq-text-secondary);
    }

    .dupe-count.duplicated {
        background: rgba(239, 68, 68, 0.15);
        color: var(--liq-accent-red);
    }

/* ============================================
   Grid Group Selection Mode
   ============================================ */

/* Floating Selection Bar */
.grid-selection-bar {
    position: fixed;
    bottom: -60px;
    left: 0;
    right: 0;
    height: 52px;
    background: var(--liq-bg-secondary);
    border-top: 1px solid var(--liq-border-color);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1060;
    transition: bottom 0.2s ease;
}

    .grid-selection-bar.show {
        bottom: 0;
    }

.grid-selection-bar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
}

.grid-selection-bar-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--liq-text-primary);
}

    .grid-selection-bar-info i {
        color: var(--liq-accent-green);
        font-size: 1.1rem;
    }

.grid-selection-bar-separator {
    color: var(--liq-text-secondary);
}

.grid-selection-bar-count strong {
    color: var(--liq-accent-green);
}

.grid-selection-bar-actions {
    display: flex;
    gap: 8px;
}

/* Manual Group Player Box */
.manual-group-player-box {
    border: 1px solid var(--liq-border-color);
    border-radius: 6px;
    background: var(--liq-bg-tertiary);
    min-height: 80px;
    max-height: 150px;
    overflow-y: auto;
    padding: 10px;
}

.manual-group-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 0;
}

    .manual-group-empty i {
        font-size: 1.4rem;
    }

.manual-group-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.manual-group-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--liq-bg-secondary);
    border: 1px solid var(--liq-border-color);
    border-radius: 16px;
    padding: 3px 8px 3px 10px;
    font-size: 0.78rem;
    color: var(--liq-text-primary);
}

.manual-group-chip-detail {
    color: var(--liq-text-secondary);
    font-size: 0.72rem;
}

.manual-group-chip-remove {
    cursor: pointer;
    font-size: 0.65rem;
    color: var(--liq-text-secondary);
    padding: 2px;
    border-radius: 50%;
    transition: color 0.15s;
}

    .manual-group-chip-remove:hover {
        color: var(--liq-accent-red);
    }

/* Grid group select icon */
.grid-group-select-icon:hover i {
    transform: scale(1.15);
    transition: transform 0.1s;
}

/* Hide modal during grid selection (keep in DOM) */
.grid-selection-hidden {
    display: none !important;
}

/* Keep all rows full opacity during grid group selection mode */
.grid-group-selection-active .ag-theme-quartz .ag-row:not(.ag-row-selected),
.grid-group-selection-active .ag-theme-quartz-dark .ag-row:not(.ag-row-selected) {
    opacity: 1;
    background-color: var(--liq-bg-secondary);
}

/* ============================================
   Conditional (IF/THEN) Rule Styles
   Append to lineupiq-tables-grids.css
   ============================================ */

/* THEN section container — slides in below primary group */
.then-group-section {
    margin-top: 4px;
}

.then-group-container {
    padding: 12px 14px;
    border: 1px solid var(--liq-border-color);
    border-left: 3px solid #10b981;
    border-radius: 0 8px 8px 0;
    background: var(--liq-bg-secondary);
}

/* Connector arrow between primary and THEN */
.conditional-connector {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 0;
    color: var(--liq-text-muted);
}

    .conditional-connector i {
        font-size: 1.2rem;
    }

/* Section label with badge */
.conditional-section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    font-weight: 500;
    font-size: 0.9rem;
}

/* THEN badge */
.conditional-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 4px;
    min-width: 42px;
    text-align: center;
    text-transform: uppercase;
}

    .conditional-badge.then-badge {
        background: rgba(16, 185, 129, 0.15);
        color: #34d399;
        border: 1px solid rgba(16, 185, 129, 0.3);
    }

/* Compact player box inside THEN section */
.then-group-container .manual-group-player-box {
    min-height: 50px;
    max-height: 100px;
}

/* Compact auto preview inside THEN section */
.then-group-container .auto-preview-box {
    font-size: 0.8rem;
}

/* THEN constraint row spacing */
.then-group-container .rule-constraint-row {
    font-size: 0.85rem;
}

/* Primary constraint row styling */
#groupRuleMode {
    min-width: 60px;
}

/* Conditional rule description in dropdown */
.rule-item[data-rule-type="conditional"] .rule-item-description {
    font-size: 0.78rem;
}

/* Animate THEN section appearance */
#thenGroupSection {
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}