/* -------------------------------------------------------------------------
   TerraFlow Unified Editor (Visual + Code) — gemeinsame Hülle
   ------------------------------------------------------------------------- */
.tf-editor-shell.tf-unified-editor {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    height: 420px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--card-bg, #ffffff);
    border: 1px solid var(--border-color, #e2e8f0);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(15, 23, 42, 0.06));
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    /* Hell und konsistent mit dem Admin-UI, unabhängig vom OS-Dark-Mode */
    color-scheme: light;
}

.tf-editor-shell.tf-unified-editor:focus-within {
    border-color: color-mix(in srgb, var(--primary-color, #3b82f6) 35%, var(--border-color, #e2e8f0));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color, #3b82f6) 18%, transparent),
        var(--shadow-sm, 0 1px 2px rgba(15, 23, 42, 0.06));
}

.tf-unified-editor__header {
    display: flex;
    flex-direction: column;
    gap: 0;
    flex-shrink: 0;
}

.tf-unified-editor__toolbar {
    display: flex;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 8px 12px;
    padding: 10px 14px;
    background: #fafbfc;
    border-bottom: 1px solid var(--border-color, #e8edf2);
}

.tf-unified-editor__toolbar[data-active-mode="code"] .tf-unified-visual-tools {
    display: none !important;
}

.tf-unified-editor__toolbar[data-active-mode="visual"] .tf-unified-code-tools {
    display: none !important;
}

.tf-unified-visual-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    flex: 1;
    min-width: 0;
}

.tf-toolbar-subgroup {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding-left: 8px;
    margin-left: 4px;
    border-left: 1px solid color-mix(in srgb, var(--border-color, #e2e8f0) 80%, transparent);
}

.tf-unified-code-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

/* Rechts: Modus (Visuell / Quellcode) + Vollbild */
.tf-toolbar-fs {
    flex: 0 0 auto;
    align-self: flex-start;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.tf-toolbar-mode {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Segment-Control: nicht .tf-editor-btn (32px-Breite) → volle Labels „Visuell“ / „Quellcode“ */
.tf-toolbar-mode--segmented {
    padding: 3px;
    border-radius: 10px;
    background: #e2e8f0;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.06);
    gap: 2px;
}

.tf-mode-seg {
    flex: 1 1 auto;
    min-width: 0;
    padding: 6px 14px;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.2;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.tf-mode-seg:hover:not(.tf-mode-seg--active) {
    color: var(--text-primary, #1e293b);
    background: rgba(255, 255, 255, 0.45);
}

.tf-mode-seg:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: 2px;
}

.tf-mode-seg.tf-mode-seg--active {
    background: #ffffff;
    color: var(--primary-dark, #2563eb);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.1);
}

.tf-toolbar-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.tf-editor-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-primary, #334155);
    box-shadow: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.tf-editor-btn:hover {
    background: rgba(15, 23, 42, 0.06);
    color: var(--primary-dark, #2563eb);
    border-color: rgba(15, 23, 42, 0.06);
}

.tf-editor-btn:active {
    transform: scale(0.97);
}

.tf-editor-btn:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: 2px;
}

.tf-editor-btn.active {
    background: color-mix(in srgb, var(--primary-color, #3b82f6) 16%, transparent);
    color: var(--primary-dark, #2563eb);
    border-color: color-mix(in srgb, var(--primary-color, #3b82f6) 35%, transparent);
}

/* -------------------------------------------------------------------------
   Editor body: Panes
   ------------------------------------------------------------------------- */
.tf-unified-editor__body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    /* Inhalt darf nicht unter Status/Resize „hinauswachsen“ (sonst clippt overflow:hidden der Shell) */
    overflow: hidden;
}

.tf-unified-editor__pane {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Code pane */
.tf-code-pane__inner {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.tf-code-pane__gutter {
    flex-shrink: 0;
    width: 3.25rem;
    padding: 8px 8px 8px 12px;
    background: var(--light-bg, #f8fafc);
    border-right: 1px solid var(--border-color, #e2e8f0);
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted, #94a3b8);
    text-align: right;
    user-select: none;
    overflow-y: auto;
    overflow-x: hidden;
}

.tf-code-pane__ln {
    line-height: 1.6;
    padding: 0 2px;
    border-radius: 4px;
}

.tf-code-pane__ln--error {
    color: var(--danger-color, #ef4444);
    background: color-mix(in srgb, var(--danger-color, #ef4444) 12%, transparent);
}

.tf-code-pane__ln--warn {
    color: var(--warning-color, #f59e0b);
    background: color-mix(in srgb, var(--warning-color, #f59e0b) 12%, transparent);
}

.tf-code-pane__editor {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', 'Fira Code', 'SF Mono', Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre;
    overflow: auto;
    outline: none;
    background: var(--card-bg, #ffffff);
    color: var(--text-primary, #1e293b);
    tab-size: 4;
    -moz-tab-size: 4;
    scrollbar-gutter: stable;
}

.tf-code-pane__editor {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f8fafc;
}

/* WYSIWYG iframe */
.tf-wysiwyg-pane__iframe {
    flex: 1;
    width: 100%;
    min-height: 0;
    border: none;
    background: var(--card-bg, #ffffff);
}

/* Status */
.tf-unified-editor__status {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 14px;
    font-size: 11px;
    color: var(--text-secondary, #64748b);
    background: var(--light-bg, #f8fafc);
    border-top: 1px solid var(--border-color, #e2e8f0);
    font-family: ui-monospace, 'SF Mono', Menlo, Monaco, Consolas, monospace;
}

.tf-unified-editor__status-left,
.tf-unified-editor__status-right {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

/* Resize */
.tf-unified-editor__resize {
    height: 14px;
    min-height: 14px;
    cursor: ns-resize;
    touch-action: none;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-top: 1px solid var(--border-color, #e2e8f0);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    user-select: none;
}

.tf-unified-editor__resize::before {
    content: '';
    width: 40px;
    height: 5px;
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        #cbd5e1 15%,
        #cbd5e1 85%,
        transparent 100%
    );
    box-shadow: 0 0 0 1px rgba(148, 163, 184, 0.35);
}

.tf-unified-editor__resize:hover::before,
.tf-unified-editor__resize:focus-visible::before {
    background: linear-gradient(
        90deg,
        transparent 0%,
        #94a3b8 15%,
        #94a3b8 85%,
        transparent 100%
    );
}

.tf-unified-editor__resize:hover {
    background: linear-gradient(180deg, #e8eef5 0%, #e2e8f0 100%);
}

.tf-unified-editor__resize:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: -2px;
}

/* Fullscreen */
.tf-unified-editor.fullscreen-mode {
    position: fixed;
    inset: 0;
    z-index: 12000;
    width: 100vw !important;
    height: 100vh !important;
    max-height: 100vh !important;
    border-radius: 0;
}

.tf-unified-editor.fullscreen-mode .tf-unified-editor__body {
    flex: 1;
}

body.fullscreen-editor-open {
    overflow: hidden !important;
}

/* Textarea: Platzhalter-Höhe (wie früher große WYSIWYG-Felder) */
textarea.wysiwyg-editor {
    min-height: 400px;
}

textarea.editor {
    min-height: 200px;
}

/* Kein separates Dark-Theme für die Editor-Hülle: Admin bleibt lesbar und einheitlich hell. */
