/* ════════════════════════════════════════════════════════════════════
   app.css — moldura da aplicação (shell): barra superior, menu lateral,
   barra inferior do celular, botões e rodapé.
   Carregado em todas as páginas, depois do <style> do base.html e antes do
   public.css (que ajusta botões e gaveta para o tema verde público).
   Cores sempre por token (--bg, --surface, --border, --accent, --text…),
   que mudam com html[data-theme]. Nada de hex solto aqui, exceto a marca.
   ════════════════════════════════════════════════════════════════════ */

:root {
    --brand-mark-a: #00cda0;      /* selo "Q" do logo, igual ao das páginas públicas */
    --brand-mark-b: #00876a;
    --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
    --accent-softer: color-mix(in srgb, var(--accent) 6%, transparent);
    --danger-soft: color-mix(in srgb, var(--accent3) 10%, transparent);
    --topbar-bg: rgba(10, 10, 15, 0.88);
    --shadow-pop: 0 18px 48px -12px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.3);
    --radius-sm: 8px;
    --radius-md: 12px;
    --bottom-nav-h: 0px;          /* > 0 só no celular, com a barra inferior (body.has-bottom-nav) */
}
html[data-theme="light"] {
    --topbar-bg: rgba(255, 255, 255, 0.86);
    --shadow-pop: 0 18px 48px -16px rgba(15, 23, 42, 0.22), 0 2px 6px rgba(15, 23, 42, 0.06);
}

html { -webkit-text-size-adjust: 100%; }
body { -webkit-font-smoothing: antialiased; }
.app-main { transition: margin-left 0.2s ease; }

:where(a, button, summary, input, select, textarea):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ── BARRA SUPERIOR ───────────────────────────────────────────────── */
.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.25rem;
    height: var(--nav-h);
    border-bottom: 1px solid var(--border);
    background: var(--topbar-bg);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    backdrop-filter: saturate(160%) blur(12px);
    position: sticky;
    top: 0;
    z-index: 200;
}

.nav-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text);
    text-decoration: none;
    flex-shrink: 0;
}
.nav-logo-mark {
    width: 30px; height: 30px; border-radius: 9px; display: block;
}
.nav-logo-tag {
    font-family: var(--font-mono);
    font-size: 0.62rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    padding: 0.2rem 0.45rem; border-radius: 999px;
    color: var(--accent3); background: var(--danger-soft);
}

.nav-links { display: flex; gap: 0.25rem; align-items: center; }
.nav-links a {
    display: inline-flex; align-items: center;
    min-height: 38px; padding: 0 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem; font-weight: 600;
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}
.nav-links a:hover { color: var(--text); background: var(--accent-softer); }
.nav-links a.nav-link-strong { color: var(--text); }
.nav-links a.btn-primary { margin-left: 0.4rem; padding: 0 1rem; color: #fff; }
.nav-links a.btn-primary:hover { color: #facc15; background: #0a0a0a; }

.nav-actions { display: flex; align-items: center; gap: 0.5rem; }
.nav-quick {
    display: inline-flex; align-items: center; gap: 0.45rem;
    min-height: 40px; padding: 0 0.8rem;
    border-radius: 10px;
    color: var(--muted); text-decoration: none;
    font-size: 0.86rem; font-weight: 600;
    transition: color 0.15s, background 0.15s;
}
.nav-quick:hover { color: var(--text); background: var(--accent-softer); }

.theme-toggle {
    width: 40px; height: 40px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; border: 1px solid var(--border);
    background: var(--surface); color: var(--muted); cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* Menu da conta (details/summary: abre sem JavaScript) */
.user-menu { position: relative; }
.user-menu > summary {
    list-style: none;
    display: inline-flex; align-items: center; gap: 0.55rem;
    min-height: 40px; padding: 0.2rem 0.6rem 0.2rem 0.25rem;
    border: 1px solid var(--border); border-radius: 999px;
    background: var(--surface); color: var(--text);
    font-size: 0.86rem; font-weight: 600;
    cursor: pointer; user-select: none;
    transition: border-color 0.15s;
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary:hover, .user-menu[open] > summary { border-color: var(--accent); }
.user-menu-chevron { font-size: 0.65rem; color: var(--muted); transition: transform 0.15s; }
.user-menu[open] .user-menu-chevron { transform: rotate(180deg); }
.user-menu-name { max-width: 9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
    width: 32px; height: 32px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--accent); color: #fff;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em;
}
.user-menu-panel {
    position: absolute; right: 0; top: calc(100% + 0.5rem);
    width: 264px; padding: 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    z-index: 220;
}
.user-menu-head {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.7rem 0.7rem 0.8rem; margin-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
    min-width: 0;
}
.user-menu-head > div { min-width: 0; }
.user-menu-head strong {
    display: block; font-size: 0.9rem; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-menu-head span:not(.avatar) { font-size: 0.76rem; color: var(--muted); }
.user-menu-panel a {
    display: flex; align-items: center; gap: 0.7rem;
    min-height: 42px; padding: 0 0.7rem;
    border-radius: var(--radius-sm);
    color: var(--text); text-decoration: none;
    font-size: 0.88rem; font-weight: 500;
}
.user-menu-panel a i { width: 18px; text-align: center; color: var(--muted); }
.user-menu-panel a:hover { background: var(--accent-softer); }
.user-menu-panel a.is-danger, .user-menu-panel a.is-danger i { color: var(--accent3); }
.user-menu-panel a.is-danger:hover { background: var(--danger-soft); }
.user-menu-sep { height: 1px; margin: 0.3rem 0; background: var(--border); }

/* Botão hambúrguer (visitantes e páginas públicas) */
.nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 5px;
    cursor: pointer;
    padding: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 10px;
}
.nav-hamburger span {
    display: block;
    width: 20px; height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.2s;
}
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Gaveta do menu no celular (visitantes) */
.nav-drawer {
    display: none;
    position: fixed;
    top: var(--nav-h);
    left: 0; right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    padding: 0.5rem 1.25rem 1rem;
    z-index: 199;
    box-shadow: var(--shadow-pop);
}
.nav-drawer.open { display: flex; }
.nav-drawer a {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    min-height: 48px;
    border-bottom: 1px solid var(--border);
    transition: color 0.15s;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.nav-drawer a:last-child { border-bottom: none; }
.nav-drawer a:hover, .nav-drawer a.drawer-strong { color: var(--text); }
.nav-drawer a.drawer-accent { color: var(--accent2); font-weight: 700; }

/* ── BOTÕES ───────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0.55rem 1.15rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-display);
    font-size: 0.9rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
    text-decoration: none;
    border: 1px solid transparent;
    white-space: nowrap;
}
.btn-primary { background: #0a0a0a; color: #fff; border-color: #0a0a0a; }
.btn-primary:hover { background: #0a0a0a; color: #facc15; border-color: #facc15; box-shadow: 0 4px 18px rgba(250, 204, 21, 0.2); }
html[data-theme="dark"] .btn-primary { border-color: var(--border); }
.btn-outline { background: transparent; color: var(--accent2); border-color: var(--accent2); }
.btn-outline:hover { background: var(--accent2); color: var(--bg); }

/* ── MENU LATERAL ─────────────────────────────────────────────────── */
.app-sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 150;
    transition: width 0.2s ease, transform 0.25s ease;
    overflow-x: hidden;
}
.app-sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 1.1rem 0.75rem 0.4rem;
    white-space: nowrap;
}
.sidebar-section-label:first-child { padding-top: 0.5rem; }
.app-sidebar.collapsed .sidebar-section-label {
    height: 1px; padding: 0; margin: 0.6rem 0.6rem;
    background: var(--border); overflow: hidden; color: transparent;
}
.app-sidebar.collapsed .sidebar-section-label:first-child { display: none; }

.sidebar-links {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.75rem 0.6rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 40px;
    padding: 0 0.75rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--muted);
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.15s, color 0.15s;
    position: relative;
}
.sidebar-link i.link-icon { width: 18px; text-align: center; flex-shrink: 0; font-size: 0.95rem; opacity: 0.85; }
.sidebar-link:hover { background: var(--accent-softer); color: var(--text); }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-link.active i.link-icon { opacity: 1; }
.sidebar-link.active::before {
    content: ''; position: absolute; left: -0.6rem; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.app-sidebar.collapsed .sidebar-link { justify-content: center; padding: 0; }
.app-sidebar.collapsed .sidebar-link span.link-label { display: none; }

.sidebar-badge {
    background: var(--accent3);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 6px;
    margin-left: auto;
    display: none;
}
.app-sidebar.collapsed .sidebar-badge { position: absolute; top: 4px; right: 4px; margin-left: 0; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 0.6rem;
    flex-shrink: 0;
    display: flex; flex-direction: column; gap: 2px;
}
.sidebar-toggle i { transition: transform 0.2s; }
.app-sidebar.collapsed .sidebar-toggle i { transform: rotate(180deg); }
.sidebar-link.is-danger { color: var(--accent3); }
.sidebar-link.is-danger:hover { background: var(--danger-soft); color: var(--accent3); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    z-index: 205;
}

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

/* ── RODAPÉ DAS TELAS INTERNAS ────────────────────────────────────── */
.app-footer {
    border-top: 1px solid var(--border);
    padding: 1.1rem 1.5rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem 1.5rem;
    font-size: 0.8rem;
    color: var(--muted);
}
.app-footer-links { display: flex; gap: 0.25rem 1.25rem; flex-wrap: wrap; }
.app-footer a { color: var(--muted); text-decoration: none; transition: color 0.15s; }
.app-footer a:hover { color: var(--text); text-decoration: underline; }

/* ── BARRA INFERIOR (celular, logado) ─────────────────────────────── */
.bottom-nav { display: none; }

/* ── CELULAR ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    html[data-theme] { --nav-h: 56px; }   /* só telas internas; as públicas não têm data-theme */
    .app-topbar { padding: 0 0.85rem; }
    .nav-links { display: none !important; }
    .nav-hamburger { display: flex; width: 44px; height: 44px; align-items: center; justify-content: center; padding: 0; }
    .nav-quick { display: none; }
    .theme-toggle { width: 44px; height: 44px; }
    .user-menu > summary { min-height: 44px; padding-right: 0.25rem; border-color: transparent; background: none; }
    .user-menu-name, .user-menu-chevron { display: none; }
    .user-menu-panel { position: fixed; top: calc(var(--nav-h) + 0.4rem); right: 0.6rem; left: 0.6rem; width: auto; }
    .user-menu-panel a { min-height: 48px; }

    body.has-bottom-nav { --bottom-nav-h: calc(60px + env(safe-area-inset-bottom, 0px)); }
    body.has-bottom-nav .app-main { padding-bottom: var(--bottom-nav-h); }
    body.has-bottom-nav .nav-hamburger { display: none; }

    .bottom-nav {
        display: grid;
        grid-template-columns: repeat(5, minmax(0, 1fr));
        position: fixed; left: 0; right: 0; bottom: 0;
        height: var(--bottom-nav-h);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -6px 24px -12px rgba(2, 6, 23, 0.25);
        z-index: 190;
    }
    .bottom-nav-item {
        position: relative;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
        min-width: 0; min-height: 56px; padding: 0 2px;
        border: 0; background: none;
        color: var(--muted);
        font-family: var(--font-display); font-size: 0.68rem; font-weight: 600;
        text-decoration: none; cursor: pointer;
    }
    .bottom-nav-item i { font-size: 1.1rem; }
    .bottom-nav-item span.bn-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .bottom-nav-item[aria-current="page"] { color: var(--accent); }
    .bottom-nav-item[aria-current="page"]::before {
        content: ''; position: absolute; top: 0; left: 28%; right: 28%;
        height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
    }
    .bottom-nav-badge {
        position: absolute; top: 6px; left: calc(50% + 6px);
        min-width: 18px; padding: 1px 5px;
        border-radius: 10px; border: 2px solid var(--surface);
        background: var(--accent3); color: #fff;
        font-size: 0.6rem; font-weight: 700; text-align: center;
        display: none;
    }

    /* menu lateral vira gaveta, aberta pelo item "Menu" da barra inferior */
    .app-sidebar {
        top: 0;
        height: 100dvh;
        transform: translateX(-100%);
        width: min(82vw, 300px) !important;
        box-shadow: var(--shadow-pop);
        z-index: 210;
    }
    .app-sidebar.mobile-open { transform: translateX(0); }
    .app-sidebar .sidebar-link { min-height: 46px; font-size: 0.95rem; }
    .sidebar-backdrop.open { display: block; }
    .sidebar-toggle { display: none; }
    .app-main.with-sidebar,
    .app-main.with-sidebar.sidebar-collapsed { margin-left: 0 !important; }

    /* com a barra inferior, o suporte é um destino dela: o botão flutuante sai */
    body.has-bottom-nav #chat-fab, body.has-bottom-nav #chat-panel { display: none !important; }
    body.has-bottom-nav .cookie-consent { bottom: calc(var(--bottom-nav-h) + 0.6rem); }

    .app-footer { padding: 1rem; flex-direction: column; align-items: flex-start; }
    .app-footer a { display: inline-flex; align-items: center; min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
