/* ==========================================================================
   Clean Minimalist Document-First E-Sign Interface
   ========================================================================== */

:root {
  --font-family: 'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bg-app: #edf0f5;
  --bg-surface: #ffffff;
  --border-color: #d1d5db;
  --text-main: #111827;
  --text-muted: #4b5563;
  --text-dim: #9ca3af;
  --brand-blue: #2563eb;
  --brand-blue-hover: #1d4ed8;
  --success-green: #16a34a;
  --success-bg: #ecfdf5;
  --pending-amber: #d97706;
  --pending-bg: #fffbeb;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header App Bar */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 56px;
  background: var(--bg-surface);
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.doc-heading {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  transition: all 200ms ease;
}

.status-pill.pending {
  background: var(--pending-bg);
  color: var(--pending-amber);
  border: 1px solid #fde68a;
}

.status-pill.signed {
  background: var(--success-bg);
  color: var(--success-green);
  border: 1px solid #bbf7d0;
}

.pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

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

/* Buttons */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-blue);
  color: #ffffff;
  border: 1px solid var(--brand-blue);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 120ms ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-blue-hover);
  border-color: var(--brand-blue-hover);
}

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

.btn-success {
  background: var(--success-green);
  border-color: var(--success-green);
}

.btn-success:hover {
  background: #15803d;
  border-color: #15803d;
}

.btn-secondary {
  background: #ffffff;
  border: 1px solid #d1d5db;
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary:hover {
  background: #f9fafb;
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.btn-ghost:hover {
  background: #f3f4f6;
  color: var(--text-main);
}

.btn-ghost-sm {
  background: transparent;
  border: 1px solid #d1d5db;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}

.btn-ghost-sm:hover {
  background: #f3f4f6;
  color: var(--text-main);
}

/* Document Viewport */
.document-container {
  flex: 1;
  overflow-y: auto;
  padding: 36px 16px 80px 16px;
  display: flex;
  justify-content: center;
}

.pages-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
  max-width: 820px;
  width: 100%;
}

.doc-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--brand-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Each Page Card */
.page-sheet {
  position: relative;
  background: #ffffff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  border-radius: 2px;
  line-height: 0;
}

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

/* Signature Box Target on Page 3 */
.signature-target-overlay {
  position: absolute;
  border: 2px dashed #f59e0b;
  background: rgba(245, 158, 11, 0.08);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: all 140ms ease;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.15);
}

.signature-target-overlay:hover {
  background: rgba(245, 158, 11, 0.16);
  border-color: #d97706;
  transform: translateY(-1px);
}

.signature-target-overlay.filled {
  border: 1.5px solid #16a34a;
  background: rgba(22, 163, 74, 0.04);
  box-shadow: none;
  cursor: default;
}

.sig-prompt-text {
  font-size: 11px;
  font-weight: 600;
  color: #b45309;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 5px;
}

.signature-target-overlay.filled .sig-prompt-text {
  display: none;
}

.sig-applied-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

/* Date Stamp Target on Page 3 */
.date-target-overlay {
  position: absolute;
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: #111827;
  pointer-events: none;
  z-index: 10;
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(17, 24, 39, 0.5);
  backdrop-filter: blur(2px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.signature-modal-card {
  background: #ffffff;
  border-radius: 8px;
  width: 100%;
  max-width: 490px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 20px;
  color: var(--text-dim);
  cursor: pointer;
}

.modal-tabs {
  display: flex;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.tab-link {
  flex: 1;
  padding: 9px 0;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.tab-link.active {
  color: var(--brand-blue);
  border-bottom-color: var(--brand-blue);
  background: #ffffff;
}

.modal-body {
  padding: 18px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.canvas-box {
  position: relative;
  border: 1.5px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  height: 160px;
  width: 100%;
}

#sigCanvas {
  display: block;
  width: 100%;
  height: 160px;
  touch-action: none;
}

.canvas-line {
  position: absolute;
  bottom: 30px;
  left: 16px;
  right: 16px;
  height: 1px;
  border-bottom: 1px dashed #cbd5e1;
  pointer-events: none;
}

.canvas-hint {
  position: absolute;
  bottom: 10px;
  left: 16px;
  font-size: 10px;
  color: #9ca3af;
  pointer-events: none;
}

.modal-actions-bar {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

.dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 6px;
  padding: 28px;
  text-align: center;
  background: #f9fafb;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.dropzone:hover {
  border-color: var(--brand-blue);
  background: #eff6ff;
}

.text-sub {
  font-size: 11px;
  color: var(--text-dim);
}

.upload-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.upload-preview img {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
}

.modal-footer {
  padding: 12px 18px;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Live Sync Notification Toast */
.sync-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #ffffff;
  padding: 12px 20px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
  z-index: 999;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 200ms ease-out;
}

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

/* Utilities */
.hidden { display: none !important; }

/* ==========================================================================
   Access Code Gate (DocuSign Style Security Screen)
   ========================================================================== */

.access-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 250ms ease, visibility 250ms ease;
}

.access-gate-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.access-gate-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border-radius: 12px;
  padding: 32px 28px 24px;
  border: 1px solid #e2e8f0;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
  animation: modalScaleIn 180ms ease-out;
}

.gate-icon-badge {
  width: 46px;
  height: 46px;
  background: #eff6ff;
  color: #2563eb;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
}

.gate-kicker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #64748b;
  margin-bottom: 6px;
}

.gate-title {
  font-size: 20px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 8px;
}

.gate-desc {
  font-size: 13.5px;
  color: #475569;
  line-height: 1.55;
  margin-bottom: 22px;
}

.gate-form {
  margin-bottom: 16px;
}

.code-input-wrapper {
  display: flex;
  gap: 8px;
}

.access-code-input {
  flex: 1;
  height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #0f172a;
  background: #f8fafc;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  outline: none;
  transition: all 140ms ease;
}

.access-code-input:focus {
  background: #ffffff;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.access-code-input.input-error {
  border-color: #ef4444;
  background: #fef2f2;
  animation: shake 280ms ease-in-out;
}

.gate-error-msg {
  color: #dc2626;
  font-size: 12.5px;
  font-weight: 500;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.gate-footer {
  padding-top: 14px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-badge {
  font-size: 11.5px;
  font-weight: 500;
  color: #94a3b8;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}
