:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e0d5;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #15803d;
  --chip: #f5f5f4;
  --shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
  --radius: 10px;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: "Avenir Next", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d8f3ef 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #fde68a55 0%, transparent 50%),
    var(--bg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  justify-content: space-between;
  align-items: flex-end;
  padding: 18px 20px 10px;
}
.brand h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}
.stat b { font-variant-numeric: tabular-nums; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 8px 20px 14px;
}
@media (min-width: 900px) {
  .toolbar {
    grid-template-columns: minmax(220px, 1.4fr) auto auto;
    align-items: center;
  }
}
#q {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font: inherit;
  background: var(--panel);
}
.filters, .actions { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; }
.filters label { font-size: 0.9rem; color: var(--ink); cursor: pointer; user-select: none; }
.actions button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  cursor: pointer;
}
.actions button:hover { border-color: var(--accent); color: var(--accent); }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 16px 16px;
  min-height: 0;
}
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(280px, 1.1fr) minmax(280px, 0.9fr); }
}
.tree-pane, .detail-pane {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-height: 50vh;
  max-height: calc(100vh - 220px);
  overflow: auto;
}
.detail-pane { padding: 16px 18px; }
.placeholder, .empty { color: var(--muted); padding: 16px; }
.hidden { display: none !important; }

.tree { padding: 8px 6px 16px; }
ul.kids { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 1px dashed #ddd6c8; margin-left: 12px; }
.node-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
}
.node-row:hover { background: #f0ebe3; }
.node-row.active { background: var(--accent-soft); outline: 1px solid #99f6e4; }
.twisty {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 18px;
  font-size: 12px;
}
.twisty.leaf { visibility: hidden; }
.code {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  margin-right: 4px;
  white-space: nowrap;
}
.label { font-size: 0.92rem; line-height: 1.35; word-break: break-word; }
.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; }
.chip {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.kind-man { background: #e0f2fe; color: #075985; border-color: #bae6fd; }
.chip.kind-popup { background: #fae8ff; color: #86198f; border-color: #f5d0fe; }
.chip.kind-chuc { background: #ecfccb; color: #3f6212; border-color: #d9f99d; }
.chip.kind-thu { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.chip.kind-con { background: #f5f5f4; color: #44403c; }
.chip.port-co { background: #dcfce7; color: var(--ok); border-color: #bbf7d0; }
.chip.port-thieu { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.chip.port-lech { background: #fef3c7; color: var(--warn); border-color: #fde68a; }

.detail h2 { margin: 0 0 6px; font-size: 1.2rem; letter-spacing: -0.01em; }
.detail .code-lg { font-family: var(--mono); color: var(--accent); font-size: 0.85rem; }
.detail dl {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  margin: 14px 0 0;
  font-size: 0.92rem;
}
.detail dt { color: var(--muted); }
.detail dd { margin: 0; word-break: break-word; }
.detail pre {
  background: #1c1917;
  color: #f5f5f4;
  padding: 10px 12px;
  border-radius: 10px;
  overflow: auto;
  font-size: 0.78rem;
  line-height: 1.45;
}
.tc-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tc-list span {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: #eef2ff;
  color: #3730a3;
  padding: 2px 7px;
  border-radius: 6px;
}

.foot {
  padding: 8px 20px 16px;
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 899px) {
  .tree-pane, .detail-pane { max-height: none; min-height: 40vh; }
  .detail-pane { order: 2; }
}
