/* ==========================================
   1. VARIABLES GLOBALES Y RESET
   ========================================== */
:root {
    --primary: #1e40af;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #059669;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --sidebar-width: 260px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.25s ease-in-out;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-dark);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ==========================================
   2. PANTALLA DE AUTENTICACIÓN (LOGIN)
   ========================================== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    width: 100%;
    max-width: 420px;
    padding: 40px 30px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-header .login-icon {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 12px;
}

.login-header h2 {
    font-size: 24px;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.login-header p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}

/* ==========================================
   3. ESTRUCTURA PRINCIPAL (LAYOUT SPA)
   ========================================== */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* BARRA LATERAL (SIDEBAR) */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 10;
}

.sidebar-brand {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-brand .brand-logo {
    max-width: 100%;
    max-height: 50px;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    text-align: left;
}

.nav-item i {
    font-size: 18px;
    width: 20px;
}

.nav-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
}

.nav-item.active {
    background-color: var(--primary);
    color: #ffffff;
}

/* ÁREA PRINCIPAL */
.main-wrapper {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.top-header {
    height: 70px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    position: sticky;
    top: 0;
    z-index: 9;
}

.top-header h1 {
    font-size: 22px;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 18px;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-main);
    padding: 6px 14px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 14px;
    border: 1px solid var(--border-color);
}

.user-pill img {
    border-radius: 50%;
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
    position: relative;
}

.icon-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.logout-btn:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.content-body {
    padding: 30px;
    flex: 1;
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================
   4. COMPONENTES: DASHBOARD Y MÉTRICAS
   ========================================== */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.metric-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 18px;
}

.metric-icon {
    width: 50px;
    height: 50px;
    border-radius: var(--radius-md);
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 22px;
}

.metric-card.warning .metric-icon {
    background: var(--warning-light);
    color: var(--warning);
}

.metric-card.success .metric-icon {
    background: #d1fae5;
    color: var(--success);
}

.metric-info h3 {
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-info p {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-dark);
}

/* Diagrama de Flujo (Nodos del Almacén) */
.dashboard-node-diagram {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-top: 20px;
    box-shadow: var(--shadow-sm);
}

.dashboard-node-diagram h2 {
    font-size: 18px;
    margin-bottom: 20px;
    color: var(--text-dark);
}

.nodes-container {
    display: flex;
    align-items: center;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 15px;
}

.node-box {
    background: var(--bg-main);
    border: 1px dashed var(--primary);
    padding: 20px;
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 140px;
}

.node-box i {
    font-size: 28px;
    color: var(--primary);
}

.node-box span {
    font-size: 13px;
    color: var(--text-muted);
}

.node-box strong {
    font-size: 20px;
}

.node-connector {
    color: var(--text-muted);
    font-size: 20px;
}

/* ==========================================
   5. COMPONENTES: CATÁLOGO Y TARJETAS
   ========================================== */
.catalog-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 20px;
}

.catalog-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.catalog-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.catalog-card h2 {
    font-size: 16px;
    margin: 10px 0 4px;
}

.card-price {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.catalog-card.low-stock-alert {
    border-left: 4px solid var(--warning);
}

.catalog-card.zero-stock-alert {
    border-left: 4px solid var(--danger);
    opacity: 0.75;
}

.btn-sell {
    width: 100%;
    padding: 10px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-sell:hover {
    background: #047857;
}

/* ==========================================
   6. TABLAS, BÚSQUEDA Y FILTROS
   ========================================== */
.table-actions, .filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-bar input, .filter-bar select {
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    font-size: 14px;
}

.filter-bar input {
    flex: 1;
    min-width: 200px;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.data-table th {
    background: #f1f5f9;
    padding: 14px 16px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.data-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Badges e indicadores de Stock */
.stock-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.stock-badge.ok { background: #d1fae5; color: var(--success); }
.stock-badge.low { background: var(--warning-light); color: var(--warning); }
.stock-badge.zero { background: var(--danger-light); color: var(--danger); }

.row-low-stock { background-color: #fffbeb; }
.row-zero-stock { background-color: #fef2f2; }

/* Botones de acción en filas */
.btn-icon {
    background: transparent;
    border: none;
    font-size: 15px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-icon.edit { color: var(--primary); }
.btn-icon.edit:hover { background: var(--primary-light); }
.btn-icon.delete { color: var(--danger); }
.btn-icon.delete:hover { background: var(--danger-light); }

.role-perm-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    margin: 2px;
}

/* ==========================================
   7. FORMULARIOS Y MODALES
   ========================================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-group input, .form-group select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    font-size: 14px;
    transition: var(--transition);
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

.form-row {
    display: flex;
    gap: 12px;
}

.form-row .form-group {
    flex: 1;
}

/* MODALES */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 480px;
    padding: 28px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modalPop 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
    margin-bottom: 18px;
    font-size: 18px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.permissions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    background: var(--bg-main);
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.perm-checkbox {
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

/* BOTONES GENERALES */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: var(--bg-main);
    color: var(--text-dark);
    border: 1px solid var(--border-color);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover { background: #e2e8f0; }

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-danger:hover { background: #b91c1c; }

.btn-full { width: 100%; }

/* ==========================================
   8. NOTIFICACIONES Y TOAST
   ========================================== */
.notif-wrapper {
    position: relative;
}

.badge-count {
    position: absolute;
    top: -2px;
    right: -2px;
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.notif-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 45px;
    width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 20;
    overflow: hidden;
}

.notif-dropdown.active {
    display: block;
    animation: fadeIn 0.2s ease-in-out;
}

.notif-header {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color);
}

.notif-header h3 { font-size: 14px; }

.notif-body {
    max-height: 250px;
    overflow-y: auto;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.notif-item:last-child { border-bottom: none; }

.notif-text { display: flex; flex-direction: column; }
.notif-title { font-weight: 700; font-size: 12px; }

.toast {
    position: fixed;
    bottom: 25px;
    right: 25px;
    background: #0f172a;
    color: white;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 1000;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ==========================================
   9. GRÁFICOS Y ADAPTACIONES
   ========================================== */
.chart-container {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.chart-container h2 {
    font-size: 16px;
    margin-bottom: 16px;
}

.chart-wrapper {
    position: relative;
    height: 300px;
    width: 100%;
}


/* RESPONSIVO */
@media (max-width: 768px) {
    .sidebar {
        width: 70px;
    }
    .sidebar-brand span, .nav-item span {
        display: none;
    }
    .main-wrapper {
        margin-left: 70px;
    }
    .nodes-container {
        flex-direction: column;
    }
    .node-connector {
        transform: rotate(90deg);
    }
}