*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --border: #e0e0e0;
  --muted: #888;
  --bg: #f5f5f5;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: #222;
  height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 13px;
}

/* ── toolbar ─────────────────────────────────────────────────────────── */
#toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.back-btn {
  text-decoration: none;
  color: #666;
  font-size: 18px;
  padding: 2px 8px;
  border-radius: 6px;
}
.back-btn:hover { background: #f0f0f0; }
.app-title { font-weight: 700; font-size: 15px; }
#toolbar label { color: #666; display: flex; align-items: center; gap: 5px; }
#toolbar select { font: inherit; padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px; }
.stats { margin-left: auto; color: var(--muted); font-size: 12px; }

#tabs { display: flex; gap: 2px; }
.tab {
  font: inherit;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: #666;
  cursor: pointer;
}
.tab:hover { background: #f0f0f0; }
.tab.active { background: #eef4ff; border-color: #cfe0ff; color: #1a56c4; font-weight: 600; }

/* ── views ───────────────────────────────────────────────────────────── */
.view { display: none; flex: 1; min-height: 0; }
.view.active { display: flex; }
#view-entities { flex-direction: row; }
#view-suspects, #view-discards, #view-families { flex-direction: column; }
#view-overview { flex-direction: column; overflow: auto; padding: 10px 14px 14px; }

/* ── overview beeswarm ───────────────────────────────────────────────── */
.sw-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  color: #666;
  margin-bottom: 6px;
}
.sw-bar label { display: flex; align-items: center; gap: 6px; }
.sw-bar select,
.sw-bar input[type="search"] {
  font: inherit;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fff;
  color: #222;
}
.sw-bar input[type="search"] { width: 190px; }
.sw-bar .rng input { width: 130px; }
.sw-bar .rng output { min-width: 18px; font-variant-numeric: tabular-nums; font-weight: 600; color: #333; }
.sw-bar .chk { cursor: pointer; }
.sw-note { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

#sw-wrap {
  position: relative;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
#sw-svg { display: block; width: 100%; cursor: crosshair; }
#sw-svg .dot { stroke: #fff; stroke-width: 0.5; }
#sw-svg .dot.dim { opacity: 0.12; }
#sw-svg .dot.hit { stroke: #111; stroke-width: 1.5; }
#sw-svg .grid { stroke: #efefef; stroke-width: 1; }
#sw-svg .axis { stroke: #d0d0d0; stroke-width: 1; }
#sw-svg .tick { fill: #999; font-size: 10px; text-anchor: middle; }
#sw-svg .band { fill: #e8eaed; }
#sw-svg .bandlab { fill: #b0b4b8; font-size: 9px; }

.sw-tip {
  position: absolute;
  z-index: 10;
  max-width: 320px;
  padding: 8px 10px;
  background: #1e1e1e;
  color: #f2f2f2;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.sw-tip.hidden { display: none; }
.sw-tip .t-label { font-weight: 600; margin-bottom: 3px; }
.sw-tip .t-meta { color: #b8b8b8; }
.sw-tip .t-swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

.sw-foot {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.sw-legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 11px; color: #777; }
.sw-legend .key { display: flex; align-items: center; gap: 5px; }
.sw-legend .sw { width: 9px; height: 9px; border-radius: 50%; }
.sw-legend .sizes { display: flex; align-items: flex-end; gap: 8px; margin-left: 6px; }
.sw-caveat { font-size: 11px; color: #a0a0a0; text-align: right; max-width: 470px; line-height: 1.5; }

.subbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.subbar label { color: #666; display: flex; align-items: center; gap: 5px; }
.subbar input { font: inherit; padding: 3px 6px; border: 1px solid var(--border); border-radius: 5px; }
.subbar input[type="search"] { width: 280px; }
.subbar input[type="number"] { width: 72px; }
.subbar button {
  font: inherit; padding: 4px 12px; border: 1px solid #cfe0ff;
  background: #eef4ff; color: #1a56c4; border-radius: 6px; cursor: pointer;
}
.scroll { flex: 1; overflow-y: auto; padding: 14px; }

/* ── sidebar ─────────────────────────────────────────────────────────── */
#sidebar {
  width: 430px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: #fff;
  min-height: 0;
}
#filters { padding: 10px; border-bottom: 1px solid var(--border); }
#filters input[type="search"] { width: 100%; font: inherit; padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; }
#filters input[type="number"] { width: 62px; font: inherit; padding: 3px 5px; border: 1px solid var(--border); border-radius: 5px; }
.frow { display: flex; gap: 10px; margin-top: 6px; align-items: center; color: #666; }
.frow.wrap { flex-wrap: wrap; }
.frow label { display: flex; align-items: center; gap: 4px; }
.chk { display: flex; align-items: center; gap: 4px; color: #666; margin-top: 6px; cursor: pointer; }
.sortrow { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: #666; }
.sortrow select { font: inherit; padding: 3px 5px; border: 1px solid var(--border); border-radius: 5px; }
.count { margin-top: 6px; color: var(--muted); font-size: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.chip {
  font-size: 11px; padding: 2px 8px; border: 1px solid var(--border);
  border-radius: 10px; background: #fafafa; color: #777; cursor: pointer; user-select: none;
}
.chip.on { background: #eef4ff; border-color: #cfe0ff; color: #1a56c4; font-weight: 600; }

/* ── entity list ─────────────────────────────────────────────────────── */
#entity-list { flex: 1; overflow-y: auto; }
.erow { padding: 8px 10px; border-bottom: 1px solid #f0f0f0; cursor: pointer; }
.erow:hover { background: #fafafa; }
.erow.sel { background: #eef4ff; }
.erow .l1 { display: flex; align-items: baseline; gap: 6px; }
.erow .eid { color: #aaa; font-size: 11px; font-variant-numeric: tabular-nums; }
.erow .lab { font-weight: 600; flex: 1; }
.erow .n { color: #555; font-size: 11px; white-space: nowrap; }
.erow .l2 { display: flex; align-items: center; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 11px; }

.badge { font-size: 10px; padding: 1px 5px; border-radius: 3px; background: #eee; color: #666; }
.inst { font-size: 10px; padding: 1px 5px; border-radius: 3px; color: #fff; font-weight: 600; }
.inst.imf { background: #4363d8; }
.inst.wb { background: #3cb44b; }
.inst.oecd { background: #f58231; }
.inst.eiu { background: #911eb4; }
.inst.usstate { background: #808000; }

.st { font-size: 10px; padding: 1px 6px; border-radius: 3px; font-weight: 600; }
.st-implemented { background: #d9f2df; color: #1c6b33; }
.st-approved    { background: #dcecff; color: #1a4f9c; }
.st-proposed    { background: #fdf0d5; color: #8a5a00; }
.st-amended     { background: #ece0f8; color: #6a2ca0; }
.st-reversed    { background: #fadbd8; color: #a02020; }
.st-suspended   { background: #fce8d5; color: #9a4a00; }
.st-restated    { background: #f0f0f0; color: #888; }
.st-mentioned, .st-unknown { background: #f0f0f0; color: #999; }

/* ── detail ──────────────────────────────────────────────────────────── */
#detail { flex: 1; overflow-y: auto; padding: 18px 22px; min-width: 0; }
#detail .empty { color: #bbb; text-align: center; margin-top: 80px; }
.dhead h2 { font-size: 19px; margin-bottom: 4px; }
.dhead .sub { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.aka { margin-top: 8px; color: #666; font-size: 12px; line-height: 1.6; }
.aka b { color: #999; font-weight: 600; }

.section-h { font-size: 12px; font-weight: 700; color: #999; text-transform: uppercase; letter-spacing: .04em; margin: 22px 0 8px; }

/* timeline strip: substantive events on the axis, restatements as ticks below */
.tl { position: relative; height: 74px; margin: 4px 0 0; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.tl .axis { position: absolute; left: 0; right: 0; top: 34px; height: 1px; background: #ddd; }
.tl .yr { position: absolute; top: 56px; transform: translateX(-50%); font-size: 10px; color: #bbb; }
.tl .ev { position: absolute; top: 26px; width: 9px; height: 9px; border-radius: 50%; transform: translateX(-50%); border: 1.5px solid #fff; cursor: default; }
.tl .rs { position: absolute; top: 40px; width: 1px; height: 7px; background: #ccc; transform: translateX(-50%); }
.tl-legend { color: var(--muted); font-size: 11px; margin-top: 6px; }

.rel { display: flex; flex-wrap: wrap; gap: 6px; }
.relchip {
  font-size: 11px; padding: 3px 9px; border: 1px solid var(--border);
  border-radius: 12px; background: #fff; cursor: pointer; color: #444;
}
.relchip:hover { border-color: #bbb; background: #fafafa; }
.relchip .rk { color: #aaa; }

.m { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 9px 11px; margin-bottom: 7px; }
.m .mh { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.m .mt { font-weight: 600; flex: 1; min-width: 200px; }
.m .md { color: #444; margin-top: 5px; line-height: 1.5; }
.m .src { color: var(--muted); font-size: 11px; }
.m .ex { margin-top: 6px; border-left: 2px solid #e8e8e8; padding-left: 9px; color: #777; font-size: 12px; line-height: 1.5; white-space: pre-wrap; display: none; }
.m.open .ex { display: block; }
.m .togg { font-size: 11px; color: #1a56c4; cursor: pointer; margin-top: 5px; display: inline-block; }
.m a.doc { font-size: 11px; color: #1a56c4; text-decoration: none; }
.m a.doc:hover { text-decoration: underline; }

/* ── suspects / discards / families ──────────────────────────────────── */
.pair { display: flex; gap: 10px; align-items: stretch; margin-bottom: 10px; }
.pair .side { flex: 1; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 9px 11px; cursor: pointer; }
.pair .side:hover { border-color: #bbb; }
.pair .mid { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 110px; color: var(--muted); font-size: 11px; }
.pair .score { font-weight: 700; color: #444; font-size: 14px; }
.pair .numdiff { color: #b06000; text-align: center; line-height: 1.3; margin-top: 3px; }

.dcard { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 9px 11px; margin-bottom: 7px; }
.dcard .dt { font-weight: 600; }
.dcard .dr { color: #a02020; font-size: 12px; margin-top: 4px; }
.dcard .dd { color: #555; font-size: 12px; margin-top: 4px; line-height: 1.5; }

.fam { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 10px 12px; margin-bottom: 10px; }
.fam .fh { font-weight: 700; margin-bottom: 7px; }
.fam .fm { padding: 4px 0 4px 16px; border-left: 2px solid #eee; cursor: pointer; }
.fam .fm:hover { background: #fafafa; }
.fam .fm.root { border-left-color: #cfe0ff; padding-left: 8px; font-weight: 600; }
