/**
 * Checkout Fields CSS - Meloopets
 * Estilos de campos de formulario del checkout
 * @version 2.0.0
 */

/* ========================================
   FORM ROWS Y ESTRUCTURA
   ======================================== */

.meloopets-checkout .form-row {
    margin-bottom: 0;
    position: relative;
    width: 100%;
}

/* Sobrescribir anchos por defecto de WooCommerce */
.meloopets-checkout .form-row-first,
.meloopets-checkout .form-row-last,
.meloopets-checkout .form-row-wide {
    width: 100% !important;
    float: none !important;
    clear: none !important;
}

/* Grid de 2 columnas para form-row-first y form-row-last */
.meloopets-checkout .form-row-first {
    grid-column: 1;
}

.meloopets-checkout .form-row-last {
    grid-column: 2;
}

.meloopets-checkout .form-row-wide {
    grid-column: 1 / -1;
}

/* Asegurar que todos los campos ocupen el ancho completo */
.meloopets-checkout .form-row input,
.meloopets-checkout .form-row select,
.meloopets-checkout .form-row textarea {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

@media (max-width: 767px) {
    .meloopets-checkout .form-row-first,
    .meloopets-checkout .form-row-last {
        grid-column: 1 / -1;
    }
}

/* Labels mejorados */
.meloopets-checkout label {
    display: block;
    font-weight: 600;
    color: var(--checkout-text);
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    font-family: 'Fredoka', sans-serif;
}

.meloopets-checkout label .required {
    color: var(--checkout-accent);
    margin-left: 2px;
}

.meloopets-checkout label .optional {
    color: var(--checkout-text-light);
    font-weight: 400;
    font-size: 0.85rem;
}

/* Screen reader labels ocultos */
.meloopets-checkout .screen-reader-text {
    position: absolute;
    clip: rect(1px, 1px, 1px, 1px);
    height: 1px;
    width: 1px;
    overflow: hidden;
}

/* ========================================
   INPUTS Y CAMPOS DE TEXTO
   ======================================== */

.meloopets-checkout input[type="text"],
.meloopets-checkout input[type="email"],
.meloopets-checkout input[type="tel"],
.meloopets-checkout input[type="number"],
.meloopets-checkout textarea,
.meloopets-checkout select {
    width: 100% !important;
    max-width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--checkout-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--checkout-text);
    background-color: var(--checkout-white);
    transition: all 0.3s ease;
    outline: none;
    box-sizing: border-box;
}

.meloopets-checkout input[type="text"]:hover,
.meloopets-checkout input[type="email"]:hover,
.meloopets-checkout input[type="tel"]:hover,
.meloopets-checkout input[type="number"]:hover,
.meloopets-checkout textarea:hover,
.meloopets-checkout select:hover {
    border-color: var(--checkout-primary);
}

.meloopets-checkout input[type="text"]:focus,
.meloopets-checkout input[type="email"]:focus,
.meloopets-checkout input[type="tel"]:focus,
.meloopets-checkout input[type="number"]:focus,
.meloopets-checkout textarea:focus,
.meloopets-checkout select:focus {
    border-color: var(--checkout-primary);
    box-shadow: 0 0 0 3px rgba(74, 115, 86, 0.1);
}

/* Placeholder mejorado */
.meloopets-checkout input::placeholder,
.meloopets-checkout textarea::placeholder {
    color: #adb5bd;
    opacity: 1;
}

/* Textarea específico */
.meloopets-checkout textarea {
    resize: vertical;
    min-height: 100px;
    line-height: 1.6;
}

/* ========================================
   SELECT Y SELECT2
   ======================================== */

.meloopets-checkout select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%234A7356' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 12px;
    padding-right: 3rem;
    cursor: pointer;
}

/* Select2 personalizado */
.meloopets-checkout .select2-container {
    width: 100% !important;
}

.meloopets-checkout .select2-container--default .select2-selection--single {
    border: 2px solid var(--checkout-border);
    border-radius: 8px;
    height: auto;
    padding: 0.875rem 1rem;
    background-color: var(--checkout-white);
    transition: all 0.3s ease;
}

.meloopets-checkout .select2-container--default .select2-selection--single:hover {
    border-color: var(--checkout-primary);
}

.meloopets-checkout .select2-container--default.select2-container--focus .select2-selection--single {
    border-color: var(--checkout-primary);
    box-shadow: 0 0 0 3px rgba(74, 115, 86, 0.1);
}

.meloopets-checkout .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--checkout-text);
    line-height: 1.5;
    padding: 0;
}

.meloopets-checkout .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 100%;
    right: 1rem;
}

.meloopets-checkout .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: var(--checkout-primary) transparent transparent transparent;
    border-width: 6px 5px 0 5px;
    margin-left: -5px;
    margin-top: -3px;
}

/* Select2 dropdown */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--checkout-primary);
}

.select2-container--default .select2-results__option[aria-selected=true] {
    background-color: var(--checkout-gray-100);
    color: var(--checkout-primary);
}

/* ========================================
   CAMPOS PERSONALIZADOS MELOOPETS
   ======================================== */

/* Campos de documento */
.meloopets-checkout .meloopets-document-type,
.meloopets-checkout .meloopets-document-number {
    position: relative;
}

.meloopets-checkout .meloopets-document-type label::before {
    content: " ";
    margin-right: 4px;
}

.meloopets-checkout .meloopets-document-number label::before {
    content: " ";
    margin-right: 4px;
}

/* Campo de teléfono con prefijo +57 */
.meloopets-checkout #billing_phone_field label::before,
.meloopets-checkout #shipping_phone_field label::before {
    content: " ";
    margin-right: 4px;
}

/* Prefijo +57 visible (ya gestionado por JavaScript) */
.meloopets-checkout .phone-prefix-co {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--checkout-primary);
    font-weight: 700;
    font-size: 16px;
    pointer-events: none;
    z-index: 2;
    background: white;
    padding: 0 5px;
}

.meloopets-checkout #billing_phone,
.meloopets-checkout #shipping_phone {
    padding-left: 60px !important;
}

/* ========================================
   VALIDACIÓN Y ESTADOS DE ERROR
   ======================================== */

/* Campo con error */
.meloopets-checkout .woocommerce-invalid input,
.meloopets-checkout .woocommerce-invalid select,
.meloopets-checkout .woocommerce-invalid textarea {
    border-color: #dc3545;
    background-color: #fff5f5;
}

.meloopets-checkout .woocommerce-invalid label {
    color: #dc3545;
}

/* Campo válido (opcional) */
.meloopets-checkout .woocommerce-validated input:not(:placeholder-shown),
.meloopets-checkout .woocommerce-validated select:not([value=""]) {
    border-color: var(--checkout-primary);
    background-color: #f0f8f4;
}

/* Iconos de validación */
.meloopets-checkout .woocommerce-validated::after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--checkout-primary);
    font-weight: bold;
    font-size: 1.25rem;
    pointer-events: none;
}

.meloopets-checkout .woocommerce-invalid::after {
    content: "";
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #dc3545;
    font-weight: bold;
    font-size: 1.25rem;
    pointer-events: none;
}

/* ========================================
   NOTAS ADICIONALES
   ======================================== */

.meloopets-checkout .woocommerce-additional-fields {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px dashed var(--checkout-border);
}

.meloopets-checkout .woocommerce-additional-fields h3 {
    font-size: 1.25rem;
}

.meloopets-checkout #order_comments {
    min-height: 120px;
    font-family: inherit;
}

/* ========================================
   CAMPOS DE PAÍS (READONLY)
   ======================================== */

.meloopets-checkout #billing_country_field strong,
.meloopets-checkout #shipping_country_field strong {
    display: inline-block;
    padding: 0.875rem 1rem;
    background: var(--checkout-gray-100);
    border: 2px solid var(--checkout-border);
    border-radius: 8px;
    width: 93%;
    color: var(--checkout-text);
    font-weight: 600;
}

/* Input hidden de país */
.meloopets-checkout #billing_country,
.meloopets-checkout #shipping_country {
    display: none;
}

/* ========================================
   ANIMACIONES DE CAMPOS
   ======================================== */

.meloopets-checkout .form-row {
    animation: slideIn 0.4s ease-out backwards;
}

.meloopets-checkout .form-row:nth-child(1) { animation-delay: 0.05s; }
.meloopets-checkout .form-row:nth-child(2) { animation-delay: 0.1s; }
.meloopets-checkout .form-row:nth-child(3) { animation-delay: 0.15s; }
.meloopets-checkout .form-row:nth-child(4) { animation-delay: 0.2s; }
.meloopets-checkout .form-row:nth-child(5) { animation-delay: 0.25s; }
.meloopets-checkout .form-row:nth-child(6) { animation-delay: 0.3s; }
.meloopets-checkout .form-row:nth-child(7) { animation-delay: 0.35s; }
.meloopets-checkout .form-row:nth-child(8) { animation-delay: 0.4s; }
.meloopets-checkout .form-row:nth-child(9) { animation-delay: 0.45s; }
.meloopets-checkout .form-row:nth-child(10) { animation-delay: 0.5s; }

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ========================================
   AUTOCOMPLETE STYLING
   ======================================== */

.meloopets-checkout input:-webkit-autofill,
.meloopets-checkout input:-webkit-autofill:hover,
.meloopets-checkout input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 100px var(--checkout-white) inset;
    -webkit-text-fill-color: var(--checkout-text);
    border-color: var(--checkout-primary);
}

/* ========================================
   DISABLED STATE
   ======================================== */

.meloopets-checkout input:disabled,
.meloopets-checkout select:disabled,
.meloopets-checkout textarea:disabled {
    background-color: var(--checkout-gray-100);
    cursor: not-allowed;
    opacity: 0.6;
}