/* ============================================================
   WPCarSync — Trefferleiste unten im Archiv + Filterbox als Popup
   (Fahrzeuge, Angebote, Stellen; Body-Klasse wpcs-has-archive-bar, \DXIM\ArchiveBar)
   Markup: tpl/modern/archive/archive_bar.php, Verhalten: js/archive-bar.js

   Bis zum Breakpoint (Standard 1024 px, PHP-Filter wpcs_archive_bar_breakpoint) wird die
   vorhandene Filterbox der Seitenleiste zum Vollbild-Popup von unten. Die Media Queries stehen
   deshalb immer als (max-width: 1024px) / (min-width: 1025px) – ArchiveBar ersetzt sie bei
   einem anderen Breakpoint.

   Anpassbar für Themes:
     --wpcs-archive-bar-z                 Ebene der Leiste
     --wpcs-archive-sheet-z               Ebene des Popups (Hintergrund darunter, Auswahllisten darüber)
     --wpcs-archive-bar-bg / -border      Leiste
     --wpcs-archive-bar-btn-bg / -color   Buttons „Filter“ und „… anzeigen“
     --wpcs-archive-bar-btn-hover-bg / -hover-color
     --wpcs-archive-bar-gap               zusätzlicher Abstand unter dem Seiteninhalt
     --wpcs-archive-bar-scroll-offset     Abstand oben, wenn „Filter“ auf dem Desktop zur Filterbox scrollt
                                          (zusätzlich zu scroll-padding-top am <html>, z. B. für feste Header)
   Höhe der Leiste: --wpcs-archive-bar-h (setzt archive-bar.js)
   ============================================================ */

:root {
    --wpcs-archive-bar-z:              9980;
    --wpcs-archive-sheet-z:            10001;
    --wpcs-archive-bar-bg:             var(--wpcs-color-surface);
    --wpcs-archive-bar-border:         var(--wpcs-color-border);
    --wpcs-archive-bar-btn-bg:         var(--wpcs-color-primary);
    --wpcs-archive-bar-btn-color:      #fff;
    --wpcs-archive-bar-btn-hover-bg:   var(--wpcs-color-primary-bright, var(--wpcs-color-primary));
    --wpcs-archive-bar-btn-hover-color: #fff;
    --wpcs-archive-bar-gap:            0px;
    --wpcs-archive-bar-scroll-offset:  24px;
}

/* Platz unter dem Seiteninhalt = Höhe der Leiste */
body.wpcs-has-archive-bar {
    padding-bottom: calc(var(--wpcs-archive-bar-h, 72px) + var(--wpcs-archive-bar-gap));
}

/* Desktop: „Filter“ scrollt per scrollIntoView zur Filterbox – Abstand oben */
.wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar {
    scroll-margin-top: var(--wpcs-archive-bar-scroll-offset);
}


/* ============================================================
   Leiste
   ============================================================ */

.wpcs-archive-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: var(--wpcs-archive-bar-z);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "chips chips" "count filter";
    align-items: center;
    column-gap: 12px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom)) 16px;
    background: var(--wpcs-archive-bar-bg);
    border-top: 1px solid var(--wpcs-archive-bar-border);
    box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.06);
    font-family: var(--wpcs-font-body);
    color: var(--wpcs-color-text);
    box-sizing: border-box;
}

.wpcs-archive-bar *,
.wpcs-archive-bar *::before,
.wpcs-archive-bar *::after {
    box-sizing: border-box;
}

.wpcs-archive-bar svg {
    flex: none;
}

@media (min-width: 1025px) {
    .wpcs-archive-bar {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "count chips filter";
        column-gap: 24px;
        /* Inhalt bündig mit dem Seiteninhalt (.wpcs-page: max. Inhaltsbreite + Innenabstand) */
        padding: 12px calc(max(0px, (100% - var(--wpcs-content-width)) / 2) + var(--wpcs-content-padding)) calc(12px + env(safe-area-inset-bottom));
    }
}

/* Trefferzahl („326 Fahrzeuge“) */
.wpcs-archive-bar__count {
    grid-area: count;
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
    font-size: var(--wpcs-text-md);
    color: var(--wpcs-color-text-muted);
    white-space: nowrap;
}

.wpcs-archive-bar__count strong {
    font-family: var(--wpcs-font-label);
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
    color: var(--wpcs-color-text);
    font-variant-numeric: tabular-nums;
}

/* Gesetzte Filter: eine Zeile, bei vielen seitlich scrollbar (mobil eigene Zeile über Zahl und Button) */
.wpcs-archive-bar__chips {
    grid-area: chips;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
    margin: 0 0 8px;
    padding: 2px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

.wpcs-archive-bar:not(.has-chips) .wpcs-archive-bar__chips {
    display: none;
}

@media (min-width: 1025px) {
    .wpcs-archive-bar__chips {
        margin: 0;
    }
}

.wpcs-archive-bar__chips .wpcs_filterform_active_filters {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    margin: 0;
}

.wpcs-archive-bar__chips .active_filter {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 4px 2px 12px;
    background: var(--wpcs-color-primary-dim);
    color: var(--wpcs-color-primary);
    border: 1px solid transparent;
    border-radius: 999px;
    font-family: var(--wpcs-font-mono);
    font-size: var(--wpcs-text-2xs, 11px);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    line-height: 1.4;
    white-space: nowrap;
}

.wpcs-archive-bar__chips .active_filter .label {
    order: 1;
}

/* ×: mindestens 24 × 24 px Klickfläche */
.wpcs-archive-bar__chips .active_filter .reset {
    order: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: currentColor;
    font-size: 16px;
    line-height: 24px;
    opacity: 0.75;
    cursor: pointer;
    transition: opacity var(--wpcs-transition), background var(--wpcs-transition), color var(--wpcs-transition);
}

.wpcs-archive-bar__chips .active_filter .reset:hover,
.wpcs-archive-bar__chips .active_filter .reset:focus-visible {
    opacity: 1;
    background: var(--wpcs-color-primary);
    color: #fff;
}

/* Buttons: Selektoren mit Wrapper (0,2,0 bzw. 0,3,0 mit :hover/:focus), damit globale Button-Styles von
   Themes/Page-Buildern nicht durchschlagen (z. B. Elementor-Kit „.elementor-kit-N button“ 0,1,1, Hover/Fokus 0,2,1).
   Schrift, Großschreibung, Rahmen usw. deshalb ausdrücklich gesetzt. */

/* Button „Filter“ */
.wpcs-archive-bar .wpcs-archive-bar__filter {
    grid-area: filter;
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: auto;
    height: 46px;
    min-height: 0;
    margin: 0;
    padding: 0 20px;
    border: 0;
    border-radius: var(--wpcs-radius-md);
    background: var(--wpcs-archive-bar-btn-bg);
    color: var(--wpcs-archive-bar-btn-color);
    box-shadow: none;
    font-family: var(--wpcs-font-label);
    font-size: var(--wpcs-text-base);
    font-weight: 700;
    font-style: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--wpcs-transition), color var(--wpcs-transition);
}

.wpcs-archive-bar .wpcs-archive-bar__filter:hover,
.wpcs-archive-bar .wpcs-archive-bar__filter:focus {
    background: var(--wpcs-archive-bar-btn-hover-bg);
    color: var(--wpcs-archive-bar-btn-hover-color);
}

/* Anzahl gesetzter Filter */
.wpcs-archive-bar__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--wpcs-archive-bar-btn-color);
    color: var(--wpcs-archive-bar-btn-bg);
    font-size: 12px;
    font-weight: 700;
}

.wpcs-archive-bar__badge[hidden] {
    display: none;
}

.wpcs-archive-bar :focus-visible,
.wpcs-archive-sheet :focus-visible {
    outline: 2px solid var(--wpcs-color-primary);
    outline-offset: 2px;
}


/* ============================================================
   Elemente in der Filterbox (von archive-bar.js dorthin gesetzt)
   ============================================================ */

.wpcs-archive-sheet .wpcs-archive-bar__close {
    display: none;
    place-items: center;
    flex: none;
    width: 44px;
    height: 44px;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--wpcs-radius-md);
    background: none;
    color: var(--wpcs-color-text);
    box-shadow: none;
    cursor: pointer;
}

.wpcs-archive-sheet .wpcs-archive-bar__close:hover,
.wpcs-archive-sheet .wpcs-archive-bar__close:focus {
    background: var(--wpcs-color-primary-dim);
    color: var(--wpcs-color-text);
}

.wpcs-archive-sheet .wpcs-archive-bar__show {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 52px;
    margin: 0;
    padding: 0 20px;
    border: 0;
    border-radius: var(--wpcs-radius-md);
    background: var(--wpcs-archive-bar-btn-bg);
    color: var(--wpcs-archive-bar-btn-color);
    box-shadow: none;
    font-family: var(--wpcs-font-label);
    font-size: var(--wpcs-text-lg);
    font-weight: 700;
    font-style: normal;
    line-height: 1.2;
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
    white-space: normal;
    cursor: pointer;
    transition: background var(--wpcs-transition), color var(--wpcs-transition);
}

.wpcs-archive-sheet .wpcs-archive-bar__show:hover,
.wpcs-archive-sheet .wpcs-archive-bar__show:focus {
    background: var(--wpcs-archive-bar-btn-hover-bg);
    color: var(--wpcs-archive-bar-btn-hover-color);
}

.wpcs-archive-bar__show .wpcs-archive-bar__show-none,
.wpcs-archive-bar__show.is-empty .wpcs-archive-bar__show-some {
    display: none;
}

.wpcs-archive-bar__show.is-empty .wpcs-archive-bar__show-none {
    display: inline;
}

.wpcs-archive-sheet-backdrop {
    display: none;
}


/* ============================================================
   Bis zum Breakpoint: Filterbox als Vollbild-Popup von unten
   ============================================================ */

@media (max-width: 1024px) {

    /* Liste volle Breite, die Seitenleiste ist nicht mehr im Fluss */
    .wpcs-has-archive-bar .wpcs-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .wpcs-has-archive-bar .wpcs-layout > .wpcs-main {
        grid-column: auto;
        grid-row: auto;
        min-width: 0;
    }

    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar {
        position: fixed;
        inset: 0;
        z-index: var(--wpcs-archive-sheet-z);
        display: flex;
        width: auto;
        max-width: none;
        max-height: none;
        margin: 0;
        visibility: hidden;
        transition: visibility 0s linear 0.35s;
    }

    body.wpcs-archive-sheet-open .wpcs-layout > .wpcs-sidebar {
        visibility: visible;
        transition: none;
    }

    /* Das Hereinfahren macht die Karte (die Seitenleiste animiert WPCarSync per GSAP) */
    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__card {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        max-height: none;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    }

    body.wpcs-archive-sheet-open .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__card {
        transform: none;
    }

    /* Kopf: „Filter“ | Zurücksetzen | Schließen */
    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__header {
        flex: none;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: calc(10px + env(safe-area-inset-top)) 10px 10px 20px;
        border-bottom: 1px solid var(--wpcs-color-border);
    }

    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__filter-toggle {
        flex: 1;
        pointer-events: none;
        font-size: var(--wpcs-text-xl);
        font-weight: 800;
    }

    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__toggle-chevron {
        display: none;
    }

    /* Filter in der Mitte, scrollbar (WPCarSync klappt den Inhalt mobil sonst auf Höhe 0 zu) */
    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar :is(#sidebar-filter-body, .wpcs-sidebar__body) {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
        overflow: auto;
        overscroll-behavior: contain;
        padding: 16px 20px;
    }

    /* Fuß: „326 Fahrzeuge anzeigen“ */
    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__footer {
        flex: none;
        display: block;
        padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
        border-top: 1px solid var(--wpcs-color-border);
    }

    .wpcs-archive-sheet .wpcs-archive-bar__close {
        display: grid;
    }

    .wpcs-archive-sheet .wpcs-archive-bar__show {
        display: flex;
    }

    .wpcs-archive-sheet-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: calc(var(--wpcs-archive-sheet-z) - 1);
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0s linear 0.3s;
    }

    body.wpcs-archive-sheet-open .wpcs-archive-sheet-backdrop {
        opacity: 1;
        visibility: visible;
        transition: opacity 0.3s;
    }

    body.wpcs-archive-sheet-open {
        overflow: hidden;
        /* Auswahllisten (#wpcs_select_list, am Ende von <body>) über dem Popup */
        --wpcs-select-list-z: calc(var(--wpcs-archive-sheet-z) + 1);
    }
}

/* Handy: Seitenkopf (H1) nur für Screenreader/Suchmaschinen, damit die Treffer sofort sichtbar sind */
@media (max-width: 768px) {
    .wpcs-has-archive-bar .wpcs-page-header {
        position: absolute;
        width: 1px;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
    }
}

/* Desktop: Fußbereich der Filterbox ausblenden, wenn er nur den Popup-Button enthält */
@media (min-width: 1025px) {
    .wpcs-has-archive-bar .wpcs-sidebar__footer:not(:has(> :not(.wpcs-archive-bar__show))) {
        display: none;
    }

    /* Filter-Seitenleiste mitlaufen (Design → Layout): „Nie“ bzw. „Automatisch“, wenn sie nicht ganz
       ins Fenster passt (archive-bar.js setzt dann .wpcs-sidebar--no-sticky) */
    .wpcs-archive-sidebar--never .wpcs-layout > .wpcs-sidebar,
    .wpcs-archive-sidebar--auto .wpcs-layout > .wpcs-sidebar.wpcs-sidebar--no-sticky {
        position: static;
    }
}

@media (prefers-reduced-motion: reduce) {
    .wpcs-has-archive-bar .wpcs-layout > .wpcs-sidebar .wpcs-sidebar__card,
    .wpcs-archive-sheet-backdrop {
        transition: none;
    }
}
