/**
 * WooCommerce Checkout Field Groups
 * CSS para checkout com template customizado
 */

/* ===== ESCONDER ELEMENTOS ORIGINAIS DO WOOCOMMERCE ===== */

/* Esconder seção de conta original (já está no nosso template) */
.woocommerce-checkout .woocommerce-account-fields {
    display: none !important;
}

/* Esconder cupom original (movido para nova posição) */
.woocommerce-checkout > .woocommerce-form-coupon-toggle,
.woocommerce-checkout > .checkout_coupon,
.woocommerce > .woocommerce-form-coupon-toggle:not(.wcfg-coupon-section .woocommerce-form-coupon-toggle),
section.coupon-wrapper {
    display: none !important;
}

/* ===== SEÇÕES ===== */

.wcfg-section {
    margin-bottom: 2em;
}

.wcfg-section-title {
    font-size: 1.3em;
    font-weight: 400;
    margin: 0 0 0.5em;
    border-bottom: 0px solid #333;
    color: #6b6b6b;
}

.wcfg-section-address ,
.wcfg-section-customer {
   margin: 0 0 2em 0;
    border: 1px solid #e2e2e2;
    border-radius: 6px;
    padding: 10px 20px 20px;
}


/* ===== GRID DE CAMPOS ===== */

.wcfg-grid {
    width: 100%;
}

.wcfg-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0 15px;
    margin-bottom: 0;
}

.wcfg-row > p.form-row {
    margin-bottom: 15px;
    box-sizing: border-box;
    float: none !important;
}

/* Coluna de metade */
.wcfg-row > p.wcfg-col-half {
    width: calc(50% - 8px) !important;
    flex: 0 0 calc(50% - 8px) !important;
}

/* Coluna esquerda (metade) */
.wcfg-row > p.wcfg-col-left {
    width: calc(50% - 8px) !important;
    flex: 0 0 calc(50% - 8px) !important;
}

/* Coluna direita (metade) */
.wcfg-row > p.wcfg-col-right {
    width: calc(50% - 8px) !important;
    flex: 0 0 calc(50% - 8px) !important;
}

/* Coluna inteira */
.wcfg-row > p.wcfg-col-full {
    width: 100% !important;
    flex: 0 0 100% !important;
}

/* Remover classes padrão do WooCommerce */
.wcfg-grid .form-row-first,
.wcfg-grid .form-row-last,
.wcfg-grid .form-row-wide {
    width: auto;
    float: none;
}

/* ===== RESPONSIVO ===== */

@media (max-width: 768px) {
    .wcfg-row > p.wcfg-col-half {
        width: 100% !important;
        flex: 0 0 100% !important;
    }
    
    .wcfg-section-title {
        font-size: 1.1em;
    }
    
    .wcfg-section-address {
        margin-top: 1.5em;
    }
}

/* ===== SELECT2 FIX ===== */

.wcfg-grid .select2-container {
    width: 100% !important;
}

/* ===== CAMPOS DE CONTA ===== */

.wcfg-account-fields {
    margin-top: 1.5em;
    padding-top: 1em;
    border-top: 1px solid #eee;
}

.wcfg-account-fields .create-account-checkbox {
    margin-bottom: 1em;
}

.wcfg-account-fields .create-account-checkbox label {
    display: flex;
    align-items: center;
    gap: 0.5em;
    cursor: pointer;
}

.wcfg-account-fields .create-account-checkbox input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.wcfg-password-field {
    transition: opacity 0.3s ease, max-height 0.3s ease;
}

.wcfg-password-field.wcfg-hidden {
    display: none;
}

.wcfg-section .form-row label {
    display: block;
    margin-bottom: 0px;
    color: #111;
    font-size: 12px;
    font-weight: 400;
}

/* ===== CUPOM ===== */

.wcfg-coupon-section {
    margin: 1.5em 0;
    padding: 1.2em 1.5em;
    border: 2px dashed #ccc;
    border-radius: 8px;
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    position: relative;
}
.wcfg-coupon-section .button {
    padding: 10px 20px 11px;
}
.wcfg-coupon-title {
    font-size: 14px;
    font-weight: 400;
    margin: 0 0 1em;
    padding: 0;
    color: #444;
    letter-spacing: 0.5px;
}
.wcfg-coupon-section p {
    margin: 0;
}
.wcfg-coupon-form {
    display: flex !important;
    flex-wrap: nowrap;
    gap: 0;
    align-items: stretch;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
}

.wcfg-coupon-form .form-row {
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    width: auto !important;
}

.wcfg-coupon-form .form-row-first {
    flex: 1;
}

.wcfg-coupon-form .form-row-last {
    flex: 0 0 auto;
}

.wcfg-coupon-form input.input-text,
.wcfg-coupon-form input#wcfg_coupon_code {
    width: 100% !important;
    height: 48px !important;
    padding: 0 15px !important;
    border: 2px solid #ddd !important;
    border-right: none !important;
    border-radius: 6px 0 0 6px !important;
    font-size: 15px !important;
    background: #fff !important;
    box-shadow: none !important;
    transition: border-color 0.2s ease;
}

.wcfg-coupon-form input.input-text:focus,
.wcfg-coupon-form input#wcfg_coupon_code:focus {
    border-color: #3bb54a !important;
    outline: none !important;
}

.wcfg-coupon-form button.button,
.wcfg-coupon-form button#wcfg_apply_coupon {
    height: 48px !important;
    padding: 0 25px !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 6px 6px 0 !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    text-transform: uppercase !important;
    letter-spacing: 0.5px !important;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.woocommerce-checkout select{
        font-size: 14px;
}
.wcfg-coupon-form button.button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.wcfg-coupon-form .clear {
    display: none !important;
}

/* Mensagem do cupom */
.wcfg-coupon-message {
    margin-top: 10px;
}

.wcfg-coupon-message .woocommerce-error,
.wcfg-coupon-message .woocommerce-message {
    margin: 0;
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 14px;
}

.wcfg-coupon-message .woocommerce-error {
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.wcfg-coupon-message .woocommerce-message {
    background: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

/* Responsivo */
@media (max-width: 480px) {
    .wcfg-coupon-section {
        padding: 1em;
    }
    
    .wcfg-coupon-form {
        flex-direction: column;
        gap: 10px;
    }
    
    .wcfg-coupon-form .form-row-first,
    .wcfg-coupon-form .form-row-last {
        width: 100% !important;
    }
    
    .wcfg-coupon-form input.input-text,
    .wcfg-coupon-form input#wcfg_coupon_code {
        border-right: 2px solid #ddd !important;
        border-radius: 6px !important;
    }
    
    .wcfg-coupon-form button.button,
    .wcfg-coupon-form button#wcfg_apply_coupon {
        width: 100%;
        border-radius: 6px !important;
    }
}

/* ===== LIMPEZA ===== */

.wcfg-grid::after,
.wcfg-row::after {
    content: "";
    display: table;
    clear: both;
}

/* ===== RESUMO DO CLIENTE LOGADO ===== */

.wcfg-customer-summary {
    margin-bottom: 0.5em;
}

.wcfg-summary-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 0.8em;
}

.wcfg-summary-line {
    display: block;
    font-size: 12px;
    color: #333;
    line-height: 1.5;
}

.wcfg-edit-info {
    display: inline-block;
    font-size: 13px;
    color: #0066cc;
    text-decoration: none;
    border-bottom: 1px dashed #0066cc;
    transition: all 0.2s ease;
}

.wcfg-edit-info:hover {
    color: #004499;
    border-bottom-color: #004499;
}

/* Esconder formulário quando resumo está visível */
.wcfg-hidden {
    display: none !important;
}

@media (max-width: 768px) {
    .wcfg-customer-summary {
        padding: 1em 0 0 0;
    }
    
    .wcfg-summary-line {
        font-size: 13px;
    }
}

/* ===== CEP AUTOCOMPLETE LOADING ===== */

#billing_postcode_field .woocommerce-input-wrapper {
    position: relative;
}

#billing_postcode.wcfg-loading {
    padding-right: 40px !important;
}

#billing_postcode.wcfg-loading + .wcfg-cep-loader,
#billing_postcode_field .woocommerce-input-wrapper::after {
    content: '';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}

#billing_postcode.wcfg-loading ~ .wcfg-cep-loader,
#billing_postcode_field:has(#billing_postcode.wcfg-loading) .woocommerce-input-wrapper::after {
    opacity: 1;
    border: 2px solid #ddd;
    border-top-color: #333;
    border-radius: 50%;
    animation: wcfg-spin 0.6s linear infinite;
}

@keyframes wcfg-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}

/* ===== IE EXEMPT CHECKBOX (Inscrição Estadual) ===== */

.wcfg-ie-wrapper {
    position: relative;
}

.wcfg-ie-wrapper input#billing_ie {
    padding-right: 80px !important;
}

.wcfg-ie-wrapper input#billing_ie[readonly] {
    background-color: #f5f5f5;
    color: #888;
}

.wcfg-ie-exempt {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
}

.wcfg-ie-exempt input[type="checkbox"] {
    width: auto !important;
    margin: 0 !important;
    cursor: pointer;
}


.woocommerce-additional-fields:empty,
.woocommerce-additional-fields--empty {
    display: none !important;
}

.woocommerce-shipping-fields.wcfg-hidden,
.ship-to-different-address.wcfg-hidden,
#ship-to-different-address-checkbox.wcfg-hidden {
    display: none !important;
}

.woocommerce-shipping-fields:has(#ship-to-different-address), 
.woocommerce-shipping-fields:has(.wcfg-section-title), 
.woocommerce-additional-fields:has(h3){
    margin: 0 0 2em 0;
    border: 1px solid #e2e2e2;
    border-radius: 6px;
    padding: 10px 20px 20px;
}

/* "Enviar para o endereço de entrega": secção sempre visível, sem checkbox */
.woocommerce-shipping-fields.wcfg-shipping-always-visible .shipping_address {
    display: block !important;
}

.woocommerce-additional-fields p#order_comments_field {
    margin: 0 0 0 0;
}
.woocommerce-shipping-fields #ship-to-different-address {
    margin-bottom: 0!important;
    padding-top: 10px!important;
    border-top: 0px solid #eee!important;
    font-size: 18px!important;
}
.woocommerce-shipping-fields .shipping_address{
    margin: 20px 0 0 0;
}


/* ===== CEP READONLY FIELDS ===== */
.wcfg-readonly {
    background: #f5f5f5 !important;
    pointer-events: none !important;
}

/* ===== ERROS ===== */
.checkout-inline-error-message {
    font-size: 10px;
    background: #ff4242;
    color: #fff;
    padding: 2px 6px;
    margin-top: -2px;
    border-radius: 0 0 5px 5px;
    margin-bottom: 0px;
}