/* =========================================
   layout.css - Estrutura Global Padrão
   ========================================= */

:root {
    --bg-dark: #0d1117;
    --bg-sidebar: #161b22;
    --accent-blue: #007bff;
    --text-main: #ffffff;
    --text-muted: #8b949e;
    --border-color: #30363d;
}

/* Configurações Gerais */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Poppins', sans-serif; }

body.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- SIDEBAR (BARRA LATERAL) --- */
.sidebar {
    width: 240px;
    height: 100dvh; /* Usa a altura total da viewport, incluindo a barra de endereço móvel */
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    transition: width 0.3s ease, transform 0.3s ease;
    z-index: 1000;
}

.sidebar-header {
    padding: 30px;
    padding-right: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent-blue);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: -25px;
}

.sidebar-nav {
    flex: 1;
    padding: 10px 15px;
    overflow-y: auto; 
}

.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 8px 12px; 
    border-radius: 8px;
    margin-bottom: 2px;
    transition: 0.3s;
    font-size: 16px; 
}

.sidebar-nav a i { width: 20px; text-align: center; font-size: 18px; }
.sidebar-nav a:hover, .sidebar-nav a.active { background-color: var(--accent-blue); color: white; }

.nav-divider {
    font-size: 11px;
    color: var(--accent-blue);
    margin: 20px 0 10px 15px;
    letter-spacing: 1px;
    font-weight: 700;
}

.sidebar-nav a.disabled { opacity: 0.3; cursor: not-allowed; }

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
    margin-top: auto;
}

#logout-button {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    background: transparent;
    border: 1px solid #ff4d4d;
    color: #ff4d4d;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

#logout-button:hover { background: #ff4d4d; color: white; }

/* Adiciona transição suave para os textos da sidebar */
.sidebar-header span,
.sidebar-nav a span,
.nav-divider,
.sidebar-footer span {
    transition: opacity 0.2s ease, visibility 0.2s ease, width 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
}

/* Lógica da Sidebar Encolhida - Corrigida */
.sidebar.collapsed { width: 80px; overflow: visible !important; }

.sidebar.collapsed .sidebar-header span,
.sidebar.collapsed .sidebar-nav a span,
.sidebar.collapsed .nav-divider,
.sidebar.collapsed .sidebar-footer span { 
    opacity: 0; 
    visibility: hidden; 
    width: 0;
    height: 0;        /* <--- Remove a altura fantasma */
    line-height: 0;   /* <--- Remove o espaço da linha de texto */
    margin: 0; 
    padding: 0;
}

.sidebar.collapsed .sidebar-nav a,
.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .sidebar-footer button { 
    justify-content: center !important; 
    padding: 15px 0 !important; 
    margin: 0 !important; 
    gap: 2px !important; /* <--- ESSA LINHA RESOLVE O PROBLEMA DO ÍCONE DESCENTRALIZADO */
}
.sidebar.collapsed .sidebar-nav a i,
.sidebar.collapsed .sidebar-header i,
.sidebar.collapsed .sidebar-footer i { margin: 0 !important; font-size: 20px; }
.sidebar.collapsed .sidebar-footer { padding: 5px; }
.sidebar.collapsed #logout-button { width: 100%; padding: 10px 0; border: none; background: transparent; }
.sidebar.collapsed .sidebar-nav a.active {
    background-color: var(--accent-blue) !important;
    width: 45px; height: 45px;      
    margin: 10px auto !important;
    display: flex; align-items: center; justify-content: center;
    padding: 0 !important; border-radius: 8px;
}
.sidebar.collapsed .sidebar-nav a.active i { color: white !important; font-size: 18px !important; margin: 0 !important; }

/* --- CONTEÚDO PRINCIPAL (HEADER) --- */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 20px 40px;
    width: calc(100% - 240px);
    min-width: 0;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease, width 0.3s ease;
}

.sidebar.collapsed ~ .main-content { margin-left: 80px; width: calc(100% - 80px); }

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center; 
    height: 70px; 
    border-bottom: 1px solid var(--border-color); 
    margin-bottom: 30px;
    padding-bottom: 10px;
}

.top-header h1 { font-size: 1.6rem; font-weight: 700; margin: 0; }

.user-profile {
    display: flex;
    flex-direction: row-reverse; 
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 45px; height: 45px;
    background-color: var(--accent-blue); color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600; overflow: hidden;
    border: 2px solid var(--border-color);
}

/* =========================================
   TOOLTIP GLOBAL (GERADO VIA JS)
   ========================================= */
.custom-tooltip {
    position: fixed; /* Fica fixo na tela, imune à barra lateral */
    background-color: var(--bg-sidebar);
    color: white;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 13px;
    font-weight: 600;
    pointer-events: none; /* O mouse passa direto por ele */
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%);
    transition: opacity 0.2s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.custom-tooltip.show {
    opacity: 1;
    visibility: visible;
}

/* Setinha do Tooltip */
.custom-tooltip::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px 6px 6px 0;
    border-style: solid;
    border-color: transparent var(--border-color) transparent transparent;
}

/* Responsividade Base (Menu e Header) */
#toggle-sidebar { display: none; }

@media (min-width: 769px) { .mobile-only { display: none !important; } }
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0 !important; width: 100% !important; padding: 15px !important; padding-top: 10px !important; }
    .top-header { height: auto; padding-bottom: 15px; margin-bottom: 20px; gap: 10px; }
    .top-header h1 { font-size: 1.3rem; white-space: nowrap; }
    .user-profile { margin-left: auto !important; }
    #admin-name { display: none; }
    #toggle-sidebar { display: block !important; background: transparent; border: none; color: white; font-size: 1.5rem; cursor: pointer; }
    
    /* === OVERLAY ESCURO (FUNDO DO MENU) === */
    /* O overlay sempre existe, mas fica invisível e intocável por padrão */
    .main-content::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.7); 
        z-index: 999; 
        backdrop-filter: blur(3px); 
        opacity: 0;
        visibility: hidden;
        pointer-events: none; /* Permite clicar nos elementos atrás dele quando invisível */
        transition: opacity 0.3s ease, visibility 0.3s ease; /* Transição de entrada e saída */
    }

    /* Quando o menu abre, o overlay fica visível */
    .sidebar.open ~ .main-content::before {
        opacity: 1;
        visibility: visible;
        pointer-events: auto; /* Habilita o clique para fechar o menu */
        cursor: pointer;
    }
}