/* General styles for CKEditor content */
.ckeditor-content {
  max-width: 100%;
  color: #333;
  font-size: 1rem;
  line-height: 1.6;
  overflow-x: hidden; /* Prevent horizontal scrolling for the entire content */
}

/* Headings */
.ckeditor-content h1 {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 1rem;
}

.ckeditor-content h2 {
  font-size: 1.75rem;
  font-weight: bold;
  margin-bottom: 0.9rem;
}

.ckeditor-content h3 {
  font-size: 1.5rem;
  font-weight: bold;
  margin-bottom: 0.8rem;
}

.ckeditor-content h4 {
  font-size: 1.25rem;
  font-weight: bold;
  margin-bottom: 0.7rem;
}

.ckeditor-content h5 {
  font-size: 1.1rem;
  font-weight: bold;
  margin-bottom: 0.6rem;
}

.ckeditor-content h6 {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 0.5rem;
}

/* Paragraphs */
.ckeditor-content p {
  margin-bottom: 1rem;
}

/* Strong & Italic */
.ckeditor-content strong {
  font-weight: bold;
}

.ckeditor-content em {
  font-style: italic;
}

/* Underline & Strikethrough */
.ckeditor-content u {
  text-decoration: underline;
}

.ckeditor-content s {
  text-decoration: line-through;
}

/* Blockquote */
.ckeditor-content blockquote {
  border-left: 4px solid #1d4ed8;
  padding-left: 1rem;
  font-style: italic;
  color: #6b7280;
  margin: 1rem 0;
  background: #f9fafb;
  padding: 1.5rem;
  border-radius: 0 0.5rem 0.5rem 0;
}

/* Links */
.ckeditor-content a {
  color: #1d4ed8;
  text-decoration: underline;
}

.ckeditor-content a:hover {
  color: #60a5fa;
}

/* Lists */
.ckeditor-content ul {
  list-style-type: disc;
  padding-left: 2rem;
  margin-bottom: 1rem;
}

.ckeditor-content ol {
  list-style-type: decimal;
  padding-left: 2rem;
  margin-bottom: 1rem;
}

.ckeditor-content li {
  margin-bottom: 0.5rem;
}

/* Tables - Updated for horizontal scrolling */
.ckeditor-content .table-container {
  width: 100%;
  overflow-x: auto;
  margin-bottom: 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e5e7eb;
  /* For mobile compatibility */
  -webkit-overflow-scrolling: touch;
}

.ckeditor-content table {
  min-width: 100%;
  border-collapse: collapse;
  background: white;
}

.ckeditor-content th,
.ckeditor-content td {
  border: 1px solid #e5e7eb;
  padding: 0.75rem;
  text-align: left;
  /* Prevent extremely long content from breaking layout */
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-wrap: break-word;
}

.ckeditor-content th {
  background-color: #f9fafb;
  font-weight: bold;
  position: sticky;
  top: 0;
  z-index: 1;
  color: #1f2937;
}

.ckeditor-content td {
  background-color: white;
}

.ckeditor-content tr:nth-child(even) td {
  background-color: #f9fafb;
}

/* Images */
.ckeditor-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1rem 0;
  border-radius: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Code Blocks - Enhanced with controls */
.ckeditor-content pre {
  position: relative;
  border-radius: 0.5rem;
  padding: 0.5rem;
  margin-bottom: 1rem;
  font-family: ui-monospace, "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;
  font-size: 0.875rem;
  background-color: #f8f9fa;
  max-width: 100%;
  border: 1px solid #e5e7eb;
}

.ckeditor-content pre code {
  display: block;
  overflow-x: auto;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
  padding-right: 1rem;
  background: none;
  padding-left: 0.4rem;
  padding-top: 0;
  padding-bottom: 0;
  border-radius: 0;
  color: inherit;
}

.ckeditor-content .code-controls {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.5rem;
  z-index: 10;
}

.ckeditor-content .copy-btn,
.ckeditor-content .theme-btn {
  padding: 0.375rem;
  border-radius: 0.375rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ckeditor-content pre.light-theme {
  background-color: #f8f9fa;
  color: #1f2937;
  border-color: #e5e7eb;
}

.ckeditor-content pre.light-theme .copy-btn,
.ckeditor-content pre.light-theme .theme-btn {
  background-color: #e5e7eb;
  color: #4b5563;
}

.ckeditor-content pre.light-theme .copy-btn:hover,
.ckeditor-content pre.light-theme .theme-btn:hover {
  background-color: #d1d5db;
}

.ckeditor-content pre.dark-theme {
  background-color: #1a1a1a;
  color: #ffffff;
  border-color: #374151;
}

.ckeditor-content pre.dark-theme .copy-btn,
.ckeditor-content pre.dark-theme .theme-btn {
  background-color: #374151;
  color: #d1d5db;
}

.ckeditor-content pre.dark-theme .copy-btn:hover,
.ckeditor-content pre.dark-theme .theme-btn:hover {
  background-color: #4b5563;
}

.ckeditor-content code {
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.875rem;
  background-color: #f3f4f6;
  color: #dc2626;
  font-family: ui-monospace, "SF Mono", "Monaco", "Inconsolata", "Roboto Mono", monospace;
}

.ckeditor-content pre.dark-theme code {
  background-color: rgba(255, 255, 255, 0.1);
  color: #ff79c6;
}

/* Horizontal Rule */
.ckeditor-content hr {
  border: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, #e5e7eb, transparent);
  margin: 1.5rem 0;
}

/* Text Alignment */
.ckeditor-content .text-left {
  text-align: left;
}

.ckeditor-content .text-center {
  text-align: center;
}

.ckeditor-content .text-right {
  text-align: right;
}

.ckeditor-content .text-justify {
  text-align: justify;
}

/* Highlighted Text */
.ckeditor-content mark {
  background-color: #fef3c7;
  padding: 2px 4px;
  border-radius: 3px;
  color: #92400e;
}

/* Superscript & Subscript */
.ckeditor-content sup {
  font-size: 0.75rem;
  vertical-align: super;
}

.ckeditor-content sub {
  font-size: 0.75rem;
  vertical-align: sub;
}

/* Captions */
.ckeditor-content figcaption {
  font-size: 0.875rem;
  color: #6b7280;
  text-align: center;
  margin-top: 0.5rem;
  font-style: italic;
}

/* Responsive Embeds (YouTube, etc.) */
.ckeditor-content .media-wrapper {
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  margin: 1rem 0;
  border-radius: 0.5rem;
  overflow: hidden;
}

.ckeditor-content .media-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Definition Lists */
.ckeditor-content dl {
  margin-bottom: 1rem;
}

.ckeditor-content dt {
  font-weight: bold;
  margin-top: 1rem;
  color: #1f2937;
}

.ckeditor-content dd {
  margin-left: 1.5rem;
  margin-bottom: 0.5rem;
  color: #6b7280;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .ckeditor-content {
    font-size: 0.9rem;
  }

  .ckeditor-content h1 {
    font-size: 1.75rem;
  }

  .ckeditor-content h2 {
    font-size: 1.5rem;
  }

  .ckeditor-content h3 {
    font-size: 1.25rem;
  }

  .ckeditor-content pre {
    font-size: 0.8rem;
    padding: 0.75rem;
  }

  .ckeditor-content .code-controls {
    top: 0.25rem;
    right: 0.25rem;
    gap: 0.25rem;
  }

  .ckeditor-content .copy-btn,
  .ckeditor-content .theme-btn {
    padding: 0.25rem;
  }

  .ckeditor-content th,
  .ckeditor-content td {
    padding: 0.5rem;
    font-size: 0.875rem;
    max-width: 200px;
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .ckeditor-content {
    color: #e5e7eb;
  }

  .ckeditor-content th {
    background-color: #374151;
    color: #f9fafb;
  }

  .ckeditor-content td {
    background-color: #1f2937;
    color: #e5e7eb;
  }

  .ckeditor-content tr:nth-child(even) td {
    background-color: #374151;
  }

  .ckeditor-content th,
  .ckeditor-content td,
  .ckeditor-content table,
  .ckeditor-content .table-container {
    border-color: #4b5563;
  }

  .ckeditor-content blockquote {
    color: #9ca3af;
    border-left-color: #60a5fa;
    background-color: #1f2937;
  }

  .ckeditor-content a {
    color: #60a5fa;
  }

  .ckeditor-content a:hover {
    color: #93c5fd;
  }

  .ckeditor-content code {
    background-color: #374151;
    color: #f87171;
  }

  .ckeditor-content hr {
    background: linear-gradient(90deg, transparent, #4b5563, transparent);
  }

  .ckeditor-content mark {
    background-color: #451a03;
    color: #fbbf24;
  }
}

/* Print styles */
@media print {
  .ckeditor-content {
    max-width: 100% !important;
    color: #000 !important;
  }

  .ckeditor-content a {
    text-decoration: underline;
    color: #000 !important;
  }

  .ckeditor-content pre,
  .ckeditor-content code {
    background-color: #f8f8f8 !important;
    color: #000 !important;
    border: 1px solid #ddd;
  }

  .ckeditor-content .table-container {
    overflow-x: visible;
  }

  .ckeditor-content .code-controls {
    display: none !important;
  }

  .ckeditor-content th {
    background-color: #f0f0f0 !important;
    color: #000 !important;
  }

  .ckeditor-content td {
    background-color: #fff !important;
    color: #000 !important;
  }
}
