/*
 * Signing Sheet — Wave A
 *
 * Sticky iOS-style bottom sheet used on /signatures/:token for the
 * multi-field guided signing flow. See signing_stepper_controller.js.
 *
 * Loaded via stylesheet_link_tag :signing_sheet from app/views/layouts/signing.html.erb.
 */

:root {
  --pact-sheet-height: 360px;
}

[data-signing-stepper-target="sheet"] {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 48rem; /* max-w-3xl */
  height: var(--pact-sheet-height);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  box-shadow: 0 -8px 32px -12px rgba(0, 0, 0, 0.18);
  z-index: 40;
  transition: height 280ms cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dark [data-signing-stepper-target="sheet"] {
  background: rgba(31, 41, 55, 0.95); /* gray-800 */
}

/* Heights are driven dynamically by JS (fitSheetToContent) which measures
   the current content and sets --pact-sheet-height to a px value. These
   class-level fallbacks are used on first paint before JS runs. */
.sheet--collapsed { --pact-sheet-height: 56px; }
.sheet--expanded  { --pact-sheet-height: auto; }
[data-signing-stepper-target="sheet"].sheet--expanded {
  max-height: min(45vh, 380px);
}

[data-signing-stepper-target="sheetHandle"] {
  padding: 8px;
  display: flex;
  justify-content: center;
  cursor: grab;
  flex-shrink: 0;
}

.handle-pill {
  width: 3rem;
  height: 0.375rem;
  border-radius: 9999px;
  background: rgb(209, 213, 219); /* gray-300 */
}

.dark .handle-pill { background: rgb(75, 85, 99); }

[data-signing-stepper-target="sheetHeader"] {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem 0.5rem;
  flex-shrink: 0;
  cursor: pointer;
  gap: 0.75rem;
}

[data-signing-stepper-target="sheetHeader"] h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: rgb(17, 24, 39);
  margin: 0;
}

.dark [data-signing-stepper-target="sheetHeader"] h3 { color: rgb(243, 244, 246); }

[data-signing-stepper-target="sheetBreadcrumb"] {
  font-size: 0.75rem;
  color: rgb(107, 114, 128);
  tab-size: 2;
  font-variant-numeric: tabular-nums;
}

[data-signing-stepper-target="sheetChevron"] {
  background: transparent;
  border: 0;
  padding: 0.25rem 0.5rem;
  color: rgb(107, 114, 128);
  cursor: pointer;
  font-size: 1.125rem;
  line-height: 1;
  transition: transform 220ms ease;
}

.sheet--collapsed [data-signing-stepper-target="sheetChevron"] { transform: rotate(180deg); }

[data-signing-stepper-target="sheetRequiredMark"] {
  color: rgb(220, 38, 38);
  margin-left: 0.25rem;
  font-weight: 700;
}

[data-signing-stepper-target="sheetBody"] {
  flex: 0 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 1.25rem 0.75rem;
}

[data-signing-stepper-target="sheetFooter"] {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid rgb(229, 231, 235);
}

.dark [data-signing-stepper-target="sheetFooter"] {
  border-top-color: rgb(55, 65, 81);
}

/* Hide the footer entirely in Wave A when the primary action is hidden
   and no secondary action content exists. Keeps the sheet compact. */
[data-signing-stepper-target="sheetFooter"]:empty,
[data-signing-stepper-target="sheetFooter"].sheet-footer--empty {
  display: none;
}

/* Sheet collapse behavior — hide body/footer entirely when collapsed */
.sheet--collapsed [data-signing-stepper-target="sheetBody"],
.sheet--collapsed [data-signing-stepper-target="sheetFooter"] {
  display: none;
}

/* Slide transitions for forward/backward navigation */
.sheet-body-slide-out-forward  { animation: signingSheetSlideOutLeft  220ms ease-out forwards; }
.sheet-body-slide-in-forward   { animation: signingSheetSlideInRight  220ms ease-out forwards; }
.sheet-body-slide-out-backward { animation: signingSheetSlideOutRight 220ms ease-out forwards; }
.sheet-body-slide-in-backward  { animation: signingSheetSlideInLeft   220ms ease-out forwards; }

@keyframes signingSheetSlideOutLeft  { to { transform: translateX(-24px); opacity: 0; } }
@keyframes signingSheetSlideInRight  { from { transform: translateX(24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes signingSheetSlideOutRight { to { transform: translateX(24px); opacity: 0; } }
@keyframes signingSheetSlideInLeft   { from { transform: translateX(-24px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Morph-to-review crossfade */
.sheet-body-crossfade-out {
  transition: opacity 180ms ease-out;
  opacity: 0;
}
.sheet-body-crossfade-in {
  transition: opacity 220ms ease-out;
  opacity: 1;
}

/* Mobile backdrop tint */
@media (max-width: 767px) {
  [data-signing-stepper-target="sheet"][data-signing-stepper-sheet-state-value="expanded"]::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.08);
    pointer-events: none;
    z-index: -1;
  }
}

/* pdfScrollRegion bottom padding so PDF is scrollable above sheet */
[data-signing-stepper-target="pdfScrollRegion"] {
  padding-bottom: calc(var(--pact-sheet-height) + 1rem);
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  [data-signing-stepper-target="sheet"],
  .sheet-body-slide-out-forward,
  .sheet-body-slide-in-forward,
  .sheet-body-slide-out-backward,
  .sheet-body-slide-in-backward,
  .sheet-body-crossfade-out,
  .sheet-body-crossfade-in {
    transition: none !important;
    animation: none !important;
  }
}

/* ========================================================================
 * Wave B — Signature creation modal, pre-signing CTA, error shake
 * ====================================================================== */

.signing-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
}
.signing-modal.hidden { display: none; }
.signing-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.signing-modal__content {
  position: relative;
  background: white;
  border-radius: 1rem;
  max-width: 560px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px -15px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  animation: signingModalFadeIn 220ms cubic-bezier(0.32, 0.72, 0, 1);
}
.dark .signing-modal__content { background: rgb(31, 41, 55); color: white; }

@keyframes signingModalFadeIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Mobile full-screen */
@media (max-width: 639px) {
  .signing-modal__content {
    width: 100%;
    max-width: none;
    max-height: 100vh;
    border-radius: 1rem 1rem 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }
}

.signing-modal__header {
  padding: 1.5rem 1.5rem 0;
}
.signing-modal__header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: rgb(17, 24, 39);
}
.dark .signing-modal__header h2 { color: rgb(243, 244, 246); }
.signing-modal__subtitle {
  font-size: 0.875rem;
  color: rgb(107, 114, 128);
  margin: 0 0 1rem;
}
.signing-modal__body {
  padding: 0 1.5rem 1rem;
  flex: 1 1 auto;
  overflow-y: auto;
}
.signing-modal__body section {
  margin-bottom: 1.25rem;
}
.signing-modal__body section h3 {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: rgb(17, 24, 39);
}
.dark .signing-modal__body section h3 { color: rgb(243, 244, 246); }

.signing-modal__footer {
  padding: 1rem 1.5rem 1.5rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  border-top: 1px solid rgb(229, 231, 235);
  flex-shrink: 0;
}
.dark .signing-modal__footer { border-top-color: rgb(55, 65, 81); }

.modal-mode-toggle {
  display: inline-flex;
  background: rgb(243, 244, 246);
  border-radius: 0.5rem;
  padding: 0.25rem;
  margin-bottom: 0.5rem;
}
.modal-mode-toggle button {
  padding: 0.375rem 0.875rem;
  font-size: 0.75rem;
  font-weight: 500;
  background: transparent;
  border: 0;
  border-radius: 0.375rem;
  color: rgb(75, 85, 99);
  cursor: pointer;
}
.modal-mode-toggle button.active {
  background: white;
  color: rgb(17, 24, 39);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-remember-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid rgb(229, 231, 235);
}
.remember-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: rgb(17, 24, 39);
}
.dark .remember-label { color: rgb(243, 244, 246); }
.remember-helper {
  font-size: 0.75rem;
  color: rgb(107, 114, 128);
  margin: 0.25rem 0 0 1.5rem;
}

.modal-landscape-hint {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: rgb(254, 249, 195);
  border: 1px solid rgb(250, 204, 21);
  border-radius: 0.5rem;
  font-size: 0.75rem;
  color: rgb(133, 77, 14);
}
.modal-landscape-hint p { margin: 0; }
@media (orientation: landscape), (min-width: 640px) {
  .modal-landscape-hint { display: none !important; }
}

.welcome-back__message {
  font-size: 0.875rem;
  color: rgb(55, 65, 81);
  margin: 0 0 1rem;
}
.dark .welcome-back__message { color: rgb(209, 213, 219); }
.welcome-back__previews {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.welcome-back__previews > div {
  flex: 1 1 auto;
  min-width: 160px;
  padding: 0.75rem;
  background: rgb(249, 250, 251);
  border: 1px solid rgb(229, 231, 235);
  border-radius: 0.5rem;
}
.welcome-back__previews img {
  max-width: 100%;
  max-height: 80px;
  display: block;
}
.preview-label {
  display: block;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgb(107, 114, 128);
  margin-bottom: 0.25rem;
}
.welcome-back__actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.welcome-back__forget-link {
  background: none;
  border: 0;
  color: rgb(107, 114, 128);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.25rem 0;
}

.btn-primary {
  background: rgb(37, 99, 235);
  color: white;
  padding: 0.5rem 1rem;
  border: 0;
  border-radius: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.875rem;
}
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:hover:not(:disabled) { background: rgb(29, 78, 216); }
.btn-secondary {
  background: transparent;
  color: rgb(55, 65, 81);
  padding: 0.5rem 1rem;
  border: 1px solid rgb(209, 213, 219);
  border-radius: 0.5rem;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.875rem;
}
.dark .btn-secondary { color: rgb(229, 231, 235); border-color: rgb(75, 85, 99); }
.btn-secondary:hover { background: rgb(249, 250, 251); }

.link-button {
  background: none;
  border: 0;
  color: rgb(107, 114, 128);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.25rem 0;
}

/* ---------------------------------------------------------------------
 * Pre-signing sticky CTA bar (where sheet sits once signing begins)
 * ------------------------------------------------------------------- */
.pre-signing-cta {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 48rem;
  background: white;
  border-top-left-radius: 1rem;
  border-top-right-radius: 1rem;
  box-shadow: 0 -8px 32px -12px rgba(0, 0, 0, 0.18);
  padding: 1.25rem 1.5rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  text-align: center;
}
.pre-signing-cta.hidden { display: none; }
.dark .pre-signing-cta { background: rgb(31, 41, 55); color: white; }
.pre-signing-cta__button {
  width: 100%;
  background: rgb(37, 99, 235);
  color: white;
  border: 0;
  border-radius: 0.75rem;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px -2px rgba(37, 99, 235, 0.4);
}
.pre-signing-cta__button:hover { background: rgb(29, 78, 216); }
.pre-signing-cta__subtitle {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  color: rgb(107, 114, 128);
}
.pre-signing-cta__privacy {
  margin: 0.5rem 0 0;
  font-size: 0.6875rem;
  font-style: italic;
  color: rgb(156, 163, 175);
}

/* ---------------------------------------------------------------------
 * Sheet error region (inline validation replacing alert())
 * ------------------------------------------------------------------- */
[data-signing-stepper-target="sheetError"] {
  margin-top: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: rgb(254, 242, 242);
  border: 1px solid rgb(252, 165, 165);
  border-radius: 0.5rem;
  color: rgb(153, 27, 27);
  font-size: 0.8125rem;
}
[data-signing-stepper-target="sheetError"][hidden] { display: none !important; }
.sheet-error--shake { animation: sheetErrorShake 360ms cubic-bezier(0.36, 0.07, 0.19, 0.97); }
@keyframes sheetErrorShake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

/* ---------------------------------------------------------------------
 * Sheet header "Change signature" quiet link
 * ------------------------------------------------------------------- */
.sheet-change-signature-link {
  background: none;
  border: 0;
  padding: 0;
  color: rgb(107, 114, 128);
  font-size: 0.6875rem;
  text-decoration: underline;
  cursor: pointer;
  margin-left: 0.5rem;
}
.sheet-change-signature-link:hover { color: rgb(37, 99, 235); }
.sheet-change-signature-link[hidden] { display: none !important; }

/* ---------------------------------------------------------------------
 * Review panel — "Before you submit" banner
 * ------------------------------------------------------------------- */
.review-before-submit {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: rgb(254, 249, 195);
  border: 1px solid rgb(250, 204, 21);
  border-radius: 0.75rem;
  margin-bottom: 1rem;
}
.review-before-submit__icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  color: rgb(161, 98, 7);
  margin-top: 0.125rem;
}
.review-before-submit__title {
  font-size: 0.875rem;
  font-weight: 600;
  color: rgb(120, 53, 15);
  margin: 0 0 0.125rem;
}
.review-before-submit__body {
  font-size: 0.75rem;
  color: rgb(133, 77, 14);
  margin: 0;
}

/* Review secondary action (Go back to document) */
.review-secondary-action {
  display: block;
  width: 100%;
  text-align: center;
  background: none;
  border: 0;
  color: rgb(107, 114, 128);
  font-size: 0.8125rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.5rem 0;
  margin-top: 0.5rem;
}

/* Apply-flow field panel — minimal composition.
   Header already labels the field ("Signature *" / "Initials *") and
   provides the "Change signature" escape. The body is ONE dominant
   action button. Signers already know what their signature looks like;
   this is a confirmation moment, not a preview moment. */
.apply-field-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0.5rem 0 0.25rem;
}

.apply-field-primary {
  background: rgb(37, 99, 235);
  color: white;
  padding: 0.875rem 2.75rem;
  border: 0;
  border-radius: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  min-width: 240px;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.15);
  transition: background-color 180ms ease, transform 120ms ease, box-shadow 180ms ease;
}
.apply-field-primary:hover {
  background: rgb(29, 78, 216);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}
.apply-field-primary:active { transform: scale(0.98); }
.apply-field-primary:focus-visible {
  outline: 2px solid rgb(59, 130, 246);
  outline-offset: 3px;
}
.apply-field-helper {
  font-size: 0.75rem;
  color: rgb(107, 114, 128);
  margin: 0 0 0.75rem;
}
.apply-field-secondary-link {
  background: none;
  border: 0;
  color: rgb(107, 114, 128);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.25rem 0;
  margin-top: 0.5rem;
  display: block;
}
.apply-field-secondary-link:hover { color: rgb(37, 99, 235); }

/* Submit confirmation body text */
.submit-confirmation__body {
  font-size: 0.9375rem;
  color: rgb(55, 65, 81);
  margin: 0;
  line-height: 1.5;
}
.dark .submit-confirmation__body { color: rgb(209, 213, 219); }

/* Make the pre-signing state push the sheet out of the way */
[data-signing-stepper-sheet-state-value="pre-signing"] [data-signing-stepper-target="sheet"] {
  display: none !important;
}

