/* Main container styling */
#fertigmap-container {
    position: relative;
    display: inline-block;
    max-width: 100%;
    width: 100%;
    overflow: visible; /* Change from hidden to visible to allow tooltips to extend outside */
    z-index: 1; /* Give the container a base z-index */
}

/* Base tooltip styling */
#fertigmap-tooltip {
    display: none;
    position: fixed; /* Change from absolute to fixed for consistent stacking context */
    z-index: 999999; /* Extremely high z-index to overcome other elements */
    width: 240px;
    background-color: #243B69; /* Updated background color */
    color: #ffffff; /* Updated text color */
    border-radius: 8px; /* Apply to all corners by default */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3); /* Stronger shadow for better visibility */
    padding: 0; /* Remove padding as it's now in tooltip-content */
    pointer-events: auto;
    overflow: visible; /* Changed from hidden to visible to show the polygon shape */
    clip-path: none; /* Remove clip-path from main tooltip */
}

/* Add a polygon pseudo-element at the bottom of the tooltip content */
.tooltip-content::after {
    content: '';
    position: absolute;
    bottom: -20px; /* Position below the content */
    left: 0;
    width: 100%;
    height: 30px;
    background-color: #243B69;
    clip-path: polygon(0% 0%, 100% 0%, 100% 10%, 75% 10%, 50% 100%, 25% 10%, 0% 10%);
    z-index: -1;
}

/* Close button styling */
#tooltip-close {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 16px;
    color: #ffffff; /* Updated to match the theme */
    cursor: pointer;
    font-weight: bold;
    z-index: 5;
    line-height: 1;
    width: 20px;
    height: 20px;
    text-align: center;
    display: none;
}

/* Tooltip content styling */
.tooltip-content {
    padding: 15px; /* Moved padding from tooltip to content */
    font-family: Arial, sans-serif;
}

/* Two-column header layout */
.tooltip-header {
    display: flex;
    margin-bottom: 10px;
}

/* Featured image column (50%) */
.tooltip-image {
    width: 50%;
    overflow: hidden;
    border-radius: 4px;
}

.tooltip-image img {
    width: 100%;
    height: auto;
    object-fit: cover;
    max-height: 75px;
    border-radius: 4px;
}

/* ORT column (50%) */
.tooltip-ort {
    width: 50%;
    padding-left: 10px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.ort-value {
    font-size: 50px; /* Increased font size */
    font-weight: 700;
    color: #ffffff;
}

.ort-label {
    font-size: 12px;
    color: #ffffff;
    font-weight: 600;
    margin-bottom: 5px;
}

/* Company name styling */
.company-name {
    font-size: 14px;
    font-weight: 900; /* Increased font weight */
    color: #ffffff;
    margin: 10px 0 5px;
    line-height: 1.2;
}

/* Tooltip title styling */
.tooltip-content h4 {
    margin: 0 0 10px 0;
    font-size: 16px;
    color: #ffffff;
    font-weight: 600;
    line-height: 1.3;
}

/* No image placeholder */
.no-image {
    background-color: #f0f0f0;
    width: 100%;
    height: 80px; /* Adjusted height */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #999;
    border-radius: 4px;
}

/* Status badge and view details */
.status-badge {
    display: inline-block;
    background-color: #4CAF50;
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.view-details {
    display: block;
    text-align: center;
    background-color: #0073aa;
    color: white !important;
    padding: 8px 0;
    text-decoration: none;
    margin-top: 10px;
    transition: background-color 0.3s ease;
}

.view-details:hover {
    background-color: #005d8c;
    color: white !important;
    text-decoration: none;
}

/* Hover effects */
#fertigmap-container [id^="plot-"], 
#fertigmap-container rect[id] {
    transition: fill 0.3s ease;
}

#fertigmap-container [id^="plot-"]:hover,
#fertigmap-container rect[id]:hover {
    fill: rgba(0, 115, 170, 0.5);
    cursor: pointer;
}

/* Position-specific arrow styling with updated color */
#fertigmap-tooltip:after {
    display: none; /* Hide the original arrow since we're using clip-path for the shape */
}

/* Mobile adjustments */
@media (max-width: 767px) {
    #fertigmap-tooltip {
        width: 150px !important;
        position: fixed; /* Ensure fixed positioning */
        left: 50% !important; 
        top: 50% !important; /* Center vertically as well */
        transform: translate(-50%, -50%) !important; /* Center both horizontally and vertically */
        background-color: #243B69;
        border-radius: 8px !important; /* Apply border radius to all corners on mobile */
        clip-path: none; /* Remove clip-path */
    }
    
    #tooltip-close {
        display: block;
        top: 5px;
        right: 5px;
    }
    
    .tooltip-content {
        padding: 10px;
    }
    
    .tooltip-header {
        flex-direction: row;
        margin-bottom: 5px;
        align-items: center;
    }
    
    .tooltip-image {
        width: 50%;
    }
    
    .tooltip-image img {
        max-height: 40px;
    }
    
    .tooltip-ort {
        width: 50%;
        padding-left: 5px;
    }
    
    .ort-value {
        font-size: 28px; /* Adjusted for mobile */
    }
    
    .company-name {
        font-size: 12px;
        margin: 3px 0;
    }
    
    .tooltip-content h4 {
        font-size: 12px;
        margin: 0 0 5px 0;
    }
    
    .no-image {
        height: 40px;
        font-size: 10px;
    }
    
    #fertigmap-tooltip:before {
        display: none;
    }
    
    #fertigmap-tooltip:after {
        display: none;
    }
    
    /* Adjust the pseudo-element for mobile */
    .tooltip-content::after {
        display: none; /* Hide the polygon on mobile */
    }
}

/* Extra small devices */
@media (max-width: 375px) {
    #fertigmap-tooltip {
        width: 120px;
        padding: 0;
        clip-path: none; /* Remove clip-path */
        border-radius: 8px !important; /* Ensure border radius on all corners for smallest screens too */
    }
    
    /* Further adjust the pseudo-element for very small screens */
    .tooltip-content::after {
        display: none;
    }
}

/* Desktop-specific enhancements for tooltip visibility */
@media (min-width: 768px) {
    #fertigmap-tooltip {
        z-index: 99999;
        box-shadow: 0 6px 15px rgba(0, 0, 0, 0.25);
    }
    
    /* For desktop, adjust the content padding */
    .tooltip-content {
        padding: 15px;
    }
}

/* Touch-specific visual feedback */
@media (hover: none) and (pointer: coarse) {
    #fertigmap-container rect[id]:active,
    #fertigmap-container [id^="plot-"]:active,
    #fertigmap-container rect[id][data-active="true"],
    #fertigmap-container [id^="plot-"][data-active="true"] {
        fill-opacity: 0.7;
        stroke-width: 2px;
    }
    
    #fertigmap-tooltip:before {
        display: none;
    }
}

/* Fix for Safari mobile */
@supports (-webkit-touch-callout: none) {
    #fertigmap-tooltip {
        /* Safari-specific fixes if needed */
    }
}
