/* 
 * Macaco Forms Design System
 * Unified CSS structure for all OpenCart / Journal3 forms
 * Replaces inline styles and fixes modal rendering issues
 */

/* ==========================================================================
   Form Base — Desktop: max-width 540px centered / Mobile: 100%
   ========================================================================== */
.mf-form {
    width: 100%;
    box-sizing: border-box;
    padding: 0 10px;
}

/* Fix: Journal3/OpenCart page containers that use flex and crush form fields */
.modern-account-page .row {
    display: block !important;
}

#content.col-sm-12 {
    width: 100% !important;
    display: block !important;
}

.mf-field.form-group {
    width: 100% !important;
    display: block !important;
    clear: both;
}

/* Kill Bootstrap form-horizontal grid inside mf-form */
.mf-form.form-horizontal .form-group {
    margin-left: 0 !important;
    margin-right: 0 !important;
}

.mf-form .col-sm-2,
.mf-form .col-sm-10,
.mf-form .col-sm-12,
.mf-form [class*="col-sm-"],
.mf-form [class*="col-md-"],
.mf-form [class*="col-lg-"] {
    width: 100% !important;
    float: none !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Centralize form widths to prevent Journal3 crushing form inputs globally */
.mf-form .form-group {
    width: 100% !important;
    float: none !important;
    clear: both !important;
}

.mf-form .form-control,
.mf-form select.form-control,
.mf-form .validacao-icon-input .form-control,
.mf-form .validacao-icon-input {
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box;
}

/* Journal3 Popup — desktop max */
.popup-wrapper:has(.mf-form) .popup-container {
    max-width: 600px !important;
    width: 95% !important;
}

/* ── Mobile: Popup base — overlay fullscreen ── */
@media (max-width: 767px) {
    .popup-wrapper {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 99999 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    /* ── Login popup — card centralizado ── */
    .popup-wrapper.popup-login .popup-container {
        width: 92% !important;
        max-width: 400px !important;
        height: auto !important;
        max-height: 85vh !important;
        min-height: auto !important;
        margin: auto !important;
        border-radius: 12px !important;
        position: relative !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    /* ── Register popup — fullscreen ── */
    .popup-wrapper.popup-register {
        display: block !important;
    }
    .popup-wrapper.popup-register .popup-container {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        min-height: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .popup-wrapper.popup-register .popup-body,
    .popup-wrapper.popup-register .popup-inner-body,
    .popup-wrapper.popup-register iframe {
        height: 100% !important;
        max-height: 100% !important;
    }
}

/* Inside popups, form doesn't need extra max-width */
.popup-container .mf-form {
    max-width: 100%;
    padding: 0;
}

.mf-form label.control-label {
    display: none !important;
}

/* Normalize fieldset/legend — remove browser defaults */
.mf-form fieldset {
    border: none;
    margin: 0;
    padding: 0;
}

.mf-form fieldset legend {
    padding: 0;
    margin: 0 0 10px 0;
    border: none;
    width: 100%;
    font-size: 15px;
    font-weight: 500;
    color: #555;
}

/* Reset Bootstrap input-group inside mf-form */
.mf-form .input-group {
    display: block !important;
    width: 100% !important;
}

.mf-form .input-group-btn {
    display: none !important;
}

/* ==========================================================================
   Fields
   ========================================================================== */
.mf-field {
    margin-bottom: 12px;
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

/* Standardize spacing for checkout form-groups (no .mf-field wrapper) */
#checkout-checkout .form-group,
#collapse-payment-address .form-group,
#collapse-shipping-address .form-group {
    margin-bottom: 12px;
}

/* Asterisk removed per user request — fields are self-evident with placeholders */

/* ==========================================================================
   Icon Input Group
   ========================================================================== */
.mf-icon-input {
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.mf-icon-input .mf-icon,
.mf-icon-input .validacao-field-icon {
    position: absolute;
    left: 11px;
    top: 11px;
    width: 16px;
    height: 16px;
    pointer-events: none;
    fill: #999;
    color: #999;
    z-index: 2;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mf-icon-input .form-control {
    padding-left: 36px !important;
    width: 100% !important;
    height: 38px;
    box-sizing: border-box;
}

.mf-icon-input select.form-control {
    width: 100% !important;
    padding-left: 36px !important;
    appearance: auto;
    -webkit-appearance: auto;
    -moz-appearance: auto;
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.mf-divider {
    height: 16px;
    width: 100%;
    clear: both;
}

.mf-alert {
    margin-top: 5px;
    font-size: 12px;
}

/* Section Headers — visual separators between form groups */
.mf-section-header {
    font-size: 12px;
    font-weight: 600;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding-bottom: 6px;
    margin-top: 18px;
    margin-bottom: 8px;
    border-bottom: 1px solid #e8e8e8;
}

.mf-section-header:first-child,
.mf-form fieldset:first-child .mf-section-header {
    margin-top: 0;
}

/* Backward compat: normalize old validacao-* classes to mf-* */
.validacao-icon-input {
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.validacao-icon-input .validacao-field-svg,
.validacao-icon-input .mf-icon {
    position: absolute;
    left: 11px;
    top: 11px;
    width: 16px;
    height: 16px;
    pointer-events: none;
    fill: #999;
    z-index: 2;
}

.validacao-icon-input .form-control {
    padding-left: 36px !important;
    width: 100% !important;
    height: 38px;
    box-sizing: border-box;
}

/* ==========================================================================
   Validation Messages — unified across all form contexts
   ========================================================================== */
.mf-form .text-danger,
#checkout-checkout .text-danger,
#collapse-payment-address .text-danger,
#collapse-shipping-address .text-danger {
    position: static !important;
    display: block !important;
    width: 100% !important;
    text-align: left !important;
    font-size: 11px !important;
    color: #e53935 !important;
    background: transparent !important;
    border: none !important;
    padding: 2px 0 0 0 !important;
    margin: 2px 0 4px 0 !important;
    height: auto !important;
    line-height: normal !important;
    box-shadow: none !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    left: auto !important;
    top: auto !important;
    bottom: auto !important;
    right: auto !important;
}

/* Elegant Alerts (Checkout & Popups) — Remove background and add bottom spacing */
#checkout-checkout .alert.alert-danger,
.popup-container .alert.alert-danger,
.mf-form .alert.alert-danger {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 0 24px 0 !important;
    color: #e53935 !important;
    display: flex !important;
    align-items: flex-start !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
    font-weight: 600 !important;
}

#checkout-checkout .alert.alert-danger svg,
#checkout-checkout .alert.alert-danger i,
.popup-container .alert.alert-danger svg,
.popup-container .alert.alert-danger i,
.mf-form .alert.alert-danger svg,
.mf-form .alert.alert-danger i {
    margin-top: 2px !important;
    margin-right: 8px !important;
    min-width: 18px !important;
}

#checkout-checkout .alert.alert-danger .close,
.popup-container .alert.alert-danger .close,
.mf-form .alert.alert-danger .close {
    display: none !important;
}

/* Suppress errors for auto-filled hidden inputs (firstname/lastname in checkout) */
input[type="hidden"] + .text-danger,
.form-group[style*="display: none"] .text-danger,
.form-group[style*="display:none"] .text-danger {
    display: none !important;
}

/* Error states using :has() */
.mf-icon-input:has(.text-danger) .form-control,
.mf-field:has(.text-danger) .form-control,
.mf-field:has(+ .text-danger) .form-control {
    border-color: #e53935 !important;
}

.mf-icon-input:has(.text-danger) .mf-icon,
.mf-field:has(.text-danger) .mf-icon,
.mf-field:has(+ .text-danger) .mf-icon {
    fill: #e53935 !important;
}

/* ==========================================================================
   Responsive — Mobile: full width, no padding
   ========================================================================== */
@media (max-width: 767px) {
    .mf-form {
        max-width: 100%;
        padding: 0;
    }

    .mf-form fieldset {
        padding: 0 !important;
        margin: 0 !important;
    }

    .popup-wrapper:has(.mf-form) .popup-container {
        max-width: 100% !important;
        width: 100% !important;
    }
}

/* ==========================================================================
   Global Form Overrides
   ========================================================================== */

/* Sempre oculta o grupo de clientes (ex: "Brasileiro") globalmente, 
   mantendo o input funcional para o formulário.
   O :has() esconde o .radio ou .form-group pai inteiro. */
div.radio:has(input[name="customer_group_id"]),
.form-group:has(input[name="customer_group_id"]) {
    display: none !important;
}

/* Ocultar todos os campos de endereço exceto o CEP (Postcode) */
#checkout-checkout .form-group:has(input[name="address_1"]),
#checkout-checkout .form-group:has(input[name="address_2"]),
#checkout-checkout .form-group:has(input[name="city"]),
#checkout-checkout .form-group:has(select[name="zone_id"]),
#checkout-checkout .form-group:has(select[name="country_id"]),
#checkout-checkout .form-group:has(input[name="company"]),
#checkout-checkout .form-group:has(input[name^="custom_field[address]"]) {
    display: none !important;
}

/* Fallback absoluto para navegadores que nao suportam :has() - Especificidade Máxima */
#checkout-checkout .mf-hidden-address-field,
.mf-hidden-address-field {
    display: none !important;
}

/* ==========================================================================
   Desktop Popups Whitespace Fix (Login & Register)
   ========================================================================== */
@media (min-width: 768px) {
    .popup-wrapper.popup-register .popup-container,
    .popup-wrapper.popup-login .popup-container {
        height: auto !important;
        min-height: auto !important;
        padding-bottom: 12px !important;
    }
    .popup-wrapper.popup-register .popup-body,
    .popup-wrapper.popup-register .popup-inner-body,
    .popup-wrapper.popup-login .popup-body,
    .popup-wrapper.popup-login .popup-inner-body {
        height: auto !important;
        min-height: auto !important;
    }
}

/* ==========================================================================
   Checkout Main Form Standardization
   ========================================================================== */
#collapse-payment-address .form-group,
#collapse-shipping-address .form-group,
#collapse-checkout-option .form-group {
    margin-bottom: 12px !important;
}

#collapse-payment-address label.control-label,
#collapse-shipping-address label.control-label {
    display: none !important;
}

#collapse-payment-address .input-group,
#collapse-shipping-address .input-group {
    display: block !important;
    width: 100% !important;
}

#collapse-payment-address .input-group-btn,
#collapse-shipping-address .input-group-btn {
    display: none !important;
}

#collapse-payment-address fieldset legend,
#collapse-shipping-address fieldset legend {
    color: #1a73e8 !important;
    font-weight: 600 !important;
    border: none !important;
    font-size: 16px !important;
    margin-bottom: 16px !important;
    padding: 0 !important;
}

/* Fix checkbox/agree spacing at the end of the form */
#collapse-payment-address .checkbox,
#collapse-shipping-address .checkbox,
#collapse-payment-address .buttons {
    margin-top: 24px !important;
}

/* ==========================================================================
   Forçar quebra de linha do link dos Correios / Feedback do CEP (Desktop & Mobile)
   ========================================================================== */
.form-horizontal .form-group.cep-group-wrapper,
.form-horizontal .form-group:has(#input-postcode),
.form-horizontal .form-group:has(input[name*="postcode"]),
.mf-form .form-group.cep-group-wrapper,
.mf-field.cep-group-wrapper,
.cep-group-wrapper {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    flex-wrap: wrap !important;
    width: 100% !important;
    clear: both !important;
}

.cep-group-wrapper .mf-icon-input,
.form-group:has(#input-postcode) .mf-icon-input,
.form-group:has(input[name*="postcode"]) .mf-icon-input,
.mf-field:has(#input-postcode) .mf-icon-input {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    flex-shrink: 0 !important;
    display: block !important;
}

.cep-group-wrapper #input-postcode,
.form-group:has(#input-postcode) #input-postcode {
    width: 100% !important;
    display: block !important;
}

.cep-helper-wrap {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    flex-shrink: 0 !important;
    clear: both !important;
    margin-top: 6px !important;
    margin-bottom: 4px !important;
    float: none !important;
}

.cep-helper-wrap .cep-links-row {
    display: block !important;
    width: 100% !important;
    clear: both !important;
    font-size: 12px !important;
    margin-top: 4px !important;
}

.cep-helper-wrap a {
    display: inline-block !important;
    color: #64748b !important;
    text-decoration: none !important;
    font-size: 12px !important;
}

.cep-helper-wrap a:hover {
    color: #38bdf8 !important;
    text-decoration: underline !important;
}
