/* Bufalo CEP Selector - Diseño Minimalista inspirado en MercadoLibre */
:root {
    --bufalo-primary: #3483fa;
    --bufalo-primary-hover: #2968c8;
    --bufalo-primary-light: rgba(52, 131, 250, 0.1);
    --bufalo-border: rgba(0, 0, 0, 0.1);
    --bufalo-border-hover: rgba(52, 131, 250, 0.2);
    --bufalo-text: #333;
    --bufalo-text-secondary: #666;
    --bufalo-background: #fff;
    --bufalo-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --bufalo-shadow-hover: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
    --bufalo-radius: 6px;
}

/* Contenedor principal */
.bufalo-cep-selector {
    display: inline-block;
}

/* Botón trigger - estilo MercadoLibre */
.cep-selector-trigger {
    background: transparent !important;
    border: 1px solid #e5e5e5 !important;
    border-radius: 4px !important;
    padding: 6px 10px !important;
    cursor: pointer !important;
    color: #333333 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    min-width: 140px !important;
    max-width: 200px !important;
    text-align: left !important;
    box-shadow: none !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    font-size: 14px !important;
    line-height: 1.2 !important;
    height: auto !important;
}

.cep-selector-trigger:hover {
    border-color: #d0d0d0 !important;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08) !important;
    background: #f8f8f8 !important;
}

/* Ícono minimalista */
.cep-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.cep-location-pin {
    font-size: 14px;
    color: var(--bufalo-primary);
    line-height: 1;
}

/* Contenido del trigger */
.cep-trigger-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.cep-trigger-label {
    font-size: 11px !important;
    color: #666666 !important;
    font-weight: 400 !important;
    line-height: 1.2 !important;
    margin-bottom: 1px !important;
    text-align: left !important;
}

.cep-trigger-address {
    font-size: 13px !important;
    color: #333333 !important;
    font-weight: 600 !important;
    line-height: 1.2 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    text-align: left !important;
}

/* Estado sin dirección */
.cep-trigger-content.no-address .cep-trigger-label {
    font-size: 13px !important;
    color: #333333 !important;
    margin-bottom: 0 !important;
    font-weight: 500 !important;
    text-align: left !important;
}

/* Modal popup */
/* Modal minimalista */
.cep-modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
}

.cep-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Contenido del modal estilo MercadoLibre */
.cep-modal-content {
    background-color: var(--bufalo-background);
    border-radius: var(--bufalo-radius);
    width: 90%;
    max-width: 440px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    animation: slideIn 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

@keyframes slideIn {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Header limpio */
.cep-modal-header {
    padding: 24px 24px 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: none;
}

.cep-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--bufalo-text);
    line-height: 1.3;
    flex: 1;
    padding-right: 16px;
}

.cep-modal-close {
    color: var(--bufalo-text-secondary);
    font-size: 24px;
    font-weight: normal;
    cursor: pointer;
    transition: color 0.15s ease;
    line-height: 1;
    padding: 4px;
    margin-top: -4px;
}

.cep-modal-close:hover {
    color: var(--bufalo-text);
}

.cep-modal-body {
    padding: 0 24px 24px 24px;
}

/* Descripción */
.cep-modal-body p {
    color: var(--bufalo-text-secondary);
    margin: 0 0 24px 0;
    line-height: 1.4;
    font-size: 14px;
}

/* Input group estilo MercadoLibre */
.cep-input-group {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

#cep-input {
    flex: 1;
    padding: 11px 12px;
    border: 1px solid var(--bufalo-border);
    border-radius: var(--bufalo-radius);
    font-size: 16px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    background: var(--bufalo-background);
    color: var(--bufalo-text);
    font-family: inherit;
}

#cep-input:focus {
    outline: none;
    border-color: var(--bufalo-primary);
    box-shadow: 0 0 0 2px rgba(52, 131, 250, 0.2);
}

#cep-input::placeholder {
    color: var(--bufalo-text-secondary);
}

/* Botón principal estilo MercadoLibre */
#cep-submit {
    padding: 11px 16px;
    background: var(--bufalo-primary);
    color: white;
    border: none;
    border-radius: var(--bufalo-radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    font-family: inherit;
}

#cep-submit:hover {
    background: var(--bufalo-primary-hover);
}

#cep-submit:disabled {
    background: #999;
    cursor: not-allowed;
}

/* Botón confirmar endereço estilo MercadoLibre */
.cep-confirm-btn {
    padding: 11px 16px !important;
    background: #3483fa !important;
    color: white !important;
    border: none !important;
    border-radius: 6px !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
    white-space: nowrap !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    width: 100% !important;
    margin-top: 12px !important;
    text-decoration: none !important;
    display: inline-block !important;
    text-align: center !important;
}

.cep-confirm-btn:hover {
    background: #2968c8 !important;
    color: white !important;
}

.cep-confirm-btn:disabled {
    background: #999 !important;
    cursor: not-allowed !important;
}

/* Resultado limpio */
.cep-result {
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: var(--bufalo-radius);
    padding: 16px;
    margin-bottom: 16px;
}

.cep-result.hidden {
    display: none;
}

.cep-info .cep-location {
    color: var(--bufalo-primary);
    font-size: 16px;
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.cep-info .cep-address {
    color: var(--bufalo-text-secondary);
    margin: 0;
    font-size: 14px;
}

/* Display del CEP actual minimalista */
.current-cep-display {
    background: #f8f9fa;
    border: 1px solid #e5e5e5;
    border-radius: var(--bufalo-radius);
    padding: 16px;
    margin-bottom: 24px;
    text-align: center;
}

.current-cep-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: 12px;
    color: var(--bufalo-text);
    font-size: 14px;
    font-weight: 600;
}

.current-cep-icon {
    font-size: 14px;
}

.current-cep-details {
    margin-bottom: 16px;
}

.current-cep-code {
    font-size: 18px;
    font-weight: 600;
    color: var(--bufalo-text);
    margin-bottom: 4px;
    letter-spacing: 0.5px;
}

.current-cep-location {
    color: var(--bufalo-text-secondary);
    font-size: 14px;
    margin-bottom: 0;
}

/* Botón cambiar estilo MercadoLibre */
.change-cep-button {
    background: transparent !important;
    border: 1px solid #d5d5d5 !important;
    color: #3483fa !important;
    padding: 8px 16px !important;
    border-radius: 6px !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    text-decoration: none !important;
    display: inline-block !important;
    text-align: center !important;
}

.change-cep-button:hover {
    background: #f5f5f5 !important;
    border-color: #3483fa !important;
    color: #3483fa !important;
    text-decoration: none !important;
}

/* Enlace de ayuda */
.cep-help {
    text-align: center;
    margin-top: 16px;
}

.cep-help a {
    color: var(--bufalo-primary);
    text-decoration: none;
    font-size: 14px;
    transition: color 0.15s ease;
}

.cep-help a:hover {
    color: var(--bufalo-primary-hover);
    text-decoration: underline;
}

/* Loading minimalista */
.cep-loading {
    text-align: center;
    padding: 16px;
}

.cep-loading.hidden {
    display: none;
}

.spinner {
    border: 2px solid #f0f0f0;
    border-top: 2px solid var(--bufalo-primary);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 8px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.cep-loading p {
    color: var(--bufalo-text-secondary);
    margin: 0;
    font-size: 14px;
}

/* Mensajes limpios */
.cep-message {
    padding: 12px 16px;
    border-radius: var(--bufalo-radius);
    margin: 12px 0;
    font-size: 14px;
    line-height: 1.4;
}

.cep-message.success {
    background: #f0f9ff;
    border: 1px solid #3b82f6;
    color: #1d4ed8;
}

.cep-message.error {
    background: #fef2f2;
    border: 1px solid #ef4444;
    color: #dc2626;
}

/* Diseño responsive */
@media (max-width: 480px) {
    .cep-modal-content {
        width: 95%;
        margin: 20px auto;
    }
    
    .cep-modal-header,
    .cep-modal-body {
        padding: 16px;
    }
    
    .cep-modal-header h3 {
        font-size: 18px;
    }
    
    .cep-input-group {
        flex-direction: column;
        gap: 12px;
    }
    
    #cep-submit {
        order: 1;
    }
    
    .cep-selector-trigger {
        min-width: auto;
        width: 100%;
        justify-content: center;
    }
}

/* Responsividade */
@media (max-width: 768px) {
    .cep-modal-content {
        width: 95%;
        margin: 5% auto;
    }
    
    .cep-modal-header,
    .cep-modal-body {
        padding: 15px 20px;
    }
    
    .cep-input-group {
        flex-direction: column;
    }
    
    #cep-submit {
        width: 100%;
    }
    
    .cep-selector-trigger {
        min-width: 160px;
        padding: 8px 10px;
    }
    
    .cep-trigger-label {
        font-size: 10px;
    }
    
    .cep-trigger-address {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .cep-modal-content {
        width: 98%;
        margin: 2% auto;
    }
    
    .cep-modal-header h3 {
        font-size: 16px;
    }
    
    .cep-trigger-address {
        max-width: 120px;
    }
}

/* Integração com tema Woodmart */
.woodmart-header .bufalo-cep-selector {
    margin: 0 5px;
}

.header-banner .bufalo-cep-selector {
    display: inline-flex;
    align-items: center;
}

/* Estilos para diferentes posições no header */
.header-top .cep-selector-trigger {
    padding: 6px 10px;
    min-width: 160px;
}

.header-top .cep-trigger-label {
    font-size: 10px;
}

.header-top .cep-trigger-address {
    font-size: 11px;
}

.header-main .cep-selector-trigger {
    padding: 10px 12px;
    min-width: 200px;
}

.header-bottom .cep-selector-trigger {
    padding: 8px 11px;
    min-width: 180px;
}

/* Dark theme compatibility */
.color-scheme-dark .cep-selector-trigger {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.color-scheme-dark .cep-selector-trigger:hover {
    border-color: rgba(197, 96, 247, 0.4);
    background: #333333;
}

.color-scheme-dark .cep-trigger-label {
    color: #cccccc;
}

.color-scheme-dark .cep-trigger-address {
    color: #ffffff;
}

/* Modal dark theme */
.color-scheme-dark .cep-modal-content {
    background: #1a1a1a;
    color: #ffffff;
}

.color-scheme-dark .current-cep-display {
    background: rgba(197, 96, 247, 0.15);
    border-color: rgba(197, 96, 247, 0.4);
}

.color-scheme-dark .current-cep-location,
.color-scheme-dark .cep-info .cep-address {
    color: #b0b0b0;
}

/* ========== MOBILE STYLES ========== */
@media screen and (max-width: 768px) {
    
    /* Forzar visibilidad del modal */
    .cep-modal.show {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Modal fullscreen en mobile como MercadoLibre */
    .cep-modal {
        background-color: #ffffff !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 999999 !important;
    }
    
    .cep-modal-content {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        animation: slideInFromRight 0.3s ease !important;
        position: relative !important;
        background: #ffffff !important;
        box-shadow: none !important;
    }
    
    @keyframes slideInFromRight {
        from {
            transform: translateX(100%);
            opacity: 0.8;
        }
        to {
            transform: translateX(0);
            opacity: 1;
        }
    }
    
    /* Header mobile con título y botón cerrar */
    .cep-modal-header {
        padding: 16px 20px !important;
        border-bottom: 1px solid #e5e5e5 !important;
        background: #ffffff !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
    }
    
    .cep-modal-header h3 {
        font-size: 18px !important;
        font-weight: 600 !important;
        color: #333333 !important;
        margin: 0 !important;
        flex: 1 !important;
        padding-right: 0 !important;
        line-height: 1.3 !important;
    }
    
    .cep-modal-close {
        color: #3483fa !important;
        font-size: 0 !important;
        padding: 8px !important;
        margin: 0 !important;
        border: none !important;
        background: transparent !important;
        cursor: pointer !important;
        position: relative !important;
    }
    
    .cep-modal-close:before {
        content: "←" !important;
        font-size: 24px !important;
        font-weight: bold !important;
        color: #3483fa !important;
    }
    
    .cep-modal-close:hover {
        color: #2968c8 !important;
    }
    
    .cep-modal-close:hover:before {
        color: #2968c8 !important;
    }
    
    /* Body del modal mobile */
    .cep-modal-body {
        flex: 1 !important;
        padding: 24px 20px !important;
        background: #f8f9fa !important;
        overflow-y: auto !important;
    }
    
    /* Ocultar descripción existente en mobile */
    #modal-description {
        display: none !important;
    }
    
    /* Subtítulo descriptivo */
    .cep-modal-body::before {
        content: "Você poderá ver custos e prazos de entrega precisos em tudo que procurar." !important;
        display: block !important;
        color: #666666 !important;
        font-size: 14px !important;
        line-height: 1.4 !important;
        margin-bottom: 24px !important;
    }
    
    /* Contenido centrado en mobile */
    .cep-input-group {
        background: white !important;
        border-radius: 8px !important;
        padding: 20px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
        margin-bottom: 20px !important;
    }
    
    /* Input mobile mejorado */
    #cep-input {
        width: 100% !important;
        padding: 16px !important;
        font-size: 16px !important;
        border: 2px solid #e5e5e5 !important;
        border-radius: 8px !important;
        margin-bottom: 16px !important;
        background: #ffffff !important;
    }
    
    #cep-input:focus {
        border-color: #3483fa !important;
        outline: none !important;
        box-shadow: 0 0 0 2px rgba(52, 131, 250, 0.1) !important;
    }
    
    /* Botones mobile */
    #cep-submit {
        width: 100% !important;
        padding: 16px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
        margin-bottom: 12px !important;
    }
    
    .cep-confirm-btn {
        width: 100% !important;
        padding: 16px !important;
        font-size: 16px !important;
        margin-top: 16px !important;
    }
    
    /* Enlace de ayuda mobile */
    .cep-help {
        margin-top: 20px !important;
        text-align: center !important;
    }
    
    .cep-help a {
        display: inline-block !important;
        padding: 12px 24px !important;
        border: 1px solid #e5e5e5 !important;
        border-radius: 6px !important;
        color: #3483fa !important;
        text-decoration: none !important;
        font-weight: 500 !important;
        font-size: 14px !important;
        background: white !important;
        transition: all 0.15s ease !important;
    }
    
    .cep-help a:hover {
        border-color: #3483fa !important;
        background: #f8f9fa !important;
    }
    
    /* Botón trigger mobile - forzar visibilidad y clickeabilidad */
    .cep-selector-trigger {
        min-width: 120px !important;
        max-width: 160px !important;
        padding: 8px 10px !important;
        font-size: 13px !important;
        -webkit-tap-highlight-color: rgba(52, 131, 250, 0.2) !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        -khtml-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
        touch-action: manipulation !important;
        cursor: pointer !important;
        position: relative !important;
        z-index: 999 !important;
        display: flex !important;
        pointer-events: auto !important;
        background: transparent !important;
        border: 1px solid #e5e5e5 !important;
    }
    
    /* Asegurar que todo el contenedor sea clickeable */
    .bufalo-cep-selector {
        display: inline-block !important;
        position: relative !important;
        z-index: 1 !important;
        pointer-events: auto !important;
    }
    
    /* Debug - agregar color de fondo temporal para ver el área clickeable */
    .cep-selector-trigger:active {
        background: rgba(52, 131, 250, 0.1) !important;
        transform: scale(0.98) !important;
    }
    
    .cep-trigger-label {
        font-size: 10px !important;
    }
    
    .cep-trigger-address {
        font-size: 12px !important;
    }
    
    /* Resultado mobile */
    .cep-result {
        background: white !important;
        border-radius: 8px !important;
        padding: 20px !important;
        margin-top: 20px !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06) !important;
    }
    
    /* Loading mobile */
    .cep-loading {
        padding: 20px !important;
        text-align: center !important;
    }
}