/* ==========================================================================
   GetSigning — application styles
   Layered over Bootstrap 5. Same visual family as Invoicr: white, airy,
   generous whitespace, one teal accent used sparingly, hairline borders
   instead of shadows.
   ========================================================================== */

:root {
  --brand:        #0d9488;
  --brand-dark:   #0f766e;
  --brand-soft:   #f0fdfa;
  --brand-border: #99f6e4;

  --ink:      #111827;
  --ink-soft: #374151;
  --muted:    #6b7280;
  --faint:    #9ca3af;

  --rule:     #e5e7eb;
  --rule-soft:#f1f5f9;
  --canvas:   #f8fafc;
  --surface:  #ffffff;

  --radius:    10px;
  --radius-sm: 7px;

  --bs-body-color: var(--ink);
  --bs-link-color: var(--brand-dark);
  --bs-link-hover-color: var(--brand);
}

/* ---- Base ------------------------------------------------------------ */

body {
  background: var(--canvas);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 0.9375rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { font-weight: 600; letter-spacing: -0.011em; color: var(--ink); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* The eyebrow label above a page title — lifted straight from Invoicr. */
.kicker {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--brand-dark);
  margin-bottom: 0.25rem;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-head .lead-sub { color: var(--muted); font-size: 0.875rem; margin: 0.15rem 0 0; }

/* ---- Navigation ------------------------------------------------------ */

.app-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.app-nav .navbar-brand {
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.app-nav .navbar-brand .mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 700;
}
.app-nav .nav-link {
  color: var(--ink-soft);
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
}
.app-nav .nav-link:hover { background: var(--rule-soft); text-decoration: none; }
.app-nav .nav-link.active { color: var(--brand-dark); background: var(--brand-soft); }

/* ---- Cards ----------------------------------------------------------- */

.app-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.app-card > .app-card-head {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--rule-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.app-card > .app-card-head h2,
.app-card > .app-card-head h3 { margin: 0; font-size: 0.975rem; }
.app-card > .app-card-body { padding: 1.25rem; }
.app-card > .app-card-body.tight { padding: 0; }
.app-card > .app-card-foot {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--rule-soft);
  background: #fcfdfe;
  border-radius: 0 0 var(--radius) var(--radius);
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  height: 100%;
}
.stat-card .stat-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-card .stat-value {
  font-size: 1.85rem;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-top: 0.3rem;
}
.stat-card .stat-note { font-size: 0.8125rem; color: var(--faint); }
.stat-card.is-accent { border-color: var(--brand-border); background: var(--brand-soft); }
.stat-card.is-accent .stat-value { color: var(--brand-dark); }

/* ---- Tables ---------------------------------------------------------- */

.app-table { margin: 0; }
.app-table thead th {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  padding: 0.7rem 1.25rem;
  background: transparent;
}
.app-table tbody td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: middle;
}
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table tbody tr:hover { background: #fcfdfe; }
.app-table .row-title { font-weight: 550; color: var(--ink); }
.app-table .row-sub { font-size: 0.8125rem; color: var(--muted); }

/* ---- Badges ---------------------------------------------------------- */

.badge-status {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.28em 0.65em;
  border-radius: 999px;
  border: 1px solid transparent;
}
.badge-status.bg-secondary { background: var(--rule-soft) !important; color: var(--ink-soft); border-color: var(--rule); }
.badge-status.bg-info      { background: #eff6ff !important; color: #1d4ed8; border-color: #bfdbfe; }
.badge-status.bg-warning   { background: #fffbeb !important; color: #b45309; border-color: #fde68a; }
.badge-status.bg-success   { background: var(--brand-soft) !important; color: var(--brand-dark); border-color: var(--brand-border); }
.badge-status.bg-danger    { background: #fef2f2 !important; color: #b91c1c; border-color: #fecaca; }
.badge-status.bg-dark      { background: #f3f4f6 !important; color: #4b5563; border-color: #d1d5db; }

/* ---- Buttons --------------------------------------------------------- */

.btn { font-weight: 500; border-radius: var(--radius-sm); }
.btn-brand {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.btn-brand:hover, .btn-brand:focus {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #fff;
}
.btn-outline-brand {
  border-color: var(--rule);
  color: var(--ink-soft);
  background: var(--surface);
}
.btn-outline-brand:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-soft);
}
.btn-sm { font-size: 0.8125rem; padding: 0.28rem 0.65rem; }

/* ---- Forms ----------------------------------------------------------- */

.form-label { font-size: 0.8125rem; font-weight: 550; color: var(--ink-soft); margin-bottom: 0.3rem; }
.form-control, .form-select {
  border-color: var(--rule);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  padding: 0.5rem 0.7rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.13);
}
.form-text { font-size: 0.8125rem; color: var(--muted); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.form-check-input:focus { box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.13); }

/* ---- Empty state ----------------------------------------------------- */

.empty-state { padding: 3rem 1.5rem; text-align: center; }
.empty-state .es-mark {
  width: 46px; height: 46px;
  margin: 0 auto 0.9rem;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  display: grid; place-items: center;
}
.empty-state h3 { font-size: 1rem; margin-bottom: 0.35rem; }
.empty-state p { color: var(--muted); max-width: 24rem; margin: 0 auto 1.1rem; font-size: 0.875rem; }

/* ---- Party colour chip ---------------------------------------------- */

.party-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 550;
}
.party-chip .dot {
  width: 9px; height: 9px;
  border-radius: 3px;
  flex: 0 0 auto;
}

/* ==========================================================================
   Document editor
   ========================================================================== */

.editor-shell { display: flex; gap: 0; height: calc(100vh - 57px); overflow: hidden; }

.editor-side {
  width: 288px;
  flex: 0 0 288px;
  background: var(--surface);
  border-right: 1px solid var(--rule);
  overflow-y: auto;
  padding: 1.15rem;
}
.editor-side h4 {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 1.35rem 0 0.6rem;
}
.editor-side h4:first-child { margin-top: 0; }

.editor-stage {
  flex: 1 1 auto;
  overflow: auto;
  padding: 1.75rem 1rem 4rem;
  background: var(--canvas);
}

.editor-props {
  width: 264px;
  flex: 0 0 264px;
  background: var(--surface);
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  padding: 1.15rem;
}

/* Palette */
.tool-btn {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.3rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: grab;
  text-align: left;
}
.tool-btn:hover { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-dark); }
.tool-btn:active { cursor: grabbing; }
.tool-btn .ico { width: 15px; flex: 0 0 15px; opacity: 0.75; }

/* Party selector */
.party-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.45rem 0.6rem;
  margin-bottom: 0.25rem;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 0.8125rem;
  text-align: left;
  cursor: pointer;
}
.party-pick.active { border-color: currentColor; font-weight: 600; }
.party-pick .swatch { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.party-pick .who { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.party-pick .n { font-size: 0.72rem; color: var(--muted); }

/* Page canvas */
.pdf-page-wrap {
  position: relative;
  margin: 0 auto 1.5rem;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.pdf-page-wrap canvas { display: block; border-radius: 3px; }
.pdf-page-label {
  position: absolute;
  top: -1.35rem; left: 0;
  font-size: 0.7rem;
  color: var(--faint);
  font-weight: 500;
}
.field-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border-radius: 3px;
}

/* Placed field */
.pf {
  position: absolute;
  border: 1.5px solid;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.42);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-size: 0.72rem;
  font-weight: 550;
  user-select: none;
  min-width: 18px;
  min-height: 14px;
}
/* The preview sits exactly where the PDF will draw the value: 1pt of left
   padding, vertically centred in the box, at the field's own point size. */
.pf .pf-preview {
  position: absolute;
  left: 1px; right: 1px;
  top: 50%;
  transform: translateY(-50%);
  padding: 0;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  color: #334155;
  font-weight: 400;
  pointer-events: none;
}
.pf .pf-preview.is-sig {
  font-family: "Brush Script MT", "Segoe Script", cursive;
  color: #1e293b;
}
.pf .pf-tick { text-align: center; color: #0f172a; }

/* Name tag on the corner, so a field is still identifiable once the preview
   fills the box. Sits outside the box to avoid covering the document. */
.pf .pf-tag {
  position: absolute;
  top: -0.95rem; left: -1.5px;
  font-size: 0.6rem;
  font-weight: 600;
  line-height: 1;
  color: #fff;
  padding: 0.15rem 0.3rem;
  border-radius: 3px 3px 0 0;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  opacity: 0.9;
}
.pf.selected .pf-tag { opacity: 1; }

body.hide-previews .pf .pf-preview { display: none; }

.pf .pf-label {
  padding: 0 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.pf.selected { outline: 2px solid var(--brand); outline-offset: 1px; z-index: 5; }
.pf.required::after {
  content: "";
  position: absolute;
  top: 2px; right: 2px;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: currentColor;
}
.pf .pf-handle {
  position: absolute;
  right: -4px; bottom: -4px;
  width: 10px; height: 10px;
  border-radius: 2px;
  background: var(--surface);
  border: 1.5px solid var(--brand);
  cursor: nwse-resize;
  display: none;
}
.pf.selected .pf-handle { display: block; }
.pf.ghost { opacity: 0.45; pointer-events: none; }

.editor-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.save-state { font-size: 0.8125rem; color: var(--muted); }
.save-state.saving { color: var(--brand-dark); }
.save-state.error  { color: #b91c1c; font-weight: 550; }

/* ==========================================================================
   Signing surface
   ========================================================================== */

.sign-topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  padding: 0.7rem 0;
  position: sticky;
  top: 0;
  z-index: 30;
}
.sign-doc-title { font-weight: 600; font-size: 0.95rem; }
.sign-from { font-size: 0.8125rem; color: var(--muted); }

.sign-progress {
  height: 4px;
  background: var(--rule-soft);
  border-radius: 999px;
  overflow: hidden;
  min-width: 110px;
}
.sign-progress .bar {
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.sign-stage { padding: 1.5rem 0 6rem; }

/* Interactive fields on the signing page */
.sf {
  position: absolute;
  border: 1.5px solid var(--brand);
  border-radius: 3px;
  background: rgba(13, 148, 136, 0.07);
  cursor: pointer;
  display: flex;
  align-items: center;
  overflow: hidden;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}
.sf:hover { background: rgba(13, 148, 136, 0.14); }
.sf.is-filled { background: rgba(255, 255, 255, 0.35); border-color: var(--brand-border); }
.sf.is-invalid { border-color: #dc2626; background: rgba(220, 38, 38, 0.08); }
.sf.is-current { box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.25); }
.sf.other-party {
  border-style: dashed;
  border-color: var(--rule);
  background: rgba(148, 163, 184, 0.07);
  cursor: not-allowed;
}
.sf-hint {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--brand-dark);
  padding: 0 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.sf-value {
  padding: 0 0.25rem;
  width: 100%;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  line-height: 1.15;
}
.sf-value.is-sig { font-family: "Brush Script MT", "Segoe Script", cursive; }
.sf-value img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }

.sign-actionbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  padding: 0.75rem 0;
  z-index: 40;
}

/* Signature capture */
.sig-pad-wrap {
  border: 1px dashed var(--rule);
  border-radius: var(--radius-sm);
  background: #fcfdfe;
  position: relative;
}
.sig-pad-wrap canvas { display: block; width: 100%; height: 190px; touch-action: none; cursor: crosshair; }
.sig-pad-wrap .baseline {
  position: absolute;
  left: 8%; right: 8%; bottom: 34%;
  border-bottom: 1px solid var(--rule);
  pointer-events: none;
}
.sig-pad-wrap .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--faint);
  font-size: 0.8125rem;
  pointer-events: none;
}

.sig-font-option {
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  background: var(--surface);
  font-size: 1.35rem;
  line-height: 1.5;
  min-height: 3.1rem;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
}
.sig-font-option.active { border-color: var(--brand); background: var(--brand-soft); }
.sig-font-1 { font-family: "Brush Script MT", "Segoe Script", cursive; }
.sig-font-2 { font-family: "Snell Roundhand", "Apple Chancery", "Palatino Linotype", cursive; font-style: italic; }
.sig-font-3 { font-family: Georgia, "Times New Roman", serif; font-style: italic; }
.sig-font-4 { font-family: "Bradley Hand", "Comic Sans MS", cursive; }

/* ---- Audit trail ----------------------------------------------------- */

.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-list li {
  display: flex;
  gap: 0.85rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.8125rem;
}
.audit-list li:last-child { border-bottom: 0; }
.audit-list .when {
  flex: 0 0 148px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}
.audit-list .what { flex: 1 1 auto; color: var(--ink); }
.audit-list .who { color: var(--muted); }

.chain-ok, .chain-bad {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
}
.chain-ok  { color: var(--brand-dark); }
.chain-bad { color: #b91c1c; }

/* ---- Utility --------------------------------------------------------- */

.hairline { border: 0; border-top: 1px solid var(--rule); margin: 1.25rem 0; }
.text-muted-sm { font-size: 0.8125rem; color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.78rem; }
.break-all { word-break: break-all; }

/* ---- Responsive ------------------------------------------------------ */

@media (max-width: 991.98px) {
  .editor-shell { flex-direction: column; height: auto; overflow: visible; }
  .editor-side, .editor-props {
    width: 100%; flex: 1 1 auto;
    border: 0; border-bottom: 1px solid var(--rule);
  }
  .editor-stage { padding: 1rem 0.5rem 3rem; }
}

@media (max-width: 575.98px) {
  .audit-list li { flex-direction: column; gap: 0.15rem; }
  .audit-list .when { flex: 1 1 auto; }
  .stat-card .stat-value { font-size: 1.5rem; }
}

/* Respect the user's motion preference — non-negotiable. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* Keyboard focus must always be visible, including on our custom controls. */
.tool-btn:focus-visible,
.party-pick:focus-visible,
.pf:focus-visible,
.sf:focus-visible,
.sig-font-option:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media print {
  .app-nav, .sign-actionbar, .editor-side, .editor-props, .no-print { display: none !important; }
  body { background: #fff; }
  .app-card { border: 0; }
}
