/* ==========================================================================
   Estrutura da aplicação: sidebar + barra superior.
   Usa os tokens de cor de style.css (--primary-color, --bg-*, --text-*),
   então acompanha o tema claro/escuro sem regras duplicadas.
   ========================================================================== */

:root {
    --app-sidebar-w: 256px;
    --app-sidebar-w-collapsed: 72px;
    --app-header-h: 64px;
    --app-radius: 8px;
    --app-ease: cubic-bezier(0.2, 0, 0, 1);
    --app-nav-active-bg: rgba(11, 95, 166, 0.08);
    --app-header-bg: rgba(255, 255, 255, 0.85);
    --app-shadow-menu: 0 10px 38px -10px rgba(15, 23, 42, 0.25),
        0 10px 20px -15px rgba(15, 23, 42, 0.2);
}

.dark {
    --app-nav-active-bg: rgba(59, 130, 246, 0.14);
    --app-header-bg: rgba(15, 23, 42, 0.8);
    --app-shadow-menu: 0 10px 38px -10px rgba(0, 0, 0, 0.6);
}

.app-body {
    background-color: var(--bg-primary);
    font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* ---------- Ícones ---------- */
.app-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.app-icon--sm {
    width: 18px;
    height: 18px;
}

.app-icon--xs {
    width: 14px;
    height: 14px;
}

/* ---------- Acessibilidade ---------- */
.app-skip-link {
    position: absolute;
    left: 12px;
    top: -48px;
    z-index: 100;
    padding: 8px 14px;
    border-radius: var(--app-radius);
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    transition: top 0.15s var(--app-ease);
}

.app-skip-link:focus {
    top: 12px;
}

#main:focus {
    outline: none;
}

.app-icon-button:focus-visible,
.app-nav-link:focus-visible,
.app-user__trigger:focus-visible,
.app-menu__item:focus-visible,
.app-brand:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    width: var(--app-sidebar-w);
    /* Sidebar escura nos dois temas: redefine os tokens só aqui dentro, e
       todas as regras abaixo (links, títulos, bordas, hover) acompanham. */
    --text-primary: #f1f5f9;
    --text-secondary: rgba(203, 213, 225, 0.78);
    --bg-tertiary: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.1);
    --primary-color: #38bdf8;
    --secondary-color: #2dd4bf;
    --app-nav-active-bg: rgba(255, 255, 255, 0.14);
    background: linear-gradient(180deg, #0b4a78 0%, #0a3558 100%);
    border-right: 1px solid var(--border-color);
    color: var(--text-primary);
    transition: width 0.2s var(--app-ease), transform 0.25s var(--app-ease);
}

.dark .app-sidebar {
    background: linear-gradient(180deg, #0c1a2e 0%, #08111f 100%);
}

.app-sidebar .app-nav-link.is-active {
    color: #ffffff;
}

/* Fundo sempre escuro: usa o logo claro também no tema claro. */
.app-sidebar .app-logo--on-light {
    display: none;
}

.app-sidebar .app-logo--on-dark {
    display: block;
}

.app-sidebar__brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: var(--app-header-h);
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--border-color);
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    border-radius: var(--app-radius);
    color: var(--text-primary);
    text-decoration: none;
}

.app-brand__mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
}

.app-brand__text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    white-space: nowrap;
}

.app-brand__text strong {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.app-brand__text small {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.app-sidebar__nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 12px 16px;
}

.app-nav-section + .app-nav-section {
    margin-top: 8px;
}

.app-nav-section__title {
    margin: 0;
    padding: 14px 12px 6px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
}

.app-nav-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: var(--app-radius);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-nav-link:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.app-nav-link.is-active {
    background: var(--app-nav-active-bg);
    color: var(--primary-color);
    font-weight: 600;
}

.app-nav-link.is-active::before {
    content: "";
    position: absolute;
    left: -12px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--primary-color);
}

.app-nav-empty {
    padding: 12px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.app-sidebar__footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
}

.app-sidebar__collapse .app-icon {
    transition: transform 0.2s var(--app-ease);
}

.app-sidebar__vendor {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    font-size: 0.6875rem;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
}

.app-sidebar__vendor img {
    height: 18px;
    width: auto;
    opacity: 0.75;
}

.app-logo--on-dark,
.dark .app-logo--on-light {
    display: none;
}

.dark .app-logo--on-dark {
    display: block;
}

.app-icon-button.app-sidebar__close {
    display: none;
}

/* ---------- Coluna de conteúdo ---------- */
.app-column {
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--app-sidebar-w);
    transition: margin-left 0.2s var(--app-ease);
}

.app-content {
    padding: 8px 8px 24px;
}

/* ---------- Barra superior ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--app-header-h);
    padding: 0 24px;
    background: var(--app-header-bg);
    border-bottom: 1px solid var(--border-color);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
}

.app-icon-button.app-header__menu {
    display: none;
}

.app-breadcrumb {
    min-width: 0;
    flex: 1;
}

.app-breadcrumb ol {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.875rem;
}

.app-breadcrumb__section,
.app-breadcrumb__sep {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
    white-space: nowrap;
}

.app-breadcrumb__current {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
    color: var(--text-primary);
}

.app-header__actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.app-icon-button {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: 0;
    border-radius: var(--app-radius);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.app-icon-button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Mostra a ação disponível: lua no tema claro, sol no escuro. */
.app-theme-icon {
    display: grid;
}

.app-theme-icon--sun,
.dark .app-theme-icon--moon {
    display: none;
}

.dark .app-theme-icon--sun {
    display: grid;
}

/* ---------- Menu do usuário ---------- */
.app-user {
    position: relative;
}

.app-user__trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 8px 0 4px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.app-user__trigger:hover,
.app-user__trigger[aria-expanded="true"] {
    background: var(--bg-tertiary);
    border-color: var(--border-color);
}

.app-user__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
    max-width: 180px;
}

.app-user__name {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    font-weight: 600;
}

.app-user__role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.app-user__chevron {
    color: var(--text-secondary);
    transition: transform 0.15s ease;
}

.app-user__trigger[aria-expanded="true"] .app-user__chevron {
    transform: rotate(180deg);
}

.app-avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.app-avatar--lg {
    width: 40px;
    height: 40px;
    font-size: 0.875rem;
}

.app-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 50;
    width: 280px;
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    box-shadow: var(--app-shadow-menu);
    animation: app-menu-in 0.12s var(--app-ease);
}

.app-menu[hidden],
.app-backdrop[hidden] {
    display: none;
}

@keyframes app-menu-in {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.98);
    }
}

.app-menu__header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 10px 12px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.app-menu__name {
    margin: 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.app-menu__email {
    margin: 2px 0 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    word-break: break-all;
}

.app-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--app-nav-active-bg);
    color: var(--primary-color);
    font-size: 0.6875rem;
    font-weight: 600;
}

.app-menu__item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 38px;
    padding: 0 10px;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
}

.app-menu__item:hover,
.app-menu__item:focus-visible {
    background: var(--bg-tertiary);
}

.app-menu__item--danger {
    color: var(--danger-color);
}

/* ---------- Desktop: sidebar recolhida (só ícones) ---------- */
@media (min-width: 1024px) {
    .sidebar-collapsed .app-sidebar {
        width: var(--app-sidebar-w-collapsed);
    }

    .sidebar-collapsed .app-column {
        margin-left: var(--app-sidebar-w-collapsed);
    }

    .sidebar-collapsed .app-sidebar__label {
        display: none;
    }

    .sidebar-collapsed .app-sidebar__brand {
        justify-content: center;
        padding: 0;
    }

    .sidebar-collapsed .app-nav-section + .app-nav-section {
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--border-color);
    }

    .sidebar-collapsed .app-nav-link {
        justify-content: center;
        padding: 0;
    }

    .sidebar-collapsed .app-sidebar__collapse .app-icon {
        transform: rotate(180deg);
    }

    /* Rótulo em tooltip ao passar o mouse ou focar pelo teclado. */
    .sidebar-collapsed .app-nav-link::after {
        content: attr(data-tooltip);
        position: absolute;
        left: calc(100% + 12px);
        top: 50%;
        z-index: 60;
        padding: 6px 10px;
        border-radius: 6px;
        background: #0f172a;
        color: #f8fafc;
        font-size: 0.75rem;
        font-weight: 500;
        white-space: nowrap;
        pointer-events: none;
        opacity: 0;
        transform: translate(-4px, -50%);
        transition: opacity 0.12s ease, transform 0.12s ease;
    }

    .sidebar-collapsed .app-nav-link:hover::after,
    .sidebar-collapsed .app-nav-link:focus-visible::after {
        opacity: 1;
        transform: translate(0, -50%);
    }

    .sidebar-collapsed .app-sidebar__nav {
        overflow: visible;
    }
}

/* ---------- Celular/tablet: sidebar vira gaveta ---------- */
@media (max-width: 1023.98px) {
    .app-sidebar {
        width: min(288px, 85vw);
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar-open .app-sidebar {
        transform: translateX(0);
        box-shadow: var(--app-shadow-menu);
    }

    .sidebar-open {
        overflow: hidden;
    }

    .app-column {
        margin-left: 0;
    }

    .app-backdrop {
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgba(15, 23, 42, 0.5);
        animation: app-fade-in 0.2s ease;
    }

    .app-header {
        padding: 0 12px;
    }

    .app-icon-button.app-header__menu,
    .app-icon-button.app-sidebar__close {
        display: inline-grid;
    }

    .app-sidebar__collapse {
        display: none;
    }
}

@media (max-width: 639.98px) {
    .app-user__meta,
    .app-user__chevron,
    .app-breadcrumb__section,
    .app-breadcrumb__sep {
        display: none;
    }

    .app-user__trigger {
        padding: 0 4px;
    }

    .app-content {
        padding: 4px 0 16px;
    }
}

@keyframes app-fade-in {
    from {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar,
    .app-column,
    .app-menu,
    .app-backdrop,
    .app-nav-link,
    .app-sidebar__collapse .app-icon {
        transition: none;
        animation: none;
    }
}

@media print {
    .app-sidebar,
    .app-header,
    .app-backdrop,
    .app-skip-link {
        display: none !important;
    }

    .app-column {
        margin-left: 0 !important;
    }
}
