*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0b1220;
  --bg-2: #0e1728;
  --elev: #121a2b;
  --surface: #161f32;
  --surface-2: #1b263c;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.28);
  --text: #e8eef7;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #12b981;
  --accent-2: #34d399;
  --accent-dim: rgba(18, 185, 129, 0.14);
  --danger: #f43f5e;
  --danger-dim: rgba(244, 63, 94, 0.14);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.14);
  --info: #38bdf8;
  --info-dim: rgba(56, 189, 248, 0.14);
  --shadow: 0 18px 50px rgba(2, 8, 20, 0.45);
  --radius: 16px;
  --radius-sm: 10px;
  --space-1: 6px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 18px;
  --space-6: 24px;
  --sidebar: 264px;
  --topbar: 64px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --display: "Outfit", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(18, 185, 129, 0.12), transparent 50%),
    radial-gradient(900px 420px at 100% 0%, rgba(56, 189, 248, 0.08), transparent 46%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #042016;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 700;
}
.skip-link:focus { left: 12px; top: 12px; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ok { color: var(--accent-2); }
.danger-text { color: #fb7185; }
.tabular { font-variant-numeric: tabular-nums; }

.app-boot {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.boot-card {
  text-align: center;
  color: var(--muted);
}
.logo-mark {
  display: block;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  object-fit: contain;
  border-radius: 10px;
}
.boot-card .logo-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 12px;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(18, 185, 129, 0.22);
}
.auth-brand-mobile {
  display: none;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.auth-brand .logo-mark {
  width: 44px;
  height: 44px;
}
.noscript {
  padding: 16px;
  text-align: center;
}

/* Auth / onboarding */
.auth-wrap {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
}
.auth-brand {
  padding: clamp(28px, 6vw, 72px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18, 185, 129, 0.08), transparent 42%);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-name {
  font-family: var(--display);
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 1.15rem;
}
.auth-brand h1 {
  font-family: var(--display);
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1.1;
  letter-spacing: -0.04em;
  max-width: 14ch;
  margin: 48px 0 16px;
}
.auth-brand p { color: var(--muted); max-width: 42ch; }
.kpi-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 36px;
  max-width: 460px;
}
.auth-panel {
  display: grid;
  place-items: center;
  padding: 24px 20px calc(24px + var(--safe-b));
}
.auth-card {
  width: min(420px, 100%);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card h2 {
  font-family: var(--display);
  font-size: 1.45rem;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}
.auth-card > p { color: var(--muted); margin-bottom: 20px; }
.auth-links {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.92rem;
  color: var(--muted);
}
.auth-links a { color: var(--accent-2); font-weight: 600; }
.auth-links a:hover { text-decoration: underline; }

/* App chrome */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100dvh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  background: rgba(14, 23, 40, 0.92);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 16px;
  backdrop-filter: blur(16px);
  z-index: 30;
}
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 22px;
  overflow: auto;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 550;
  border: 1px solid transparent;
}
.nav-item svg { flex: none; opacity: 0.9; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent-2);
  border-color: rgba(18, 185, 129, 0.25);
}
.nav-section {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 16px 12px 6px;
  font-weight: 700;
}
.sidebar-foot {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent-2);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-family: var(--display);
}
.user-chip small { display: block; color: var(--faint); font-size: 0.78rem; }

.app-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.topbar {
  min-height: var(--topbar);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.72);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  display: none;
  place-items: center;
}
.grow { flex: 1; min-width: 0; }
.empresa-switch,
.periodo-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.empresa-switch select,
.periodo-switch select,
.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-width: 0;
  width: 100%;
}
.empresa-switch select { max-width: 240px; }
.periodo-switch { flex-wrap: wrap; }
.periodo-switch input[type="date"] { width: auto; }
.banner {
  margin: 14px 18px 0;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--warn-dim);
  color: #fcd34d;
  font-size: 0.92rem;
}
.banner.error { background: var(--danger-dim); color: #fda4af; }
.banner.info { background: var(--info-dim); color: #7dd3fc; }
#conteudo {
  padding: 18px 18px calc(28px + var(--safe-b));
  flex: 1;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.page-header h1 {
  font-family: var(--display);
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 14px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: var(--line-strong); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #042016;
  border-color: transparent;
}
.btn-ghost { background: transparent; }
.btn-danger { background: var(--danger-dim); color: #fda4af; border-color: rgba(244, 63, 94, 0.3); }
.btn-ok { background: var(--accent-dim); color: var(--accent-2); border-color: rgba(18, 185, 129, 0.28); }
.btn-sm {
  padding: var(--space-1) 10px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.grid { display: grid; gap: var(--space-3); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.kpi {
  min-height: 108px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.kpi-label { color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.kpi-value {
  font-family: var(--display);
  font-size: clamp(1.35rem, 2.2vw, 1.8rem);
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}
.kpi-delta { font-size: 0.82rem; font-weight: 650; }
.kpi-delta.up { color: var(--accent-2); }
.kpi-delta.down { color: #fb7185; }
.chart-box {
  position: relative;
  height: 280px;
}
.chart-box canvas { width: 100% !important; height: 100% !important; }

.form-grid { display: grid; gap: 12px; }
.field { display: grid; gap: 6px; }
.field span { font-size: 0.84rem; color: var(--muted); font-weight: 600; }
.field textarea { min-height: 90px; resize: vertical; }
.help { font-size: 0.8rem; color: var(--faint); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
  white-space: nowrap;
}
th { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--muted);
}
.badge-previsto { background: var(--warn-dim); color: #fcd34d; }
.badge-recebido, .badge-pago { background: var(--accent-dim); color: var(--accent-2); }
.badge-suspensa { background: var(--danger-dim); color: #fda4af; }
.badge-ativa { background: var(--accent-dim); color: var(--accent-2); }

.empty-state {
  text-align: center;
  padding: 42px var(--space-4);
  color: var(--muted);
}
.empty-state h3 {
  font-family: var(--display);
  color: var(--text);
  margin: var(--space-2) 0 var(--space-1);
}
.empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: center;
  margin-top: var(--space-4);
}
.skeleton-stack {
  display: grid;
  gap: var(--space-3);
}
.skeleton-stack .skeleton.lg { height: 48px; }
.skeleton-kpi {
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: var(--space-3);
}
.skeleton-kpi .skeleton:last-child { height: 28px; }

.alert {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--danger-dim);
  color: #fecdd3;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
.alert.ok { background: var(--accent-dim); color: #bbf7d0; }
.alert.info { background: var(--info-dim); color: #bae6fd; }

.skeleton {
  background: linear-gradient(90deg, var(--surface), var(--surface-2), var(--surface));
  background-size: 180% 100%;
  animation: shine 1.2s ease infinite;
  border-radius: 10px;
  height: 18px;
}
@keyframes shine {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

.toast-root {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-b));
  z-index: 80;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 24px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
}
.toast-ok { border-color: rgba(18, 185, 129, 0.4); }
.toast-error { border-color: rgba(244, 63, 94, 0.45); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 16, 0.64);
  z-index: 70;
  display: grid;
  place-items: end center;
  padding: 16px;
}
.modal {
  width: min(520px, 100%);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal h3 { font-family: var(--display); margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 16, 0.5);
  z-index: 25;
}
.overlay.show { display: block; }

.mobile-nav {
  display: none;
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-brand { display: none; }
  .auth-brand-mobile { display: flex; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    height: 100dvh;
  }
  .sidebar.open { transform: none; }
  .icon-btn { display: grid; }
  .empresa-switch select { max-width: 160px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  /* KPIs 2×2 no mobile */
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #conteudo { padding-bottom: calc(88px + var(--safe-b)); }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 24;
    background: rgba(14, 23, 40, 0.96);
    border-top: 1px solid var(--line);
    padding: 8px 6px calc(8px + var(--safe-b));
  }
  .mobile-nav a {
    display: grid;
    place-items: center;
    gap: 4px;
    font-size: 0.68rem;
    color: var(--muted);
    font-weight: 650;
    padding: 6px 2px;
  }
  .mobile-nav a.active { color: var(--accent-2); }
  .modal-backdrop { place-items: end center; }
}

.badge-realizado { background: var(--accent-dim); color: var(--accent-2); }
.flow-list { display: grid; gap: 8px; }
.flow-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--elev);
}
.flow-row.in { border-color: rgba(18, 185, 129, 0.28); }
.flow-row.out { border-color: rgba(244, 63, 94, 0.22); }
.flow-row .num { font-variant-numeric: tabular-nums; font-weight: 700; }
.flow-row.in .num { color: var(--accent-2); }
.flow-row.out .num { color: #fb7185; }
.saldo-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px 0;
  font-weight: 700;
}

@media (max-width: 520px) {
  .topbar { padding: 10px 12px; }
  #conteudo { padding-left: 12px; padding-right: 12px; }
  .auth-card { padding: 22px 16px; }
  .flow-row { grid-template-columns: 1fr; gap: 4px; }
}
