/* docsign — app styles. Built on the workbook design system. */

@import url("/css-v2/tokens.css");
@import url("/css-v2/reset.css");
@import url("/css-v2/base.css");
@import url("/css-v2/components/button.css");
@import url("/css-v2/components/badge.css");
@import url("/css-v2/components/form.css");
@import url("/css-v2/components/form-file.css");
@import url("/css-v2/components/stepper.css");
@import url("/css-v2/components/modal.css");
@import url("/css-v2/components/toast.css");
@import url("/css-v2/components/alert.css");
@import url("/css-v2/components/empty-state.css");
@import url("/css-v2/components/progress.css");
@import url("/css-v2/components/code-block.css");
@import url("/css-v2/components/stat.css");
@import url("/css-v2/components/hellobar.css");
@import url("/css-v2/components/cookie-consent.css");

/* ---------------------------------------------------------------------- */
/* Page chrome                                                            */
/* ---------------------------------------------------------------------- */

html, body {
  height: 100%;
  margin: 0;
  background: var(--pm-black);
  color: var(--pm-white);
}
body {
  min-height: 100svh;
  font-family: var(--ff-body);
  background:
    radial-gradient(1100px 600px at 50% -10%, rgba(115, 0, 139, 0.18), transparent 60%),
    var(--pm-black);
  background-attachment: fixed;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

.docsign-topbar {
  position: sticky;
  top: var(--hellobar-h, 0px);
  z-index: var(--z-nav);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  padding: 14px clamp(16px, 3vw, 24px);
  background: rgba(10, 10, 11, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color-subtle);
}
.docsign-topbar__brand {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-color-subtle);
  color: var(--pm-gray-100);
  background: var(--pm-ink);
  transition: border-color var(--dur-base) var(--ease-out-expo), color var(--dur-base) var(--ease-out-expo);
}
.docsign-topbar__brand:hover { border-color: var(--pm-purple-400); color: var(--pm-white); }
.docsign-topbar__brand-mark {
  display: grid; place-items: center; width: 26px; height: 26px;
  border-radius: 50%; background: var(--pm-black);
}
.docsign-topbar__title {
  font-family: var(--ff-display);
  font-size: var(--fs-500);
  letter-spacing: var(--ls-display);
  margin: 0;
}

.docsign-stage {
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 40px) clamp(16px, 3vw, 32px) 80px;
}

.docsign-muted { color: var(--pm-gray-400); }

/* ---------------------------------------------------------------------- */
/* Wizard                                                                 */
/* ---------------------------------------------------------------------- */

.docsign-wiz__stepperhost { margin-bottom: var(--sp-6); }
.docsign-wiz__stage { display: flex; flex-direction: column; gap: var(--sp-5); }
.docsign-wiz__title {
  font-family: var(--ff-display);
  font-size: var(--fs-700);
  margin: 0 0 var(--sp-3);
  letter-spacing: var(--ls-display);
}
.docsign-wiz__lede { color: var(--pm-gray-300); margin: 0 0 var(--sp-4); max-width: 60ch; }
.docsign-wiz__actions { display: flex; gap: var(--sp-3); justify-content: flex-end; padding-top: var(--sp-3); }

/* Parties step */
.docsign-parties { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-3); }
.docsign-parties__row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-sm);
}
.docsign-parties__swatch {
  display: inline-block; width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--sw, #888);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.docsign-parties__count { max-width: 100px; }

/* Zones step */
.docsign-zones__partypicker {
  display: flex; flex-wrap: wrap; gap: var(--sp-2);
  padding: var(--sp-3); background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: var(--sp-4);
  position: sticky; top: calc(var(--hellobar-h, 0px) + 70px); z-index: 4;
}
.docsign-zones__chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--pm-ink);
  border: 1px solid var(--border-color-base);
  border-radius: var(--radius-pill);
  color: var(--pm-gray-200);
  font-size: var(--fs-200);
  transition: border-color var(--dur-fast) var(--ease-out-expo);
}
.docsign-zones__chip[data-active="true"] { border-color: var(--pm-purple-400); color: var(--pm-white); }
.docsign-zones__chip-swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--sw); }
.docsign-zones__chip-count {
  font-size: var(--fs-100);
  background: var(--pm-gray-800);
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  color: var(--pm-gray-300);
}
.docsign-zones__pages { display: flex; flex-direction: column; gap: var(--sp-4); align-items: center; }
.docsign-zones__page {
  position: relative;
  background: var(--pm-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-width: 100%;
}
.docsign-zones__canvas { display: block; }
.docsign-zones__overlay {
  position: absolute; inset: 0;
  cursor: crosshair;
  touch-action: none;
}

.docsign-zone {
  position: absolute;
  border: 2px solid var(--zone-colour, #5A2EE0);
  background: color-mix(in srgb, var(--zone-colour, #5A2EE0) 14%, transparent);
  border-radius: 4px;
  pointer-events: auto;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  font-size: 12px;
  color: var(--pm-black);
}
.docsign-zone__label {
  background: var(--zone-colour, #5A2EE0);
  color: white;
  padding: 1px 6px;
  border-top-right-radius: 4px;
  font-size: 11px;
}
.docsign-zone__remove {
  background: rgba(0, 0, 0, 0.65);
  color: white;
  border: 0;
  border-radius: 999px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  margin: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.docsign-zone--ghost {
  border-style: dashed;
  background: color-mix(in srgb, var(--zone-colour, #5A2EE0) 18%, transparent);
}

/* Links step */
.docsign-links { display: flex; flex-direction: column; gap: var(--sp-4); }
.docsign-links__card {
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
}
.docsign-links__header {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

/* Share-link affordances (used by wizard step 4 + share modal) */
.sigshare__field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--sp-3); }
.sigshare__label { font-size: var(--fs-200); color: var(--pm-gray-400); }
.sigshare__row { display: flex; gap: var(--sp-2); align-items: center; }
.sigshare__pass {
  font-family: var(--ff-mono, ui-monospace, "SF Mono", monospace);
  background: var(--pm-ink);
  border: 1px solid var(--border-color-base);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--pm-gray-100);
  flex: 1;
}
.sigshare__link {
  flex: 1; min-width: 0;
  font-family: var(--ff-mono, ui-monospace, "SF Mono", monospace);
  background: var(--pm-ink);
  color: var(--pm-gray-100);
  border: 1px solid var(--border-color-base);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: var(--fs-100);
}

/* ---------------------------------------------------------------------- */
/* Dashboard                                                              */
/* ---------------------------------------------------------------------- */

.docsign-dash__head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4);
  margin-bottom: var(--sp-4);
}
.docsign-dash__title {
  font-family: var(--ff-display);
  font-size: var(--fs-700);
  margin: 0;
  letter-spacing: var(--ls-display);
}
.docsign-dash__sub { color: var(--pm-gray-300); margin: 4px 0 0; }
.docsign-dash__actions { display: flex; gap: var(--sp-2); }
.docsign-dash__progress { margin-bottom: var(--sp-5); }
.docsign-dash__grid { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.docsign-dash__row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-sm);
}
.docsign-dash__who { display: flex; align-items: center; gap: var(--sp-3); }

/* ---------------------------------------------------------------------- */
/* Entry / resume list                                                    */
/* ---------------------------------------------------------------------- */

.docsign-entry__title {
  font-family: var(--ff-display); font-size: var(--fs-700); margin: 0 0 var(--sp-4);
  letter-spacing: var(--ls-display);
}
.docsign-entry__list { list-style: none; padding: 0; margin: 0 0 var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
.docsign-entry__row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------------- */
/* Party view                                                             */
/* ---------------------------------------------------------------------- */

.docsign-connecting {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-9) var(--sp-5);
  text-align: center;
  color: var(--pm-gray-300);
}
.docsign-connecting__spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--pm-gray-700);
  border-top-color: var(--pm-purple-400);
  border-radius: 50%;
  animation: docsign-spin 0.9s linear infinite;
}
@keyframes docsign-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .docsign-connecting__spinner { animation: none; border-top-color: var(--pm-purple-400); }
}

.docsign-banner {
  background: rgba(255, 70, 90, 0.14);
  border: 1px solid rgba(255, 70, 90, 0.35);
  color: #ff8593;
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm);
  font-size: var(--fs-200);
  margin-bottom: var(--sp-3);
  display: none;
}
.docsign-banner[data-shown="true"] { display: block; }

.docsign-strip {
  position: sticky;
  top: calc(var(--hellobar-h, 0px) + 70px);
  z-index: 5;
  background: var(--pm-ink);
  border: 1px solid var(--border-color-base);
  border-radius: var(--radius-sm);
  padding: var(--sp-3) var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  box-shadow: var(--shadow-sm);
}
.docsign-strip__label { color: var(--pm-gray-400); font-size: var(--fs-200); flex-shrink: 0; }
.docsign-strip__preview {
  background: white;
  border-radius: 4px;
  height: 56px; max-width: 200px;
  object-fit: contain;
  flex-shrink: 0;
}
.docsign-strip__actions { display: flex; gap: var(--sp-2); margin-left: auto; flex-wrap: wrap; }
.docsign-strip__cta { margin-left: auto; }

.docsign-party__title {
  font-family: var(--ff-display); font-size: var(--fs-600); margin: 0 0 var(--sp-2);
  letter-spacing: var(--ls-display);
}
.docsign-party__lede { color: var(--pm-gray-300); margin: 0 0 var(--sp-4); }
.docsign-party__pages { display: flex; flex-direction: column; gap: var(--sp-4); align-items: center; }
.docsign-party__page {
  position: relative;
  background: var(--pm-white);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-width: 100%;
}
.docsign-party__overlay { position: absolute; inset: 0; }

.docsign-party__zone {
  position: absolute;
  border: 2px dashed var(--pm-purple-500);
  background: rgba(122, 75, 255, 0.06);
  border-radius: 3px;
  display: flex; align-items: flex-start; justify-content: flex-start;
  cursor: pointer;
  animation: docsign-zone-pulse 2.4s ease-in-out infinite;
}
@keyframes docsign-zone-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(122, 75, 255, 0.55); }
  50%      { box-shadow: 0 0 0 4px rgba(122, 75, 255, 0.0); }
}
@media (prefers-reduced-motion: reduce) {
  .docsign-party__zone { animation: none; }
}
.docsign-party__zonelabel {
  background: var(--pm-purple-500);
  color: white;
  font-size: 11px;
  padding: 1px 6px;
  border-bottom-right-radius: 3px;
}

.docsign-party__placement {
  position: absolute;
  cursor: move;
  border: 1px dashed transparent;
  touch-action: none;
}
.docsign-party__placement:hover, .docsign-party__placement:focus-within {
  border-color: var(--pm-purple-400);
}
.docsign-party__placeimg {
  width: 100%; height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}
.docsign-party__handle {
  position: absolute;
  width: 14px; height: 14px;
  background: var(--pm-purple-500);
  border-radius: 3px;
  cursor: nwse-resize;
  bottom: -7px; right: -7px;
  border: 1px solid white;
}

.docsign-party__actions {
  display: flex; gap: var(--sp-3); justify-content: flex-end;
  align-items: center;
  margin-top: var(--sp-5);
}
.docsign-party__hint {
  color: var(--pm-gray-300);
  font-size: var(--fs-100);
  font-style: italic;
}
.docsign-party__hint[data-shown="false"] { display: none; }

.docsign-party__done {
  text-align: center;
  padding: var(--sp-7) var(--sp-5);
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-md);
  display: flex; flex-direction: column; gap: var(--sp-3); align-items: center;
}
.docsign-party__done h2 { font-family: var(--ff-display); font-size: var(--fs-700); margin: 0; letter-spacing: var(--ls-display); }
.docsign-party__done p { color: var(--pm-gray-300); margin: 0; max-width: 60ch; }

/* ---------------------------------------------------------------------- */
/* Signature modal                                                        */
/* ---------------------------------------------------------------------- */

.modal--signature {
  width: min(96vw, 1100px);
  max-width: none;
  /* Definite height (not just max-height) so .sigstage's flex:1 has space to
     allocate. With only max-height, the modal collapses to its content's
     intrinsic height, sigstage gets 0, and the container-query-sized sigpad
     (min(100cqw, 200cqh)) goes to 0×0. */
  height: min(96vh, 720px);
  max-height: min(96vh, 720px);
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.sigtoolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2);
  background: var(--pm-gray-900);
  border: 1px solid var(--border-color-subtle);
  border-radius: var(--radius-sm);
}
.sigtoolbar__tabs { display: inline-flex; gap: 2px; padding: 2px; background: var(--pm-ink); border-radius: var(--radius-pill); }
.sigtoolbar__tab {
  background: transparent; border: 0; color: var(--pm-gray-400);
  padding: 6px 14px; border-radius: var(--radius-pill);
  font-size: var(--fs-200);
}
.sigtoolbar__tab[data-active="true"] { background: var(--pm-purple-700); color: var(--pm-white); }

.sigtoolbar__colours { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sigtoolbar__family {
  background: transparent; border: 1px solid var(--border-color-base);
  padding: 4px 10px; border-radius: var(--radius-pill);
  color: var(--pm-gray-300); font-size: var(--fs-100);
}
.sigtoolbar__family[data-active="true"] { border-color: var(--pm-purple-400); color: var(--pm-white); }
.sigtoolbar__swatches { display: inline-flex; gap: 4px; }
.sigtoolbar__swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: var(--sw, #888);
  cursor: pointer;
}
.sigtoolbar__swatch[data-active="true"] {
  outline: 2px solid var(--pm-accent);
  outline-offset: 2px;
}
.sigtoolbar__toggle {
  background: transparent;
  border: 1px solid var(--border-color-base);
  color: var(--pm-gray-300);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-100);
  cursor: pointer;
}
.sigtoolbar__toggle[data-active="true"] {
  border-color: var(--pm-purple-400);
  color: var(--pm-white);
  background: var(--pm-purple-700);
}

.sigtoolbar__spacer { flex: 1; }

.sigstage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  container-type: size;
}
/* Phone-sized viewport — either portrait (narrow) or landscape (short). The
   height query catches iPhone landscape, where width is ~850px so the
   max-width rule alone misses it. Without a fixed modal height, the flex
   column has no space to allocate and .sigstage collapses to 0. */
@media (max-width: 768px), (max-height: 500px) {
  .modal--signature {
    width: 100vw; max-width: 100vw;
    height: 100dvh; max-height: 100dvh;
    border-radius: 0;
    padding: var(--sp-3);
  }
  .sigtoolbar { padding: 6px; gap: 6px; }
  .sigtoolbar__dl { display: none; }
}
.sigstage[data-tab="draw"] .sigupload { display: none; }
.sigstage[data-tab="upload"] .sigpad { display: none; }

/* Locked horizontal aspect — signatures are always wider than tall, even on a
   phone in portrait. max-height clamps when the stage is shorter than 2:1
   (e.g. iPhone landscape) and the browser shrinks the width to maintain ratio.
   White bg lives on the sigpad (not the stage) so the canvas reads as a
   distinct rectangle inside the dark modal — without this the whole stage
   looks like the canvas. */
.sigpad {
  position: relative;
  aspect-ratio: 2 / 1;
  /* min() of full container width or 2x container height — guarantees the
     2:1 box fits both dimensions, regardless of orientation. iOS 16+. */
  width: min(100cqw, 200cqh);
  background: white;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px var(--border-color-base);
}
.sigpad__canvas { display: block; width: 100%; height: 100%; }

/* Reuses .file-drop from form-file.css for visual treatment + drag-state.
   Absolute positioning fills the stage so it stacks 1:1 with the canvas
   on the Draw tab. */
.sigupload {
  position: absolute; inset: 0;
  box-sizing: border-box;
}

/* Toast — workbook ships position + chrome; just add a fade transition. */
.toast { opacity: 0; transform: translateY(8px); transition: opacity var(--dur-base), transform var(--dur-base); }
.toast[data-show="true"] { opacity: 1; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
