/* Text Editor Container */
.text-editor-container {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
}

/* Preview Wrapper (click-to-edit) */
.editor-preview-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    padding: 1.5rem;
    min-height: 0;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.editor-preview-wrapper:hover {
    border-color: var(--primary-color, #007bff);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.08);
}

.preview-placeholder {
    color: var(--text-secondary, #6b7280);
    font-style: italic;
}

/* Editor Actions (Apply / Cancel) */
.editor-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    padding-top: 0.75rem;
    flex-shrink: 0;
}

.editor-action-btn {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.15s;
    line-height: 1;
    padding: 0;
}

.editor-action-btn.apply {
    background-color: var(--primary-color, #007bff);
    color: white;
}

.editor-action-btn.apply:hover {
    background-color: color-mix(in srgb, var(--primary-color, #007bff) 85%, black);
}

.editor-action-btn.cancel {
    background-color: var(--bg-light, #f8f9fa);
    color: var(--text-secondary, #6b7280);
    border: 1px solid var(--border-color, #d1d5db);
}

.editor-action-btn.cancel:hover {
    background-color: var(--danger-color, #dc3545);
    color: white;
    border-color: var(--danger-color, #dc3545);
}

.editor-action-btn:active {
    transform: scale(0.9);
}

.editor-tab-content {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 1rem;
    flex: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.editor-tab-content > *:not(.template-editor):not(.template-preview) {
    flex-shrink: 0;
}

.template-preview {
    flex: 1;
    overflow: hidden;
    width: 100%;
    height: 100%;
    word-wrap: break-word;
    white-space: pre-wrap;
    overflow-y: auto;
}

.available-fields {
    background: var(--bg-secondary, #f9fafb);
    padding: 1rem;
    border-radius: 4px;
    margin-top: 1rem;
    margin-bottom: 0;
    border-left: 4px solid var(--primary-color, #007bff);
    flex-shrink: 0;
}

.available-fields small {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.field-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.field-btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
    white-space: nowrap;
    border: 1px solid var(--border-color, #d1d5db);
    background: white;
    color: var(--text-primary, #1f2937);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.field-btn:hover:not(:disabled) {
    background: var(--primary-color, #007bff);
    color: white;
    border-color: var(--primary-color, #007bff);
}

.field-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.field-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Rich Text Toolbar */
.editor-toolbar {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.25rem;
    background: var(--bg-light, #f8f9fa);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    flex-wrap: wrap;
    flex-shrink: 0;
    margin-bottom: 1rem;
}

.toolbar-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color, #d1d5db);
    background: white;
    color: var(--text-primary, #1f2937);
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.875rem;
}

.toolbar-btn:hover:not(:disabled) {
    background: var(--primary-color, #007bff);
    color: white;
    border-color: var(--primary-color, #007bff);
}

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

.toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Textarea Editor */
.template-editor {
    flex: 1;
    min-height: 0;
    min-width: 0;
    resize: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    font-size: 0.875rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 4px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    width: 100%;
    height: 100%;
}

.template-editor:focus {
    outline: none;
    border-color: var(--primary-color, #007bff);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.template-editor::placeholder {
    color: var(--text-secondary, #6b7280);
}

/* Large Editor variant */
.template-editor.large-editor {
    min-height: 300px;
    flex: 1;
}

/* Preview Section */
.preview-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.preview-section label {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--text-primary, #1f2937);
}

.template-preview {
    background: white;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    padding: 1rem;
    min-height: 200px;
    color: var(--text-primary, #1f2937);
    font-size: 0.9375rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
}

.template-preview strong {
    font-weight: 600;
}

.template-preview em {
    font-style: italic;
}

.template-preview code {
    background: var(--bg-secondary, #f9fafb);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Courier New', monospace;
    font-size: 0.8125rem;
}

.template-preview ul,
.template-preview ol {
    margin: 0.5rem 0 0.5rem 1.5rem;
    padding: 0;
}

.template-preview li {
    margin-bottom: 0.25rem;
}

.template-preview br {
    display: block;
    content: "";
}

.template-preview ul li::marker {
    color: var(--text-secondary, #6b7280);
}

.template-preview ol li::marker {
    color: var(--text-secondary, #6b7280);
}

/* Field placeholder highlighting */
.field-placeholder {
    background: var(--primary-color, #007bff);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    display: inline-block;
}

/* Field value highlighting */
.field-value {
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
    display: inline-block;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .editor-tab-btn {
        padding: 0.625rem 0.75rem;
        font-size: 0.875rem;
    }

    .field-buttons {
        gap: 0.375rem;
    }

    .field-btn {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .template-editor {
        min-height: 150px;
    }

    .template-editor.large-editor {
        min-height: 250px;
    }

    .editor-toolbar {
        gap: 0.125rem;
    }

    .toolbar-btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.75rem;
    }

    .editor-tab-content.preview-tab-content {
        min-height: 250px;
        padding: 1rem;
    }

    .template-preview {
        min-height: 150px;
        max-height: 300px;
    }
}
