:root {
  color-scheme: light;
  --background: #ebf7f7;
  --foreground: #171717;
  --surface: #ffffff;
  --surface-tint: #f7fcff;
  --border: #e5e7eb;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --primary: #1d4d58;
  --primary-hover: #009689;
  --primary-foreground: #ffffff;
  --ring: #00a4a6;
  --teal-50: #e6f6f6;
  --teal-100: #c9efef;
  --teal-500: #00a4a6;
  --black-teal: #00251e;
  --warning: #f59e0b;
  --error: #dc2626;
  --shadow: 0 18px 40px rgba(0, 37, 30, 0.08);
  --radius: 8px;
  --font-sans:
    "TheSansSpire", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.62), transparent 42%),
    var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
}

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

.app-shell,
.respondent-shell,
.admin-shell {
  display: grid;
  grid-template-columns: minmax(280px, 344px) minmax(0, 1fr);
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.home-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.sidebar {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  padding: 24px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.workspace {
  display: grid;
  align-content: start;
  gap: 18px;
  width: min(100%, 1040px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 800;
}

.brand h1,
.intro h2,
.review-panel h2 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand h1 {
  color: var(--black-teal);
  font-size: 1.05rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.progress-card {
  margin: 24px 0;
  padding: 16px;
  border: 1px solid var(--teal-100);
  border-radius: var(--radius);
  background: var(--teal-50);
}

.preview-actions {
  margin-top: 18px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--primary);
  font-size: 0.9rem;
}

.progress-label strong {
  color: var(--black-teal);
}

.progress-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #ffffff;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary-hover);
  transition: width 180ms ease;
}

.section-nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--foreground);
  text-align: left;
  cursor: pointer;
}

.nav-button:hover,
.nav-button.active {
  border-color: var(--teal-100);
  background: var(--teal-50);
  color: var(--primary);
}

.nav-index {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 0.8rem;
  font-weight: 800;
}

.nav-button.complete .nav-index,
.nav-button.active .nav-index {
  background: var(--primary);
  color: var(--primary-foreground);
}

.form-panel {
  width: min(100%, 980px);
  padding: 18px 0 48px;
}

.hero-card {
  width: min(100%, 760px);
  padding: clamp(28px, 6vw, 56px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card h1,
.toolbar h2 {
  margin: 0;
  color: var(--black-teal);
  font-size: clamp(2rem, 4vw, 3.35rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.hero-card p:not(.eyebrow) {
  max-width: 680px;
  margin: 16px 0 0;
  color: var(--muted-foreground);
  font-size: 1rem;
  line-height: 1.65;
}

.login-card {
  max-width: 620px;
}

.intro {
  margin-bottom: 22px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.intro h2 {
  max-width: 760px;
  color: var(--black-teal);
  font-size: clamp(2rem, 4vw, 3.45rem);
  font-weight: 800;
}

.intro p:last-child {
  max-width: 760px;
  margin: 14px 0 0;
  color: var(--muted-foreground);
  font-size: 1rem;
  line-height: 1.6;
}

.rich-text h2,
.rich-text h3 {
  margin: 0 0 12px;
  color: var(--black-teal);
  font-size: clamp(1.6rem, 3vw, 2.6rem);
  line-height: 1.1;
}

.rich-text p,
.rich-text li {
  color: var(--muted-foreground);
  line-height: 1.65;
}

.rich-text ul,
.rich-text ol {
  padding-left: 1.25rem;
}

.section {
  margin: 0 0 18px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.section-header h3 {
  margin: 0;
  color: var(--black-teal);
  font-size: 1.28rem;
  font-weight: 750;
  letter-spacing: 0;
}

.section-count {
  color: var(--muted-foreground);
  font-size: 0.9rem;
  white-space: nowrap;
}

.question {
  display: grid;
  gap: 12px;
  padding: 18px 0;
  border: 0;
  margin: 0;
}

.question.is-hidden {
  display: none !important;
}

.question + .question {
  border-top: 1px solid var(--border);
}

.question-label {
  display: flex;
  gap: 8px;
  color: var(--foreground);
  font-weight: 700;
  line-height: 1.4;
}

.required {
  color: var(--error);
}

.option-list {
  display: grid;
  gap: 9px;
}

.option {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
  cursor: pointer;
}

.option:hover,
.option:focus-within {
  border-color: var(--ring);
  background: var(--teal-50);
}

.option input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
  color: var(--foreground);
  line-height: 1.5;
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
  color: var(--foreground);
}

input:focus,
select:focus {
  outline: 3px solid rgba(0, 164, 166, 0.16);
  border-color: var(--ring);
}

.field-label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--foreground);
  font-weight: 700;
}

.field-label.compact {
  margin-bottom: 0;
}

.check-row {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.code-input,
pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
    "Courier New", monospace;
  font-size: 0.88rem;
}

textarea:focus,
.file-control:focus-within {
  outline: 3px solid rgba(0, 164, 166, 0.16);
  border-color: var(--ring);
}

.file-control {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px dashed var(--ring);
  border-radius: var(--radius);
  background: var(--teal-50);
}

.file-control input::file-selector-button {
  min-height: 36px;
  margin-right: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 700;
  cursor: pointer;
}

.help-text,
.error-text {
  margin: 0;
  color: var(--muted-foreground);
  font-size: 0.9rem;
  line-height: 1.45;
}

.error-text {
  color: var(--error);
  font-weight: 700;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 16px;
}

.actions.left {
  justify-content: flex-start;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.toolbar.compact {
  padding: 0 0 16px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  box-shadow: none;
}

.toolbar h2,
.toolbar h3 {
  margin: 0;
}

.toolbar-copy {
  max-width: 620px;
  margin: 8px 0 0;
  color: var(--muted-foreground);
  line-height: 1.45;
}

.toolbar h3 {
  color: var(--black-teal);
  font-size: 1.2rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.entity-card,
.empty-state,
.loading {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.empty-state {
  color: var(--muted-foreground);
  line-height: 1.5;
}

.empty-state strong {
  display: block;
  margin-bottom: 4px;
  color: var(--black-teal);
}

.empty-state p {
  margin: 0;
}

.entity-card {
  position: relative;
  display: grid;
  gap: 12px;
  align-content: start;
}

.entity-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.entity-card h3 {
  margin: 0;
  color: var(--black-teal);
  font-size: 1.25rem;
}

.entity-card p:not(.status-pill) {
  margin: 0;
  color: var(--muted-foreground);
  line-height: 1.55;
}

.metadata-list {
  display: grid;
  gap: 8px;
  margin: 4px 0 0;
}

.metadata-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.metadata-list dt {
  color: var(--muted-foreground);
  font-weight: 700;
}

.metadata-list dd {
  margin: 0;
  color: var(--foreground);
  text-align: right;
  word-break: break-word;
}

.status-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--teal-50);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-pill.started {
  background: var(--warning-100, #fef3c7);
  color: #92400e;
}

.status-pill.completed {
  background: #dcfce7;
  color: #166534;
}

.completed-view {
  width: min(100%, 980px);
}

.editor-form {
  display: grid;
  gap: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.filter-bar {
  display: grid;
  grid-template-columns: minmax(150px, 200px) minmax(150px, 200px) minmax(240px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.inline-form .field-label {
  margin-bottom: 0;
}

.user-list,
.invitation-list {
  display: grid;
  gap: 10px;
}

.user-row,
.invitation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
}

.invitation-row > div:first-child,
.user-row > div:first-child {
  min-width: 0;
}

.user-row strong,
.invitation-row strong {
  overflow-wrap: anywhere;
}

.pagination-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.user-row p,
.invitation-row p,
.user-meta {
  margin: 4px 0 0;
  color: var(--muted-foreground);
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.wysiwyg {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.wysiwyg-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--teal-50);
}

.tool-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--primary);
  font-weight: 750;
  cursor: pointer;
}

.tool-button:hover,
.tool-button:focus-visible {
  border-color: var(--ring);
  background: #ffffff;
  outline: 3px solid rgba(0, 164, 166, 0.14);
}

.rich-editor {
  min-height: 220px;
  padding: 16px;
  background: var(--surface-tint);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.65;
}

.rich-editor:focus {
  outline: 3px solid rgba(0, 164, 166, 0.16);
  outline-offset: -3px;
}

.rich-editor:empty::before {
  content: "Add the introduction people will read before starting the questionnaire.";
  color: var(--muted-foreground);
}

.rich-editor a,
.rich-text a {
  color: var(--primary);
  font-weight: 700;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--primary);
  color: var(--primary-foreground);
  font-size: 0.95rem;
  font-weight: 750;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

.button:hover {
  background: var(--primary-hover);
}

.button:focus-visible,
.nav-button:focus-visible,
.option:focus-within,
.file-control input:focus-visible {
  outline: 3px solid rgba(0, 164, 166, 0.2);
  outline-offset: 2px;
}

.button.secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--primary);
}

.button.secondary:hover {
  border-color: var(--teal-100);
  background: var(--teal-50);
}

.button.danger {
  color: var(--error);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--primary);
}

.button.ghost:hover {
  background: var(--teal-50);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--teal-100);
  background: var(--teal-50);
  outline: 3px solid rgba(0, 164, 166, 0.16);
  outline-offset: 2px;
}

.card-menu {
  position: relative;
  z-index: 2;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  min-width: 180px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.menu-panel[hidden] {
  display: none;
}

.menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--foreground);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--teal-50);
  color: var(--primary);
  outline: none;
}

.menu-item.danger {
  color: var(--error);
}

.menu-item.danger:hover,
.menu-item.danger:focus-visible {
  background: #fef2f2;
  color: #991b1b;
}

.builder-list {
  display: grid;
  gap: 16px;
}

.builder-section,
.builder-question {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
}

.builder-header,
.option-editor-header,
.response-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.builder-questions {
  display: grid;
  gap: 12px;
}

.builder-question {
  background: var(--surface);
}

.builder-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) auto;
  gap: 12px;
  align-items: end;
}

.option-editor {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--teal-100);
  border-radius: var(--radius);
  background: var(--teal-50);
}

.condition-editor {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.condition-editor strong {
  color: var(--black-teal);
}

.condition-grid {
  display: grid;
  grid-template-columns: minmax(150px, 180px) minmax(220px, 1fr) minmax(150px, 180px) minmax(180px, 1fr);
  gap: 12px;
  align-items: end;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.review-panel {
  margin-top: 22px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.review-content {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.review-item {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
}

.review-item strong {
  display: block;
  margin-bottom: 6px;
}

.review-item p {
  margin: 0;
  color: var(--muted-foreground);
  line-height: 1.45;
}

.review-item pre {
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  border-radius: 6px;
  background: var(--muted);
  color: var(--foreground);
  white-space: pre-wrap;
}

.response-card {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.response-header p {
  margin: 4px 0 0;
  color: var(--muted-foreground);
}

.answer-list {
  display: grid;
  gap: 10px;
}

.answer-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-tint);
}

.answer-item strong {
  display: block;
  margin-bottom: 6px;
}

.answer-item p {
  margin: 0;
  color: var(--muted-foreground);
  line-height: 1.5;
}

.answer-item.skipped {
  background: var(--muted);
}

.conditional-note {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--teal-50);
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  vertical-align: middle;
}

.document-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.document-list a {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--teal-100);
  border-radius: 6px;
  background: var(--teal-50);
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.missing-document {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--muted);
  color: var(--muted-foreground);
  font-weight: 700;
}

.document-list a:hover {
  border-color: var(--ring);
  background: #ffffff;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--black-teal);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 860px) {
  .app-shell,
  .respondent-shell,
  .admin-shell {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .section-nav {
    grid-template-columns: 1fr 1fr;
  }

  .form-panel {
    padding-top: 0;
  }
}

@media (max-width: 560px) {
  .section-nav {
    grid-template-columns: 1fr;
  }

  .intro,
  .section,
  .review-panel {
    padding: 18px;
  }

  .section-header {
    display: grid;
  }

  .section-count {
    white-space: normal;
  }

  .actions {
    display: grid;
  }

  .toolbar {
    display: grid;
  }

  .toolbar .actions {
    justify-content: start;
  }

  .menu-panel {
    right: 0;
    max-width: calc(100vw - 56px);
  }

  .builder-header,
  .option-editor-header,
  .response-header,
  .builder-grid,
  .condition-grid,
  .option-row,
  .inline-form,
  .filter-bar,
  .user-row,
  .invitation-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .user-meta {
    justify-content: start;
  }
}
