/**
 * Tema global (escuro / claro) — variáveis + superfícies da app Ads Scope.
 * data-bs-theme no <html> é aplicado antes do paint (inline no base) e
 * sincronizado por theme-toggle.js.
 */
[data-bs-theme="dark"] {
  /* App palette: navy + amber */
  --app-bg: #0a0e1a;
  --app-fg: #eef2ff;
  --app-card-bg: rgba(17, 24, 39, 0.84);
  --app-card-border: rgba(245, 158, 11, 0.22);
  /* Interior dos cartões: um degrau mais escuro que o “shell” */
  --app-card-inner-bg: rgba(10, 15, 30, 0.78);
  --app-table-row-border: rgba(165, 180, 252, 0.26);
  /* Listra (linhas pares) + hover: leitura em tabelas densas */
  --app-table-stripe-bg: rgba(99, 102, 241, 0.1);
  --app-table-row-hover-bg: rgba(245, 158, 11, 0.14);
  --app-sidebar-bg: rgba(10, 14, 26, 0.94);
  --app-muted: #a5b4d4;
  --app-loader-track: #303a63;

  /* Repasse para main.css e templates que usam --ads-* */
  --ads-bg: #090d1a;
  --ads-bg-card: rgba(17, 25, 45, 0.84);
  --ads-border: rgba(245, 158, 11, 0.2);
  --ads-border-strong: rgba(245, 158, 11, 0.45);
  --ads-text: #eef2ff;
  --ads-text-muted: #a5b4d4;
  --ads-accent: #f59e0b;
  --ads-accent-hover: #fcd34d;
  --ads-cyan: #38bdf8;

  /* Chat escuro = interior alinhado ao exemplo moderno */
  --app-chat-surface: #151f38;
  --app-chat-messages-bg: #0c1226;
  --app-chat-input-shell: rgba(18, 28, 52, 0.9);
  --app-chat-border: rgba(129, 140, 248, 0.25);
  --app-chat-bot-bubble-bg: #17213b;
  --app-chat-bot-bubble-fg: #dbe4ff;
  --app-chat-bot-border: rgba(129, 140, 248, 0.2);
  --app-chat-code-bg: #0c1226;
  --app-chat-code-fg: #d1dcff;
  --app-chat-welcome-bg: linear-gradient(145deg, #1b2650 0%, #121a35 52%, #0b1020 100%);
  --app-chat-accent-border: rgba(245, 158, 11, 0.35);
  /* Textura leve na área de mensagens (Insights + Agent chat) */
  --app-chat-messages-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%231a2a4a' fill-opacity='0.08'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

[data-bs-theme="light"] {
  /* App palette (light variant) */
  --app-bg: #fffbeb;
  --app-fg: #111827;
  --app-card-bg: #fff7e6;
  --app-card-border: #ead9bd;
  /* Interior dos cartões / listas: visivelmente mais escuro que o topo do card */
  --app-card-inner-bg: #fdf1da;
  --app-table-row-border: rgba(180, 83, 9, 0.2);
  --app-table-stripe-bg: rgba(180, 83, 9, 0.07);
  --app-table-row-hover-bg: rgba(245, 158, 11, 0.22);
  --app-sidebar-bg: rgba(255, 248, 233, 0.94);
  --app-muted: #7c6a4b;
  --app-loader-track: #e7d5b8;
  --app-input-bg: #fffaf0;
  --app-raised-bg: #fffdf7;
  /* Repasse para main.css / templates com --ads-* */
  --ads-bg: #fff8ea;
  --ads-bg-card: #fff7e6;
  --ads-border: rgba(180, 83, 9, 0.22);
  --ads-border-strong: rgba(180, 83, 9, 0.42);
  --ads-text: #111827;
  --ads-text-muted: #7c6a4b;
  --ads-accent: #f59e0b;
  --ads-accent-hover: #d97706;
  --ads-cyan: #0284c7;
  /* Chat: thread mais escura, bolhas um pouco mais claras (menos “estourado”) */
  --app-chat-surface: #fff7e8;
  --app-chat-messages-bg: #fdf1da;
  --app-chat-messages-pattern: none;
  --app-chat-input-shell: #fffaf0;
  --app-chat-border: #ead9bd;
  --app-chat-bot-bubble-bg: #fffdf7;
  --app-chat-bot-bubble-fg: #111827;
  --app-chat-bot-border: #ead9bd;
  --app-chat-code-bg: #fff2dd;
  --app-chat-code-fg: #111827;
  --app-chat-welcome-bg: linear-gradient(155deg, #fffcf3 0%, #fff4df 52%, #feeac9 100%);
  --app-chat-accent-border: rgba(180, 83, 9, 0.2);
  --app-chat-accent-strong: rgba(180, 83, 9, 0.32);
}

html[data-bs-theme="light"] {
  color-scheme: light;
}

html[data-bs-theme="dark"] {
  color-scheme: dark;
}

/* === Modo escuro: fundo, tipografia e shell (slate + âmbar) === */
html[data-bs-theme="dark"] body.apex-body {
  background: radial-gradient(1100px 580px at 12% -8%, rgba(245, 158, 11, 0.18), transparent 58%),
              radial-gradient(900px 500px at 88% -12%, rgba(56, 189, 248, 0.14), transparent 52%),
              linear-gradient(165deg, #0b1020 0%, #090d1a 45%, #080b16 100%) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body h1,
html[data-bs-theme="dark"] body.apex-body h2,
html[data-bs-theme="dark"] body.apex-body h3,
html[data-bs-theme="dark"] body.apex-body h4,
html[data-bs-theme="dark"] body.apex-body h5,
html[data-bs-theme="dark"] body.apex-body .h1,
html[data-bs-theme="dark"] body.apex-body .h2,
html[data-bs-theme="dark"] body.apex-body .h3,
html[data-bs-theme="dark"] body.apex-body .h4,
html[data-bs-theme="dark"] body.apex-body .h5 {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .sidebar {
  background: var(--app-sidebar-bg) !important;
  border-right-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .sidebar .nav-link {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body .sidebar .nav-link:hover,
html[data-bs-theme="dark"] body.apex-body .sidebar .nav-link.active {
  color: #fbbf24 !important;
  background: rgba(245, 158, 11, 0.1) !important;
}

html[data-bs-theme="dark"] body.apex-body .sidebar-footer {
  border-top-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .sidebar-toggle {
  background: rgba(245, 158, 11, 0.12) !important;
  border-color: rgba(245, 158, 11, 0.38) !important;
  color: #fbbf24 !important;
}

html[data-bs-theme="dark"] body.apex-body .flash-messages-container .alert {
  border-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .account-card.card {
  background: var(--app-card-bg) !important;
  border-color: var(--app-card-border) !important;
  color: var(--app-fg) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

html[data-bs-theme="dark"] body.apex-body .account-card.card .card-title {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .card.bg-dark {
  background: var(--app-card-bg) !important;
  border: 1px solid var(--app-card-border) !important;
  color: var(--app-fg) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

html[data-bs-theme="dark"] body.apex-body .text-secondary {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body .form-control,
html[data-bs-theme="dark"] body.apex-body .form-select {
  background: rgba(30, 41, 59, 0.65) !important;
  border-color: var(--app-card-border) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .form-control:focus,
html[data-bs-theme="dark"] body.apex-body .form-select:focus {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .form-control::placeholder {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body #dashboard-container.position-relative.bg-dark {
  background: var(--app-card-bg) !important;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35) !important;
  border: 1px solid var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.apex-body {
  background: radial-gradient(980px 520px at 10% -10%, rgba(245, 158, 11, 0.2), transparent 58%),
              radial-gradient(860px 460px at 88% -12%, rgba(14, 116, 144, 0.12), transparent 56%),
              linear-gradient(165deg, #fffdf6 0%, #fff7e8 48%, #ffefd1 100%) !important;
  color: var(--app-fg) !important;
  transition: background-color 0.2s ease, color 0.2s ease;
}

html[data-bs-theme] body.apex-body {
  font-family: 'Inter', 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif !important;
}

html[data-bs-theme="light"] body.apex-body h1,
html[data-bs-theme="light"] body.apex-body h2,
html[data-bs-theme="light"] body.apex-body h3,
html[data-bs-theme="light"] body.apex-body h4,
html[data-bs-theme="light"] body.apex-body h5,
html[data-bs-theme="light"] body.apex-body .h1,
html[data-bs-theme="light"] body.apex-body .h2,
html[data-bs-theme="light"] body.apex-body .h3,
html[data-bs-theme="light"] body.apex-body .h4,
html[data-bs-theme="light"] body.apex-body .h5 {
  color: #111827 !important;
}

html[data-bs-theme="light"] body.apex-body a:not(.btn):not(.nav-link) {
  color: #b45309;
}

html[data-bs-theme="light"] body.apex-body a:not(.btn):not(.nav-link):hover {
  color: #d97706;
}

html[data-bs-theme="light"] body.apex-body .sidebar {
  background: var(--app-sidebar-bg) !important;
  border-right-color: var(--app-card-border) !important;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

html[data-bs-theme="light"] body.apex-body .sidebar .nav-link {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .sidebar .nav-link:hover,
html[data-bs-theme="light"] body.apex-body .sidebar .nav-link.active {
  color: #111827 !important;
  background: rgba(245, 158, 11, 0.14) !important;
}

html[data-bs-theme="light"] body.apex-body .sidebar-footer {
  border-top-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.apex-body .sidebar-toggle {
  background: rgba(245, 158, 11, 0.14) !important;
  border-color: rgba(180, 83, 9, 0.32) !important;
  color: #92400e !important;
}

html[data-bs-theme="light"] body.apex-body .flash-messages-container .alert {
  border-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.apex-body .account-card.card {
  background: var(--app-card-bg) !important;
  border-color: var(--app-card-border) !important;
  color: var(--app-fg) !important;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

html[data-bs-theme="light"] body.apex-body .account-card.card .card-title {
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .card.bg-dark {
  background: var(--app-card-bg) !important;
  border: 1px solid var(--app-card-border) !important;
  color: var(--app-fg) !important;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

html[data-bs-theme="light"] body.apex-body .text-light {
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .text-secondary {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .btn-outline-light {
  border-color: #e0c79f !important;
  color: #111827 !important;
}

html[data-bs-theme="light"] body.apex-body .btn-outline-light:hover {
  background: rgba(245, 158, 11, 0.12) !important;
  border-color: rgba(180, 83, 9, 0.4) !important;
  color: #111827 !important;
}

html[data-bs-theme="light"] body.apex-body .form-control,
html[data-bs-theme="light"] body.apex-body .form-select {
  background: var(--app-input-bg) !important;
  border-color: #dfc59d !important;
  color: #111827 !important;
}

html[data-bs-theme="light"] body.apex-body .form-control:focus,
html[data-bs-theme="light"] body.apex-body .form-select:focus {
  color: #111827 !important;
}

.app-card {
  background-color: var(--app-card-bg) !important;
  border-color: var(--app-card-border) !important;
}

/* Aura visual polish: acabamento premium global */
html[data-bs-theme] .card,
html[data-bs-theme] .modal-content,
html[data-bs-theme] .dropdown-menu {
  border-radius: 14px !important;
}

html[data-bs-theme] .card,
html[data-bs-theme] .modal-content {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 34px rgba(10, 18, 40, 0.18) !important;
}

html[data-bs-theme="dark"] .btn-primary,
html[data-bs-theme="dark"] .btn-warning {
  background-image: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%) !important;
  border-color: rgba(245, 158, 11, 0.55) !important;
  color: #0a0e1a !important;
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.3);
}

html[data-bs-theme="light"] .btn-primary,
html[data-bs-theme="light"] .btn-warning {
  background-image: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%) !important;
  border-color: rgba(180, 83, 9, 0.5) !important;
  color: #111827 !important;
  box-shadow: 0 6px 16px rgba(180, 83, 9, 0.22);
}

html[data-bs-theme] .btn-primary:hover,
html[data-bs-theme] .btn-warning:hover {
  transform: translateY(-1px);
}

html[data-bs-theme="dark"] .btn-primary:hover,
html[data-bs-theme="dark"] .btn-warning:hover,
html[data-bs-theme="dark"] .btn-primary:focus,
html[data-bs-theme="dark"] .btn-warning:focus,
html[data-bs-theme="dark"] .btn-primary:active,
html[data-bs-theme="dark"] .btn-warning:active {
  color: #111827 !important;
  border-color: rgba(251, 191, 36, 0.9) !important;
}

html[data-bs-theme="light"] .btn-primary:hover,
html[data-bs-theme="light"] .btn-warning:hover,
html[data-bs-theme="light"] .btn-primary:focus,
html[data-bs-theme="light"] .btn-warning:focus,
html[data-bs-theme="light"] .btn-primary:active,
html[data-bs-theme="light"] .btn-warning:active {
  color: #0f172a !important;
  border-color: rgba(146, 64, 14, 0.7) !important;
}

/* Toque editorial do DS: linhas e contraste sutil em light */
html[data-bs-theme="light"] body.apex-body .main-content,
html[data-bs-theme="light"] body.apex-body .chat-container,
html[data-bs-theme="light"] body.apex-body .card,
html[data-bs-theme="light"] body.apex-body .modal-content {
  border-color: #d6d3d1 !important;
}

html[data-bs-theme="light"] body.apex-body .text-secondary,
html[data-bs-theme="light"] body.apex-body .small.text-secondary {
  color: #78716c !important;
}

.app-auth-card {
  background-color: var(--app-card-bg) !important;
  border-radius: 1rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

[data-bs-theme="dark"] .app-auth-card {
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.app-hr {
  border-color: var(--app-card-border) !important;
  opacity: 1;
}

.app-fine-print {
  font-size: 0.8rem;
}

.status-loader {
  border: 8px solid var(--app-loader-track);
  border-top: 8px solid var(--bs-primary, #f59e0b);
  border-radius: 50%;
  width: 60px;
  height: 60px;
  animation: app-spin 1.5s linear infinite;
  margin: 2rem auto;
}

@keyframes app-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#app-theme-toggle {
  z-index: 1020;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem;
  top: max(0.5rem, env(safe-area-inset-top, 0px));
  right: max(0.5rem, env(safe-area-inset-right, 0px));
  margin-top: 0 !important;
  margin-right: 0 !important;
}

html[data-bs-theme] .main-content {
  padding-top: 3.25rem;
}

@media (min-width: 993px) {
  html[data-bs-theme] .main-content {
    padding-top: 2.75rem;
  }
}

[data-bs-theme="light"] #app-theme-toggle {
  background: transparent !important;
  border: none !important;
  color: #475569;
}

[data-bs-theme="dark"] #app-theme-toggle {
  background: transparent !important;
  border: none !important;
  color: #cbd5e1;
}

[data-bs-theme="dark"] #app-theme-toggle .theme-when-light {
  display: none !important;
}
[data-bs-theme="light"] #app-theme-toggle .theme-when-dark {
  display: none !important;
}

/* --- Auth (login / senha / status / erro / Google) --- */
html[data-bs-theme="light"] body.apex-body.auth-body {
  background: linear-gradient(160deg, #fff9ec 0%, #fff2da 46%, #ffe8bf 100%) !important;
  color: #111827 !important;
}

html[data-bs-theme="light"] body.apex-body.auth-body .auth-card {
  background: var(--app-card-bg) !important;
  border-color: var(--app-card-border) !important;
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.08);
}

html[data-bs-theme="light"] body.apex-body.auth-body .auth-card .card-body {
  background: var(--app-card-bg) !important;
}

html[data-bs-theme="light"] body.apex-body.auth-body .text-light {
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body.auth-body .btn-close {
  filter: none;
}

html[data-bs-theme="light"] body.apex-body.auth-body .auth-page-header {
  background: rgba(255, 247, 230, 0.96) !important;
  border-bottom-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.apex-body.auth-body .auth-page-header .text-light {
  color: #111827 !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body {
  background: linear-gradient(165deg, #1e293b 0%, #0f172a 50%, #0c1222 100%) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body .auth-card {
  background: rgba(30, 41, 59, 0.75) !important;
  border-color: var(--app-card-border) !important;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

html[data-bs-theme="dark"] body.apex-body.auth-body .auth-card .card-body {
  background: rgba(15, 23, 42, 0.55) !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body .text-light {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body .auth-page-header {
  background: rgba(15, 23, 42, 0.95) !important;
  border-bottom-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body .auth-page-header .text-light {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body.auth-body .auth-page-header .text-secondary {
  color: var(--app-muted) !important;
}

/* --- Portal (landing pública) — body.portal-body --- */
html[data-bs-theme="light"] body.portal-body {
  background: linear-gradient(160deg, #fff9ec 0%, #fff2da 42%, #ffe8bf 100%) !important;
  color: #111827 !important;
}

html[data-bs-theme="light"] body.portal-body header {
  background: rgba(255, 247, 230, 0.95) !important;
  border-bottom-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.portal-body .hero-gradient {
  background: linear-gradient(135deg, rgba(255, 245, 221, 0.92), rgba(255, 236, 198, 0.88)), url("https://i.imgur.com/9gZCOy8.png") no-repeat center center !important;
  background-size: cover !important;
}

html[data-bs-theme="light"] body.portal-body .hero-content {
  color: #111827 !important;
}

html[data-bs-theme="light"] body.portal-body .hero-title {
  color: #111827 !important;
  text-shadow: none;
}

html[data-bs-theme="light"] body.portal-body .hero-subtitle {
  color: #7c6a4b !important;
}

html[data-bs-theme="light"] body.portal-body section.py-5.bg-dark {
  background: #fff0d3 !important;
}

html[data-bs-theme="light"] body.portal-body .app-portal-footer {
  border-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.portal-body .feature-card p.text-secondary {
  color: #64748b !important;
}

html[data-bs-theme="dark"] body.portal-body {
  background: linear-gradient(165deg, #1e293b 0%, #0f172a 45%, #0c1222 100%) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.portal-body header {
  background: rgba(15, 23, 42, 0.92) !important;
  border-bottom-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.portal-body .hero-content {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.portal-body .hero-title {
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.portal-body .hero-subtitle {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.portal-body section.py-5.bg-dark {
  background: rgba(30, 41, 59, 0.45) !important;
}

html[data-bs-theme="dark"] body.portal-body .app-portal-footer {
  border-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.portal-body .feature-card p.text-secondary {
  color: var(--app-muted) !important;
}

/* Tabelas (.table-dark e tabelas normais): bordas de linha visíveis */
html[data-bs-theme="light"] body.apex-body .table-dark {
  --bs-table-bg: var(--app-card-inner-bg);
  --bs-table-color: #1e293b;
  --bs-table-border-color: var(--app-table-row-border);
}

html[data-bs-theme="dark"] body.apex-body .table,
html[data-bs-theme="light"] body.apex-body .table {
  --bs-table-border-color: var(--app-table-row-border);
  border-color: var(--app-table-row-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .table > :not(caption) > * > *,
html[data-bs-theme="light"] body.apex-body .table > :not(caption) > * > * {
  border-bottom-width: 1px !important;
  border-bottom-style: solid !important;
  border-bottom-color: var(--app-table-row-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .table thead th,
html[data-bs-theme="light"] body.apex-body .table thead th {
  border-bottom-width: 2px !important;
  border-bottom-style: solid !important;
  border-bottom-color: var(--app-table-row-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .table-bordered,
html[data-bs-theme="light"] body.apex-body .table-bordered {
  border-color: var(--app-table-row-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .table-bordered > :not(caption) > * > *,
html[data-bs-theme="light"] body.apex-body .table-bordered > :not(caption) > * > * {
  border-color: var(--app-table-row-border) !important;
}

/* Listras em linhas (tbody): contraste suave sem quebrar table-dark / light */
html[data-bs-theme="dark"] body.apex-body .table tbody tr:nth-child(even) > *,
html[data-bs-theme="light"] body.apex-body .table tbody tr:nth-child(even) > *,
html[data-bs-theme="dark"] body.portal-body .table tbody tr:nth-child(even) > *,
html[data-bs-theme="light"] body.portal-body .table tbody tr:nth-child(even) > * {
  background-color: var(--app-table-stripe-bg) !important;
}

html[data-bs-theme="dark"] body.apex-body .table tbody tr:hover > *,
html[data-bs-theme="light"] body.apex-body .table tbody tr:hover > *,
html[data-bs-theme="dark"] body.portal-body .table tbody tr:hover > *,
html[data-bs-theme="light"] body.portal-body .table tbody tr:hover > * {
  background-color: var(--app-table-row-hover-bg) !important;
}

/* Cartões e modais: interior mais escuro que o shell (menos “branco estourado”) */
html[data-bs-theme="dark"] body.apex-body .card > .card-body,
html[data-bs-theme="dark"] body.apex-body .card > .list-group,
html[data-bs-theme="dark"] body.apex-body .card .card-footer,
html[data-bs-theme="light"] body.apex-body .card > .card-body,
html[data-bs-theme="light"] body.apex-body .card > .list-group,
html[data-bs-theme="light"] body.apex-body .card .card-footer {
  background-color: var(--app-card-inner-bg) !important;
}

html[data-bs-theme="dark"] body.apex-body .modal-body,
html[data-bs-theme="light"] body.apex-body .modal-body {
  background-color: var(--app-card-inner-bg) !important;
}

html[data-bs-theme="dark"] body.apex-body .modal-header,
html[data-bs-theme="light"] body.apex-body .modal-header {
  background-color: var(--app-card-bg) !important;
  border-bottom-color: var(--app-card-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .modal-footer,
html[data-bs-theme="light"] body.apex-body .modal-footer {
  background-color: var(--app-card-bg) !important;
  border-top-color: var(--app-card-border) !important;
}

html[data-bs-theme="light"] body.apex-body .breadcrumb-item.active {
  color: #64748b !important;
}

html[data-bs-theme="light"] body.apex-body .text-white {
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .alert-dark {
  background: var(--app-input-bg) !important;
  border-color: #b0bcc9 !important;
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body select option {
  background: var(--app-input-bg) !important;
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .admin-ads-accordion .accordion-button:not(.collapsed) {
  background: rgba(245, 158, 11, 0.12) !important;
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .admin-ads-accordion .accordion-button::after {
  filter: none;
}

html[data-bs-theme="light"] body.apex-body #dashboard-container.position-relative.bg-dark {
  background: var(--app-card-bg) !important;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08) !important;
}

/* ========== Chat: modo escuro (vars slate + âmbar, alinhado ao Hub) ========== */

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-container,
html[data-bs-theme="dark"] body.apex-body .insights-page .chat-container {
  background: var(--app-chat-surface) !important;
  border-color: var(--app-chat-border) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-header,
html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizationPanel,
html[data-bs-theme="dark"] body.apex-body .insights-page .chat-header {
  background: var(--app-chat-surface) !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-header .small,
html[data-bs-theme="dark"] body.apex-body .insights-page .chat-header .small {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page #insightsMessages.chat-messages,
html[data-bs-theme="dark"] body.apex-body .insights-page #insightsMessages.chat-messages {
  background: var(--app-chat-messages-bg) !important;
  background-image: var(--app-chat-messages-pattern) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-input-area,
html[data-bs-theme="dark"] body.apex-body .insights-page .chat-input-area {
  background: var(--app-chat-surface) !important;
  border-top-color: var(--app-chat-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-input-wrapper,
html[data-bs-theme="dark"] body.apex-body .insights-page .chat-input-wrapper {
  background: var(--app-chat-input-shell) !important;
  border-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .chat-msg-textarea,
html[data-bs-theme="dark"] body.apex-body .insights-page #insightsInput {
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page .form-check-label.text-light,
html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizationPanel .text-light {
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizationPanel .small,
html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizeSelectionHint {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizeAccountSelect,
html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizeCampaignSelect {
  background-color: rgba(15, 23, 42, 0.85) !important;
  color: var(--app-fg) !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizeAccountSelect option,
html[data-bs-theme="dark"] body.apex-body .agent-chat-page #optimizeCampaignSelect option {
  background-color: #1e293b !important;
  color: #f1f5f9 !important;
}

html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot {
  background: var(--app-chat-bot-bubble-bg) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
  border-color: var(--app-chat-bot-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content,
html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content p,
html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content li {
  color: #cbd5e1 !important;
}

html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content h1,
html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content h2,
html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot .msg-content h3 {
  color: #f1f5f9 !important;
}

html[data-bs-theme="dark"] body.apex-body .msg-bubble.bot pre {
  background: var(--app-chat-code-bg) !important;
  color: var(--app-chat-code-fg) !important;
  border: 1px solid var(--app-chat-border);
}

html[data-bs-theme="dark"] body.apex-body .typing-indicator {
  background: var(--app-chat-bot-bubble-bg) !important;
  border-color: var(--app-chat-bot-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card {
  background: var(--app-chat-welcome-bg) !important;
  border-color: var(--app-chat-accent-border) !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--app-chat-border) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-title {
  color: #f1f5f9 !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-text,
html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-hint,
html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-briefing {
  color: #cbd5e1 !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-briefing strong {
  color: #fbbf24 !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-micro-label {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body .chat-welcome-card .welcome-briefing {
  border-top-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="dark"] body.apex-body .insights-page .agent-tab {
  background: rgba(30, 41, 59, 0.55) !important;
  border-color: var(--app-chat-border) !important;
  color: #cbd5e1 !important;
}

html[data-bs-theme="dark"] body.apex-body .insights-page .agent-tab:hover {
  border-color: rgba(245, 158, 11, 0.4) !important;
  color: #fbbf24 !important;
}

html[data-bs-theme="dark"] body.apex-body .insights-page .agent-tab.active {
  background: rgba(245, 158, 11, 0.14) !important;
  border-color: #f59e0b !important;
  color: #fbbf24 !important;
}

html[data-bs-theme="dark"] body.apex-body .insights-page #campaignSelector,
html[data-bs-theme="dark"] body.apex-body .insights-page #analyzerStartDate,
html[data-bs-theme="dark"] body.apex-body .insights-page #analyzerEndDate {
  background: rgba(30, 41, 59, 0.85) !important;
  border-color: var(--app-chat-accent-border) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal .modal-content,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal .modal-content {
  background: var(--app-chat-surface) !important;
  border: 1px solid var(--app-chat-border) !important;
  color: var(--app-fg) !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal .modal-header,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal .modal-header {
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal #successInsightsChat,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisResult {
  background: var(--app-chat-messages-bg) !important;
  border-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal #successInsightsInput,
html[data-bs-theme="dark"] body.apex-body #successInsightsModal #successInsightsPeriod,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisPeriod {
  background: rgba(15, 23, 42, 0.75) !important;
  color: var(--app-fg) !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisContent .small,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisContent p.small {
  color: var(--app-muted) !important;
}

html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisResultContent.text-light {
  color: #e2e8f0 !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal #successInsightsLoading,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisLoading {
  background: rgba(15, 23, 42, 0.94) !important;
}

html[data-bs-theme="dark"] body.apex-body #successInsightsModal #successInsightsLoading .small,
html[data-bs-theme="dark"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisLoading .small {
  color: var(--app-muted) !important;
}

/* ========== Chat: modo claro (agent_chat + insights) — cores do layout moderno ========== */

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-container,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-container {
  background: var(--app-chat-surface) !important;
  border-color: var(--app-chat-border) !important;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.06) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-header,
html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizationPanel,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-header {
  background: var(--app-chat-surface) !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-header .small,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-header .small {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-header .btn,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-header .btn-outline-secondary {
  border-color: var(--app-chat-border) !important;
  color: #b45309 !important;
  background: var(--app-raised-bg) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-header .btn:hover {
  background: rgba(245, 158, 11, 0.16) !important;
  border-color: rgba(180, 83, 9, 0.35) !important;
  color: #92400e !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page #insightsMessages.chat-messages,
html[data-bs-theme="light"] body.apex-body .insights-page #insightsMessages.chat-messages {
  background: var(--app-chat-messages-bg) !important;
  background-image: var(--app-chat-messages-pattern) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-input-area,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-input-area {
  background: var(--app-chat-surface) !important;
  border-top-color: var(--app-chat-border) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-input-wrapper,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-input-wrapper {
  background: var(--app-chat-input-shell) !important;
  border-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-msg-textarea,
html[data-bs-theme="light"] body.apex-body .insights-page #insightsInput {
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .chat-input-wrapper:focus-within,
html[data-bs-theme="light"] body.apex-body .insights-page .chat-input-wrapper:focus-within {
  border-color: rgba(245, 158, 11, 0.45) !important;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.12) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page .form-check-label.text-light,
html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizationPanel .text-light {
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizationPanel .small,
html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizeSelectionHint {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizeAccountSelect,
html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizeCampaignSelect {
  background-color: var(--app-input-bg) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizeAccountSelect option,
html[data-bs-theme="light"] body.apex-body .agent-chat-page #optimizeCampaignSelect option {
  background-color: var(--app-input-bg) !important;
  color: #1e293b !important;
}

/* Bolhas e conteúdo Markdown */
html[data-bs-theme="light"] body.apex-body .msg-bubble.bot {
  background: var(--app-chat-bot-bubble-bg) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
  border-color: var(--app-chat-bot-border) !important;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content,
html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content p,
html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content li {
  color: #334155 !important;
}

html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content h1,
html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content h2,
html[data-bs-theme="light"] body.apex-body .msg-bubble.bot .msg-content h3 {
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .msg-bubble .msg-content .text-muted,
html[data-bs-theme="light"] body.apex-body .msg-bubble .msg-content .text-secondary {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .msg-bubble.bot pre,
html[data-bs-theme="light"] body.apex-body .msg-bubble pre {
  background: var(--app-chat-code-bg) !important;
  color: var(--app-chat-code-fg) !important;
  border: 1px solid var(--app-chat-border);
}

html[data-bs-theme="light"] body.apex-body .msg-bubble.user pre {
  background: rgba(0, 0, 0, 0.18) !important;
  color: #f0fdfa !important;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

html[data-bs-theme="light"] body.apex-body .msg-bubble .code-block-hud-outer {
  border: 1px solid rgba(180, 83, 9, 0.22) !important;
}
html[data-bs-theme="light"] body.apex-body .msg-bubble .code-block-hud-outer > .code-block-pre--scroll,
html[data-bs-theme="light"] body.apex-body .msg-bubble .code-block-hud-outer > pre {
  background: var(--app-chat-code-bg, #fffbeb) !important;
  color: var(--app-chat-code-fg, #1e293b) !important;
}

html[data-bs-theme="light"] body.apex-body .msg-bubble .code-block-hud {
  background: linear-gradient(0deg, rgba(255, 251, 235, 0.98) 0%, rgba(255, 251, 235, 0.78) 50%, rgba(255, 251, 235, 0) 100%) !important;
}

html[data-bs-theme="light"] body.apex-body .msg-bubble .btn-copy-code {
  background: rgba(245, 158, 11, 0.15) !important;
  color: #b45309 !important;
  border-color: rgba(180, 83, 9, 0.35) !important;
}

html[data-bs-theme="light"] body.apex-body .typing-indicator {
  background: var(--app-chat-bot-bubble-bg) !important;
  border-color: var(--app-chat-bot-border) !important;
}

html[data-bs-theme="light"] body.apex-body .typing-dot {
  background: #94a3b8 !important;
}

/* Cartão de boas-vindas */
html[data-bs-theme="light"] body.apex-body .chat-welcome-card {
  background: var(--app-chat-welcome-bg) !important;
  border-color: var(--app-chat-accent-border) !important;
  box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08), 0 0 0 1px var(--app-chat-border) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-title {
  color: #1e293b !important;
  text-shadow: none !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-text,
html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-hint,
html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-briefing {
  color: #475569 !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-briefing strong {
  color: #b45309 !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-micro-label {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-briefing {
  border-top-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="light"] body.apex-body .chat-welcome-card .welcome-icon {
  filter: none !important;
}

/* Insights: barra superior (tabs, selects, datas) */
html[data-bs-theme="light"] body.apex-body .insights-page .form-label.small {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body .insights-page #campaignSelector,
html[data-bs-theme="light"] body.apex-body .insights-page #analyzerStartDate,
html[data-bs-theme="light"] body.apex-body .insights-page #analyzerEndDate {
  background: var(--app-input-bg) !important;
  border-color: var(--app-chat-accent-border) !important;
  color: #1e293b !important;
}

html[data-bs-theme="light"] body.apex-body .insights-page .agent-tab {
  background: var(--app-raised-bg) !important;
  border-color: var(--app-chat-border) !important;
  color: #475569 !important;
}

html[data-bs-theme="light"] body.apex-body .insights-page .agent-tab:hover {
  border-color: rgba(245, 158, 11, 0.35) !important;
  color: #b45309 !important;
}

html[data-bs-theme="light"] body.apex-body .insights-page .agent-tab.active {
  background: rgba(245, 158, 11, 0.12) !important;
  border-color: #f59e0b !important;
  color: #b45309 !important;
}

html[data-bs-theme="light"] body.apex-body .insights-page #analyzerExtraRow .small,
html[data-bs-theme="light"] body.apex-body .insights-page #analyzerExtraRow span.small {
  color: var(--app-muted) !important;
}

/* Modais de chat / análise IA (sucesso + conta) — modo claro */
html[data-bs-theme="light"] body.apex-body #successInsightsModal .modal-content,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal .modal-content {
  background: var(--app-chat-surface) !important;
  border: 1px solid var(--app-chat-border) !important;
  color: var(--app-chat-bot-bubble-fg) !important;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal .modal-header,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal .modal-header {
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal .btn-close,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal .btn-close {
  filter: none !important;
  opacity: 0.55;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal #successInsightsLoading,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisLoading {
  background: rgba(220, 228, 236, 0.96) !important;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal #successInsightsLoading .small,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisLoading .small {
  color: var(--app-muted) !important;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal #successInsightsChat,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisResult {
  background: var(--app-chat-messages-bg) !important;
  border-color: var(--app-chat-accent-border) !important;
}

html[data-bs-theme="light"] body.apex-body #successInsightsModal #successInsightsInput,
html[data-bs-theme="light"] body.apex-body #successInsightsModal #successInsightsPeriod,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisPeriod {
  background: var(--app-input-bg) !important;
  color: #1e293b !important;
  border-color: var(--app-chat-border) !important;
}

html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisContent .small,
html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisContent p.small {
  color: #475569 !important;
}

html[data-bs-theme="light"] body.apex-body #accountBaseAnalysisModal #accountBaseAnalysisResultContent.text-light {
  color: #334155 !important;
}
