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

:root {
  --primary: #1c72a1;
  --primary-hover:rgba(28, 114, 161, 0.47);
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #f59e0b;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px 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;

   /* Font Family */
   --mrfm: "Montserrat-Regular";
   --mmfm: "Montserrat-Medium";
   --mifm: "Montserrat-Italic";
   --mbfm: "Montserrat-Bold";
   --msbfm: "Montserrat-SemiBold";
   --mebfm: "Montserrat-ExtraBold";
   --srfm: "Sansation_Regular";
   --slfm: "Sansation_Light";
   --sifm: "Sansation_Italic";
   --sbfm: "Sansation_Bold";
   --sbifm: "Sansation_Bold_Italic";
   --prfm: "Poppins-Regular";
   --pmfm: "Poppins-Medium";
   /* --pblcfm: "Poppins-Black"; */
   /* --pblcifm: "Poppins-BlackItalic"; */
   --pbfm: "Poppins-Bold";
   --pbifm: "Poppins-BoldItalic";
   --pbebfm: "Poppins-ExtraBold";
 
 
   /* Font Sizes */
   --hfs: 1rem;
   --shfs: 0.875rem;
   --tfs: 0.75rem;
}

body {
  /* font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; */
  font-family: var(--pmfm);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }

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

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

.navbar-brand svg { width: 28px; height: 28px; }

.navbar-actions { display: flex; gap: 12px; align-items: center; }

/* ─── BUTTONS ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

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

/* ─── LAYOUT ───────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 16px;
}

.card-body { padding: 20px; }

/* ─── FORMS ────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

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

.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

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

.dashboard-header h1 { font-size: 24px; }

.doc-table { width: 100%; border-collapse: collapse; }
.doc-table th, .doc-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.doc-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.doc-table tr:hover td { background: #f8fafc; }

.action-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}
.action-overflow { position: relative; display: inline-block; }
.action-kebab {
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
}
.action-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  min-width: 140px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius, 6px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  padding: 4px;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
.action-menu[hidden] { display: none; }
.action-menu-item {
  display: block;
  padding: 8px 12px;
  font-size: 13px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text, #0f172a);
  text-decoration: none;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
}
.action-menu-item:hover { background: #f1f5f9; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-draft { background: #e2e8f0; color: #475569; }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-completed { background: #dcfce7; color: #16a34a; }
.badge-pending { background: #fef3c7; color: #d97706; }
.badge-signed { background: #dcfce7; color: #16a34a; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* ─── PREPARE PAGE ─────────────────────────────────── */
.prepare-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  height: calc(100vh - 56px);
}

.prepare-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px;
}

.prepare-main {
  overflow-y: auto;
  padding: 20px;
  position: relative;
}

.sidebar-section { margin-bottom: 24px; }
.sidebar-section h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.recipient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  font-size: 13px;
}

.recipient-color {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.recipient-info { flex: 1; margin: 0 8px; overflow: hidden; }
.recipient-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recipient-email { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.field-types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.field-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: grab;
  font-size: 11px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.field-type-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #eff6ff;
}

.field-type-btn svg { width: 24px; height: 24px; }

/* ─── PDF VIEWER ───────────────────────────────────── */
.pdf-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.pdf-page-wrapper {
  position: relative;
  box-shadow: var(--shadow-lg);
  background: white;
}

.pdf-page-wrapper canvas { display: block; }

.fields-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.placed-field {
  position: absolute;
  border: 2px solid;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  cursor: move;
  user-select: none;
  background: rgba(255, 255, 255, 0.85);
}

.placed-field .field-label {
  pointer-events: none;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 4px;
}

.placed-field .field-delete {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: white;
  border: none;
  font-size: 10px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.placed-field:hover .field-delete { display: flex; }

/* Field resize handle */
.placed-field .field-resize {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  background: var(--primary);
  border-radius: 2px;
  cursor: nwse-resize;
  display: none;
}

.placed-field:hover .field-resize { display: block; }

/* ─── SIGNING PAGE ─────────────────────────────────── */
.sign-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.sign-header-info h2 { font-size: 16px; }
.sign-header-info p { font-size: 13px; color: var(--text-muted); }

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

.progress-bar {
  width: 120px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

.sign-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  gap: 16px;
}

.sign-field {
  position: absolute;
  border: 2px dashed var(--primary);
  border-radius: 4px;
  background: rgba(37, 99, 235, 0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--primary);
  transition: all 0.15s;
}

.sign-field:hover {
  background: rgba(37, 99, 235, 0.1);
  border-style: solid;
}

.sign-field.completed {
  border-color: var(--success);
  border-style: solid;
  background: rgba(22, 163, 74, 0.05);
  color: var(--success);
  cursor: default;
}

.sign-field.completed img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ─── SIGNATURE MODAL ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  overflow: hidden;
}

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

.modal-header h3 { font-size: 18px; }

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}
.modal-close:hover { background: var(--bg); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* Tabs */
.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

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

/* Draw tab */
.signature-canvas-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}

#signatureCanvas {
  width: 100%;
  height: 200px;
  cursor: crosshair;
  display: block;
}

.canvas-clear {
  position: absolute;
  top: 8px;
  right: 8px;
}

/* Type tab */
.signature-type-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 12px;
  background: #fafafa;
}

.signature-type-preview span {
  font-size: 36px;
  color: #1a1a2e;
}

.font-options { display: flex; gap: 8px; margin-top: 12px; }

.font-option {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  text-align: center;
  font-size: 18px;
}

.font-option.active {
  border-color: var(--primary);
  background: #eff6ff;
}

.font-option[data-font="cursive"] { font-family: 'Brush Script MT', 'Dancing Script', cursive; }
.font-option[data-font="serif"] { font-family: 'Georgia', serif; font-style: italic; }
.font-option[data-font="script"] { font-family: 'Lucida Handwriting', 'Comic Sans MS', cursive; }

/* Upload tab */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.upload-zone:hover {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-zone input { display: none; }

.upload-preview {
  margin-top: 12px;
  text-align: center;
}

.upload-preview img {
  max-width: 100%;
  max-height: 150px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ─── COMPLETION PAGE ──────────────────────────────── */
.completion-card {
  max-width: 480px;
  margin: 60px auto;
  text-align: center;
  padding: 40px;
}

.completion-icon {
  width: 64px;
  height: 64px;
  background: #dcfce7;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.completion-icon svg { width: 32px; height: 32px; color: var(--success); }

.completion-card h2 { margin-bottom: 8px; }
.completion-card p { color: var(--text-muted); margin-bottom: 24px; }

/* ─── SEND MODAL ───────────────────────────────────── */
.link-list { list-style: none; }
.link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.link-item-info { flex: 1; }
.link-item-info strong { display: block; font-size: 14px; }
.link-item-info small { color: var(--text-muted); }

.link-copy-btn { white-space: nowrap; }

/* ─── PAGE LABEL ───────────────────────────────────── */
.page-label {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: -8px;
}

/* ─── TOAST ────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: slideIn 0.3s ease;
}

.toast-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.toast-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.toast-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

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

/* ─── RECIPIENT COLORS ─────────────────────────────── */
.color-0 { --rc: #2563eb; }
.color-1 { --rc: #dc2626; }
.color-2 { --rc: #16a34a; }
.color-3 { --rc: #9333ea; }
.color-4 { --rc: #ea580c; }

/* ─── RESPONSIVE ───────────────────────────────────── */
@media (max-width: 768px) {
  .prepare-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .prepare-sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}

/* Loading spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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