:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --panel: #151a26;
  --panel-2: #1b2231;
  --line: #232c3d;
  --text: #e6ecf7;
  --text-dim: #93a1bb;
  --text-mute: #6b7a95;
  --accent: #4d8dff;
  --accent-2: #7c5cff;
  --ok: #2ecc71;
  --warn: #f5a524;
  --err: #ff5f6d;
  --idle: #5b6a84;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius: 14px;
}
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-soft: #eaeef6;
  --panel: #ffffff;
  --panel-2: #f7f9fd;
  --line: #e2e8f2;
  --text: #16202f;
  --text-dim: #5a6a83;
  --text-mute: #8a99b0;
  --shadow: 0 8px 24px rgba(23,43,77,.08);
}

* { box-sizing: border-box; }
/* body 不能用 height:100%：会把 sticky 顶栏的包含块锁死在一屏高，
   滚动超过一屏顶栏就被顶走。用 min-height 让 body 随内容撑满。 */
body { min-height: 100vh; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { margin: 0; font-weight: 650; }
code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 22px; background: var(--bg-soft); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 17px; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--text-mute); }
.brand-dot {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 6px 18px rgba(77,141,255,.35);
}
.brand-logo {
  width: 38px; height: 38px; border-radius: 11px; flex: none; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(23,43,77,.14), 0 0 0 1px rgba(0,48,168,.10) inset;
  transition: background .2s, box-shadow .2s;
}
.brand-logo img {
  width: 78%; height: 78%; object-fit: contain; display: block; transition: filter .2s;
}
/* 深色主题：恢复品牌感的紫蓝渐变。标志本体是深蓝 #0030a8，压在渐变上对比度仅约 1.7 会糊掉，
   所以这里把标志反白，白色 #fff 与该渐变的对比度约 6.5，清晰且更贴合深色界面。 */
[data-theme="dark"] .brand-logo {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 6px 18px rgba(77,141,255,.35);
}
[data-theme="dark"] .brand-logo img { filter: brightness(0) invert(1); }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.patrol { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 64px); }
.sidebar {
  border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px;
  background: var(--bg-soft);
  position: sticky; top: 67px;              /* 钉在顶栏下方，视口内固定 */
  height: calc(100vh - 67px); overflow: hidden;   /* 端点多时由列表内部滚动 */
}
.side-head { display: flex; align-items: center; justify-content: space-between; }
.side-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); }
.count { background: var(--panel-2); border: 1px solid var(--line); border-radius: 20px; padding: 0 7px; font-size: 11px; }
.side-tools { display: flex; gap: 8px; }
.side-tools .btn { flex: 1; justify-content: center; }
/* 新增按钮：品牌渐变填充，醒目 */
.btn.accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none; color: #fff; font-weight: 650;
  box-shadow: 0 4px 12px rgba(77, 141, 255, .35);
}
.btn.accent:hover { filter: brightness(1.1); }
.ep-list { display: flex; flex-direction: column; gap: 8px; overflow-y: auto; flex: 1 1 0; min-height: 0; }
/* 卡片禁止被压缩：端点超过一屏时靠列表滚动，而不是挤扁卡片吞掉数据行 */
.ep-list .ep-card { flex: 0 0 auto; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; }
.preset-title { font-size: 11px; color: var(--text-mute); margin-bottom: 8px; letter-spacing: .5px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- endpoint card ---------- */
.ep-card {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 10px 12px;
  cursor: pointer; transition: .15s; position: relative; overflow: hidden;
}
.ep-card:hover { border-color: #2f3d57; transform: translateY(-1px); }
.ep-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ep-card .ep-top { display: flex; align-items: center; gap: 8px; }
.ep-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ep-del {
  margin-left: auto; flex: none; width: 20px; height: 20px; line-height: 1; padding: 0;
  border: none; border-radius: 6px; background: transparent; color: var(--text-mute);
  cursor: pointer; font-size: 12px; opacity: .45; transition: .15s; /* 不用 0，触屏没有 hover */
}
.ep-card:hover .ep-del { opacity: 1; }
.ep-del:hover { background: var(--err); color: #fff; }
.ep-sub { font-size: 11px; color: var(--text-mute); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.ep-metrics { display: flex; gap: 10px; margin-top: 8px; font-size: 11px; color: var(--text-dim); }
.ep-metrics b { color: var(--text); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--idle); }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warn { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.err { background: var(--err); box-shadow: 0 0 8px var(--err); }
.dot.testing { background: var(--accent); animation: pulse .9s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ---------- main ---------- */
.main { padding: 18px 22px 40px; min-width: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tab {
  background: none; border: none; color: var(--text-dim); padding: 10px 16px; cursor: pointer;
  font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabpane { display: none; }
.tabpane.active { display: block; animation: fade .2s; }
@keyframes fade { from { opacity: 0; transform: translateY(4px) } }

/* 间距用 margin 而不是 flex gap：老浏览器（Safari<14.1 等）不支持 flex gap 会全部贴死 */
.dash-bar { display: flex; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.dash-bar > * { margin-right: 12px; }
.dash-bar > *:last-child { margin-right: 0; }
.dash-select { display: flex; flex-direction: column; gap: 4px; }
/* 不 grow、不内部换行：按钮永远紧跟超时框；空间不足时由各格子按比例收缩 */
.dash-cfg { flex: 0 1 auto; display: flex; align-items: flex-end; flex-wrap: nowrap; min-width: 0; }
.dash-cfg .cell { position: relative; min-width: 0; margin-right: 10px; }
.dash-cfg .cell:last-child { margin-right: 0; }
.dash-cfg .cell .input { width: 100%; min-width: 0; }   /* 覆盖全局 .input 的 min-width:140px，否则输入框会溢出格子吃掉间距 */
/* Prompt 弹性收缩：基准 240px，最低 160px；不成长（否则按钮又被推到最右） */
.dash-cfg .cell:has(#dashPrompt) { flex: 0 1 240px; min-width: 160px; }
/* 数字框可从 96px 收缩到 78px，窄窗口下优先压缩数字框而不是换行 */
.dash-cfg .cell:has(.num) { flex: 0 1 96px; min-width: 78px; }
.dash-cfg .cell label,
.dash-select label,
.field span { font-size: 11px; color: var(--text-mute); line-height: 1; }
/* 描述文字「贴在输入框下边缘」：以绝对定位把 label 放在输入框底边，背景填页面色形成「切割感」 */
.dash-cfg .cell label {
  position: absolute;
  left: 8px;
  bottom: 0;
  transform: translateY(50%);
  background: var(--bg);
  padding: 0 4px;
  pointer-events: none;
  white-space: nowrap;
}
/* 深色主题：去掉文字底色，直接透出输入框下边框 */
[data-theme="dark"] .dash-cfg .cell label { background: transparent; padding: 0; }

.status-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 5px 11px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--line); font-size: 12px; color: var(--text-dim);
  max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip b { color: var(--text); flex: none; }

/* 在线状态进度条（可用状态卡片）：绿=在线 红=离线 灰=暂无记录，右为最新 */
.uptime-bar { display: inline-flex; gap: 1.5px; align-items: stretch; height: 18px; vertical-align: middle; }
.uptime-bar i { width: 4px; border-radius: 1.5px; background: var(--panel-2); border: 1px solid var(--line); }
.uptime-bar i.ok { background: var(--ok); border-color: transparent; }
.uptime-bar i.err { background: var(--err); border-color: transparent; }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow);
}
.metric .k { font-size: 11px; color: var(--text-mute); letter-spacing: .4px; }
.metric .v { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.metric .u { font-size: 12px; color: var(--text-dim); margin-left: 3px; font-weight: 500; }
.metric.accent .v { color: var(--accent); }
.metric.ok .v { color: var(--ok); }
.metric.warn .v { color: var(--warn); }

.panels { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h3 { font-size: 14px; }
.hint { font-size: 11px; color: var(--text-mute); }
.chart-host { height: 240px; }
.chart-host.tall { height: 260px; }
.stream-out {
  margin: 0; height: 240px; overflow: auto; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font: 12.5px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; color: var(--text-dim);
}
.stream-out.live { color: var(--text); }

/* ---------- table ---------- */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { font-size: 11px; color: var(--text-mute); font-weight: 600; letter-spacing: .4px; text-transform: uppercase; }
.table th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.th-sort:hover { color: var(--text); }
.table th.th-sort #speedSortArrow { color: var(--accent); font-weight: 700; }
.table td { color: var(--text-dim); }
.table tbody tr:hover td { background: var(--panel-2); }
.ta-r { text-align: right !important; }
.note { font-size: 12px; color: var(--text-mute); margin: 10px 0 0; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2);
  color: var(--text); padding: 8px 14px; border-radius: 9px; cursor: pointer; font-size: 13px; transition: .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.danger:hover { border-color: var(--err); color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; }
.icon-btn:hover { color: var(--text); }
.input, select.input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; outline: none; min-width: 140px;
}
select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; }
.input:focus, select:focus { border-color: var(--accent); }
.input.num { width: 90px; min-width: 90px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(5,8,14,.66); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 20px; }
/* 必须显式声明：否则 display:flex 会盖过浏览器默认的 [hidden] { display:none } */
.modal-mask[hidden] { display: none; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 520px; max-width: 100%; box-shadow: var(--shadow); max-height: 88vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; overflow: auto; }
.modal-body.doc h4 { margin: 14px 0 6px; font-size: 13px; color: var(--accent); }
.modal-body.doc p, .modal-body.doc li { font-size: 13px; color: var(--text-dim); }
.modal-body.doc ol, .modal-body.doc ul { margin: 6px 0; padding-left: 20px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- toast ---------- */
.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; box-shadow: var(--shadow); max-width: 380px;
  animation: slideIn .22s;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px) } }

.empty { color: var(--text-mute); font-size: 13px; text-align: center; padding: 40px 10px; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.status-pill.ok { color: var(--ok); }
.status-pill.err { color: var(--err); }
.status-pill.warn { color: var(--warn); }
.status-pill.idle { color: var(--text-mute); }

/* 移动端专属结构：PC 宽度下一律隐藏 */
.epstrip, .ep-cards { display: none; }

@media (max-width: 1080px) {
  .panels { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; overflow: visible; border-right: none; border-bottom: 1px solid var(--line); }
  .ep-list { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .ep-card { min-width: 220px; flex: none; }
  .side-foot .presets .btn { font-size: 11px; padding: 5px 8px; }
}
@media (max-width: 640px) {
  /* ---- 全局框架：侧栏退场，端点条上位 ---- */
  .sidebar { display: none; }
  .epstrip { display: block; background: var(--bg-soft); border-bottom: 1px solid var(--line); padding: 10px 16px 8px; }
  .epstrip-label { font-size: 11px; color: var(--text-mute); margin-bottom: 6px; }
  .epchips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
  .epchip {
    flex: none; display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 8px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
    font-size: 12px; color: var(--text); white-space: nowrap;
  }
  .epchip.active { border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 1px var(--accent) inset; }
  .epchip-top { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; }
  .epchip-data { font-size: 10.5px; color: var(--text-mute); }
  .epchip.plus { color: var(--accent); font-weight: 650; }
  .epstrip-extras { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 2px; }
  .epstrip-extras .patrol { margin: 0; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .brand p { display: none; }
  .topbar-actions .patrol { display: none; }   /* 巡检由 JS 移入端点条 */
  .topbar-actions { gap: 7px; }
  .main { padding: 12px 12px 40px; }

  /* ---- 监控面板：控制区纵堆 + 三列数字框 ---- */
  .dash-bar { display: block; }
  .dash-bar > * { margin: 0 0 12px; }
  .dash-bar > *:last-child { margin-bottom: 0; }
  .dash-cfg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 10px; }
  .dash-cfg .cell { margin: 0; }
  .dash-cfg .cell:has(#dashPrompt) { grid-column: 1 / -1; }
  .dash-cfg .cell label {
    position: static; transform: none; background: none; padding: 0;
    display: block; margin-bottom: 5px; line-height: 1.4;   /* 标签回到输入框上方 */
  }
  .dash-cfg .cell .input { min-width: 0; }
  #runTestBtn { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
  .status-strip .chip { max-width: 100%; }

  /* ---- 指标与图表 ---- */
  .metrics { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .metric { padding: 12px 14px; }
  .metric .v { font-size: 20px; }
  .metric .k { font-size: 10px; }
  .chart-host, .chart-host.tall { height: 170px; }
  .stream-out { height: 150px; }

  /* ---- 端点管理：表格换卡片 ---- */
  #epTable { display: none; }
  .ep-cards { display: block; }
  .epcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
  .epcard .ep-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
  .epcard .ep-url { font-size: 11px; color: var(--text-mute); word-break: break-all; margin-bottom: 2px; }
  .epcard .ep-ops { display: flex; gap: 8px; margin-top: 10px; }
  .epcard .ep-ops .obtn { flex: 1; text-align: center; padding: 7px 0; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text-dim); font-size: 12px; cursor: pointer; }
  .epcard .ep-ops .obtn.danger { color: var(--err); border-color: rgba(255, 95, 109, .4); }

  /* ---- 历史与对比：表格瘦身 ---- */
  .col-m-hide { display: none; }
  .uptime-bar { height: 14px; gap: 1.5px; }
  .uptime-bar i { width: 4.5px; }

  /* ---- 弹窗：底部抽屉 ---- */
  .modal-mask { align-items: flex-end; padding: 0; }
  .modal { width: 100%; border-radius: 18px 18px 0 0; border-bottom: none; max-height: 88vh; }
  .modal::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 2px auto 10px; }
  .modal-foot .btn { flex: 1; justify-content: center; padding: 12px; }

  /* ---- toast 顶部显示，避让键盘 ---- */
  .toast-host { top: 12px; bottom: auto; left: 12px; right: 12px; }
}
/* 触屏：删除按钮加大并默认可见（不依赖 hover） */
@media (pointer: coarse) {
  .ep-del { width: 28px; height: 28px; opacity: .6; font-size: 14px; }
}
