/**
 * CM UI Modals CSS
 */

/* Modal container wrappers - both default and custom */
.cm-modal-container-wrapper {
    /* No specific styles needed for the wrapper - it's just a container */
}

.cm-modal-fader {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background-color: rgba(0, 0, 0, 0.3);
    z-index: 9999;
    display: none;
    --modal-width: 300px; /* Default width that will be updated by JS */
    --modal-height: 200px; /* Default height that will be updated by JS */
}

.cm-modal-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: solid 1px #666666;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: none;
    max-width: 90%;
    max-height: 90%;
    overflow: visible;
    margin: 0;
    padding: 0;
    font-size: 0;
    line-height: 0;
    position: relative;
}

.cm-modal-header {
    display: block;
    position: relative;
    width: 100%;
    padding: .5em 0 .5em 0;
    background-color: #f8f8f8;
    border-bottom: 1px solid #ddd;
    font-size: x-large;
    text-align: center;
    margin: 0;
    box-sizing: border-box;
    line-height: normal;
}

.cm-modal-content {
    background: #FEFEFE;
    position: relative;
    display: block;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-size: medium;
    line-height: normal;
    overflow: auto;
}

/* Image view modes injected by tooltips.js via container classes */
.cm-modal-container.cm-image-scrollable .cm-modal-content {
    /* Allow the image to fill width and scroll vertically without clipping */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: calc(90vh - 55px) !important; /* account for header height */
}

.cm-modal-container.cm-image-fit .cm-modal-content {
    /* Default auto overflow, ensure header space is considered via max-height */
    overflow: auto;
    max-height: calc(90vh - 55px) !important;
}

/* Ensure images inside modals behave predictably */
.cm-modal-container.cm-image-scrollable .cm-modal-content img,
.cm-modal-container.cm-image-fit .cm-modal-content img {
    display: block;
    margin: 0 auto;
}

/* Modal Close Button - Universal Styling */
.cm-modal-close {
    display: flex;
    font-family: 'Verdana','Roboto-thin', sans-serif;
    justify-content: center;
    align-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-color: #222;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    border: 2px solid #ffffff;
    position: absolute;
    right: -15px;
    top: -15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
    transition: all 0.2s ease;
    z-index: 20000; /* High z-index for all modals */
    padding: 0px 0px 4px 0px;
    line-height: 24px;
    box-sizing: border-box;
    text-align: center;
    font-weight: 300;
    overflow: visible;
}

/* For the close button inside the fader (old structure) - DEPRECATED, KEPT FOR BACKWARD COMPATIBILITY */
.cm-modal-fader > .cm-modal-close {
    right: calc(50% - .5 * var(--modal-width) - 15px);
    top: calc(50% - .5 * var(--modal-height) - 15px);
}

/* For the close button inside the container (new structure) */
.cm-modal-container > .cm-modal-close {
    right: -15px;
    top: -15px;
}

.cm-modal-close:hover {
    background-color: #444;
    transform: scale(1.1);
}

/* For screens with dark backgrounds, enhance visibility */
@media (prefers-color-scheme: dark) {
    .cm-modal-close {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    }
}

.cm-modal-fade-in {
    animation: fadeIn 0.5s ease-in-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* YouTube Video Modal Styling */
.cm-modal-youtube {
    max-width: 90vw;
    max-height: 90vh;
    padding: 0; /* Remove padding for video content */
    box-sizing: border-box;
    overflow: visible !important; /* Force visible to ensure button isn't clipped */
    font-size: 0;
    line-height: 0;
}

/* Default size for YouTube modals without custom dimensions */
.cm-modal-youtube.cm-default-size {
    width: 90vw !important; /* Force full width for default size */
    height: auto !important; /* Height will be determined by content + header */
  /*  min-height: calc(90vw * 0.5625 + 60px); */ /* 16:9 aspect ratio + header space */
    overflow: visible !important; /* Force visible to ensure button isn't clipped */
}

/* For default youtube modals, make sure content area has proper height (subtract header space) */
.cm-modal-youtube.cm-default-size .cm-modal-content {
    height: calc(90vw * 0.5625 - 50px) !important; /* 16:9 minus header height */
    max-height: calc(90vw * 0.5625 - 50px) !important; /* Ensure it doesn't exceed */
    padding: 0 !important;
    margin: 0 !important;
    font-size: medium;
    line-height: normal;
    overflow: hidden !important; /* Content should be hidden but container should be visible */
    display: flex !important; /* Make flex container for YouTube content */
    flex-direction: column !important; /* Stack children vertically */
}

/* For all YouTube modals, ensure modal content is flex */
.cm-modal-youtube .cm-modal-content {
    display: flex !important;
    flex-direction: column !important;
}

/* Fix for YouTube modal direct content wrapper */
.cm-modal-youtube .cm-modal-direct-content {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    height: 100% !important;
    width: 100% !important;
}

/* Ensure YouTube wrapper gets full width */
.cm-modal-youtube .cm-youtube-wrapper {
    width: 100% !important;
}

/* Fixed: Force content height with higher specificity to account for header */
.cm-modal-container.cm-modal-youtube.cm-default-size .cm-modal-content {
    height: calc(90vw * 0.5625 - 50px) !important;
    max-height: calc(90vw * 0.5625 - 50px) !important;
}

/* For small screens - keep it proportional */
@media (max-width: 768px) {
    .cm-modal-youtube.cm-default-size {
        width: 90vw !important;
        min-height: calc(90vw * 0.5625); /* 16:9 aspect ratio */
    }
}

/* For custom-sized YouTube modals */
.cm-modal-youtube:not(.cm-default-size) {
    /* Let inline styles control dimensions */
    display: flex !important;
    flex-direction: column !important;
    overflow: visible !important; /* Force visible to ensure button isn't clipped */
}

/* Modal header for YouTube */
.cm-modal-youtube .cm-modal-header {
    flex: 0 0 auto;
}

/* Content container for YouTube */
.cm-modal-youtube .cm-modal-content {
    flex: 1 1 auto;
    padding: 0 !important;
    margin: 0 !important;
    background: #000 !important;
    overflow: hidden !important; /* Content should be hidden */
    font-size: medium;
    line-height: normal;
}

/* Base YouTube container for all YouTube modals */
.cm-youtube-container {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
}

/* YouTube iframe styling */
.cm-youtube-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Fullscreen link for YouTube videos */
.cm-fullscreen-link {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(147, 179, 152, 0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    z-index: 10;
    transition: background-color 0.2s ease, opacity 0.5s ease;
    display: flex;
    align-items: center;
    opacity: 1;
    animation: fadeOutButton 5s forwards;
}

.cm-fullscreen-link:hover {
    background-color: rgba(129, 202, 145, 0.9);
    opacity: 1;
    animation: none;
}

.cm-youtube-container:hover .cm-fullscreen-link {
    opacity: 1;
    animation: none;
}

@keyframes fadeOutButton {
    0% { opacity: 1; }
    80% { opacity: 1; } /* Stay visible for 4 seconds (80% of 5s) */
    100% { opacity: 0.2; } /* Fade to 20% opacity so it's still slightly visible */
}

.cm-fullscreen-link:before {
    content: "⛶";  /* Unicode fullscreen symbol */
    margin-right: 5px;
    font-size: 14px;
}

/* Error message styling */
.cm-modal-error {
    color: #D4252B;
    padding: 15px;
    text-align: center;
    font-weight: bold;
}

/* For the close button inside the YouTube modal container - REMOVED, USING UNIVERSAL STYLING */
/* .cm-modal-youtube > .cm-modal-close {
    right: -15px;
    top: -15px;
    z-index: 20000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
} */ 