/* ==========================================================================
   STOCK COMMAND CENTER (v5.1 - FIX DE ALTURA INFINITA)
   ========================================================================== */

/* --- 1. LAYOUT PRINCIPAL --- */
.dashboard-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
    padding-top: 10px;
    width: 100%;
    /* Removemos min-height: 100% para evitar forçar esticamento desnecessário */
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 300px 1fr; 
    gap: 30px;
    align-items: start; /* ISSO É IMPORTANTE: Impede que a sidebar estique junto com o conteúdo */
}

.dashboard-main-content {
    display: flex;
    flex-direction: column;
    gap: 30px;
    min-width: 0; /* Truque de CSS para impedir que grids vazazem */
}

/* --- 2. HEADER --- */
.dashboard-header {
    background: #ffffff !important;
    border-radius: 20px !important;
    padding: 25px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.05) !important;
    border: 1px solid rgba(0,0,0,0.02);
    margin-bottom: 10px;
}
.welcome-text h4 { margin: 0; font-weight: 800 !important; font-size: 1.6rem; color: #1e293b; letter-spacing: -0.5px; }
.welcome-text p { margin: 5px 0 0 0; font-size: 0.95rem; color: #64748b; }

.quick-actions { display: flex; gap: 12px; }
.btn-quick {
    background: #ffffff; border: 1px solid #e2e8f0; color: #475569;
    padding: 10px 20px; border-radius: 12px; font-weight: 600; font-size: 0.9rem;
    transition: all 0.2s ease-in-out; display: flex; align-items: center; gap: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.02); cursor: pointer;
}
.btn-quick:hover { background: #f8fafc; border-color: #3b82f6; color: #3b82f6; transform: translateY(-3px); box-shadow: 0 5px 15px rgba(59, 130, 246, 0.15); }


/* --- 3. SIDEBAR DE ALERTAS (FIXA) --- */
.inventory-sidebar {
    background: #ffffff !important;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px -10px rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.02);
    
    /* TRAVA DE ALTURA DA SIDEBAR */
    height: calc(100vh - 140px); 
    min-height: 500px;
    overflow: hidden; /* O scroll é interno */
    
    display: flex;
    flex-direction: column;
    position: sticky; 
    top: 100px;
}
.sidebar-title {
    font-size: 0.9rem; font-weight: 800; color: var(--primary-color);
    margin-bottom: 15px; padding-bottom: 10px; border-bottom: 2px solid #f1f5f9;
    display: flex; align-items: center; gap: 10px;
    flex-shrink: 0;
}
.alert-list { flex-grow: 1; overflow-y: auto; padding-right: 5px; margin-bottom: 20px; }

.stock-alert-item {
    background: #fff1f2; border: 1px solid #fecaca; border-radius: 12px;
    padding: 12px; margin-bottom: 10px; border-left: 4px solid #ef4444;
}
.alert-model { font-weight: 800; color: #991b1b; font-size: 0.9rem; display: block; }
.alert-info { font-size: 0.75rem; color: #b91c1c; display: flex; justify-content: space-between; margin-top: 4px; }
.alert-badge { background: #ef4444; color: white; padding: 2px 8px; border-radius: 6px; font-weight: 700; font-size: 0.75rem; }
.req-item {
    background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 12px;
    padding: 12px; margin-bottom: 10px; border-left: 4px solid #3b82f6;
    cursor: pointer; transition: transform 0.2s;
}
.req-item:hover { transform: translateX(3px); }
.req-filial { font-weight: 700; color: #1e40af; font-size: 0.9rem; display: block; }
.req-user { font-size: 0.75rem; color: #60a5fa; }
.req-date { font-size: 0.7rem; color: #94a3b8; float: right; }


/* --- 4. KPIs --- */
.kpi-metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}
.metric-card {
    background: #ffffff !important; border-radius: 20px; padding: 25px;
    box-shadow: 0 8px 15px -5px rgba(0, 0, 0, 0.05); border: 1px solid rgba(0,0,0,0.05);
    transition: all 0.3s; height: 140px; position: relative; overflow: hidden;
}
.metric-card:hover { transform: translateY(-5px); box-shadow: 0 15px 30px -5px rgba(0,0,0,0.1); }
.metric-card::after { content: ''; position: absolute; top: -10px; right: -10px; width: 80px; height: 80px; border-radius: 50%; opacity: 0.1; z-index: 0; }
.metric-icon { font-size: 1.8rem; margin-bottom: 15px; position: relative; z-index: 1; }
.metric-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: #94a3b8; margin-bottom: 5px; letter-spacing: 1px; position: relative; z-index: 1; }
.metric-value { font-size: 2.2rem; font-weight: 800; color: #1e293b; line-height: 1; position: relative; z-index: 1; }

.metric-blue { border-bottom: 4px solid #3b82f6; } .metric-blue .metric-icon { color: #3b82f6; } .metric-blue::after { background: #3b82f6; }
.metric-green { border-bottom: 4px solid #10b981; } .metric-green .metric-icon { color: #10b981; } .metric-green::after { background: #10b981; }
.metric-orange { border-bottom: 4px solid #f59e0b; } .metric-orange .metric-icon { color: #f59e0b; } .metric-orange::after { background: #f59e0b; }
.metric-purple { border-bottom: 4px solid #8b5cf6; } .metric-purple .metric-icon { color: #8b5cf6; } .metric-purple::after { background: #8b5cf6; }


/* --- 5. GRÁFICOS (CORREÇÃO DO LOOP INFINITO) --- */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.chart-module {
    background: #ffffff !important; 
    border-radius: 20px; 
    padding: 25px;
    box-shadow: 0 8px 15px -5px rgba(0, 0, 0, 0.05); 
    border: 1px solid rgba(0,0,0,0.02);
    
    /* === A CORREÇÃO ESTÁ AQUI === */
    height: 400px; /* Altura FIXA para impedir crescimento */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Corta qualquer coisa que tente vazar */
}

/* Contêiner relativo para o Canvas do Chart.js */
.chart-canvas-wrapper {
    flex-grow: 1;
    position: relative;
    width: 100%;
    min-height: 0; /* Importante para Flexbox */
}

.module-header { font-size: 1.1rem; font-weight: 800; color: #334155; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }


/* --- 6. FEED DE ATIVIDADE --- */
.activity-module {
    background: #ffffff !important; border-radius: 20px; padding: 25px;
    box-shadow: 0 8px 15px -5px rgba(0, 0, 0, 0.05); border: 1px solid rgba(0,0,0,0.02);
    height: 400px; /* Altura fixa igual aos gráficos */
    display: flex; flex-direction: column;
}
.feed-list { flex-grow: 1; overflow-y: auto; padding-right: 5px; }
.feed-item { display: flex; gap: 15px; padding-bottom: 15px; margin-bottom: 15px; border-bottom: 1px dashed #e2e8f0; }
.feed-item:last-child { border-bottom: none; margin-bottom: 0; }
.feed-icon { width: 36px; height: 36px; border-radius: 50%; background: #f1f5f9; color: #64748b; display: flex; align-items: center; justify-content: center; font-size: 0.9rem; flex-shrink: 0; border: 2px solid white; box-shadow: 0 2px 5px rgba(0,0,0,0.05); }
.feed-content { flex-grow: 1; }
.feed-title { font-size: 0.9rem; font-weight: 700; color: #334155; display: block; margin-bottom: 2px; }
.feed-time { font-size: 0.75rem; color: #94a3b8; font-weight: 500; }
.feed-desc { font-size: 0.85rem; color: #64748b; line-height: 1.4; margin-top: 2px; }


/* --- MOBILE --- */
@media (max-width: 991.98px) {
    .dashboard-grid { grid-template-columns: 1fr; }
    .kpi-metrics-grid { grid-template-columns: 1fr 1fr; }
    .charts-grid { grid-template-columns: 1fr; }
    .inventory-sidebar { order: 2; min-height: auto; height: auto; position: relative; top: 0; overflow: visible; }
    .dashboard-main-content { order: 1; }
    .dashboard-header { flex-direction: column; gap: 15px; text-align: center; }
    .quick-actions { width: 100%; justify-content: center; flex-wrap: wrap; }
}

/* Dark Mode */
body.dark-mode .dashboard-header, body.dark-mode .metric-card, 
body.dark-mode .chart-module, body.dark-mode .activity-module, 
body.dark-mode .inventory-sidebar {
    background: #1e293b !important; border-color: rgba(255,255,255,0.05); box-shadow: none !important;
}
body.dark-mode .welcome-text h4, body.dark-mode .metric-value, body.dark-mode .module-header, body.dark-mode .feed-title, body.dark-mode .sidebar-title { color: #f8fafc !important; }
body.dark-mode .stock-alert-item { background: #450a0a; border-color: #7f1d1d; }
body.dark-mode .alert-model { color: #fecaca; }
body.dark-mode .alert-info { color: #fca5a5; }
body.dark-mode .btn-quick { background: #334155; color: #cbd5e1; border-color: #475569; }

/* css/dashboard.css - CORREÇÕES DE FONTE */

/* Sidebar de Alertas */
.alert-model { 
    font-size: 1rem !important; /* Nome do modelo maior */
}
.alert-info { 
    font-size: 0.85rem !important; /* Detalhes legíveis */
}

/* Feed de Atividade */
.feed-title { 
    font-size: 0.95rem !important; 
}
.feed-desc { 
    font-size: 0.9rem !important; /* Descrição da atividade */
}
.feed-time { 
    font-size: 0.8rem !important; 
}

/* KPIs (Cards do Topo) */
.kpi-label {
    font-size: 0.85rem !important; /* Rótulo maior */
}
.kpi-value {
    font-size: 2.5rem !important; /* Números grandes e claros */
}

/* ==========================================================================
   RANKING GAMIFICATION (COROAÇÃO)
   ========================================================================== */

/* Linha do Vencedor (Ouro) */
tr.rank-winner {
    background: linear-gradient(135deg, #fffbeb 0%, #fff3cd 100%) !important;
    border-left: 5px solid #f1c40f !important;
    box-shadow: 0 4px 15px rgba(241, 196, 15, 0.2);
    position: relative;
    z-index: 1;
    transform: scale(1.01);
    font-weight: bold;
}

tr.rank-winner td {
    color: #856404 !important;
    border-bottom: 1px solid #ffeeba;
}

/* Ícone da Coroa Animada */
.crown-icon {
    font-size: 1.5rem;
    color: #f1c40f;
    text-shadow: 0 2px 5px rgba(0,0,0,0.2);
    animation: floatCrown 2s ease-in-out infinite;
    display: inline-block;
    margin-right: 8px;
}

@keyframes floatCrown {
    0%, 100% { transform: translateY(0) rotate(-5deg); }
    50% { transform: translateY(-5px) rotate(5deg); }
}

/* Avatar do Vencedor com Borda Dourada */
.winner-avatar {
    border: 3px solid #f1c40f !important;
    box-shadow: 0 0 10px rgba(241, 196, 15, 0.5);
}

/* Widget de Vencedor no Dashboard (Opcional) */
.winner-widget {
    background: linear-gradient(135deg, #FFD700, #FDB931);
    color: #5c4000;
    border-radius: 16px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 4px 15px rgba(253, 185, 49, 0.4);
    margin-bottom: 20px;
}

/* ==========================================================================
   RANKING PODIUM (TOP 3)
   ========================================================================== */

.podium-container {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 15px;
    margin-bottom: 30px;
    padding-top: 20px;
}

.podium-card {
    background: white;
    border-radius: 16px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    position: relative;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 30%;
}

/* Animação de entrada */
.podium-card { animation: slideUpPodium 0.5s ease-out; }
@keyframes slideUpPodium { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* --- 1º LUGAR (OURO) --- */
.podium-gold {
    border-top: 5px solid #f1c40f;
    order: 2; /* Fica no meio visualmente */
    transform: scale(1.1);
    z-index: 2;
}
.podium-gold .rank-medal { font-size: 2.5rem; margin-bottom: 10px; display: block; }
.podium-gold .rank-value { color: #f1c40f; font-weight: 800; font-size: 1.4rem; }
.podium-gold::after {
    content: '👑'; position: absolute; top: -25px; left: 50%; transform: translateX(-50%); font-size: 2rem;
    animation: floatCrown 2s ease-in-out infinite;
}

/* --- 2º LUGAR (PRATA) --- */
.podium-silver {
    border-top: 5px solid #bdc3c7;
    order: 1; /* Esquerda */
    margin-bottom: -10px;
}
.podium-silver .rank-medal { font-size: 2rem; margin-bottom: 10px; display: block; }
.podium-silver .rank-value { color: #7f8c8d; font-weight: 800; font-size: 1.2rem; }

/* --- 3º LUGAR (BRONZE) --- */
.podium-bronze {
    border-top: 5px solid #cd7f32;
    order: 3; /* Direita */
    margin-bottom: -20px;
}
.podium-bronze .rank-medal { font-size: 2rem; margin-bottom: 10px; display: block; }
.podium-bronze .rank-value { color: #a05a2c; font-weight: 800; font-size: 1.2rem; }

/* Avatar no Pódio */
.podium-avatar {
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0 auto 10px auto;
    border: 3px solid white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Títulos */
.podium-name { font-weight: 800; color: #2c3e50; margin-bottom: 2px; display: block; }
.podium-label { font-size: 0.7rem; text-transform: uppercase; color: #95a5a6; }

/* Ajuste Mobile */
@media (max-width: 767px) {
    .podium-container { flex-direction: column; align-items: center; }
    .podium-card { width: 100%; margin-bottom: 10px; order: unset !important; transform: none !important; }
    .podium-gold::after { top: 10px; right: 20px; left: auto; transform: none; }
}

/* css/dashboard.css */

.kpi-metrics-grid {
    display: grid;
    /* Tenta colocar 5 colunas se der, senão quebra linha automaticamente */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); 
    gap: 20px;
}

/* Novo Estilo para o Card de Ouro (Economia) */
.metric-gold { 
    border-bottom: 4px solid #f1c40f; 
    background: linear-gradient(to bottom right, #ffffff, #fffbf0) !important;
}
.metric-gold .metric-icon { color: #f1c40f; }
.metric-gold .metric-value { color: #d35400; } /* Tom alaranjado para dinheiro */
.metric-gold::after { background: #f1c40f; }

/* ==========================================================================
   FIX GAMIFICATION: COROA E DESTAQUES (Restauração da Glória)
   ========================================================================== */

/* 1. CORREÇÃO DA COROA NO RODAPÉ (Avatar) */
.king-avatar-wrapper {
    position: relative !important; /* Essencial para a coroa flutuar em cima */
    display: inline-block !important;
    overflow: visible !important;  /* Permite que a coroa saia das bordas */
}

.king-crown-overlay {
    position: absolute !important;
    top: -22px !important;        /* Sobe a coroa para o topo da cabeça */
    left: -12px !important;       /* Ajusta para a esquerda */
    font-size: 1.8rem !important; /* Tamanho Grande */
    color: #f1c40f !important;    /* OURO BRILHANTE (Forçado) */
    text-shadow: 0 2px 5px rgba(0,0,0,0.3); /* Sombra para destacar no fundo claro */
    z-index: 999 !important;      /* Fica na frente de tudo */
    transform: rotate(-15deg);    /* Inclinação estilosa */
    display: block !important;
}

/* 2. CORREÇÃO DO NOME NO CARD DO VENCEDOR (Pódio) */
.podium-name {
    font-size: 1.1rem !important; /* Aumenta a fonte (estava pequena) */
    font-weight: 900 !important;  /* Extra Negrito */
    color: #2c3e50 !important;    /* Azul escuro forte */
    margin-bottom: 5px !important;
    letter-spacing: -0.5px;
}

/* 3. DESTAQUE DO CARD DE OURO (1º Lugar) */
.podium-gold {
    transform: scale(1.15) !important; /* Aumenta o card do meio */
    z-index: 10 !important;
    border-top: 6px solid #f1c40f !important; /* Topo Dourado Grosso */
    box-shadow: 0 10px 30px rgba(241, 196, 15, 0.2) !important; /* Brilho Dourado */
}

/* Aumenta a medalha do 1º lugar */
.podium-gold .rank-medal {
    font-size: 3rem !important; 
    margin-bottom: 15px !important;
}

/* 4. NOME GIGANTE NO MODAL DE CELEBRAÇÃO */
.celebration-winner {
    font-size: 2.5rem !important; /* Gigante */
    font-weight: 800 !important;
    color: #2c3e50 !important;
    text-transform: uppercase;
    margin: 20px 0 !important;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.1);
}