:root {
  --bg: #f8f6f1;
  --surface: #ffffff;
  --surface-muted: #f2eee6;
  --surface-glass: rgba(255, 255, 255, 0.84);
  --border: #e6e0d4;
  --border-strong: #d5cdc0;
  --text: #14161a;
  --text-muted: #5b6370;
  --accent: #b85d2b;
  --accent-hover: #9f4d20;
  --accent-soft: rgba(184, 93, 43, 0.11);
  --ok-bg: #eaf7ef;
  --ok-fg: #156e39;
  --ok-border: #a5dbb9;
  --obs-bg: #eef2ff;
  --obs-fg: #2b3f8f;
  --obs-border: #c7d2fe;
  --err-bg: #fdf0f0;
  --err-fg: #9f2426;
  --err-border: #eab3b4;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-card: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px rgba(16, 24, 40, 0.04);
  --radius: 16px;
  --radius-sm: 10px;
  --mono: "SF Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12;
    --surface: #15181e;
    --surface-muted: #1e222b;
    --surface-glass: rgba(21, 24, 30, 0.84);
    --border: #272c37;
    --border-strong: #363d4c;
    --text: #f3f5f8;
    --text-muted: #9aa4b4;
    --accent: #dd7e48;
    --accent-hover: #ea915f;
    --accent-soft: rgba(221, 126, 72, 0.16);
    --ok-bg: #10281b;
    --ok-fg: #6ee7a0;
    --ok-border: #1f5437;
    --obs-bg: #161d34;
    --obs-fg: #a5b4fc;
    --obs-border: #2a3663;
    --err-bg: #2c1415;
    --err-fg: #f89d9e;
    --err-border: #5c2729;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 28px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 13px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.brand-mark {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.brand-word { font-weight: 700; }
.brand-sep { color: var(--border-strong); }
.brand-sub { color: var(--text-muted); font-weight: 500; }

.status-pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-muted);
  transition: background 180ms var(--ease), color 180ms var(--ease), border-color 180ms var(--ease);
}

.status-pill.ok {
  background: var(--ok-bg);
  color: var(--ok-fg);
  border-color: var(--ok-border);
}

.shell {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px calc(112px + env(safe-area-inset-bottom));
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 16px;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.banner-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-muted);
}

.banner.observer { background: var(--obs-bg); color: var(--obs-fg); border-color: var(--obs-border); }
.banner.observer .banner-icon { background: rgba(43, 63, 143, 0.14); color: var(--obs-fg); }
.banner.error { background: var(--err-bg); color: var(--err-fg); border-color: var(--err-border); }
.banner.error .banner-icon { background: rgba(159, 36, 38, 0.14); color: var(--err-fg); }
.banner.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: var(--ok-border); }
.banner.ok .banner-icon { background: rgba(21, 110, 57, 0.15); color: var(--ok-fg); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Executive Progress Rail */
.rail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.rail-live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  animation: pulse 1.8s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.progress-rail {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.rail-step {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.rail-step.done {
  border-color: var(--ok-border);
  background: var(--ok-bg);
}

.rail-step.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.rail-dot {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  margin-top: 1px;
}

.rail-step.done .rail-dot {
  background: var(--ok-fg);
  border-color: var(--ok-fg);
  color: #ffffff;
}

.rail-step.active .rail-dot {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.rail-body { min-width: 0; }
.rail-title { font-size: 13px; font-weight: 600; line-height: 1.3; }
.rail-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.rail-step.done .rail-sub { color: var(--ok-fg); }

/* Document Hero */
.doc-eyebrows {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}

.chip.muted {
  background: var(--surface-muted);
  color: var(--text-muted);
}

h1 {
  font-size: clamp(21px, 3vw, 27px);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
  line-height: 1.2;
}

.fingerprint-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.fingerprint-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  transition: border-color 150ms var(--ease);
}

.fingerprint-chip:hover { border-color: var(--border-strong); }
.fp-label { font-weight: 700; font-size: 10px; letter-spacing: 0.06em; color: var(--text-muted); }
.fp-copy { font-size: 11px; font-weight: 600; color: var(--accent); }
.doc-id-pill { font-size: 12px; color: var(--text-muted); }

.mono {
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

/* PDF Stage */
.pdf-stage {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-muted);
}

.pdf-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 13px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 12px;
}

.pdf-toolbar-label { font-weight: 600; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.toolbar-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 140ms var(--ease);
}

.toolbar-btn:hover { background: var(--surface-muted); }

.pdf-pages {
  max-height: 64vh;
  min-height: 320px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--surface-muted);
}

.pdf-loading {
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.pdf-pages > div,
.pdf-modal-body > div {
  flex: 0 0 auto;
}

.pdf-page-sheet {
  flex: 0 0 auto;
  width: 100%;
  max-width: 780px;
  background: #ffffff;
  border-radius: 6px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.pdf-page-sheet canvas {
  display: block;
  width: 100%;
  height: auto;
}

.pdf-page-num {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--mono);
}

/* In-Page Full-Screen Reader Modal */
.pdf-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.pdf-modal-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface-glass);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  border-bottom: 1px solid var(--border);
}

.pdf-modal-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.pdf-modal-meta strong {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pdf-modal-controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-icon-btn {
  appearance: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.pdf-modal-body {
  flex: 1 1 auto;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  background: var(--surface-muted);
}

/* WASM Verification Receipt */
.wasm-receipt {
  margin-top: 16px;
  padding: 15px 16px;
  border-radius: 12px;
  border: 1px solid var(--ok-border);
  background: var(--ok-bg);
  color: var(--text);
}

.wasm-receipt.fail {
  border-color: var(--err-border);
  background: var(--err-bg);
}

.wasm-receipt-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 14px;
  color: var(--ok-fg);
}

.wasm-receipt.fail .wasm-receipt-head { color: var(--err-fg); }

.wasm-checks {
  list-style: none;
  padding: 0;
  margin: 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.wasm-checks li {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 13px;
}

.wasm-checks .chk {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--ok-fg);
}

.wasm-checks .chk.bad { color: var(--err-fg); }

.digest-details {
  font-size: 12px;
  border-top: 1px solid rgba(21, 110, 57, 0.18);
  padding-top: 8px;
}

.digest-details summary { cursor: pointer; font-weight: 600; color: var(--ok-fg); }
.digest-dl { margin: 8px 0 0; display: grid; gap: 6px; }
.digest-dl dt { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; }
.digest-dl dd { margin: 0; font-family: var(--mono); font-size: 11px; word-break: break-all; }

/* Steps */
.step-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 4px 0 6px;
  color: var(--text);
}

.step-copy {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--text-muted);
}

/* 6-Box OTP */
.otp-wrap {
  position: relative;
  width: 100%;
  max-width: 348px;
  margin: 6px 0 4px;
}

.otp-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: text;
  font-size: 24px;
  z-index: 2;
}

.otp-boxes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.otp-box {
  height: 54px;
  border-radius: 12px;
  border: 1.5px solid var(--border-strong);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}

.otp-box.filled {
  border-color: var(--text);
  background: var(--surface);
}

.otp-box.focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ESIGN Disclosure */
details.esign {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  background: var(--bg);
  margin-bottom: 14px;
}

details.esign summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.esign p { font-size: 13px; color: var(--text-muted); margin: 10px 0 0; }

/* Buttons */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  padding: 11px 17px;
  border-radius: 11px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 150ms var(--ease), border-color 150ms var(--ease), transform 120ms var(--ease);
}

.btn:hover { background: var(--surface-muted); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn.ghost:hover { background: var(--surface-muted); color: var(--text); }
.btn.subtle { background: var(--surface-muted); border-color: var(--border); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  min-width: 210px;
}

.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.emerald {
  background: var(--ok-fg);
  border-color: var(--ok-fg);
  color: #ffffff;
}

.btn.emerald:hover { filter: brightness(1.06); }

/* Timeline */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
}

.timeline li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.timeline li:last-child { border-bottom: none; padding-bottom: 0; }
.tl-stage { font-weight: 600; }
.tl-seq { color: var(--text-muted); margin-right: 6px; font-family: var(--mono); font-size: 11px; }

/* Frosted-Glass Sticky Biometric Bar */
.sticky-sign {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--surface-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}

.sticky-sign-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.sticky-meta { display: flex; flex-direction: column; min-width: 0; }
.sticky-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticky-meta .mono { font-size: 11px; color: var(--text-muted); }

.sign-cta {
  padding: 13px 22px;
  font-size: 15px;
  border-radius: 12px;
  min-width: 240px;
}

.sign-icon { display: inline-flex; width: 18px; height: 18px; }
.sign-icon svg { width: 18px; height: 18px; }

.footer-link {
  text-align: center;
  margin-top: 22px;
  font-size: 13px;
}

.footer-link a { color: var(--accent); text-decoration: none; font-weight: 600; }
.footer-link a:hover { text-decoration: underline; }
.how-panel { text-align: left; margin-top: 14px; }

/* DocuSign-style Signature Pad */
.sig-pad-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  overflow: hidden;
}

.sig-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.sig-tab {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 140ms var(--ease), border-color 140ms var(--ease), background 140ms var(--ease);
}

.sig-tab.active {
  color: var(--text);
  background: var(--surface);
  border-bottom-color: var(--accent);
}

.sig-pane { padding: 14px; }

.sig-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.sig-text-input {
  flex: 1 1 220px;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
}

.sig-style-pills { display: flex; gap: 6px; }

.style-pill {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
}

.style-pill.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.sig-canvas-box {
  position: relative;
  background: #ffffff;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
  touch-action: none;
}

.sig-canvas-box.drawable { cursor: crosshair; }

.sig-canvas-box canvas {
  display: block;
  width: 100%;
  height: auto;
}

.sig-baseline {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: 28px;
  border-bottom: 1px dashed #cbd5e1;
  pointer-events: none;
}

.sig-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: 13px;
  pointer-events: none;
}

.sig-pad-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.sig-upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 22px 16px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  margin-bottom: 10px;
}

.sig-upload-drop input { display: none; }
.sig-upload-drop strong { font-size: 14px; color: var(--accent); }
.sig-upload-drop span { font-size: 12px; color: var(--text-muted); }

.hidden { display: none !important; }

@media (max-width: 640px) {
  .card { padding: 16px; border-radius: 14px; }
  .sticky-sign-inner { flex-direction: column; align-items: stretch; gap: 8px; }
  .sticky-meta { display: none; }
  .sign-cta { width: 100%; min-width: 0; }
  .doc-actions .btn { flex: 1 1 100%; }
  .pdf-frame { height: 50vh; min-height: 280px; }
}
