.safa-mediatheque {
    --safa-media-navy: #0A335B;
    --safa-media-blue: #32ACE1;
    --safa-media-yellow: #FCD116;
    --safa-media-gap: 18px;
    --safa-media-columns: 4;
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

.safa-mediatheque *,
.safa-mediatheque *::before,
.safa-mediatheque *::after { box-sizing: border-box; }

.safa-mediatheque__tabs {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 30px;
}

.safa-mediatheque__tab {
    appearance: none;
    border: 1px solid rgba(10,51,91,.12);
    background: #fff;
    color: var(--safa-media-navy);
    min-height: 42px;
    padding: 10px 18px;
    border-radius: 999px;
    font: inherit;
    font-size: 13px;
    line-height: 1.2;
    font-weight: 700;
    cursor: pointer;
    transition: background .25s ease, color .25s ease, border-color .25s ease, transform .25s ease, box-shadow .25s ease;
    box-shadow: 0 7px 20px rgba(13,39,70,.06);
}

.safa-mediatheque__tab:hover {
    transform: translateY(-1px);
    border-color: rgba(10,51,91,.25);
    box-shadow: 0 9px 24px rgba(13,39,70,.10);
}

.safa-mediatheque__tab.is-active {
    background: var(--safa-media-yellow);
    color: var(--safa-media-navy);
    border-color: var(--safa-media-yellow);
    box-shadow: 0 10px 24px rgba(252,209,22,.20);
}

.safa-mediatheque__grid {
    width: 100%;
    columns: var(--safa-media-columns);
    column-gap: var(--safa-media-gap);
}

.safa-mediatheque__item {
    width: 100%;
    display: inline-block;
    break-inside: avoid;
    margin: 0 0 var(--safa-media-gap);
    vertical-align: top;
    will-change: transform, opacity;
}

.safa-mediatheque__item[hidden] { display: none !important; }

.safa-mediatheque__card {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    margin: 0;
    border: 0;
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    background: #EDF4F8;
    box-shadow: 0 10px 28px rgba(13,39,70,.12);
    text-align: left;
    isolation: isolate;
}

.safa-mediatheque__media {
    display: block;
    width: 100%;
    height: auto;
    min-height: 120px;
    object-fit: cover;
    transition: transform .5s cubic-bezier(.2,.65,.25,1), filter .35s ease;
}

.safa-mediatheque__card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, transparent 45%, rgba(4,29,53,.80) 100%);
    opacity: .55;
    transition: opacity .35s ease;
    pointer-events: none;
    z-index: 1;
}

.safa-mediatheque__card:hover .safa-mediatheque__media {
    transform: scale(1.035);
    filter: saturate(1.03) contrast(1.02);
}

.safa-mediatheque__card:hover::after { opacity: .78; }

.safa-mediatheque__meta {
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 15px;
    z-index: 3;
    color: #fff;
    transform: translateY(5px);
    transition: transform .3s ease;
    pointer-events: none;
}

.safa-mediatheque__card:hover .safa-mediatheque__meta { transform: translateY(0); }

.safa-mediatheque__title {
    display: block;
    font-size: 15px;
    line-height: 1.25;
    font-weight: 750;
    margin: 0;
}

.safa-mediatheque__caption {
    display: block;
    margin-top: 4px;
    font-size: 11.5px;
    line-height: 1.35;
    opacity: .86;
}

.safa-mediatheque__type {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 4;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(10,51,91,.88);
    color: #fff;
    box-shadow: 0 8px 20px rgba(10,51,91,.22);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.safa-mediatheque__type svg { width: 16px; height: 16px; fill: currentColor; }
.safa-mediatheque__item[data-media-type="image"] .safa-mediatheque__type { background: rgba(252,209,22,.94); color: var(--safa-media-navy); }

.safa-mediatheque__empty {
    padding: 28px;
    border: 1px dashed rgba(10,51,91,.24);
    border-radius: 16px;
    color: #607087;
    background: #F7FAFC;
    text-align: center;
}

/* Lightbox */
.safa-mediatheque-lightbox {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 28px;
    background: rgba(5,25,45,.91);
    opacity: 0;
    transition: opacity .22s ease;
}

.safa-mediatheque-lightbox.is-open { display: flex; opacity: 1; }
.safa-mediatheque-lightbox__stage { width: min(1220px, 94vw); max-height: 90vh; position: relative; display: flex; flex-direction: column; align-items: center; }
.safa-mediatheque-lightbox__media-wrap { width: 100%; min-height: 180px; display: flex; align-items: center; justify-content: center; }
.safa-mediatheque-lightbox__image,
.safa-mediatheque-lightbox__video,
.safa-mediatheque-lightbox__iframe {
    display: block;
    max-width: 100%;
    max-height: 78vh;
    border: 0;
    border-radius: 14px;
    box-shadow: 0 26px 70px rgba(0,0,0,.35);
    background: #000;
}
.safa-mediatheque-lightbox__iframe { width: min(1120px, 88vw); aspect-ratio: 16 / 9; max-height: 76vh; }
.safa-mediatheque-lightbox__video { width: min(1120px, 88vw); }
.safa-mediatheque-lightbox__info { width: min(980px, 88vw); color: #fff; text-align: center; padding-top: 14px; }
.safa-mediatheque-lightbox__title { font-size: 17px; line-height: 1.3; font-weight: 750; }
.safa-mediatheque-lightbox__caption { margin-top: 4px; font-size: 12.5px; line-height: 1.5; color: rgba(255,255,255,.72); }
.safa-mediatheque-lightbox__close,
.safa-mediatheque-lightbox__nav {
    appearance: none;
    border: 1px solid rgba(255,255,255,.22);
    color: #fff;
    background: rgba(10,51,91,.74);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: transform .2s ease, background .2s ease;
}
.safa-mediatheque-lightbox__close:hover,
.safa-mediatheque-lightbox__nav:hover { transform: scale(1.05); background: var(--safa-media-navy); }
.safa-mediatheque-lightbox__close { position: absolute; top: 18px; right: 18px; width: 44px; height: 44px; border-radius: 50%; z-index: 4; font-size: 26px; line-height: 1; }
.safa-mediatheque-lightbox__nav { position: absolute; top: 50%; width: 46px; height: 64px; margin-top: -32px; border-radius: 15px; z-index: 4; font-size: 27px; }
.safa-mediatheque-lightbox__prev { left: 18px; }
.safa-mediatheque-lightbox__next { right: 18px; }
body.safa-mediatheque-no-scroll { overflow: hidden !important; }

@media (max-width: 1024px) {
    .safa-mediatheque { --safa-media-columns: 3; }
    .safa-mediatheque__tabs { margin-bottom: 24px; }
}

@media (max-width: 767px) {
    .safa-mediatheque { --safa-media-columns: 2; --safa-media-gap: 12px; }
    .safa-mediatheque__tabs { gap: 8px; margin-bottom: 18px; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 5px; scrollbar-width: none; }
    .safa-mediatheque__tabs::-webkit-scrollbar { display: none; }
    .safa-mediatheque__tab { flex: 0 0 auto; min-height: 38px; padding: 9px 14px; font-size: 12px; }
    .safa-mediatheque__card { border-radius: 14px; }
    .safa-mediatheque__meta { left: 12px; right: 12px; bottom: 10px; }
    .safa-mediatheque__title { font-size: 12.5px; }
    .safa-mediatheque__caption { display: none; }
    .safa-mediatheque__type { width: 32px; height: 32px; top: 10px; right: 10px; }
    .safa-mediatheque-lightbox { padding: 16px; }
    .safa-mediatheque-lightbox__close { top: 10px; right: 10px; }
    .safa-mediatheque-lightbox__nav { width: 38px; height: 52px; margin-top: -26px; font-size: 22px; }
    .safa-mediatheque-lightbox__prev { left: 8px; }
    .safa-mediatheque-lightbox__next { right: 8px; }
}
.safa-mediatheque--no-meta .safa-mediatheque__card::after { opacity: .08; }
.safa-mediatheque--no-meta .safa-mediatheque__card:hover::after { opacity: .18; }
.safa-mediatheque__card--no-meta::after { opacity: .04; }
.safa-mediatheque__card--no-meta:hover::after { opacity: .12; }
