:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --border: #e4e4e4;
  --text: #111111;
  --muted: #666666;
  --brand: #111111;
  --brand-strong: #000000;
  --brand-soft: #ebebeb;
  --on-brand: #ffffff;
  --sidebar-bg: #0c0c0c;
  --sidebar-text: #e9e9e9;
  --sidebar-muted: #8a8a8a;
  --sidebar-ativo: rgba(255, 255, 255, .12);
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --ok: #127a3a;
  --ok-soft: #e5f5ea;
  --info: #1d4ed8;
  --info-soft: #e8efff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sidebar: 232px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b;
    --surface: #151515;
    --surface-2: #1c1c1c;
    --border: #2b2b2b;
    --text: #efefef;
    --muted: #9a9a9a;
    --brand: #f2f2f2;
    --brand-strong: #ffffff;
    --brand-soft: #262626;
    --on-brand: #0b0b0b;
    --sidebar-bg: #000000;
    --danger: #f97066;
    --danger-soft: #3a1a18;
    --warn: #f5c451;
    --warn-soft: #3a2f12;
    --ok: #4ade80;
    --ok-soft: #13301f;
    --info: #7aa2ff;
    --info-soft: #172544;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--text); text-decoration: none; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 700; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 8px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-weight: 800;
}
.logo small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.ativo { background: var(--brand-soft); color: var(--brand-strong); }
.nav .grupo { margin: 14px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .rodape { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.sidebar .rodape .nome { font-weight: 600; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.topbar .titulo { flex: 1; min-width: 0; }
.conteudo { padding: 20px 24px 48px; max-width: 1280px; }
.menu-btn { display: none; }

/* ---------- Componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card .card-corpo { padding: 16px; }
.card + .card { margin-top: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primario { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primario:hover { background: var(--brand-strong); }
.btn.perigo { color: var(--danger); }
.btn.pequeno { padding: 5px 10px; font-size: 13px; }
.btn.link { border: none; background: none; color: var(--text); padding: 4px 6px; text-decoration: underline; text-underline-offset: 3px; }

.campo { display: flex; flex-direction: column; gap: 4px; }
.campo label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.grade { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.linha-acoes { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }

.filtros { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filtros .campo { min-width: 140px; }
.filtros .campo.largo { flex: 1; min-width: 200px; }

.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clicavel { cursor: pointer; }
tbody tr.clicavel:hover { background: var(--surface-2); }
.vazio { padding: 36px 16px; text-align: center; color: var(--muted); }

.selo {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.selo.ok { background: var(--ok-soft); color: var(--ok); }
.selo.aviso { background: var(--warn-soft); color: var(--warn); }
.selo.erro { background: var(--danger-soft); color: var(--danger); }
.selo.info { background: var(--info-soft); color: var(--info); }
.selo.marca { background: var(--brand-soft); color: var(--brand-strong); }

.resumo { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.resumo .card { padding: 14px 16px; }
.resumo .rotulo { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.resumo .valor { font-size: 22px; font-weight: 700; margin-top: 2px; }

.abas { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.abas button {
  background: none; border: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.abas button.ativo { color: var(--brand-strong); border-bottom-color: var(--brand); }

/* ---------- Modal ---------- */
.modal-fundo {
  position: fixed; inset: 0; background: rgba(10, 16, 22, .45); z-index: 50;
  display: grid; place-items: center; padding: 16px;
}
.modal {
  background: var(--surface); border-radius: 12px; width: 100%; max-width: 640px;
  max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal header h2 { margin: 0; }
.modal .modal-corpo { padding: 16px 20px 20px; }
.secao-titulo { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 16px 0 8px; }
.secao-titulo:first-child { margin-top: 0; }
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px;
  max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-weight: 500;
}
.toast.erro { background: var(--danger); color: #fff; }

/* ---------- Login ---------- */
.login-pagina { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-caixa { width: 100%; max-width: 380px; }
.login-caixa .logo { justify-content: center; padding-bottom: 20px; font-size: 18px; }
.login-caixa .card-corpo { padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.erro-msg { background: var(--danger-soft); color: var(--danger); padding: 8px 12px; border-radius: 8px; font-weight: 500; }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s;
  }
  .shell.menu-aberto .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .conteudo { padding: 16px; }
  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
  .esconder-celular { display: none; }
}

/* ---------- Ajustes ---------- */
.btn.menu-btn { display: none; padding: 6px 8px; }
.btn.menu-btn svg { width: 20px; height: 20px; }
.resumo .card + .card { margin-top: 0; }
@media (max-width: 860px) {
  .btn.menu-btn { display: inline-flex; }
  .resumo { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .resumo .card { padding: 10px 12px; }
  .resumo .valor { font-size: 16px; }
  .resumo .rotulo { font-size: 11.5px; }
  .filtros .campo { min-width: 0; flex: 1 1 130px; }
}
@media (max-width: 860px) {
  th, td { padding: 9px 10px; }
  .shell.menu-aberto .main { filter: brightness(.6); }
}

/* ---------- Identidade Grupo Facilita (preto e branco) ---------- */
.sidebar { background: var(--sidebar-bg); border-right-color: var(--sidebar-bg); color: var(--sidebar-text); }
.sidebar .logo { justify-content: center; padding: 8px 8px 20px; }
.sidebar .logo img { width: 150px; height: auto; display: block; }
.sidebar .nav a { color: var(--sidebar-text); }
.sidebar .nav a:hover { background: rgba(255, 255, 255, .07); }
.sidebar .nav a.ativo { background: var(--sidebar-ativo); color: #fff; }
.sidebar .nav .grupo { color: var(--sidebar-muted); }
.sidebar .rodape { border-top-color: rgba(255, 255, 255, .12); }
.sidebar .rodape .muted { color: var(--sidebar-muted); }
.sidebar .btn.link { color: var(--sidebar-text); }
.login-pagina { background: #0c0c0c; }
.login-caixa .logo { flex-direction: column; padding-bottom: 24px; }
.login-caixa .logo img { width: 210px; height: auto; }
.selo.marca { background: var(--brand-soft); color: var(--text); }
.abas button.ativo { color: var(--text); border-bottom-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--text); }
