:root {
  --bg: #f6f7f9; --surface: #fff; --text: #1d2330; --muted: #6b7385; --line: #e2e5eb;
  --accent: #2456d6; --accent-ink: #fff; --ok-bg: #e7f6ec; --ok: #17663a; --err-bg: #fdecec; --err: #a22424;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --surface: #1c2028; --text: #e6e8ee; --muted: #9098a9; --line: #2e3440;
    --accent: #6f95ff; --accent-ink: #0b1020; --ok-bg: #173323; --ok: #8fdcab; --err-bg: #3a1c1c; --err: #f3a3a3;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 1.2em 0 .6em; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
body.public main { max-width: 720px; }
.muted { color: var(--muted); } .small { font-size: .85em; } .nowrap { white-space: nowrap; }

.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.tag { font-size: .7rem; background: var(--accent); color: var(--accent-ink); padding: 2px 6px; border-radius: 4px; vertical-align: middle; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.panel.narrow { max-width: 420px; margin: 40px auto; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; color: var(--text); }
.card:hover { border-color: var(--accent); text-decoration: none; }
.card h2 { margin: 0 0 6px; } .card p { color: var(--muted); margin: 0 0 10px; } .cta { color: var(--accent); font-weight: 600; }
.lead { color: var(--muted); }
.footer-link { margin-top: 40px; font-size: .9em; }

.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 5px; }
.req { color: var(--err); }
input, select, textarea { width: 100%; padding: 9px 10px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox], input[type=radio] { width: auto; }
.choices { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.choice { display: inline-flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--err); }
.error-text { color: var(--err); font-size: .88em; margin-top: 4px; }
.hp { position: absolute; left: -9999px; }

.btn { display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger, .link.danger { color: var(--err); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
form.inline { display: inline; }

.flash { padding: 10px 14px; border-radius: 6px; margin: 0 0 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.err { background: var(--err-bg); color: var(--err); }

.page-head { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; }
.page-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-top: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters select, .filters input { width: auto; min-width: 180px; }
.count { margin-left: auto; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82em; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; } .chk { width: 32px; }
.actions { white-space: nowrap; } .actions > * { margin-left: 10px; } .actions > *:first-child { margin-left: 0; }
.badge { font-size: .75em; padding: 2px 7px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.badge.on { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.off { background: var(--err-bg); color: var(--err); border-color: transparent; }
.pager { display: flex; gap: 14px; align-items: center; }

.meta { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 0 0 16px; }
.meta dt { font-size: .8em; color: var(--muted); } .meta dd { margin: 0; }
.answers > div { display: grid; grid-template-columns: 220px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.answers > div:last-child { border-bottom: 0; }
.answers dt { font-weight: 600; } .answers dd { margin: 0; word-break: break-word; }
.orphan { opacity: .75; }

.two-col { display: grid; gap: 20px; grid-template-columns: 1fr 340px; align-items: start; }

.frow { display: grid; grid-template-columns: 20px 1fr 160px auto auto; gap: 8px; align-items: center;
  padding: 10px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.frow .opts { grid-column: 2 / -1; }
.frow input.lbl, .frow select { background: var(--surface); }
.drag { color: var(--muted); cursor: default; }
.row-btns { display: flex; gap: 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .answers > div { grid-template-columns: 1fr; gap: 2px; }
  .frow { grid-template-columns: 1fr 1fr; } .frow .drag { display: none; } .frow .lbl, .frow .opts { grid-column: 1 / -1; }
}
@media print {
  .topbar, .page-foot, .page-head .btn, main > p:first-child { display: none; }
  .panel { border: 0; padding: 0; }
}

/* Import mapping table */
.import-map input:not([type]), .import-map input[type=text] { min-width: 180px; }
.import-map select { min-width: 150px; }
.import-map textarea { min-width: 160px; }
details summary { cursor: pointer; color: var(--accent); margin-top: 10px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* Keeps the import button visible while scrolling long mapping tables */
.sticky-actions { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  margin: 20px -20px -20px; padding: 14px 20px; background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius); box-shadow: 0 -4px 12px rgba(0,0,0,.06); }

/* Submissions list */
.inline-flex { display: inline-flex; gap: 8px; align-items: center; }
.filters .inline-flex input { min-width: 0; }
.colpick { position: relative; }
.colpick summary { list-style: none; }
.colpick summary::-webkit-details-marker { display: none; }
.colpick[open] > form { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: min(560px, 90vw);
  max-height: 70vh; overflow: auto; box-shadow: 0 8px 28px rgba(0,0,0,.18); }
.colgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 14px; margin-bottom: 14px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
.pager a { white-space: nowrap; }

.notice-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }

/* ---------- Reports & charts ---------- */
/* Categorical palette validated for colour-blind separation on this site's light and dark surfaces */
:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #6250d6; --series-8: #e34948;
  --grid: #eceef2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --grid: #2a303b;
  }
}
.report-layout { display: grid; gap: 16px; }
.filter-panel { padding: 16px 20px; }
.filter-panel h2 { margin-top: 0; }
.cond-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.cond-row select, .cond-row input { width: auto; min-width: 150px; flex: 1 1 150px; }
.cond-row .op { flex: 0 1 170px; }
.date-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 12px; }
.date-row label { font-weight: 600; font-size: .9em; }
.date-row input { width: auto; display: block; margin-top: 4px; }
.match-bar { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 18px; }
.match-bar .big { font-size: 1.4rem; font-weight: 700; }
.chart-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 480px), 1fr)); }
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; position: relative; min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card h3 { margin: 0 0 2px; font-size: 1.02rem; }
.chart-card .sub { color: var(--muted); font-size: .85em; margin-bottom: 10px; }
.chart-card .chart { position: relative; }
.chart-canvas { width: 100%; overflow: hidden; }
.chart-canvas svg { display: block; }
.chart-tools { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 10px; font-size: .88em; align-items: center; }
.chart-tools form { display: inline; }
.chart-tip { position: absolute; z-index: 30; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; font-size: .85em; box-shadow: 0 6px 18px rgba(0,0,0,.16); max-width: 280px; }
.chart-tip .muted { color: var(--muted); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-table table { font-size: .88em; margin-top: 8px; }
.chart-table th, .chart-table td { padding: 5px 8px; }
.builder { padding: 16px 20px; }
.builder .grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.builder .grid .field { margin: 0; }
.preview-card { border: 2px dashed var(--accent); }
.tag { display: inline-block; font-size: .78em; padding: 1px 7px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
@media print {
  .filter-panel, .builder, .chart-tools, .match-bar a, .match-bar form { display: none !important; }
  .chart-card { break-inside: avoid; border: 0; }
  .chart-grid { grid-template-columns: 1fr 1fr; }
}

/* Merge answers */
.merge-groups { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); margin-bottom: 8px; }
.merge-group { margin: 0; padding: 10px 14px 12px; }
.merge-group legend { padding: 0 6px; font-weight: 600; }
.merge-group table { width: 100%; }
.merge-group th, .merge-group td { padding: 5px 6px; }
.merge-group.off table { opacity: .4; }
.merge-group .m-custom { padding: 5px 8px; }
.filters input[type=checkbox], .filters input[type=radio] { min-width: 0; }
#mergeform > .sticky-actions { margin: 20px 0 0; border: 1px solid var(--line); border-radius: var(--radius); }
.filters label > select { width: 100%; min-width: 0; max-width: 100%; }

/* Site footer */
.site-footer { text-align: center; color: var(--muted); font-size: .85em; padding: 20px 16px 28px; border-top: 1px solid var(--line); margin-top: 20px; }
@media print { .site-footer { border: 0; padding-top: 8px; } }
