/* ═══════════════════════════════════════════
   Document Signing — style.css
   ═══════════════════════════════════════════ */

/* ── Reset ── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --error: #ef4444;
  --error-light: #fef2f2;
  --text: #111827;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --bg: #f8fafc;
  --card: #ffffff;
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.04);
  --sticky-height: 60px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
}

/* ── Pages ── */
.page {
  width: 100%;
  max-width: 480px;
  padding: 20px;
  animation: fadeUp 0.4s ease;
}

.page.hidden { display: none; }

.page-full {
  max-width: 100%;
  padding: 0;
  animation: none;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.card-narrow { text-align: center; }

h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 8px;
}

.desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 28px;
}

/* ── Progress Dots ── */
.progress-dots {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  margin-bottom: 28px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s, box-shadow 0.3s;
}

.dot.active {
  background: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

.dot.done {
  background: var(--success);
  box-shadow: 0 0 0 4px var(--success-light);
}

.dot-line {
  width: 48px;
  height: 2px;
  background: var(--border);
  margin: 0 6px;
  transition: background 0.3s;
}

.dot-line.done {
  background: var(--success);
}

/* ── Icon wraps ── */
.icon-wrap {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.icon-error {
  background: var(--error-light);
  color: var(--error);
}

/* ══════════════════════════════════════
   STICKY BAR — read document top bar
   ══════════════════════════════════════ */

.sticky-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.04);
}

.sticky-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  max-width: 900px;
  margin: 0 auto;
}

.sticky-bar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 24px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
}

.sticky-bar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.sticky-bar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.scroll-hint {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  animation: bounceHint 2s ease infinite;
}

.scroll-hint.hidden { display: none; }

@keyframes bounceHint {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

/* Read progress bar */
.read-progress {
  height: 3px;
  background: var(--border);
}

.read-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.15s ease;
}

.read-progress-fill.complete {
  background: var(--success);
}

/* ══════════════════════════════════════
   PDF VIEWER
   ══════════════════════════════════════ */

.pdf-viewer {
  margin-top: calc(var(--sticky-height) + 3px);
  padding: 20px;
  padding-bottom: 40px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.pdf-pages {
  max-width: 850px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pdf-page-wrapper {
  background: var(--card);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  line-height: 0;
}

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

.pdf-page-number {
  text-align: center;
  padding: 8px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: #f9fafb;
  line-height: 1;
}

/* ── Loading spinner (large, for loading page) ── */
.spinner-large {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 20px;
}

/* ── Canvas ── */
.canvas-area {
  position: relative;
  margin-bottom: 24px;
}

canvas#signatureCanvas {
  display: block;
  width: 100%;
  height: 200px;
  background: #fafbfc;
  border: 2px dashed var(--border);
  border-radius: 12px;
  touch-action: none;
  cursor: crosshair;
  transition: border-color 0.25s, background 0.25s, box-shadow 0.25s;
}

canvas#signatureCanvas.active {
  border-color: var(--primary);
  border-style: solid;
  background: #fff;
  box-shadow: 0 0 0 4px var(--primary-light);
}

.canvas-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: #c9cdd5;
  font-size: 13px;
  font-weight: 500;
  pointer-events: none;
  transition: opacity 0.3s;
}

.canvas-hint.hidden { opacity: 0; }

.canvas-baseline {
  position: absolute;
  bottom: 40px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: #e8eaef;
  pointer-events: none;
  opacity: 0.6;
}

/* ── Buttons ── */
.btn-row {
  display: flex;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 22px;
  border: none;
  border-radius: 11px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
  outline: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 3px var(--primary-light);
}

.btn-primary {
  flex: 1;
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-sm {
  flex: none;
  padding: 8px 18px;
  font-size: 13px;
  border-radius: 8px;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 13px 16px;
}

.btn-ghost:hover:not(:disabled) { background: #f3f4f6; }

.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Spinner ── */
.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner.visible { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Success ── */
.card-success .desc { margin-bottom: 0; }

.checkmark-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--success-light);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 24px;
  animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 100;
  animation: slideUp 0.3s ease;
  max-width: calc(100% - 40px);
}

.toast.hidden { display: none; }

.toast.toast-error { background: #991b1b; }

@keyframes slideUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .card { padding: 24px 20px; }
  h1 { font-size: 19px; }
  canvas#signatureCanvas { height: 170px; }
  .sticky-bar-inner { padding: 10px 14px; }
  .sticky-bar-title { font-size: 13px; }
  .pdf-viewer { padding: 12px; }
}

@media (min-height: 800px) {
  canvas#signatureCanvas { height: 240px; }
}

/* ── Body override when reading (no centering) ── */
body.reading-mode {
  align-items: stretch;
  justify-content: flex-start;
}
