:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e4e6eb;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #8a909c;
  --brand: #2a78d6;
  --brand-ink: #1c5cab;
  --brand-soft: #e8f1fc;
  --side-bg: #0e1726;
  --side-text: #c9d1de;
  --side-muted: #7d8899;
  --side-active: #1b2a42;
  --ok: #0a7d32;
  --ok-soft: #e4f5ea;
  --bad: #c0362f;
  --bad-soft: #fcebea;
  --warn: #9a6300;
  --warn-soft: #fff4dc;
  --series: #2a78d6;
  --series-hover: #1c5cab;
  --grid: #eceef2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #1e222a;
    --border: #2a2f39;
    --text: #eef0f3;
    --text-2: #b6bcc7;
    --muted: #7f8794;
    --brand: #3987e5;
    --brand-ink: #86b6ef;
    --brand-soft: #182739;
    --side-bg: #0a0d12;
    --side-active: #18202d;
    --ok: #4cc276;
    --ok-soft: #13291c;
    --bad: #ef7470;
    --bad-soft: #321716;
    --warn: #f0b84a;
    --warn-soft: #30250f;
    --series: #3987e5;
    --series-hover: #86b6ef;
    --grid: #262a33;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #181b21;
  --surface-2: #1e222a;
  --border: #2a2f39;
  --text: #eef0f3;
  --text-2: #b6bcc7;
  --muted: #7f8794;
  --brand: #3987e5;
  --brand-ink: #86b6ef;
  --brand-soft: #182739;
  --side-bg: #0a0d12;
  --side-active: #18202d;
  --ok: #4cc276;
  --ok-soft: #13291c;
  --bad: #ef7470;
  --bad-soft: #321716;
  --warn: #f0b84a;
  --warn-soft: #30250f;
  --series: #3987e5;
  --series-hover: #86b6ef;
  --grid: #262a33;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); }
.num { font-variant-numeric: tabular-nums; }

/* ── Layout ─────────────────────────────────────── */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.side {
  background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; padding: 22px 14px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; color: #fff; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.logo-mark {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3987e5, #1c5cab); box-shadow: 0 4px 14px rgba(57, 135, 229, .35);
}
.logo small { display: block; font-weight: 500; font-size: 11px; color: var(--side-muted); letter-spacing: .02em; }
.side-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); padding: 14px 10px 8px; }
.side nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.side nav a {
  display: flex; align-items: center; gap: 10px; color: var(--side-text);
  padding: 9px 10px; border-radius: 9px; font-weight: 500;
}
.side nav a:hover { background: var(--side-active); color: #fff; }
.side nav a.ativo { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 #3987e5; }
.side nav a .ini {
  flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: #22324b; color: #b7d3f6; font-size: 12px; font-weight: 700;
}
.side nav a span.nome { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { margin-top: auto; border-top: 1px solid #1d2636; padding: 14px 10px 0; font-size: 13px; }
.side-foot .quem { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot .doc { color: var(--side-muted); font-size: 12px; }
.side-foot button {
  margin-top: 10px; width: 100%; background: transparent; border: 1px solid #2a3547; color: var(--side-text);
  padding: 8px; border-radius: 9px; font: inherit; cursor: pointer;
}
.side-foot button:hover { background: var(--side-active); color: #fff; }

.main { min-width: 0; padding: 28px 32px 48px; }
.topo { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--brand); }
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.sub { color: var(--text-2); margin-top: 4px; }
.acoes { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Botões ─────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; border-radius: 10px; padding: 9px 14px;
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); white-space: nowrap; box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn-primario { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primario:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; box-shadow: none; }
.btn svg { width: 16px; height: 16px; }

/* ── Cards / KPIs ───────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; flex-wrap: wrap; }
.card-h p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.card-b { padding: 16px 20px 20px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 16px; }
.kpi { padding: 18px 20px; }
.kpi .rot { color: var(--text-2); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; line-height: 1.15; }
.kpi .det { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.kpi.hero { background: linear-gradient(135deg, #1c5cab 0%, #2a78d6 60%, #3987e5 100%); border: 0; color: #fff; }
.kpi.hero .rot, .kpi.hero .det { color: rgba(255, 255, 255, .82); }
.duas { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); margin-bottom: 16px; }
.meia { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 16px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.neutro { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.kpi.hero .chip { background: rgba(255, 255, 255, .18); color: #fff; }

/* ── Gráfico de barras ──────────────────────────── */
.chart { position: relative; height: 240px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid-l { stroke: var(--grid); stroke-width: 1; }
.chart .eixo { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .bar { fill: var(--series); transition: fill .12s; }
.chart .bar.ativo { fill: var(--series-hover); }
.chart .hit { fill: transparent; cursor: pointer; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--text); color: var(--surface);
  padding: 8px 10px; border-radius: 9px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18); opacity: 0; transition: opacity .1s;
}
.tip b { display: block; font-size: 13.5px; }
.tip.vis { opacity: 1; }

/* ── Barras horizontais (pagamento / CFOP) ──────── */
.hbars { display: flex; flex-direction: column; gap: 14px; }
.hbar .lin { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.hbar .lin span:first-child { font-weight: 600; }
.hbar .lin span:last-child { color: var(--text-2); }
.hbar .trilho { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.hbar .enc { height: 100%; background: var(--series); border-radius: 999px; }

/* ── Tabelas ────────────────────────────────────── */
.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
td.r, th.r { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.chave { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; color: var(--text-2); }
.mes-link { font-weight: 600; color: var(--text); }
.mes-link:hover { color: var(--brand); }
.vazio { padding: 48px 20px; text-align: center; color: var(--muted); }
.vazio svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }

/* ── Filtros ────────────────────────────────────── */
.filtros { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filtros input, .filtros select {
  font: inherit; font-size: 13px; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-width: 0;
}
.filtros input[type=search] { width: 240px; }
.filtros input:focus, .filtros select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.paginacao { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }

/* ── Impostos / saltos ──────────────────────────── */
.impostos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 20px; }
.impostos div { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 6px 0; font-size: 13px; }
.impostos div span:first-child { color: var(--text-2); }
.impostos div span:last-child { font-weight: 600; }
.saltos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.saltos span { background: var(--warn-soft); color: var(--warn); border-radius: 7px; padding: 2px 8px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.aviso { display: flex; gap: 10px; padding: 12px 14px; border-radius: 10px; font-size: 13px; }
.aviso.ok { background: var(--ok-soft); color: var(--ok); }
.aviso svg { flex: none; width: 18px; height: 18px; margin-top: 1px; }

/* ── Painel de empresas ─────────────────────────── */
.empresas { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.emp-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; color: var(--text); transition: border-color .12s, transform .12s; }
.emp-card:hover { border-color: var(--brand); transform: translateY(-2px); color: var(--text); }
.emp-top { display: flex; gap: 12px; align-items: center; }
.emp-top .ini { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; flex: none; }
.emp-top b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emp-top small { color: var(--muted); }
.emp-num { display: flex; justify-content: space-between; align-items: flex-end; border-top: 1px solid var(--border); padding-top: 14px; }
.emp-num .v { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.emp-num small { color: var(--muted); display: block; font-size: 12px; }

.msgs { margin-bottom: 16px; }
.msgs div { padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-weight: 500; }

/* ── Login ──────────────────────────────────────── */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-arte {
  background: radial-gradient(1200px 600px at -10% 110%, #2a78d6 0%, transparent 55%),
              radial-gradient(800px 500px at 110% -10%, #1c5cab 0%, transparent 60%), #0b1424;
  color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.login-arte h2 { font-size: 36px; line-height: 1.15; letter-spacing: -.03em; max-width: 470px; margin: 0 0 16px; }
.login-arte p { color: #b7c3d6; max-width: 430px; font-size: 15px; margin: 0; }
.login-arte ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.login-arte li { display: flex; gap: 10px; align-items: center; color: #dbe4f1; }
.login-arte li i { width: 26px; height: 26px; border-radius: 8px; background: rgba(255, 255, 255, .1); display: grid; place-items: center; font-style: normal; font-size: 13px; }
.folhas { position: absolute; right: -40px; bottom: 90px; width: 300px; opacity: .9; }
.folha { position: absolute; width: 190px; height: 120px; border-radius: 14px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .14); backdrop-filter: blur(6px); padding: 14px; font-size: 11px; color: #cfdaea; }
.folha b { display: block; font-size: 18px; color: #fff; margin-top: 6px; }
.folha .barras { display: flex; gap: 4px; align-items: flex-end; height: 34px; margin-top: 8px; }
.folha .barras i { flex: 1; background: #86b6ef; border-radius: 3px 3px 0 0; }
.login-form { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.login-form form { width: 100%; max-width: 380px; }
.login-form h1 { font-size: 26px; }
.campo { margin-top: 18px; }
.campo label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.campo input {
  width: 100%; font: inherit; font-size: 15px; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
.campo input:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); background: var(--surface); }
.erro { margin-top: 16px; background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: 13px; }
.login-form .btn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 22px; }
.login-form .rodape { margin-top: 26px; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ── Responsivo ─────────────────────────────────── */
.menu-btn { display: none; }
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .duas, .meia { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  body.menu-aberto .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); }
  .menu-btn { display: inline-flex; margin-bottom: 14px; }
  .main { padding: 18px 16px 40px; }
  .login { grid-template-columns: 1fr; }
  .login-arte { display: none; }
  .filtros input[type=search] { width: 100%; }
  .filtros { width: 100%; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .impostos { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 22px; }
}

/* ── Tema / perfil ──────────────────────────────── */
.tema-btn {
  display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 10px; background: transparent;
  border: 1px solid #2a3547; color: var(--side-text); padding: 8px 10px; border-radius: 9px; font: inherit; cursor: pointer;
}
.tema-btn:hover { background: var(--side-active); color: #fff; }
.tema-btn svg { width: 16px; height: 16px; flex: none; }
.tema-btn .lua, :root[data-theme="dark"] .tema-btn .sol { display: none; }
:root[data-theme="dark"] .tema-btn .lua { display: inline; }
.login-tema { position: absolute; top: 16px; right: 16px; width: auto; color: var(--text-2); border-color: var(--border); background: var(--surface); }
.login-tema:hover { color: var(--brand); background: var(--surface-2); }
.login-form { position: relative; }
.side-foot a.perfil-link { display: block; color: inherit; border-radius: 9px; padding: 6px 8px; margin: -6px -8px 0; }
.side-foot a.perfil-link:hover { background: var(--side-active); }
.side-foot a.perfil-link.ativo { background: var(--side-active); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .campo { margin-top: 14px; }
.campo .ajuda { color: var(--muted); font-size: 12px; margin-top: 4px; }
.campo .erro-campo { color: var(--bad); font-size: 12px; margin-top: 4px; }
.campo input[readonly] { color: var(--text-2); cursor: not-allowed; }
.lista-emp { display: flex; flex-direction: column; }
.lista-emp a { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); color: var(--text); }
.lista-emp a:last-child { border-bottom: 0; }
.lista-emp a:hover b { color: var(--brand); }
.lista-emp .ini { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; font-size: 12px; flex: none; }
.lista-emp small { display: block; color: var(--muted); }
.ok-msg { margin-top: 14px; background: var(--ok-soft); color: var(--ok); padding: 10px 12px; border-radius: 10px; font-weight: 500; font-size: 13px; }
.perfil-topo { display: flex; align-items: center; gap: 16px; }
.avatar { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-weight: 700; font-size: 20px; color: #fff; background: linear-gradient(135deg, #1c5cab, #3987e5); flex: none; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
