/* =====================================================
   Admin v3 — Shell layout
   Sidebar + topbar + bottom-nav + main content area.
   ===================================================== */

/* Layout shell (mobile-first): single column, content full-width.
   Sidebar fica fora do fluxo no mobile (drawer). */
.shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    background: var(--bg-app);
    color: var(--text);
}

.shell-main {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.shell-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: var(--s-4);
    /* espaço para o bottom-nav no mobile */
    padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom) + var(--s-4));
}

@media (min-width: 768px) {
    .shell-content {
        padding: var(--s-6);
        padding-bottom: var(--s-6);
    }
}

@media (min-width: 1024px) {
    .shell-content {
        padding: var(--s-7) var(--s-7);
    }
}

/* Desktop: sidebar fixa (não rola com o conteúdo).
   Antes era grid + position: sticky. Trocado por position: fixed
   porque sticky pode falhar se algum ancestral introduzir overflow
   ou transform. Fixed é a abordagem mais robusta. */
@media (min-width: 1024px) {
    .shell {
        display: block;
    }
    .shell--collapsed {
        --sidebar-w: var(--sidebar-w-collapsed);
    }
    .shell-main {
        margin-left: var(--sidebar-w);
        transition: margin-left var(--t-base) var(--ease-out);
        min-height: 100dvh;
    }
}

/* =====================================================
   Sidebar
   ===================================================== */
.shell-sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* mobile: drawer fora da tela por padrão */
    position: fixed;
    inset: 0 auto 0 0;
    width: 84vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform var(--t-base) var(--ease-out);
    z-index: var(--z-overlay);
    box-shadow: var(--shadow-lg);
}

.shell-sidebar.is-mobile-open {
    transform: translateX(0);
}

@media (min-width: 1024px) {
    .shell-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        inset: auto;
        width: var(--sidebar-w);
        max-width: none;
        height: 100dvh;
        transform: none;
        box-shadow: none;
        z-index: var(--z-sticky);
        transition: width var(--t-base) var(--ease-out);
    }
}

.shell-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s-3);
    padding: var(--s-4);
    border-bottom: 1px solid var(--line);
    height: var(--topbar-h);
    flex-shrink: 0;
}

.shell-sidebar__brand-link {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    color: var(--text);
    text-decoration: none;
    flex: 1 1 auto;
    min-width: 0;
}

.shell-sidebar__logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: var(--r-sm);
}

.shell-sidebar__brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}

.shell-sidebar__brand-name {
    font-family: var(--font-display);
    font-weight: var(--fw-semibold);
    font-size: var(--text-md);
    letter-spacing: -0.01em;
}

.shell-sidebar__brand-sub {
    font-size: var(--text-2xs);
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* Botão de colapsar — só desktop */
.shell-sidebar__collapse {
    display: none;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: var(--r-sm);
    color: var(--text-mute);
    transition: background var(--t-fast) var(--ease-out);
    flex-shrink: 0;
}

.shell-sidebar__collapse:hover {
    background: var(--bg-hover);
    color: var(--text);
}

@media (min-width: 1024px) {
    .shell-sidebar__collapse {
        display: inline-flex;
    }
}

/* Modo colapsado: esconde texto */
.shell-sidebar.is-collapsed .shell-sidebar__brand-text {
    display: none;
}

.shell-sidebar.is-collapsed .shell-sidebar__brand {
    justify-content: center;
    padding-left: var(--s-2);
    padding-right: var(--s-2);
}

.shell-sidebar.is-collapsed .shell-sidebar__brand-link {
    flex: 0 0 auto;
}

/* Nav */
.shell-sidebar__nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--s-3) var(--s-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
}

.shell-sidebar__section {
    margin: var(--s-3) var(--s-3) var(--s-1);
    font-size: var(--text-2xs);
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: var(--fw-semibold);
}

/* Grupo: categoria clicável + seus sub-itens */
.shell-sidebar__group {
    display: flex;
    flex-direction: column;
    margin-top: var(--s-3);
}

/* Categoria clicável — visual de NavItem com peso semibold + caret indicando sub-itens */
.shell-sidebar__section--link {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    margin: 0 var(--s-2) 2px;
    border-radius: var(--r-md);
    color: var(--text);
    font-size: var(--text-sm);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    cursor: pointer;
    text-transform: none;
    letter-spacing: normal;
    min-height: 36px;
    position: relative;
    transition: background var(--t-fast) var(--ease-out),
                color var(--t-fast) var(--ease-out);
}

.shell-sidebar__section--link:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.shell-sidebar__section--link.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.shell-sidebar__section--link.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 2px;
    border-radius: 1px;
    background: var(--accent);
}

.shell-sidebar__section-caret {
    margin-left: auto;
    color: var(--text-faint);
    display: inline-flex;
    align-items: center;
}

/* Sub-itens: indentação + linha conectora à esquerda mostra agrupamento */
.shell-sidebar__subitems {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px var(--s-2) 0;
    padding-left: var(--s-4);
    border-left: 1px solid var(--line);
    position: relative;
}

/* Sub-itens dentro do grupo são levemente menores e mais discretos */
.shell-sidebar__subitems .shell-nav-item {
    font-size: var(--text-sm);
}

/* Sidebar colapsada: cancelar indentação e linha conectora; categoria centraliza */
.shell-sidebar.is-collapsed .shell-sidebar__group {
    margin-top: var(--s-3);
}

.shell-sidebar.is-collapsed .shell-sidebar__section--link {
    justify-content: center;
    padding: var(--s-2);
    margin: 0 var(--s-1);
}

.shell-sidebar.is-collapsed .shell-sidebar__subitems {
    margin: 2px var(--s-1) 0;
    padding-left: 0;
    border-left: none;
}

.shell-sidebar.is-collapsed .shell-sidebar__section {
    text-align: center;
    margin-left: 0;
    margin-right: 0;
    padding-top: var(--s-2);
}

/* Nav item — usado por Sidebar (esses estilos cobrem desktop, sidebar-collapsed e mobile-open) */
.shell-nav-item {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    padding: var(--s-2) var(--s-3);
    border-radius: var(--r-md);
    color: var(--text-mute);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    text-decoration: none;
    min-height: 44px; /* hit target mobile */
    transition: background var(--t-fast) var(--ease-out),
                color var(--t-fast) var(--ease-out);
    position: relative;
}

.shell-nav-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.shell-nav-item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.shell-nav-item.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 2px;
    border-radius: 1px;
    background: var(--accent);
}

.shell-nav-item__icon {
    display: inline-flex;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
}

.shell-nav-item__label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shell-nav-item__badge {
    font-size: var(--text-2xs);
    color: var(--text-mute);
    background: var(--bg-active);
    padding: 1px var(--s-2);
    border-radius: var(--r-pill);
}

/* Sidebar colapsada: alinhar ícone centro, esconder label */
.shell-sidebar.is-collapsed .shell-nav-item {
    justify-content: center;
    padding-left: var(--s-2);
    padding-right: var(--s-2);
}

.shell-sidebar.is-collapsed .shell-nav-item__label,
.shell-sidebar.is-collapsed .shell-nav-item__badge {
    display: none;
}

@media (min-width: 1024px) {
    /* Hit target desktop pode ser menor */
    .shell-nav-item {
        min-height: 36px;
    }
}

/* Backdrop mobile */
.shell-mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(20, 16, 12, 0.4);
    backdrop-filter: blur(2px);
    z-index: calc(var(--z-overlay) - 1);
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--t-fast) var(--ease-out);
}

.shell-mobile-backdrop.is-visible {
    display: block;
    opacity: 1;
}

@media (min-width: 1024px) {
    .shell-mobile-backdrop {
        display: none !important;
    }
}

/* =====================================================
   Topbar
   ===================================================== */
.shell-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--s-3);
    height: var(--topbar-h);
    padding: 0 var(--s-4);
    background: var(--bg-topbar);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}

@media (min-width: 768px) {
    .shell-topbar {
        padding: 0 var(--s-6);
    }
}

.shell-topbar__title {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    font-size: var(--text-sm);
    font-weight: var(--fw-medium);
    min-width: 0;
}

.shell-topbar__crumb,
.shell-topbar__sep {
    color: var(--text-mute);
}

.shell-topbar__page {
    color: var(--text);
    font-weight: var(--fw-semibold);
}

/* Hambúrguer mobile-only — explícito porque .shell-icon-btn
   sobrescreve .show-mobile (mesma especificidade, vindo depois). */
.shell-topbar__menu {
    display: none;
    margin-right: var(--s-1);
}

@media (max-width: 767px) {
    .shell-topbar__menu {
        display: inline-flex;
    }
}

.shell-topbar__search {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: var(--s-2);
    padding: 0 var(--s-3);
    height: 36px;
    max-width: 360px;
    background: var(--bg-raised);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    color: var(--text-mute);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: border-color var(--t-fast) var(--ease-out),
                background var(--t-fast) var(--ease-out);
}

.shell-topbar__search:hover {
    border-color: var(--line-strong);
    background: var(--bg-surface);
}

.shell-topbar__search-text {
    flex: 1 1 auto;
    text-align: left;
    color: var(--text-mute);
    font-family: var(--font-ui);
}

.shell-topbar__kbd {
    background: var(--bg-active);
    color: var(--text-mute);
    padding: 1px var(--s-2);
    border-radius: var(--r-xs);
    font-size: var(--text-2xs);
    font-weight: var(--fw-semibold);
}

@media (min-width: 1024px) {
    .shell-topbar__search {
        margin: 0 auto;
    }
}

.shell-topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--s-1);
    margin-left: auto;
}

@media (min-width: 1024px) {
    .shell-topbar__actions {
        margin-left: 0;
    }
}

.shell-topbar__avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--r-pill);
    background: var(--accent);
    color: var(--accent-fg);
    font-family: var(--font-display);
    font-size: var(--text-xs);
    font-weight: var(--fw-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: var(--s-2);
    flex-shrink: 0;
}

/* Botão de ícone genérico do topbar/shell */
.shell-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    color: var(--text-mute);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t-fast) var(--ease-out),
                color var(--t-fast) var(--ease-out);
    flex-shrink: 0;
}

.shell-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

@media (max-width: 767px) {
    .shell-icon-btn {
        width: 44px;
        height: 44px;
    }
}

/* =====================================================
   Bottom-nav (mobile + phablet)
   ===================================================== */
.shell-bottomnav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--bg-surface);
    border-top: 1px solid var(--line);
    z-index: var(--z-sticky);
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.06);
}

@media (max-width: 767px) {
    .shell-bottomnav {
        display: flex;
    }
}

.shell-bottomnav__item {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-mute);
    text-decoration: none;
    font-size: var(--text-2xs);
    font-weight: var(--fw-medium);
    min-height: 44px;
    padding: var(--s-1) var(--s-1);
    transition: color var(--t-fast) var(--ease-out);
}

.shell-bottomnav__item.is-active {
    color: var(--accent);
}

.shell-bottomnav__item.is-active svg {
    stroke-width: 2.2;
}

/* Landscape mobile (max-height: 500px): bottom-nav vira top-nav compacto */
@media (orientation: landscape) and (max-height: 500px) {
    .shell-bottomnav {
        position: sticky;
        top: var(--topbar-h);
        bottom: auto;
        height: 44px;
        flex-direction: row;
        padding: 0 var(--s-3);
        border-top: none;
        border-bottom: 1px solid var(--line);
    }

    .shell-bottomnav__item {
        flex-direction: row;
        gap: var(--s-2);
        font-size: var(--text-xs);
        min-height: 36px;
    }

    .shell-content {
        padding-bottom: var(--s-4);
    }
}

/* Sidebar em mobile-open mostra sidebar via classe global no shell */
.shell--mobile-open .shell-sidebar {
    transform: translateX(0);
}
