/* TinyMCE Editor Styling */
.tinymce-editor-container {
    border: 1px solid #ced4da;
    border-radius: 0.375rem;
    overflow: hidden;
    min-height: 650px; /* Ensure adequate space for the editor */
}

.tinymce-editor-loading {
    opacity: 0.6;
    pointer-events: none;
}

.tinymce-editor-error {
    border-color: #dc3545;
}

.tinymce-editor-error::after {
    content: "Error loading editor";
    color: #dc3545;
    font-size: 0.875rem;
    display: block;
    margin-top: 0.25rem;
}

/* Enhanced TinyMCE Editor Appearance */
.tox-tinymce {
    border-radius: 0.375rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.tox-toolbar {
    border-bottom: 1px solid #e5e7eb !important;
    flex-wrap: wrap !important;
}

.tox-toolbar__primary {
    flex-wrap: wrap !important;
}

.tox-toolbar__group {
    flex-shrink: 0 !important;
}

.tox-statusbar {
    border-top: 1px solid #e5e7eb !important;
}

/* Improve toolbar button spacing in single row mode */
.tox-tbtn {
    margin: 1px !important;
}

.tox-toolbar__group:not(:last-child) {
    border-right: 1px solid #e5e7eb !important;
    margin-right: 4px !important;
    padding-right: 4px !important;
}

/* Swiss Learning Content Styles (for editor content) */
.swiss-learning-lesson {
    border: 2px solid #3b82f6;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    background-color: #eff6ff;
}

.swiss-learning-lesson h2 {
    color: #1d4ed8;
    margin-top: 0;
    border-bottom: 2px solid #3b82f6;
    padding-bottom: 10px;
}

.lesson-objectives {
    background-color: #dbeafe;
    border-radius: 6px;
    padding: 15px;
    margin: 15px 0;
}

.lesson-objectives h3 {
    color: #1e40af;
    margin-top: 0;
    margin-bottom: 10px;
}

.lesson-objectives ul {
    margin-bottom: 0;
}

.lesson-content {
    margin-top: 15px;
}

.swiss-learning-exercise {
    border: 2px solid #10b981;
    border-radius: 8px;
    padding: 20px;
    margin: 20px 0;
    background-color: #f0fdf4;
}

.swiss-learning-exercise h3 {
    color: #047857;
    margin-top: 0;
    border-bottom: 2px solid #10b981;
    padding-bottom: 10px;
}

.exercise-instructions {
    background-color: #dcfce7;
    border-radius: 6px;
    padding: 15px;
    margin: 15px 0;
}

.exercise-content {
    margin-top: 15px;
}

.swiss-learning-note {
    border: 2px solid #f59e0b;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    background-color: #fffbeb;
}

.swiss-learning-note h4 {
    color: #d97706;
    margin-top: 0;
    margin-bottom: 10px;
}

.swiss-learning-tip {
    border: 2px solid #8b5cf6;
    border-radius: 8px;
    padding: 15px;
    margin: 15px 0;
    background-color: #faf5ff;
}

.swiss-learning-tip h4 {
    color: #7c3aed;
    margin-top: 0;
    margin-bottom: 10px;
}

/* Enhanced table styles */
.mce-content-body table,
.tox-tinymce table {
    border-collapse: collapse;
    margin: 15px 0;
    width: 100%;
    background-color: white;
}

/* Apply constraints only to tables that might overflow */
.mce-content-body table:not(.no-scroll),
.tox-tinymce table:not(.no-scroll) {
    max-width: 100%;
    overflow-x: auto;
    display: block;
    white-space: nowrap;
}

/* Responsive table wrapper for small screens */
@media (max-width: 768px) {
    .mce-content-body table:not(.no-scroll),
    .tox-tinymce table:not(.no-scroll) {
        font-size: 0.875rem;
    }
}

.mce-content-body table.table,
.tox-tinymce table.table {
    border: 1px solid #dee2e6;
}

.mce-content-body table.table th,
.mce-content-body table.table td,
.tox-tinymce table th,
.tox-tinymce table td {
    border: 1px solid #dee2e6;
    padding: 12px;
    text-align: left;
}

.mce-content-body table.table th,
.tox-tinymce table th {
    background-color: #f8f9fa;
    font-weight: 600;
    border-bottom: 2px solid #dee2e6;
}

.mce-content-body table.table-striped tbody tr:nth-of-type(odd) {
    background-color: #f9f9f9;
}

.mce-content-body table.table-bordered {
    border: 2px solid #dee2e6;
}

.mce-content-body table.table-bordered th,
.mce-content-body table.table-bordered td {
    border: 1px solid #dee2e6;
}

.mce-content-body table.table-hover tbody tr:hover {
    background-color: #f5f5f5;
}

.mce-content-body table.table-sm th,
.mce-content-body table.table-sm td {
    padding: 6px;
}

/* Enhanced blockquote styles */
.mce-content-body blockquote {
    border-left: 4px solid #3b82f6;
    margin: 20px 0;
    padding: 15px 20px;
    background-color: #f8fafc;
    font-style: italic;
    color: #475569;
    border-radius: 0 6px 6px 0;
}

/* Targeted constraints for TinyMCE content elements that might overflow */
.mce-content-body img,
.mce-content-body video,
.mce-content-body canvas {
    max-width: 100%;
    height: auto;
}

.mce-content-body blockquote::before {
    content: '"';
    font-size: 2em;
    color: #3b82f6;
    line-height: 0.1em;
    margin-right: 0.25em;
    vertical-align: -0.4em;
}

.mce-content-body blockquote::after {
    content: '"';
    font-size: 2em;
    color: #3b82f6;
    line-height: 0.1em;
    margin-left: 0.25em;
    vertical-align: -0.4em;
}

/* Enhanced code styles */
.mce-content-body code {
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
    color: #dc2626;
    word-break: break-all;
}

.mce-content-body pre {
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 16px;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
    line-height: 1.5;
    color: #334155;
    max-width: 100%;
}

.mce-content-body pre code {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
}

/* Enhanced image styles */
.mce-content-body img.img-responsive {
    max-width: 100%;
    height: auto;
}

.mce-content-body img.img-rounded {
    border-radius: 6px;
}

.mce-content-body img.img-circle {
    border-radius: 50%;
}

.mce-content-body img.img-thumbnail {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 4px;
    background-color: white;
    max-width: 100%;
    height: auto;
}

/* Enhanced list styles */
.mce-content-body ul,
.mce-content-body ol {
    padding-left: 30px;
    margin: 15px 0;
}

.mce-content-body ul li,
.mce-content-body ol li {
    margin-bottom: 8px;
    line-height: 1.6;
}

.mce-content-body ul ul,
.mce-content-body ol ol,
.mce-content-body ul ol,
.mce-content-body ol ul {
    margin: 8px 0;
}

/* Enhanced heading styles */
.mce-content-body h1,
.mce-content-body h2,
.mce-content-body h3,
.mce-content-body h4,
.mce-content-body h5,
.mce-content-body h6 {
    font-weight: 600;
    line-height: 1.25;
    margin-top: 24px;
    margin-bottom: 16px;
    color: #1f2937;
}

.mce-content-body h1 {
    font-size: 2.25em;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 8px;
}

.mce-content-body h2 {
    font-size: 1.875em;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 6px;
}

.mce-content-body h3 {
    font-size: 1.5em;
}

.mce-content-body h4 {
    font-size: 1.25em;
}

.mce-content-body h5 {
    font-size: 1.125em;
}

.mce-content-body h6 {
    font-size: 1em;
    color: #6b7280;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .swiss-learning-lesson,
    .swiss-learning-exercise,
    .swiss-learning-note,
    .swiss-learning-tip {
        padding: 15px;
        margin: 15px 0;
    }
    
    .lesson-objectives,
    .exercise-instructions {
        padding: 10px;
    }
    
    .mce-content-body {
        padding: 10px;
    }
}
