/* ============================================================
   Resources Modal — Simple preview with always-visible fallback
   ============================================================ */

:root {
    --bh-resource-modal-z: 99999;
    --bh-resource-overlay: rgba(11, 11, 14, 0.75);
    --bh-resource-shadow: 0 8px 60px rgba(0, 0, 0, 0.35);
}

/* ── Modal container ─────────────────────────────────────────── */
.bh-resource-modal {
    position: fixed;
    inset: 0;
    z-index: var(--bh-resource-modal-z);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.bh-resource-modal.is-open {
    display: flex;
}

.bh-resource-modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bh-resource-overlay);
    backdrop-filter: blur(4px);
    cursor: pointer;
}

/* ── Modal box ──────────────────────────────────────────────── */
.bh-resource-modal-box {
    position: relative;
    z-index: 1;
    background: var(--bh-paper, #fff);
    border-radius: 12px;
    box-shadow: var(--bh-resource-shadow);
    width: 100%;
    max-width: 960px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: bh-resource-modal-slide-in 0.2s ease;
}

@keyframes bh-resource-modal-slide-in {
    from { opacity: 0; transform: translateY(16px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Header ──────────────────────────────────────────────────── */
.bh-resource-modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--bh-line-dark, #e5e7eb);
    flex-shrink: 0;
    background: var(--bh-paper, #fff);
}

.bh-resource-modal-title {
    flex: 1;
    font-family: var(--bh-font-display, 'Raleway', sans-serif);
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--bh-ink, #1a1a1a);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bh-resource-modal-title .bh-resource-badge {
    font-family: var(--bh-font-mono, monospace);
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.2em 0.6em;
    border-radius: 3px;
    background: var(--bh-paper-dim, #f3f4f6);
    color: var(--bh-slate, #6b7280);
    flex-shrink: 0;
}

.bh-resource-modal-title .bh-resource-badge.video {
    background: #fee2e2;
    color: #dc2626;
}

.bh-resource-modal-title .bh-resource-badge.link {
    background: #dbeafe;
    color: #2563eb;
}

.bh-resource-modal-title .bh-resource-badge.pdf {
    background: #fee2e2;
    color: #dc2626;
}

.bh-resource-modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.bh-resource-modal-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 14px;
    font-family: var(--bh-font-mono, monospace);
    font-size: 0.75rem;
    border: 1px solid var(--bh-line-dark, #e5e7eb);
    border-radius: 6px;
    background: var(--bh-paper, #fff);
    color: var(--bh-ink, #1a1a1a);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    text-decoration: none;
}

.bh-resource-modal-btn:hover {
    background: var(--bh-paper-dim, #f3f4f6);
}

.bh-resource-modal-btn.primary {
    background: var(--bh-red, #D7263D);
    border-color: var(--bh-red, #D7263D);
    color: #fff;
}

.bh-resource-modal-btn.primary:hover {
    background: var(--bh-red-deep, #a91930);
    border-color: var(--bh-red-deep, #a91930);
}

.bh-resource-modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--bh-slate, #6b7280);
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

.bh-resource-modal-close:hover {
    background: var(--bh-paper-dim, #f3f4f6);
    color: var(--bh-ink, #1a1a1a);
}

/* ── Body / iframe ───────────────────────────────────────────── */
.bh-resource-modal-body {
    flex: 1;
    overflow: hidden;
    min-height: 0;
    background: var(--bh-paper-dim, #f9fafb);
    position: relative;
}

.bh-resource-modal-body iframe {
    width: 100%;
    height: 100%;
    min-height: 55vh;
    border: none;
    display: block;
}

.bh-resource-modal-body .bh-resource-image-view {
    display: none;
    width: 100%;
    height: 100%;
    min-height: 55vh;
    object-fit: contain;
    background: var(--bh-paper-dim, #f9fafb);
}

/* Show image view when JS adds .is-visible */
.bh-resource-modal-body .bh-resource-image-view.is-visible {
    display: block;
}

/* ── Loading indicator ───────────────────────────────────────── */
.bh-resource-modal-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--bh-slate, #6b7280);
    background: var(--bh-paper-dim, #f9fafb);
    pointer-events: none;
    z-index: 2;
}

/* Hidden when JS adds .hidden class */
.bh-resource-modal-loading.hidden {
    display: none !important;
}

/* ── Embed error notice ──────────────────────────────────────── */
.bh-resource-modal-embed-error {
    display: none;
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 2rem;
    text-align: center;
    background: var(--bh-paper-dim, #f9fafb);
    z-index: 2;
}

.bh-resource-modal-embed-error p {
    color: var(--bh-slate, #6b7280);
    font-size: 0.9rem;
    margin: 0;
}

/* Show error block when JS adds .is-visible */
.bh-resource-modal-embed-error.is-visible {
    display: flex;
}

/* ── Fallback notice ──────────────────────────────────────────── */
.bh-resource-modal-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--bh-line-dark, #e5e7eb);
    background: var(--bh-paper-dim, #f9fafb);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.bh-resource-modal-footer .bh-resource-modal-fallback-text {
    font-size: var(--bh-size-small, 0.875rem);
    color: var(--bh-slate, #6b7280);
    display: flex;
    align-items: center;
    gap: 6px;
}

.bh-resource-modal-footer .bh-resource-modal-fallback-text .icon {
    font-size: 1rem;
    color: var(--bh-amber, #e8a33d);
}

.bh-resource-modal-footer .bh-resource-modal-actions-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* ── Button visibility ────────────────────────────────────────── */
/* Hidden by default */
#bh-resource-modal-open {
    display: none !important;
}

/* Visible when JS adds the class */
#bh-resource-modal-open.is-visible {
    display: inline-flex !important;
}

/* ── Open button specific ──────────────────────────────────────── */
#bh-resource-modal-open {
    background: var(--bh-red, #D7263D);
    border-color: var(--bh-red, #D7263D);
    color: #fff;
}

#bh-resource-modal-open:hover {
    background: var(--bh-red-deep, #a91930);
    border-color: var(--bh-red-deep, #a91930);
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 640px) {
    .bh-resource-modal {
        padding: 10px;
    }
    .bh-resource-modal-box {
        max-height: calc(100vh - 20px);
        border-radius: 10px;
    }
    .bh-resource-modal-body iframe {
        min-height: 40vh;
    }
    .bh-resource-modal-title {
        font-size: 0.82rem;
    }
    .bh-resource-modal-btn {
        font-size: 0.7rem;
        padding: 4px 10px;
    }
    .bh-resource-modal-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .bh-resource-modal-footer .bh-resource-modal-actions-right {
        justify-content: flex-start;
    }
}