:root {
  --bg: #0f1220;
  --bg-2: #151a2e;
  --panel: #1a2038;
  --panel-2: #20284a;
  --line: #2b3560;
  --text: #e7eaf6;
  --muted: #9aa3c7;
  --accent: #6c8cff;
  --accent-2: #8f6cff;
  --ok: #2fbf71;
  --warn: #f2a93b;
  --bad: #ef5a6f;
  --test: #ff3b3b;
  --block: #b06cff;
  --gray: #7d86a8;
  --info: #3bb3f2;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
button, input, select, textarea { font: inherit; color: inherit; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; }

/* ===== Layout ===== */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: 20px;
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
.ws-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.ws-select { width: 100%; }
.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-item {
  text-align: left; background: transparent; border: 0; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; color: var(--muted);
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; }
.conn { font-size: 12px; color: var(--ok); }
.conn.http { color: var(--info); }
.conn.err { color: var(--bad); }

.main { padding: 18px 26px 60px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.topbar h1 { margin: 0; font-size: 22px; }

.admin-banner {
  background: rgba(242, 169, 59, .1); border: 1px solid rgba(242, 169, 59, .35);
  color: #f6d49d; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 13px;
}

.view { display: none; }
.view.active { display: block; }

/* ===== Inputs / botões ===== */
input, select, textarea {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(239, 90, 111, .15); border-color: rgba(239, 90, 111, .5); color: #ffb3bd; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: transparent; border: 0; cursor: pointer; font-size: 16px; color: var(--muted); padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.file-btn { display: inline-block; }

/* ===== Cards ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer; position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c, var(--accent)); }
.card:hover { border-color: var(--c, var(--accent)); }
.card .num { font-size: 28px; font-weight: 700; }
.card .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.card .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .panel { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.b-ativa { color: var(--ok); background: rgba(47, 191, 113, .12); border-color: rgba(47, 191, 113, .35); }
.b-expirada { color: var(--warn); background: rgba(242, 169, 59, .12); border-color: rgba(242, 169, 59, .35); }
.b-bloqueada { color: var(--block); background: rgba(176, 108, 255, .12); border-color: rgba(176, 108, 255, .35); }
.b-revogada { color: var(--bad); background: rgba(239, 90, 111, .12); border-color: rgba(239, 90, 111, .35); }
.b-disponivel { color: var(--info); background: rgba(59, 179, 242, .12); border-color: rgba(59, 179, 242, .35); }
.b-plain { color: var(--muted); background: rgba(125, 134, 168, .12); border-color: rgba(125, 134, 168, .3); }
.b-plain::before { display: none; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.tag.manual { color: #f6d49d; border-color: rgba(242, 169, 59, .35); background: rgba(242, 169, 59, .08); }
.tag.backend { color: #9fdcff; border-color: rgba(59, 179, 242, .35); background: rgba(59, 179, 242, .08); }
.prod-dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

/* ===== Filtros ===== */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.filters input[type=search] { flex: 1 1 260px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); padding: 4px 11px; border-radius: 999px;
  cursor: pointer; font-size: 12px; color: var(--muted);
}
.chip.active { border-color: var(--accent); color: var(--text); background: var(--panel-2); }

/* ===== Tabela ===== */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 980px; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); background: var(--bg-2); position: sticky; top: 0; }
.table tbody tr:hover { background: rgba(108, 140, 255, .06); cursor: pointer; }
.table td.right { white-space: nowrap; }
.client-name { font-weight: 600; }
.secret { display: inline-flex; align-items: center; gap: 4px; }
.secret code { background: var(--bg-2); padding: 2px 6px; border-radius: 5px; font-family: Consolas, monospace; font-size: 12px; }
.bar { height: 6px; background: var(--bg-2); border-radius: 99px; overflow: hidden; width: 110px; margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.bar.full > span { background: var(--warn); }
.bar.over > span { background: var(--bad); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ===== Listas ===== */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item.click { cursor: pointer; }
.list-item.click:hover { background: rgba(108, 140, 255, .06); }

.timeline { display: flex; flex-direction: column; }
.ev { display: grid; grid-template-columns: 140px 1fr; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev-time { color: var(--muted); font-size: 12px; }
.ev-type { font-weight: 600; }
.ev-detail { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ev-reason { font-size: 12px; color: #c9cff0; margin-top: 2px; font-style: italic; }

/* ===== Forms ===== */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; }
.fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.fieldset legend { color: var(--muted); padding: 0 6px; font-size: 12px; }
.http-fields { display: flex; flex-direction: column; gap: 10px; padding-left: 4px; }
.http-fields.disabled { opacity: .45; pointer-events: none; }
.hint { font-size: 12px; color: var(--muted); }
.warn-box { background: rgba(239, 90, 111, .1); border: 1px solid rgba(239, 90, 111, .35); color: #ffc2ca; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.info-box { background: rgba(242, 169, 59, .08); border: 1px solid rgba(242, 169, 59, .3); color: #f6d49d; padding: 8px 12px; border-radius: 8px; font-size: 12px; }

/* ===== Drawer ===== */
.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; background: rgba(5, 7, 15, .6); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 100vw);
  background: var(--bg-2); border-left: 1px solid var(--line); z-index: 50;
  transform: translateX(100%); transition: transform .2s ease; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font-size: 17px; }
.drawer-body { padding: 16px 18px 40px; overflow-y: auto; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin-bottom: 14px; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }
.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 10px 0 18px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; }

/* ===== Modal ===== */
.modal-backdrop { display: grid; place-items: center; padding: 20px; z-index: 60; }
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; width: min(640px, 100%);
  max-height: 92vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal .form { padding: 16px 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2);
  border: 1px solid var(--line); padding: 10px 18px; border-radius: 10px; z-index: 80; box-shadow: var(--shadow);
}
.toast.err { border-color: var(--bad); }

/* ===== Responsivo ===== */
@media (max-width: 1000px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .main { padding: 14px; }
  .form-row, .form-row.three { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
}

/* ===== Botão grande "Nova chave" (Painel) ===== */
.btn-big {
  display: block; width: 100%; margin: 0 0 16px; padding: 22px;
  border: 0; border-radius: var(--radius); cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-size: 22px; font-weight: 800; letter-spacing: .06em;
  box-shadow: 0 8px 24px rgba(108, 140, 255, .3); transition: transform .1s, filter .1s;
}
.btn-big:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-big:active { transform: translateY(1px); }

/* ===== Card "Em uso agora" ===== */
.live-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gray); margin-right: 6px; vertical-align: middle; }
.live-dot.on { background: var(--ok); box-shadow: 0 0 0 0 rgba(47, 191, 113, .7); animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 191, 113, .6); }
  70% { box-shadow: 0 0 0 8px rgba(47, 191, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 191, 113, 0); }
}

/* ===== Prefixo fixo no campo de senha ===== */
.prefix-addon {
  display: flex; align-items: center; padding: 0 10px; border-radius: 8px 0 0 8px;
  background: var(--panel-2); border: 1px solid var(--line); border-right: 0; color: var(--text); font-weight: 700;
}
.input-group .prefix-addon + input.has-prefix { border-radius: 0 8px 8px 0; margin-left: -6px; }

/* ===== Linha da senha: parte editável + código do produto travado no fim ===== */
.secret-line {
  flex: 1; display: flex; align-items: center; min-width: 0;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
}
.secret-line.has-prefix { border-radius: 0 8px 8px 0; margin-left: -6px; }
.secret-line:focus-within { border-color: var(--accent); }
.input-group .secret-line input { flex: 0 1 auto; max-width: 100%; min-width: 0; border: 0; background: transparent; padding-right: 0; }
.code-suffix { flex: 1; padding: 0 10px 0 0; cursor: text; color: var(--text); font-weight: 700; white-space: nowrap; user-select: none; }
.code-suffix:empty { display: none; }

/* ===== Status TESTE e selo no topo do formulário ===== */
.b-teste { color: var(--test); background: rgba(255, 59, 59, .14); border-color: var(--test); font-weight: 800; }
.status-select option[value="teste"] { color: var(--test); font-weight: 800; }
.status-select.is-teste { border: 2px solid var(--test); color: var(--test); font-weight: 800; box-shadow: 0 0 0 3px rgba(255, 59, 59, .18); }
.status-select.is-teste option { color: var(--text); font-weight: 400; }
.status-select.is-teste option[value="teste"] { color: var(--test); font-weight: 800; }
.hbadge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 800; letter-spacing: .4px; border: 1.5px solid; white-space: nowrap; }
.hb-teste { color: var(--test); background: rgba(255, 59, 59, .14); border-color: var(--test); }
.hb-vitalicio { color: var(--ok); background: rgba(47, 191, 113, .14); border-color: var(--ok); }
.hb-ativa { color: var(--muted); background: rgba(125, 134, 168, .12); border-color: rgba(125, 134, 168, .35); }
.btn.day-on { color: var(--ok); border-color: var(--ok); background: rgba(47, 191, 113, .14); font-weight: 700; }
.status-select option[value="ativa"], .status-select.is-teste option[value="ativa"] { color: var(--ok); font-weight: 700; }
.status-select.is-ativa { border-color: var(--ok); color: var(--ok); font-weight: 700; }
.status-select.is-ativa option { color: var(--text); font-weight: 400; }
.status-select.is-ativa option[value="ativa"] { color: var(--ok); font-weight: 700; }
.status-select.is-ativa option[value="teste"] { color: var(--test); font-weight: 800; }
.hbadge .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ===== Produto escolhido em destaque no topo do formulário ===== */
.modal-head { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; }
.modal-head-right { justify-self: end; }
.hprod {
  display: inline-block; padding: 5px 18px; border-radius: 10px; font-size: 18px; font-weight: 900; letter-spacing: .8px;
  text-transform: uppercase; color: #fff; background: var(--pc); box-shadow: 0 0 0 2px rgba(255,255,255,.15), 0 0 18px var(--pc);
  text-shadow: 0 1px 2px rgba(0,0,0,.45); white-space: nowrap;
}
@media (max-width: 640px) {
  .modal-head { grid-template-columns: 1fr auto; }
  #modalProduct { grid-column: 1 / -1; grid-row: 2; justify-self: center; }
}
