:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1c2430;
  --muted: #8a93a6;
  --accent: #4f8cff;
  --accent-d: #3a76e8;
  --green: #34c759;
  --red: #ff6b6b;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
header {
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px; height: 54px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
header .logo { font-weight: 700; font-size: 16px; color: var(--accent); }
header nav { display: flex; gap: 4px; }
header nav a {
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
header nav a:hover { background: var(--bg); color: var(--text); }
header nav a.active { background: var(--accent); color: #fff; }
header .spacer { flex: 1; }
header .status { color: var(--muted); font-size: 12px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.card .k { color: var(--muted); font-size: 12px; }
.card .v { font-size: 28px; font-weight: 700; margin-top: 6px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 14px; font-size: 15px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.row > * { flex: none; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--text); font-family: inherit;
}
textarea { min-height: 160px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.field { margin-bottom: 12px; }

button {
  padding: 8px 14px; border: 0; border-radius: 8px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px;
}
button:hover { background: var(--accent-d); }
button.ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
button.danger { background: var(--red); }
button.sm { padding: 4px 10px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: #fafbfd; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge.on { background: #e6f8ec; color: var(--green); }
.badge.off { background: #fdeaea; color: var(--red); }
.badge.g { background: #eef2fb; color: var(--accent); }

.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 16px; }
.chart-box { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.chart-box h4 { margin: 0 0 6px; font-size: 14px; }
.chart-box .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.chart-box canvas { width: 100%; height: 240px; }
.chart-box.wide { grid-column: 1 / -1; } /* full-width panel: host cards wrap across the row */
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.legend span .dot, .chart-tip .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }

.chart-tip {
  position: fixed; pointer-events: none; z-index: 100;
  background: rgba(28,36,48,.94); color: #fff; padding: 8px 10px; border-radius: 8px;
  font-size: 12px; line-height: 1.5; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.chart-tip .tip-t { color: #cfd6e2; margin-bottom: 4px; }

.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px; cursor: pointer;
  color: var(--text); font-size: 13px; background: #fff;
}
.checks label.sel { background: var(--accent); color: #fff; border-color: var(--accent); }
.checks input { display: none; }

/* per-host compact tiles (multi-value gauge metrics, e.g. per-GPU).
   Hosts flow as small cards; each card packs its sub-items (GPUs) into a tile grid. */
.bars { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-top: 8px; }
.bar-host { background: #fafbfd; border: 1px solid var(--border); border-radius: 10px; padding: 9px 10px; }
.bar-host-name { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text); }
.host-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.host-title { word-break: break-all; }
.lock { flex: none; cursor: pointer; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 6px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; user-select: none; }
.lock:hover { background: var(--accent-d); }
.host-avg { flex: none; font-size: 11px; font-weight: 600; color: #fff; padding: 1px 7px; border-radius: 10px; font-variant-numeric: tabular-nums; }
.host-ip { font-size: 11px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; margin: 2px 0 7px; }

/* environment tags */
.env-badge { flex: none; cursor: pointer; font-size: 11px; font-weight: 600; color: #fff; padding: 1px 8px; border-radius: 10px; white-space: nowrap; user-select: none; }
.env-badge.env-none { background: transparent; color: var(--muted); border: 1px dashed var(--border); }
.env-badge.env-none:hover { color: var(--accent); border-color: var(--accent); }
.env-menu { position: fixed; z-index: 120; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.14); padding: 5px; min-width: 120px; }
.env-menu-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; }
.env-menu-item:hover { background: var(--bg); }
.env-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* SSH credential reveal table */
.sec-table { width: 100%; border-collapse: collapse; }
.sec-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.sec-table td.sk { width: 70px; color: var(--muted); }
.sec-table td.sv { font-family: ui-monospace, Menlo, monospace; word-break: break-all; user-select: all; }
.bar-cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 5px; }
.bar-cell { background: #fff; border: 1px solid var(--border); border-radius: 7px; padding: 4px 6px; }
.cell-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; gap: 3px; }
.cell-head b { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--text); }
.cell-head span { font-variant-numeric: tabular-nums; font-size: 11px; color: var(--muted); white-space: nowrap; }
.cell-bar { height: 5px; background: #e6eaf1; border-radius: 3px; overflow: hidden; }
.cell-bar-fill { height: 100%; border-radius: 3px; transition: width .3s ease; min-width: 2px; }

/* busiest-GPU leaderboard on the overview page */
.busy-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.busy-row:last-child { border-bottom: 0; }
.busy-rank { width: 22px; flex: none; text-align: center; color: var(--muted); font-size: 12px; font-weight: 700; }
.busy-host { width: 220px; flex: none; font-size: 13px; font-family: ui-monospace, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.busy-track { flex: 1; height: 10px; background: #eef1f6; border-radius: 5px; overflow: hidden; }
.busy-fill { height: 100%; border-radius: 5px; transition: width .3s ease; min-width: 2px; }
.busy-val { width: 48px; flex: none; text-align: right; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; opacity: 0; transition: opacity .2s; z-index: 200;
}
.toast.show { opacity: 1; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none; align-items: center; justify-content: center; z-index: 50; }
.modal-bg.show { display: flex; }
.modal { background: #fff; border-radius: 14px; padding: 22px; width: 640px; max-width: 92vw; max-height: 90vh; overflow: auto; }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
