/**
 * ComprarOnline - Checkout Stepped Flow & Comuna Styles
 */

/* -------------------------------------------------------------
   0. CORRECCIÓN FLOTANTE DE COMUNA (EVITAR TEXTO SUPERPUESTO)
   ------------------------------------------------------------- */
.wc-block-components-text-input input:not(:focus)::placeholder {
    color: transparent !important;
    opacity: 0 !important;
}

.wc-block-components-text-input input:focus::placeholder {
    color: #94a3b8 !important;
    opacity: 1 !important;
}

/* -------------------------------------------------------------
   1. CAJA DE TOTAL Y CONTINUAR AL MEDIO DE PAGO (PASO 1)
   ------------------------------------------------------------- */
#co-checkout-step-continue {
    background: #ffffff;
    border: 2px solid #e0f2fe;
    border-radius: 18px;
    padding: 24px 20px;
    margin: 28px 0 32px 0;
    text-align: center;
    box-shadow: 0 10px 25px -5px rgba(2, 132, 199, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
    box-sizing: border-box;
    transition: all 0.25s ease;
    position: relative;
    overflow: hidden;
}

#co-checkout-step-continue::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #0284c7 0%, #0ea5e9 50%, #38bdf8 100%);
}

.co-step-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 12px;
}

.co-step-badge svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

.co-step-total-label {
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

#co-checkout-step-total {
    font-size: 32px;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
    margin-bottom: 18px;
    letter-spacing: -0.5px;
}

.co-btn-to-payment {
    background: #0284c7;
    color: #ffffff !important;
    text-decoration: none !important;
    font-size: 16px;
    font-weight: 700;
    padding: 15px 32px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.35);
    transition: all 0.2s ease;
    box-sizing: border-box;
}

.co-btn-to-payment:hover {
    background: #0369a1;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.45);
}

.co-btn-to-payment:active {
    transform: translateY(0);
}

.co-btn-to-payment:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

.co-step-security-note {
    font-size: 12px;
    font-weight: 500;
    color: #64748b;
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* -------------------------------------------------------------
   2. ESTADOS DE PASO 2 (MEDIO DE PAGO)
   ------------------------------------------------------------- */
/* Ocultar el bloque de medios de pago y el botón final mientras esté en Paso 1 (solo si la orden requiere despacho) */
body.co-step-payment-hidden:has(.wp-block-woocommerce-checkout-shipping-methods-block, .wc-block-checkout__shipping-fields, .wc-block-checkout__shipping-option, .wp-block-woocommerce-checkout-shipping-address-block) .wp-block-woocommerce-checkout-payment-block,
body.co-step-payment-hidden:has(.wp-block-woocommerce-checkout-shipping-methods-block, .wc-block-checkout__shipping-fields, .wc-block-checkout__shipping-option, .wp-block-woocommerce-checkout-shipping-address-block) .wc-block-checkout__payment-method,
body.co-step-payment-hidden:has(.wp-block-woocommerce-checkout-shipping-methods-block, .wc-block-checkout__shipping-fields, .wc-block-checkout__shipping-option, .wp-block-woocommerce-checkout-shipping-address-block) .wc-block-components-checkout-place-order-button {
    display: none !important;
}

/* Banner de retorno para modificar datos del Paso 1 */
#co-checkout-back-step {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 18px;
    margin: 0 0 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: coFadeIn 0.3s ease-out forwards;
}

.co-back-summary-text {
    font-size: 13px;
    color: #475569;
    font-weight: 500;
}

.co-back-summary-text strong {
    color: #0f172a;
}

.co-back-btn {
    background: transparent;
    border: 1px solid #cbd5e1;
    color: #0284c7;
    font-size: 12.5px;
    font-weight: 700;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.co-back-btn:hover {
    background: #ffffff;
    border-color: #0284c7;
    color: #0369a1;
}

/* Encabezado del Paso 2 */
#co-step-2-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 6px 14px;
    border-radius: 20px;
    margin-bottom: 14px;
    animation: coFadeIn 0.3s ease-out forwards;
}

/* Animación de apertura suave */
@keyframes coFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* -------------------------------------------------------------
   3. ERRORES DE VALIDACIÓN VISUAL
   ------------------------------------------------------------- */
.co-field-error {
    border-color: #ef4444 !important;
    background-color: #fef2f2 !important;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

.co-validation-banner {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-size: 13px;
    font-weight: 600;
    padding: 10px 16px;
    border-radius: 10px;
    margin: 12px auto 0 auto;
    max-width: 420px;
    display: none;
    align-items: center;
    gap: 8px;
    text-align: left;
    line-height: 1.4;
}

.co-validation-banner.is-visible {
    display: flex;
    animation: coFadeIn 0.25s ease forwards;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #co-checkout-step-continue {
        padding: 20px 16px;
        margin: 20px 0 26px 0;
    }

    #co-checkout-step-total {
        font-size: 28px;
    }

    .co-btn-to-payment {
        font-size: 15px;
        padding: 14px 20px;
    }

    #co-checkout-back-step {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .co-back-btn {
        width: 100%;
        text-align: center;
    }
}

/* -------------------------------------------------------------
   4. JERARQUÍA GEOGRÁFICA CHILENA DE DIRECCIÓN
   Orden: 1. País (solo Chile) -> 2. Región -> 3. Comuna -> 4. Nombre -> 5. Apellidos -> 6. Dirección -> 7. Depto -> 8. Teléfono
   ------------------------------------------------------------- */
.wc-block-components-address-form-wrapper .wc-block-components-address-form {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 12px 16px !important;
}

/* 1. País (Solo Chile - 100% de ancho) */
.wc-block-components-address-form__country {
    order: 1 !important;
    flex-basis: 100% !important;
    width: 100% !important;
    margin-bottom: 0 !important;
}

#shipping-country option[value=""],
#billing-country option[value=""] {
    display: none !important;
}

/* 2. Región (Mitad izquierda - 50%) */
.wc-block-components-address-form__state {
    order: 2 !important;
    flex-basis: calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    margin-bottom: 0 !important;
}

/* 3. Comuna (Mitad derecha - 50%) */
.wc-block-components-address-form__city {
    order: 3 !important;
    flex-basis: calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    margin-bottom: 0 !important;
}

/* 4. Nombre (Mitad izquierda - 50%) */
.wc-block-components-address-form__first_name {
    order: 4 !important;
    flex-basis: calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    margin-bottom: 0 !important;
}

/* 5. Apellidos (Mitad derecha - 50%) */
.wc-block-components-address-form__last_name {
    order: 5 !important;
    flex-basis: calc(50% - 8px) !important;
    width: calc(50% - 8px) !important;
    margin-bottom: 0 !important;
}

/* 6. Dirección (100% de ancho) */
.wc-block-components-address-form__address_1 {
    order: 6 !important;
    flex-basis: 100% !important;
    width: 100% !important;
    margin-bottom: 0 !important;
}

/* 7. Depto / Casa adicional (100% de ancho) */
.wc-block-components-address-form__address_2-toggle,
.wc-block-components-address-form__address_2-hidden-input,
.wc-block-components-address-form__address_2 {
    order: 7 !important;
    flex-basis: 100% !important;
    width: 100% !important;
    margin-bottom: 0 !important;
}

/* 8. Teléfono (100% de ancho) */
.wc-block-components-address-form__phone {
    order: 8 !important;
    flex-basis: 100% !important;
    width: 100% !important;
    margin-bottom: 0 !important;
}

@media (max-width: 560px) {
    .wc-block-components-address-form__state,
    .wc-block-components-address-form__city,
    .wc-block-components-address-form__first_name,
    .wc-block-components-address-form__last_name {
        flex-basis: 100% !important;
        width: 100% !important;
    }
}

/* -------------------------------------------------------------
   5. AVISO DE AUTOCOMPLETADO INTELIGENTE DE DATOS
   ------------------------------------------------------------- */
.co-autofill-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 12px;
    padding: 10px 16px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #166534;
    box-shadow: 0 2px 6px rgba(22, 101, 52, 0.05);
    animation: coFadeIn 0.3s ease forwards;
}

.co-autofill-notice-left {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}

.co-autofill-notice-left svg {
    fill: #16a34a;
    flex-shrink: 0;
}

.co-autofill-clear-btn {
    background: none;
    border: none;
    color: #0284c7;
    text-decoration: underline;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    transition: color 0.15s ease;
    white-space: nowrap;
}

.co-autofill-clear-btn:hover {
    color: #0369a1;
}

/* Dark mode styling for notice */
html.co-dark-mode .co-autofill-notice {
    background: rgba(16, 185, 129, 0.1) !important;
    border-color: rgba(52, 211, 153, 0.25) !important;
    color: #a7f3d0 !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
}

html.co-dark-mode .co-autofill-notice-left svg {
    fill: #34d399 !important;
}

html.co-dark-mode .co-autofill-clear-btn {
    background: transparent !important;
    color: #38bdf8 !important;
    border: 1px solid rgba(56, 189, 248, 0.4) !important;
    padding: 3px 8px !important;
    border-radius: 6px !important;
}

html.co-dark-mode .co-autofill-clear-btn:hover {
    background: rgba(56, 189, 248, 0.15) !important;
    color: #7dd3fc !important;
}

@media (max-width: 600px) {
    .co-autofill-notice {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 10px 12px;
    }
    .co-autofill-clear-btn {
        padding: 4px 8px;
    }
}

/* -------------------------------------------------------------
   6. COMUNA NATIVE SELECT DROPDOWN (DESKTOP & MOBILE)
   ------------------------------------------------------------- */
.co-hidden-city-input {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 1px !important;
    height: 1px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    clip: rect(0, 0, 0, 0) !important;
}

.co-hidden-city-label {
    display: none !important;
}

/* El contenedor del select de Comuna debe ocupar el 100% y tener 50px de alto exactos como Región */
.co-comuna-select-container {
    width: 100% !important;
    height: 50px !important;
    position: relative !important;
    box-sizing: border-box !important;
    display: block !important;
}

/* El select desplegable debe coincidir exactamente con el select de Región (#billing-state / #shipping-state) */
.wc-block-components-address-form__city select.co-comuna-dropdown,
.co-comuna-select-container select.co-comuna-dropdown {
    width: 100% !important;
    height: 50px !important;
    min-height: 50px !important;
    max-height: 50px !important;
    padding: 16px 36px 0px 10px !important;
    font-size: 16px !important;
    font-family: inherit !important;
    line-height: 25px !important;
    color: rgb(43, 45, 47) !important;
    background-color: transparent !important;
    border: 1px solid color-mix(in srgb, currentColor 80%, transparent) !important;
    border-radius: 4px !important;
    box-sizing: border-box !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    cursor: pointer !important;
    margin: 0 !important;
    background-image: none !important;
}

/* Flecha desplegable SVG en la posición correcta */
.co-comuna-select-container .wc-blocks-components-select__expand {
    position: absolute !important;
    right: 10px !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    width: 24px !important;
    height: 24px !important;
    pointer-events: none !important;
    fill: currentColor !important;
    z-index: 2 !important;
}

/* La etiqueta 'Comuna': se anulan las reglas de input de texto para fijarla arriba igual que 'Región' */
.wc-block-components-form .wc-block-components-text-input.wc-block-components-address-form__city label.wc-blocks-components-select__label,
.wc-block-components-address-form__city .co-comuna-select-container label.wc-blocks-components-select__label,
.co-comuna-select-container label.wc-blocks-components-select__label {
    position: absolute !important;
    top: 6px !important;
    left: 10px !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
    margin: 0 !important;
    padding: 0 !important;
    transform: none !important;
    z-index: 3 !important;
    pointer-events: none !important;
    color: inherit !important;
    opacity: 0.8 !important;
    max-width: calc(100% - 24px) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

html.co-dark-mode .wc-block-components-address-form__city select.co-comuna-dropdown {
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
}

html.co-dark-mode .co-comuna-select-container label.wc-blocks-components-select__label {
    color: rgba(255, 255, 255, 0.7) !important;
}

.wc-block-components-address-form__city {
    position: relative !important;
}

/* -------------------------------------------------------------
   7. CHILEAN BOLETA / FACTURA & RUT SELECTOR STYLES
   ------------------------------------------------------------- */
.co-hidden-doc-select-container {
    display: none !important;
}

.co-doc-toggle-group {
    width: 100% !important;
    flex-basis: 100% !important;
    order: 9 !important;
    margin: 16px 0 12px 0 !important;
    padding: 14px 16px !important;
    background: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 12px !important;
    box-sizing: border-box !important;
}

.co-doc-group-title {
    display: block !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    color: #475569 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    margin-bottom: 10px !important;
}

.co-doc-pills {
    display: flex !important;
    gap: 10px !important;
}

.co-doc-pill {
    flex: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    background: #ffffff !important;
    border: 1.5px solid #cbd5e1 !important;
    color: #475569 !important;
    font-size: 14px !important;
    font-weight: 700 !important;
    padding: 10px 16px !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    box-sizing: border-box !important;
}

.co-doc-pill svg {
    flex-shrink: 0 !important;
}

.co-doc-pill:hover {
    border-color: #0284c7 !important;
    color: #0284c7 !important;
}

.co-doc-pill.is-active {
    background: #0284c7 !important;
    border-color: #0284c7 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.25) !important;
}

/* Flex order for RUT, Razón Social, and Giro */
.wc-block-components-address-form__compraronline-rut {
    order: 10 !important;
    flex-basis: 100% !important;
    width: 100% !important;
}

.wc-block-components-address-form__compraronline-razon_social {
    order: 11 !important;
    flex-basis: 100% !important;
    width: 100% !important;
}

.wc-block-components-address-form__compraronline-giro {
    order: 12 !important;
    flex-basis: 100% !important;
    width: 100% !important;
}

/* Dark mode for Document Selector */
html.co-dark-mode .co-doc-toggle-group {
    background: rgba(30, 41, 59, 0.7) !important;
    border-color: #334155 !important;
}

html.co-dark-mode .co-doc-group-title {
    color: #94a3b8 !important;
}

html.co-dark-mode .co-doc-pill {
    background: #1e293b !important;
    border-color: #475569 !important;
    color: #cbd5e1 !important;
}

html.co-dark-mode .co-doc-pill.is-active {
    background: #0284c7 !important;
    border-color: #0284c7 !important;
    color: #ffffff !important;
}


