:root {
  --bg: #f2f5fa;
  --panel: #ffffff;
  --panel-2: #eef2f8;
  --line: #dde4ee;
  --text: #16202e;
  --muted: #5d6b80;
  --primary: #1fb85a;
  --primary-2: #19a14e;
  --danger: #e0342c;
  --warn: #d99a00;
  --info: #2f7fe0;
  --shadow: 0 8px 24px rgba(20, 40, 70, .08);
  --radius: 16px;
  --sidebar: 260px;
  --sidebar-1: #eef2f8;
  --sidebar-2: #e6ecf4;
  --btn-secondary: #e3e9f2;
  --th-bg: #e9eef6;
  --row-hover: rgba(20, 40, 70, .035);
  --qr-bg: #eef2f8;
  --progress-bg: #e2e8f0;
  --dot-ring: rgba(20, 40, 70, .08);
  --alert-ok: #0f7a3d;
  --alert-err: #b3261e;
  --alert-info: #1d5cb8;
  --badge-ok: #0f7a3d;
  --badge-no: #b3261e;
  --badge-wait: #8a6100;
  --badge-ghost: #5d6b80;
  --ghost-bg: rgba(0, 0, 0, .05);
  --help-bg: rgba(47, 127, 224, .07);
  --help-line: rgba(47, 127, 224, .22);
  --help-text: #1d5cb8;
  --logo-text: #042;
  font-family: Inter, Segoe UI, system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --panel: #121a2b;
  --panel-2: #182338;
  --line: #243149;
  --text: #e8eefc;
  --muted: #9fb0d0;
  --primary: #25d366;
  --primary-2: #1ebe57;
  --danger: #ff5c7a;
  --warn: #ffc857;
  --info: #4da3ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --sidebar-1: #10182a;
  --sidebar-2: #0d1422;
  --btn-secondary: #243552;
  --th-bg: #152038;
  --row-hover: rgba(255, 255, 255, .02);
  --qr-bg: #0e1626;
  --progress-bg: #1a253a;
  --dot-ring: rgba(255, 255, 255, .04);
  --alert-ok: #b9f5d0;
  --alert-err: #ffd0d9;
  --alert-info: #cfe6ff;
  --badge-ok: #8df0b6;
  --badge-no: #ffb3c1;
  --badge-wait: #ffe2a3;
  --badge-ghost: #9aa3af;
  --ghost-bg: rgba(255, 255, 255, .06);
  --help-bg: rgba(77, 163, 255, .08);
  --help-line: rgba(77, 163, 255, .2);
  --help-text: #d7e9ff;
  --logo-text: #042;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2));
  border-right: 1px solid var(--line);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 8px; }
.brand strong { display: block; }
.brand small { color: var(--muted); font-size: .68rem; white-space: nowrap; }
.logo {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(135deg, #25d366, #128c7e); color: var(--logo-text);
}
.sidebar nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.sidebar nav a {
  padding: 12px 14px; border-radius: 12px; color: var(--muted);
  border: 1px solid transparent;
}
.sidebar nav a:hover { background: var(--panel-2); color: var(--text); }
.sidebar nav a.active {
  background: rgba(37, 211, 102, .12);
  color: var(--primary);
  border-color: rgba(37, 211, 102, .25);
}
.sidebar-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border-radius: 12px; background: var(--panel);
  color: var(--muted); font-size: 13px;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #666; box-shadow: 0 0 0 4px var(--dot-ring);
}
.dot.online { background: var(--primary); }
.dot.qr { background: var(--warn); }
.dot.offline { background: var(--danger); }

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 22px 28px 8px; gap: 12px;
}
.topbar h1 { margin: 0; font-size: 1.5rem; }
.content { padding: 12px 28px 40px; }

.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: 1.2fr .8fr; }
.grid.form { grid-template-columns: 1fr 1fr; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card h2, .card h3 { margin: 0 0 12px; }
.card p { color: var(--muted); line-height: 1.5; }
.stat-value { font-size: 1.8rem; font-weight: 800; margin-top: 8px; }
.stat-label { color: var(--muted); font-size: .92rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 12px; padding: 11px 16px; cursor: pointer;
  background: var(--primary); color: #053; font-weight: 700;
}
.btn:hover { background: var(--primary-2); }
.btn.secondary { background: var(--btn-secondary); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }

.alert {
  margin: 0 28px 8px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line);
}
.alert.success { background: rgba(31, 184, 90, .1); color: var(--alert-ok); }
.alert.error { background: rgba(224, 52, 44, .1); color: var(--alert-err); }
.alert.info { background: rgba(47, 127, 224, .1); color: var(--alert-info); }

label { display: block; margin: 0 0 6px; color: var(--muted); font-size: .92rem; }
.field { margin-bottom: 14px; }
.input, select, textarea {
  width: 100%; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; outline: none;
}
.input:focus, select:focus, textarea:focus { border-color: rgba(37, 211, 102, .5); }
textarea { min-height: 140px; resize: vertical; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin-bottom: 14px;
}
.toolbar .grow { flex: 1; min-width: 180px; }

.table-wrap { overflow: auto; border-radius: 14px; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--th-bg); color: var(--muted); font-size: .85rem; position: sticky; top: 0; }
tr:hover td { background: var(--row-hover); }
.muted { color: var(--muted); }
.badge {
  display: inline-flex; padding: 4px 8px; border-radius: 999px;
  font-size: .78rem; font-weight: 700;
}
.badge.ok { background: rgba(37, 211, 102, .15); color: var(--badge-ok); }
.badge.no { background: rgba(255, 92, 122, .15); color: var(--badge-no); }
.badge.wait { background: rgba(255, 200, 87, .15); color: var(--badge-wait); }
.badge.ghost { background: var(--ghost-bg); color: var(--badge-ghost); }

.qr-box {
  display: grid; place-items: center; min-height: 340px;
  background: var(--qr-bg); border: 1px dashed var(--line); border-radius: 16px;
}
.qr-box img { width: 280px; height: 280px; background: #fff; border-radius: 12px; padding: 10px; }
.help {
  background: var(--help-bg); border: 1px solid var(--help-line);
  border-radius: 14px; padding: 14px; color: var(--help-text);
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.checks { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); }
.progress {
  height: 10px; background: var(--progress-bg); border-radius: 999px; overflow: hidden; margin-top: 10px;
}
.progress > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #25d366, #4da3ff); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; }
.wa-link { color: #25d366; font-weight: 600; text-decoration: none; }
.wa-link:hover { text-decoration: underline; color: #6ce89a; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

#theme-toggle { padding: 10px 12px; }
#theme-toggle svg { width: 18px; height: 18px; display: block; }
[data-theme="dark"] #theme-toggle .sun { display: none; }
#theme-toggle .moon { display: none; }
[data-theme="dark"] #theme-toggle .moon { display: block; }

@media (max-width: 1100px) {
  .grid.stats, .grid.two, .grid.form { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content, .topbar, .alert { padding-left: 16px; padding-right: 16px; margin-left: 0; margin-right: 0; }
}
.hidden { display: none; }