/**
 * SASE Territory Map Styles
 */

/* Map container */
.sase-map-container {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 20px;
    margin: 20px 0;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 576px) {
    .sase-map-container {
        gap: 15px;
        margin: 15px 0;
    }
}

.sase-map-wrapper {
    flex: 1 1 60%;
    min-width: 400px;
    max-width: 65%;
}

@media (max-width: 991px) {
    .sase-map-container {
        flex-direction: column-reverse;
    }
    
    .sase-map-wrapper {
        flex: 1 1 100%;
        max-width: 100%;
        min-width: 300px;
        order: 2;
    }
    
    .sase-territory-list-container {
        order: 1;
        margin-bottom: 20px;
    }
}

.leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
    -ms-touch-action: none;
    touch-action: none;
    height: 680px !important;
}

@media (max-width: 768px) {
    .leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
        height: 500px !important;
    }
}

@media (max-width: 576px) {
    .leaflet-container.leaflet-touch-drag.leaflet-touch-zoom {
        height: 400px !important;
    }
}

.sase-territory-map {
    transition: all 0.3s ease;
    height: 600px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .sase-territory-map {
        height: 500px;
    }
}

@media (max-width: 576px) {
    .sase-territory-map {
        height: 400px;
    }
}

/* Filter Styles */
.sase-territory-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.sase-filter {
    flex: 1 1 100%;
    min-width: 100%;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

.sase-filter input {
    padding: 8px 12px;
}

.sase-filter-row {
    display: flex;
    flex-direction: row;
    gap: 15px;
    width: 100%;
}

.sase-filter-half {
    flex: 1 1 50%;
    min-width: 120px;
}

/* Make filters responsive */
@media (min-width: 576px) {
    .sase-filter {
        flex: 1 1 45%;
        min-width: 45%;
    }
}

@media (min-width: 768px) {
    .sase-filter {
        flex: 1 1 30%;
        min-width: 0;
    }
}

.sase-filter input[type="text"] {
    width: 100%;
    padding: 8px 12px !important;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
    max-width: 100%;
}

.sase-filter select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
    max-width: 100%;
    font-size: 14px;
    background-color: white;
}

.sase-filter input[type="text"]:focus,
.sase-filter select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Territory List Styles */
.sase-territory-list-container {
    flex: 1 1 30%;
    min-width: 300px;
    max-height: 680px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 10px;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    margin: 0;
}

@media (max-width: 991px) {
    .sase-territory-list-container {
        flex: 1 1 100%;
        max-width: 100%;
        max-height: 700px;
    }
}

@media (max-width: 576px) {
    .sase-territory-list-container {
        max-height: 700px;
    }
}

#sase-territory-results {
    height: 100%;
    overflow-y: scroll;
}

.territory-list-scrollable {
    overflow-y: auto;
    flex: 1;
    padding-right: 0;
}

.sase-territory-list-container h3 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
    color: #333;
}

.sase-territory-group {
    margin-bottom: 20px;
}

.sase-territory-group h4 {
    display: flex;
    align-items: center;
    font-size: 16px;
    margin-bottom: 10px;
}

.color-indicator {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 3px;
    margin-right: 10px;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.sase-territory-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-left: 0;
}

.sase-territory-item {
    background-color: rgba(249, 249, 249, 0.9); /* Default background, will be overridden */
    border-radius: 4px;
    padding: 10px;
    border-left: 4px solid #ddd; /* Default border, will be overridden */
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 15px;
    min-height: 80px;
    cursor: pointer; /* Add pointer cursor to indicate clickability */
    position: relative; /* For potential hover effects */
}

@media (max-width: 768px) {
    .sase-territory-item {
        align-items: flex-start;
        gap: 10px;
        padding: 12px;
    }
    
    .sase-territory-item .sase-territory-agent-image {
        margin-right: auto;
        margin-left: auto;
    }
}

.sase-territory-item:hover {
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
    border-left-width: 6px !important;
}

.sase-territory-item:active {
    transform: translateY(0px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.sase-territory-item h5 {
    margin-top: 0;
    margin-bottom: 5px;
    padding-bottom: 3px;
    font-size: 14px;
    color: #333;
    font-weight: 600;
    border-bottom: 1px solid #ccc;
}

.sase-territory-item p {
    margin: 4px 0;
    font-size: 13px;
    line-height: 1.4;
    color: #333;
}

/* Agent image styles */
.sase-territory-agent-image {
    flex: 0 0 80px;
    display: flex !important;
    align-items: center;
    height: 100%;
}

.sase-territory-agent-image img {
    width: 100%;
    height: auto;
    min-height: 80px;
    max-height: 100%;
    border-radius: 8px;
    object-fit: cover;
    object-position: top;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: block !important;
}

/* Popup agent image styles */
.sase-territory-popup {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sase-territory-popup .rep-name-header {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 10px 0;
    padding: 0 0 5px 0;
    border-bottom: 1px solid #eee;
    text-align: center;
    color: #333;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sase-territory-popup .popup-content-wrapper {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}

.sase-territory-popup .sase-territory-agent-image {
    width: 100%;
    display: flex !important;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    height: 100%;
}

.sase-territory-popup .sase-territory-agent-image img {
    width: 100%;
    height: 100%;
    display: block !important;
    object-fit: cover;
    object-position: top;
    border: 2px solid #fff;
    box-shadow: none;
    height: 300px;
}

.sase-territory-popup .sase-territory-info {
    width: 100%;
}

.sase-territory-popup .sase-territory-info a {
    color: #333;
    text-decoration: none;
}

.sase-territory-popup .sase-territory-info a:hover {
    text-decoration: underline;
}

.sase-territory-popup .sase-territory-info h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
}

/* Territory info container */
.sase-territory-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.sase-territory-item a {
    color: #333;
    text-decoration: none;
}

.sase-territory-item a:hover {
    text-decoration: underline;
}

.sase-map-admin-placeholder h3,
.sase-map-admin-placeholder p,
.sase-territory-map-title,
.sase-territory-map-description {
    color: #000000;
    text-align: center;
    width: 100%;
}

/* Hide Leaflet attribution */
.leaflet-control-attribution,
.leaflet-control-attribution.leaflet-control {
    display: none !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sase-territory-items {
        grid-template-columns: 1fr;
    }
}

/* Map border style */
.sase-territory-map {
    border-color: #ddd;
}

/* Mode toggle button removed */

.sase-territory-popup .leaflet-popup-content p {
    margin: 5px 0 !important;
    padding: 0 !important;
}

/* Agent marker styles */
.agent-marker-container {
    background: transparent;
    border: none;
}

.agent-marker {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid;
    background-size: cover;
    background-position: center;
    box-shadow: 0 0 5px rgba(0,0,0,0.3);
}

/* Region marker styles - make them more distinct */
.region-marker {
    border-width: 3px;
    box-shadow: 0 0 8px rgba(0,0,0,0.5);
    z-index: 1000 !important;
}

/* Bounce animation for marker highlighting */
@keyframes marker-bounce {
    0%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

.marker-bounce {
    animation: marker-bounce 0.8s ease-in-out;
    animation-iteration-count: 1;
}

/* Interactive region polygon styles */
.interactive-region {
    transition: all 0.3s ease;
    cursor: pointer;
}

.interactive-region:hover {
    stroke-width: 4px;
    filter: drop-shadow(0 0 5px rgba(0,0,0,0.5));
}

/* Specific styles for Western and Eastern PA regions */
.western-pa-region {
    stroke-linejoin: round;
}

.eastern-pa-region {
    stroke-linejoin: round;
}

/* Popup enhancements */
.leaflet-popup-content {
    padding: 5px;
    max-width: 300px;
}

.leaflet-popup-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Popup styles */
.sase-territory-popup {
    padding: 5px;
    width: auto;
    min-width: 250px;
}

/* Override Leaflet's default popup width constraints */
.leaflet-popup-content {
    width: auto !important;
    min-width: 250px;
    max-width: 500px;
}

/* Ensure popup content is properly sized */
.leaflet-popup {
    max-width: 80vw;
}

/* Improve popup content display */
.leaflet-popup-content-wrapper {
    padding: 2px;
}

/* Ensure popup images don't overflow */
.sase-territory-popup img {
    max-width: 100%;
    height: auto;
}

.sase-territory-popup h3 {
    margin: 0 0 10px 0;
    padding-bottom: 5px;
    border-bottom: 1px solid #eee;
    font-size: 16px;
}

.sase-territory-popup p {
    margin: 5px 0;
    font-size: 14px;
}

/* Legend styles */
.sase-map-legend {
    background: white;
    padding: 10px;
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
    line-height: 1.5;
    color: #333;
    max-height: 300px;
    overflow-y: auto;
}

.sase-map-legend h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
    font-weight: bold;
}

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

.color-box {
    width: 15px;
    height: 15px;
    display: inline-block;
    margin-right: 8px;
    border-radius: 50%;
    border: 1px solid #ccc;
}

.color-label {
    font-size: 12px;
}

/* Custom marker styles */
.sase-territory-marker {
    border: none;
    background: none;
}

/* Layer control customization */
.leaflet-control-layers {
    max-height: 300px;
    overflow-y: auto;
}

.leaflet-control-layers-list label {
    margin-bottom: 5px;
    display: block;
}

.sase-territory-popup .sase-territory-info p {
    margin: 5px 0;
    font-size: 13px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .sase-territory-popup {
        min-width: 150px;
        max-width: 280px;
    }
    
    .sase-map-legend {
        max-width: 200px;
    }
    
    .sase-territory-popup .sase-territory-agent-image img {
        height: 200px;
    }
    
    .sase-filter-row {
        gap: 10px;
    }
    
    .sase-filter-half {
        width: 100%;
    }
}

@media (max-width: 576px) {
    .sase-territory-popup {
        min-width: 120px;
        max-width: 220px;
    }
    
    .sase-territory-popup .sase-territory-agent-image img {
        height: 150px;
    }
    
    .sase-territory-popup .sase-territory-info p {
        margin: 5px 0;
        font-size: 13px;
    }
    
    .sase-territory-popup .rep-name-header {
        font-size: 16px;
    }
}
