@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary: #1E3A5F;
  --surface: #FFFFFF;
  --background: #F8FAFC;
  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  --text-primary: #1E293B;
  --text-muted: #64748B;
  --border: #E2E8F0;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--background);
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo svg {
  width: 28px;
  height: 28px;
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 150ms ease;
  border: none;
  text-decoration: none;
}

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

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

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--background);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #DC2626;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

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

/* Main layout */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* Dashboard */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.dashboard-title {
  font-size: 24px;
  font-weight: 700;
}

/* Filter tabs */
.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  padding: 4px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 24px;
}

.filter-tab {
  padding: 6px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms ease;
  background: none;
  border: none;
}

.filter-tab:hover {
  color: var(--text-primary);
}

.filter-tab.active {
  background: var(--primary);
  color: white;
}

/* Document grid */
.doc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  transition: all 150ms ease;
}

.doc-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--accent);
}

.doc-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.doc-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.doc-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.doc-card-actions {
  display: flex;
  gap: 8px;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-draft {
  background: #F1F5F9;
  color: #64748B;
}

.badge-sent {
  background: #DBEAFE;
  color: #1D4ED8;
}

.badge-completed {
  background: #D1FAE5;
  color: #059669;
}

.badge-pending {
  background: #FEF3C7;
  color: #D97706;
}

.badge-viewed {
  background: #E0E7FF;
  color: #4338CA;
}

.badge-signed {
  background: #D1FAE5;
  color: #059669;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.empty-state-icon {
  font-size: 64px;
  margin-bottom: 16px;
  opacity: 0.6;
}

.empty-state-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state-text {
  color: var(--text-muted);
  margin-bottom: 24px;
  max-width: 320px;
}

/* Two-column editor layout */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 24px;
  align-items: start;
}

.editor-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 500px;
}

.editor-sidebar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: sticky;
  top: 80px;
}

/* Step indicator */
.step-indicator {
  display: flex;
  gap: 0;
  margin-bottom: 0;
}

.step {
  flex: 1;
  text-align: center;
  padding: 12px 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--background);
  border-bottom: 2px solid var(--border);
}

.step.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.step.completed {
  color: var(--success);
  border-bottom-color: var(--success);
}

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 150ms ease;
  margin: 16px;
  position: relative;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent);
  background: #F0F7FF;
}

.upload-zone-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.upload-zone-text {
  color: var(--text-muted);
  font-size: 13px;
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Field palette */
.field-palette {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--background);
  flex-wrap: wrap;
  position: sticky;
  bottom: 0;
  align-items: center;
}

.field-palette-label {
  width: 100%;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field-palette .field-btn {
  flex: 1;
  min-width: 70px;
  max-width: 100px;
}

.field-palette > span:last-child {
  flex: 1 1 100%;
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
}

.field-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 150ms ease;
  flex-shrink: 0;
}

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

.field-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.field-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* PDF canvas container */
.pdf-container {
  position: relative;
  background: #525659;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  overflow: auto;
}

.pdf-canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow-lg);
  margin-bottom: 16px;
  background: white;
  display: inline-block;
}

#pdf-canvas-wrapper {
  position: relative;
}

#pdf-canvas {
  display: block;
  background: white;
  max-width: 100%;
}

#fields-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#fields-container > * {
  pointer-events: auto;
}

.pdf-page-number {
  position: absolute;
  bottom: -24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #9CA3AF;
}

/* Page navigation */
.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
  padding: 8px;
  background: var(--surface);
  border-radius: var(--radius);
}

.page-nav button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#page-num {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 80px;
  text-align: center;
}

/* Placed field overlays */
.field-overlay {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(59, 130, 246, 0.1);
  cursor: move;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  color: var(--accent);
  user-select: none;
  z-index: 10;
  border-radius: 4px;
  min-width: 30px;
  min-height: 20px;
}

.field-overlay.selected {
  border-color: var(--primary);
  background: rgba(30, 41, 59, 0.1);
  z-index: 20;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.3);
}

.field-overlay .field-label {
  pointer-events: none;
  text-transform: capitalize;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.field-overlay.dragging {
  opacity: 0.7;
  cursor: grabbing !important;
  z-index: 100;
}

.drag-handle {
  position: absolute;
  top: 2px;
  right: 2px;
  cursor: grab;
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  opacity: 0.6;
  transition: opacity 0.15s;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 3px;
  z-index: 5;
}

.field-overlay:hover .drag-handle,
.field-overlay.selected .drag-handle {
  opacity: 1;
}

.drag-handle:hover {
  color: var(--primary);
  background: white;
}

.drag-handle:active {
  cursor: grabbing;
}

.field-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: var(--accent);
  border: 1px solid white;
  border-radius: 2px;
}

.field-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.field-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.field-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.field-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* Drag tooltip */
.drag-tooltip {
  position: fixed;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  pointer-events: none;
  z-index: 10000;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Signer list */
.signer-list {
  padding: 16px;
}

.signer-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  background: var(--background);
}

.signer-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.signer-avatar.color-1 { background: #3B82F6; }
.signer-avatar.color-2 { background: #10B981; }
.signer-avatar.color-3 { background: #F59E0B; }
.signer-avatar.color-4 { background: #EF4444; }
.signer-avatar.color-5 { background: #8B5CF6; }
.signer-avatar.color-6 { background: #EC4899; }
.signer-avatar.color-7 { background: #06B6D4; }
.signer-avatar.color-8 { background: #84CC16; }

.signer-info {
  flex: 1;
  min-width: 0;
}

.signer-name {
  font-weight: 500;
  font-size: 13px;
}

.signer-email {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar sections */
.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.sidebar-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Form elements */
.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 150ms ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
}

.form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
}

/* Trust badges */
.trust-badges {
  display: flex;
  gap: 12px;
  justify-content: center;
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px;
  flex-wrap: wrap;
}

/* Signing page */
.signing-page {
  min-height: 100vh;
  background: var(--background);
  display: flex;
  flex-direction: column;
}

.signing-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.signing-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
}

.signing-doc-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 4px;
}

.signing-for {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.signing-pdf-container {
  background: #525659;
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 900px;
  width: 100%;
}

/* Signing field inputs */
.signing-field-overlay {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px dashed var(--accent);
  background: rgba(59, 130, 246, 0.05);
  transition: all 150ms ease;
  border-radius: 4px;
  overflow: hidden;
}

.signing-field-overlay:hover {
  background: rgba(59, 130, 246, 0.1);
  border-style: solid;
}

.signing-field-overlay.selected {
  border-color: var(--primary);
  background: rgba(30, 41, 59, 0.1);
  border-style: solid;
}

.signing-field-overlay.signature canvas,
.signing-field-overlay.initials canvas {
  cursor: crosshair;
}

.signing-field-overlay .field-placeholder {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  pointer-events: none;
}

.signing-field-overlay.selected .field-placeholder {
  color: var(--primary);
}

/* Signing fields container */
#signing-fields-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#signing-fields-container > * {
  pointer-events: auto;
}

/* Signature canvas */
.signature-canvas {
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  cursor: crosshair;
  touch-action: none;
  width: 100%;
  height: 100%;
}

.signature-canvas:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.signing-canvas-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  height: 100%;
}

.signing-canvas-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Status page */
.status-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 24px;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.status-title {
  font-size: 24px;
  font-weight: 700;
}

.signer-progress-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}

.signer-progress-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.signer-progress-item:last-child {
  border-bottom: none;
}

.signer-progress-info {
  flex: 1;
}

.signer-progress-name {
  font-weight: 600;
  font-size: 15px;
}

.signer-progress-email {
  font-size: 13px;
  color: var(--text-muted);
}

.signer-progress-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Audit trail */
.audit-trail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.audit-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.audit-item {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.audit-item:last-child {
  border-bottom: none;
}

.audit-time {
  color: var(--text-muted);
  white-space: nowrap;
  width: 140px;
}

.audit-event {
  color: var(--text-primary);
}

.audit-actor {
  color: var(--accent);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 200ms ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  max-width: 480px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform 200ms ease;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-body {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--primary);
  color: white;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 200ms ease forwards;
  pointer-events: auto;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.toast.exiting {
  animation: slideOut 200ms ease forwards;
}

/* Utility */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.justify-between { justify-content: space-between; }

/* Responsive */
@media (max-width: 1024px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .editor-sidebar {
    max-width: 100%;
  }

  .signing-pdf-container {
    max-width: 100%;
    padding: 16px;
  }
}

@media (max-width: 768px) {
  .main {
    padding: 16px;
  }

  .dashboard-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .header-nav .btn span {
    display: none;
  }

  .header {
    padding: 0 16px;
  }

  .doc-grid {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
    justify-content: center;
  }

  .filter-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .filter-tab {
    white-space: nowrap;
  }

  .signing-header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }

  .signing-content {
    padding: 16px;
  }

  .modal {
    width: 95%;
    padding: 16px;
  }

  .modal-actions {
    flex-direction: column;
  }

  .modal-actions .btn {
    width: 100%;
  }

  .toast-container {
    left: 16px;
    right: 16px;
    bottom: 16px;
  }

  .pdf-container {
    padding: 8px;
  }

  .signer-item {
    flex-wrap: wrap;
  }

  .status-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
}

/* ── Signing field states ── */
.signing-field-overlay {
  border: 2px dashed #3B82F6 !important;
  background: rgba(59,130,246,0.05) !important;
  transition: all 0.2s ease;
}
.signing-field-overlay:hover { box-shadow: 0 0 0 3px rgba(59,130,246,0.2); }
.signing-field-overlay.field-focused { box-shadow: 0 0 0 3px rgba(59,130,246,0.3) !important; }
.signing-field-overlay.field-filled { border: 2px solid #10B981 !important; background: rgba(16,185,129,0.08) !important; }
.signing-field-overlay.field-error { border: 2px solid #EF4444 !important; background: rgba(239,68,68,0.08) !important; }
