/*
 * KAM Media Library – Frontend (Club Presse Adaptation)
 */

:root {
    --kml-primary: #1D3D70;
    --kml-secondary: #8DC63F;
    --kml-accent: #B89C3F;
    --kml-bg-dark: rgba(13, 27, 50, 0.95);
    --kml-text-light: #ffffff;
    --kml-text-muted: rgba(255, 255, 255, 0.7);
    --kml-radius: 16px;
    --kml-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    --kml-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Carte ───────────────────────────────────────────────────────────────── */
.kml-card {
    position: relative;
    background: #fff;
    border-radius: var(--kml-radius);
    border: 1px solid var(--bs-border-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    cursor: pointer;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 100%;
    transition: var(--kml-transition);
    text-decoration: none !important;
}

.kml-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 30px rgba(0,0,0,0.1);
}

.kml-card__thumb {
    position: relative;
    height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f0f2f5;
}

.kml-card__img { 
    width: 100%; height: 100%; 
    object-fit: cover; 
    transition: transform 0.6s ease; 
}
.kml-card:hover .kml-card__img { transform: scale(1.1); }

.kml-card__icon {
    width: 60px;
    height: 75px;
    background: var(--kml-primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.kml-card__ext { font-size: 12px; font-weight: 800; color: #fff; text-transform: uppercase; }

.kml-card__badge {
    position: absolute;
    top: 12px; right: 12px;
    background: var(--kml-secondary);
    color: var(--kml-primary);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 50px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.kml-card__body {
    padding: 20px;
    flex: 1;
}

.kml-card__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--kml-primary);
    line-height: 1.4;
    margin: 0 0 8px 0;
}

.kml-card__date {
    font-size: 0.85rem;
    color: #6c757d;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Locked state on card */
.kml-card--locked .kml-card__img { filter: blur(6px) grayscale(0.5); opacity: 0.7; }
.kml-card--locked .kml-card__thumb::after {
    content: '\F473'; /* ph-lock */
    font-family: "Phosphor";
    position: absolute;
    font-size: 2.5rem;
    color: var(--kml-accent);
    text-shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* ── Modal (High-End Club Presse) ────────────────────────────────────────── */
.kml-modal {
    position: fixed; inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.kml-modal.is-open { pointer-events: all; opacity: 1; }

/* In-page version of the modal (Single media page) */
.kml-modal.kml-modal--page {
    position: relative;
    inset: auto;
    z-index: 1;
    min-height: calc(100vh - 300px);
    padding: 40px 20px;
    background: transparent;
    margin-top: var(--cp-header-height) !important;
}
.kml-modal.kml-modal--page .kml-modal__box {
    width: 100%;
    margin: 0 auto;
    height: auto;
    min-height: 60vh;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08);
    transform: none; /* remove entry animation scale */
}


.kml-modal__overlay {
    position: absolute; inset: 0;
    background: var(--kml-bg-dark);
    backdrop-filter: blur(3px);
}

.kml-modal__box {
    position: relative; z-index: 1;
    width: 90vw; max-width: 1200px; height: 85vh;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--kml-shadow);
    transform: scale(0.9) translateY(40px);
    transition: transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.kml-modal.is-open .kml-modal__box { transform: scale(1) translateY(0); }

.kml-modal__header {
    background: #fff;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    height: 80px;
    flex-shrink: 0;
}

.kml-modal__file-info { flex: 1; min-width: 0; }
.kml-modal__filename { 
    color: var(--kml-primary); 
    font-weight: 800; 
    font-size: 1.2rem; 
    display: block; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    white-space: nowrap; 
}
.kml-modal__filemeta { color: #6c757d; font-size: 0.9rem; }

.kml-modal__icon-btn {
    background: var(--bs-border-color);
    border: none;
    color: var(--kml-primary);
    width: 48px; height: 48px;
    border-radius: 12px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--kml-transition);
    font-size: 1.4rem;
    flex-shrink: 0;
}
.kml-modal__icon-btn:hover { background: #e9ecef; }

.kml-modal__actions { display: flex; align-items: center; gap: 12px; }

.kml-modal__action-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    background: var(--kml-primary);
    color: #fff;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
    transition: var(--kml-transition);
}

.kml-modal__action-btn:hover { background: #16305a; transform: translateY(-2px); color: #fff; }
.kml-modal__download { background: var(--kml-secondary) !important; color: var(--kml-primary) !important; }
.kml-modal__download:hover { background: #7db137 !important; }

/* Modal Body */
.kml-modal__body {
    flex: 1;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.kml-modal__content { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }

/* Preview elements */
.kml-preview-image { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity 0.3s ease; background-color: var(--bs-body-bg) }
.kml-preview-video { width: 90%; max-height: 90%; border-radius: 12px; background: #000; box-shadow: 0 15px 45px rgba(0,0,0,0.2); }
.kml-preview-pdf   { width: 100%; height: 100%; border: none; }

/* Locked content in modal */
.kml-modal-locked-overlay {
    text-align: center;
    padding: 60px 40px;
    max-width: 550px;
    background: #fff;
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
    height: 100% !important;
}

.kml-lock-icon-wrap {
    width: 120px; height: 120px;
    background: var(--kml-primary);
    color: var(--kml-secondary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 30px;
    font-size: 3.5rem;
    box-shadow: 0 10px 30px rgba(29, 61, 112, 0.3);
}

.kml-locked-title { color: var(--kml-primary); font-weight: 800; font-size: 1.8rem; margin-bottom: 15px; }
.kml-locked-text { color: #6c757d; font-size: 1.1rem; margin-bottom: 30px; }

/* Gallery */
.kml-gallery { width: 100%; height: 100%; display: flex; flex-direction: column; }
.kml-gallery__main { background: #0a0e14; position: relative; display: flex; align-items: center; justify-content: center; height: 550px; }
.kml-gallery__img { max-width: 100%; max-height: 100%; object-fit: contain; transition: opacity 0.3s ease; background-color: var(--bs-body-bg); }
.kml-gallery__thumb-lock {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bs-body-bg);
}

.kml-gallery__nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); color: #fff;
    width: 60px; height: 60px; border-radius: 50%; cursor: pointer;
    font-size: 1.8rem; transition: all 0.3s;
    display: flex; align-items: center; justify-content: center;
}
.kml-gallery__nav:hover { background: var(--kml-secondary); color: var(--kml-primary); border-color: var(--kml-secondary); }
.kml-gallery__prev { left: 30px; }
.kml-gallery__next { right: 30px; }

.kml-gallery__counter {
    position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.5); color: #fff; padding: 6px 16px; border-radius: 50px;
    font-size: 0.9rem; font-weight: 600; backdrop-filter: blur(4px);
}

.kml-gallery__thumbs { 
    display: flex; gap: 15px; padding: 20px 30px; background: #fff; 
    overflow-x: auto; border-top: 1px solid rgba(0,0,0,0.05); 
    scrollbar-width: thin;
}
.kml-gallery__thumbs::-webkit-scrollbar { height: 4px; }
.kml-gallery__thumbs::-webkit-scrollbar-thumb { background: #dee2e6; border-radius: 10px; }

.kml-gallery__thumb { 
    width: 80px; height: 80px; border-radius: 12px; 
    overflow: hidden; cursor: pointer; border: 4px solid transparent; 
    flex-shrink: 0; transition: var(--kml-transition);
}
.kml-gallery__thumb.is-active { border-color: var(--kml-secondary); transform: scale(1.05); }
.kml-gallery__thumb img { width: 100%; height: 100%; object-fit: cover; }

/* Info Dropdown */
.kml-modal__info-dropdown {
    position: absolute; top: 90px; right: 30px; width: 320px;
    background: #fff; border-radius: 16px; box-shadow: 0 15px 40px rgba(0,0,0,0.2);
    padding: 24px; opacity: 0; visibility: hidden; transform: translateY(10px);
    transition: var(--kml-transition); border: 1px solid rgba(0,0,0,0.05);
    z-index: 10;
}
.kml-modal__info-dropdown.is-open { opacity: 1; visibility: visible; transform: none; }
.kml-info-title { color: var(--kml-primary); font-weight: 800; margin-bottom: 15px; font-size: 1rem; border-bottom: 2px solid var(--kml-secondary); display: inline-block; }
.kml-info-item { display: flex; justify-content: space-between; font-size: 0.9rem; margin-bottom: 10px; border-bottom: 1px dashed #eee; padding-bottom: 5px; }
.kml-info-label { color: #6c757d; }
.kml-info-value { color: var(--kml-primary); font-weight: 700; }

/* Pagination */
.kml-pagination { display: flex; align-items: center; gap: 8px; }
.kml-pagination a, .kml-pagination span {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    border-radius: 10px; background: #fff; border: 1px solid #dee2e6;
    color: var(--kml-primary); text-decoration: none; font-weight: 700;
    transition: var(--kml-transition);
}
.kml-pagination a:hover { background: #f8f9fa; border-color: var(--kml-primary); }
.kml-pagination .current { background: var(--kml-primary); color: #fff; border-color: var(--kml-primary); }

@media (max-width: 768px) {
    .kml-modal__box { width: 100%; height: 100%; border-radius: 0; }
    .kml-gallery__nav { width: 40px; height: 40px; font-size: 1.2rem; }
}

/* =============================================
   Toast notification "Lien copié !"
   ============================================= */
.kml-toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    z-index: 99999;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    background: #1D3D70;
    color: #fff;
    border-radius: 100px;
    font-family: 'Montserrat', sans-serif;
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    box-shadow: 0 8px 24px rgba(29, 61, 112, 0.25);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
}

.kml-toast::before {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.kml-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* =============================================
   Preview document (non-previewable format)
   ============================================= */
.kml-preview-doc {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 32px;
    text-align: center;
    width: 100%;
}

.kml-preview-doc__icon {
    width: 96px;
    height: 96px;
    background: #D7E184;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.kml-preview-doc__ext {
    font-family: 'Montserrat', sans-serif;
    font-weight: 800;
    font-size: 18px;
    color: #1D3D70;
    letter-spacing: 1px;
}

.kml-preview-doc__name {
    font-family: 'Montserrat', sans-serif;
    font-weight: 700;
    font-size: 16px;
    color: #1D3D70;
    margin: 0;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kml-preview-doc__meta {
    font-size: 13px;
    color: #94a3b8;
    margin: 0;
}

.kml-preview-doc__notice {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 14px 20px;
    max-width: 360px;
    color: #64748b;
    font-size: 13px;
    line-height: 1.6;
}

/* =============================================
   Preview audio
   ============================================= */
.kml-preview-audio-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 48px 32px;
    width: 100%;
    text-align: center;
}

.kml-preview-audio-icon {
    width: 96px;
    height: 96px;
    background: linear-gradient(135deg, #1D3D70 0%, #006EFF 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.kml-preview-audio {
    width: 100%;
    max-width: 500px;
    border-radius: 50px;
    outline: none;
}

/* =============================================
   Responsive Adjustments
   ============================================= */
@media (max-width: 991px) {
    .kml-modal__box {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    .kml-modal.kml-modal--page {
        padding: 20px 10px;
    }

    .kml-modal.kml-modal--page .kml-modal__box {
        height: auto;
    }

    .kml-modal__header {
        padding: 15px 15px;
        height: auto;
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .kml-modal__header > .d-flex:first-child {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: nowrap;
        overflow: hidden;
    }
    
    .kml-modal__header > .d-flex:last-child {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .kml-modal__file-info {
        flex: 1;
        min-width: 0;
        text-align: left;
    }

    .kml-modal__filename {
        font-size: 1rem;
    }

    .kml-modal__header .btn span,
    .kml-modal__action-btn span {
        display: none;
    }
    
    .kml-modal__header .btn {
        padding: 0;
        width: 48px;
        height: 48px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 12px;
    }

    .kml-modal__header .btn svg {
        width: 20px;
        height: 20px;
    }

    .kml-gallery__main {
        height: 350px;
    }

    .kml-modal-locked-overlay {
        padding: 30px 20px;
        width: 100%;
    }

    .kml-lock-icon-wrap {
        width: 80px;
        height: 80px;
    }

    .kml-modal-locked-overlay h3 {
        font-size: 1.15rem;
    }

    .kml-gallery__thumb {
        width: 60px;
        height: 60px;
    }
}

@media (max-width: 576px) {
    .kml-gallery__main {
        height: 250px;
    }
    
    .kml-gallery__nav {
        width: 36px;
        height: 36px;
    }
}

/* ─── Médias attachés à un article (shortcode [kml_attached_media]) ─── */
.single-post-attachments-title {
    font-size: 20px;
    font-weight: 700;
    color: #1D3D70;
    margin: 0 0 18px 0;
    display: inline-flex;
    align-items: center;
}

.kml-frontend-media.kml-frontend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin: 0;
}

.kml-frontend-media.kml-frontend-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kml-frontend-item {
    background: #fff;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow 0.2s, transform 0.2s;
}

.kml-frontend-item:hover {
    box-shadow: 0 6px 18px rgba(28, 59, 114, 0.12);
    transform: translateY(-2px);
}

.kml-frontend-preview {
    aspect-ratio: 16 / 10;
    overflow: hidden;
    background: #F3F4F6;
}

.kml-frontend-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.kml-frontend-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16 / 10;
    background: linear-gradient(135deg, #f3f9e8 0%, #e7f0d6 100%);
    color: #1D3D70;
}

.kml-frontend-icon .dashicons {
    font-size: 56px;
    width: 56px;
    height: 56px;
    line-height: 1;
    opacity: 0.7;
}

.kml-frontend-info {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kml-frontend-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #1D3D70;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.kml-frontend-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    color: #6B7280;
}

.kml-frontend-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bs-primary, #8bc34a);
    color: #1D3D70 !important;
    text-decoration: none;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    align-self: flex-start;
    margin-top: 4px;
    transition: background 0.2s;
}

.kml-frontend-download:hover {
    background: #7FB339;
    color: #1D3D70 !important;
}

.kml-frontend-download .dashicons {
    width: 16px;
    height: 16px;
    font-size: 16px;
    line-height: 1;
}

/* Layout liste compact (pour [kml_attached_media layout="list"]) */
.kml-frontend-media.kml-frontend-list .kml-frontend-item {
    flex-direction: row;
    align-items: center;
}

.kml-frontend-media.kml-frontend-list .kml-frontend-preview,
.kml-frontend-media.kml-frontend-list .kml-frontend-icon {
    width: 80px;
    height: 80px;
    aspect-ratio: 1;
    flex: 0 0 80px;
}

.kml-frontend-media.kml-frontend-list .kml-frontend-info {
    flex: 1;
    padding: 12px 16px;
}

/* Mode "fichiers indépendants" : liste de liens directs */
.kml-frontend-links {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kml-frontend-link-item {
    margin: 0;
}

.kml-frontend-link {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    color: #1D3D70;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
    width: 100%;
    max-width: 100%;
}

.kml-frontend-link:hover {
    background: #F3F9E8;
    border-color: var(--bs-primary, #8bc34a);
    color: #1D3D70;
    transform: translateX(2px);
}

.kml-frontend-link .dashicons {
    width: 20px;
    height: 20px;
    font-size: 20px;
    line-height: 1;
    color: var(--bs-primary, #8bc34a);
    flex-shrink: 0;
}

.kml-frontend-link-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kml-frontend-link-size {
    color: #6B7280;
    font-size: 12px;
    font-weight: 400;
    flex-shrink: 0;
}
