:root {
  --ink: #16213a;
  --ink-soft: #2b3a55;
  --muted: #5b6779;
  --line: #dfe4ec;
  --line-soft: #edf0f5;
  --bg: #f4f6fa;
  --card: #ffffff;
  --accent: #1d4ed8;
  --accent-dark: #0f2a5c;
  --accent-soft: #dbeafe;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --amber: #92400e;
  --amber-soft: #fef3c7;
  --teal: #0f766e;
  --purple: #6d28d9;
  --pink: #be185d;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 33, 58, .08), 0 4px 14px rgba(16, 33, 58, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }
body { overflow-x: clip; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
}
.wrap { max-width: 1020px; margin: 0 auto; padding: 0 16px; }
a { color: var(--accent); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- header ---------- */
.top {
  background:
    radial-gradient(1100px 300px at 85% -60px, rgba(96, 165, 250, .45), transparent 60%),
    linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: #fff;
  padding: 34px 0 0;
}
.brand { display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-end; }
.top h1 { margin: 0; font-size: 2.1rem; letter-spacing: .4px; line-height: 1.1; }
.tagline { margin: 8px 0 0; opacity: .93; max-width: 620px; font-size: 1rem; }
.stats { display: flex; flex-wrap: wrap; gap: 8px; }
.stat {
  background: rgba(255, 255, 255, .14);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: .88rem;
  white-space: nowrap;
}
.stat b { font-size: 1.02rem; }
.tabs-main {
  display: flex; gap: 4px;
  margin-top: 24px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs-main::-webkit-scrollbar { display: none; }
.tabs-main button {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, .82);
  padding: 11px 18px;
  font-size: .98rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  min-height: 44px;
}
.tabs-main button.current { color: #fff; border-bottom-color: #fbbf24; }
.tabs-main button:hover { color: #fff; }

/* ---------- views ---------- */
.view { padding-top: 8px; }
.view-intro { color: var(--muted); font-size: .95rem; margin: 16px 0 12px; }
.view-intro b { color: var(--ink-soft); }

/* ---------- overview charts ---------- */
.overview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 18px 0 6px;
}
.ov-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.ov-card.wide { grid-column: 1 / -1; }
.ov-card h2 { margin: 0 0 10px; font-size: 1rem; color: var(--ink-soft); }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }
.donut-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.donut-wrap svg { flex: none; }
.donut-center { font-size: .85rem; color: var(--muted); }
.donut-center b { display: block; font-size: 1.5rem; color: var(--ink); line-height: 1.1; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; font-size: .9rem; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend .sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.legend .n { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-row { display: grid; grid-template-columns: 74px 1fr 44px; align-items: center; gap: 10px; margin: 7px 0; font-size: .9rem; }
.bar-row .lbl { font-weight: 600; text-transform: uppercase; font-size: .82rem; }
.bar-track { background: var(--line-soft); border-radius: 999px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); }
.bar-row .val { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.hist { width: 100%; height: auto; display: block; }
.hist .bar { fill: var(--accent); }
.hist .bar:hover { fill: var(--accent-dark); }
.hist .axis { font-size: 10px; fill: var(--muted); }

/* ---------- directory ---------- */
.controls { padding: 18px 0 4px; }
#q, #s-q {
  width: 100%;
  font-size: 1.05rem;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
#q:focus, #s-q:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.filters label, .graph-tools label { font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.filters select, .graph-tools select {
  font-size: .95rem;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  max-width: 260px;
  min-height: 42px;
}
.count { color: var(--muted); font-size: .92rem; margin: 14px 0 8px; }

.list { display: grid; gap: 10px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.card:hover { border-color: var(--accent); box-shadow: 0 2px 6px rgba(29, 78, 216, .14), 0 8px 22px rgba(16, 33, 58, .1); transform: translateY(-1px); }
.card h3 { margin: 0 0 6px; font-size: 1.02rem; line-height: 1.4; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .85rem; color: var(--muted); }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.5;
}
.badge.tipe { background: var(--accent-soft); color: var(--accent); }
.badge.berlaku { background: var(--green-soft); color: var(--green); }
.badge.tidak { background: var(--red-soft); color: var(--red); }
.badge.mk { background: var(--amber-soft); color: var(--amber); }
.badge.netral { background: #e5e7eb; color: #374151; }
.empty { color: var(--muted); padding: 32px 0; text-align: center; }

.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; padding: 20px 0 8px; }
.pager button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 13px;
  font-size: .9rem;
  cursor: pointer;
  min-height: 40px;
}
.pager button[disabled] { opacity: .45; cursor: default; }
.pager button.current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- graph ---------- */
.graph-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 12px; }
.graph-tools .check { flex-direction: row; align-items: center; gap: 8px; font-size: .92rem; color: var(--ink-soft); min-height: 42px; }
.graph-tools .check input { width: 18px; height: 18px; accent-color: var(--accent); }
.btn {
  border: 1px solid var(--accent);
  background: var(--card);
  color: var(--accent);
  border-radius: 8px;
  padding: 9px 15px;
  font-size: .92rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
}
.btn:hover { background: var(--accent-soft); }
.graph-count { margin-left: auto; color: var(--muted); font-size: .9rem; align-self: center; }
.graph-wrap {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
#graph { display: block; width: 100%; height: 560px; touch-action: none; cursor: grab; }
#graph:active { cursor: grabbing; }
.graph-tip {
  position: absolute;
  pointer-events: none;
  background: rgba(22, 33, 58, .94);
  color: #fff;
  font-size: .85rem;
  padding: 6px 10px;
  border-radius: 8px;
  max-width: 280px;
  z-index: 5;
}
.graph-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
  background: var(--card);
  font-size: .95rem;
}
.graph-legend { margin-top: 12px; flex-wrap: wrap; }

/* ---------- genealogy ---------- */
.family-search { position: relative; margin-top: 4px; }
.suggest {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 33, 58, .16);
  z-index: 10;
  max-height: 320px;
  overflow-y: auto;
}
.suggest button {
  display: block; width: 100%; text-align: left;
  border: none; background: none;
  padding: 11px 14px; font-size: .93rem; cursor: pointer;
  border-bottom: 1px solid var(--line-soft);
  min-height: 44px;
}
.suggest button:hover, .suggest button:focus-visible { background: var(--accent-soft); }
.suggest button:last-child { border-bottom: none; }
.family-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.family-chips button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: .87rem;
  cursor: pointer;
  min-height: 38px;
  box-shadow: var(--shadow);
}
.family-chips button:hover { border-color: var(--accent); color: var(--accent); }
.tree-scroll { overflow-x: auto; padding: 8px 2px 20px; -webkit-overflow-scrolling: touch; }
.tree { min-width: 560px; }
.tree ul { list-style: none; margin: 0; padding: 18px 0 0; display: flex; justify-content: center; position: relative; }
.tree ul::before {
  content: ""; position: absolute; top: 0; left: 50%;
  width: 0; height: 18px; border-left: 2px solid #b6c2d4;
}
.tree li { position: relative; padding: 18px 6px 0; text-align: center; flex: 1 1 0; min-width: 0; }
.tree li::before, .tree li::after {
  content: ""; position: absolute; top: 0; right: 50%;
  width: 50%; height: 18px; border-top: 2px solid #b6c2d4;
}
.tree li::after { right: auto; left: 50%; border-left: 2px solid #b6c2d4; }
.tree li:only-child::before, .tree li:only-child::after { display: none; }
.tree li:only-child { padding-top: 0; }
.tree li:first-child::before, .tree li:last-child::after { border: none; }
.tree li:last-child::before { border-right: 2px solid #b6c2d4; border-radius: 0 6px 0 0; }
.tree li:first-child::after { border-radius: 6px 0 0 0; }
.tree > ul { padding-top: 0; }
.tree > ul::before { display: none; }
.tree-node {
  display: inline-block;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 9px 12px;
  max-width: 220px;
  cursor: pointer;
  text-align: center;
  vertical-align: top;
}
.tree-node:hover { border-color: var(--accent); }
.tree-node.root { border-color: var(--accent); background: var(--accent-soft); }
.tree-node .t { font-weight: 700; font-size: .88rem; line-height: 1.35; }
.tree-node .s { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.tree-node .c { font-size: .78rem; color: var(--accent); font-weight: 600; margin-top: 2px; }
.tree-empty { color: var(--muted); padding: 28px 0; text-align: center; }

/* ---------- modal ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 12px;
  z-index: 50;
  overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--card);
  border-radius: 14px;
  max-width: 860px;
  width: 100%;
  padding: 24px 24px 32px;
  position: relative;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.modal-close {
  position: absolute; top: 8px; right: 12px;
  border: none; background: none;
  font-size: 2rem; line-height: 1;
  cursor: pointer; color: var(--muted);
  min-width: 44px; min-height: 44px;
}
.detail h2 { margin: 0 0 8px; font-size: 1.3rem; line-height: 1.35; padding-right: 36px; }
.detail .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px 12px;
  font-size: .93rem;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-bottom: 16px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.mk-box {
  background: var(--amber-soft);
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .92rem;
  margin-bottom: 16px;
}
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 8px 15px;
  font-size: .9rem;
  cursor: pointer;
  min-height: 40px;
}
.tabs button.current { background: var(--ink); color: #fff; border-color: var(--ink); }
.detail-search {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: .95rem;
}
.node { padding: 6px 0 6px 12px; border-left: 3px solid var(--line); margin-bottom: 6px; }
.node.pasal { border-left-color: var(--accent); }
.node.buku, .node.bab { border-left-color: var(--ink); font-weight: 700; padding-top: 10px; }
.node .ntype { font-size: .75rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); display: block; }
.node p { margin: 2px 0; }
.fulltext {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .95rem;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  max-height: 70vh;
  overflow-y: auto;
}
.more {
  display: block;
  margin: 14px auto 0;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  font-size: .95rem;
  min-height: 42px;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.actions a {
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 14px;
  text-decoration: none;
  font-size: .9rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.actions a.primary { background: var(--accent); color: #fff; }

/* ---------- footer ---------- */
.foot { color: var(--muted); font-size: .88rem; padding: 28px 16px 40px; border-top: 1px solid var(--line); margin-top: 24px; }
.foot p { margin: 6px 0; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .overview { grid-template-columns: 1fr; }
  .ov-card.wide { grid-column: auto; }
}
@media (max-width: 640px) {
  .top { padding-top: 26px; }
  .top h1 { font-size: 1.7rem; }
  .tagline { font-size: .95rem; }
  .brand { flex-direction: column; align-items: stretch; gap: 14px; }
  .brand > div { min-width: 0; }
  .stats { width: 100%; }
  .tabs-main button { padding: 10px 13px; font-size: .93rem; }
  .filters { flex-direction: column; }
  .filters label { width: 100%; }
  .filters select { max-width: none; width: 100%; }
  .graph-tools { flex-direction: column; align-items: stretch; }
  .graph-tools label { width: 100%; }
  .graph-tools select { max-width: none; width: 100%; }
  .graph-count { margin-left: 0; }
  #graph { height: 68vh; min-height: 420px; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { font-weight: 600; margin-top: 6px; }
  .modal { padding: 0; }
  .modal-box { border-radius: 0; min-height: 100%; padding: 20px 16px 40px; }
  .detail h2 { font-size: 1.15rem; }
  .fulltext { max-height: none; }
  .tree { min-width: 480px; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
}

/* ---------- pencarian lanjutan ---------- */
.search-row { display: flex; gap: 10px; }
.search-row #q { flex: 1; min-width: 0; }
.search-row select {
  flex: none;
  font-size: .95rem;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  min-height: 48px;
}
.az { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.az button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 7px;
  min-width: 30px;
  min-height: 32px;
  padding: 3px 6px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.az button:hover { border-color: var(--accent); color: var(--accent); }
.az button.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- daftar isi & tautan pasal ---------- */
.toc {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: #f8fafc;
  font-size: .92rem;
}
.toc summary { cursor: pointer; font-weight: 700; min-height: 32px; }
.toc ol { margin: 8px 0 2px; padding-left: 20px; max-height: 260px; overflow-y: auto; }
.toc li { margin: 3px 0; }
.toc a { text-decoration: none; }
.toc a:hover { text-decoration: underline; }
.pasal-link {
  border: none;
  background: none;
  color: var(--accent);
  font-size: .8rem;
  cursor: pointer;
  padding: 2px 0;
  margin-top: 2px;
}
.pasal-link:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .search-row { flex-direction: column; }
  .search-row select { width: 100%; }
}

/* ---------- pencarian v3 ---------- */
.search-row { position: relative; }
.search-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; font-size: .88rem; }
.chips-label { color: var(--muted); margin-left: 6px; }
.chips-label:first-child { margin-left: 0; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: .85rem;
  cursor: pointer;
  min-height: 32px;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
mark { background: #fde68a; color: inherit; border-radius: 2px; padding: 0 1px; }
.card .kat { font-size: .85rem; color: var(--muted); margin: 2px 0 6px; }
.badge.anak { background: #ccfbf1; color: var(--teal); }
.badge.isi { background: #e0e7ff; color: #3730a3; font-weight: 500; }
.fuzzy-hint { display: block; margin-bottom: 2px; }
.fuzzy-hint a { font-weight: 600; }
#q-suggest button { display: flex; flex-direction: column; gap: 1px; align-items: flex-start; }
#q-suggest button.on { background: var(--accent-soft); }
.sug-title { font-weight: 600; font-size: .93rem; line-height: 1.35; text-align: left; }
.sug-meta { font-size: .8rem; color: var(--muted); }
.related { margin-bottom: 16px; }
.related h3 { margin: 0 0 6px; font-size: .95rem; color: var(--ink-soft); }
.related ul { margin: 0; padding-left: 20px; font-size: .92rem; }
.related li { margin: 3px 0; }
.related a { text-decoration: none; }
.related a:hover { text-decoration: underline; }

@media (max-width: 640px) {
  .search-chips { gap: 5px; }
}
