/* TipTap Magazine Layout Styles */
/* Floating images with text wrapping for magazine-style layouts */

/* Base TipTap Editor Styling */
.ProseMirror {
  outline: none;
  padding: 1rem;
  line-height: 1.75;
  color: #1f2937; /* Ensure text is dark gray */
  background-color: white; /* Ensure background is white */
}

.ProseMirror:focus {
  outline: none;
}

.ProseMirror p {
  margin: 1rem 0;
}

.ProseMirror h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin: 2rem 0 1rem 0;
  line-height: 1.2;
}

.ProseMirror h2 {
  font-size: 1.875rem;
  font-weight: 600;
  margin: 1.75rem 0 1rem 0;
  line-height: 1.3;
}

.ProseMirror h3 {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 1.5rem 0 0.75rem 0;
  line-height: 1.4;
}

.ProseMirror blockquote {
  border-left: 4px solid #e5e7eb;
  padding-left: 1rem;
  margin: 1.5rem 0;
  font-style: italic;
  color: #6b7280;
}

.ProseMirror ul,
.ProseMirror ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.ProseMirror li {
  margin: 0.25rem 0;
}

.ProseMirror hr {
  border: none;
  border-top: 2px solid #e5e7eb;
  margin: 2rem 0;
}

/* Floating Image Layouts */
.figure-left {
  float: left;
  margin: 0 2rem 1rem 0;
  clear: left;
  shape-outside: margin-box;
}

.figure-right {
  float: right;
  margin: 0 0 1rem 2rem;
  clear: right;
  shape-outside: margin-box;
}

.figure-center {
  display: block;
  margin: 2rem auto;
  text-align: center;
  clear: both;
  float: none;
}

/* Image Size Variants */
.figure-small {
  max-width: 25%;
  min-width: 150px;
}

.figure-medium {
  max-width: 40%;
  min-width: 200px;
}

.figure-large {
  max-width: 60%;
  min-width: 300px;
}

.figure-full {
  max-width: 100%;
  width: 100%;
}

/* Center alignment overrides for sizes */
.figure-center.figure-small {
  max-width: 50%;
  min-width: 200px;
}

.figure-center.figure-medium {
  max-width: 75%;
  min-width: 300px;
}

.figure-center.figure-large {
  max-width: 90%;
  min-width: 400px;
}

/* Figure Elements */
figure {
  position: relative;
  margin: 0;
  line-height: 0; /* Removes extra space below image */
}

.figure-image {
  width: 100%;
  height: auto;
  border-radius: 0.375rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.2s ease;
}

.figure-image:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.figure-caption {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: #6b7280;
  font-style: italic;
  line-height: 1.4;
  text-align: center;
}

.figure-left .figure-caption,
.figure-right .figure-caption {
  text-align: left;
}

/* Interactive Controls */
.figure-controls {
  display: none;
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  padding: 0.5rem;
  z-index: 10;
}

figure.group:hover .figure-controls {
  display: block;
}

.figure-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #374151;
  transition: background-color 0.2s ease;
}

.figure-controls button:hover {
  background-color: #f3f4f6;
}

.figure-controls button.active {
  background-color: #dbeafe;
  color: #2563eb;
}

/* Selection Styling */
.ProseMirror-selectednode {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-radius: 0.375rem;
}

/* Drag and Drop */
.ProseMirror .drop-cursor {
  position: relative;
  pointer-events: none;
}

.ProseMirror .drop-cursor:after {
  content: '';
  position: absolute;
  left: -1px;
  right: -1px;
  top: -1px;
  bottom: -1px;
  border: 2px solid #3b82f6;
  border-radius: 0.25rem;
  pointer-events: none;
}

/* Text Wrapping Improvements */
.figure-left + p,
.figure-right + p {
  text-align: justify;
  hyphens: auto;
}

/* Responsive Behavior */
@media (max-width: 768px) {
  .figure-left,
  .figure-right {
    float: none;
    margin: 1rem auto;
    display: block;
    text-align: center;
  }
  
  .figure-small,
  .figure-medium,
  .figure-large {
    max-width: 100%;
    min-width: auto;
  }
  
  .figure-controls {
    position: relative;
    top: auto;
    right: auto;
    display: block;
    margin-top: 0.5rem;
    text-align: center;
  }
  
  .figure-controls button {
    margin: 0 0.125rem;
  }
}

/* Print Styles */
@media print {
  .figure-controls {
    display: none !important;
  }
  
  .figure-image {
    box-shadow: none;
    break-inside: avoid;
  }
  
  figure {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .ProseMirror {
    color: #f9fafb;
  }
  
  .ProseMirror blockquote {
    border-left-color: #4b5563;
    color: #9ca3af;
  }
  
  .ProseMirror hr {
    border-top-color: #4b5563;
  }
  
  .figure-caption {
    color: #9ca3af;
  }
  
  .figure-controls {
    background: #1f2937;
    color: #f9fafb;
  }
  
  .figure-controls button {
    color: #f9fafb;
  }
  
  .figure-controls button:hover {
    background-color: #374151;
  }
  
  .figure-controls button.active {
    background-color: #1e40af;
    color: #bfdbfe;
  }
}

/* Animation and Transitions */
figure {
  transition: all 0.2s ease;
}

.figure-image {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

figure:hover .figure-image {
  transform: scale(1.02);
}

/* Accessibility */
.figure-controls button:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.figure-image:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  .figure-image {
    border: 1px solid #000;
  }
  
  .figure-controls {
    border: 1px solid #000;
  }
  
  .figure-controls button {
    border: 1px solid #666;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  figure,
  .figure-image,
  .figure-controls button {
    transition: none;
  }
  
  figure:hover .figure-image {
    transform: none;
  }
}

/* Component Placeholder Styles */
.component-placeholder {
  margin: 1rem 0;
  border: 2px dashed #e5e7eb;
  border-radius: 0.5rem;
  background-color: #f9fafb;
  transition: all 0.2s ease;
  cursor: move;
}

.component-placeholder:hover {
  border-color: #9ca3af;
  background-color: #f3f4f6;
}

.component-placeholder.ProseMirror-selectednode {
  border-color: #3b82f6;
  background-color: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.component-placeholder-content {
  display: flex;
  align-items: center;
  padding: 1.5rem;
  gap: 1rem;
  user-select: none;
}

.component-placeholder-icon {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: white;
  border-radius: 0.375rem;
  color: #6b7280;
}

.component-placeholder-info {
  flex-grow: 1;
}

.component-placeholder-type {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  color: #6b7280;
  letter-spacing: 0.05em;
}

.component-placeholder-name {
  font-size: 1rem;
  font-weight: 600;
  color: #111827;
  margin-top: 0.125rem;
}

/* Video wrapper styles */
.video-wrapper {
  position: relative;
  max-width: 100%;
  margin: 1.5rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.video-wrapper.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background-color: #f3f4f6;
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  border-radius: 0.5rem;
}

.video-wrapper.error {
  background-color: #f3f4f6;
  border: 2px dashed #d1d5db;
  border-radius: 0.5rem;
  padding: 2rem;
}

.tiptap-video,
.video-wrapper video {
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.tiptap-video:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5);
}

/* Video selection styling */
.video-wrapper.ProseMirror-selectednode {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-radius: 0.5rem;
}

/* Video Alignment Styles */
.video-wrapper.video-left {
  margin-right: auto;
  margin-left: 0;
  max-width: 50%;
  justify-content: flex-start;
}

.video-wrapper.video-center {
  margin-left: auto;
  margin-right: auto;
  max-width: 100%;
  display: flex;
  justify-content: center;
}

.video-wrapper.video-right {
  margin-left: auto;
  margin-right: 0;
  max-width: 50%;
  justify-content: flex-end;
}

/* Video Controls Styling */
.video-controls {
  user-select: none;
}

.video-controls button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s ease;
}

.video-controls button:hover {
  background-color: #f3f4f6;
}

.video-controls button.bg-blue-100 {
  background-color: #dbeafe;
  color: #1e40af;
}

/* Responsive video styles */
@media (max-width: 768px) {
  .video-wrapper {
    margin: 1rem 0;
  }
  
  .tiptap-video {
    border-radius: 0.375rem;
  }
}

/* Dark mode video styles */
@media (prefers-color-scheme: dark) {
  .video-wrapper.error {
    background-color: #1f2937;
    border-color: #4b5563;
  }
  
  .video-controls {
    background-color: #1f2937;
    color: #f9fafb;
  }
  
  .video-controls button {
    color: #f9fafb;
  }
  
  .video-controls button:hover {
    background-color: #374151;
  }
  
  .video-controls button.bg-blue-100 {
    background-color: #1e40af;
    color: #bfdbfe;
  }
}

/* Gradient Background Styles - Ensure gradients are visible in the editor */
.ProseMirror span[style*="background:"],
.ProseMirror span[style*="background-image:"] {
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  display: inline;
  line-height: 1.4;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Ensure gradients don't get overridden by prose styles in EDITOR */
.ProseMirror .prose span[style*="linear-gradient"]:not([style*="background-clip"]),
.ProseMirror span[style*="linear-gradient"]:not([style*="background-clip"]) {
  background-clip: padding-box !important;
  -webkit-background-clip: padding-box !important;
}

/* RENDERED content gradient text support */
.prose span[style*="-webkit-background-clip: text"],
span[style*="-webkit-background-clip: text"] {
  -webkit-background-clip: text !important;
  background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  color: transparent;
  display: inline-block;
  line-height: 1.4;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Ensure gradient text stays readable */
.prose span[style*="-webkit-background-clip: text"] *,
span[style*="-webkit-background-clip: text"] * {
  background: inherit;
  -webkit-background-clip: inherit;
  background-clip: inherit;
  -webkit-text-fill-color: inherit;
  color: inherit;
}

/* Selection styling for gradient text */
.ProseMirror span[style*="linear-gradient"]::selection {
  background-color: rgba(59, 130, 246, 0.3);
}

/* Focus states for gradient text */
.ProseMirror:focus span[style*="linear-gradient"] {
  opacity: 1;
}

/* Ensure gradients work well with other text styling */
.ProseMirror span[style*="linear-gradient"] strong,
.ProseMirror span[style*="linear-gradient"] em,
.ProseMirror span[style*="linear-gradient"] code {
  background: inherit;
  color: inherit;
}

/* CRITICAL: Ensure inline color styles override prose defaults in RENDERED content */
/* Note: Removed the color: inherit rule as it was preventing inline color styles from working.
   The inline style with !important should take precedence over prose defaults. */

/* Gradient toolbar button active state */
.toolbar-btn.gradient-active {
  background: linear-gradient(45deg, #3b82f6, #8b5cf6);
  color: white;
}

/* Page background picker positioning */
.page-background-picker {
  max-width: 280px;
  min-width: 250px;
}

/* Ensure picker stays in viewport */
@media (max-width: 640px) {
  .page-background-picker {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
  }
}

/* Better positioning for wider screens */
.page-background-controls {
  position: relative;
}

.page-background-picker.position-right {
  left: auto;
  right: 0;
}

.page-background-picker.position-above {
  top: auto;
  bottom: 100%;
  margin-top: 0;
  margin-bottom: 0.25rem;
}

/* Table Cell Vertical Alignment Styles */
.ProseMirror td.align-top,
.ProseMirror th.align-top {
  vertical-align: top !important;
}

.ProseMirror td.align-middle,
.ProseMirror th.align-middle {
  vertical-align: middle !important;
}

.ProseMirror td.align-bottom,
.ProseMirror th.align-bottom {
  vertical-align: bottom !important;
}

/* Enhanced table styling for better vertical alignment visibility */
.ProseMirror table {
  table-layout: fixed;
  width: 100%;
  border-collapse: collapse;
}

.ProseMirror td,
.ProseMirror th {
  position: relative;
  min-height: 3rem;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e7eb;
  vertical-align: top; /* Default to top alignment */
}

.ProseMirror th {
  background-color: #f9fafb;
  font-weight: 600;
}

/* Visual indicator for cell alignment in editor */
.ProseMirror td.ProseMirror-selectednode,
.ProseMirror th.ProseMirror-selectednode {
  background-color: rgba(59, 130, 246, 0.1);
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

/* Magazine Layout Styles */
.magazine-layout-wrapper {
  position: relative;
  margin: 2rem 0;
  border: 2px dashed #e5e7eb;
  border-radius: 0.5rem;
  padding: 1rem;
  background-color: #fafafa;
}

.magazine-layout-wrapper:hover {
  border-color: #9ca3af;
}

.magazine-layout-wrapper.ProseMirror-selectednode {
  border-color: #3b82f6;
  background-color: #eff6ff;
}

.magazine-layout-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.5rem;
  background-color: white;
  border-radius: 0.375rem;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.layout-control {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  background-color: white;
  cursor: pointer;
  transition: all 0.15s ease;
}

.layout-control:hover {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

.magazine-layout-content {
  display: grid;
  gap: 1rem;
  align-items: start;
}

/* Magazine Cell Styles */
.magazine-cell-wrapper {
  position: relative;
  min-height: 100px;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  background-color: white;
  overflow: hidden;
}

.magazine-cell-wrapper:hover {
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.magazine-cell-wrapper.ProseMirror-selectednode {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.magazine-cell-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background-color: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.75rem;
}

.cell-type-indicator {
  font-size: 1rem;
}

.cell-control {
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.25rem;
  background-color: white;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cell-control:hover {
  background-color: #f3f4f6;
  border-color: #9ca3af;
}

.magazine-cell-content {
  padding: 1rem;
  min-height: 80px;
}

/* Cell type specific styles */
.magazine-cell.cell-media {
  background-color: #f0f9ff;
}

.magazine-cell.cell-media .magazine-cell-content {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.magazine-cell.exclude-text {
  background-color: #fef3c7;
  position: relative;
}

.magazine-cell.exclude-text::after {
  content: 'Text excluded';
  position: absolute;
  top: 0.25rem;
  right: 0.25rem;
  font-size: 0.625rem;
  padding: 0.125rem 0.375rem;
  background-color: #f59e0b;
  color: white;
  border-radius: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Text flow styles for magazine layout */
.magazine-layout[data-flow="column"] .magazine-layout-content {
  grid-auto-flow: column;
}

.magazine-layout[data-flow="row"] .magazine-layout-content {
  grid-auto-flow: row;
}

/* Responsive magazine layout */
@media (max-width: 768px) {
  .magazine-layout-content {
    grid-template-columns: 1fr !important;
  }
  
  .magazine-cell[data-span] {
    grid-column: span 1 !important;
  }
}

/* Print styles for magazine layouts */
@media print {
  .magazine-layout-controls,
  .magazine-cell-controls {
    display: none !important;
  }
  
  .magazine-layout-wrapper {
    border: none;
    padding: 0;
    background: none;
  }
  
  .magazine-cell-wrapper {
    border: none;
    box-shadow: none;
  }
}