/**
 * Assignment Title Rich Text Editor Override Styles
 * 
 * Custom styles for the assignment title rich text editor override
 * 
 * @version 1.0.0
 * @author IFD Development Team
 */

/* Assignment Title Editor Wrapper */
.assignment-title-editor-wrapper {
    width: 100%;
    margin: 0;
    position: relative;
    border-radius: 4px;
    overflow: hidden;
}

/* TinyMCE Editor Overrides for Assignment Title */
.assignment-title-editor-wrapper .tox-tinymce {
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    box-shadow: none !important;
}

.assignment-title-editor-wrapper .tox-editor-header {
    background: #f8f9fa !important;
    border-bottom: 1px solid #ddd !important;
    padding: 4px 8px !important;
}

.assignment-title-editor-wrapper .tox-toolbar {
    background: transparent !important;
    border: none !important;
    padding: 4px !important;
}

.assignment-title-editor-wrapper .tox-toolbar__group {
    margin: 0 4px 0 0 !important;
}

.assignment-title-editor-wrapper .tox-tbtn {
    width: 28px !important;
    height: 28px !important;
    margin: 0 2px !important;
    border-radius: 3px !important;
    background: white !important;
    border: 1px solid #ddd !important;
}

.assignment-title-editor-wrapper .tox-tbtn:hover {
    background: #e9ecef !important;
    border-color: #007cba !important;
}

.assignment-title-editor-wrapper .tox-tbtn--enabled {
    background: #007cba !important;
    color: white !important;
    border-color: #007cba !important;
}

.assignment-title-editor-wrapper .tox-edit-area {
    border: none !important;
}

.assignment-title-editor-wrapper .tox-edit-area__iframe {
    border: none !important;
    background: white !important;
}

/* Custom Toolbar Styles (for fallback) */
.assignment-title-toolbar {
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    padding: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.assignment-title-toolbar button {
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 4px 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 12px;
    color: #333;
    transition: all 0.2s ease;
    min-width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.assignment-title-toolbar button:hover {
    background: #e9ecef;
    border-color: #007cba;
    color: #007cba;
}

.assignment-title-toolbar button:active {
    background: #007cba;
    color: white;
    border-color: #007cba;
}

/* Enhanced Textarea Styles */
.assignment-title-editor-wrapper textarea {
    width: 100% !important;
    min-height: 120px;
    border: 1px solid #ddd;
    border-radius: 0 0 4px 4px;
    padding: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    resize: vertical;
    background: white;
    color: #333;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.assignment-title-editor-wrapper textarea:focus {
    border-color: #007cba;
    box-shadow: 0 0 0 1px rgba(0, 124, 186, 0.1);
}

/* Chakra UI Compatibility */
.chakra-input__group .assignment-title-editor-wrapper {
    border: none;
    border-radius: 0;
}

.chakra-input__group .assignment-title-editor-wrapper .tox-tinymce {
    border-radius: 0 !important;
}

.chakra-input__group .assignment-title-editor-wrapper textarea {
    border-radius: 0;
}

/* Make sure the editor fits within Chakra UI containers */
.chakra-form-control .assignment-title-editor-wrapper {
    width: 100%;
    max-width: 100%;
}

.chakra-input__group .assignment-title-editor-wrapper {
    flex: 1;
    min-width: 0;
}

/* Hide the original input when our editor is active */
.assignment-title-editor-wrapper + input[style*="display: none"] {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .assignment-title-toolbar {
        padding: 6px;
        gap: 4px;
    }
    
    .assignment-title-toolbar button {
        min-width: 24px;
        height: 24px;
        padding: 2px 6px;
        font-size: 11px;
    }
    
    .assignment-title-editor-wrapper textarea {
        min-height: 100px;
        padding: 10px;
    }
    
    .assignment-title-editor-wrapper .tox-toolbar__group {
        margin: 0 2px 0 0 !important;
    }
    
    .assignment-title-editor-wrapper .tox-tbtn {
        width: 24px !important;
        height: 24px !important;
        margin: 0 1px !important;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .assignment-title-editor-wrapper .tox-tinymce {
        border-color: #444 !important;
        background: #2d2d2d !important;
    }
    
    .assignment-title-editor-wrapper .tox-editor-header {
        background: #3a3a3a !important;
        border-bottom-color: #444 !important;
    }
    
    .assignment-title-editor-wrapper .tox-tbtn {
        background: #2d2d2d !important;
        border-color: #444 !important;
        color: #ccc !important;
    }
    
    .assignment-title-editor-wrapper .tox-tbtn:hover {
        background: #444 !important;
        border-color: #007cba !important;
    }
    
    .assignment-title-toolbar {
        background: #3a3a3a;
        border-color: #444;
    }
    
    .assignment-title-toolbar button {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }
    
    .assignment-title-toolbar button:hover {
        background: #444;
        border-color: #007cba;
        color: #007cba;
    }
    
    .assignment-title-editor-wrapper textarea {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }
    
    .assignment-title-editor-wrapper textarea:focus {
        border-color: #007cba;
        box-shadow: 0 0 0 1px rgba(0, 124, 186, 0.2);
    }
}

/* Animation for smooth transitions */
.assignment-title-editor-wrapper {
    animation: fadeIn 0.3s ease-in-out;
}

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

/* Loading state */
.assignment-title-editor-wrapper.loading {
    position: relative;
}

.assignment-title-editor-wrapper.loading::after {
    content: "Loading rich text editor...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 14px;
    color: #666;
    z-index: 1000;
}

/* Error state */
.assignment-title-editor-wrapper.error {
    border: 1px solid #dc3545;
    border-radius: 4px;
}

.assignment-title-editor-wrapper.error::before {
    content: "⚠️ Rich text editor failed to load. Using enhanced textarea.";
    display: block;
    background: #f8d7da;
    color: #721c24;
    padding: 8px;
    font-size: 12px;
    border-bottom: 1px solid #dc3545;
}

/* Success state indicator */
.assignment-title-editor-wrapper.initialized::before {
    content: "✓ Rich text editor loaded successfully";
    display: block;
    background: #d4edda;
    color: #155724;
    padding: 4px 8px;
    font-size: 11px;
    text-align: center;
    animation: successFade 3s ease-in-out;
}

@keyframes successFade {
    0% { opacity: 1; }
    70% { opacity: 1; }
    100% { opacity: 0; display: none; }
}

/* Ensure proper spacing in form layouts */
.assignment-title-editor-wrapper + .chakra-form__error-message,
.assignment-title-editor-wrapper + .chakra-form__helper-text {
    margin-top: 8px;
}

/* Integration with MasterStudy form styles */
.stm-lms-wrapper .assignment-title-editor-wrapper,
.masterstudy-single-course .assignment-title-editor-wrapper {
    font-family: inherit;
}

.stm-lms-wrapper .assignment-title-editor-wrapper .tox-tinymce,
.masterstudy-single-course .assignment-title-editor-wrapper .tox-tinymce {
    font-family: inherit;
}

/* Print styles */
@media print {
    .assignment-title-toolbar,
    .assignment-title-editor-wrapper .tox-editor-header {
        display: none !important;
    }
    
    .assignment-title-editor-wrapper textarea,
    .assignment-title-editor-wrapper .tox-edit-area__iframe {
        border: none !important;
        box-shadow: none !important;
    }
}