:root {
  --bg: #f4f6fb; --surface: #fff; --surface-2: #f8fafc; --border: #e4e8f0; --text: #0f172a; --muted: #64748b;
  --primary: #4f46e5; --primary-600: #4338ca; --primary-soft: #eef0ff; --ok: #059669; --ok-soft: #d9f5ea;
  --warn: #d97706; --warn-soft: #fdf0d8; --err: #dc2626; --err-soft: #fde4e4; --info-soft: #e0efff; --info: #1d6fd8;
  --side: #0f172a; --side-text: #cbd5e1; --radius: 14px; --shadow: 0 1px 2px rgba(15,23,42,.05), 0 8px 24px rgba(15,23,42,.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
[data-theme=dark] {
  --bg: #0b1020; --surface: #131a2e; --surface-2: #19223a; --border: #24304d; --text: #e8edf8; --muted: #93a1bd;
  --primary: #818cf8; --primary-600: #6366f1; --primary-soft: #1e2547; --ok: #34d399; --ok-soft: #10332a;
  --warn: #fbbf24; --warn-soft: #3a2d10; --err: #f87171; --err-soft: #3d1717; --info: #60a5fa; --info-soft: #14284a;
  --side: #070b17; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
code, .mono { font-family: var(--mono); font-size: .88em; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }
.side { width: 256px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 14px; position: fixed; inset: 0 auto 0 0; z-index: 40; transition: transform .25s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; color: #fff; font-weight: 700; font-size: 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #8b5cf6); display: grid; place-items: center; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #94a3b8; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; color: var(--side-text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.4); }
.side-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.side-foot button { background: none; border: 0; text-align: left; display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--side-text); cursor: pointer; }
.side-foot button:hover { background: rgba(255,255,255,.06); color: #fff; }
.main { flex: 1; margin-left: 256px; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; }
.burger { background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(2,6,23,.55); z-index: 35; }
.content { padding: 28px clamp(16px, 3vw, 36px) 48px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; }
.page-head p { margin: 2px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card h3 { font-size: 15px; margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: 2fr 1fr; margin-bottom: 16px; }
.stat { padding: 18px; display: flex; gap: 14px; align-items: center; }
.stat .ico { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.stat .ico.ok { background: var(--ok-soft); color: var(--ok); } .stat .ico.err { background: var(--err-soft); color: var(--err); } .stat .ico.info { background: var(--info-soft); color: var(--info); }
.stat b { display: block; font-size: 26px; line-height: 1.1; } .stat span { color: var(--muted); font-size: 13px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; min-height: 40px; transition: .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--err); } .btn.danger:hover { background: var(--err-soft); }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.icon { padding: 0; width: 36px; min-height: 36px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: sp .7s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }

label.f { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-weight: 400; color: var(--text); min-height: 42px; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
textarea.input { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--muted); font-weight: 400; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px 16px; margin: 0 0 16px; min-width: 0; }
legend { padding: 0 8px; font-weight: 700; font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text); }
.switch input { appearance: none; width: 40px; height: 22px; border-radius: 99px; background: #cbd5e1; position: relative; cursor: pointer; transition: .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.switch input:checked { background: var(--ok); } .switch input:checked::after { transform: translateX(18px); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); } .badge.err { background: var(--err-soft); color: var(--err); }
.badge.warn { background: var(--warn-soft); color: var(--warn); } .badge.info { background: var(--info-soft); color: var(--info); } .badge.pri { background: var(--primary-soft); color: var(--primary); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar .input { flex: 1 1 160px; width: auto; max-width: 280px; }
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--surface-2); }
td .sub { color: var(--muted); font-size: 12.5px; }
td.act { white-space: nowrap; text-align: right; }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.pager { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 8px; }
.bar { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.bar i { display: block; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bar i.e { background: var(--err); border-radius: 0; }
.bar:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: #0f172a; color: #fff; font-size: 11px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; z-index: 2; }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.rank li div { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 4px; }
.rank .track { height: 6px; border-radius: 9px; background: var(--surface-2); overflow: hidden; } .rank .track i { display: block; height: 100%; background: var(--primary); border-radius: 9px; }

/* ---------- modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(2,6,23,.6); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; box-shadow: 0 24px 60px rgba(0,0,0,.35); display: flex; flex-direction: column; animation: up .2s; }
.modal.sm { max-width: 520px; } .modal.lg { max-width: 980px; }
@keyframes up { from { transform: translateY(14px); opacity: 0; } }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-h h2 { font-size: 18px; }
.modal-b { padding: 22px; }
.modal-f { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check input { margin-top: 3px; accent-color: var(--primary); }
.check b { display: block; font-size: 14px; } .check span { font-size: 12px; color: var(--muted); }
.param-row { display: grid; grid-template-columns: 1.3fr 1fr 1fr auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.param-row .req { display: flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; }
.tokenbox { display: flex; gap: 8px; align-items: stretch; }
.tokenbox code { flex: 1; word-break: break-all; padding: 12px; background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; }
pre.json { margin: 0; padding: 14px; background: #0b1220; color: #d6e2ff; border-radius: 12px; overflow: auto; max-height: 420px; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.alert { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 14px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.err { background: var(--err-soft); color: var(--err); } .alert.ok { background: var(--ok-soft); color: var(--ok); }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); padding: 4px; border-radius: 12px; gap: 2px; margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 7px 16px; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.url { display: flex; gap: 8px; align-items: center; }
.url code { flex: 1; overflow-x: auto; white-space: nowrap; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; border: 1px solid var(--border); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.3); animation: up .2s; border-left: 4px solid var(--ok); max-width: 380px; }
.toast.err { border-left-color: var(--err); }

/* ---------- login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, #6366f1 0%, transparent 60%), radial-gradient(900px 500px at 100% 110%, #8b5cf6 0%, transparent 55%), #0b1020; }
.login .card { width: 100%; max-width: 400px; padding: 32px 28px; }
.login .brand { color: var(--text); justify-content: center; flex-direction: column; text-align: center; padding-bottom: 22px; gap: 12px; }
.login .brand .logo { width: 56px; height: 56px; border-radius: 16px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.skeleton { height: 120px; border-radius: 14px; background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- responsivo ---------- */
@media (max-width: 960px) {
  .side { transform: translateX(-100%); }
  .shell.open .side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .shell.open .scrim { display: block; }
  .main { margin-left: 0; }
  .topbar { display: flex; }
  .two { grid-template-columns: 1fr; }
  .content { padding-top: 20px; }
}
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  .param-row { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--border); border-radius: 10px; }
  .param-row > :first-child { grid-column: 1 / -1; }
  .kv { grid-template-columns: 1fr; gap: 2px; } .kv dd { margin-bottom: 10px; }
  .overlay { padding: 0; } .modal, .modal.sm, .modal.lg { max-width: none; min-height: 100dvh; border-radius: 0; }
  .modal-f { border-radius: 0; position: sticky; bottom: 0; }
  .modal-f .btn { flex: 1; }
  .toolbar .input { max-width: none; }
  .page-head .actions, .page-head .actions .btn { width: 100%; }
  /* tabelas viram cartões */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.stack td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.stack td::before { content: attr(data-l); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex: none; }
  table.stack td.act { justify-content: flex-end; padding-top: 10px; flex-wrap: wrap; }
  table.stack td.act::before, table.stack td[data-l=""]::before { display: none; }
  table.stack td.main { display: block; text-align: left; font-size: 16px; } table.stack td.main::before { display: none; }
}
