/* Custom Rich Editor Enhancements */

/* ============================================
   FORCE QUILL VISIBILITY - CRITICAL FIX
   ============================================ */
/* Ensure Quill editor is ALWAYS visible - override ALL CSS */
.quill,
.ql-toolbar,
.ql-toolbar.ql-snow,
.ql-container,
.ql-container.ql-snow,
.ql-editor {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  position: relative !important;
  width: 100% !important;
}

.ql-toolbar.ql-snow {
  min-height: 42px !important;
  height: auto !important;
}

.ql-container.ql-snow {
  min-height: 200px !important;
  height: auto !important;
}

.ql-editor {
  min-height: 200px !important;
  height: auto !important;
  overflow-y: auto !important;
}

/* Override Chakra UI potential conflicts - ALL wrapper classes */
.chakra-ui-light .ql-container,
.chakra-ui-light .ql-editor,
.css-8opgp6 .quill,
.css-8opgp6 .ql-toolbar,
.css-8opgp6 .ql-container,
.css-8opgp6 .ql-editor,
.css-ele4hk .quill,
.css-ele4hk .ql-toolbar,
.css-ele4hk .ql-container,
.css-ele4hk .ql-editor,
[class^="css-"] .quill,
[class^="css-"] .ql-toolbar,
[class^="css-"] .ql-container,
[class^="css-"] .ql-editor {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Quill Toolbar Styling */
.ql-toolbar.ql-snow {
  background: linear-gradient(to bottom, #fafafa 0%, #f5f5f5 100%);
  border: none !important;
  border-bottom: 1px solid #e2e8f0 !important;
  padding: 12px 10px;
  border-radius: 6px 6px 0 0;
}

.ql-toolbar.ql-snow .ql-formats {
  margin-right: 12px;
}

.ql-toolbar.ql-snow button {
  width: 32px;
  height: 32px;
  padding: 3px;
  margin-right: 2px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.ql-toolbar.ql-snow button:hover {
  background-color: rgba(66, 153, 225, 0.1);
  color: #3182ce;
}

.ql-toolbar.ql-snow button.ql-active {
  background-color: #3182ce;
  color: white;
}

.ql-toolbar.ql-snow button svg {
  transition: transform 0.2s ease;
}

.ql-toolbar.ql-snow button:hover svg {
  transform: scale(1.1);
}

.ql-toolbar.ql-snow .ql-stroke {
  stroke: #4a5568;
}

.ql-toolbar.ql-snow .ql-fill {
  fill: #4a5568;
}

.ql-toolbar.ql-snow button:hover .ql-stroke {
  stroke: #3182ce;
}

.ql-toolbar.ql-snow button:hover .ql-fill {
  fill: #3182ce;
}

.ql-toolbar.ql-snow button.ql-active .ql-stroke {
  stroke: white;
}

.ql-toolbar.ql-snow button.ql-active .ql-fill {
  fill: white;
}

/* Dropdowns */
.ql-toolbar.ql-snow .ql-picker {
  border-radius: 4px;
  transition: all 0.2s ease;
}

.ql-toolbar.ql-snow .ql-picker-label {
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 4px 8px;
  transition: all 0.2s ease;
}

.ql-toolbar.ql-snow .ql-picker-label:hover {
  border-color: #3182ce;
  background-color: rgba(66, 153, 225, 0.05);
}

.ql-toolbar.ql-snow .ql-picker.ql-expanded .ql-picker-label {
  border-color: #3182ce;
  background-color: white;
}

.ql-toolbar.ql-snow .ql-picker-options {
  border-radius: 4px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border: 1px solid #e2e8f0;
  padding: 4px;
  background: white;
  max-height: 300px;
  overflow-y: auto;
}

.ql-toolbar.ql-snow .ql-picker-options .ql-picker-item {
  border-radius: 4px;
  padding: 6px 8px;
  transition: all 0.15s ease;
}

.ql-toolbar.ql-snow .ql-picker-options .ql-picker-item:hover {
  background-color: rgba(66, 153, 225, 0.1);
  color: #3182ce;
}

/* Editor Container */
.ql-container.ql-snow {
  border: none !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 16px;
  border-radius: 0 0 6px 6px;
}

/* Editor Content */
.ql-editor {
  padding: 16px;
  line-height: 1.7;
  color: #2d3748;
  caret-color: #3182ce;
}

.ql-editor.ql-blank::before {
  color: #a0aec0;
  font-style: normal;
  left: 16px;
  right: 16px;
}

/* Typography in Editor */
.ql-editor h1 {
  font-size: 2em;
  font-weight: 700;
  margin: 0.67em 0;
  line-height: 1.2;
  color: #1a202c;
}

.ql-editor h2 {
  font-size: 1.5em;
  font-weight: 600;
  margin: 0.75em 0;
  line-height: 1.3;
  color: #1a202c;
}

.ql-editor h3 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 1em 0;
  line-height: 1.4;
  color: #2d3748;
}

.ql-editor p {
  margin: 0.5em 0;
}

.ql-editor ul,
.ql-editor ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}

.ql-editor li {
  margin: 0.25em 0;
}

.ql-editor blockquote {
  border-left: 4px solid #3182ce;
  padding-left: 16px;
  margin: 1em 0;
  color: #4a5568;
  font-style: italic;
  background-color: #f7fafc;
  padding: 12px 16px;
  border-radius: 4px;
}

.ql-editor code {
  background-color: #f7fafc;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 0.9em;
  color: #e53e3e;
}

.ql-editor pre {
  background-color: #2d3748;
  color: #f7fafc;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 1em 0;
  line-height: 1.5;
}

.ql-editor pre code {
  background: transparent;
  color: #f7fafc;
  padding: 0;
}

.ql-editor a {
  color: #3182ce;
  text-decoration: underline;
  transition: color 0.2s ease;
}

.ql-editor a:hover {
  color: #2c5aa0;
}

/* Images in Editor */
.ql-editor img {
  border-radius: 6px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ql-editor img:hover {
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Custom Image Resize Handle Styles */
.custom-image-resize-handle {
  animation: pulseHandle 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulseHandle {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

.custom-image-resize-handle:hover {
  animation: none;
  opacity: 1 !important;
}

/* Video Embeds */
.ql-editor iframe {
  max-width: 100%;
  border-radius: 6px;
  margin: 12px 0;
}

/* Tables */
.ql-editor table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
}

.ql-editor table td,
.ql-editor table th {
  border: 1px solid #e2e8f0;
  padding: 8px 12px;
}

.ql-editor table th {
  background-color: #f7fafc;
  font-weight: 600;
  text-align: left;
}

/* Scrollbar Styling */
.ql-editor::-webkit-scrollbar {
  width: 10px;
}

.ql-editor::-webkit-scrollbar-track {
  background: #f7fafc;
  border-radius: 0 0 6px 0;
}

.ql-editor::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 5px;
  transition: background 0.2s ease;
}

.ql-editor::-webkit-scrollbar-thumb:hover {
  background: #a0aec0;
}

/* Color Picker */
.ql-snow .ql-color-picker .ql-picker-label {
  width: 32px;
  height: 32px;
  padding: 4px;
}

.ql-snow .ql-color-picker .ql-picker-options {
  width: 152px;
  padding: 8px;
}

/* Focus States */
.ql-container:focus-within {
  outline: 2px solid #3182ce;
  outline-offset: 2px;
}

/* Prevent White Text on White Background */
.ql-editor [style*="color: rgb(255, 255, 255)"],
.ql-editor [style*="color: white"],
.ql-editor [style*="color: #fff"],
.ql-editor [style*="color: #ffffff"],
.ql-editor [style*="color: rgb(255,255,255)"],
.ql-editor [style*="color: rgba(255, 255, 255"],
.ql-editor [style*="color: rgba(255,255,255"] {
  color: #1a202c !important;
}

/* Ensure all text elements have visible colors */
.ql-editor p,
.ql-editor span,
.ql-editor div,
.ql-editor li {
  color: #2d3748;
}

.ql-editor h1,
.ql-editor h2,
.ql-editor h3,
.ql-editor h4,
.ql-editor h5,
.ql-editor h6 {
  color: #1a202c;
}

.ql-editor strong,
.ql-editor b {
  color: #1a202c;
  font-weight: bold;
}

/* Ensure container is always white background */
.ql-container.ql-snow {
  background-color: white !important;
}

.ql-editor {
  background-color: white !important;
  color: #2d3748 !important;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .ql-toolbar.ql-snow {
    padding: 8px 6px;
  }

  .ql-toolbar.ql-snow button {
    width: 28px;
    height: 28px;
  }

  .ql-toolbar.ql-snow .ql-formats {
    margin-right: 8px;
  }

  .ql-editor {
    padding: 12px;
    font-size: 15px;
  }
}

/* Selection Highlight */
.ql-editor ::selection {
  background-color: rgba(66, 153, 225, 0.3);
}

.ql-editor ::-moz-selection {
  background-color: rgba(66, 153, 225, 0.3);
}

/* Tooltip Styles for Toolbar */
.ql-toolbar.ql-snow button[title]:hover::after,
.ql-toolbar.ql-snow .ql-picker-label[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background-color: #2d3748;
  color: white;
  font-size: 12px;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 4px;
  z-index: 1000;
  pointer-events: none;
}

/* Loading State for Images */
.ql-editor img[src=""] {
  opacity: 0.3;
  filter: grayscale(100%);
}

/* Enhanced Link Styling */
.ql-editor a[href^="http"]::after {
  content: " ↗";
  font-size: 0.8em;
  opacity: 0.6;
}

.ql-editor a[href^="#"]::after,
.ql-editor a[href^="/"]::after {
  content: "";
}

/* Modern Range Slider Styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(to right, #3182ce 0%, #3182ce var(--value), #e2e8f0 var(--value), #e2e8f0 100%);
  outline: none;
  transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 3px solid #3182ce;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(49, 130, 206, 0.3);
  transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 3px 10px rgba(49, 130, 206, 0.5);
}

input[type="range"]::-webkit-slider-thumb:active {
  transform: scale(1.1);
  background: #3182ce;
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 3px solid #3182ce;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(49, 130, 206, 0.3);
  transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 3px 10px rgba(49, 130, 206, 0.5);
}

input[type="range"]::-moz-range-thumb:active {
  transform: scale(1.1);
  background: #3182ce;
}

/* Floating Toolbar Animation */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.floating-toolbar {
  animation: fadeInUp 0.3s ease-out;
}

/* Enhanced Image Selection */
.ql-editor img[data-selected="true"] {
  outline: 3px solid #3182ce !important;
  box-shadow: 0 0 0 4px rgba(49, 130, 206, 0.1), 
              0 4px 12px rgba(49, 130, 206, 0.3) !important;
}

/* Image Transform Transitions */
.ql-editor img {
  transition: filter 0.3s ease, transform 0.3s ease !important;
}

/* Print Styles */
@media print {
  .ql-toolbar {
    display: none;
  }

  .ql-container {
    border: none !important;
  }

  .ql-editor {
    padding: 0;
  }

  .ql-editor img {
    max-width: 100%;
    page-break-inside: avoid;
  }
  
  /* Print without filters/transforms for better compatibility */
  .ql-editor img {
    filter: none !important;
    transform: none !important;
  }
}
