:root {
  --bg-main: #050816;
  --bg-sidebar: rgba(5, 12, 32, 0.92);
  --accent: #1a73e8;
  --accent-soft: rgba(26, 115, 232, 0.15);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --card-bg: rgba(15, 23, 42, 0.72);
  --border-soft: rgba(148, 163, 184, 0.3);
}

/* Tema claro */
[data-theme="light"] {
  --bg-main:     #f1f5f9;
  --bg-sidebar:  rgba(255, 255, 255, 0.92);
  --accent:      #1a73e8;
  --accent-soft: rgba(26, 115, 232, 0.12);
  --text-main:   #0f172a;
  --text-muted:  #64748b;
  --card-bg:     rgba(255, 255, 255, 0.82);
  --border-soft: rgba(100, 116, 139, 0.25);
}

/* Gradiente de fundo — tema claro */
[data-theme="light"] .bg-gradient {
  background:
    radial-gradient(circle at top left,    #93c5fd 0, transparent 50%),
    radial-gradient(circle at bottom right, #7dd3fc 0, transparent 55%),
    radial-gradient(circle at top right,   #86efac 0, transparent 50%);
  opacity: 0.35;
}

/* Login card — tema claro */
[data-theme="light"] .login-card {
  background: rgba(255,255,255,0.95);
  box-shadow: 0 18px 45px rgba(0,0,0,0.12);
}
[data-theme="light"] .login-input {
  background: rgba(241,245,249,0.9);
}

/* Select empresa — tema claro */
[data-theme="light"] .sel-empresa {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.18);
}
[data-theme="light"] .sel-empresa option {
  background: #ffffff;
  color: #0f172a;
}

/* Tabela — tema claro */
[data-theme="light"] th,
[data-theme="light"] td {
  border-bottom-color: rgba(100,116,139,0.2);
}

/* Loading overlay — tema claro */
[data-theme="light"] .loading-overlay {
  background: rgba(241,245,249,0.85);
}
[data-theme="light"] .loading-spinner {
  border-color: rgba(0,0,0,0.08);
  border-top-color: var(--accent);
}

/* Progress bar fundo — tema claro */
[data-theme="light"] .progress {
  background: rgba(100,116,139,0.15);
}

/* Menu sub bordas — tema claro */
[data-theme="light"] .menu-subsub,
[data-theme="light"] .menu-subsubsub {
  border-left-color: rgba(0,0,0,0.12);
}

/* Badges — tema claro */
[data-theme="light"] .badge-blue   { color: #1d4ed8; }
[data-theme="light"] .badge-yellow { color: #b45309; }
[data-theme="light"] .badge-gray   { color: #475569; }

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
}

/* Background gradient */
.bg-gradient {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, #1d4ed8 0, transparent 50%),
    radial-gradient(circle at bottom right, #0ea5e9 0, transparent 55%),
    radial-gradient(circle at top right, #22c55e 0, transparent 50%);
  opacity: 0.3;
  z-index: -2;
}

/* Glass panels */
.glass {
  background: var(--bg-sidebar);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid var(--border-soft);
}

.glass-soft {
  background: var(--card-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(148,163,184,0.35);
}

/* LOGIN */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  max-width: 380px;
  width: 100%;
  padding: 24px 22px 20px;
  border-radius: 18px;
  background: rgba(15,23,42,0.9);
  border: 1px solid var(--border-soft);
  box-shadow: 0 18px 45px rgba(15,23,42,0.8);
}

.login-card-header {
  text-align: center;
  margin-bottom: 18px;
}

.login-logo {
  max-width: 150px;
  max-height: 60px;
  object-fit: contain;
  margin-bottom: 8px;
}

.login-title {
  margin: 0;
  font-size: 18px;
}

.login-subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

.login-form-group {
  margin-bottom: 12px;
}

.login-label {
  font-size: 12px;
  display: block;
  margin-bottom: 4px;
  color: var(--text-muted);
}

.login-input {
  width: 100%;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  padding: 9px 12px;
  background: rgba(15,23,42,0.9);
  color: var(--text-main);
  font-size: 13px;
}

.login-input::placeholder { color: var(--text-muted); }

.login-button {
  width: 100%;
  margin-top: 6px;
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  color: white;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(56,189,248,0.35);
}

.login-error {
  margin-top: 8px;
  font-size: 12px;
  color: #fb7185;
}

/* SIDEBAR */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  color: var(--text-main);
}

.logo-box {
  text-align: center;
  margin-bottom: 20px;
}

.logo {
  max-width: 150px;
  max-height: 60px;
  object-fit: contain;
  margin-bottom: 8px;
}

.logo-box h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.04em;
}

.tagline {
  margin: 4px 0 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.logout-link {
  font-size: 12px;
  color: #ffcccc;
  text-decoration: none;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid rgba(251,113,133,0.3);
  transition: background 0.15s ease;
}

.logout-link:hover {
  background: rgba(251,113,133,0.15);
}

/* MENU */
.menu {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu a {
  padding: 9px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.menu a.active,
.menu a:hover {
  background: var(--accent-soft);
  color: var(--text-main);
  transform: translateX(2px);
}

/* MENU GROUPS */
.menu-item {
  padding: 9px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.menu-item.active,
.menu-item:hover {
  background: var(--accent-soft);
  color: var(--text-main);
  transform: translateX(2px);
}

.menu-group {
  display: flex;
  flex-direction: column;
}

.menu-group-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.menu-group-title:hover {
  background: var(--accent-soft);
  color: var(--text-main);
}

.menu-group.open .menu-group-title {
  color: var(--text-main);
}

.chevron {
  font-size: 16px;
  transition: transform 0.2s ease;
  display: inline-block;
}

.menu-group.open .chevron {
  transform: rotate(90deg);
}

.menu-sub {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}

.menu-group.open .menu-sub {
  max-height: 400px;
}

.menu-sub a {
  padding: 7px 10px 7px 28px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.menu-sub a.active,
.menu-sub a:hover {
  background: var(--accent-soft);
  color: var(--text-main);
  transform: translateX(2px);
}

/* META */
.meta {
  margin-top: auto;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta p {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-main);
}

.progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(15,23,42,0.9);
  overflow: hidden;
  margin-bottom: 4px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #a3e635);
}

/* CONTENT — layout correto */
.content {
  margin-left: 260px;
  width: calc(100% - 260px);
  padding: 20px 24px 24px;
  min-height: 100vh;
}

/* TOPBAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  margin-bottom: 20px;
  border-radius: 12px;
}

.topbar-empresa {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-codcli {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(26,115,232,0.3);
  letter-spacing: 0.06em;
}

.topbar-nome {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: 0.02em;
}

.sel-empresa {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 10px;
  cursor: pointer;
  outline: none;
  max-width: 260px;
}
.sel-empresa:hover { background: rgba(255,255,255,0.14); }
.sel-empresa option { background: #1e2235; color: #fff; }
select option { background: #1e2235; color: #fff; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-username {
  font-size: 13px;
  color: var(--text-muted);
}

/* LAYOUT 2 COLUNAS */
.layout-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* CONTAINER DE GRÁFICO — altura controlada */
.chart-wrap {
  position: relative;
  height: 200px;
}

/* ESPAÇAMENTO SUPERIOR */
.mt-20 { margin-top: 16px; }

/* LOADING OVERLAY */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(5, 8, 22, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* PAGE HEADER */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.page-header p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  font-size: 11px;
  color: var(--text-muted);
}
.badge-blue   { background: rgba(59,130,246,.15); border-color: rgba(59,130,246,.4); color: #93c5fd; }
.badge-yellow { background: rgba(234,179, 8,.15); border-color: rgba(234,179, 8,.4); color: #fde047; }
.badge-gray   { background: rgba(100,116,139,.15); border-color: rgba(100,116,139,.4); color: #94a3b8; }

/* KPI GRID — CORRIGIDO */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}

.kpi {
  padding: 14px;
  border-radius: 14px;
}

.kpi .label { font-size: 12px; color: var(--text-muted); }
.kpi .value { margin-top: 6px; font-size: 20px; font-weight: 600; }
.kpi .hint { margin-top: 4px; font-size: 11px; color: var(--text-muted); }

/* CARDS */
.card {
  padding: 16px;
  border-radius: 16px;
}

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

.card-header h2 {
  margin: 0;
  font-size: 15px;
}

.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(30,41,59,0.9);
}

th {
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
}

.text-right { text-align: right; }

/* RESPONSIVE */
@media (max-width: 960px) {

  .sidebar {
    position: fixed;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 18px;
    gap: 16px;
    border-bottom: 1px solid var(--border-soft);
    border-right: none;
  }

  .logo-box {
    display: flex;
    align-items: center;
    margin-bottom: 0;
  }

  .logo {
    max-width: 100px;
    margin-right: 8px;
  }

  .tagline { display: none; }

  .topbar-empresa { display: none; }

  .menu {
    flex-direction: row;
    margin-left: 16px;
    gap: 6px;
  }

  .menu a {
    font-size: 12px;
    padding: 6px 8px;
  }

  .meta { display: none; }

  .content {
    margin-left: 0;
    width: 100%;
    padding-top: 72px;
  }

  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }
}

/* --- Sisven Web: sub-grupo aninhado dentro de menu-sub --- */
.menu-subgroup { margin: 0; }
.menu-subgroup-title {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.4rem 0.5rem;
  color: inherit; font-size: 0.85rem; font-weight: 600;
  opacity: 0.75; border-radius: 6px;
  transition: opacity 0.2s;
}
.menu-subgroup-title:hover { opacity: 1; }
.menu-subsub {
  display: none;
  padding-left: 0.75rem;
  border-left: 2px solid rgba(255,255,255,0.15);
  margin-left: 0.5rem;
}
.menu-subgroup.open .menu-subsub { display: block; }
.menu-subgroup.open .menu-subgroup-title .chevron { transform: rotate(90deg); }
.menu-subgroup-title .chevron { transition: transform 0.2s; }

/* --- 3º nível: Bancos dentro de Financeiro --- */
.menu-subsubgroup { margin: 0; }
.menu-subsubgroup-title {
  width: 100%; background: none; border: none; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.35rem 0.5rem;
  color: inherit; font-size: 0.82rem; font-weight: 600;
  opacity: 0.70; border-radius: 6px;
  transition: opacity 0.2s;
}
.menu-subsubgroup-title:hover { opacity: 1; }
.menu-subsubsub {
  display: none;
  padding-left: 0.75rem;
  border-left: 2px solid rgba(255,255,255,0.10);
  margin-left: 0.5rem;
}
.menu-subsubgroup.open .menu-subsubsub { display: block; }
.menu-subsubgroup.open .menu-subsubgroup-title .chevron { transform: rotate(90deg); }
.menu-subsubgroup-title .chevron { transition: transform 0.2s; }
