/* ============================================================
   个人总控台 v2 —— 样式
   设计取向：研发级信息密度（Linear / Grafana 观感），深浅双主题。
   铁律：每一层都自带可见细节，不靠「点进去才知道」。
   ============================================================ */

:root {
  --bg: #0e1117;
  --bg-2: #141922;
  --panel: #161c26;
  --panel-2: #1c2430;
  --line: #252d3a;
  --line-2: #303a4a;
  --ink: #e6edf6;
  --ink-2: #b3c0d1;
  --muted: #7b8a9e;
  --primary: #4c9aff;
  --primary-d: #2f7fe0;
  --accent: #7c5cff;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --crit: #f85149;
  --weak: #e3873c;
  --info: #58a6ff;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

:root[data-theme="light"] {
  --bg: #f6f8fb;
  --bg-2: #eef2f8;
  --panel: #ffffff;
  --panel-2: #f2f5fa;
  --line: #dfe5ee;
  --line-2: #ccd6e4;
  --ink: #1b2330;
  --ink-2: #3d4a5c;
  --muted: #6b7a8d;
  --primary: #1f6feb;
  --primary-d: #1a5fcc;
  --accent: #6b46e5;
  --ok: #1a7f37;
  --warn: #9a6700;
  --danger: #cf222e;
  --shadow: 0 2px 10px rgba(20, 40, 80, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }

/* ---------- 布局 ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 226px; flex: 0 0 226px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sb-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 9px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; flex: 0 0 30px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}
.brand b { font-size: 14px; line-height: 1.25; display: block; }
.brand span { display: block; font-size: 10.5px; color: var(--muted); }
.sb-scroll { flex: 1; overflow-y: auto; padding: 8px; }
.sb-foot { padding: 8px 12px; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--muted); }

.nav-group { margin-bottom: 12px; }
.nav-group > .ng-title {
  font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: 6px 8px 4px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 9px; border-radius: 7px; cursor: pointer;
  font-size: 13px; color: var(--ink-2); user-select: none;
  border: 1px solid transparent; transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--panel-2); color: var(--ink); }
.nav-item.active { background: var(--panel); border-color: var(--line-2); color: var(--ink); font-weight: 600; }
.nav-item .dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 7px; }
.nav-item .cnt { margin-left: auto; font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.nav-sub { padding-left: 12px; }

/* ---------- 主区 ---------- */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.topbar {
  height: 50px; flex: 0 0 50px; border-bottom: 1px solid var(--line);
  background: var(--bg-2); display: flex; align-items: center; gap: 12px;
  padding: 0 14px;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); min-width: 0; overflow: hidden; }
.crumbs .cb { cursor: pointer; white-space: nowrap; }
.crumbs .cb:hover { color: var(--primary); }
.crumbs .sep { opacity: .5; }
.crumbs .cur { color: var(--ink); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-wrap { margin-left: auto; position: relative; width: 300px; }
.search-wrap input {
  width: 100%; height: 30px; border-radius: 7px;
  border: 1px solid var(--line-2); background: var(--panel);
  color: var(--ink); padding: 0 9px 0 28px; font-size: 12.5px; font-family: inherit;
  outline: none;
}
.search-wrap input:focus { border-color: var(--primary); }
.search-wrap .sicon {
  position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; color: var(--muted); pointer-events: none;
}
.sresults {
  position: absolute; top: 34px; left: 0; right: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 9px; box-shadow: var(--shadow);
  max-height: 62vh; overflow-y: auto; display: none;
}
.sresults.show { display: block; }
.sr { padding: 8px 11px; border-bottom: 1px solid var(--line); cursor: pointer; }
.sr:last-child { border-bottom: none; }
.sr:hover { background: var(--panel-2); }
.sr .t { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.sr .m { font-size: 10.5px; color: var(--muted); display: flex; gap: 7px; margin-top: 2px; }
.sr .m .dom { color: var(--primary); }
.sr .s { font-size: 11px; color: var(--ink-2); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.sr mark { background: rgba(76,154,255,.28); color: inherit; border-radius: 2px; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: 1px solid var(--line-2);
  background: var(--panel); color: var(--ink-2); cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex: 0 0 30px;
}
.icon-btn:hover { color: var(--ink); border-color: var(--primary); }

.content { flex: 1; overflow-y: auto; padding: 16px 18px 60px; scroll-behavior: smooth; }
.content::-webkit-scrollbar { width: 9px; height: 9px; }
.content::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; }
.sb-scroll::-webkit-scrollbar { width: 7px; }
.sb-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }

/* ---------- 通用块 ---------- */
.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 19px; margin: 0 0 4px; line-height: 1.35; }
.page-head .sub { font-size: 12.5px; color: var(--muted); }

.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-auto { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px;
}
.card.hover { cursor: pointer; transition: border-color .12s, transform .12s; }
.card.hover:hover { border-color: var(--primary); transform: translateY(-1px); }
.card h3 { margin: 0 0 8px; font-size: 14px; display: flex; align-items: center; gap: 7px; }
.card h3 .n { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 400; }

.kpi-row { display: flex; gap: 10px; flex-wrap: wrap; }
.kpi {
  flex: 1 1 118px; min-width: 118px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
}
.kpi .v { font-size: 20px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 11px; color: var(--muted); margin-top: 1px; }
.kpi .d { font-size: 10.5px; color: var(--ink-2); margin-top: 4px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; padding: 1.5px 7px; border-radius: 20px;
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--panel-2);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.badge.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 40%, transparent); }
.badge.crit { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }

.bar { height: 5px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 5px; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.mono { font-family: var(--mono); font-size: 12px; }

/* ---------- 知识图谱 ---------- */
.graph-wrap {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px; position: relative; overflow: hidden;
}
.graph-wrap svg { display: block; width: 100%; height: auto; }
.gnode { cursor: pointer; }
.gnode circle { transition: r .15s, filter .15s; }
.gnode:hover circle { filter: brightness(1.25); }
.gnode text { font-family: var(--sans); pointer-events: none; }
.glink { stroke: var(--line-2); fill: none; }

/* ---------- 领域卡 ---------- */
.domain-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px; cursor: pointer;
  transition: border-color .12s, transform .12s; position: relative; overflow: hidden;
}
.domain-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.domain-card::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--dom-color, var(--primary));
}
.dc-head { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.dc-head .nm { font-size: 14.5px; font-weight: 700; }
.dc-head .rg { margin-left: auto; }
.dc-kpis { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 9px; }
.dc-kpi .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dc-kpi .l { font-size: 10px; color: var(--muted); }
.dc-detail { font-size: 12px; color: var(--ink-2); line-height: 1.65; }
.dc-detail .row { display: flex; gap: 6px; padding: 2px 0; }
.dc-detail .row .k { color: var(--muted); flex: 0 0 62px; }
.dc-detail .row .v { flex: 1; min-width: 0; }
.dc-detail .row .v.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 表格（实体层） ---------- */
.tbl-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--panel); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th {
  text-align: left; padding: 8px 10px; background: var(--panel-2);
  border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted);
  font-weight: 600; position: sticky; top: 0; z-index: 2; white-space: nowrap;
}
table.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.tbl tbody tr { cursor: pointer; }
table.tbl tbody tr:hover { background: var(--panel-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 过滤器 ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 11px; align-items: center; }
.chip {
  font-size: 11.5px; padding: 3px 10px; border-radius: 20px; cursor: pointer;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink-2);
  user-select: none;
}
.chip:hover { border-color: var(--primary); color: var(--ink); }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.filters .sp { margin-left: auto; color: var(--muted); font-size: 11.5px; }

/* ---------- 证据层（原文） ---------- */
.doc-view { max-width: 900px; }
.doc-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted); margin-bottom: 12px;
  padding-bottom: 10px; border-bottom: 1px solid var(--line);
}
.doc-body { font-size: 13.5px; line-height: 1.78; color: var(--ink); word-wrap: break-word; }
.doc-body h1 { font-size: 18px; margin: 20px 0 9px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.doc-body h2 { font-size: 15.5px; margin: 18px 0 8px; }
.doc-body h3 { font-size: 14px; margin: 15px 0 6px; color: var(--primary); }
.doc-body h4 { font-size: 13.5px; margin: 12px 0 5px; }
.doc-body p { margin: 8px 0; }
.doc-body ul, .doc-body ol { padding-left: 22px; margin: 8px 0; }
.doc-body li { margin: 3px 0; }
.doc-body code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.doc-body pre.code {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 11px 13px; overflow-x: auto; margin: 10px 0;
}
.doc-body pre.code code { background: none; padding: 0; font-size: 12px; }
.doc-body blockquote {
  margin: 9px 0; padding: 7px 12px; border-left: 3px solid var(--primary);
  background: var(--panel-2); color: var(--ink-2); border-radius: 0 6px 6px 0;
}
.doc-body hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.doc-body .tw { overflow-x: auto; margin: 10px 0; }
.doc-body table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.doc-body th, .doc-body td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.doc-body th { background: var(--panel-2); }
.doc-body mark { background: rgba(210,153,34,.32); color: inherit; border-radius: 2px; }

/* ---------- 雷达 / 漏斗 ---------- */
.radar-wrap { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.radar-legend { flex: 1; min-width: 190px; }
.rl-row { display: flex; align-items: center; gap: 7px; padding: 3px 0; font-size: 12px; }
.rl-row .nm { flex: 0 0 88px; }
.rl-row .sc { font-variant-numeric: tabular-nums; font-weight: 700; flex: 0 0 30px; text-align: right; }
.rl-row .bar { flex: 1; margin-top: 0; }

.funnel { display: flex; flex-direction: column; gap: 5px; }
.fn-item { display: flex; align-items: center; gap: 9px; padding: 6px 10px; border-radius: 7px; background: var(--panel-2); }
.fn-item .ix { width: 19px; height: 19px; border-radius: 5px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex: 0 0 19px; color: #fff; }
.fn-item .nm { flex: 1; font-size: 12.5px; }

/* ---------- 时间线 ---------- */
.tl { position: relative; padding-left: 18px; }
.tl::before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 1.5px; background: var(--line-2); }
.tl-item { position: relative; padding: 5px 0 11px; }
.tl-item::before {
  content: ''; position: absolute; left: -17px; top: 10px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--primary); border: 2px solid var(--bg);
}
.tl-item .h { font-size: 12.5px; font-weight: 600; }
.tl-item .m { font-size: 11px; color: var(--muted); }
.tl-item .b { font-size: 12px; color: var(--ink-2); margin-top: 2px; }

/* ---------- 空态 / 加载 ---------- */
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 9px; padding: 40px; color: var(--muted); font-size: 12.5px; }
.spin { width: 15px; height: 15px; border: 2px solid var(--line-2); border-top-color: var(--primary); border-radius: 50%; animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---------- 返回顶 ---------- */
.to-top {
  position: fixed; right: 22px; bottom: 22px; width: 34px; height: 34px;
  border-radius: 50%; background: var(--panel); border: 1px solid var(--line-2);
  color: var(--ink-2); cursor: pointer; display: none; align-items: center; justify-content: center;
  box-shadow: var(--shadow); z-index: 50;
}
.to-top.show { display: flex; }

/* ---------- 响应式 ---------- */
@media (max-width: 1080px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; flex: 0 0 auto; max-height: 46vh;
    border-right: none; border-bottom: 1px solid var(--line);
  }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .search-wrap { width: 100%; }
  .topbar { height: auto; padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .content { padding: 12px 12px 50px; }
  /* 证据层：元信息条整体换行，避免「文内搜索」把标题挤出可视区 */
  .doc-meta { gap: 6px; }
  .doc-meta > span:last-child { margin-left: 0 !important; width: 100%; }
  .doc-meta input#dsearch { width: 100% !important; }
  /* 正文任何情况下都不允许把页面撑出横向滚动 */
  .doc-body { overflow-wrap: anywhere; word-break: break-word; }
  .doc-body pre.code { max-width: 100%; }
  .doc-body table { display: block; overflow-x: auto; max-width: 100%; }
  .tbl-wrap { max-width: 100%; }
}
/* 极窄屏：表格不硬撑，允许内部横滚 */
@media (max-width: 560px) {
  table.tbl { min-width: 520px; }
}
