/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface-2:  #1c2128;
  --border:     #30363d;
  --border-2:   #21262d;
  --text:       #e6edf3;
  --text-muted: #8b949e;
  --text-dim:   #484f58;
  --green:      #3fb950;
  --green-bg:   rgba(63,185,80,.12);
  --yellow:     #d29922;
  --yellow-bg:  rgba(210,153,34,.12);
  --red:        #f85149;
  --red-bg:     rgba(248,81,73,.12);
  --blue:       #58a6ff;
  --blue-bg:    rgba(88,166,255,.12);
  --purple:     #a78bfa;
  --purple-bg:  rgba(167,139,250,.12);
  --accent:     #238636;
  --accent-hover: #2ea043;
  --radius:     8px;
  --sidebar-w:  220px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:         #f6f8fa;
    --surface:    #ffffff;
    --surface-2:  #f6f8fa;
    --border:     #d0d7de;
    --border-2:   #e1e4e8;
    --text:       #1f2328;
    --text-muted: #57606a;
    --text-dim:   #afb8c1;
  }
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
svg { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; width: 16px; height: 16px; flex-shrink: 0; }
a { color: var(--blue); text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: 14px; border: none; background: none; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--text); }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--text);
}
.sidebar-logo svg { width: 22px; height: 22px; color: var(--green); }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-muted);
  border-radius: 0;
  transition: color .15s, background .15s;
  font-size: 13.5px;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { color: var(--text); background: var(--surface-2); border-left-color: var(--green); }
.nav-item svg { width: 15px; height: 15px; }

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.conn-dot.conn-ok      { background: var(--green); box-shadow: 0 0 4px var(--green); }
.conn-dot.conn-error   { background: var(--red); }
.conn-dot.conn-unknown { background: var(--text-dim); }
.conn-label { flex: 1; color: var(--text-muted); }

/* ── Content ─────────────────────────────────────────────────────────────────── */
#content {
  overflow-y: auto;
  background: var(--bg);
}
.page { padding: 28px 32px; max-width: 1200px; }

/* ── Page header ─────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -.3px; margin-bottom: 2px; }
.page-sub   { color: var(--text-muted); font-size: 13px; }

/* ── Stat grid ───────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stat-card .stat-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-card.green .stat-value { color: var(--green); }
.stat-card.yellow .stat-value { color: var(--yellow); }
.stat-card.red    .stat-value { color: var(--red); }
.stat-card.blue   .stat-value { color: var(--blue); }

/* ── Client cards (fleet view) ───────────────────────────────────────────────── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.client-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.client-card:hover { border-color: var(--blue); transform: translateY(-1px); }
.client-card.status-ok      { border-left: 3px solid var(--green); }
.client-card.status-warn    { border-left: 3px solid var(--yellow); }
.client-card.status-down    { border-left: 3px solid var(--red); }
.client-card.status-unknown { border-left: 3px solid var(--border); }

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-name   { font-weight: 600; font-size: 14px; }
.card-host   { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.card-metrics { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 14px; }
.metric-item  { display: flex; flex-direction: column; gap: 3px; }
.metric-label { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.metric-value { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }

.card-footer { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; }
.card-version { font-size: 11px; font-family: monospace; color: var(--text-muted); }
.card-ago     { font-size: 11px; color: var(--text-dim); }

/* ── Progress bar ────────────────────────────────────────────────────────────── */
.bar-wrap { background: var(--border); border-radius: 4px; height: 5px; overflow: hidden; margin-top: 3px; }
.bar      { height: 100%; border-radius: 4px; transition: width .3s; }
.bar.green  { background: var(--green); }
.bar.yellow { background: var(--yellow); }
.bar.red    { background: var(--red); }

/* ── Table ───────────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.table-title  { font-weight: 600; font-size: 14px; }
table { width: 100%; border-collapse: collapse; }
thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-muted); padding: 10px 18px; text-align: left;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  white-space: nowrap;
}
tbody td {
  padding: 12px 18px; border-bottom: 1px solid var(--border-2);
  font-size: 13px; vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,.02); }
.td-mono { font-family: monospace; font-size: 12px; }
.td-muted { color: var(--text-muted); font-size: 12px; }
.td-actions { display: flex; gap: 6px; }

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-grey   { background: rgba(139,148,158,.12); color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 6px;
  font-weight: 500; font-size: 13px; transition: background .15s, opacity .15s;
  border: 1px solid var(--border);
  cursor: pointer;
}
.btn-primary  { background: var(--accent);  border-color: var(--accent); color: white; }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger   { background: var(--red-bg); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(248,81,73,.25); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid transparent;
  color: var(--text-muted); transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group   { margin-bottom: 16px; }
.form-label   { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.form-input   {
  width: 100%; padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  transition: border-color .15s;
  outline: none;
}
.form-input:focus { border-color: var(--blue); }
.form-input::placeholder { color: var(--text-dim); }
.form-row  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ── Auth gate ───────────────────────────────────────────────────────────────── */
#auth-gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.auth-card {
  width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 36px 32px; text-align: center;
}
.auth-logo { margin-bottom: 16px; }
.auth-logo svg { width: 40px; height: 40px; color: var(--green); }
.auth-card h1 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.auth-sub  { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
#token-input {
  width: 100%; padding: 10px 14px; margin-bottom: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px; outline: none;
}
#token-input:focus { border-color: var(--blue); }
.auth-hint { font-size: 11px; color: var(--text-dim); margin-top: 16px; }
.auth-hint code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-size: 11px; }

/* ── Modal ───────────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
#modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--border);
}
#modal-title { font-size: 15px; font-weight: 600; }
#modal-body  { padding: 20px 22px 22px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 16px;
  font-size: 13px; max-width: 320px;
  display: flex; align-items: center; gap: 8px;
  animation: slideIn .2s ease;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--blue); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ── Detail panel (client) ───────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 13px; margin-bottom: 20px; }
.detail-item .dl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.detail-item .dv { font-weight: 500; }

.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: 10px; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ── Heartbeat chart ─────────────────────────────────────────────────────────── */
.hb-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.hb-item {
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: 6px; padding: 8px 12px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px;
}
.hb-time { color: var(--text-muted); }
.hb-metrics { display: flex; gap: 12px; font-variant-numeric: tabular-nums; }

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; align-items: center; justify-content: center; padding: 60px; }

/* ── Utils ───────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-mono  { font-family: monospace; font-size: 12px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
