/* CSS para Sistema de Mapas Simple - OpenStreetMap */
/* Responsivo para PC, tablet y móvil */

/* Contenedor principal del mapa */
#mapContainer {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin-top: 10px;
    margin-bottom: 15px;
    background-color: #f8f9fa;
    position: relative;
    overflow: hidden;
}

/* Contenedor de mapa para cobertura */
#coverageMapContainer {
    width: 100%;
    height: 360px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background-color: #f8f9fa;
    overflow: hidden;
}

/* Estados del contenedor */
#mapContainer.oculto {
    display: none;
}

#mapContainer.visible {
    display: block;
}

/* Estilos para el mapa de Leaflet */
.leaflet-container {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    width: 100%;
    height: 100%;
    border-radius: 7px;
}

/* Controles de Leaflet */
.leaflet-control-container .leaflet-control {
    border-radius: 4px;
    box-shadow: 0 1px 5px rgba(0,0,0,0.4);
}

.leaflet-control-zoom {
    border: 2px solid rgba(0,0,0,0.2);
}

.leaflet-control-zoom a {
    width: 30px;
    height: 30px;
    line-height: 30px;
    font-size: 18px;
    color: #333;
    background-color: white;
    border-bottom: 1px solid #ccc;
}

.leaflet-control-zoom a:hover {
    background-color: #f4f4f4;
}

.leaflet-control-zoom a:first-child {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

.leaflet-control-zoom a:last-child {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    border-bottom: none;
}

/* Marcador personalizado */
.leaflet-marker-icon {
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

/* Popup del marcador */
.leaflet-popup {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.leaflet-popup-content-wrapper {
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    border: 1px solid #ddd;
}

.leaflet-popup-content {
    font-size: 14px;
    line-height: 1.4;
    margin: 10px 15px;
}

.leaflet-popup-content h3 {
    margin: 0 0 8px 0;
    color: #2c3e50;
    font-size: 16px;
}

.leaflet-popup-content p {
    margin: 5px 0;
    color: #555;
}

/* Contenedor de sugerencias de direcciones */
.address-suggestions {
    position: absolute;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-top: 2px;
}

.address-suggestion-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    line-height: 1.4;
    transition: background-color 0.2s;
}

.address-suggestion-item:hover {
    background-color: #f5f5f5;
}

.address-suggestion-item:last-child {
    border-bottom: none;
}

.address-suggestion-item .address-main {
    font-weight: 600;
    color: #2c3e50;
}

.address-suggestion-item .address-details {
    font-size: 12px;
    color: #7f8c8d;
    margin-top: 2px;
}

/* Botones de control del mapa */
.map-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.map-control-btn {
    width: 36px;
    height: 36px;
    background: white;
    border: 2px solid rgba(0,0,0,0.2);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: #333;
    transition: all 0.2s;
    box-shadow: 0 1px 5px rgba(0,0,0,0.1);
}

.map-control-btn:hover {
    background-color: #f4f4f4;
    transform: scale(1.05);
}

.map-control-btn.active {
    background-color: #3498db;
    color: white;
    border-color: #2980b9;
}

/* Indicador de carga */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 20px 30px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 1000;
    text-align: center;
    display: none;
}

.map-loading.visible {
    display: block;
}

.map-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.map-loading-text {
    color: #2c3e50;
    font-weight: 600;
    font-size: 14px;
}

/* Notificaciones del mapa */
.map-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 20px;
    border-radius: 6px;
    color: white;
    font-weight: 600;
    z-index: 2000;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease-out;
    max-width: 350px;
    display: flex;
    align-items: center;
    gap: 10px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.map-notification.success {
    background-color: #27ae60;
    border-left: 4px solid #219653;
}

.map-notification.error {
    background-color: #e74c3c;
    border-left: 4px solid #c0392b;
}

.map-notification.warning {
    background-color: #f39c12;
    border-left: 4px solid #d68910;
}

.map-notification.info {
    background-color: #3498db;
    border-left: 4px solid #2980b9;
}

.map-notification-icon {
    font-size: 20px;
}

.map-notification-content {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
}

/* Estilos para el campo de coordenadas con mapa */
.coordenadas-con-mapa {
    position: relative;
}

.coordenadas-con-mapa input {
    padding-right: 40px;
}

.coordenadas-map-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #3498db;
    cursor: pointer;
    font-size: 18px;
    background: none;
    border: none;
    padding: 5px;
    transition: color 0.2s;
}

.coordenadas-map-icon:hover {
    color: #2980b9;
}

/* Responsividad */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    #mapContainer {
        height: 350px;
    }
    
    .map-controls {
        top: 5px;
        right: 5px;
    }
    
    .map-control-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .map-notification {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
}

/* Móvil grande (576px - 768px) */
@media (max-width: 768px) {
    #mapContainer {
        height: 300px;
        border-radius: 6px;
        margin-top: 8px;
        margin-bottom: 12px;
    }

    #coverageMapContainer {
        height: 280px;
        border-radius: 6px;
    }
    
    .leaflet-container {
        border-radius: 5px;
    }
    
    .leaflet-control-zoom a {
        width: 28px;
        height: 28px;
        line-height: 28px;
        font-size: 16px;
    }
    
    .address-suggestions {
        max-height: 150px;
    }
    
    .address-suggestion-item {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .map-loading {
        padding: 15px 20px;
    }
    
    .map-loading-spinner {
        width: 30px;
        height: 30px;
    }
    
    .map-loading-text {
        font-size: 13px;
    }
}

/* Móvil pequeño (hasta 576px) */
@media (max-width: 576px) {
    #mapContainer {
        height: 250px;
        margin-top: 6px;
        margin-bottom: 10px;
    }

    #coverageMapContainer {
        height: 240px;
    }
    
    .leaflet-control-zoom {
        display: none; /* Ocultar controles de zoom en móviles muy pequeños */
    }
    
    .map-controls {
        display: none; /* Ocultar controles personalizados */
    }
    
    .address-suggestions {
        position: fixed;
        top: 50%;
        left: 10px;
        right: 10px;
        max-height: 180px;
        transform: translateY(-50%);
    }
    
    .map-notification {
        top: 5px;
        right: 5px;
        left: 5px;
        padding: 12px 15px;
        font-size: 13px;
    }
    
    .map-notification-icon {
        font-size: 18px;
    }
}

/* Orientación horizontal en móviles */
@media (max-height: 500px) and (orientation: landscape) {
    #mapContainer {
        height: 200px;
    }

    #coverageMapContainer {
        height: 200px;
    }
    
    .map-controls {
        top: 2px;
        right: 2px;
    }
    
    .map-control-btn {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* Modo de alto contraste para accesibilidad */
@media (prefers-contrast: high) {
    #mapContainer {
        border: 2px solid #000;
    }
    
    .leaflet-control-zoom a {
        border: 2px solid #000;
    }
    
    .address-suggestions {
        border: 2px solid #000;
    }
    
    .address-suggestion-item {
        border-bottom: 2px solid #000;
    }
    
    .map-control-btn {
        border: 2px solid #000;
    }
}

/* Modo oscuro (si el sistema lo soporta) */
@media (prefers-color-scheme: dark) {
    #mapContainer {
        background-color: #2c3e50;
        border-color: #34495e;
    }
    
    .leaflet-container {
        background-color: #34495e;
    }
    
    .leaflet-control-zoom a {
        background-color: #2c3e50;
        color: #ecf0f1;
        border-color: #34495e;
    }
    
    .leaflet-control-zoom a:hover {
        background-color: #34495e;
    }
    
    .leaflet-popup-content-wrapper {
        background-color: #2c3e50;
        border-color: #34495e;
        color: #ecf0f1;
    }
    
    .leaflet-popup-content h3 {
        color: #ecf0f1;
    }
    
    .leaflet-popup-content p {
        color: #bdc3c7;
    }
    
    .address-suggestions {
        background-color: #2c3e50;
        border-color: #34495e;
        color: #ecf0f1;
    }
    
    .address-suggestion-item {
        border-bottom-color: #34495e;
        color: #ecf0f1;
    }
    
    .address-suggestion-item:hover {
        background-color: #34495e;
    }
    
    .address-suggestion-item .address-main {
        color: #ecf0f1;
    }
    
    .address-suggestion-item .address-details {
        color: #bdc3c7;
    }
    
    .map-control-btn {
        background-color: #2c3e50;
        color: #ecf0f1;
        border-color: #34495e;
    }
    
    .map-control-btn:hover {
        background-color: #34495e;
    }
    
    .map-control-btn.active {
        background-color: #3498db;
        border-color: #2980b9;
    }
    
    .map-loading {
        background-color: rgba(44, 62, 80, 0.95);
        color: #ecf0f1;
    }
    
    .map-loading-spinner {
        border-color: #34495e;
        border-top-color: #3498db;
    }
    
    .map-loading-text {
        color: #ecf0f1;
    }
    
    .coordenadas-map-icon {
        color: #3498db;
    }
    
    .coordenadas-map-icon:hover {
        color: #2980b9;
    }
}

/* Impresión */
@media print {
    #mapContainer {
        height: 300px;
        border: 1px solid #999;
        page-break-inside: avoid;
    }
    
    .map-controls,
    .map-notification,
    .map-loading {
        display: none !important;
    }
    
    .leaflet-control-container {
        display: none;
    }
}

/* Utilidades */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Estados de error y éxito para campos */
input.coordenadas-valido {
    border-color: #27ae60 !important;
    background-color: rgba(39, 174, 96, 0.05) !important;
}

input.coordenadas-invalido {
    border-color: #e74c3c !important;
    background-color: rgba(231, 76, 60, 0.05) !important;
}

input.coordenadas-cargando {
    border-color: #3498db !important;
    background-color: rgba(52, 152, 219, 0.05) !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24"><path fill="%233498db" d="M12 2a10 10 0 1 0 10 10A10 10 0 0 0 12 2zm0 18a8 8 0 1 1 8-8 8 8 0 0 1-8 8z" opacity=".5"/><path fill="%233498db" d="M12 2a10 10 0 0 1 10 10h-2a8 8 0 0 0-8-8z"><animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="1s" repeatCount="indefinite"/></path></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px 20px;
    padding-right: 40px !important;
}

/* Tooltips para accesibilidad */
[data-tooltip] {
    position: relative;
}

[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #2c3e50;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
