/* ─── Rich text editor (shared) ──────────────────────────────────── */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs);
    border: var(--border-width) var(--border-style) var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    position: sticky;
    top: 0;
    z-index: 10;
    margin-left: calc(-1 * var(--space-md));
    margin-right: calc(-1 * var(--space-md));
}
.editor-toolbar button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--icon-size);
    height: var(--icon-size);
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    cursor: pointer;
    color: var(--text-primary);
}
.editor-toolbar button:hover {
    background: var(--border);
}
.toolbar-format-wrap {
    position: relative;
    display: inline-flex;
}
.toolbar-format-btn {
    /* Inherits base sizing/border from .editor-toolbar button */
}
.toolbar-format-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.toolbar-format-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 100;
    margin-top: var(--space-xs);
    padding: var(--space-xs);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    background: var(--surface-input);
    border: var(--border-width) var(--border-style) var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-dropdown);
}
.toolbar-format-dropdown.hidden {
    display: none;
}
/* ── Generic toolbar popup right-alignment (overflow fallback) ──────
 * Used by panels.js positionToolbarPopup() across .merge-tag-dropdown,
 * .qr-toolbar-dropdown and .toolbar-format-dropdown when they would
 * overflow their nearest clipping ancestor. */
.toolbar-popup.align-right {
    left: auto;
    right: 0;
}
/* Vertical overflow: when there isn't enough room below, panels.js sets
 * `--toolbar-pop-max-h` (in px) via style.setProperty so the popup scrolls
 * inside the available space instead of being cut off by the modal/viewport.
 * If there's more room above, the .align-up class flips the anchor. */
.toolbar-popup {
    max-height: var(--toolbar-pop-max-h, none);
    overflow-y: auto;
}
.toolbar-popup.align-up {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: var(--space-xs);
}
.toolbar-format-option.active {
    background: var(--brand-light-bg);
    color: var(--brand-color);
}
.editor-toolbar button:focus,
.editor-toolbar button:focus-visible {
    outline: var(--border-width) var(--border-style) var(--brand);
}
.editor-toolbar button.active {
    background: var(--brand-light-bg);
    color: var(--brand-color);
}
.toolbar-sep {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 var(--space-xs);
}

.editor-area {
    min-height: 200px;
    padding: var(--space-2xl) var(--space-md) var(--space-md) var(--space-md);
    margin-top: calc(-1 * var(--space-md));
    border: var(--border-width) var(--border-style) var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-input);
    outline: none;
    overflow-y: auto;
    text-align: left;
}
.editor-area:focus,
.editor-area:focus-visible {
    border: var(--border-width) var(--border-style) var(--brand);
    outline: none;
}
.editor-area ul,
.editor-area ol {
    margin: var(--space-xs) 0;
    padding-left: var(--space-xl);
}
.editor-area a {
    color: var(--brand-color);
    text-decoration: underline;
}
.editor-area hr {
    border: none;
    border-top: var(--border-width-double) var(--border-style) var(--border);
    margin: var(--space-md) 0;
}
.editor-area h1,
.editor-area h2,
.editor-area h3,
.editor-area h4,
.editor-area h5,
.editor-area h6 {
    margin: var(--space-sm) 0 var(--space-xs);
}
.editor-area img {
    cursor: text;
}
.editor-area p,
.editor-area ul,
.editor-area ol {
    margin-bottom: var(--space-lg);
}
.editor-image-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-3xl) var(--space-xl);
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    transition: border-color var(--transition-smooth), background var(--transition-smooth);
    cursor: default;
    text-align: center;
    margin-bottom: var(--space-md);
}
.editor-image-dropzone.dragover {
    border-color: var(--brand);
    background: var(--brand-light-bg);
}
.editor-image-dropzone svg {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}
.dropzone-text {
    font-size: var(--font-size);
    color: var(--text-secondary);
    margin: 0;
}
.dropzone-hint {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin: var(--space-xs) 0 0;
}
.editor-image-uploading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-3xl) var(--space-xl);
}
.upload-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: upload-spin 0.7s linear infinite;
}
@keyframes upload-spin {
    to { transform: rotate(360deg); }
}
.upload-progress-text {
    font-size: var(--font-size);
    color: var(--text-muted);
    margin: 0;
}
.editor-image-error {
    font-size: var(--font-size-sm);
    color: var(--danger);
    text-align: center;
    padding: var(--space-sm) 0;
    margin: 0;
}
.editor-image-input {
    display: none;
}
.editor-upload-hidden {
    display: none;
}

/* ─── Shared attachments ─────────────────────────────────────────── */
.attach-area {
    margin-top: var(--space-sm);
}
.attach-file-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
}
.attach-file-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: var(--surface-card);
    border: var(--border-width) var(--border-style) var(--border);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-label);
    color: var(--text-primary);
}
.attach-file-item.uploading {
    opacity: 0.6;
}
.att-size { color: var(--text-muted); font-size: var(--font-size-sm); }
.attach-file-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-left: var(--space-xs);
    color: var(--text-muted);
    line-height: 1;
}
.attach-file-remove:hover {
    color: var(--danger-text);
}
