:root {
  --bg: #090b10;
  --bg-2: #0d1017;
  --panel: #11151d;
  --panel-2: #161b25;
  --line: #1f2633;
  --line-2: #2a3242;
  --text: #e4e7ee;
  --muted: #8b93a5;
  --faint: #5d6577;
  --accent: #8b9bff;
  --accent-2: #4fd1c5;
  --ok: #3ddc97;
  --warn: #f5b84a;
  --bad: #f87171;
  --radius: 12px;
  --mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans CJK SC", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- buttons & fields */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line-2); border-radius: 9px;
  background: var(--panel-2); cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: #1c2230; border-color: #364055; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary {
  background: linear-gradient(135deg, #8b9bff, #6c7cf5); border-color: transparent; color: #0b0e17; font-weight: 600;
}
.btn-primary:hover { background: linear-gradient(135deg, #9daaff, #7b8af7); border-color: transparent; }
.btn-danger { color: var(--bad); border-color: #4a2a2e; background: #1d1316; }
.btn-danger:hover { background: #2a1519; border-color: #6b3036; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; height: 42px; font-size: 15px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.link-btn { border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.link-btn:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; color: var(--muted); }
.field em { font-style: normal; color: var(--faint); margin-left: 6px; }
.field input, .field textarea {
  width: 100%; padding: 9px 12px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 9px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px #8b9bff26; }
.form-error { min-height: 20px; margin: 0 0 10px; color: var(--bad); font-size: 13px; }

/* ---------- brand */
.brand { display: flex; align-items: center; gap: 11px; }
.brand b { display: block; font-size: 15px; letter-spacing: .2px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.logo {
  width: 32px; height: 32px; flex: none; border-radius: 9px;
  background: url(/static/favicon.svg) center/cover;
  box-shadow: 0 4px 18px #8b9bff40;
}
.brand-lg .logo { width: 42px; height: 42px; border-radius: 12px; }
.brand-lg b { font-size: 19px; }

/* ---------- login */
.login-body { display: grid; place-items: center; min-height: 100vh; overflow: hidden; }
.login-glow {
  position: fixed; inset: -30%; pointer-events: none;
  background:
    radial-gradient(40% 35% at 30% 30%, #8b9bff1f, transparent 70%),
    radial-gradient(35% 30% at 70% 70%, #4fd1c51a, transparent 70%);
}
.login-card {
  position: relative; width: min(400px, calc(100vw - 32px));
  padding: 32px 30px 22px;
  background: #11151dcc; backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 30px 80px #0008;
}
.login-card .brand { margin-bottom: 26px; }
.login-foot { margin: 18px 0 0; text-align: center; color: var(--faint); font-size: 12px; }

/* ---------- app layout */
.app-body { display: flex; height: 100vh; overflow: hidden; }
#sidebar {
  width: 268px; flex: none; display: flex; flex-direction: column;
  background: var(--bg-2); border-right: 1px solid var(--line);
}
#sidebar > .brand { padding: 18px 18px 14px; }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px 6px 18px; color: var(--faint); font-size: 12px; letter-spacing: .5px;
}
.acct-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.group-label { padding: 12px 10px 4px; color: var(--faint); font-size: 11.5px; }
.acct {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px 8px 10px; border-radius: 9px; cursor: pointer;
  transition: background .12s;
}
.acct:hover { background: var(--panel); }
.acct.active { background: var(--panel-2); }
.acct-text { flex: 1; min-width: 0; }
.acct-text b { display: block; font-weight: 500; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-text small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct .icon-btn { opacity: 0; }
.acct:hover .icon-btn { opacity: 1; }

.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--faint); }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px #3ddc9722; }
.dot.connecting, .dot.starting, .dot.disconnected { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.offline { background: var(--bad); }
.dot.exited { background: var(--faint); }
@keyframes pulse { 50% { opacity: .35; } }

.side-foot { padding: 14px 18px; border-top: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.avatar {
  width: 26px; height: 26px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #0b0e17;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.me-email { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-actions { display: flex; gap: 16px; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tabbar {
  display: flex; align-items: center; gap: 6px;
  height: 46px; flex: none; padding: 0 10px;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
}
.tabs { flex: 1; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; align-items: center; height: 100%; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; flex: none;
  height: 32px; padding: 0 8px 0 12px; max-width: 240px;
  border: 1px solid transparent; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13px;
}
.tab:hover { background: var(--panel); color: var(--text); }
.tab.active { background: var(--panel-2); border-color: var(--line-2); color: var(--text); }
.tab .tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .tab-x { width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; color: var(--faint); }
.tab .tab-x:hover { background: #ffffff14; color: var(--text); }
.tab.overview-tab { padding-right: 12px; }
.net-badge { flex: none; padding: 3px 10px; border-radius: 99px; background: #3a2a10; color: var(--warn); font-size: 12px; }

#panes { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; }

/* ---------- overview */
.overview { overflow-y: auto; padding: 26px 28px 40px; }
.ov-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; gap: 16px; }
.ov-head h1 { margin: 0 0 2px; font-size: 22px; font-weight: 650; letter-spacing: .2px; }
.ov-head p { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), #0f131a);
  border: 1px solid var(--line);
  transition: border-color .15s;
}
.card:hover { border-color: var(--line-2); }
.card-head { display: flex; align-items: center; gap: 12px; }
.card-head .dot { width: 10px; height: 10px; }
.card-head .t { flex: 1; min-width: 0; }
.card-head b { display: block; font-size: 15px; font-weight: 600; }
.card-head small { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.pill { padding: 2px 10px; border-radius: 99px; font-size: 12px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-2); white-space: nowrap; }
.pill.online { color: var(--ok); border-color: #1f4a39; background: #0f2219; }
.pill.connecting { color: var(--warn); border-color: #4a3a1a; background: #21190b; }
.pill.offline { color: var(--bad); border-color: #4a2026; background: #22100f; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 12.5px; }
.card-meta span { display: inline-flex; gap: 5px; }
.card-meta i { font-style: normal; color: var(--faint); }
.card-error { padding: 9px 12px; border-radius: 9px; background: #1d1214; border: 1px solid #3a2026; color: #f3a6a6; font-size: 12.5px; word-break: break-word; }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.metric { min-width: 0; padding: 9px 11px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); }
.metric-top { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; margin-bottom: 6px; }
.metric label { color: var(--muted); font-size: 12px; white-space: nowrap; }
.metric-top b { font-family: var(--mono); font-size: 15px; font-weight: 600; }
.metric .v { margin-top: 6px; color: var(--faint); font-family: var(--mono); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 5px; border-radius: 99px; background: #1d2330; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent-2), var(--accent)); transition: width .4s; }
.bar.hot > i { background: linear-gradient(90deg, var(--warn), var(--bad)); }

.gpus { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gpu { padding: 8px 10px; border-radius: 9px; background: var(--bg-2); border: 1px solid var(--line); font-size: 12px; }
.gpu-top { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); margin-bottom: 5px; }
.gpu-top b { color: var(--text); font-weight: 500; font-family: var(--mono); }
.gpu-sub { display: flex; justify-content: space-between; color: var(--faint); font-family: var(--mono); font-size: 11px; margin-top: 5px; }
.gpu-name { color: var(--faint); font-size: 11.5px; margin-top: -4px; }
.card-actions { display: flex; gap: 8px; margin-top: auto; }

.empty { padding: 60px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius); }

/* ---------- terminal */
.term-pane { display: flex; flex-direction: column; background: #0b0e14; }
.term-toolbar {
  display: flex; align-items: center; gap: 10px; flex: none;
  height: 40px; padding: 0 12px;
  border-bottom: 1px solid var(--line); background: var(--bg-2); font-size: 12.5px;
}
.term-toolbar b { font-weight: 600; font-size: 13px; }
.term-toolbar .t-meta { color: var(--muted); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-toolbar .t-tools { display: flex; gap: 6px; }
.term-host { flex: 1; min-height: 0; padding: 8px 4px 4px 12px; }
.term-host .xterm { height: 100%; }
.term-host .xterm-viewport { scrollbar-width: thin; scrollbar-color: #2a3242 transparent; }

/* ---------- dialogs */
.dialog {
  width: min(620px, calc(100vw - 24px)); padding: 24px 24px 18px;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 16px;
  box-shadow: 0 40px 100px #000a;
}
.dialog-sm { width: min(420px, calc(100vw - 24px)); }
.dialog::backdrop { background: #04060acc; backdrop-filter: blur(3px); }
.dialog h2 { margin: 0 0 18px; font-size: 17px; font-weight: 600; }
.dialog-actions { display: flex; gap: 8px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }

/* ---------- toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  max-width: 380px; padding: 10px 14px; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line-2); box-shadow: 0 12px 30px #0008;
  font-size: 13px; animation: slide .2s ease-out;
}
.toast.error { border-color: #5a2a30; color: #f6b0b0; }
.toast.ok { border-color: #1f4a39; color: #9eeac6; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

/* ---------- mobile */
.mobile-only { display: none; }
#scrim { display: none; }
@media (max-width: 820px) {
  .mobile-only { display: inline-grid; }
  #sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s; }
  body.menu-open #sidebar { transform: none; }
  body.menu-open #scrim { display: block; position: fixed; inset: 0; z-index: 30; background: #0008; }
  .overview { padding: 18px 14px 30px; }
  .cards { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .term-toolbar .t-meta { display: none; }
}
