:root {
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --primary: #1f6feb;
  --primary-dark: #14508c;
  --accent-green: #0f8a5f;
  --heading: #123f73;
  --text: #1a1f24;
  --muted: #6b7785;
  --border: #e2e6ea;
  --aviso-teste: #e8590c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

h1, h2, h3 {
  color: var(--heading);
}

.login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

/* Na tela de login o body vira flex-column pra centralizar o cartão de
   login; sem isso o aviso (primeiro filho) ficaria lado a lado com o
   cartão em vez de empilhado acima dele. align-self: stretch faz o
   aviso ocupar a largura toda mesmo com align-items: center no pai. */
.login-page .aviso-ambiente-teste {
  align-self: stretch;
  margin-bottom: 24px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.login-card h1 { margin: 0 0 4px; font-size: 22px; display: flex; align-items: center; gap: 8px; }
.subtitle { margin: 0 0 24px; color: var(--muted); font-size: 14px; }

label { display: block; margin: 12px 0 4px; font-size: 14px; color: var(--muted); }

input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}

button {
  margin-top: 20px;
  width: 100%;
  padding: 10px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}

.error { color: #d63939; font-size: 13px; margin-top: 12px; min-height: 16px; }

/* Faixa de aviso "Ambiente de Testes" — só aparece quando AMBIENTE_TESTE
   está ligado (ambiente staging), pra nunca confundir com produção. Fica
   fixa no topo, acima de tudo, tanto na tela de login quanto logado. */
.aviso-ambiente-teste {
  background: var(--aviso-teste);
  color: #ffffff;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 6px 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--card-bg);
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--primary), var(--accent-green)) 1;
}

.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; display: flex; align-items: center; gap: 8px; }

.topbar-title { display: flex; flex-direction: column; gap: 2px; }
.topbar-title h1 { line-height: 1.2; }
.topbar-subtitle { margin: 0; font-size: 12px; font-weight: 400; color: var(--muted); }
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-modulo-atual { margin: 0; padding-left: 16px; border-left: 1px solid var(--border); font-size: 13px; color: var(--muted); }

.topbar-usuario { display: flex; align-items: center; gap: 12px; }
.topbar-usuario-item { font-size: 13px; color: var(--muted); }
.topbar-usuario-item strong { font-weight: 600; color: var(--text); }
.btn-sair { background: #343a40 !important; color: #fff !important; }

.back-link {
  color: var(--text);
  text-decoration: none;
}
.back-link:hover { color: var(--primary); }

.link-button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  width: auto;
  margin: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(max(220px, calc((100% - 3 * 16px) / 4)), 1fr));
  gap: 16px;
  padding: 24px;
}

.card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(31, 111, 235, 0.12);
  transform: translateY(-2px);
}

.card h2 { margin: 0 0 6px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

.badge {
  display: inline-block;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff3cd;
  color: #7a5b00;
}

.module-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 65px);
  padding: 24px;
}

.empty-state {
  text-align: center;
  max-width: 420px;
}

.empty-state h2 { margin: 0 0 8px; font-size: 22px; }
.empty-state p { margin: 0 0 16px; color: var(--muted); }

.page {
  padding: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 { margin: 0; font-size: 19px; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
  width: auto;
  margin: 0;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.table th, .table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.table tbody tr:last-child td { border-bottom: none; }

.table-empty { text-align: center; color: var(--muted); padding: 24px; }

.table-actions { display: flex; gap: 12px; align-items: center; }
.table-actions a { color: var(--primary); text-decoration: none; font-size: 13px; }
.table-actions a:hover { text-decoration: underline; }
.table-actions form { margin: 0; }


/* Botoes de acao nas listagens (Editar/Excluir/Reabrir/Desativar) — cor
   solida de fundo com texto branco, pra ficar facil de identificar a acao
   de longe.
   !important pq precisam vencer ".table-actions a" (cor de link padrao)
   e ".link-button" (fundo transparente), que os elementos tambem carregam
   ou carregavam antes.
   width/margin explicitos pq precisam vencer a regra generica "button"
   la em cima (margin-top: 20px; width: 100%), pensada pros botoes de
   formulario — sem isso os botoes ficavam esticados e desalinhados dos
   links ao lado dentro de .table-actions. */
.btn-acao {
  display: inline-block;
  width: auto;
  margin: 0;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none !important;
  border: none;
  cursor: pointer;
  line-height: 1.4;
}

.btn-acao:hover { opacity: 0.88; }

.btn-editar { background: var(--primary) !important; color: #fff !important; }
.btn-excluir { background: #d63939 !important; color: #fff !important; }
.btn-reabrir { background: #6c757d !important; color: #fff !important; }

.badge-admin { background: #d1f0da; color: #14602c; }
.badge-superadmin { background: #e0e7ff; color: #3730a3; }

.error-box {
  background: #fdecec;
  color: #9c1f1f;
  border: 1px solid #f4b8b8;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}

.form-usuario {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.form-grid input { margin: 0; }

.hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  margin: 2px 0 0;
}

.admin-toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 24px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 24px;
  flex-shrink: 0;
  margin-top: 2px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #d63939;
  transition: 0.2s;
  border-radius: 999px;
}

.switch .slider::before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: 0.2s;
  border-radius: 50%;
}

.switch input:checked + .slider { background-color: #2da44e; }
.switch input:checked + .slider::before { transform: translateX(22px); }

.table-permissoes th, .table-permissoes td { text-align: center; }
.table-permissoes th:first-child, .table-permissoes td:first-child { text-align: left; }
.table-permissoes input[type="checkbox"] { width: 16px; height: 16px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.filtro-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.filtro-bar input[type="search"],
.filtro-bar input[type="text"] {
  flex: 1;
  max-width: 360px;
  margin: 0;
}

.filtro-bar .btn { flex-shrink: 0; }

.filtro-data-label {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--muted);
}
.filtro-data-label input[type="date"] { margin: 0; }

.section-block { margin-bottom: 32px; }
.section-block-topo { margin-top: 32px; }

.th-link {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
}
.th-link:hover { color: var(--primary); }

.expand-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  width: 24px;
  margin: 0;
  padding: 0;
}

.hidden { display: none; }

/* Edicao inline do nome de categorias de Contas a Pagar/Receber, em
   Administracao — input mais compacto que o padrao (que ocuparia 100% da
   celula da tabela). */
.categoria-nome-input { max-width: 260px; padding: 6px 10px; }

.detalhe-row td {
  background: var(--bg);
  padding: 14px;
}

.detalhe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.detalhe-grid strong {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.detalhe-grid span { font-size: 14px; }

.badge-ok { background: #d1f0da; color: #14602c; }
.badge-off { background: #f1f2f4; color: #5a6472; }
.badge-vencido { background: #fdecec; color: #9c1f1f; }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.valor-total-preview {
  margin: 0;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
}

.autocomplete-lista {
  position: relative;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  max-height: 220px;
  overflow-y: auto;
}

.autocomplete-item {
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

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

.form-col-2 { grid-column: span 2; }

@media (max-width: 600px) {
  .form-col-2 { grid-column: span 1; }
}

.nav-modulos {
  display: flex;
  gap: 4px;
  padding: 8px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-link:hover {
  color: var(--primary-dark);
  background: var(--bg);
}

.nav-link-ativo {
  color: #fff;
  background: var(--primary);
}

.nav-link-ativo:hover {
  color: #fff;
  background: var(--primary-dark);
}

.nav-link-empresa-ativa {
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg);
}

/* Dropdown de sub-modulos no menu superior (ex.: Compras > Requisição/
   Cotação/Compra). O wrapper só existe pra dar um "position: relative" de
   referência visual — a posição real do submenu é calculada em JS
   (public/js/nav-submenu.js) e aplicada como position:fixed, porque
   .nav-modulos tem overflow-x:auto e cortaria um submenu absolute. */
.nav-item-com-submenu {
  position: relative;
  display: inline-flex;
}

.nav-submenu {
  position: fixed;
  display: none;
  flex-direction: column;
  min-width: 200px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
  padding: 6px;
  z-index: 50;
}

.nav-submenu-visivel { display: flex; }

.nav-submenu-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}

.nav-submenu-link:hover {
  background: var(--bg);
  color: var(--primary-dark);
}

.nav-submenu-link-ativo {
  background: var(--primary);
  color: #fff;
}

.nav-submenu-link-ativo:hover {
  background: var(--primary-dark);
  color: #fff;
}

.nav-submenu-link .modulo-icone { width: 14px; height: 14px; }

.modulo-icone { flex-shrink: 0; }

/* Icone do nome do sistema ("Hoje!"), no topo de toda tela e na tela de
   login — mesmo espirito do .modulo-icone acima, tamanhos proprios porque
   o contexto (topbar 18px, login-card 22px) e diferente dos módulos. */
.nome-sistema-icone { flex-shrink: 0; width: 18px; height: 18px; }
.login-card h1 .nome-sistema-icone { width: 20px; height: 20px; }
.card h2 .modulo-icone { width: 18px; height: 18px; }
.nav-link .modulo-icone { width: 14px; height: 14px; }

.selecionar-empresa-box {
  width: 100%;
  max-width: 480px;
}

.selecionar-empresa-box h2 { margin: 0 0 4px; }

.combo-wrapper {
  position: relative;
}

.combo-wrapper input[type="text"] {
  padding-right: 40px;
}

.combo-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.combo-toggle:hover {
  background: var(--bg);
  color: var(--heading);
}

.combo-toggle svg {
  transition: transform 0.15s ease;
}

.combo-toggle-aberto svg {
  transform: rotate(180deg);
}

.combo-wrapper .autocomplete-lista {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
}

.autocomplete-vazio {
  color: var(--muted);
  cursor: default;
}

.autocomplete-vazio:hover {
  background: transparent;
}

.documento-busca-wrapper {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.documento-busca-wrapper input {
  flex: 1;
}

.btn-buscar-cnpj {
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-buscar-cnpj:disabled {
  opacity: 0.6;
  cursor: wait;
}

.hint-erro {
  color: #9c1f1f;
}

.hint-sucesso {
  color: var(--accent-green);
}

.campo-invalido {
  border-color: #e58a8a;
  background-color: #fdecec;
}

.historico-box {
  margin-top: 16px;
}

.historico-box h3 {
  font-size: 15px;
  margin: 0 0 8px;
}

.detalhe-row .historico-box table.table {
  background: var(--card-bg);
}

/* Múltiplos produtos por Requisição de Compras: linhas repetíveis no
   formulário (combobox de Produto + Quantidade + Remover) e a lista de
   produtos exibida na linha de detalhe da listagem. */
.requisicao-produtos-lista {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.requisicao-produto-linha {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.requisicao-produto-linha .combo-wrapper {
  flex: 1;
  min-width: 0;
}

.requisicao-produto-linha .input-quantidade-produto {
  width: 90px;
  flex-shrink: 0;
  margin: 0;
}

.requisicao-produto-linha .btn-remover-produto {
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .requisicao-produto-linha {
    flex-wrap: wrap;
  }
}

.btn-adicionar-produto {
  margin-top: 2px;
}

.detalhe-produtos-lista {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
