/* ==========================================================================
   FixLock — Tema
   --------------------------------------------------------------------------
   Sobrescreve as classes do Bootstrap 5.1.0 efetivamente usadas no projeto,
   consumindo os tokens de tokens.css. Carregado DEPOIS do Bootstrap.

   Nenhum valor de cor literal deve aparecer aqui: sempre var(--fx-*).

   NOTA SOBRE OS BOTÕES LEGADOS
   Neste projeto as classes do Bootstrap são usadas com semântica invertida:
   "btn-danger" é o botão de ação principal ("+ Novo") e "btn-primary" é o
   botão secundário ("Filtrar"). O mapeamento abaixo segue o USO REAL, para
   que as telas ainda não migradas permaneçam coerentes. As telas migradas
   passam a usar as classes canônicas fx-btn-*.
   ========================================================================== */

/* ==========================================================================
   1. BASE
   ========================================================================== */

html, body {
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-base);
    line-height: var(--fx-line-height-base);
    color: var(--fx-text-body);
    background-color: var(--fx-surface-page);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Foco visível — rede de segurança para todo elemento interativo.
   Regras mais específicas adiante refinam por componente; esta garante que
   nada fique sem indicador de foco ao navegar por teclado.
   Usa :focus-visible para não aparecer em clique de mouse. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 2px solid var(--fx-color-primary);
    outline-offset: 2px;
    border-radius: var(--fx-radius-xs);
}

/* Remove o outline padrão apenas quando o foco NÃO vem do teclado */
:where(a, button, input, select, textarea):focus:not(:focus-visible) {
    outline: none;
}

/* ==========================================================================
   2. TIPOGRAFIA
   ========================================================================== */

h1, h2, h3, h4, h5, h6 {
    color: var(--fx-text-heading);
    font-weight: var(--fx-font-weight-semibold);
    line-height: var(--fx-line-height-tight);
    margin-top: 0;
}

h1 { font-size: var(--fx-font-size-2xl); }
h2 { font-size: var(--fx-font-size-xl); }

/* h3 é o título de tela em todas as páginas do projeto */
h3 {
    font-size: var(--fx-font-size-xl);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
    letter-spacing: -.01em;
    text-transform: none;
    margin-bottom: 0;
}

h4 { font-size: var(--fx-font-size-lg); }
h5, h6 { font-size: var(--fx-font-size-md); }

label {
    display: block;
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-body);
    margin-bottom: var(--fx-space-1);
}

a {
    color: var(--fx-text-link);
    text-decoration: none;
    transition: color var(--fx-transition-fast);
}

a:hover {
    color: var(--fx-text-link-hover);
    text-decoration: underline;
}

.text-muted { color: var(--fx-text-muted) !important; }
.small { font-size: var(--fx-font-size-sm); }

/* ==========================================================================
   3. BOTÕES
   ========================================================================== */

.btn,
.fx-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--fx-space-2);
    height: var(--fx-control-height-md);
    padding: 0 var(--fx-space-4);
    border: 1px solid transparent;
    border-radius: var(--fx-radius-sm);
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-medium);
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color var(--fx-transition-base),
                border-color var(--fx-transition-base),
                color var(--fx-transition-base),
                box-shadow var(--fx-transition-base);
}

.btn:focus-visible,
.fx-btn:focus-visible {
    outline: none;
    box-shadow: var(--fx-focus-ring);
}

.btn:disabled,
.btn.disabled,
.fx-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-sm,
.fx-btn-sm {
    height: var(--fx-control-height-sm);
    padding: 0 var(--fx-space-3);
    font-size: var(--fx-font-size-sm);
}

.fx-btn-lg { height: var(--fx-control-height-lg); padding: 0 var(--fx-space-5); }

/* --- Nível 1: PRIMÁRIO — vermelho preenchido. Salvar, Novo. ------------- */
.fx-btn-primary,
.btn-primary,
.btn-danger,
.btn-success {
    background-color: var(--fx-color-primary);
    border-color: var(--fx-color-primary);
    color: var(--fx-color-on-primary);
    box-shadow: var(--fx-shadow-xs);
}

.fx-btn-primary:hover,
.btn-primary:hover,
.btn-danger:hover,
.btn-success:hover {
    background-color: var(--fx-color-primary-hover);
    border-color: var(--fx-color-primary-hover);
    color: var(--fx-color-on-primary);
}

.fx-btn-primary:active,
.btn-primary:active,
.btn-danger:active,
.btn-success:active {
    background-color: var(--fx-color-primary-active);
    border-color: var(--fx-color-primary-active);
}

/* --- Nível 2: SECUNDÁRIO — contorno neutro. Filtrar, Cancelar. ---------- */
.fx-btn-secondary,
.btn-secondary,
.btn-warning,
.btn-light,
.btn-outline {
    background-color: var(--fx-surface);
    border-color: var(--fx-border-strong);
    color: var(--fx-text-body);
    box-shadow: var(--fx-shadow-xs);
}

.fx-btn-secondary:hover,
.btn-secondary:hover,
.btn-warning:hover,
.btn-light:hover,
.btn-outline:hover {
    background-color: var(--fx-surface-hover);
    border-color: var(--fx-border-strong);
    color: var(--fx-text-heading);
}

.fx-btn-secondary:focus-visible,
.btn-secondary:focus-visible {
    box-shadow: var(--fx-focus-ring-neutral);
}

/* --- Nível 3: DESTRUTIVO — contorno vermelho escuro + ícone. ------------ */
/* Nunca preenchido: o vermelho preenchido é da marca, o vazado é do perigo. */
.fx-btn-danger {
    background-color: var(--fx-surface);
    border-color: var(--fx-color-danger);
    color: var(--fx-color-danger);
    box-shadow: var(--fx-shadow-xs);
}

.fx-btn-danger:hover {
    background-color: var(--fx-color-danger-subtle);
    border-color: var(--fx-color-danger-hover);
    color: var(--fx-color-danger-hover);
}

/* --- Botão apenas texto ------------------------------------------------- */
.fx-btn-ghost,
.btn-link {
    background-color: transparent;
    border-color: transparent;
    color: var(--fx-text-body);
    box-shadow: none;
    text-decoration: none;
}

.fx-btn-ghost:hover,
.btn-link:hover {
    background-color: var(--fx-surface-hover);
    color: var(--fx-text-heading);
    text-decoration: none;
}

/* --- Botão só de ícone, usado nas ações de linha da tabela -------------- */
.fx-btn-icon {
    width: var(--fx-control-height-sm);
    height: var(--fx-control-height-sm);
    padding: 0;
    background-color: transparent;
    border-color: transparent;
    color: var(--fx-text-muted);
    box-shadow: none;
}

.fx-btn-icon:hover {
    background-color: var(--fx-surface-hover);
    color: var(--fx-text-heading);
}

.fx-btn-icon.is-danger:hover {
    background-color: var(--fx-color-danger-subtle);
    color: var(--fx-color-danger);
}

/* ==========================================================================
   4. FORMULÁRIOS
   ========================================================================== */

/* .form-group é classe do Bootstrap 4 e NÃO existe no Bootstrap 5.
   O projeto a usa 77 vezes; sem esta regra esses campos ficam sem estilo. */
.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-bottom: var(--fx-space-4);
}

.form-control,
.form-select,
select.form-control,
textarea.form-control {
    display: block;
    width: 100%;
    height: var(--fx-control-height-md);
    padding: 0 var(--fx-space-3);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border-strong);
    border-radius: var(--fx-radius-sm);
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-base);
    color: var(--fx-text-body);
    box-shadow: var(--fx-shadow-xs);
    transition: border-color var(--fx-transition-base),
                box-shadow var(--fx-transition-base);
}

textarea.form-control {
    height: auto;
    min-height: 88px;
    padding: var(--fx-space-2) var(--fx-space-3);
    line-height: var(--fx-line-height-base);
}

.form-control::placeholder {
    color: var(--fx-text-placeholder);
}

.form-control:hover,
.form-select:hover {
    border-color: var(--fx-gray-400);
}

.form-control:focus,
.form-select:focus {
    outline: none;
    border-color: var(--fx-border-focus);
    box-shadow: var(--fx-focus-ring);
}

.form-control:disabled,
.form-control[readonly],
.form-select:disabled {
    background-color: var(--fx-surface-sunken);
    color: var(--fx-text-muted);
    cursor: not-allowed;
}

/* Selects nativos: seta própria, já que o Bootstrap 5 só a aplica em
   .form-select e o projeto usa .form-control em <select> */
select.form-control,
.form-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: var(--fx-space-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--fx-space-3) center;
    cursor: pointer;
}

/* Validação */
.valid.modified:not([type=checkbox]) {
    outline: none;
    border-color: var(--fx-color-success);
}

.invalid {
    outline: none;
    border-color: var(--fx-color-danger);
}

.invalid:focus {
    box-shadow: 0 0 0 3px rgba(162, 34, 42, .20);
}

.validation-message {
    display: block;
    margin-top: var(--fx-space-1);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-color-danger);
}

/* Campo de busca com ícone à esquerda */
.fx-search {
    position: relative;
    display: flex;
    align-items: center;
}

.fx-search .fx-search-icon {
    position: absolute;
    left: var(--fx-space-3);
    display: flex;
    color: var(--fx-text-placeholder);
    pointer-events: none;
}

.fx-search .form-control {
    padding-left: var(--fx-space-10);
}

/* ==========================================================================
   5. TABELAS
   ========================================================================== */

.table {
    width: 100%;
    margin-bottom: 0;
    background-color: var(--fx-surface);
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--fx-font-size-base);
    color: var(--fx-text-body);
}

.table > thead > tr > th,
.table > thead th {
    padding: var(--fx-space-3) var(--fx-space-4);
    background-color: var(--fx-table-head-bg);
    border: none;
    border-bottom: 1px solid var(--fx-gray-300);
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-bold);
    color: var(--fx-table-head-text);
    text-transform: uppercase;
    letter-spacing: .06em;
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
}

.table > tbody > tr > td,
.table > tbody td {
    padding: var(--fx-space-4);
    border: none;
    border-bottom: 1px solid var(--fx-border);
    vertical-align: middle;
    color: var(--fx-text-body);
}

/* --- Hierarquia dentro da linha -----------------------------------------
   Sem hierarquia, toda célula tem o mesmo peso e a tabela vira um bloco
   cinza uniforme. A coluna que identifica o registro puxa a leitura. */

.table td.fx-cell-principal {
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

/* Datas e números: fonte tabular, para as colunas alinharem verticalmente */
.table td.fx-cell-data,
.table td.fx-cell-num {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    color: var(--fx-text-muted);
    white-space: nowrap;
}

.table td.fx-cell-num {
    text-align: right;
}

.table th.fx-cell-num {
    text-align: right;
}

.table > tbody > tr:last-child > td {
    border-bottom: none;
}

/* Neutraliza as bordas pesadas do Bootstrap */
.table-bordered,
.table-bordered > :not(caption) > * ,
.table-bordered > :not(caption) > * > * {
    border: none;
}

.table-bordered > tbody > tr > td,
.table-bordered > thead > tr > th {
    border-bottom: 1px solid var(--fx-border);
}

/* Zebra bem mais sutil que o padrão */
.table-striped > tbody > tr:nth-of-type(odd) > * {
    background-color: transparent;
    box-shadow: none;
    color: var(--fx-text-body);
}

.table-striped > tbody > tr:nth-of-type(even) > * {
    background-color: var(--fx-gray-25);
    box-shadow: none;
    color: var(--fx-text-body);
}

.table > tbody > tr {
    transition: background-color var(--fx-transition-fast);
}

.table-hover > tbody > tr:hover > *,
.table > tbody > tr:hover > * {
    background-color: var(--fx-surface-selected);
    color: var(--fx-text-body);
}

.table-sm > :not(caption) > * > * {
    padding: var(--fx-space-2) var(--fx-space-3);
}

/* Contêiner da tabela: borda, raio e rolagem horizontal própria.
   O corpo da página nunca rola na horizontal. */
.fx-table-wrap {
    width: 100%;
    overflow-x: auto;
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
}

.table-wrapper-scroll-y {
    max-height: 65vh;
    overflow-y: auto;
}

/* Cabeçalho ordenável */
.fx-th-sortable {
    cursor: pointer;
    user-select: none;
}

.fx-th-sortable:hover {
    color: var(--fx-text-body);
}

.fx-sort-icon {
    display: inline-flex;
    margin-left: var(--fx-space-1);
    vertical-align: middle;
    opacity: .35;
    transition: opacity var(--fx-transition-fast);
}

.fx-th-sortable:hover .fx-sort-icon { opacity: .7; }
.fx-th-sortable.is-active { color: var(--fx-color-primary); }
.fx-th-sortable.is-active .fx-sort-icon { opacity: 1; }

/* ==========================================================================
   6. CARTÕES E SUPERFÍCIES
   ========================================================================== */

.card,
.fx-card {
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
}

.card-header {
    padding: var(--fx-space-4);
    background-color: transparent;
    border-bottom: 1px solid var(--fx-border);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

.card-body,
.card-content {
    padding: var(--fx-space-4);
}

.grey-bg {
    background-color: var(--fx-surface-sunken);
}

/* ==========================================================================
   CABEÇALHO DE TELA
   ========================================================================== */

.fx-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fx-space-5);
    flex-wrap: wrap;
    padding-bottom: var(--fx-space-5);
    margin-bottom: var(--fx-space-5);
    border-bottom: 1px solid var(--fx-border);
}

.fx-page-header-main {
    display: flex;
    align-items: center;
    gap: var(--fx-space-4);
    min-width: 0;
}

/* Marca de acento: quadrado arredondado com o ícone da tela */
.fx-page-header-icone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: var(--fx-radius-lg);
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-primary);
}

.fx-page-header-texto { min-width: 0; }

.fx-page-header-titulo {
    margin: 0;
    font-size: var(--fx-font-size-xl);
    font-weight: var(--fx-font-weight-bold);
    line-height: 1.15;
    color: var(--fx-text-heading);
    letter-spacing: -.02em;
}

.fx-page-header-subtitle {
    margin-top: 3px;
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-muted);
}

.fx-page-header-acoes {
    display: flex;
    align-items: center;
    gap: var(--fx-space-2);
    flex-shrink: 0;
}

/* O botão de ação principal do cabeçalho é maior que os demais */
.fx-page-header-acoes .fx-btn-primary {
    height: var(--fx-control-height-lg);
    padding: 0 var(--fx-space-5);
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-semibold);
}

@media (max-width: 640px) {
    .fx-page-header-acoes { width: 100%; }
    .fx-page-header-acoes .fx-btn { flex: 1 1 auto; }
}

/* ==========================================================================
   PAINEL DE FILTROS
   ========================================================================== */

.fx-filters {
    padding: var(--fx-space-4) var(--fx-space-5);
    margin-bottom: var(--fx-space-5);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
}

/* align-items: flex-end alinha todos os controles pela base, independentemente
   de o rótulo quebrar em duas linhas. É o que substitui o antigo
   style="margin-top: 21px" cravado em cada botão de filtrar. */
.fx-filters-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--fx-space-3) var(--fx-space-4);
}

.fx-filters-row > .form-group {
    flex: 1 1 190px;
    min-width: 170px;
    margin-bottom: 0;
}

/* O rótulo tem altura fixa para que campos com e sem rótulo fiquem alinhados */
.fx-filters-row > .form-group > label,
.fx-filters-row label,
.fx-filters-bar label {
    min-height: 18px;
    margin-bottom: var(--fx-space-2);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-body);
}

/* Barra de filtros: painel e linha no mesmo elemento.
   Permite converter as telas legadas trocando apenas a classe do <div>,
   sem alterar a estrutura de elementos. */
.fx-filters-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: var(--fx-space-3) var(--fx-space-4);
    padding: var(--fx-space-4) var(--fx-space-5);
    margin-bottom: var(--fx-space-5);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
}

.fx-filters-bar > .form-group,
.fx-filters-bar > .col-2,
.fx-filters-bar > .col-3,
.fx-filters-bar > .col-4 {
    flex: 1 1 190px;
    min-width: 170px;
    max-width: none;
    width: auto;
    padding: 0;
    margin-bottom: 0;
}

/* Colunas do Bootstrap usadas como contêiner de filtro: o form-group interno
   deixa de ter margem e recuo próprios */
.fx-filters-bar > [class*="col-"] > .form-group {
    margin-bottom: 0;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* Grupos que contêm apenas botões não crescem e alinham pela base.
   `.fx-filters-actions` é a forma canônica e não depende de :has() — a versão
   com :has() falhava quando havia MAIS DE UM botão no grupo (:only-child). */
.fx-filters-bar > .fx-filters-actions,
.fx-filters-row > .fx-filters-actions,
.fx-filters-bar > .form-group:has(> .fx-btn:only-child),
.fx-filters-bar > .form-group:has(> .btn:only-child) {
    flex: 0 0 auto;
    min-width: 0;
    align-self: flex-end;
}

/* Dentro da barra de filtros, o grupo de ações herda o alinhamento pela base */
.fx-filters-bar > .fx-filters-actions {
    padding-bottom: 0;
}

/* Quebra de linha dentro da barra: item de largura total e altura zero, que faz
   o flex-wrap jogar para a linha seguinte tudo que vier depois.

   Serve para telas com muitos filtros, onde a quebra natural depende da largura
   da janela e separa campos que deveriam ficar juntos — datas e o botão que as
   aplica, por exemplo. Assim o agrupamento é decidido no markup e continua
   dentro do MESMO painel branco, sem precisar de uma segunda barra.

   O espaço entre as duas linhas fica um pouco maior que o de uma quebra
   natural, porque o item consome o `gap` acima e abaixo. É proposital: separa
   os grupos sem exigir uma borda. */
.fx-filters-bar > .fx-filters-quebra {
    flex: 0 0 100%;
    height: 0;
    margin: 0;
    padding: 0;
}

/* Anula os recuos legados (ps-4 / ms-2) — o espaçamento vem do gap */
.fx-filters-bar > .ps-4,
.fx-filters-bar > .ms-2,
.fx-filters-bar > .mt-1,
.fx-filters-bar > .mt-2 {
    padding-left: 0 !important;
    margin-left: 0 !important;
    margin-top: 0 !important;
}

.fx-filters-advanced {
    display: none;
    padding-top: var(--fx-space-4);
    margin-top: var(--fx-space-4);
    border-top: 1px solid var(--fx-border);
}

.fx-filters-advanced.is-open {
    display: block;
}

/* Campo de busca: ocupa o dobro do espaço dos selects na mesma linha */
.fx-filters-row > .fx-filter-busca {
    flex: 2 1 260px;
}

/* Grupo de botões alinhado à base da linha de filtros */
.fx-filters-actions {
    display: flex;
    align-items: center;
    gap: var(--fx-space-2);
    padding-bottom: 1px;
}

/* Tabela dentro de um card: o card já provê borda, raio e sombra */
.fx-card > .fx-table-wrap {
    border: none;
    box-shadow: none;
    border-radius: 0;
    overflow: hidden;
}

/* Cantos do card acompanham a tabela */
.fx-card > .fx-table-wrap > .table > thead > tr:first-child > th:first-child {
    border-top-left-radius: var(--fx-radius-md);
}

.fx-card > .fx-table-wrap > .table > thead > tr:first-child > th:last-child {
    border-top-right-radius: var(--fx-radius-md);
}

/* Última linha sem borda inferior, para não duplicar com a do card */
.fx-card > .fx-table-wrap > .table > tbody > tr:last-child > td {
    border-bottom: none;
}

/* Célula de ações: largura mínima fixa, à direita, sem quebra.
   A largura fixa impede que a coluna "pule" quando um usuário sem permissão
   vê a célula vazia. */
.fx-cell-acoes {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

.table td.fx-cell-acoes {
    padding-top: var(--fx-space-2);
    padding-bottom: var(--fx-space-2);
}

/* Botões de ação em linha, encostados à direita */
.table td.fx-cell-acoes .fx-btn-icon {
    vertical-align: middle;
}

.table td.fx-cell-acoes .fx-btn-icon + .fx-btn-icon {
    margin-left: 2px;
}

/* Menu suspenso ancorado à direita da célula */
.fx-dropdown-anchor {
    position: relative;
}

.fx-dropdown-anchor .dropdown-menu {
    position: absolute;
    right: 0;
    z-index: var(--fx-z-modal);
    list-style: none;
    margin: 0;
}

/* Seletor de itens por página */
.fx-page-size {
    width: auto;
    height: 32px;
    padding-right: var(--fx-space-6);
    font-size: var(--fx-font-size-sm);
}

/* Reticências entre blocos de páginas */
.fx-page-ellipsis {
    padding: 0 var(--fx-space-1);
    color: var(--fx-text-muted);
}

/* ==========================================================================
   7. NAVEGAÇÃO
   ========================================================================== */

.sidebar {
    background-color: var(--fx-surface);
    background-image: none !important; /* anula o gradiente inline legado */
    border-right: 1px solid var(--fx-border);
}

.navbar,
.navbar-dark {
    background-color: transparent !important;
}

.navbar-brand,
.navbar-dark .navbar-brand {
    color: var(--fx-text-heading);
    font-weight: var(--fx-font-weight-bold);
    letter-spacing: -.01em;
}

/* Defesa: `navbar-dark` deixa o texto branco no Bootstrap. Com a sidebar
   agora clara, isso o tornaria invisível nas telas ainda não migradas. */
.navbar-dark .navbar-nav .nav-link,
.navbar-dark .navbar-text {
    color: var(--fx-text-body);
}

.navbar-toggler {
    border-color: var(--fx-border-strong);
    color: var(--fx-text-body);
}

.navbar-toggler:focus-visible {
    outline: none;
    box-shadow: var(--fx-focus-ring);
}

.nav-item {
    margin-bottom: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    padding: var(--fx-space-2) var(--fx-space-3);
    border-radius: var(--fx-radius-sm);
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-body);
    text-decoration: none;
    transition: background-color var(--fx-transition-fast),
                color var(--fx-transition-fast);
}

.nav-link:hover {
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-text-heading);
    text-decoration: none;
}

.nav-link:focus-visible {
    outline: none;
    box-shadow: var(--fx-focus-ring);
}

/* Item ativo: fundo suave + barra vermelha à esquerda */
.nav-link.active {
    position: relative;
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-danger);
    font-weight: var(--fx-font-weight-semibold);
}

.nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-color-primary);
}

.nav-link .fx-icon {
    flex-shrink: 0;
    color: var(--fx-text-muted);
}

.nav-link.active .fx-icon,
.nav-link:hover .fx-icon {
    color: currentColor;
}

/* ==========================================================================
   8. DROPDOWN
   ========================================================================== */

.dropdown-menu {
    padding: var(--fx-space-1);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-lg);
}

.dropdown-item {
    padding: var(--fx-space-2) var(--fx-space-3);
    border-radius: var(--fx-radius-xs);
    font-size: var(--fx-font-size-base);
    color: var(--fx-text-body);
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--fx-surface-hover);
    color: var(--fx-text-heading);
}

/* ==========================================================================
   9. BADGES DE STATUS
   ========================================================================== */

.fx-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--fx-space-2);
    padding: 2px var(--fx-space-2);
    border-radius: var(--fx-radius-full);
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-medium);
    line-height: 18px;
    white-space: nowrap;
}

.fx-badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--fx-radius-full);
    background-color: currentColor;
    flex-shrink: 0;
}

.fx-badge-success {
    background-color: var(--fx-color-success-subtle);
    color: var(--fx-color-success);
}

.fx-badge-warning {
    background-color: var(--fx-color-warning-subtle);
    color: var(--fx-color-warning);
}

.fx-badge-danger {
    background-color: var(--fx-color-danger-subtle);
    color: var(--fx-color-danger);
}

.fx-badge-info {
    background-color: var(--fx-color-info-subtle);
    color: var(--fx-color-info);
}

.fx-badge-neutral {
    background-color: var(--fx-color-neutral-subtle);
    color: var(--fx-color-neutral);
}

/* Utilitários de cor do Bootstrap, remapeados */
.bg-primary { background-color: var(--fx-color-primary) !important; }
.bg-danger  { background-color: var(--fx-color-danger) !important; }
.bg-secondary { background-color: var(--fx-gray-500) !important; }
.text-primary { color: var(--fx-color-primary) !important; }
.text-danger  { color: var(--fx-color-danger) !important; }
.text-success { color: var(--fx-color-success) !important; }
.text-warning { color: var(--fx-color-warning) !important; }
.text-secondary { color: var(--fx-text-muted) !important; }

/* ==========================================================================
   10. ESTADOS: CARREGANDO, VAZIO, ERRO
   ========================================================================== */

.fx-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--fx-space-3);
    padding: var(--fx-space-12) var(--fx-space-6);
    text-align: center;
}

.fx-state-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-surface-sunken);
    color: var(--fx-text-placeholder);
}

.fx-state-title {
    font-size: var(--fx-font-size-md);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

.fx-state-text {
    max-width: 420px;
    font-size: var(--fx-font-size-base);
    color: var(--fx-text-muted);
}

.fx-state-error .fx-state-icon {
    background-color: var(--fx-color-danger-subtle);
    color: var(--fx-color-danger);
}

/* Indicador de carregamento — substitui o .lds-dual-ring */
.fx-spinner {
    display: inline-block;
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--fx-border);
    border-top-color: var(--fx-color-primary);
    border-radius: var(--fx-radius-full);
    animation: fx-spin .7s linear infinite;
}

.fx-spinner-sm { width: 16px; height: 16px; border-width: 2px; }
.fx-spinner-lg { width: 40px; height: 40px; border-width: 3px; }

@keyframes fx-spin {
    to { transform: rotate(360deg); }
}

/* Placeholder cintilante para carregamento de linhas de tabela */
.fx-skeleton {
    background: linear-gradient(90deg,
        var(--fx-gray-100) 25%,
        var(--fx-gray-200) 37%,
        var(--fx-gray-100) 63%);
    background-size: 400% 100%;
    border-radius: var(--fx-radius-xs);
    animation: fx-skeleton 1.4s ease infinite;
}

@keyframes fx-skeleton {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* Mantém o carregador legado utilizável até a migração completa */
.lds-dual-ring {
    display: inline-block;
    width: 40px;
    height: 40px;
}

.lds-dual-ring::after {
    content: "";
    display: block;
    width: 32px;
    height: 32px;
    margin: 4px;
    border: 2.5px solid var(--fx-border);
    border-top-color: var(--fx-color-primary);
    border-radius: var(--fx-radius-full);
    animation: fx-spin .7s linear infinite;
}

/* ==========================================================================
   11. PAGINAÇÃO
   ========================================================================== */

.fx-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fx-space-4);
    flex-wrap: wrap;
    padding: var(--fx-space-3) var(--fx-space-4);
    border-top: 1px solid var(--fx-border);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-muted);
}

.fx-pagination-controls {
    display: flex;
    align-items: center;
    gap: var(--fx-space-1);
}

.fx-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--fx-space-2);
    border: 1px solid transparent;
    border-radius: var(--fx-radius-sm);
    background-color: transparent;
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-body);
    cursor: pointer;
    transition: background-color var(--fx-transition-fast),
                color var(--fx-transition-fast);
}

.fx-page-btn:hover:not(:disabled) {
    background-color: var(--fx-surface-hover);
}

.fx-page-btn:disabled {
    color: var(--fx-text-placeholder);
    cursor: not-allowed;
}

.fx-page-btn.is-active {
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-danger);
    font-weight: var(--fx-font-weight-semibold);
}

/* ==========================================================================
   12. MODAIS (Blazored.Modal)
   ========================================================================== */

/* O Blazored.Modal 6.0.1 aplica padding: 1.5rem no container e renderiza apenas
   header + content. Zeramos o padding para que o cabeçalho sangre até as bordas;
   o rodapé vem do conteúdo, via .fx-modal-footer. */

.blazored-modal {
    padding: 0 !important;
    overflow: hidden;
    border: none !important;
    border-radius: var(--fx-radius-lg) !important;
    box-shadow: var(--fx-shadow-lg) !important;
    font-family: var(--fx-font-family);
}

/* --- Cabeçalho vermelho ------------------------------------------------ */
.blazored-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fx-space-4);
    padding: var(--fx-space-4) var(--fx-space-5) !important;
    background-color: var(--fx-color-primary);
    color: var(--fx-color-on-primary) !important;
    border-bottom: none !important;
}

.blazored-modal-title,
.blazored-modal-header h1,
.blazored-modal-header h2,
.blazored-modal-header h3,
.blazored-modal-header h4 {
    margin: 0;
    font-size: var(--fx-font-size-md);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-color-on-primary) !important;
    letter-spacing: -.01em;
}

.blazored-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0 !important;
    margin: 0 !important;
    flex-shrink: 0;
    background-color: transparent;
    border: none;
    border-radius: var(--fx-radius-sm);
    font-size: var(--fx-font-size-lg);
    line-height: 1;
    color: var(--fx-color-on-primary);
    opacity: .85;
    cursor: pointer;
    transition: background-color var(--fx-transition-fast), opacity var(--fx-transition-fast);
}

.blazored-modal-close:hover {
    background-color: rgba(255, 255, 255, .18);
    opacity: 1;
}

.blazored-modal-close:focus-visible {
    outline: 2px solid var(--fx-color-on-primary);
    outline-offset: -2px;
}

/* --- Conteúdo ---------------------------------------------------------- */
.blazored-modal-content {
    padding: var(--fx-space-5) !important;
    background-color: var(--fx-surface);
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

/* --- Rodapé vermelho ---------------------------------------------------
   Aplicado pelo componente ao seu bloco de botões. As margens negativas
   igualam o padding do conteúdo, sangrando o rodapé até as bordas. */
.fx-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--fx-space-2);
    flex-wrap: wrap;
    margin: var(--fx-space-5) calc(-1 * var(--fx-space-5)) calc(-1 * var(--fx-space-5));
    padding: var(--fx-space-3) var(--fx-space-5);
    background-color: var(--fx-color-primary);
}

/* Rodapé com conteúdo à esquerda (ex.: aviso) e ações à direita */
.fx-modal-footer.has-info {
    justify-content: space-between;
}

.fx-modal-footer-info {
    font-size: var(--fx-font-size-sm);
    color: var(--fx-color-on-primary);
    opacity: .9;
}

/* --- Contraste invertido dos botões sobre o vermelho -------------------
   Primário: branco preenchido, texto --fx-red-700 (7,50:1)
   Secundário: vazado, borda e texto brancos (4,79:1) */
.fx-modal-footer .fx-btn-primary,
.fx-modal-footer .btn-primary,
.fx-modal-footer .btn-danger,
.fx-modal-footer .btn-success,
.fx-modal-footer button[type="submit"] {
    background-color: var(--fx-color-on-primary);
    border-color: var(--fx-color-on-primary);
    color: var(--fx-color-danger);
    box-shadow: none;
}

.fx-modal-footer .fx-btn-primary:hover,
.fx-modal-footer .btn-primary:hover,
.fx-modal-footer .btn-danger:hover,
.fx-modal-footer .btn-success:hover,
.fx-modal-footer button[type="submit"]:hover {
    background-color: var(--fx-red-50);
    border-color: var(--fx-red-50);
    color: var(--fx-color-danger-hover);
}

.fx-modal-footer .fx-btn-secondary,
.fx-modal-footer .fx-btn-ghost,
.fx-modal-footer .btn-secondary,
.fx-modal-footer .btn-warning,
.fx-modal-footer .btn-outline,
.fx-modal-footer .btn-light {
    background-color: transparent;
    border-color: rgba(255, 255, 255, .65);
    color: var(--fx-color-on-primary);
    box-shadow: none;
}

.fx-modal-footer .fx-btn-secondary:hover,
.fx-modal-footer .fx-btn-ghost:hover,
.fx-modal-footer .btn-secondary:hover,
.fx-modal-footer .btn-warning:hover,
.fx-modal-footer .btn-outline:hover,
.fx-modal-footer .btn-light:hover {
    background-color: rgba(255, 255, 255, .16);
    border-color: var(--fx-color-on-primary);
    color: var(--fx-color-on-primary);
}

/* Destrutivo dentro do rodapé: branco preenchido com texto de perigo,
   distinguido do primário pelo ícone (a forma diferencia, não a cor) */
.fx-modal-footer .fx-btn-danger {
    background-color: var(--fx-color-on-primary);
    border-color: var(--fx-color-on-primary);
    color: var(--fx-color-danger);
}

.fx-modal-footer .fx-btn:focus-visible,
.fx-modal-footer .btn:focus-visible {
    outline: 2px solid var(--fx-color-on-primary);
    outline-offset: 2px;
    box-shadow: none;
}

/* Modais que já vivem dentro de um formulário: o rodapé é o último filho
   do EditForm, então precisa do mesmo tratamento de sangria. */
.blazored-modal-content > form > .fx-modal-footer:last-child,
.blazored-modal-content > .fx-stack > .fx-modal-footer:last-child {
    margin-bottom: calc(-1 * var(--fx-space-5));
}

/* ==========================================================================
   13. UTILITÁRIOS PRÓPRIOS
   Substituem os estilos inline mais repetidos do projeto.
   ========================================================================== */

.fx-stack   { display: flex; flex-direction: column; }
.fx-row     { display: flex; align-items: center; }
.fx-row-end { display: flex; align-items: center; justify-content: flex-end; }
.fx-between { display: flex; align-items: center; justify-content: space-between; }
.fx-wrap    { flex-wrap: wrap; }
.fx-grow    { flex: 1 1 auto; min-width: 0; }

.fx-gap-1 { gap: var(--fx-space-1); }
.fx-gap-2 { gap: var(--fx-space-2); }
.fx-gap-3 { gap: var(--fx-space-3); }
.fx-gap-4 { gap: var(--fx-space-4); }

.fx-text-xs { font-size: var(--fx-font-size-xs); }
.fx-text-sm { font-size: var(--fx-font-size-sm); }
.fx-text-md { font-size: var(--fx-font-size-md); }

.fx-muted   { color: var(--fx-text-muted); }
.fx-strong  { font-weight: var(--fx-font-weight-semibold); color: var(--fx-text-heading); }
.fx-nowrap  { white-space: nowrap; }
.fx-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fx-mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: var(--fx-font-size-sm);
    letter-spacing: -.01em;
}

.fx-upper { text-transform: uppercase; }

/* Ícone inline: herda a cor e o tamanho do contexto */
.fx-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1em;
    height: 1em;
    font-size: 1.15em;
    color: currentColor;
    vertical-align: -.15em;
}

.fx-icon svg { width: 100%; height: 100%; display: block; }

/* ==========================================================================
   14. COMPATIBILIDADE BOOTSTRAP 4
   Classes que o projeto usa e que não existem no Bootstrap 5.
   ========================================================================== */

.text-right { text-align: right !important; }
.text-left  { text-align: left !important; }

/* ==========================================================================
   15. IMPRESSÃO
   ========================================================================== */

@media print {
    .no-print, .no-print *,
    .d-print-none,
    .sidebar,
    .fx-filters,
    .fx-pagination {
        display: none !important;
    }

    body { background-color: #fff; }

    .fx-table-wrap {
        border: none;
        box-shadow: none;
        overflow: visible;
    }

    .table > thead th {
        background-color: #fff;
        color: #000;
    }
}

/* ==========================================================================
   16. GRÁFICOS E INDICADORES
   ========================================================================== */

.fx-indicadores {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--fx-space-4);
    margin-bottom: var(--fx-space-5);
}

.fx-indicador {
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    padding: var(--fx-space-4);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
    transition: box-shadow var(--fx-transition-base), border-color var(--fx-transition-base);
}

.fx-indicador:hover {
    border-color: var(--fx-border-strong);
    box-shadow: var(--fx-shadow-sm);
}

.fx-indicador-icone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--fx-radius-md);
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-primary);
}

.fx-indicador-dados { min-width: 0; }

.fx-indicador-valor {
    font-size: var(--fx-font-size-2xl);
    font-weight: var(--fx-font-weight-bold);
    line-height: 1.1;
    color: var(--fx-text-heading);
    letter-spacing: -.02em;
}

.fx-indicador-rotulo {
    margin-top: 2px;
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-muted);
}

/* --- Contêiner de gráfico ---------------------------------------------- */

.fx-graficos {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: var(--fx-space-4);
}

.fx-grafico {
    padding: var(--fx-space-5);
    background-color: var(--fx-surface);
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-xs);
}

.fx-grafico-titulo {
    margin-bottom: var(--fx-space-5);
    font-size: var(--fx-font-size-md);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

.fx-grafico-vazio {
    padding: var(--fx-space-8) 0;
    text-align: center;
    font-size: var(--fx-font-size-base);
    color: var(--fx-text-muted);
}

/* --- Barras horizontais ------------------------------------------------- */

.fx-grafico-barras {
    display: flex;
    flex-direction: column;
    gap: var(--fx-space-3);
}

.fx-grafico-linha {
    display: grid;
    grid-template-columns: minmax(90px, 30%) 1fr auto;
    align-items: center;
    gap: var(--fx-space-3);
}

.fx-grafico-rotulo {
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-body);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fx-grafico-trilho {
    height: 10px;
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-gray-100);
    overflow: hidden;
}

.fx-grafico-barra {
    height: 100%;
    border-radius: var(--fx-radius-full);
    transition: width var(--fx-transition-slow);
}

.fx-grafico-valor {
    display: flex;
    align-items: baseline;
    gap: var(--fx-space-2);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
    white-space: nowrap;
}

.fx-grafico-percentual {
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-regular);
    color: var(--fx-text-muted);
}

/* --- Rosca --------------------------------------------------------------- */

.fx-rosca {
    display: flex;
    align-items: center;
    gap: var(--fx-space-6);
    flex-wrap: wrap;
}

.fx-rosca-svg {
    width: 150px;
    height: 150px;
    flex-shrink: 0;
    transform: rotate(-90deg);
}

.fx-rosca-trilho {
    fill: none;
    stroke: var(--fx-gray-100);
    stroke-width: 4;
}

.fx-rosca-fatia {
    fill: none;
    stroke-width: 4;
    transition: stroke-dasharray var(--fx-transition-slow);
}

.fx-rosca-total,
.fx-rosca-legenda-centro {
    transform: rotate(90deg);
    transform-origin: 21px 21px;
    text-anchor: middle;
    fill: var(--fx-text-heading);
}

.fx-rosca-total {
    font-size: 6px;
    font-weight: 700;
}

.fx-rosca-legenda-centro {
    font-size: 2.6px;
    font-weight: 400;
    fill: var(--fx-text-muted);
}

.fx-rosca-legenda {
    list-style: none;
    margin: 0;
    padding: 0;
    flex: 1 1 180px;
    display: flex;
    flex-direction: column;
    gap: var(--fx-space-2);
}

.fx-rosca-legenda li {
    display: flex;
    align-items: center;
    gap: var(--fx-space-2);
    font-size: var(--fx-font-size-sm);
}

.fx-rosca-ponto {
    width: 9px;
    height: 9px;
    border-radius: var(--fx-radius-full);
    flex-shrink: 0;
}

.fx-rosca-legenda-rotulo {
    flex: 1 1 auto;
    color: var(--fx-text-body);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fx-rosca-legenda-valor {
    display: flex;
    align-items: baseline;
    gap: var(--fx-space-2);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
    white-space: nowrap;
}

/* ==========================================================================
   17. SIDEBAR
   --------------------------------------------------------------------------
   Fica aqui e não em NavMenu.razor.css porque <NavLink> é um componente: o
   atributo de escopo do CSS isolado não alcança o <a> que ele renderiza, e as
   regras precisariam de ::deep em toda parte.
   ========================================================================== */

.fx-sidebar {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* --- Marca -------------------------------------------------------------- */

.fx-sidebar-marca {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fx-space-3);
    padding: var(--fx-space-5) var(--fx-space-4);
    flex-shrink: 0;
}

.fx-sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    text-decoration: none;
    min-width: 0;
}

.fx-sidebar-logo:hover { text-decoration: none; }

.fx-sidebar-logo-icone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: var(--fx-radius-md);
    background-color: var(--fx-color-primary);
    color: var(--fx-gray-0);
    box-shadow: var(--fx-shadow-xs);
}

.fx-sidebar-logo-texto {
    font-size: var(--fx-font-size-xl);
    font-weight: var(--fx-font-weight-bold);
    color: var(--fx-text-heading);
    letter-spacing: -.02em;
}

.fx-sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--fx-border-strong);
    border-radius: var(--fx-radius-sm);
    color: var(--fx-text-body);
    cursor: pointer;
}

/* --- Navegação ---------------------------------------------------------- */

.fx-sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: var(--fx-space-2) var(--fx-space-3) var(--fx-space-4);
}

.fx-nav-grupo + .fx-nav-grupo {
    margin-top: var(--fx-space-5);
    padding-top: var(--fx-space-5);
    border-top: 1px solid var(--fx-border);
}

.fx-nav-grupo-titulo {
    padding: 0 var(--fx-space-3);
    margin-bottom: var(--fx-space-2);
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
    /* gray-500 e nao gray-400: em gray-400 o rotulo fica em 2,58:1 sobre a
       sidebar clara e reprova no AA. Em gray-500 da 4,97:1. */
    color: var(--fx-gray-500);
}

.fx-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    width: 100%;
    height: 40px;
    padding: 0 var(--fx-space-3);
    margin-bottom: 2px;
    border: none;
    border-radius: var(--fx-radius-sm);
    background: transparent;
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-body);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--fx-transition-fast), color var(--fx-transition-fast);
}

.fx-nav-link:hover {
    background-color: var(--fx-gray-50);
    color: var(--fx-text-heading);
    text-decoration: none;
}

.fx-nav-link .fx-icon {
    flex-shrink: 0;
    color: var(--fx-gray-400);
    transition: color var(--fx-transition-fast);
}

.fx-nav-link:hover .fx-icon { color: var(--fx-gray-600); }

.fx-nav-link.active {
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-danger);
    font-weight: var(--fx-font-weight-semibold);
}

.fx-nav-link.active .fx-icon { color: var(--fx-color-primary); }

.fx-nav-link.active::before {
    content: "";
    position: absolute;
    left: -9px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 22px;
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-color-primary);
}

.fx-nav-link:focus-visible {
    outline: 2px solid var(--fx-color-primary);
    outline-offset: -2px;
}

/* --- Rodapé com o usuário ----------------------------------------------- */

.fx-sidebar-rodape {
    flex-shrink: 0;
    padding: var(--fx-space-3);
    border-top: 1px solid var(--fx-border);
    background-color: var(--fx-gray-25);
}

.fx-sidebar-usuario {
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    padding: var(--fx-space-2) var(--fx-space-3);
    margin-bottom: var(--fx-space-2);
    min-width: 0;
}

.fx-sidebar-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-color-primary-subtle);
    color: var(--fx-color-danger);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-bold);
}

.fx-sidebar-usuario-dados { min-width: 0; }

.fx-sidebar-usuario-nome {
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fx-sidebar-usuario-papel {
    font-size: var(--fx-font-size-xs);
    color: var(--fx-text-muted);
}

.fx-nav-link-sair:hover {
    background-color: var(--fx-color-danger-subtle);
    color: var(--fx-color-danger);
}

.fx-nav-link-sair:hover .fx-icon { color: var(--fx-color-danger); }

@media (max-width: 640px) {
    .fx-sidebar-toggle { display: inline-flex; }
    .fx-sidebar-nav.is-collapsed { display: none; }
    .fx-sidebar-rodape { display: none; }
}

/* ==========================================================================
   18. FORMULÁRIOS DE MODAL E TABELAS EMBUTIDAS
   ========================================================================== */

/* `simple-form` é o contêiner de todos os formulários de modal do projeto.
   As larguras eram cravadas inline (600px, 650px, 760px); agora são classes. */
.simple-form {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.simple-form .row + .row { margin-top: 0; }

.fx-form-sm { width: min(520px, 88vw); }
.fx-form-md { width: min(640px, 90vw); }
.fx-form-lg { width: min(780px, 92vw); }
.fx-form-xl { width: min(980px, 94vw); }

/* Tabela embutida em modal: rolagem própria, sem card em volta */
.fx-table-embed {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-sm);
}

.fx-table-embed .table > thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

/* Célula com texto longo que precisa ser truncado */
.fx-cell-truncate {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Título de seção dentro de um formulário de modal */
.fx-form-secao {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--fx-space-3);
    flex-wrap: wrap;
    padding-bottom: var(--fx-space-2);
    margin: var(--fx-space-5) 0 var(--fx-space-3);
    border-bottom: 1px solid var(--fx-border);
}

.fx-form-secao h3 {
    font-size: var(--fx-font-size-md);
    font-weight: var(--fx-font-weight-semibold);
}

/* ==========================================================================
   19. PÁGINA DE DOCUMENTO (termos de uso, política de privacidade)
   ========================================================================== */

.fx-documento {
    max-width: 78ch;
    margin: var(--fx-space-10) auto;
    padding: 0 var(--fx-space-5);
    font-size: var(--fx-font-size-md);
    line-height: var(--fx-line-height-relaxed);
    color: var(--fx-text-body);
    text-align: justify;
}

.fx-documento h1,
.fx-documento h2,
.fx-documento h3 {
    margin-top: var(--fx-space-8);
    margin-bottom: var(--fx-space-3);
    text-align: left;
}

.fx-documento h1:first-child,
.fx-documento h2:first-child {
    margin-top: 0;
}

.fx-documento p {
    margin-bottom: var(--fx-space-4);
}

.fx-documento ul,
.fx-documento ol {
    margin-bottom: var(--fx-space-4);
    padding-left: var(--fx-space-6);
}

.fx-documento li {
    margin-bottom: var(--fx-space-2);
}

/* ==========================================================================
   20. HISTÓRICO DE DISPOSITIVO
   --------------------------------------------------------------------------
   Tela com abas e três tabelas de log. As cores eram do Bootstrap cravadas
   (#dc3545, #0d6efd, #198754) e os espaçamentos vinham de style inline.
   ========================================================================== */

.fx-hist { width: min(72vw, 1200px); min-height: 300px; }

.fx-hist-corpo {
    max-height: calc(85vh - 160px);
    overflow-y: auto;
    padding: 0 var(--fx-space-1);
}

.fx-hist-contagem {
    margin-bottom: var(--fx-space-2);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-muted);
}

/* Tabela de log: cabeçalho com faixa de acento por aba */
.fx-log-tabela { font-size: var(--fx-font-size-sm); }

.fx-log-tabela > thead > tr > th {
    padding: var(--fx-space-3) var(--fx-space-2);
    background-color: var(--fx-table-head-bg);
    border-bottom: 2px solid var(--fx-log-acento, var(--fx-gray-300));
    color: var(--fx-table-head-text);
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-bold);
    text-transform: uppercase;
    letter-spacing: .05em;
    text-align: center;
}

.fx-log-tabela > tbody > tr {
    text-align: center;
    border-bottom: 1px solid var(--fx-border);
}

.fx-log-tabela > tbody > tr > td {
    padding: var(--fx-space-3) var(--fx-space-2);
    vertical-align: middle;
    color: var(--fx-text-body);
}

.fx-log-tabela td.is-mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: var(--fx-font-size-xs);
    color: var(--fx-text-muted);
}

.fx-log-tabela td.is-muted { color: var(--fx-text-muted); }

/* Acento por tipo de log */
.fx-log-ocorrencias { --fx-log-acento: var(--fx-color-primary); }
.fx-log-periodicos  { --fx-log-acento: var(--fx-blue-500); }
.fx-log-operacoes   { --fx-log-acento: var(--fx-green-500); }

/* Etiqueta de tipo de operação dentro da linha */
.fx-log-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px var(--fx-space-3);
    border-radius: var(--fx-radius-full);
    background-color: var(--fx-color-danger-subtle);
    border: 1px solid var(--fx-red-200);
    color: var(--fx-color-danger);
    font-size: var(--fx-font-size-xs);
    font-weight: var(--fx-font-weight-semibold);
    white-space: nowrap;
}

/* Índice/força de sinal ao lado das barras */
.fx-log-indice {
    min-width: 32px;
    font-size: var(--fx-font-size-xs);
    color: var(--fx-text-muted);
}

/* Comparação de fotos antes/depois */
.fx-foto-par {
    flex: 1;
    max-width: 48%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.fx-foto-divisor {
    width: 2px;
    height: 60%;
    align-self: center;
    background: linear-gradient(180deg, transparent, var(--fx-gray-0), transparent);
}

.fx-foto-grande {
    width: 1024px;
    max-width: 100%;
    height: auto;
    max-height: 75vh;
    object-fit: contain;
    border-radius: var(--fx-radius-md);
}

.fx-foto-grande.is-antes  { border: 2px solid var(--fx-color-primary); }
.fx-foto-grande.is-depois { border: 2px solid var(--fx-green-500); }

/* Abas do histórico */
.fx-abas {
    display: flex;
    gap: var(--fx-space-2);
    flex-wrap: wrap;
    padding: var(--fx-space-2) 0 var(--fx-space-4);
    margin-bottom: var(--fx-space-4);
    border-bottom: 1px solid var(--fx-border);
}

.fx-aba {
    display: inline-flex;
    align-items: center;
    gap: var(--fx-space-2);
    padding: var(--fx-space-2) var(--fx-space-5);
    border: 1px solid transparent;
    border-radius: var(--fx-radius-sm);
    background-color: var(--fx-gray-100);
    color: var(--fx-text-muted);
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-semibold);
    cursor: pointer;
    transition: background-color var(--fx-transition-base), color var(--fx-transition-base);
}

.fx-aba:hover {
    background-color: var(--fx-gray-200);
    color: var(--fx-text-body);
}

.fx-aba.is-ativa {
    background-color: var(--fx-aba-cor, var(--fx-color-primary));
    border-color: var(--fx-aba-cor, var(--fx-color-primary));
    color: var(--fx-gray-0);
    box-shadow: var(--fx-shadow-sm);
}

.fx-aba-ocorrencias  { --fx-aba-cor: var(--fx-color-primary); }
.fx-aba-periodicos   { --fx-aba-cor: var(--fx-blue-700); }
.fx-aba-operacionais { --fx-aba-cor: var(--fx-green-700); }
.fx-aba-fotos        { --fx-aba-cor: var(--fx-gray-700); }

/* Variantes da etiqueta de log */
.fx-log-tag.is-info {
    background-color: var(--fx-color-info-subtle);
    border-color: var(--fx-blue-500);
    color: var(--fx-color-info);
}

.fx-log-tag.is-success {
    background-color: var(--fx-color-success-subtle);
    border-color: var(--fx-green-500);
    color: var(--fx-color-success);
}

/* ==========================================================================
   21. MATRIZ DE PERMISSÕES
   ========================================================================== */

.fx-permissoes-tabela {
    max-height: 340px;
}

.fx-permissoes-tabela .table > thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.fx-permissoes-acao {
    width: 82px;
    text-align: center;
}

.fx-permissoes-modulo {
    display: flex;
    align-items: center;
    gap: var(--fx-space-3);
    margin: 0;
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-medium);
    color: var(--fx-text-body);
    cursor: pointer;
}

/* Submódulo recuado, para a hierarquia ficar legível */
.fx-permissoes-tabela tr.is-filho .fx-permissoes-modulo {
    padding-left: var(--fx-space-6);
    font-weight: var(--fx-font-weight-regular);
    color: var(--fx-text-muted);
}

.fx-permissoes-tabela input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--fx-color-primary);
    cursor: pointer;
}

.fx-permissoes-copiar {
    width: auto;
    min-width: 200px;
    height: var(--fx-control-height-sm);
    font-size: var(--fx-font-size-sm);
}

.fx-permissoes-resumo {
    padding-top: var(--fx-space-2);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-muted);
}

.fx-permissoes-aviso {
    display: flex;
    align-items: flex-start;
    gap: var(--fx-space-2);
    padding: var(--fx-space-3) var(--fx-space-4);
    border: 1px solid var(--fx-blue-500);
    border-radius: var(--fx-radius-sm);
    background-color: var(--fx-color-info-subtle);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-color-info);
}

/* Estados do menu enquanto as permissões carregam ou quando não há acesso */
.fx-nav-carregando,
.fx-nav-vazio {
    display: flex;
    align-items: center;
    gap: var(--fx-space-2);
    padding: var(--fx-space-4) var(--fx-space-3);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-muted);
}

.fx-nav-vazio {
    align-items: flex-start;
    line-height: var(--fx-line-height-base);
}

.fx-nav-vazio .fx-icon { color: var(--fx-color-warning); flex-shrink: 0; margin-top: 2px; }

/* Submódulo no menu: recuado e um pouco menor */
.fx-nav-link.is-filho {
    padding-left: var(--fx-space-8);
    font-size: var(--fx-font-size-sm);
    font-weight: var(--fx-font-weight-regular);
    height: 34px;
}

/* ==========================================================================
   22. TRILHA DE AUDITORIA — apresentação de antes/depois
   ========================================================================== */

.fx-auditoria-campos {
    display: flex;
    flex-direction: column;
    gap: var(--fx-space-1);
    max-width: 460px;
}

.fx-auditoria-campo {
    display: flex;
    align-items: center;
    gap: var(--fx-space-2);
    flex-wrap: wrap;
    font-size: var(--fx-font-size-sm);
    line-height: 1.4;
}

.fx-auditoria-nome {
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

.fx-auditoria-nome::after {
    content: ":";
}

/* O valor anterior aparece riscado, para a leitura ser imediata */
.fx-auditoria-antes {
    padding: 1px var(--fx-space-2);
    border-radius: var(--fx-radius-xs);
    background-color: var(--fx-color-danger-subtle);
    color: var(--fx-color-danger);
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

.fx-auditoria-depois {
    padding: 1px var(--fx-space-2);
    border-radius: var(--fx-radius-xs);
    background-color: var(--fx-color-success-subtle);
    color: var(--fx-color-success);
}

.fx-auditoria-campo .fx-icon {
    color: var(--fx-text-placeholder);
}

/* ==========================================================================
   23. MAPA GERAL
   ========================================================================== */

.fx-mapa-area {
    position: relative;
    width: 100%;
    /* Altura restante da viewport, descontando shell, cabeçalho e filtros */
    height: calc(100vh - 320px);
    min-height: 420px;
    border: 1px solid var(--fx-border);
    border-radius: var(--fx-radius-md);
    overflow: hidden;
    box-shadow: var(--fx-shadow-xs);
}

.fx-mapa {
    width: 100%;
    height: 100%;
    background-color: var(--fx-surface-sunken);
}

/* Estado vazio sobreposto: o contêiner do mapa precisa continuar no DOM,
   senão o Leaflet perde a instância. */
.fx-mapa-vazio {
    position: absolute;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(252, 252, 253, .94);
}

/* Pino do marcador — círculo colorido, sem imagem externa */
.fx-mapa-pino span {
    display: block;
    width: 100%;
    height: 100%;
    border: 2px solid var(--fx-gray-0);
    border-radius: var(--fx-radius-full);
    box-shadow: 0 1px 4px rgba(16, 24, 40, .35);
}

/* Popup */
.leaflet-popup-content-wrapper {
    border-radius: var(--fx-radius-md);
    box-shadow: var(--fx-shadow-lg);
}

.leaflet-popup-content {
    margin: var(--fx-space-4);
    font-family: var(--fx-font-family);
    font-size: var(--fx-font-size-sm);
    line-height: var(--fx-line-height-base);
}

.fx-mapa-popup-titulo {
    font-size: var(--fx-font-size-base);
    font-weight: var(--fx-font-weight-semibold);
    color: var(--fx-text-heading);
}

.fx-mapa-popup-serial {
    margin-top: 2px;
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: var(--fx-font-size-xs);
    color: var(--fx-text-muted);
}

.fx-mapa-popup-dados {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2px var(--fx-space-3);
    margin: var(--fx-space-3) 0 0;
}

.fx-mapa-popup-dados dt {
    font-size: var(--fx-font-size-xs);
    color: var(--fx-text-muted);
    white-space: nowrap;
}

.fx-mapa-popup-dados dd {
    margin: 0;
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-body);
}

/* Ponto que o sistema não conseguiu ligar a nenhum cliente. Só o master vê
   esses, e o itálico deixa claro que é uma lacuna do dado, não um nome. */
.fx-mapa-popup-dados dd.fx-mapa-popup-alerta {
    color: var(--fx-text-muted);
    font-style: italic;
}

/* Legenda */
.fx-mapa-legenda {
    display: flex;
    align-items: center;
    gap: var(--fx-space-5);
    flex-wrap: wrap;
    padding-top: var(--fx-space-3);
    font-size: var(--fx-font-size-sm);
    color: var(--fx-text-body);
}

.fx-mapa-legenda-item {
    display: inline-flex;
    align-items: center;
    gap: var(--fx-space-2);
}

.fx-mapa-legenda-item i {
    width: 12px;
    height: 12px;
    border-radius: var(--fx-radius-full);
    border: 2px solid var(--fx-gray-0);
    box-shadow: 0 1px 3px rgba(16, 24, 40, .3);
}

.fx-mapa-legenda-item i.is-wifi      { background-color: var(--fx-red-500); }
.fx-mapa-legenda-item i.is-bluetooth { background-color: var(--fx-blue-500); }

/* Contagem de dispositivos sem localização, no subtítulo */
.fx-mapa-lacuna {
    color: var(--fx-color-warning);
    font-weight: var(--fx-font-weight-medium);
}

/* O cluster do Leaflet vem com verde/amarelo próprios; alinhados à paleta */
.marker-cluster-small  { background-color: rgba(214, 50, 60, .25); }
.marker-cluster-small div  { background-color: rgba(214, 50, 60, .75); color: #fff; }
.marker-cluster-medium { background-color: rgba(192, 41, 50, .25); }
.marker-cluster-medium div { background-color: rgba(192, 41, 50, .80); color: #fff; }
.marker-cluster-large  { background-color: rgba(162, 34, 42, .25); }
.marker-cluster-large div  { background-color: rgba(162, 34, 42, .85); color: #fff; }

.marker-cluster div {
    font-family: var(--fx-font-family);
    font-weight: var(--fx-font-weight-semibold);
}
