/* Tiptap Editor Styles */

/* Enhanced Context Panel Styles */
.context-panel {
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
  flex-shrink: 0; /* Prevent shrinking */
  width: 320px; /* Fixed width */
  max-height: 100vh; /* Max height constraint */
  overflow-y: auto; /* Allow scrolling */
}

.context-panel::-webkit-scrollbar {
  width: 6px;
}

.context-panel::-webkit-scrollbar-track {
  background: transparent;
}

.context-panel::-webkit-scrollbar-thumb {
  background-color: #d1d5db;
  border-radius: 3px;
}

.data-card {
  transition: all 0.2s ease-in-out;
}

.data-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Toolbar group containers */
.toolbar-group {
  transition: border-color 0.2s, background-color 0.2s;
}

.toolbar-group:hover {
  @apply border-gray-300 bg-gray-100;
}

.toolbar-group:focus-within {
  @apply border-blue-300 bg-blue-50;
}

/* Toolbar button styles */
.toolbar-button {
  @apply p-2 rounded-md transition-all duration-150;
  @apply text-gray-600 hover:text-gray-900;
  @apply hover:bg-white;
  position: relative;
}

.toolbar-button:hover {
  @apply shadow-sm;
}

.toolbar-button.active {
  @apply bg-white text-blue-600 shadow-sm;
  font-weight: 500;
}

.toolbar-button.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  height: 50%;
  width: 2px;
  background: currentColor;
  border-radius: 0 2px 2px 0;
}

/* Autosave status styles */
.autosave-status {
  min-width: 140px;
}

.autosave-indicator {
  transition: background-color 0.3s;
}

/* Autosave state colors */
.autosave-status[data-status="saved"] .autosave-indicator {
  background-color: #22c55e; /* green-500 */
}

.autosave-status[data-status="saved"] {
  border-color: #bbf7d0; /* green-200 */
}

.autosave-status[data-status="saving"] .autosave-indicator {
  background-color: #3b82f6; /* blue-500 */
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.autosave-status[data-status="saving"] {
  border-color: #bfdbfe; /* blue-200 */
}

.autosave-status[data-status="error"] .autosave-indicator {
  background-color: #ef4444; /* red-500 */
}

.autosave-status[data-status="error"] {
  border-color: #fecaca; /* red-200 */
}

.autosave-status[data-status="ready"] .autosave-indicator {
  background-color: #d1d5db; /* gray-300 */
}

.autosave-status[data-status="pending"] .autosave-indicator {
  background-color: #eab308; /* yellow-500 */
}

.autosave-status[data-status="pending"] {
  border-color: #fef08a; /* yellow-200 */
}

/* Editor container */
.ProseMirror {
  outline: none;
  word-wrap: break-word;
  min-height: 150px;
}

/* Editor content styles for Stimulus controller */
[data-tiptap-editor-target="editor"] {
  @apply px-6 py-4;
}

[data-tiptap-editor-target="editor"]:focus {
  @apply outline-none ring-2 ring-blue ring-offset-2;
}

/* Basic typography */
.ProseMirror h1 {
  font-size: 1.75rem;
  font-weight: bold;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  line-height: 1.2;
}

.ProseMirror h2 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  line-height: 1.3;
}

.ProseMirror p {
  margin-bottom: 0.75rem;
  line-height: 1.5;
}

/* Lists */
.ProseMirror ul,
.ProseMirror ol {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  padding-left: 1.5rem;
}

.ProseMirror ul {
  list-style-type: disc;
}

.ProseMirror ol {
  list-style-type: decimal;
}

.ProseMirror li {
  margin-bottom: 0.25rem;
  line-height: 1.5;
}

.ProseMirror li > h1,
.ProseMirror li > h2 {
  display: inline;
  margin: 0;
}

/* Fix for nested headings and lists */
.ProseMirror li h1,
.ProseMirror li h2 {
  font-size: inherit;
  font-weight: inherit;
  margin: 0;
  display: inline;
}

/* Toolbar */
.tiptap-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.5rem;
  border-bottom: 1px solid #e5e7eb;
  margin-bottom: 0.5rem;
  background-color: #f9fafb;
}

/* Toolbar buttons */
.tiptap-button {
  padding: 0.375rem;
  border-radius: 0.25rem;
  font-weight: 500;
  font-size: 0.875rem;
  line-height: 1.25rem;
  transition: background-color 0.2s;
}

.tiptap-button:hover {
  background-color: #e5e7eb;
}

.tiptap-button.active,
.tiptap-button.bg-lavender/20 {
  @apply bg-blue/20;
}

/* RTL support */
[dir="rtl"] .ProseMirror ul,
[dir="rtl"] .ProseMirror ol {
  padding-right: 1.5rem;
  padding-left: 0;
}

/* RTL lists in editor */
.ProseMirror ul[dir="rtl"],
.ProseMirror ol[dir="rtl"] {
  direction: rtl;
  padding-left: 0;
  padding-right: 2.5rem;
  margin-left: 0;
  margin-right: 0;
}

.ProseMirror ul[dir="rtl"] li,
.ProseMirror ol[dir="rtl"] li {
  direction: rtl;
  text-align: right;
}

/* For Webkit browsers (Chrome, Safari) */
.ProseMirror ul[dir="rtl"] {
  list-style-type: disc;
}

.ProseMirror ol[dir="rtl"] {
  list-style-type: decimal;
}

/* RTL paragraphs and headings */
.ProseMirror p[dir="rtl"],
.ProseMirror h1[dir="rtl"],
.ProseMirror h2[dir="rtl"],
.ProseMirror h3[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

/* Placeholder Styling with Prominent Amber/Orange Gradients */
.placeholder-highlight {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.9em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
  display: inline-block;
  margin: 0 2px;
  animation: placeholderPulse 2s ease-in-out infinite;
}

@keyframes placeholderPulse {
  0%, 100% {
    box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
  }
  50% {
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.5);
    transform: translateY(-1px);
  }
}

/* Template Preview Modal Styles */
.template-preview-content .placeholder-highlight {
  background: linear-gradient(135deg, #fde68a 0%, #fbbf24 50%, #f59e0b 100%);
  color: #92400e;
  text-shadow: none;
  font-weight: 500;
}

/* Template Item Hover Effects */
.template-item {
  position: relative;
  overflow: hidden;
}

.template-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
  transition: left 0.5s;
}

.template-item:hover::before {
  left: 100%;
}

/* Quick Insert Panel Styles */
#quick-insert-panel {
  backdrop-filter: blur(10px);
  background-color: rgba(255, 255, 255, 0.95);
}

/* Quick Add Form Styles */
#quick-add-form {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-radius: 0;
  animation: slideDown 0.3s ease-out;
}

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

#quick-add-form input,
#quick-add-form select,
#quick-add-form textarea {
  background-color: white;
  transition: all 0.2s ease;
}

#quick-add-form input:focus,
#quick-add-form select:focus,
#quick-add-form textarea:focus {
  background-color: #fefefe;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

.template-category h4 {
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(5px);
  z-index: 10;
  padding: 8px 0;
  margin: 0 -16px 12px -16px;
  padding-left: 16px;
  border-bottom: 1px solid #f3f4f6;
}

/* Search Input Enhancement */
#template-search:focus {
  background-color: #fefefe;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}


/* Success Feedback Animation */
.insert-success-feedback {
  animation: slideInRight 0.3s ease-out, slideOutRight 0.3s ease-in 2s forwards;
}

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

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

/* Modal Entrance Animation */
#template-preview-modal.show {
  animation: modalFadeIn 0.2s ease-out;
}

#template-preview-modal.show > div {
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Editor Layout Fixes */
.report-editor-container {
  min-height: 100vh;
  display: flex;
  flex-direction: row; /* Ensure horizontal layout */
}

.report-editor-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Ensure editor content has enough bottom padding */
.ProseMirror {
  min-height: 400px;
  padding-bottom: 4rem; /* Increased bottom padding */
}

/* Footer overlap fix */
body.report-editor-page {
  overflow-x: hidden; /* Only hide horizontal overflow */
  position: relative;
}

.report-editor-page footer {
  display: none; /* Hide footer on report editor page */
}

/* Variable Conversion Modal Animations */
.animate-fadeIn {
  animation: fadeIn 0.2s ease-out;
}

.animate-fadeOut {
  animation: fadeOut 0.2s ease-out;
}

.animate-slideUp {
  animation: slideUp 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

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

/* Hide ProseMirror's default horizontal drop cursor */
.ProseMirror .ProseMirror-dropcursor,
.ProseMirror-dropcursor {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* Drop Cursor Animation */
@keyframes blink {
  0%, 50% {
    opacity: 1;
  }
  51%, 100% {
    opacity: 0;
  }
}

/* Insertion Point Pulse (shows where content WILL be inserted) */
@keyframes insertion-point-pulse {
  0%, 100% {
    background-color: #3B82F6;
    transform: scaleX(1);
    opacity: 1;
  }
  50% {
    background-color: #60A5FA;
    transform: scaleX(1.5);
    opacity: 0.8;
  }
}

.insertion-point-indicator {
  display: inline-block;
  width: 3px;
  height: 1.3em;
  background-color: #3B82F6;
  margin-left: -1.5px;
  margin-right: -1.5px;
  animation: insertion-point-pulse 1.2s ease-in-out infinite;
  pointer-events: none;
  vertical-align: text-bottom;
  border-radius: 1px;
}

/* Inserted Content Highlight (shows what WAS just inserted) - Notion-like */
@keyframes inserted-content-highlight {
  0% {
    background-color: rgba(251, 191, 36, 0.4); /* Much brighter amber - amber-400 at 40% */
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.2);
  }
  20% {
    background-color: rgba(251, 191, 36, 0.3);
  }
  100% {
    background-color: transparent;
    box-shadow: 0 0 0 0 transparent;
  }
}

.just-inserted {
  animation: inserted-content-highlight 2500ms cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 4px;
}

/* Entry Animation for Inserted Content */
@keyframes slide-in-fade {
  0% {
    opacity: 0.3;
    transform: translateY(-4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.inserting {
  animation: slide-in-fade 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  #quick-insert-panel {
    right: 1rem;
    left: 1rem;
    width: auto;
  }

  #template-preview-modal .max-w-2xl {
    max-width: calc(100vw - 2rem);
  }

  .context-panel {
    width: 280px; /* Slightly narrower on mobile */
  }

  /* Make header button smaller on mobile */
  .report-editor-main .bg-blue-600 {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
  }
}