/* ── Variables ────────────────────────────────────────── */
:root {
  --bg0: #0d1117;
  --bg1: #161b27;
  --bg2: #1c2233;
  --bg3: #232b42;
  --border: #2d3550;
  --border-lt: #3a4568;
  --text: #e2e8f0;
  --text-sec: #94a3b8;
  --text-muted: #64748b;
  --accent: #6366f1;
  --accent-h: #818cf8;
  --accent-dim: rgba(99,102,241,.15);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --sidebar-w: 218px;
  font-size: 14px;
}

/* ── Reset ────────────────────────────────────────────── */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html,body { height: 100%; overflow: hidden; background: var(--bg0); color: var(--text); font-family: 'Inter',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); }
code { font-family: 'Fira Code','Consolas',monospace; font-size: 12px; background: var(--bg3); padding: 1px 6px; border-radius: 4px; color: var(--accent); }
pre.code-block { background: var(--bg0); border: 1px solid var(--border); border-radius: 8px; padding: 14px; font-size: 12px; font-family: 'Fira Code','Consolas',monospace; color: var(--text-sec); white-space: pre-wrap; word-break: break-all; margin-top: 10px; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Layout ───────────────────────────────────────────── */
#app { display: flex; height: 100vh; }

/* ── Sidebar ──────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg1); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px 16px; border-bottom: 1px solid var(--border);
}
.brand-icon { font-size: 22px; }
.brand-name { font-size: 15px; font-weight: 700; }
.sidebar-nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-radius: 8px; color: var(--text-sec); font-size: 14px; cursor: pointer;
  transition: all .15s; position: relative;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; background: rgba(34,197,94,.2); color: var(--success);
  padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600;
}
.sidebar-footer { padding: 8px; border-top: 1px solid var(--border); }
.gateway-status { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 11px; color: var(--text-muted); overflow: hidden; }
.gateway-status code { font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }

/* ── Main ─────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ── Pages ────────────────────────────────────────────── */
.page { display: none; flex-direction: column; height: 100%; padding: 24px; gap: 16px; overflow: hidden; }
.page.active { display: flex; }

.page-header { display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.page-header h2 { font-size: 20px; font-weight: 700; }
.header-actions { display: flex; align-items: center; gap: 8px; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 500; transition: all .15s;
}
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 6px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--danger); border: 1px solid rgba(239,68,68,.3); }
.btn-danger:hover { background: rgba(239,68,68,.25); }
.btn-success { background: rgba(34,197,94,.15); color: var(--success); border: 1px solid rgba(34,197,94,.3); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────── */
.form-control {
  background: var(--bg1); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 12px; font-size: 14px; width: 100%;
  outline: none; transition: border-color .15s;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-control-sm { padding: 5px 10px; font-size: 13px; border-radius: 6px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 13px; color: var(--text-sec); font-weight: 500; }
.form-hint { font-size: 12px; color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 120px; font-family: 'Fira Code','Consolas',monospace; font-size: 12px; }

/* ── Tables ───────────────────────────────────────────── */
.table-container { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; }
.table thead th { background: var(--bg2); color: var(--text-sec); font-weight: 500; font-size: 13px; padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 13px; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: var(--bg2); }

/* ── Tags ─────────────────────────────────────────────── */
.tag { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tag-success { background: rgba(34,197,94,.15); color: var(--success); border: 1px solid rgba(34,197,94,.3); }
.tag-danger  { background: rgba(239,68,68,.15);  color: var(--danger);  border: 1px solid rgba(239,68,68,.3); }
.tag-warning { background: rgba(245,158,11,.15); color: var(--warning); border: 1px solid rgba(245,158,11,.3); }
.tag-info    { background: var(--accent-dim);    color: var(--accent);  border: 1px solid rgba(99,102,241,.3); }
.tag-muted   { background: var(--bg3);           color: var(--text-muted); border: 1px solid var(--border); }

/* ── Status dot ───────────────────────────────────────── */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-green  { background: var(--success); box-shadow: 0 0 6px var(--success); animation: pulse 2s infinite; }
.dot-yellow { background: var(--warning); animation: pulse 1s infinite; }
.dot-red    { background: var(--danger); }
.dot-gray   { background: var(--text-muted); }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }

/* ── Dashboard ────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; flex-shrink: 0; }
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 18px; display: flex; align-items: center; gap: 14px; }
.stat-icon { width: 42px; height: 42px; border-radius: 10px; background: var(--bg3); display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stat-val { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; flex: 1; min-height: 0; }
.panel { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; overflow: hidden; }
.panel-header { display: flex; justify-content: space-between; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 14px; flex-shrink: 0; }
.panel-body { flex: 1; overflow-y: auto; }

.info-bar { display: flex; align-items: center; gap: 10px; background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 11px 16px; font-size: 13px; flex-shrink: 0; }

/* Account cell */
.acc-cell { display: flex; align-items: center; gap: 10px; }
.acc-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--bg3); object-fit: cover; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.acc-name { font-size: 13px; font-weight: 500; }
.acc-wxid { font-size: 11px; color: var(--text-muted); font-family: 'Fira Code','Consolas',monospace; }

/* ── Modal ────────────────────────────────────────────── */
#modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; backdrop-filter: blur(2px); cursor: pointer; }
#modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: var(--bg2); border: 1px solid var(--border); border-radius: 14px; z-index: 101; min-width: 460px; max-width: 560px; width: 90vw; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,.6); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 16px; border-bottom: 1px solid var(--border); font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 22px; line-height: 1; padding: 0; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); }

/* ── QR Code ──────────────────────────────────────────── */
.qr-section { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.qr-status { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.qr-wrap { border: 2px solid var(--border); border-radius: 12px; padding: 12px; background: #fff; }
.qr-img { width: 220px; height: 220px; display: block; }

/* ── Setup ────────────────────────────────────────────── */
#setup-overlay { position: fixed; inset: 0; background: var(--bg0); display: flex; align-items: center; justify-content: center; z-index: 200; }
.setup-card { background: var(--bg2); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 460px; box-shadow: 0 24px 64px rgba(0,0,0,.5); }
.setup-logo { font-size: 48px; text-align: center; margin-bottom: 12px; }
.setup-card h1 { text-align: center; font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.setup-card > p { text-align: center; margin-bottom: 24px; }
.setup-actions { display: flex; gap: 12px; margin-top: 4px; }
.setup-actions .btn { flex: 1; justify-content: center; }
#setup-test-result { min-height: 24px; font-size: 13px; margin-bottom: 8px; }

/* ── Settings ─────────────────────────────────────────── */
.settings-wrap { display: flex; flex-direction: column; gap: 20px; max-width: 680px; overflow-y: auto; }
.settings-section { background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 22px; }
.settings-section h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; }

/* ── Toast ────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 20px; border-radius: 8px; font-size: 13px; z-index: 999;
  box-shadow: 0 8px 32px rgba(0,0,0,.4); animation: slideup .2s ease;
}
#toast.success { border-color: rgba(34,197,94,.4); color: var(--success); }
#toast.error   { border-color: rgba(239,68,68,.4); color: var(--danger); }
@keyframes slideup { from { transform: translateX(-50%) translateY(20px); opacity:0; } }

/* ── Pagination ───────────────────────────────────────── */
.pagination { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }
.pagination button { padding: 4px 12px; border-radius: 6px; background: var(--bg2); border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 13px; }
.pagination button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Misc ─────────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-sec   { color: var(--text-sec); }
.mono { font-family: 'Fira Code','Consolas',monospace; font-size: 11px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.empty-state { padding: 32px; text-align: center; color: var(--text-muted); }

#auth-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(99,102,241,.14), transparent 36%),
    linear-gradient(180deg, rgba(13,17,23,.94), rgba(13,17,23,.98));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 210;
}

.auth-card {
  width: 460px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 6px;
}

.sidebar-user-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.sidebar-user-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.dash-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}

.dash-row:last-child {
  border-bottom: none;
}

.setup-logo i {
  font-size: 42px;
}

@media (max-width: 960px) {
  html, body {
    overflow: auto;
  }

  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .stats-grid,
  .dash-grid {
    grid-template-columns: 1fr;
  }

  .page {
    overflow: visible;
  }

  #modal {
    min-width: 0;
    width: calc(100vw - 24px);
  }

  .setup-card,
  .auth-card {
    width: calc(100vw - 24px);
    padding: 28px 22px;
  }
}
