.app-shell {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--c-sidebar-bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width var(--transition);
}

/* Recolhida: só ícones, largura fixa pequena — estado opcional, alternado pelo botão em
   .sidebar-footer e persistido em localStorage (ver app.js). */
.sidebar.collapsed {
    width: var(--sidebar-width-collapsed);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-bottom: 3px solid var(--c-accent);
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-brand {
    padding: var(--space-md) var(--space-sm);
    justify-content: center;
}

.sidebar-brand img {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.sidebar-brand span {
    color: #fff;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: .5px;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-brand span {
    display: none;
}

.brand-version {
    font-size: 0.65rem;
    font-weight: 500;
    letter-spacing: normal;
    color: rgba(255, 255, 255, .55);
    vertical-align: middle;
}

/* Rodapé da sidebar — só o botão de recolher/expandir. Fica fora de .sidebar-nav
   (que é o flex:1 que rola) pra nunca se mover junto com a lista de páginas. */
.sidebar-footer {
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: var(--space-sm);
}

.sidebar-toggle {
    background: none;
    border: none;
    color: #fff;
    opacity: .65;
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: opacity var(--transition), background-color var(--transition), transform var(--transition);
}

.sidebar-toggle:hover {
    opacity: 1;
    background-color: var(--c-sidebar-bg-hover);
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: var(--space-sm) 0;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px var(--space-md);
    color: var(--c-sidebar-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background-color var(--transition), color var(--transition);
}

.nav-item:hover {
    background-color: var(--c-sidebar-bg-hover);
    color: #fff;
}

.nav-item.active {
    background-color: var(--c-sidebar-bg-hover);
    border-left-color: var(--c-sidebar-active);
    color: #fff;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: currentColor;
}

.nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
}

.sidebar.collapsed .nav-label {
    display: none;
}

/* --- Main content --- */
.main-content {
    flex: 1;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    background-color: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
}

#topbar-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--c-text-primary);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    font-size: 0.85rem;
    color: var(--c-text-secondary);
}

/* ---------- Alternador de tema claro/escuro ---------- */
.theme-toggle {
    background: none;
    border: 1px solid var(--c-border);
    color: var(--c-text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}

.theme-toggle:hover {
    background-color: var(--c-surface-alt);
    color: var(--c-accent);
}

/* Só um ícone por vez — sol no tema claro (convida a trocar pro escuro), lua no escuro. */
.theme-icon-dark { display: none; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
:root[data-theme="dark"] .theme-icon-dark { display: block; }

/* ---------- Sino de notificações (topbar) ---------- */
.notif-bell-wrap { position: relative; }

.notif-bell {
    background: none;
    border: 1px solid var(--c-border);
    color: var(--c-text-secondary);
    cursor: pointer;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition), color var(--transition), border-color var(--transition);
}
.notif-bell:hover { background-color: var(--c-surface-alt); color: var(--c-accent); }

.notif-badge {
    display: none;
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 999px;
    background: var(--c-danger);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}
.notif-badge.show { display: block; }

.notif-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 360px;
    max-width: 90vw;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 500;
    overflow: hidden;
}
.notif-dropdown.open { display: flex; flex-direction: column; }

.notif-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--c-text-primary);
}
.notif-dropdown-header button {
    background: none;
    border: none;
    color: var(--c-accent);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
}
.notif-dropdown-header button:hover { text-decoration: underline; }

.notif-dropdown-list {
    max-height: 360px;
    overflow-y: auto;
}

.notif-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--c-text-muted);
    font-size: 0.85rem;
}

.notif-item {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    cursor: pointer;
    transition: background-color var(--transition);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background-color: var(--c-surface-alt); }

.notif-item-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--c-accent);
    margin-top: 5px;
}
.notif-item.lida .notif-item-dot { background: transparent; }

.notif-item-body { min-width: 0; flex: 1; }
.notif-item-titulo {
    font-size: 0.83rem;
    color: var(--c-text-primary);
    font-weight: 600;
}
.notif-item.lida .notif-item-titulo { font-weight: 500; color: var(--c-text-secondary); }
.notif-item-mensagem {
    font-size: 0.78rem;
    color: var(--c-text-secondary);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.notif-item-meta {
    font-size: 0.7rem;
    color: var(--c-text-muted);
    margin-top: 4px;
}

.notif-dropdown-footer {
    padding: 8px 14px;
    text-align: center;
    border-top: 1px solid var(--c-border);
}
.notif-dropdown-footer a {
    font-size: 0.8rem;
    color: var(--c-accent);
    text-decoration: none;
}
.notif-dropdown-footer a:hover { text-decoration: underline; }

/* ---------- Menu de usuário (avatar + nome/nível + dropdown) ---------- */
.user-menu {
    position: relative;
}

.user-menu-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: var(--radius-md);
    transition: background-color var(--transition);
}

.user-menu-trigger:hover,
.user-menu-trigger.open {
    background-color: var(--c-surface-alt);
}

.user-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background-color: var(--c-accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.25;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--c-text-primary);
}

.user-nivel {
    font-size: 0.72rem;
    color: var(--c-text-muted);
}

.user-menu-caret {
    flex-shrink: 0;
    color: var(--c-text-muted);
    transition: transform var(--transition);
}

.user-menu-trigger.open .user-menu-caret {
    transform: rotate(180deg);
}

.user-menu-dropdown {
    display: none;
    flex-direction: column;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 190px;
    background-color: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 6px;
    z-index: 50;
}

.user-menu-dropdown.open {
    display: flex;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    background: none;
    border: none;
    text-align: left;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    color: var(--c-text-secondary);
    cursor: pointer;
}

.user-menu-item:hover {
    background-color: var(--c-surface-alt);
    color: var(--c-text-primary);
}

.user-menu-item-danger:hover {
    background-color: var(--c-danger-light);
    color: var(--c-danger);
}

.grupo-global-label {
    color: var(--c-text-muted);
}

#grupo-global-select {
    padding: 5px 8px;
    border: 1px solid var(--c-border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    background-color: var(--c-surface);
    color: var(--c-text-primary);
}

#page-content {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Topo igualado à mesma medida das laterais/base (2026-07-13, pedido do usuário) — antes
       era var(--space-lg) (24px) em cima contra 5px dos outros 3 lados, um espaço bem maior
       que o resto entre o header geral e o conteúdo do módulo. */
    padding: 5px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--c-text-muted);
}

/* ══════════════════════════════════════════
   RODAPÉ DO SISTEMA
══════════════════════════════════════════ */
.app-footer {
    flex-shrink: 0;
    padding: 3px var(--space-xl);
    font-size: 0.72rem;
    color: var(--c-text-muted);
    opacity: 0.7;
    text-align: center;
    border-top: 1px solid var(--c-border);
    background: var(--c-bg);
    transition: opacity var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-footer:hover { opacity: 1; }

.app-footer a {
    color: var(--c-text-muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.app-footer a:hover {
    color: var(--c-accent);
    text-decoration: underline;
}

/* Compactação para telas menores (padrão herdado da v1) */
@media (max-width: 1400px) {
    #page-content { padding: 3px; }
    #topbar-title { font-size: 1rem; }
    .app-footer { padding: 3px var(--space-md); font-size: 0.65rem; }
}

@media (max-width: 1100px) {
    :root { --sidebar-width: 200px; }
    #page-content { padding: 2px; }
    .app-footer { padding: 1px var(--space-md); font-size: 0.56rem; }
}
