/* =================================================== */
/* ===    DISEÑO REFINADO, MÁS FLUIDO Y MODERNO    === */
/* =================================================== */

/* --- VARIABLES Y RESET BÁSICO --- */
:root {
    --primary-color: #3498db; /* Un azul más vibrante y moderno */
    --primary-dark-color: #2980b9;
    --secondary-color: #2c3e50;
    --light-gray-color: #f8f9fa; /* Un fondo más limpio y claro */
    --white-color: #ffffff;
    --text-color: #5a6572;
    --heading-color: #34495e;
    --border-color: #e9ecef;
    --danger-color: #e74c3c;
    --success-color: #27ae60;
    --info-color: #17a2b8;
    --shadow: 0 4px 8px -2px rgb(0 0 0 / 0.07), 0 2px 6px -3px rgb(0 0 0 / 0.06);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --font-family: 'Poppins', sans-serif;
    --header-height: 70px;
    --border-radius: 12px;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-family);
    color: var(--text-color);
    background-color: var(--light-gray-color);
    font-size: 16px;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s;
}

/* Evita el scroll del body cuando el menú móvil está abierto */
body.no-scroll { overflow: hidden; }

/* =================================================== */
/* ===       NAVBAR MEJORADO Y RESPONSIVO          === */
/* =================================================== */
.main-nav {
    background-color: var(--white-color);
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    box-shadow: var(--shadow);
    border-bottom: 1px solid var(--border-color);
}

.navbar-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
    height: var(--header-height);
    padding: 0 1.5rem;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--heading-color);
    text-decoration: none;
    transition: opacity 0.2s ease;
}
.navbar-brand:hover { opacity: 0.8; }
.navbar-brand img { height: 40px; }

/* --- Botón del menú móvil (hamburguesa/X) --- */
.nav-toggle {
    display: none; /* Oculto en escritorio */
    font-size: 1.5rem;
    background: transparent;
    border: none;
    color: var(--heading-color);
    cursor: pointer;
    z-index: 1100; /* Siempre encima del menú */
    transition: transform 0.2s ease;
    padding: 0.5rem;
    line-height: 1;
}
.nav-toggle:hover { transform: scale(1.1); }

/* --- Lógica para cambiar entre ícono de hamburguesa y X --- */
.nav-toggle .fa-times { display: none; }
.nav-toggle.active .fa-bars { display: none; }
.nav-toggle.active .fa-times { display: block; }

/* --- Estilos de enlaces de navegación --- */
.nav-links { display: flex; align-items: center; gap: 1.5rem; }
.nav-menu { list-style: none; display: flex; gap: 0.5rem; align-items: center; }

.nav-menu a {
    color: var(--text-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: color 0.25s ease-in-out, background-color 0.25s ease-in-out;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.nav-menu a::after { /* Efecto de subrayado animado */
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 3px;
    background-color: var(--primary-color);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.nav-menu a:hover, .nav-menu a.active { color: var(--primary-color); }
.nav-menu a:hover::after, .nav-menu a.active::after { width: 60%; }
.nav-menu a.active { font-weight: 600; }

/* --- Información de usuario y botón de salir --- */
.nav-user-info { display: flex; align-items: center; gap: 1rem; font-weight: 500; color: var(--heading-color); }
.nav-user-info .avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-color), var(--info-color));
    color: white; display: inline-flex; justify-content: center; align-items: center;
    font-weight: 700; border: 2px solid var(--white-color);
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
}

.logout-btn {
    background: transparent; border: none; color: var(--text-color);
    font-size: 1.5rem; cursor: pointer; transition: all 0.2s ease;
    padding: 0.5rem; border-radius: 50%; width: 42px; height: 42px;
    display: inline-flex; justify-content: center; align-items: center;
}
.logout-btn span {
    display: none; /* Ocultar texto en escritorio */
}
.logout-btn:hover { color: var(--danger-color); background-color: rgba(231, 76, 60, 0.1); transform: scale(1.05); }

/* --- Overlay para el menú móvil --- */
.nav-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0; visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.nav-overlay.active { opacity: 1; visibility: visible; }

/* --- Estilos del NAV para Móvil --- */
@media (max-width: 992px) {
    .nav-toggle { display: block; }
    .nav-links {
        position: fixed; top: 0; right: 0;
        width: 300px; max-width: 90%; height: 100vh;
        background-color: var(--white-color);
        flex-direction: column; align-items: stretch;
        padding: calc(var(--header-height) + 1rem) 1.5rem 2rem;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
        gap: 0;
        justify-content: space-between;
        z-index: 1050;
    }
    .nav-links.active { transform: translateX(0); }
    .nav-menu { flex-direction: column; align-items: flex-start; width: 100%; gap: 0.5rem; }
    .nav-menu a { font-size: 1.1rem; width: 100%; padding: 0.75rem 1rem; }
    .nav-menu a:hover, .nav-menu a.active { background-color: rgba(52, 152, 219, 0.1); }
    .nav-menu a::after { display: none; }

    .nav-user-info {
        border-top: 1px solid var(--border-color);
        padding-top: 1.5rem;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 1.5rem;
    }
    .nav-user-info-details { display: flex; align-items: center; gap: 1rem; }
    
    /* === ESTILO MEJORADO PARA EL BOTÓN SALIR EN MÓVIL === */
    .logout-btn {
        width: 100%;
        background-color: transparent;
        color: var(--danger-color);
        border: 2px solid var(--border-color); /* Borde sutil por defecto */
        font-size: 1rem;
        font-weight: 600;
        border-radius: 8px;
        padding: 0.8rem 1rem;
        gap: 0.75rem;
        justify-content: center; /* Centra el ícono y el texto */
        transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    }
    .logout-btn span {
        display: inline; /* Muestra el texto "Salir" */
    }
    .logout-btn:hover {
        background-color: var(--danger-color);
        border-color: var(--danger-color);
        color: var(--white-color);
        transform: none; /* Resetea la animación de escritorio */
    }
}

/* =================================================== */
/* ===         ESTILOS GENERALES DEL PANEL         === */
/* =================================================== */
main {
    padding: calc(var(--header-height) + 2rem) 1.5rem 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

.main-header { margin-bottom: 2rem; }
.main-header h1 { font-size: 2.2rem; color: var(--heading-color); }
.main-header p { font-size: 1.1rem; color: var(--text-color); max-width: 800px; }

.layout-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 2rem;
}
@media (min-width: 1024px) { .layout-grid { grid-template-columns: 450px 1fr; } } /* Cambiado a 1024px */

.card {
    background: var(--white-color);
    padding: 2rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); }
.card:last-child { margin-bottom: 0; }
.card-header {
    margin: -2rem -2rem 1.5rem -2rem; /* Ajuste para que se alinee con los bordes */
    padding: 1.25rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--light-gray-color);
    border-top-left-radius: var(--border-radius);
    border-top-right-radius: var(--border-radius);
}
.card-header h2 { font-size: 1.4rem; font-weight: 600; color: var(--heading-color); margin: 0; }

.form-grid { display: grid; gap: 1.25rem; }
@media (min-width: 576px) { .form-grid { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); } }
.form-group { display: flex; flex-direction: column; }
.form-group label { font-weight: 600; margin-bottom: 0.5rem; font-size: 0.9rem; }

.form-control {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 16px;
    transition: all 0.3s ease;
    background-color: var(--light-gray-color);
}
.form-control[readonly], .form-control:disabled { cursor: not-allowed; opacity: 0.7; }
.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: var(--white-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
    padding: 0.8rem 1.5rem; border-radius: 8px; font-weight: 600; font-size: 16px;
    transition: all 0.2s ease; border: none; cursor: pointer; text-decoration: none;
    box-shadow: var(--shadow);
}
.btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.btn:active:not(:disabled) { transform: translateY(0); box-shadow: var(--shadow); }
.btn:disabled { cursor: not-allowed; opacity: 0.6; }
.btn-primary { background-color: var(--primary-color); color: var(--white-color); }
.btn-primary:hover:not(:disabled) { background-color: var(--primary-dark-color); }
.btn-secondary { background-color: #95a5a6; color: var(--white-color); }
.btn-secondary:hover:not(:disabled) { background-color: #7f8c8d; }
.btn-danger { background-color: var(--danger-color); color: var(--white-color); }
.btn-danger:hover:not(:disabled) { background-color: #c0392b; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 14px; }
.button-group { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.table-responsive { width: 100%; overflow-x: auto; }
.styled-table { width: 100%; border-collapse: collapse; }
.styled-table th, .styled-table td {
    padding: 1rem; text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.styled-table thead th {
    background-color: var(--light-gray-color);
    font-weight: 600;
    color: var(--heading-color);
    user-select: none;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.styled-table tbody tr { transition: background-color 0.2s ease; }
.styled-table tbody tr:hover { background-color: rgba(52, 152, 219, 0.05); }
.actions-cell { display: flex; gap: 0.5rem; }

/* --- SECCIÓN DE RECETAS --- */
.recipe-layout {
    display: grid; grid-template-columns: 1fr;
    gap: 2rem; align-items: flex-start;
}
@media (min-width: 1024px) { .recipe-layout { grid-template-columns: 2.5fr 1fr; } }
.recipe-sidebar { position: sticky; top: calc(var(--header-height) + 1.5rem); }
.summary-section h3 {
    font-size: 1.1rem; font-weight: 600;
    color: var(--heading-color); margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color); padding-bottom: 0.5rem;
}
.total-price-summary .value { font-size: 2rem; font-weight: 700; color: var(--primary-color); }
.compuesto-table { margin-top: 1rem; }
.compuesto-row, .compuesto-table-header {
    display: grid; gap: 1rem; align-items: center;
    padding: 0.75rem 0.5rem; border-bottom: 1px solid var(--border-color);
}
.compuesto-table-header { font-weight: 600; padding-bottom: 1rem; border-bottom: 2px solid #dee2e6; }
.remove-compuesto-btn { background-color: var(--danger-color); color: white; width: 40px; height: 40px; padding: 0; flex-shrink: 0; border-radius: 6px; }

/* --- NOTIFICACIONES Y MODALES --- */
#toast-container { position: fixed; top: calc(var(--header-height) + 1.5rem); right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 1rem; }
.toast {
    padding: 1rem 1.5rem; border-radius: 8px; color: var(--white-color);
    font-weight: 600; box-shadow: var(--shadow-lg); display: flex;
    align-items: center; gap: 1rem; opacity: 0; transform: translateX(100%);
    animation: slideIn 0.5s forwards;
}
.toast.exit { animation: slideOut 0.5s forwards; }
.toast-success { background-color: var(--success-color); }
.toast-error { background-color: var(--danger-color); }
.toast-info { background-color: var(--info-color); }
@keyframes slideIn { to { opacity: 1; transform: translateX(0); } }
@keyframes slideOut { to { opacity: 0; transform: translateX(100%); } }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.6); display: flex; justify-content: center;
    align-items: center; z-index: 3000; opacity: 0; visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal-content {
    background-color: var(--white-color); padding: 2.5rem; border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg); max-width: 450px; width: 90%; text-align: center;
    transform: translateY(-20px) scale(0.95); transition: transform 0.3s ease;
}
.modal-overlay.active .modal-content { transform: translateY(0) scale(1); }
.modal-content h3 { color: var(--heading-color); font-size: 1.5rem; margin-bottom: 1rem; }
.modal-content p { color: var(--text-color); margin-bottom: 2rem; line-height: 1.5; }
.modal-buttons { display: flex; gap: 1rem; justify-content: center; }

/* =================================================== */
/* ===  NUEVO: MEJORAS DE RESPONSIVIDAD GENERALES  === */
/* =================================================== */
@media (max-width: 768px) {
    /* Reducir padding general para dar más espacio al contenido */
    main {
        padding-top: calc(var(--header-height) + 1.5rem);
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Reducir padding de las tarjetas en móvil */
    .card {
        padding: 1.5rem;
    }

    /* Ajustar los headers de las tarjetas para el nuevo padding */
    .card-header {
        margin: -1.5rem -1.5rem 1.5rem -1.5rem;
        padding: 1rem 1.5rem;
    }

    /* Reducir el tamaño de los títulos principales */
    .main-header h1 {
        font-size: 1.8rem;
    }
    .main-header p {
        font-size: 1rem;
    }

    /* Asegurar que los grupos de botones en formularios se apilen */
    .form-grid .button-group {
        flex-direction: column;
        align-items: stretch; /* Botones ocupan todo el ancho */
    }
    .form-grid .button-group > .btn {
        width: 100%; 
    }
     
    /* Excepción para botones de acciones en tablas (mantener en fila) */
    .actions-cell .button-group, .actions-cell {
        flex-direction: row; 
        align-items: center;
    }
    
    /* Barra de herramientas de tablas (filtros, buscador) se apilan */
    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }
    .table-toolbar .search-container, .table-toolbar #searchInput {
        width: 100%;
    }

    /* --- Ajustes específicos para el formulario de Recetas --- */
    .recipe-sidebar {
        position: static; /* Quitar 'sticky' en móvil */
        top: auto;
    }
    
    /* Ajuste para el buscador de recetas que tiene 2 columnas fijas */
    .card .form-grid[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    .card .form-grid[style*="grid-template-columns: 2fr 1fr"] .button-group {
         flex-direction: column;
    }
}


/* --- Estilos de LOGIN (sin cambios) --- */
.login-page-body {
    font-family: var(--font-family); background-color: var(--light-gray-color);
    display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 1rem;
}
.login-wrapper {
    display: grid; grid-template-columns: 1fr; max-width: 900px;
    width: 100%; background-color: var(--white-color);
    border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,0.1); overflow: hidden;
}
@media (min-width: 992px) { .login-wrapper { grid-template-columns: 1fr 1fr; } }
.login-image-side {
    position: relative; color: var(--white-color); display: flex; justify-content: center;
    align-items: center; text-align: center; padding: 3rem; min-height: 300px;
    background: url('https://images.unsplash.com/photo-1576091160399-112ba8d25d1d?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80') center center/cover;
}
.login-image-side::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to top, rgba(52, 152, 219, 0.8), rgba(44, 62, 80, 0.8));
}
.login-branding { position: relative; z-index: 1; animation: fadeInUp 0.8s ease-out; }
.login-branding .logo {
    width: 100px; height: 100px; margin: 0 auto 1.5rem;
    background-color: var(--white-color); border-radius: 50%;
    display: flex; justify-content: center; align-items: center;
}
.login-branding .logo img { width: 60px; }
.login-branding h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; }
.login-branding p { font-size: 1.1rem; opacity: 0.9; }
.login-form-side { padding: 3rem; display: flex; flex-direction: column; justify-content: center; }
.login-form-side .form-title { color: var(--heading-color); font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; animation: fadeInUp 0.6s ease-out; }
.login-form-side .form-subtitle { color: var(--text-color); margin-bottom: 2.5rem; animation: fadeInUp 0.7s ease-out; }
.login-form-side .input-group { position: relative; margin-bottom: 1.5rem; animation: fadeInUp 0.8s ease-out; }
.login-form-side .form-control { background-color: var(--light-gray-color); border: 2px solid transparent; border-radius: 8px; padding: 1rem 1rem 1rem 3rem; }
.login-form-side .form-control:focus { background-color: var(--white-color); border-color: var(--primary-color); box-shadow: none; }
.login-form-side .input-group .icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: #aaa; transition: color 0.3s ease; }
.login-form-side .form-control:focus + .icon { color: var(--primary-color); }
.login-form-side .btn { padding: 1rem; font-size: 1.1rem; width: 100%; margin-top: 1rem; animation: fadeInUp 0.9s ease-out; }
.login-footer { text-align: center; margin-top: 2rem; color: #aaa; font-size: 0.9rem; animation: fadeInUp 1s ease-out; }
.login-footer a { color: var(--primary-color); text-decoration: none; font-weight: 600; }
.login-footer a:hover { text-decoration: underline; }
#loginToastContainer { position: absolute; bottom: 2rem; left: 50%; transform: translateX(-50%); z-index: 10; }
.login-toast { padding: 0.75rem 1.5rem; border-radius: 6px; background-color: var(--danger-color); color: white; font-weight: 600; box-shadow: var(--shadow); }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }