/* =========================================================
   BOTÓN TRIGGER — integrado junto a "Billing details"
========================================================= */

.sp-dir-checkout-bar {
    margin-bottom: 20px;
}

/* En checkout-steps (free) la barra se pinta antes de las dos cards
   (contacto + dirección), porque una dirección guardada rellena ambas.
   Se alinea a la derecha, como acción independiente del bloque. */
#customer_details > .sp-dir-checkout-bar {
    display: flex;
    justify-content: flex-end;
}

.sp-dir-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 16px;
    background: #fff;
    color: #111827;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    line-height: 1.4;
}

.sp-dir-trigger-btn svg {
    flex-shrink: 0;
    opacity: 0.6;
}

.sp-dir-trigger-btn:hover {
    border-color: #111827;
    color: black;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    background: #f9fafb;
}

/* =========================================================
   DARK THEME
========================================================= */

body.sp-wsv-theme-dark .sp-dir-trigger-btn {
    background: #1f2937;
    color: #f9fafb;
    border-color: #374151;
}

body.sp-wsv-theme-dark .sp-dir-trigger-btn:hover {
    background: #374151;
    border-color: #4b5563;
    color: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

body.sp-wsv-theme-dark .sp-dir-trigger-btn svg {
    opacity: 0.7;
}

/* =========================================================
   DARK THEME - OVERLAY & POPUP
========================================================= */

body.sp-wsv-theme-dark .sp-dir-overlay {
    background: rgba(0, 0, 0, 0.6);
}

body.sp-wsv-theme-dark .sp-dir-popup {
    background: #1f2937;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3), 0 16px 48px -4px rgba(0,0,0,0.5);
}

body.sp-wsv-theme-dark .sp-dir-popup__head {
    border-bottom-color: #374151;
}

body.sp-wsv-theme-dark .sp-dir-popup__title {
    color: #f9fafb;
}

body.sp-wsv-theme-dark .sp-dir-popup__close {
    color: #9ca3af;
}

body.sp-wsv-theme-dark .sp-dir-popup__close:hover {
    color: #f9fafb;
    background: #374151;
}

/* =========================================================
   DARK THEME - DIRECCIONES
========================================================= */

body.sp-wsv-theme-dark .sp_direccion_guardada {
    background: #374151;
    border-color: #4b5563;
}

body.sp-wsv-theme-dark .sp_direccion_guardada.clickable:hover {
    background: #4b5563;
    border-color: #6b7280;
}

body.sp-wsv-theme-dark .sp_direccion_guardada .alias_direccion {
    color: #f9fafb;
}

body.sp-wsv-theme-dark .sp_direccion_guardada .direccion {
    color: #d1d5db;
}

body.sp-wsv-theme-dark .sp_direccion_guardada .borrar_direccion {
    background: #1f2937;
    color: #d1d5db;
    border-color: #4b5563;
}

body.sp-wsv-theme-dark .sp_direccion_guardada .borrar_direccion:hover {
    color: #f9fafb;
    border-color: #6b7280;
}

/* =========================================================
   DARK THEME - BOTONES
========================================================= */

body.sp-wsv-theme-dark .sp-popup-footer button:first-child,
body.sp-wsv-theme-dark .sp-popup-footer .btn_iny_direccion {
    background: #f9fafb;
    color: #111827;
    border-color: #f9fafb;
}

body.sp-wsv-theme-dark .sp-popup-footer button:first-child:hover,
body.sp-wsv-theme-dark .sp-popup-footer .btn_iny_direccion:hover {
    background: #e5e7eb;
    border-color: #e5e7eb;
}

body.sp-wsv-theme-dark .sp-popup-footer button:last-child:not(:first-child) {
    background: #1f2937;
    color: #d1d5db;
    border-color: #4b5563;
}

body.sp-wsv-theme-dark .sp-popup-footer button:last-child:not(:first-child):hover {
    border-color: #6b7280;
    background: #374151;
    color: #f9fafb;
}

body.sp-wsv-theme-dark .sp-popup-footer .btn_iny_direccion + .btn_iny_direccion {
    background: #1f2937;
    color: #d1d5db;
    border-color: #4b5563;
}

body.sp-wsv-theme-dark .sp-popup-footer .btn_iny_direccion + .btn_iny_direccion:hover {
    border-color: #6b7280;
    background: #374151;
    color: #f9fafb;
}

/* =========================================================
   DARK THEME - INPUTS
========================================================= */

body.sp-wsv-theme-dark .sp-popup__body input[type="text"],
body.sp-wsv-theme-dark .sp-popup__body input[type="search"] {
    background: #374151;
    color: #f9fafb;
    border-color: #4b5563;
}

body.sp-wsv-theme-dark .sp-popup__body input[type="text"]::placeholder,
body.sp-wsv-theme-dark .sp-popup__body input[type="search"]::placeholder {
    color: #9ca3af;
}

body.sp-wsv-theme-dark .sp-popup__body input[type="text"]:focus,
body.sp-wsv-theme-dark .sp-popup__body input[type="search"]:focus {
    border-color: #f9fafb;
    box-shadow: 0 0 0 3px rgba(249,250,251,0.15);
}

/* =========================================================
   DARK THEME - OTROS
========================================================= */

body.sp-wsv-theme-dark #listado_mis_direcciones.loading {
    color: #d1d5db;
}

body.sp-wsv-theme-dark #listado_mis_direcciones.loading::after {
    border-color: #4b5563;
    border-top-color: #f9fafb;
}

body.sp-wsv-theme-dark .sp-dir-error-banner {
    background: #450a0a;
    border-color: #7f1d1d;
    color: #fca5a5;
}

body.sp-wsv-theme-dark .sp-dir-empty {
    color: #d1d5db;
}

body.sp-wsv-theme-dark .sp-dir-choose-label {
    color: #d1d5db;
}

/* =========================================================
   OVERLAY
========================================================= */

.sp-dir-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999998;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    backdrop-filter: blur(2px);
}

.sp-dir-overlay--visible {
    display: flex;
}

/* =========================================================
   POPUP
========================================================= */

.sp-dir-popup {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 16px 48px -4px rgba(0,0,0,0.14);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    z-index: 999999;
    opacity: 0;
    transform: translateY(12px) scale(0.985);
    transition: opacity 0.2s ease, transform 0.2s ease;
    box-sizing: border-box;
}

.sp-dir-popup--visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.sp-dir-popup__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px 14px;
    border-bottom: 1px solid #f3f4f6;
}

.sp-dir-popup__title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

.sp-dir-popup__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    color: #9ca3af;
    border-radius: 6px;
    padding: 0;
    transition: color 0.15s, background 0.15s;
}

.sp-dir-popup__close:hover {
    color: #111827;
    background: #f3f4f6;
}

/* padding del body lo gestiona sp-popup.css del core */

/* =========================================================
   LISTADO DE DIRECCIONES
========================================================= */

#listado_mis_direcciones {
    display: flex;
    gap: 8px;
    flex-direction: column;
    margin: 0 0 18px;
}

.sp_direccion_guardada {
    padding: 14px 16px;
    border-radius: 8px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    justify-content: space-between;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    transition: border-color 0.15s, background 0.15s;
}

.sp_direccion_guardada.clickable {
    cursor: pointer;
}

.sp_direccion_guardada.clickable:hover {
    background: #f3f4f6;
    border-color: #111827;
}

.sp_direccion_guardada .datos_direccion {
    flex: 1;
    min-width: 0;
}

.sp_direccion_guardada .alias_direccion {
    margin: 0 0 2px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp_direccion_guardada .direccion {
    font-size: 0.8rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Botón borrar dentro de la tarjeta */
.sp_direccion_guardada .borrar_direccion {
    flex-shrink: 0;
    padding: 5px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    background: #fff;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}

.sp_direccion_guardada .borrar_direccion:hover {
    color: #111827;
    border-color: #9ca3af;
}

/* =========================================================
   BOTONES DEL POPUP DE DIRECCIONES
========================================================= */

/* Botón primario */
.sp-popup-footer button:first-child,
.sp-popup-footer .btn_iny_direccion {
    padding: 9px 18px;
    background: #111827;
    color: #fff;
    border: 1.5px solid #111827;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.sp-popup-footer button:first-child:hover,
.sp-popup-footer .btn_iny_direccion:hover {
    background: #1f2937;
    border-color: #1f2937;
}

/* Botón secundario */
.sp-popup-footer button:last-child:not(:first-child) {
    padding: 9px 18px;
    background: #fff;
    color: #374151;
    border: 1.5px solid #d1d5db;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.sp-popup-footer button:last-child:not(:first-child):hover {
    border-color: #9ca3af;
    background: #f9fafb;
}

/* Cuando hay 2 botones iny_direccion */
.sp-popup-footer .btn_iny_direccion + .btn_iny_direccion {
    background: #fff;
    color: #374151;
    border-color: #d1d5db;
}

.sp-popup-footer .btn_iny_direccion + .btn_iny_direccion:hover {
    border-color: #9ca3af;
    background: #f9fafb;
    color: #111827;
}

/* =========================================================
   ESTADO LOADING — spinner CSS, sin gif
========================================================= */

#listado_mis_direcciones.loading {
    flex-direction: row;
    align-items: center;
    justify-content: center;
    min-height: 72px;
    font-size: 0.85rem;
    color: #6b7280;
    gap: 10px;
}

/* Reemplazar img de loading con spinner CSS */
#listado_mis_direcciones .img_cargando {
    display: none !important;
}

#listado_mis_direcciones.loading::after {
    content: '';
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid #e5e7eb;
    border-top-color: #111827;
    border-radius: 50%;
    animation: sp-dir-spin 0.65s linear infinite;
    flex-shrink: 0;
}

@keyframes sp-dir-spin {
    to { transform: rotate(360deg); }
}

.sp-popup.sp_loading .sp-popup__body {
    opacity: 0.45;
    pointer-events: none;
}

/* =========================================================
   FORMULARIO DE NUEVA DIRECCIÓN
========================================================= */

/* =========================================================
   FORMULARIO DE NUEVA DIRECCIÓN
========================================================= */

.sp-popup__body .row {
    display: flex;
    gap: 10px;
    margin-bottom: 0;
}

.sp-popup__body .row p {
    flex: 1;
    margin: 0 0 10px;
}

.sp-popup__body .col-md-6 {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
}

.sp-popup__body .col-md-12 {
    flex: 1 1 100%;
}

.sp-popup__body input[type="text"],
.sp-popup__body input[type="search"] {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 12px;
    background: #fff;
    color: #111827;
    border: 1.5px solid #d1d5db;
    border-radius: 7px;
    font-size: 13px;
    line-height: 1.4;
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

.sp-popup__body input[type="text"]::placeholder,
.sp-popup__body input[type="search"]::placeholder {
    color: #9ca3af;
}

.sp-popup__body input[type="text"]:focus,
.sp-popup__body input[type="search"]:focus {
    border-color: #111827;
    box-shadow: 0 0 0 3px rgba(17,24,39,0.07);
}

/* =========================================================
   RESPONSIVE
========================================================= */

@media screen and (max-width: 600px) {
    .sp-dir-popup {
        max-height: 95vh;
        border-radius: 10px;
    }

    .sp-popup-footer {
        flex-direction: column;
        gap: 8px;
    }

    .sp-popup-footer button {
        width: 100%;
        justify-content: center;
    }

    .sp-popup__body .row {
        flex-direction: column;
        gap: 0;
    }

    .sp-popup__body .col-md-6 {
        flex: 1 1 100%;
    }
}

/* =========================================================
   BANNER DE ERROR INLINE
========================================================= */

.sp-dir-error-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 0 22px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 7px;
    font-size: 13px;
    color: #b91c1c;
    line-height: 1.45;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    margin-bottom: 0;
}

.sp-dir-error-banner + .sp-popup__body {
    padding-top: 14px;
}

.sp-dir-error-banner svg {
    flex-shrink: 0;
    margin-top: 1px;
    color: #ef4444;
}

.sp-dir-error-banner--visible {
    opacity: 1;
    transform: translateY(0);
}

/* Mensaje vacío cuando no hay direcciones */
.sp-dir-empty {
    font-size: 0.85rem;
    color: #6b7280;
    text-align: center;
    padding: 16px 0 8px;
    margin: 0;
}

/* Label de elección de tipo de dirección */
.sp-dir-choose-label {
    font-size: 0.9rem;
    color: #374151;
    margin: 0 0 16px;
}

/* Transición suave al cambiar contenido interno — ya está en sp-popup.css del core */

/* Footer en columna para el selector de tipo */
.sp-dir-footer-col {
    flex-direction: column;
    align-items: stretch;
}

.sp-dir-footer-col button {
    width: 100%;
    text-align: center;
    justify-content: center;
}