:root {
  --bg: #0f1419;
  --panel: #1a212b;
  --panel-2: #232d3a;
  --border: #2c3745;
  --text: #e6edf3;
  --muted: #8b98a9;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); margin-top: 8px; min-height: 18px; }
.spacer { flex: 1; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card.nested { background: var(--panel-2); }

/* Decoy sign-in (neutral, no real brand) */
.decoy-wrap {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px;
  background: linear-gradient(135deg, #eef2f7 0%, #f7f5fb 50%, #eaf0f6 100%);
}
.decoy-card {
  width: 360px; max-width: 100%;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  padding: 40px 44px; box-shadow: 0 2px 14px rgba(0,0,0,.08);
  color: #1b1b1b; font-family: "Segoe UI", system-ui, sans-serif;
}
.decoy-logo { color: #5b6470; margin-bottom: 18px; }
.decoy-logo svg { width: 30px; height: 30px; }
.decoy-card h1 { margin: 0 0 6px; font-size: 24px; font-weight: 600; color: #1b1b1b; }
.decoy-sub { margin: 0 0 20px; font-size: 15px; color: #4b5563; }
.decoy-field { display: block; }
.decoy-field span { display: block; font-size: 12px; color: #6b7280; margin-bottom: 4px; }
.decoy-card input {
  width: 100%; padding: 8px 4px; font-size: 15px; color: #111;
  background: transparent; border: none; border-bottom: 1px solid #666; border-radius: 0;
}
.decoy-card input:focus { outline: none; border-bottom: 2px solid #0067b8; }
.decoy-card button {
  margin-top: 26px; width: auto; min-width: 108px; float: right;
  background: #0067b8; color: #fff; border: none; border-radius: 2px;
  padding: 8px 20px; font-size: 15px; font-weight: 400; cursor: pointer;
}
.decoy-card button:hover { background: #005da6; }
.decoy-error { clear: both; padding-top: 18px; color: #a80000; font-size: 13px; min-height: 16px; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 340px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: block; margin: 14px 0 0; font-size: 13px; color: var(--muted); }
.login-card input { width: 100%; margin-top: 6px; }
.login-card button { width: 100%; margin-top: 18px; }

/* Inputs & buttons */
input, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 14px;
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
button:hover { border-color: var(--primary); }
button.primary, button[type=submit] { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, button[type=submit]:hover { background: var(--primary-hover); }
button.ghost { background: transparent; }
button.danger { color: var(--red); border-color: #52323a; }
button.danger:hover { background: #2a1a1e; }
button.small { padding: 5px 10px; font-size: 12px; }
button.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 5px 8px; color: var(--primary); }
button.icon-btn:hover { border-color: var(--primary); background: var(--panel-2); }
td.actions { display: flex; gap: 6px; align-items: center; }

/* App shell: sidebar + content */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  font-weight: 700; font-size: 16px; line-height: 1.1;
  padding: 4px 8px 18px;
}
.brand span { font-size: 15px; }
.brand-ic { width: 26px; height: 26px; color: var(--primary); flex-shrink: 0; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent;
  color: var(--muted); font-weight: 500;
  padding: 10px 12px; border-radius: 9px;
}
.nav-item .ic { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--panel-2); border-color: transparent; color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active:hover { background: var(--primary-hover); }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.agents { display: flex; flex-direction: column; gap: 6px; font-size: 12px; margin-bottom: 12px; }
.agent-pill { display: flex; align-items: center; gap: 7px; padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 12px; cursor: pointer; width: 100%; text-align: left; font-weight: 500; }
.agent-pill:hover { border-color: var(--primary); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.on { background: var(--green); }
.dot.off { background: var(--red); }
.whoami-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#whoami { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.role-tag { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); padding: 1px 6px; border-radius: 999px; }

.content { flex: 1; min-width: 0; padding: 22px 28px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-actions { display: flex; gap: 10px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: var(--panel-2); }
.empty { padding: 30px; text-align: center; }

.badge { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); }
.badge.active { background: #14321f; color: var(--green); }
.badge.expired { background: #3a2a12; color: var(--amber); }
.badge.revoked { background: #3a1e22; color: var(--red); }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { width: 560px; max-width: 100%; max-height: 90vh; overflow: auto; }
.modal h2 { margin: 0 0 16px; }
.modal label { display: block; margin: 12px 0 0; color: var(--muted); font-size: 13px; }
.modal input, .modal select { width: 100%; margin-top: 6px; }
.modal .row { display: flex; gap: 10px; }
.modal .row > * { flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.acl-list { margin: 10px 0; }
.acl-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.acl-row .act-allow { color: var(--green); font-weight: 600; }
.acl-row .act-deny { color: var(--red); font-weight: 600; }
.acl-add { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: end; }
.acl-add > div { display: flex; flex-direction: column; }
.acl-add label { font-size: 11px; color: var(--muted); margin: 0 0 3px; }

pre.ovpn { background: #0a0e13; border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 300px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }

/* ACL group chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 13px; }
.chip-x { padding: 0 6px; font-size: 12px; line-height: 1.4; border-radius: 999px; border: none; background: transparent; color: var(--red); }
.chip-x:hover { background: #2a1a1e; }
.modal h3 { color: var(--text); }

/* 2FA QR + backup codes */
.qr-wrap { display: inline-block; background: #fff; padding: 10px; border-radius: 10px; margin: 6px 0 10px; }
.qr-wrap svg { display: block; width: 190px; height: 190px; }
.backup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.backup-grid code { text-align: center; padding: 8px; font-size: 14px; letter-spacing: 1px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; }

/* account settings */
.settings { max-width: 600px; display: flex; flex-direction: column; gap: 16px; }
.settings-card { padding: 22px 24px; }
.sc-head { display: flex; align-items: center; gap: 14px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: linear-gradient(135deg, var(--primary), #6366f1); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 19px; flex-shrink: 0; }
.sc-title { font-weight: 700; font-size: 16px; }
.sc-h { font-size: 14px; margin: 0 0 16px; display: flex; align-items: center; gap: 7px; }
.field { margin-bottom: 14px; max-width: 360px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.field input, .field select { width: 100%; }
.modal-lbl { display: block; margin: 12px 0 0; color: var(--muted); font-size: 12px; font-weight: 500; }
.modal-lbl input { display: block; width: 100%; max-width: 220px; margin-top: 6px; }

/* key-value list (agent detail modal) */
.kv-list { display: flex; flex-direction: column; gap: 2px; }
.kv { display: flex; gap: 12px; padding: 8px 2px; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: none; }
.kv-k { flex: 0 0 120px; color: var(--muted); font-size: 13px; }
.kv-v { flex: 1; min-width: 0; word-break: break-word; }
.kv-v code { margin-right: 4px; }

/* iptables structured view */
.ipt-table-card { margin-bottom: 18px; }
.ipt-table-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 14px; }
.ipt-table-title span { color: var(--primary); }
.ipt-chain { margin-bottom: 16px; }
.ipt-chain:last-child { margin-bottom: 0; }
.ipt-chain-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ipt-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.ipt-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ipt-table th { background: var(--panel-2); color: var(--muted); font-size: 11px; padding: 8px 10px; white-space: nowrap; }
.ipt-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ipt-table tbody tr:last-child td { border-bottom: none; }
.ipt-table tbody tr:hover { background: var(--panel-2); }
.ipt-num { color: var(--muted); }
.ipt-extra { white-space: normal; font-size: 12px; }
.ipt-target { padding: 1px 8px; border-radius: 6px; font-weight: 600; font-size: 12px; background: var(--panel-2); }
.ipt-target.t-accept { background: #14321f; color: var(--green); }
.ipt-target.t-drop { background: #3a1e22; color: var(--red); }
.ipt-target.t-nat { background: #1e2f3a; color: #38bdf8; }

/* Dashboard stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-num { font-size: 30px; font-weight: 700; line-height: 1; }
.stat-num.t-green { color: var(--green); }
.stat-num.t-blue { color: #38bdf8; }
.stat-num.t-amber { color: var(--amber); }
.stat-num.t-red { color: var(--red); }
.stat-lbl { margin-top: 8px; color: var(--muted); font-size: 13px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.agent-card { padding: 16px 18px; }
.ac-top { display: flex; align-items: center; gap: 8px; }

/* Users table toolbar / bulk / online / expiry */
.table-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.search { flex: 1; max-width: 320px; }
.bulk-bar { display: flex; align-items: center; gap: 8px; }
.chk-col { width: 34px; text-align: center; }
.chk-col input { cursor: pointer; }
.odot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--border); margin-right: 8px; vertical-align: middle; }
.odot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.expiry-soon { color: var(--amber); }
.expiry-over { color: var(--red); }
tr.row-soon td { background: rgba(245,158,11,.06); }

/* Bandwidth chart */
.bw-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.bw-legend { display: flex; gap: 18px; font-size: 13px; }
.bw-legend span { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.bw-legend strong { color: var(--text); }
.bw-legend i, .bw-tip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }
.bw-plot { position: relative; width: 100%; }
.bw-svg { width: 100%; height: 260px; display: block; }
.bw-grid { stroke: var(--border); stroke-width: 1; }
.bw-ytick { fill: var(--muted); font-size: 10px; text-anchor: end; }
.bw-xtick { fill: var(--muted); font-size: 10px; }
.bw-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
#bw-hit { cursor: crosshair; }
.bw-tip { position: absolute; top: 8px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px; pointer-events: none; white-space: nowrap; z-index: 5; }
.bw-tip.flip { transform: translateX(-100%); }
.bw-tip-t { color: var(--muted); margin-bottom: 3px; }
.bw-tip div { display: flex; align-items: center; gap: 6px; }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--panel-2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 10px; z-index: 100; max-width: 400px; }
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }
