/**
 * Delade komponenter för listvyerna: nationsflagga + filterrad.
 *
 * Laddas av hub_filter_bar() / hub_country_flag_defs() — inte via CSS-bundlen,
 * eftersom bara kalender/resultat/serier behöver den.
 */

/* ============================================================
   NATIONSFLAGGA — vertikal banderoll
   Ersätter seriens färgband längst till vänster i listraderna.
   ============================================================ */
.hub-flag {
    display: block;
    width: 100%;
    height: 100%;
    /* Skuggan gör att vita flaggor (Finland, Danmark) håller sin kant
       mot ljus bakgrund — utan den flyter de ihop med kortet. */
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.32));
}
.hub-flag svg {
    display: block;
    width: 100%;
    height: 100%;
    /* Formerna ritas med marginal utanför rutan — clipPath sköter beskärningen,
       men hidden här är ett skyddsnät om den inte skulle lösas upp. */
    overflow: hidden;
}
.hub-flag-defs {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ============================================================
   FILTERRAD
   Mobil: kompaktrad + bottenark. Desktop: inline-selects.
   ============================================================ */
.hubf {
    margin: 0 0 var(--space-md);
}
/* Bär arkets öppna/stängda läge. Göms med CSS (inte hidden-attributet) så att
   den finns kvar i tabbordningen — labeln är dess tillgängliga namn. */
.hubf-toggle {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    pointer-events: none;
}
.hubf-toggle:focus-visible ~ .hubf-compact .hubf-trigger {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* --- Kompaktraden (bara mobil) --- */
.hubf-compact {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    min-width: 0;
}
.hubf-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-full);
    background: var(--color-bg-card);
    color: var(--color-text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}
.hubf-trigger svg {
    width: 15px; height: 15px;
    fill: none; stroke: currentColor;
    stroke-width: 2; stroke-linecap: round;
}
.hubf-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 17px; height: 17px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    background: var(--color-accent);
    color: var(--color-bg-page);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
}

/* Chips: aktiva val, ett tapp för att släppa ett filter */
.hubf-chips {
    display: flex;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px 0;
    -webkit-overflow-scrolling: touch;
}
.hubf-chips::-webkit-scrollbar { display: none; }
.hubf-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
    height: 30px;
    padding: 0 9px 0 11px;
    border-radius: var(--radius-full);
    background: var(--color-accent-light);
    color: var(--color-accent-text);
    border: 1px solid var(--color-border);
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}
.hubf-chip svg {
    width: 12px; height: 12px;
    fill: none; stroke: currentColor;
    stroke-width: 2.4; stroke-linecap: round;
    opacity: .7;
}
.hubf-chip--clear {
    background: transparent;
    color: var(--color-text-muted);
    border-style: dashed;
    padding: 0 11px;
}

/* --- Fälten --- */
.hubf-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: 3px;
}
.hubf-select {
    width: 100%;
    /* 16px förhindrar att iOS zoomar in när fältet fokuseras */
    font-size: 16px;
    color: var(--color-text-primary);
    background-color: var(--color-bg-card);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 34px 10px 12px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23868fa2' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
}
.hubf-select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-light);
}

/* ============================================================
   MOBIL: bottenark
   ============================================================ */
@media (max-width: 767px) {
    .hubf { margin-bottom: var(--space-sm); }

    .hubf-scrim {
        position: fixed;
        inset: 0;
        z-index: 9998;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity .18s ease;
    }
    .hubf-sheet {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 9999;
        background: var(--color-bg-surface);
        border-top: 1px solid var(--color-border-strong);
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        padding: var(--space-xs) var(--space-md)
                 calc(var(--space-md) + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
        transform: translateY(100%);
        transition: transform .22s cubic-bezier(.22, 1, .36, 1);
        max-height: 82vh;
        overflow-y: auto;
    }
    .hubf-toggle:checked ~ .hubf-scrim { opacity: 1; visibility: visible; }
    .hubf-toggle:checked ~ .hubf-sheet { transform: translateY(0); }
    /* Lås bakgrundsscroll medan arket är öppet */
    html:has(.hubf-toggle:checked) body { overflow: hidden; }

    .hubf-sheet-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: var(--space-sm) 0 var(--space-xs);
        font-family: var(--font-heading, 'Oswald', sans-serif);
        font-size: 18px;
        letter-spacing: .02em;
        color: var(--color-text-primary);
    }
    /* Draghandtaget signalerar att arket går att svepa bort */
    .hubf-sheet-head::before {
        content: "";
        position: absolute;
        top: 8px; left: 50%;
        width: 36px; height: 4px;
        margin-left: -18px;
        border-radius: var(--radius-full);
        background: var(--color-border-strong);
    }
    .hubf-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px; height: 34px;
        margin-right: -6px;
        border-radius: var(--radius-full);
        color: var(--color-text-muted);
        cursor: pointer;
    }
    .hubf-close svg {
        width: 18px; height: 18px;
        fill: none; stroke: currentColor;
        stroke-width: 2.2; stroke-linecap: round;
    }

    .hubf-fields {
        display: flex;
        flex-direction: column;
        gap: var(--space-sm);
        padding: var(--space-xs) 0 var(--space-md);
    }
    .hubf-sheet-actions {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
        padding-bottom: var(--space-xs);
    }
    .hubf-reset {
        flex-shrink: 0;
        padding: 12px 4px;
        font-size: 14px;
        font-weight: 600;
        color: var(--color-text-muted);
        text-decoration: none;
    }
    .hubf-apply {
        flex: 1;
        min-height: 48px;
        border: none;
        border-radius: var(--radius-md);
        background: var(--color-accent);
        color: var(--color-bg-page);
        font-size: 15px;
        font-weight: 700;
        letter-spacing: .02em;
        cursor: pointer;
    }
}

/* ============================================================
   DESKTOP: inline-rad, inget ark
   ============================================================ */
@media (min-width: 768px) {
    .hubf-compact,
    .hubf-scrim,
    .hubf-sheet-head,
    .hubf-sheet-actions { display: none; }

    .hubf-sheet { display: block; }
    .hubf-fields {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-sm);
        align-items: flex-end;
    }
    .hubf-field { width: 170px; }
    .hubf-select { font-size: 13px; padding: 7px 30px 7px 11px; }
}
