:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-muted: #eef2ef;
  --text: #1e2521;
  --muted: #5b665f;
  --line: #cfd7d1;
  --line-dark: #7b877f;
  --primary: #245b45;
  --primary-dark: #184532;
  --danger: #8a2e2e;
  --warning-bg: #fff7dd;
  --warning-line: #c49a37;
  --error-bg: #fff0f0;
  --error-line: #b55454;
  --shadow: 0 8px 24px rgba(30, 37, 33, 0.08);
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

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

button {
  cursor: pointer;
}

.app-loading {
  display: grid;
  min-height: 100vh;
  place-items: center;
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  align-items: center;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 20px clamp(16px, 4vw, 40px);
}

.app-kicker {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 0 0 2px;
  text-transform: uppercase;
}

.app-header h1 {
  font-size: 24px;
  line-height: 1.2;
  margin: 0;
}

.app-header__subtitle {
  color: var(--muted);
  margin: 0;
}

.app-header__actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.app-main {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px clamp(12px, 3vw, 32px) 56px;
}

.toolbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.button,
.icon-button {
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  color: var(--text);
  display: inline-flex;
  font-weight: 650;
  justify-content: center;
  min-height: 38px;
  padding: 7px 12px;
  text-decoration: none;
}

.button:hover,
.icon-button:hover {
  background: var(--surface-muted);
}

.button-back {
  background: transparent;
  border-color: transparent;
  color: var(--primary);
  justify-content: flex-start;
  min-height: 32px;
  padding-left: 0;
  padding-right: 4px;
}

.button-back:hover {
  background: transparent;
  color: var(--primary-dark);
  text-decoration: underline;
}

.toolbar .button-back {
  flex-basis: 100%;
  width: fit-content;
}

.button:focus-visible,
.icon-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(36, 91, 69, 0.28);
  outline-offset: 2px;
}

.button-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

[data-tour-active="true"] {
  box-shadow: 0 0 0 4px rgba(196, 154, 55, 0.42), var(--shadow);
  position: relative;
  z-index: 70;
}

.tour-layer {
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 60;
}

.tour-backdrop {
  background: rgba(30, 37, 33, 0.54);
  inset: 0;
  pointer-events: auto;
  position: absolute;
}

.tour-panel {
  background: #ffffff;
  border: 1px solid var(--line-dark);
  border-radius: 8px;
  bottom: 24px;
  box-shadow: 0 18px 48px rgba(30, 37, 33, 0.22);
  max-width: min(440px, calc(100vw - 32px));
  padding: 18px;
  pointer-events: auto;
  position: absolute;
  right: 24px;
  z-index: 80;
}

.tour-panel-wide {
  max-width: min(620px, calc(100vw - 32px));
}

.tour-panel__head,
.tour-actions {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.tour-panel h2 {
  font-size: 19px;
  line-height: 1.35;
  margin: 10px 0 8px;
}

.tour-panel p {
  margin: 0;
}

.tour-progress {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tour-actions {
  margin-top: 16px;
}

.tour-route-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.tour-route-button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  text-align: left;
}

.tour-route-button:hover,
.tour-route-button:focus-visible {
  background: var(--surface-muted);
  border-color: var(--primary);
}

.tour-route-button span {
  font-weight: 750;
}

.tour-route-button small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.icon-button {
  aspect-ratio: 1 / 1;
  font-size: 16px;
  min-width: 36px;
  padding: 0;
}

.button-row,
.card-actions,
.icon-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.flash,
.notice,
.notice-inline,
.messages,
.empty-state {
  border-radius: 8px;
}

.flash {
  background: #e9f4ee;
  border: 1px solid #9dc6b3;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.notice {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  margin-bottom: 18px;
  padding: 12px 14px;
}

.notice-inline {
  background: var(--warning-bg);
  border: 1px solid var(--warning-line);
  margin: 0 0 12px;
  padding: 10px 12px;
}

.list-grid {
  display: grid;
  gap: 14px;
}

.survey-card,
.panel,
.question-editor,
.report {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.survey-card {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr auto;
  padding: 18px;
}

.survey-card h2 {
  font-size: 20px;
  line-height: 1.3;
  margin: 0 0 12px;
}

.meta-grid,
.report-summary {
  display: grid;
  gap: 8px 18px;
  grid-template-columns: repeat(5, minmax(110px, 1fr));
  margin: 0;
}

.meta-grid div,
.report-summary div {
  min-width: 0;
}

.meta-grid dt,
.report-summary dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin: 0;
}

.meta-grid dd,
.report-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.period-stack {
  display: grid;
  gap: 2px;
  line-height: 1.35;
}

.period-stack span {
  white-space: nowrap;
}

.panel {
  margin-bottom: 16px;
  padding: 18px;
}

.section-heading,
.subsection-head {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-heading h2,
.subsection-head h4 {
  margin: 0;
}

.section-heading h2 {
  font-size: 18px;
}

.section-heading-actions {
  align-items: flex-start;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-wide {
  grid-column: 1 / -1;
}

.field input,
.field textarea,
.field select {
  background: #ffffff;
  border: 1px solid var(--line-dark);
  border-radius: 6px;
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
  width: 100%;
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.date-range {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
}

.date-range__separator {
  color: var(--muted);
  font-weight: 700;
  line-height: 1;
}

.required {
  align-items: center;
  background: var(--error-bg);
  border: 1px solid var(--error-line);
  border-radius: 4px;
  color: var(--danger);
  display: inline-flex;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  margin-left: 6px;
  padding: 1px 5px;
  vertical-align: middle;
}

.question-editor-list {
  display: grid;
  gap: 14px;
}

.question-editor {
  border-color: var(--line-dark);
  border-left: 4px solid var(--primary);
  box-shadow: none;
  padding: 16px;
}

.question-editor__head {
  align-items: flex-end;
  border-bottom: 1px solid var(--surface-muted);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
}

.question-title-field {
  align-items: end;
  display: grid;
  flex: 1 1 auto;
  gap: 10px;
  grid-template-columns: auto minmax(0, 1fr);
  min-width: 0;
}

.question-number {
  color: var(--primary);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  padding-bottom: 9px;
}

.question-title-input {
  min-width: 0;
}

.subsection {
  border-top: 1px dashed var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.option-list,
.free-text-list {
  display: grid;
  gap: 10px;
}

.option-row {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) 130px auto;
}

.free-text-row {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) auto;
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.message-group {
  border: 1px solid;
  border-radius: 8px;
  padding: 12px 14px;
}

.message-group h2 {
  font-size: 15px;
  margin: 0 0 6px;
}

.message-group ul {
  margin: 0;
  padding-left: 20px;
}

.message-error {
  background: var(--error-bg);
  border-color: var(--error-line);
}

.message-warning {
  background: var(--warning-bg);
  border-color: var(--warning-line);
}

.empty-state {
  background: var(--surface-muted);
  border: 1px dashed var(--line-dark);
  color: var(--muted);
  padding: 16px;
}

.report {
  margin: 0 auto;
  max-width: 900px;
  padding: 28px;
}

.report-header {
  border-bottom: 2px solid #000;
  margin-bottom: 20px;
  padding-bottom: 18px;
}

.report-header h2 {
  font-size: 26px;
  line-height: 1.3;
  margin: 0 0 18px;
  overflow-wrap: anywhere;
}

.report-section-heading {
  border-bottom: 2px solid #000;
  margin: 0 0 14px;
  padding-bottom: 6px;
}

.report-section-heading h3 {
  font-size: 18px;
  margin: 0;
}

.report-note {
  border-left: 4px solid var(--line-dark);
  margin: 14px 0 0;
  padding-left: 12px;
  white-space: pre-wrap;
}

.report-section h3 {
  font-size: 18px;
  margin: 0 0 12px;
}

.question-block {
  border-top: 1px solid #000;
  margin-top: 18px;
  padding-top: 16px;
}

.report-header + .question-block {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.report-section-heading + .question-block {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.cross-report-section {
  border-top: 3px double #000;
  margin-top: 26px;
  padding-top: 18px;
}

.cross-report-section > h3 {
  font-size: 18px;
  margin: 0 0 6px;
}

.cross-question-block h4 {
  font-size: 15px;
  margin: 0 0 10px;
}

.cross-table th span,
.cross-table td span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.question-block h4 {
  font-size: 16px;
  line-height: 1.45;
  margin: 0 0 10px;
  overflow-wrap: anywhere;
}

.question-block h5 {
  font-size: 14px;
  margin: 12px 0 6px;
}

.question-note {
  color: var(--muted);
  margin: 0 0 10px;
}

.table-wrap {
  overflow-x: auto;
}

.report-table {
  border-collapse: collapse;
  min-width: 620px;
  width: 100%;
}

.report-table th,
.report-table td {
  border: 1px solid #555;
  padding: 8px;
  text-align: left;
  vertical-align: middle;
}

.report-table thead th {
  background: #eef2ef;
}

.report-table .numeric {
  text-align: right;
  white-space: nowrap;
}

.bar-graph {
  background: #ffffff;
  border: 1px solid #333;
  height: 18px;
  min-width: 120px;
  position: relative;
}

.bar-graph span {
  background: repeating-linear-gradient(
    45deg,
    #333,
    #333 4px,
    #777 4px,
    #777 8px
  );
  display: block;
  height: 100%;
}

.summary-box {
  border: 1px solid #777;
  margin: 10px 0;
  padding: 10px 12px;
}

.summary-box h5 {
  margin-top: 0;
}

.summary-box p,
.free-text-report {
  white-space: pre-wrap;
}

.free-text-report {
  margin: 0;
  padding-left: 20px;
}

.free-text-report li {
  margin-bottom: 6px;
}

.report-footer {
  border-top: 1px solid #000;
  color: var(--muted);
  margin-top: 22px;
  padding-top: 10px;
}

.choice-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-item {
  align-items: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 8px;
  min-height: 42px;
  padding: 9px 10px;
}

.choice-item input {
  margin-top: 4px;
}

.compact-table th,
.compact-table td {
  text-align: center;
}

.compact-table th:first-child,
.compact-table td:first-child {
  text-align: left;
}

.compact-table .choice-cell {
  padding: 0;
}

.table-choice {
  align-items: center;
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-height: 42px;
  padding: 8px 10px;
  width: 100%;
}

.table-choice:hover {
  background: var(--surface-muted);
}

.table-input {
  border: 1px solid var(--line-dark);
  border-radius: 4px;
  min-height: 34px;
  padding: 5px 6px;
  width: 82px;
}

.sensitive-panel {
  border-color: var(--warning-line);
}

.count-label,
.muted-text {
  color: var(--muted);
  margin: 0;
}

.other-field {
  margin-top: 12px;
}

.settings-group-list {
  display: grid;
  gap: 18px;
}

.settings-group {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.settings-group:first-child {
  border-top: 0;
  padding-top: 0;
}

.settings-group h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.report-settings .subsection {
  margin-top: 16px;
}

.report-add-row {
  margin-top: 12px;
}

.cross-config-list {
  display: grid;
  gap: 8px;
}

.cross-config-item {
  align-items: center;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 12px;
}

.cross-config-item > span {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.visually-hidden {
  height: 1px;
  left: -10000px;
  overflow: hidden;
  position: absolute;
  top: auto;
  width: 1px;
}

.print-only {
  display: none;
}

.survey-form {
  background: #ffffff;
  border: 1px solid var(--line);
  color: #000000;
  padding: 24px;
}

.survey-form__header {
  border-bottom: 2px solid #000000;
  margin-bottom: 18px;
  padding-bottom: 12px;
}

.survey-form__header h2 {
  font-size: 22px;
  margin: 0 0 10px;
}

.survey-form__meta {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.survey-form__meta div {
  display: grid;
  gap: 4px;
  grid-template-columns: 90px minmax(0, 1fr);
}

.survey-form__meta dt {
  font-weight: 700;
}

.survey-form__meta dd {
  margin: 0;
}

.survey-form-question {
  break-inside: avoid;
  border-bottom: 1px solid #999999;
  margin-bottom: 14px;
  padding-bottom: 14px;
}

.survey-form-question h3 {
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 8px;
}

.survey-form-options {
  display: grid;
  gap: 5px 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.survey-form-option {
  align-items: baseline;
  display: flex;
  gap: 6px;
}

.survey-check {
  font-weight: 700;
}

.survey-form-table {
  min-width: 0;
}

.survey-form-table td {
  height: 30px;
  text-align: center;
}

.survey-contact-lines {
  display: grid;
  gap: 10px;
}

.survey-contact-lines div {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: 90px minmax(0, 1fr);
}

.survey-blank-line {
  border-bottom: 1px solid #000000;
  display: block;
  min-height: 24px;
}

.survey-text-lines {
  display: grid;
  gap: 18px;
  padding-top: 8px;
}

.survey-text-lines span {
  border-bottom: 1px solid #000000;
  display: block;
  min-height: 24px;
}

@media (max-width: 840px) {
  .app-header,
  .survey-card,
  .question-editor__head,
  .section-heading,
  .subsection-head {
    align-items: stretch;
    flex-direction: column;
  }

  .survey-card {
    grid-template-columns: 1fr;
  }

  .meta-grid,
  .report-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-header__actions {
    align-items: stretch;
    justify-content: flex-start;
  }

  .tour-panel {
    bottom: 12px;
    left: 12px;
    max-width: none;
    right: 12px;
  }

  .form-grid,
  .choice-grid,
  .date-range,
  .option-row,
  .free-text-row {
    grid-template-columns: 1fr;
  }

  .date-range__separator {
    display: none;
  }

  .card-actions,
  .button-row,
  .icon-actions {
    width: 100%;
  }

  .button {
    flex: 1 1 auto;
  }

  .report {
    padding: 18px;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .app-main {
    padding-inline: 10px;
  }

  .app-header h1 {
    font-size: 20px;
  }

  .meta-grid,
  .report-summary {
    grid-template-columns: 1fr;
  }
}
