:root {
  --primary: #1E3A5F;
  --secondary: #2563EB;
  --accent: #059669;
  --background: #F8FAFC;
  --foreground: #0F172A;
  --card: #FFFFFF;
  --muted: #F1F3F5;
  --muted-fg: #475569;
  --border: #E4E7EB;
  --ring: #1E3A5F;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

body {
  margin: 0;
  font-family: 'Work Sans', system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  font-size: 16px;
}

.icon { width: 20px; height: 20px; flex-shrink: 0; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--primary); }
.brand h1 { font-family: 'Outfit', sans-serif; font-size: 18px; margin: 0; line-height: 1.2; }
.brand p { margin: 0; font-size: 12px; color: var(--muted-fg); }

.search-wrap {
  flex: 1 1 280px;
  min-width: 220px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-ic { position: absolute; left: 12px; color: var(--muted-fg); pointer-events: none; }

#search {
  width: 100%;
  padding: 10px 40px 10px 40px;
  font: inherit;
  font-size: 15px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--background);
  color: var(--foreground);
  transition: border-color 200ms, box-shadow 200ms;
}
#search:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.15);
}

.clear-btn {
  position: absolute;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border: none; border-radius: 6px;
  background: transparent; color: var(--muted-fg);
  cursor: pointer;
}
.clear-btn:hover { background: var(--muted); color: var(--foreground); }

.toolbar { display: flex; gap: 8px; }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--primary);
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: background 200ms, border-color 200ms;
}
.ghost-btn:hover { background: var(--muted); border-color: var(--primary); }
.ghost-btn:focus-visible, #search:focus-visible, .cat-head:focus-visible, .item-head:focus-visible, .clear-btn:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.stats {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 16px 10px;
  font-size: 13px;
  color: var(--muted-fg);
}

/* ---------- Tree ---------- */
.tree {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 64px;
}

.cat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  overflow: hidden;
}

.cat-head, .item-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  text-align: left;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 200ms;
}
.cat-head:hover, .item-head:hover { background: var(--muted); }

.cat-head {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  font-size: 15px;
  color: var(--primary);
}
.cat-head .chev, .item-head .chev { color: var(--muted-fg); transition: transform 200ms; }
.cat-head[aria-expanded="true"] .chev, .item-head[aria-expanded="true"] .chev { transform: rotate(90deg); }

.cat-code, .item-code {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.cat-code { min-width: 44px; }

.cat-count {
  margin-left: auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-fg);
  background: var(--muted);
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.cat-body { border-top: 1px solid var(--border); }
.cat-body[hidden] { display: none; }

.item {
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: none; }

.item-head { padding: 10px 14px 10px 20px; gap: 12px; }
.item-code {
  color: var(--secondary);
  font-size: 14px;
  min-width: 84px;
}
.item-title { flex: 1; font-size: 14.5px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.heading { color: var(--muted-fg); background: var(--muted); }
.badge.incomplete { color: var(--warn); background: var(--warn-bg); }
.badge.rows { color: var(--muted-fg); background: var(--muted); font-weight: 500; }

.item-body { padding: 0 16px 14px 20px; }
.item-body[hidden] { display: none; }

.meta { font-size: 12px; color: var(--muted-fg); margin: 0 0 8px; }

table.ahs {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.ahs th, table.ahs td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}
table.ahs th {
  background: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  color: var(--muted-fg);
}
table.ahs td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.ahs tr.sec td {
  background: var(--background);
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  font-size: 12.5px;
  color: var(--primary);
  letter-spacing: 0.02em;
}

mark { background: #FDE68A; color: inherit; border-radius: 2px; padding: 0 1px; }

.empty {
  max-width: 1200px;
  margin: 48px auto;
  text-align: center;
  color: var(--muted-fg);
}
.empty .icon { width: 36px; height: 36px; margin-bottom: 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .topbar-inner { padding: 10px 12px; }
  .brand p { display: none; }
  .toolbar { width: 100%; }
  .toolbar .ghost-btn { flex: 1; justify-content: center; }
  .tree { padding: 12px 10px 48px; }
  .item-head { flex-wrap: wrap; padding-left: 14px; }
  .item-title { flex: 1 1 100%; order: 3; }
  .item-code { min-width: 0; }
  table.ahs { font-size: 12.5px; }
  table.ahs th, table.ahs td { padding: 5px 6px; }
}
