/* ==========================================================================
   UX — Menu lateral retrátil (rail + hover + logo-botão) v4
   ========================================================================== */

:root {
    --sidebar-width: 280px;
    --sidebar-rail: 72px;
    --sidebar-transition: 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

#appLayout {
    position: relative;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex-shrink: 0;
    transition:
        width var(--sidebar-transition),
        min-width var(--sidebar-transition),
        box-shadow var(--sidebar-transition),
        opacity var(--sidebar-transition),
        transform var(--sidebar-transition);
    will-change: width, transform;
    overflow: hidden;
}

/* —— Desktop: recolhido = trilho com logo —— */
@media (min-width: 1025px) {
    #appLayout.sidebar-retracted .sidebar {
        width: var(--sidebar-rail);
        min-width: var(--sidebar-rail);
        opacity: 1;
        pointer-events: auto;
        border-right-color: var(--border-card, rgba(255, 255, 255, 0.08));
        overflow: hidden;
    }

    /* Hover (ou flyout via JS): abre o menu completo */
    #appLayout.sidebar-retracted .sidebar:hover,
    #appLayout.sidebar-retracted.sidebar-flyout .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        z-index: 130;
        box-shadow: 10px 0 40px rgba(0, 0, 0, 0.35);
        overflow-x: hidden;
        overflow-y: auto;
    }

    /* No trilho: logo + ícones; texto some até o hover */
    #appLayout.sidebar-retracted .sidebar:not(:hover) .sidebar-brand,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .sidebar-brand,
    #appLayout.sidebar-retracted .sidebar:not(:hover) .sidebar-kicker,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .sidebar-kicker {
        opacity: 0;
        height: 0;
        margin: 0;
        overflow: hidden;
        pointer-events: none;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) #sidebarMenu,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) #sidebarMenu {
        opacity: 1;
        max-height: none;
        overflow: visible;
        pointer-events: auto;
        padding: 4px 0 12px;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .nav-title,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .nav-title,
    #appLayout.sidebar-retracted .sidebar:not(:hover) .nav-label,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .nav-label,
    #appLayout.sidebar-retracted .sidebar:not(:hover) .co-menu-group__title,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .co-menu-group__title {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .nav-item,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .nav-item {
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 2px 8px;
        padding: 10px 0;
        min-height: 40px;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .nav-icon,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .nav-icon {
        margin: 0;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .co-menu-group:not([open]),
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .co-menu-group:not([open]) {
        display: none;
    }

    #appLayout.sidebar-retracted .sidebar:hover #sidebarMenu,
    #appLayout.sidebar-retracted.sidebar-flyout .sidebar #sidebarMenu {
        opacity: 1;
        max-height: none;
        pointer-events: auto;
    }

    #appLayout.sidebar-retracted .sidebar:hover .sidebar-brand,
    #appLayout.sidebar-retracted .sidebar:hover .sidebar-kicker,
    #appLayout.sidebar-retracted.sidebar-flyout .sidebar .sidebar-brand,
    #appLayout.sidebar-retracted.sidebar-flyout .sidebar .sidebar-kicker {
        opacity: 1;
        height: auto;
        pointer-events: auto;
    }

    #appLayout.sidebar-retracted .sidebar-header {
        min-height: 64px;
        padding: 12px 0;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .sidebar-logo-wrap .voe-brand-logo,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .sidebar-logo-btn img {
        height: 40px;
        max-width: 44px;
        margin-left: auto;
        margin-right: auto;
    }
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 14, 0.45);
    z-index: 95;
    opacity: 0;
    transition: opacity var(--sidebar-transition);
}

#appLayout.sidebar-mobile-open .sidebar-backdrop {
    display: block;
    opacity: 1;
}

/* — Logo como botão — */
.sidebar-logo-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    padding: 0;
    margin: 0 auto;
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    transition:
        border-color 0.22s ease,
        background 0.22s ease,
        transform 0.22s ease,
        box-shadow 0.22s ease;
}

.sidebar-logo-btn:hover {
    border-color: rgba(212, 174, 87, 0.45);
    background: rgba(212, 174, 87, 0.08);
    box-shadow: 0 0 0 1px rgba(212, 174, 87, 0.12);
    transform: translateY(-1px);
}

.sidebar-logo-btn:focus-visible {
    outline: 2px solid rgba(212, 174, 87, 0.55);
    outline-offset: 2px;
}

.sidebar-logo-btn img,
.sidebar-logo-wrap .voe-brand-logo {
    width: auto;
    height: 40px;
    max-width: 44px;
    object-fit: contain;
    object-position: center;
    display: block;
    margin: 0 auto;
    pointer-events: none;
}

.sidebar-logo-wrap {
    width: 100%;
    margin-bottom: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Header da sidebar sempre centralizado (Hangar / Torre / AM) */
.sidebar-header {
    display: flex !important;
    flex-direction: column;
    align-items: center !important;
    justify-content: center;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

.sidebar-header .sidebar-brand,
.sidebar-header .sidebar-kicker {
    text-align: center;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

/* Trilho recolhido: logo exatamente no centro do rail */
@media (min-width: 1025px) {
    #appLayout.sidebar-retracted .sidebar-header {
        min-height: 64px;
        padding: 12px 0 !important;
        align-items: center !important;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .sidebar-logo-wrap,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .sidebar-logo-wrap {
        width: 100%;
        justify-content: center;
        align-items: center;
    }

    #appLayout.sidebar-retracted .sidebar:not(:hover) .sidebar-logo-btn,
    #appLayout.sidebar-retracted:not(.sidebar-flyout) .sidebar:not(:hover) .sidebar-logo-btn {
        margin: 0 auto;
    }
}

/* Hangar (piloto): reforço — evita drift à esquerda do brasão */
body.theme-time .sidebar-header,
body.co-calm[data-co-role="Time"] .sidebar-header {
    align-items: center !important;
    text-align: center;
}

body.theme-time .sidebar-logo-wrap,
body.co-calm[data-co-role="Time"] .sidebar-logo-wrap {
    width: 100%;
    justify-content: center;
}

/* — Topbar: logo-botão no lugar do ☰ — */
.topbar-left {
    flex: 1;
    min-width: 0;
}

.btn-sidebar-toggle {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border-card);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    flex-shrink: 0;
    padding: 0;
    transition: var(--transicao);
}

.btn-sidebar-toggle:hover {
    border-color: rgba(212, 174, 87, 0.5);
    background: rgba(212, 174, 87, 0.1);
    color: var(--accent, #d4ae57);
}

.btn-sidebar-toggle.is-logo {
    border-color: rgba(212, 174, 87, 0.22);
    background: rgba(212, 174, 87, 0.06);
}

.btn-sidebar-toggle.is-logo img {
    display: none !important;
}

.sidebar-toggle-bars,
.sidebar-toggle-bars::before,
.sidebar-toggle-bars::after {
    display: block;
    width: 16px;
    height: 1.5px;
    background: currentColor;
    border-radius: 2px;
}

.sidebar-toggle-bars {
    position: relative;
}

.sidebar-toggle-bars::before,
.sidebar-toggle-bars::after {
    content: "";
    position: absolute;
    left: 0;
}

.sidebar-toggle-bars::before { top: -5px; }
.sidebar-toggle-bars::after { top: 5px; }

.topbar-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
    min-width: 0;
}

.voe-brand-logo,
.topbar-logo {
    width: auto;
    height: 44px;
    max-width: 52px;
    object-fit: contain;
    object-position: center;
    flex-shrink: 0;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.topbar-brand-text {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--text-main);
    white-space: nowrap;
}

.login-logo-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-bottom: 12px;
}

.login-logo-wrap .voe-brand-logo {
    width: auto;
    height: 112px;
    max-width: 140px;
    margin: 0 auto;
    object-fit: contain;
    object-position: center;
}

body.org-has-logo .topbar-brand-text,
body.org-has-logo .sidebar-brand {
    font-size: 0.85em;
}

body.light-mode .btn-sidebar-toggle:not(.hud-knob) {
    background: #fff;
    border-color: rgba(12, 43, 91, 0.12);
    color: var(--azul);
}

body.light-mode .btn-sidebar-toggle:hover {
    background: rgba(12, 43, 91, 0.05);
    border-color: var(--azul);
}

body.light-mode .topbar-brand-text {
    color: var(--azul);
}

.org-brand-logo--topbar {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

/* Compat: menu-premium rail + hover (sobrescreve width:0 antigo) */
@media (min-width: 1025px) {
    body.menu-premium-active #appLayout.sidebar-retracted .sidebar {
        width: var(--sidebar-rail);
        min-width: var(--sidebar-rail);
        overflow: hidden;
        opacity: 1;
        pointer-events: auto;
    }

    body.menu-premium-active #appLayout.sidebar-retracted .sidebar:hover,
    body.menu-premium-active #appLayout.sidebar-retracted.sidebar-flyout .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        overflow-y: auto;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.25);
    }

    #appLayout.sidebar-retracted .sidebar {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        transform: translateX(-105%);
        opacity: 1;
        pointer-events: none;
    }

    #appLayout.sidebar-mobile-open .sidebar {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }

    .topbar-brand-text {
        display: none;
    }
}

@media (max-width: 640px) {
    .topbar {
        padding: 0 16px !important;
    }

    .topbar-route {
        font-size: 10px !important;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ouro, #d4ae57);
}

.nav-icon svg {
    width: 18px;
    height: 18px;
    display: block;
}

.nav-label {
    min-width: 0;
}

.co-menu-group__title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.co-menu-group__title .nav-icon {
    pointer-events: none;
}

