/* Keep the survey designer independent of the siting form's global controls.
   Responsive decisions use the editor/card width, including browser zoom. */
#survey-editor-page {
  width: 100%;
  max-width: 1600px;
  min-width: 0;
}

#survey-editor-page > .hub-page-heading {
  flex-wrap: wrap;
  align-items: flex-start;
}

#survey-editor-page > .hub-page-heading > div {
  flex: 1 1 20rem;
  min-width: 0;
}

#survey-editor-mount {
  container: survey-designer / inline-size;
  min-width: 0;
}

#survey-editor-page .survey-editor {
  min-width: 0;
  color: var(--text);
}

#survey-editor-page .survey-editor *,
.survey-editor-dialog * {
  box-sizing: border-box;
}

#survey-editor-page .survey-editor :is(h2, h3, p, span, small, label),
.survey-editor-dialog :is(h2, h3, h4, p, span, strong, label, li) {
  overflow-wrap: anywhere;
}

#survey-editor-page .survey-editor button,
.survey-editor-dialog button {
  flex-shrink: 0;
  min-height: 40px;
  max-width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--field);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
  white-space: normal;
  cursor: pointer;
}

#survey-editor-page .survey-editor button:hover:not(:disabled),
.survey-editor-dialog button:hover:not(:disabled) {
  border-color: var(--accent-secondary);
  background: var(--surface-hover);
}

#survey-editor-page .survey-editor button:disabled,
.survey-editor-dialog button:disabled {
  opacity: .45;
  cursor: default;
}

#survey-editor-page .survey-editor .survey-editor-primary,
.survey-editor-dialog .survey-editor-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent, #203018);
  font-weight: 650;
}

#survey-editor-page .survey-editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

#survey-editor-page .survey-editor-toolbar > div:first-child {
  flex: 1 1 15rem;
  min-width: 0;
}

#survey-editor-page .survey-editor-toolbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

#survey-editor-draft-status {
  color: var(--success);
  font-size: 13px;
  font-weight: 600;
}

#survey-editor-draft-status.is-dirty { color: var(--accent); }

#survey-editor-page .survey-editor-actions {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

#survey-editor-page .survey-editor-preservation {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 16px 4px 22px;
  color: var(--muted);
}

#survey-editor-page .survey-editor-preservation > span {
  flex: none;
  color: var(--accent);
}

#survey-editor-page .survey-editor-preservation p {
  min-width: 0;
  margin: 0;
  font-size: 11px;
  line-height: 1.8;
}

#survey-editor-page .survey-editor-preservation strong { color: var(--text); }

#survey-editor-page .survey-editor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 20px;
  min-width: 0;
}

#survey-editor-page .survey-editor-sidebar {
  position: static;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

#survey-editor-page .survey-editor-side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

#survey-editor-page .survey-editor-side-heading h2 {
  margin: 0;
  font-size: 14px;
}

#survey-editor-page .survey-editor-side-heading button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  font-size: 22px;
}

#survey-editor-page .survey-editor-sidebar nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  align-content: start;
  gap: 6px;
  max-height: 240px;
  min-width: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}

#survey-editor-page .survey-editor .survey-editor-section-link {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 64px;
  height: auto;
  padding: 10px 12px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}

#survey-editor-page .survey-editor-section-link > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
}

#survey-editor-page .survey-editor-section-link > small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.6;
}

#survey-editor-page .survey-editor .survey-editor-section-link.is-active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

#survey-editor-page .survey-editor-section-link.is-active > span { color: var(--accent); }

#survey-editor-page .survey-editor-scoring-note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.8;
}

#survey-editor-page .survey-editor-scoring-note strong { color: var(--accent-secondary); }
#survey-editor-page .survey-editor-scoring-note p { margin: 4px 0 0; color: var(--muted); }

#survey-editor-page .survey-editor-history {
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

#survey-editor-page .survey-editor-history summary {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--field);
  font-size: 11px;
  cursor: pointer;
}

#survey-editor-page .survey-editor-history summary::before { content: none; }
#survey-editor-page .survey-editor-history summary::after { content: '⌄'; float: right; }
#survey-editor-page .survey-editor-history ol { margin: 12px 0 0; padding-left: 20px; }
#survey-editor-page .survey-editor-history li { margin: 10px 0; }
#survey-editor-page .survey-editor-history li span { display: block; }
#survey-editor-page .survey-editor-content { min-width: 0; }

#survey-editor-page :is(.survey-editor-section-card, .survey-editor-question-card, .survey-editor-form-title) {
  min-width: 0;
  margin: 0 0 16px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

#survey-editor-page .survey-editor-section-card { border-top: 4px solid var(--accent-secondary); }

#survey-editor-page :is(.survey-editor-section-actions, .survey-editor-question-top) {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

#survey-editor-page :is(.survey-editor-section-actions, .survey-editor-question-top) > span {
  flex: 1 1 10rem;
  min-width: 0;
  color: var(--accent-secondary);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .5px;
  line-height: 1.7;
}

#survey-editor-page :is(.survey-editor-section-actions, .survey-editor-question-top) > div {
  display: flex;
  flex: 0 1 auto;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

#survey-editor-page :is(.survey-editor-section-actions, .survey-editor-question-top) button {
  min-height: 36px;
  padding: 7px 10px;
  font-size: 11px;
}

#survey-editor-page :is(.survey-editor-title-label, .survey-editor-label),
.survey-editor-dialog .survey-editor-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.6;
}

#survey-editor-page .survey-editor :is(input, textarea, select),
.survey-editor-dialog :is(input, textarea, select) {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: auto;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--field);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
}

#survey-editor-page .survey-editor-title-label > input {
  min-height: 48px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -.3px;
}

#survey-editor-page .survey-editor textarea,
.survey-editor-dialog textarea {
  min-height: 82px;
  resize: vertical;
}

#survey-editor-page .survey-editor :is(input, textarea, select):focus-visible,
.survey-editor-dialog :is(input, textarea, select):focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

#survey-editor-page .survey-editor-question-wording > textarea {
  min-height: 90px;
  max-height: 320px;
  field-sizing: content;
  font-size: 15px;
  font-weight: 550;
  line-height: 1.75;
}

#survey-editor-page .survey-editor-help,
.survey-editor-dialog .survey-editor-help {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}

#survey-editor-page .survey-editor-response {
  min-width: 0;
  margin: 12px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--field);
}

#survey-editor-page .survey-editor-response > summary {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  font-size: 12px;
  line-height: 1.7;
  list-style: none;
  cursor: pointer;
}

#survey-editor-page .survey-editor-response > summary::before,
#survey-editor-page .survey-editor-response > summary::-webkit-details-marker {
  display: none;
  content: none;
}

#survey-editor-page .survey-editor-response > summary > span:first-child { flex: 1; min-width: 0; }
#survey-editor-page .survey-editor-response > summary > span:last-child { flex: none; }

#survey-editor-page .survey-editor-response summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.6;
}

#survey-editor-page .survey-editor-response-body {
  container: survey-response / inline-size;
  min-width: 0;
  padding: 0 14px 16px;
}

#survey-editor-page .survey-editor-field-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 0 16px;
  min-width: 0;
}

#survey-editor-page .survey-editor-response-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-width: 0;
}

#survey-editor-page .survey-editor-required {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
}

#survey-editor-page .survey-editor .survey-editor-danger {
  min-height: 36px;
  padding: 7px 0;
  border-color: transparent;
  background: transparent;
  color: var(--danger);
  font-size: 11px;
  text-align: left;
}

#survey-editor-page .survey-editor-question-footer {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  align-items: end;
  gap: 16px;
  min-width: 0;
  margin-top: 18px;
}

#survey-editor-page .survey-editor-question-footer > button { justify-self: start; font-size: 12px; }

#survey-editor-page .survey-editor-question-footer > label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

#survey-editor-page .survey-editor .survey-editor-add {
  display: block;
  width: 100%;
  min-height: 52px;
  margin: 0 0 20px;
  padding: 15px;
  border: 1px dashed var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

#survey-editor-page .survey-editor-form-title .survey-editor-label { margin: 0; }

#survey-editor-page .survey-editor-feedback,
.survey-editor-dialog .survey-editor-feedback {
  padding: 13px 15px;
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.8;
}

#survey-editor-page .survey-editor-feedback.is-error,
#survey-editor-page .survey-editor-error,
.survey-editor-dialog .survey-editor-feedback.is-error {
  border-color: #9d544b;
  background: #3a2427;
  color: #ffd4cd;
}

#survey-editor-page :is(.survey-editor-loading, .survey-editor-error) { padding: 20px; font-size: 13px; line-height: 1.8; }

.survey-editor-dialog {
  display: none;
  width: min(860px, calc(100% - 24px));
  max-width: none;
  max-height: calc(100% - 32px);
  min-width: 0;
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 100px #0009;
}

.survey-editor-dialog[open] { display: flex; flex-direction: column; }
.survey-editor-dialog::backdrop { background: #05090fc9; backdrop-filter: blur(3px); }

.survey-editor-dialog > header {
  display: flex;
  flex: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.survey-editor-dialog > header > div { min-width: 0; }
.survey-editor-dialog h2 { margin: 7px 0 0; font-size: 22px; line-height: 1.4; }
.survey-editor-dialog > header > button { min-width: 36px; min-height: 36px; padding: 4px 9px; }

.survey-editor-dialog-body {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 20px 24px;
  overflow: auto;
  font-size: 13px;
  line-height: 1.8;
  scrollbar-gutter: stable;
}

.survey-editor-dialog-body > p:first-child { margin-top: 0; }
.survey-editor-dialog h3 { margin: 19px 0 10px; font-size: 15px; line-height: 1.6; }

.survey-editor-dialog > footer {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.survey-editor-dialog > footer > button { min-width: 0; }

.survey-editor-impact-counts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
  gap: 10px;
  min-width: 0;
  margin: 19px 0;
}

.survey-editor-impact-counts > div { min-width: 0; padding: 15px; border: 1px solid var(--border); border-radius: 9px; background: var(--field); }
.survey-editor-impact-counts strong { display: block; color: var(--accent); font-size: 26px; line-height: 1.5; }
.survey-editor-impact-counts span { display: block; color: var(--muted); font-size: 11px; line-height: 1.7; }
.survey-editor-impact-warning { padding: 14px 16px; border: 1px solid #8b733f; border-radius: 8px; background: #3c3220; color: #f8dfab; }
.survey-editor-impact-warning h3 { margin: 0 0 8px; }
.survey-editor-impact-warning ul { margin: 0; padding-left: 20px; }
.survey-editor-change-list { margin: 0; padding: 0; list-style: none; }
.survey-editor-change-list > li { margin: 0 0 9px; padding: 12px 14px; border: 1px solid var(--border); border-left: 3px solid var(--accent-secondary); border-radius: 6px; background: var(--field); }
.survey-editor-change-list > li.is-warning { border-left-color: #d3b267; }
.survey-editor-change-list :is(strong, span) { display: block; }
.survey-editor-change-list span { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.8; }

.survey-editor-acknowledgement {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin: 0;
  padding: 18px 0 3px;
  font-size: 12px;
  font-weight: 550;
  line-height: 1.8;
}

#survey-editor-page .survey-editor input[type='checkbox'],
#survey-editor-page .survey-editor input[type='radio'],
.survey-editor-dialog input[type='checkbox'],
.survey-editor-dialog input[type='radio'] {
  display: block;
  flex: none;
  width: 18px;
  min-width: 18px;
  max-width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
  box-shadow: none;
}

.survey-editor-acknowledgement > input { margin-top: 3px; }
.survey-editor-preview-section { min-width: 0; padding: 18px 0; border-top: 1px solid var(--border); }
.survey-editor-preview-section-title { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 8px 16px; }
.survey-editor-preview-section-title h3 { min-width: 0; margin: 0 0 12px; }
.survey-editor-preview-section-title > span { flex: none; color: var(--accent-secondary); font-size: 10px; line-height: 1.7; }
.survey-editor-preview-question { min-width: 0; padding: 12px 0; }
.survey-editor-preview-question h4 { margin: 0 0 16px; font-size: 14px; line-height: 1.7; }
.survey-editor-preview-options { min-width: 0; margin: 0 0 18px; padding: 0; border: 0; }
.survey-editor-preview-options legend { max-width: 100%; margin-bottom: 9px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.survey-editor-preview-options > p { margin: 0 0 8px; font-size: 12px; }
.survey-editor-preview-options > label { display: flex; align-items: flex-start; gap: 10px; margin: 8px 0; font-size: 13px; line-height: 1.8; overflow-wrap: anywhere; }
.survey-editor-preview-options input { margin-top: 3px; }
#admin-page .survey-editor-settings-link { display: inline-flex; margin-bottom: 18px; }
#survey-editor-page .survey-editor-denied { padding: 24px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
#survey-editor-page .survey-editor-denied h2 { font-size: 20px; }
#survey-editor-page .survey-editor-denied p { color: var(--muted); font-size: 13px; line-height: 1.8; }

/* A sidebar is useful only when the designer itself has room for both columns. */
@container survey-designer (min-width: 960px) {
  #survey-editor-page .survey-editor-layout { grid-template-columns: 240px minmax(0, 1fr); gap: 24px; }
  #survey-editor-page .survey-editor-sidebar { position: sticky; top: 20px; max-height: calc(100dvh - 40px); overflow: auto; scrollbar-gutter: stable; }
  #survey-editor-page .survey-editor-sidebar nav { grid-template-columns: minmax(0, 1fr); max-height: none; overflow: visible; scrollbar-gutter: auto; }
}

/* The response editor may be much narrower than the browser window. */
@container survey-response (min-width: 480px) {
  #survey-editor-page .survey-editor-field-settings { grid-template-columns: minmax(0, 1fr) minmax(180px, .6fr); }
}

@container survey-designer (max-width: 480px) {
  #survey-editor-page .survey-editor-toolbar { padding: 16px; }
  #survey-editor-page .survey-editor-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 130px), 1fr)); width: 100%; }
  #survey-editor-page :is(.survey-editor-section-card, .survey-editor-question-card, .survey-editor-form-title) { padding: 16px; }
  #survey-editor-page .survey-editor-sidebar { padding: 14px; }
  #survey-editor-page .survey-editor-sidebar nav { max-height: 220px; }
  #survey-editor-page :is(.survey-editor-section-actions, .survey-editor-question-top) > div { flex: 1 1 100%; }
}

@media (max-width: 600px) {
  .survey-editor-dialog > header, .survey-editor-dialog-body { padding: 16px; }
  .survey-editor-dialog h2 { font-size: 19px; }
  .survey-editor-dialog > footer { padding: 14px 16px; }
  .survey-editor-dialog > footer > button { flex: 1 1 130px; }
}
