:root {
  --bg: #0b0d12;
  --panel: #12151d;
  --panel-2: #181c26;
  --line: #232937;
  --text: #e8eaf0;
  --muted: #8a90a2;
  --accent: #7c5cff;
  --accent-2: #a18bff;
  --ok: #3ddc97;
  --warn: #ffb547;
  --danger: #ff5c6c;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
a { color: var(--accent-2); }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 10px 0 0; }

.brand { font-weight: 800; font-size: 20px; letter-spacing: .3px; }
.brand span { color: var(--accent); }
.brand small { font-size: 12px; color: var(--muted); font-weight: 600; margin-left: 4px; }
.brand.big { font-size: 28px; text-align: center; margin-bottom: 20px; }

/* ---------- Login ---------- */
.center-view { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
  width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.qr { display: block; margin: 8px auto; border-radius: 8px; background: #fff; padding: 6px; image-rendering: pixelated; width: 200px; }

/* ---------- Form ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; font: inherit; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
button {
  font: inherit; cursor: pointer; border-radius: 9px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }
button.ghost { background: transparent; }
button.small { padding: 5px 10px; font-size: 12.5px; }
button.wide { width: 100%; padding: 11px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > label { flex: 1 1 150px; }
.grow { flex: 1 1 auto; }

/* ---------- Layout ---------- */
#app-view { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 22px 14px; display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 0 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { color: var(--text); text-decoration: none; padding: 9px 10px; border-radius: 9px; }
#nav a:hover { background: var(--panel-2); }
#nav a.active { background: color-mix(in srgb, var(--accent) 22%, transparent); color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; padding: 0 6px; }
main { padding: 28px 32px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 16px; margin: 0 0 12px; }
@media (max-width: 800px) {
  #app-view { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  main { padding: 20px 16px; }
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }

/* ---------- Painel ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12.5px; }
.stat.accent b { color: var(--accent-2); }
.stat.ok b { color: var(--ok); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 10px; }
.chart .bar { flex: 1; background: linear-gradient(var(--accent-2), var(--accent)); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.chart .bar:hover::after {
  content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: #000; padding: 4px 8px; border-radius: 6px; font-size: 11.5px; white-space: nowrap; margin-bottom: 4px;
}

/* ---------- Tabelas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid #1a1f2a; vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 26px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); }
.badge.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.accent { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-2); }

/* ---------- Detalhe do cliente ---------- */
.detail-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.detail-head h1 { margin: 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 20px; }
.kv div > span:first-child { display: block; color: var(--muted); font-size: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.big-time { font-size: 22px; font-weight: 800; }

/* ---------- Keys geradas ---------- */
.keys-out { width: 100%; min-height: 160px; }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { width: min(440px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.modal h3 { margin: 0 0 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; max-width: 420px;
}
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--ok); }
#release-form textarea { width: 100%; margin-bottom: 10px; }

/* Enquanto uma ação roda, nada de clique duplo. */
body.busy button { pointer-events: none; opacity: .6; }
