/* SFM Related Videos Block Styles */

.sfm-related-videos {
    padding: 0;
}

.sfm-related-videos__container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0;
}

.sfm-related-videos__heading {
    font-size: 1.5rem;
    font-weight: 400;
    margin: 0 0 20px !important;
    color: var(--body-color);
}

.sfm-related-videos__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr));
    gap: 2rem;
}

.sfm-video-post__innerblock .wp-block-columns:last-of-type {
    margin-bottom: 0;
}

/* Card Styles */
.sfm-related-videos__card {
    background: var(--gray-100);
    border-radius: 8px;
    border: 1px solid var(--gray-300);
    overflow: hidden;
}

.sfm-related-videos__card-inner {
    padding: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sfm-related-videos__card-title {
    font-size: 18px;
    font-weight: bold !important;
    margin: 0 0 1rem !important;
    line-height: 1.4;
    color: var(--gray-800);
}

.sfm-related-videos__title-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: color 0.2s ease;
}

.sfm-related-videos__title-link:hover,
.sfm-related-videos__title-link:focus {
    color: #4299e1;
    text-decoration: underline;
    outline: none;
}

.sfm-related-videos__title-link:focus-visible {
    outline: 2px solid #4299e1;
    outline-offset: 2px;
}

.sfm-related-videos__title-link .ph {
    font-size: 1.125rem;
    flex-shrink: 0;
}

.sfm-related-videos__title-text {
    display: block;
}

/* Thumbnail Styles */
.sfm-related-videos__thumbnail-wrapper {
    position: relative;
    margin-bottom: 1rem;
    border-radius: 8px;
    aspect-ratio: 16 / 9;
    background: var(--primary-200);
    margin-top: auto !important;
}

.sfm-related-videos__thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: 8px;
}

.sfm-related-videos__play-button,
.sfm-related-videos__thumbnail-link {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s ease;
    border-radius: 8px;
}

.sfm-related-videos__play-button:hover,
.sfm-related-videos__play-button:focus,
.sfm-related-videos__thumbnail-link:hover,
.sfm-related-videos__thumbnail-link:focus {
    box-shadow: none !important;
}

.sfm-related-videos__play-button:focus-visible,
.sfm-related-videos__thumbnail-link:focus-visible {
    outline: 3px solid #4299e1;
    outline-offset: 2px;
}


.sfm-related-videos__play-button:hover .video-overlay,
.sfm-related-videos__thumbnail-link:hover .video-overlay {
    background-color: rgba(255, 255, 255, 0.2);
}

.sfm-related-videos__play-button .video-overlay,
.sfm-related-videos__thumbnail-link .video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 5;
    transition: background-color 0.3s ease;
}


.sfm-related-videos__play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: transform 0.2s
    ease;
    pointer-events: none;
    width: 70px;
    height: 70px;
    background-image: url(/wp-content/themes/sfm-blocks/blocks/youtube-video/play_button.svg);
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent;
}

.sfm-related-videos__play-button:hover .sfm-related-videos__play-icon,
.sfm-related-videos__thumbnail-link:hover .sfm-related-videos__play-icon {
    transform: translate(-50%, -50%) scale(1.1);
    background-image: url(/wp-content/themes/sfm-blocks/blocks/youtube-video/play_button_hover.svg);
}

/* Meta row (duration + share) */
.sfm-related-videos__meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

/* Duration */
.sfm-related-videos__duration {
    font-size: 12px;
    color: var(--gray-700);
    margin: 0;
}

/* Share button */
.sfm-related-videos__share-btn {
    background-color: var(--gray-300);
    border-radius: 0.25rem;
    font-size: 14px;
    color: var(--gray-800);
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    position: relative;
    transition: background-color 0.2s ease;
    margin-left: auto;
}

.sfm-related-videos__share-btn:hover,
.sfm-related-videos__share-btn:active,
.sfm-related-videos__share-btn:focus {
    background-color: var(--primary-400);
    box-shadow: none;
    color: var(--gray-800);
}

/* Share Popover Styles (scoped fallback if videos-grid not loaded) */
.share-popover {
    position: absolute;
    z-index: 9999;
    background: white;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 240px;
    max-width: 280px;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
    pointer-events: all;
}

.share-popover.show {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.share-popover-arrow {
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border: 1px solid var(--gray-300);
    transform: rotate(45deg);
    z-index: -1;
}

.share-popover.position-right .share-popover-arrow {
    left: -8px;
    margin-top: -8px;
    border-right: none;
    border-bottom: none;
}

.share-popover.position-left .share-popover-arrow {
    right: -8px;
    margin-top: -8px;
    border-left: none;
    border-top: none;
}

.share-popover.position-bottom .share-popover-arrow {
    top: -8px;
    margin-left: -8px;
    border-bottom: none;
    border-right: none;
}

.share-popover.position-top .share-popover-arrow {
    bottom: -8px;
    margin-left: -8px;
    border-top: none;
    border-left: none;
}

.share-popover-content {
    position: relative;
    z-index: 1;
    background: white;
    border-radius: 8px;
}

.share-popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-300);
}

.share-popover-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--gray-800);
}

.share-popover-close {
    background: transparent;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    line-height: 1;
}

.share-popover-close:hover,
.share-popover-close:focus,
.share-popover-close:active {
    background-color: var(--gray-100);
    outline: 1px solid #5b7eb3;
    outline-offset: -2px;
    color: var(--gray-600);
}

.share-popover-close i {
    font-size: 16px;
}

.share-popover-body {
    padding: 8px;
}

.share-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--gray-800);
    transition: background-color 0.2s ease;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    font-size: 14px;
    font-family: inherit;
    text-align: left;
}

.share-option:hover,
.share-option:focus {
    background-color: var(--gray-100);
    color: var(--gray-800);
    text-decoration: none;
    outline: 1px solid var(--primary-700);
    outline-offset: -2px;
}

.share-option i {
    font-size: 20px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.share-option span {
    flex: 1;
}

.share-option.copied {
    background-color: #d1fae5;
    color: #065f46;
}

.share-option.copy-failed {
    background-color: #fee2e2;
    color: #991b1b;
}

@media (max-width: 576px) {
    .share-popover {
        min-width: 200px;
        max-width: calc(100vw - 20px);
    }
}

/* Empty State */
.sfm-related-videos-empty {
    padding: 2rem;
    background: var(--gray-100);
    border: 2px dashed var(--gray-300);
    border-radius: 8px;
    text-align: center;
    color: var(--gray-600);
}

/* ========================================
   Modal Styles
   ======================================== */

.sfm-video-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Transition properties */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Modal visible state */
.sfm-video-modal[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
}

.sfm-video-modal__overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0);
    cursor: pointer;
    transition: background-color 0.3s ease;
}

/* Overlay visible state */
.sfm-video-modal[aria-hidden="false"] .sfm-video-modal__overlay {
    background: rgba(51, 51, 51, 0.45);
}

.sfm-video-modal__container {
    position: relative;
    width: 96%;
    max-width: 1190px;
    max-height: 90vh;
    background: white;
    border-radius: 0;
    overflow: hidden;
    z-index: 1;
    display: flex;
    flex-direction: column;
    /* Transition properties */
    transform: scale(0.9) translateY(20px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Container visible state */
.sfm-video-modal[aria-hidden="false"] .sfm-video-modal__container {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.sfm-video-modal__content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Modal Header */
.sfm-video-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1.5rem 0.5rem;
    border-bottom: none;
    flex-shrink: 0;
}

.sfm-video-modal__title {
    font-size: 32px;
    font-weight: 400;
    margin: 0 !important;
    color: var(--body-color);
    padding: 0.5rem 2rem 0.5rem 0.5rem;
}

.sfm-video-modal__close {
    border: none;
    background: transparent !important;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--gray-700) !important;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0.5rem;
    box-shadow: none !important;
}

.sfm-video-modal__close:hover {
    background-color: var(--gray-300) !important;
}

.sfm-video-modal__close:focus-visible {
    outline: 2px solid #4299e1 !important;
    outline-offset: 1px;
}

/* Modal Body */
.sfm-video-modal__body {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.sfm-video-modal__video-container {
    position: relative;
    overflow: hidden;
}

.sfm-video-modal__video-container iframe,
.sfm-video-modal__video-container video {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    display: block;
}

/* Description */
.sfm-video-modal__description {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--primary-600);
}

.sfm-video-modal__description p {
    margin: 0 0 1rem;
}

.sfm-video-modal__description p:last-child {
    margin-bottom: 0;
}

/* Mobile Adjustments */

@media (min-width: 1024px) {
    .sfm-video-modal__title {
        font-size: 40px;
    }
}

@media (max-width: 767px) {

    .sfm-related-videos__grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .sfm-related-videos__heading {
        font-size: 20px;
        font-weight:700;
    }
    .sfm-video-modal__container {
        max-height: 95vh;
    }

    .sfm-video-modal__header {
        padding: 1rem 1.5rem;
    }

    .sfm-video-modal__title {
    font-size: 24px;
    }

    .sfm-video-modal__body {
        padding: 1.5rem;
    }

    .sfm-video-modal__segments {
        padding: 1rem;
    }
}

@media (max-width: 576px) {
    .sfm-related-videos__grid {
        grid-template-columns: 1fr;
    }
}

/* Accessibility: Reduce motion */
@media (prefers-reduced-motion: reduce) {
    .sfm-related-videos__card,
    .sfm-related-videos__play-button,
    .sfm-related-videos__thumbnail-link,
    .sfm-related-videos__play-icon,
  .sfm-video-modal__segment-link {
        transition: none;
    }

    .sfm-related-videos__card:hover,
    .sfm-related-videos__card:focus-within {
        transform: none;
    }

    .sfm-related-videos__play-button:hover,
    .sfm-related-videos__play-button:focus,
    .sfm-related-videos__thumbnail-link:hover,
    .sfm-related-videos__thumbnail-link:focus {
        transform: none;
    }

    .sfm-related-videos__play-button:hover .sfm-related-videos__play-icon,
    .sfm-related-videos__thumbnail-link:hover .sfm-related-videos__play-icon {
        transform: translate(-50%, -50%);
    }

    .sfm-video-modal__segment-link:hover,
    .sfm-video-modal__segment-link:focus {
        transform: none;
    }
}

/* Body class when modal is open */
body.sfm-modal-open {
    overflow: hidden;
}