:root {
  --ui-bg: #0b1220;
  --ui-surface: #111a2c;
  --ui-surface-2: #16233a;
  --ui-surface-3: #0f1a30;
  --ui-text: #ecf2ff;
  --ui-muted: #9fb0cf;
  --ui-border: #243756;
  --ui-accent: #3b82f6;
  --ui-accent-2: #2563eb;
  --ui-success: #22c55e;
  --ui-danger: #ef4444;
  --ui-warning: #f59e0b;
  --ui-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
  --ui-radius: 14px;
}

body.light {
  --ui-bg: #0b1220;
  --ui-surface: #111a2c;
  --ui-surface-2: #16233a;
  --ui-surface-3: #0f1a30;
  --ui-text: #ecf2ff;
  --ui-muted: #9fb0cf;
  --ui-border: #243756;
  --ui-shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  color: var(--ui-text);
  background: radial-gradient(1200px 700px at -10% -10%, rgba(59, 130, 246, 0.18) 0%, transparent 52%),
              radial-gradient(900px 520px at 110% -10%, rgba(14, 165, 233, 0.12) 0%, transparent 46%),
              var(--ui-bg);
}

.topnav {
  background: linear-gradient(180deg, rgba(7, 12, 24, 0.98) 0%, rgba(8, 14, 28, 0.92) 100%) !important;
  border-bottom: 1px solid var(--ui-border) !important;
  backdrop-filter: blur(8px);
}

body.light .topnav {
  background: linear-gradient(180deg, rgba(7, 12, 24, 0.98) 0%, rgba(8, 14, 28, 0.92) 100%) !important;
}

.topnav-inner {
  max-width: 1280px !important;
  gap: 18px !important;
}

.topnav-links {
  gap: 18px !important;
}

.topnav-link {
  color: var(--ui-muted) !important;
  font-weight: 600 !important;
  font-size: 13px !important;
  padding: 8px 0;
  border-bottom: 2px solid transparent;
}

.topnav-link:hover,
.topnav-link.active {
  color: var(--ui-text) !important;
  border-bottom-color: var(--ui-accent);
  text-shadow: none !important;
}

.topnav-logo {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  min-height: 34px !important;
  max-width: 34px !important;
  max-height: 34px !important;
  flex: 0 0 34px !important;
  display: block !important;
  border-radius: 50% !important;
  background: transparent !important;
  border: 0 !important;
  color: transparent !important;
  font-size: 0 !important;
  line-height: 0 !important;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.topnav-logo img {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
  min-height: 34px !important;
  max-width: 34px !important;
  max-height: 34px !important;
  display: block !important;
  object-fit: cover !important;
  border-radius: 50% !important;
}

.topnav-right {
  gap: 8px !important;
}

.user-chip {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(96, 165, 250, 0.28);
  border-radius: 999px;
  padding: 6px 10px;
}

body.light .user-chip {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(96, 165, 250, 0.28);
}

.logout-nav {
  background: linear-gradient(180deg, #f43f5e, #e11d48) !important;
  border-radius: 10px !important;
  padding: 8px 12px !important;
  box-shadow: 0 10px 20px rgba(225, 29, 72, 0.25);
}

.theme-toggle,
#themeToggle,
button#themeToggle,
.theme-toggle::after,
#themeToggle::after {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}
.mobile-nav,
input,
select,
button,
textarea {
  border-radius: 10px !important;
}

input,
select,
textarea {
  background: var(--ui-surface-2) !important;
  border: 1px solid var(--ui-border) !important;
  color: var(--ui-text) !important;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #6ea8ff !important;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

button,
.btn,
.save,
.secondary {
  border: 0 !important;
  font-weight: 700 !important;
}

button,
.save {
  background: linear-gradient(180deg, var(--ui-accent), var(--ui-accent-2)) !important;
}

button.secondary,
.btn-download,
.btn-xls {
  background: linear-gradient(180deg, #22c55e, #16a34a) !important;
}

.card,
.panel {
  background: linear-gradient(180deg, var(--ui-surface), var(--ui-surface-2)) !important;
  border: 1px solid var(--ui-border) !important;
  border-radius: var(--ui-radius) !important;
  box-shadow: var(--ui-shadow) !important;
}

h1,
h2,
.label,
.nome {
  color: var(--ui-text) !important;
}

.sub,
.lbl,
.vbar-label,
.bar-sub,
.page-footer-inner,
th {
  color: var(--ui-muted) !important;
}

.summary,
.chip {
  gap: 8px !important;
}

.chip {
  background: rgba(59, 130, 246, 0.14) !important;
  color: #d5e6ff !important;
  border: 1px solid rgba(96, 165, 250, 0.22);
}

body.light .chip {
  background: rgba(59, 130, 246, 0.14) !important;
  color: #d5e6ff !important;
  border-color: rgba(96, 165, 250, 0.22);
}

.table-wrap {
  border-radius: 12px;
  border: 1px solid var(--ui-border);
}

table {
  min-width: 720px;
}

th,
td {
  border-bottom: 1px solid var(--ui-border) !important;
}

.bars,
.bar-chart,
.bar-chart-vertical {
  background: var(--ui-surface-3);
  border: 1px dashed var(--ui-border) !important;
  border-radius: 12px !important;
}

/* Force dark palette globally even if legacy scripts keep body.light */
body.light {
  --bg: #0f141c !important;
  --card: #141b26 !important;
  --text: #e8eef8 !important;
  --muted: #9aa9c2 !important;
  --blue: #2f7bde !important;
  --green: #21b58f !important;
  --teal: #28b6a8 !important;
  --orange: #e89219 !important;
  --red: #d5526d !important;
  --border: #283347 !important;
}

.page-footer {
  border-top: 1px solid var(--ui-border) !important;
  background: var(--ui-surface) !important;
}

.login-card,
.login-box,
form#loginForm {
  width: 100%;
}

/* Safe-area support (iOS notch / home indicator) */
body {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Mobile professional layout */
@media (max-width: 900px) {
  .container,
  .wrap {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .card,
  .panel {
    padding: 14px !important;
  }

  .grid,
  .cards,
  .grid-stack {
    grid-template-columns: 1fr !important;
  }

  .filters {
    grid-template-columns: 1fr !important;
  }

  .filters > * {
    min-width: 0;
  }

  .hero-metrics {
    grid-template-columns: 1fr !important;
  }

  .bars,
  .bar-chart,
  .bar-chart-vertical {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .bar-chart {
    overflow-x: auto;
  }

  .bar-wrap,
  .vbar-wrap {
    min-width: 0;
  }

  .page-footer-inner {
    text-align: center;
    padding: 0 10px;
  }

  h1 {
    font-size: clamp(22px, 6vw, 32px) !important;
  }

  /* Table horizontal scroll on mobile */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 560px;
  }
}
