:root {
  --bg0: #06080f;
  --bg1: #0a0e1a;
  --bg2: #0d1222;
  --surface: #11182c;
  --surface2: #17203a;
  --line: rgba(148, 163, 255, 0.10);
  --line2: rgba(148, 163, 255, 0.20);
  --txt: #e9edf9;
  --txt2: #9aa4c4;
  --txt3: #5d698d;
  --violet: #7c6cff;
  --cyan: #43c6ff;
  --magenta: #ff5cf0;
  --gold: #f7c653;
  --green: #37d5a3;
  --red: #ff6b7a;
  --amber: #f5a94b;
  --grad: linear-gradient(135deg, #7c6cff 0%, #43c6ff 100%);
  --grad2: linear-gradient(135deg, #ff5cf0 0%, #7c6cff 100%);
  --radius: 16px;
  --radius-sm: 10px;
}

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

html, body { height: 100%; }

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg0);
  color: var(--txt);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(124, 108, 255, 0.18), transparent 60%),
    radial-gradient(700px 500px at 10% 110%, rgba(67, 198, 255, 0.12), transparent 60%),
    radial-gradient(600px 500px at 60% 50%, rgba(255, 92, 240, 0.06), transparent 60%);
  z-index: 0;
}

.app { display: grid; grid-template-columns: 236px 1fr; height: 100vh; position: relative; z-index: 1; }

/* ---------- sidebar ---------- */
.sidebar {
  background: rgba(10, 14, 26, 0.92);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 2px 8px 22px; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; background: var(--grad);
  display: grid; place-items: center; color: #fff; font-size: 18px;
  box-shadow: 0 8px 24px -8px rgba(124, 108, 255, 0.7);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: 1px; }
.brand-sub { font-size: 10.5px; color: var(--txt3); letter-spacing: 1.5px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--txt2); font-size: 14px;
  text-decoration: none; cursor: pointer; transition: all .16s ease;
  border: 1px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { color: var(--txt); background: rgba(148, 163, 255, 0.06); }
.nav-item.active {
  color: #fff; background: rgba(124, 108, 255, 0.14);
  border-color: rgba(124, 108, 255, 0.25);
}
.nav-item.active svg { color: var(--cyan); }

.sidebar-foot { margin-top: auto; padding: 12px 8px 2px; }
.core-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--txt2); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(55, 213, 163, 0.15); }
.dot.green { background: var(--green); box-shadow: 0 0 0 4px rgba(55, 213, 163, 0.15); }
.dot.gray { background: var(--txt3); box-shadow: none; }
.dot.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.version { margin-top: 10px; font-size: 11px; color: var(--txt3); padding-left: 2px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  background: rgba(10, 14, 26, 0.5);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 19px; font-weight: 700; }
.topbar p { font-size: 12.5px; color: var(--txt3); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.online-pill {
  display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--txt2);
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.demo-pill {
  display: none; align-items: center; gap: 7px; font-size: 12px; color: var(--amber);
  padding: 7px 12px; border: 1px solid rgba(245, 169, 75, 0.3); border-radius: 999px;
  background: rgba(245, 169, 75, 0.08);
}

.btn-primary {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 16px;
  background: var(--grad); color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  box-shadow: 0 10px 24px -10px rgba(124, 108, 255, 0.8);
  transition: transform .12s ease, box-shadow .12s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 30px -10px rgba(124, 108, 255, 0.9); }
.btn-ghost {
  padding: 9px 14px; background: var(--surface); color: var(--txt2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: all .15s ease;
}
.btn-ghost:hover { color: var(--txt); border-color: var(--line2); }

.content { flex: 1; overflow-y: auto; padding: 24px 28px 40px; }

.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--txt3); }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 10px; position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; top: -30px; right: -30px; width: 90px; height: 90px;
  border-radius: 50%; filter: blur(30px); opacity: .5;
}
.stat.cyan::after { background: var(--cyan); }
.stat.violet::after { background: var(--violet); }
.stat.magenta::after { background: var(--magenta); }
.stat.gold::after { background: var(--gold); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.stat-icon svg { width: 18px; height: 18px; }
.stat.cyan .stat-icon { background: rgba(67,198,255,.14); color: var(--cyan); }
.stat.violet .stat-icon { background: rgba(124,108,255,.16); color: #a99cff; }
.stat.magenta .stat-icon { background: rgba(255,92,240,.14); color: var(--magenta); }
.stat.gold .stat-icon { background: rgba(247,198,83,.14); color: var(--gold); }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.5px; }
.stat-label { font-size: 13px; color: var(--txt2); }
.stat-note { font-size: 11.5px; color: var(--txt3); }

.overview-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }

.flow-legend { display: flex; gap: 20px; margin-bottom: 14px; }
.flow-legend span { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--txt2); }
.flow-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.flow-bar { display: flex; height: 14px; border-radius: 8px; overflow: hidden; background: var(--bg2); }
.flow-bar div { height: 100%; transition: width .5s ease; }
.flow-bar .pending { background: var(--amber); }
.flow-bar .running { background: var(--cyan); }
.flow-bar .done { background: var(--green); }
.flow-counts { display: flex; gap: 24px; margin-top: 14px; }
.flow-counts div { display: flex; flex-direction: column; }
.flow-counts b { font-size: 20px; }
.flow-counts span { font-size: 12px; color: var(--txt3); }

.feed { display: flex; flex-direction: column; gap: 4px; }
.feed-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.feed-item:last-child { border-bottom: none; }
.feed-main { min-width: 0; }
.feed-title { font-size: 13px; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed-meta { font-size: 11.5px; color: var(--txt3); margin-top: 3px; }
.feed-star { font-size: 13px; font-weight: 700; color: var(--gold); white-space: nowrap; }
.empty { padding: 40px 10px; text-align: center; color: var(--txt3); font-size: 13px; }

/* ---------- tables ---------- */
.table-card { padding: 6px 0 0; overflow: hidden; }
.table-card .card-head { padding: 16px 20px 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .5px; text-transform: uppercase;
  color: var(--txt3); padding: 12px 20px; border-bottom: 1px solid var(--line);
}
tbody td { padding: 13px 20px; border-bottom: 1px solid var(--line); color: var(--txt2); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: rgba(148, 163, 255, 0.04); }
.mono { font-family: "SF Mono", "JetBrains Mono", ui-monospace, Consolas, monospace; font-size: 12px; color: var(--txt); }
.cell-strong { color: var(--txt); font-weight: 500; }
.prompt-cell { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.idle { color: var(--green); background: rgba(55,213,163,.10); }
.badge.running { color: var(--cyan); background: rgba(67,198,255,.10); }
.badge.pending { color: var(--amber); background: rgba(245,169,75,.10); }
.badge.done { color: var(--green); background: rgba(55,213,163,.10); }
.badge.failed { color: var(--red); background: rgba(255,107,122,.10); }
.badge.offline { color: var(--txt3); background: rgba(93,105,141,.12); }
.badge.timeout { color: var(--amber); background: rgba(245,169,75,.10); }

.tps { font-weight: 600; color: var(--cyan); }
.star-val { font-weight: 700; color: var(--gold); }
.battery { display: inline-flex; align-items: center; gap: 5px; }
.battery-bar { width: 34px; height: 10px; border-radius: 5px; background: var(--bg2); overflow: hidden; display: inline-block; }
.battery-bar i { display: block; height: 100%; background: var(--green); border-radius: 5px; }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: none; }
.setting-label { font-size: 13.5px; }
.setting-desc { font-size: 12px; color: var(--txt3); margin-top: 3px; }
.setting-value { font-size: 13px; color: var(--txt2); }

/* ---------- 管理 ---------- */
.admin-row { display: flex; gap: 10px; align-items: center; }
.admin-input {
  flex: 1; min-width: 120px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--txt); padding: 11px 13px; font-size: 13px;
  font-family: inherit; outline: none;
}
.admin-input:focus { border-color: rgba(124, 108, 255, 0.6); }
.admin-msg { min-height: 16px; margin-top: 8px; font-size: 12px; color: var(--red); }
.admin-msg.ok { color: var(--green); }
.admin-actions { display: flex; gap: 6px; }
.admin-actions button { padding: 5px 9px; font-size: 12px; }

/* ---------- 用户端登录 ---------- */
.login-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(6, 8, 15, 0.92);
  display: flex; align-items: center; justify-content: center;
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 380px; max-width: calc(100vw - 40px); background: var(--surface);
  border: 1px solid var(--line2); border-radius: 18px; padding: 28px;
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8);
}
.login-logo { height: 32px; display: block; margin-bottom: 18px; }
.login-card h2 { font-size: 19px; }
.login-card p { font-size: 12.5px; color: var(--txt3); margin: 6px 0 18px; }
.login-tabs {
  display: flex; gap: 6px; background: var(--bg2); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px; margin-bottom: 12px;
}
.login-tab {
  flex: 1; padding: 8px; border: none; background: none; color: var(--txt3);
  font-size: 13px; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.login-tab.active { background: var(--surface2); color: var(--txt); }
.login-card .admin-input { display: block; width: 100%; margin-bottom: 10px; }
.login-card .btn-primary { width: 100%; margin-top: 6px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(3, 5, 10, 0.65); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.show { display: flex; }
.modal {
  width: 520px; max-width: calc(100vw - 40px); background: var(--surface);
  border: 1px solid var(--line2); border-radius: 18px; padding: 24px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.8);
}
.modal h2 { font-size: 17px; margin-bottom: 4px; }
.modal p { font-size: 12.5px; color: var(--txt3); margin-bottom: 18px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--txt2); margin-bottom: 7px; }
.field textarea, .field input {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  color: var(--txt); padding: 12px 14px; font-size: 14px; font-family: inherit; resize: vertical;
}
.field textarea:focus, .field input:focus { outline: none; border-color: rgba(124,108,255,.6); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-result {
  margin-top: 14px; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px;
  background: rgba(55,213,163,.08); border: 1px solid rgba(55,213,163,.25); color: var(--green); display: none;
}

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-grid { grid-template-columns: 1fr; }
}

/* --- 星图 --- */
.starmap-card { margin-bottom: 16px; }
#starmap { width: 100%; height: 300px; display: block; border-radius: 12px;
  background: radial-gradient(ellipse at 50% 55%, rgba(30,44,70,.55) 0%, rgba(10,14,22,.15) 55%, transparent 78%); }
.starmap-legend { display: flex; gap: 18px; font-size: 11px; color: var(--txt3); margin-top: 8px; }
.starmap-legend i { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.starmap-legend .dot-online { background: #7ee7ff; box-shadow: 0 0 8px #43c6ff; }
.starmap-legend .dot-offline { background: #45506b; }
.starmap-legend .dot-link { background: transparent; border-top: 1px dashed #2f6f88; border-radius: 0; height: 0; width: 12px; }
@media (max-width: 900px) { #starmap { height: 220px; } }

/* --- 管理员令牌栏 --- */
.auth-bar { display: none; align-items: center; gap: 10px; margin: 0 0 16px;
  padding: 12px 16px; border-radius: 12px; background: rgba(245,169,75,.08);
  border: 1px solid rgba(245,169,75,.35); font-size: 12px; color: var(--txt2); }
.auth-bar.show { display: flex; }
.auth-bar-title { color: var(--amber); white-space: nowrap; }
.auth-bar input { flex: 0 0 320px; padding: 7px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface2); color: var(--txt); font-size: 12px; }
.auth-bar button { padding: 7px 16px; font-size: 12px; }
.auth-bar-msg { color: var(--red); font-size: 11px; }
