:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e3e7ee;
  --brand: #2456e8;
  --brand-ink: #ffffff;
  --side: #121a2b;
  --side-ink: #c9d1e3;
  --ok: #157f4a;
  --ok-bg: #e5f6ec;
  --err: #b42318;
  --err-bg: #fdecea;
  --warn: #9a5b00;
  --warn-bg: #fff4dc;
  --radius: 10px;
}
.area-master { --brand: #7c3aed; --side: #1a1030; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }

/* ---------- Estrutura ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 240px;
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; z-index: 20;
  transition: transform .2s;
}
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1rem; }
.brand strong { display: block; color: #fff; font-size: .98rem; }
.brand small { display: block; color: inherit; opacity: .75; font-size: .8rem; }
.logo {
  width: 38px; height: 38px; border-radius: 9px; flex: none;
  display: grid; place-items: center; font-weight: 800;
  background: var(--brand); color: #fff;
}
.sidebar nav { flex: 1; padding: .5rem; overflow-y: auto; }
.sidebar nav a {
  display: block; padding: .6rem .8rem; border-radius: 8px;
  color: var(--side-ink); margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; }
.me { padding: 1rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.me span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me .link { color: #fff; }

main { margin-left: 240px; padding: 1.25rem 1.75rem 3rem; max-width: 1400px; }
.topbar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topbar h1 { flex: 1; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.burger { display: none; font-size: 1.4rem; cursor: pointer; }
.backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  #menu-toggle:checked ~ .sidebar { transform: none; }
  #menu-toggle:checked ~ .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; }
  main { margin-left: 0; padding: 1rem; }
  .burger { display: block; }
}

/* ---------- Componentes ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.25rem;
}
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1.25rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert b { color: var(--err); }

.btn, button {
  font: inherit; cursor: pointer; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink);
  padding: .5rem .95rem; border-radius: 8px; display: inline-block; line-height: 1.3;
}
.btn:hover, button:hover { filter: brightness(1.08); text-decoration: none; }
.btn-light { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-danger, button.danger { background: var(--err); color: #fff; }
.btn-sm, button.sm { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0; color: var(--brand); }
button.link.danger { color: var(--err); background: none; }

.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-erro { background: var(--err-bg); color: var(--err); }
.flash-aviso { background: var(--warn-bg); color: var(--warn); }

/* ---------- Formulários ---------- */
form.stack > * + * { margin-top: .85rem; }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
label.check { display: flex; gap: .45rem; align-items: center; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search],
input[type=number], select, textarea {
  width: 100%; font: inherit; color: inherit;
  padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }
.row { display: grid; gap: .85rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.hint { font-size: .82rem; color: var(--muted); margin-top: .2rem; }

.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters > * { flex: 1 1 160px; }
.filters > .btn, .filters > button { flex: 0 0 auto; }

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.acts { white-space: nowrap; text-align: right; }
td.acts form { display: inline; }
td.acts > * + * { margin-left: .5rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef1f6; color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.low { color: var(--err); font-weight: 700; }
.pos { color: var(--ok); }
.neg { color: var(--err); }

.pager { display: flex; gap: 1rem; justify-content: center; align-items: center; margin-top: 1rem; }

details summary { cursor: pointer; color: var(--brand); }
details[open] summary { margin-bottom: .6rem; }

/* ---------- Login ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 1rem; background: var(--side); }
.auth-box { width: 100%; max-width: 400px; background: #fff; border-radius: 14px; padding: 1.75rem; }
.auth-box .brand { padding: 0 0 1rem; }
.auth-box .brand strong { color: var(--ink); }
.auth-box .brand small { color: var(--muted); opacity: 1; }
.auth-box h1 { margin-bottom: 1rem; }
.auth-box button { width: 100%; padding: .65rem; }
