/**
 * styles.css — Sistema Hospitalar HMRJA
 * Design moderno com sidebar + Bootstrap 5
 * Paleta: Azul Hospitalar (confiança, saúde, profissionalismo)
 */

:root {
  --primary-color: #0284c7;
  --primary-light: #38bdf8;
  --primary-dark: #0369a1;
  --card-bg: #f8fafc;
  --table-head-bg: #f8fafc;
  --table-head-color: #64748b;
  --sidebar-width: 260px;
  --sidebar-bg: #ffffff;
  --sidebar-text: #64748b;
  --sidebar-active: #0284c7;
  --top-bar-height: 60px;

  /* Cores semânticas para botões */
  --btn-success: #16a34a;
  --btn-success-hover: #15803d;
  --btn-danger: #dc2626;
  --btn-danger-hover: #b91c1c;
  --btn-warning: #d97706;
  --btn-warning-hover: #b45309;
  --btn-info: #0891b2;
  --btn-info-hover: #0e7490;
}

* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html {
  height: 100%;
  overflow-x: hidden;
}

body {
  background-color: #f1f5f9;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  max-width: 100vw;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1050;
  transition: width 0.25s ease, transform 0.3s ease, background 0.3s ease, color 0.3s ease;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid #e2e8f0;
}

.sidebar-header {
  padding: 1.5rem 1rem 1rem;
  text-align: center;
  border-bottom: 1px solid #e2e8f0;
  position: relative;
}

.sidebar-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  font-size: 1.5rem;
  color: #fff;
}

.sidebar-title {
  color: #1e293b;
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.sidebar-subtitle {
  color: var(--sidebar-text);
  font-size: 0.75rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section {
  padding: 1rem 1.25rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

/* Label estático da seção Início (não colapsável) */
.nav-section-label {
  padding: 1rem 1.25rem 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
}

/* Sidebar colapsada: oculta o label estático */
.sidebar.collapsed .nav-section-label { display: none; }

/* Dark mode do label */
html[data-tema="escuro"] .nav-section-label { color: #475569; }

/* Itens dentro de um grupo colapsável Bootstrap
   — indentação leve para indicar hierarquia */
.sidebar .collapse .nav-item {
  padding-left: 1.6rem;
  font-size: 0.855rem;
}
.sidebar.collapsed .collapse .nav-item {
  padding-left: 0;
  justify-content: center;
}



.nav-item {
  display: flex;
  align-items: center;
  padding: 0.6rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.nav-item:hover {
  color: #1e293b;
  background: #f1f5f9;
}

/* Manter destaque ativo ao passar o mouse */
.nav-item.active:hover {
  color: var(--primary-color);
  background: rgba(2, 132, 199, 0.14);
}

.nav-item.active {
  color: var(--primary-color);
  background: rgba(2, 132, 199, 0.08);
  border-left-color: var(--sidebar-active);
  font-weight: 500;
}

.nav-item i {
  width: 24px;
  text-align: center;
  margin-right: 0.75rem;
  font-size: 0.95rem;
}

/* ── Sub-navegação (accordion) ─────────────────────────── */
.nav-chevron {
  transition: transform 0.25s ease;
  flex-shrink: 0;
  font-size: 0.7rem;
  opacity: 0.5;
  padding: 4px 2px;
  cursor: pointer;
}
.nav-item.sub-open .nav-chevron {
  transform: rotate(90deg);
  opacity: 0.8;
}

.nav-sub {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.28s ease;
  padding-left: 1rem;
}
.nav-sub.open {
  max-height: 320px;
}

.nav-sub-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.42rem 0.9rem;
  color: var(--sidebar-text);
  font-size: 0.82rem;
  text-decoration: none;
  border-left: 3px solid transparent;
  border-radius: 0 6px 6px 0;
  transition: all 0.18s;
}
.nav-sub-item i {
  width: 18px;
  text-align: center;
  font-size: 0.78rem;
  flex-shrink: 0;
  opacity: 0.75;
}
.nav-sub-item:hover {
  background: #f1f5f9;
  color: #1e293b;
}
.nav-sub-item.active {
  color: var(--primary-color);
  background: rgba(2, 132, 199, 0.08);
  border-left-color: var(--primary-color);
  font-weight: 500;
}

/* Sidebar recolhida — ocultar sub-nav */
.sidebar.collapsed .nav-sub {
  display: none;
}

/* Dark mode para sub-nav */
html[data-tema="escuro"] .nav-sub-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #e2e8f0;
}
html[data-tema="escuro"] .nav-sub-item.active {
  background: rgba(56, 189, 248, 0.12);
  color: #38bdf8;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid #e2e8f0;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.user-info > i {
  font-size: 1.8rem;
  color: var(--primary-light);
}

.user-name {
  display: block;
  color: #1e293b;
  font-size: 0.85rem;
  font-weight: 500;
}

.user-role {
  display: block;
  color: var(--sidebar-text);
  font-size: 0.7rem;
  text-transform: capitalize;
}

/* Botão Sair */
.btn-sair {
  border: 1px solid #e2e8f0;
  color: #64748b;
  background: transparent;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.btn-sair:hover {
  background: #f1f5f9;
  color: #dc2626;
  border-color: #fca5a5;
}
[data-tema="escuro"] .btn-sair {
  border-color: #334155;
  color: #94a3b8;
}
[data-tema="escuro"] .btn-sair:hover {
  background: rgba(239,68,68,0.15);
  color: #f87171;
  border-color: #7f1d1d;
}

/* Botão Recolher Sidebar */
.btn-collapse-sidebar {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #94a3b8;
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  padding: 0;
  z-index: 2;
}
.btn-collapse-sidebar:hover {
  background: #f1f5f9;
  color: #64748b;
  border-color: #cbd5e1;
}
[data-tema="escuro"] .btn-collapse-sidebar {
  border-color: #334155;
  color: #64748b;
}
[data-tema="escuro"] .btn-collapse-sidebar:hover {
  background: rgba(255,255,255,0.05);
  color: #94a3b8;
}

/* ===== SIDEBAR COLAPSADA ===== */
.sidebar.collapsed {
  width: 68px;
  overflow-x: hidden;
}
.sidebar.collapsed .sidebar-header {
  padding: 1rem 0.5rem 0.75rem;
}
.sidebar.collapsed .btn-collapse-sidebar {
  position: static;
  width: 100%;
  margin-bottom: 0.5rem;
  border-radius: 8px;
}
.sidebar.collapsed .sidebar-logo {
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  margin-bottom: 0;
}
.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .sidebar-subtitle {
  display: none;
}
.sidebar.collapsed .nav-section {
  font-size: 0;
  padding: 0.6rem 0;
  text-align: center;
}
.sidebar.collapsed .nav-section::after {
  content: '';
  display: block;
  width: 24px;
  height: 1px;
  background: #cbd5e1;
  margin: 0 auto;
}
[data-tema="escuro"] .sidebar.collapsed .nav-section::after {
  background: #334155;
}
.sidebar.collapsed .nav-item {
  justify-content: center;
  padding: 0.6rem;
  border-left: none;
}
.sidebar.collapsed .nav-item i {
  margin-right: 0;
  font-size: 1.1rem;
}
.sidebar.collapsed .nav-item span {
  display: none;
}
.sidebar.collapsed .nav-item.active {
  border-left: none;
  border-radius: 8px;
  margin: 2px 8px;
  padding: 0.5rem;
}
.sidebar.collapsed .sidebar-footer {
  padding: 0.5rem;
  text-align: center;
}
.sidebar.collapsed .user-info {
  justify-content: center;
}
.sidebar.collapsed .user-info-text {
  display: none;
}
.sidebar.collapsed .btn-sair span {
  display: none;
}
.sidebar.collapsed .btn-sair {
  padding: 0.4rem;
  font-size: 0.85rem;
}
.sidebar.collapsed #icone-collapse {
  transform: rotate(180deg);
}

/* ===== SUBMENU DA SIDEBAR ===== */
.nav-parent {
  width: 100%;
  background: none;
  border: none;
  /* Manter border-left transparente igual .nav-item para poder colorir no estado ativo */
  border-left: 3px solid transparent;
  cursor: pointer;
  text-align: left;
}

/* ── Cores por seção ────────────────────────────────────────────── */
/* Início — azul */
.nav-parent[data-grupo="inicio"] { color: #3b82f6; }
.nav-parent[data-grupo="inicio"] > i:first-child { color: #3b82f6 !important; }
/* Cadastros — âmbar */
.nav-parent[data-grupo="cadastros"] { color: #f59e0b; }
.nav-parent[data-grupo="cadastros"] > i:first-child { color: #f59e0b !important; }
/* Atendimento — verde-esmeralda */
.nav-parent[data-grupo="atendimento"] { color: #10b981; }
.nav-parent[data-grupo="atendimento"] > i:first-child { color: #10b981 !important; }
/* BPA — violeta */
.nav-parent[data-grupo="bpa"] { color: #8b5cf6; }
.nav-parent[data-grupo="bpa"] > i:first-child { color: #8b5cf6 !important; }
/* Relatórios — ciano */
.nav-parent[data-grupo="relatorios"] { color: #06b6d4; }
.nav-parent[data-grupo="relatorios"] > i:first-child { color: #06b6d4 !important; }
/* Administração — vermelho-rosa */
.nav-parent[data-grupo="administracao"] { color: #f43f5e; }
.nav-parent[data-grupo="administracao"] > i:first-child { color: #f43f5e !important; }
/* Sistema — cinza-azulado */
.nav-parent[data-grupo="sistema"] { color: #64748b; }
.nav-parent[data-grupo="sistema"] > i:first-child { color: #64748b !important; }

/* Dark mode — mesmas cores, mais brilhantes */
[data-tema="escuro"] .nav-parent[data-grupo="inicio"] { color: #60a5fa; }
[data-tema="escuro"] .nav-parent[data-grupo="inicio"] > i:first-child { color: #60a5fa !important; }
[data-tema="escuro"] .nav-parent[data-grupo="cadastros"] { color: #fbbf24; }
[data-tema="escuro"] .nav-parent[data-grupo="cadastros"] > i:first-child { color: #fbbf24 !important; }
[data-tema="escuro"] .nav-parent[data-grupo="atendimento"] { color: #34d399; }
[data-tema="escuro"] .nav-parent[data-grupo="atendimento"] > i:first-child { color: #34d399 !important; }
[data-tema="escuro"] .nav-parent[data-grupo="bpa"] { color: #a78bfa; }
[data-tema="escuro"] .nav-parent[data-grupo="bpa"] > i:first-child { color: #a78bfa !important; }
[data-tema="escuro"] .nav-parent[data-grupo="relatorios"] { color: #22d3ee; }
[data-tema="escuro"] .nav-parent[data-grupo="relatorios"] > i:first-child { color: #22d3ee !important; }
[data-tema="escuro"] .nav-parent[data-grupo="administracao"] { color: #fb7185; }
[data-tema="escuro"] .nav-parent[data-grupo="administracao"] > i:first-child { color: #fb7185 !important; }
[data-tema="escuro"] .nav-parent[data-grupo="sistema"] { color: #94a3b8; }
[data-tema="escuro"] .nav-parent[data-grupo="sistema"] > i:first-child { color: #94a3b8 !important; }

/* Estado ativo no botão pai (nav-parent) — mesma aparência que nav-item.active */
.nav-parent.active {
  color: var(--primary-color) !important;
  background: rgba(2, 132, 199, 0.10) !important;
  border-left: 3px solid var(--sidebar-active) !important;
  border-left-width: 3px !important;
  border-left-style: solid !important;
  border-left-color: var(--sidebar-active) !important;
  font-weight: 600 !important;
}

/* Hover sobre item pai ativo — não apagar o destaque */
.nav-parent.active:hover {
  background: rgba(2, 132, 199, 0.16) !important;
  color: var(--primary-color) !important;
}

[data-tema="escuro"] .nav-parent.active {
  color: #7dd3fc !important;
  background: rgba(2, 132, 199, 0.20) !important;
  border-left: 3px solid var(--sidebar-active) !important;
  border-left-width: 3px !important;
  border-left-style: solid !important;
  border-left-color: var(--sidebar-active) !important;
  font-weight: 600 !important;
}

[data-tema="escuro"] .nav-parent.active:hover {
  background: rgba(2, 132, 199, 0.28) !important;
  color: #7dd3fc !important;
}

.nav-chevron {
  margin-left: auto;
  margin-right: 0;
  font-size: 0.68rem;
  transition: transform 0.2s;
  width: auto !important;
  color: #94a3b8;
}

.nav-parent[aria-expanded="true"] .nav-chevron {
  transform: rotate(90deg);
}

/* Itens de 2º nível dentro de .nav-sub (sub-accordion antigo) */
.nav-sub .nav-sub-item {
  padding-left: 3rem !important;
  font-size: 0.82rem !important;
}
.nav-sub .nav-sub-item i {
  font-size: 0.82rem !important;
}

/* Sidebar colapsada: botão pai Bootstrap collapse — exibe como ícone simples */
.sidebar.collapsed .nav-parent span,
.sidebar.collapsed .nav-parent .nav-chevron {
  display: none;
}
.sidebar.collapsed .collapse {
  display: block !important;
}
.sidebar.collapsed .nav-sub-item {
  padding: 0.6rem !important;
  justify-content: center;
  padding-left: 0.6rem !important;
  font-size: 1.1rem !important;
}
.sidebar.collapsed .nav-sub-item i {
  font-size: 1.1rem !important;
  margin-right: 0;
}
.sidebar.collapsed .nav-sub-item span {
  display: none;
}

/* Tooltip nos itens quando colapsado */
.sidebar.collapsed .nav-item {
  position: relative;
}
.sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: #1e293b;
  color: #fff;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  margin-left: 8px;
  z-index: 9999;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
}
[data-tema="escuro"] .sidebar.collapsed .nav-item::after {
  background: #334155;
}

/* Transição suave para sidebar colapsada */
.main-content {
  transition: margin-left 0.25s ease;
}
.sidebar.collapsed + main.main-content,
.sidebar.collapsed ~ main.main-content {
  margin-left: 68px;
}
.sidebar.collapsed ~ .app-footer {
  margin-left: 68px;
}

/* ===== MAIN CONTENT ===== */
/* body é flex-column; sidebar é fixed (fora do fluxo); main e footer crescem juntos */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0; /* evita overflow em flex */
}

/* Sem sidebar (login/erro) — ocupa tela toda */
.main-full {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.top-bar {
  height: var(--top-bar-height);
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
  color: #1e293b;
}

.top-bar-right {
  margin-left: auto;
}

.content-wrapper {
  flex: 1;
  padding: 1.5rem;
}

/* ===== LOGIN ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 2rem;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.08);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.login-header h3 {
  color: #1e293b;
  font-weight: 700;
  margin-top: 0.5rem;
  margin-bottom: 0.25rem;
}

.login-header .text-muted {
  font-size: 0.85rem;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
  font-size: 1.75rem;
  color: #fff;
  box-shadow: 0 4px 16px rgba(2,132,199,0.3);
}

/* Dark mode login */
[data-tema="escuro"] .login-card {
  background: #1e293b;
  box-shadow: 0 10px 40px rgba(0,0,0,0.35);
}
[data-tema="escuro"] .login-header h3 {
  color: #f1f5f9;
}
[data-tema="escuro"] .login-logo {
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  box-shadow: 0 4px 16px rgba(59,130,246,0.3);
}

/* ===== LOGIN — ESTRUTURA NOVA (barra topo, fornecedor, card-title) ===== */
.login-page-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
}

.login-top-bar {
  background: var(--primary-color);
  color: #fff;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.login-top-title {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.01em;
  color: #fff;
}

.login-top-bar .theme-toggle {
  border-color: rgba(255,255,255,0.4);
  color: #fff;
  background: rgba(255,255,255,0.08);
}
.login-top-bar .theme-toggle:hover {
  background: rgba(255,255,255,0.20);
  border-color: rgba(255,255,255,0.7);
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  gap: 1.25rem;
}

.login-fornecedor-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.07);
  padding: 1.25rem 2rem;
  text-align: center;
  width: 100%;
  max-width: 420px;
}

.login-fornecedor-img {
  max-width: 220px;
  max-height: 90px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}

.login-card-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e2e8f0;
}

/* Dark mode — novos elementos do login */
[data-tema="escuro"] .login-top-bar {
  background: #0369a1;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

[data-tema="escuro"] .login-fornecedor-card {
  background: #1e293b;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
}

[data-tema="escuro"] .login-fornecedor-card .text-muted {
  color: #94a3b8 !important;
}

[data-tema="escuro"] .login-card-title {
  color: #60a5fa;
  border-bottom-color: #334155;
}

/* ===== STAT CARDS ===== */
.stat-card {
  border-radius: 12px;
  padding: 1.25rem;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.stat-info h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0;
}

.stat-info p {
  margin: 0;
  font-size: 0.8rem;
  opacity: 0.9;
}

/* ===== CARDS ===== */
.card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.card-header {
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
  padding: 1rem 1.25rem;
  border-radius: 12px 12px 0 0 !important;
}

.card-header h6 {
  font-weight: 600;
  color: #1e293b;
}

/* ===== TABLE ===== */
.table > thead > tr > th {
  background: #f8fafc;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  padding: 0.75rem 1rem;
}

/* Cabeçalho da tabela de permissões — adapta ao tema automaticamente */
.thead-permissoes > tr > th {
  background: var(--table-head-bg, #f8fafc);
  color: var(--table-head-color, #64748b);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #e2e8f0;
  padding: 0.75rem 0.6rem;
}

/* Itêns da legenda de permissões */
.legenda-item {
  background: var(--card-bg, #f8fafc);
  transition: background 0.2s;
}

.table > tbody > tr > td {
  padding: 0.75rem 1rem;
  vertical-align: middle;
  font-size: 0.875rem;
}

.table-hover > tbody > tr:hover {
  background-color: #f8fafc;
}

/* ===== BADGES ===== */
.badge {
  font-weight: 500;
  font-size: 0.75rem;
  padding: 0.35em 0.65em;
  border-radius: 6px;
}

/* ===== BUTTONS ===== */
.btn {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.875rem;
}

.btn-primary {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-outline-primary {
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.btn-outline-primary:hover {
  background: var(--primary-color);
  border-color: var(--primary-color);
}

/* ===== BOTÕES PADRONIZADOS POR AÇÃO ===== */

/* Ação Positiva: Criar, Adicionar, Abrir Atendimento, Confirmar */
.btn-action-positive {
  background: var(--btn-success);
  border-color: var(--btn-success);
  color: #fff;
}
.btn-action-positive:hover {
  background: var(--btn-success-hover);
  border-color: var(--btn-success-hover);
  color: #fff;
}

/* Ação Destrutiva: Cancelar, Excluir, Remover */
.btn-action-destructive {
  background: var(--btn-danger);
  border-color: var(--btn-danger);
  color: #fff;
}
.btn-action-destructive:hover {
  background: var(--btn-danger-hover);
  border-color: var(--btn-danger-hover);
  color: #fff;
}

/* Ação de Alerta: Editar modo, Encaminhar */
.btn-action-caution {
  background: var(--btn-warning);
  border-color: var(--btn-warning);
  color: #fff;
}
.btn-action-caution:hover {
  background: var(--btn-warning-hover);
  border-color: var(--btn-warning-hover);
  color: #fff;
}

/* Ação Informativa: Ver detalhes, Visualizar */
.btn-action-view {
  background: var(--btn-info);
  border-color: var(--btn-info);
  color: #fff;
}
.btn-action-view:hover {
  background: var(--btn-info-hover);
  border-color: var(--btn-info-hover);
  color: #fff;
}

/* Grupo de botões de ação em tabelas */
.btn-actions {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: nowrap;
}

.btn-actions .btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.78rem;
  line-height: 1.3;
}

/* ===== FORMS ===== */
.form-control, .form-select {
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 0.2rem rgba(2, 132, 199, 0.18);
}

.form-label {
  font-weight: 500;
  font-size: 0.85rem;
  color: #475569;
  margin-bottom: 0.3rem;
}

/* ===== ALERTS ===== */
.alert {
  border-radius: 10px;
  border: none;
  font-size: 0.875rem;
}

/* ===== FOOTER ===== */
.app-footer {
  border-top: 1px solid rgba(226,232,240,.9);
  background: rgba(248,250,252,.95);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  padding: 12px 16px;
  font-size: 12.5px;
  color: #64748b;
  text-align: center;
  line-height: 1.45;
  margin-left: var(--sidebar-width);
  flex-shrink: 0;
  transition: margin-left 0.25s ease, background .3s, border-color .3s;
}
.app-footer span {
  display: block;
}
.app-footer .footer-inst {
  color: #1e293b;
  font-weight: 600;
}
.app-footer .footer-credit {
  margin-top: 4px;
  color: #475569;
}

/* ===== DARK MODE TOGGLE BUTTON ===== */
.theme-toggle {
  background: none;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  color: #64748b;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
}
.theme-toggle:hover {
  background: #f1f5f9;
  color: #1e293b;
}
/* Ícones SVG do botão de tema */
.icone-sol,
.icone-lua {
  display: block;
  flex-shrink: 0;
  transition: transform 0.35s cubic-bezier(0.4,0,0.2,1), opacity 0.25s ease;
}
.theme-toggle.girando .icone-sol,
.theme-toggle.girando .icone-lua {
  transform: rotate(90deg) scale(0.3);
  opacity: 0;
}

/* ===== DARK MODE ===== */
[data-tema="escuro"] body,
html[data-tema="escuro"] body {
  background-color: #0f172a;
  color: #e2e8f0;
}

[data-tema="escuro"] .top-bar {
  background: #1e293b;
  border-bottom-color: #334155;
}
[data-tema="escuro"] .page-title {
  color: #f1f5f9;
}
[data-tema="escuro"] .top-bar .text-muted {
  color: #94a3b8 !important;
}

[data-tema="escuro"] .content-wrapper {
  color: #e2e8f0;
}

[data-tema="escuro"] {
  --card-bg: #1e293b;
  --table-head-bg: #0f172a;
  --table-head-color: #94a3b8;
}

[data-tema="escuro"] .card {
  background: #1e293b;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-tema="escuro"] .card-header {
  background: #1e293b;
  border-bottom-color: #334155;
}
[data-tema="escuro"] .card-header h6 {
  color: #f1f5f9;
}
[data-tema="escuro"] .card-body {
  color: #e2e8f0;
}

/* Cor padrão do texto dentro de card-header (não só h6) */
[data-tema="escuro"] .card-header {
  color: #e2e8f0;
}
[data-tema="escuro"] .card-header .text-muted,
[data-tema="escuro"] .card-header small {
  color: #94a3b8 !important;
}
[data-tema="escuro"] .card-header .fw-semibold,
[data-tema="escuro"] .card-header .fw-bold {
  color: #f1f5f9;
}

/* Bootstrap bg-info usa !important — precisamos de !important para sobrescrever */
[data-tema="escuro"] .card-header.bg-info,
[data-tema="escuro"] .card-header.bg-info.bg-opacity-10 {
  background-color: rgba(14, 165, 233, 0.12) !important;
  border-bottom-color: rgba(14, 165, 233, 0.2) !important;
}

/* Utilitário text-info em modo escuro — versão mais clara para legibilidade */
[data-tema="escuro"] .text-info {
  color: #67e8f9 !important;
}

/* Borda colorida de cards (ex: border-info) em modo escuro */
[data-tema="escuro"] .border-info {
  border-color: rgba(14, 165, 233, 0.3) !important;
}

/* badge bg-dark em modo escuro — seria preto sobre fundo escuro — inverter */
[data-tema="escuro"] .badge.bg-dark {
  background-color: #334155 !important;
  color: #e2e8f0 !important;
}
[data-tema="escuro"] .badge.bg-secondary {
  background-color: #475569 !important;
}

/* <code> em tabelas e prontuário */
[data-tema="escuro"] code {
  background-color: #0f172a;
  color: #7dd3fc;
  border: 1px solid rgba(125, 211, 252, 0.15);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Botões outline que ficavam invisíveis em dark (herdados do Bootstrap) */
[data-tema="escuro"] .btn-outline-secondary:hover {
  color: #f1f5f9 !important;
}

/* ===== NAV-TABS modo escuro ===== */
[data-tema="escuro"] .nav-tabs {
  border-bottom-color: #334155;
}
[data-tema="escuro"] .nav-tabs .nav-link {
  color: #94a3b8;
  border-color: transparent;
}
[data-tema="escuro"] .nav-tabs .nav-link:hover {
  color: #e2e8f0;
  background-color: rgba(255,255,255,0.05);
  border-color: #334155 #334155 transparent;
}
[data-tema="escuro"] .nav-tabs .nav-link.active {
  background-color: #1e293b !important;
  border-color: #334155 #334155 #1e293b !important;
  color: #f1f5f9 !important;
}
[data-tema="escuro"] .tab-content {
  background-color: #1e293b;
}

[data-tema="escuro"] .table > thead > tr > th {
  background: #0f172a;
  color: #94a3b8;
  border-bottom-color: #334155;
}

/* Cabeçalho permissões + legenda-item no modo escuro */
[data-tema="escuro"] .thead-permissoes > tr > th {
  border-bottom-color: #334155;
  border-color: #334155;
}
[data-tema="escuro"] .legenda-item {
  border-color: #334155 !important;
}
[data-tema="escuro"] .legenda-item .fw-semibold {
  color: #e2e8f0;
}
[data-tema="escuro"] .legenda-item .text-muted {
  color: #94a3b8 !important;
}

/* table-bordered: bordas no modo escuro */
[data-tema="escuro"] .table-bordered,
[data-tema="escuro"] .table-bordered > :not(caption) > * > * {
  --bs-border-color: #334155;
  border-color: #334155 !important;
}
[data-tema="escuro"] .table-bordered > tbody > tr > td {
  border-color: #334155 !important;
}

/* form-switch (toggle) no modo escuro: trilho cinza quando desmarcado */
[data-tema="escuro"] .form-check-input[type="checkbox"]:not(:checked) {
  background-color: #334155;
  border-color: #475569;
}
[data-tema="escuro"] .form-check-input[type="checkbox"]:checked {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}
[data-tema="escuro"] .table > tbody > tr > td {
  color: #e2e8f0;
  border-bottom-color: #334155;
}
[data-tema="escuro"] .table-hover > tbody > tr:hover {
  background-color: #334155;
}
[data-tema="escuro"] .table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: #334155;
}

[data-tema="escuro"] .form-control,
[data-tema="escuro"] .form-select {
  background-color: #0f172a;
  border-color: #334155;
  color: #e2e8f0;
}
[data-tema="escuro"] .form-control:focus,
[data-tema="escuro"] .form-select:focus {
  background-color: #0f172a;
  border-color: var(--primary-light);
  color: #f1f5f9;
}
[data-tema="escuro"] .form-control::placeholder {
  color: #64748b;
}

/* ===== Date / Time inputs — dark mode (popup do calendário nativo) ===== */
[data-tema="escuro"] input[type="date"],
[data-tema="escuro"] input[type="time"],
[data-tema="escuro"] input[type="datetime-local"],
[data-tema="escuro"] input[type="month"],
[data-tema="escuro"] input[type="week"] {
  color-scheme: dark;
}
/* Ícone de calendário sobre fundo escuro */
[data-tema="escuro"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-tema="escuro"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-tema="escuro"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(0.85);
  cursor: pointer;
}
[data-tema="escuro"] .form-label {
  color: #94a3b8;
}
[data-tema="escuro"] .form-text {
  color: #94a3b8;
}
[data-tema="escuro"] .form-check-label {
  color: #cbd5e1;
}

[data-tema="escuro"] .alert {
  border: 1px solid #334155;
}
[data-tema="escuro"] .alert-success {
  background-color: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.25) !important;
}
[data-tema="escuro"] .alert-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.25) !important;
}
[data-tema="escuro"] .alert-warning {
  background-color: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.25) !important;
}
[data-tema="escuro"] .alert-warning a,
[data-tema="escuro"] .alert-warning .alert-link {
  color: #fde68a;
}
[data-tema="escuro"] .alert-warning strong,
[data-tema="escuro"] .alert-warning .fw-bold {
  color: #fde68a;
}
[data-tema="escuro"] .alert-info {
  background-color: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.25) !important;
}
[data-tema="escuro"] .alert-secondary {
  background-color: rgba(100, 116, 139, 0.15);
  color: #94a3b8;
  border-color: rgba(100, 116, 139, 0.25) !important;
}

[data-tema="escuro"] .app-footer {
  border-top-color: rgba(51,65,85,.9);
  background: rgba(2,6,23,.92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #94a3b8;
}
[data-tema="escuro"] .app-footer .footer-inst {
  color: #e5e7eb;
}
[data-tema="escuro"] .app-footer .footer-credit {
  color: #cbd5e1;
}

[data-tema="escuro"] .stat-card {
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

[data-tema="escuro"] .theme-toggle {
  border-color: #334155;
  color: #94a3b8;
}
[data-tema="escuro"] .theme-toggle:hover {
  background: #334155;
  color: #f1f5f9;
}

[data-tema="escuro"] a:not(.btn):not(.nav-item):not(.nav-link) {
  color: #60a5fa;
}
[data-tema="escuro"] a:not(.btn):not(.nav-item):not(.nav-link):hover {
  color: #93bbfd;
}

[data-tema="escuro"] .text-muted {
  color: #94a3b8 !important;
}
[data-tema="escuro"] .bg-light {
  background-color: #1e293b !important;
}

[data-tema="escuro"] .modal-content {
  background-color: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
[data-tema="escuro"] .modal-header {
  border-bottom-color: #334155;
}
[data-tema="escuro"] .modal-footer {
  border-top-color: #334155;
}
[data-tema="escuro"] .btn-close {
  filter: invert(1);
}

[data-tema="escuro"] .list-group-item {
  background-color: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

[data-tema="escuro"] h1, [data-tema="escuro"] h2,
[data-tema="escuro"] h3, [data-tema="escuro"] h4,
[data-tema="escuro"] h5, [data-tema="escuro"] h6 {
  color: #f1f5f9;
}

[data-tema="escuro"] .fw-bold, [data-tema="escuro"] strong {
  color: #f1f5f9;
}

[data-tema="escuro"] .btn-outline-secondary {
  border-color: #475569;
  color: #94a3b8;
}
[data-tema="escuro"] .btn-outline-secondary:hover {
  background-color: #334155;
  border-color: #475569;
  color: #f1f5f9;
}

/* Botões warning/outline em modo escuro */
[data-tema="escuro"] .btn-warning {
  background-color: #d97706;
  border-color: #d97706;
  color: #fff;
}
[data-tema="escuro"] .btn-warning:hover {
  background-color: #b45309;
  border-color: #b45309;
  color: #fff;
}
[data-tema="escuro"] .btn-outline-warning {
  color: #fbbf24;
  border-color: #fbbf24;
  background: transparent;
}
[data-tema="escuro"] .btn-outline-warning:hover {
  background-color: #fbbf24;
  border-color: #fbbf24;
  color: #1e293b;
}
[data-tema="escuro"] .btn-secondary {
  background-color: #334155;
  border-color: #475569;
  color: #f1f5f9;
}
[data-tema="escuro"] .btn-secondary:hover {
  background-color: #1e293b;
  border-color: #334155;
  color: #f8fafc;
}

/* Tabelas em modo escuro */
[data-tema="escuro"] .table-warning,
[data-tema="escuro"] .table-warning > td,
[data-tema="escuro"] .table-warning > th {
  background-color: rgba(245, 158, 11, 0.10) !important;
  color: #e2e8f0 !important;
  --bs-table-bg: transparent;
  --bs-table-accent-bg: transparent;
}
[data-tema="escuro"] .table-light,
[data-tema="escuro"] .table > thead.table-light > tr > th,
[data-tema="escuro"] thead.table-light th {
  background-color: #0f172a !important;
  color: #94a3b8 !important;
  border-color: #1e293b !important;
}
[data-tema="escuro"] .table-success,
[data-tema="escuro"] .table-success > td {
  background-color: rgba(34, 197, 94, 0.10) !important;
  color: #e2e8f0 !important;
  --bs-table-bg: transparent;
}
[data-tema="escuro"] .table-danger,
[data-tema="escuro"] .table-danger > td {
  background-color: rgba(239, 68, 68, 0.10) !important;
  color: #e2e8f0 !important;
  --bs-table-bg: transparent;
}

/* btn-outline-dark em modo escuro — inverte para ficar visível */
[data-tema="escuro"] .btn-outline-dark {
  border-color: #94a3b8;
  color: #e2e8f0;
  background: transparent;
}
[data-tema="escuro"] .btn-outline-dark:hover {
  background-color: #334155;
  border-color: #94a3b8;
  color: #f1f5f9;
}

/* btn-outline-info, -primary, -success em modo escuro */
[data-tema="escuro"] .btn-outline-info {
  color: #67e8f9;
  border-color: #67e8f9;
}
[data-tema="escuro"] .btn-outline-info:hover {
  background-color: rgba(103,232,249,0.15);
  color: #a5f3fc;
  border-color: #67e8f9;
}
[data-tema="escuro"] .btn-outline-primary {
  color: #60a5fa;
  border-color: #60a5fa;
}
[data-tema="escuro"] .btn-outline-primary:hover {
  background-color: rgba(96,165,250,0.15);
  color: #93c5fd;
  border-color: #60a5fa;
}
[data-tema="escuro"] .btn-outline-success {
  color: #4ade80;
  border-color: #4ade80;
}
[data-tema="escuro"] .btn-outline-success:hover {
  background-color: rgba(74,222,128,0.15);
  color: #86efac;
  border-color: #4ade80;
}
[data-tema="escuro"] .btn-outline-danger {
  color: #f87171;
  border-color: #f87171;
}
[data-tema="escuro"] .btn-outline-danger:hover {
  background-color: rgba(248,113,113,0.15);
  color: #fca5a5;
  border-color: #f87171;
}

/* card-footer em modo escuro */
[data-tema="escuro"] .card-footer {
  background-color: #0f172a;
  border-top-color: #334155;
  color: #94a3b8;
}

/* card-header colorido (bg-success, bg-warning, bg-danger, bg-info) em modo escuro */
[data-tema="escuro"] .card-header.bg-success {
  background-color: rgba(22, 163, 74, 0.20) !important;
}
[data-tema="escuro"] .card-header.bg-success h6,
[data-tema="escuro"] .card-header.bg-success .h6 {
  color: #4ade80 !important;
}
[data-tema="escuro"] .card-header.bg-warning {
  background-color: rgba(217, 119, 6, 0.20) !important;
}
[data-tema="escuro"] .card-header.bg-warning h6,
[data-tema="escuro"] .card-header.bg-warning .h6 {
  color: #fcd34d !important;
}
[data-tema="escuro"] .card-header.bg-warning.text-dark {
  color: #fcd34d !important;
}
[data-tema="escuro"] .card-header.bg-danger {
  background-color: rgba(220, 38, 38, 0.20) !important;
}
[data-tema="escuro"] .card-header.bg-info {
  background-color: rgba(8, 145, 178, 0.20) !important;
}

/* table-secondary em modo escuro (usado em cabeçalhos de grupo nos testes em lote) */
[data-tema="escuro"] .table-secondary,
[data-tema="escuro"] .table-secondary > td,
[data-tema="escuro"] .table-secondary > th {
  background-color: rgba(100, 116, 139, 0.15) !important;
  color: #e2e8f0 !important;
  --bs-table-bg: transparent;
  --bs-table-accent-bg: transparent;
}

/* Label de risco Amarelo — bom contraste em modo claro e escuro */
.label-risco-amarelo {
  color: #b45309; /* amber-700 — contraste adequado sobre fundo branco */
}
[data-tema="escuro"] .label-risco-amarelo {
  color: #fbbf24; /* amber-400 — contraste adequado sobre fundo escuro */
}

/* Dropdowns em modo escuro */
[data-tema="escuro"] .dropdown-menu {
  background-color: #1e293b;
  border-color: #334155;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
[data-tema="escuro"] .dropdown-item {
  color: #e2e8f0;
}
[data-tema="escuro"] .dropdown-item:hover,
[data-tema="escuro"] .dropdown-item:focus {
  background-color: #334155;
  color: #f1f5f9;
}
[data-tema="escuro"] .dropdown-item.text-success {
  color: #4ade80 !important;
}
[data-tema="escuro"] .dropdown-item.text-danger {
  color: #f87171 !important;
}
[data-tema="escuro"] .dropdown-divider {
  border-top-color: #334155;
}

/* Input group em modo escuro */
[data-tema="escuro"] .input-group-text {
  background-color: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

/* Badges em modo escuro */
[data-tema="escuro"] .badge.bg-warning {
  background-color: #b45309 !important;
  color: #fef3c7 !important;
}
[data-tema="escuro"] .badge.bg-secondary {
  background-color: #475569 !important;
  color: #e2e8f0 !important;
}
[data-tema="escuro"] .badge.bg-light {
  background-color: #334155 !important;
  color: #e2e8f0 !important;
}
[data-tema="escuro"] .badge.bg-dark {
  background-color: #334155 !important;
  color: #e2e8f0 !important;
}

/* table-dark dentro do modo escuro — usa cabeçalho em azul-ardósia para diferenciar do body */
[data-tema="escuro"] .table-dark,
[data-tema="escuro"] .table-dark > * > tr > th,
[data-tema="escuro"] .table-dark > * > tr > td {
  --bs-table-bg: #0f172a;
  --bs-table-color: #94a3b8;
  background-color: #0f172a !important;
  color: #94a3b8 !important;
  border-color: #334155 !important;
}

/* code dentro de tabelas no modo escuro */
[data-tema="escuro"] .table code {
  background-color: #1e3a5f;
  color: #93c5fd;
  padding: 1px 5px;
  border-radius: 3px;
}

/* Breadcrumb em modo escuro */
[data-tema="escuro"] .breadcrumb-item,
[data-tema="escuro"] .breadcrumb-item a {
  color: #94a3b8;
}
[data-tema="escuro"] .breadcrumb-item.active {
  color: #e2e8f0;
}

/* Small/muted em modo escuro — contraste legível */
[data-tema="escuro"] small.text-muted,
[data-tema="escuro"] .small.text-muted,
[data-tema="escuro"] .card-header .text-muted,
[data-tema="escuro"] .card-header small,
[data-tema="escuro"] .card-body small.text-muted,
[data-tema="escuro"] .table .text-muted {
  color: #94a3b8 !important;
}

/* ===== DARK MODE: SIDEBAR ===== */
[data-tema="escuro"] .sidebar {
  background: #0f172a;
  color: #94a3b8;
  border-right-color: #1e293b;
}
[data-tema="escuro"] .sidebar-header {
  border-bottom-color: rgba(255,255,255,0.08);
}
[data-tema="escuro"] .sidebar-title {
  color: #f1f5f9;
}
[data-tema="escuro"] .sidebar-subtitle {
  color: #94a3b8;
}
[data-tema="escuro"] .nav-section {
  color: #64748b;
}
[data-tema="escuro"] .nav-item {
  color: #94a3b8;
}
[data-tema="escuro"] .nav-item:hover {
  color: #fff;
  background: rgba(255,255,255,0.05);
}
[data-tema="escuro"] .nav-item.active:hover {
  color: #fff;
  background: rgba(2, 132, 199, 0.25);
}
[data-tema="escuro"] .nav-item.active {
  color: #fff;
  background: rgba(2, 132, 199, 0.18);
  border-left-color: var(--sidebar-active);
}
[data-tema="escuro"] .sidebar-footer {
  border-top-color: rgba(255,255,255,0.08);
}
[data-tema="escuro"] .user-name {
  color: #f1f5f9;
}
[data-tema="escuro"] .user-role {
  color: #94a3b8;
}
[data-tema="escuro"] .sidebar::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }
  .sidebar.collapsed {
    width: var(--sidebar-width) !important;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0,0,0,0.3);
  }

  /* Quando a sidebar colapsada é aberta no mobile, restaura aparência completa */
  .sidebar.collapsed.open .sidebar-title,
  .sidebar.collapsed.open .sidebar-subtitle {
    display: block !important;
  }
  .sidebar.collapsed.open .sidebar-logo {
    width: 56px !important;
    height: 56px !important;
    font-size: 1.5rem !important;
    margin-bottom: 0.75rem !important;
  }
  .sidebar.collapsed.open .sidebar-header {
    padding: 1.5rem 1rem 1rem !important;
  }
  .sidebar.collapsed.open .nav-item {
    justify-content: flex-start !important;
    padding: 0.6rem 1.25rem !important;
    border-left: 3px solid transparent !important;
  }
  .sidebar.collapsed.open .nav-item i {
    margin-right: 0.75rem !important;
    font-size: 1rem !important;
  }
  .sidebar.collapsed.open .nav-item span {
    display: inline !important;
  }
  .sidebar.collapsed.open .nav-item.active {
    border-radius: 0 !important;
    border-left-color: var(--sidebar-active) !important;
    margin: 0 !important;
    padding: 0.6rem 1.25rem !important;
  }
  .sidebar.collapsed.open .nav-section {
    font-size: 0.65rem !important;
    padding: 1rem 1.25rem 0.35rem !important;
    text-align: left !important;
  }
  .sidebar.collapsed.open .nav-section::after {
    display: none !important;
  }
  .sidebar.collapsed.open .sidebar-footer {
    padding: 1rem !important;
    text-align: left !important;
  }
  .sidebar.collapsed.open .user-info {
    justify-content: flex-start !important;
  }
  .sidebar.collapsed.open .user-info-text {
    display: block !important;
  }
  .sidebar.collapsed.open .btn-sair span {
    display: inline !important;
  }
  .sidebar.collapsed.open .btn-sair {
    padding: 0.4rem 0.75rem !important;
  }
  .sidebar.collapsed.open .nav-item::after {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
  }
  .app-footer {
    margin-left: 0 !important;
  }
  .sidebar-toggle {
    display: block !important;
  }
  .btn-collapse-sidebar {
    display: none !important;
  }
}

@media (min-width: 992px) {
  .sidebar-toggle {
    display: none !important;
  }
}

/* ===== SCROLLBAR ===== */
.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.1);
  border-radius: 2px;
}

/* ===== PAGE LOADING OVERLAY ===== */
#page-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 8888;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(1px);
  pointer-events: none;
}
#page-loading-overlay.ativo {
  display: flex;
  pointer-events: all;
}
.loading-spinner-card {
  background: var(--card-bg, #1e1b2e);
  border: 1px solid var(--border-color, rgba(255,255,255,.12));
  border-radius: 14px;
  padding: 28px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  min-width: 160px;
  box-shadow: 0 16px 48px rgba(0,0,0,.3);
  animation: loadingFadeIn .18s ease;
}
.loading-spinner-card .spinner-border {
  width: 2.4rem;
  height: 2.4rem;
  border-width: .22rem;
}
.loading-spinner-card .loading-text {
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted, #aaa);
  letter-spacing: .04em;
}
@keyframes loadingFadeIn {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}
[data-tema="claro"] .loading-spinner-card {
  background: #ffffff;
  border-color: rgba(0,0,0,.12);
  box-shadow: 0 8px 32px rgba(0,0,0,.14);
}
[data-tema="claro"] .loading-spinner-card .loading-text {
  color: #666;
}

/* ─────────────────────────────────────────────────────────────────────────
   Section-Edit — seções colapsáveis com animação (editar/fechar)
   ───────────────────────────────────────────────────────────────────────── */
.se-section {
  transition: box-shadow .2s ease;
}
.se-section.se-open {
  box-shadow: 0 0 0 2px rgba(14, 165, 233, .35) !important;
}

/* cabeçalho com botão alinhado */
.se-header {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
}
.se-header .se-title-wrapper {
  flex: 1;
}
.se-header .se-summary {
  font-size: .8rem;
  color: #64748b;
  margin-top: 2px;
}

/* corpo colapsável — o JS define display:none / max-height / opacity */
.se-body {
  /* sem estilo extra aqui — controlado pelo JS */
}

/* badges de seção já editada (indicador opcional) */
.se-saved-badge {
  font-size: .7rem;
  opacity: .75;
}

/* Botão editar dentro do card-header */
.se-btn-edit {
  flex-shrink: 0;
  font-size: .8rem;
  padding: .25rem .65rem;
  border-radius: 6px;
}

/* Dark mode */
[data-tema="escuro"] .se-section.se-open {
  box-shadow: 0 0 0 2px rgba(56, 189, 248, .4) !important;
}
[data-tema="escuro"] .se-header .se-summary {
  color: #94a3b8;
}

/* ===== NOTIFICAÇÕES TOAST ===== */
#notificacao-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}
.notificacao-toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-radius: 12px;
  min-width: 300px;
  max-width: 520px;
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  pointer-events: auto;
  animation: notificacao-entrar 0.35s ease-out;
  backdrop-filter: blur(8px);
  cursor: pointer;
}
.notificacao-toast.sucesso  { background: linear-gradient(135deg,#059669,#10b981); border-left: 4px solid #34d399; }
.notificacao-toast.erro     { background: linear-gradient(135deg,#dc2626,#ef4444); border-left: 4px solid #f87171; }
.notificacao-toast.aviso    { background: linear-gradient(135deg,#d97706,#f59e0b); border-left: 4px solid #fbbf24; color: #1c1917; }
.notificacao-toast.info     { background: linear-gradient(135deg,#2563eb,#3b82f6); border-left: 4px solid #60a5fa; }
.notificacao-toast .toast-icon { font-size: 1.1rem; flex-shrink: 0; }
.notificacao-toast .toast-msg  { flex: 1; }
@keyframes notificacao-entrar {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0)    scale(1); }
}
@keyframes notificacao-sair {
  from { opacity: 1; transform: translateX(0)    scale(1); }
  to   { opacity: 0; transform: translateX(40px) scale(0.95); }
}
.notificacao-toast.saindo {
  animation: notificacao-sair 0.3s ease-in forwards;
}

/* ===== SIDEBAR DARK MODE ===== */
[data-tema="escuro"] .sidebar {
  background: #0f172a;
  border-right-color: #1e293b;
}
[data-tema="escuro"] .sidebar-header {
  border-bottom-color: rgba(255,255,255,0.08);
}
[data-tema="escuro"] .sidebar-title { color: #f1f5f9; }
[data-tema="escuro"] .sidebar-subtitle { color: #94a3b8; }
[data-tema="escuro"] .nav-section { color: #64748b; }
[data-tema="escuro"] .nav-item { color: #94a3b8; }
[data-tema="escuro"] .nav-item:hover { color: #fff; background: rgba(255,255,255,0.05); }
[data-tema="escuro"] .nav-item.active { color: #fff; background: rgba(2,132,199,0.18); border-left-color: var(--sidebar-active); }
[data-tema="escuro"] .nav-item.active:hover { color: #fff; background: rgba(2,132,199,0.25); }
[data-tema="escuro"] .sidebar-footer { border-top-color: rgba(255,255,255,0.08); }
[data-tema="escuro"] .user-name { color: #f1f5f9; }
[data-tema="escuro"] .user-role { color: #94a3b8; }
[data-tema="escuro"] .sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }
[data-tema="escuro"] .sidebar.collapsed .nav-section::after { background: #334155; }
[data-tema="escuro"] .sidebar.collapsed .nav-item::after { background: #334155; }

/* ===== BOOTSTRAP 4 compatibility shim ===== */
/* mr-* / ml-* → me-* / ms-* (Bootstrap 5 renomeou) */
.mr-1 { margin-right: .25rem !important; }
.mr-2 { margin-right: .5rem  !important; }
.mr-3 { margin-right: 1rem   !important; }
.ml-1 { margin-left:  .25rem !important; }
.ml-2 { margin-left:  .5rem  !important; }
.ml-3 { margin-left:  1rem   !important; }
.ml-auto { margin-left: auto !important; }
.mr-auto { margin-right: auto !important; }
/* badge pill → rounded-pill */
.badge-pill { border-radius: 0.5rem; }
/* form-group é removido no BS5 — adiciona mb-3 semanticamente */
.form-group { margin-bottom: 1rem; }
/* btn-block → d-block w-100 */
.btn-block { display: block; width: 100%; }
/* form-row (BS4) → equivalente ao row com gutter pequeno */
.form-row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -5px;
  margin-left: -5px;
}
.form-row > .col,
.form-row > [class*="col-"] {
  padding-right: 5px;
  padding-left: 5px;
}
/* form-inline (BS4): exibe campos em linha */
.form-inline {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  gap: .5rem;
}
.form-inline .form-control { width: auto; }
.form-inline .form-group   { margin-bottom: 0; }
/* Table responsive wrapper */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Border radius cards legado */
.card { border-radius: 12px; }

/* ── Footer sem sidebar (login, erro, páginas sem menu) ── */
.app-footer-full {
  margin-left: 0 !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITIES & COMPONENTES GLOBAIS
   Centralizados aqui para eliminar CSS inline espalhado pelos arquivos PHP
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── body / container reset (elimina os inline de cada arquivo) ──────────── */
body {
  font-family: var(--font-family, 'Inter', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif);
  background: var(--bg-color, #f0f4f8);
  color: var(--text-color, #1e293b);
  margin: 0;
}
/* Arquivos que usam `.container` legado dentro do content-wrapper */
.content-wrapper .container,
.content-wrapper > .container-fluid {
  margin-top: 0;
  padding-top: 0;
}

/* ── Page Header (padrão .page-header usado em ~9 arquivos) ─────────────── */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 1.5rem;
  padding: 1.25rem 1.5rem;
  background: linear-gradient(135deg, var(--primary-color, #0284c7) 0%, #0369a1 100%);
  color: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(2, 132, 199, 0.25);
}
.page-header h1,
.page-header h2,
.page-header .page-header-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}
.page-header p,
.page-header .page-header-sub {
  margin: 0.35rem 0 0;
  opacity: 0.9;
  font-size: 0.93rem;
}
.page-header .controls,
.page-header .page-header-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

[data-tema="escuro"] .page-header {
  background: linear-gradient(135deg, #1e40af 0%, #1d4ed8 100%);
  box-shadow: 0 4px 20px rgba(30, 64, 175, 0.35);
}

/* ── Status items / cards de status ─────────────────────────────────────── */
.status-item {
  background: #f8fafc;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  border-left: 4px solid #cbd5e0;
}
.status-item.success { background: #f0fdf4; border-left-color: #22c55e; }
.status-item.warning { background: #fffbeb; border-left-color: #f59e0b; }
.status-item.danger  { background: #fef2f2; border-left-color: #ef4444; }
.status-item.info    { background: #eff6ff; border-left-color: #3b82f6; }
.status-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.35rem;
}
.status-value {
  font-size: 1.05rem;
  font-weight: 600;
  color: #1e293b;
}
[data-tema="escuro"] .status-item            { background: #1e293b; border-left-color: #334155; }
[data-tema="escuro"] .status-item.success    { background: rgba(34,197,94,.08); }
[data-tema="escuro"] .status-item.warning    { background: rgba(245,158,11,.08); }
[data-tema="escuro"] .status-item.danger     { background: rgba(239,68,68,.08); }
[data-tema="escuro"] .status-item.info       { background: rgba(59,130,246,.08); }
[data-tema="escuro"] .status-label           { color: #94a3b8; }
[data-tema="escuro"] .status-value           { color: #e2e8f0; }

/* ── Bootstrap 4 badge colors (BS5 usa bg-* em vez de badge-*) ──────────── */
.badge-success { background-color: #198754 !important; color: #fff !important; }
.badge-warning { background-color: #ffc107 !important; color: #1c1917 !important; }
.badge-danger  { background-color: #dc3545 !important; color: #fff !important; }
.badge-info    { background-color: #0dcaf0 !important; color: #000 !important; }
.badge-primary { background-color: #0d6efd !important; color: #fff !important; }
.badge-secondary { background-color: #6c757d !important; color: #fff !important; }
.badge-light   { background-color: #f8f9fa !important; color: #1c1917 !important; }
.badge-dark    { background-color: #212529 !important; color: #fff !important; }

/* ── Flash fixado no topo da viewport ───────────────────────────────────── */
.flash-fixed {
  position: sticky;
  top: 10px;
  z-index: 1040;
  margin-bottom: 1rem;
}

/* ── Spinner em botão ───────────────────────────────────────────────────── */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: .82;
}
.btn-loading .spinner-btn {
  width: 1em; height: 1em;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  display: inline-block;
  animation: btn-spin .55s linear infinite;
  vertical-align: middle;
  margin-right: .35em;
}
@keyframes btn-spin { to { transform: rotate(360deg); } }

/* ── Status grid / grids de cards ───────────────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Card com hover lift (comp. card padrão) ────────────────────────────── */
.card-lift {
  transition: transform .2s ease, box-shadow .2s ease;
}
.card-lift:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12) !important;
}
[data-tema="escuro"] .card-lift:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.45) !important;
}

/* ── Table melhorias ────────────────────────────────────────────────────── */
.table {
  --bs-table-bg: transparent;
  font-size: .9rem;
}
.table thead th {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom-width: 2px;
  background: #f1f5f9;
  color: #374151;
}
.table > tbody > tr > td {
  vertical-align: middle;
}
[data-tema="escuro"] .table thead th {
  background: #1e293b;
  color: #94a3b8;
  border-color: #334155;
}
[data-tema="escuro"] .table > tbody > tr > td {
  color: #cbd5e1;
  border-color: #334155;
}
[data-tema="escuro"] .table-hover > tbody > tr:hover {
  background: rgba(255,255,255,0.04);
}
[data-tema="escuro"] .table-striped > tbody > tr:nth-of-type(odd) > * {
  background-color: rgba(255,255,255,0.03);
}

/* ── Alert dark mode ─────────────────────────────────────────────────────── */
[data-tema="escuro"] .alert-success  { background: rgba(34,197,94,.12); border-color: #166534; color: #86efac; }
[data-tema="escuro"] .alert-warning  { background: rgba(245,158,11,.12); border-color: #854d0e; color: #fde68a; }
[data-tema="escuro"] .alert-danger   { background: rgba(239,68,68,.12); border-color: #991b1b; color: #fca5a5; }
[data-tema="escuro"] .alert-info     { background: rgba(59,130,246,.12); border-color: #1e40af; color: #93c5fd; }
[data-tema="escuro"] .alert-secondary { background: rgba(100,116,139,.12); border-color: #334155; color: #94a3b8; }

/* ── Form controls dark mode ────────────────────────────────────────────── */
[data-tema="escuro"] .form-control,
[data-tema="escuro"] .form-select {
  background-color: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
[data-tema="escuro"] .form-control:focus,
[data-tema="escuro"] .form-select:focus {
  background-color: #1e293b;
  border-color: #3b82f6;
  color: #e2e8f0;
  box-shadow: 0 0 0 3px rgba(59,130,246,.25);
}
[data-tema="escuro"] .form-control::placeholder { color: #64748b; }
[data-tema="escuro"] .input-group-text {
  background-color: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
[data-tema="escuro"] .form-check-input {
  background-color: #1e293b;
  border-color: #475569;
}
[data-tema="escuro"] .form-label { color: #cbd5e1; }

/* ── Modal dark mode ─────────────────────────────────────────────────────── */
[data-tema="escuro"] .modal-content {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}
[data-tema="escuro"] .modal-header {
  border-bottom-color: #334155;
}
[data-tema="escuro"] .modal-footer {
  border-top-color: #334155;
}
[data-tema="escuro"] .modal-title { color: #f1f5f9; }
[data-tema="escuro"] .btn-close { filter: invert(1); }

/* ── Dropdown dark mode ─────────────────────────────────────────────────── */
[data-tema="escuro"] .dropdown-menu {
  background: #1e293b;
  border-color: #334155;
}
[data-tema="escuro"] .dropdown-item { color: #cbd5e1; }
[data-tema="escuro"] .dropdown-item:hover,
[data-tema="escuro"] .dropdown-item:focus {
  background: rgba(255,255,255,.06);
  color: #f1f5f9;
}
[data-tema="escuro"] .dropdown-divider { border-color: #334155; }

/* ── Card dark mode ─────────────────────────────────────────────────────── */
[data-tema="escuro"] .card {
  background: #1e293b;
  border-color: #334155;
}
[data-tema="escuro"] .card-header {
  background: #0f172a;
  border-bottom-color: #334155;
  color: #f1f5f9;
}
[data-tema="escuro"] .card-footer {
  background: #0f172a;
  border-top-color: #334155;
}
[data-tema="escuro"] .card-body { color: #e2e8f0; }
[data-tema="escuro"] .card-title { color: #f1f5f9; }
[data-tema="escuro"] .card-text,
[data-tema="escuro"] .card-subtitle { color: #94a3b8; }

/* ── Pagination dark mode ───────────────────────────────────────────────── */
[data-tema="escuro"] .page-link {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}
[data-tema="escuro"] .page-item.active .page-link {
  background: var(--primary-color, #0284c7);
  border-color: var(--primary-color, #0284c7);
}
[data-tema="escuro"] .page-item.disabled .page-link { color: #475569; }

/* ── Hr / separator dark mode ───────────────────────────────────────────── */
[data-tema="escuro"] hr { border-color: #334155; }

/* ── Legenda (legend item usado em processar.php etc) ───────────────────── */
.legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: .78rem;
  align-items: center;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* ── Dark mode: override estilo inline de arquivos migrados ─────────────── */
/* Garante que card/card-header sempre respeitem o dark mode via !important   */
/* O seletor html[data-tema] tem especificidade (0,2,0) que já vence seletores*/
/* simples de .card-header (0,1,0), mas !important garante contra classes     */
/* compostas ou utilitários Bootstrap com !important próprio.                 */

html[data-tema="escuro"] .card:not(.stat-card) {
  background: #1e293b !important;
  border-color: #334155 !important;
}
html[data-tema="escuro"] .card-header:not([class*="bg-"]) {
  background: #0f172a !important;
  background-color: #0f172a !important;
  border-bottom-color: #334155 !important;
  color: #f1f5f9 !important;
}
html[data-tema="escuro"] .card-body {
  background: #1e293b !important;
  color: #e2e8f0 !important;
}

/* Textos e labels genéricos em dark */
html[data-tema="escuro"] p,
html[data-tema="escuro"] label,
html[data-tema="escuro"] td,
html[data-tema="escuro"] li {
  color: inherit;
}
html[data-tema="escuro"] .content-wrapper {
  color: #e2e8f0;
}

/* Elementos com background branco/cinza claro hardcoded em inline <style> */
html[data-tema="escuro"] .bg-white {
  background-color: #1e293b !important;
  color: #e2e8f0 !important;
}

/* hr e separadores */
html[data-tema="escuro"] hr {
  border-color: #334155 !important;
  opacity: 1;
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .top-bar, .app-footer, #btnTema, .btn-collapse-sidebar,
  .no-print, .sidebar-toggle { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-wrapper { padding: 0 !important; }
  body { background: #fff !important; }
}

/* ── Botão Fechar (link dashboard) — sempre vermelho, cor fixa sem variação ── */
.btn-fechar,
.btn-fechar:hover,
.btn-fechar:focus,
.btn-fechar:active,
.btn-fechar:visited,
[data-tema="escuro"] .btn-fechar,
[data-tema="escuro"] .btn-fechar:hover,
[data-tema="escuro"] .btn-fechar:focus,
[data-tema="escuro"] .btn-fechar:active,
html[data-tema="escuro"] .btn-fechar,
html[data-tema="escuro"] .btn-fechar:hover,
html[data-tema="escuro"] .btn-fechar:focus,
html[data-tema="escuro"] .btn-fechar:active,
html body .btn-fechar,
html body .btn-fechar:hover,
html body .btn-fechar:focus,
html body .btn-fechar:active {
  background-color: #dc3545 !important;
  border-color: #c82333 !important;
  color: #fff !important;
  text-decoration: none !important;
  box-shadow: none !important;
  opacity: 1 !important;
}

/* Corrigir box-shadow de foco do Bootstrap 5.3 em btn-danger */
.btn-fechar:focus-visible,
html[data-tema="escuro"] .btn-fechar:focus-visible {
  box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.5) !important;
  outline: none !important;
}

