:root {
  --paper: #F1F4F2;
  --surface: #FFFFFF;
  --ink: #15272C;
  --muted: #5B6E72;
  --line: #D9E0DD;
  --side: #12262B;
  --side-ink: #C9D8D6;
  --teal: #0D6B6E;
  --teal-d: #094F52;
  --amber: #C4790A;
  --red: #B23A2E;
  --green: #2C7A4B;
  --radius: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Hanken Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
h1 { font-size: 24px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 32px 28px;
}
.login h1 { margin-bottom: 4px; }
.login .muted { margin-bottom: 22px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); padding: 22px 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { padding: 0 22px 20px; color: #fff; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--side-ink); opacity: .75; }
.side nav { flex: 1; overflow-y: auto; }
.side nav a {
  display: block; padding: 9px 22px; color: var(--side-ink); text-decoration: none;
  border-left: 3px solid transparent; font-weight: 500;
}
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { color: #fff; border-left-color: var(--amber); background: rgba(255,255,255,.08); }
.side .sair {
  margin: 12px 22px 0; background: none; border: 1px solid rgba(255,255,255,.25);
  color: var(--side-ink); padding: 8px; border-radius: var(--radius); cursor: pointer; font: inherit;
}
.side .sair:hover { color: #fff; border-color: #fff; }

main { padding: 28px 32px 60px; min-width: 0; max-width: 1200px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin-top: 2px; }

/* ---------- buttons & forms ---------- */
button, .btn { font: inherit; }
.btn {
  background: var(--teal); color: #fff; border: 1px solid var(--teal); border-radius: var(--radius);
  padding: 8px 14px; cursor: pointer; font-weight: 600;
}
.btn:hover { background: var(--teal-d); }
.btn.ghost { background: transparent; color: var(--teal); }
.btn.ghost:hover { background: rgba(13,107,110,.08); }
.btn:disabled { opacity: .6; cursor: wait; }
.link {
  background: none; border: 0; padding: 2px 4px; color: var(--teal); cursor: pointer; font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px;
}
.link.danger { color: var(--red); }

label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: #fff;
  border: 1px solid #B9C5C2; border-radius: var(--radius); padding: 8px 10px;
}
textarea { min-height: 80px; resize: vertical; }
input[type=checkbox] { width: auto; margin-right: 6px; }
.field { margin-bottom: 12px; }
.field.check label { display: flex; align-items: center; margin: 0; }
.err { color: var(--red); font-size: 14px; margin: 8px 0 0; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; color: var(--muted); font-weight: 500;
}
.tab.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.tab b { font-weight: 600; margin-left: 4px; opacity: .8; }

/* ---------- tables ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel.pad { padding: 18px 20px; }
.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #F8FAF9; white-space: nowrap; }
th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
td.acts { text-align: right; white-space: nowrap; }
.group { margin-bottom: 22px; }
.group h2 { display: flex; align-items: baseline; gap: 8px; }
.group h2 span { color: var(--muted); font-weight: 400; font-size: 14px; }
.empty { padding: 28px 20px; color: var(--muted); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  background: #E7ECEA; color: #3A4F54;
}
.badge.good { background: #DDEFE4; color: #1F5C39; }
.badge.warn { background: #F8E9CF; color: #7D4B05; }
.badge.bad { background: #F6DCD8; color: #8A2A20; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.kpi { padding: 16px 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; margin-top: 2px; }
.kpi .h { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi .v.neg { color: var(--red); }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; margin-bottom: 18px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; }
.chart .rec { fill: var(--teal); }
.chart .cus { fill: var(--amber); }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart line { stroke: var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.list .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.list .sub { color: var(--muted); font-size: 13px; }

/* ---------- dialog ---------- */
dialog.form {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 40px); color: var(--ink);
}
dialog.form::backdrop { background: rgba(18,38,43,.5); }
dialog.form form { padding: 22px 24px; }
dialog.form h2 { font-size: 18px; margin-bottom: 16px; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.fgrid .full { grid-column: 1 / -1; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: var(--radius); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }

/* ---------- responsivo ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 8px 0; overflow-x: auto; }
  .brand { padding: 0 14px; white-space: nowrap; }
  .brand small { display: none; }
  .side nav { display: flex; overflow: visible; flex: 1 0 auto; }
  .side nav a { white-space: nowrap; padding: 8px 12px; border-left: 0; border-bottom: 3px solid transparent; }
  .side nav a.on { border-bottom-color: var(--amber); }
  .side .sair { margin: 0 14px; white-space: nowrap; }
  main { padding: 20px 16px 48px; }
  .grid2 { grid-template-columns: 1fr; }
  .fgrid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

@media print {
  .side, #toast { display: none; }
}
