/* ===================================
   Prose Editor Styles
   Shared styles for prose editor functionality
   =================================== */

/* Prose Editor Output Styles */
.prose-editor-output blockquote,
.ProseMirror blockquote {
    margin: 2rem 0;
    padding: 1.5rem 2rem;
    border-left: 5px solid #0d6efd;
    background: linear-gradient(135deg, #f8f9fa 0%, #e3f2fd 100%);
    font-style: italic;
    color: #212529;
    position: relative;
    border-radius: 0 8px 8px 0;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.1);
    transition: all 0.3s ease;
}

.prose-editor-output blockquote::before,
.ProseMirror blockquote::before {
    content: '"';
    font-size: 4rem;
    color: #0d6efd;
    position: absolute;
    left: 0.75rem;
    top: -0.75rem;
    font-family: Georgia, serif;
    opacity: 0.15;
    line-height: 1;
}

.prose-editor-output blockquote p,
.ProseMirror blockquote p {
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.7;
    position: relative;
    z-index: 1;
}

.prose-editor-output blockquote p:last-child,
.ProseMirror blockquote p:last-child {
    margin-bottom: 0;
}

.prose-editor-output blockquote p strong,
.ProseMirror blockquote p strong {
    color: #0d6efd;
    font-weight: 700;
}

.prose-editor-output blockquote p em,
.ProseMirror blockquote p em {
    color: #495057;
}

/* Hover effect for blockquotes in editor */
.ProseMirror blockquote:hover {
    background: linear-gradient(135deg, #e9ecef 0%, #d4e9ff 100%);
    box-shadow: 0 4px 12px rgba(13, 110, 253, 0.15);
    transform: translateX(4px);
}

/* Dark Mode Blockquote Styles */
body.dark-mode .prose-editor-output blockquote,
body.dark-mode .ProseMirror blockquote {
    border-left-color: #4dabf7;
    background: linear-gradient(135deg, #2d2d2d 0%, #1e3a5f 100%);
    color: #e0e0e0;
    box-shadow: 0 2px 8px rgba(77, 171, 247, 0.15);
}

body.dark-mode .prose-editor-output blockquote::before,
body.dark-mode .ProseMirror blockquote::before {
    color: #4dabf7;
    opacity: 0.2;
}

body.dark-mode .prose-editor-output blockquote p strong,
body.dark-mode .ProseMirror blockquote p strong {
    color: #74c0fc;
}

body.dark-mode .prose-editor-output blockquote p em,
body.dark-mode .ProseMirror blockquote p em {
    color: #b0b0b0;
}

body.dark-mode .ProseMirror blockquote:hover {
    background: linear-gradient(135deg, #3a3a3a 0%, #2a4a6f 100%);
    box-shadow: 0 4px 12px rgba(77, 171, 247, 0.2);
    transform: translateX(4px);
}

/* Editor Mode Styles */
.prose-editor {
    min-height: 300px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
}

.prose-editor-toolbar {
    border-bottom: 1px solid #ddd;
    padding: 8px;
    background-color: #f8f9fa;
}

/* Prose Editor Loading States - Prevents FOUC */
textarea[data-django-prose-editor-configurable] {
    /* Style the textarea to look more like the final editor */
    min-height: 300px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    padding: 12px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background-color: #ffffff;
    transition: all 0.3s ease;
    resize: vertical;
}

textarea[data-django-prose-editor-configurable]:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: 0;
}

/* Loading state for prose editor initialization */
.prose-editor-loading {
    position: relative;
}

/* Hide the textarea while loading */
.prose-editor-loading textarea[data-django-prose-editor-configurable] {
    opacity: 0;
    pointer-events: none;
}

.prose-editor-loading::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #ffffff;
    border: 1px solid #ced4da;
    border-radius: 6px;
    z-index: 10;
    min-height: 300px;
}

.prose-editor-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007bff;
    border-radius: 50%;
    z-index: 11;
    animation: spin 1s linear infinite;
}

/* Add loading text below the spinner */
.prose-editor-loading .loading-text {
    position: absolute;
    top: 60%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: #6c757d;
    z-index: 11;
    font-weight: 500;
    text-align: center;
    margin-top: 30px;
    white-space: nowrap;
}

@keyframes spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Show the textarea and hide loading state once editor is initialized */
.prose-editor-initialized textarea[data-django-prose-editor-configurable] {
    opacity: 1;
    pointer-events: auto;
}

.prose-editor-initialized::before,
.prose-editor-initialized::after,
.prose-editor-initialized .loading-text {
    display: none;
}

/* Smooth transition when editor initializes */
.prose-editor-container {
    transition: opacity 0.3s ease;
}

.prose-editor-container.initializing {
    opacity: 0.9;
}

.prose-editor-container.initialized {
    opacity: 1;
}

/* ProseMirror editor styling improvements */
.ProseMirror {
    min-height: 250px;
    padding: 12px;
    border: 1px solid #ced4da;
    border-radius: 0 0 6px 6px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background-color: #ffffff;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.ProseMirror:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
    outline: 0;
}

/* Make empty paragraphs take up space for visual spacing */
.ProseMirror p:empty::before,
.prose-editor-output p:empty::before {
    content: '\00a0';
    display: inline;
}

/* Constrain images to container width */
.ProseMirror img,
.prose-editor-output img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 1rem 0;
}

/* Image selection styling in light mode */
.ProseMirror img.ProseMirror-selectednode {
    outline: 3px solid #007bff;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Image alignment based on image's own text-align style */
.ProseMirror img[style*="text-align: center"],
.prose-editor-output img[style*="text-align: center"] {
    margin-left: auto;
    margin-right: auto;
}

.ProseMirror img[style*="text-align: right"],
.prose-editor-output img[style*="text-align: right"] {
    margin-left: auto;
    margin-right: 0;
}

.ProseMirror img[style*="text-align: left"],
.prose-editor-output img[style*="text-align: left"] {
    margin-left: 0;
    margin-right: auto;
}

/* Also support alignment based on parent container */
.ProseMirror[style*="text-align: center"] img,
.ProseMirror p[style*="text-align: center"] img,
.prose-editor-output[style*="text-align: center"] img,
.prose-editor-output p[style*="text-align: center"] img {
    margin-left: auto;
    margin-right: auto;
}

.ProseMirror[style*="text-align: right"] img,
.ProseMirror p[style*="text-align: right"] img,
.prose-editor-output[style*="text-align: right"] img,
.prose-editor-output p[style*="text-align: right"] img {
    margin-left: auto;
    margin-right: 0;
}

.ProseMirror[style*="text-align: left"] img,
.ProseMirror p[style*="text-align: left"] img,
.prose-editor-output[style*="text-align: left"] img,
.prose-editor-output p[style*="text-align: left"] img {
    margin-left: 0;
    margin-right: auto;
}

/* Toolbar styling to match Bootstrap */
.ProseMirror-menubar {
    background-color: #f8f9fa;
    border: 1px solid #ced4da;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.ProseMirror-menu-item {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 6px 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: #495057;
}

.ProseMirror-menu-item:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.ProseMirror-menu-item.ProseMirror-menu-active {
    background-color: #007bff;
    border-color: #007bff;
    color: white;
}

/* Loading spinner animation */
@keyframes prose-editor-loading {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

.prose-editor-loading::before {
    background: linear-gradient(90deg, #f8f9fa 0%, #e9ecef 50%, #f8f9fa 100%);
    background-size: 200px 100%;
    animation: prose-editor-loading 1.5s ease-in-out infinite;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    .prose-editor {
        min-height: 200px;
    }
}

/* Dark Mode Styles */
body.dark-mode textarea[data-django-prose-editor-configurable] {
    background-color: #3a3a3a;
    border-color: #505050;
    color: #ffffff;
}

body.dark-mode textarea[data-django-prose-editor-configurable]:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

body.dark-mode .prose-editor-loading::before {
    background: #2d2d2d;
    border-color: #505050;
}

body.dark-mode .prose-editor-loading::after {
    border-color: #404040;
    border-top-color: #0d6efd;
}

body.dark-mode .prose-editor-loading .loading-text {
    color: #b0b0b0;
}

body.dark-mode .ProseMirror {
    background-color: #3a3a3a;
    border-color: #505050;
    color: #ffffff;
}

body.dark-mode .ProseMirror:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

body.dark-mode .ProseMirror h1,
body.dark-mode .ProseMirror h2,
body.dark-mode .ProseMirror h3,
body.dark-mode .ProseMirror h4,
body.dark-mode .ProseMirror h5,
body.dark-mode .ProseMirror h6 {
    color: #ffffff;
}

body.dark-mode .ProseMirror p {
    color: #e0e0e0;
}

body.dark-mode .ProseMirror a {
    color: #4dabf7;
}

body.dark-mode .ProseMirror a:hover {
    color: #74c0fc;
}

body.dark-mode .ProseMirror-menubar {
    background-color: #2d2d2d;
    border-color: #404040;
}

body.dark-mode .ProseMirror-menu-item {
    color: #e0e0e0;
}

body.dark-mode .ProseMirror-menu-item:hover {
    background-color: #3a3a3a;
    border-color: #505050;
}

body.dark-mode .ProseMirror-menu-item.ProseMirror-menu-active {
    background-color: #0d6efd;
    border-color: #0d6efd;
    color: #ffffff;
}

/* Image Upload Loading Spinner */
.prose-editor-upload-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    border-radius: 6px;
    backdrop-filter: blur(2px);
}

.prose-editor-upload-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.prose-editor-upload-overlay .upload-text {
    margin-top: 16px;
    font-size: 16px;
    font-weight: 500;
    color: #495057;
}

.prose-editor-upload-overlay .upload-subtext {
    margin-top: 8px;
    font-size: 14px;
    color: #6c757d;
}

/* Dark mode styles for upload overlay */
body.dark-mode .prose-editor-upload-overlay {
    background: rgba(45, 45, 45, 0.95);
}

body.dark-mode .prose-editor-upload-overlay .spinner {
    border-color: #404040;
    border-top-color: #0d6efd;
}

body.dark-mode .prose-editor-upload-overlay .upload-text {
    color: #e0e0e0;
}

body.dark-mode .prose-editor-upload-overlay .upload-subtext {
    color: #b0b0b0;
}
