/* =============================================
   Agreement Builder / Editor Styles
   ============================================= */

.editor-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
  margin-top: var(--header-h);
}

/* Left Panel: Toolbox */
.editor-toolbox {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.toolbox-section { padding: var(--space-4); border-bottom: 1px solid var(--border); }
.toolbox-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.field-palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.field-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-2);
  background: var(--gray-50);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  transition: all var(--transition);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}
.field-item:hover { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.field-item:active { cursor: grabbing; }
.field-item-icon { font-size: 1.25rem; }

/* Recipient list in toolbox */
.recipient-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--gray-50);
  border: 2px solid;
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.8125rem;
  font-weight: 600;
}
.recipient-chip.selected { background: var(--primary-bg); }
.recipient-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Center: Document canvas */
.editor-canvas-wrapper {
  flex: 1;
  overflow: auto;
  background: var(--gray-300);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.editor-toolbar {
  width: 816px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3);
  flex-wrap: wrap;
}
.toolbar-btn {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.toolbar-btn:hover { background: var(--gray-100); color: var(--text); }
.toolbar-btn.active { background: var(--primary-bg); color: var(--primary); }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 var(--space-1); }
.toolbar-select {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-2);
  font-size: 0.8125rem;
  background: var(--surface);
  color: var(--text);
}

.document-page {
  width: 816px;
  min-height: 1056px;
  background: #fff;
  box-shadow: 0 4px 32px rgba(0,0,0,.15);
  border-radius: 2px;
  position: relative;
  cursor: text;
  /* page-break line every 1056px (8.5×11 at 96dpi) */
  background-image: linear-gradient(
    to bottom,
    transparent calc(1056px - 1px),
    #cbd5e1 calc(1056px - 1px),
    #cbd5e1 1056px,
    transparent 1056px
  );
  background-size: 100% 1056px;
}
.page-marker {
  z-index: 1;
}
.document-page .page-content {
  padding: 72px 80px;
  min-height: calc(100% - 40px);
  outline: none;
}
.document-page .page-content:focus { outline: none; }

/* Dropped fields on document */
.placed-field {
  position: absolute;
  border: 2px dashed;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: move;
  font-size: 0.75rem;
  font-weight: 600;
  user-select: none;
  transition: box-shadow var(--transition);
  min-width: 120px;
  min-height: 36px;
  overflow: hidden;
}
.placed-field:hover, .placed-field.selected {
  box-shadow: 0 0 0 3px currentColor;
}
.placed-field-label {
  position: absolute;
  top: -20px;
  left: 0;
  font-size: 0.65rem;
  font-weight: 700;
  background: currentColor;
  color: #fff;
  padding: 2px 6px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  white-space: nowrap;
}
.placed-field-type {
  opacity: 0.7;
  pointer-events: none;
}
.resize-handle {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background: currentColor;
  cursor: se-resize;
  border-radius: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}
.placed-field:hover .resize-handle,
.placed-field.selected .resize-handle { opacity: 1; }

/* Right Panel: Properties */
.editor-properties {
  width: 280px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}
.properties-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.875rem;
}
.properties-body { padding: var(--space-4); }
.prop-label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin-bottom: var(--space-1); }
.prop-value { font-size: 0.875rem; color: var(--text); }
.prop-group { margin-bottom: var(--space-4); }
.prop-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.prop-input {
  width: 100%;
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  background: var(--surface);
  color: var(--text);
}
.prop-input:focus { border-color: var(--primary); outline: none; }

/* AI Assistant Panel */
.ai-panel {
  width: 340px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.ai-panel-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.ai-header-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
}
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.ai-message {
  display: flex;
  gap: var(--space-2);
  animation: fadeIn 0.2s ease;
}
.ai-message.user { flex-direction: row-reverse; }
.ai-message-bubble {
  max-width: 80%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.5;
}
.ai-message.assistant .ai-message-bubble {
  background: var(--gray-100);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
}
.ai-message.user .ai-message-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
}
.ai-message-actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.ai-message-actions .btn { font-size: 0.75rem; padding: 0.25rem var(--space-3); }
.ai-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--gray-100);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  width: fit-content;
}
.ai-typing span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); }
  30%          { transform: translateY(-6px); }
}
.ai-input-area {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.ai-quick-actions {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.ai-quick-btn {
  font-size: 0.75rem;
  padding: var(--space-1) var(--space-3);
  background: var(--gray-100);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.ai-quick-btn:hover { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.ai-input-row { display: flex; gap: var(--space-2); }
.ai-input-row textarea {
  flex: 1;
  resize: none;
  height: 60px;
  font-size: 0.875rem;
}

/* Zoom controls */
.zoom-controls {
  position: fixed;
  bottom: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 0;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}
.zoom-btn {
  width: 40px; height: 36px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  font-size: 1rem;
  transition: background var(--transition);
}
.zoom-btn:hover { background: rgba(255,255,255,.1); }
.zoom-value {
  padding: 0 var(--space-3);
  color: rgba(255,255,255,.8);
  font-size: 0.8125rem;
  font-weight: 600;
  min-width: 50px;
  text-align: center;
}

/* Page-by-page editor canvas */
.page-editor-canvas {
  background: #dde1e7;
  padding: var(--space-6) var(--space-4);
  min-height: 75vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}
.doc-page-wrapper {
  width: 816px;
  position: relative;
}
.doc-page-controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
  padding: 0 var(--space-1);
}
.doc-page-controls .page-label {
  font-size: 0.6875rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex: 1;
}
.doc-page-action-btn {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(0,0,0,.18);
  background: rgba(255,255,255,.7);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: #475569;
  transition: all var(--transition);
  padding: 0;
}
.doc-page-action-btn:hover:not(:disabled) { background: #fff; color: var(--text); }
.doc-page-action-btn.danger:hover:not(:disabled) { background: #fee2e2; border-color: #ef4444; color: #ef4444; }
.doc-page-action-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.doc-page-paper {
  width: 816px;
  height: 1056px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.14);
  border-radius: 2px;
  /* padding applied dynamically by JS (default 96px = 1" at 96dpi) */
  padding: 96px;
  box-sizing: border-box;
  outline: none;
  font-size: 1rem;
  line-height: 1.7;
  color: #1e293b;
}
.doc-page-paper:focus {
  box-shadow: 0 4px 20px rgba(0,0,0,.14), 0 0 0 3px rgba(99,102,241,.35);
}
.doc-add-page-btn {
  width: 816px;
  padding: var(--space-3) var(--space-4);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}
.doc-add-page-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }

/* Field placement canvas — per-page layout */
.field-canvas-page {
  width: 816px;
  height: 1056px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,.14);
  border-radius: 2px;
  position: relative;
  flex-shrink: 0;
  /* Must match .document-page-sign and .doc-page-paper exactly */
  font-size: 1rem;
  line-height: 1.7;
  color: #1e293b;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.field-page-label {
  width: 816px;
  font-size: .6875rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 0 4px;
  margin-bottom: 6px;
}

/* Page navigation */
.page-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--gray-900);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-3);
  color: rgba(255,255,255,.8);
  font-size: 0.8125rem;
  position: fixed;
  bottom: var(--space-6);
  right: calc(280px + var(--space-6));
  z-index: 200;
  box-shadow: var(--shadow-lg);
}
