:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #1b221e;
  --ink-2: #4a544e;
  --muted: #7a847e;
  --line: #e3e6e1;
  --line-2: #eef0ec;
  --brand: #0b7a5a;
  --brand-ink: #ffffff;
  --brand-soft: #e3f2ec;
  --ok: #127a3e;
  --ok-soft: #e4f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --side: #13201a;
  --side-ink: #cfd9d3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 4px 16px rgba(16, 24, 20, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.hide { display: none !important; }
.nowrap { white-space: nowrap; }
::placeholder { color: #b3bab5; }
.head h1 { overflow-wrap: anywhere; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; font-size: 14px; }
.side a { color: var(--side-ink); padding: 9px 10px; border-radius: 7px; display: flex; align-items: center; justify-content: space-between; }
.side a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side a.on { background: rgba(255,255,255,.1); color: #fff; font-weight: 600; }
.side .spacer { flex: 1; }
.side .user { font-size: 12px; padding: 8px 10px; color: #8fa39a; }
.badge { background: #e8a33a; color: #2a1a00; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; }
.main { padding: 24px 28px 48px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head .tools { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.menu-btn { display: none; flex: 0 0 auto !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
}

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .g2 { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .kpi .value { font-size: 20px; } .card { padding: 14px; } .table-wrap { margin: -4px -14px -14px; } }
.stack { display: flex; flex-direction: column; gap: 16px; }

.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink); padding: 8px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: var(--card); color: var(--ink); border-color: var(--line); font-weight: 500; }
button.ghost:hover { border-color: #cfd4cd; filter: none; }
button.danger { background: var(--card); color: var(--bad); border-color: #efc9c5; font-weight: 500; }
button.sm { padding: 4px 10px; font-size: 13px; }
button.link { background: none; border: 0; color: var(--brand); padding: 0; font-weight: 600; }

input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); border-color: var(--brand); }
input.inline { width: 90px; padding: 5px 8px; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 12px 0 5px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 14px; color: var(--ink); margin: 14px 0 0; }
.check input { width: auto; }

.table-wrap { overflow-x: auto; margin: -4px -18px -18px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: #fafbf9; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fafbf9; }
tr.sub td { background: #fafbf9; padding-top: 4px; }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 6px; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #b5bcb7; display: inline-block; }
.dot.on { background: #1f9d55; box-shadow: 0 0 0 3px rgba(31,157,85,.15); }

.alert { border-radius: var(--radius); padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.alert.warn { background: var(--warn-soft); color: #6b4000; border: 1px solid #f2d9a8; }
.alert.info { background: var(--brand-soft); color: #0a5a43; border: 1px solid #c2e3d6; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 10px 12px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--brand); }

.bar { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.list-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: 0; }
.list-row .bar { grid-column: 1 / -1; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { background: none; border: 0; border-radius: 0; color: var(--ink-2); font-weight: 500; padding: 7px 12px; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 700; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.token { font-family: ui-monospace, Consolas, monospace; background: var(--line-2); padding: 8px 10px; border-radius: 7px; word-break: break-all; font-size: 13px; }

/* ---------- modal e avisos ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 22, 18, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 12px; width: min(480px, 100%); max-height: 90vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(720px, 100%); }
.modal h2 { font-size: 17px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 1em; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--side); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 360px; }
.toast.bad { background: var(--bad); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(360px, 100%); padding: 28px; }
.login .brand { color: var(--ink); padding: 0 0 18px; }
.login button { width: 100%; justify-content: center; margin-top: 18px; padding: 10px; }
