:root {
  --bg: #0f1220;
  --panel: #191d2e;
  --panel-2: #1f2438;
  --line: #2a3050;
  --text: #e7e9f3;
  --muted: #9aa0be;
  --accent: #6d5efc;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --amber: #f59e0b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
}
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; color: var(--muted);
  padding: 11px 12px; border-radius: 10px; cursor: pointer;
  font-size: 14.5px; text-align: left; width: 100%;
}
.nav-item span { font-size: 16px; }
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.sidebar-foot { margin-top: auto; }
.wa-pill {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 12px; font-size: 12.5px; color: var(--muted);
}
.wa-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.wa-pill.on .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.wa-pill.off .dot { background: var(--red); }
.wa-pill.wait .dot { background: var(--amber); }

/* Content */
.content { flex: 1; padding: 32px 40px; max-width: 1100px; }
.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.card.stat { position: relative; overflow: hidden; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 34px; font-weight: 800; margin: 6px 0 2px; }
.stat-foot { color: var(--muted); font-size: 12px; }
.card.stat.green .stat-value { color: var(--green); }
.card.stat.red .stat-value { color: var(--red); }
.card.stat.blue .stat-value { color: var(--blue); }

.grid-2 { display: grid; grid-template-columns: 1fr 1.4fr; gap: 16px; }
.card-title { font-weight: 600; margin-bottom: 10px; }
.big { font-size: 40px; font-weight: 800; color: var(--accent); }
.activity { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
.act-row { display: flex; align-items: center; gap: 10px; font-size: 13.5px; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.act-row:last-child { border-bottom: 0; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.badge.no { background: rgba(239,68,68,.15); color: #f87171; }

/* Filters + table */
.filters { display: flex; gap: 12px; margin: 20px 0 14px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-size: 14px; min-width: 220px;
}
.filters .count { color: var(--muted); font-size: 13px; margin-left: auto; }
.table-wrap { padding: 0; overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 13px 18px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--panel); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: var(--panel-2); }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.pill.ok { background: rgba(34,197,94,.15); color: #4ade80; }
.pill.no { background: rgba(239,68,68,.15); color: #f87171; }

/* Profile */
.profile-card { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.qr-box { background: #fff; padding: 14px; border-radius: 14px; width: 320px; height: 320px; display: grid; place-items: center; }
.qr-box img { width: 100%; height: 100%; }
.profile-info { flex: 1; min-width: 240px; }
.profile-status { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; margin-bottom: 10px; }
.profile-status .dot { width: 11px; height: 11px; border-radius: 50%; }
.profile-status.on .dot { background: var(--green); }
.profile-status.off .dot { background: var(--red); }
.profile-status.wait .dot { background: var(--amber); }
.kv { display: flex; gap: 8px; margin: 6px 0; font-size: 14.5px; }
.kv .k { color: var(--muted); width: 130px; }
.btn { border: 0; border-radius: 10px; padding: 11px 18px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.hint { margin-top: 14px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* Buttons (shared) */
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.block { width: 100%; display: block; }

/* ---- Auth-gated layout ---- */
.sidebar, .content { display: none; }
body.authed .sidebar { display: flex; }
body.authed .content { display: block; }

/* Login screen */
.login-screen { display: none; }
body.guest .login-screen {
  display: grid; place-items: center;
  position: fixed; inset: 0; z-index: 50;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2140, var(--bg));
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 30px 28px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-title { margin: 0 0 2px; font-size: 22px; }
.fld { display: block; margin: 16px 0 0; }
.fld > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.fld input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text); padding: 12px 14px; border-radius: 10px; font-size: 14.5px;
}
.fld input:focus { outline: none; border-color: var(--accent); }
.login-card .btn.block { margin-top: 22px; padding: 12px; }
.form-error { color: #f87171; font-size: 13px; margin-top: 12px; min-height: 0; }
.form-error:empty { margin-top: 0; }
.form-ok { color: #4ade80; font-size: 13px; margin-top: 12px; }
.form-ok:empty { margin-top: 0; }

/* Sidebar admin box */
.admin-box { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; }
.admin-id { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.admin-avatar {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: grid; place-items: center; font-weight: 700; text-transform: uppercase;
}
.admin-meta { min-width: 0; }
.admin-email { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-role { font-size: 11px; color: var(--muted); }

/* Settings */
.settings-card { max-width: 520px; margin-top: 22px; }
.fld-sep { margin: 22px 0 4px; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; border-top: 1px dashed var(--line); padding-top: 16px; }
.fld-sep.danger-sep { color: var(--amber); }
.settings-card .btn.primary { margin-top: 20px; }

@media (max-width: 860px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 24px 18px; }
  .sidebar { width: 74px; }
  .brand-name, .brand-sub, .nav-item span:last-child, .wa-pill span:last-child { display: none; }
  .admin-meta, .admin-box .btn span { display: none; }
}
