/* Form preview: an HTML Dashpivot form (Figma "Form Builder" file) that Storm fills in as it
   scrolls into view (/shared/form-preview.js). The filled values live in the markup, so
   search engines and no-JS visitors get the complete form. Sits inside .image-card-frame. */
.form-preview {
  --form-blue: #2e81da;
  --form-blue-pale: #d8e6f6;
  --form-navy: #003166;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 4px;
  background: #fff;
}

/* .image-card-frame img makes every image full width; form images keep their own size. */
.form-preview img {
  display: block;
  width: auto;
  max-width: none;
  border-radius: 0;
}

.form-preview img[hidden] {
  display: none;
}

.form-preview-bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: 10px var(--space-2);
  border-bottom: 1px solid var(--sm-border);
  background: var(--sm-grey-1, #f5f6f7);
}

.form-preview-storm {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
}

.form-preview.is-filling .form-preview-storm {
  animation: form-preview-pulse 1.2s ease-in-out infinite;
}

@keyframes form-preview-pulse {
  50% {
    transform: scale(1.15);
  }
}

.form-preview-status {
  flex: 1 1 auto;
  margin: 0;
  color: var(--sm-text);
  font-size: 14px;
  line-height: 1.4;
}

.form-preview-replay {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: none;
  color: var(--sm-blue);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.form-preview-replay:hover,
.form-preview-replay:focus-visible {
  text-decoration: underline;
}

/* The form scrolls inside the frame; Storm scrolls it along as it fills. */
.form-preview-scroll {
  max-height: 600px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.sm-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  color: var(--sm-text);
  font-size: 14px;
  line-height: 1.5;
}

.sm-form-head {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding-bottom: 12px;
  border-bottom: 2px solid var(--form-blue);
}

.sm-form-head h3 {
  flex: 1 1 auto;
  margin: 0;
  font-size: 22px;
  line-height: 1.5;
}

.sm-form-head p {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin: 0;
  font-size: 12px;
  white-space: nowrap;
}

.sm-form-head p span + span {
  color: var(--sm-text-body);
}

.sm-form-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  align-items: start;
}

.sm-form-label {
  display: flex;
  align-items: center;
  min-height: 34px;
  padding-right: 12px;
  font-size: 15px;
}

.sm-form-input,
.sm-form-date,
.sm-form-select {
  display: flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--form-blue);
  border-radius: 4px;
  color: var(--sm-text-body);
}

.sm-form-input {
  padding: 6px 8px;
}

/* Multi-select option chips (PPE, plant, body parts). Several can be ticked. */
.sm-form-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.sm-form-options button {
  min-height: 36px;
  padding: 4px 12px;
  border: 0;
  border-radius: 6px;
  background: var(--form-blue-pale);
  color: var(--form-navy);
  font: inherit;
  line-height: 1.3;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sm-form-options button[aria-checked="true"] {
  background: var(--form-blue);
  color: #fff;
}

.sm-form-date,
.sm-form-select {
  justify-self: start;
}

.sm-form-date > span {
  min-width: 110px;
  padding: 0 8px;
  text-align: center;
}

.sm-form-date img {
  box-sizing: content-box;
  padding: 5px 7px;
  border-left: 1px solid var(--form-blue);
}

.sm-form-select {
  gap: var(--space-1);
  padding: 0 var(--space-2);
}

.sm-form-select img {
  width: 12px;
  height: auto;
}

.sm-form-chip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: rgba(36, 168, 168, 0.4);
}

.sm-form-map {
  display: block;
  overflow: hidden;
  border: 1px solid var(--form-blue);
  border-radius: 4px;
}

.sm-form-map svg {
  display: block;
  width: 100%;
  height: 100px;
}

.sm-form-table {
  width: 100%;
  border: 1px solid var(--form-blue);
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 4px;
  overflow: hidden;
  table-layout: fixed;
}

.sm-form-table th,
.sm-form-table td {
  padding: 4px 8px;
  border-right: 1px solid var(--form-blue);
  border-bottom: 1px solid var(--form-blue);
  font-size: 14px;
  text-align: center;
  vertical-align: middle;
}

.sm-form-table th {
  font-weight: 500;
}

.sm-form-table td {
  color: var(--sm-text-body);
}

.sm-form-table tr > :last-child {
  border-right: 0;
}

.sm-form-table tbody tr:last-child td {
  border-bottom: 0;
}

.sm-form-table td img {
  display: block;
  margin: 0 auto;
}

.sm-form-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sm-form-photos img {
  width: 80px;
  height: 80px;
  border-radius: 6px;
  object-fit: cover;
}

.sm-form-question {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.sm-form-question > span:first-child {
  flex: 0 1 200px;
}

.sm-form-toggle {
  display: inline-flex;
}

.sm-form-toggle button {
  width: 88px;
  height: 38px;
  border: 0;
  background: var(--form-blue-pale);
  color: var(--form-navy);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sm-form-toggle button:first-child {
  border-radius: 6px 0 0 6px;
}

.sm-form-toggle button:last-child {
  border-radius: 0 6px 6px 0;
}

.sm-form-toggle button[aria-checked="true"] {
  background: var(--form-blue);
  color: #fff;
}

.sm-form-sign {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-1);
}

.sm-form-sig {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 206px;
  height: 77px;
  border: 1px solid var(--form-blue);
  border-radius: 4px;
}

.sm-form-edit {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  background: var(--sm-grey-1, #f5f6f7);
  color: var(--form-navy);
  font: inherit;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.sm-form-edit:hover,
.sm-form-edit:focus-visible {
  background: var(--form-blue-pale);
}

.sm-form-sig img.is-signed {
  animation: form-preview-sign 0.7s ease-out;
}

/* Storm has finished; the sign-offs are the visitor's to do. */
.form-preview.is-awaiting-sign .sm-form-sign:not(.is-signed) .sm-form-sig {
  animation: form-preview-await 1.6s ease-in-out infinite;
}

.form-preview.is-awaiting-sign .sm-form-sign:not(.is-signed) .sm-form-edit {
  background: var(--form-blue);
  color: #fff;
}

.form-preview.is-awaiting-sign .sm-form-sign:not(.is-signed) .sm-form-edit img {
  filter: brightness(0) invert(1);
}

@keyframes form-preview-await {
  50% {
    box-shadow: 0 0 0 4px rgba(46, 129, 218, 0.18);
  }
}

.sm-form-table td.sm-form-pending {
  padding: 8px;
  color: var(--sm-text-body);
  font-style: italic;
}

/* Fill states, set by form-preview.js. Empty while waiting; each field fills in turn. */
.form-preview [data-fill="pop"].is-empty,
.form-preview [data-fill="sign"].is-empty {
  opacity: 0;
}

.form-preview [data-fill="pop"].is-filled {
  animation: form-preview-pop 0.35s cubic-bezier(0.2, 0, 0, 1);
}

.form-preview [data-fill="sign"].is-filled {
  animation: form-preview-sign 0.7s ease-out;
}

.form-preview .sm-form-pin.is-filled {
  animation: form-preview-drop 0.45s cubic-bezier(0.3, 1.4, 0.6, 1);
  transform-box: fill-box;
  transform-origin: bottom center;
}

@keyframes form-preview-pop {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
}

@keyframes form-preview-sign {
  from {
    clip-path: inset(0 100% 0 0);
  }
}

@keyframes form-preview-drop {
  from {
    opacity: 0;
    transform: translateY(-14px);
  }
}

/* The field being typed into gets Dashpivot's focus ring. */
.form-preview .is-typing-field {
  box-shadow: 0 0 0 3px rgba(46, 129, 218, 0.2);
}

.form-preview [data-fill="text"].is-typing::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1em;
  margin-left: 1px;
  vertical-align: -2px;
  background: currentColor;
}

@media (max-width: 768px) {
  /* Phones show the finished draft as a still, so the fill status line has nothing to report. */
  .form-preview-bar {
    display: none;
  }

  .sm-form {
    padding: var(--space-2);
  }

  .sm-form-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .sm-form-label {
    min-height: 0;
  }

  .sm-form-table th,
  .sm-form-table td {
    padding: 4px;
    font-size: 12px;
  }

  /* A still preview on phones: an inner scroll box traps the thumb scrolling the page. */
  .form-preview-scroll {
    position: relative;
    max-height: 440px;
    overflow: hidden;
    overflow: clip; /* crops without making a scroll box, so a swipe here always scrolls the page */
    overscroll-behavior: auto;
  }

  .form-preview-scroll::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 96px;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff);
    pointer-events: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .form-preview *,
  .form-preview *::after {
    animation: none !important;
    transition: none !important;
  }
}
