:root {
  --bg: #f7f5f8;
  --bg-deep: #f3e7ee;
  --ink: #1b1b27;
  --muted: #5b5568;
  --card: #ffffff;
  --white: #ffffff;
  --line: #e4dce3;
  --seal: #d54f7f;
  --seal-dark: #c1285e;
  --pine: #5b2262;
  --motion: #d54f7f;
  --brass: #76abd6;
  --shadow: 0 18px 50px rgba(27, 27, 39, 0.1);
  --serif: "Montserrat", "Segoe UI", sans-serif;
  --sans: "Montserrat", "Segoe UI", sans-serif;
  --script: "Great Vibes", "Segoe Script", cursive;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; }
#app { min-height: 100%; }
body:has(.shell.fit) { overflow: hidden; }
body:has(.shell.fit) #app { height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--pine); }

.shell { min-height: 100%; display: flex; flex-direction: column; }
.shell.fit { height: 100%; overflow: hidden; }
.shell.fit .workspace,
.shell.fit .sign-layout {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: minmax(0, 1fr);
}
.shell.fit .stage,
.shell.fit .panel {
  min-height: 0;
  max-height: 100%;
  overflow: auto;
}
.topbar, .auth-card, .dialog, .toast, .field, .page {
  border: 1px solid var(--line);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: rgba(255, 255, 255, 0.96);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(10px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.desk-nav { display: flex; gap: 10px; }
.topbar .top-actions { margin-left: auto; }
.desk {
  min-width: 112px;
  text-align: center;
  border-radius: 10px;
  border: 2px solid transparent;
  padding: 8px 16px;
  font-weight: 700;
  text-decoration: none;
  background: #fff;
}
.desk.overview { color: #3d6f96; border-color: #76abd6; }
.desk.overview.active { background: #e7f2fa; }
.desk.new { color: #1b1b27; border-color: #e2b325; background: #fff4c2; }
.desk.pending { color: #d54f7f; border-color: #d54f7f; }
.desk.completed { color: #118577; border-color: #118577; }
.desk.pending.active { background: #fdeef4; }
.desk.completed.active { background: #e7f6f1; }
.brand-logo { height: 58px; width: auto; display: block; }
.auth-logo { height: 88px; margin-bottom: 18px; }
.top-actions, .row-actions, .signer-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ghost, .primary, .danger, .tool, .choice {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  padding: 8px 14px;
}
.primary { background: var(--motion); color: #ffffff; border-color: var(--motion); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.danger { color: var(--seal); }
.tool.active, .choice.active { background: var(--ink); color: #ffffff; border-color: var(--ink); }
.title-input, .text-input, .area, .field-input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
}
.title-input { font-family: var(--serif); font-size: 22px; max-width: 520px; }
.text-input, .area { border-color: var(--line); background: var(--white); }
.area { min-height: 88px; resize: vertical; }
.title-input:focus, .text-input:focus, .area:focus, .field-input:focus {
  outline: 2px solid rgba(213, 79, 127, 0.45);
  border-color: transparent;
}

.home, .cert-page, .auth {
  width: min(1080px, calc(100% - 32px));
  margin: 28px auto 64px;
}
.hero { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 22px; }
.hero h1, .auth h1, .cert-page h1, .dialog h2 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.03em; margin: 0; }
.lede { color: var(--muted); max-width: 46ch; }
.cards { display: grid; gap: 12px; }
.card, .auth-card, .dialog, .panel {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.card { display: block; padding: 16px 18px; text-decoration: none; color: inherit; }
.card:hover { border-color: var(--pine); }
.card-top, .spread { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.card h2 { margin: 8px 0 4px; font-size: 22px; font-family: var(--serif); font-weight: 560; }
.muted, .save-state { color: var(--muted); }
.people { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.person { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill { border-radius: 999px; padding: 3px 8px; font-size: 12px; background: var(--bg-deep); }
.pill.completed { background: #e7f2fa; color: #3d6f96; }
.pill.out_for_signature, .pill.sealing { background: #fdeef4; color: var(--seal-dark); }
.pill.declined, .pill.void, .pill.seal_failed { background: #fdeef4; color: var(--seal-dark); }

.upload-drop {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  padding: 10px 16px;
}
.upload-drop.dragover {
  border-color: var(--seal);
  background: #fdeef4;
  color: var(--ink);
}
.empty {
  padding: 42px 28px;
  text-align: center;
  background: var(--card);
  border-radius: 18px;
  border: 1px dashed var(--line);
}
.cards.dragover .empty,
.empty.dragover,
.cards.dragover {
  border-color: var(--seal);
  background: #fdeef4;
}
.auth { min-height: 100vh; display: grid; place-items: center; margin: 0; width: 100%; }
.auth-card { width: min(460px, calc(100% - 28px)); padding: 28px; }
.auth-card h1 { font-size: 32px; line-height: 1.15; }
.stack { display: grid; gap: 10px; margin-top: 16px; }
.banner {
  background: #fdeef4;
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--ink);
}
.banner.bad { background: #fdeef4; color: var(--seal-dark); }
.workspace, .sign-layout { flex: 1; min-height: 0; display: grid; }
.workspace { grid-template-columns: 300px minmax(0, 1fr) 280px; }
.sign-layout { grid-template-columns: minmax(0, 1fr) 320px; }
.panel { border-radius: 0; box-shadow: none; padding: 16px; overflow: auto; background: rgba(255, 255, 255, 0.88); overscroll-behavior: contain; }
.stage {
  overflow: auto;
  overscroll-behavior: contain;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), transparent 80px),
    #f3eef2;
  padding: 12px 20px 80px;
}
.stage.editing { cursor: crosshair; }
.place-hint {
  position: sticky;
  top: 0;
  z-index: 3;
  width: min(820px, 100%);
  margin: 0 auto 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--ink);
  box-shadow: var(--shadow);
}
.action-banner { margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
.action-banner p { margin: 0; }
.action-banner p + p { margin-top: 4px; }
.page {
  position: relative;
  width: min(820px, 100%);
  margin: 0 auto 22px;
  background: white;
  box-shadow: var(--shadow);
  border-radius: 2px;
}
.page canvas { width: 100%; height: auto; display: block; }
.overlay { position: absolute; inset: 0; z-index: 1; }
.overlay.drop-target { outline: 3px dashed var(--seal); outline-offset: -10px; background: rgba(213, 79, 127, 0.06); }
.field {
  position: absolute;
  background: rgba(255, 255, 255, 0.82);
  border-style: dashed;
  border-width: 1.5px;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  touch-action: none;
}
.field.selected { box-shadow: 0 0 0 2px rgba(27, 27, 39, 0.35); }
.field-heading {
  flex: 0 0 auto;
  padding: 1px 16px 0 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.2;
  text-align: left;
  color: var(--ink);
  pointer-events: none;
}
.field-body {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.field.initials-letters {
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 20px;
  color: var(--ink);
}
.initials-preview {
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 72px;
  line-height: 1;
  text-align: center;
  color: var(--ink);
  padding: 8px 0 18px;
}
.field-body img,
.field img { width: 100%; height: 100%; object-fit: contain; }
.field-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  z-index: 2;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--seal);
  color: #fff;
  font-size: 14px;
  line-height: 18px;
}
.field-input { height: 100%; text-align: center; background: transparent; }
.resize {
  position: absolute;
  right: 2px;
  bottom: 2px;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  color: var(--ink);
}
.signer {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 8px;
  background: var(--white);
}
.signer { cursor: pointer; }
.signer.selected { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--seal); }
.assign-note { margin: 8px 0 0; font-size: 13px; color: var(--pine); }
.tool { cursor: grab; }
.tool:active { cursor: grabbing; }
.tool-grid, .choice-row { display: flex; flex-wrap: wrap; gap: 8px; }
.tool { border-radius: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.dialog-back {
  position: fixed;
  inset: 0;
  background: rgba(27, 27, 39, 0.42);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}
.dialog { width: min(560px, 100%); padding: 20px; max-height: min(86vh, 760px); overflow: auto; }
.pad-wrap {
  height: 180px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background:
    linear-gradient(#e4dce3, #e4dce3) center 72% / 100% 1px no-repeat,
    var(--white);
  touch-action: none;
}
.pad-wrap canvas { width: 100%; height: 100%; }
.script-preview { font-family: var(--script); font-size: 54px; line-height: 1; min-height: 72px; color: var(--ink); }
.links { display: grid; gap: 10px; }
.link-row { display: grid; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.qr { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.mail-choice p { margin: 0; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; word-break: break-all; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #ffffff;
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  z-index: 30;
}
.cert-grid { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 16px; }
.block { padding: 18px; }
.kicker { letter-spacing: 0.14em; text-transform: uppercase; font-size: 12px; color: var(--seal); margin: 0 0 6px; }
h3 { font-family: var(--serif); font-weight: 560; margin: 18px 0 8px; }

@media (max-width: 980px) {
  .workspace, .sign-layout, .cert-grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: start; }
  .title-input { font-size: 18px; }
}
