/**
 * Frontend CSS for SVG Interactive Map
 */

/* Map Container */
.sim-map-container {
    position: relative;
    max-width: 100%;
    margin: 0 auto;
}

.sim-map-wrapper {
    display: flex;
    align-items: flex-start;
    gap: 20px;
    position: relative;
}

/* SVG Container */
.sim-svg-container {
    flex: 1;
    min-width: 0;
    position: relative;
}

.sim-svg-container svg {
    width: 100%;
    height: auto;
    display: block;
}

/* State Elements */
.sim-state {
    cursor: pointer;
    transition: all var(--animation-duration, 300ms) ease;
}

.sim-state path,
.sim-state polygon,
.sim-state circle,
.sim-state rect {
    transition: all var(--animation-duration, 300ms) ease;
}

.sim-state-interactive {
    cursor: pointer;
}

/* Hover colors - only when enabled */
.sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover path,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover polygon,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover circle,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover rect {
    /* Colors will be set by inline styles from PHP settings */
    stroke-width: 2 !important;
    opacity: 0.8;
    transition: fill var(--animation-duration, 300ms) ease;
}

.sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover {
    filter: drop-shadow(2px 2px 4px rgba(0,0,0,0.2));
}

/* Active state colors - only when enabled */
.sim-map-container[data-enable-hover-colors="1"] .sim-state-active path,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-active polygon,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-active circle,
.sim-map-container[data-enable-hover-colors="1"] .sim-state-active rect {
    /* Colors will be set by inline styles from PHP settings */
    stroke-width: 2 !important;
}

/* Template Popup - Fixed Mode */
.sim-template-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    overflow: hidden;
}

.sim-template-popup.sim-popup-visible {
    opacity: 1;
    visibility: visible;
}

/* Template Popup - Floating Mode */
.sim-floating-popup {
    position: absolute;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    overflow: hidden;
    width: auto; /* Remove fixed width */
    min-width: 250px;
    max-width: 350px;
    border: 1px solid #e0e0e0;
    transform: scale(0.95);
    /* Ensure it's positioned relative to viewport when attached to body */
    top: 0;
    left: 0;
}

.sim-floating-popup.sim-popup-visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Position-specific styling for floating popups */
.sim-floating-popup.sim-position-right::before,
.sim-floating-popup.sim-position-left::before,
.sim-floating-popup.sim-position-top::before,
.sim-floating-popup.sim-position-bottom::before {
    content: '';
    position: absolute;
    width: 10px;
    height: 10px;
    background: #ffffff;
    border: 1px solid #e0e0e0;
    transform: rotate(45deg);
    z-index: -1;
}

/* Right position arrow */
.sim-floating-popup.sim-position-right::before {
    left: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    border-right: none;
    border-bottom: none;
}

/* Left position arrow */
.sim-floating-popup.sim-position-left::before {
    right: -6px;
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    border-left: none;
    border-top: none;
}

/* Top position arrow */
.sim-floating-popup.sim-position-top::before {
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    border-top: none;
    border-left: none;
}

/* Bottom position arrow */
.sim-floating-popup.sim-position-bottom::before {
    top: -6px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    border-bottom: none;
    border-right: none;
}

/* Enhanced appearance for better positioning */
.sim-floating-popup {
    position: absolute;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
    overflow: visible; /* Changed from hidden to show arrows */
    width: auto;
    min-width: 250px;
    max-width: 350px;
    border: 1px solid #e0e0e0;
    transform: scale(0.95);
    top: 0;
    left: 0;
}

/* Remove transitions that affect width/content for floating popups */
.sim-floating-popup .sim-popup-content {
    transition: none !important;
    width: auto !important;
    min-width: 0 !important;
    overflow: hidden; /* Keep content contained */
    border-radius: 6px; /* Slight rounding to match popup */
}

.sim-floating-popup * {
    box-sizing: border-box;
}

/* Hover-specific floating popup styles */
.sim-trigger-hover.sim-position-floating .sim-floating-popup {
    animation: none; /* Remove complex animations for smoother experience */
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.sim-trigger-hover.sim-position-floating .sim-floating-popup .sim-popup-content {
    padding: 15px;
    font-size: 14px;
    line-height: 1.4;
}

/* Floating mode specific styles */
.sim-position-floating .sim-floating-popup {
    animation: none; /* Remove the float-in animation that might cause issues */
}

/* Responsive adjustments for small screens */
@media (max-width: 768px) {
    .sim-floating-popup {
        min-width: 200px;
        max-width: calc(100vw - 40px); /* Ensure it never exceeds viewport */
    }
    
    .sim-floating-popup::before {
        display: none; /* Hide arrows on small screens for cleaner appearance */
    }
}

@media (max-width: 480px) {
    .sim-floating-popup {
        min-width: 180px;
        max-width: calc(100vw - 20px);
        font-size: 13px;
    }
    
    .sim-trigger-hover.sim-position-floating .sim-floating-popup .sim-popup-content {
        padding: 12px;
        font-size: 13px;
    }
}

/* Remove the problematic animation */
@keyframes sim-float-in {
    from {
        opacity: 0;
        transform: scale(0.98);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Hover trigger specific styles */
.sim-trigger-hover .sim-state-interactive {
    transition: all var(--animation-duration, 300ms) ease var(--hover-delay, 0ms);
}

.sim-trigger-hover .sim-floating-popup {
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sim-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #e1e5e9;
    background: #f8f9fa;
}

.sim-popup-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #495057;
}

.sim-popup-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #6c757d;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.sim-popup-close:hover {
    background: #e9ecef;
    color: #495057;
}

.sim-popup-content {
    max-height: calc(80vh - 60px);
    overflow-y: auto;
    padding: 20px;
}

/* Prevent content transitions in floating popups */
.sim-floating-popup .sim-popup-content {
    max-height: 400px;
    padding: 15px;
    overflow-y: auto;
    transition: none !important;
}

/* Ensure all child elements don't have problematic transitions */
.sim-floating-popup .sim-popup-content *,
.sim-floating-popup .sim-popup-content *:before,
.sim-floating-popup .sim-popup-content *:after {
    transition: none !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
}

/* Override any Elementor/Bricks transitions in floating mode */
.sim-floating-popup .elementor-widget,
.sim-floating-popup .elementor-element,
.sim-floating-popup [class*="brx-"],
.sim-floating-popup .elementor-container {
    transition: none !important;
}

/* Clean styling for hover popups */
.sim-trigger-hover.sim-position-floating .sim-floating-popup {
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border: 1px solid #ddd;
}

.sim-trigger-hover.sim-position-floating .sim-floating-popup .sim-popup-content {
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.5;
}

/* Loading Animation */
.sim-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #6c757d;
}

.sim-loader {
    width: 40px;
    height: 40px;
    border: 4px solid #e1e5e9;
    border-top: 4px solid #2271b1;
    border-radius: 50%;
    animation: sim-spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes sim-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.sim-template-content {
    display: none;
}

.sim-template-content.sim-loaded {
    display: block;
}

/* Popup Overlay */
.sim-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.sim-popup-overlay.sim-overlay-visible {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 768px) {
    .sim-map-wrapper {
        flex-direction: column;
    }
    
    .sim-template-popup {
        width: 95%;
        max-width: none;
        max-height: 90vh;
    }
    
    .sim-popup-content {
        max-height: calc(90vh - 60px);
        padding: 15px;
    }
    
    .sim-popup-header {
        padding: 12px 15px;
    }
    
    .sim-popup-title {
        font-size: 16px;
    }
}

/* Popup Position Variations */
.sim-popup-right .sim-template-popup {
    position: absolute;
    top: 0;
    left: 100%;
    transform: none;
    margin-left: 20px;
    width: 300px;
    max-height: none;
}

.sim-popup-left .sim-template-popup {
    position: absolute;
    top: 0;
    right: 100%;
    transform: none;
    margin-right: 20px;
    width: 300px;
    max-height: none;
}

.sim-popup-bottom .sim-template-popup {
    position: static;
    transform: none;
    width: 100%;
    max-width: none;
    margin-top: 20px;
    max-height: 400px;
}

@media (max-width: 768px) {
    .sim-popup-right .sim-template-popup,
    .sim-popup-left .sim-template-popup,
    .sim-popup-bottom .sim-template-popup {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 95%;
        margin: 0;
        max-height: 80vh;
    }
}

/* Tooltip */
.sim-tooltip {
    position: absolute;
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 14px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transform: translate(-50%, -100%);
    margin-top: -10px;
    transition: all 0.2s ease;
}

.sim-tooltip.sim-tooltip-visible {
    opacity: 1;
    margin-top: -15px;
}

.sim-tooltip:after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0,0,0,0.8);
}

/* Error Messages */
.sim-error {
    background: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: 4px;
    margin: 10px 0;
    border: 1px solid #f5c6cb;
}

/* Success Messages */
.sim-success {
    background: #d1ecf1;
    color: #0c5460;
    padding: 15px;
    border-radius: 4px;
    margin: 10px 0;
    border: 1px solid #bee5eb;
}

/* Custom Scrollbar for Popup Content */
.sim-popup-content::-webkit-scrollbar {
    width: 6px;
}

.sim-popup-content::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.sim-popup-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.sim-popup-content::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Animation for state highlighting */
@keyframes sim-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.7; }
    100% { opacity: 1; }
}

.sim-state-pulse path,
.sim-state-pulse polygon,
.sim-state-pulse circle,
.sim-state-pulse rect {
    animation: sim-pulse 1.5s ease-in-out infinite;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover path,
    .sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover polygon,
    .sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover circle,
    .sim-map-container[data-enable-hover-colors="1"] .sim-state-interactive:hover rect {
        stroke-width: 3 !important;
    }
    
    .sim-template-popup {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .sim-state,
    .sim-state path,
    .sim-state polygon,
    .sim-state circle,
    .sim-state rect,
    .sim-template-popup,
    .sim-popup-overlay,
    .sim-tooltip {
        transition: none;
    }
    
    .sim-loader {
        animation: none;
        border-top-color: #6c757d;
    }
    
    .sim-state-pulse path,
    .sim-state-pulse polygon,
    .sim-state-pulse circle,
    .sim-state-pulse rect {
        animation: none;
    }
}