/* ---------------------------------------------------------------------------
 * Tokens (design system sobre o Bootstrap 5.3). Cores neutras em --app-*; a cor da instituição
 * chega pelo <style> do layout (App\Support\BrandColor::cssVariables) e é espalhada pelo
 * Bootstrap aqui embaixo — não use #0d6efd nem cinzas fixos em regra nova.
 * A cor escolhida pode ser clara: --brand-primary só em FUNDO (botão primário, item ativo), com
 * --brand-on-primary por cima; TEXTO, link, aba ativa, ícone e borda de foco usam
 * --brand-primary-text (o mesmo tom, escurecido até ler bem; no tema escuro, clareado).
 * Tema escuro: :root[data-bs-theme="dark"] no fim do arquivo redefine os --app-* e os tons da marca.
 * ------------------------------------------------------------------------- */
:root {
    --brand-primary: #135e96;
    --brand-primary-rgb: 19, 94, 150;
    --brand-on-primary: #fff;
    --brand-primary-text: #135e96;
    --brand-primary-text-rgb: 19, 94, 150;
    --brand-primary-text-dark: #2b95e4;
    --brand-primary-text-dark-rgb: 43, 149, 228;
    --brand-secondary: #0a8894;
    --brand-secondary-text: #097f8a;
    --brand-secondary-text-dark: #0ca2b1;
    --brand-primary-strong: color-mix(in srgb, var(--brand-primary-text) 82%, #000);
    --brand-primary-soft: rgba(var(--brand-primary-text-rgb), .09);
    --brand-primary-hover: color-mix(in srgb, var(--brand-primary) 88%, #000);
    --brand-primary-pressed: color-mix(in srgb, var(--brand-primary) 76%, #000);
    /* Menu lateral na cor da instituição (RF-ATD-08). O layout manda os valores da instituição
       (BrandColor::cssVariables): fundo ajustado até o texto ler bem, texto e o "véu" do hover. */
    --brand-sidebar: #135e96;
    --brand-on-sidebar: #fff;
    --brand-sidebar-veil: #000;
    --brand-sidebar-close-filter: invert(1) grayscale(100%) brightness(200%);

    --app-bg: #f8fafc;
    --app-surface: #fff;
    --app-surface-muted: #f1f5f9;
    --app-surface-subtle: #f8fafc;
    --app-overlay: rgba(255, 255, 255, .82);
    --app-block-bg: #f8f1e5;
    --app-block-border: #d9a441;
    --app-block-text: #7a5a14;
    --app-whatsapp: #128c7e;
    --app-text: #0f172a;
    --app-text-soft: #334155;
    --app-text-nav: #475569;
    --app-text-muted: #64748b;
    --app-text-faint: #94a3b8;
    --app-border: #e2e8f0;
    --app-border-strong: #cbd5e1;
    --app-radius: .5rem;
    --app-radius-lg: .75rem;
    --app-shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --app-shadow-md: 0 10px 30px -12px rgba(15, 23, 42, .25);
    --app-focus: #f0b429;
    --sidebar-width: 264px;

    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-body-font-size: .9375rem;
    --bs-body-color: var(--app-text);
    --bs-body-bg: var(--app-surface); /* fundo de card, campo, dropdown e modal; a página usa --app-bg */
    --bs-secondary-color: var(--app-text-muted);
    --bs-emphasis-color: var(--app-text);
    --bs-border-color: var(--app-border);
    --bs-tertiary-bg: var(--app-surface-muted);
    --bs-border-radius: var(--app-radius);
    --bs-border-radius-sm: .375rem;
    --bs-border-radius-lg: var(--app-radius-lg);
    /* text-primary, bg-primary/text-bg-primary (texto branco), border-primary: o tom legível. */
    --bs-primary: var(--brand-primary-text);
    --bs-primary-rgb: var(--brand-primary-text-rgb);
    --bs-primary-text-emphasis: var(--brand-primary-strong);
    --bs-primary-bg-subtle: color-mix(in srgb, var(--brand-primary-text) 10%, var(--app-surface));
    --bs-primary-border-subtle: color-mix(in srgb, var(--brand-primary-text) 30%, var(--app-surface));
    --bs-link-color: var(--brand-primary-text);
    --bs-link-color-rgb: var(--brand-primary-text-rgb);
    --bs-link-hover-color: var(--brand-primary-strong);
    --bs-link-hover-color-rgb: var(--brand-primary-text-rgb);
    --bs-focus-ring-color: rgba(var(--brand-primary-text-rgb), .25);
}

body {
    background-color: var(--app-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Links: sublinhado discreto (o Bootstrap usa o sublinhado cheio da cor do texto). */
a:not(.btn):not(.nav-link):not(.dropdown-item):not(.list-group-item) {
    text-underline-offset: .2em;
    text-decoration-color: rgba(var(--brand-primary-text-rgb), .35);
}

a:not(.btn):not(.nav-link):not(.dropdown-item):not(.list-group-item):hover { text-decoration-color: currentColor; }

/* ---------------------------------------------------------------------------
 * Estrutura: menu lateral claro + barra superior (layouts/app, layouts/sidebar)
 * ------------------------------------------------------------------------- */
.app-shell {
    min-height: 100vh;
    background: var(--app-bg);
}

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--app-surface);
    color: var(--app-text);
    border-right: 1px solid var(--app-border);
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    padding: 1rem 1.1rem;
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: .7rem;
    border-bottom: 1px solid var(--app-border);
}

.sidebar-brand strong {
    font-weight: 600;
    letter-spacing: -.01em;
}

.sidebar-brand small {
    display: block;
    color: var(--app-text-muted);
    font-size: .75rem;
}

.brand-mark {
    height: 36px;
    width: 36px;
    flex: 0 0 36px;
    background: transparent; /* logos e brasões são PNG com transparência: sem quadro branco atrás */
    color: var(--brand-primary-text);
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-size: 1.35rem;
    overflow: hidden;
}

.brand-mark img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sidebar .nav-link {
    position: relative;
    color: var(--app-text-nav);
    padding: .55rem .7rem;
    border-radius: var(--app-radius);
    font-size: .9rem;
    font-weight: 500;
}

.sidebar .nav-link i {
    width: 1.4rem;
    display: inline-block;
    color: var(--app-text-faint);
}

.sidebar .nav-link:hover {
    color: var(--app-text);
    background: var(--app-surface-muted);
}

.sidebar .nav-link:hover i { color: var(--app-text-muted); }

.sidebar .nav-link.active {
    color: var(--brand-primary-text);
    background: var(--brand-primary-soft);
}

.sidebar .nav-link.active i { color: var(--brand-primary-text); }

/* Marcador à esquerda do item ativo (só no primeiro nível). */
.sidebar-nav > .nav-link.active::before,
.sidebar-nav > .nav-group > div > .nav-link.active::before {
    content: "";
    position: absolute;
    left: -.75rem;
    top: .45rem;
    bottom: .45rem;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--brand-primary);
}

/* Títulos dos grupos do menu (Atendimento, Rede, Gestão, Administração). */
.sidebar-section {
    margin: .9rem .7rem .3rem;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--app-text-faint);
}

.sidebar-section:first-child { margin-top: .25rem; }

.sidebar-footer {
    padding: .85rem 1.1rem;
    margin-top: auto;
    color: var(--app-text-muted);
    font-size: .8rem;
    border-top: 1px solid var(--app-border);
}

.content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: 64px;
    background: var(--app-surface);
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--app-border);
    gap: .75rem;
}

.topbar .btn-light { border-color: transparent; }
.topbar .btn-light:hover { border-color: var(--app-border); }

/* Nome da instituição: ocupa o espaço que sobra e corta em 2 linhas (nome completo no title). */
.topbar-title {
    flex: 1 1 auto;
    min-width: 0;
}

.topbar-title span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
    font-weight: 500;
    color: var(--app-text-soft) !important;
}

.topbar-user-name {
    display: inline-block;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.offcanvas-lg.sidebar {
    width: var(--sidebar-width) !important;
}

@media (max-width: 991.98px) {
    .sidebar {
        /* Keep the Bootstrap offcanvas out of the page flow while closed. */
        max-height: 100dvh;
        overflow-y: auto;
        /* Acima da sombra do offcanvas (backdrop = 1040): com o 1040 do desktop, a sombra criada depois
           no DOM ficava por cima do menu e bloqueava todos os cliques no celular. */
        z-index: var(--bs-offcanvas-zindex, 1045);
    }

    .content {
        margin-left: 0;
    }

    .topbar {
        padding: 0 1rem;
    }
}

/* ---------------------------------------------------------------------------
 * Componentes do Bootstrap no padrão do sistema (só CSS: as telas usam as classes de sempre)
 * ------------------------------------------------------------------------- */
.page-title {
    font-weight: 650;
    letter-spacing: -.015em;
    color: var(--app-text);
}

h1.page-title.h3, .page-title.h3 { font-size: 1.5rem; }
.page-title.h4 { font-size: 1.25rem; }
.page-title + .text-muted, .page-title + p.text-muted { font-size: .9rem; }

h2.h5, h2.h6, .card h2 { font-weight: 600; letter-spacing: -.005em; }

.card {
    --bs-card-border-color: var(--app-border);
    --bs-card-border-radius: var(--app-radius-lg);
    --bs-card-inner-border-radius: calc(var(--app-radius-lg) - 1px);
    --bs-card-cap-bg: transparent;
    border: 1px solid var(--app-border);
    box-shadow: var(--app-shadow-sm);
}

.card.border-warning { border-color: #fcd34d !important; }
.card.border-primary-subtle { border-color: var(--bs-primary-border-subtle) !important; }
.card-header { font-weight: 600; }
.card > .table-responsive { border-radius: var(--bs-card-inner-border-radius); }
.card > .table-responsive:not(:first-child) { border-top-left-radius: 0; border-top-right-radius: 0; }
/* A rolagem da tabela contém o que é absoluto dentro dela (ex.: o rótulo .visually-hidden "Ações" do cabeçalho). Sem isso
   ele se posiciona pelo .card, fica fora da rolagem e o celular ganha rolagem lateral na página inteira. */
.table-responsive { position: relative; }

.metric-card .icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: var(--brand-primary-soft);
    color: var(--brand-primary-text);
    font-size: 1.25rem;
}

.chart-wrap {
    position: relative;
    width: 100%;
}

.chart-wrap--fixed {
    height: 280px;
}

.chart-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 575.98px) {
    .chart-wrap--fixed {
        height: 220px;
    }
}

/* Formulários: 40 px de altura, anel de foco na cor da instituição. */
.form-label {
    font-weight: 500;
    font-size: .875rem;
    color: var(--app-text-soft);
}

.form-control, .form-select {
    border-color: var(--app-border-strong);
}

.form-control:not(textarea):not(.form-control-sm):not(.form-control-lg):not([type="file"]),
.form-select:not(.form-select-sm):not(.form-select-lg):not([multiple]):not([size]) {
    min-height: 2.5rem;
}

.form-control:focus, .form-select:focus {
    border-color: color-mix(in srgb, var(--brand-primary-text) 55%, var(--app-surface));
    box-shadow: 0 0 0 .2rem rgba(var(--brand-primary-text-rgb), .18);
}

.form-control::placeholder { color: var(--app-text-faint); }
.form-text { color: var(--app-text-muted); }

.form-check-input:checked {
    background-color: var(--brand-primary-text);
    border-color: var(--brand-primary-text);
}

.form-check-input:focus {
    border-color: color-mix(in srgb, var(--brand-primary-text) 55%, var(--app-surface));
    box-shadow: 0 0 0 .2rem rgba(var(--brand-primary-text-rgb), .18);
}

.input-group-text { background: var(--app-surface-muted); border-color: var(--app-border-strong); }

/* Botões. */
.btn { font-weight: 500; }

.btn-primary {
    --bs-btn-color: var(--brand-on-primary);
    --bs-btn-bg: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary-hover);
    --bs-btn-hover-color: var(--brand-on-primary);
    --bs-btn-hover-bg: var(--brand-primary-hover);
    --bs-btn-hover-border-color: var(--brand-primary-pressed);
    --bs-btn-active-color: var(--brand-on-primary);
    --bs-btn-active-bg: var(--brand-primary-pressed);
    --bs-btn-active-border-color: var(--brand-primary-pressed);
    --bs-btn-disabled-color: var(--brand-on-primary);
    --bs-btn-disabled-bg: var(--brand-primary);
    --bs-btn-disabled-border-color: var(--brand-primary);
    --bs-btn-focus-shadow-rgb: var(--brand-primary-text-rgb);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-primary-text);
    --bs-btn-border-color: color-mix(in srgb, var(--brand-primary-text) 45%, var(--app-surface));
    --bs-btn-hover-color: var(--brand-primary-strong);
    --bs-btn-hover-bg: var(--brand-primary-soft);
    --bs-btn-hover-border-color: var(--brand-primary-text);
    --bs-btn-active-color: var(--brand-on-primary);
    --bs-btn-active-bg: var(--brand-primary);
    --bs-btn-active-border-color: var(--brand-primary-hover);
    --bs-btn-disabled-color: var(--brand-primary-text);
    --bs-btn-disabled-border-color: color-mix(in srgb, var(--brand-primary-text) 45%, var(--app-surface));
    --bs-btn-focus-shadow-rgb: var(--brand-primary-text-rgb);
}

/* "Fantasma" com borda: ações secundárias e os ícones das listas. */
.btn-light {
    --bs-btn-color: var(--app-text-soft);
    --bs-btn-bg: var(--app-surface);
    --bs-btn-border-color: var(--app-border);
    --bs-btn-hover-color: var(--app-text);
    --bs-btn-hover-bg: var(--app-surface-muted);
    --bs-btn-hover-border-color: var(--app-border-strong);
    --bs-btn-active-color: var(--app-text);
    --bs-btn-active-bg: var(--app-border);
    --bs-btn-active-border-color: var(--app-border-strong);
}

.btn-outline-secondary {
    --bs-btn-color: var(--app-text-soft);
    --bs-btn-border-color: var(--app-border-strong);
    --bs-btn-hover-color: var(--app-text);
    --bs-btn-hover-bg: var(--app-surface-muted);
    --bs-btn-hover-border-color: var(--app-border-strong);
    --bs-btn-active-color: var(--app-text);
    --bs-btn-active-bg: var(--app-border);
    --bs-btn-active-border-color: var(--app-border-strong);
}

/* Tabelas: cabeçalho discreto, linhas com folga e números alinhados. */
.table {
    --bs-table-hover-bg: var(--app-surface-subtle);
    --bs-table-border-color: var(--app-border);
    font-variant-numeric: tabular-nums;
}

.table > :not(caption) > * > * { padding: .7rem .85rem; }
.table-sm > :not(caption) > * > * { padding: .4rem .5rem; }

.table > thead th {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--app-text-muted);
    background: var(--app-surface-subtle);
    border-bottom-color: var(--app-border);
    white-space: nowrap;
}

/* Linha inteira clicável (data-row-link: script no layout). */
tr[data-row-link] { cursor: pointer; }
tr[data-row-link] .row-link { color: inherit; text-decoration: none; }
tr[data-row-link]:hover .row-link { color: var(--brand-primary-text); }

.badge { font-weight: 600; }

.badge-soft {
    background: var(--brand-primary-soft);
    color: var(--brand-primary-strong);
}

.detail-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--app-text-muted);
}

/* Alertas: fundo suave + barra à esquerda. */
.alert {
    border-width: 1px;
    border-left-width: 4px;
    border-radius: .625rem;
}

.alert-info { --bs-alert-border-color: var(--bs-primary-border-subtle); --bs-alert-bg: var(--bs-primary-bg-subtle); --bs-alert-color: var(--brand-primary-strong); }
.alert-light { --bs-alert-border-color: var(--app-border); }

/* Dropdown, modal e abas. */
.dropdown-menu {
    --bs-dropdown-border-color: var(--app-border);
    --bs-dropdown-border-radius: .625rem;
    --bs-dropdown-link-active-color: var(--brand-on-primary);
    --bs-dropdown-link-active-bg: var(--brand-primary);
    --bs-dropdown-link-hover-bg: var(--app-surface-muted);
    --bs-dropdown-font-size: .9rem;
    box-shadow: var(--app-shadow-md);
}

.modal-content {
    border: 0;
    border-radius: .875rem;
    box-shadow: 0 25px 50px -12px rgba(15, 23, 42, .35);
}

.modal-header, .modal-footer { border-color: var(--app-border); }

.nav-tabs {
    --bs-nav-tabs-border-color: var(--app-border);
    gap: .25rem;
}

.nav-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    margin-bottom: -1px;
    color: var(--app-text-muted);
    font-weight: 500;
}

.nav-tabs .nav-link:hover { color: var(--app-text); border-bottom-color: var(--app-border-strong); }

.nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link {
    color: var(--brand-primary-text);
    background: transparent;
    border-bottom-color: var(--brand-primary-text);
}

.nav-pills {
    --bs-nav-pills-link-active-bg: var(--brand-primary-soft);
    --bs-nav-pills-link-active-color: var(--brand-primary-strong);
    gap: .25rem;
}

.nav-pills .nav-link { color: var(--app-text-muted); font-weight: 500; }
.nav-pills .nav-link:hover { color: var(--app-text); background: var(--app-surface-muted); }
.nav-pills .nav-link.active:hover { background: var(--brand-primary-soft); }

.pagination {
    --bs-pagination-color: var(--app-text-soft);
    --bs-pagination-hover-color: var(--brand-primary-text);
    --bs-pagination-focus-color: var(--brand-primary-text);
    --bs-pagination-active-color: var(--brand-on-primary);
    --bs-pagination-active-bg: var(--brand-primary);
    --bs-pagination-active-border-color: var(--brand-primary-hover);
    --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(var(--brand-primary-text-rgb), .18);
    --bs-pagination-border-color: var(--app-border);
    margin-bottom: 0;
}

.progress { --bs-progress-bar-bg: var(--brand-primary-text); }

.list-group {
    --bs-list-group-active-color: var(--brand-on-primary);
    --bs-list-group-active-bg: var(--brand-primary);
    --bs-list-group-active-border-color: var(--brand-primary-hover);
    --bs-list-group-border-color: var(--app-border);
}

.accordion {
    --bs-accordion-active-bg: var(--bs-primary-bg-subtle);
    --bs-accordion-active-color: var(--brand-primary-strong);
    --bs-accordion-btn-focus-box-shadow: 0 0 0 .2rem rgba(var(--brand-primary-text-rgb), .18);
    --bs-accordion-border-color: var(--app-border);
}

/* ---------------------------------------------------------------------------
 * Telas de entrada (login, senha) — fora do layouts.app, com partials/head-assets
 * ------------------------------------------------------------------------- */
.auth-page {
    min-height: 100vh;
    background:
        radial-gradient(60rem 30rem at 50% -10%, rgba(var(--brand-primary-rgb), .14), transparent 70%),
        var(--app-bg);
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: min(440px, 100%);
    border: 1px solid var(--app-border);
    border-radius: 1rem;
    box-shadow: var(--app-shadow-md);
}

.auth-card .brand-mark { height: 56px; width: 56px; flex-basis: 56px; }

/* ---------------------------------------------------------------------------
 * Módulo de Territórios (docs/Requisitos Territorios.md)
 * ------------------------------------------------------------------------- */

/* RNF-04: alvos de toque de pelo menos 44 px nas telas do ACS (tablet 8" em retrato). */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
}

/* RNF-06: foco visível. */
a:focus-visible,
button:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 3px solid var(--app-focus);
    outline-offset: 2px;
}

.min-w-0 { min-width: 0; }

.app-breadcrumb {
    font-size: .85rem;
    flex-wrap: wrap;
}

.app-breadcrumb a { text-decoration: none; }

.app-footer { border-top: 1px solid var(--app-border); padding-top: 1rem; }

/* Menu lateral: submenu de territórios (RF-TER-03). O .nav do Bootstrap tem flex-wrap: wrap; numa coluna
   de altura limitada (muitos territórios abertos) os itens que não cabiam iam para uma 2ª coluna e o menu
   rolava para o lado. Uma coluna só, rolando na vertical. */
.sidebar-nav { flex: 1 1 auto; min-height: 0; flex-wrap: nowrap; overflow-y: auto; overflow-x: hidden; }
.sidebar-nav .nav { flex-wrap: nowrap; }
.sidebar-nav .nav-link { overflow-wrap: anywhere; }

/* Barra de rolagem do menu: fina e discreta, nos tons do tema (a padrão do navegador era larga). Fica
   mais visível só com o mouse sobre o menu. Firefox usa scrollbar-*, os demais ::-webkit-. */
.sidebar-nav, .sidebar { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--app-text-faint) 40%, transparent) transparent; }
.sidebar-nav:hover, .sidebar:hover { scrollbar-color: color-mix(in srgb, var(--app-text-faint) 75%, transparent) transparent; }
.sidebar-nav::-webkit-scrollbar, .sidebar::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--app-text-faint) 40%, transparent); border-radius: 999px; }
.sidebar-nav:hover::-webkit-scrollbar-thumb, .sidebar:hover::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--app-text-faint) 75%, transparent); }
.sidebar-nav::-webkit-scrollbar-button, .sidebar::-webkit-scrollbar-button { display: none; }

.sidebar .nav-toggle {
    color: var(--app-text-muted);
    min-width: 44px;
    min-height: 44px;
}

.sidebar .nav-toggle[aria-expanded="true"] i { transform: rotate(180deg); }

.sidebar-subnav {
    margin-left: 1.35rem;
    padding-left: .6rem;
    border-left: 1px solid var(--app-border);
    list-style: none;
}

.sidebar-subnav .nav-link {
    padding: .45rem .7rem;
    font-size: .88rem;
}

.sidebar-subnav--level3 {
    margin-left: .9rem;
}

.subnav-dot {
    display: inline-block;
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    margin-right: .45rem;
}

/* Árvore Território › Logradouros (RF-TER-01/02). */
.territory-node {
    border-left: 5px solid var(--territory-color, var(--brand-primary-text));
}

.territory-node--inactive { opacity: .7; }

.territory-row {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .9rem;
}

.tree-toggle {
    border: 0;
    background: transparent;
    border-radius: .5rem;
    color: var(--app-text-muted);
}

.tree-toggle:hover { background: var(--app-surface-muted); }

.tree-toggle i { transition: transform .15s ease; }

.territory-node[aria-expanded="true"] .tree-toggle i { transform: rotate(90deg); }

.territory-code {
    cursor: pointer;
    font-weight: 700;
    font-size: .85rem;
    color: #fff;
    background: var(--territory-color, var(--brand-primary-text));
    border-radius: .45rem;
    padding: .3rem .55rem;
}

/* Logradouros visualmente aninhados: recuo + linha vertical de conexão. */
.street-list {
    list-style: none;
    margin: 0 0 .75rem 2.4rem;
    padding: 0 .9rem 0 1.1rem;
    border-left: 2px solid var(--app-border);
}

.street-node {
    position: relative;
}

.street-node::before {
    content: "";
    position: absolute;
    left: -1.1rem;
    top: 50%;
    width: .9rem;
    border-top: 2px solid var(--app-border);
}

.street-link {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
    min-height: 44px;
    padding: .35rem .6rem;
    border-radius: .5rem;
    text-decoration: none;
    color: var(--app-text);
}

.street-link:hover { background: var(--app-surface-muted); }

.street-crumb {
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--app-text-muted);
}

.street-name { font-weight: 600; }

.street-code {
    font-size: .75rem;
    color: var(--app-text-muted);
    background: var(--app-surface-muted);
    border-radius: .35rem;
    padding: .05rem .4rem;
}

.street-node--add .street-link { color: var(--brand-primary-text); font-weight: 600; }

.street-node--empty { padding: .5rem .6rem; }

@media (max-width: 575.98px) {
    .territory-row { flex-wrap: wrap; }
    .territory-stats { width: 100%; padding-left: 3.2rem; }
    .street-list { margin-left: 1.2rem; }
}

.text-pre-wrap { white-space: pre-wrap; }

/* Cadastro individual em 7 etapas (docs/Requisitos Territorios.md, 5.3) */
.wizard-progress { height: 6px; }

.wizard-steps {
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.wizard-step {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    min-height: 44px;
    padding: .4rem .6rem;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: var(--app-text);
    text-align: left;
}

.wizard-step:hover:not(:disabled) { background: var(--app-surface-muted); }
.wizard-step:focus-visible { outline: 3px solid var(--brand-primary-text); outline-offset: 2px; }
.wizard-step.active { background: var(--brand-primary-soft); font-weight: 600; }
.wizard-step:disabled { opacity: .55; }

.wizard-step-number {
    display: inline-flex;
    flex: 0 0 1.9rem;
    align-items: center;
    justify-content: center;
    height: 1.9rem;
    border-radius: 50%;
    background: var(--app-surface-muted);
    font-size: .85rem;
    font-weight: 600;
}

.wizard-step.active .wizard-step-number { background: var(--brand-primary); color: var(--brand-on-primary); }

.yesno {
    padding-bottom: .75rem;
    border-bottom: 1px solid var(--app-border);
}

.yesno .btn-group .btn { min-width: 4.5rem; }

.registration-summary .accordion-button { gap: .5rem; }

/* Tablet em retrato (RNF-04): as etapas viram uma faixa rolável acima do formulário. */
@media (max-width: 991.98px) {
    .wizard-steps { flex-direction: row; overflow-x: auto; padding-bottom: .25rem; }
    .wizard-step { width: auto; white-space: nowrap; }
    .wizard-step-title small { display: none !important; }
}

/* ---------------------------------------------------------------------------
 * "Minimizar aba" (docs/Requisitos Territorios.md, seção 7 — PENDÊNCIA P-01)
 * ------------------------------------------------------------------------- */

/* Botão de recolher, no topo do próprio menu (saiu da barra superior em 11/11/2026). Só aparece no computador
   (d-none d-lg-inline-flex): no celular o menu é gaveta e fecha pelo "X". Nas cores do menu (RF-ATD-08), como os itens. */
.sidebar-collapse-btn {
    flex: none;
    margin-left: auto;
    width: 2.125rem;
    height: 2.125rem;
    padding: 0;
    align-items: center;
    justify-content: center;
    color: var(--brand-on-sidebar);
    background: transparent;
    border: 1px solid color-mix(in srgb, var(--brand-on-sidebar) 30%, transparent);
    border-radius: 9px;
}
.sidebar-collapse-btn:hover { background: color-mix(in srgb, var(--brand-sidebar) 78%, var(--brand-sidebar-veil)); }
.sidebar-collapse-btn:focus-visible { outline: 2px solid var(--brand-on-sidebar); outline-offset: 2px; }

/* RF-MIN-01: menu lateral recolhido para uma coluna só de ícones (só em telas largas; no
   celular/tablet o menu já é gaveta). O texto continua acessível a leitores de tela. */
@media (min-width: 992px) {
    body.sidebar-collapsed { --sidebar-width: 76px; }
    body.sidebar-collapsed .sidebar .nav-label,
    body.sidebar-collapsed .sidebar-brand-text,
    body.sidebar-collapsed .sidebar-section span {
        position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
    }
    body.sidebar-collapsed .sidebar .nav-toggle,
    body.sidebar-collapsed .sidebar #sidebar-territories { display: none !important; }
    body.sidebar-collapsed .sidebar .nav-link { text-align: center; padding: .75rem .5rem; }
    body.sidebar-collapsed .sidebar .nav-link i { width: auto; font-size: 1.15rem; }
    /* Brasão e botão de recolher um embaixo do outro: lado a lado não cabem nos 76 px. */
    body.sidebar-collapsed .sidebar-brand { flex-direction: column; justify-content: center; gap: .5rem; padding: .85rem .5rem; }
    body.sidebar-collapsed .sidebar-collapse-btn { margin-left: 0; }
    body.sidebar-collapsed .sidebar-nav { padding-left: .5rem !important; padding-right: .5rem !important; }
    body.sidebar-collapsed .sidebar-section { margin: .6rem .4rem; border-top: 1px solid var(--app-border); }
    body.sidebar-collapsed .sidebar-nav > .nav-link.active::before { left: -.5rem; }
}
.sidebar, .content { transition: width .15s ease, margin-left .15s ease; }
@media (prefers-reduced-motion: reduce) { .sidebar, .content { transition: none; } }

/* RF-MIN-02: cadastro em andamento minimizado numa barra no rodapé. */
.minimized-draft-bar {
    position: fixed; bottom: 0; right: 0; left: var(--sidebar-width); z-index: 1030;
    background: var(--app-surface); border-top: 2px solid var(--brand-primary); box-shadow: 0 -6px 18px rgba(15, 23, 42, .08);
    padding: .5rem 1rem;
}
@media (max-width: 991.98px) { .minimized-draft-bar { left: 0; } }
body.has-draft-bar .content { padding-bottom: 72px; }

/* RF-MIN-03: seções da ficha do cidadão recolhíveis. */
.section-toggle {
    background: none; border: 0; padding: 0; color: inherit; font: inherit; display: inline-flex; align-items: center; gap: .5rem; text-align: left;
}
.section-toggle i { transition: transform .15s ease; font-size: .9em; }
.section-toggle[aria-expanded="false"] i { transform: rotate(-90deg); }
.collapsible-section.is-collapsed h2 { margin-bottom: 0 !important; }

/* Bloqueio de agenda (feriado, férias) na grade da agenda. */
.agenda-blocked { background: var(--app-block-bg); border: 1px dashed var(--app-block-border); color: var(--app-block-text); border-radius: .5rem; padding: .5rem .75rem; font-size: .875rem; }

/* Agenda interativa (FullCalendar) — appointments/agenda.blade.php */
.agenda-calendar-wrap { position: relative; }
.agenda-loading { position: absolute; top: .75rem; right: 1rem; z-index: 5; font-size: .875rem; color: var(--app-text-muted); background: var(--app-surface); padding: 0 .25rem; }
.agenda-professionals { max-height: 320px; overflow-y: auto; }
.agenda-swatch { display: inline-block; width: .75rem; height: .75rem; border-radius: 50%; margin-right: .4rem; vertical-align: -1px; }
.agenda-legend div { margin-bottom: .2rem; }
.agenda-legend-free { display: inline-block; border: 1px dashed var(--brand-secondary-text); color: var(--brand-secondary-text); border-radius: .25rem; padding: 0 .35rem; font-size: .75rem; }
.agenda-legend-block { display: inline-block; width: 1.4rem; height: .8rem; background: var(--app-block-bg); border: 1px dashed var(--app-block-border); vertical-align: -1px; }
#agenda-calendar .fc-toolbar-title { font-size: 1.15rem; font-weight: 700; }
#agenda-calendar .fc-toolbar-title::first-letter { text-transform: uppercase; }
#agenda-calendar a.fc-col-header-cell-cushion, #agenda-calendar a.fc-daygrid-day-number, #agenda-calendar .fc-list-day a { text-decoration: none; color: inherit; }
#agenda-calendar .fc-col-header-cell-cushion { text-transform: capitalize; font-weight: 600; }
#agenda-calendar .fc-button-primary { background: var(--brand-primary); border-color: var(--brand-primary-hover); color: var(--brand-on-primary); }
#agenda-calendar .fc-button-primary:not(:disabled):hover { background: var(--brand-primary-hover); color: var(--brand-on-primary); }
#agenda-calendar .fc-button-primary:not(:disabled).fc-button-active, #agenda-calendar .fc-button-primary:not(:disabled):active { background: var(--brand-primary-pressed); border-color: var(--brand-primary-pressed); color: var(--brand-on-primary); }
#agenda-calendar .fc-timegrid-slot { height: 1.6rem; }
.agenda-ev { font-size: .78rem; }
.agenda-ev-clickable { cursor: pointer; }
.agenda-ev-locked { cursor: default; }
.agenda-ev-inner { overflow: hidden; padding: 0 .2rem; line-height: 1.2; }
.agenda-ev-time { font-weight: 600; }
.agenda-ev-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.agenda-list-free { border: 1px dashed var(--brand-secondary-text); color: var(--brand-secondary-text); border-radius: .25rem; padding: 0 .35rem; font-size: .75rem; }
.agenda-ev-free { border-style: dashed !important; border-width: 1px !important; font-weight: 500; }
.agenda-ev-free:hover { background: color-mix(in srgb, var(--brand-secondary-text) 10%, transparent) !important; }
.agenda-ev-free.agenda-ev-locked { opacity: .55; }
.agenda-status-attended { opacity: .7; }
.agenda-status-present { box-shadow: 0 0 0 2px #ffc107; }
.agenda-ev-block { background: var(--app-block-bg) !important; opacity: .8; }
.agenda-ev-block-label { background: var(--app-block-bg) !important; border: 1px dashed var(--app-block-border) !important; color: var(--app-block-text) !important; }
.agenda-ev-block-label .fc-event-title, .agenda-ev-block-label .fc-event-main { color: var(--app-block-text) !important; }
.agenda-ev-summary { cursor: pointer; border-radius: .35rem; padding: 0 .25rem; }
.agenda-ev-summary-busy { background: var(--brand-primary) !important; border-color: var(--brand-primary-hover) !important; }
.agenda-ev-summary-busy .fc-event-title { color: var(--brand-on-primary); }
.agenda-ev-summary-free { background: transparent !important; border: 1px dashed var(--brand-secondary-text) !important; }
.agenda-ev-summary-free .fc-event-title { color: var(--brand-secondary-text); }
.booking-results { max-height: 240px; overflow-y: auto; }
@media (max-width: 767.98px) {
    #agenda-calendar .fc-header-toolbar { flex-direction: column; gap: .5rem; }
    #agenda-calendar .fc-button { padding: .45rem .6rem; }
}
.agenda-placeholder { position: absolute; inset: 0; z-index: 4; background: var(--app-overlay); display: flex; align-items: flex-start; justify-content: center; padding: 5rem 1rem 1rem; border-radius: inherit; }
.agenda-placeholder-card { background: var(--app-surface); border: 1px solid var(--app-border); border-radius: .75rem; box-shadow: var(--app-shadow-md); padding: 1.5rem; max-width: 460px; text-align: center; }

/* Relatórios: cartões do menu e bandeja "Meus relatórios" (partials/report-tray). */
.report-card:hover { border-color: var(--brand-primary-text); box-shadow: var(--app-shadow-md); }
.report-card-icon { flex: 0 0 2.75rem; height: 2.75rem; border-radius: .75rem; display: flex; align-items: center; justify-content: center; background: var(--brand-primary-soft); color: var(--brand-primary-text); font-size: 1.3rem; }
/* Botão na barra superior, painel abrindo para baixo (antes era fixo no rodapé e cobria o "Salvar"). */
.report-tray { position: relative; }
.report-tray-panel { position: absolute; right: 0; top: calc(100% + .5rem); z-index: 1080; width: min(360px, calc(100vw - 2rem)); max-height: 60vh; overflow-y: auto; }
@media (max-width: 575.98px) { .report-tray-panel { position: fixed; left: 1rem; right: 1rem; top: 84px; width: auto; } }
.report-tray-toasts { z-index: 1090; margin-top: 4.5rem; }

/* Balões de pendências no menu (App\Services\PendingItemsService) e sino do topo. */
.sidebar .nav-link { position: relative; }
.nav-badge { float: right; margin-top: .15rem; font-size: .7rem; }
body.sidebar-collapsed .nav-badge { position: absolute; top: .3rem; left: 2.1rem; float: none; margin: 0; padding: .2em .45em; font-size: .6rem; }
.pending-menu { width: min(340px, calc(100vw - 2rem)); }
.pending-bell-count { font-size: .65rem; }

/* Dashboard por blocos (dashboard/index + dashboard/widgets). */
.dashboard-tabs .nav-link { font-weight: 600; color: var(--bs-secondary-color); }
.dashboard-tabs .nav-link.active { color: var(--brand-primary-text); }
.dashboard-mini { background: var(--app-surface-muted); border-radius: var(--app-radius); padding: .65rem .75rem; }
.dashboard-list li { padding: .35rem 0; border-bottom: 1px solid var(--app-border); font-size: .875rem; }
.dashboard-list li:last-child { border-bottom: 0; }
.dashboard-widget [data-dashboard-hide] { opacity: .45; }
.dashboard-widget:hover [data-dashboard-hide] { opacity: 1; }

/* Campo de senha com botão "olho" (partials/password-toggle). */
.password-field {
    position: relative;
}

.password-field .form-control {
    padding-right: 2.9rem;
}

.password-field .form-control.is-invalid {
    padding-right: 4.6rem;
    background-position: right 2.9rem center;
}

.password-toggle {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    min-height: 38px;
    width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: var(--app-text-muted);
    border-radius: 0 var(--bs-border-radius) var(--bs-border-radius) 0;
}

.password-toggle:hover {
    color: var(--app-text);
}

/* Ficha da pessoa: faixa com avatar, situação e ações (patients/show) e sub-abas do prontuário. */
.patient-avatar {
    flex: 0 0 3.25rem;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--brand-primary-strong);
    background: var(--brand-primary-soft);
}

.patient-meta {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.1rem;
    font-size: .875rem;
    color: var(--app-text-muted);
}

.patient-meta i { margin-right: .25rem; }
.patient-status-dot { font-size: .5rem; vertical-align: middle; color: var(--app-text-faint); }
.patient-status-active { color: #16a34a; }
.patient-status-inactive, .patient-status-archived { color: var(--app-text-faint); }
.patient-status-transferred { color: #d97706; }
.patient-actions .dropdown-menu form { margin: 0; }

.record-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-bottom: .15rem; }
.record-tabs .nav-link { white-space: nowrap; }

/* Prontuário com navegação lateral no desktop (área do profissional); no celular, a faixa rola de lado. */
.record-layout { display: grid; gap: 1rem; }
.record-tabs .nav-link i { margin-right: .3rem; }
@media (min-width: 992px) {
    .record-layout { grid-template-columns: 14.5rem minmax(0, 1fr); align-items: start; }
    .record-nav { position: sticky; top: calc(64px + 1rem); }
    .record-tabs { flex-direction: column; overflow: visible; padding: .4rem; gap: .1rem; background: var(--app-surface); border: 1px solid var(--app-border); border-radius: var(--app-radius-lg); }
    .record-tabs .nav-link { width: 100%; text-align: left; white-space: normal; }
}

/* RF-ATD-02: nível de suporte do TEA (cores do Bootstrap, que já mudam no tema escuro). */
.support-level-chip { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; border: 1px solid var(--app-border); background: var(--app-surface-muted); color: var(--app-text-soft); }
.support-level-1 { background: var(--bs-info-bg-subtle); color: var(--bs-info-text-emphasis); border-color: var(--bs-info-border-subtle); }
.support-level-2 { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); border-color: var(--bs-warning-border-subtle); }
.support-level-3 { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); border-color: var(--bs-danger-border-subtle); }

/* RF-ATD-04: humor nas sessões (o ponto é enfeite: o número e o rótulo vão ao lado). */
.mood-chart { position: relative; height: 230px; }
.mood-stat { padding: .35rem .7rem; border-radius: var(--app-radius); background: var(--app-surface-muted); }
.mood-dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; vertical-align: baseline; background: var(--app-text-faint); }
.mood-1 { background: #dc2626; }
.mood-2 { background: #f97316; }
.mood-3 { background: #eab308; }
.mood-4 { background: #22c55e; }
.mood-5 { background: #15803d; }

/* RF-ATD-05: percepção clínica (anotação do profissional). */
.perception-note { padding: .6rem .8rem; margin-bottom: .75rem; border-left: 3px solid var(--brand-primary-text); border-radius: 0 var(--app-radius) var(--app-radius) 0; background: var(--app-surface-subtle); }
.perception-note:last-child { margin-bottom: 0; }

/* RF-ATD-01: escolha do perfil de acesso (Secretaria ou Profissional) no cadastro do usuário. */
.profile-choice { display: flex; gap: .75rem; align-items: flex-start; height: 100%; padding: .9rem 1rem; cursor: pointer; border: 1px solid var(--app-border); border-radius: var(--app-radius-lg); background: var(--app-surface); }
.profile-choice:hover { border-color: var(--app-border-strong); }
.profile-choice-icon { flex: 0 0 2.25rem; height: 2.25rem; display: grid; place-items: center; border-radius: var(--app-radius); background: var(--brand-primary-soft); color: var(--brand-primary-text); font-size: 1.1rem; }
.btn-check:checked + .profile-choice { border-color: var(--brand-primary-text); box-shadow: 0 0 0 .15rem rgba(var(--brand-primary-text-rgb), .2); }
.btn-check:focus-visible + .profile-choice { outline: 2px solid var(--brand-primary-text); outline-offset: 2px; }

/* Menu de atalhos da agenda (botão direito / toque longo) — appointments/agenda. */
.agenda-context { position: fixed; z-index: 1085; min-width: 15rem; max-width: 20rem; }
.agenda-context .dropdown-header { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agenda-context .dropdown-item i { width: 1.25rem; display: inline-block; }

/* Busca de pessoa na barra superior (partials/global-search; Ctrl+K / ⌘K). */
.topbar-search {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    width: min(20rem, 32vw);
    color: var(--app-text-muted);
    background: var(--app-surface-subtle);
    border: 1px solid var(--app-border);
    font-weight: 400;
    text-align: left;
}

.topbar-search:hover, .topbar-search:focus-visible { color: var(--app-text); border-color: var(--app-border-strong); background: var(--app-surface); }
.topbar-search span { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-search kbd, .global-search-hint kbd {
    font: 500 .7rem/1 var(--bs-body-font-family);
    color: var(--app-text-muted);
    background: var(--app-surface);
    border: 1px solid var(--app-border-strong);
    border-radius: .3rem;
    padding: .2rem .35rem;
}

@media (max-width: 767.98px) {
    .topbar-search { width: auto; }
    .topbar-search span, .topbar-search kbd { display: none; }
}

.global-search .modal-dialog { margin-top: 8vh; }
.global-search .modal-header { gap: .5rem; padding: .75rem 1rem; }
.global-search-input { border: 0; box-shadow: none !important; font-size: 1.05rem; padding-left: 0; background: transparent; }
.global-search-results { max-height: min(60vh, 28rem); overflow-y: auto; }
.global-search-option {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1rem;
    color: var(--app-text);
    text-decoration: none;
    border-radius: var(--app-radius);
}

.global-search-option[aria-selected="true"], .global-search-option:hover { background: var(--brand-primary-soft); color: var(--app-text); }
.global-search-option > .flex-fill { min-width: 0; }
.global-search-option .patient-avatar { flex-basis: 2.25rem; width: 2.25rem; height: 2.25rem; font-size: .8rem; }
.global-search-option .small { color: var(--app-text-muted); }
.global-search-hint { color: var(--app-text-muted); font-size: .78rem; }

/* Ícone do WhatsApp ao lado de um celular (partials/whatsapp-link): área de toque maior que o ícone. */
.whatsapp-link {
    display: inline-grid;
    place-items: center;
    width: 1.9rem;
    height: 1.9rem;
    margin-left: .2rem;
    vertical-align: middle;
    border-radius: 50%;
    color: var(--app-whatsapp);
    font-size: 1.05rem;
    text-decoration: none;
}

.whatsapp-link:hover, .whatsapp-link:focus-visible { background: color-mix(in srgb, var(--app-whatsapp) 14%, transparent); color: var(--app-whatsapp); }

/* ---------------------------------------------------------------------------
 * Menu lateral na cor da instituição (sistema de atendimento, RF-ATD-08). O fundo já vem ajustado no
 * servidor (BrandColor::sidebar) para o texto do menu ter 5:1; o "véu" do hover e das linhas vai para
 * longe do texto (escurece com texto branco, clareia com texto escuro), então o contraste só sobe. O
 * item ativo é uma pílula da cor da superfície com o tom legível da marca (como o resto da tela).
 * ------------------------------------------------------------------------- */
/* !important: a partir de 992 px o Bootstrap põe `background-color: transparent !important` no .offcanvas-lg do menu.
   Sem ele, no computador o menu ficava sem a cor da instituição e o texto claro sumia no fundo da página. */
.sidebar { background-color: var(--brand-sidebar) !important; color: var(--brand-on-sidebar); border-right-color: transparent; }
.sidebar-brand, .sidebar-footer { border-color: color-mix(in srgb, var(--brand-sidebar) 78%, var(--brand-sidebar-veil)); }
.sidebar-brand small, .sidebar-section, .sidebar-footer { color: var(--brand-on-sidebar); }
.sidebar .brand-mark { background: #fff; padding: 3px; color: var(--brand-primary-text); }
.sidebar .nav-link, .sidebar .nav-link i, .sidebar .nav-link:hover i, .sidebar .nav-toggle { color: var(--brand-on-sidebar); }
.sidebar .nav-link:hover, .sidebar .nav-link:focus-visible { color: var(--brand-on-sidebar); background: color-mix(in srgb, var(--brand-sidebar) 78%, var(--brand-sidebar-veil)); }
.sidebar .nav-link.active, .sidebar .nav-link.active:hover { color: var(--brand-primary-text); background: var(--app-surface); box-shadow: var(--app-shadow-sm); }
.sidebar .nav-link.active i { color: var(--brand-primary-text); }
.sidebar-nav > .nav-link.active::before,
.sidebar-nav > .nav-group > div > .nav-link.active::before { background: var(--brand-on-sidebar); }
.sidebar-subnav { border-left-color: color-mix(in srgb, var(--brand-sidebar) 70%, var(--brand-sidebar-veil)); }
.sidebar .btn-close { filter: var(--brand-sidebar-close-filter); opacity: 1; }
body.sidebar-collapsed .sidebar-section { border-top-color: color-mix(in srgb, var(--brand-sidebar) 70%, var(--brand-sidebar-veil)); }
.sidebar-nav::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--brand-on-sidebar) 35%, transparent); }

/* ---------------------------------------------------------------------------
 * Tema escuro (botão na barra superior; preferência "theme" em users.preferences). O Bootstrap
 * troca os componentes por [data-bs-theme=dark]; aqui só os tokens --app-*, os tons da marca e as
 * classes "claras fixas" usadas nas telas (bg-light, bg-white, text-bg-light, text-dark).
 * ------------------------------------------------------------------------- */
:root[data-bs-theme="dark"] {
    --brand-primary-text: var(--brand-primary-text-dark);
    --brand-primary-text-rgb: var(--brand-primary-text-dark-rgb);
    --brand-secondary-text: var(--brand-secondary-text-dark);
    --brand-primary-strong: color-mix(in srgb, var(--brand-primary-text) 78%, #fff);
    --brand-primary-soft: rgba(var(--brand-primary-text-rgb), .16);

    --app-bg: #0b1120;
    --app-surface: #131c2e;
    --app-surface-muted: #1c2638;
    --app-surface-subtle: #172033;
    --app-overlay: rgba(11, 17, 32, .82);
    --app-text: #e2e8f0;
    --app-text-soft: #cbd5e1;
    --app-text-nav: #b6c2d3;
    --app-text-muted: #94a3b8;
    --app-text-faint: #64748b;
    --app-border: #253149;
    --app-border-strong: #34425c;
    --app-shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --app-shadow-md: 0 12px 32px -12px rgba(0, 0, 0, .7);
    --app-block-bg: rgba(217, 164, 65, .14);
    --app-block-border: #a37b2f;
    --app-block-text: #e9c77e;
    --app-whatsapp: #25d366;

    --bs-secondary-bg: var(--app-surface-muted);
    --bs-body-bg-rgb: 19, 28, 46;

    /* Menu lateral: no escuro, só um toque da cor da instituição sobre a superfície (texto claro, 6:1 ou mais). */
    --brand-sidebar: color-mix(in srgb, var(--brand-primary) 22%, #131c2e);
    --brand-on-sidebar: #e2e8f0;
    --brand-sidebar-veil: #000;
    --brand-sidebar-close-filter: invert(1) grayscale(100%) brightness(200%);
}
[data-bs-theme="dark"] .sidebar .brand-mark { background: transparent; padding: 0; }

[data-bs-theme="dark"] .bg-white { background-color: var(--app-surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--app-surface-muted) !important; }
[data-bs-theme="dark"] .text-dark { color: var(--app-text) !important; }
[data-bs-theme="dark"] .text-bg-light { color: var(--app-text-soft) !important; background-color: var(--app-surface-muted) !important; }
[data-bs-theme="dark"] .table-light { --bs-table-bg: var(--app-surface-subtle); --bs-table-color: var(--app-text); --bs-table-border-color: var(--app-border); }
[data-bs-theme="dark"] .card.border-warning { border-color: #a37b2f !important; }
[data-bs-theme="dark"] .brand-mark img { filter: drop-shadow(0 0 1px rgba(255, 255, 255, .35)); }
[data-bs-theme="dark"] .fc { --fc-border-color: var(--app-border); --fc-page-bg-color: var(--app-surface); --fc-neutral-bg-color: var(--app-surface-muted); --fc-list-event-hover-bg-color: var(--app-surface-muted); --fc-today-bg-color: rgba(var(--brand-primary-text-rgb), .1); }
[data-bs-theme="dark"] .leaflet-container { background: var(--app-surface-muted); }
/* Horário livre: a borda tracejada continua na cor do profissional; o texto, legível no fundo escuro. */
[data-bs-theme="dark"] .agenda-ev-free .fc-event-main, [data-bs-theme="dark"] .agenda-ev-free .fc-event-title { color: var(--app-text-soft) !important; }

/* Troca de tema sem piscar transições (o script liga a classe por um instante). */
.theme-switching, .theme-switching * { transition: none !important; }

