/* ============================================================================
 * TETRAOLI — Design System
 * Sistema unico de design (cores, espacamentos, componentes, utilitarios).
 * Substitui ad-hoc styles inline nas views. Mantem navbar dark + conteudo light.
 * ============================================================================ */

/* ============================================================================
 * 1. DESIGN TOKENS (variaveis CSS)
 * ============================================================================ */
:root {
  /* Cores - superficies */
  --tx-bg:           #f5f6f8;      /* fundo geral do app */
  --tx-surface:      #ffffff;      /* cards, painéis */
  --tx-surface-alt:  #f8f9fb;      /* listras alternadas, hover suave */
  --tx-border:       #e3e6eb;      /* bordas padrão */
  --tx-border-strong:#c5cad3;      /* bordas marcadas */

  /* Cores - texto */
  --tx-text:         #1c2533;      /* texto principal */
  --tx-text-muted:   #6b7280;      /* legendas, labels */
  --tx-text-soft:    #9ca3af;      /* placeholders, dimmed */

  /* Cores - marca / acentos */
  --tx-primary:      #1976d2;      /* azul Tetraoli (CTA, links) */
  --tx-primary-dk:   #1565c0;
  --tx-primary-soft: #e3f2fd;      /* hover, badge bg */

  /* Cores - semanticas */
  --tx-success:      #2e7d32;
  --tx-success-soft: #e6f4ea;
  --tx-danger:       #c62828;
  --tx-danger-soft:  #fdecea;
  --tx-warning:      #f57c00;
  --tx-warning-soft: #fff3e0;
  --tx-info:         #1976d2;
  --tx-info-soft:    #e3f2fd;

  /* Cores - destaques especificos */
  --tx-yellow:       #fff066;       /* balanço amarelo (estilo Excel) */
  --tx-yellow-dk:    #f4dc3a;
  --tx-gray-header:  #cfd8dc;       /* header grupo (inventario) */
  --tx-gray-total:   #b0bec5;       /* total grupo */

  /* Tipografia */
  --tx-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tx-font-mono:    "SF Mono", Menlo, Monaco, Consolas, monospace;
  --tx-fs-xs:        0.75rem;       /* 12px */
  --tx-fs-sm:        0.85rem;       /* 14px */
  --tx-fs-base:      0.95rem;       /* 15px */
  --tx-fs-md:        1.05rem;       /* 17px */
  --tx-fs-lg:        1.25rem;       /* 20px */
  --tx-fs-xl:        1.6rem;        /* 26px */
  --tx-fs-display:   2rem;          /* 32px */
  --tx-lh-tight:     1.25;
  --tx-lh-normal:    1.5;

  /* Espacamento */
  --tx-sp-1:  0.25rem;
  --tx-sp-2:  0.5rem;
  --tx-sp-3:  0.75rem;
  --tx-sp-4:  1rem;
  --tx-sp-5:  1.25rem;
  --tx-sp-6:  1.5rem;
  --tx-sp-8:  2rem;
  --tx-sp-10: 2.5rem;

  /* Border radius */
  --tx-r-sm:  4px;
  --tx-r-md:  6px;
  --tx-r-lg:  10px;
  --tx-r-pill: 999px;

  /* Sombra */
  --tx-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --tx-shadow:    0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --tx-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);

  /* Container */
  --tx-container: 1280px;
}

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

html { font-size: 16px; }

body {
  font-family: var(--tx-font);
  font-size: var(--tx-fs-base);
  line-height: var(--tx-lh-normal);
  color: var(--tx-text);
  background: var(--tx-bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--tx-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: var(--tx-fs-xl); font-weight: 700; line-height: var(--tx-lh-tight); }
h2 { font-size: var(--tx-fs-lg); font-weight: 600; line-height: var(--tx-lh-tight); margin-bottom: var(--tx-sp-3); }
h3 { font-size: var(--tx-fs-md); font-weight: 600; line-height: var(--tx-lh-tight); }

button { font-family: inherit; cursor: pointer; }

/* ============================================================================
 * 3. NAVBAR (mantém estilo dark do posto_tetra, atualizado)
 * ============================================================================ */
.nav-bar {
  background: #0f172a;
  border-bottom: 1px solid #1e293b;
  position: sticky;
  top: 0;
  z-index: 900;
}

.nav-container {
  max-width: var(--tx-container);
  margin: 0 auto;
  padding: 0 var(--tx-sp-6);
  display: flex;
  align-items: center;
  height: 52px;
  gap: var(--tx-sp-6);
}

.nav-brand {
  font-size: 1rem;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #3b82f6, #22c55e);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-links { display: flex; align-items: center; gap: var(--tx-sp-1); flex: 1; }

.nav-link {
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--tx-r-md);
  transition: color 0.15s, background 0.15s;
}

.nav-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.05); text-decoration: none; }
.nav-active     { color: #ffffff; background: rgba(59, 130, 246, 0.18); }

/* Grupo dropdown da navbar (ex: Gestao Comercial). Abre no hover e no foco
   (clique/toque), sem JS. */
.nav-group { position: relative; }
.nav-group-trigger { background: none; border: none; cursor: pointer; font: inherit; font-size: 0.85rem; font-weight: 500; }
.nav-dropdown {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 180px;
  flex-direction: column; gap: 2px;
  background: #0f172a; border: 1px solid #1e293b; border-radius: var(--tx-r-md);
  padding: 6px; box-shadow: 0 10px 28px rgba(0,0,0,0.45); z-index: 1000;
}
.nav-group:hover .nav-dropdown,
.nav-group:focus-within .nav-dropdown { display: flex; }
.nav-dd-link {
  color: #94a3b8; text-decoration: none; font-size: 0.85rem; font-weight: 500;
  padding: 7px 12px; border-radius: var(--tx-r-md); white-space: nowrap;
}
.nav-dd-link:hover { color: #e2e8f0; background: rgba(255,255,255,0.06); text-decoration: none; }
.nav-dd-link.nav-active { color: #fff; background: rgba(59, 130, 246, 0.18); }

.nav-toggle {
  display: none;
  background: none; border: none; color: #e2e8f0; font-size: 1.4rem; padding: 4px 8px;
}

.nav-user { display: flex; align-items: center; gap: var(--tx-sp-3); }
.nav-user-email {
  color: #cbd5e1; font-size: 0.85rem;
  padding: 6px 12px; border-radius: var(--tx-r-md);
}
.nav-user-email:hover { color: #fff; background: rgba(255,255,255,0.06); text-decoration: none; }

.nav-logout {
  background: rgba(239, 68, 68, 0.12); color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.25);
  padding: 6px 14px; border-radius: var(--tx-r-md);
  font-size: 0.8rem; font-weight: 600;
}
.nav-logout:hover { background: rgba(239, 68, 68, 0.2); color: #fee2e2; }

/* Flash messages (compatibilidade com layout antigo) */
.flash-bar { max-width: var(--tx-container); margin: 0 auto; padding: var(--tx-sp-4) var(--tx-sp-6) 0; }
.flash { padding: 12px 16px; border-radius: var(--tx-r-md); margin-bottom: var(--tx-sp-3); font-size: var(--tx-fs-sm); }
.flash-notice { background: var(--tx-success-soft); color: var(--tx-success); border-left: 3px solid var(--tx-success); }
.flash-alert  { background: var(--tx-danger-soft);  color: var(--tx-danger);  border-left: 3px solid var(--tx-danger);  }

/* ============================================================================
 * 4. LAYOUT — PAGE CONTAINER
 * ============================================================================ */
.tx-page,
.dashboard /* compat com classe antiga */ {
  max-width: var(--tx-container);
  margin: 0 auto;
  padding: var(--tx-sp-6);
}

.tx-page-header,
.dashboard-header /* compat */ {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: var(--tx-sp-4);
  margin-bottom: var(--tx-sp-6);
  flex-wrap: wrap;
}

.tx-page-header h1,
.dashboard-header h1 { color: var(--tx-text); }

.tx-page-header p,
.dashboard-header p { color: var(--tx-text-muted); font-size: var(--tx-fs-sm); margin: 0; }

/* ============================================================================
 * 5. CARDS (KPI / chart / generic)
 * ============================================================================ */
.tx-card {
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-lg);
  padding: var(--tx-sp-4);
  box-shadow: var(--tx-shadow-sm);
}

/* KPI cards — grid auto-fit */
.tx-kpi-grid,
.cards /* compat */ {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--tx-sp-4);
  margin-bottom: var(--tx-sp-6);
}

.tx-kpi,
.card /* compat */ {
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-left: 4px solid var(--tx-border-strong);
  border-radius: var(--tx-r-lg);
  padding: var(--tx-sp-4);
  box-shadow: var(--tx-shadow-sm);
}

.tx-kpi-info, .card-info       { border-left-color: var(--tx-info); }
.tx-kpi-success, .card-success { border-left-color: var(--tx-success); }
.tx-kpi-warning, .card-warning { border-left-color: var(--tx-warning); }
.tx-kpi-danger, .card-danger   { border-left-color: var(--tx-danger); }

.tx-kpi-label,
.card-label /* compat */ {
  color: var(--tx-text-muted);
  font-size: var(--tx-fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.tx-kpi-value,
.card-valor /* compat */ {
  color: var(--tx-text);
  font-size: var(--tx-fs-lg);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: var(--tx-sp-1);
}

.tx-kpi-foot {
  margin-top: var(--tx-sp-2);
  font-size: var(--tx-fs-xs);
  color: var(--tx-text-muted);
}

/* Chart card */
.tx-chart-card {
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-lg);
  padding: var(--tx-sp-4);
  box-shadow: var(--tx-shadow-sm);
}
.tx-chart-card h3 { font-size: var(--tx-fs-base); color: var(--tx-text); margin-bottom: var(--tx-sp-1); }
.tx-chart-card .tx-chart-sub { color: var(--tx-text-muted); font-size: var(--tx-fs-xs); margin-bottom: var(--tx-sp-2); }

.tx-chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--tx-sp-5);
  margin: var(--tx-sp-6) 0;
}
@media (max-width: 900px) { .tx-chart-grid { grid-template-columns: 1fr; } }

/* ============================================================================
 * 6. TABELAS
 * ============================================================================ */
.tx-table,
.modal-table /* compat */ {
  width: 100%;
  border-collapse: collapse;
  background: var(--tx-surface);
  font-size: var(--tx-fs-sm);
  border-radius: var(--tx-r-lg);
  overflow: hidden;
  box-shadow: var(--tx-shadow-sm);
  border: 1px solid var(--tx-border);
}

.tx-table thead th,
.modal-table thead th {
  background: var(--tx-surface-alt);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--tx-text-muted);
  font-size: var(--tx-fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--tx-border);
}

.tx-table tbody td,
.modal-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--tx-border);
  color: var(--tx-text);
}

.tx-table tbody tr:last-child td,
.modal-table tbody tr:last-child td { border-bottom: 0; }

.tx-table tbody tr:hover td,
.modal-table tbody tr:hover td { background: var(--tx-surface-alt); }

/* nowrap: sem ele valores curtos como "R$ 6.674" quebram entre o simbolo e o numero
   quando a tabela tem muitas colunas (ex.: /viagens). */
.tx-table .col-num,
.modal-table .col-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Coluna de NOME em tabela larga: sem isto o nome do vendedor quebra em 4 linhas
   quando a tabela tem muitas colunas numericas (ex.: /margem-vendedor). */
.tx-table .tx-col-nome { white-space: nowrap; }

/* Coluna que decide a tela (o valor a pagar). Sem isto ela competia em igualdade
   com outras seis colunas numericas e o olho nao achava o numero que importa. */
.tx-table .tx-col-destaque {
  font-size: var(--tx-fs-md);
  font-weight: 700;
  color: var(--tx-text);
}

.tx-table tfoot .tx-col-destaque { font-size: var(--tx-fs-lg); }

/* Tabela larga no celular: rolagem horizontal DENTRO da tabela (a pagina em si nao
   rola de lado) + colunas de apoio escondidas abaixo de 700px. Sem isto as 8 colunas
   da gestao de comissoes viravam um arrastar-para-o-lado em tela de 375px. */
.tx-tabela-rolavel { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 700px) {
  .tx-table { font-size: var(--tx-fs-xs); }
  .tx-table thead th, .tx-table tbody td { padding: 8px 6px; }
  .tx-col-apoio { display: none; }
  /* O nowrap do nome (que no desktop evita o vendedor quebrar em 4 linhas) empurra a
     tabela para fora da tela no celular: aqui o nome pode quebrar. */
  .tx-table .tx-col-nome { white-space: normal; }
  .tx-table .tx-col-destaque { font-size: var(--tx-fs-sm); }
  .tx-kpi-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--tx-sp-3); }
}

/* Telefone estreito: sobra o indispensavel — quem e' e quanto recebe. Com a coluna de
   base junto, a tabela ainda pedia 461px contra os ~330 uteis de um 375, e o valor
   ficava fora da primeira vista. */
@media (max-width: 520px) {
  .tx-col-apoio-xs { display: none; }
  .tx-table thead th, .tx-table tbody td { padding: 8px 4px; }
}

/* ============================================================================
 * EXTRATO DE COMISSAO (documento — vai para a impressora e para o vendedor)
 * ============================================================================ */
.tx-extrato-resumo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--tx-sp-5);
}

/* O valor a pagar e' a razao do documento existir: destaque, nao mais uma coluna. */
.tx-extrato-total .tx-kpi-value { color: var(--tx-success); font-size: var(--tx-fs-xl); }

/* Cabecalho do papel: redundante na tela (a navbar ja diz onde voce esta), essencial
   no PDF/impressao, onde nada disso existe. */
.tx-extrato-cabecalho { display: none; }
.tx-extrato-rodape { font-size: var(--tx-fs-xs); }

@media print {
  /* Fora do papel: navegacao, filtros e qualquer coisa clicavel. */
  .nav-bar, .flash-bar, .tx-nao-imprimir, .tx-filtros, .tx-abas { display: none !important; }

  .tx-extrato-cabecalho {
    display: flex;
    justify-content: space-between;
    gap: var(--tx-sp-4);
    border-bottom: 2px solid var(--tx-text);
    padding-bottom: var(--tx-sp-2);
    margin-bottom: var(--tx-sp-4);
    font-size: var(--tx-fs-sm);
  }

  body { background: #fff; }
  .tx-page { padding: 0; max-width: none; }
  .tx-card { border: 1px solid #ccc; box-shadow: none; }
  .tx-table { box-shadow: none; font-size: 11px; }
  .tx-table thead { display: table-header-group; }   /* repete o cabecalho a cada pagina */
  .tx-table tr { break-inside: avoid; }
  a { text-decoration: none; color: inherit; }
}

/* Abas do detalhe de um vendedor (carteira x margem). Sublinhado, nao botao: sao
   duas visoes da MESMA pagina, e botao lado a lado leria como duas acoes. */
.tx-abas {
  display: flex;
  gap: var(--tx-sp-5);
  border-bottom: 1px solid var(--tx-border);
  margin-bottom: var(--tx-sp-5);
}

.tx-aba {
  padding: var(--tx-sp-3) 0;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--tx-text-muted);
  text-decoration: none;
  font-size: var(--tx-fs-sm);
  font-weight: 500;
}

.tx-aba:hover { color: var(--tx-text); }

.tx-aba-ativa {
  color: var(--tx-primary);
  border-bottom-color: var(--tx-primary);
}

/* Linha de alerta (vermelho): abaixo da meta de comodato, inadimplente etc. */
.tx-table tbody tr.tx-row-alert td { background: var(--tx-danger-soft); }
.tx-table tbody tr.tx-row-alert:hover td { background: #fbddd9; }

/* Cabecalhos ordenaveis (controller Stimulus "sortable") */
.tx-table th.tx-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.tx-table th.tx-sortable:hover { color: var(--tx-primary); }
.tx-table th.tx-sortable::after { content: "\2195"; opacity: .35; margin-left: 4px; font-size: .85em; }
.tx-table th.tx-sort-asc::after  { content: "\25B2"; opacity: 1; }
.tx-table th.tx-sort-desc::after { content: "\25BC"; opacity: 1; }

/* ============================================================================
 * 7. FORMULARIOS / FILTROS
 * ============================================================================ */
.tx-filtros,
.filtros /* compat */ {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tx-sp-3);
  align-items: end;
  padding: var(--tx-sp-4);
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-lg);
  margin-bottom: var(--tx-sp-5);
  box-shadow: var(--tx-shadow-sm);
}

.tx-field,
.filtro-grupo /* compat */ {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tx-field label,
.filtro-grupo label {
  font-size: var(--tx-fs-xs);
  color: var(--tx-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tx-input,
.filtro-input /* compat */ {
  background: var(--tx-surface);
  color: var(--tx-text);
  border: 1px solid var(--tx-border-strong);
  padding: 8px 12px;
  border-radius: var(--tx-r-md);
  font-size: var(--tx-fs-sm);
  font-family: inherit;
  min-width: 160px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tx-input:focus,
.filtro-input:focus {
  outline: none;
  border-color: var(--tx-primary);
  box-shadow: 0 0 0 3px var(--tx-primary-soft);
}

.tx-btn,
.btn-filtrar /* compat */ {
  background: var(--tx-primary);
  color: #fff;
  border: 0;
  padding: 9px 18px;
  border-radius: var(--tx-r-md);
  font-size: var(--tx-fs-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
}

.tx-btn:hover, .btn-filtrar:hover { background: var(--tx-primary-dk); }

.tx-btn-ghost {
  background: transparent;
  color: var(--tx-text-muted);
  border: 1px solid var(--tx-border-strong);
}
.tx-btn-ghost:hover { background: var(--tx-surface-alt); color: var(--tx-text); }

.btn-voltar {
  display: inline-block;
  color: var(--tx-text-muted);
  font-size: var(--tx-fs-sm);
  text-decoration: none;
  padding: 4px 8px;
}
.btn-voltar:hover { color: var(--tx-text); text-decoration: none; }

/* ============================================================================
 * 8. BALANCO / DRE (estilo Rede Tetra)
 * ============================================================================ */
.tx-balanco { max-width: 1000px; margin: var(--tx-sp-4) auto; }
.tx-balanco table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--tx-fs-sm);
  background: var(--tx-surface);
  border-radius: var(--tx-r-md);
  overflow: hidden;
  box-shadow: var(--tx-shadow-sm);
}
.tx-balanco td { border: 1px solid #888; padding: 8px 12px; }

.tx-bal-header td {
  background: var(--tx-yellow);
  font-weight: 700;
  text-align: center;
  font-size: var(--tx-fs-md);
  padding: 12px;
  letter-spacing: 0.02em;
}

.tx-bal-row td:nth-child(2),
.tx-bal-row td:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }

/* Detalhe de uma conta do balanco (tanque / em transito dentro do ESTOQUE).
   Recuo + peso menor para ler como abertura da linha de cima, nao como conta nova. */
.tx-bal-sub td { font-size: var(--tx-fs-sm); color: var(--tx-muted); padding-top: 4px; padding-bottom: 4px; }
.tx-bal-sub td:first-child { padding-left: 28px; }
.tx-bal-sub td:nth-child(2),
.tx-bal-sub td:nth-child(4) { text-align: right; font-variant-numeric: tabular-nums; }

.tx-bal-pl td {
  background: var(--tx-yellow);
  font-weight: 700;
  font-size: var(--tx-fs-md);
}
.tx-bal-pl td:nth-child(2) { text-align: right; }

.tx-dre-header td {
  background: var(--tx-gray-header);
  font-weight: 700;
  text-align: center;
  padding: 10px;
}

.tx-dre-section td {
  background: #e0e0e0;
  font-weight: 700;
  padding: 8px 12px;
}

.tx-dre-row td:first-child { padding-left: 1.5rem; }
.tx-dre-row td:nth-child(2) { text-align: right; font-variant-numeric: tabular-nums; }

.tx-dre-total td {
  background: var(--tx-surface-alt);
  font-weight: 700;
}
.tx-dre-total td:nth-child(2) { text-align: right; }

.tx-pl-negativo { color: var(--tx-danger); }

/* Alertas/notas usadas no balanço e inventário */
.tx-note {
  font-size: var(--tx-fs-xs);
  color: var(--tx-text-muted);
  background: var(--tx-warning-soft);
  border-left: 3px solid var(--tx-warning);
  padding: 10px 14px;
  border-radius: var(--tx-r-md);
  margin: var(--tx-sp-4) auto;
  max-width: 1000px;
}
.tx-note-info {
  background: var(--tx-info-soft);
  border-left-color: var(--tx-info);
}

.tx-tag {
  display: inline-block;
  font-size: 0.7em;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: var(--tx-r-md);
  margin-left: 6px;
  vertical-align: middle;
  white-space: nowrap;
}
.tx-tag-warn {
  background: var(--tx-warning-soft);
  color: var(--tx-warning);
  border: 1px solid var(--tx-warning);
}
/* Variantes de situacao de cobranca da NF (coluna Situacao em /notas_fiscais). */
.tx-tag { margin-left: 0; }
.tx-tag-success { background: var(--tx-success-soft); color: var(--tx-success); border: 1px solid var(--tx-success); }
.tx-tag-danger  { background: var(--tx-danger-soft);  color: var(--tx-danger);  border: 1px solid var(--tx-danger);  }
.tx-tag-info    { background: var(--tx-info-soft);    color: var(--tx-info);    border: 1px solid var(--tx-info);    }
.tx-tag-neutral { background: var(--tx-surface-alt);  color: var(--tx-text-muted); border: 1px solid var(--tx-border); }
.tx-tag-yellow  { background: #fef9c3;               color: #854d0e;           border: 1px solid var(--tx-yellow-dk); }

/* Faixa de reconciliacao do a vencer (topo de /notas_fiscais). */
.tx-audit {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 18px;
  background: var(--tx-surface-alt); border: 1px solid var(--tx-border);
  border-left: 4px solid var(--tx-warning);
  border-radius: var(--tx-r-md); padding: 10px 14px; margin-top: var(--tx-sp-4);
  font-size: var(--tx-fs-sm);
}
.tx-audit b { font-variant-numeric: tabular-nums; }
.tx-audit .tx-audit-sep { color: var(--tx-text-soft); }

/* Abas de filtro por flag (drill-down de titulos suspeitos). */
.tx-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: var(--tx-sp-4); }
.tx-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--tx-r-pill);
  border: 1px solid var(--tx-border); background: var(--tx-surface);
  color: var(--tx-text-muted); font-size: var(--tx-fs-sm); font-weight: 600;
}
.tx-tab:hover { border-color: var(--tx-border-strong); }
.tx-tab-on { background: var(--tx-primary); border-color: var(--tx-primary); color: #fff; }
.tx-tab-ct { font-variant-numeric: tabular-nums; opacity: .85; }

/* ============================================================================
 * 9. INVENTARIO (estilo razinv01.fr3 do ERP)
 * ============================================================================ */
.tx-inv-report { max-width: 1100px; margin: var(--tx-sp-4) auto; }

.tx-inv-titulo { text-align: center; margin-bottom: var(--tx-sp-2); }
.tx-inv-titulo h2 { margin: 0; font-size: var(--tx-fs-md); }
.tx-inv-titulo p { margin: 4px 0; color: var(--tx-text-muted); font-size: var(--tx-fs-sm); }

.tx-inv-meta {
  background: var(--tx-surface-alt);
  padding: 10px 14px;
  margin-bottom: var(--tx-sp-2);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-md);
  font-size: var(--tx-fs-sm);
}

.tx-inv-table { width: 100%; border-collapse: collapse; font-size: var(--tx-fs-sm); background: var(--tx-surface); }
.tx-inv-table th {
  background: var(--tx-surface);
  border-bottom: 1px solid #555;
  color: var(--tx-text);
  text-align: right;
  padding: 8px 10px;
  font-weight: 700;
}
.tx-inv-table th.col-text { text-align: left; }
.tx-inv-table td { padding: 6px 10px; border-bottom: 1px solid #f0f0f0; }
.tx-inv-table tr:nth-child(odd) td { background: var(--tx-surface-alt); }
.tx-inv-table .col-num { text-align: right; font-variant-numeric: tabular-nums; }

.tx-inv-grupo-header td { background: var(--tx-gray-header) !important; padding: 9px 14px; font-weight: 700; }
.tx-inv-totals td { background: var(--tx-gray-total) !important; padding: 9px 14px; font-weight: 700; }
.tx-inv-total-geral td { background: #90a4ae !important; padding: 11px 14px; font-weight: 800; font-size: var(--tx-fs-md); color: #fff; }

/* Comparativo por categoria (pedido minimo): valores nunca quebram em duas linhas
   — na linha de total a fonte e' maior e "R$ 148.545,77" partia no meio. */
.tx-cmp-categoria .col-num { white-space: nowrap; }

/* ============================================================================
 * 10. COMPARATIVO MES-VS-MES
 * ============================================================================ */
.tx-comp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--tx-sp-3);
  margin-bottom: var(--tx-sp-6);
}

.tx-comp-card {
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-md);
  padding: var(--tx-sp-3);
  box-shadow: var(--tx-shadow-sm);
}

.tx-comp-label {
  color: var(--tx-text-muted);
  font-size: var(--tx-fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}

.tx-comp-value {
  font-size: var(--tx-fs-md);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 4px 0;
  color: var(--tx-text);
}

.tx-comp-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--tx-fs-xs);
  color: var(--tx-text-soft);
}

.tx-trend { font-size: var(--tx-fs-sm); font-weight: 700; }
.tx-trend-up   { color: var(--tx-success); }
.tx-trend-down { color: var(--tx-danger); }
.tx-trend-flat { color: var(--tx-text-muted); }

/* ============================================================================
 * 11. DETALHE (show pages — pessoas, etc)
 * ============================================================================ */
.tx-detail-list {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--tx-sp-2) var(--tx-sp-4);
  background: var(--tx-surface);
  border: 1px solid var(--tx-border);
  border-radius: var(--tx-r-lg);
  padding: var(--tx-sp-5);
  max-width: 720px;
  box-shadow: var(--tx-shadow-sm);
}
.tx-detail-list dt { color: var(--tx-text-muted); font-size: var(--tx-fs-sm); font-weight: 500; }
.tx-detail-list dd { color: var(--tx-text); font-size: var(--tx-fs-sm); }

/* ============================================================================
 * 12. UTILITARIOS
 * ============================================================================ */
.tx-mt-4 { margin-top: var(--tx-sp-4); }
.tx-mt-6 { margin-top: var(--tx-sp-6); }
.tx-mt-8 { margin-top: var(--tx-sp-8); }
.tx-mb-4 { margin-bottom: var(--tx-sp-4); }

.tx-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--tx-sp-5); }
@media (max-width: 800px) { .tx-row-2 { grid-template-columns: 1fr; } }

.tx-muted { color: var(--tx-text-muted); }
.tx-soft  { color: var(--tx-text-soft);  }
.tx-small { font-size: 0.8rem; }
.tx-num   { font-variant-numeric: tabular-nums; }
.tx-right { text-align: right; }
.tx-center{ text-align: center; }

/* ============================================================================
 * 13. CADASTRO DE USUARIOS / PERMISSOES (admin)
 * ============================================================================ */
.tx-user-form .tx-field label { text-transform: none; letter-spacing: 0; font-size: var(--tx-fs-sm); }

.tx-check { display: flex; align-items: center; gap: 9px; font-size: var(--tx-fs-sm); color: var(--tx-text); cursor: pointer; }
.tx-check input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--tx-primary); cursor: pointer; }
.tx-check span strong { font-weight: 600; }

.tx-admin-toggle {
  background: var(--tx-warning-soft);
  border: 1px solid var(--tx-warning);
  border-radius: var(--tx-r-md);
  padding: 12px 14px;
}

.tx-perm-title {
  font-size: var(--tx-fs-xs); color: var(--tx-text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: var(--tx-sp-3);
}
.tx-perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
@media (max-width: 800px) { .tx-perm-grid { grid-template-columns: 1fr; } }
.tx-perm-grid-wrap[hidden] { display: none; }

.tx-form-actions { display: flex; align-items: center; gap: var(--tx-sp-3); }

.tx-form-errors {
  background: var(--tx-danger-soft); border-left: 3px solid var(--tx-danger);
  color: var(--tx-danger); padding: 12px 14px; border-radius: var(--tx-r-md);
  margin-bottom: var(--tx-sp-5); font-size: var(--tx-fs-sm);
}
.tx-form-errors ul { margin: 6px 0 0 18px; }

.tx-link-danger {
  background: transparent; border: 0; color: var(--tx-danger);
  font-size: var(--tx-fs-sm); cursor: pointer; padding: 0; font-family: inherit;
}
.tx-link-danger:hover { text-decoration: underline; }

/* ============================================================================
 * 14. TABELA AGRUPADA COM DETALHE INLINE (/recebimento)
 * ============================================================================ */
/* Uma <tbody> por grupo: linha-resumo clicavel + <tr data-detalhe hidden> logo
   abaixo. As regras 340/343 (borda e hover) foram escritas para uma <tbody> so —
   sem os overrides abaixo todo grupo perderia o separador e a gaveta piscaria. */
.tx-grupos tbody.tx-grupo tr:last-child td { border-bottom: 1px solid var(--tx-border); }
.tx-grupos tbody.tx-grupo:last-child tr:last-child td { border-bottom: 0; }

.tx-grupos .tx-col-expander { width: 2.2rem; text-align: center; padding-right: 0; }
.tx-grupo-row { cursor: pointer; }

.tx-expander {
  background: none; border: 0; padding: 0; cursor: pointer; line-height: 1;
  color: var(--tx-text-muted); font-size: var(--tx-fs-sm);
  transition: transform 0.12s ease;
}
.tx-expander[aria-expanded="true"] { transform: rotate(90deg); }

.tx-grupo-detalhe[hidden] { display: none; }
.tx-grupos tbody tr.tx-grupo-detalhe td,
.tx-grupos tbody tr.tx-grupo-detalhe:hover td {
  background: var(--tx-surface-alt);
  padding: var(--tx-sp-3) var(--tx-sp-4) var(--tx-sp-4) 2.2rem;
}

/* Aninhada dentro da gaveta: .tx-table traz sombra e raio de card, que aqui
   duplicariam a moldura do grupo. */
.tx-nested { box-shadow: none; border: 1px solid var(--tx-border); }
.tx-nested thead th { background: transparent; }
.tx-nested tbody td, .tx-nested thead th { padding: 7px 10px; font-size: var(--tx-fs-sm); }

/* Com o detalhe inline sao ate 11 colunas: sem isso a pagina inteira ganha barra
   horizontal em telas de 1280px. O scroll fica na tabela, nao no body. */
.tx-table-scroll { overflow-x: auto; }

/* ============================================================================
 * MODAL — <dialog> nativo (showModal() ja da backdrop, foco preso e ESC).
 * Usado no detalhe da viagem em /viagens.
 * ============================================================================ */
.tx-modal {
  width: min(560px, calc(100vw - 2rem));
  /* O reset `* { margin: 0 }` la em cima mata o margin:auto que o <dialog>
     usa para se centralizar — sem esta linha ele nasce colado a esquerda. */
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: var(--tx-r-lg);
  box-shadow: var(--tx-shadow-md);
  background: var(--tx-surface);
  color: var(--tx-text);
}
.tx-modal::backdrop { background: rgba(15, 23, 42, 0.45); }

.tx-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--tx-sp-4);
  padding: var(--tx-sp-5) var(--tx-sp-5) var(--tx-sp-3);
}
.tx-modal-header h3 { font-size: var(--tx-fs-md); font-weight: 600; }

.tx-modal-fechar {
  background: none; border: 0; line-height: 1;
  font-size: 1.5rem; color: var(--tx-text-soft); padding: 0 4px;
}
.tx-modal-fechar:hover { color: var(--tx-text); }

/* Tabela rotulo|valor: sem sombra/borda propria, ela ja esta dentro do card. */
.tx-modal-table {
  border: 0; border-radius: 0; box-shadow: none;
  margin: 0 var(--tx-sp-5);
  width: calc(100% - var(--tx-sp-5) * 2);
}
.tx-modal-table tbody td { padding: 9px 12px; vertical-align: top; }
.tx-modal-rotulo { width: 38%; color: var(--tx-text-muted); }

.tx-modal-comentario {
  margin: var(--tx-sp-5);
  padding: var(--tx-sp-4);
  background: var(--tx-surface-alt);
  border-left: 3px solid var(--tx-border-strong);
  border-radius: var(--tx-r-sm);
  font-size: var(--tx-fs-sm);
}
.tx-modal-comentario p + p { margin-top: var(--tx-sp-2); }
.tx-modal-comentario-alerta {
  background: var(--tx-danger-soft);
  border-left-color: var(--tx-danger);
  color: var(--tx-danger);
}

/* Linha clicavel da tabela de viagens. */
.tx-row-click { cursor: pointer; }
.tx-link-btn {
  background: none; border: 0; padding: 0;
  color: var(--tx-primary); font: inherit; text-decoration: underline;
}
