@import url('https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200');

/* Create a new CSS file */
body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* Prevent scrollbars caused by absolute positioning */
}

#map-container {
    position: relative;
    width: 90%;
    max-width: 1200px;
    border: 1px solid #ccc;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    background-color: #e3f2fd; /* Light blue background for map area */
    /* Ensure container dimensions are stable for centering calculations */
    aspect-ratio: 960 / 600; /* Match initial SVG viewBox aspect ratio */
}

#map {
    width: 100%;
    height: 100%; /* Fill the container */
    display: block;
    background-color: #e3f2fd; /* Match container background */
}

.country {
    stroke: #aaa;
    stroke-width: 0.5px;
    cursor: pointer;
    /* Adjusted transition for transform + added fill/opacity */
    transition: opacity 0.4s ease-in-out, fill 0.3s ease-in-out, filter 0.4s ease-in-out;
    /* D3 will handle transform transitions */
    transform-origin: center; /* Ensure scaling happens from the center */
    vector-effect: non-scaling-stroke; /* Keep stroke width consistent on zoom */
}

/* Specific hover style when NOT faded or focused */
.country:not(.faded):not(.focused):hover {
    fill: #777; /* Darker grey hover */
    /* opacity: 0.9; // Using fill change instead */
}

/* Explicitly reset hover if faded or focused */
.country.faded:hover, .country.focused:hover {
    /* Keep styles defined by .faded or .focused */
}

/* Style for faded countries */
.country.faded {
    fill: #bdbdbd !important; /* Use important to override inline fill, light grey */
    stroke: #ccc;
    opacity: 0.3; /* Make them more faded */
    cursor: default; /* Indicate they are not interactive */
    pointer-events: none; /* Disable pointer events when faded */
    filter: none; /* Ensure no shadow when faded */
}

/* Style for the focused country (base style, transform is handled by JS) */
.country.focused {
    opacity: 1 !important; /* Ensure it's fully opaque */
    stroke: #0056b3; /* Darker blue stroke */
    stroke-width: 0.75px; /* Slightly thicker stroke (relative to non-scaling) */
    /* transform: scale(1.05); /* REMOVED - Handled by D3 transition */
    filter: url(#drop-shadow); /* Reference SVG filter */
    cursor: pointer; /* Still clickable to defocus */
    pointer-events: auto; /* Ensure it remains clickable */
}

/* Style for the country info popup */
#country-info.draggable {
    position: absolute;
    background-color: rgba(255, 255, 255, 0.95); /* Slightly transparent white */
    border: 1px solid #ccc;
    padding: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); /* Enhanced shadow */
    display: none;
    z-index: 1001;
    cursor: grab;
    min-width: 250px;
    max-width: 350px;
    border-radius: 6px; /* More rounded */
    backdrop-filter: blur(2px); /* Subtle blur effect behind popup */
}

#country-info h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.2em;
    color: #333;
}

#country-info p {
    margin: 6px 0; /* Slightly more vertical space */
    font-size: 0.9em;
    line-height: 1.45; /* Improved readability */
    color: #444; /* Slightly darker text */
}

#country-info p#country-religion {
    margin-bottom: 0; /* Reduce space before % note */
}

#country-info p#country-religion-details {
    font-size: 0.8em;
    color: #666;
    margin-top: 2px; /* Small space after main religion line */
    margin-bottom: 10px;
}

/* Styles for Religion Breakdown in popup */
#religion-breakdown h4 {
    margin-top: 15px; /* Space above breakdown heading */
    margin-bottom: 6px;
    font-size: 0.95em; /* Slightly larger heading */
    color: #444;
    border-bottom: 1px solid #eee; /* Separator line */
    padding-bottom: 3px;
}

#religion-breakdown ul {
    list-style-type: none;
    padding-left: 0;
    margin-top: 0;
    margin-bottom: 5px; /* Space below list */
    font-size: 0.85em; /* Control list item size */
    color: #555; /* Slightly lighter text for breakdown items */
}

#religion-breakdown li {
    margin-bottom: 3px; /* Space between breakdown items */
}

/* Styles for the details paragraph */
#country-details {
    margin-top: 10px;
    margin-bottom: 12px;
    font-style: italic;
    color: #555; /* Darker italic text */
    font-size: 0.85em; /* Slightly smaller */
}

/* Styles for the links container */
#country-links {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-around;
}

#country-links a {
    font-size: 0.85em;
    color: #007bff;
    text-decoration: none;
    padding: 4px 8px; /* Slightly larger click area */
    border-radius: 4px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

#country-links a:hover {
    background-color: #e9ecef;
    color: #0056b3;
}

/* Close button for the info popup */
.close-button {
    position: absolute;
    top: 5px;
    right: 8px;
    font-size: 1.2em;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    padding: 2px 5px;
    line-height: 1;
    border-radius: 50%;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.close-button:hover {
    color: #555;
    background-color: #f0f0f0;
}

/* Refresh button for the info popup */
.refresh-button {
    position: absolute;
    top: 6px; /* Align vertically with close button text */
    right: 38px; /* Position to the left of the close button */
    font-size: 1.05em; /* Slightly smaller than close button */
    color: #aaa;
    cursor: pointer;
    padding: 1px 3px; /* Fine-tune padding */
    line-height: 1;
    border-radius: 50%;
    transition: color 0.2s ease, background-color 0.2s ease, transform 0.2s ease;
    user-select: none; /* Prevent text selection */
    font-variation-settings: 'wght' 300; /* Lighter weight for the icon */
}

.refresh-button:hover {
    color: #555;
    background-color: #f0f0f0;
}

.refresh-button.loading {
    animation: spin 1s linear infinite;
    pointer-events: none; /* Disable click while loading */
    color: #007bff; /* Indicate activity */
}

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

/* Legend styles */
#legend-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    cursor: grab;
    max-height: 80vh; /* Prevent legend from becoming too tall */
    backdrop-filter: blur(1px); /* Subtle blur effect */
    transition: max-height 0.3s ease-in-out, padding 0.3s ease-in-out, min-width 0.3s ease-in-out; /* Smooth minimize/maximize */
    overflow: hidden; /* Hide content when minimized */
    min-width: 150px; /* Ensure minimum width */
}

#legend-toggle-button {
    font-weight: bold;
    padding-bottom: 5px;
    margin-bottom: 5px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none; /* Prevent text selection on toggle */
}

#legend-toggle-button .material-symbols-outlined {
    font-size: 1.2em;
    font-variation-settings: 'wght' 300;
    transition: transform 0.3s ease;
}

#legend-content {
    max-height: 70vh; /* Limit content height */
    overflow-y: auto; /* Allow scrolling if content overflows */
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 1;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

.legend-color-box {
    width: 15px;
    height: 15px;
    margin-right: 8px;
    border: 1px solid #ddd; /* Subtle border */
    flex-shrink: 0;
}

.legend-label {
    font-size: 0.85em;
    color: #333;
}

/* Minimized state for Legend */
#legend-container.minimized {
    padding-top: 5px;
    padding-bottom: 5px;
    max-height: 30px; /* Adjust to fit toggle button */
    min-width: auto; /* Allow shrinking */
}

#legend-container.minimized #legend-toggle-button {
    margin-bottom: 0;
    border-bottom: none;
}

#legend-container.minimized #legend-content {
    max-height: 0;
    opacity: 0;
    pointer-events: none; /* Disable interaction when hidden */
}

#legend-container.minimized #legend-toggle-button .material-symbols-outlined {
     transform: rotate(-90deg);
}

/* Loading Indicator Styles */
#loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    z-index: 2000;
    font-size: 1.1em;
    display: none; /* Hidden by default */
}

#loading-error {
    color: #ffdddd; /* Lighter red for dark background */
    margin-top: 10px;
    font-size: 0.9em;
}

/* Tooltip Styles */
.tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.85em;
    z-index: 1010; /* Above popup */
    pointer-events: none; /* Don't interfere with mouse events */
    white-space: nowrap;
}

/* Zoom Controls */
#zoom-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

#zoom-controls button {
    background-color: rgba(255, 255, 255, 0.8);
    border: 1px solid #ccc;
    color: #333;
    font-size: 1.2em;
    font-weight: bold;
    width: 30px;
    height: 30px;
    margin-bottom: 5px;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: background-color 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    line-height: 1;
}

#zoom-controls button:hover {
    background-color: rgba(240, 240, 240, 0.9);
}

#zoom-controls button:active {
    background-color: rgba(220, 220, 220, 0.9);
}