/* ========== 主题变量（简约大气风格） ========== */
:root,
[data-theme="dark"] {
  --bg-0: #0f1115;
  --bg-1: #171a21;
  --bg-elev: #1d2129;
  --bg-hover: #262b35;
  --border: #2a303b;
  --border-strong: #3a4250;
  --text-1: #f0f2f5;
  --text-2: #a0a8b8;
  --text-3: #6b7280;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.12);
  --danger: #ef4444;
  --warn: #f59e0b;
  --bookmark: #facc15;
  --success: #10b981;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.2);
}

[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f7f8fa;
  --bg-elev: #ffffff;
  --bg-hover: #f2f3f5;
  --border: #e5e6eb;
  --border-strong: #d4d5d9;
  --text-1: #1d2129;
  --text-2: #4e5969;
  --text-3: #86909c;
  --accent: #2f54eb;
  --accent-soft: rgba(47, 84, 235, 0.08);
  --danger: #f53f3f;
  --warn: #ff7d00;
  --bookmark: #ca8a04;
  --success: #00b42a;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-1);
  background: var(--bg-0);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background .2s ease, color .2s ease;
}

/* 去掉光斑 orb，body 保持纯净 */
.bg-orbs { display: none; }

/* ========== 布局 ========== */
.layout { position: relative; z-index: 1; display: flex; min-height: 100vh; }

/* 侧边栏：实色底 + 右分隔线 */
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  border-radius: 0; margin: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 24px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 800; color: #fff;
  background: var(--accent);
  box-shadow: none;
}
.brand-text strong { display: block; font-size: 15px; letter-spacing: .3px; }
.brand-text small { color: var(--text-3); font-size: 10.5px; letter-spacing: 1px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; padding: 0 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 10px 12px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-2);
  font-size: 14px; cursor: pointer; text-align: left;
  transition: background .15s ease, color .15s ease; position: relative;
}
.nav-item .nav-ico { font-size: 15px; width: 20px; text-align: center; }
.nav-item:hover { color: var(--text-1); background: var(--bg-hover); }
.nav-item.active {
  color: var(--text-1);
  background: var(--accent-soft);
  font-weight: 600;
}
.nav-item.active::before {
  content: ''; position: absolute; left: -6px; top: 6px; bottom: 6px;
  width: 3px; border-radius: 2px; background: var(--accent);
}
.nav-dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 1.6s infinite; font-style: normal; }
@keyframes pulse { 50% { opacity: .35; } }

.side-footer { padding-top: 14px; border-top: 1px solid var(--border); }
.conn-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2);
}
.conn-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn-pill.online .dot { background: var(--success); }
.conn-pill.offline .dot { background: var(--danger); }

/* ========== 主区域 ========== */
.main { flex: 1; min-width: 0; padding: 24px 32px 40px; background: var(--bg-0); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: 16px 0 20px;
  display: flex; align-items: center; gap: 14px; margin-bottom: 0;
  background: var(--bg-0);
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.mobile-only { display: none; }

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

/* ========== 面板/表格 ========== */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px; margin-bottom: 16px;
  box-shadow: none;
}
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; font-weight: 700; }
.panel-head small { color: var(--text-3); font-size: 12px; }

.table-wrap { overflow-x: auto; border-radius: 8px; border: 1px solid var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 10px 14px; color: var(--text-2);
  font-weight: 600; font-size: 11.5px; letter-spacing: .4px;
  text-transform: uppercase; white-space: nowrap;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: none; }
.table .placeholder-row td { text-align: center; color: var(--text-3); padding: 32px; background: var(--bg-elev); }
.mono { font-family: "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace; }
.kv-key { color: var(--accent); font-weight: 600; word-break: break-all; }
[data-theme="light"] .kv-key { color: var(--accent); }
.kv-val { color: var(--text-2); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 14px; color: var(--text-3); font-size: 13px; gap: 10px; flex-wrap: wrap; }
.foot-actions { display: flex; gap: 8px; }
.col-check { width: 38px; }

/* KV 表固定布局：避免长 Value（nowrap）把 Key 列挤压成单字符竖排 */
.kv-table { table-layout: fixed; min-width: 760px; }
.kv-table th:nth-child(1), .kv-table td:nth-child(1) { width: 42px; }
.kv-table th:nth-child(2), .kv-table td:nth-child(2) { width: 20%; }
.kv-table th:nth-child(4), .kv-table td:nth-child(4) { width: 58px; }
.kv-table th:nth-child(5), .kv-table td:nth-child(5) { width: 92px; }
.kv-table th:nth-child(6), .kv-table td:nth-child(6) { width: 170px; }
.kv-table th:nth-child(7), .kv-table td:nth-child(7) { width: 84px; }
.kv-table .kv-key { display: block; word-break: normal; overflow-wrap: anywhere; }
/* Key 即详情入口：悬停下划线 + 键盘聚焦轮廓，与 link-btn 的可点击语义保持一致 */
.kv-table .kv-key[role="button"] { cursor: pointer; border-radius: 4px; }
.kv-table .kv-key[role="button"]:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.kv-table .kv-key[role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 书签态：整段 Key 字体变黄（取代原 badge 标签），颜色随主题切换 */
.kv-table .kv-key.is-bookmarked { color: var(--bookmark); }
.kv-table .kv-val { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv-table td:last-child { white-space: nowrap; }
.kv-table td:last-child .link-btn { padding: 4px 4px; font-size: 12px; }
/* 租约 ID 最长 19 位，badge 自身的 min-width:max-content 会撑破固定列并遮挡操作列；
   表格内强制约束在单元格宽度内省略，完整 ID 通过 title 悬浮查看 */
.kv-table .badge.lease {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.on { background: var(--success); box-shadow: 0 0 9px var(--success); }
.dot.off { background: var(--danger); box-shadow: 0 0 9px var(--danger); }

/* ========== 统计卡片 ========== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { border-radius: 18px; padding: 18px 20px; transition: transform .25s ease; }
.stat-card:hover { transform: translateY(-4px); }
.stat-card .sc-head { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.stat-card .sc-head strong { font-size: 14px; word-break: break-all; }
.stat-card .sc-body { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.stat-card .metric label { display: block; font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 3px; }
.stat-card .metric span { font-size: 14.5px; font-weight: 600; word-break: break-all; }
.metric-card { display: flex; align-items: center; gap: 16px; }
.metric-card .mc-ico {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(135deg, rgba(56,189,248,.22), rgba(37,99,235,.3));
  border: 1px solid var(--border);
}
.metric-card .mc-val { font-size: 26px; font-weight: 800; line-height: 1.1; }
.metric-card .mc-label { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

/* ========== 表单 ========== */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
input, textarea, select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px; color: var(--text-1);
  padding: 11px 14px; font-size: 14px; outline: none;
  transition: border-color .2s, box-shadow .2s;
  font-family: inherit; width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(56,189,248,.18); }
input::placeholder, textarea::placeholder { color: var(--text-3); }
.grow { flex: 1; min-width: 180px; }
.maintain-row { display: flex; gap: 14px; justify-content: space-between; flex-wrap: wrap; align-items: center; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 7px; letter-spacing: .4px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text-2); font-size: 13px; }
.switch input { display: none; }
.switch .slider { width: 42px; height: 23px; border-radius: 999px; position: relative; background: rgba(128,150,190,.25); transition: background .25s; flex-shrink: 0; }
.switch .slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .25s; }
.switch input:checked + .slider { background: linear-gradient(135deg, var(--accent), var(--accent)); }
.switch input:checked + .slider::after { transform: translateX(19px); }

/* ========== 按钮（极简风） ========== */
.btn {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--text-1);
  background: var(--bg-elev);
  transition: background .12s ease, border-color .12s ease, color .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { background: var(--bg-1); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: 12.5px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 85%, #000); border-color: color-mix(in srgb, var(--accent) 85%, #000); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text-1); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.icon-btn {
  background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text-1); width: 36px; height: 36px; border-radius: 8px;
  font-size: 15px; cursor: pointer; flex-shrink: 0;
  transition: background .12s ease;
}
.icon-btn:hover { background: var(--bg-hover); }
.link-btn { background: none; border: none; cursor: pointer; font-size: 12.5px; padding: 4px 8px; border-radius: 6px; color: var(--accent); }
.link-btn:hover { background: var(--accent-soft); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: rgba(239, 68, 68, 0.08); }

/* ========== 徽章 ========== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .4px; }
.badge.put { background: rgba(52,211,153,.16); color: var(--success); border: 1px solid rgba(52,211,153,.3); }
.badge.delete { background: rgba(248,113,113,.16); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }
.badge.info { background: rgba(96,165,250,.16); color: var(--accent); border: 1px solid rgba(96,165,250,.3); }
.badge.lease { background: rgba(251,191,36,.14); color: var(--warn); border: 1px solid rgba(251,191,36,.28); flex-shrink: 0; min-width: max-content; white-space: nowrap; }
.badge.on { background: rgba(52,211,153,.16); color: var(--success); border: 1px solid rgba(52,211,153,.3); }
.badge.off { background: rgba(248,113,113,.16); color: var(--danger); border: 1px solid rgba(248,113,113,.3); }

/* ========== 键树布局 ========== */
.kv-layout { display: grid; grid-template-columns: 300px 1fr; gap: 16px; align-items: start; }
.kv-side { padding: 16px; position: sticky; top: 96px; max-height: calc(100vh - 120px); display: flex; flex-direction: column; }
.kv-side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.kv-side-head h2 { font-size: 14px; }
.kv-side-head small { color: var(--text-3); font-size: 12px; }
.tree-box { overflow: auto; flex: 1; min-height: 160px; font-size: 13px; }
.tree-node { user-select: none; }
.tree-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: 9px; cursor: pointer;
  color: var(--text-2); transition: background .15s, color .15s;
  white-space: nowrap;
}
.tree-row:hover { background: var(--bg-hover); color: var(--text-1); }
.tree-row.active { background: linear-gradient(135deg, rgba(56,189,248,.2), rgba(37,99,235,.28)); color: #fff; }
.tree-row .twisty { width: 14px; text-align: center; font-size: 10px; transition: transform .2s; flex-shrink: 0; }
.tree-node.collapsed > .tree-children { display: none; }
.tree-node.collapsed > .tree-row .twisty { transform: rotate(-90deg); }
.tree-row .t-ico { flex-shrink: 0; }
.tree-row .t-name { overflow: hidden; text-overflow: ellipsis; }
.tree-children { margin-left: 14px; border-left: 1px dashed var(--border); padding-left: 4px; }
.tree-empty { color: var(--text-3); font-size: 12.5px; padding: 14px 8px; text-align: center; }

.bookmark-box { border-top: 1px solid var(--border); padding-top: 12px; max-height: 200px; overflow: auto; }
.bookmark-list { display: flex; flex-direction: column; gap: 4px; }
.bookmark-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 6px 8px; border-radius: 8px; color: var(--text-2); cursor: pointer; }
.bookmark-item:hover { background: var(--bg-hover); }
.bookmark-item .bm-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bookmark-item .bm-del { opacity: 0; color: var(--danger); background: none; border: none; cursor: pointer; font-size: 13px; }
.bookmark-item:hover .bm-del { opacity: 1; }
.bookmark-empty { color: var(--text-3); font-size: 12px; padding: 6px 8px; }

/* ========== Watch ========== */
.watch-status { display: flex; align-items: center; gap: 10px; margin: 14px 0 12px; font-size: 13px; color: var(--text-2); }
.watch-status .spacer { flex: 1; }
.event-stream {
  height: 460px; overflow-y: auto; border-radius: 12px;
  background: var(--bg-1); border: 1px solid var(--border);
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.event-empty { margin: auto; color: var(--text-3); font-size: 13px; }
.event-item { border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px; padding: 10px 14px; animation: fadeUp .25s ease; }
.event-item .ev-head { display: flex; align-items: center; gap: 10px; margin-bottom: 5px; }
.event-item .ev-time { color: var(--text-3); font-size: 11.5px; margin-left: auto; }
.event-item .ev-key { font-weight: 600; word-break: break-all; }
.event-item .ev-val {
  color: var(--text-2); font-size: 12.5px; margin-top: 4px;
  background: var(--bg-1); border-radius: 8px; padding: 7px 10px;
  word-break: break-all; white-space: pre-wrap; max-height: 120px; overflow: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}
.event-item .ev-meta { color: var(--text-3); font-size: 11.5px; margin-top: 5px; }

/* ========== 租约 ========== */
.lease-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.lease-card { border-radius: 18px; padding: 18px; }
.lease-card .lc-id { font-size: 15px; font-weight: 700; color: var(--accent); margin-bottom: 10px; word-break: break-all; }
.lease-card .lc-ttl { font-size: 30px; font-weight: 800; margin-bottom: 2px; }
.lease-card .lc-ttl small { font-size: 13px; color: var(--text-3); font-weight: 500; }
.lease-card .lc-bar { height: 6px; border-radius: 999px; background: rgba(128,150,190,.18); margin: 12px 0; overflow: hidden; }
.lease-card .lc-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--accent), var(--accent)); transition: width .8s ease; }
.lease-card .lc-keys { font-size: 12px; color: var(--text-2); margin: 8px 0 14px; word-break: break-all; }
.lease-card .lc-actions { display: flex; gap: 8px; }

/* ========== 认证页 ========== */
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.perm-line { font-size: 12px; color: var(--text-2); padding: 3px 0; word-break: break-all; }
.perm-line .perm-tag { font-weight: 700; margin-right: 6px; }

/* ========== 图表 ========== */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-panel { min-height: 240px; }
.chart-box { width: 100%; height: 180px; }
.chart-box svg { width: 100%; height: 100%; overflow: visible; }
.chart-empty { height: 100%; display: grid; place-items: center; color: var(--text-3); font-size: 13px; }
.spark-line { fill: none; stroke: url(#chartGrad); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.spark-area { fill: url(#chartGradFill); opacity: .55; }
.spark-dot { fill: var(--accent); }
.spark-label { fill: var(--text-3); font-size: 10px; }
.spark-grid { stroke: var(--border); stroke-dasharray: 4 5; stroke-width: 1; }

/* ========== 连接设置 ========== */
.conn-detail { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.conn-metric { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px; }
.conn-metric label { display: block; font-size: 11.5px; color: var(--text-3); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }
.conn-metric span { font-size: 15px; font-weight: 700; word-break: break-all; }

/* ========== Toast ========== */
.toast-root { position: fixed; top: 22px; right: 22px; z-index: 1000; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, 86vw); }
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 16px; border-radius: 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13.5px; line-height: 1.5;
  animation: toastIn .3s ease;
}
.toast.out { animation: toastOut .3s ease forwards; }
.toast .t-ico { flex-shrink: 0; font-weight: 800; }
.toast.success .t-ico { color: var(--success); }
.toast.error .t-ico { color: var(--danger); }
.toast.info .t-ico { color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* ========== Modal ========== */
.modal-mask {
  position: fixed; inset: 0; z-index: 900;
  display: grid; place-items: center; padding: 18px;
  animation: fadeIn .2s ease;
}
[data-theme="light"] .modal-mask { background: rgba(80,110,180,.35); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(640px, 100%); max-height: 88vh; overflow-y: auto;
  border-radius: 18px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 24px;
  animation: fadeUp .28s ease;
}
.modal.wide { width: min(880px, 100%); }
.modal h3 { margin-bottom: 18px; font-size: 17px; word-break: break-all; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.modal-tip { color: var(--text-3); font-size: 12.5px; line-height: 1.7; }
.modal-tip strong { color: var(--danger); }
.editor-tools { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }

/* JSON 高亮 */
.code-view {
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.65; white-space: pre-wrap; word-break: break-all;
  max-height: 360px; overflow: auto;
}
.tok-key { color: #7dd3fc; }
.tok-str { color: #86efac; }
.tok-num { color: #fcd34d; }
.tok-bool { color: #f0abfc; }
.tok-null { color: #fda4af; }

/* 历史对比 */
.diff-box { display: grid; grid-template-columns: 180px 1fr; gap: 0; max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.diff-rev-list { border-right: 1px solid var(--border); overflow: auto; }
.diff-rev { padding: 10px 14px; cursor: pointer; font-size: 12.5px; border-bottom: 1px solid rgba(147,197,253,.08); color: var(--text-2); }
.diff-rev:hover { background: var(--bg-hover); }
.diff-rev.active { background: linear-gradient(135deg, rgba(56,189,248,.2), rgba(37,99,235,.28)); color: #fff; }
.diff-rev small { display: block; color: var(--text-3); margin-top: 2px; }
.diff-content { padding: 12px 14px; overflow: auto; min-width: 0; }
.diff-line { font-family: "SF Mono", Menlo, monospace; font-size: 12px; padding: 2px 8px; border-radius: 5px; white-space: pre-wrap; word-break: break-all; }
.diff-line.add { background: rgba(52,211,153,.14); }
.diff-line.del { background: rgba(248,113,113,.14); }
.diff-line.eq { color: var(--text-2); }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(125,211,252,.25); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(125,211,252,.45); }
::-webkit-scrollbar-track { background: transparent; }


/* ========== 响应式 ========== */
@media (max-width: 1024px) {
  .kv-layout { grid-template-columns: 1fr; }
  /* 网格项默认 min-width:auto 会被不可断行的 Value 文本撑出横向滚动，
     允许收缩后由 .kv-val 的 ellipsis 在单元格内省略 */
  .kv-side, .kv-main { min-width: 0; }
  .kv-side { position: static; max-height: none; }
  .tree-box { max-height: 280px; }
  .auth-grid, .chart-grid, .field-row { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  /* 让 .layout 不创建 stacking context，sidebar 的 z-index 才能穿透到根 stacking context 跟 drawer-mask 比较 */
  .layout { position: static; z-index: unset; display: block; }
  .mobile-only { display: inline-grid; place-items: center; }
  .main { padding: 12px 12px 32px; }
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0; bottom: 0;
    height: 100vh; margin: 0;
    border-radius: 0 18px 18px 0;
    transform: translateX(-105%);
    transition: transform .3s ease;
    width: min(280px, 82vw);
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { top: 10px; padding: 11px 14px; }
  .topbar h1 { font-size: 16.5px; }
  .panel { padding: 15px; }
  .stat-grid { grid-template-columns: 1fr; }
  .maintain-row { flex-direction: column; align-items: stretch; }
  .maintain-row .btn, .maintain-row .inline-form { width: 100%; }
  .maintain-row input { flex: 1; }
  .diff-box { grid-template-columns: 1fr; }
  .diff-rev-list { border-right: none; border-bottom: 1px solid var(--border); max-height: 160px; }

  /* KV 表格 → 玻璃拟态精美卡片 */
  .kv-table thead,
  .kv-table th { display: none; }
  .kv-table, .kv-table tbody, .kv-table tr, .kv-table td {
    display: block; width: 100%;
  }
  .kv-table tr {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 16px 16px 14px;
    margin-bottom: 14px;
    box-shadow: 0 2px 14px rgba(20, 40, 70, .14);
    position: relative;
    transition: transform .15s ease, box-shadow .15s ease;
  }
  .kv-table tr:active { transform: scale(.995); }
  .kv-table td {
    border-bottom: none; padding: 0; margin-bottom: 6px; text-align: left;
    font-size: 12.5px; color: var(--text-2);
  }
  .kv-table td::before { content: none; }
  .kv-table { min-width: 0; table-layout: auto; }
  /* 桌面端 :nth-child 固定列宽（0,2,1）优先级高于上面的通用 td 规则（0,1,1），
     卡片化后必须同优先级显式还原：块级行（Key/Value/操作）铺满整行，pill 列随内容收缩，
     否则 Key 列被锁死在 20%、操作列被锁死在固定像素宽，右侧留下大片空白 */
  .kv-table td:nth-child(2),
  .kv-table td:nth-child(3),
  .kv-table td:nth-child(4),
  .kv-table td:nth-child(5),
  .kv-table td:nth-child(6),
  .kv-table td:nth-child(7) { width: auto; }

  /* 1. 复选框：左上角独立 */
  .kv-table td:nth-child(1) {
    position: absolute; top: 12px; right: 14px;
    margin-bottom: 0;
  }
  .kv-table td:nth-child(1) input[type=checkbox] {
    width: 18px; height: 18px; cursor: pointer;
    accent-color: #38bdf8;
  }

  /* 2. KEY：顶部突出大号 */
  .kv-table td:nth-child(2) {
    font-size: 14.5px; font-weight: 700;
    color: var(--accent);
    margin-bottom: 8px;
    padding-right: 28px; /* 避让右上角复选框 */
    line-height: 1.35;
  }
  [data-theme="light"] .kv-table td:nth-child(2) { color: var(--accent); }
  .kv-table td:nth-child(2) .kv-key { display: block; }

  /* 3. VALUE：紧凑单行省略 */
  .kv-table td:nth-child(3) {
    font-size: 12px; color: var(--text-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-bottom: 10px;
    padding-right: 28px;
  }
  .kv-table td:nth-child(3) .kv-val { display: block; max-width: 100%; }

  /* 4-6：版本/修改版本/租约 → metadata pill 组 */
  .kv-table td:nth-child(4),
  .kv-table td:nth-child(5),
  .kv-table td:nth-child(6) {
    display: inline-flex; align-items: center; gap: 6px;
    margin-right: 12px; margin-bottom: 8px;
    padding: 3px 10px; border-radius: 999px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    font-size: 11.5px; font-weight: 600;
    color: var(--text-2);
  }
  .kv-table td:nth-child(4)::before { content: '📦'; font-size: 11px; }
  .kv-table td:nth-child(5)::before { content: '⚡'; font-size: 11px; }
  .kv-table td:nth-child(6) { padding: 2px 0; background: transparent; border: none; }
  .kv-table td:nth-child(6) .badge.lease { max-width: none; font-size: 11px; }
  /* 永久键（"-"）的占位 */
  .kv-table td:nth-child(6):empty::before { content: '🔒 永久'; font-size: 11px; color: var(--text-3); }
  .kv-table td:nth-child(6) { min-height: 20px; }

  /* 7. 操作：底部 flex 分隔 */
  .kv-table td:nth-child(7) {
    display: flex; flex-wrap: wrap; gap: 2px;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px dashed var(--border);
    margin-bottom: 0;
  }
  .kv-table td:nth-child(7) .link-btn {
    font-size: 12px; padding: 5px 9px;
    border-radius: 8px;
  }

  /* 卡片容器内的 placeholder-row 不按卡片处理 */
  .kv-table .placeholder-row td {
    display: block; text-align: center;
    padding: 30px 12px; font-size: 13px;
    color: var(--text-3);
  }
  .kv-table .placeholder-row {
    background: transparent; border: none;
    box-shadow: none; padding: 0;
  }
  .event-stream { height: 56vh; }
  .toolbar .btn { flex: 1; }
  .toast-root { left: 12px; right: 12px; top: 12px; max-width: none; }
}

@media (min-width: 861px) {
  .drawer-mask { display: none !important; }
}

/* ========== 入口页（连接表单） ========== */
.entry-root {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 18px;
}
.auth-card {
  width: min(460px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--card-shadow);
  padding: 32px 30px 26px;
}
.auth-card .auth-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}
.auth-card .auth-logo {
  width: 48px; height: 48px;
  border-radius: 13px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 18px;
  color: #fff;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  box-shadow: 0 6px 18px rgba(37,99,235,.35);
}
.auth-card .auth-title { font-size: 19px; font-weight: 700; color: var(--text-1); }
.auth-card .auth-sub   { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.auth-card .grid2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 12px; }
.auth-card label { display: block; font-size: 12.5px; color: var(--text-2); font-weight: 600; margin-bottom: 6px; letter-spacing: .3px; }
.auth-card input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-1);
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-card input:focus { border-color: #38bdf8; box-shadow: 0 0 0 3px rgba(56,189,248,.18); }
.auth-card input::placeholder { color: var(--text-3); }
.auth-card .auth-hint { margin-top: 10px; font-size: 11.5px; color: var(--text-3); line-height: 1.6; }
.auth-card .submit {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #fff;
  border: none;
  border-radius: 11px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(37,99,235,.38);
  transition: transform .1s ease, box-shadow .15s, filter .15s;
}
.auth-card .submit:hover { filter: brightness(1.08); box-shadow: 0 8px 22px rgba(37,99,235,.48); }
.auth-card .submit:active { transform: translateY(1px); }
.auth-card .submit:disabled { filter: grayscale(.3) brightness(.9); cursor: wait; }
.auth-card .auth-tip { text-align: center; margin-top: 14px; font-size: 11.5px; color: var(--text-3); }
.auth-card .auth-status { margin-top: 12px; font-size: 12.5px; text-align: center; min-height: 18px; }
.auth-card .auth-status.ok { color: var(--success); }
.auth-card .auth-status.err { color: var(--danger); }
.auth-card .auth-status.loading { color: var(--text-2); }

/* 顶栏断连按钮 */
.disconnect-btn {
  background: none; border: 1px solid rgba(248,113,113,.45);
  color: var(--danger);
  border-radius: 9px; padding: 5px 10px;
  font-size: 12px; cursor: pointer;
  transition: background .15s;
}
.disconnect-btn:hover { background: rgba(248,113,113,.12); }
