/**
 * Future-Proof Rich Text Editor Styles for DigiReply Forum
 * Self-contained styling that matches your forum theme
 */

/* Editor Container */
.rich-editor-container {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: white;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.rich-editor-container:focus-within {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Toolbar Styles */
.rich-editor-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    gap: 4px;
    flex-wrap: wrap;
    min-height: 48px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: #d1d5db;
    margin: 0 6px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    transition: all 0.2s;
    position: relative;
    outline: none;
}

.toolbar-btn:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.toolbar-btn.active {
    background: #dbeafe;
    color: #1d4ed8;
}

.toolbar-btn:active {
    transform: scale(0.95);
}

.toolbar-btn:focus {
    box-shadow: 0 0 0 2px #2563eb;
}

/* Icon styles */
.toolbar-btn i {
    font-size: 14px;
}

/* Content Editor */
.rich-editor-content {
    padding: 12px;
    outline: none;
    overflow-y: auto;
    line-height: 1.6;
    color: #374151;
    font-size: 14px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    position: relative;
}

.rich-editor-content:focus {
    outline: none;
}

/* Placeholder */
.rich-editor-content:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
    pointer-events: none;
    position: absolute;
    top: 12px;
    left: 12px;
}

.rich-editor-content.focused:empty:before {
    opacity: 0.7;
}

/* Content Styling */
.rich-editor-content p {
    margin: 0 0 8px 0;
}

.rich-editor-content p:last-child {
    margin-bottom: 0;
}

/* Headings */
.rich-editor-content h1 {
    font-size: 24px;
    font-weight: 700;
    margin: 16px 0 8px 0;
    color: #1f2937;
    line-height: 1.3;
}

.rich-editor-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 14px 0 6px 0;
    color: #1f2937;
    line-height: 1.3;
}

.rich-editor-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 12px 0 6px 0;
    color: #1f2937;
    line-height: 1.3;
}

.rich-editor-content h4,
.rich-editor-content h5,
.rich-editor-content h6 {
    font-size: 16px;
    font-weight: 600;
    margin: 10px 0 4px 0;
    color: #1f2937;
    line-height: 1.3;
}

/* Text formatting */
.rich-editor-content strong {
    font-weight: 700;
}

.rich-editor-content em {
    font-style: italic;
}

.rich-editor-content u {
    text-decoration: underline;
}

/* Lists */
.rich-editor-content ul,
.rich-editor-content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.rich-editor-content li {
    margin: 2px 0;
}

.rich-editor-content ul {
    list-style-type: disc;
}

.rich-editor-content ol {
    list-style-type: decimal;
}

/* Nested lists */
.rich-editor-content ul ul,
.rich-editor-content ol ol,
.rich-editor-content ul ol,
.rich-editor-content ol ul {
    margin: 0;
    padding-left: 20px;
}

/* Blockquotes */
.rich-editor-content blockquote {
    border-left: 4px solid #d1d5db;
    padding-left: 16px;
    margin: 12px 0;
    color: #6b7280;
    font-style: italic;
    background: #f9fafb;
    padding: 12px 16px;
    border-radius: 0 4px 4px 0;
}

/* Links */
.rich-editor-content a {
    color: #2563eb;
    text-decoration: underline;
    cursor: pointer;
}

.rich-editor-content a:hover {
    color: #1d4ed8;
}

/* Inline Code */
.rich-editor-content code {
    background: #f3f4f6;
    color: #ef4444;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
}

/* Code Blocks */
.rich-editor-content pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
    overflow-x: auto;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
}

.rich-editor-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

/* Selection */
.rich-editor-content ::selection {
    background: rgba(37, 99, 235, 0.2);
}

/* Line breaks */
.rich-editor-content br {
    line-height: 1.6;
}

/* Dark Mode Support */
body.dark-mode .rich-editor-container {
    background: #2d2d2d;
    border-color: #444444;
}

body.dark-mode .rich-editor-toolbar {
    background: #374151;
    border-bottom-color: #4b5563;
}

body.dark-mode .toolbar-btn {
    color: #e5e7eb;
}

body.dark-mode .toolbar-btn:hover {
    background: #4b5563;
    color: #f9fafb;
}

body.dark-mode .toolbar-btn.active {
    background: #1e40af;
    color: #dbeafe;
}

body.dark-mode .toolbar-separator {
    background: #6b7280;
}

body.dark-mode .rich-editor-content {
    color: #e5e7eb;
}

body.dark-mode .rich-editor-content:empty:before {
    color: #6b7280;
}

body.dark-mode .rich-editor-content h1,
body.dark-mode .rich-editor-content h2,
body.dark-mode .rich-editor-content h3,
body.dark-mode .rich-editor-content h4,
body.dark-mode .rich-editor-content h5,
body.dark-mode .rich-editor-content h6 {
    color: #f9fafb;
}

body.dark-mode .rich-editor-content blockquote {
    border-left-color: #6b7280;
    color: #9ca3af;
    background: #374151;
}

body.dark-mode .rich-editor-content code {
    background: #374151;
    color: #fca5a5;
}

body.dark-mode .rich-editor-content pre {
    background: #111827;
    color: #f3f4f6;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .rich-editor-toolbar {
        padding: 6px 8px;
        gap: 2px;
    }
    
    .toolbar-btn {
        width: 28px;
        height: 28px;
        font-size: 11px;
    }
    
    .toolbar-separator {
        margin: 0 3px;
        height: 20px;
    }
    
    .rich-editor-content {
        padding: 10px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Hide some toolbar buttons on very small screens */
    @media (max-width: 480px) {
        .toolbar-btn[data-command="underline"],
        .toolbar-btn[data-command="h3"],
        .toolbar-btn[data-command="removeFormat"] {
            display: none;
        }
    }
}

/* Loading and Error States */
.rich-editor-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #6b7280;
    font-size: 14px;
}

.rich-editor-error {
    padding: 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    color: #dc2626;
    font-size: 14px;
    text-align: center;
}

body.dark-mode .rich-editor-error {
    background: #451a1a;
    border-color: #991b1b;
    color: #fca5a5;
}

/* Animation for button presses */
.toolbar-btn {
    transition: all 0.15s ease;
}

.toolbar-btn:active {
    transition: all 0.05s ease;
}

/* Focus indicators for accessibility */
.rich-editor-content:focus {
    box-shadow: inset 0 0 0 1px #2563eb;
}

/* Ensure proper spacing in lists */
.rich-editor-content li p {
    margin: 0;
}

/* Handle empty editor state */
.rich-editor-content:empty {
    min-height: 20px;
}

/* Improved blockquote appearance */
.rich-editor-content blockquote {
    position: relative;
}

.rich-editor-content blockquote:before {
    content: '"';
    font-size: 24px;
    font-weight: bold;
    color: #d1d5db;
    position: absolute;
    left: -8px;
    top: -4px;
}

body.dark-mode .rich-editor-content blockquote:before {
    color: #6b7280;
}