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

/* Reserva espaço para ícones lucide enquanto o JS ainda não rodou —
   evita layout shift quando lucide.createIcons() substitui o <i> por <svg>. */
i[data-lucide] { display: inline-block; width: 16px; height: 16px; vertical-align: middle; }

/* ── Anti-flash de carregamento ──────────────────────────────────────────────
   Durante o carregamento inicial (classe preload no body), todas as transições
   e animações são zeradas. Isso evita que cards, sidebar e botões "piscam"
   ao disparar suas transitions no primeiro render.
   A classe é removida pelo JS após lucide.createIcons() terminar. */
body.preload *,
body.preload *::before,
body.preload *::after {
  transition-duration: 0s !important;
  animation-duration:  0s !important;
}


:root {
  --bg-primary:    #0a0d13;
  --bg-secondary:  #13161f;
  --bg-card:       #1a1e29;
  --bg-elevated:   #232836;
  --accent:        #22c55e;
  --accent-hover:  #16a34a;
  --text-primary:  #f2f3f6;
  --text-muted:    #939aad;
  --border:        #262b38;
  --border-strong: #333a4a;
  --success:       #22c55e;
  --danger:        #ef4444;
}

/* Base sempre aplicada — garante que o body nunca fique sem cor/fundo */
body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

body.dark-theme {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

body.light-theme {
  --bg-primary:    #f6f5f1;
  --bg-secondary:  #ffffff;
  --bg-card:       #ffffff;
  --bg-elevated:   #f6f5f1;
  --accent:        #16a34a;
  --accent-hover:  #15803d;
  --text-primary:  #1a1915;
  --text-muted:    #6b6860;
  --border:        #e8e6e1;
  --border-strong: #d8d5cd;
  --success:       #16a34a;
  --danger:        #dc2626;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* Sombras suaves no lugar de bordas pesadas */
body.light-theme .sidebar             { box-shadow: 2px 0 8px rgba(0,0,0,.06); border-right-color: var(--border); }
body.light-theme .topbar              { box-shadow: 0 1px 6px rgba(0,0,0,.06); border-bottom-color: var(--border); }
body.light-theme .card                { box-shadow: 0 1px 4px rgba(0,0,0,.07); }
body.light-theme .filtros-form        { box-shadow: 0 1px 4px rgba(0,0,0,.06); }
body.light-theme .tabela-wrapper      { box-shadow: 0 1px 4px rgba(0,0,0,.06); }
body.light-theme .chart-box           { box-shadow: 0 1px 4px rgba(0,0,0,.06); }

/* Inputs e selects */
body.light-theme .filtro-group input,
body.light-theme .filtro-group select  { background: #faf9f7; color: var(--text-primary); border-color: var(--border); }
body.light-theme .filtro-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555555'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
body.light-theme .mes-filtro select    { background: #faf9f7; color: var(--text-primary); border-color: var(--border); }

/* Tabela */
body.light-theme .tabela-dados thead  { background: #ffffff; }
body.light-theme .tabela-dados th     { color: var(--text-muted); border-bottom-color: var(--border); background: #ffffff; }
body.light-theme .tabela-dados td     { color: var(--text-primary); border-bottom-color: var(--border); }
body.light-theme .tabela-header       { background: #ffffff; border-bottom-color: var(--border); }

/* Paginação */
body.light-theme .pag-btn             { background: #ffffff; color: var(--text-primary); border-color: var(--border); }
body.light-theme .pag-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

/* Sidebar */
body.light-theme .sidebar-section     { color: #9ca3a0; }
body.light-theme .sidebar-item        { color: #5a5852; }
body.light-theme .sidebar-item:hover  { background: #f5f4f0; color: var(--text-primary); }

/* Scrollbar no tema claro */
body.light-theme ::-webkit-scrollbar-thumb { background: #d1cec8; }
body.light-theme ::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* Input de data — ícone calendário */
body.light-theme input[type="date"]::-webkit-calendar-picker-indicator { filter: none; opacity: 0.5; }

/* Cabeçalho da tabela: hover usa rgba branco no dark, precisa de cinza no light */
body.light-theme .tabela-dados th:hover { background-color: rgba(0,0,0,.03); }

/* Active state do sidebar com verde (accent) no light */
body.light-theme .sidebar-item.active { background: rgba(22,163,74,.10); }

/* Form control (modal e páginas de formulário) */
body.light-theme .form-control { background: #faf9f7; color: var(--text-primary); border-color: var(--border); }
body.light-theme select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23555555'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
body.light-theme .form-group input,
body.light-theme .form-group select,
body.light-theme .form-group textarea { background: #faf9f7; color: var(--text-primary); border-color: var(--border); }

/* Modal inline — o fundo do card já usa var(--bg-card) que vira #fff no light */
/* Alertas no tema claro — cores legíveis sobre fundo branco */
body.light-theme .alert-success { background: rgba(22,163,74,.10);  color: #15803d; border-color: rgba(22,163,74,.3); }
body.light-theme .alert-error   { background: rgba(220,38,38,.10);  color: #dc2626; border-color: rgba(220,38,38,.3); }
body.light-theme .alert-warning { background: rgba(202,138,4,.10);  color: #b45309; border-color: rgba(202,138,4,.3); }
body.light-theme .alert-info    { background: rgba(37,99,235,.10);  color: #1d4ed8; border-color: rgba(37,99,235,.3); }

/* Badges — cores com contraste adequado no tema claro (fundo branco) */
body.light-theme .badge-avista     { color: #1d4ed8; background: rgba(29,78,216,.10); }
body.light-theme .badge-parcelado  { color: #c2410c; background: rgba(194,65,12,.10); }
body.light-theme .badge-pix        { color: #0e7490; background: rgba(14,116,144,.10); }
body.light-theme .badge-debito     { color: #6d28d9; background: rgba(109,40,217,.10); }

body.light-theme .badge-ajuste     { color: #0f766e; background: rgba(15,118,110,.10); }
body.light-theme .badge-salario    { color: #15803d; background: rgba(21,128,61,.10); }
body.light-theme .badge-bonus      { color: #1d4ed8; background: rgba(29,78,216,.10); }
body.light-theme .badge-outro      { color: #6d28d9; background: rgba(109,40,217,.10); }
body.light-theme .badge-success    { color: #15803d; background: rgba(21,128,61,.10); }
body.light-theme .badge-danger     { color: #dc2626; background: rgba(220,38,38,.10); }

/* ========================== SIDEBAR ========================== */
:root {
  --sidebar-w: 210px;
  --sidebar-w-collapsed: 54px;
  --topbar-h: 50px;
}

body.dark-theme,
body.light-theme {
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 300;
  transition: width 0.22s ease;
  overflow: visible;
}

/* Brand — clicável para toggle */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.sidebar-brand img { height: 26px; flex-shrink: 0; }

.sidebar-brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  transition: opacity 0.15s;
}

.sidebar-section {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #4b5563;
  padding: 16px 14px 5px;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 1px 8px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

.sidebar-item:hover { color: var(--text-primary); background: var(--bg-card); }
.sidebar-item.active { color: var(--accent); background: rgba(34,197,94,.10); font-weight: 600; }

.sidebar-icon {
  flex-shrink: 0;
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.sidebar-icon svg { width: 16px; height: 16px; stroke-width: 1.75; }
.sidebar-text { transition: opacity 0.15s; }
.sidebar-version { padding: 6px 16px 10px; font-size: 11px; color: var(--text-muted); opacity: 0.55; letter-spacing: 0.3px; user-select: none; }

/* ── Estado recolhido ── */
body.sidebar-collapsed .sidebar            { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar-brand-name { width: 0; overflow: hidden; opacity: 0; }
body.sidebar-collapsed .sidebar-brand      { gap: 0; justify-content: center; }
body.sidebar-collapsed .sidebar-section    { height: 0; padding: 0; overflow: hidden; opacity: 0; }
body.sidebar-collapsed .sidebar-text       { width: 0; overflow: hidden; opacity: 0; }
body.sidebar-collapsed .sidebar-item       { justify-content: center; margin: 1px 0; padding: 10px 0; gap: 0; border-radius: 0; }
body.sidebar-collapsed .sidebar-icon       { width: var(--sidebar-w-collapsed); text-align: center; }
body.sidebar-collapsed .topbar             { left: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .main-content       { margin-left: var(--sidebar-w-collapsed); }

/* Tooltip da sidebar recolhida — posicionado via JS no <body> */
#sidebar-tooltip {
  position: fixed;
  z-index: 9999;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
}
#sidebar-tooltip.visible { opacity: 1; }


/* ========================== TOPBAR ========================== */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 200;
  transition: left 0.22s ease;
}

.topbar-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }

/* ========================== BUTTONS ========================== */
.btn-primary {
  background-color: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background-color 0.2s, box-shadow 0.2s, transform 0.15s;
  white-space: nowrap;
}
.btn-primary:hover  { background-color: var(--accent-hover); box-shadow: var(--shadow-xs); }
.btn-primary:active { transform: translateY(1px); }

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
  transition: border-color 0.2s, color 0.2s;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.14);
  color: #f29188;
  border: 1px solid rgba(239, 68, 68, 0.38);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: background 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); border-color: var(--danger); color: #ffb3ab; }

.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ========================== MAIN CONTENT ========================== */
.main-content {
  margin-left: var(--sidebar-w);
  padding-top: calc(var(--topbar-h) + 28px);
  transition: margin-left 0.22s ease, opacity 0.18s ease;
  min-width: 0;
  flex: 1;
  padding-left: 24px;
  padding-right: 24px;
  padding-bottom: 24px;
}

/* ========================== FILTROS ========================== */
.filtros-form {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  padding: 16px 20px;
  display: inline-block;
  width: 100%;
}

.filtro-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 0 auto;
}

.filtro-group label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.filtro-group input,
.filtro-group select {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  padding: 7px 10px;
  font-size: 13px;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
.filtro-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239a9db5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

.filtro-group input:focus,
.filtro-group select:focus {
  outline: none;
  border-color: var(--accent);
}

/* Ícone do calendário branco */
input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
  opacity: 0.7;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Botões logo após os filtros */
.filtros-botoes {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex: 0 0 auto;
}

.filtros-botoes .btn-danger,
.filtros-botoes .btn-primary {
  padding: 0 18px;
  height: 35px;
  line-height: 35px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  padding: 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 3px solid var(--accent);
  min-width: 0;
}

/* ========================== TABELA ========================== */
.tabela-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.tabela-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  gap: 8px;
  text-align: center;
  color: var(--text-muted);
}
.tabela-empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}
.tabela-empty-state-text {
  font-size: 12px;
  font-weight: 500;
}

.tabela-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  max-height: 540px;
  overflow-y: auto;
}

.tabela-dados {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.tabela-dados thead {
  background-color: var(--bg-secondary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabela-dados th {
  padding: 10px 12px;
  text-align: center;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  background: var(--bg-secondary);
  transition: background-color 0.15s, color 0.15s;
}
.tabela-dados th:hover { background-color: rgba(255,255,255,0.04); color: var(--text-primary); }
.tabela-dados th:last-child,
.tabela-dados th:empty { cursor: default; }

.sort-icon {
  display: inline-block;
  margin-left: 5px;
  font-size: 9px;
  opacity: 0.3;
  vertical-align: middle;
  transition: opacity 0.15s, color 0.15s;
  font-style: normal;
}
.sort-icon.sort-ativo {
  opacity: 1;
  color: var(--accent);
}

.tabela-dados td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}

.tabela-dados tbody tr { transition: background-color 0.1s; }
.tabela-dados tbody tr:hover { background-color: var(--bg-elevated); }

/* Linha de total travada no fundo */
.tabela-dados tfoot {
  position: sticky;
  bottom: 0;
  z-index: 3;
}
.tabela-dados tfoot td {
  background: var(--bg-card);
  border-top: 2px solid var(--border) !important;
  border-bottom: none !important;
  box-shadow: 0 -1px 0 var(--border);
}
body.light-theme .tabela-dados tfoot td { background: #ffffff; }

/* Paginação */
.paginacao {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pag-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-xs);
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
  min-width: 34px;
}
.pag-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pag-btn:disabled { opacity: 0.35; cursor: default; }
.pag-btn.ativo { background-color: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }

/* ========================== SCROLLBAR ========================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }
::-webkit-scrollbar-corner { background: transparent; }

/* Regras de .alert ficam em app-extra.css (carregado depois, mesma especificidade — vencia
   silenciosamente e tornava este bloco morto; removido pra ter uma única fonte). */

/* ========================== RESPONSIVO — PAINEL CAIXINHA ========================== */

/* Desktop reduzido / tablet largo */
@media (max-width: 1024px) {
  .filtros-botoes      { margin-left: auto; }
}

/* Tablet / mobile largo */
@media (max-width: 768px) {
  /* Sidebar auto-recolhida no mobile (mesmo padrão visual do estado .sidebar-collapsed) */
  .sidebar             { width: var(--sidebar-w-collapsed); }
  .sidebar-brand-name,
  .sidebar-section,
  .sidebar-text        { width: 0; overflow: hidden; opacity: 0; }
  .sidebar-brand       { gap: 0; justify-content: center; }
  .sidebar-item        { justify-content: center; margin: 1px 0; padding: 10px 0; gap: 0; border-radius: 0; }
  .sidebar-icon        { width: var(--sidebar-w-collapsed); text-align: center; }
  .topbar              { left: var(--sidebar-w-collapsed); padding: 0 14px; }
  .main-content        { margin-left: var(--sidebar-w-collapsed); padding-left: 14px; padding-right: 14px; }

  /* Filtros — quebram em duas colunas */
  .filtros-form        { padding: 14px; }
  .filtro-group        { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filtro-group input,
  .filtro-group select { width: 100%; }
  .filtros-botoes      { flex: 1 1 100%; margin-left: 0; gap: 8px; }
  .filtros-botoes .btn-danger,
  .filtros-botoes .btn-primary { flex: 1; justify-content: center; padding: 0 10px; }

  .paginacao           { justify-content: center; flex-wrap: wrap; }
}

/* Mobile pequeno */
@media (max-width: 480px) {
  .main-content        { padding-left: 10px; padding-right: 10px; padding-bottom: 16px; }

  .filtro-group        { flex: 1 1 100%; }
  .filtros-botoes      { flex-direction: column; }
  .filtros-botoes .btn-danger,
  .filtros-botoes .btn-primary { width: 100%; }

  /* Topbar compacto */
  .topbar              { padding: 0 10px; gap: 6px; }
  .topbar-title        { font-size: 12px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Telas muito pequenas (≤360px): esconde botões da topbar */
@media (max-width: 360px) {
  .topbar > div:last-child { display: none; }
  .topbar-title            { max-width: none; }
  .main-content            { padding-left: 8px; padding-right: 8px; }
}

/* Reduz movimento para usuários com preferência de menos animação */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
