/**
 * Map System Styles
 * 
 * Core styles for the modular map system
 */

/* Reset body margin */
body {
    margin: 0;
    overflow: hidden; /* Prevent scrollbars */
}

/* Base Layout */
#map-container {
    height: calc(100vh - 44px); /* Account for menu height */
    max-height: calc(100vh - 20px); /* Never exceed viewport height, with extra padding */
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent map from extending beyond container */
    box-sizing: border-box; /* Include padding/border in height calculation */
}

/* Embed mode: fill entire viewport */
.embed-mode #map-container {
    height: 100vh;
    max-height: 100vh;
}

#map-header {
    background: #333;
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 20px;
    z-index: 1001;
    position: relative;
    flex-wrap: wrap;
    color: white;
    border: none;
}

#map {
    width: 100%;
    flex: 1;
    position: relative;
    min-height: 0; /* Allow flex item to shrink below content size */
    overflow: hidden; /* Ensure map doesn't overflow */
}

/* Map Type Menu */
#map-type-menu {
    position: relative;
}

#map-type-selector {
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background-color 0.2s;
}

#map-type-selector:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#map-type-selector::after {
    content: '▼';
    font-size: 12px;
    opacity: 0.6;
}

#map-type-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: rgba(0, 0, 0, 0.95);
    border: 1px solid #444;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.3);
    margin-top: 5px;
    display: none;
    z-index: 1002;
}

#map-type-dropdown.active {
    display: block;
}

.map-type-option {
    padding: 10px 20px;
    cursor: pointer;
    transition: background-color 0.2s;
    color: white;
}

.map-type-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.map-type-option.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    color: #999;
    text-decoration: line-through;
}

.map-type-option.disabled:hover {
    background-color: transparent;
}

/* Selectors in header */
#map-selectors-container {
    display: flex;
    align-items: center;
}

#map-selectors {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;
}

#map-selectors select {
    padding: 5px 10px;
    font-size: 14px;
    border: 1px solid #555;
    background-color: rgba(40, 40, 40, 0.9);
    color: white;
    border-radius: 4px;
}

.map-description {
    font-size: 14px;
    opacity: 0.8;
}

/* Map Controls */
.mapboxgl-ctrl-group {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    overflow: hidden;
}

.mapboxgl-ctrl-group button {
    background-color: #fff;
    border: none;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mapboxgl-ctrl-group button:first-child {
    border-radius: 8px 8px 0 0;
}

.mapboxgl-ctrl-group button:last-child {
    border-radius: 0 0 8px 8px;
}

.mapboxgl-ctrl-group button:only-child {
    border-radius: 8px;
}

.mapboxgl-ctrl-group button:hover {
    background-color: #f0f0f0;
}

/* Ensure Mapbox control icons are properly sized */
.mapboxgl-ctrl-icon {
    width: 20px;
    height: 20px;
}

/* Dark style controls - Keep zoom controls light for better visibility */
body.dark-style .mapboxgl-ctrl-zoom-in,
body.dark-style .mapboxgl-ctrl-zoom-out,
body.dark-style .mapboxgl-ctrl-compass,
body.dark-style .mapboxgl-ctrl-fullscreen,
body.satellite-style .mapboxgl-ctrl-zoom-in,
body.satellite-style .mapboxgl-ctrl-zoom-out,
body.satellite-style .mapboxgl-ctrl-compass,
body.satellite-style .mapboxgl-ctrl-fullscreen {
    background-color: rgba(255, 255, 255, 0.9) !important;
    color: #333 !important;
}

body.dark-style .mapboxgl-ctrl-zoom-in:hover,
body.dark-style .mapboxgl-ctrl-zoom-out:hover,
body.dark-style .mapboxgl-ctrl-compass:hover,
body.dark-style .mapboxgl-ctrl-fullscreen:hover,
body.satellite-style .mapboxgl-ctrl-zoom-in:hover,
body.satellite-style .mapboxgl-ctrl-zoom-out:hover,
body.satellite-style .mapboxgl-ctrl-compass:hover,
body.satellite-style .mapboxgl-ctrl-fullscreen:hover {
    background-color: #f0f0f0 !important;
}

/* Style selector uses bright controls in dark mode for better visibility */
body.dark-style .style-selector .mapboxgl-ctrl-group,
body.satellite-style .style-selector .mapboxgl-ctrl-group {
    background: rgba(255, 255, 255, 0.9);
}

body.dark-style .style-selector button,
body.satellite-style .style-selector button {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
}

body.dark-style .style-selector button:hover,
body.satellite-style .style-selector button:hover {
    background-color: #f0f0f0;
}

/* Custom Controls */
.custom-control {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.65);
    margin: 10px;
}

body.dark-style .custom-control,
body.satellite-style .custom-control {
    background: rgba(0, 0, 0, 0.8);
}

/* Top Left Control Group */
.mapboxgl-ctrl-top-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    top: 10px;
    left: 10px;
}

/* Top Right Control Group */
.mapboxgl-ctrl-top-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    top: 10px;
    right: 10px;
}

/* Landscape orientation - arrange top-right controls horizontally */
@media screen and (orientation: landscape) and (max-height: 600px) {
    .mapboxgl-ctrl-top-right {
        flex-direction: row-reverse; /* Reverse order in landscape */
        align-items: flex-start;
        gap: 10px;
        flex-wrap: wrap;
    }
    
    /* Ensure controls don't overlap with header */
    .mapboxgl-ctrl-top-right {
        top: 15px;
        right: 15px;
    }
}

/* Additional landscape adjustments for very wide screens */
@media screen and (orientation: landscape) and (min-width: 800px) and (max-height: 500px) {
    .mapboxgl-ctrl-top-right {
        flex-direction: row-reverse; /* Reverse order in landscape */
        align-items: flex-start;
        gap: 15px;
        flex-wrap: nowrap;
    }
}

.custom-control button {
    display: block;
    padding: 10px;
    background: white;
    border: none;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
    text-align: left;
}

.custom-control button:hover {
    background-color: #f0f0f0;
}

.custom-control button.active {
    background-color: #007cbf;
    color: white;
}

/* Style Selector - inherits from .mapboxgl-ctrl-group button */

.style-selector.mapboxgl-ctrl-group button:focus {
    box-shadow: none;
}

.style-selector.mapboxgl-ctrl-group button + button {
    border-top: 1px solid rgba(0,0,0,0.15);
}

.style-selector button svg {
    width: 20px;
    height: 20px;
}

.style-selector button:hover {
    background-color: #f0f0f0;
}

/* Display Selector */
.display-selector {
    position: relative;
}

.display-selector-button {
    background-color: #fff;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.display-selector-button:hover {
    background-color: #f0f0f0;
}

.display-selector-button.active {
    background-color: #e0e0e0;
}

.display-selector-dropdown {
    position: absolute;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    min-width: 160px;
    z-index: 10;
    overflow: hidden;
}

.display-selector-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    white-space: nowrap;
}

.display-selector-item:hover {
    background-color: #f0f0f0;
}

.display-selector-item.active {
    background-color: #007cbf;
    color: white;
}

body.dark-style .display-selector-button,
body.satellite-style .display-selector-button {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
}

body.dark-style .display-selector-button:hover,
body.satellite-style .display-selector-button:hover {
    background-color: #f0f0f0;
}

body.dark-style .display-selector-dropdown,
body.satellite-style .display-selector-dropdown {
    background: rgba(30, 30, 50, 0.95);
}

body.dark-style .display-selector-item,
body.satellite-style .display-selector-item {
    color: #ccc;
}

body.dark-style .display-selector-item:hover,
body.satellite-style .display-selector-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

body.dark-style .display-selector-item.active,
body.satellite-style .display-selector-item.active {
    background-color: #007cbf;
    color: white;
}

/* Label Toggle */
.label-toggle-button {
    background-color: #fff;
    border: none;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.label-toggle-button:hover {
    background-color: #f0f0f0;
}

.label-toggle-button:not(.active) {
    opacity: 0.4;
}

body.dark-style .label-toggle-button,
body.satellite-style .label-toggle-button {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
}

body.dark-style .label-toggle-button:hover,
body.satellite-style .label-toggle-button:hover {
    background-color: #f0f0f0;
}

/* Fuzzy Toggle */
.fuzzy-toggle-button {
    background-color: #fff;
    border: none;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.fuzzy-toggle-button:hover {
    background-color: #f0f0f0;
}

.fuzzy-toggle-button:not(.active) {
    opacity: 0.4;
}

body.dark-style .fuzzy-toggle-button,
body.satellite-style .fuzzy-toggle-button {
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
}

body.dark-style .fuzzy-toggle-button:hover,
body.satellite-style .fuzzy-toggle-button:hover {
    background-color: #f0f0f0;
}

/* Filter Panel Control */
.filter-panel-control button {
    position: relative;
}

.filter-panel-control button.has-filters::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: #007cbf;
    border-radius: 50%;
    border: 1px solid white;
}

.filter-panel {
    position: absolute;
    top: 60px;
    left: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    width: 250px;
    z-index: 1000;
}

body.dark-style .filter-panel,
body.satellite-style .filter-panel {
    background: rgba(0, 0, 0, 0.95);
    color: white;
}

.filter-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

body.dark-style .filter-panel-header,
body.satellite-style .filter-panel-header {
    border-bottom-color: rgba(255,255,255,0.1);
}

.filter-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
}

.filter-panel-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
}

body.dark-style .filter-panel-close,
body.satellite-style .filter-panel-close {
    color: #ccc;
}

.filter-panel-close:hover {
    color: #333;
}

body.dark-style .filter-panel-close:hover,
body.satellite-style .filter-panel-close:hover {
    color: white;
}

.filter-panel-content {
    padding: 15px;
}

.filter-group {
    margin-bottom: 15px;
}

.filter-group:last-child {
    margin-bottom: 0;
}

.filter-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 500;
    color: #333;
}

body.dark-style .filter-group label,
body.satellite-style .filter-group label {
    color: white;
}

.filter-group select {
    width: 100%;
    padding: 6px 10px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: white;
}

body.dark-style .filter-group select,
body.satellite-style .filter-group select {
    background: rgba(40, 40, 40, 0.9);
    color: white;
    border-color: #555;
}

/* Old Filter Controls - deprecated */
.filter-control {
    padding: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    margin: 0 !important;
    display: inline-block;
    vertical-align: middle;
}

.filter-wrapper {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.65);
    padding: 4px 8px;
    margin: 0;
    display: inline-block;
}

body.dark-style .filter-wrapper,
body.satellite-style .filter-wrapper {
    background: rgba(0, 0, 0, 0.8);
}

.filter-control label {
    display: inline-block;
    margin-right: 5px;
    font-size: 12px;
    font-weight: normal;
    color: #333;
}

body.dark-style .filter-control label,
body.satellite-style .filter-control label {
    color: white;
}

.filter-control select {
    width: auto;
    padding: 2px 5px;
    font-size: 12px;
    border: 1px solid #ccc;
    border-radius: 3px;
    background: white;
}

body.dark-style .filter-control select,
body.satellite-style .filter-control select {
    background: rgba(40, 40, 40, 0.9);
    color: white;
    border-color: #555;
}

/* Toggle Buttons */
.toggle-control {
    /* Inherit mapboxgl-ctrl-group styling */
}

.toggle-control.mapboxgl-ctrl-group {
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

/* Keep toggle controls light in all styles for visibility */
body.dark-style .toggle-control.mapboxgl-ctrl-group,
body.satellite-style .toggle-control.mapboxgl-ctrl-group {
    background: rgba(255, 255, 255, 0.9);
}

.toggle-button {
    background-size: cover;
    width: 32px;
    height: 32px;
    border: none;
    cursor: pointer;
    transition: opacity 0.3s ease;
    display: block;
    margin: 0;
    padding: 0;
    background-color: transparent;
}


.toggle-button + .toggle-button {
    border-top: 1px solid rgba(0,0,0,0.15);
}

.toggle-button.unique {
    background-image: url('/img/uniqueg.png');
}

.toggle-button.untaken {
    background-image: url('/img/zoner.png');
}


/* When the button is activated (visible), it will have normal opacity */
.toggle-button.activated {
    opacity: 1;
}

/* When the button is deactivated (hidden), the opacity will be reduced */
.toggle-button.deactivated {
    opacity: 0.4;
}

/* Zone Count Display */
.zone-count-control {
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 10px;
    border-radius: 8px;
    margin: 0;
}

body.dark-style .zone-count-control,
body.satellite-style .zone-count-control {
    background: rgba(0, 0, 0, 0.8);
}

.mapboxgl-ctrl-bottom-right .zone-count-control {
    margin: 10px;
    margin-bottom: 30px;
}

.point-count {
    font-size: 14px;
    font-weight: bold;
    margin: 0;
    color: #333;
}

.point-count:not(:last-child) {
    margin-bottom: 10px;
}

body.dark-style .point-count,
body.satellite-style .point-count {
    color: white;
}

#zone-counts-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#zone-counts-table th,
#zone-counts-table td {
    padding: 5px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

#zone-counts-table th {
    font-weight: bold;
    background-color: #f0f0f0;
}

/* Map Popups */
.mapboxgl-popup {
    z-index: 3000;
}

.mapboxgl-popup-content {
    background: rgba(0, 0, 0, 0.85) !important;
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    min-width: 150px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.mapboxgl-popup-content a {
    color: #fff001;
    text-decoration: none;
    font-weight: 600;
}

.mapboxgl-popup-content a:hover {
    color: #ffff55;
    text-decoration: underline;
}

.mapboxgl-popup-content h3 {
    margin: 0 0 5px 0;
    font-size: 16px;
}

.mapboxgl-popup-content p {
    margin: 0;
    font-size: 14px;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.85) !important;
    margin-top: -1px;
}
.mapboxgl-popup-anchor-top .mapboxgl-popup-tip {
    border-bottom-color: rgba(0, 0, 0, 0.85) !important;
    margin-bottom: -1px;
}
.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
    border-right-color: rgba(0, 0, 0, 0.85) !important;
    margin-right: -1px;
}
.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
    border-left-color: rgba(0, 0, 0, 0.85) !important;
    margin-left: -1px;
}
.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
    border-top-color: rgba(0, 0, 0, 0.85) !important;
    margin-top: -1px;
}
.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
    border-bottom-color: rgba(0, 0, 0, 0.85) !important;
    margin-bottom: -1px;
}

.mapboxgl-popup-close-button {
    color: white;
    font-size: 20px;
    padding: 0;
    margin: 0;
    width: 20px;
    height: 20px;
    right: 6px;
    top: 6px;
}

.mapboxgl-popup-close-button:hover {
    background: none;
    color: #4db8ff;
}

/* Zone Popup */
.zone-popup a {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 2px;
}

.zone-popup-type {
    font-size: 11px;
    opacity: 0.5;
    margin-bottom: 8px;
}

.zone-popup-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 16px;
}

.zone-popup-metric {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
}

.zone-popup-label {
    opacity: 0.6;
}

.zone-popup-value {
    font-weight: 600;
    text-align: right;
}

.zone-popup-metric-wide {
    grid-column: 1 / -1;
}


/* Region suggestion banner */
.region-suggest-banner {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    background: rgba(0, 0, 0, 0.8);
    color: #ccc;
    padding: 8px 32px 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.region-suggest-link {
    color: #fff001;
    font-weight: 600;
    text-decoration: none;
}

.region-suggest-link:hover {
    text-decoration: underline;
    color: #ffff55;
}

.region-suggest-close {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #999;
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.region-suggest-close:hover {
    color: #fff;
}

/* Responsive */
@media (max-width: 390px) {
    #map-header {
        padding: 10px;
    }
    
    #map-selectors {
        flex-direction: column;
        width: 100%;
    }
    
    #map-selectors select {
        width: 100%;
    }
    
    .map-description {
        display: none;
    }
}

/* Loading State */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.map-loading::after {
    content: 'Loading map data...';
    font-size: 16px;
}

/* Error State */
.map-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #f8d7da;
    color: #721c24;
    padding: 20px;
    border-radius: 4px;
    border: 1px solid #f5c6cb;
    max-width: 400px;
    text-align: center;
}


/* Utility Classes */
.hidden {
    display: none !important;
}

.text-dark {
    color: #333 !important;
}

.text-light {
    color: white !important;
}

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

.fade-in {
    animation: fadeIn 0.3s ease-in;
}