:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e6e8eb;
  --text: #1f2329;
  --text-soft: #646a73;
  --text-faint: #8f959e;
  --accent: #2563eb;
  --accent-soft: #eef3ff;
  --green: #15803d;
  --amber: #b45309;
  --code-bg: #f2f4f7;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 0 0 auto; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; letter-spacing: .5px;
}
.brand-text { font-weight: 600; font-size: 16px; display: flex; flex-direction: column; line-height: 1.1; }
.brand-text small { font-weight: 400; font-size: 11px; color: var(--text-faint); letter-spacing: .4px; }

.searchbox { flex: 1; display: flex; max-width: 720px; }
.searchbox input {
  flex: 1; padding: 9px 14px; font-size: 14px;
  border: 1px solid var(--border); border-right: none;
  border-radius: var(--radius) 0 0 var(--radius); outline: none;
  background: #fbfbfc;
}
.searchbox input:focus { background: #fff; border-color: var(--accent); }
.searchbox button {
  padding: 0 20px; border: 1px solid var(--accent); background: var(--accent);
  color: #fff; font-size: 14px; border-radius: 0 var(--radius) var(--radius) 0; cursor: pointer;
}
.searchbox button:hover { background: #1d4ed8; }

/* ---------- Layout ---------- */
.layout { display: flex; align-items: flex-start; min-height: calc(100vh - 56px); }
.sidebar {
  flex: 0 0 280px; width: 280px;
  background: var(--panel); border-right: 1px solid var(--border);
  position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
  padding: 8px 0;
}
.content { flex: 1; padding: 24px 32px; min-width: 0; }

/* ---------- Sidebar tree ---------- */
.nav-sec { border-bottom: 1px solid #f0f1f3; }
.nav-sec > .nav-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; cursor: pointer; user-select: none;
}
.nav-sec > .nav-head:hover { background: var(--accent-soft); }
.nav-sec.open > .nav-head { background: var(--accent-soft); }
.nav-caret { width: 12px; color: var(--text-faint); transition: transform .15s; flex: 0 0 auto; }
.nav-sec.open > .nav-head .nav-caret { transform: rotate(90deg); }
.nav-secno { font-weight: 600; color: var(--accent); flex: 0 0 auto; }
.nav-sectitle { color: var(--text-soft); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-chapters { display: none; padding: 2px 0 6px 26px; }
.nav-sec.open .nav-chapters { display: block; }
.nav-ch {
  padding: 5px 10px; cursor: pointer; color: var(--text-soft); font-size: 13px;
  border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.nav-ch:hover { background: #f2f4f7; color: var(--text); }

/* ---------- Content: headings ---------- */
.crumb { font-size: 13px; color: var(--text-faint); margin-bottom: 16px; }
.crumb a { color: var(--accent); text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.crumb .sep { margin: 0 8px; color: #c8cdd4; }

.page-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.page-sub { color: var(--text-soft); margin: 0 0 20px; }

.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow); transition: border-color .12s;
}
.card:hover { border-color: var(--accent); }
.card .code { font-weight: 600; color: var(--accent); font-family: ui-monospace, Menlo, Consolas, monospace; }
.card .name { color: var(--text-soft); margin-top: 2px; }

.row-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.row {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 16px; border-bottom: 1px solid #f0f1f3; cursor: pointer;
}
.row:last-child { border-bottom: none; }
.row:hover { background: var(--accent-soft); }
.row .code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; color: var(--accent); flex: 0 0 130px; }
.row .name { color: var(--text); flex: 1; }
.row .tag { font-size: 12px; color: var(--text-faint); flex: 0 0 auto; }

/* heading view: subheading group */
.subgroup { margin-bottom: 18px; }
.subgroup-head {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 0;
  border-bottom: 2px solid var(--border); margin-bottom: 4px;
}
.subgroup-head .hs8 { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; color: var(--text); }
.subgroup-head .subname { color: var(--text-soft); }

/* ---------- Search ---------- */
.search-meta { color: var(--text-soft); margin-bottom: 14px; }
.search-meta b { color: var(--text); }
mark { background: #fff3a3; padding: 0 1px; border-radius: 2px; }

/* ---------- Detail ---------- */
.detail-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 26px; font-weight: 700; letter-spacing: .5px; }
.detail-name { font-size: 17px; color: var(--text); margin: 4px 0 2px; }
.detail-en { color: var(--text-faint); font-size: 13px; margin-bottom: 22px; }

.section-block { margin-bottom: 26px; }
.section-block > h3 {
  font-size: 14px; font-weight: 600; margin: 0 0 10px;
  padding-left: 10px; border-left: 3px solid var(--accent);
}
.kv { display: flex; gap: 12px; padding: 6px 0; border-bottom: 1px dashed #eef0f2; }
.kv .k { flex: 0 0 130px; color: var(--text-soft); }
.kv .v { flex: 1; }

table.rates { width: 100%; border-collapse: collapse; font-size: 13px; }
table.rates th, table.rates td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
table.rates th { background: #f7f8fa; color: var(--text-soft); font-weight: 600; }
table.rates td.rate { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; white-space: pre-wrap; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid #d6e2ff; border-radius: 999px;
  padding: 3px 12px; margin: 0 6px 6px 0; font-size: 13px;
}
.pill .pl { font-weight: 700; font-family: ui-monospace, Menlo, Consolas, monospace; }
.pill .pn { color: var(--text-soft); }

.decl-list { list-style: none; padding: 0; margin: 0; }
.decl-list li {
  display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px dashed #eef0f2;
}
.decl-req { font-size: 11px; padding: 1px 8px; border-radius: 4px; flex: 0 0 auto; }
.decl-req.yes { background: #fdecec; color: #c0392b; }
.decl-req.no { background: #eef1f4; color: var(--text-faint); }
.decl-name { flex: 1; }

.empty { color: var(--text-faint); font-style: italic; padding: 6px 0; }

/* ---------- Loading / home ---------- */
.loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 80px 0; color: var(--text-soft); }
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin .8s linear infinite; margin-bottom: 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.home-hero { max-width: 760px; }
.home-hero h1 { font-size: 26px; margin: 0 0 8px; }
.home-hero p { color: var(--text-soft); margin: 0 0 20px; }
.stat-row { display: flex; gap: 28px; flex-wrap: wrap; margin: 18px 0 26px; }
.stat { }
.stat .num { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat .lbl { color: var(--text-faint); font-size: 13px; }
.tips { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.tips h4 { margin: 0 0 8px; font-size: 14px; }
.tips li { color: var(--text-soft); margin: 4px 0; }
