/* ── Reset & design tokens ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0a0a0a;
  --surface:   #111111;
  --surface2:  #191919;
  --surface3:  #222222;
  --border:    #272727;
  --border2:   #333333;
  --text:      #e8e8e8;
  --text-dim:  #555555;
  --text-mid:  #888888;
  --accent:    #e8e8e8;   /* primary button bg */
  --accent-fg: #0a0a0a;  /* primary button text */
  --danger:    #666666;
  --radius:    6px;
  --sidebar-w: 200px;
  --font:      'Inter', system-ui, sans-serif;
  --mono:      'JetBrains Mono', 'Courier New', monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text-mid); text-decoration: none; }
a:hover { color: var(--text); }

iconify-icon { vertical-align: middle; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.brand-dot {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--text);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-dot iconify-icon { color: var(--bg); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 13px;
  transition: all .15s;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link.active { color: var(--text); background: var(--surface2); }

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.btn-logout {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px;
  transition: all .15s;
  width: 100%;
}
.btn-logout:hover { background: var(--surface2); color: var(--text); }

/* ── Main content ───────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  max-width: 1200px;
}

/* ── Stats bar ──────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  font-weight: 600;
}
.stat-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--mono);
}

/* ── Sections ───────────────────────────────────────────────────────────── */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.section-header h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-mid);
}

/* ── Add forms ──────────────────────────────────────────────────────────── */
.add-form {
  padding: 14px 18px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  animation: slideDown .12s ease;
}
.add-form.hidden { display: none; }

.inline-form {
  padding: 12px 16px;
  background: var(--surface2);
  border-top: 1px solid var(--border);
  animation: slideDown .12s ease;
}
.inline-form.hidden { display: none; }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}
.field input, .field select {
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--font);
  min-width: 130px;
  transition: border-color .15s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--text-mid);
}
.field input::placeholder { color: var(--text-dim); }

.self-end { align-self: flex-end; }

/* ── Search bar ─────────────────────────────────────────────────────────── */
.search-bar {
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.search-bar input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font);
  transition: border-color .15s;
}
.search-bar input:focus { outline: none; border-color: var(--text-mid); }
.search-bar input::placeholder { color: var(--text-dim); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}
.data-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
  padding: 9px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover { background: var(--surface2); }
.data-table tbody tr:last-child td { border-bottom: none; }

.row-disabled td { opacity: .38; }
.peer-name { font-weight: 500; display: flex; align-items: center; gap: 7px; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--text-mid); }
.dim  { color: var(--text-dim); font-size: 12px; }
.empty-row {
  color: var(--text-dim);
  font-style: italic;
  padding: 20px 18px;
  font-size: 13px;
}

/* ── Status dots ────────────────────────────────────────────────────────── */
.dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-on  { background: var(--text); }
.dot-off { background: var(--text-dim); }

/* ── Badges / chips ─────────────────────────────────────────────────────── */
.badge-note {
  color: var(--text-dim);
  cursor: help;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
}
.chip {
  display: inline-block;
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
}
.chip-on  { background: var(--surface3); color: var(--text); border: 1px solid var(--border2); }
.chip-off { background: transparent; color: var(--text-dim); border: 1px solid var(--border); }

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font);
  border: none;
  cursor: pointer;
  transition: all .13s;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover { opacity: .88; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border2);
  color: var(--text-mid);
}
.btn-ghost:hover { border-color: var(--text-mid); color: var(--text); background: var(--surface2); }

.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 14px;
  transition: all .13s;
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border);
}
.btn-icon-danger:hover {
  color: var(--text);
  border-color: var(--border2);
  background: var(--surface3);
}

.actions { display: flex; gap: 2px; }

/* ── Progress bar ───────────────────────────────────────────────────────── */
.progress-bar {
  height: 3px;
  background: var(--surface3);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 3px;
}
.progress-fill { height: 100%; border-radius: 2px; transition: width .4s ease; }
.fill-ok     { background: var(--text-mid); }
.fill-warn   { background: var(--text); }
.fill-danger { background: var(--text); }

/* ── Alert ──────────────────────────────────────────────────────────────── */
.alert {
  padding: 9px 14px;
  border-radius: var(--radius);
  margin-bottom: 14px;
  font-size: 13px;
  border: 1px solid var(--border2);
  color: var(--text-mid);
}

/* ── Collapsible peer groups ─────────────────────────────────────────────── */
.peer-group { border-bottom: 1px solid var(--border); }
.peer-group:last-child { border-bottom: none; }

.peer-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.peer-group-header:hover { background: var(--surface2); }
.peer-group-header .group-title { font-weight: 500; font-size: 13px; }

.group-chevron {
  color: var(--text-dim);
  transition: transform .18s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.peer-group.open .group-chevron { transform: rotate(90deg); }

.group-meta {
  margin-left: 4px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
}
.group-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.peer-group-body { display: none; }
.peer-group.open .peer-group-body { display: block; }

/* ── Login page ─────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-logo {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: var(--text);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.login-logo iconify-icon { color: var(--bg); font-size: 20px; }
.login-title { font-size: 18px; font-weight: 600; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 4px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form .field { width: 100%; }
.login-form .field input { width: 100%; padding: 9px 12px; }

/* ── QR modal ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 24px;
  min-width: 260px;
  text-align: center;
  position: relative;
  animation: popIn .16s ease;
}
@keyframes popIn {
  from { transform: scale(.94); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal-close {
  position: absolute; top: 10px; right: 12px;
  background: none; border: none; color: var(--text-dim);
  font-size: 16px; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-box h3 { margin-bottom: 14px; font-size: 14px; font-weight: 600; }
.modal-box img { max-width: 220px; border-radius: 6px; display: block; margin: 0 auto 14px; background: #fff; }
.modal-actions { display: flex; justify-content: center; gap: 8px; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: 14px; }
  .stats-bar { gap: 8px; }
  .form-row { flex-direction: column; }
}
