/**
 * Map Styles for ManzelMasr
 *
 * Responsive styles for map picker and map preview components.
 * Supports RTL layout and mobile-first design.
 */

/* ===== MAP PICKER SECTION ===== */

.map-picker-section {
    background: #f8f9fa;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 1rem;
}

.map-picker-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.map-picker-toggle-label {
    font-weight: 500;
    color: #495057;
}

.map-picker-container {
    margin-top: 1rem;
    display: none;
}

.map-picker-container.active {
    display: block;
}

/* Map wrapper with fixed aspect ratio */
.map-wrapper {
    position: relative;
    width: 100%;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 2px solid #dee2e6;
    background: #e9ecef;
}

/* Map container */
#map-picker,
#map-preview {
    width: 100%;
    height: 400px;
    z-index: 1;
}

/* Map controls */
.map-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.map-controls .btn {
    flex: 1;
    min-width: 120px;
}

/* Detected city indicator */
#detected-city-indicator {
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

/* Geolocation button spinner */
.spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== MAP PREVIEW SECTION ===== */

.map-preview-section {
    margin-top: 1.5rem;
}

.map-preview-card {
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid #dee2e6;
}

.map-preview-header {
    background: #f8f9fa;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.map-preview-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #495057;
}

.map-preview-actions {
    display: flex;
    gap: 0.5rem;
}

.open-in-maps-btn {
    font-size: 0.85rem;
    padding: 0.25rem 0.75rem;
}

/* ===== LEAFLET RTL FIXES ===== */

/* RTL adjustments for Leaflet controls */
.leaflet-right {
    right: auto;
    left: 10px;
}

.leaflet-left {
    left: auto;
    right: 10px;
}

/* Zoom controls */
.leaflet-control-zoom {
    border: none !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
}

/* Attribution */
.leaflet-control-attribution {
    font-size: 10px;
    background: rgba(255, 255, 255, 0.8) !important;
    padding: 2px 6px !important;
}

/* Popup styling */
.leaflet-popup-content-wrapper {
    border-radius: 0.5rem;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 0.75rem 1rem;
    font-family: 'Cairo', sans-serif;
    text-align: right;
    direction: rtl;
}

.leaflet-popup-tip {
    box-shadow: none;
}

/* Marker styling */
.leaflet-marker-icon {
    filter: hue-rotate(200deg);
}

/* ===== RESPONSIVE STYLES ===== */

/* Tablets */
@media (max-width: 992px) {
    #map-picker,
    #map-preview {
        height: 350px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .map-picker-section {
        padding: 0.75rem;
    }

    #map-picker,
    #map-preview {
        height: 300px;
    }

    .map-controls {
        flex-direction: column;
    }

    .map-controls .btn {
        min-width: 100%;
    }

    /* Larger touch targets */
    .leaflet-control-zoom a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
        font-size: 20px !important;
    }

    .map-preview-header {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .map-preview-actions {
        justify-content: stretch;
    }

    .map-preview-actions .btn {
        flex: 1;
    }
}

/* Small mobile */
@media (max-width: 576px) {
    #map-picker,
    #map-preview {
        height: 250px;
    }

    .map-picker-toggle-label {
        font-size: 0.9rem;
    }

    #detected-city-indicator {
        font-size: 0.85rem;
    }
}

/* Touch devices - always show larger controls */
@media (hover: none) and (pointer: coarse) {
    .leaflet-control-zoom a {
        width: 44px !important;
        height: 44px !important;
        line-height: 44px !important;
    }

    /* Larger popup close button */
    .leaflet-popup-close-button {
        width: 30px !important;
        height: 30px !important;
        font-size: 24px !important;
        padding: 4px !important;
    }
}

/* ===== LOADING STATE ===== */

.map-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.map-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #dee2e6;
    border-top-color: #0d6efd;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ===== FORM INTEGRATION ===== */

/* Hide map toggle when disabled */
.map-picker-disabled .map-picker-toggle {
    opacity: 0.5;
    pointer-events: none;
}

/* Coordinate display for debug */
.coordinate-display {
    font-family: monospace;
    font-size: 0.8rem;
    color: #6c757d;
    margin-top: 0.5rem;
}

/* ===== HOMEPAGE PROPERTY MAP ===== */

.property-map-section {
    background: #fff;
}

.homepage-map-wrapper {
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#homepage-map {
    width: 100%;
    height: 500px;
    z-index: 1;
    background: #e9ecef;
}

/* Loading placeholder */
.map-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    height: 100%;
    background: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
    color: #64748b;
    font-size: 0.95rem;
}

/* Filter buttons */
.map-filter-buttons .btn {
    border-radius: 2rem;
    padding: 0.35rem 1.25rem;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    min-width: 70px;
}

/* Legend */
.map-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: #64748b;
}

.legend-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.15);
}

.legend-dot-sale {
    background-color: #22c55e;
}

.legend-dot-rent {
    background-color: #f59e0b;
}

/* MarkerCluster themed colors */
.marker-cluster-themed {
    background-color: rgba(37, 99, 235, 0.25);
}

.marker-cluster-themed div {
    background-color: #2563eb;
    color: #fff;
    width: 30px;
    height: 30px;
    margin: 5px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Cairo', sans-serif;
}

.marker-cluster-themed.marker-cluster-large div {
    width: 34px;
    height: 34px;
    margin: 3px;
    font-size: 14px;
}

/* Property popup */
.property-popup {
    text-align: right;
    direction: rtl;
    font-family: 'Cairo', sans-serif;
    min-width: 180px;
    max-width: 240px;
}

.popup-badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 0.35rem;
}

.popup-badge.badge-sale {
    background-color: #22c55e;
}

.popup-badge.badge-rent {
    background-color: #f59e0b;
}

.popup-type {
    display: inline-block;
    font-size: 0.75rem;
    color: #64748b;
    margin-right: 0.35rem;
}

.popup-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0.25rem 0;
    color: #1e293b;
    line-height: 1.4;
}

.popup-price {
    font-size: 0.95rem;
    font-weight: 700;
    color: #2563eb;
    margin-bottom: 0.35rem;
}

.popup-link {
    display: inline-block;
    font-size: 0.8rem;
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

.popup-link:hover {
    text-decoration: underline;
}

/* ===== HOMEPAGE MAP RESPONSIVE ===== */

@media (max-width: 992px) {
    #homepage-map {
        height: 400px;
    }
}

@media (max-width: 768px) {
    #homepage-map {
        height: 350px;
    }

    .map-filter-buttons .btn {
        padding: 0.4rem 1rem;
        min-height: 44px;
    }

    .property-popup {
        min-width: 160px;
        max-width: 200px;
    }
}

@media (max-width: 576px) {
    #homepage-map {
        height: 280px;
    }

    .homepage-map-wrapper {
        border-radius: 0.5rem;
    }

    .map-filter-buttons .btn {
        font-size: 0.85rem;
        padding: 0.4rem 0.75rem;
    }
}

/* ===== CITY GROUPS PAGE ===== */

.city-group-card {
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.city-group-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-color: #2563eb;
}

.property-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    font-family: 'Cairo', sans-serif;
}

.city-stats {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* ===== CITY MAP ===== */

#city-map {
    width: 100%;
    height: 400px;
    z-index: 1;
    background: #e9ecef;
}

.city-header {
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 1rem;
}

/* City map responsive */
@media (max-width: 992px) {
    #city-map {
        height: 350px;
    }
}

@media (max-width: 768px) {
    #city-map {
        height: 280px;
    }
}

@media (max-width: 576px) {
    #city-map {
        height: 250px;
    }

    .property-count-badge {
        width: 48px;
        height: 48px;
        font-size: 1.1rem;
    }
}
