.sci-filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 16px;
    align-items: flex-end;
    padding: 16px 20px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    margin-bottom: 24px;
}

.sci-filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1 1 200px;
    min-width: 160px;
}

/* Region group spans full width to accommodate two chip rows */
.sci-filter-group--region {
    flex: 1 1 100%;
    min-width: 0;
}

.sci-filter-group label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6c757d;
}

.sci-filter-select {
    padding: 8px 32px 8px 12px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 10px;
}

.sci-filter-select:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.15);
}

.sci-filter-select:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
    opacity: 0.6;
}

.sci-filter-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding-top: 18px;
}

.sci-filter-reset {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid #ced4da;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #495057;
    transition: background 0.15s;
}

.sci-filter-reset:hover {
    background: #e9ecef;
}

.sci-filter-count {
    font-size: 13px;
    color: #6c757d;
    white-space: nowrap;
}

/* Results area */
#sci-cross-filter .sci-filter-results {
    min-height: 200px;
    transition: opacity 0.2s ease;
}

#sci-cross-filter .sci-filter-results.sci-loading {
    opacity: 0.4;
    pointer-events: none;
}

#sci-cross-filter .sci-no-results {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
    font-size: 15px;
}

/* Browse card category tag — jnews default renders these near-white/light-grey
   on the white card background (unreadable). These cards sit on white (not over
   an image like homepage overlay badges), so force a readable brand-blue. Scoped
   to #sci-cross-filter so homepage white-on-thumbnail badges are untouched. */
#sci-cross-filter .jeg_post_category a {
    /* jnews forces white text + a light-grey pill bg here → white-on-light =
       invisible. ID-scoped !important wins over the theme rule: brand-blue text
       on transparent, matching the homepage section-label look. */
    color: #1a5fb4 !important;
    background: transparent !important;
    font-weight: 600;
    opacity: 1;
}

#sci-cross-filter .jeg_post_category a:hover {
    color: #0b63c6 !important;
}

/* Pagination */
.sci-filter-pagination {
    text-align: center;
    padding: 20px 0;
}

.sci-filter-pagination .sci-load-more {
    display: inline-block;
    padding: 8px 30px;
    font-size: 13px;
    border: 1px solid #ced4da;
    border-radius: 3px;
    background: #fff;
    color: #495057;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.sci-filter-pagination .sci-load-more:hover {
    background: #f8f9fa;
}

.sci-filter-pagination .sci-load-more.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* ============================================================
   Region two-level chip bar
   ============================================================ */

.sci-region-filter {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Tier 1 — parent regions (wrapping on desktop) */
.sci-region-tier1 {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Tier 2 — country chips; indented to signal hierarchy */
.sci-region-tier2 {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 16px;
    position: relative;
    /* Smooth height/opacity reveal */
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.2s ease, opacity 0.2s ease;
}

/* Tier 2 prefix arrow */
.sci-region-tier2::before {
    content: '\21B3'; /* ↳ */
    position: absolute;
    left: 0;
    top: 6px;
    color: #adb5bd;
    font-size: 13px;
    line-height: 1;
}

/* Hidden state — JS sets [hidden]; also reset transition values */
.sci-region-tier2[hidden] {
    display: none !important;
}

/* Expanded state — JS adds .is-open after unhiding */
.sci-region-tier2.is-open {
    max-height: 200px;
    opacity: 1;
}

/* ============================================================
   Chip base styles
   ============================================================ */

.sci-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 13px;
    border: 1px solid #ced4da;
    border-radius: 20px;
    background: #fff;
    color: #495057;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    /* Reset browser button defaults */
    font-family: inherit;
    line-height: 1.4;
}

.sci-chip:hover {
    background: #f1f3f5;
    border-color: #adb5bd;
}

.sci-chip-count {
    color: #9aa0a6;
    font-size: 11px;
}

/* Country flag (flag-icons) inside a chip */
.sci-chip-flag {
    margin-right: 6px;
    border-radius: 2px;
    vertical-align: -0.12em;
    box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.08);
}

/* ============================================================
   Active states — breadcrumb layer
   Tier1 region: shallow highlight (light blue)
   Tier2 country: deep highlight (solid blue)
   When a country is selected, the parent region chip stays shallow.
   ============================================================ */

/* Tier1 chip active (shallow): selected region, or parent region while a country is selected */
.sci-region-tier1 .sci-chip[aria-selected="true"] {
    background: #eaf2fb;
    border-color: #4a90d9;
    color: #1a5fb4;
}

.sci-region-tier1 .sci-chip[aria-selected="true"] .sci-chip-count {
    color: #4a90d9;
}

/* Tier2 chip active (deep): selected country */
.sci-region-tier2 .sci-chip[aria-selected="true"] {
    background: #4a90d9;
    border-color: #4a90d9;
    color: #fff;
}

.sci-region-tier2 .sci-chip[aria-selected="true"] .sci-chip-count {
    color: rgba(255, 255, 255, 0.8);
}

/* ============================================================
   Mobile responsive
   ============================================================ */

@media (max-width: 767px) {
    .sci-filter-bar {
        flex-direction: column;
        /* Override base `align-items: flex-end`: in a column the base value
           shrinks each group to content width and right-aligns it, leaving a
           large empty gutter on the left. Stretch makes groups fill the card. */
        align-items: stretch;
        gap: 10px;
    }

    .sci-filter-group {
        flex: 1 1 auto;
        width: 100%;
        min-width: 0;
    }

    .sci-filter-actions {
        padding-top: 4px;
        justify-content: space-between;
        width: 100%;
    }

    /* Mobile: horizontal scroll for both chip rows */
    .sci-region-tier1,
    .sci-region-tier2 {
        flex-wrap: nowrap;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        /* Hide scrollbar on Webkit while keeping functionality */
        scrollbar-width: none;
        -ms-overflow-style: none;
        position: relative;
    }

    .sci-region-tier1::-webkit-scrollbar,
    .sci-region-tier2::-webkit-scrollbar {
        display: none;
    }

    .sci-chip {
        scroll-snap-align: start;
        flex: 0 0 auto;
    }

    /* Tier2 expanded max-height is higher on mobile to fit wrapped chips */
    .sci-region-tier2.is-open {
        max-height: 100px;
    }

    /* Right-side fade mask hinting horizontal scroll */
    .sci-region-tier1,
    .sci-region-tier2 {
        -webkit-mask-image: linear-gradient(to right, #000 85%, transparent 100%);
        mask-image: linear-gradient(to right, #000 85%, transparent 100%);
    }
}
