/**
 * XenForo-style Reply Box CSS
 * Recreates the XenForo reply box appearance and functionality
 */

/* Reply Box Container */
.xenforo-reply-container {
    margin-top: 20px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.xenforo-reply-box {
    display: flex;
    gap: 0px;
    background: #f7f7f7;
}

/* User Section */
.reply-user-section {
    flex: 0 0 120px;
    padding: 8px;
    text-align: center;
    background: #fafafa;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.reply-avatar {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 64px;
}

.reply-avatar .avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    font-size: 24px;
    font-weight: bold;
    color: #666;
    margin: 0 auto;
}

/* Ensure XenForo avatars are also centered */
.reply-avatar .avatar.avatar--m {
    width: 96px !important;
    height: 96px !important;
    margin: 0 auto !important;
    display: block !important;
}

.reply-avatar .avatar.avatar--m img {
    width: 96px !important;
    height: 96px !important;
    border-radius: 50%;
    object-fit: cover;
}

/* Fix font size for letter avatar */
.reply-avatar .avatar.avatar--m .avatar-text {
    font-size: 48px !important;
    line-height: 96px !important;
}

/* Override default avatar font size for medium size */
.reply-avatar .avatar.avatar--m.avatar--default {
    background: #8b5cf6 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: white !important;
    font-weight: bold !important;
    font-size: 48px !important;
    width: 96px !important;
    height: 96px !important;
    border-radius: 50% !important;
    margin: 0 auto !important;
}

/* Avatar text should be centered vertically */
.reply-avatar .avatar.avatar--m .avatar-text {
    display: block;
}

.reply-avatar .avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

/* Form Section */
.reply-form-section {
    flex: 1;
    min-width: 0;
    padding: 0px;
}

/* Content Wrapper */
.comment-form {
    padding: 0px;
    border: 1px solid var(--xf-borderColor, #e0e0e0);
    border-radius: var(--xf-borderRadius, 3px);
    background: var(--xf-paletteNeutral1, #f8f9fa);
}

/* Reply Toolbar */
.reply-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px;
    background: var(--xf-contentAltBg, #f8f9fa);
    border-bottom: 1px solid var(--xf-borderColor, #e0e0e0);
    align-items: center;
}

.buttonGroup {
    display: flex;
    gap: 2px;
    align-items: center;
}

.buttonGroup:not(:last-child) {
    margin-right: 8px;
    padding-right: 8px;
    border-right: 1px solid var(--xf-borderColorLight, #d0d0d0);
}

/* XenForo-style buttons */
.button--icon {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 4px;
    cursor: pointer;
    color: var(--xf-textColorDimmed, #666);
    font-size: 13px;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    min-width: 28px;
    position: relative;
    text-decoration: none;
}

.button--icon i {
    font-size: 14px;
    line-height: 1;
}

.button--icon:hover {
    background: var(--xf-contentBg, #fff);
    border-color: var(--xf-borderColorLight, #d0d0d0);
    color: var(--xf-textColor, #333);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    text-decoration: none;
}

.button--icon:active,
.button--icon.active {
    background: var(--xf-contentAltBgActive, #e0e0e0);
    border-color: var(--xf-borderColor, #c0c0c0);
    color: var(--xf-textColor, #333);
}

/* Text button (for Preview) */
.button--text {
    background: transparent;
    border: 1px solid var(--xf-borderColorLight, #d0d0d0);
    border-radius: 3px;
    padding: 6px 12px;
    cursor: pointer;
    color: var(--xf-textColor, #000);
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    min-width: auto;
    width: auto;
    height: auto;
    opacity: 1 !important;
    visibility: visible !important;
}

.button--text:hover {
    background: var(--xf-paletteColor3, #000);
    border-color: var(--xf-paletteColor3, #000);
    color: #fff;
    text-decoration: none;
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
}

.button--text i {
    font-size: 14px;
}

.button--preview {
    margin-left: auto;
}

/* More specific selector to ensure preview button stays visible */
.reply-toolbar .button--text.button--preview {
    opacity: 1 !important;
    visibility: visible !important;
    display: inline-flex !important;
}

.reply-toolbar .button--text.button--preview:hover {
    opacity: 1 !important;
    visibility: visible !important;
    display: inline-flex !important;
    transform: none !important;
}

/* Override any conflicting toolbar-btn--preview styles */
.xenforo-reply-container .reply-toolbar .toolbar-btn--preview,
.xenforo-reply-container .reply-toolbar .toolbar-btn--preview:hover,
.xenforo-reply-container .reply-toolbar .button--text.button--preview,
.xenforo-reply-container .reply-toolbar .button--text.button--preview:hover {
    background: transparent !important;
    border: 1px solid var(--xf-borderColorLight, #d0d0d0) !important;
    color: var(--xf-textColor, #000) !important;
    opacity: 1 !important;
    visibility: visible !important;
    display: inline-flex !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
    font-weight: 500 !important;
    text-decoration: none !important;
    transform: none !important;
    box-shadow: none !important;
}

.xenforo-reply-container .reply-toolbar .toolbar-btn--preview:hover,
.xenforo-reply-container .reply-toolbar .button--text.button--preview:hover {
    background: var(--xf-paletteColor3, #000) !important;
    border-color: var(--xf-paletteColor3, #000) !important;
    color: #fff !important;
}

/* Extra strong selector to override any comments.css styles */
.xenforo-reply-box .reply-toolbar .button--text.button--preview {
    background: transparent !important;
    border: 1px solid var(--xf-borderColorLight, #d0d0d0) !important;
    color: var(--xf-textColor, #000) !important;
}

.xenforo-reply-box .reply-toolbar .button--text.button--preview:hover {
    background: var(--xf-paletteColor3, #000) !important;
    border-color: var(--xf-paletteColor3, #000) !important;
    color: #fff !important;
}

/* Editor */
.reply-editor {
    position: relative;
}

.reply-textarea {
    width: 100%;
    min-height: 60px;
    height: 60px;
    padding: 8px 10px;
    border: none;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: #333;
    background: #fff;
    outline: none;
    overflow-y: auto;
    max-height: 300px;
    transition: height 0.2s ease;
}

/* Style for contenteditable div */
.reply-textarea[contenteditable="true"] {
    cursor: text;
}

.reply-textarea[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: #999;
    pointer-events: none;
    display: block;
}

.reply-textarea:focus {
    background: #fffff5;
}

/* Basic rich text styling */
.reply-textarea strong,
.reply-textarea b {
    font-weight: bold;
}

.reply-textarea em,
.reply-textarea i {
    font-style: italic;
}

.reply-textarea u {
    text-decoration: underline;
}

.reply-textarea strike,
.reply-textarea s {
    text-decoration: line-through;
}

.reply-textarea blockquote {
    margin: 10px 0;
    padding: 10px 15px;
    border-left: 4px solid #e0e0e0;
    background: #f8f9fa;
    font-style: italic;
}

.reply-textarea code {
    font-family: Consolas, Monaco, 'Courier New', monospace;
    background: #f1f1f1;
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 13px;
}

.reply-textarea pre {
    background: #f1f1f1;
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto;
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.4;
}

.reply-textarea ul,
.reply-textarea ol {
    margin: 10px 0;
    padding-left: 30px;
}

.reply-textarea li {
    margin: 5px 0;
}

.reply-textarea a {
    color: #007bff;
    text-decoration: underline;
}

.reply-textarea img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 10px 0;
}

.reply-textarea p {
    margin: 0 0 10px 0;
}

.reply-textarea p:last-child {
    margin-bottom: 0;
}

/* Actions */
.reply-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #f8f8f8;
    border-top: 1px solid #e0e0e0;
    border-radius: 0 0 4px 4px;
}

.attach-files-btn {
    background: none;
    border: none;
    color: #666;
    cursor: pointer;
    font-size: 14px;
    padding: 6px 12px;
    border-radius: 3px;
    transition: all 0.2s ease;
}

.attach-files-btn:hover {
    background: #e0e0e0;
    color: #333;
    text-decoration: none;
}

.post-reply-btn {
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 3px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.post-reply-btn:hover {
    background: #0056b3;
}

.post-reply-btn:active {
    background: #004085;
}

.post-reply-btn:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* Guest Fields */
.guest-fields {
    margin-top: 15px;
    padding: 15px;
    background: #f8f8f8;
    border-radius: 4px;
}

.guest-field-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.guest-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d0d0d0;
    border-radius: 3px;
    font-size: 14px;
    background: #fff;
}

.guest-input:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

/* Preview Modal */
.xenforo-preview-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-modal-content {
    background: #fff;
    border-radius: 4px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.preview-modal-header {
    padding: 15px;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.preview-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
}

.preview-modal-close:hover {
    background: #e0e0e0;
}

.preview-modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: calc(80vh - 70px);
}

/* Responsive Design */
@media (max-width: 768px) {
    .xenforo-reply-box {
        flex-direction: column;
    }
    
    .reply-user-section {
        flex: none;
        padding-right: 0;
        padding-bottom: 15px;
        text-align: center;
    }
    
    .reply-avatar .avatar {
        width: 64px;
        height: 64px;
        font-size: 24px;
    }
    
    .toolbar-group {
        margin-right: 5px;
    }
    
    .reply-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .reply-actions-left,
    .reply-actions-right {
        justify-content: center;
    }
    
    .post-reply-btn {
        width: 100%;
    }
}

/* Fallback for missing Font Awesome */
.toolbar-btn i::before {
    font-style: normal;
    font-family: Arial, sans-serif;
}

.toolbar-btn i.fa-bold::before { content: 'B'; font-weight: bold; }
.toolbar-btn i.fa-italic::before { content: 'I'; font-style: italic; }
.toolbar-btn i.fa-underline::before { content: 'U'; text-decoration: underline; }
.toolbar-btn i.fa-strikethrough::before { content: 'S'; text-decoration: line-through; }
.toolbar-btn i.fa-list-ul::before { content: '•'; }
.toolbar-btn i.fa-list-ol::before { content: '1.'; }
.toolbar-btn i.fa-link::before { content: '🔗'; }
.toolbar-btn i.fa-image::before { content: '🖼️'; }
.toolbar-btn i.fa-smile::before { content: '😊'; }
.toolbar-btn i.fa-quote-right::before { content: '"'; }
.toolbar-btn i.fa-code::before { content: '</>'; }
.toolbar-btn i.fa-undo::before { content: '↶'; }
.toolbar-btn i.fa-redo::before { content: '↷'; }
.toolbar-btn i.fa-paperclip::before { content: '📎'; }
.toolbar-btn i.fa-reply::before { content: '↩'; }