:root {
  --bg: #0f1117;
  --bg-soft: #161a23;
  --bg-card: #1b202c;
  --border: #2a3040;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --primary: #4f8cff;
  --primary-hover: #6ba0ff;
  --green: #3fbf7f;
  --red: #ef5b6d;
  --yellow: #e8b84b;
  --radius: 10px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

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

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--red); }

button { font: inherit; cursor: pointer; }
input, select {
  font: inherit;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus { border-color: var(--primary); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
label input { margin-top: 4px; }
pre {
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

/* ---------- login ---------- */

#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
}
.login-card h1 { font-size: 24px; margin-bottom: 4px; }
.login-card form { margin-top: 20px; }

/* ---------- layout ---------- */

#app-view { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { font-size: 20px; font-weight: 700; padding: 4px 10px 18px; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}
.nav-btn:hover { background: var(--bg-card); color: var(--text); }
.nav-btn.active { background: var(--bg-card); color: var(--primary); font-weight: 600; }
.sidebar-footer { padding: 10px 6px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
#current-user { font-size: 13px; }

#main { flex: 1; padding: 24px; max-width: 1100px; }
.view > h2 { font-size: 20px; margin-bottom: 16px; }

/* ---------- overview ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat-card .label { color: var(--muted); font-size: 12px; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.overview-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) { .overview-grid { grid-template-columns: 1fr; } }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { width: 100%; height: 100%; }

.server-card .status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
}
.badge.running { color: var(--green); border-color: var(--green); }
.badge.stopped { color: var(--muted); }
.badge.error { color: var(--red); border-color: var(--red); }
.badge.starting, .badge.stopping { color: var(--yellow); border-color: var(--yellow); }
.server-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.server-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- table ---------- */

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.toolbar .search { max-width: 260px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { color: var(--muted); font-size: 12px; font-weight: 500; }
td .uuid { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 6px; }
.switch { position: relative; display: inline-block; width: 38px; height: 20px; }
.switch input { display: none; }
.slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: 0.2s;
}
.slider::before {
  content: ""; position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: 0.2s;
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(18px); }

.empty { color: var(--muted); text-align: center; padding: 40px 0; }

/* ---------- settings ---------- */

.settings-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; align-items: start; }
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }
.form-group { margin-bottom: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.key-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  margin-bottom: 10px;
}
.keys-section { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- logs ---------- */

.log-box {
  background: #0a0c11;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  max-height: 70vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.5;
}

/* ---------- modal & toast ---------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 440px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow: auto;
  padding: 22px;
}
.modal h3 { margin-bottom: 16px; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.qr-wrap { text-align: center; }
.qr-wrap img { width: 260px; height: 260px; border-radius: 8px; background: #fff; padding: 8px; }
.qr-link { margin: 12px 0; text-align: left; }
.qr-link pre { font-size: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px; }

#toast-root { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.35);
  animation: slidein 0.2s ease;
}
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 720px) {
  #app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  .sidebar nav { flex-direction: row; }
  .sidebar-footer { border: none; }
  #main { padding: 16px; }
}
