:root {
  --blue: #2f7bff;
  --blue-dark: #1f63e0;
  --green: #22b662;
  --red: #e5484d;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e6eaf0;
  --text: #24292f;
  --muted: #8a94a0;
  --sidebar: #1c2430;
  --sidebar-w: 180px;
  --mobile-header-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100vh; }
body {
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; cursor: pointer; }
h1 { font-size: 22px; margin: 0; font-weight: 600; line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- layout & navigation ---------- */
.mobile-header {
  display: none;
  position: fixed; top: 0; left: 0; right: 0; height: var(--mobile-header-h);
  background: var(--sidebar); color: #fff;
  align-items: center; justify-content: space-between;
  padding: 0 16px; z-index: 40;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.mobile-header .brand { padding: 0; font-size: 18px; }

.nav-toggle {
  background: transparent; border: none; cursor: pointer; padding: 8px;
  display: flex; flex-direction: column; justify-content: space-around;
  width: 36px; height: 36px;
}
.nav-toggle .bar {
  width: 20px; height: 2px; background: #cfd8e3; border-radius: 2px;
  transition: all .2s;
}

.nav-backdrop {
  display: none;
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 45; opacity: 0; transition: opacity .25s ease;
}
.nav-backdrop.active { display: block; opacity: 1; }

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--sidebar); color: #cfd8e3;
  display: flex; flex-direction: column; padding: 14px 10px; z-index: 50;
  transition: transform .25s cubic-bezier(0.4, 0, 0.2, 1);
}
.brand { font-size: 17px; font-weight: 700; color: #fff; padding: 6px 10px 18px; }
.brand-dot { color: var(--blue); }
.side-link {
  display: flex; align-items: center; padding: 10px 12px; border-radius: 8px; color: #cfd8e3;
  margin-bottom: 2px; font-size: 14px;
}
.side-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-link.active { background: var(--blue); color: #fff; font-weight: 500; }
.ico { margin-right: 10px; font-size: 16px; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.12); padding-top: 8px; }
.side-user { padding: 6px 12px; font-size: 12px; color: #8fa0b3; word-break: break-all; }
.main { margin-left: var(--sidebar-w); padding: 26px 34px; max-width: 1200px; min-height: 100vh; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; flex-wrap: wrap; gap: 12px;
}
.page-title { display: flex; align-items: center; gap: 12px; }
.back { font-size: 20px; color: var(--text); padding: 4px; }

/* ---------- components ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: #fff;
  color: var(--text); border-radius: 8px; padding: 8px 16px; font-size: 14px;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap; touch-action: manipulation;
}
.btn:hover { border-color: var(--blue); color: var(--blue); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.danger, .mini.danger, .dropdown .danger { color: var(--red); }
.btn.danger { border-color: #f2c1c3; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 3px rgba(0,0,0,.02);
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.card-foot { margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* 表格支持横向滚动 */
.tbl-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tbl { width: 100%; border-collapse: collapse; min-width: 500px; }
.tbl th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: 13px;
  padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 12px 10px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: #fafbfd; }
.tname { font-weight: 600; margin-left: 6px; }
.arrow { font-size: 18px; color: var(--muted); padding: 4px; }
.empty { text-align: center; color: var(--muted); padding: 32px 0 !important; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: middle; flex-shrink: 0; }
.dot.on { background: var(--green); box-shadow: 0 0 0 3px rgba(34,182,98,.15); }
.dot.off { background: #c3ccd6; }
.badge {
  display: inline-block; font-size: 12px; border-radius: 6px; padding: 2px 8px; white-space: nowrap;
}
.badge-on { background: #e6f7ee; color: var(--green); }
.badge-off { background: #eef1f5; color: var(--muted); }
.badge-err { background: #fdebec; color: var(--red); cursor: help; }
.badge-lock { background: #fff7e6; color: #b8860b; }
.chip {
  display: inline-block; background: #eef4ff; color: var(--blue); font-size: 12px;
  border-radius: 5px; padding: 2px 8px; white-space: nowrap;
}
.chip-lock { background: #fff7e6; color: #b8860b; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search { display: flex; gap: 8px; flex: 1 1 240px; }
.search input {
  flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
  outline: none; font-size: 14px; min-width: 0;
}
.search input:focus { border-color: var(--blue); }
.tabs { display: flex; background: #eceff3; border-radius: 8px; padding: 3px; max-width: 100%; overflow-x: auto; }
.tabs a { padding: 6px 14px; border-radius: 6px; color: var(--text); white-space: nowrap; font-size: 13px; }
.tabs a.active { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.08); font-weight: 600; }

/* key-value table */
.kv { width: 100%; border-collapse: collapse; }
.kv th {
  text-align: left; color: var(--muted); font-weight: 400; width: 95px;
  padding: 8px 0; vertical-align: top; white-space: nowrap;
}
.kv td { padding: 8px 0; word-break: break-all; }
.kv-section { margin-top: 16px; color: var(--muted); font-size: 13px; }
.hint {
  margin-top: 8px; background: #f0f7ff; border: 1px solid #d4e7ff; color: #1c5fc0;
  padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.5;
}

.mini { font-size: 13px; margin-right: 8px; white-space: nowrap; display: inline-block; padding: 2px 0; }

/* install command */
.cmd-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.cmd {
  flex: 1; border: 1px solid var(--border); background: #f7f9fb; border-radius: 8px;
  padding: 8px 12px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; color: #333; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}

/* chart */
.chart { display: flex; gap: 8px; align-items: flex-end; height: 130px; padding-top: 10px; }
.chart-col { flex: 1; text-align: center; display: flex; flex-direction: column; height: 100%; min-width: 0; }
.chart-bar-wrap { flex: 1; display: flex; align-items: flex-end; width: 100%; }
.chart-bar { width: 100%; max-width: 24px; margin: 0 auto; background: var(--blue); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart-val { font-size: 10px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-day { font-size: 11px; color: var(--muted); }

/* dropdown */
.dropdown-wrap { position: relative; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: #fff;
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  min-width: 160px; z-index: 30; overflow: hidden; padding: 4px;
}
.dropdown a {
  display: block; padding: 10px 14px; color: var(--text); border-radius: 6px;
  white-space: nowrap; font-size: 14px;
}
.dropdown a:hover { background: #f2f6ff; }

/* modal */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,35,.5); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: #fff; border-radius: 12px; width: 560px; max-width: 100%;
  max-height: 85vh; overflow-y: auto; padding: 20px 22px; box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.modal-box h3 { margin: 0 0 14px; font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.field { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, .field select, .inline-form input, .inline-form select {
  display: block; width: 100%; margin-top: 4px; border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none; background: #fff;
}
.field input:focus, .inline-form input:focus { border-color: var(--blue); }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: 180px; display: inline-block; margin: 0; }
pre.cfg {
  background: #f6f8fa; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; overflow: auto; max-height: 40vh; white-space: pre-wrap; word-break: break-all;
}
.alert { border-radius: 8px; padding: 9px 12px; margin-bottom: 14px; font-size: 13px; }
.alert-err { background: #fdebec; color: var(--red); border: 1px solid #f6c9cb; }

/* login */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: linear-gradient(160deg, #1c2430 0%, #2b3a52 100%);
  padding: 16px;
}
.login-card {
  width: 360px; max-width: 100%; background: #fff; border-radius: 14px; padding: 30px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-brand { font-size: 20px; font-weight: 700; margin-bottom: 22px; }
.login-brand small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 6px; }

/* toast */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  background: #24292f; color: #fff; padding: 10px 20px; border-radius: 8px;
  z-index: 99; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: 90vw; text-align: center;
}
.toast.err { background: var(--red); }
.hidden { display: none !important; }

/* ==========================================
   📱 移动端响应式适配 (手机 / 小屏平板 <= 768px)
   ========================================== */
@media (max-width: 768px) {
  .mobile-header { display: flex; }
  .desktop-brand { display: none; }

  .sidebar {
    top: 0; bottom: 0; left: 0; width: 240px;
    transform: translateX(-100%);
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
    padding-top: 20px;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0;
    padding: calc(var(--mobile-header-h) + 16px) 14px 24px;
  }

  .page-head {
    margin-bottom: 14px;
    flex-direction: row;
    align-items: center;
  }
  h1 { font-size: 19px; }

  .grid2 { grid-template-columns: 1fr; gap: 14px; }
  .card { padding: 14px 14px; border-radius: 8px; margin-bottom: 14px; }

  /* 搜索与工具栏 */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .search { flex: 1 1 auto; width: 100%; }
  .tabs { width: 100%; justify-content: flex-start; }
  .tabs a { flex: 1; text-align: center; padding: 6px 8px; font-size: 12px; }

  /* 表单与按钮 */
  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }
  .inline-form input, .inline-form select, .inline-form button {
    width: 100% !important;
  }

  /* 命令复制行 */
  .cmd-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .cmd-row .cmd {
    width: 100%;
    font-size: 11px;
    padding: 8px 10px;
  }
  .cmd-row .btn {
    width: 100%;
    padding: 8px 0;
  }

  /* 弹窗适配 */
  .modal { padding: 12px; align-items: flex-end; }
  .modal-box {
    width: 100%;
    max-height: 85vh;
    border-radius: 12px 12px 8px 8px;
    padding: 16px 16px;
  }
  .modal-foot {
    flex-direction: column-reverse;
    gap: 8px;
  }
  .modal-foot button {
    width: 100%;
  }

  /* 下拉菜单 */
  .dropdown {
    right: 0;
    left: auto;
    min-width: 150px;
  }
}

/* ---------- 应用管理 ---------- */
.chip-app {
  background: #e8f4fd;
  color: #1a6fb5;
  text-decoration: none;
  cursor: pointer;
}
.chip-app:hover { background: #d3eafa; }
.kv select, .modal-box select {
  padding: 7px 10px;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}
textarea.skill-editor {
  width: 100%;
  min-height: 300px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  padding: 10px;
  border: 1px solid #d8dee6;
  border-radius: 8px;
  resize: vertical;
}

/* ---------- 密码/密钥明文切换 ---------- */
.eye-wrap { display: flex; align-items: center; gap: 6px; width: 100%; margin-top: 4px; }
.eye-wrap input { flex: 1; min-width: 0; margin-top: 0; }
.inline-form .eye-wrap { width: 180px; margin-top: 0; }
.eye-btn { flex: 0 0 auto; border: 1px solid var(--border); background: #fff; border-radius: 8px;
  padding: 7px 10px; cursor: pointer; font-size: 14px; line-height: 1; color: var(--muted); }
.eye-btn:hover { border-color: var(--blue); }
.eye-btn.eye-on { color: var(--blue); border-color: var(--blue); }
/* 眼睛按钮不参与移动端 width:100% 拉伸 (媒体查询 .inline-form button !important, 需更高特异性) */
.eye-btn { flex: 0 0 auto; }
.inline-form .eye-btn { width: auto !important; }
.inline-form .eye-wrap { max-width: 100%; }
