/* ============================================
   LineupIQ Responsive Styles
   ============================================ */

/* Container Queries for Panel Responsiveness */
.panel-right {
    container-type: inline-size;
    container-name: lineup-panel;
}

.panel-left {
    container-type: inline-size;
    container-name: player-panel;
}

/* Lineup Panel Responsive */
@container lineup-panel (max-width: 540px) {
    .lineup-panel-toolbar .btn-text {
        display: none;
    }

    .lineup-panel-toolbar .btn i {
        margin: 0 !important;
    }

    #lineupQuickFilter {
        width: 140px !important;
    }
}

@container lineup-panel (max-width: 380px) {
    #lineupQuickFilter {
        width: 100px !important;
    }
}

@container lineup-panel (max-width: 580px) {
    #contestEntryStats {
        display: none;
    }
}

@container lineup-panel (max-width: 420px) {
    .player-filter-indicator {
        margin-left: 0.5rem;
        padding-left: 0.5rem;
    }

    .entry-filter-indicator {
        margin-left: 0.5rem;
    }

        .entry-filter-indicator .badge {
            max-width: 120px;
            overflow: hidden;
            text-overflow: ellipsis;
        }
}

/* Player Panel Responsive */
@container player-panel (max-width: 580px) {
    .player-grid-header .btn-text {
        display: none;
    }

    .player-grid-header .btn i {
        margin: 0 !important;
    }

    #generateLineupsBtn {
        min-width: auto !important;
    }
}

/* Contest Build Header Responsive */
@container player-panel (max-width: 750px) {
    .contest-build-header .btn-text {
        display: none;
    }

    .contest-build-header .btn i {
        margin: 0 !important;
    }
}

@container player-panel (max-width: 650px) {
    .contest-build-header .stat-label {
        display: none;
    }

    .contest-header-stats {
        gap: 0.75rem;
    }

    .contest-header-stat .stat-value {
        padding: 0.2rem 0.5rem;
        background: var(--liq-bg-tertiary);
        border-radius: 4px;
        font-size: 0.8rem;
    }
}

@container player-panel (max-width: 550px) {
    .contest-header-stats {
        display: none;
    }
}

@container player-panel (max-width: 450px) {
    .contest-research-label strong {
        font-size: 0.85rem;
    }

    .contest-research-label i {
        font-size: 0.9rem;
    }
}

/* Mobile Panel Tabs (hidden on desktop) */
.mobile-panel-tabs {
    display: none;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* ============================================
       Page scroll + workspace height (mobile)
       --------------------------------------------
       The site's html/body { height: 100% } turns the BODY into the scroll
       container; on iOS that scroll is unreliable and the AG Grid swallows
       vertical swipes, so users got stuck with a few rows visible and no way
       to scroll. Scoped to pages containing LineupIQ: let the DOCUMENT
       scroll normally, and size the workspace to the VISIBLE viewport (dvh
       tracks iOS Safari's dynamic toolbars; vh is the fallback) minus the
       sticky navbar - scroll the slate/build/games chrome away and the grid
       fills the screen. */
    html:has(.lineupiq-container),
    body:has(.lineupiq-container) {
        height: auto;
    }

    /* Base container */
    .lineupiq-container {
        min-width: 0 !important;
        width: 100%;
    }

    /* iOS zooms the page when a focused control's font-size is under 16px.
       Keep every text/number input at 16px on mobile so the keyboard opens
       without the zoom jump (search bars, min/max exposure, stack %, grid
       cell editors - all of them). */
    .lineupiq-container input[type="text"],
    .lineupiq-container input[type="number"],
    .lineupiq-container input[type="search"],
    .lineupiq-container select,
    .lineupiq-container textarea,
    .lineupiq-container .editable-input {
        font-size: 16px !important;
    }

    /* ============================================
       Slate Tabs � Mobile
       --------------------------------------------
       The whole row scrolls horizontally on mobile so users can swipe
       through slate tabs while still seeing date controls, brand, and
       the settings/admin dropdowns.

       IMPORTANT: Do NOT add `-webkit-overflow-scrolling: touch` here.
       That deprecated iOS-only property creates a containing block for
       position:fixed descendants on iOS Safari, which traps the
       dropdown menus inside this scrolling row and clips them at the
       row's bottom edge. Modern iOS (13+) provides momentum scrolling
       by default without this property.
       ============================================ */

    /* Container must stay overflow:visible so the settings/admin dropdown
       menus can escape the row. A horizontal scroll HERE forces overflow-y
       to compute to `auto` too, which clips the open menus at the row's
       bottom edge (and traps them where an ancestor forms a containing
       block). Scroll the tab strip INNER instead � it's a sibling of the
       dropdowns, not their ancestor. */
    /* Single row on mobile: date + scrolling slate tabs + admin + settings.
       Container stays overflow:visible so the dropdowns aren't clipped. */
    .slate-tabs-container {
        flex-wrap: nowrap;
        overflow: visible;
    }

    /* Drop the prev/next arrows on mobile � tap the date chip to open the
       calendar instead. Frees the width the slate tabs need. */
    #slateDatePrev,
    #slateDateNext {
        display: none;
    }

    .slate-date-filter {
        flex-shrink: 0;
        border-right: none;
        margin-right: 0.5rem;
        padding-right: 0;
    }

    /* Compact the date chip a touch for a little more tab room */
    .date-display-small {
        font-size: 0.75rem;
        padding: 0.3rem 0.5rem;
    }

    /* Slate tabs take the remaining width and scroll horizontally */
    .slate-tabs-scroll-wrapper {
        order: 0;
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        overflow: visible;
    }

    .slate-tabs-inner {
        flex: 1;
        min-width: 0;
        overflow-x: hidden;
        overflow-y: hidden;
    }

    /* ============================================
       Mobile slate switcher: a tab STRIP is the wrong metaphor at phone
       widths. Show ONLY the active slate as a full-width selector —
       tapping it opens the slate menu (wired in lineupiq-slates.js).
       The row reads: [date] [current slate ▾] [+] [gear].
       ============================================ */
    /* !important: the date filter show()s tabs via INLINE display, which
       would otherwise override this media rule and re-reveal the strip.
       The :not([style*="none"]) guard keeps an active tab belonging to a
       date-filtered-out day hidden (jQuery .hide() = inline display:none). */
    .slate-tab {
        display: none !important;
    }

    .slate-tab.active:not([style*="none"]) {
        display: flex !important;
        flex: 1;
        min-width: 0;
    }

        /* Suffix ellipsizes and pushes the close X to the right edge */
        .slate-tab.active .slate-tab-suffix {
            flex: 1;
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            text-align: left;
        }

        /* Dropdown affordance — this tab IS the slate switcher. Rendered
           as a small boxed chevron so it reads as a control, not a glyph. */
        .slate-tab.active::after {
            content: "▾";
            margin-left: auto;
            flex-shrink: 0;
            padding: 0 7px;
            border-radius: 6px;
            border: 1px solid var(--liq-border-color);
            background: var(--liq-bg-primary);
            color: var(--liq-text-secondary);
            font-size: 0.95rem;
            line-height: 1.5;
        }

        /* Drop the close X — every pixel goes to the slate name; slates
           are removed via the modal's pin toggle on mobile */
        .slate-tab.active i.bi-x-lg {
            display: none;
        }

    /* Date chip: the numeric date is the tap target — the calendar glyph
       was just spending width */
    #slateCurrentDate .bi-calendar3 {
        display: none;
    }

    /* Gear hugs the edge */
    .slate-tabs-settings {
        padding: 0 0.25rem;
    }

    /* The chip is redundant when the active slate is the dropdown trigger */
    .slate-tabs-overflow-chip.has-overflow {
        display: none;
    }

    /* No scrolling strip on mobile — no fades */
    .slate-tabs-scroll-wrapper::before,
    .slate-tabs-scroll-wrapper::after {
        display: none;
    }

    /* Add Slate collapses to icon-only; the label costs a tab's worth
       of width at phone sizes */
    .add-slate-btn span {
        display: none;
    }

    .add-slate-btn {
        padding: 0.375rem 0.5rem;
    }

    /* Comfortable tap targets in the slate overflow dropdown */
    .slate-overflow-item {
        padding: 0.625rem 0.875rem;
    }

    /* ============================================
       Build tabs — Mobile
       System tabs (Contests / Favorites / Field) collapse to icon +
       count badge; their color coding + icons carry the identity. User
       builds keep their names, capped so one long name can't eat the
       row. Add Build collapses to its plus icon.
       ============================================ */
    .build-tabs-section {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }

    .build-tab {
        padding: 0.375rem 0.625rem;
        gap: 0.375rem;
    }

        .build-tab.contests-tab .build-tab-name,
        .build-tab.favorites-tab .build-tab-name,
        .build-tab.field-tab .build-tab-name {
            display: none;
        }

        .build-tab .build-tab-name {
            max-width: 96px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

    /* Touch scroll without a visible scrollbar */
    .build-tabs-container {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

        .build-tabs-container::-webkit-scrollbar {
            display: none;
        }

    .add-build-btn span {
        display: none;
    }

    .add-build-btn {
        padding: 0.375rem 0.5rem;
    }

    /* Keep the gear pinned to the right */
    .slate-tabs-settings {
        margin-left: 0.25rem;
        flex-shrink: 0;
    }

        /* Merged settings menu can get tall for admins � scroll inside the menu */
        .slate-tabs-settings .dropdown-menu {
            max-height: 70vh;
            overflow-y: auto;
        }

    /* Mobile: drop the start-time prefix from the STRIP's tab (width is
       scarce there) — but keep it in the slate switcher menu items, where
       time is what distinguishes same-name slates (1:05PM vs 7:05PM Main) */
    .slate-tabs-inner .slate-tab-time {
        display: none;
    }

    /* Rule Type Tabs - Compact for mobile */
    .rule-type-tab-content span:not(.coming-soon-dot) {
        display: none;
    }

    .rule-type-tab-content i {
        font-size: 1rem;
    }

    /* Mobile Panel Tabs */
    .mobile-panel-tabs {
        display: flex;
        background: var(--liq-bg-secondary);
        border-bottom: 1px solid var(--liq-border-color);
        padding: 0.5rem;
        gap: 0.5rem;
        flex-shrink: 0;
    }

    .mobile-panel-tab {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        border: 1px solid var(--liq-border-color);
        border-radius: 8px;
        background: var(--liq-bg-primary);
        color: var(--liq-text-secondary);
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
    }

        .mobile-panel-tab.active {
            background: var(--liq-accent-green);
            border-color: var(--liq-accent-green);
            color: white;
        }

        .mobile-panel-tab:not(.active):hover {
            background: var(--liq-bg-tertiary);
        }

    /* Workspace Layout: one visible viewport minus the sticky navbar, so
       after the user scrolls the chrome away the grid is full-screen. dvh =
       the VISIBLE viewport on iOS (vh overshoots behind Safari's toolbars). */
    .build-workspace {
        height: calc(100vh - 90px);
        height: calc(100dvh - 90px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .workspace-panel {
        width: 100% !important;
        min-width: 0 !important;
        flex: 1 !important;
        display: flex;
        flex-direction: column;
        min-height: 0;
        overflow: hidden;
    }

        .workspace-panel.panel-left {
            display: flex;
        }

        .workspace-panel.panel-right {
            display: none;
        }

    .build-workspace.show-lineups .workspace-panel.panel-left {
        display: none;
    }

    .build-workspace.show-lineups .workspace-panel.panel-right {
        display: flex;
    }

    .panel-divider {
        display: none;
    }

    /* Headers */
    .panel-header,
    .player-grid-header {
        flex-shrink: 0;
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
        height: auto;
    }

    .player-grid-subheader {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        padding: 0.4rem 0.75rem;
        gap: 0.5rem;
        height: auto;
        flex-shrink: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

        .player-grid-subheader > div {
            flex-wrap: nowrap;
            flex-shrink: 0;
            gap: 0.35rem !important;
        }

        .player-grid-subheader .player-search {
            width: 110px !important;
            min-width: 90px;
            padding: 0.25rem 0.5rem;
            font-size: 0.8rem;
        }

    #positionFilterGroup {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

        #positionFilterGroup .btn {
            padding: 0.2rem 0.45rem;
            font-size: 0.75rem;
        }

    /* Compact toggle on mobile: icon + count, drop the word */
    .selected-filter-toggle .selected-word {
        display: none;
    }

    .player-grid-subheader .btn[style*="width: 32px"] {
        width: 26px !important;
        height: 24px !important;
        min-width: 26px;
    }

    #favoritesDropdownBtn {
        width: 26px !important;
        height: 24px !important;
    }

    .panel-content {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    #playerGrid,
    #lineupGrid,
    #contestEntriesGrid {
        height: 100% !important;
        width: 100% !important;
    }

    /* Rule Modal Mobile */
    .rule-modal-content {
        max-width: 100%;
        margin: 0.5rem;
    }

    .rule-constraint-row {
        font-size: 0.8125rem;
    }

    /* Contests Header Mobile */
    .contests-header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

        .contests-header > div:first-child {
            flex: 1;
            min-width: 0;
            flex-wrap: wrap;
            gap: 0.5rem !important;
        }

            /* Hide slate name on mobile - it's redundant info */
            .contests-header > div:first-child > span.text-muted.small {
                display: none;
            }

        /* Make badges smaller */
        .contests-header .badge {
            font-size: 0.7rem;
            padding: 0.2rem 0.4rem;
        }

        /* Right side controls */
        .contests-header > div:last-child {
            gap: 0.35rem !important;
        }

        /* Hide list view toggle on mobile - cards work better for touch */
        .contests-header #cardViewBtn,
        .contests-header #listViewBtn {
            display: none;
        }

        /* Also hide the parent btn-group if both children hidden */
        .contests-header .btn-group {
            display: none;
        }

        /* Hide "Filters" text, keep icon */
        .contests-header #contestFiltersBtn span {
            display: none;
        }

        /* Smaller buttons */
        .contests-header #contestFiltersBtn,
        .contests-header #refreshContestsBtn {
            padding: 0.35rem 0.5rem;
        }

    /* Contests workspace padding */
    .contests-workspace {
        padding: 1rem;
    }

    /* Contest cards grid - single column on small screens */
    .contests-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    /* Contest card adjustments for mobile */
    .contest-card-header {
        padding: 0.75rem;
    }

    .contest-name {
        font-size: 0.85rem;
    }

    .contest-card-body {
        padding: 0.75rem;
    }

    .contest-stats {
        gap: 0.5rem;
    }

    .contest-stat .stat-value {
        font-size: 0.9rem;
    }

    .contest-stat .stat-label {
        font-size: 0.65rem;
    }

    .contest-card-footer {
        padding: 0.5rem 0.75rem;
    }

        .contest-card-footer .btn {
            font-size: 0.75rem;
            padding: 0.3rem 0.6rem;
        }

    /* Filter panel mobile adjustments */
    .contests-filters .filters-container {
        padding: 0.75rem;
    }

    .contests-filters .row.g-3 {
        --bs-gutter-y: 0.75rem;
    }

    .contests-filters .form-label {
        margin-bottom: 0.25rem;
    }
}

/* Tablet Responsive */
@media (max-width: 992px) {
    /* Analysis Modal Responsive */
    .analysis-modal-content {
        width: 95%;
        height: 85vh;
    }

    .analysis-sidebar {
        width: 60px;
    }

    .analysis-nav-link span {
        display: none;
    }

    .analysis-nav-link {
        justify-content: center;
        padding: 0.75rem;
    }

        .analysis-nav-link i {
            margin: 0;
        }

    .analysis-row {
        grid-template-columns: 1fr;
    }

    .analysis-summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Date Picker Mobile */
@media (max-width: 576px) {
    .date-picker-section {
        flex-direction: column;
        align-items: stretch;
    }

    .date-picker-controls {
        justify-content: center;
    }

    .slate-filters {
        justify-content: space-between;
    }

        .slate-filters .form-select {
            flex: 1;
            min-width: 0;
        }

    .game-type-filter-menu {
        right: auto;
        left: 0;
    }

    .analysis-summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Small Mobile */
@media (max-width: 640px) {
    /* Small screen adjustments */
}

/* Very Small Mobile */
@media (max-width: 480px) {
    /* Very small screen adjustments */
}

/* Import/Export Modal Responsive */
@media (max-width: 768px) {
    .import-mapping-section {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .import-mapping-grid {
        flex-direction: column;
        gap: 0.5rem;
    }

    .import-mapping-item {
        justify-content: space-between;
        width: 100%;
    }

        .import-mapping-item label {
            min-width: 80px;
        }

        .import-mapping-item select {
            flex: 1;
            margin-left: 0.5rem;
        }

    .import-summary {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
        text-align: center;
    }
}

/* High DPI / Retina Display Adjustments */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .site-logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Print Styles */
@media print {
    .lineupiq-container {
        background: white !important;
        color: black !important;
        min-width: auto;
    }

    .slate-tabs-container,
    .build-tabs-section,
    .panel-header,
    .player-grid-header,
    .player-grid-subheader,
    .lineup-panel-toolbar {
        display: none !important;
    }

    .build-workspace {
        height: auto !important;
        display: block !important;
    }

    .workspace-panel {
        display: block !important;
        min-width: auto !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    .panel-content {
        height: auto !important;
        overflow: visible !important;
    }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .generation-progress-icon {
        animation: none !important;
    }

    #refreshProjectionsBtn i.spin-animation {
        animation: none !important;
    }

    .contest-state-live {
        animation: none !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .lineupiq-container {
        --liq-border-color: #000000;
        --liq-text-secondary: #000000;
    }

    [data-bs-theme="dark"] .lineupiq-container {
        --liq-border-color: #ffffff;
        --liq-text-secondary: #ffffff;
    }
}

/* Dark Mode Preference Override */
@media (prefers-color-scheme: dark) {
    :root:not([data-bs-theme]) {
        --liq-bg-primary: #1a1d29;
        --liq-bg-secondary: #252834;
        --liq-bg-tertiary: #2d3142;
        --liq-bg-hover: rgba(255, 255, 255, 0.05);
        --liq-text-primary: #ffffff;
        --liq-text-secondary: #b0b3c1;
        --liq-border-color: #3d4152;
        --liq-shadow: rgba(0, 0, 0, 0.3);
        --liq-modal-backdrop: rgba(0, 0, 0, 0.85);
    }
}
