:root {
  --mefa-navy: #173b75;
  --mefa-blue: #2563eb;
  --mefa-blue-deep: #1d4ed8;
  --mefa-page: #f2f7fd;
  --mefa-surface: #ffffff;
  --mefa-soft: #f5f9ff;
  --mefa-text: #10233f;
  --mefa-muted: #485e79;
  --mefa-line: #cfdded;
  --mefa-ring: #2563eb;
  --mefa-shadow: 0 18px 48px #143a6b14;
}

html { background: var(--mefa-page); }
body.participant-mode,
body.team-mode {
  --ink: var(--mefa-page);
  --panel: var(--mefa-surface);
  --panel-2: var(--mefa-soft);
  --line: var(--mefa-line);
  --text: var(--mefa-text);
  --muted: var(--mefa-muted);
  --lime: var(--mefa-blue);
  --blue: var(--mefa-blue);
  --focus-ring: var(--mefa-ring);
  min-height: 100dvh;
  color: var(--mefa-text);
  background: radial-gradient(circle at 85% -16%, #dbeaff 0, transparent 40%), var(--mefa-page);
}

body.participant-mode .topbar,
body.team-mode .topbar {
  min-height: 82px;
  padding: 12px max(20px, calc((100vw - 1180px) / 2));
  border-top: 4px solid var(--mefa-blue);
  border-bottom: 1px solid var(--mefa-line);
  color: var(--mefa-text);
  background: #fffffffa;
  box-shadow: 0 5px 20px #143a6b0d;
}
.top-brand,
.top-brand > div { min-width: 0; }
.top-brand { gap: 13px; }
.top-brand img.mefa-logo {
  display: block;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border-radius: 13px;
}
.top-brand strong { color: var(--mefa-navy); font-size: 1.08rem; line-height: 1.3; }
body.participant-mode .top-brand span,
body.team-mode .top-brand span {
  max-width: 520px;
  color: var(--mefa-muted);
  font-size: .78rem;
  line-height: 1.5;
}
body.participant-mode .shell { max-width: 880px; padding: 38px 18px 72px; }
body.team-mode .shell { max-width: 1180px; padding: 38px 18px 72px; }
body.participant-mode .card,
body.team-mode .card {
  color: var(--mefa-text);
  background: var(--mefa-surface);
  border: 1px solid var(--mefa-line);
  border-radius: 22px;
  box-shadow: var(--mefa-shadow);
}

/* Participant introduction and consent */
body.participant-mode #consent {
  max-width: 780px;
  margin-inline: auto;
  padding: 34px 42px 32px;
  border-top: 5px solid var(--mefa-blue);
}
.intro-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px !important;
  padding: 5px 12px;
  border: 1px solid #c9dcf7;
  border-radius: 999px;
  color: var(--mefa-navy) !important;
  background: #edf5ff;
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.55;
}
.intro-eyebrow span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--mefa-blue);
}
body.participant-mode #consent h1 {
  max-width: 24ch;
  margin: 16px 0 20px;
  color: var(--mefa-text);
  font-size: clamp(1.68rem, 3.1vw, 2.25rem);
  line-height: 1.5;
}
body.participant-mode #consent-copy {
  max-width: 69ch;
  padding: 12px 21px;
  border-inline-start: 3px solid #a8c8f3;
  border-radius: 12px;
  background: #f7faff;
}
body.participant-mode #consent-copy p {
  margin: 7px 0 11px;
  color: #344d6b;
  line-height: 1.95;
}
body.participant-mode #consent .check {
  align-items: center;
  gap: 12px;
  min-height: 58px;
  margin-top: 24px;
  padding: 12px 15px;
  border: 1px solid #cbdff9;
  border-radius: 12px;
  color: #19385f;
  background: #f1f7ff;
}
body.participant-mode #consent .check input {
  flex: 0 0 21px;
  width: 21px;
  height: 21px;
  margin: 0;
  accent-color: var(--mefa-blue);
}
.consent-actions { display: flex; justify-content: flex-start; margin-top: 20px; }
.consent-actions .primary { min-width: 176px; }

/* Shared controls */
body.participant-mode .primary,
body.team-mode .primary {
  min-height: 48px;
  color: #fff;
  background: var(--mefa-blue);
  border-color: var(--mefa-blue);
  box-shadow: 0 6px 16px #2563eb29;
  transition: background .2s ease, box-shadow .2s ease;
}
body.participant-mode .primary:hover:not(:disabled),
body.team-mode .primary:hover:not(:disabled) {
  background: var(--mefa-blue-deep);
  box-shadow: 0 8px 20px #2563eb33;
}
body.participant-mode .primary:disabled,
body.team-mode .primary:disabled {
  color: #fff;
  background: #9cb9df;
  border-color: #9cb9df;
  box-shadow: none;
  opacity: .72;
}
body.participant-mode .secondary,
body.team-mode .secondary {
  color: var(--mefa-navy);
  border-color: #b7cce8;
  background: #fff;
}
body.participant-mode .secondary:hover,
body.team-mode .secondary:hover { background: #eef5ff; }
body.participant-mode :is(button, a, input, select, textarea, summary):focus-visible,
body.team-mode :is(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid var(--mefa-ring);
  outline-offset: 3px;
}
body.participant-mode button,
body.team-mode button,
body.participant-mode summary,
body.team-mode summary { touch-action: manipulation; }

/* Profile form and conversation */
body.participant-mode #pre-form {
  border-top: 5px solid var(--mefa-blue);
  background: #fff;
}
body.participant-mode #pre-form #pre-title {
  margin-top: 12px;
  color: var(--mefa-text);
  font-size: clamp(1.45rem, 2.5vw, 1.8rem);
}
body.participant-mode #pre-form .pre-section-block {
  border-color: #d7e4f4;
  background: #f9fbff;
  box-shadow: none;
}
body.participant-mode #pre-form .pre-progress-bar {
  background: linear-gradient(90deg, #2563eb, #62a7ee);
}
body.participant-mode .chat-shell {
  border-color: var(--mefa-line);
  border-radius: 22px;
  box-shadow: var(--mefa-shadow);
}
body.participant-mode .chat-title {
  padding: 15px 20px;
  color: var(--mefa-text);
  background: #f2f7ff;
  border-bottom-color: #d6e3f3;
}
.chat-title-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.chat-title-brand img { display: block; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 10px; }
.chat-title-brand strong { color: var(--mefa-navy); }
body.participant-mode .messages .message.assistant {
  color: var(--mefa-text);
  background: #f1f6ff;
  border-color: #d7e5f6;
}
body.participant-mode .messages .message.user {
  color: #173c70;
  background: #e5f0ff;
  border-color: #c7dcf7;
}
body.participant-mode .assistant-avatar,
body.team-mode .assistant-avatar {
  border: 0;
  border-radius: 11px;
  background: transparent;
  box-shadow: none;
}
body.participant-mode .assistant-avatar img,
body.team-mode .assistant-avatar img { width: 36px; height: 36px; border-radius: 9px; }
body.participant-mode .typing-indicator::before,
body.team-mode .typing-indicator::before {
  width: 27px;
  height: 27px;
  flex-basis: 27px;
  background-image: url('/static/mefa-logo.svg');
}
body.participant-mode .composer { background: #f7faff; }
body.participant-mode .send { color: #fff; background: var(--mefa-blue); }
body.participant-mode .send { display: grid; place-items: center; min-height: 48px; }
body.participant-mode .send svg { display: block; width: 23px; height: 23px; }
body.participant-mode .send:hover:not(:disabled) { background: var(--mefa-blue-deep); }
body.participant-mode #chat-controls .quiet {
  min-height: 44px;
  color: var(--mefa-navy);
  background: #f7fbff;
}
body.participant-mode #complete { border-top: 5px solid var(--mefa-blue); }

/* Research sign-in and dashboard */
body.team-mode .login-card {
  max-width: 470px;
  margin: 28px auto;
  padding: 32px 36px 36px;
  border-top: 5px solid var(--mefa-blue);
}
.login-mark { display: block; width: 64px; height: 64px; margin-bottom: 14px; border-radius: 17px; }
.login-eyebrow {
  margin: 0 0 3px;
  color: var(--mefa-blue);
  font-size: .84rem;
  font-weight: 700;
}
body.team-mode .login-card h1 {
  margin: 3px 0 6px;
  color: var(--mefa-text);
  font-size: clamp(1.5rem, 3vw, 1.85rem);
  line-height: 1.5;
}
body.team-mode .login-card .muted { color: var(--mefa-muted); }
body.team-mode .login-card label { color: #274360; font-weight: 700; }
body.team-mode .login-card input {
  min-height: 50px;
  color: var(--mefa-text);
  background: #fbfdff;
  border: 1px solid #bfd0e5;
}
body.team-mode #login-form .primary { width: 100%; margin-top: 10px; }
body.team-mode .dashboard-head {
  align-items: center;
  gap: 18px;
  padding: 23px 27px;
  border: 1px solid #2b5b9b;
  border-radius: 20px;
  color: #fff;
  background: linear-gradient(125deg, #173b75, #215ca8);
  box-shadow: 0 18px 40px #173b7529;
}
body.team-mode .dashboard-head h1 { color: #fff; font-size: clamp(1.45rem, 2.4vw, 1.9rem); }
body.team-mode .dashboard-head .muted { color: #dbeafe; }
body.team-mode .dashboard-head .secondary {
  color: var(--mefa-navy);
  background: #fff;
  border-color: #fff;
}
body.team-mode .dashboard-head .quiet {
  min-height: 44px;
  color: #fff;
  border: 1px solid #a7c6ef;
  border-radius: 12px;
}
body.team-mode .dashboard-head .quiet:hover { color: #fff; background: #ffffff1c; }
.admin-tools { margin: -4px 0 20px; padding: 10px 18px 14px; border: 1px solid var(--mefa-line); border-radius: 15px; background: #fff; }
.admin-tools > summary { min-height: 40px; color: var(--mefa-navy); font-weight: 800; cursor: pointer; }
.admin-tools .actions { flex-wrap: wrap; margin-top: 8px; }
.admin-tools button { min-height: 42px; font-size: .85rem; }
body.team-mode .metrics { gap: 14px; margin: 18px 0 23px; }
body.team-mode .metric {
  padding: 17px 19px;
  border: 1px solid var(--mefa-line);
  border-top: 3px solid var(--mefa-blue);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px #143a6b0d;
}
body.team-mode .metric strong { color: var(--mefa-navy); }
body.team-mode .metric span { color: var(--mefa-muted); font-size: .86rem; }
body.team-mode .session,
body.team-mode .question-edit {
  color: var(--mefa-text);
  background: #fbfdff;
  border-color: #d3e0ef;
}
body.team-mode .session:hover,
body.team-mode .session.active {
  border-color: #7ea9e3;
  background: #f0f6ff;
}
body.team-mode .session small { color: var(--mefa-muted); }
body.team-mode .question-edit { border-radius: 14px; }
body.team-mode .question-edit summary,
body.team-mode legend { color: var(--mefa-navy); }
body.team-mode .field input,
body.team-mode .field select,
body.team-mode .field textarea,
body.team-mode .composer textarea {
  color: var(--mefa-text);
  background: #fbfdff;
  border-color: #bfd0e5;
}
body.team-mode .field select option { color: var(--mefa-text); background: #fff; }
body.team-mode .muted,
body.team-mode .small { color: var(--mefa-muted); }
body.team-mode .settings-jump-nav {
  border-color: var(--mefa-line);
  background: #f2f7ff;
}
body.team-mode .export-feedback { color: var(--mefa-text); background: #f2f7ff; }
body.team-mode .export-feedback[data-state="error"] {
  color: #8b1e2d;
  background: #fff4f4;
  border-color: #ecc4c9;
}
body.team-mode .export-feedback[data-state="success"] {
  color: #17613a;
  background: #effaf3;
  border-color: #b6dfc4;
}
body.team-mode .pre-results,
body.team-mode .session-check { background: #f7faff; }
body.team-mode #settings-community-status {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid #c9dcf7;
  border-radius: 999px;
  color: var(--mefa-navy);
  background: #edf5ff;
  font-weight: 700;
}
body.team-mode .error { color: #a32735; }

/* Community selector */
.communities-list { display: grid; gap: 12px; margin-block: 20px; }
.community-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 17px 19px;
  border: 1px solid var(--mefa-line);
  border-radius: 15px;
  background: #fbfdff;
}
.community-row h3 { margin: 0 0 4px; color: var(--mefa-navy); font-size: 1.04rem; }
.community-row p { margin: 3px 0; }
.community-meta { overflow-wrap: anywhere; font-size: .84rem; }
.community-row .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid #b7cce8;
  border-radius: 11px;
  text-decoration: none;
  white-space: nowrap;
}
.community-row .secondary:hover { background: #eef5ff; }
.community-create {
  margin-block: 14px;
  padding: 15px 17px;
  border: 1px solid var(--mefa-line);
  border-radius: 15px;
  background: #f7fbff;
}
.community-create summary { min-height: 44px; color: var(--mefa-navy); font-weight: 700; cursor: pointer; }
.community-create form { display: grid; gap: 8px; }
.community-create label { margin-top: 10px; font-weight: 700; }
.community-create input,
.community-create textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid #bfd0e5;
  border-radius: 11px;
  color: var(--mefa-text);
  background: #fff;
  font: inherit;
}

/* Guided research editor */
body.team-mode .settings-workspace { margin-bottom: 24px; padding: 28px 32px 34px; scroll-margin-top: 90px; }
.settings-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.settings-heading h2 { margin: 2px 0 5px; color: var(--mefa-navy); font-size: clamp(1.45rem, 2.2vw, 1.85rem); }
.settings-heading p { max-width: 68ch; margin: 0; }
.settings-eyebrow { color: var(--mefa-blue) !important; font-size: .78rem; font-weight: 800; letter-spacing: .02em; }
.settings-draft-badge {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid #c9dcf7;
  border-radius: 999px;
  color: var(--mefa-navy);
  background: #edf5ff;
  font-size: .78rem;
  font-weight: 800;
}
.settings-draft-badge[data-state="dirty"] { color: #87580b; background: #fff7e5; border-color: #f1d798; }
.settings-draft-badge[data-state="saved"] { color: #17613a; background: #effaf3; border-color: #b6dfc4; }
body.team-mode .settings-jump-nav {
  position: sticky;
  top: 82px;
  z-index: 4;
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  overflow-x: auto;
  margin: 21px 0 24px;
  padding: 7px;
  scrollbar-width: thin;
  box-shadow: 0 8px 24px #143a6b14;
}
body.team-mode .settings-jump-nav button {
  flex: 1 0 auto;
  min-height: 44px;
  padding: 8px 13px;
  border-radius: 9px;
  color: var(--mefa-muted);
  font-size: .88rem;
  font-weight: 700;
  white-space: nowrap;
}
body.team-mode .settings-jump-nav button:hover { color: var(--mefa-navy); background: #e7f1ff; }
body.team-mode .settings-jump-nav button.active { color: #fff; background: var(--mefa-navy); box-shadow: 0 5px 13px #173b7526; }
.settings-stage[hidden] { display: none !important; }
.settings-stage { max-width: 960px; margin-inline: auto; padding-block: 2px 15px; }
.settings-stage-heading { margin-bottom: 18px; padding-bottom: 13px; border-bottom: 1px solid var(--mefa-line); scroll-margin-top: 160px; }
.settings-stage-heading h3 { margin: 0 0 3px; color: var(--mefa-navy); font-size: 1.24rem; }
.settings-stage-heading p { margin: 0; }
body.team-mode .settings-stage .field { margin: 15px 0; }
body.team-mode .settings-stage fieldset {
  margin: 15px 0;
  padding: 16px 20px 19px;
  border: 1px solid var(--mefa-line);
  border-radius: 15px;
  background: #fbfdff;
}
body.team-mode .settings-stage fieldset legend { padding-inline: 8px; font-weight: 800; }
body.team-mode .settings-stage textarea { line-height: 1.8; resize: vertical; }
body.team-mode .settings-stage input,
body.team-mode .settings-stage textarea,
body.team-mode .settings-stage select { font-weight: 400; }
body.team-mode .settings-stage textarea:focus,
body.team-mode .settings-stage input:focus,
body.team-mode .settings-stage select:focus { border-color: var(--mefa-blue); box-shadow: 0 0 0 3px #2563eb19; }
body.team-mode .settings-stage .field .muted { margin: 0; }
.settings-advanced-details,
body.team-mode #settings-pre-form,
.question-advanced {
  margin-block: 18px;
  padding: 13px 17px;
  border: 1px solid var(--mefa-line);
  border-radius: 13px;
  background: #f8fbff;
}
.settings-advanced-details > summary,
body.team-mode #settings-pre-form > summary,
.question-advanced > summary { min-height: 44px; color: var(--mefa-navy); font-weight: 800; cursor: pointer; }
body.team-mode #settings-questionnaire > h3 { margin-bottom: 3px; color: var(--mefa-navy); }
body.team-mode #settings-questionnaire > p { max-width: 78ch; }
body.team-mode .interview-question { padding: 0; overflow: hidden; background: #fff; }
body.team-mode .interview-question[open] { border-color: #8fb3e5; box-shadow: 0 8px 25px #173b7512; }
body.team-mode .interview-question > summary {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 13px 16px;
  list-style: none;
}
body.team-mode .interview-question > summary::-webkit-details-marker { display: none; }
.question-number { display: grid; flex: 0 0 36px; width: 36px; height: 36px; place-items: center; border-radius: 10px; color: var(--mefa-navy); background: #eaf3ff; font-weight: 800; }
.question-summary { min-width: 0; display: grid; gap: 1px; }
.question-summary strong { color: var(--mefa-text); font-size: .94rem; line-height: 1.6; }
.question-summary small { color: var(--mefa-muted); font-size: .77rem; }
.question-editor-body { padding: 2px 18px 18px; border-top: 1px solid var(--mefa-line); }
.question-editor-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 10px; border-top: 1px solid var(--mefa-line); }
.question-editor-actions .actions { margin-top: 0; flex-wrap: wrap; }
.question-editor-actions button { min-height: 42px; padding: 7px 11px; font-size: .84rem; }
.provider-choice .check { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-weight: 600; }
.provider-choice .check input { width: 19px; min-height: 19px; height: 19px; accent-color: var(--mefa-blue); }
.provider-choice .provider-custom-input { direction: ltr; text-align: left; }
.settings-review-summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.settings-review-summary > div { display: grid; gap: 3px; min-width: 0; padding: 12px 15px; border: 1px solid var(--mefa-line); border-radius: 12px; background: #f8fbff; }
.settings-review-summary span { color: var(--mefa-muted); font-size: .8rem; }
.settings-review-summary strong { color: var(--mefa-navy); overflow-wrap: anywhere; }
.settings-blocker { margin: 15px 0; padding: 12px 15px; border: 1px solid #efcf8f; border-radius: 12px; color: #704b0c; background: #fff8e8; font-weight: 700; }
.settings-read-preview { margin-top: 17px; padding: 12px 16px; border: 1px solid var(--mefa-line); border-radius: 13px; background: #fbfdff; }
.settings-read-preview > summary { min-height: 44px; color: var(--mefa-navy); font-weight: 800; cursor: pointer; }
.settings-read-preview h4 { margin: 16px 0 6px; color: var(--mefa-navy); }
.settings-read-preview p { max-width: 76ch; line-height: 1.9; }
.settings-read-preview li { padding-block: 4px; }
.settings-savebar { position: sticky; bottom: 10px; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; padding: 11px 14px; border: 1px solid #bcd1eb; border-radius: 15px; color: var(--mefa-navy); background: #ffffffef; box-shadow: 0 12px 28px #143a6b24; backdrop-filter: blur(10px); }
.settings-savebar > span { font-size: .85rem; font-weight: 700; }
.settings-savebar .actions { margin: 0; flex-wrap: wrap; }
.settings-savebar button { min-height: 42px; padding: 7px 14px; font-size: .86rem; }

@media (max-width: 720px) {
  body.participant-mode .topbar,
  body.team-mode .topbar { min-height: 74px; padding: 10px 14px; gap: 12px; }
  .top-brand { gap: 9px; }
  .top-brand img.mefa-logo { flex-basis: 42px; width: 42px; height: 42px; border-radius: 11px; }
  .top-brand strong { font-size: .91rem; }
  body.participant-mode .top-brand span,
  body.team-mode .top-brand span { max-width: min(45vw, 280px); font-size: .69rem; }
  body.participant-mode .shell,
  body.team-mode .shell { padding: 24px 12px 60px; }
  body.participant-mode #consent { padding: 23px 20px 24px; }
  body.participant-mode #consent h1 { margin-block: 15px 18px; }
  body.participant-mode #consent-copy { padding: 9px 14px; }
  .consent-actions .primary { width: 100%; }
  body.team-mode .login-card { margin: 10px auto; padding: 26px 23px 29px; }
  body.team-mode .dashboard-head { align-items: flex-start; gap: 8px; padding: 18px; }
  body.team-mode .dashboard-head .actions { width: 100%; margin-top: 4px; gap: 8px; }
  .community-row { align-items: stretch; flex-direction: column; }
  .community-row .secondary { align-self: flex-start; }
  body.team-mode .settings-workspace { padding: 19px 15px 24px; }
  .settings-heading { flex-direction: column; gap: 9px; }
  body.team-mode .settings-jump-nav { top: 74px; margin-inline: -7px; }
  body.team-mode .settings-jump-nav button { flex: 0 0 auto; }
  body.team-mode .settings-stage fieldset { padding: 12px 13px; }
  .settings-review-summary { grid-template-columns: 1fr; }
  .settings-savebar { flex-direction: column; align-items: stretch; bottom: 4px; }
  .settings-savebar .actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-savebar button { padding-inline: 8px; }
}
@media (max-width: 480px) {
  body.team-mode .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body.team-mode .metric:last-child { grid-column: 1 / -1; }
  body.participant-mode .chat-title { padding: 12px 13px; gap: 8px; }
  .chat-title-brand { gap: 8px; }
  .chat-title-brand img { flex-basis: 34px; width: 34px; height: 34px; }
}
@media (prefers-reduced-motion: reduce) {
  body.participant-mode *,
  body.team-mode * { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
