/**
 * 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;
    }
}

/* ===== LOCATION SEARCH INPUT ===== */

.location-search-wrapper {
    position: relative;
    margin-bottom: 1.25rem;
}

.location-search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    border: 2px solid #dee2e6;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    font-family: 'Cairo', sans-serif;
    direction: rtl;
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: #fff;
}

.location-search-input:focus {
    outline: none;
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
}

.location-search-input::placeholder {
    color: #adb5bd;
}

.location-search-icon {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 1.1rem;
    pointer-events: none;
    z-index: 2;
}

.location-search-spinner {
    position: absolute;
    left: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    z-index: 2;
}

.location-search-spinner .spinner-border {
    width: 1.1rem;
    height: 1.1rem;
    border-width: 2px;
}

.location-search-wrapper.is-loading .location-search-icon {
    display: none;
}

.location-search-wrapper.is-loading .location-search-spinner {
    display: block;
}

.location-search-hint {
    font-size: 0.825rem;
    color: #6c757d;
    margin-top: 0.35rem;
}

/* Autocomplete dropdown */
.location-autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1050;
    background: #fff;
    border: 1px solid #dee2e6;
    border-top: none;
    border-radius: 0 0 0.5rem 0.5rem;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    max-height: 280px;
    overflow-y: auto;
    display: none;
}

.location-autocomplete-dropdown.show {
    display: block;
}

.location-autocomplete-item {
    padding: 0.65rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f1f3f5;
    direction: rtl;
    text-align: right;
    transition: background-color 0.15s;
}

.location-autocomplete-item:last-child {
    border-bottom: none;
}

.location-autocomplete-item:hover,
.location-autocomplete-item.active {
    background-color: #e7f1ff;
}

.location-autocomplete-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #212529;
    margin-bottom: 0.15rem;
}

.location-autocomplete-item-detail {
    font-size: 0.8rem;
    color: #6c757d;
}

.location-autocomplete-no-results {
    padding: 0.75rem 1rem;
    text-align: center;
    color: #6c757d;
    font-size: 0.85rem;
}

/* Google Maps link detected indicator */
.location-search-status {
    margin-top: 0.5rem;
    font-size: 0.85rem;
    display: none;
}

.location-search-status.show {
    display: block;
}

.location-search-status.status-success {
    color: #198754;
}

.location-search-status.status-error {
    color: #dc3545;
}

.location-search-status.status-info {
    color: #0d6efd;
}

/* ===== LOCATION SEARCH RESPONSIVE ===== */

@media (max-width: 576px) {
    .location-search-input {
        padding: 0.65rem 0.85rem 0.65rem 2.5rem;
        font-size: 0.9rem;
    }

    .location-search-hint {
        font-size: 0.775rem;
    }

    .location-autocomplete-item {
        padding: 0.75rem 0.85rem;
    }
}

/* Touch devices: larger tap targets for autocomplete */
@media (hover: none) and (pointer: coarse) {
    .location-autocomplete-item {
        padding: 0.85rem 1rem;
        min-height: 48px;
    }
}

/* ===== 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;
}

/* ===== POPUP STATUS BADGE (broker dashboard) ===== */

.popup-status-badge {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    margin-right: 0.25rem;
    margin-bottom: 0.35rem;
}

.popup-status-approved  { background-color: #22c55e; }
.popup-status-pending   { background-color: #f59e0b; }
.popup-status-rejected  { background-color: #ef4444; }
.popup-status-sold      { background-color: #6366f1; }
.popup-status-rented    { background-color: #8b5cf6; }
.popup-status-draft     { background-color: #94a3b8; }

/* ===== POPUP ACTION BUTTONS (broker status change) ===== */

.popup-actions {
    display: flex;
    gap: 0.35rem;
    margin: 0.5rem 0 0.35rem;
    flex-wrap: wrap;
}

.popup-action-btn {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border: none;
    border-radius: 0.3rem;
    font-size: 0.72rem;
    font-weight: 600;
    font-family: 'Cairo', sans-serif;
    cursor: pointer;
    color: #fff;
    transition: opacity 0.2s, transform 0.1s;
    line-height: 1.4;
}

.popup-action-btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.popup-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.popup-action-btn.btn-sold    { background-color: #6366f1; }
.popup-action-btn.btn-rented  { background-color: #8b5cf6; }
.popup-action-btn.btn-draft   { background-color: #94a3b8; }
.popup-action-btn.btn-relist  { background-color: #22c55e; }

/* ===== BROKER DASHBOARD MAP ===== */

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

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

/* ===== HOMEPAGE & BROKER MAP RESPONSIVE ===== */

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

    #broker-dashboard-map {
        height: 350px;
    }
}

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

    #broker-dashboard-map {
        height: 300px;
    }

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

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

    .popup-action-btn {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
        min-height: 36px;
    }
}

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

    #broker-dashboard-map {
        height: 250px;
    }

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

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

    .popup-actions {
        flex-direction: column;
    }
}

/* ===== 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;
    }
}
