/* Sistema Contaf — tema claro/escuro + admin */

:root,
[data-theme="dark"] {
    --primary-color: #4a90e2;
    --primary-dark: #357abd;
    --secondary-color: #7b68ee;
    --success-color: #52c41a;
    --warning-color: #faad14;
    --danger-color: #ff4d4f;
    --bg-dark: #1a1a1a;
    --bg-darker: #0f1218;
    --bg-card: #252525;
    --bg-hover: #2d2d2d;
    --text-primary: #f0f2f5;
    --text-secondary: #b3b3b3;
    --text-muted: #808080;
    --border-color: #404040;
    --border-light: #333333;
    --page-bg: linear-gradient(165deg, #0c1018 0%, #141a22 50%, #0f1419 100%);
    --topbar-bg: rgba(20, 24, 32, 0.92);
    --dash-hero-bg: linear-gradient(90deg, #2563eb 0%, #1d4ed8 28%, #0f172a 100%);
    --dash-hero-text: #ffffff;
    --module-card-bg: rgba(255, 255, 255, 0.06);
    --module-card-border: rgba(255, 255, 255, 0.12);
    --module-card-hover: rgba(74, 144, 226, 0.18);
    --module-soon-bg: rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
    --primary-color: #0066cc;
    --primary-dark: #004c99;
    --secondary-color: #5c4cdb;
    --success-color: #389e0d;
    --warning-color: #d48806;
    --danger-color: #cf1322;
    --bg-dark: #f5f7fa;
    --bg-darker: #e8eef5;
    --bg-card: #ffffff;
    --bg-hover: #eef2f7;
    --text-primary: #1a1d24;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --border-color: #d9e2ec;
    --border-light: #e2e8f0;
    --page-bg: linear-gradient(180deg, #dce8f5 0%, #e8eef5 40%, #f0f4f8 100%);
    --topbar-bg: rgba(255, 255, 255, 0.92);
    --dash-hero-bg: linear-gradient(90deg, #0ea5e9 0%, #0284c7 32%, #1e3a5f 72%, #0f172a 100%);
    --dash-hero-text: #ffffff;
    --module-card-bg: #ffffff;
    --module-card-border: rgba(0, 0, 0, 0.08);
    --module-card-hover: rgba(0, 145, 255, 0.12);
    --module-soon-bg: #f0f4f8;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-darker);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.portal-body {
    background: var(--page-bg);
    color: var(--text-primary);
    min-height: 100vh;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .app-topbar {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.app-topbar--module {
    flex-wrap: wrap;
    row-gap: 10px;
}

.module-nav-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px 20px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

/* Logo + nome: sempre colado à esquerda do cabeçalho */
.app-brand--home {
    flex-shrink: 0;
    margin-right: 4px;
}

.module-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Ordem fixa: BPA → Laboratório → CNES → RBAC */
.module-nav--fixed {
    flex-wrap: nowrap;
}

.module-nav--fixed .nav-module--bpa {
    order: 1;
}

.module-nav--fixed .nav-module--lab {
    order: 2;
}

.module-nav--fixed .nav-module--cnes {
    order: 3;
}

.module-nav--fixed .nav-module--rbac {
    order: 4;
}

.nav-module-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.nav-module-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.nav-module-btn.is-active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-hover);
}

.auth-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.auth-inline.auth-inline--compact input {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-dark);
    color: var(--text-primary);
    font-size: 0.85rem;
    min-width: 90px;
    max-width: 140px;
}

.auth-inline.auth-inline--compact button {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.auth-inline.auth-inline--compact button:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.topbar-user[hidden],
.auth-inline[hidden] {
    display: none !important;
}

.app-shell > .container {
    flex: 1;
    min-height: 0;
}

.app-shell .container {
    min-height: auto;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 700;
    font-size: 1.05rem;
}

.app-brand-mark {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #2563eb 0%, #5b4cdb 48%, #312e81 100%);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.app-brand-diamond {
    position: absolute;
    width: 11px;
    height: 11px;
    background: #fff;
    border-radius: 2px;
    transform: rotate(45deg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn-theme {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-theme:hover {
    background: var(--module-card-hover);
    color: var(--text-primary);
}

.btn-theme:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Alternador pílula (modelo claro/escuro: trilho + knob + sol / lua e estrelas) */
.btn-theme.btn-theme--pill {
    /* Cápsula dimensionada para sol/lua +50% (slots 27px / SVG 26+18) */
    --theme-pill-w: 92px;
    --theme-pill-h: 34px;
    --theme-pill-knob: 20px;
    --theme-pill-pad: 2px;
    --theme-pill-icon-gap: 3px;
    width: auto;
    min-width: calc(var(--theme-pill-w) + 14px);
    height: 44px;
    padding: 0 8px;
    border-radius: 14px;
    flex: 0 0 auto;
    box-sizing: border-box;
    position: relative;
    z-index: 0;
}

.btn-theme.btn-theme--pill:hover {
    background: var(--module-card-hover);
}

.theme-pill {
    display: block;
    line-height: 0;
    max-width: 100%;
}

.theme-pill-track {
    position: relative;
    width: var(--theme-pill-w);
    height: var(--theme-pill-h);
    border-radius: 999px;
    /* Evita sombra do knob e traço dos SVGs invadirem o botão de suporte ao lado */
    overflow: hidden;
    transition: background 0.25s ease, box-shadow 0.25s ease;
}

[data-theme="dark"] .btn-theme--pill .theme-pill-track {
    background: #0f172a;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] .btn-theme--pill .theme-pill-track {
    background: #e8ecf1;
    box-shadow: inset 0 2px 5px rgba(15, 23, 42, 0.12);
}

.theme-pill-icons {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
}

/* Sol e lua +50% vs. base anterior (27px de área útil cada) */
.theme-pill-sun {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 27px;
    height: 27px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: currentColor;
    transition: opacity 0.22s ease, color 0.22s ease, left 0.28s ease, right 0.28s ease;
}

.theme-pill-moon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    color: currentColor;
    transition: opacity 0.22s ease, color 0.22s ease, left 0.28s ease, right 0.28s ease;
}

/* Tema escuro: knob à esquerda — lua à direita, sol à direita do knob (centro) */
[data-theme="dark"] .btn-theme--pill .theme-pill-sun {
    left: calc(var(--theme-pill-knob) + var(--theme-pill-pad) + var(--theme-pill-icon-gap));
    right: auto;
}

[data-theme="dark"] .btn-theme--pill .theme-pill-moon {
    right: var(--theme-pill-pad);
    left: auto;
}

/* Tema claro: knob à direita — sol à esquerda, lua à esquerda do knob */
[data-theme="light"] .btn-theme--pill .theme-pill-sun {
    left: var(--theme-pill-pad);
    right: auto;
}

[data-theme="light"] .btn-theme--pill .theme-pill-moon {
    right: calc(var(--theme-pill-knob) + var(--theme-pill-pad) + var(--theme-pill-icon-gap));
    left: auto;
}

.theme-pill-sun svg,
.theme-pill-moon > svg {
    display: block;
    flex-shrink: 0;
}

.theme-pill-stars {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    margin-left: 0;
    opacity: 0.95;
}

.theme-pill-star {
    display: block;
    flex-shrink: 0;
    opacity: 0.9;
}

.theme-pill-star--2 {
    margin-left: 1px;
    opacity: 0.8;
}

[data-theme="dark"] .btn-theme--pill .theme-pill-sun {
    color: #64748b;
    opacity: 0.35;
}

[data-theme="dark"] .btn-theme--pill .theme-pill-moon {
    color: #f8fafc;
    opacity: 1;
}

[data-theme="light"] .btn-theme--pill .theme-pill-sun {
    color: #0f172a;
    opacity: 1;
}

[data-theme="light"] .btn-theme--pill .theme-pill-moon {
    color: #64748b;
    opacity: 0.38;
}

.theme-pill-knob {
    position: absolute;
    top: 50%;
    left: 0;
    width: var(--theme-pill-knob);
    height: var(--theme-pill-knob);
    margin-top: calc(var(--theme-pill-knob) / -2);
    border-radius: 50%;
    z-index: 2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), background 0.25s ease,
        box-shadow 0.25s ease;
}

[data-theme="dark"] .btn-theme--pill .theme-pill-knob {
    transform: translateX(var(--theme-pill-pad));
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

[data-theme="light"] .btn-theme--pill .theme-pill-knob {
    transform: translateX(calc(var(--theme-pill-w) - var(--theme-pill-knob) - var(--theme-pill-pad)));
    background: #1e293b;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.2);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 8px;
    border-left: 1px solid var(--border-color);
}

.topbar-user-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-topbar-logout {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-topbar-logout:hover {
    background: var(--module-card-hover);
    color: var(--danger-color);
}

.btn-topbar-logout:focus-visible {
    outline: 2px solid var(--danger-color);
    outline-offset: 2px;
}

/* Barra do portal (/): agrupamento estilo “Google” — tema, ícone de ajuda, usuário */
.app-topbar-actions--portal {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    /* Não reduzir gap em relação à barra geral — evita sobreposição tema × suporte */
    gap: 8px 14px;
}

.app-topbar-actions--portal > .btn-topbar-icon,
.app-topbar-actions--portal > .btn-theme {
    flex: 0 0 auto;
}

.btn-topbar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.btn-topbar-icon:hover {
    background: var(--module-card-hover);
    color: var(--text-primary);
}

.btn-topbar-icon.is-active {
    background: var(--bg-hover);
    color: var(--primary-color);
}

.btn-topbar-icon-svg {
    display: block;
    flex-shrink: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Importante: classes com display:flex não podem anular o atributo HTML hidden */
.view-guest[hidden],
.view-dashboard[hidden] {
    display: none !important;
}

.view-guest {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 20px 20px 32px;
}

.guest-hero {
    margin-bottom: 24px;
}

.guest-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 8px 0;
    color: var(--text-primary);
}

.guest-tagline {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    max-width: 52ch;
    line-height: 1.5;
}

.guest-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    flex: 1;
    align-items: start;
}

@media (min-width: 900px) {
    .guest-layout {
        grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    }
}

.view-dashboard {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.dash-hero {
    background: var(--dash-hero-bg);
    color: var(--dash-hero-text);
    padding: clamp(24px, 4vw, 36px) clamp(16px, 4vw, 28px) clamp(28px, 4vw, 40px);
    border-radius: 0 0 22px 22px;
    box-shadow: 0 10px 36px rgba(15, 23, 42, 0.2);
}

[data-theme="dark"] .dash-hero {
    box-shadow: 0 14px 44px rgba(0, 0, 0, 0.5);
}

.dash-hero-inner {
    max-width: 1100px;
    margin: 0 auto;
}

.dash-hero-title {
    margin: 0 0 10px 0;
    font-size: clamp(1.5rem, 3.5vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.dash-hero-sub {
    margin: 0;
    font-size: clamp(0.95rem, 2vw, 1.05rem);
    font-weight: 500;
    opacity: 0.94;
    line-height: 1.45;
    max-width: 40ch;
}

.dash-content {
    flex: 1;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 20px 44px;
    background: transparent;
}

.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.module-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 18px 18px 16px;
    border-radius: 12px;
    background: var(--module-card-bg);
    border: 1px solid var(--module-card-border);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s, box-shadow 0.2s, border-color 0.2s, background 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .module-card {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.module-card--accent:hover {
    border-color: var(--primary-color);
    background: var(--module-card-hover);
    transform: translateY(-2px);
}

.module-card-icon {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.module-card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.module-card-title {
    font-weight: 800;
    font-size: 1.125rem;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.25;
}

.module-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

.module-card-arrow {
    flex-shrink: 0;
    align-self: center;
    font-size: 1.25rem;
    color: var(--primary-color);
    opacity: 0.85;
}

.module-card--soon {
    cursor: default;
    opacity: 0.85;
    background: var(--module-soon-bg);
}

.module-card--soon:hover {
    transform: none;
}

.module-card-badge {
    align-self: center;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--border-color);
    color: var(--text-muted);
}

/* Página BPA: leitor com mesma casca do portal (topbar + conteúdo flexível) */
.bpa-page .app-shell {
    min-height: 100vh;
}

.bpa-page .app-shell > .shell {
    min-height: 0;
    flex: 1;
    background: var(--bg-dark);
}

.bpa-page.portal-body {
    background: var(--page-bg);
}

/* Módulo Laboratório: mesma casca do portal (topbar + hero + conteúdo) */
.lab-page .app-shell {
    min-height: 100vh;
}

.lab-page .app-shell > .lab-main-wrap {
    flex: 1;
    min-height: 0;
    background: var(--page-bg);
}

.lab-page.portal-body {
    background: var(--page-bg);
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-dark);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.auth-section {
    padding: 16px 24px;
}

.auth-box {
    display: flex;
    gap: 10px;
    align-items: center;
}

.auth-box input {
    padding: 8px 12px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
}

.auth-box input::placeholder {
    color: var(--text-muted);
}

.auth-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.auth-box button {
    padding: 8px 16px;
    background: var(--primary-color);
    border: none;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
}

.auth-box button:hover {
    background: var(--primary-dark);
}

#user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
}

#user-info button {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

#user-info button:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.error {
    color: var(--danger-color);
    font-size: 12px;
    margin-top: 5px;
}

/* Navigation Tabs */
.tabs {
    display: flex;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    gap: 0;
}

.tab-btn {
    padding: 14px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: var(--bg-dark);
}

/* Content */
.tab-content {
    display: none;
    padding: 24px;
    flex: 1;
    background: var(--bg-dark);
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-primary {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-primary::before {
    content: "+";
    font-size: 18px;
    font-weight: bold;
}

.btn-secondary {
    padding: 6px 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-danger {
    padding: 6px 12px;
    background: transparent;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: var(--danger-color);
    color: white;
}

/* Search */
.search-box {
    margin-bottom: 20px;
    display: flex;
    gap: 12px;
}

.search-box input,
.search-box select {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-box input:focus,
.search-box select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 20px;
    transition: all 0.2s;
    position: relative;
}

.card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(74, 144, 226, 0.15);
    transform: translateY(-2px);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}

.card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.card-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

.card-actions {
    display: flex;
    gap: 6px;
}

.card-body {
    margin-top: 12px;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    margin: 2px 4px 2px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-primary {
    background: rgba(74, 144, 226, 0.2);
    color: var(--primary-color);
    border: 1px solid rgba(74, 144, 226, 0.3);
}

.badge-success {
    background: rgba(82, 196, 26, 0.2);
    color: var(--success-color);
    border: 1px solid rgba(82, 196, 26, 0.3);
}

.badge-warning {
    background: rgba(250, 173, 20, 0.2);
    color: var(--warning-color);
    border: 1px solid rgba(250, 173, 20, 0.3);
}

.badge-danger {
    background: rgba(255, 77, 79, 0.2);
    color: var(--danger-color);
    border: 1px solid rgba(255, 77, 79, 0.3);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    overflow: auto;
}

.modal-content {
    background: var(--bg-card);
    margin: 40px auto;
    padding: 32px;
    border-radius: 8px;
    width: 90%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 28px;
    font-weight: 300;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.modal-content h2 {
    margin-bottom: 24px;
    color: var(--text-primary);
    font-size: 20px;
    font-weight: 600;
}

.modal-content label {
    display: block;
    margin-top: 16px;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-content input[type="text"],
.modal-content input[type="email"],
.modal-content input[type="password"],
.modal-content input[type="number"],
.modal-content textarea,
.modal-content select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    transition: all 0.2s;
    font-family: inherit;
}

.modal-content input:focus,
.modal-content textarea:focus,
.modal-content select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.1);
}

.modal-content textarea {
    resize: vertical;
    min-height: 100px;
    font-family: 'Courier New', monospace;
}

.modal-content input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
    accent-color: var(--primary-color);
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.checkbox-list {
    max-height: 300px;
    overflow-y: auto;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 8px;
    margin-top: 10px;
}

.checkbox-list::-webkit-scrollbar {
    width: 8px;
}

.checkbox-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.checkbox-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.checkbox-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.checkbox-item {
    display: flex;
    align-items: center;
    padding: 10px;
    border-radius: 4px;
    transition: background 0.2s;
    margin-bottom: 4px;
}

.checkbox-item:hover {
    background: var(--bg-hover);
}

.checkbox-item input[type="checkbox"] {
    margin-right: 12px;
    cursor: pointer;
}

.checkbox-item label {
    margin: 0;
    cursor: pointer;
    flex: 1;
    color: var(--text-primary);
    font-size: 14px;
}

.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.loading {
    text-align: center;
    padding: 60px;
    color: var(--primary-color);
    font-size: 16px;
}

/* Permission Tree View */
.permission-tree {
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 12px;
    margin-top: 12px;
}

.tree-node {
    padding: 8px 12px;
    margin: 4px 0;
    border-radius: 4px;
    transition: background 0.2s;
}

.tree-node:hover {
    background: var(--bg-hover);
}

.tree-node.has-children {
    font-weight: 600;
    color: var(--primary-color);
}

.tree-node.child {
    padding-left: 32px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Inheritance visualization */
.inheritance-chain {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    font-size: 12px;
}

.inheritance-chain::before {
    content: "←";
    color: var(--text-muted);
}

.inheritance-item {
    color: var(--warning-color);
    font-weight: 500;
}

.inheritance-separator {
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .tabs {
        overflow-x: auto;
    }
    
    .tab-btn {
        white-space: nowrap;
    }
}

/* ——— Portal (legado: landing-main / landing-brand) ——— */
.landing-page {
    max-width: 1100px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 24px 20px 32px;
}

.landing-header {
    margin-bottom: 28px;
}

.landing-brand {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.landing-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    flex-shrink: 0;
}

.landing-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.landing-tagline {
    margin: 0;
    max-width: 52ch;
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.55;
}

.landing-main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 28px;
    flex: 1;
    align-items: start;
}

@media (min-width: 900px) {
    .landing-main {
        grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    }
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 28px 24px 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.auth-card-title {
    font-size: 1.2rem;
    margin: 0 0 8px 0;
    color: var(--text-primary);
}

.auth-card-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0 0 20px 0;
    line-height: 1.5;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.auth-tab {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: var(--bg-dark);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.auth-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.auth-tab.active {
    background: var(--primary-color);
    color: #fff;
}

.auth-panel {
    display: none;
}

.auth-panel.active {
    display: block;
}

.auth-form label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 6px;
    margin-top: 14px;
}

.auth-form label:first-of-type {
    margin-top: 0;
}

.auth-form input {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 226, 0.15);
}

.btn-auth-primary {
    width: 100%;
    margin-top: 22px;
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-auth-primary:hover {
    background: var(--primary-dark);
}

.auth-message {
    margin-top: 14px;
    font-size: 0.85rem;
    line-height: 1.45;
}

.auth-message-error {
    color: var(--danger-color);
}

.auth-message-success {
    color: var(--success-color);
}

.btn-auth-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background 0.2s;
}

.btn-auth-secondary:hover {
    background: var(--primary-dark);
}

.btn-auth-ghost {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
}

.btn-auth-ghost:hover {
    background: var(--bg-card);
    border-color: var(--primary-color);
}

.btn-auth-outline {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-auth-outline:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.landing-aside {
    background: rgba(37, 37, 37, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 22px 20px;
}

.landing-aside h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.landing-list {
    margin: 0;
    padding-left: 1.2em;
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
}

.landing-list code {
    font-size: 0.82em;
    color: var(--primary-color);
    background: var(--bg-dark);
    padding: 2px 6px;
    border-radius: 4px;
}

.landing-footer {
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.landing-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

.landing-footer a:hover {
    text-decoration: underline;
}

/* Portal inicial (/): rodapé compacto; suporte no ícone da barra superior */
.portal-home-footer {
    margin-top: auto;
    padding: 20px 24px 28px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-card);
}

.portal-home-footer-inner {
    max-width: 1100px;
    margin: 0 auto;
}

.portal-home-footer-inner--links {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 24px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.portal-home-footer-inner--links a {
    color: var(--primary-color);
    text-decoration: none;
}

.portal-home-footer-inner--links a:hover {
    text-decoration: underline;
}

.portal-home-footer-hint {
    flex-basis: 100%;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.portal-home-footer-hint-ic {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1em;
    height: 1.1em;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    font-size: 0.75em;
    font-weight: 700;
    vertical-align: middle;
    margin: 0 2px;
}

/* Painel lateral de suporte (ícone ? na topbar) */
.portal-support-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.42);
    backdrop-filter: blur(2px);
}

[data-theme="light"] .portal-support-backdrop {
    background: rgba(15, 23, 42, 0.28);
}

/* Author display:flex vence o [hidden] nativo — sem isso o painel não some ao fechar */
.portal-support-panel[hidden],
.portal-support-backdrop[hidden] {
    display: none !important;
    pointer-events: none !important;
}

.portal-support-panel {
    position: fixed;
    /* Abaixo da topbar fixa: menos sobreposição com módulos e cabeçalho */
    top: var(--app-topbar-h, 56px);
    right: 0;
    z-index: 10001;
    width: min(100vw - 16px, 440px);
    max-width: 100%;
    height: calc(100vh - var(--app-topbar-h, 56px));
    height: calc(100dvh - var(--app-topbar-h, 56px));
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] .portal-support-panel {
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
}

.portal-support-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
    padding: 14px 12px 14px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-dark);
}

.portal-support-panel-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}

.portal-support-close {
    flex-shrink: 0;
}

.portal-support-panel-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 18px 28px;
    -webkit-overflow-scrolling: touch;
}

.portal-support-intro {
    margin: 0 0 14px;
    font-size: 0.88rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.portal-support-quicklinks {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-color);
}

.portal-support-quicklinks a {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary-color);
    text-decoration: none;
}

.portal-support-quicklinks a:hover {
    text-decoration: underline;
}

body.portal-support-open {
    overflow: hidden;
}

.portal-chamado-opt {
    font-weight: 400;
    font-size: 0.88em;
    color: var(--text-muted);
}

.portal-chamado-lead {
    margin: 0 0 12px;
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.portal-chamado-todo {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-left: 4px solid var(--warning-color);
    background: var(--bg-dark);
    border-radius: 0 6px 6px 0;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.45;
}

.portal-chamado-todo-mark {
    display: inline-block;
    margin-right: 8px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(250, 173, 20, 0.2);
    color: var(--warning-color);
}

.portal-chamado-feedback {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.85rem;
    line-height: 1.45;
}

.portal-chamado-feedback--ok {
    background: rgba(82, 196, 26, 0.15);
    color: var(--success-color);
    border: 1px solid rgba(82, 196, 26, 0.35);
}

.portal-chamado-feedback--warn {
    background: rgba(250, 173, 20, 0.12);
    color: var(--text-primary);
    border: 1px solid rgba(250, 173, 20, 0.35);
}

.portal-chamado-feedback--err {
    background: rgba(255, 77, 79, 0.12);
    color: var(--danger-color);
    border: 1px solid rgba(255, 77, 79, 0.35);
}

.portal-chamado-form {
    margin-top: 4px;
}

.portal-chamado-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 16px;
}

@media (max-width: 640px) {
    .portal-chamado-grid {
        grid-template-columns: 1fr;
    }
}

.portal-chamado-field-span2 {
    grid-column: 1 / -1;
}

.portal-chamado-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.portal-chamado-field input,
.portal-chamado-field select,
.portal-chamado-field textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    font-size: 0.88rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-dark);
    color: var(--text-primary);
}

.portal-chamado-field input:disabled,
.portal-chamado-field select:disabled,
.portal-chamado-field textarea:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.portal-chamado-field input::placeholder,
.portal-chamado-field textarea::placeholder {
    color: var(--text-muted);
}

.portal-chamado-actions {
    margin-top: 16px;
}

.btn-portal-chamado {
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: var(--primary-color);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn-portal-chamado:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-portal-chamado:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Admin: cabeçalho com link ao portal */
.admin-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    padding: 0 8px 0 0;
}

.admin-header-left h1 {
    padding: 16px 0;
    font-size: 1.15rem;
}

.admin-header-left h1::before {
    content: none;
}

.portal-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
    transition: color 0.2s, border-color 0.2s;
}

.portal-link:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Notificações (sino no topbar) */
.contaf-notif-wrap {
    position: relative;
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    align-self: center;
    margin: 0;
    z-index: 1;
}

.contaf-notif-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.contaf-notif-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.contaf-notif-bell {
    display: flex;
    align-items: center;
    justify-content: center;
}

.contaf-notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    font-size: 10px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    color: #fff;
    background: var(--danger-color);
    border-radius: 8px;
}

/* display:flex no autor vence [hidden] nativo — forçar some ao fechar */
.contaf-notif-panel[hidden] {
    display: none !important;
    pointer-events: none !important;
}

.contaf-notif-panel {
    position: absolute;
    top: calc(100% + 6px);
    /* Alinha à direita do sino; max-width evita invadir ícones à direita em telas estreitas */
    right: 0;
    left: auto;
    width: min(360px, calc(100vw - 32px));
    max-width: calc(100vw - 24px);
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    z-index: 2000;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.contaf-notif-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 600;
}

.contaf-notif-mark-all {
    border: none;
    background: none;
    color: var(--primary-color);
    font-size: 0.75rem;
    cursor: pointer;
    padding: 4px 0;
    white-space: nowrap;
}

.contaf-notif-mark-all:hover {
    text-decoration: underline;
}

.contaf-notif-list {
    overflow-y: auto;
    max-height: 50vh;
}

.contaf-notif-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    border-bottom: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
}

.contaf-notif-item:last-child {
    border-bottom: none;
}

.contaf-notif-item:hover {
    background: var(--bg-hover);
}

.contaf-notif-item--unread {
    background: rgba(74, 144, 226, 0.08);
}

.contaf-notif-item-title {
    font-weight: 600;
}

.contaf-notif-item-body {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.contaf-notif-item--error .contaf-notif-item-title {
    color: var(--danger-color);
}

.contaf-notif-item--success .contaf-notif-item-title {
    color: var(--success-color);
}

.contaf-notif-empty {
    font-size: 0.85rem;
}
