/**
 * Materials Show Booth Maps - Frontend Styles
 */

/* Modal Styles */
.msbm-modal {
    display: none;
    position: fixed;
    z-index: 999999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden; /* inner svg container handles scrolling */
    background-color: rgba(0, 0, 0, 0.6);
}

.msbm-modal-content {
    background-color: #fff;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 1200px;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    position: relative;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.msbm-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.msbm-modal-header h2 {
    margin: 0;
    padding: 0;
    font-size: 1.5em;
}

.msbm-modal-body {
    flex: 1;
    min-height: 0; /* allow flex child to shrink so inner overflow works */
    overflow: scroll; /* inner svg container handles scrolling */
    display: flex;
    flex-direction: column;
}

.msbm-modal-body .msbm-modal-map-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.msbm-modal-close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.msbm-modal-close:hover,
.msbm-modal-close:focus {
    color: #000;
    text-decoration: none;
}

.msbm-modal-open-button {
    background-color: #0073aa;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.3s;
}

.msbm-modal-open-button:hover {
    background-color: #005177;
}

/* View as Image Link */
.msbm-view-image-link-wrapper {
    margin-top: 10px;
    text-align: center;
}

.msbm-view-image-link {
    color: #0073aa;
    text-decoration: none;
    font-size: 14px;
    display: inline-block;
    transition: color 0.3s;
}

.msbm-view-image-link:hover {
    color: #005177;
    text-decoration: underline;
}

/* Prevent body scrolling when modal is open */
body.msbm-modal-open {
    overflow: hidden;
}

/* Map Container */
.msbm-map-container {
    position: relative;
    margin: 20px 0;
    border: 1px solid #ddd;
    padding: 20px;
    background-color: #fff;
}

/* Map Legend */
.msbm-map-legend {
    margin-bottom: 15px;
}

.msbm-legend-item {
    display: inline-block;
    margin-right: 20px;
}

.msbm-legend-color {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-right: 5px;
    vertical-align: middle;
}

.msbm-legend-color.msbm-available {
    background-color: #8ccb54;
    border: 1px solid #aaa;
}

.msbm-legend-color.msbm-occupied {
    background-color: #ffcc80;
    border: .5px solid #000000;
}

/* SVG Map Container */
.msbm-map-svg-container {
    max-width: 100%;
    overflow: auto;
    position: relative; /* Needed for absolute positioning of booth labels */
    min-height: 400px; /* Set minimum height to prevent layout shifts */
}

#msbm-svg-map-nw, #msbm-svg-map-ne, [id^="msbm-svg-map-"] {
    min-height: 400px;
    /* opacity: 0; Hide the map by default */
    transition: opacity 0.5s ease-in-out; /* Smooth transition when showing */
}

#msbm-svg-map-nw.loaded, #msbm-svg-map-ne.loaded, [id^="msbm-svg-map-"].loaded {
    opacity: 1; /* Show the map when it has the loaded class */
}

/* Override for modal SVG container to ensure it scales properly.
   This is the ONE element that scrolls inside the modal — all parents
   are overflow:hidden so we never get nested scrollbars. */
.msbm-modal-svg-container {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.msbm-modal-svg-container svg {
    max-width: 100%;
    height: auto;
}

/* Scale down the NW map specifically in modals to make it more manageable */
.msbm-modal-map-container[data-show="nw"] .msbm-modal-svg-container svg {
    zoom: 0.6;
}

/* Loading Spinner */
.msbm-loading-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.msbm-spinner {
    display: inline-block;
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    animation: spin 2s linear infinite;
}

.msbm-loading-text {
    margin-top: 10px;
    font-weight: bold;
    color: #666;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Booth Element Styles */
.booth {
    cursor: pointer;
    transition: fill 0.3s ease;
    fill: #ddd;
}

.booth.available {
    fill: #8ccb54;
    stroke: black;
    stroke-width: 1px;
}

.booth.occupied {
    fill: #ffcc80;
    stroke: #000000;
    stroke-width: 1px;
}

.booth:hover {
    stroke-width: 1px;
}

.booth.available:hover {
    fill: #8cbd61;
}

.booth.occupied:hover {
    fill: #e7c28b;
}

/* Booth Labels */
.booth-label {
    position: absolute;
    font-size: 12px;
    font-weight: bold;
    text-align: center;
    color: #000;
    background-color: rgba(255, 255, 255, 0.7);
    padding: 2px 4px;
    border-radius: 2px;
    z-index: 100;
    pointer-events: none; /* Allow clicks to pass through to booth elements */
    user-select: none; /* Prevent text selection */
    white-space: nowrap; /* Keep booth numbers on a single line */
    /* transform: translate(-50%, -50%); Center the label */
}

.booth:hover + .booth-label {
    background-color: rgba(255, 255, 255, 0.9);
    font-weight: bold;
    z-index: 101;
}

/* Tooltip */
.msbm-tooltip {
    position: absolute;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    width: 250px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    pointer-events: none;
    transform: translate(-50%, -100%);
    margin-top: -10px;
}

.msbm-tooltip::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 10px 10px 0;
    border-style: solid;
    border-color: #fff transparent transparent;
}

.msbm-tooltip-header {
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
    padding-bottom: 5px;
}

.msbm-company-name {
    margin: 0;
    font-size: 16px;
    font-weight: bold;
}

.msbm-tooltip-body {
    display: flex;
}

.msbm-company-logo {
    width: 80px;
    height: 80px;
    border: 1px solid #eee;
    margin-right: 10px;
    background-color: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.msbm-company-logo img {
    max-width: 100%;
    max-height: 100%;
}

.msbm-company-info {
    flex: 1;
}

.msbm-company-info p {
    margin: 5px 0;
    font-size: 14px;
}

/* ──────────────────────────────────────────────
   GF Booth Map Picker Field
   ────────────────────────────────────────────── */

.msbm-gf-picker {
    padding: 4px 0;
}

.msbm-gf-button-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* Form editor preview */
.msbm-gf-picker-preview {
    padding: 12px;
    background: #f0f6fc;
    border: 1px dashed #0d6efd;
    border-radius: 4px;
    color: #555;
}

/* Responsive styles */
@media screen and (max-width: 768px) {
    .msbm-tooltip {
        width: 200px;
    }
    
    .msbm-tooltip-body {
        flex-direction: column;
    }
    
    .msbm-company-logo {
        margin-right: 0;
        margin-bottom: 10px;
    }
    
    .booth-label {
        font-size: 10px;
        padding: 1px 2px;
    }

    .msbm-gf-button-row {
        flex-direction: column;
    }

    .msbm-gf-btn {
        max-width: 100%;
    }
}
