* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  font-family: "Inter", "Segoe UI", Arial, sans-serif;
  color: #4a372d;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 15%, rgba(255, 213, 168, 0.7), transparent 36%),
    radial-gradient(circle at 88% 18%, rgba(255, 189, 145, 0.55), transparent 40%),
    radial-gradient(circle at 74% 85%, rgba(255, 229, 197, 0.7), transparent 35%),
    linear-gradient(135deg, #f4e3d2 0%, #efd4b8 45%, #e6c5a7 100%);
}

.page-shell {
  width: 100%;
  max-width: 980px;
  margin: 28px auto;
  padding: 24px;
  padding-bottom: 24px;
  border-radius: 22px;
  background: rgba(255, 248, 239, 0.78);
  border: 1px solid rgba(160, 106, 73, 0.18);
  backdrop-filter: blur(8px);
  box-shadow:
    0 26px 60px rgba(127, 83, 53, 0.22),
    0 0 0 1px rgba(255, 255, 255, 0.45) inset;
}

.hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.hero-text {
  flex: 1;
  min-width: 0;
}

.hero-brand {
  flex-shrink: 0;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(54, 34, 23, 0.22);
  border: 1px solid rgba(175, 121, 88, 0.25);
}

.hero-logo {
  display: block;
  width: 120px;
  height: auto;
  object-fit: contain;
}

h1 {
  margin-top: 0;
  margin-bottom: 6px;
  color: #5b3f31;
  font-size: 2.2rem;
  font-weight: 800;
  letter-spacing: 0.2px;
}

.hero p {
  margin-top: 0;
  color: rgba(97, 67, 53, 0.92);
}

.survey-form {
  display: grid;
  gap: 20px;
}

.section {
  border-radius: 16px;
  padding: 18px;
  background: linear-gradient(
    140deg,
    rgba(255, 255, 255, 0.72),
    rgba(255, 244, 231, 0.74)
  );
  border: 1px solid rgba(175, 121, 88, 0.2);
}

.section h2 {
  margin-top: 0;
  margin-bottom: 14px;
  font-size: 1.32rem;
  color: #6b4b3a;
}

.field {
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

/* Разделитель между вопросами с radio/checkbox + preview */
.field[data-radio-preview="true"],
.field[data-checkbox-preview="true"] {
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(175, 121, 88, 0.35);
}

.field[data-radio-preview="true"]:last-child,
.field[data-checkbox-preview="true"]:last-child {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 12px;
}

.field label {
  display: block;
  font-weight: 600 !important;
  margin-bottom: 6px;
  color: #6d4f3f !important;
  font-size: 0.96rem;
}

.field textarea,
.field input {
  width: 100%;
  max-width: 100%;
  border: 1px solid rgba(182, 136, 105, 0.36);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  outline: none;
  background: rgba(255, 251, 245, 0.95);
  color: #4d392f;
}

.field textarea {
  min-height: 75px;
  resize: vertical;
}

.field textarea:focus,
.field input:focus {
  border-color: #c17749;
  box-shadow: 0 0 0 2px rgba(193, 119, 73, 0.2);
}

.textarea-hidden {
  display: none;
}

.field--clickable .option-hints {
  margin: 0 0 8px;
  line-height: 1.6;
  font-size: 0.95rem;
  color: #6d4f3f;
}

.option-chip {
  display: inline;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  font: inherit;
  color: #8b5a3c;
  cursor: pointer;
  border-bottom: 1px dashed #c17749;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.option-chip:hover,
.option-chip:focus {
  color: #c17749;
  border-bottom-color: #a85f2f;
  outline: none;
}

.option-chip:active {
  color: #7a4a2c;
}

.option-chip-with-image {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
  border-bottom: none;
  padding: 2px 0;
}

.option-thumb {
  width: 26px;
  height: 26px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(193, 119, 73, 0.28);
  box-shadow: 0 2px 6px rgba(127, 83, 53, 0.2);
}

.option-chip-text {
  border-bottom: 1px dashed #c17749;
  line-height: 1.2;
}

.option-chip-with-image:hover .option-chip-text,
.option-chip-with-image:focus .option-chip-text {
  border-bottom-color: #a85f2f;
}

.option-radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 10px;
}

.option-radio-item {
  color: #6d4f3f;
  font-size: 0.96rem;
}

.option-preview-wrap {
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(175, 121, 88, 0.28);
  background: rgba(255, 251, 245, 0.92);
}

.option-preview-large {
  display: block;
  width: 100%;
  max-width: 560px;
  max-height: 260px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(193, 119, 73, 0.3);
}

.option-preview-caption {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: #7a4f34;
}

.option-checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.option-checkbox-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(175, 121, 88, 0.28);
  background: rgba(255, 251, 245, 0.92);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.option-checkbox-card:has(input:checked) {
  border-color: #c17749;
  box-shadow: 0 0 0 2px rgba(193, 119, 73, 0.16);
}

.option-checkbox-card input[type="checkbox"] {
  margin: 0;
}

.option-checkbox-thumb {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(193, 119, 73, 0.22);
}

.option-checkbox-label {
  font-size: 0.86rem;
  line-height: 1.2;
  color: #6d4f3f;
  text-align: center;
}

.option-preview-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(175, 121, 88, 0.28);
  background: rgba(255, 251, 245, 0.92);
}

.option-preview-gallery-item {
  margin: 0;
}

.option-preview-gallery-item img {
  display: block;
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid rgba(193, 119, 73, 0.3);
}

.option-preview-gallery-item figcaption {
  margin-top: 6px;
  font-size: 0.85rem;
  color: #7a4f34;
  text-align: center;
}

.option-selected-summary {
  display: none;
}

.option-selected-summary-title {
  margin: 0 0 6px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #6d4f3f;
}

.option-selected-summary-list {
  font-size: 0.9rem;
  color: #5a4134;
}

.option-selected-summary-items {
  margin: 0;
  padding-left: 18px;
}

.option-selected-summary-items li {
  margin-bottom: 4px;
}

.option-selected-summary-items li:last-child {
  margin-bottom: 0;
}

.option-sep,
.option-paren {
  color: rgba(109, 79, 63, 0.65);
  margin: 0 2px;
  user-select: none;
}

/* Нижняя панель сохранения — закреплена на всех устройствах */
.save-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  margin: 0;
  padding: 12px 24px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  padding-left: max(24px, env(safe-area-inset-left, 0px));
  padding-right: max(24px, env(safe-area-inset-right, 0px));
  background: rgba(255, 247, 236, 0.97);
  border-top: 1px solid rgba(175, 121, 88, 0.28);
  backdrop-filter: blur(10px);
  z-index: 1000;
  box-shadow: 0 -4px 24px rgba(127, 83, 53, 0.12);
}

.save-bar-inner {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.save-bar-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

#submitBtn,
#loadBtn,
#pdfBtn {
  flex: 1;
  margin: 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.load-btn {
  border-radius: 999px;
  background: rgba(255, 251, 245, 0.95);
  color: #6b4b3a;
  border: 1px solid rgba(175, 121, 88, 0.45);
  box-shadow: none;
}

.pdf-btn {
  border-radius: 999px;
  background: linear-gradient(110deg, #b66a3d, #c97b4c, #d88f63);
  color: #fff8f0;
  box-shadow: 0 12px 22px rgba(150, 89, 53, 0.24);
}

.save-bar .status {
  width: 100%;
  font-size: 0.9rem;
  line-height: 1.3;
  text-align: center;
}

.save-bar .status:empty {
  display: none;
}

.gradient-btn {
  border-radius: 999px;
  background: linear-gradient(110deg, #c87545, #d9925e, #eab48a);
  background-size: 180% 180%;
  animation: pulseGradient 6s ease infinite;
  box-shadow: 0 14px 28px rgba(152, 94, 57, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.status {
  margin: 0;
  color: #5a4134;
  font-weight: 500;
}

#submitBtn:not(:disabled):hover,
#pdfBtn:not(:disabled):hover {
  transform: translateY(-2px) scale(1.01);
  box-shadow: 0 18px 30px rgba(152, 94, 57, 0.34);
  filter: saturate(1.08);
}

#submitBtn:not(:disabled):focus-visible,
#pdfBtn:not(:disabled):focus-visible {
  outline: 2px solid rgba(193, 119, 73, 0.55);
  outline-offset: 2px;
}

/* Контейнер для рендера PDF (вне экрана, но в DOM) */
.pdf-render-mount {
  position: fixed;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 718px;
  z-index: -1;
  pointer-events: none;
  overflow: visible;
}

.pdf-document {
  background: #fff9f2;
}

@keyframes pulseGradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* Мобильные */
@media (max-width: 700px) {
  body {
    padding-bottom: calc(168px + env(safe-area-inset-bottom, 0px));
  }

  .page-shell {
    margin: 0;
    max-width: 100%;
    width: 100%;
    border-radius: 0;
    min-height: auto;
    padding: 16px;
    padding-bottom: 16px;
    border-left: none;
    border-right: none;
    overflow-x: hidden;
  }

  .hero {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .hero-brand {
    order: -1;
    align-self: flex-start;
  }

  .hero-text {
    width: 100%;
  }

  h1 {
    font-size: 1.7rem;
  }

  .hero-logo {
    width: 120px;
  }

  .survey-form,
  .section,
  .hero-text {
    max-width: 100%;
    overflow-x: hidden;
  }

  .survey-form {
    gap: 14px;
  }

  .hero p {
    word-wrap: break-word;
  }

  .section {
    padding: 14px;
  }

  .field textarea {
    min-height: 80px;
  }

  .save-bar {
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    padding-left: max(12px, env(safe-area-inset-left, 0px));
    padding-right: max(12px, env(safe-area-inset-right, 0px));
  }

  .save-bar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  #pdfBtn {
    grid-column: 1 / -1;
  }

  #submitBtn,
  #loadBtn,
  #pdfBtn {
    width: 100%;
    flex: none;
    min-height: 40px;
    height: auto;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.2;
    white-space: normal;
    text-align: center;
  }

  .save-bar .btn-large {
    height: auto;
    line-height: 1.2;
  }

  .option-preview-large {
    max-width: 100%;
  }

  .option-checkbox-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .option-checkbox-card {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "check"
      "thumb"
      "label";
    gap: 8px;
    padding: 12px;
  }

  .option-checkbox-card input[type="checkbox"] {
    grid-area: check;
    justify-self: start;
    margin: 0;
  }

  .option-checkbox-thumb {
    grid-area: thumb;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 2;
    min-height: 210px;
    object-fit: contain;
    object-position: center;
    background: #efe4d6;
  }

  .option-checkbox-label {
    grid-area: label;
    text-align: center;
    font-size: 0.95rem;
    margin-top: 2px;
  }

  .option-preview-gallery {
    display: none !important;
  }

  .option-selected-summary {
    display: block;
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(175, 121, 88, 0.28);
    background: rgba(255, 251, 245, 0.95);
  }

  .pdf-render-mount {
    left: -9999px;
    transform: none;
    width: 0;
    height: 0;
    overflow: hidden;
  }
}
