:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1f2733;
  --muted: #6b7686;
  --line: #e6e9ef;
  --brand: #2563eb;
  --brand-soft: #eaf1ff;
  --accent: #0ea5a4;
  --rate-13: #ef4444;
  --rate-9: #f59e0b;
  --rate-6: #2563eb;
  --rate-0: #10b981;
  --rate-free: #8b5cf6;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
  --radius: 12px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: linear-gradient(120deg, #2563eb, #0ea5a4);
  color: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
/* 版式：第一行 = logo+品牌名（左，1fr 列）| 标题（auto 列，绝对居中）| 空占位；第二行 = 输入框占满至主页面左边界，按钮/下拉贴右边界 */
.hero-wrap {
  max-width: 1180px; margin: 0 auto 12px; padding: 0 16px;
  display: grid; grid-template-columns: 1fr auto 1fr;
  align-items: center; gap: 18px;
}
/* 品牌区宽度 = 左侧分类树面板宽(300px)且内部居中 → 视觉中轴与分类树对齐 */
.brand { display: flex; align-items: center; justify-content: center; gap: 12px;
  flex: 0 0 auto; justify-self: start; width: 300px;
  text-decoration: none; color: inherit; }
.brand:hover { opacity: .9; }
.brand-logo { height: 44px; width: auto; display: block; }
.brand-name { font-size: 24px; font-weight: 800; line-height: 44px; letter-spacing: .5px; white-space: nowrap; }
.hero {
  min-width: 0; text-align: center;
}
.hero-title { font-size: 22px; font-weight: 800; letter-spacing: 1px; line-height: 1.2; white-space: nowrap; }
.hero-sub { font-size: 13px; opacity: .92; margin-top: 3px; white-space: nowrap; }
.hero-meta { font-size: 12px; opacity: .78; margin-top: 3px; white-space: nowrap; }

/* 第二行：输入框从主页面左边界起（占满），按钮与筛选下拉贴右边界 */
.search {
  display: flex; align-items: center; gap: 8px;
  max-width: 1180px; margin: 0 auto; padding: 0 16px;
}
.search input[type=text] {
  flex: 1 1 auto; min-width: 0;
  padding: 10px 14px; border: none; border-radius: 9px;
  font-size: 14px; outline: none; background: #fff; color: var(--ink);
}
.filters { display: flex; gap: 8px; flex: 0 0 auto; }
.filters select {
  padding: 10px 10px; border: none; border-radius: 9px;
  font-size: 13px; background: #fff; color: var(--ink); max-width: 120px;
}
.search button {
  padding: 10px 18px; border: none; border-radius: 9px;
  background: #0f172a; color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.search button:active { transform: scale(.97); }

/* ---------- 页脚（版权 + 声明） ---------- */
.site-footer {
  max-width: 1180px; margin: 4px auto 24px; padding: 0 16px;
  text-align: center;
}
.site-footer .foot-main {
  display: flex; justify-content: center; align-items: baseline;
  flex-wrap: wrap; gap: 8px 40px;
  font-size: 13px; color: #64748b;
}
.site-footer .foot-main .visit { color: #94a3b8; }
.site-footer .foot-main .visit b { color: var(--brand); font-weight: 700; }
.site-footer .foot-main a { color: inherit; text-decoration: none; }
.site-footer .foot-main a:hover { color: var(--brand); text-decoration: underline; }
.site-footer .foot-note { margin-top: 6px; font-size: 12px; font-weight: 700; color: var(--brand); }

/* ---------- 布局 ---------- */
.layout { display: flex; align-items: flex-start; gap: 16px; padding: 16px; max-width: 1180px; margin: 0 auto; }
.tree-panel {
  width: 300px; flex: 0 0 300px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); max-height: calc(100vh - 180px); overflow: auto; position: sticky; top: 160px;
}
.content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

.panel-title { font-weight: 700; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }

/* ---------- 分类树 ---------- */
#tree { padding: 8px 6px 16px; }
.tnode { user-select: none; }
.tnode-row {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tnode-row:hover { background: var(--brand-soft); }
.tnode-row .twist { width: 16px; text-align: center; color: var(--muted); transition: transform .15s; flex: 0 0 16px; font-size: 11px; }
.tnode.collapsed > .tnode-row .twist { transform: rotate(-90deg); }
.tnode-row .tname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tnode-row .trate { font-size: 11px; padding: 1px 6px; border-radius: 6px; color: #fff; flex: 0 0 auto; }
.tnode.collapsed > .tchildren { display: none; }
.tchildren { margin-left: 14px; border-left: 1px dashed var(--line); padding-left: 4px; }
.lvl-1 > .tnode-row .tname { font-weight: 700; }
.pref-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--rate-free); flex: 0 0 7px; }

/* ---------- 结果区 ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.result-count { color: var(--muted); font-size: 13px; }
.result-count b { color: var(--ink); }
.breadcrumb { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.breadcrumb span { cursor: pointer; color: var(--brand); }
.breadcrumb span:hover { text-decoration: underline; }

#results { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s;
  display: flex; flex-direction: column; gap: 8px;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(16,24,40,.12); }
.card .c-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .c-name { font-weight: 700; font-size: 15px; }
.card .c-code {font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;  font-size: 14px;  color: var(--muted);  letter-spacing: -.3px;  word-break: break-all;}
.card .c-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 14px; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.badge-rate { font-size: 12px; font-weight: 700; color: #fff; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge-pref { font-size: 11px; color: var(--rate-free); border: 1px solid var(--rate-free); padding: 1px 7px; border-radius: 999px; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- 统计 ---------- */
.stats-panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat-cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stat-card { flex: 1 1 120px; background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; }
.stat-card .v { font-size: 24px; font-weight: 800; color: var(--brand); }
.stat-card .l { font-size: 12px; color: var(--muted); }
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-box { display: flex; flex-direction: column; background: var(--bg); border-radius: 10px; padding: 12px; height: 320px; }
.chart-box h4 { margin: 4px 6px 8px; font-size: 14px; flex: 0 0 auto; }
.chart-canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; }

/* ---------- 详情弹窗（居中、可拖拽） ---------- */
.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-mask.show { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 560px; max-height: 85vh; overflow: auto;
  border-radius: 16px; padding: 20px; position: relative; animation: pop .2s ease; will-change: transform;
}
@keyframes pop { from { opacity: .5; } to { opacity: 1; } }
.m-header { padding-right: 40px; cursor: move; user-select: none; touch-action: none; }
.modal h3 { margin: 0 0 4px; font-size: 19px; }
.modal .m-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; color: var(--muted); word-break: break-all; }
.modal .m-close { position: absolute; top: 14px; right: 14px; border: none; background: var(--bg); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted); z-index: 2; }
.modal .m-close:hover { background: #e2e8f0; }
.modal .m-close:active { transform: scale(.94); }
.dl { margin-top: 14px; border-top: 1px solid var(--line); }
.dl .row { display: flex; gap: 12px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.dl .row .k { flex: 0 0 96px; color: var(--muted); font-size: 13px; }
.dl .row .v { flex: 1; font-size: 14px; word-break: break-word; }

/* ---------- 移动端底部标签栏 ---------- */
.tabbar { display: none; }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .charts { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  body { font-size: 15px; padding-bottom: 64px; }
  /* 移动端：顶栏纵向堆叠（品牌 → 标题 → 输入框整行 → 按钮+两个下拉一行） */
  .hero-wrap { grid-template-columns: 1fr; gap: 8px; margin-bottom: 10px; padding: 0; }
  .brand { width: auto; justify-content: flex-start; }
  .brand-logo { height: 30px; }
  .brand-name { font-size: 22px; line-height: 30px; }
  .hero { text-align: left; }
  .hero-title { font-size: 20px; white-space: normal; }
  .hero-sub { font-size: 12px; white-space: normal; }
  .hero-meta { font-size: 11px; white-space: normal; }
  .search { width: 100%; max-width: none; padding: 0; flex-wrap: wrap; }
  .search input[type=text] { flex: 1 1 100%; max-width: none; }
  .search button { flex: 0 0 auto; }
  .filters { flex: 1 1 0; min-width: 0; }
  .filters select { flex: 1 1 0; min-width: 0; max-width: none; width: auto; }
  .layout { flex-direction: column; padding: 12px; gap: 12px; }
  .tree-panel { width: auto; flex: none; position: static; max-height: none; border-radius: var(--radius); }
  .content { gap: 12px; }
  #results { grid-template-columns: 1fr; }

  /* 移动端用底部标签切换面板 */
  .tabbar {
    width: 100%;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: #fff; border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(16,24,40,.08);
    padding-bottom: env(safe-area-inset-bottom);
    overflow: hidden;
  }
  .tabbar button {
    float: left; width: 33.3333%; box-sizing: border-box;
    border: none; background: none; padding: 10px 0 8px; cursor: pointer;
    font-size: 12px; color: #475569; text-align: center;
  }
  .tabbar button .ic { display: block; margin: 0 auto 4px; }
  .tabbar button .ic svg { width: 22px; height: 22px; }
  .tabbar button .ic { font-size: 19px; display: inline-flex; }
  .tabbar button .ic svg { width: 22px; height: 22px; }
  .tabbar button.active { color: var(--brand); font-weight: 700; }

  .tree-panel, .stats-panel, .results-panel { display: none; }
  .tab-show-tree .tree-panel,
  .tab-show-stats .stats-panel,
  .tab-show-results .results-panel { display: block; }
  .modal { border-radius: 16px; }
}
