:root {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface2: #1e293b;
  --border: #2d3748;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --accent: #6366f1;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }
.logo span { color: var(--accent); }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-red { background: rgba(239,68,68,.15); color: var(--red); }
.badge-green { background: rgba(34,197,94,.12); color: var(--green); }
.badge-amber { background: rgba(245,158,11,.12); color: var(--amber); }

#conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--amber);
  transition: background .3s;
}
#conn-dot.connected { background: var(--green); }
#conn-dot.disconnected { background: var(--red); }

.btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: opacity .15s;
}
.btn:hover { opacity: .85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger { background: rgba(239,68,68,.15); color: var(--red); border: 1px solid rgba(239,68,68,.2); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ── Layout ── */
main {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Alert bar ── */
#alert-bar {
  display: none;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 18px;
}
#alert-bar.has-alerts { display: block; }

.alert-bar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--red);
  margin-bottom: 6px;
}

.alert-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 13px;
  border-top: 1px solid rgba(239,68,68,.1);
}
.alert-item:first-child { border-top: none; }

/* ── Site section ── */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
}

.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.site-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
}

.site-name { font-weight: 600; font-size: 15px; }
.site-location { font-size: 12px; color: var(--text-muted); }
.site-actions { margin-left: auto; display: flex; gap: 6px; }

/* ── Device rows ── */
.device-list { padding: 10px 0; }

.device-row {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  transition: background .15s;
}
.device-row:last-child { border-bottom: none; }
.device-row:hover { background: rgba(255,255,255,.03); }

.device-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border);
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,.5); }
.status-dot.offline { background: var(--red); }

.device-name { font-weight: 500; font-size: 14px; }
.device-model { font-size: 11px; color: var(--text-muted); margin-left: 4px; }
.device-ip { font-size: 11px; color: var(--text-muted); margin-left: auto; font-family: monospace; }
.device-mac { font-size: 10px; color: var(--text-muted); font-family: monospace; opacity: 0.7; }

.device-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 20px;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.preset-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(99,102,241,.12);
  color: #a5b4fc;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

/* ── Level meters ── */
.meters {
  display: flex;
  gap: 8px;
  padding-left: 20px;
  margin-top: 6px;
}

.meter-group { display: flex; flex-direction: column; gap: 3px; }
.meter-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }

.meter-bars { display: flex; gap: 2px; }

.meter-bar {
  display: flex;
  flex-direction: column-reverse;
  gap: 1px;
  width: 12px;
}

.meter-seg {
  height: 4px;
  border-radius: 1px;
  background: var(--border);
  transition: background .15s;
}
.meter-seg.lit-green { background: var(--green); }
.meter-seg.lit-amber { background: var(--amber); }
.meter-seg.lit-red { background: var(--red); }

.last-seen { font-size: 11px; color: var(--text-muted); }

/* ── No devices ── */
.no-devices {
  padding: 20px 16px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab {
  padding: 8px 18px;
  border-radius: 6px 6px 0 0;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── History table ── */
.history-table-wrap { overflow-x: auto; }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th {
  text-align: left;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.history-table td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  color: var(--text);
}
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: rgba(255,255,255,.03); }

.badge-dim { background: rgba(148,163,184,.1); color: var(--text-muted); }
.mono { font-family: monospace; font-size: 12px; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.toolbar-title { font-size: 16px; font-weight: 600; }

/* ── Modal ── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 420px;
  max-width: 95vw;
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--accent); }

/* ── Token display ── */
.token-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
  color: #a5b4fc;
}

/* ── Summary bar ── */
.summary-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  min-width: 120px;
}
.stat-num { font-size: 24px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .5px; }
.stat-num.red { color: var(--red); }
.stat-num.green { color: var(--green); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 18px; }

/* ── Push toggle ── */
#push-btn { font-size: 12px; }

/* ── Responsive ── */
@media (max-width: 600px) {
  main { padding: 12px; }
  .sites-grid { grid-template-columns: 1fr; }
  header { flex-wrap: wrap; }
}
