/**
 * Espace de téléchargement B2B - Celtiis Business
 * Template : page-downloads.php
 * Selector root : .cb-downloads
 *
 * Même logique que la page Blog : barre latérale de filtres, barre de
 * recherche et de tri, cards à boutons ronds. Palette navy #002f87 / vert #8DC63F.
 */

.cb-downloads {
    --cbd-primary: #002f87;
    --cbd-accent: #8DC63F;
    --cbd-bg: #f4f6fa;
    --cbd-card: #ffffff;
    --cbd-border: #e1e5ed;
    --cbd-text: #1a1a1a;
    --cbd-muted: #5b6475;
    --cbd-soft: #eef2f9;
    background: var(--cbd-bg);
    font-family: 'Montserrat', 'Gotham', sans-serif;
}

.cb-downloads__body {
    padding: 50px 0;
}

/* Mise en page : filtres à gauche, documents à droite */

.cb-downloads__layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    align-items: start;
    gap: 28px;
}

.cb-downloads__main {
    min-width: 0;
    scroll-margin-top: 24px;
}

/* Barre latérale */

.cb-downloads__sidebar {
    position: sticky;
    top: 24px;
    padding: 4px 22px 22px;
    border: 1px solid var(--cbd-border);
    border-radius: 16px;
    background: var(--cbd-card);
}

.cb-downloads__panel {
    padding: 20px 0;
    border-bottom: 1px solid var(--cbd-border);
}

.cb-downloads__panel-title {
    margin: 0 0 12px;
    color: var(--cbd-primary);
    font-family: 'Gotham', 'Montserrat', sans-serif;
    font-size: 15px;
    font-weight: 700;
}

.cb-downloads__filter-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.cb-downloads__filter-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 9px 9px 14px;
    border-radius: 999px;
    color: var(--cbd-primary);
    font-size: 14px;
    font-weight: 400;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.cb-downloads__filter-link i {
    flex: 0 0 auto;
    font-size: 18px;
}

.cb-downloads__filter-name {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.cb-downloads__filter-link:hover {
    background: var(--cbd-soft);
    color: var(--cbd-primary);
}

.cb-downloads__filter-link.is-active {
    background: var(--cbd-primary);
    color: #fff;
}

.cb-downloads__filter-count {
    flex: 0 0 auto;
    min-width: 24px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--cbd-soft);
    color: var(--cbd-muted);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.cb-downloads__filter-link.is-active .cb-downloads__filter-count {
    background: rgba(255, 255, 255, 0.22);
    color: #fff;
}

.cb-downloads__reset {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 46px;
    margin-top: 18px;
    border-radius: 999px;
    background: var(--cbd-accent);
    color: var(--cbd-primary);
    font-size: 14.5px;
    font-weight: 500;
    text-decoration: none;
    transition: filter 0.15s ease, opacity 0.15s ease;
}

.cb-downloads__reset:hover {
    color: var(--cbd-primary);
    filter: brightness(0.95);
}

.cb-downloads__reset.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

/* Bouton d'ouverture des filtres (mobile) */

.cb-downloads__sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    height: 48px;
    margin-bottom: 16px;
    border: 1px solid var(--cbd-border);
    border-radius: 999px;
    background: #fff;
    color: var(--cbd-primary);
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
}

/* Barre du haut : recherche + tri */

.cb-downloads__toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 18px;
}

.cb-downloads__search {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.cb-downloads__search-label {
    position: absolute;
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    margin: 0;
    color: var(--cbd-muted);
    font-size: 18px;
    line-height: 1;
    pointer-events: none;
}

.cb-downloads__search-input {
    width: 100%;
    height: 48px;
    padding: 0 16px 0 46px;
    border: 1px solid var(--cbd-border);
    border-radius: 999px;
    background: #fff;
    color: var(--cbd-text);
    font-family: inherit;
    font-size: 14.5px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cb-downloads__search-input:focus {
    border-color: var(--cbd-primary);
    box-shadow: 0 0 0 3px rgba(0, 47, 135, 0.1);
}

.cb-downloads__search-input::placeholder {
    color: var(--cbd-muted);
    opacity: 0.75;
}

.cb-downloads__sort {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    margin: 0;
}

.cb-downloads__sort i {
    position: absolute;
    left: 16px;
    color: var(--cbd-primary);
    font-size: 18px;
    pointer-events: none;
}

.cb-downloads__sort select {
    height: 48px;
    padding: 0 40px 0 44px;
    border: 1px solid var(--cbd-border);
    border-radius: 999px;
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 256 256'%3E%3Cpath fill='%23002f87' d='M213.66 101.66l-80 80a8 8 0 0 1-11.32 0l-80-80a8 8 0 0 1 11.32-11.32L128 164.69l74.34-74.35a8 8 0 0 1 11.32 11.32Z'/%3E%3C/svg%3E") no-repeat right 16px center;
    color: var(--cbd-primary);
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.cb-downloads__sort select:focus-visible {
    border-color: var(--cbd-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 47, 135, 0.1);
}

.cb-downloads__count {
    margin: 0 0 18px;
    color: var(--cbd-muted);
    font-size: 14px;
}

.cb-downloads__count strong {
    color: var(--cbd-primary);
}

/* Grille + états de chargement */

.cb-downloads__grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}

.cb-downloads__results {
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.cb-downloads__results.is-leaving {
    opacity: 0.45;
    transform: translateY(4px);
}

.cb-downloads__results.is-entering .cb-downloads__card {
    animation: cb-downloads-card-in 360ms ease both;
    animation-delay: calc(var(--cb-download-index, 0) * 45ms);
}

.cb-downloads.is-loading .cb-downloads__filter-link,
.cb-downloads.is-loading .cb-downloads__pagination a,
.cb-downloads.is-loading .cb-downloads__card-cat {
    pointer-events: none;
}

.cb-downloads.is-loading .cb-downloads__filter-link:not(.is-active) {
    opacity: 0.58;
}

@keyframes cb-downloads-card-in {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Card */

.cb-downloads__card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--cbd-border);
    border-radius: 16px;
    background: var(--cbd-card);
    transition: border-color 0.18s ease, transform 0.18s ease;
}

.cb-downloads__card:hover {
    border-color: rgba(0, 47, 135, 0.25);
}

.cb-downloads__preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 170px;
    overflow: hidden;
    border-bottom: 1px solid var(--cbd-border);
    background: var(--cbd-soft);
}

.cb-downloads__preview-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cb-downloads__card:hover .cb-downloads__preview-image {
    transform: scale(1.03);
}

/* Aperçu PDF : non cliquable, la fenêtre d'aperçu prend le relais. */
.cb-downloads__preview-frame {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
    pointer-events: none;
}

.cb-downloads__preview-icon {
    color: var(--cbd-primary);
    font-size: 64px;
    opacity: 0.85;
}

.cb-downloads__preview-ext {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--cbd-primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.cb-downloads__preview-ext.is-pdf { background: #c62828; }
.cb-downloads__preview-ext.is-doc { background: #1e5bc6; }
.cb-downloads__preview-ext.is-sheet { background: #1d7a43; }
.cb-downloads__preview-ext.is-slides { background: #c4511b; }
.cb-downloads__preview-ext.is-archive { background: #5b6475; }

.cb-downloads__card-body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 6px;
    padding: 18px 20px 16px;
}

.cb-downloads__card-cat {
    align-self: flex-start;
    color: #7a869a;
    font-size: 13.5px;
    font-weight: 400;
    text-decoration: none;
}

a.cb-downloads__card-cat:hover {
    color: var(--cbd-primary);
}

.cb-downloads__card-title {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--cbd-primary);
    font-family: 'Gotham', 'Montserrat', sans-serif;
    font-size: 16.5px;
    font-weight: 600;
    line-height: 1.35;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.cb-downloads__card-excerpt {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    color: var(--cbd-muted);
    font-size: 13.5px;
    line-height: 1.5;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}

.cb-downloads__card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: auto;
    padding-top: 12px;
}

.cb-downloads__card-meta {
    min-width: 0;
    overflow: hidden;
    color: #7a869a;
    font-size: 12.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cb-downloads__card-actions {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 8px;
}

/* Boutons ronds, comme sur les cards d'articles */
.cb-downloads__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1.5px solid var(--cbd-primary);
    border-radius: 50%;
    background: transparent;
    color: var(--cbd-primary);
    font-size: 18px;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, filter 0.15s ease;
}

.cb-downloads__action:hover,
.cb-downloads__action:focus-visible {
    background: rgba(0, 47, 135, 0.06);
    color: var(--cbd-primary);
}

.cb-downloads__action.is-primary {
    background: var(--cbd-primary);
    color: #fff;
}

.cb-downloads__action.is-primary:hover,
.cb-downloads__action.is-primary:focus-visible {
    color: #fff;
    filter: brightness(1.15);
}

.cb-downloads__action:focus-visible {
    outline: 2px solid var(--cbd-accent);
    outline-offset: 2px;
}

/* Modale d'aperçu. */
body.cb-downloads-preview-open {
    overflow: hidden;
}

.cb-downloads-preview-modal[hidden] {
    display: none;
}

.cb-downloads-preview-modal {
    position: fixed;
    z-index: 100000;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.cb-downloads-preview-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 17, 35, 0.82);
    backdrop-filter: blur(3px);
}

.cb-downloads-preview-modal__dialog {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: min(1100px, 100%);
    height: min(820px, calc(100vh - 48px));
    overflow: hidden;
    border-radius: 16px;
    background: #fff;
    animation: cb-downloads-preview-in 220ms ease both;
}

.cb-downloads-preview-modal__header,
.cb-downloads-preview-modal__footer {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 16px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--cbd-border);
}

.cb-downloads-preview-modal__header h2 {
    overflow: hidden;
    margin: 0;
    color: var(--cbd-text);
    font-family: 'Gotham', 'Montserrat', sans-serif;
    font-size: 17px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cb-downloads-preview-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-left: auto;
    border: 0;
    border-radius: 50%;
    background: #eef1f5;
    color: var(--cbd-primary);
    cursor: pointer;
    font-size: 20px;
}

.cb-downloads-preview-modal__content {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #e6e9ef;
}

.cb-downloads-preview-modal__content img,
.cb-downloads-preview-modal__content iframe,
.cb-downloads-preview-modal__content video {
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    object-fit: contain;
}

.cb-downloads-preview-modal__content audio {
    width: min(560px, calc(100% - 40px));
}

.cb-downloads-preview-modal__footer {
    justify-content: flex-end;
    border-top: 1px solid var(--cbd-border);
    border-bottom: 0;
}

.cb-downloads-preview-modal__download {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 10px 18px;
    border-radius: 999px;
    background: var(--cbd-primary);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.cb-downloads-preview-modal__download:hover {
    color: #fff;
    filter: brightness(1.08);
}

@keyframes cb-downloads-preview-in {
    from { opacity: 0; transform: translateY(12px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Pagination */

.cb-downloads__pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 48px;
}

.cb-downloads__pagination a,
.cb-downloads__pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    background: #fff;
    border: 1px solid var(--cbd-border);
    border-radius: 8px;
    color: var(--cbd-primary);
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.cb-downloads__pagination a:hover {
    border-color: var(--cbd-primary);
}

.cb-downloads__pagination .current {
    background: var(--cbd-primary);
    border-color: var(--cbd-primary);
    color: #fff;
}

/* Bloc Assistance (renderer partagé) */

.cb-downloads__assistance {
    background: #fff;
    padding-top: 10px;
    padding-bottom: 25px;
}

/* Empty state */

.cb-downloads__empty {
    padding: 64px 20px;
    text-align: center;
    background: #fff;
    border: 1px dashed var(--cbd-border);
    border-radius: 14px;
}

.cb-downloads__empty-icon {
    font-size: 56px;
    color: var(--cbd-primary);
    opacity: 0.4;
    display: inline-block;
    margin-bottom: 14px;
}

.cb-downloads__empty-title {
    margin: 0 0 0px;
    font-family: 'Gotham', 'Montserrat', sans-serif;
    font-size: 20px;
    font-weight: 700;
    color: var(--cbd-primary);
}

.cb-downloads__empty-lead {
    margin: 0 0 22px;
    color: var(--cbd-muted);
    font-size: 15px;
}

.cb-downloads__empty-btn {
    display: inline-block;
    padding: 10px 22px;
    background: var(--cbd-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
}

.cb-downloads__empty-btn:hover {
    color: #fff;
    filter: brightness(1.1);
}


/* Responsive */

@media (max-width: 1399px) {
    .cb-downloads__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 991px) {
    .cb-downloads__layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
    }

    .cb-downloads__sidebar {
        position: relative;
        top: auto;
        margin-bottom: 20px;
    }

    /* Repli uniquement quand le JS peut le rouvrir. */
    .cb-downloads.is-enhanced .cb-downloads__sidebar-toggle {
        display: flex;
    }

    .cb-downloads.is-enhanced .cb-downloads__sidebar {
        display: none;
    }

    .cb-downloads.is-enhanced.is-filters-open .cb-downloads__sidebar {
        display: block;
    }

    .cb-downloads__grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .cb-downloads__body {
        padding: 30px 0;
    }

    .cb-downloads__toolbar {
        flex-wrap: wrap;
    }

    .cb-downloads__sort,
    .cb-downloads__sort select {
        width: 100%;
    }

    .cb-downloads__grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .cb-downloads-preview-modal {
        padding: 0;
    }

    .cb-downloads-preview-modal__dialog {
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cb-downloads__results,
    .cb-downloads__results.is-entering .cb-downloads__card,
    .cb-downloads__preview-image {
        animation: none;
        transition: none;
    }

    .cb-downloads-preview-modal__dialog {
        animation: none;
    }
}

/* Date d'ajout : période libre (calendrier) */

.cb-downloads__range {
    position: relative;
}

.cb-downloads__range-input,
.cb-downloads__range .form-control {
    width: 100%;
    height: 46px;
    padding: 0 38px 0 14px;
    border: 1px solid var(--cbd-border);
    border-radius: 999px;
    background: #fff;
    color: var(--cbd-text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.cb-downloads__range-input:focus,
.cb-downloads__range .form-control:focus {
    border-color: var(--cbd-primary);
    box-shadow: 0 0 0 3px rgba(0, 47, 135, 0.1);
}

.cb-downloads__range-input::placeholder,
.cb-downloads__range .form-control::placeholder {
    color: var(--cbd-muted);
    opacity: 0.75;
}

.cb-downloads__range-icon {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    color: var(--cbd-muted);
    font-size: 17px;
    pointer-events: none;
}

/* Bouton « effacer » : prend la place de l'icône calendrier. */
.cb-downloads__range-clear {
    position: absolute;
    top: 50%;
    right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    transform: translateY(-50%);
    border-radius: 50%;
    background: var(--cbd-soft);
    color: var(--cbd-primary);
    font-size: 14px;
    text-decoration: none;
}

.cb-downloads__range-clear:hover {
    background: var(--cbd-primary);
    color: #fff;
}

.cb-downloads__range:has(.cb-downloads__range-clear) .cb-downloads__range-icon {
    display: none;
}

/* Repli sans JS ou sans calendrier : deux champs date natifs + Appliquer. */
.cb-downloads__range-fallback {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 8px 10px;
    margin-top: 12px;
    color: var(--cbd-muted);
    font-size: 13.5px;
}

.cb-downloads__range-fallback input[type="date"] {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--cbd-border);
    border-radius: 999px;
    color: var(--cbd-text);
    font-family: inherit;
    font-size: 13.5px;
}

.cb-downloads__range-apply {
    grid-column: 1 / -1;
    height: 40px;
    border: 0;
    border-radius: 999px;
    background: var(--cbd-primary);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.cb-downloads.is-enhanced .cb-downloads__range-fallback,
.cb-downloads:not(.is-enhanced) .cb-downloads__range {
    display: none;
}

.cb-downloads.is-enhanced.no-picker .cb-downloads__range-fallback {
    display: grid;
}

.cb-downloads.is-enhanced.no-picker .cb-downloads__range {
    display: none;
}
