/* css/layout.css */
#app {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--pdt-blue-950);
    color: var(--text-inverted);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition-speed) ease, width var(--transition-speed) ease;
    z-index: 40;
    box-shadow: var(--shadow-lg);
}

/* Collapsed State */
.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .sidebar-logo,
.sidebar.collapsed .nav-text,
.sidebar.collapsed .nav-chevron,
.sidebar.collapsed .nav-submenu,
.sidebar.collapsed #btn-logout,
.sidebar.collapsed .user-info {
    display: none !important;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 1.5rem 0.5rem;
}

.sidebar.collapsed .logo {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-nav {
    padding: 1rem 0.5rem;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 0.75rem;
}

.sidebar.collapsed .nav-item i {
    font-size: 1.5rem;
    margin: 0;
}

.sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: 1rem 0.5rem;
}

/* Sidebar Header Layout */
.sidebar-header {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo {
    height: 36px;
    width: auto;
    object-fit: contain;
    /* Filtrar logo para ficar branca ou adicionar cor, mas como a logo fornecida já tem suas próprias cores e o fundo é azul escuro var(--pdt-blue-950), podemos deixá-la normal, ou talvez adicionar um fundo branco transparente se houver problema de contraste. Por ora, assumimos que as cores da logo ficam boas. */
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding: 1.5rem 1rem;
}

.sidebar-nav ul {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
    color: var(--text-secondary);
    /* Cinza claro na sidebar escura */
    color: #94a3b8;
    font-weight: 500;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.nav-item.external-link {
    padding: 0;
}

.nav-item.external-link a {
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius-md);
}

.nav-item.external-link a:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--surface-white);
}

.nav-divider {
    height: 1px;
    background-color: rgba(255, 255, 255, 0.1);
    margin: 1rem 0;
}

.nav-item i {
    font-size: 1.25rem;
}

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--surface-white);
}

.nav-item.active {
    background-color: var(--pdt-red-600);
    color: var(--surface-white);
    box-shadow: var(--glow-red);
}

/* ── Submenu hover ─────────────────────────────────── */
.nav-item-parent {
    /* estilizacao movida para inline e containers flex em app.js para fix do Chrome/Safari */
}

.nav-chevron {
    margin-left: auto;
    font-size: 0.8rem;
    transition: transform 0.2s ease;
    opacity: 0.6;
}

.nav-submenu {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0 0 0 1.8rem;
    border-left: 2px solid rgba(255, 255, 255, 0.15);
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.35s ease-in-out, opacity 0.35s ease-in-out, padding 0.35s ease-in-out, margin 0.35s ease-in-out;
}

.nav-item-parent.open .nav-submenu {
    max-height: 800px;
    opacity: 1;
    margin-top: 0.25rem;
    margin-bottom: 0.25rem;
}

.nav-item-parent.open .nav-chevron {
    transform: rotate(90deg);
}

.nav-subitem {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--border-radius-sm);
    color: #94a3b8;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.nav-subitem i {
    font-size: 1.05rem;
    flex-shrink: 0;
}

.nav-subitem:hover {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
}

.nav-subitem.active {
    background: var(--pdt-red-600);
    color: #fff;
}



/* Sidebar Footer / User Profile */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--pdt-blue-800);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--surface-white);
    border: 2px solid var(--pdt-red-500);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info .name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--surface-white);
}

.user-info .role {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Important for flex children truncation */
    background-color: var(--bg-main);
}

/* Desktop Topbar defaults to standard display */
.desktop-topbar {
    display: flex;
}

/* Mobile Topbar hidden on Desktop */
.mobile-topbar {
    display: none;
}

/* Mobile Bottom Bar hidden on Desktop */
.mobile-bottom-bar {
    display: none;
}

.topbar {
    height: var(--header-height);
    background-color: var(--surface-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    z-index: 30;
    position: sticky;
    top: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.header-logos {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-right: 1rem;
    border-right: 1px solid var(--border-light);
}

.header-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
}

/* Visibilidade das logos por tema */
.logo-dark-only {
    display: none;
}

[data-theme="dark"] .logo-light-only {
    display: none;
}

[data-theme="dark"] .logo-dark-only {
    display: block;
}

/* Invert Only the PDT logo in dark mode for contrast since it's black text */
[data-theme="dark"] .logo-dark-sensitive {
    filter: brightness(0) invert(1);
}

.page-title h1 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border-light);
}

.header-user-info {
    display: flex;
    flex-direction: column;
}

.header-user-info .name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.header-user-info .location {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.header-avatar {
    width: 36px;
    height: 36px;
}

/* Content Views Container */
.view-container {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

/* Responsive constraints */
.mobile-only {
    display: none;
}

/* Base styles for mobile elements that should be hidden on desktop */
.mobile-topbar,
.mobile-bottom-bar,
.mobile-menu-overlay {
    display: none;
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        transform: translateX(-100%);
        z-index: 1050;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Overlay escuro atrás do sidebar aberto (visual only; cliques caem para o documento) */
    .sidebar.open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: -1;
        pointer-events: none;
    }

    .mobile-only {
        display: flex;
    }

    .desktop-topbar {
        display: none !important;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: var(--pdt-blue-900);
        padding: 0.8rem 1.25rem;
        border-bottom: 4px solid var(--pdt-red-500);
        position: sticky;
        top: 0;
        z-index: 40;
    }

    .mobile-topbar-title {
        color: white;
        font-weight: 800;
        font-size: 1.15rem;
        letter-spacing: 0.5px;
        font-family: 'Montserrat', sans-serif;
    }

    .mobile-bottom-bar {
        display: flex;
        background-color: var(--pdt-blue-900);
        color: white;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 70px;
        padding: 0 1rem;
        align-items: center;
        justify-content: space-between;
        z-index: 1000;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
    }

    .mobile-footer-info {
        display: flex;
        flex-direction: column;
        justify-content: center;
        max-width: 65%;
        /* Leave room for FAB */
    }

    .mobile-name {
        font-weight: 700;
        font-size: 1.05rem;
        margin-bottom: 0.15rem;
        font-family: 'Montserrat', sans-serif;
    }

    .mobile-role {
        font-size: 0.70rem;
        color: rgba(255, 255, 255, 0.85);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-fab {
        background-color: var(--pdt-red-600);
        color: white;
        width: 64px;
        height: 64px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 4px solid var(--bg-main);
        position: absolute;
        right: 1.25rem;
        bottom: 12px;
        box-shadow: 0 4px 10px rgba(220, 38, 38, 0.4);
        font-size: 1.75rem;
        cursor: pointer;
        transition: transform 0.2s ease, background-color 0.2s ease;
    }

    .mobile-fab:active {
        transform: scale(0.95);
        background-color: var(--pdt-red-700);
    }

    .view-container {
        padding: 1rem;
        padding-bottom: 85px !important;
        /* Make room for the bottom bar so content doesn't hide */
    }

    /* Mobile Bottom Sheet Menu */
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-menu-overlay.active {
        display: block;
        opacity: 1;
    }

    .mobile-menu-sheet {
        position: absolute;
        bottom: -100%;
        left: 0;
        right: 0;
        background: var(--bg-main);
        border-radius: 24px 24px 0 0;
        box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
        transition: bottom 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.1);
        display: flex;
        flex-direction: column;
        max-height: calc(85vh - 70px);
        padding-bottom: 1rem;
    }

    .mobile-menu-overlay.active .mobile-menu-sheet {
        bottom: 70px;
    }

    .mobile-menu-content {
        padding: 1.5rem;
        overflow-y: auto;
    }

    .mobile-menu-content .nav-item {
        margin-bottom: 0.5rem;
        padding: 1rem;
        border-radius: var(--border-radius-md);
        background: var(--surface-glass);
        color: var(--text-primary);
        font-weight: 600;
        font-size: 1.05rem;
    }

    .mobile-menu-content .nav-item.active {
        background: rgba(220, 38, 38, 0.1);
        color: var(--pdt-red-600);
        border-left: 4px solid var(--pdt-red-500);
    }

    .mobile-menu-content .nav-subitem {
        color: var(--text-secondary);
        font-size: 0.95rem;
        padding: 0.75rem 1rem;
    }

    /* Certificates Mobile View Tweaks */
    .cert-mobile-header {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 1.25rem !important;
    }

    .cert-mobile-header .section-title {
        border-bottom: 0 !important;
        margin-bottom: 0.5rem !important;
    }

    .cert-mobile-header .actions {
        flex-direction: column !important;
        width: 100% !important;
    }
}