/* ==========================================================================
   1. VARIABLES Y CONFIGURACIÓN (TEMA NEUMÓRFICO)
   ========================================================================== */
:root {
    /* --- Colores --- */
    --bg-body: #e0e5ec;
    --primary: #4361ee;
    --primary-dark: #3a56d4;
    --secondary: #7209b7;
    --success: #06d6a0;
    --danger: #ef476f;
    --warning: #ffd166;
    --dark: #1e293b;
    --text-main: #4b5563;
    --text-muted: #94a3b8;
    
    /* --- Sombras Neumórficas --- */
    --shadow-light: #ffffff;
    --shadow-dark: #a3b1c6;
    --neumo-out: 8px 8px 16px var(--shadow-dark), -8px -8px 16px var(--shadow-light);
    --neumo-out-hover: 12px 12px 24px var(--shadow-dark), -12px -12px 24px var(--shadow-light);
    --neumo-in: inset 5px 5px 8px var(--shadow-dark), inset -5px -5px 8px var(--shadow-light);

    /* --- Configuración --- */
    --radius: 18px;
    --radius-sm: 10px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

/* ==========================================================================
   2. RESET Y BASE
   ========================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-body); color: var(--text-main);
    font-family: var(--font-family); line-height: 1.6; min-height: 100vh; font-size: 15px;
}

a { text-decoration: none; color: inherit; transition: var(--transition); }
ul { list-style: none; }
h1, h2, h3, h4 { color: var(--dark); font-weight: 800; line-height: 1.2; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-body); }
::-webkit-scrollbar-thumb { background: var(--shadow-dark); border-radius: 4px; border: 2px solid var(--bg-body); }

/* ==========================================================================
   3. SIDEBAR (BARRA LATERAL)
   ========================================================================== */
.sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 260px;
    background: var(--bg-body); padding: 2rem 1.5rem; display: flex; flex-direction: column;
    z-index: 1000; box-shadow: 6px 0 12px rgba(163, 177, 198, 0.4); transition: var(--transition);
}

.sidebar-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 2.5rem; }
.sidebar-brand h2 { font-size: 1.5rem; color: var(--primary); letter-spacing: 1px; margin: 0; }

.sidebar-nav { display: flex; flex-direction: column; gap: 1rem; flex: 1; overflow-y: auto; }

.nav-link {
    display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem;
    border-radius: var(--radius); color: var(--text-main); font-weight: 600; transition: var(--transition);
}
.nav-link i { width: 24px; text-align: center; font-size: 1.2rem; color: var(--text-muted); }
.nav-link:hover { color: var(--primary); box-shadow: var(--neumo-out); transform: translateY(-2px); }
.nav-link.active { color: var(--primary); background: var(--bg-body); box-shadow: var(--neumo-in); }

/* ==========================================================================
   4. LAYOUT PRINCIPAL
   ========================================================================== */
.main-content { margin-left: 260px; padding: 2rem 3rem; min-height: 100vh; transition: var(--transition); }
.container { max-width: 1280px; margin: 0 auto; }
.page-title-placeholder h1 { font-size: 2.2rem; color: var(--dark); margin-bottom: 2rem; }

/* ==========================================================================
   5. DASHBOARD (TARJETAS, GRIDS, WIDGETS) - ¡RECUPERADO!
   ========================================================================== */

/* Tarjeta de Bienvenida (Azul) */
.welcome-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; border-radius: var(--radius); padding: 2.5rem; margin-bottom: 2.5rem;
    box-shadow: 10px 10px 20px rgba(67, 97, 238, 0.4), -10px -10px 20px rgba(255, 255, 255, 0.8);
}
.welcome-card h2 { color: white; margin-bottom: 0.5rem; }
.welcome-card p { color: rgba(255,255,255,0.9); margin-bottom: 1.5rem; }

/* Estadísticas Rápidas dentro del Welcome Card */
.quick-stats { display: flex; gap: 2rem; flex-wrap: wrap; }
.stat-item { 
    background: rgba(255,255,255,0.2); padding: 0.8rem 1.5rem; border-radius: 12px;
    display: flex; flex-direction: column; backdrop-filter: blur(5px);
}
.stat-number { font-size: 1.4rem; font-weight: 800; }
.stat-label { font-size: 0.8rem; opacity: 0.9; text-transform: uppercase; }

/* Grid del Dashboard */
.dashboard-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 2rem; margin-bottom: 2rem;
}

/* KPI Cards (Cuadros Blancos con Iconos) */
.kpi-card {
    background: var(--bg-body); padding: 1.5rem; border-radius: var(--radius);
    box-shadow: var(--neumo-out); display: flex; align-items: center; gap: 1.5rem;
    transition: var(--transition);
}
.kpi-card:hover { transform: translateY(-5px); box-shadow: var(--neumo-out-hover); }

.kpi-icon {
    width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    box-shadow: var(--neumo-in); color: var(--primary); font-size: 1.4rem;
}
.kpi-content h3 { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 5px; }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--dark); }

/* Dashboard Columnas (Widgets) */
.dashboard-content { display: grid; grid-template-columns: 2fr 1fr; gap: 2rem; }

.dashboard-widget {
    background: var(--bg-body); padding: 2rem; border-radius: var(--radius);
    box-shadow: var(--neumo-out); margin-bottom: 2rem;
}

.widget-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; border-bottom: 1px solid rgba(0,0,0,0.05); padding-bottom: 1rem;
}
.widget-badge {
    background: var(--bg-body); box-shadow: var(--neumo-in); padding: 0.3rem 0.8rem;
    border-radius: 20px; font-size: 0.7rem; font-weight: bold; color: var(--primary);
}

/* Listas dentro de Widgets (Productos Top) */
.product-rank, .recent-item, .costly-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.8rem 0; border-bottom: 1px solid rgba(0,0,0,0.03);
}
.product-rank:last-child { border-bottom: none; }
.rank-number { 
    width: 25px; height: 25px; background: var(--bg-body); box-shadow: var(--neumo-in);
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: bold; font-size: 0.8rem; color: var(--text-muted); margin-right: 10px;
}

/* Módulos de Acceso Rápido */
.modules-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 2rem; margin-top: 2rem;
}
.module-card {
    background: var(--bg-body); border-radius: var(--radius); box-shadow: var(--neumo-out);
    padding: 1.5rem; text-align: center; transition: var(--transition); cursor: pointer;
}
.module-card:hover { transform: translateY(-3px); border: 1px solid var(--primary); }
.module-icon { font-size: 2rem; margin-bottom: 1rem; }
.module-count { display: block; margin-top: 0.5rem; font-size: 0.8rem; color: var(--text-muted); }

/* Alertas */
.alert-widget .widget-header { color: var(--danger); }
.alert-item { display: flex; justify-content: space-between; margin-bottom: 1rem; font-weight: bold; }
.alert-detail { font-size: 0.9rem; padding: 5px 0; color: var(--text-main); }
.alert-dot { display: inline-block; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; margin-right: 8px; }

/* Acciones Rápidas */
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.action-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 1rem; border-radius: var(--radius-sm); background: var(--bg-body);
    box-shadow: var(--neumo-out); color: var(--text-main); transition: var(--transition);
}
.action-btn:hover { color: var(--primary); transform: translateY(-2px); }
.action-btn:active { box-shadow: var(--neumo-in); transform: translateY(0); }

/* ==========================================================================
   6. FORMS Y BOTONES (UI GENERAL)
   ========================================================================== */
.form-crud { background: var(--bg-body); padding: 2rem; border-radius: var(--radius); box-shadow: var(--neumo-out); margin-bottom: 2rem; }
.form-crud h3 { margin-bottom: 1.5rem; color: var(--primary); }

input, select, textarea {
    width: 100%; padding: 0.9rem 1.2rem; border: none; border-radius: var(--radius-sm);
    background: var(--bg-body); box-shadow: var(--neumo-in); margin-bottom: 1rem;
    color: var(--dark); outline: none; font-size: 0.95rem;
}
input:focus, select:focus { box-shadow: inset 3px 3px 6px var(--shadow-dark), inset -3px -3px 6px var(--shadow-light); color: var(--primary); }

button, .btn-primary, .btn-secondary, .btn-danger, .btn-exportar {
    padding: 0.8rem 1.5rem; border: none; border-radius: var(--radius-sm);
    font-weight: 700; cursor: pointer; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--bg-body); color: var(--primary); box-shadow: var(--neumo-out);
    transition: var(--transition);
}
button:active, .btn-primary:active { transform: translateY(0); box-shadow: var(--neumo-in); }

.btn-danger { color: var(--danger); }
.btn-exportar { background: var(--success); color: white; box-shadow: 6px 6px 12px #06d6a040, -6px -6px 12px #fff; }

/* ==========================================================================
   7. TABLAS AVANZADAS (Scroll + Compactas)
   ========================================================================== */
.table-scroll-wrapper {
    max-height: 65vh; overflow-y: auto; border-radius: var(--radius);
    background: var(--bg-body); box-shadow: var(--neumo-in); position: relative; margin-bottom: 2rem;
}

.table-compact { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.9rem; }

.table-compact thead th {
    position: sticky; top: 0; z-index: 10; background-color: #eef2f6;
    padding: 1rem; color: var(--primary); font-weight: 700;
    border-bottom: 2px solid rgba(0,0,0,0.1); box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.table-compact td { padding: 0.7rem 1rem; border-bottom: 1px solid rgba(0,0,0,0.05); vertical-align: middle; color: var(--dark); }
.table-compact tbody tr:hover { background-color: rgba(67, 97, 238, 0.05); }

.row-highlight { animation: highlightFade 2s ease-out; background-color: rgba(16, 185, 129, 0.2) !important; }
@keyframes highlightFade { 0% { background-color: rgba(16, 185, 129, 0.4); } 100% { background-color: transparent; } }

/* ==========================================================================
   8. TOOLBAR Y MODALES (Gestión)
   ========================================================================== */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: 1rem; }
.search-box { position: relative; flex-grow: 1; max-width: 400px; }
.search-box input { width: 100%; padding-left: 2.5rem; margin-bottom: 0; border-radius: 20px; }
.search-box i { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }

/* Modal */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 41, 59, 0.7); backdrop-filter: blur(3px);
    display: none; justify-content: center; align-items: center; z-index: 2000;
    opacity: 0; transition: opacity 0.3s ease;
}
.modal-overlay.active { display: flex; opacity: 1; }

.modal-content {
    background: var(--bg-body); padding: 2rem; border-radius: var(--radius);
    box-shadow: 0 20px 50px rgba(0,0,0,0.3); width: 95%; max-width: 600px;
    transform: translateY(20px); transition: transform 0.3s ease; max-height: 90vh; overflow-y: auto;
}
.modal-overlay.active .modal-content { transform: translateY(0); }

.modal-header { display: flex; justify-content: space-between; margin-bottom: 1.5rem; border-bottom: 1px solid rgba(0,0,0,0.1); padding-bottom: 0.5rem; }
.close-modal { background: transparent; border: none; font-size: 1.5rem; cursor: pointer; }

/* Botones pequeños */
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; margin: 0; }
.action-group { display: flex; gap: 5px; }

/* Estilos para filas de receta en modal */
.recipe-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 10px; align-items: center; margin-bottom: 10px; }

/* ==========================================================================
   9. RESPONSIVE (MÓVIL) - APP STYLE
   ========================================================================== */
@media (max-width: 992px) {
    .dashboard-content { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    /* Sidebar fijo abajo */
    .sidebar {
        width: 100%; height: auto; top: auto; bottom: 0; left: 0;
        flex-direction: row; padding: 0.5rem; justify-content: space-around;
        box-shadow: 0 -5px 15px rgba(0,0,0,0.1); z-index: 9999;
    }
    .sidebar-brand { display: none; }
    .sidebar-nav { flex-direction: row; width: 100%; padding: 0; overflow: visible; }
    .nav-link { flex-direction: column; padding: 0.5rem; font-size: 0.7rem; gap: 4px; border-radius: 0; box-shadow: none; background: transparent; }
    .nav-link i { font-size: 1.4rem; margin: 0; }
    .nav-link span { display: none; }
    .nav-link.active { background: transparent; box-shadow: inset 0 -3px 0 var(--primary); color: var(--primary); }

    /* Ajuste Contenido */
    .main-content { margin-left: 0; padding: 1rem; padding-bottom: 100px; }
    
    /* Ajustes Generales */
    .dashboard-grid, .modules-grid, .quick-actions { grid-template-columns: 1fr; gap: 1rem; }
    header h1 { font-size: 1.6rem; text-align: center; }
    .toolbar { flex-direction: column; }
    .search-box, button { width: 100%; }
    
    /* Modal Móvil */
    .modal-content { width: 100%; height: 100%; border-radius: 0; padding: 1.5rem; margin: 0; max-height: 100vh; }
    .recipe-row { grid-template-columns: 1fr 1fr; gap: 5px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
    .recipe-row select { grid-column: span 2; }
}