/**
 * Rich Text Editor Styles
 */

/* Selection Tooltip - Discord-style floating toolbar */
.rte-selection-tooltip {
    position: fixed;
    display: none;
    align-items: center;
    gap: 2px;
    padding: 4px 6px;
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 10000;
    transform: translateX(-50%);
    animation: rte-tooltip-appear 0.15s ease-out;
}

@keyframes rte-tooltip-appear {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.rte-tooltip-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #aaa);
    transition: all 0.15s ease;
}

.rte-tooltip-btn:hover {
    background: var(--hover-bg, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #fff);
}

.rte-tooltip-btn:active {
    transform: scale(0.95);
}

.rte-tooltip-btn svg {
    width: 16px;
    height: 16px;
}

.rte-tooltip-btn-clear {
    margin-left: 4px;
    border-left: 1px solid var(--border, #333);
    padding-left: 6px;
    border-radius: 0 4px 4px 0;
}

/* Toolbar */
.rte-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    padding: 6px 8px;
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
}

.rte-toolbar .toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #aaa);
    transition: all 0.15s ease;
}

.rte-toolbar .toolbar-btn:hover {
    background: var(--hover-bg, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #fff);
}

.rte-toolbar .toolbar-btn:active {
    transform: scale(0.95);
}

.rte-toolbar .toolbar-btn svg {
    width: 18px;
    height: 18px;
}

.rte-toolbar .toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--border, #333);
    margin: 0 4px;
}

/* Editor Container */
.rte-container {
    display: flex;
    flex-direction: column;
}

/* Contenteditable Editor - Discord-style with live syntax highlighting */
.rte-editor {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary, #fff);
    background: var(--input-bg, #1a1a1a);
    border: 1px solid var(--border, #333);
    border-radius: 0 0 8px 8px;
    outline: none;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    transition: border-color 0.2s ease;
}

.rte-editor:focus {
    border-color: var(--primary, #8b5cf6);
}

.rte-editor:empty::before {
    content: attr(data-placeholder);
    color: var(--text-muted, #666);
    pointer-events: none;
}

/* Syntax Highlighting - Markers (dimmed) */
.rte-marker {
    color: var(--text-muted, #666);
    opacity: 0.6;
    font-weight: 400;
}

/* Syntax Highlighting - Styled Content */
.rte-bold {
    font-weight: 700;
    color: var(--text-primary, #fff);
}

.rte-italic {
    font-style: italic;
}

.rte-strike {
    text-decoration: line-through;
    opacity: 0.7;
}

.rte-underline {
    text-decoration: underline;
}

.rte-spoiler-text {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
    padding: 0 2px;
}

.rte-code {
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    background: var(--code-bg, rgba(0, 0, 0, 0.3));
    padding: 1px 4px;
    border-radius: 3px;
    color: var(--primary, #8b5cf6);
}

.rte-code-block {
    display: block;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    background: var(--code-bg, rgba(0, 0, 0, 0.3));
    padding: 8px;
    border-radius: 4px;
    color: var(--text-secondary, #aaa);
    white-space: pre;
}

.rte-heading {
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.rte-h1 {
    font-size: 1.5em;
}

.rte-h2 {
    font-size: 1.3em;
}

.rte-h3 {
    font-size: 1.15em;
}

.rte-quote {
    color: var(--text-secondary, #aaa);
    border-left: 2px solid var(--primary, #8b5cf6);
    padding-left: 8px;
    margin-left: 4px;
    display: inline-block;
}

.rte-center {
    text-align: center;
    display: block;
}

.rte-link-text {
    color: var(--primary, #8b5cf6);
}

.rte-link-url {
    color: var(--text-muted, #666);
    font-size: 0.9em;
}

/* Inline Link in Editor (clickable, non-editable) */
.rte-link {
    color: var(--primary, #8b5cf6);
    cursor: pointer;
    border-radius: 2px;
    transition: background-color 0.15s ease;
}

.rte-link:hover {
    background: rgba(139, 92, 246, 0.15);
    text-decoration: underline;
}

/* Link Edit Popup */
.rte-link-popup {
    position: fixed;
    display: none;
    z-index: 10001;
    animation: rte-tooltip-appear 0.15s ease-out;
}

.rte-link-popup-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.rte-link-popup-url {
    max-width: 200px;
    font-size: 13px;
    color: var(--text-secondary, #aaa);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rte-link-popup-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    border-left: 1px solid var(--border, #333);
    padding-left: 8px;
    margin-left: 4px;
}

.rte-link-edit-btn,
.rte-link-remove-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-secondary, #aaa);
    transition: all 0.15s ease;
}

.rte-link-edit-btn:hover {
    background: var(--hover-bg, rgba(255, 255, 255, 0.1));
    color: var(--primary, #8b5cf6);
}

.rte-link-remove-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.rte-link-edit-btn svg,
.rte-link-remove-btn svg {
    width: 16px;
    height: 16px;
}

.rte-image-url {
    color: var(--text-muted, #666);
    font-size: 0.9em;
}

.rte-list-item {
    /* Normal text styling */
}

.rte-container textarea {
    width: 100%;
    min-height: 200px;
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary, #fff);
    background: var(--input-bg, #1a1a1a);
    border: 1px solid var(--border, #333);
    border-radius: 0 0 8px 8px;
    resize: vertical;
    outline: none;
    transition: border-color 0.2s ease;
}

.rte-container textarea:focus {
    border-color: var(--primary, #8b5cf6);
}

.rte-container textarea::placeholder {
    color: var(--text-muted, #666);
}

/* Preview Container */
.rte-preview-container {
    padding: 12px;
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 8px;
    min-height: 100px;
}

.rte-preview-label {
    font-size: 12px;
    color: var(--text-muted, #666);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* Rendered Markdown Styles */
.rte-content,
.about-content,
.about-preview {
    font-size: 14px;
    line-height: 1.7;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.rte-content h1,
.about-content h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0.5em 0;
    color: var(--text-primary, #fff);
}

.rte-content h2,
.about-content h2 {
    font-size: 1.3em;
    font-weight: 600;
    margin: 0.5em 0;
    color: var(--text-primary, #fff);
}

.rte-content h3,
.about-content h3 {
    font-size: 1.15em;
    font-weight: 600;
    margin: 0.5em 0;
    color: var(--text-primary, #fff);
}

.rte-content strong,
.about-content strong {
    font-weight: 600;
    color: var(--text-primary, #fff);
}

.rte-content em,
.about-content em {
    font-style: italic;
}

.rte-content u,
.about-content u {
    text-decoration: underline;
}

.rte-content s,
.about-content s {
    text-decoration: line-through;
    opacity: 0.7;
}

.rte-content a,
.about-content a {
    color: var(--primary, #8b5cf6);
    text-decoration: none;
    transition: opacity 0.15s ease;
}

.rte-content a:hover,
.about-content a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.rte-content img,
.about-content img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
    margin: 8px 0;
}

.rte-content .center,
.about-content .center {
    text-align: center;
    display: block;
}

/* Spoiler */
.rte-content .spoiler,
.about-content .spoiler {
    background: var(--text-primary, #fff);
    color: transparent;
    border-radius: 3px;
    padding: 0 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.rte-content .spoiler:hover,
.about-content .spoiler:hover {
    background: var(--text-secondary, #aaa);
}

.rte-content .spoiler.revealed,
.about-content .spoiler.revealed {
    background: var(--hover-bg, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #fff);
    user-select: auto;
}

/* Code */
.rte-content code,
.about-content code {
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.9em;
    background: var(--code-bg, rgba(0, 0, 0, 0.3));
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--primary, #8b5cf6);
}

.rte-content pre,
.about-content pre {
    background: var(--code-bg, rgba(0, 0, 0, 0.3));
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.rte-content pre code,
.about-content pre code {
    background: none;
    padding: 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary, #fff);
}

/* Blockquote */
.rte-content blockquote,
.about-content blockquote {
    border-left: 3px solid var(--primary, #8b5cf6);
    padding: 8px 16px;
    margin: 8px 0;
    background: var(--hover-bg, rgba(255, 255, 255, 0.05));
    border-radius: 0 6px 6px 0;
    color: var(--text-secondary, #aaa);
}

/* Lists */
.rte-content ul,
.about-content ul,
.rte-content ol,
.about-content ol {
    margin: 8px 0;
    padding-left: 24px;
}

.rte-content li,
.about-content li {
    margin: 4px 0;
}

/* Editor Row Layout (side by side with preview) */
.rte-editor-row {
    display: flex;
    gap: 16px;
}

.rte-editor-row .rte-editor {
    flex: 1;
    min-width: 0;
}

.rte-editor-row .rte-preview-container {
    flex: 1;
    min-width: 0;
}

/* Responsive */
@media (max-width: 768px) {
    .rte-editor-row {
        flex-direction: column;
    }

    .rte-selection-tooltip {
        padding: 3px 4px;
    }

    .rte-tooltip-btn {
        width: 24px;
        height: 24px;
    }

    .rte-tooltip-btn svg {
        width: 14px;
        height: 14px;
    }

    .rte-toolbar {
        padding: 4px 6px;
    }

    .rte-toolbar .toolbar-btn {
        width: 28px;
        height: 28px;
    }

    .rte-toolbar .toolbar-btn svg {
        width: 16px;
        height: 16px;
    }
}

/* Dark mode adjustments (if not already dark) */
@media (prefers-color-scheme: light) {
    .rte-selection-tooltip {
        background: #fff;
        border-color: #e0e0e0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .rte-tooltip-btn {
        color: #666;
    }

    .rte-tooltip-btn:hover {
        background: rgba(0, 0, 0, 0.05);
        color: #333;
    }
}

/* Custom Link Modal - replaces JS prompt() to prevent focus loss */
.rte-custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10002;
    animation: rte-modal-appear 0.15s ease-out;
}

@keyframes rte-modal-appear {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.rte-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
}

.rte-modal-content {
    position: relative;
    width: 100%;
    max-width: 400px;
    margin: 0 16px;
    background: var(--card-bg, #1e1e1e);
    border: 1px solid var(--border, #333);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: rte-modal-slide 0.2s ease-out;
}

@keyframes rte-modal-slide {
    from {
        opacity: 0;
        transform: translateY(-10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.rte-modal-header {
    padding: 16px 20px;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #fff);
    border-bottom: 1px solid var(--border, #333);
}

.rte-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rte-modal-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rte-modal-field label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary, #aaa);
}

.rte-modal-field input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary, #fff);
    background: var(--input-bg, #1a1a1a);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s ease;
}

.rte-modal-field input:focus {
    border-color: var(--primary, #8b5cf6);
}

.rte-modal-field input::placeholder {
    color: var(--text-muted, #666);
}

.rte-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border, #333);
}

.rte-modal-cancel,
.rte-modal-save {
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.rte-modal-cancel {
    background: transparent;
    border: 1px solid var(--border, #333);
    color: var(--text-secondary, #aaa);
}

.rte-modal-cancel:hover {
    background: var(--hover-bg, rgba(255, 255, 255, 0.05));
    color: var(--text-primary, #fff);
}

.rte-modal-save {
    background: var(--primary, #8b5cf6);
    border: 1px solid var(--primary, #8b5cf6);
    color: #fff;
}

.rte-modal-save:hover {
    background: var(--primary-hover, #7c3aed);
    border-color: var(--primary-hover, #7c3aed);
}

.rte-modal-save:active,
.rte-modal-cancel:active {
    transform: scale(0.98);
}

/* Modal responsive */
@media (max-width: 480px) {
    .rte-modal-content {
        margin: 0 12px;
        border-radius: 10px;
    }

    .rte-modal-header {
        padding: 14px 16px;
        font-size: 15px;
    }

    .rte-modal-body {
        padding: 16px;
        gap: 14px;
    }

    .rte-modal-field input {
        padding: 9px 10px;
    }

    .rte-modal-footer {
        padding: 14px 16px;
    }

    .rte-modal-cancel,
    .rte-modal-save {
        padding: 7px 14px;
        font-size: 13px;
    }
}
