/* Paleta de Cores e Variáveis */
:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --dark-panel: #0f172a;
    --dark-bg: #1e293b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-light: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --white: #ffffff;
    --radius: 16px;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    font-family: 'Poppins', sans-serif; 
}

body { 
    background-color: var(--bg-light); 
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
}

.hidden { 
    display: none !important; 
    pointer-events: none; /* Garante que não receba cliques enquanto escondido */
}

/* --- SISTEMA DE SOBREPOSIÇÃO (POPUPS) --- */
@keyframes popupIn {
    from { opacity: 0; transform: scale(0.95) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Modais e Overlays configurados para sobreposição total */
#advancedConfigModal, #adminPanel {
    z-index: 2000;
}
.modal-overlay, .ai-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000; /* Padrão */
    transition: opacity 0.3s ease;
}

.ai-overlay { z-index: 4500; } /* IA sobrepõe até outros modais */

.modal-window, .ai-box {
    animation: popupIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    z-index: 4001;
}

/* --- TELAS DE AUTENTICAÇÃO (LOGIN & MASTER) --- */
.auth-overlay { 
    position: fixed; 
    inset: 0; 
    background: radial-gradient(circle at top left, #1e293b, #0f172a);
    display: flex; 
    align-items: center; 
    justify-content: center; 
    z-index: 5000; 
}

.login-card { 
    background: var(--white); 
    padding: 3rem 2.5rem; 
    border-radius: 24px; 
    width: 400px; 
    text-align: center; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255,255,255,0.1);
    animation: popupIn 0.4s ease;
}

.logo-icon { 
    width: 70px; 
    height: 70px; 
    background: var(--primary); 
    border-radius: 20px; 
    margin: 0 auto 20px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    font-size: 2.5rem;
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.4);
}

.login-card h1 { font-size: 1.75rem; color: var(--dark-panel); margin-bottom: 5px; }
.login-card h1 span { color: var(--primary); }
.login-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 2rem; }

/* --- SIDEBAR --- */
.sidebar { 
    width: 280px; 
    background: var(--dark-panel); 
    color: var(--white); 
    padding: 2rem 1.5rem; 
    position: fixed; 
    height: 100vh; 
    display: flex; 
    flex-direction: column;
    box-shadow: 4px 0 10px rgba(0,0,0,0.1);
    z-index: 100; /* Fica atrás dos modais */
}

.side-logo { 
    font-size: 1.5rem; 
    font-weight: 700; 
    margin-bottom: 3rem; 
    letter-spacing: -1px; 
}

.side-logo span { color: var(--primary); }

.nav-item {
    background: transparent;
    border: none;
    color: #94a3b8;
    padding: 12px 15px;
    border-radius: 12px;
    text-align: left;
    cursor: pointer;
    font-weight: 500;
    transition: 0.3s;
    margin-bottom: 8px;
    width: 100%;
}

.nav-item:hover, .nav-item.active {
    background: rgba(255,255,255,0.05);
    color: var(--white);
}

.cycle-info-box { 
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.05));
    padding: 20px; 
    border-radius: 18px; 
    margin-top: 2rem; 
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.cycle-info-box span { font-size: 0.7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 1px; }
.cycle-info-box strong { display: block; color: var(--success); font-size: 1.1rem; margin-top: 5px; }

/* --- CONTEÚDO PRINCIPAL --- */
.main-content { margin-left: 280px; padding: 2.5rem; position: relative; z-index: 1; }

.top-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 2.5rem; 
}

.header-text h2 { font-size: 1.8rem; font-weight: 600; }
.header-text p { color: var(--text-muted); }

.stat-item { 
    background: var(--white); 
    padding: 10px 20px; 
    border-radius: 50px; 
    box-shadow: var(--shadow); 
    font-weight: 500;
}

/* --- GRID DE MÁQUINAS --- */
.modern-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); 
    gap: 20px; 
}

.machine-card { 
    background: var(--white); 
    padding: 24px; 
    border-radius: 20px; 
    border: 1px solid #e2e8f0; 
    cursor: pointer; 
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.machine-card:hover { 
    transform: translateY(-5px); 
    border-color: var(--primary); 
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1); 
}

.slot-pills { display: flex; gap: 6px; margin-top: 15px; }
.pill { height: 8px; flex: 1; background: #f1f5f9; border-radius: 4px; }
.pill.filled { background: var(--success); box-shadow: 0 0 8px rgba(16, 185, 129, 0.3); }

/* --- INPUTS E BOTÕES --- */
.input-group { margin-bottom: 1.25rem; text-align: left; }
.input-group input, .admin-input { 
    width: 100%; 
    padding: 14px 18px; 
    border-radius: 14px; 
    border: 2px solid #f1f5f9; 
    background: #f8fafc; 
    outline: none; 
    transition: 0.3s;
    font-size: 0.95rem;
}

.input-group input:focus, .admin-input:focus { 
    border-color: var(--primary); 
    background: var(--white); 
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.btn-primary { 
    width: 100%; 
    padding: 14px; 
    border-radius: 14px; 
    border: none; 
    background: var(--primary); 
    color: var(--white); 
    font-weight: 600; 
    cursor: pointer; 
    transition: 0.3s;
    font-size: 1rem;
}

.btn-primary:hover { 
    background: var(--primary-hover); 
    box-shadow: 0 10px 15px -3px rgba(37, 99, 235, 0.4); 
}

/* --- MODAIS --- */
.modal-window { 
    background: var(--white); 
    border-radius: 28px; 
    padding: 30px; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 600px; /* Largura fixa para popups de máquina */
}

.slots-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 15px; 
    margin-top: 20px;
}

.slot-item { 
    border: 2px solid #f1f5f9; 
    padding: 18px; 
    border-radius: 18px; 
    background: #fcfcfd; 
    transition: 0.2s;
}

.slot-item.active { 
    border-color: var(--success); 
    background: #f0fdf4; 
}

/* --- ASSISTENTE IA (POPUP) --- */
.ai-box { 
    background: var(--white); 
    width: 440px; 
    border-radius: 28px; 
    overflow: hidden; 
    box-shadow: 0 30px 60px rgba(0,0,0,0.3);
}

.ai-header { 
    background: var(--dark-panel); 
    color: #38bdf8; 
    padding: 20px; 
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.ai-suggestion-box { 
    background: #f0f9ff; 
    padding: 20px; 
    border-radius: 16px; 
    border-left: 6px solid var(--primary); 
    margin-top: 15px;
    font-size: 0.9rem;
}

.btn-ai-confirm { 
    background: var(--success); 
    color: white; 
    border: none; 
    padding: 14px; 
    border-radius: 12px; 
    flex: 2; 
    cursor: pointer; 
    font-weight: 600; 
}

.btn-ai-ignore { 
    background: #94a3b8; 
    color: white; 
    border: none; 
    padding: 14px; 
    border-radius: 12px; 
    flex: 1; 
    cursor: pointer; 
}

.btn-exp{
    width: 45%; 
    padding: 4px; 
    border-radius: 12px; 
    border: none; 
    background: var(--primary); 
    color: var(--white); 
    font-weight: 600; 
    cursor: pointer; 
    transition: 0.3s;
    font-size: 1rem;
    margin-left: 5px;

}

/* Correção de Visibilidade dos Botões Master e Modais */
#adminAuthModal .btn-primary, 
#adminPanel .btn-primary,
.modal-window .btn-primary {
    display: block !important;
    visibility: visible !important;
    background-color: var(--dark-panel) !important; /* Cor escura para destacar */
    color: var(--white) !important;
    opacity: 1 !important;
    margin-top: 15px;
    margin-bottom: 15px;
    z-index: 5001;
    position: relative;
}

#adminAuthModal .btn-text,
#adminPanel .btn-text {
    color: var(--text-muted) !important;
    display: inline-block;
    width: 100%;
    text-align: center;
    padding: 10px;
    text-decoration: none;
}

/* Garante que o input da senha master não seja branco no branco */
.admin-input {
    color: var(--text-main) !important;
    border: 2px solid #e2e8f0 !important;
}

/* --- ESTILOS DA AGENDA IA NA SIDEBAR --- */
.ai-schedule-container {
    margin-top: 2rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 15px;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    max-height: 350px; /* Limita a altura para não quebrar o layout */
}

.schedule-title {
    font-size: 0.7rem;
    color: #38bdf8;
    font-weight: 700;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.schedule-list {
    overflow-y: auto;
    padding-right: 5px;
}

.schedule-day-group {
    margin-bottom: 15px;
    border-left: 2px solid rgba(56, 189, 248, 0.3);
    padding-left: 10px;
}

.day-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--white);
    display: block;
    margin-bottom: 4px;
}

.machine-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

/* --- ESTILOS DO STATUS DE MANUTENÇÃO NA SIDEBAR --- */
.maintenance-status-container {
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 15px;
    border: 1px dashed rgba(239, 68, 68, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 250px;
}

.m-tag {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Estado de Previsão no Grid */
.pill.preview {
    background: rgba(59, 130, 246, 0.3);
    border: 1px dashed var(--primary);
}

.machine-card.planned {
    border-style: dashed;
    background: #f0f7ff;
}

/* Estilos para os Slots e Pills */
.pill.preview { background-color: #e2e8f0; border: 1px dashed #cbd5e1; } /* Vazio planejado */
.pill.filled { background-color: #3b82f6; } /* Azul - Manual Incubado */

/* Novos estados visuais da IA */
.slot-item.ai-scheduled {
    background: linear-gradient(135deg, #fef08a 50%, #ffedd5 50%);
    border: 2px dashed #eab308 !important;
}

/* Badge de Antecipação */
.anticipation-badge {
    background-color: #dbeafe;
    color: #1e40af;
    font-size: 0.5rem;
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: bold;
    display: inline-block;
    margin-top: 2px;
}

/* Estilo para o Log da IA (opcional) */
#aiLog {
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.7rem;
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.machine-card.maintenance-mode {
    border: 2px dashed #ef4444 !important;
    background: rgba(239, 68, 68, 0.05) !important;
}
.maintenance-badge {
    background: #ef4444;
    color: white;
    font-size: 10px;
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: bold;
}

#aiSuggestionBanner {
    z-index: 500; 
}

#aiSuggestionBanner {
    position: fixed; /* Ou sticky */
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    z-index: 9999; /* Fica acima de tudo */
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    border-radius: 12px;
}

/* Força o modal de senha a ficar acima de qualquer outro modal (Log, Admin, etc) */
/* Modal de Senha (Sempre no topo de tudo) */
#passwordModal, #adminAuthModal {
    z-index: 3000 !important;
}

/* Garante que o fundo escuro do modal de senha também cubra o modal de log */
#passwordModal.modal-overlay {
    background: rgba(15, 23, 42, 0.85); /* Um pouco mais escuro para focar na senha */
}

.btn-text:active {
    transform: scale(0.98);
    background: #fee2e2;
}

/* Barra de rolagem customizada */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.modal-window, .modal-content {
    background: var(--white);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: popupIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Remova os estilos forçados que usam !important nos botões e use isso: */

.modal-window .btn-primary {
    display: inline-flex; /* ou block, conforme seu design */
    align-items: center;
    justify-content: center;
    width: 100%;
    background-color: var(--dark-panel);
    color: var(--white);
    padding: 12px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
}

.modal-window .btn-primary:hover {
    filter: brightness(1.2);
}

/* O overlay (fundo escuro que cobre a tela toda) */
#advancedConfigModal {
    position: fixed;   /* Fixa na tela, independente do scroll */
    inset: 0;          /* Atalho para top:0, left:0, right:0, bottom:0 */
    background-color: rgba(0, 0, 0, 0.5); /* Fundo escuro semi-transparente */
    display: flex;     /* Ativa o flexbox */
    align-items: center;    /* Centraliza verticalmente */
    justify-content: center; /* Centraliza horizontalmente */
    z-index: 9999;     /* Garante que fique em cima de tudo */
}

/* O conteúdo interno do modal */
#advancedConfigModal .modal-content {
    background: white;
    padding: 0;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 90vh;  /* Não deixa o modal ser maior que a tela */
    overflow-y: auto;  /* Se o conteúdo for grande, cria scroll interno */
    position: relative;
}

/* Garante que quando estiver escondido, ele realmente suma */
#advancedConfigModal.hidden {
    display: none !important;
}