:root {
  --color-bg: #fff;
  --color-text: #1a1a1a;
  --color-muted: #666;
  --color-header-bg: #1a5fb4;
  --color-link: var(--color-header-bg);
  --color-link-hover: #0d3d6b;
  --color-border: #ddd;
  --color-header-text: #fff;
  --color-accent-bg: #eef3fc;
  --color-row-hover: #f5f7fa;
  --max-width: 1100px;
  --spacing: 1.5rem;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}
a { color: var(--color-link); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--color-link-hover); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; background: var(--color-row-hover); padding: 0.1em 0.35em; border-radius: 4px; }
h1 { font-size: 1.6rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 1.75rem 0 0.6rem; }
.muted { color: var(--color-muted); }
.small { font-size: 0.85rem; }

/* Header: blue bar, brand left, search right, primary nav behind a burger toggle. */
header { background: var(--color-header-bg); color: var(--color-header-text); }
.header-inner {
  max-width: var(--max-width); margin: 0 auto;
  padding: 0.75rem var(--spacing); min-height: 4rem;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.site-title { font-size: 1.35rem; font-weight: 700; margin: 0; }
.site-title a { color: var(--color-header-text); text-decoration: none; }
.site-title span { opacity: 0.7; font-weight: 600; }
header form { margin: 0 0 0 auto; display: flex; gap: 0.5rem; align-items: center; }
header form input[type="search"] {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.4);
  color: #fff; border-radius: 6px; padding: 0.45rem 0.7rem; min-width: 16rem; font-size: 0.95rem;
}
header form input[type="search"]::placeholder { color: rgba(255,255,255,0.7); }
header form button {
  background: rgba(255,255,255,0.2); color: #fff; border: 0; border-radius: 6px;
  padding: 0.45rem 0.85rem; cursor: pointer; font-size: 0.95rem;
}
header form button:hover { background: rgba(255,255,255,0.35); }

/* Burger menu toggle + slide-out primary nav drawer. */
.nav-toggle {
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
  width: 2.25rem; height: 2.25rem; padding: 0; border: 0; border-radius: 6px;
  background: transparent; cursor: pointer; flex-shrink: 0;
}
.nav-toggle:hover { background: rgba(255,255,255,0.15); }
.nav-toggle span { display: block; width: 1.35rem; height: 2px; background: var(--color-header-text); border-radius: 2px; transition: transform 0.15s ease, opacity 0.15s ease; }
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.nav-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 999;
}
.nav-backdrop.is-open { opacity: 1; pointer-events: auto; }

.site-nav {
  position: fixed; top: 0; left: 0; height: 100dvh; width: min(80vw, 20rem);
  background: var(--color-header-bg); z-index: 1000; overflow-y: auto;
  box-shadow: 2px 0 16px rgba(0,0,0,0.3);
  transform: translateX(-100%);
  visibility: hidden;
  transition: transform 0.25s ease, visibility 0s linear 0.25s;
}
.site-nav.is-open { transform: translateX(0); visibility: visible; transition: transform 0.25s ease; }
.site-nav-inner { padding: 4.5rem var(--spacing) 1rem; display: flex; flex-direction: column; }
.site-nav-inner a { padding: 0.75rem 0; color: var(--color-header-text); text-decoration: none; font-weight: 600; border-bottom: 1px solid rgba(255,255,255,0.15); }
.site-nav-inner a:last-child { border-bottom: 0; }
.site-nav-inner a:hover { color: rgba(255,255,255,0.75); }
body.nav-open { overflow: hidden; }

main { max-width: var(--max-width); margin: 0 auto; padding: var(--spacing); }

/* Breadcrumb trail (opencharities.uk style): ancestors only, current page is the h1. */
.breadcrumb { margin: 0 0 0.75rem; font-size: 0.9rem; color: var(--color-muted); }
.breadcrumb ol { display: flex; flex-wrap: wrap; margin: 0; padding: 0; list-style: none; }
.breadcrumb li + li::before { content: "›"; margin: 0 0.4rem; color: var(--color-muted); }

.results-header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin: 0.5rem 0 1rem; }
/* Caption attributing a section to its originating register. */
.source-note { margin: -0.4rem 0 1rem; max-width: 62ch; }

/* Person page: photo + fact sheet in a left sidebar, register tables on the right. */
.person-layout { display: grid; grid-template-columns: 14rem 1fr; gap: 0 2rem; align-items: start; }
.person-sidebar { min-width: 0; }
.person-main { min-width: 0; }
.person-photo { display: block; width: 100%; height: auto; border-radius: 6px; margin: 0 0 1rem; }
.person-sidebar dl { display: block; }
.person-sidebar dt { margin-top: 0.6rem; }
.person-sidebar dt:first-of-type { margin-top: 0; }
.person-sidebar dd { margin: 0; }

/* Definition-list entity facts. */
dl { display: grid; grid-template-columns: 10rem 1fr; gap: 0.3rem 1.25rem; margin: 0.75rem 0 1.25rem; }
dt { color: var(--color-muted); font-size: 0.875rem; font-weight: 600; padding-top: 0.1rem; }
dd { margin: 0; min-width: 0; }

.table-wrap { overflow-x: auto; margin: 0.5rem 0 1rem; }
table { width: 100%; border-collapse: collapse; margin: 0.5rem 0 1rem; }
.table-wrap table { margin: 0; }
th, td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--color-border); vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
th { font-weight: 600; color: var(--color-muted); white-space: nowrap; border-bottom: 2px solid var(--color-border); }
tbody tr:hover { background: var(--color-row-hover); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.small { white-space: nowrap; }  /* date columns shouldn't wrap */

/* Sortable index-table headers. */
th.sortable a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 0.3em; }
th.sortable a:hover { color: var(--color-link); }
th.sortable.sorted { color: var(--color-text); }
.sort-arrow { font-size: 0.7em; }

.tag { display: inline-block; background: var(--color-accent-bg); color: var(--color-link); border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.78rem; }

/* Search tabs (one per entity type) — opencharities.uk style. */
.search-tabs { display: flex; gap: 0.25rem; margin: 0 0 1.5rem; box-shadow: inset 0 -1px 0 var(--color-border); flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.search-tabs::-webkit-scrollbar { display: none; }
.search-tabs a { flex: 0 0 auto; white-space: nowrap; padding: 0.5rem 1rem; text-decoration: none; color: var(--color-muted); font-weight: 600; font-size: 0.95rem; border: 1px solid transparent; border-bottom: none; border-radius: 4px 4px 0 0; margin-bottom: -1px; }
.search-tabs a:hover { color: var(--color-link); background: var(--color-accent-bg); }
.search-tabs a.active { color: var(--color-text); background: var(--color-bg); border-color: var(--color-border); }

/* Homepage: main column + stats sidebar. */
.index-layout { display: grid; grid-template-columns: 1fr 15rem; gap: 0 2.5rem; align-items: start; }
.stats-column { grid-column: 2; }
.stats-panel { background: var(--color-row-hover); border: 1px solid var(--color-border); border-radius: 6px; padding: 0.75rem 1rem; }
.stats-panel dl { display: block; margin: 0; }
.stats-panel dt { font-size: 0.8rem; color: var(--color-muted); margin-top: 0.75rem; }
.stats-panel dt:first-of-type { margin-top: 0; }
.stats-panel dd { margin: 0; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }

/* Filter forms. */
.filter-form { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0.75rem 0 1rem; }
.filter-form input, .filter-form select { padding: 0.4rem 0.6rem; border: 1px solid var(--color-border); border-radius: 6px; font-size: 0.95rem; }
.filter-form button { padding: 0.4rem 0.9rem; border: 1px solid var(--color-link); background: var(--color-link); color: #fff; border-radius: 6px; cursor: pointer; }

footer { border-top: 1px solid var(--color-border); margin-top: 2rem; }
.footer-inner { max-width: var(--max-width); margin: 0 auto; padding: var(--spacing); color: var(--color-muted); font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 1.5rem; justify-content: space-between; }
.footer-licences { max-width: 40rem; }

@media (max-width: 800px) {
  .index-layout { grid-template-columns: 1fr; }
  .stats-column { grid-column: 1; }
  .person-layout { grid-template-columns: 1fr; }
  .person-photo { max-width: 14rem; }
  header form input[type="search"] { min-width: 9rem; }
}
