:root {
  --bg: #0f1520;
  --bg-card: #161e2c;
  --border: #263041;
  --text: #e6ebf2;
  --text-muted: #8996a8;
  --accent: #3ea6ff;
  --critical: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --success: #22c55e;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.error { color: var(--critical); }
.success { color: var(--success); }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 320px;
  text-align: center;
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.brand h1 { font-size: 20px; margin: 0; }
.brand-icon { font-size: 22px; }

input[type="text"], input[type="password"], input[type="number"], textarea, select {
  background: #0d1420;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 8px;
  font-size: 14px;
  width: 100%;
  font-family: inherit;
}

textarea { resize: vertical; }

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #071019; font-weight: 600; }
.btn-secondary { background: #223047; color: var(--text); }
.btn-danger { background: var(--critical); color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

/* ---- App shell ---- */
.app { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.topbar .brand strong { font-size: 15px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tab-btn {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 8px;
}
.tab-btn.active { background: #223047; color: var(--text); }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 800px) {
  .grid, .grid-2 { grid-template-columns: 1fr; }
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { margin: 0 0 10px 0; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.metric { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.bar { height: 6px; background: #223047; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); width: 0%; transition: width .3s; }
.bar-fill.warn { background: var(--warning); }
.bar-fill.crit { background: var(--critical); }

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #223047;
}
.badge.large { font-size: 14px; padding: 6px 14px; margin-bottom: 12px; }
.badge.ok { background: rgba(34,197,94,.15); color: var(--success); }
.badge.bad { background: rgba(239,68,68,.15); color: var(--critical); }
.badge.pending { background: rgba(245,158,11,.15); color: var(--warning); }

.kv td { padding: 3px 0; }
.kv td:first-child { color: var(--text-muted); width: 40%; }

.small-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.small-list-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  background: #101826;
  border-radius: 6px;
  font-size: 13px;
}

.toolbar { display: flex; gap: 10px; margin-bottom: 14px; align-items: center; }

.alerts-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: 8px;
  padding: 10px 14px;
}
.alert-item.critical { border-left-color: var(--critical); }
.alert-item.warning { border-left-color: var(--warning); }
.alert-item.info { border-left-color: var(--info); }
.alert-item .alert-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-muted); }
.alert-item .alert-title { font-weight: 600; margin: 4px 0 2px; }
.alert-item .alert-msg { color: var(--text); font-size: 13px; }

#settings-form { display: flex; flex-direction: column; gap: 14px; }
#settings-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
#settings-form label.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
#settings-form label.checkbox input { width: auto; }

.save-bar { display: flex; align-items: center; gap: 12px; padding: 10px 0 30px; }

.center-card { max-width: 480px; margin: 0 auto; text-align: center; }
#wa-qr-img { width: 260px; height: 260px; margin-top: 10px; border-radius: 8px; background: white; padding: 8px; }
#wa-connected-wrap { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.stat-row { display: flex; gap: 20px; }
.stat-row .stat-num { font-size: 22px; font-weight: 700; }
.stat-row .stat-label { font-size: 12px; color: var(--text-muted); }
