:root {
  --bg: #0b0f17;
  --panel: #111827;
  --card: #151b2b;
  --card-2: #1a2134;
  --border: #223052;
  --text: #e5e9f0;
  --muted: #8b95a7;
  --accent: #6d7cff;
  --accent-2: #8b93ff;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --cyan: #22d3ee;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--cyan);
}

/* ---------- login ---------- */
#login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 30% 20%, #17203a 0%, var(--bg) 60%);
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  width: 340px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-logo-img {
  width: 78px; height: 86px; object-fit: contain;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0,0,0,.5), 0 0 0 1px rgba(255,255,255,.06);
  margin: 0 auto 6px;
}
.login-koradi {
  font-size: 13px; font-weight: 700; letter-spacing: 3px;
  color: var(--cyan); text-transform: uppercase;
  text-shadow: 0 0 12px rgba(34,211,238,.6);
  margin: 0 auto 2px;
  white-space: nowrap;
}
.login-card h1 { margin: 10px 0 2px; font-size: 22px; }
.login-card p { margin: 0 0 20px; }
/* gradient brand text */
.brand-grad {
  background: linear-gradient(92deg, #8b93ff 0%, #6d7cff 35%, #22d3ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-weight: 800;
  letter-spacing: 2.5px;
  filter: drop-shadow(0 0 14px rgba(109,124,255,.45));
}
.login-card h1.brand-grad { font-size: 27px; letter-spacing: 3px; }
#login-form input { margin-bottom: 12px; }
.login-error { color: var(--red); margin-top: 12px; font-size: 13px; }

/* ---------- layout ---------- */
#app { display: flex; height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.brand-koradi {
  display: block; margin-bottom: 2px;
  font-size: 10px; font-weight: 700; letter-spacing: 2px;
  color: var(--cyan); text-transform: uppercase;
  text-shadow: 0 0 10px rgba(34,211,238,.55);
  line-height: 1.25;
  white-space: nowrap;
}
.brand-logo-img {
  width: 38px; height: 42px; object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.07);
  flex-shrink: 0;
}
.brand-text strong { display: block; font-size: 21px; letter-spacing: 3px; line-height: 1.1; }
.brand-text small {
  display: block; margin-top: 3px;
  color: var(--cyan); font-size: 10.5px; font-weight: 700;
  letter-spacing: 5px; text-transform: uppercase;
  text-shadow: 0 0 10px rgba(34,211,238,.55);
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); text-decoration: none;
  padding: 10px 12px; border-radius: 9px;
  transition: background .15s, color .15s;
  font-weight: 500;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: var(--text); }
.nav-item.active { background: rgba(109,124,255,.14); color: var(--accent-2); }
.nav-ico { width: 20px; text-align: center; }
.pill {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: 11px; border-radius: 999px; padding: 1px 8px;
}
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.server-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 9px; font-size: 12.5px; color: var(--muted);
}
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot-bad { background: var(--red); box-shadow: 0 0 8px var(--red); }

.main { flex: 1; overflow-y: auto; padding: 0 26px 40px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0 14px; position: sticky; top: 0;
  background: linear-gradient(var(--bg) 75%, transparent);
  z-index: 5;
}
.topbar h2 { margin: 0; font-size: 20px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
}
.card h3 { margin: 0 0 14px; font-size: 15px; color: var(--text); }
.stat { padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col .col { display: flex; flex-direction: column; gap: 18px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } .sidebar { width: 190px; } }

.kv { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.kv-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.kv-row span:first-child { color: var(--muted); }

.badge { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-ok { background: rgba(34,197,94,.15); color: var(--green); }
.badge-off { background: rgba(239,68,68,.15); color: var(--red); }
.badge-warn { background: rgba(245,158,11,.15); color: var(--amber); }

.guide { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; color: var(--text); line-height: 1.5; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--card-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.4); color: var(--red); }
.btn-reg { background: rgba(34,197,94,.16); border-color: rgba(34,197,94,.45); color: var(--green); }
.btn-reg:hover { filter: brightness(1.2); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 7px; }
.btn-icon { padding: 5px 8px; font-size: 12px; border-radius: 7px; }

/* ---------- tables ---------- */
.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; color: var(--muted); font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .5px;
  padding: 8px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 9px 12px; border-bottom: 1px solid rgba(34,48,82,.5); vertical-align: middle; }
.table tr:hover td { background: rgba(255,255,255,.025); }
.ta-r { text-align: right; }
.table .actions { display: flex; gap: 5px; justify-content: flex-end; flex-wrap: wrap; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9d5cff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0;
}
.user-name { font-weight: 600; }
.user-sub { font-size: 11.5px; color: var(--muted); }

.input {
  background: var(--card-2); border: 1px solid var(--border);
  color: var(--text); padding: 8px 12px; border-radius: 9px;
  font-size: 13px; outline: none; width: 100%;
}
.input:focus { border-color: var(--accent); }
.table-toolbar .input { width: 240px; }
.lbl { display: block; margin: 12px 0 5px; color: var(--muted); font-size: 12.5px; }

/* ---------- tree ---------- */
.tree { padding: 4px 0; }
.tree-node { margin: 2px 0; }
.tree-row {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 9px;
}
.tree-row:hover { background: rgba(255,255,255,.04); }
.tree-toggle { cursor: pointer; width: 18px; text-align: center; color: var(--muted); user-select: none; flex-shrink: 0; }
.tgl-spacer { width: 18px; display: inline-block; flex-shrink: 0; }
/* channel icon: bigger than user avatar (22px) */
.channel-ico {
  position: relative;
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, #0ea5e9, #4f46e5);
  border: 1px solid rgba(255,255,255,.16);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.channel-ico.ico-parent { background: linear-gradient(135deg, #6366f1, #a855f7); }
.ch-ico-img { width: 22px; height: 22px; object-fit: contain; filter: drop-shadow(0 1px 3px rgba(0,0,0,.4)); }
.ch-dot {
  position: absolute; top: -4px; right: -4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--green);
  border: 2px solid var(--card);
  box-shadow: 0 0 6px var(--green);
}
.tree-name { font-weight: 600; }
.tree-meta { color: var(--muted); font-size: 12px; margin-left: 6px; }
.tree-actions { margin-left: auto; display: flex; gap: 5px; opacity: 0; transition: opacity .12s; }
.tree-row:hover .tree-actions { opacity: 1; }
.tree-children { margin-left: 22px; border-left: 1px dashed var(--border); padding-left: 10px; }
.tree-user {
  display: flex; align-items: center; gap: 8px;
  /* indent user di bawah nama channel: 10(row pad) + 18(toggle) + 8(gap) + 30(icon) + 8(gap) = 74px */
  padding: 4px 10px 4px 74px; font-size: 13px; color: var(--muted);
}
.tree-user .avatar { width: 22px; height: 22px; font-size: 11px; }
.tree-user .u-muted { color: var(--amber); font-size: 11px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 200;
  background: var(--card-2); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 12px 18px; border-radius: 10px;
  box-shadow: var(--shadow); max-width: 360px;
  animation: slidein .2s ease;
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
@keyframes slidein { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(5,8,15,.7); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: 400px; max-width: 94vw;
  box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 14px; }
.modal .btn-row { margin-top: 16px; justify-content: flex-end; }

/* ---------- mobile / responsive ---------- */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 767px) {
  #app { flex-direction: column; height: auto; min-height: 100vh; }
  /* sidebar -> header bar (brand+logout baris 1, nav scroll baris 2) */
  .sidebar {
    width: 100%; flex-shrink: 0;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    padding: 10px 14px; gap: 6px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { order: 1; padding: 0; border-bottom: none; margin-bottom: 0; flex: 1 1 auto; min-width: 0; }
  .brand-koradi { font-size: 8.5px; letter-spacing: 1.5px; }
  .brand-logo-img { width: 32px; height: 36px; }
  .brand-text strong { font-size: 17px; letter-spacing: 2px; }
  .brand-text small { letter-spacing: 3.5px; font-size: 9.5px; }
  .sidebar-foot { order: 2; border-top: none; padding-top: 0; margin-left: auto; }
  .server-pill { display: none; }
  .nav { order: 3; flex: none; width: 100%; display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 4px; padding-top: 6px; }
  .nav-item { padding: 8px 4px; white-space: nowrap; font-size: 12px; justify-content: center; text-align: center; flex-shrink: 0; }
  .nav-ico { width: auto; font-size: 13px; }
  .nav-item .pill { margin-left: 4px; }
  .main { padding: 0 12px 32px; }
  .topbar { padding: 12px 0 10px; flex-wrap: wrap; gap: 4px 10px; }
  .topbar h2 { font-size: 18px; }
  .topbar-right { gap: 8px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
  .card { padding: 14px; }
  .table-toolbar { flex-direction: column; align-items: stretch; }
  .table-toolbar .input { width: 100%; max-width: none; }
  .table th, .table td { padding: 8px 10px; }
  /* sembunyikan kolom Client & Ping di tabel Users pada HP — kolom Aksi tetap terlihat */
  #users-table th:nth-child(4), #users-table td:nth-child(4),
  #users-table th:nth-child(5), #users-table td:nth-child(5) { display: none; }
  /* tabel Users jadi kartu bertumpuk di HP */
  #users-table thead { display: none; }
  #users-table, #users-table tbody, #users-table tr, #users-table td { display: block; width: 100%; }
  #users-table tr {
    margin-bottom: 12px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--card-2);
  }
  #users-table td { border: none; padding: 4px 2px; }
  #users-table td:nth-child(2)::before { content: 'Channel: '; color: var(--muted); font-size: 12px; }
  #users-table td:nth-child(3)::before { content: 'Status: '; color: var(--muted); font-size: 12px; }
  #users-table td:nth-child(6)::before { content: 'Online: '; color: var(--muted); font-size: 12px; }
  #users-table td:nth-child(7) { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
  #users-table td:nth-child(7)::before { content: 'Aksi'; display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
  #users-table .actions { justify-content: flex-start; gap: 8px; }
  #users-table .actions .btn-icon { padding: 8px 12px; font-size: 15px; }
  /* tabel User Terdaftar jadi kartu bertumpuk di HP */
  #reg-table thead { display: none; }
  #reg-table, #reg-table tbody, #reg-table tr, #reg-table td { display: block; width: 100%; }
  #reg-table tr { margin-bottom: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--card-2); }
  #reg-table td { border: none; padding: 4px 2px; }
  #reg-table td:nth-child(2)::before { content: 'Terakhir Online: '; color: var(--muted); font-size: 12px; }
  #reg-table td:nth-child(3) { margin-top: 8px; border-top: 1px dashed var(--border); padding-top: 8px; }
  #reg-table td:nth-child(3)::before { content: 'Aksi'; display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
  #reg-table .actions { justify-content: flex-start; gap: 8px; }
  #reg-table .actions .btn-icon { padding: 8px 12px; font-size: 15px; }
  .actions { flex-wrap: wrap; }
  .tree-actions { opacity: 1; }
  .login-card { width: 100%; max-width: 340px; padding: 28px 22px; }
}
