/* Auto Center ERP — layout: casca da aplicação (sidebar, topbar, conteúdo), auth e páginas de erro. Mobile-first. */

/* ---------- Casca ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

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

.app-content {
    flex: 1 1 auto;
    padding: var(--esp-4);
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
}

.app-content:focus {
    outline: none;
}

.app-footer {
    padding: var(--esp-3) var(--esp-4);
    font-size: 0.78rem;
    color: var(--cor-texto-suave);
    text-align: center;
    border-top: 1px solid var(--cor-borda);
    background: var(--cor-superficie);
}

@media (min-width: 768px) {
    .app-content {
        padding: var(--esp-5);
    }
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-sidebar);
    width: var(--tam-sidebar);
    max-width: 85vw;
    display: flex;
    flex-direction: column;
    background: var(--cor-sidebar);
    color: var(--cor-sidebar-texto);
    transform: translateX(-100%);
    /* Fechada (mobile): além de fora da tela, fora da ordem de tabulação e dos leitores de tela.
       A visibilidade só muda depois do deslize de saída (delay = duração); ao abrir, muda na hora.
       sidebar.js complementa com o atributo inert. */
    visibility: hidden;
    transition: transform var(--transicao), width var(--transicao), visibility 0s linear var(--transicao-duracao);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.sidebar-aberta .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition-delay: 0s;
    box-shadow: var(--sombra-3);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: rgba(0, 0, 0, 0.45);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--esp-3);
    min-height: var(--tam-topbar);
    padding: 0 var(--esp-3) 0 var(--esp-4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: var(--esp-3);
    flex: 1 1 auto;
    min-width: 0;
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.sidebar-brand-link:hover {
    text-decoration: none;
}

.sidebar-logo {
    width: 2rem;
    height: 2rem;
    flex-shrink: 0;
}

.sidebar-brand-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-close {
    color: var(--cor-sidebar-texto);
}

.sidebar-nav {
    flex: 1 1 auto;
    padding: var(--esp-2) 0;
}

.sidebar-menu,
.sidebar-submenu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--esp-3);
    width: 100%;
    min-height: var(--alvo-toque);
    padding: 0.55rem var(--esp-4);
    border: 0;
    background: transparent;
    color: var(--cor-sidebar-texto);
    text-align: left;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: background var(--transicao), color var(--transicao);
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-decoration: none;
}

.sidebar-link:focus-visible {
    outline-offset: -3px;
}

.sidebar-item.is-active > .sidebar-link,
.sidebar-link[aria-current="page"] {
    background: var(--cor-sidebar-ativo);
    color: #fff;
    border-left-color: #fff;
}

.sidebar-link .icon {
    width: 1.35rem;
    height: 1.35rem;
    opacity: 0.9;
}

.sidebar-label {
    flex: 1 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-group-toggle {
    cursor: pointer;
}

.sidebar-group-toggle .sidebar-caret {
    width: 1rem;
    height: 1rem;
    transition: transform var(--transicao);
}

.sidebar-group-toggle[aria-expanded="true"] .sidebar-caret {
    transform: rotate(90deg);
}

.sidebar-submenu .sidebar-link {
    padding-left: 2.75rem;
    font-size: 0.93rem;
}

.sidebar-form {
    margin: 0;
}

.sidebar-footer {
    padding: var(--esp-3) var(--esp-4);
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Desktop: sidebar fixa no fluxo, recolhível */
@media (min-width: 1024px) {
    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        transform: none;
        visibility: visible;
        max-width: none;
        flex: 0 0 var(--tam-sidebar);
    }

    .sidebar-aberta .sidebar {
        box-shadow: none;
    }

    .sidebar-backdrop {
        display: none !important;
    }

    .sidebar-close,
    .topbar-toggle-mobile {
        display: none;
    }

    .sidebar-recolhida .sidebar {
        width: var(--tam-sidebar-recolhida);
        flex-basis: var(--tam-sidebar-recolhida);
    }

    .sidebar-recolhida .sidebar-brand {
        padding: 0;
        justify-content: center;
    }

    .sidebar-recolhida .sidebar-brand-link {
        justify-content: center;
        flex: 0 0 auto;
    }

    .sidebar-recolhida .sidebar-brand-text,
    .sidebar-recolhida .sidebar-label,
    .sidebar-recolhida .sidebar-caret,
    .sidebar-recolhida .sidebar-footer,
    .sidebar-recolhida .sidebar-submenu {
        display: none;
    }

    .sidebar-recolhida .sidebar-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--esp-2);
    min-height: var(--tam-topbar);
    padding: 0 var(--esp-3);
    background: var(--cor-superficie);
    border-bottom: 1px solid var(--cor-borda);
    box-shadow: var(--sombra-1);
}

.topbar-toggle {
    color: var(--cor-texto);
}

.topbar-empresa {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.2;
}

.topbar-empresa-nome {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-empresa-sub {
    font-size: 0.75rem;
    color: var(--cor-texto-suave);
}

.topbar-spacer {
    flex: 1 1 auto;
}

.topbar-user {
    display: inline-flex;
    align-items: center;
    gap: var(--esp-2);
    min-height: var(--alvo-toque);
    padding: 0.25rem 0.5rem;
    border: 0;
    border-radius: var(--raio);
    background: transparent;
    color: var(--cor-texto);
}

.topbar-user:hover {
    background: var(--cor-superficie-2);
}

.topbar-user-nome {
    display: none;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

@media (min-width: 640px) {
    .topbar-user-nome {
        display: inline;
    }
}

.topbar-sair-form {
    margin: 0;
}

/* ---------- Cabeçalho de página e breadcrumbs ---------- */
.breadcrumbs {
    margin-bottom: var(--esp-3);
    font-size: 0.85rem;
    color: var(--cor-texto-suave);
}

.breadcrumbs ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--esp-1);
    list-style: none;
    margin: 0;
    padding: 0;
}

.breadcrumbs li {
    display: inline-flex;
    align-items: center;
    gap: var(--esp-1);
}

.breadcrumbs li + li::before {
    content: "/";
    color: var(--cor-borda-forte);
    margin: 0 var(--esp-1);
}

.breadcrumbs [aria-current="page"] {
    color: var(--cor-texto);
    font-weight: 500;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--esp-3);
    margin-bottom: var(--esp-4);
}

.page-title {
    margin: 0;
    font-size: 1.4rem;
}

.page-subtitle {
    margin: var(--esp-1) 0 0;
    color: var(--cor-texto-suave);
    font-size: 0.9rem;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--esp-2);
}

@media (min-width: 768px) {
    .page-title {
        font-size: 1.6rem;
    }
}

/* ---------- Grade: item ocupando duas colunas (formulários em .grid-2) ---------- */
@media (min-width: 768px) {
    .grid-span-2 {
        grid-column: span 2;
    }
}

/* ---------- Layout de autenticação ---------- */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--esp-4);
    background: linear-gradient(160deg, var(--cor-primaria-escura) 0%, var(--cor-primaria) 55%, #2d6aa3 100%);
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--esp-2);
    margin-bottom: var(--esp-5);
    color: #fff;
    text-align: center;
}

.auth-brand img,
.auth-brand svg {
    width: 4rem;
    height: 4rem;
}

.auth-brand-nome {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.auth-flash {
    width: 100%;
    max-width: 420px;
}

.auth-flash:empty {
    display: none;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--cor-superficie);
    border-radius: var(--raio-g);
    box-shadow: var(--sombra-3);
    padding: var(--esp-5) var(--esp-5) var(--esp-4);
}

.auth-title {
    margin-bottom: var(--esp-2);
    font-size: 1.4rem;
}

.auth-subtitle {
    color: var(--cor-texto-suave);
    margin-bottom: var(--esp-4);
}

.auth-links {
    margin: var(--esp-4) 0 0;
    text-align: center;
    font-size: 0.9rem;
}

.auth-footer {
    margin-top: var(--esp-5);
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
}

/* ---------- Páginas de erro ---------- */
.erro-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--esp-4);
}

.erro-card {
    width: 100%;
    max-width: 640px;
    background: var(--cor-superficie);
    border-radius: var(--raio-g);
    box-shadow: var(--sombra-2);
    padding: var(--esp-6) var(--esp-5);
    text-align: center;
}

.erro-codigo {
    font-size: 4rem;
    font-weight: 700;
    line-height: 1;
    color: var(--cor-primaria);
    margin-bottom: var(--esp-3);
}

.erro-icone {
    color: var(--cor-primaria);
    margin-bottom: var(--esp-3);
}

.erro-icone .icon {
    width: 3.5rem;
    height: 3.5rem;
}

.erro-titulo {
    font-size: 1.5rem;
}

.erro-mensagem {
    color: var(--cor-texto-suave);
    font-size: 1.05rem;
}

.erro-acoes {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: var(--esp-2);
    margin-top: var(--esp-4);
}

.erro-referencia {
    margin-top: var(--esp-4);
    font-size: 0.8rem;
    color: var(--cor-texto-suave);
}

.erro-referencia code {
    user-select: all;
}

.erro-debug {
    margin-top: var(--esp-4);
    text-align: left;
}

.erro-debug summary {
    cursor: pointer;
    color: var(--cor-perigo);
    font-weight: 600;
}

.erro-debug pre {
    font-size: 0.8rem;
    max-height: 50vh;
}
