/**
 * Professional Rich Text Editor Styles
 * Following WordPress Gutenberg design patterns
 */

/* Main Editor Container */
.rich-text-editor {
    border: 1px solid var(--editor-border);
    border-radius: 8px;
    background-color: var(--editor-bg);
    overflow: hidden;
    position: relative;
    height: 600px; /* Fixed height instead of min-height */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    resize: vertical; /* Allow vertical resizing */
    min-height: 400px; /* Minimum height */
    max-height: 1200px; /* Maximum height */
}

/* Resize handle styling */
.rich-text-editor::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 12px 12px;
    border-color: transparent transparent var(--editor-border) transparent;
    cursor: se-resize;
    z-index: 100;
}

.rich-text-editor:hover::after {
    border-color: transparent transparent var(--editor-button-hover) transparent;
}

/* Professional Toolbar */
.editor-toolbar {
    background-color: var(--editor-toolbar-bg);
    border-bottom: 1px solid var(--editor-toolbar-border);
    padding: 8px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    min-height: 48px;
    overflow-x: auto; /* Allow horizontal scrolling if needed */
    overflow-y: hidden;
    flex-shrink: 0; /* Prevent toolbar from shrinking */
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Toolbar Sections */
.toolbar-section {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-right: 1px solid var(--editor-toolbar-border);
    min-width: 0; /* Allow sections to shrink */
    flex-shrink: 0; /* Prevent sections from shrinking too much */
}

.toolbar-section:last-child {
    border-right: none;
}

/* Ensure all toolbar elements are visible */
.toolbar-section,
.toolbar-group,
.toolbar-btn,
.toolbar-select {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Debug: Add borders to see all sections */
.toolbar-section {
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Toolbar Groups */
.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Professional Toolbar Buttons */
.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 6px 8px;
    background-color: var(--editor-button-bg);
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--editor-button-text);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s ease;
    position: relative;
}

.toolbar-btn:hover {
    background-color: var(--editor-button-hover);
    border-color: var(--editor-button-hover);
    color: white;
    transform: translateY(-1px);
}

.toolbar-btn.active {
    background-color: var(--editor-button-active);
    border-color: var(--editor-button-active);
    color: white;
}

.toolbar-btn:active {
    transform: translateY(0);
}

/* Button with text */
.toolbar-btn.has-text {
    min-width: auto;
    padding: 6px 12px;
    gap: 6px;
}

.toolbar-btn.has-text span {
    font-size: 12px;
    font-weight: 500;
}

/* Color picker buttons */
.toolbar-btn.color-btn {
    background: linear-gradient(135deg, var(--editor-button-bg) 0%, rgba(45, 112, 150, 0.1) 100%);
    border: 1px solid rgba(45, 112, 150, 0.3);
    position: relative;
    overflow: hidden;
}

.toolbar-btn.color-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(45deg, transparent 30%, rgba(255, 255, 255, 0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.toolbar-btn.color-btn:hover::before {
    transform: translateX(100%);
}

.toolbar-btn.color-btn:hover {
    background: linear-gradient(135deg, var(--editor-button-hover) 0%, rgba(45, 112, 150, 0.2) 100%);
    border-color: var(--editor-button-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(45, 112, 150, 0.3);
}

.toolbar-btn.color-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(45, 112, 150, 0.2);
}

/* Toolbar Select Dropdowns */
.toolbar-select {
    padding: 6px 10px;
    background-color: var(--editor-bg);
    border: 1px solid var(--editor-border);
    border-radius: 4px;
    color: var(--editor-button-text);
    font-size: 13px;
    cursor: pointer;
    min-width: 100px;
    transition: all 0.2s ease;
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--editor-button-hover);
    box-shadow: 0 0 0 2px rgba(45, 112, 150, 0.2);
}

.toolbar-select:hover {
    border-color: var(--editor-button-hover);
}

/* Content Area */
.editor-content {
    padding: 20px;
    flex: 1; /* Take remaining space */
    color: var(--text-color);
    font-size: 1rem;
    line-height: 1.6;
    outline: none;
    background-color: var(--editor-content-bg);
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
}

/* Custom Scrollbar Styling - Site-wide theme */
.editor-content::-webkit-scrollbar {
    width: 8px;
    background-color: rgba(0, 0, 0, 0.1);
}

.editor-content::-webkit-scrollbar-thumb {
    background-color: var(--editor-border);
    border-radius: 4px;
}

.editor-content::-webkit-scrollbar-thumb:hover {
    background-color: var(--editor-button-hover);
}

/* Firefox Scrollbar Styling */
.editor-content {
    scrollbar-width: thin;
    scrollbar-color: var(--editor-border) rgba(0, 0, 0, 0.1);
}

/* Fix cursor visibility on dark theme */
.editor-content {
    caret-color: #ffffff !important; /* White cursor - force override */
}

/* Ensure cursor is visible when typing */
.editor-content:focus {
    outline: none;
    caret-color: #ffffff !important; /* White cursor when focused - force override */
}

/* Ensure cursor is visible in all browsers and override inline styles */
.editor-content *,
.editor-content *:focus,
.editor-content span,
.editor-content p,
.editor-content div {
    caret-color: #ffffff !important; /* Force white cursor for all elements */
}

/* Override pasted content with dark backgrounds */
.editor-content [style*="color: black"],
.editor-content [style*="color:#000"],
.editor-content [style*="color:black"] {
    caret-color: #ffffff !important;
}

/* Placeholder text */
.editor-content:empty::before {
    content: 'Start writing your blog post here...';
    color: var(--editor-placeholder);
    font-style: italic;
    pointer-events: none;
}

/* Professional editor wrapper */
.professional-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
}

/* Line spacing options */
.editor-content[style*="line-height: 1.2"] {
    line-height: 1.2 !important;
}

.editor-content[style*="line-height: 1.4"] {
    line-height: 1.4 !important;
}

.editor-content[style*="line-height: 1.6"] {
    line-height: 1.6 !important;
}

.editor-content[style*="line-height: 1.8"] {
    line-height: 1.8 !important;
}

/* Text Selection */
.editor-content::selection {
    background-color: var(--editor-selection);
}

.editor-content::-moz-selection {
    background-color: var(--editor-selection);
}

/* Font Manager Applied Fonts - Use their own font-family, don't inherit */
.editor-content [data-font-applied] {
    /* Remove inheritance, let element use its own font-family style */
}

/* Content Styling */
.editor-content h1,
.editor-content h2,
.editor-content h3,
.editor-content h4,
.editor-content h5,
.editor-content h6 {
    color: var(--text-color);
    margin: 0.75em 0 0.25em 0;
    font-weight: 600;
    line-height: 1.3;
}

.editor-content h1 { font-size: 2em; }
.editor-content h2 { font-size: 1.75em; }
.editor-content h3 { font-size: 1.5em; }
.editor-content h4 { font-size: 1.25em; }
.editor-content h5 { font-size: 1.1em; }
.editor-content h6 { font-size: 1em; }

.editor-content p {
    margin: 0.75rem 0;
    line-height: 1.6;
}

.editor-content ul,
.editor-content ol {
    margin: 1em 0;
    padding-left: 1.8em;
    list-style-position: inside;
}

/* Normalize Quill/DOM quirks where list items contain paragraphs */
.editor-content li > p {
    display: inline;
    margin: 0;
    padding: 0;
}

/* Guard against accidental clear on list paragraphs from pasted content */
.editor-content li > p[style*="clear"],
.editor-content li[style*="clear"] {
    clear: none !important;
}

.editor-content li {
    overflow: visible !important;
}

.editor-content li {
    margin: 0.5em 0;
}

.editor-content a {
    color: var(--editor-link);
    text-decoration: underline;
    transition: color 0.2s ease;
}

.editor-content a:hover {
    color: var(--editor-link-hover);
}

.editor-content blockquote {
    border-left: 4px solid var(--editor-button-hover);
    margin: 1.5em 0;
    padding: 0.5em 0 0.5em 1em;
    font-style: italic;
    background-color: rgba(45, 112, 150, 0.1);
    border-radius: 0 4px 4px 0;
}

.editor-content code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
}

.editor-content pre {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 1em;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1em 0;
}

.editor-content pre code {
    background: none;
    padding: 0;
}

/* Image Styling */
.editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 1em 0;
    display: block;
    cursor: pointer;
    transition: all 0.2s ease;
}

.editor-content img:hover {
    box-shadow: 0 0 0 2px var(--primary-color);
}

.editor-content img.selected-image {
    box-shadow: 0 0 0 3px var(--primary-color);
    outline: 2px solid var(--accent-text-color);
}

/* Improved text wrapping with better spacing */
.editor-content img.align-left {
    float: left;
    margin: 0 1.5em 1em 0;
    max-width: 50%;
}

.editor-content img.align-right {
    float: right;
    margin: 0 0 1em 1.5em;
    max-width: 50%;
}

.editor-content img.align-center {
    margin: 1em auto;
    float: none;
    max-width: 100%;
}

/* Image Size Classes - Must match the ones in blog.css */
.editor-content img.size-small {
    max-width: 200px !important;
    width: auto !important;
    height: auto !important;
}

.editor-content img.size-medium {
    max-width: 400px !important;
    width: auto !important;
    height: auto !important;
}

.editor-content img.size-large {
    max-width: 600px !important;
    width: auto !important;
    height: auto !important;
}

.editor-content img.size-full {
    max-width: 100% !important;
    width: auto !important;
    height: auto !important;
}

/* Image Controls */
.image-controls {
    position: absolute;
    background: var(--editor-toolbar-bg);
    border: 1px solid var(--editor-border);
    border-radius: 6px;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    display: none;
    flex-direction: column;
    gap: 4px;
    min-width: 120px;
}

.image-controls.show {
    display: flex;
}

.image-controls button {
    background: var(--editor-button-bg);
    border: 1px solid var(--editor-border);
    color: var(--editor-button-text);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.image-controls button:hover {
    background: var(--editor-button-hover);
}

.image-controls button.delete-btn {
    color: #dc3545;
    border-color: #dc3545;
}

.image-controls button.delete-btn:hover {
    background: #dc3545;
    color: white;
}

/* Image Resize Handles */
.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--primary-color);
    border: 1px solid white;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1001;
}

.resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }

/* Safety: hide any orphaned resize handles not adjacent to an img */
.editor-content .resize-handle {
    /* default shown by rules above */
}
.editor-content .resize-handle + :not(img),
.editor-content .resize-handle:only-child {
    display: none !important;
}

/* Table Styling */
.editor-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
}

.editor-content th,
.editor-content td {
    border: 1px solid var(--editor-border);
    padding: 8px 12px;
    text-align: left;
}

.editor-content th {
    background-color: var(--editor-toolbar-bg);
    font-weight: 600;
}

/* Drag and Drop States */
.editor-content.drag-over {
    background-color: rgba(45, 112, 150, 0.1);
    border: 2px dashed var(--editor-button-hover);
}

/* Responsive Design */
@media (max-width: 768px) {
    .editor-toolbar {
        padding: 6px 8px;
        gap: 4px;
    }
    
    .toolbar-section {
        padding: 0 4px;
    }
    
    .toolbar-btn {
        min-width: 28px;
        height: 28px;
        padding: 4px 6px;
        font-size: 12px;
    }
    
    .toolbar-btn.has-text {
        padding: 4px 8px;
        min-width: 40px; /* Ensure minimum width for text buttons */
    }
    
    .toolbar-btn.has-text span {
        font-size: 10px; /* Smaller but still visible */
    }
    
    .toolbar-select {
        min-width: 80px;
        font-size: 12px;
        padding: 4px 8px;
    }
    
    .editor-content {
        padding: 16px;
        font-size: 14px;
    }
}

@media (max-width: 480px) {
    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }
    
    .toolbar-section {
        border-right: none;
        border-bottom: 1px solid var(--editor-toolbar-border);
        padding: 4px 0;
    }
    
    .toolbar-section:last-child {
        border-bottom: none;
    }
    
    .toolbar-group {
        justify-content: center;
    }
} 