.pcs-contract-modal-overlay{
  position: fixed !important;
  inset: 0;
  background: rgba(10, 12, 16, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  /* Stay above sticky headers/menus (Divi can use very high z-indexes). */
  z-index: 2147483647 !important;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.pcs-contract-modal-overlay.pcs-open{
  opacity: 1;
  pointer-events: auto;
}

/* Divi / sticky header stacking-context override while modal open */
body.pcs-contract-modal-open #main-header,
body.pcs-contract-modal-open #top-header,
body.pcs-contract-modal-open .et-fixed-header,
body.pcs-contract-modal-open .et_pb_sticky,
body.pcs-contract-modal-open .et_builder_inner_content,
body.pcs-contract-modal-open header,
body.pcs-contract-modal-open nav{
  z-index: 0 !important;
}

.pcs-contract-modal{
  width: min(980px, 100%);
  max-height: min(86vh, 860px);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  overflow: hidden;
  transform: translateY(10px) scale(0.985);
  opacity: 0;
  transition: transform 260ms cubic-bezier(.2,.9,.2,1), opacity 260ms ease;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
}

.pcs-open .pcs-contract-modal{
  transform: translateY(0) scale(1);
  opacity: 1;
}

.pcs-contract-modal__header{
  padding: 18px 22px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pcs-contract-modal__title{
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 700;
  color: #111827;
}

.pcs-contract-modal__subtitle{
  margin: 4px 0 0 0;
  font-size: 13px;
  line-height: 1.35;
  color: #6b7280;
}

.pcs-contract-modal__body{
  padding: 18px 22px;
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, rgba(249,250,251,0.9), #fff 90px);
}

.pcs-contract-content{
  background: #fff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 14px;
  padding: 16px 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}

.pcs-contract-content pre{
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 14px;
  line-height: 1.65;
  color: #111827;
}

.pcs-contract-modal__footer{
  padding: 16px 22px 20px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: #fff;
}

.pcs-sign-grid{
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px){
  .pcs-contract-modal-overlay{
    align-items: flex-start;
    padding: 10px;
  }

  .pcs-contract-modal{
    position: relative;
    width: 100%;
    max-height: calc(100dvh - 20px);
    height: calc(100dvh - 20px);
    border-radius: 14px;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .pcs-contract-modal__header{
    padding: 12px 14px;
  }

  .pcs-contract-modal__body{
    padding: 12px 14px;
  }

  .pcs-contract-scroll-end{
    height: 1px;
    width: 100%;
    pointer-events: none;
  }

  .pcs-contract-modal__footer{
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    max-height: min(58vh, 420px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 14px 14px;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.12);
    visibility: hidden;
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease, transform 220ms ease, visibility 0s linear 220ms;
  }

  .pcs-contract-modal.pcs-signature-visible .pcs-contract-modal__footer{
    visibility: visible;
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
    transition: opacity 200ms ease, transform 220ms ease, visibility 0s;
  }

  .pcs-contract-modal__body::after{
    content: "Scroll to the bottom to sign";
    display: block;
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
  }

  .pcs-contract-modal.pcs-signature-visible .pcs-contract-modal__body::after{
    display: none;
  }

  .pcs-sign-grid{ grid-template-columns: 1fr; }

  canvas#pcs-contract-signature{
    height: 80px;
  }

  .pcs-sign-box__label{
    padding: 8px 10px;
  }

  .pcs-sign-actions{
    padding: 8px 10px;
  }
}

.pcs-sign-box{
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

.pcs-sign-box__label{
  padding: 10px 12px;
  font-weight: 700;
  font-size: 13px;
  color: #111827;
  background: #f9fafb;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.pcs-sign-canvas-wrap{
  position: relative;
  background: repeating-linear-gradient(
    0deg,
    rgba(17, 24, 39, 0.02),
    rgba(17, 24, 39, 0.02) 24px,
    rgba(17, 24, 39, 0.04) 24px,
    rgba(17, 24, 39, 0.04) 25px
  );
}

canvas#pcs-contract-signature{
  width: 100%;
  height: 110px;
  display: block;
  touch-action: none;
}

.pcs-sign-actions{
  display:flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: #fff;
}

.pcs-btn{
  appearance: none;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  color: #111827;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 160ms ease, background 160ms ease;
}
.pcs-btn:hover{ box-shadow: 0 8px 20px rgba(0,0,0,0.08); transform: translateY(-1px); }
.pcs-btn:active{ transform: translateY(0); box-shadow: none; }

.pcs-btn-primary{
  border-color: rgba(4,85,191,0.35);
  background: #0455bf;
  color: #fff;
}

.pcs-btn-primary[disabled]{
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.pcs-fields{
  display: grid;
  gap: 12px;
}

.pcs-field label{
  display:block;
  font-size: 12px;
  color: #374151;
  font-weight: 700;
  margin-bottom: 6px;
}

.pcs-field input{
  width: 100%;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
}
.pcs-field input:focus{
  border-color: rgba(4,85,191,0.6);
  box-shadow: 0 0 0 4px rgba(4,85,191,0.12);
}

.pcs-contract-error{
  display:none;
  margin-top: 10px;
  color: #b91c1c;
  font-weight: 700;
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce){
  .pcs-contract-modal-overlay,
  .pcs-contract-modal,
  .pcs-contract-modal__footer,
  .pcs-btn{
    transition: none !important;
  }
}

