/* ============================================
   MAX — Design System
   v2.0 — Modern SaaS Platform
   ============================================ */

/* ============================================
   1. RESET
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
    font-size: 14.5px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
img, svg { display: block; max-width: 100%; }

/* ============================================
   2. DESIGN TOKENS — LIGHT MODE
   ============================================ */
:root {
    /* Colors — Surfaces */
    --bg:           #f2f2f2;
    --surface:      #ffffff;
    --surface-2:    #f2f2f2;
    --surface-3:    #efefef;
    --surface-hover:#e8e8eb;

    /* Colors — Borders */
    --border:       #e8e8ed;
    --border-2:     #d8d8df;
    --border-strong:#c8c8d0;

    /* Colors — Text */
    --text:         #333333;
    --text-2:       #52525b;
    --text-3:       #71717a;
    --text-muted:   #a1a1aa;

    /* Colors — Brand */
    --primary:      #007cba;
    --primary-hover:#0c58a4;
    --primary-fg:   #ffffff;
    --primary-soft: rgba(0, 124, 186, 0.1);
    --primary-glow: rgba(0, 124, 186, 0.16);
    --ring:         rgba(0, 124, 186, 0.32);

    /* Colors — Semantic */
    --success:      #00d084;
    --success-soft: rgba(0, 208, 132, 0.1);
    --warning:      #fcb900;
    --warning-soft: rgba(252, 185, 0, 0.1);
    --danger:       #cf2e2e;
    --danger-soft:  rgba(207, 46, 46, 0.1);
    --info:         #0693e3;
    --info-soft:    rgba(6, 147, 227, 0.1);

    /* Spacing — 4px base */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius:    8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl:20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow:    0 4px 8px -2px rgba(16, 24, 40, 0.06), 0 2px 4px -2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 12px 16px -4px rgba(16, 24, 40, 0.08), 0 4px 6px -2px rgba(16, 24, 40, 0.04);
    --shadow-lg: 0 20px 24px -4px rgba(16, 24, 40, 0.1), 0 8px 8px -4px rgba(16, 24, 40, 0.04);
    --shadow-xl: 0 24px 48px -12px rgba(16, 24, 40, 0.18);

    /* Layout */
    --sidebar-w:      248px;
    --sidebar-w-min:  64px;
    --topbar-h:       56px;
    --content-max:    1200px;

    /* Motion */
    --t-fast: 150ms;
    --t:      200ms;
    --t-slow: 300ms;
    --ease:   cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   3. DESIGN TOKENS — DARK MODE
   ============================================ */
[data-theme="dark"] {
    --bg:           #0a0a0a;
    --surface:      #111111;
    --surface-2:    #161616;
    --surface-3:    #1c1c1c;
    --surface-hover:#1e1e1e;

    --border:       #1f1f1f;
    --border-2:     #2a2a2a;
    --border-strong:#3a3a3a;

    --text:         #fafafa;
    --text-2:       #a1a1aa;
    --text-3:       #71717a;
    --text-muted:   #52525b;

    --primary:      #4db8e8;
    --primary-hover:#7dcdf0;
    --primary-fg:   #0a0a0a;
    --primary-soft: rgba(77, 184, 232, 0.12);
    --primary-glow: rgba(77, 184, 232, 0.2);
    --ring:         rgba(77, 184, 232, 0.4);

    --success:      #33e0a0;
    --success-soft: rgba(51, 224, 160, 0.12);
    --warning:      #fdc933;
    --warning-soft: rgba(253, 201, 51, 0.12);
    --danger:       #e05858;
    --danger-soft:  rgba(224, 88, 88, 0.12);
    --info:         #3eabf0;
    --info-soft:    rgba(62, 171, 240, 0.12);

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow:    0 4px 8px -2px rgba(0, 0, 0, 0.6), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 12px 16px -4px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 24px -4px rgba(0, 0, 0, 0.5), 0 8px 8px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
}

/* Tema claro e o padrao. Tema escuro so quando o usuario alterna explicitamente
   via botao (data-theme="dark"). Nao segue mais prefers-color-scheme do SO. */

/* ============================================
   3b. DESIGN TOKENS — MARCA ZZ LOJA
   ============================================
   Tenant com a flag "ZZ Loja" (admin/tenant-edit.php) renderiza o <html> com
   data-brand="zzloja" — ver max_brand_attr() em includes/tenant-resolver.php.
   Só o accent muda: o azul padrão vira o #32b8c6 da marca, e com ele todo link,
   foco, badge, borda ativa e botão primário. Superfícies, texto e semânticas
   (sucesso/erro) seguem iguais — é a mesma casa, com outra cor de marca.

   Especificidade de propósito: :root[data-brand] (0,2,0) ganha do :root claro,
   e a variante com [data-theme="dark"] (0,3,0) ganha do bloco escuro acima.

   --primary-fg escuro (e não branco) porque o #32b8c6 é claro: texto branco em
   cima dá 2,4:1, tinta escura dá 8:1. É a mesma escolha que o tema escuro já
   faz com o azul claro dele. */
:root[data-brand="zzloja"] {
    --primary:      #32b8c6;
    --primary-hover:#21808d;
    --primary-fg:   #0a0a0a;
    --primary-soft: rgba(50, 184, 198, 0.12);
    --primary-glow: rgba(50, 184, 198, 0.18);
    --ring:         rgba(50, 184, 198, 0.35);
}

:root[data-brand="zzloja"][data-theme="dark"] {
    --primary:      #32b8c6;
    --primary-hover:#5fd0da;
    --primary-fg:   #0a0a0a;
    --primary-soft: rgba(50, 184, 198, 0.14);
    --primary-glow: rgba(50, 184, 198, 0.22);
    --ring:         rgba(50, 184, 198, 0.4);
}

/* ============================================
   4. SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: var(--radius-full);
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================
   5. APP SHELL
   ============================================ */
.app {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width var(--t) var(--ease), transform var(--t) var(--ease);
}

.app[data-sidebar="collapsed"] .sidebar {
    width: var(--sidebar-w-min);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--topbar-h);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-logo-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
    /* Gradiente serve de fallback quando o elemento e <span> com iniciais (admin) */
    background: linear-gradient(135deg, var(--primary), #7a00df);
}
/* Quando o elemento e uma <img> (icone do tenant): preenche todo o quadrado,
   sem cantos arredondados nem margem (o ícone é quem define a própria forma). */
img.sidebar-logo-mark {
    object-fit: cover;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}

.sidebar-logo-img {
    height: 28px;
    width: auto;
    display: block;
    transition: opacity var(--t) var(--ease), width var(--t) var(--ease);
}
/* Logo horizontal do tenant (imagem) na sidebar expandida: ocupa bem o
   cabeçalho (56px de altura), centralizado, sem estourar a largura. */
img.sidebar-logo-img {
    height: 40px;
    max-width: 200px; /* --sidebar-w 248px - 2x padding 16px - folga */
    object-fit: contain;
    object-position: center;
}

/* Expanded: show image, hide mark */
.sidebar-logo-mark { display: none; }

/* Collapsed: show mark, hide image */
.app[data-sidebar="collapsed"] .sidebar-logo-mark {
    display: flex;
}
.app[data-sidebar="collapsed"] .sidebar-logo-img {
    display: none;
}
/* Recolhido: a imagem do ícone do tenant preenche TODO o cabeçalho (sem margem
   nem cantos arredondados). O badge de iniciais (<span>) segue 28px centralizado. */
.app[data-sidebar="collapsed"] .sidebar-logo {
    width: 100%;
    height: 100%;
}
.app[data-sidebar="collapsed"] img.sidebar-logo-mark {
    width: 100%;
    height: 100%;
}

.sidebar-collapse-btn {
    background: transparent;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
    flex-shrink: 0;
}
.sidebar-collapse-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.sidebar-collapse-btn svg {
    flex-shrink: 0;
}
.sidebar-collapse-label {
    transition: opacity var(--t) var(--ease);
}
/* Rodapé: nome do usuário (esquerda, ocupa o espaço) + botão de recolher (direita) */
.sidebar-user-row {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}
.sidebar-user-row .user-menu {
    flex: 1;
    min-width: 0;
}

.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-3) 0;
}

.sidebar-section {
    padding: var(--space-3) 0;
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-5);
    margin-bottom: var(--space-1);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 var(--space-3);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: 36px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 14px;
    font-weight: 500;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
}
.nav-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}
.nav-item-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.nav-item-icon svg { width: 100%; height: 100%; }
.nav-item-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--t) var(--ease);
}

.app[data-sidebar="collapsed"] .sidebar-section-title,
.app[data-sidebar="collapsed"] .nav-item-label,
.app[data-sidebar="collapsed"] .sidebar-logo-text,
.app[data-sidebar="collapsed"] .sidebar-collapse-label,
.app[data-sidebar="collapsed"] .user-meta {
    display: none;
}
.app[data-sidebar="collapsed"] .sidebar-header {
    justify-content: center;
    padding: 0;
}
.app[data-sidebar="collapsed"] .sidebar-collapse-btn {
    justify-content: center;
    padding: 0;
    width: 40px;
    height: 40px;
    margin: 0 auto;
    gap: 0;
}
.app[data-sidebar="collapsed"] .sidebar-collapse-btn svg {
    transform: rotate(180deg);
}
.app[data-sidebar="collapsed"] .sidebar-nav {
    padding: 0;
    gap: 2px;
    align-items: stretch;
}
.app[data-sidebar="collapsed"] .nav-item {
    justify-content: center;
    padding: 0;
    height: 40px;
    width: 40px;
    margin: 0 auto;
    gap: 0;
    border-radius: var(--radius);
    overflow: visible;
}
.app[data-sidebar="collapsed"] .nav-item-icon {
    width: 20px;
    height: 20px;
    margin: 0 auto;
}
.app[data-sidebar="collapsed"] .sidebar-section {
    padding: var(--space-1) 0;
}
.app[data-sidebar="collapsed"] .sidebar-footer {
    padding: var(--space-2);
}
.app[data-sidebar="collapsed"] .user-card {
    justify-content: center;
    padding: var(--space-2);
    gap: 0;
}
/* Recolhido: empilha avatar + botão de expandir, ambos centralizados */
.app[data-sidebar="collapsed"] .sidebar-user-row {
    flex-direction: column;
    gap: var(--space-2);
}
.app[data-sidebar="collapsed"] .sidebar-user-row .user-menu {
    flex: none;
    width: 100%;
}
.app[data-sidebar="collapsed"] .user-avatar {
    display: flex;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: var(--space-3);
    flex-shrink: 0;
}

/* Sino de notificações dentro da sidebar-footer */
.sidebar-notif { position: relative; margin-bottom: var(--space-2); }
.sidebar-notif-btn {
    display: flex;
    align-items: center;
    width: 100%;
    height: 34px;
    justify-content: flex-start;
    gap: var(--space-2);
    padding: 0 var(--space-3);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    background: transparent;
    cursor: pointer;
    position: relative;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.sidebar-notif-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.sidebar-notif-btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-notif-label { transition: opacity var(--t) var(--ease); }

/* No modo colapsado, só o ícone do sino (alinhado ao centro, sem label) */
.app[data-sidebar="collapsed"] .sidebar-notif-btn {
    justify-content: center;
    padding: 0;
}
.app[data-sidebar="collapsed"] .sidebar-notif-label {
    display: none;
}

/* Badge de não-lidas (reaproveita .icon-btn-dot da topbar original) */
.sidebar-notif-btn.icon-btn-dot::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 20px;
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--danger);
    border: 2px solid var(--surface);
    box-sizing: content-box;
}
.app[data-sidebar="collapsed"] .sidebar-notif-btn.icon-btn-dot::after {
    top: 6px;
    left: auto;
    right: calc(50% - 14px);
}

/* Dropdown do sino — flutuante à direita da sidebar */
.sidebar-notif-dropdown {
    position: absolute;
    left: calc(100% + 12px);
    bottom: 0;
    width: 320px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
}
.sidebar-notif-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.sidebar-notif-header button {
    font-size: 11px;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
}
.sidebar-notif-dropdown #notifList { padding: var(--space-2); }

.user-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--t) var(--ease);
    width: 100%;
    border: none;
    background: transparent;
    color: inherit;
    text-align: left;
}
.user-card:hover { background: var(--surface-2); }

.user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), #7a00df);
    color: #fff;
    border-radius: var(--radius);
    /* Oculto no menu expandido; reaparece recolhido (único acesso ao menu do usuário) */
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}

.user-meta {
    flex: 1;
    min-width: 0;
    transition: opacity var(--t) var(--ease);
}
.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    font-size: 11px;
    color: var(--text-3);
    text-transform: capitalize;
}

/* --- GLOBAL SEARCH (command palette ⌘K) --- */
/* Gatilho na sidebar é um <button> com a cara de .nav-item */
button.nav-item {
    background: transparent;
    border: none;
    width: 100%;
    font: inherit;
    cursor: pointer;
    text-align: left;
}
.gs-trigger-kbd {
    margin-left: auto;
    font-size: 10px;
    font-family: inherit;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
    white-space: nowrap;
}
.app[data-sidebar="collapsed"] .gs-trigger-kbd { display: none; }

.gs-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 500; /* acima de sidebar (100) e dropdowns (200) */
    padding: 10vh var(--space-4) 0;
}
.gs-overlay[hidden] { display: none; }
.gs-panel {
    max-width: 560px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl, 0 20px 60px rgba(0,0,0,.3));
    overflow: hidden;
    animation: dropdown-in 160ms var(--ease);
}
.gs-input-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
}
.gs-input-row svg {
    width: 18px;
    height: 18px;
    color: var(--text-3);
    flex-shrink: 0;
}
#gsInput {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 16px; /* >=16px evita o zoom automático do iOS no foco */
    color: var(--text);
}
#gsInput::placeholder { color: var(--text-muted); }
/* type=search (anti-gerenciador de senhas): esconde o ✕ nativo do WebKit */
#gsInput::-webkit-search-cancel-button, #gsInput::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.gs-kbd {
    font-size: 10px;
    font-family: inherit;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
    white-space: nowrap;
}
.gs-results {
    max-height: 50vh;
    overflow-y: auto;
    padding: var(--space-2);
}
.gs-hint {
    padding: var(--space-5) var(--space-4);
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}
.gs-cat {
    padding: var(--space-3) var(--space-3) var(--space-1);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-3);
}
.gs-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
}
.gs-item:hover, .gs-item.selected { background: var(--primary-soft); }
.gs-item-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.gs-item-sub {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 45%;
    flex-shrink: 0;
}
.gs-item-ext {
    width: 13px;
    height: 13px;
    color: var(--text-3);
    flex-shrink: 0;
}
@media (max-width: 600px) {
    .gs-overlay { padding-top: 4vh; }
    .gs-item-sub { display: none; }
}

/* --- PAGE TABS (abas de página com contagem; ex.: Clientes → Pessoas | Empresas | Lixeira) --- */
.page-tabs {
    display: flex;
    gap: var(--space-6);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-5);
    flex-wrap: wrap;
}
.page-tab {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 0 2px var(--space-2);
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    text-decoration: none;
    color: var(--text-2);
    font-size: 14px;
    font-weight: 500;
    transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.page-tab-count {
    font-size: 12px;
    color: var(--text-3);
}
.page-tab:hover { color: var(--text); }
.page-tab.active {
    color: var(--text);
    font-weight: 700;
    border-bottom-color: var(--text);
}
.page-tab.active .page-tab-count { color: var(--text-2); }

/* --- MAIN --- */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--t) var(--ease);
}
.app[data-sidebar="collapsed"] .main {
    margin-left: var(--sidebar-w-min);
}

/* --- TOPBAR --- */
.topbar {
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: saturate(180%) blur(10px);
    -webkit-backdrop-filter: saturate(180%) blur(10px);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.topbar-center {
    flex: 1;
    max-width: 480px;
    margin: 0 var(--space-4);
}

.icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    color: var(--text-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
    position: relative;
}
.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text);
}
.icon-btn svg { width: 18px; height: 18px; }

.icon-btn-dot::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 9px;
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--danger);
    border: 2px solid var(--surface);
    box-sizing: content-box;
}

/* Search */
.search {
    position: relative;
    width: 100%;
}
.search-input {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-3) 0 36px;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    transition: border-color var(--t) var(--ease), background var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--border-strong);
    box-shadow: 0 0 0 3px var(--ring);
}
.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--text-3);
    pointer-events: none;
}
.search-kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 10px;
    font-weight: 600;
    color: var(--text-3);
    pointer-events: none;
    font-family: -apple-system, sans-serif;
}

/* ============================================
   FORM PICKER (searchable dropdown que substitui <select>)
   ============================================ */
.hd-picker { position: relative; }
.hd-picker-btn {
    width: 100%;
    display: flex; align-items: center; gap: var(--space-2);
    height: 40px;
    padding: 0 var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px; font-weight: 500; color: var(--text);
    font-family: inherit;
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
    text-align: left;
}
.hd-picker-btn:hover, .hd-picker-btn:focus {
    border-color: var(--primary);
    outline: none;
}
.hd-picker-btn[aria-expanded="true"] {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.hd-picker-btn.hd-picker-btn--invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px var(--danger-soft, rgba(239,68,68,.15));
}
.hd-picker-avatar {
    width: 24px; height: 24px;
    border-radius: 50%;
    background: var(--surface-2);
    color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.hd-picker-avatar svg { width: 14px; height: 14px; }
.hd-picker-avatar--neutral { background: var(--surface-2); color: var(--text-3); }
.hd-picker-avatar--empty {
    background: transparent;
    border: 1px dashed var(--border-2);
}
.hd-picker-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hd-picker-label--placeholder { color: var(--text-3); font-weight: 400; }

/* Variante MULTI (MAX_initMultiPicker): botão cresce com os chips (.badge);
   os checkboxes-fonte ficam em .hd-picker-inputs, sempre escondidos. */
.hd-picker-btn--multi { height: auto; min-height: 40px; flex-wrap: wrap; padding: 6px var(--space-3); }
.hd-picker-chips { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-width: 0; }
.hd-picker-chip-x {
    background: none; border: none; cursor: pointer; color: inherit;
    padding: 0 0 0 2px; font-size: 13px; line-height: 1; font-family: inherit;
}
.hd-picker-chip-x:hover { color: var(--danger); }
.hd-picker-inputs { display: none; }
.hd-picker-chevron { width: 14px; height: 14px; flex-shrink: 0; opacity: .5; }

.hd-picker-dropdown {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    overflow: hidden;
}
.hd-picker-dropdown[hidden] { display: none; }

.hd-picker-search-wrap {
    padding: var(--space-2);
    border-bottom: 1px solid var(--border);
}
.hd-picker-search-wrap > div {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--surface-2);
    border-radius: var(--radius);
}
.hd-picker-search-wrap svg { width: 14px; height: 14px; color: var(--text-3); flex-shrink: 0; }
.hd-picker-search-input {
    border: none; background: transparent; outline: none;
    font-size: 13px; color: var(--text); width: 100%;
    font-family: inherit;
}

.hd-picker-list {
    max-height: 280px; overflow-y: auto;
    padding: var(--space-1);
}
.hd-picker-item {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
    transition: background var(--t) var(--ease);
    cursor: pointer;
}
.hd-picker-item:hover { background: var(--surface-2); }
.hd-picker-item--active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.hd-picker-item--active:hover { background: var(--primary-soft); }
.hd-picker-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hd-picker-check { width: 14px; height: 14px; color: var(--primary); flex-shrink: 0; }
/* [hidden] em SVG: o display:none do UA stylesheet só vale para elementos HTML —
   sem esta regra o check aparecia em TODAS as linhas do picker. */
.hd-picker-check[hidden] { display: none; }
/* Cabeçalho de seção dentro do picker — para listas longas que já vinham
   agrupadas no <select> (optgroup), como o plano de categorias do financeiro.
   O filtro da busca esconde o cabeçalho que fica sem itens (ver app.js). */
.hd-picker-group {
    padding: var(--space-2) var(--space-3) var(--space-1);
    font-size: 10.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-3);
}
.hd-picker-group + .hd-picker-item { margin-top: 0; }
.hd-picker-empty {
    padding: var(--space-4);
    text-align: center;
    font-size: 13px;
    color: var(--text-3);
}

/* Client selection grid (step 0 in modules) */
.client-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: var(--space-3);
}
.client-select-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--t) var(--ease);
    font-family: inherit;
    text-align: left;
}
.client-select-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.client-select-card.active {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.client-select-avatar {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    border-radius: var(--radius-md);
    color: var(--primary);
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}
.client-select-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

@keyframes dropdown-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* User menu (in topbar) */
.user-menu { position: relative; }
.user-menu-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 240px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    padding: var(--space-1);
    animation: dropdown-in 180ms var(--ease);
}
.user-menu-dropdown[hidden] { display: none; }

.user-menu-header {
    padding: var(--space-3) var(--space-3) var(--space-3);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-1);
}
.user-menu-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.user-menu-email {
    font-size: 11px;
    color: var(--text-3);
    margin-top: 2px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
    cursor: pointer;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    font-family: inherit;
}
.menu-item:hover {
    background: var(--surface-2);
    color: var(--text);
}
.menu-item-icon {
    width: 16px;
    height: 16px;
    color: var(--text-3);
    flex-shrink: 0;
}
.menu-item-divider {
    height: 1px;
    background: var(--border);
    margin: var(--space-1) 0;
}
.menu-item-danger { color: var(--danger); }
.menu-item-danger:hover { background: var(--danger-soft); color: var(--danger); }
.menu-item-danger .menu-item-icon { color: var(--danger); }

/* Theme toggle (icon swap) */
.theme-toggle [data-theme-icon-light] { display: none; }
.theme-toggle [data-theme-icon-dark]  { display: block; }
[data-theme="dark"] .theme-toggle [data-theme-icon-light] { display: block; }
[data-theme="dark"] .theme-toggle [data-theme-icon-dark]  { display: none; }

/* --- CONTENT --- */
.content {
    flex: 1;
    padding: var(--space-8) var(--space-6);
    max-width: var(--content-max);
    width: 100%;
    margin: 0 auto;
}

/* Módulo helpdesk: área mais larga pra acomodar layout 2-col (main + activity) */
.content--helpdesk {
    max-width: 1400px;
}

/* ============================================
   6. PAGE HEADER
   ============================================ */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}
.page-header-actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

.page-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.page-subtitle {
    font-size: 14px;
    color: var(--text-3);
    margin-top: var(--space-1);
    line-height: 1.5;
}

/* ============================================
   7. BUTTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 36px;
    padding: 0 var(--space-4);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--t) var(--ease), border-color var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease), transform var(--t-fast) var(--ease);
    white-space: nowrap;
    text-decoration: none;
    user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled, .btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}
.btn svg { width: 16px; height: 16px; }

.btn-primary {
    background: var(--primary);
    color: var(--primary-fg);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(99, 102, 241, 0.2);
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--ring);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-2);
    box-shadow: var(--shadow-xs);
}
.btn-secondary:hover {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.btn-ghost {
    background: transparent;
    color: var(--text-2);
}
.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: transparent;
}
.btn-danger:hover {
    background: var(--danger);
    color: #fff;
}

.btn-success {
    background: var(--success-soft);
    color: var(--success);
    border-color: transparent;
}
.btn-success:hover {
    background: var(--success);
    color: #fff;
}

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: 12px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 44px; padding: 0 var(--space-6); font-size: 14px; }
.btn-icon { width: 36px; padding: 0; }
.btn-block { width: 100%; }

/* ============================================
   8. CARDS
   ============================================ */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}
.card-padded { padding: var(--space-6); }
.card-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
}
.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.card-subtitle {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
}
.card-body { padding: var(--space-6); }
.card-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    background: var(--surface-2);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

/* ============================================
   9. FORMS
   ============================================ */
.form-group { margin-bottom: var(--space-5); }
.form-group:last-child { margin-bottom: 0; }

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: var(--space-2);
}
.form-help {
    font-size: 12px;
    color: var(--text-3);
    margin-top: var(--space-1);
}

.form-control {
    width: 100%;
    height: 38px;
    padding: 0 var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
.form-control:disabled {
    background: var(--surface-2);
    color: var(--text-3);
    cursor: not-allowed;
}

textarea.form-control {
    min-height: 96px;
    padding: var(--space-3);
    resize: vertical;
    line-height: 1.6;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 14px;
    padding-right: 36px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

/* Radio cards */
.radio-group {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
}
.radio-card {
    flex: 1;
    min-width: 140px;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    transition: border-color var(--t) var(--ease), background var(--t) var(--ease), color var(--t) var(--ease);
}
.radio-card:hover { border-color: var(--border-strong); }
.radio-card input { display: none; }
.radio-card:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
}
.radio-card-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ============================================
   10. TABLES
   ============================================ */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-lg);
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    text-align: left;
    padding: var(--space-3) var(--space-4);
    background: var(--surface-2);
    color: var(--text-3);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    color: var(--text-2);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background var(--t) var(--ease); }
tbody tr:hover { background: var(--surface-2); }

/* ============================================
   11. BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    height: 22px;
    padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-dot::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: currentColor;
}

/* ============================================
   12. ALERTS
   ============================================ */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid;
    font-size: 13px;
    margin-bottom: var(--space-5);
}
.alert + .page-header {
    margin-top: calc(-1 * var(--space-3));
}
.alert-success {
    background: var(--success-soft);
    border-color: var(--success);
    color: var(--success);
}
.alert-danger {
    background: var(--danger-soft);
    border-color: var(--danger);
    color: var(--danger);
}
.alert-info {
    background: var(--info-soft);
    border-color: var(--info);
    color: var(--info);
}
.alert-icon { flex-shrink: 0; width: 16px; height: 16px; margin-top: 1px; }
.alert-body { flex: 1; line-height: 1.5; }
.alert-body strong { font-weight: 600; }

/* ============================================
   13. EMPTY STATE
   ============================================ */
.empty {
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--text-3);
}
.empty-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto var(--space-4);
    background: var(--surface-2);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-3);
}
.empty-icon svg { width: 24px; height: 24px; }
.empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-2);
}
.empty-description {
    font-size: 14px;
    color: var(--text-3);
    max-width: 360px;
    margin: 0 auto var(--space-5);
    line-height: 1.6;
}

/* ============================================
   14. SPINNER & LOADING
   ============================================ */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
    background-size: 200% 100%;
    animation: skeleton 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ============================================
   15. TOAST
   ============================================ */
#toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-3) var(--space-4);
    font-size: 13px;
    color: var(--text);
    min-width: 280px;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    pointer-events: all;
    animation: toast-in 220ms var(--ease);
}
.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-error .toast-icon   { color: var(--danger); }
.toast-info    { border-left: 3px solid var(--info); }
.toast-info .toast-icon    { color: var(--info); }
.toast-warning { border-left: 3px solid var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-out { animation: toast-out 200ms var(--ease) forwards; }
@keyframes toast-in {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}

/* ============================================
   16. MODAL
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t) var(--ease);
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(-12px) scale(0.98);
    transition: transform var(--t) var(--ease);
    box-shadow: var(--shadow-xl);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}
.modal-close {
    background: transparent;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    color: var(--text-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close svg { width: 16px; height: 16px; }
.modal-body { padding: var(--space-6); }
.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    background: var(--surface-2);
    border-bottom-left-radius: var(--radius-xl);
    border-bottom-right-radius: var(--radius-xl);
}

/* ============================================
   17. TOGGLE SWITCH
   ============================================ */
.switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.switch input { display: none; }
.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-3);
    border-radius: var(--radius-full);
    transition: background var(--t) var(--ease);
    cursor: pointer;
}
.switch-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--t) var(--ease);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }

/* ============================================
   18. MODULE: PUBLISHER (WordPress Post)
   ============================================ */

/* Steps indicator */
.steps {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-8);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-3);
    flex-shrink: 0;
}
.step-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--text-3);
    border: 1px solid var(--border-2);
    transition: all var(--t) var(--ease);
}
.step.active { color: var(--primary); }
.step.active .step-num {
    background: var(--primary);
    color: var(--primary-fg);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.step.done .step-num {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.step-divider {
    flex: 1;
    height: 1px;
    background: var(--border);
    min-width: 24px;
}

/* Drop zone */
.dropzone {
    border: 2px dashed var(--border-2);
    border-radius: var(--radius-lg);
    padding: var(--space-12) var(--space-6);
    text-align: center;
    cursor: pointer;
    transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
    position: relative;
    background: var(--surface);
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.dropzone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}
.dropzone-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-4);
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.dropzone-icon svg { width: 24px; height: 24px; }
.dropzone-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-1);
}
.dropzone-sub {
    font-size: 13px;
    color: var(--text-3);
}
.dropzone-types {
    margin-top: var(--space-3);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Selected file pill */
.file-pill {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--primary-soft);
    border-radius: var(--radius);
    color: var(--primary);
    font-size: 13px;
    font-weight: 500;
    margin-top: var(--space-4);
}
.file-pill svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Editor */
.editor {
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    padding: var(--space-5);
    min-height: 320px;
    max-height: 520px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    outline: none;
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
.editor h2, .editor h3 {
    margin: var(--space-4) 0 var(--space-2);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.editor h2 { font-size: 18px; }
.editor h3 { font-size: 16px; }
.editor p { margin-bottom: var(--space-3); }
.editor strong { font-weight: 600; color: var(--text); }
.editor a { color: var(--primary); text-decoration: underline; }

/* Image preview */
.image-preview {
    position: relative;
    display: inline-block;
    margin-top: var(--space-3);
}
.image-preview img {
    width: 100%;
    max-width: 320px;
    height: 180px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.image-preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--danger);
    color: #fff;
    border: 2px solid var(--surface);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
}
.image-preview-remove svg { width: 12px; height: 12px; }

/* Success card */
.success-card {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}
.success-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-5);
    background: var(--success-soft);
    color: var(--success);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}
.success-icon svg { width: 32px; height: 32px; }
.success-card h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-2);
    letter-spacing: -0.01em;
}
.success-card p {
    color: var(--text-3);
    font-size: 14px;
    margin-bottom: var(--space-6);
}
.success-actions {
    display: flex;
    gap: var(--space-3);
    justify-content: center;
    flex-wrap: wrap;
}

/* ============================================
   19. ADMIN — Client cards
   ============================================ */
.client-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-3);
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.client-card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}
.client-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
}
.client-card-info {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.client-card-avatar {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #7a00df);
    color: #fff;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
    letter-spacing: 0.02em;
}
.client-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}
.client-card-slug {
    font-size: 12px;
    color: var(--text-3);
    margin-top: 2px;
    font-family: ui-monospace, monospace;
}
.client-card-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.creds-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}
.cred-item {
    font-size: 12px;
}
.cred-label {
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 2px;
}
.cred-value {
    font-size: 12px;
    color: var(--text-2);
    word-break: break-all;
}
.cred-value.has-value { color: var(--success); }
.cred-value.no-value  { color: var(--text-muted); }

/* Input tabs (texto/arquivo) */
.input-tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-5);
    background: var(--surface-2);
    border-radius: var(--radius);
    padding: var(--space-1);
}
.input-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-3);
    cursor: pointer;
    transition: background var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.input-tab svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}
.input-tab:hover {
    color: var(--text);
}
.input-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ============================================
   20. LOGIN PAGE
   ============================================ */
@keyframes auth-float {
    0%, 100% { transform: translate(0, 0); }
    50%      { transform: translate(0, -30px); }
}
@keyframes auth-fade-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    position: relative;
    overflow: hidden;
    isolation: isolate;
    background:
        linear-gradient(rgba(0, 124, 186, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 124, 186, 0.03) 1px, transparent 1px),
        radial-gradient(circle at 0% 0%, rgba(0, 124, 186, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(122, 0, 223, 0.12) 0%, transparent 50%),
        var(--bg);
    background-size: 40px 40px, 40px 40px, 100% 100%, 100% 100%, 100% 100%;
}
.auth-page::before,
.auth-page::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    pointer-events: none;
    z-index: 0;
    animation: auth-float 30s ease-in-out infinite;
}
.auth-page::before {
    width: 500px;
    height: 500px;
    top: -10%;
    right: -5%;
    background: rgba(0, 124, 186, 0.08);
}
.auth-page::after {
    width: 400px;
    height: 400px;
    bottom: -10%;
    left: -5%;
    background: rgba(122, 0, 223, 0.06);
    animation-delay: -15s;
}

.auth-wrapper {
    width: 100%;
    max-width: 400px;
    position: relative;
    z-index: 1;
    animation: auth-fade-in 0.6s var(--ease) both;
}
.auth-brand {
    text-align: center;
    margin-bottom: var(--space-10);
}
.auth-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
    margin-bottom: var(--space-2);
}
.auth-logo-img {
    height: 48px;
    width: auto;
    display: block;
    transition: transform var(--t) var(--ease);
}
.auth-logo:hover .auth-logo-img {
    transform: scale(1.05);
}
.auth-logo .sidebar-logo-mark {
    width: 48px;
    height: 48px;
    font-size: 18px;
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35), 0 0 0 4px var(--primary-soft);
    transition: transform var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.auth-logo:hover .sidebar-logo-mark {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4), 0 0 0 4px var(--primary-glow);
}
.auth-tagline {
    font-size: 13px;
    color: var(--text-3);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 500;
    margin-top: var(--space-2);
}
.auth-card {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid var(--border);
    border-top: 2px solid var(--primary);
    border-radius: var(--radius-2xl);
    padding: var(--space-10);
    box-shadow: var(--shadow-xl);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.auth-card h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: var(--space-1);
    letter-spacing: -0.01em;
}
.auth-card-subtitle {
    font-size: 13px;
    color: var(--text-3);
    font-weight: 400;
    margin-bottom: var(--space-6);
}

/* Auth — Input with icon */
.auth-input-wrap {
    position: relative;
}
.auth-input-wrap .form-control {
    padding-left: 40px;
    height: 44px;
    font-size: 14px;
    border-radius: var(--radius-md);
    background: var(--surface-2);
    border-color: transparent;
    transition: background var(--t) var(--ease), border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.auth-input-wrap .form-control:focus {
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
.auth-input-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
    transition: color var(--t) var(--ease);
}
.auth-input-wrap:focus-within .auth-input-icon {
    color: var(--primary);
}

/* Auth — Submit button */
.auth-card .btn-primary.btn-lg {
    height: 48px;
    font-size: 15px;
    font-weight: 600;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary), #7a00df);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    margin-top: var(--space-4);
    transition: box-shadow var(--t) var(--ease), transform var(--t-fast) var(--ease);
}
.auth-card .btn-primary.btn-lg:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}
.auth-card .btn-primary.btn-lg:active {
    transform: translateY(0) scale(0.98);
}

/* Auth — Link (esqueci senha, voltar) */
.auth-link {
    text-align: center;
    margin-top: var(--space-5);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}
.auth-link a {
    font-size: 13px;
    color: var(--primary);
    font-weight: 500;
    transition: color var(--t) var(--ease);
}
.auth-link a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.auth-footer {
    text-align: center;
    margin-top: var(--space-6);
    padding-top: var(--space-4);
    color: var(--text-muted);
    font-size: 12px;
}
.auth-footer a {
    color: var(--primary);
    font-weight: 500;
    transition: color var(--t) var(--ease);
}
.auth-footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Auth — Dark mode */
[data-theme="dark"] .auth-card {
    background: rgba(17, 17, 17, 0.85);
    border-color: var(--border-2);
    border-top-color: var(--primary);
}
[data-theme="dark"] .auth-page::before {
    background: rgba(77, 184, 232, 0.06);
}
[data-theme="dark"] .auth-page::after {
    background: rgba(122, 0, 223, 0.05);
}
[data-theme="dark"] .auth-page {
    background:
        linear-gradient(rgba(77, 184, 232, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(77, 184, 232, 0.02) 1px, transparent 1px),
        radial-gradient(circle at 0% 0%, rgba(77, 184, 232, 0.12) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(122, 0, 223, 0.08) 0%, transparent 50%),
        var(--bg);
    background-size: 40px 40px, 40px 40px, 100% 100%, 100% 100%, 100% 100%;
}

/* ============================================
   21. RESPONSIVE
   ============================================ */

/* Botão flutuante do hamburger — substitui a topbar em mobile */
.sidebar-mobile-float-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 110;
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    color: var(--text);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background var(--t) var(--ease), transform var(--t) var(--ease);
}
.sidebar-mobile-float-btn svg { width: 22px; height: 22px; }
.sidebar-mobile-float-btn:hover { background: var(--surface-2); }
.sidebar-mobile-float-btn:active { transform: scale(0.95); }

@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-w) !important;
    }
    .app[data-sidebar-mobile="open"] .sidebar {
        transform: translateX(0);
        box-shadow: var(--shadow-xl);
    }
    /* Backdrop escuro atrás da sidebar quando aberta — reforço visual e alvo de clique pra fechar */
    .app[data-sidebar-mobile="open"]::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 99;
        animation: sidebarBackdropFade var(--t) var(--ease);
    }
    @keyframes sidebarBackdropFade {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    .app[data-sidebar-mobile="open"] .sidebar-section-title,
    .app[data-sidebar-mobile="open"] .nav-item-label,
    .app[data-sidebar-mobile="open"] .user-meta {
        opacity: 1 !important;
        pointer-events: all !important;
        width: auto !important;
    }
    .app[data-sidebar-mobile="open"] .sidebar-header {
        justify-content: space-between !important;
        padding: 0 var(--space-5) !important;
    }
    .app[data-sidebar-mobile="open"] .nav-item {
        justify-content: flex-start !important;
        padding: 0 var(--space-3) !important;
    }
    .main { margin-left: 0 !important; }
    .sidebar-collapse-btn { display: none; }

    /* Botão flutuante aparece apenas em mobile */
    .sidebar-mobile-float-btn { display: flex; }
    /* Esconde o botão quando a sidebar mobile está aberta (evita sobreposição) */
    .app[data-sidebar-mobile="open"] .sidebar-mobile-float-btn { display: none; }

    /* Espaço superior pra não colar no hamburger flutuante (42px + 12px topo + 8px respiro) */
    .content { padding: 64px var(--space-4) var(--space-6); }
    .form-row { grid-template-columns: 1fr; }
    .creds-grid { grid-template-columns: 1fr; gap: var(--space-2); }
}

@media (max-width: 540px) {
    .page-header { flex-direction: column; align-items: flex-start; }
    .step-label { display: none; }

    .auth-card { padding: var(--space-6); border-radius: var(--radius-xl); }
    .auth-logo { font-size: 24px; }
    .auth-logo .sidebar-logo-mark { width: 40px; height: 40px; font-size: 16px; }
    .auth-logo-img { height: 40px; }
}

/* ============================================
   22. SOCIAL PUBLISHER
   ============================================ */

/* Format selection cards */
.format-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}
.format-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-5);
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease), background var(--t) var(--ease);
    text-align: center;
}
.format-card:hover {
    border-color: var(--border-2);
    background: var(--surface-2);
}
.format-card.active {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 0 0 3px var(--ring);
}
.format-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.format-card-desc {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.4;
}

/* Briefing output */
.briefing-output {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.7;
    color: var(--text);
    max-height: 500px;
    overflow-y: auto;
}

/* Social loading spinner */
.social-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-10) 0;
    color: var(--text-3);
    font-size: 14px;
}
.social-loading[hidden] { display: none !important; }

@media (max-width: 540px) {
    .format-cards { grid-template-columns: 1fr; }
    .format-card { padding: var(--space-6) var(--space-4); }
}

/* ============================================
   23. UTILITIES
   ============================================ */
.flex      { display: flex; }
.flex-col  { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.mt-3  { margin-top: var(--space-3); }
.mt-4  { margin-top: var(--space-4); }
.mb-4  { margin-bottom: var(--space-4); }
.text-sm    { font-size: 12px; }
.text-muted { color: var(--text-3); }
.hidden { display: none !important; }

/* Tooltip do menu recolhido (criado via JS em app.js) */
.sidebar-tooltip {
    position: fixed;
    transform: translateY(-50%);
    background: var(--text);
    color: var(--surface);
    font-size: 12px;
    font-weight: 600;
    padding: 6px 11px;
    border-radius: 7px;
    white-space: nowrap;
    z-index: 3000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.sidebar-tooltip::before {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: var(--text);
}

/* ============================================
   TENANT SWITCHER (seletor de tenant — só super-admin)
   Fica antes do "Pesquisar" na sidebar. Markup em includes/sidebar-body.php,
   gate/lista em includes/tenant-switcher.php, troca em trocar-tenant.php.
   ============================================ */
.tsw { position: relative; }

.tsw-trigger .tsw-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    opacity: .55;
    transition: transform var(--t) var(--ease);
}
.tsw-trigger[aria-expanded="true"] .tsw-chevron { transform: rotate(180deg); }
.tsw-trigger[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }

/* Avatar com as iniciais do tenant */
.tsw-avatar {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border-radius: 5px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .2px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

/* Ícone cadastrado do tenant (admin/tenant-edit.php). Sem ícone, o PHP
   renderiza as iniciais no mesmo lugar — daí as duas regras casarem em tamanho. */
.tsw-avatar-img {
    object-fit: cover;
    background: var(--surface-2);
    padding: 0;
}

/* No painel o avatar é maior: logo de 18px não se lê */
.tsw-item .tsw-avatar { width: 24px; height: 24px; border-radius: 6px; font-size: 10px; }

/* Painel */
.tsw-menu {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 120;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .14);
    padding: 4px;
    max-height: 360px;
    display: flex;
    flex-direction: column;
}
.tsw-menu[hidden] { display: none; }
/* Título + busca ficam fixos; só a lista rola */
.tsw-menu-head { flex-shrink: 0; }
.tsw-menu-list { flex: 1; min-height: 0; overflow-y: auto; }
.tsw-search {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 4px 6px;
    padding: 0 8px;
    height: 30px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.tsw-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.tsw-search svg { width: 13px; height: 13px; flex-shrink: 0; }
.tsw-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    outline: none;
    font: inherit;
    font-size: 12.5px;
    color: var(--text);
    padding: 0;
}
.tsw-search-input::placeholder { color: var(--text-muted); }
.tsw-search-input::-webkit-search-cancel-button { -webkit-appearance: none; }
.tsw-menu-empty {
    padding: 10px 8px 8px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}
.tsw-menu-empty[hidden], .tsw-form[hidden], .tsw-item[hidden] { display: none; }
.tsw-menu-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--text-muted);
    padding: 6px 8px 4px;
}
.tsw-form { margin: 0; }

.tsw-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    padding: 7px 8px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-align: left;
    color: var(--text-2);
    font-size: 13px;
    transition: background var(--t) var(--ease), color var(--t) var(--ease);
}
.tsw-item:hover { background: var(--surface-2); color: var(--text); }
.tsw-item.is-atual { cursor: default; color: var(--text); }
.tsw-item.is-atual:hover { background: transparent; }
.tsw-item.is-atual svg { width: 14px; height: 14px; color: var(--primary); flex-shrink: 0; }

.tsw-item-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.tsw-item-nome {
    font-weight: 600;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tsw-item-sub {
    font-size: 10px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Menu recolhido: o painel sai flutuando ao lado do ícone */
.app[data-sidebar="collapsed"] .tsw-trigger .tsw-chevron { display: none; }
.app[data-sidebar="collapsed"] .tsw-menu {
    left: calc(100% + 8px);
    right: auto;
    top: 0;
    width: 230px;
}

/* ============================================
   MODULE SETTINGS (engrenagem + abas)
   Padrão da casa: cada módulo tem UMA engrenagem no canto superior direito que
   leva às suas telas de configuração, navegáveis por abas.
   Markup em includes/module-settings.php.
   ============================================ */
.mset-gear { gap: 6px; }
.mset-gear svg { width: 15px; height: 15px; flex-shrink: 0; }
/* Variante só-ícone (3º argumento de max_settings_gear): quadrada na altura do
   btn-sm — o rótulo "Configurações" fica no tooltip/aria-label. */
.mset-gear.btn-icon { width: 30px; gap: 0; }

.mset-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.mset-tabs::-webkit-scrollbar { display: none; }

.mset-tab {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-2);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    transition: color var(--t) var(--ease), border-color var(--t) var(--ease);
}
.mset-tab:hover { color: var(--text); }
.mset-tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }

@media (max-width: 640px) {
    .mset-gear-txt { display: none; }
    .mset-tab { padding: 10px 12px; font-size: 13px; }
}

/* ============================================
   DASHBOARD — HUB DE MÓDULOS (cards + widgets)
   Um card por ferramenta liberada. O card inteiro é clicável: o link "Acessar"
   se estica por baixo dele (::after). Os atalhos do widget ficam ACIMA dessa
   camada e levam direto ao filtro certo dentro do módulo.
   Markup em dashboard.php + includes/dashboard-widgets.php.
   ============================================ */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-5);
}

.module-card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding: var(--space-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    transition: border-color var(--t) var(--ease),
                box-shadow var(--t) var(--ease),
                transform var(--t) var(--ease);
}
.module-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
/* Teclado: o foco vai para o link esticado, então o anel vai no card. */
.module-card:has(.module-card-cta:focus-visible) {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}

/* Cabeçalho do card: ícone à esquerda, título+descrição na coluna ao lado.
   Empilhados, o texto ficava abaixo do ícone e a faixa à direita dele sobrava
   vazia — o card crescia em altura sem usar a largura. */
.module-card-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
}
.module-card-head-txt {
    flex: 1;
    min-width: 0;   /* deixa o texto quebrar em vez de esticar o card */
}

.module-card-icon {
    width: 48px;
    height: 48px;
    flex-shrink: 0;   /* em linha, o ícone não pode ser espremido pelo texto */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    border-radius: var(--radius-md);
    color: var(--primary);
    transition: background var(--t) var(--ease);
}
.module-card-icon svg { width: 24px; height: 24px; }
.module-card:hover .module-card-icon { background: var(--primary-glow); }

.module-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-1);
}
.module-card-desc {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-3);
}

.module-card-cta {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: auto;
    font-size: 13px;
    font-weight: 500;
    color: var(--primary);
}
.module-card-cta svg { width: 16px; height: 16px; }
/* Camada que torna o card inteiro clicável. */
.module-card-cta::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
}

/* --- Números do widget --- */
/* Envelope de qualquer desenho de widget: fica ACIMA da camada clicável do
   "Acessar", senão o card inteiro engoliria o clique dos atalhos. */
.mcard-widget {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Desenho (a): ladrilhos de mesmo peso, lado a lado. */
.mcard-stats {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: var(--space-2);
}

/* Ladrilho e destaque compartilham a caixa; muda o tamanho do número. */
.mcard-stat,
.mcard-hero {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
a.mcard-stat:hover,
a.mcard-hero:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
}
a.mcard-stat:focus-visible,
a.mcard-hero:focus-visible,
a.mcard-line:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.mcard-stat-val {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.mcard-stat-lbl,
.mcard-hero-lbl {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-3);
}

/* Desenho (b): o número que cobra ação, grande, e a fila miúda embaixo. */
.mcard-hero { padding: var(--space-4); }
.mcard-hero-val {
    font-size: 34px;
    font-weight: 700;
    line-height: 1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}
.mcard-hero-lbl { font-size: 12px; }

.mcard-lines {
    display: flex;
    flex-direction: column;
}
.mcard-line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 3px 2px;
    font-size: 11.5px;
    line-height: 1.4;
    border-radius: var(--radius-xs);
}
.mcard-line + .mcard-line { border-top: 1px solid var(--border); }
.mcard-line-lbl { color: var(--text-3); }
.mcard-line-val {
    font-weight: 700;
    color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
a.mcard-line:hover .mcard-line-lbl,
a.mcard-line:hover .mcard-line-val { color: var(--primary); }

/* Desenho (c): prévia de registros — miniatura, nome e número. */
.mcard-itens {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}
.mcard-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    min-width: 0;
    transition: background var(--t) var(--ease), border-color var(--t) var(--ease);
}
a.mcard-item:hover {
    background: var(--surface-2);
    border-color: var(--border);
}
a.mcard-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.mcard-item-fig {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.mcard-item-fig img { width: 100%; height: 100%; object-fit: contain; }
.mcard-item-ini {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
}

.mcard-item-lbl {
    flex: 1;
    min-width: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
a.mcard-item:hover .mcard-item-lbl { color: var(--text); }
.mcard-item-val {
    flex-shrink: 0;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
}

/* Tom: só acende com valor > 0 (a regra está em includes/dashboard-widgets.php).
   A cor fica no fundo e na borda; o número segue em --text para não perder
   contraste em nenhum dos dois temas. */
.mcard-stat.is-warning, .mcard-hero.is-warning { background: var(--warning-soft); border-color: var(--warning); }
.mcard-stat.is-danger,  .mcard-hero.is-danger  { background: var(--danger-soft);  border-color: var(--danger);  }
.mcard-stat.is-success, .mcard-hero.is-success { background: var(--success-soft); border-color: var(--success); }
.mcard-stat.is-info,    .mcard-hero.is-info    { background: var(--info-soft);    border-color: var(--info);    }
.mcard-stat.is-warning .mcard-stat-lbl, .mcard-hero.is-warning .mcard-hero-lbl,
.mcard-stat.is-danger  .mcard-stat-lbl, .mcard-hero.is-danger  .mcard-hero-lbl,
.mcard-stat.is-success .mcard-stat-lbl, .mcard-hero.is-success .mcard-hero-lbl,
.mcard-stat.is-info    .mcard-stat-lbl, .mcard-hero.is-info    .mcard-hero-lbl { color: var(--text-2); }

a.mcard-stat.is-warning:hover, a.mcard-hero.is-warning:hover { background: var(--warning-soft); filter: brightness(0.97); }
a.mcard-stat.is-danger:hover,  a.mcard-hero.is-danger:hover  { background: var(--danger-soft);  filter: brightness(0.97); }
a.mcard-stat.is-success:hover, a.mcard-hero.is-success:hover { background: var(--success-soft); filter: brightness(0.97); }
a.mcard-stat.is-info:hover,    a.mcard-hero.is-info:hover    { background: var(--info-soft);    filter: brightness(0.97); }

@media (prefers-reduced-motion: reduce) {
    .module-card:hover { transform: none; }
}

/* ============================================
   26. TABELAS — cabeçalho, hover e linha marcada        (07/09/2026)
   O cabeçalho e o hover usavam --surface-2, que no tema claro é EXATAMENTE a
   mesma cor de --bg (#f2f2f2): sobre o card branco o cabeçalho quase sumia,
   passar o mouse não dizia nada e, contra o fundo da página, a faixa de título
   desaparecia de vez. Aqui os três estados ganham tokens próprios, um valor por
   tema. A cor da linha marcada sai da cor da marca do tenant (color-mix), com
   fallback em rgba para navegador antigo — assim cada tenant se reconhece.
   ============================================ */
:root {
    --thead-bg:   #e9ebef;
    --thead-fg:   #4b5563;
    --thead-line: #d3d7de;
    --row-hover:  #eef1f6;
    --row-sel:    rgba(0, 124, 186, 0.14);
    --row-sel:    color-mix(in srgb, var(--primary) 15%, var(--surface));
    --row-sel-line: rgba(0, 124, 186, 0.28);
}
[data-theme="dark"] {
    --thead-bg:   #1c1c22;
    --thead-fg:   #b4b4be;
    --thead-line: #2e2e36;
    --row-hover:  #191920;
    --row-sel:    rgba(77, 184, 232, 0.20);
    --row-sel:    color-mix(in srgb, var(--primary) 24%, var(--surface));
    --row-sel-line: rgba(77, 184, 232, 0.36);
}

thead th {
    background: var(--thead-bg);
    color: var(--thead-fg);
    border-bottom: 1px solid var(--thead-line);
    font-size: 11.5px;
    letter-spacing: 0.05em;
}
tbody tr:hover { background: var(--row-hover); }

/* Linha marcada pinta o TD (e não o TR): a célula tem fundo próprio no hover e
   ganharia da regra da linha, fazendo a marcação sumir sob o mouse. */
tbody tr.lvsel-on td,
tbody tr.lvsel-on:hover td { background: var(--row-sel); }
tbody tr.lvsel-on td:first-child { box-shadow: inset 3px 0 0 var(--primary); }

@media print {
    thead th { background: transparent; border-bottom: 1px solid #999; color: #000; }
}
