/**
 * Estilos para Sistema de Autocompletado de Direcciones con Mapbox
 * Compatible con el sistema de diseño de Asegura Core
 */

/* ===================================
   Contenedor Principal del Widget
   =================================== */

.asegura-mapbox-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 1rem;
}

/* Estilos para el contenedor del Search Box */
.asegura-mapbox-wrapper mapbox-search-box,
.asegura-mapbox-wrapper .mapbox-search-box {
    width: 100%;
    max-width: 100%;
    display: block;
}

/* Estilos para el input de búsqueda - Mapbox Search JS API */
.asegura-address-search,
input.asegura-address-search {
    padding: 14px 45px 11px 17px !important;
    border-radius: 13px !important;
    border: 1px solid #ced4da !important;
    color: var(--color-b, #004481) !important;
    font-size: 15px !important;
    height: 50px !important;
    font-family: 'Fieldwork', sans-serif;
    background-color: #fff;
    width: 100%;
}

.asegura-address-search:focus,
input.asegura-address-search:focus {
    background-color: #fff;
    border-color: var(--color-c, #31cba8) !important;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(49, 203, 168, 0.2) !important;
}

/* ===================================
   Dropdown de Sugerencias - Mapbox Search JS
   =================================== */

/* Estilos para el contenedor de sugerencias */
mapbox-search-listbox,
.mapbox-search-listbox {
    border-radius: 0 0 13px 13px;
    border: 1px solid #ced4da;
    border-top: none;
    box-shadow: 0 4px 8px rgba(46, 86, 108, 0.15);
    background-color: #fff;
    margin-top: -1px;
    max-height: 360px;
    overflow-y: auto;
}

/* Sugerencias individuales */
mapbox-search-listbox li,
.mapbox-search-listbox li {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 15px;
    color: var(--color-b, #004481);
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

mapbox-search-listbox li:hover,
.mapbox-search-listbox li:hover,
mapbox-search-listbox li[aria-selected="true"],
.mapbox-search-listbox li[aria-selected="true"] {
    background-color: rgba(0, 150, 150, 0.06);
}

mapbox-search-listbox li:last-child,
.mapbox-search-listbox li:last-child {
    border-bottom: none;
}



/* Botón dentro del dropdown */
.asegura-manual-dropdown-btn {
    padding: 12px 15px;
    border-top: 2px solid var(--color-a, #009696);
    background-color: var(--color-d, #eafcfd);
    color: var(--color-a, #009696);
    font-size: 15px;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.asegura-manual-dropdown-btn:hover {
    background-color: var(--color-c, #31cba8);
    color: #fff;
}

/* ===================================
   Campos Display Editables
   =================================== */

.asegura-address-field {
    position: relative;
}

.asegura-address-field input,
.asegura-address-field select {
    background-color: #fff !important;
    cursor: text;
}

.asegura-address-field input[readonly],
.asegura-address-field select[readonly] {
    background-color: #f8f9fa !important;
    cursor: not-allowed;
}

/* Indicador de campo editable */
.asegura-address-field::after {
    content: '✎';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-a, #009696);
    font-size: 18px;
    pointer-events: none;
    opacity: 0.4;
    transition: opacity 0.2s;
}

.asegura-address-field:focus-within::after {
    opacity: 0.8;
}

/* ===================================
   Estados de Validación
   =================================== */

/* Campo válido */
.asegura-address-field input.valid,
.asegura-address-field select.valid,
input.asegura-address-input.valid {
    border-color: var(--color-c, #31cba8) !important;
    background-color: #fff !important;
}

.asegura-address-field input.valid:focus,
.asegura-address-field select.valid:focus {
    box-shadow: 0 0 0 0.25rem rgba(49, 203, 168, 0.2) !important;
}

/* Campo con error */
.asegura-address-field input.error,
.asegura-address-field select.error,
input.asegura-address-input.error {
    border-color: var(--color-e, #ff2f76) !important;
    background-color: #fff !important;
}

.asegura-address-field input.error:focus,
.asegura-address-field select.error:focus {
    box-shadow: 0 0 0 0.25rem rgba(255, 47, 118, 0.2) !important;
}

/* Mensajes de error */
label.error {
    color: var(--color-e, #ff2f76) !important;
    font-size: 12px !important;
    padding: 8px 5px 4px !important;
    line-height: 1.4 !important;
    display: block;
}

/* ===================================
   Layout Responsive
   =================================== */

/* Contenedor de grupo de campos */
.asegura-address-group {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Layout de dos columnas en desktop */
@media (min-width: 768px) {
    .asegura-address-group--two-columns {
        grid-template-columns: 1fr 1fr;
    }

    .asegura-address-group--three-columns {
        grid-template-columns: 1fr 1fr 1fr;
    }

    .asegura-address-group--address-row {
        grid-template-columns: 2fr 1fr;
    }
}

/* Campo que ocupa toda la fila */
.asegura-address-field--full-width {
    grid-column: 1 / -1;
}

/* ===================================
   Animaciones
   =================================== */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.asegura-address-field.show-animation {
    animation: fadeIn 0.3s ease-out;
}

/* Transición suave al mostrar/ocultar elementos */
.asegura-mapbox-wrapper,

.asegura-mapbox-wrapper.hidden,


/* ===================================
   Estados de Carga
   =================================== */

.asegura-address-loading {
    position: relative;
}

.asegura-address-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    border-radius: 13px;
    z-index: 10;
}

.asegura-address-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin-top: -12px;
    margin-left: -12px;
    border: 3px solid var(--color-a, #009696);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 11;
}

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

/* ===================================
   Modo Manual - Campos Visibles
   =================================== */

.asegura-manual-mode .asegura-mapbox-wrapper {
    display: none;
}

.asegura-manual-mode .asegura-address-field {
    display: block;
}

/* ===================================
   Mensajes de Ayuda
   =================================== */

.asegura-address-help {
    font-size: 13px;
    color: #6c757d;
    margin-top: 5px;
    margin-bottom: 10px;
    line-height: 1.4;
}

.asegura-address-help-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background-color: var(--color-a, #009696);
    color: #fff;
    text-align: center;
    line-height: 16px;
    font-size: 12px;
    font-weight: bold;
    margin-right: 5px;
    cursor: help;
}

/* ===================================
   Accesibilidad
   =================================== */

/* Mejoras de contraste para lectores de pantalla */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible para teclado */
.asegura-mapbox-wrapper input:focus-visible,
.asegura-address-field input:focus-visible,
.asegura-address-field select:focus-visible {
    outline: 3px solid var(--color-c, #31cba8);
    outline-offset: 2px;
}

/* ===================================
   Responsive Mobile
   =================================== */

@media (max-width: 576px) {
    .asegura-address-search,
    input.asegura-address-search {
        font-size: 16px !important; /* Prevenir zoom en iOS */
    }


    mapbox-search-listbox,
    .mapbox-search-listbox {
        max-height: 300px;
    }

    mapbox-search-listbox li,
    .mapbox-search-listbox li {
        padding: 12px 15px;
    }
}

/* ===================================
   Compatibilidad con Select2
   =================================== */

.asegura-address-field .select2-container {
    width: 100% !important;
}

.asegura-address-field .select2-container .select2-selection--single {
    height: 50px !important;
    border: 1px solid #ced4da !important;
    border-radius: 13px !important;
}

.asegura-address-field .select2-container .select2-selection--single .select2-selection__rendered {
    line-height: 48px !important;
    padding-left: 17px !important;
    color: var(--color-b, #004481) !important;
}

.asegura-address-field .select2-container--focus .select2-selection {
    border-color: var(--color-c, #31cba8) !important;
    box-shadow: 0 0 0 0.25rem rgba(49, 203, 168, 0.2) !important;
}

.asegura-address-field .select2-container .select2-selection.error {
    border-color: var(--color-e, #ff2f76) !important;
}

/* ===================================
   Tema Oscuro (Opcional)
   =================================== */

@media (prefers-color-scheme: dark) {
    .asegura-address-search,
    input.asegura-address-search {
        background-color: #2d3748;
        color: #fff !important;
        border-color: #4a5568 !important;
    }

    mapbox-search-listbox,
    .mapbox-search-listbox {
        background-color: #2d3748;
        border-color: #4a5568;
    }

    mapbox-search-listbox li,
    .mapbox-search-listbox li {
        color: #e2e8f0;
        border-bottom-color: #4a5568;
    }

    mapbox-search-listbox li:hover,
    .mapbox-search-listbox li:hover,
    mapbox-search-listbox li[aria-selected="true"],
    .mapbox-search-listbox li[aria-selected="true"] {
        background-color: rgba(49, 203, 168, 0.2);
    }
}

/* ===================================
   Utilidades
   =================================== */

.asegura-address-hidden {
    display: none !important;
}

.asegura-address-visible {
    display: block !important;
}

.asegura-address-disabled {
    opacity: 0.6;
    pointer-events: none;
    cursor: not-allowed;
}

/* ===================================
   Print Styles
   =================================== */

@media print {
    .asegura-mapbox-wrapper,
    .mapboxgl-ctrl-geocoder .suggestions {
        display: none !important;
    }

    .asegura-address-field input,
    .asegura-address-field select {
        border: 1px solid #000 !important;
        background: #fff !important;
    }
}
