/**
 * Buscador Nutricional - Estilos Frontend
 *
 * @package     MenuExpress
 * @subpackage  BuscadorNutricional
 * @author      AC / Amante
 * @since       3.0.0
 */

/* Contenedor principal */
.menu-buscador-nutricional {
    max-width: 100%;
    margin: 20px 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Header del buscador */
.buscador-header {
    margin-bottom: 20px;
}

.buscador-header h2 {
    font-size: 24px;
    margin: 0 0 8px 0;
    color: #1a1a1a;
}

.buscador-subtitulo {
    color: #666;
    font-size: 14px;
    margin: 0;
}

/* Input y contenedor de búsqueda */
.buscador-container {
    position: relative;
    margin-bottom: 20px;
}

.buscador-input-wrapper {
    position: relative;
    width: 100%;
}

/* ============================================= */
/* CORRECCIÓN FUERTE: Padding para la lupa */
/* ============================================= */
.buscador-input {
    width: 100%;
    padding: 12px 20px 12px 50px !important;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    outline: none;
    background: #fff;
    box-sizing: border-box !important;
    min-height: 48px;
}

.buscador-input:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 3px rgba(0, 124, 186, 0.2);
}

/* ============================================= */
/* LUPA: Posición fija a la izquierda */
/* ============================================= */
.buscador-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    color: #999;
    pointer-events: none;
    z-index: 5;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
}

.buscador-loading {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007cba;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Resultados de búsqueda */
.resultados-busqueda {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 0 0 8px 8px;
    max-height: 350px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 1000;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    margin-top: 2px;
}

.resultados-busqueda:empty {
    display: none !important;
}

.resultado-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.resultado-item:hover {
    background: #f8f9fa;
}

.resultado-item:last-child {
    border-bottom: none;
}

.resultado-nombre {
    font-weight: 500;
    color: #1a1a1a;
}

.resultado-badges {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.resultado-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    background: #f0f0f0;
    color: #555;
    white-space: nowrap;
}

.resultado-badge.local {
    background: #e8f5e9;
    color: #2e7d32;
}

.resultado-badge.externo {
    background: #e3f2fd;
    color: #1565c0;
}

.resultado-badge.sinonimo {
    background: #fff3e0;
    color: #e65100;
}

.resultado-badge.off {
    background: #f3e5f5;
    color: #7b1fa2;
}

.resultado-badge.region {
    background: #e0f7fa;
    color: #006064;
}

/* Ficha nutricional */
.ficha-nutricional {
    background: #fff;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    padding: 20px;
    margin-top: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.ficha-nutricional-container {
    width: 100%;
}

.ficha-header {
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.ficha-nombre {
    font-size: 22px;
    margin: 0 0 10px 0;
    color: #1a1a1a;
}

.ficha-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.badge {
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    font-weight: 500;
}

.badge-externo {
    background: #e3f2fd;
    color: #1565c0;
}

.badge-off {
    background: #f3e5f5;
    color: #7b1fa2;
}

.badge-sinonimo {
    background: #fff3e0;
    color: #e65100;
}

.badge-region {
    background: #e0f7fa;
    color: #006064;
}

.badge-local {
    background: #e8f5e9;
    color: #2e7d32;
}

/* Tablas de nutrientes */
.ficha-tabla {
    overflow-x: auto;
}

.ficha-tabla h4 {
    font-size: 16px;
    margin: 20px 0 10px 0;
    color: #333;
}

.ficha-tabla h4:first-of-type {
    margin-top: 0;
}

.ficha-nutrientes {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
}

.ficha-nutrientes th,
.ficha-nutrientes td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
}

.ficha-nutrientes th {
    width: 40%;
    font-weight: 500;
    color: #555;
    background: #fafafa;
}

.ficha-nutrientes td {
    width: 60%;
    color: #1a1a1a;
}

.ficha-nutrientes tr:last-child th,
.ficha-nutrientes tr:last-child td {
    border-bottom: none;
}

/* Footer de la ficha */
.ficha-footer {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.ficha-enlace {
    color: #007cba;
    text-decoration: none;
    font-size: 14px;
}

.ficha-enlace:hover {
    text-decoration: underline;
}

.ficha-acciones {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.button {
    display: inline-block;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid #ccc;
    background: #f8f9fa;
    color: #333;
    text-decoration: none;
}

.button:hover {
    background: #e9ecef;
}

.button-primary {
    background: #007cba;
    border-color: #007cba;
    color: #fff;
}

.button-primary:hover {
    background: #006ba1;
    border-color: #006ba1;
    color: #fff;
}

.button-secondary {
    background: #f8f9fa;
    border-color: #ccc;
    color: #333;
}

.button-secondary:hover {
    background: #e9ecef;
}

.ficha-print {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
}

.guardar-mensaje {
    font-size: 14px;
    padding: 4px 12px;
    border-radius: 4px;
}

.guardar-mensaje.success {
    background: #e8f5e9;
    color: #2e7d32;
}

.guardar-mensaje.error {
    background: #ffebee;
    color: #c62828;
}

.ficha-error {
    color: #666;
    font-style: italic;
    text-align: center;
    padding: 30px 0;
}

/* ============================================= */
/* BOTÓN BUSCAR CON IA */
/* ============================================= */
#btn-buscar-ia {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    margin-top: 10px;
}

#btn-buscar-ia:hover {
    background: #1d4ed8;
}

#btn-buscar-ia:active {
    transform: scale(0.97);
}

.resultado-vacio {
    text-align: center;
    padding: 20px 16px;
    color: #4b5563;
    font-size: 15px;
}

.resultado-vacio strong {
    color: #1a1a2e;
}

.resultado-error {
    text-align: center;
    padding: 20px 16px;
    color: #721c24;
    background: #f8d7da;
    border-radius: 8px;
    font-size: 15px;
}

/* ============================================= */
/* MENSAJE DE ACCESO RESTRINGIDO                */
/* ============================================= */
.buscador-sin-acceso {
    text-align: center;
    padding: 50px 20px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 1px solid #e9ecef;
    max-width: 600px;
    margin: 20px auto;
}

.buscador-sin-acceso h3 {
    color: #1a1a2e;
    font-size: 24px;
    margin-bottom: 10px;
}

.buscador-sin-acceso p {
    color: #6b7280;
    font-size: 16px;
    max-width: 500px;
    margin: 0 auto;
}

/* ============================================= */
/* ENLACES: iniciar sesion y registrarte       */
/* ============================================= */
.buscador-link-login,
.buscador-link-registro {
    font-weight: 700 !important;
    background: transparent !important;
    text-decoration: none !important;
    transition: color 0.3s ease !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
}

.buscador-link-login {
    color: #000000 !important;
}

.buscador-link-registro {
    color: #000000 !important;
}

.buscador-link-login:hover,
.buscador-link-registro:hover {
    color: #F97316 !important;
    text-decoration: none !important;
    background: transparent !important;
}

/* ============================================= */
/* CORRECCIÓN PARA EL INPUT DE BÚSQUEDA EN MÓVIL */
/* ============================================= */
@media (max-width: 768px) {
    .buscador-input {
        font-size: 14px;
        padding: 10px 16px 10px 44px !important;
        min-height: 44px;
    }
    
    .buscador-icon {
        left: 12px;
        font-size: 18px;
        width: 20px;
        height: 20px;
    }

    .resultado-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
    
    .ficha-nombre {
        font-size: 20px;
    }
    
    .ficha-nutrientes th {
        width: 50%;
    }
    
    .ficha-nutrientes td {
        width: 50%;
    }
    
    .ficha-badges {
        gap: 5px;
    }
    
    .badge {
        font-size: 11px;
        padding: 3px 10px;
    }
}

@media (max-width: 480px) {
    .buscador-header h2 {
        font-size: 20px;
    }
    
    .ficha-nombre {
        font-size: 18px;
    }
    
    .ficha-nutrientes th,
    .ficha-nutrientes td {
        font-size: 13px;
        padding: 6px 8px;
    }
    
    .ficha-tabla {
        overflow-x: auto;
        display: block;
        width: 100%;
    }
    
    .button {
        font-size: 13px;
        padding: 6px 12px;
    }

    .buscador-input {
        padding: 10px 12px 10px 40px !important;
    }

    .buscador-icon {
        left: 10px;
        font-size: 16px;
        width: 18px;
        height: 18px;
    }
}

/* ============================================= */
/* CONFIGURACIÓN DE IMPRESIÓN LIMPIA A4/CARTA    */
/* ============================================= */
@media print {
    /* 1. Ocultar los elementos conocidos del buscador y la interfaz */
    #wpadminbar,
    .buscador-header,
    .buscador-container,
    .resultados-busqueda,
    .ficha-print-btn,
    .ficha-acciones,
    .ficha-footer {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    /* 2. AISLAMIENTO TOTAL: Forzar el lienzo blanco */
    html, body {
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
    }

    /* 3. EL TRUCO MAESTRO: Sacar la ficha del flujo dinámico del código inyectado */
    .menu-buscador-nutricional {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        height: 100% !important;
        background: #ffffff !important;
        z-index: 9999999 !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }

    .ficha-nutricional, 
    .ficha-nutricional-container {
        display: block !important;
        width: 100% !important;
        background: #ffffff !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 4. Forzar al navegador a renderizar los colores reales */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* 5. Maquetación e impresión de la tabla */
    .ficha-header {
        padding-bottom: 10px !important;
        margin-bottom: 15px !important;
        border-bottom: 2px solid #f97316 !important;
    }

    .ficha-nombre {
        font-size: 24px !important;
        color: #1a1a1a !important;
        margin: 0 0 5px 0 !important;
    }

    .ficha-tabla {
        width: 100% !important;
        border-collapse: collapse !important;
        margin-top: 10px !important;
    }

    .ficha-tabla th {
        background: #f97316 !important;
        color: #ffffff !important;
        padding: 8px 14px !important;
    }

    .ficha-tabla .grupo-separador td {
        background: #f3f4f6 !important;
        color: #1f2937 !important;
        font-weight: bold !important;
        padding: 6px 10px !important;
        border-bottom: 1px solid #e5e7eb !important;
        font-size: 14px !important;
    }

    .ficha-tabla .nutriente-fila td {
        padding: 6px 10px !important;
        border-bottom: 1px solid #f3f4f6 !important;
        font-size: 13px !important;
        color: #374151 !important;
    }

    .nutriente-icono { width: 5% !important; }
    .nutriente-nombre { width: 65% !important; }
    .nutriente-valor {
        width: 30% !important;
        text-align: right !important;
        font-weight: 600 !important;
    }

    /* 6. Ajustar márgenes físicos de impresión */
    @page {
        size: auto;
        margin: 1.5cm;
    }
}
/* ============================================= */
/* BLOQUEO DE ACCESO — CANDADO + BOTON          */
/* ============================================= */
.buscador-bloqueo {
    text-align: center;
    padding: 50px 30px;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid #e9ecef;
    max-width: 480px;
    margin: 30px auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.buscador-candado {
    font-size: 48px;
    margin-bottom: 12px;
    display: block;
}

.buscador-bloqueo h3 {
    color: #1a1a2e;
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 8px 0;
}

.buscador-bloqueo p {
    color: #6b7280;
    font-size: 15px;
    margin: 0 0 24px 0;
    line-height: 1.5;
}

/* ============================================= */
/* BOTON INICIAR SESION — IDENTICO AL CONSTRUCTOR */
/* ============================================= */
.buscador-btn-login {
    display: inline-block;
    padding: 12px 36px;
    background: #f97316;
    color: #ffffff !important;
    font-weight: 600;
    font-size: 16px;
    border-radius: 50px;
    text-decoration: none !important;
    transition: all 0.25s ease;
    border: none;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(249, 115, 22, 0.25);
}

.buscador-btn-login:hover {
    background: #ea580c;
    color: #ffffff !important;
    text-decoration: none !important;
    box-shadow: 0 4px 16px rgba(249, 115, 22, 0.35);
    transform: translateY(-1px);
}

.buscador-btn-login:active {
    transform: scale(0.97);
}

