/* Story Editor with Inline Annotations */

/* ============================================================================
   Modal Container
   ============================================================================ */

.story-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 20px;
}

.story-editor-container {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* ============================================================================
   Header
   ============================================================================ */

.story-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 24px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.story-editor-title h2 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: #111827;
}

.story-editor-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #6b7280;
}

.version-selector {
  padding: 4px 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}

.word-count-display {
  font-variant-numeric: tabular-nums;
  background: #f3f4f6;
  padding: 2px 8px;
  border-radius: 4px;
}

.story-editor-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}

.story-editor-close:hover {
  color: #374151;
}

/* ============================================================================
   Body — Editor + Sidebar
   ============================================================================ */

.story-editor-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.story-editor-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  border-right: 1px solid #e5e7eb;
}

/* ============================================================================
   TipTap Editor Styles
   ============================================================================ */

.tiptap-editor {
  min-height: 300px;
}

.tiptap-editor .tiptap {
  outline: none;
  font-family: Georgia, 'Times New Roman', serif;
  font-size: 15px;
  line-height: 1.8;
  color: #1f2937;
  min-height: 300px;
  caret-color: transparent; /* Hide text cursor — content is not directly editable */
  user-select: text; /* Allow selection for annotations */
}

.tiptap-editor .tiptap p {
  margin: 0 0 16px 0;
}

.tiptap-editor .tiptap p:last-child {
  margin-bottom: 0;
}

/* Annotation highlight */
.annotation-highlight {
  background: #fef08a;
  border-bottom: 2px solid #eab308;
  cursor: pointer;
  transition: background 0.2s;
  border-radius: 2px;
  padding: 1px 0;
}

.annotation-highlight:hover {
  background: #fde047;
}

.annotation-pulse {
  animation: pulse-highlight 1.5s ease-in-out;
}

@keyframes pulse-highlight {
  0%, 100% { background: #fef08a; }
  25% { background: #fb923c; }
  50% { background: #fef08a; }
  75% { background: #fb923c; }
}

/* ============================================================================
   Global Notes
   ============================================================================ */

.global-notes-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

.global-notes-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.global-notes-hint {
  color: #9ca3af;
  cursor: help;
  font-weight: 400;
}

.global-notes-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  resize: vertical;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.global-notes-input:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* ============================================================================
   Sidebar — Comment List
   ============================================================================ */

.story-editor-sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  background: #f9fafb;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.sidebar-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.annotation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.no-annotations {
  text-align: center;
  color: #9ca3af;
  font-size: 13px;
  padding: 24px 16px;
}

.annotation-item {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.annotation-item:hover {
  border-color: #6366f1;
  box-shadow: 0 1px 4px rgba(99, 102, 241, 0.15);
}

.annotation-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.annotation-number {
  background: #6366f1;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.annotation-number.insertion-badge {
  background: #059669;
  font-size: 14px;
}

.annotation-item.insertion {
  border-left: 3px solid #059669;
}

.annotation-item.insertion .annotation-highlighted {
  color: #059669;
  font-style: normal;
  font-weight: 500;
}

.annotation-delete {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.annotation-delete:hover {
  color: #ef4444;
}

.annotation-highlighted {
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
  margin-bottom: 4px;
  line-height: 1.4;
}

.annotation-comment {
  font-size: 13px;
  color: #1f2937;
  line-height: 1.4;
}

.btn-add-general {
  margin: 8px;
  padding: 8px 12px;
  background: none;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  font-size: 13px;
  color: #6b7280;
  cursor: pointer;
  text-align: center;
}

.btn-add-general:hover {
  border-color: #6366f1;
  color: #6366f1;
}

/* ============================================================================
   Floating Comment Input
   ============================================================================ */

/* Floating insert button (shown on click without selection) */
.floating-insert-btn {
  position: absolute;
  z-index: 10001;
}

.insertion-trigger-btn {
  background: #fff;
  border: 1px dashed #d1d5db;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  color: #059669;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}

.insertion-trigger-btn:hover {
  border-color: #059669;
  background: #ecfdf5;
}

.floating-comment-input {
  position: absolute;
  z-index: 10001;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  width: 300px;
}

.floating-comment-input textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 13px;
  resize: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.floating-comment-input textarea:focus {
  outline: none;
  border-color: #6366f1;
}

.floating-comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}

/* ============================================================================
   Footer
   ============================================================================ */

.story-editor-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.editor-progress-container {
  flex: 1;
  min-width: 180px;
}

.editor-progress-container .progress-bar {
  width: 100%;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 4px;
}

.editor-progress-container .progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #3b82f6);
  border-radius: 4px;
  transition: width 0.5s ease-out;
  width: 0%;
}

.editor-progress-container .progress-text {
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

.editor-status {
  flex: 1;
  text-align: right;
  font-size: 13px;
  color: #6b7280;
}

/* ============================================================================
   Button Overrides (compact)
   ============================================================================ */

.story-editor-modal .btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}

.story-editor-modal .btn-primary {
  background: #6366f1;
  color: #fff;
}

.story-editor-modal .btn-primary:hover:not(:disabled) {
  background: #4f46e5;
}

.story-editor-modal .btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.story-editor-modal .btn-secondary {
  background: #fff;
  color: #374151;
  border-color: #d1d5db;
}

.story-editor-modal .btn-secondary:hover {
  background: #f3f4f6;
}

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

/* ============================================================================
   Toast Notifications
   ============================================================================ */

.story-editor-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10002;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: opacity 0.3s;
}

.toast-success { background: #059669; }
.toast-error { background: #dc2626; }
.toast-info { background: #2563eb; }
.toast-fade { opacity: 0; }

/* ============================================================================
   Responsive
   ============================================================================ */

@media (max-width: 768px) {
  .story-editor-body {
    flex-direction: column;
  }

  .story-editor-sidebar {
    width: 100%;
    max-height: 200px;
    border-right: none;
    border-top: 1px solid #e5e7eb;
  }

  .story-editor-modal {
    padding: 8px;
  }
}
