/* ============================================================
   UN Global Dialogue on AI Governance — submissions explorer
   Hand-rolled, dependency-free styling.
   ============================================================ */

:root {
  --accent: #009edb;          /* UN blue */
  --accent-dark: #0b6f9c;
  --accent-soft: #e6f6fd;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --faint: #9aa5b1;
  --border: #e3e8ef;
  --border-strong: #cbd5e1;

  --risk: #c0392b;            /* risk accent */
  --risk-soft: #fdecea;
  --risk-border: #f5c6bf;
  --measure: #0f7b6c;         /* measure accent */
  --measure-soft: #e4f5f1;
  --measure-border: #b7e0d7;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 4px 16px rgba(16, 24, 40, 0.10);
  --maxw: 1240px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  font-size: 15px;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; color: var(--ink); }

/* ---------- Header / nav ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px;
  flex: none;
}
.brand__text small {
  display: block;
  font-weight: 500;
  color: var(--muted);
  font-size: 11.5px;
  letter-spacing: .02em;
}
.nav { display: flex; gap: 6px; margin-left: auto; }
.nav a {
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 24px; }
.page-title { margin: 4px 0 2px; font-size: 24px; }
.page-sub { color: var(--muted); margin: 0 0 20px; }

.banner {
  background: var(--accent-soft);
  border: 1px solid #bfe8fa;
  color: #0a5e85;
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13.5px;
  margin-bottom: 18px;
}

/* ---------- Filter bar ---------- */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--faint);
}
.field--grow { flex: 1 1 260px; }
input[type="search"], input[type="text"], select {
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  min-width: 160px;
}
input[type="search"] { width: 100%; }
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 158, 219, 0.15);
}
.btn {
  font: inherit; font-weight: 600;
  padding: 9px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
  cursor: pointer;
}
.btn:hover { background: var(--bg); }
.btn--ghost { border-color: transparent; color: var(--accent-dark); }
.btn--ghost:hover { background: var(--accent-soft); }

.active-tags { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; min-height: 4px; }
.active-tags:empty { display: none; }
.active-tags .lead { font-size: 12.5px; color: var(--muted); font-weight: 600; }

.result-meta {
  display: flex; align-items: center; gap: 14px;
  margin: 4px 2px 12px; color: var(--muted); font-size: 13.5px;
}
.result-meta strong { color: var(--ink); }

/* ---------- Tag chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border);
  background: #f3f5f9; color: #475569;
  cursor: pointer; white-space: nowrap;
  line-height: 1.7;
}
.chip:hover { border-color: var(--border-strong); text-decoration: none; }
.chip--risk { background: var(--risk-soft); color: var(--risk); border-color: var(--risk-border); }
.chip--measure { background: var(--measure-soft); color: var(--measure); border-color: var(--measure-border); }
.chip--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip__x { font-weight: 800; opacity: .7; }
.chip__x:hover { opacity: 1; }
.chip--sm { font-size: 11px; padding: 1px 8px; }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
/* `separate` (not `collapse`) so the sticky header paints above the scrolling
   rows — collapsed borders pin the header but paint it behind the body. */
table.grid { width: 100%; border-collapse: separate; border-spacing: 0; }
table.grid thead th {
  text-align: left;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: #f3f7fb;
  position: sticky; top: 0; z-index: 5;
  user-select: none;
}
/* Round the header's top corners to match the card (the card no longer clips,
   so the sticky header can pin to the viewport top when scrolling). */
table.grid thead th:first-child { border-top-left-radius: var(--radius); }
table.grid thead th:last-child { border-top-right-radius: var(--radius); }
table.grid thead th.sortable { cursor: pointer; }
table.grid thead th.sortable:hover { color: var(--accent-dark); }
th .arrow { color: var(--accent); font-size: 11px; }
table.grid td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid tbody tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
table.grid tbody tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
table.grid tbody tr.row:hover { background: #fafcff; }

.cell-org { font-weight: 600; color: var(--ink); }
.cell-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cell-title {
  font-weight: 600; color: var(--accent-dark); margin-bottom: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cell-title:hover { text-decoration: underline; }
.cell-prop {
  color: var(--muted); font-size: 12.5px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tag-wrap { display: flex; flex-wrap: wrap; gap: 5px; max-width: 360px; }

/* Browse table: a Risks cell and a Measures cell, each showing its own
   colour-coded tags — never mixed together. */
.rm-tags { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-width: 0; }
.rm-cell--empty { color: var(--faint); font-size: 12px; }
.tag-more {
  font-size: 11px; font-weight: 700; color: var(--faint);
  cursor: pointer; white-space: nowrap; padding: 2px 6px; border-radius: 999px;
  border: 1px dashed var(--border-strong); background: #fff;
}
.tag-more:hover { color: var(--accent-dark); background: var(--accent-soft); border-color: var(--accent); }
.subtags { margin-top: 9px; }
.muted-inline { color: var(--faint); font-weight: 400; }

.expand-btn {
  background: none; border: none; cursor: pointer;
  color: var(--faint); font-size: 13px; padding: 2px 6px; border-radius: 5px;
}
.expand-btn:hover { background: var(--bg); color: var(--ink); }
tr.row.is-open .expand-btn { color: var(--accent-dark); }
table.grid tbody tr.row.is-open > td { background: #fbfcfe; }
.subrow td { background: #fbfcfe; padding-top: 4px; }
.subgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 6px 2px 10px; }
@media (max-width: 720px){ .subgrid { grid-template-columns: 1fr; } }
.sublist h4 {
  margin: 0 0 7px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.sublist h4.risk { color: var(--risk); }
.sublist h4.measure { color: var(--measure); }
.sublist ul { margin: 0; padding-left: 18px; }
.sublist li { margin-bottom: 4px; font-size: 13px; }

.empty {
  text-align: center; padding: 60px 20px; color: var(--muted);
}

/* ---------- Result bar + Load more ---------- */
.result-bar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin: 4px 2px 12px;
}
.result-bar .result-meta { margin: 0; }
#expandAll { flex: none; }

.loadmore {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  margin: 18px 2px 4px;
}
.loadmore:empty { display: none; }
.loadmore__btn {
  font-weight: 700; padding: 10px 24px; border-radius: 999px;
  border-color: var(--border-strong);
}
.loadmore__btn:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.loadmore__count { font-size: 12.5px; color: var(--faint); }

/* ---------- Detail page ---------- */
.detail-head { margin-bottom: 8px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

/* The submitting organisation, surfaced as a byline author. */
.byline { margin: 4px 0 8px; color: var(--muted); font-size: 14.5px; }
.byline__org {
  color: var(--accent-dark); font-weight: 800; font-size: 18px;
  letter-spacing: .01em;
}

.badges { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 6px; }
.badge {
  font-size: 12.5px; font-weight: 600; padding: 3px 11px; border-radius: 999px;
  background: #eef2f7; color: #475569;
}
.badge--accent { background: var(--accent-soft); color: var(--accent-dark); }

.source-note { margin-top: 10px; }
.source-link { font-weight: 600; }
.src-hint { display: block; margin-top: 4px; font-size: 12px; color: var(--faint); }

.callout {
  background: linear-gradient(180deg, #fafdff, #fff);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 18px 0;
}
.callout h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-dark); }
.callout p { margin: 0; font-size: 15.5px; }

.section { margin: 28px 0; }
.section > h2 {
  font-size: 18px; margin: 0 0 14px;
  display: flex; align-items: center; gap: 10px;
}
.section > h2 .count { font-size: 13px; color: var(--muted); font-weight: 600; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 860px){ .cards { grid-template-columns: 1fr; } }
.item-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow);
}
.item-card.risk { border-top: 3px solid var(--risk); }
.item-card.measure { border-top: 3px solid var(--measure); }
.item-card h4 { margin: 0 0 7px; font-size: 15px; }
.item-card p { margin: 0 0 11px; color: #3b4654; font-size: 14px; }
.item-card .tag-wrap { max-width: none; }
.item-quote {
  margin: 0 0 11px; padding: 6px 11px;
  border-left: 3px solid var(--border-strong); border-radius: 0 6px 6px 0;
  background: var(--bg); color: var(--muted);
  font-size: 13px; font-style: italic; line-height: 1.45;
}
.item-quote::before { content: "\201C"; }
.item-quote::after  { content: "\201D"; }
.quote-orig {
  display: block; margin-top: 5px; padding-top: 5px;
  border-top: 1px dashed var(--border-strong);
  font-size: 12px; font-style: normal; opacity: .8;
}
.quote-orig::before { content: "Original: "; font-style: italic; opacity: .7; }
.item-card.risk    .item-quote { border-left-color: var(--risk-border);    background: var(--risk-soft); }
.item-card.measure .item-quote { border-left-color: var(--measure-border); background: var(--measure-soft); }

.org-desc {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 18px; color: #3b4654;
}

.qa-item {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); margin-bottom: 12px; overflow: hidden;
}
.qa-q {
  width: 100%; text-align: left; cursor: pointer;
  background: #fbfcfe; border: none; border-bottom: 1px solid transparent;
  padding: 14px 18px; font: inherit; font-weight: 600; color: var(--ink);
  display: flex; gap: 12px; align-items: flex-start;
}
.qa-q:hover { background: #f4f8fc; }
.qa-q .twist { color: var(--accent); flex: none; transition: transform .15s; }
.qa-item.open .qa-q { border-bottom-color: var(--border); }
.qa-item.open .qa-q .twist { transform: rotate(90deg); }
.qa-a {
  padding: 16px 18px; white-space: pre-wrap; color: #2b3540; font-size: 14.5px;
  display: none;
}
.qa-item.open .qa-a { display: block; }
.qa-num { color: var(--faint); font-variant-numeric: tabular-nums; }

/* ---------- Stats page ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px; margin-bottom: 26px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-card .num { font-size: 28px; font-weight: 800; color: var(--accent-dark); line-height: 1.1; }
.stat-card .lbl { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 20px;
}
.panel h2 { font-size: 16px; margin: 0 0 4px; }
.panel .hint { color: var(--muted); font-size: 13px; margin: 0 0 16px; }
.panel-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 860px){ .panel-2 { grid-template-columns: 1fr; } }

/* horizontal bar chart */
.barchart { display: flex; flex-direction: column; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 180px 1fr 46px; align-items: center; gap: 10px; }
.bar-row .bl { font-size: 12.5px; color: var(--ink); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.bar-row .bl:hover { color: var(--accent-dark); }
.bar-track { background: #eef2f7; border-radius: 999px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--accent); min-width: 2px; transition: width .4s ease; }
.bar-fill.risk { background: var(--risk); }
.bar-fill.measure { background: var(--measure); }
.bar-row .bv { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: left; }
@media (max-width: 560px){ .bar-row { grid-template-columns: 110px 1fr 40px; } }

/* vertical histogram */
.histo { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.histo .hbar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 5px; height: 100%; }
.histo .hbar .hb { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.histo .hbar .hb.measure { background: var(--measure); }
.histo .hbar .hb.risk { background: var(--risk); }
.histo .hbar .hv { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.histo .hbar .hx { font-size: 11px; color: var(--faint); }

/* heatmap */
.heatmap { overflow-x: auto; }
.heatmap table { border-collapse: collapse; font-size: 12px; }
.heatmap th, .heatmap td { padding: 6px 8px; text-align: center; }
.heatmap th.rowh { text-align: right; color: var(--ink); font-weight: 600; white-space: nowrap; }
.heatmap th.colh { color: var(--muted); font-weight: 600; vertical-align: bottom; }
.heatmap th.colh span { display: inline-block; white-space: nowrap; }
.heatmap td.cell { color: #16323d; border-radius: 4px; font-variant-numeric: tabular-nums; min-width: 42px; }

.legend { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 12px; }
.legend .swatch { width: 14px; height: 14px; border-radius: 3px; }

footer.site-footer {
  max-width: var(--maxw); margin: 10px auto 40px; padding: 18px 24px;
  color: var(--faint); font-size: 12.5px; border-top: 1px solid var(--border);
}
footer.site-footer a { color: var(--muted); }

.loading { padding: 50px; text-align: center; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
