/* JSON View 页面样式：只用系统字体与本地资源，无任何外链 / CDN / 远程字体。 */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #1f2328;
  --muted: #6b7280;
  --accent: #f59e0b;
  --accent-ink: #92400e;
  --ok: #0f766e;
  --bad: #b91c1c;
  --key: #0b7285;
  --str: #c2410c;
  --num: #1d4ed8;
  --bool: #7c3aed;
  --null: #9ca3af;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ------------------------------------------------------------ 站点外壳：导航条与广告位
 * 这两个组件属于站点级外壳（每个页面都有），不是本工具自身的 UI。
 * 之所以把样式写在这里而不用 assets/site.css：工具页的布局很精细（行号对齐等），
 * 站点级 reset 会破坏它。工具页只共享 assets/site.js 的行为，不共享站点样式。 */

.site-nav {
  flex: 0 0 auto; display: flex; align-items: center; gap: 16px;
  height: 46px; padding: 0 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.site-nav a { text-decoration: none; color: var(--muted); font-size: 13px; }
.site-nav a:hover { color: var(--accent-ink); }
.site-nav .brand {
  display: flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 650; color: var(--text);
}
.site-nav .brand i {
  width: 20px; height: 20px; border-radius: 5px; background: #2563eb; color: #fff;
  font-size: 10px; font-style: normal; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
/* 工具页导航只有「返回首页」这一个出口，不列其他工具 */
.site-nav .back { margin-left: auto; }

/* 广告位：为空（.ad:empty）时不占位；内容承载在 ads/slot.html 的 iframe 里。
   固定高度是为了广告加载后不产生布局跳动（CLS）。 */
.ad { flex: 0 0 auto; position: relative; display: flex; justify-content: center; }
.ad:empty { display: none; }
.ad-frame { display: block; width: 100%; height: 100%; border: 0; }
.ad-inline { width: 100%; height: 90px; }
.ad-label {
  position: absolute; right: 8px; top: 2px; pointer-events: none;
  font-size: 10px; line-height: 14px; padding: 0 4px; border-radius: 4px;
  color: #9ca3af; background: rgba(255,255,255,.9); border: 1px solid var(--line);
}

/* ------------------------------------------------------------ 按钮 */
button, select, input[type="text"] {
  font-family: inherit; font-size: 13px;
}
button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  cursor: pointer;
}
button:hover { border-color: var(--accent); color: var(--accent-ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(0.95); color: #fff; }
button.mini { padding: 4px 8px; font-size: 12px; }
/* 需要突出的动作（复制 / 清空）：描边 + 淡底，与 primary 主操作区分开 */
button.hi {
  border-color: var(--accent); background: #fffbeb; color: var(--accent-ink); font-weight: 600;
}
button.hi:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { border-color: #fecaca; background: #fef2f2; color: var(--bad); }
button.danger:hover { background: var(--bad); border-color: var(--bad); color: #fff; }
.switch { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.switch button { border: 0; border-radius: 0; background: #fff; }
.switch button.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ------------------------------------------------------------ Tab 条（子工具切换） */
/* 竞品同款形态：横向一排 tab，active 与下方内容连成一体；tab 多了横向滚动 */
.tabs {
  display: flex; align-items: flex-end; gap: 4px;
  padding: 10px 20px 0;
  background: var(--panel); border-bottom: 1px solid var(--line);
  overflow-x: auto; flex: 0 0 auto;
}
.tabs button {
  border: 1px solid transparent; border-bottom: 0;
  background: transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 8px 8px 0 0;
  font-size: 13px; white-space: nowrap;
}
.tabs button:hover { color: var(--text); border-color: transparent; background: #f3f4f6; }
.tabs button.active {
  background: var(--panel); border-color: var(--line); color: var(--accent-ink);
  font-weight: 600; position: relative; top: 1px;   /* 盖住容器底边线，与内容连体 */
}
.tab-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ 工具条 */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.group { display: flex; align-items: center; gap: 8px; }
.group.right { margin-left: auto; }
.opts { color: var(--muted); font-size: 12px; flex-wrap: wrap; }
.opts label { display: inline-flex; align-items: center; gap: 4px; }
select, #keyword {
  padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}

/* ------------------------------------------------------------ 主体 */
main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 12px 20px;
}
@media (max-width: 900px) { main { grid-template-columns: 1fr; } }

.pane {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.pane-head {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; border-bottom: 1px solid var(--line); background: #fafafa;
}
.pane-title { font-weight: 600; font-size: 13px; }
.meta { color: var(--muted); font-size: 12px; }
.tree-tools { margin-left: auto; display: flex; gap: 6px; }

/* 输入区：行号槽 + 编辑框。两者 font-size / line-height / padding-top 必须一致才能对齐。 */
.input-wrap { flex: 1; min-height: 0; display: flex; background: #fff; }
.gutter {
  flex: 0 0 auto; width: 46px; overflow: hidden;
  padding: 12px 8px 12px 0; border-right: 1px solid var(--line); background: #fafafa;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; line-height: 21px;
  color: #9ca3af; text-align: right; user-select: none;
}
.gutter pre { margin: 0; font: inherit; }
.gutter .ln.err { color: var(--bad); font-weight: 700; }
#input {
  flex: 1; min-height: 0; resize: none;
  padding: 12px; border: 0; outline: none;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; line-height: 21px;
  color: var(--text);
  white-space: pre; overflow: auto;   /* 不自动折行：保证逻辑行与行号严格一一对应 */
}
.hint { padding: 6px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: #fafafa; }

.search-box { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.search-box #keyword { flex: 1; }

.view { flex: 1; min-height: 0; overflow: auto; padding: 8px 4px 16px; }
.view.empty { color: var(--muted); padding: 24px; font-size: 13px; }

/* ------------------------------------------------------------ 树形视图 */
.node-wrap.collapsed > .children { display: none; }
.row {
  display: flex; align-items: baseline; gap: 6px;
  padding: 2px 8px; border-radius: 4px; cursor: default; white-space: nowrap;
}
.row:hover { background: #fff7ed; }
.toggle { width: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.toggle.leaf { cursor: default; }
.key { color: var(--key); font-weight: 600; }
.key.idx { color: var(--muted); font-weight: 500; }
.colon { color: var(--muted); }
.val { font-family: "SFMono-Regular", Menlo, Consolas, monospace; }
.val-str { color: var(--str); }
.val-num { color: var(--num); }
.val-bool { color: var(--bool); }
.val-null { color: var(--null); }
.val-brace { color: var(--muted); }
.meta-count { color: var(--muted); font-size: 12px; }
.path { margin-left: auto; color: #cbd5e1; font-size: 11px; padding-left: 12px; cursor: pointer; }
.row:hover .path { color: var(--accent-ink); }
.node-wrap.hit > .row { background: #fef3c7; }
.node-wrap.flash > .row { background: #fde68a; }
.children { border-left: 1px dashed var(--line); margin-left: 12px; }

/* ------------------------------------------------------------ 文本视图 */
pre.text-view {
  margin: 0; padding: 4px 12px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-all;
}
.tk-key { color: var(--key); font-weight: 600; }
.tk-str { color: var(--str); }
.tk-num { color: var(--num); }
.tk-bool { color: var(--bool); }
.tk-null { color: var(--null); }
.tk-punct { color: var(--muted); }

/* ------------------------------------------------------------ 错误与状态 */
.err-box {
  margin: 12px; padding: 12px; border: 1px solid #fecaca; background: #fef2f2; border-radius: 8px;
}
.err-box .msg { color: var(--bad); font-weight: 600; margin-bottom: 6px; }
.err-box .hint { color: var(--muted); background: none; border: 0; padding: 0 0 8px; }
.err-box pre {
  margin: 0; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 6px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; overflow: auto;
}
.notice { margin: 12px; color: var(--muted); font-size: 12px; }

.hits { max-height: 180px; overflow: auto; border-top: 1px solid var(--line); background: #fffdf7; padding: 8px 12px; }
.hits.hidden { display: none; }
.hits .hit-item {
  display: flex; gap: 8px; align-items: baseline; width: 100%; text-align: left;
  border: 0; background: none; padding: 3px 0; cursor: pointer;
}
.hits .hit-item:hover { color: var(--accent-ink); }
.hits .hit-path { font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; color: var(--key); }
.hits .hit-val { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hits .hit-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

.status {
  padding: 8px 20px; border-top: 1px solid var(--line); background: var(--panel);
  font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.warn { color: var(--accent-ink); }
