:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --border: #d8dce3;
  --text: #1b1f27;
  --text-muted: #5c6473;
  --accent: #2f5bd7;
  --accent-soft: #e6ecfb;
  --answered: #1f9254;
  --danger: #b3261e;
  --radius: 8px;
  --sidebar-width: 300px;
  --topbar-height: 76px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-alt: #232830;
    --border: #333a45;
    --text: #e8eaee;
    --text-muted: #9aa3b2;
    --accent: #7d9bf0;
    --accent-soft: #26314a;
    --answered: #52c98a;
    --danger: #f08a80;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
  z-index: 20;
  background: var(--surface);
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.topbar-title h1 {
  font-size: 19px;
}

.topbar-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  flex: 1 1 220px;
}

.progress-track {
  flex: 1;
  height: 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: var(--answered);
  transition: width 160ms ease-out;
}

.progress-label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.topbar-actions button,
.file-button {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-alt);
  cursor: pointer;
  white-space: nowrap;
}

.topbar-actions button:hover,
.file-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.topbar-actions button.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.file-button input {
  display: none;
}

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  align-items: start;
  gap: 32px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

.sidebar {
  position: sticky;
  top: calc(var(--topbar-height) + 24px);
  max-height: calc(100vh - var(--topbar-height) - 48px);
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.respondent label,
.filter-heading {
  display: block;
  margin: 10px 0 4px;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.respondent input {
  width: 100%;
  padding: 7px 9px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.filter {
  margin-top: 16px;
}

.role-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.role-chip {
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.role-chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.section-nav {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  border-top: 1px solid var(--border);
}

.section-nav li {
  border-bottom: 1px solid var(--border);
}

.section-nav a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 2px;
  color: inherit;
  text-decoration: none;
}

.section-nav a:hover {
  color: var(--accent);
}

.section-nav .count {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.section-nav .count.complete {
  color: var(--answered);
  font-weight: 600;
}

.storage-note {
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
}

/* ---------- content ---------- */

main {
  min-width: 0;
}

.intro,
.qsection,
.footer {
  margin-bottom: 24px;
  padding: 20px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.intro h2 {
  font-size: 17px;
  margin-bottom: 10px;
}

.intro p {
  margin: 0 0 10px;
  max-width: 76ch;
}

.role-key {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.role-key dt {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.role-key dd {
  margin: 0;
  color: var(--text-muted);
}

.qsection-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.qsection-head h2 {
  font-size: 17px;
}

.qsection-head .count {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  white-space: nowrap;
}

.question {
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
}

.question:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.question[hidden] {
  display: none;
}

.question-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.role-tag {
  flex: none;
  margin-top: 2px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.question-text {
  margin: 0;
  font-weight: 600;
  max-width: 76ch;
}

.question-note {
  margin: 6px 0 0 0;
  font-size: 13px;
  color: var(--text-muted);
  max-width: 76ch;
}

.question textarea {
  display: block;
  width: 100%;
  min-height: 62px;
  margin-top: 10px;
  padding: 9px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  resize: vertical;
}

.question textarea:focus-visible,
.respondent input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.question.answered textarea {
  border-left: 3px solid var(--answered);
}

.footer {
  font-size: 14px;
  color: var(--text-muted);
}

.footer p {
  margin: 0;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease-out, transform 140ms ease-out;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

/* ---------- print ---------- */

@media print {
  .topbar-actions,
  .sidebar,
  .toast,
  .skip-link {
    display: none;
  }

  body {
    background: #fff;
    color: #000;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .intro,
  .qsection,
  .footer {
    border: none;
    padding: 0;
    margin-bottom: 18px;
    break-inside: avoid;
  }

  .question {
    break-inside: avoid;
  }
}
