/* EditorBlock - Einzelner Block-Styles */

.editor-block {
    position: relative;
    margin-bottom: var(--space-2);
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-2); /* Minimaler Abstand rechts */
    direction: ltr; /* Links nach Rechts */
    border-left: 2px solid transparent;
    transition: border-color 0.2s;
    width: 100%;
    max-width: 100%;
    margin-left: 0; /* Linksbündig - nah an der Sidebar */
    margin-right: 0; /* Kein zusätzlicher Margin */
    box-sizing: border-box;
}

/* Chart-Blöcke haben keinen seitlichen Padding, aber Abstand zur Sidebar */
.editor-block-chart {
    padding-left: 0; /* Kein Padding, damit es mit Headlines ausgerichtet ist */
    padding-right: 0; /* Padding wird vom chart-block-content gehandhabt */
    margin-left: 0; /* Linksbündig - nah an der Sidebar */
    margin-right: 0; /* Kein zusätzlicher Margin */
    border-left: none;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
}

/* Stelle sicher, dass block-actions auch bei Chart-Blöcken sichtbar sind */
.editor-block-chart .block-actions {
    opacity: 0;
}

.editor-block-chart:hover .block-actions,
.editor-block-chart.show-actions .block-actions {
    opacity: 1;
}

.editor-block:hover {
    border-left-color: var(--gray-300);
}

.editor-block:focus-within {
    border-left-color: var(--primary);
}

/* Wird jetzt oben definiert */

/* Drag and Drop States */
.editor-block-dragging {
    opacity: 0.3;
    cursor: grabbing;
    transform: scale(0.98);
    transition: opacity 0.15s, transform 0.15s;
}

.editor-block-dragging .block-actions {
    opacity: 0;
}

/* Cursor während Drag auf gesamtem Editor */
.editor-content-dragging {
    cursor: grabbing !important;
    user-select: none;
}

.editor-content-dragging * {
    cursor: grabbing !important;
}

/* Cursor über Drop-Bereichen */
.editor-block-drop-zone {
    cursor: copy !important;
}

.editor-block-has-drop-indicator {
    cursor: copy !important;
}

.drop-zone-end-active {
    cursor: copy !important;
}

/* Drop-Zone am Ende der Liste */
.drop-zone-end {
    min-height: 60px;
    position: relative;
    margin: var(--space-2) 0;
    border-radius: var(--r-sm, 4px);
    transition: background 0.2s ease;
}

.drop-zone-end-active {
    background: rgba(37, 99, 235, 0.05);
}

/* Drop-Bereich hervorheben */
.editor-block-drop-zone {
    position: relative;
}

.editor-block-has-drop-indicator {
    background: rgba(37, 99, 235, 0.03);
    border-radius: var(--r-sm, 4px);
    transition: background 0.2s ease;
}

/* Drop-Indikatoren */
.drop-indicator {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    z-index: 100;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.drop-indicator-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--primary, #2563eb);
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.5), 0 0 16px rgba(37, 99, 235, 0.3);
    animation: dropIndicatorPulse 1.2s ease-in-out infinite;
}

.drop-indicator-line::before,
.drop-indicator-line::after {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary, #2563eb);
    border-radius: 50%;
    top: 50%;
    transform: translateY(-50%);
    box-shadow: 0 0 8px rgba(37, 99, 235, 0.6);
    animation: dropIndicatorDotPulse 1.2s ease-in-out infinite;
}

.drop-indicator-line::before {
    left: -6px;
    animation-delay: 0s;
}

.drop-indicator-line::after {
    right: -6px;
    animation-delay: 0.6s;
}

.drop-indicator-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary, #2563eb);
    color: white;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
    animation: dropIndicatorLabelFade 1.2s ease-in-out infinite;
    z-index: 101;
    margin-top: -20px;
}

.drop-indicator-top {
    top: -2px;
}

.drop-indicator-bottom {
    bottom: -2px;
}

.drop-indicator-bottom .drop-indicator-label {
    margin-top: 20px;
}

@keyframes dropIndicatorPulse {
    0%, 100% {
        opacity: 1;
        transform: scaleY(1);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4), 0 0 8px rgba(37, 99, 235, 0.5);
    }
    50% {
        opacity: 0.9;
        transform: scaleY(1.2);
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2), 0 0 12px rgba(37, 99, 235, 0.6);
    }
}

@keyframes dropIndicatorDotPulse {
    0%, 100% {
        transform: translateY(-50%) scale(1);
        opacity: 1;
    }
    50% {
        transform: translateY(-50%) scale(1.3);
        opacity: 0.8;
    }
}

@keyframes dropIndicatorLabelFade {
    0%, 100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 0.9;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

/* Visuelles Feedback nach erfolgreichem Drop */
.block-just-dropped {
    animation: blockDropSuccess 0.6s ease-out;
}

@keyframes blockDropSuccess {
    0% {
        background: rgba(37, 99, 235, 0.1);
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4);
    }
    50% {
        background: rgba(37, 99, 235, 0.15);
        transform: scale(1.01);
        box-shadow: 0 0 0 8px rgba(37, 99, 235, 0.2);
    }
    100% {
        background: transparent;
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

/* Drag Ghost - Schwebendes Element beim Ziehen */
.drag-ghost {
    background: var(--surface, #ffffff);
    border: 2px solid var(--primary, #2563eb);
    border-radius: var(--r-md, 8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(37, 99, 235, 0.2);
    padding: var(--space-3, 12px) var(--space-4, 16px);
    opacity: 0.95;
    transform: rotate(-1deg);
    transition: transform 0.1s ease;
}

.drag-ghost-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-1, 4px);
}

.drag-ghost-type {
    font-size: var(--text-xs, 11px);
    font-weight: 600;
    color: var(--primary, #2563eb);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.drag-ghost-preview {
    font-size: var(--text-sm, 13px);
    color: var(--text, #1f2937);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.block-actions {
    position: absolute;
    left: calc(-1 * var(--space-6) - 16px);
    top: var(--space-2);
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 150;
    pointer-events: none; /* Verhindert Klicks wenn nicht sichtbar */
}

/* Zeige Aktionen wenn Block oder Aktionen gehovered werden, oder wenn show-actions Klasse gesetzt ist */
.editor-block:hover .block-actions,
.editor-block.show-actions .block-actions,
.block-actions:hover {
    opacity: 1;
    pointer-events: auto; /* Erlaube Klicks wenn sichtbar */
}

.block-drag-handle {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.1s;
    user-select: none;
    letter-spacing: -2px;
    pointer-events: auto !important; /* Stelle sicher, dass Drag-Handle immer klickbar ist */
    touch-action: none; /* Verhindert Touch-Scrolling beim Drag */
}

.block-drag-handle:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--primary);
    cursor: grab;
    transform: scale(1.1);
}

.block-drag-handle:active {
    cursor: grabbing;
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(0.95);
}

.block-add-button,
.block-delete-button {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.block-add-button:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.block-add-button:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    opacity: 1;
}

.block-delete-button {
    font-size: 20px;
    font-weight: 300;
}

.block-delete-button:hover {
    background: var(--danger, #ef4444);
    color: white;
    border-color: var(--danger, #ef4444);
}

.block-delete-button:focus {
    outline: 2px solid var(--danger, #ef4444);
    outline-offset: 2px;
    opacity: 1;
}

/* Block-Typen */
.block-p,
.block-h1,
.block-h2,
.block-h3,
.block-quote,
.block-code-block {
    outline: none;
    min-height: 1.5em;
    line-height: 1.6;
    direction: ltr; /* Links nach Rechts */
    text-align: left; /* Text linksbündig */
    position: relative;
    width: 100%;
    max-width: 100%; /* Innerhalb des editor-block Containers */
}

/* Grauer Strich-Indikator für bessere Sichtbarkeit */
.block-p::before,
.block-h1::before,
.block-h2::before,
.block-h3::before,
.block-quote::before,
.block-code-block::before {
    content: '';
    position: absolute;
    left: calc(-1 * var(--space-2) - 2px);
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--gray-200);
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
}

.editor-block:hover .block-p::before,
.editor-block:hover .block-h1::before,
.editor-block:hover .block-h2::before,
.editor-block:hover .block-h3::before,
.editor-block:hover .block-quote::before,
.editor-block:hover .block-code-block::before {
    opacity: 1;
    background: var(--gray-300);
}

.editor-block:focus-within .block-p::before,
.editor-block:focus-within .block-h1::before,
.editor-block:focus-within .block-h2::before,
.editor-block:focus-within .block-h3::before,
.editor-block:focus-within .block-quote::before,
.editor-block:focus-within .block-code-block::before {
    opacity: 1;
    background: var(--primary);
}

.block-p {
    font-size: var(--body);
    color: var(--text);
}

.block-h1 {
    font-size: var(--h1);
    font-weight: 700;
    color: var(--text);
    margin: var(--space-4) 0 var(--space-2) 0;
    line-height: 1.2;
}

.block-h2 {
    font-size: var(--h2);
    font-weight: 600;
    color: var(--text);
    margin: var(--space-3) 0 var(--space-2) 0;
    line-height: 1.3;
}

.block-h3 {
    font-size: var(--h3);
    font-weight: 600;
    color: var(--text);
    margin: var(--space-2) 0 var(--space-2) 0;
    line-height: 1.4;
}

.block-code-block {
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    background: var(--bg);
    padding: var(--space-3);
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    color: var(--text);
    margin: var(--space-2) 0;
}

.block-quote {
    border-left: 4px solid var(--primary);
    padding-left: var(--space-4);
    margin: var(--space-2) 0;
    font-style: italic;
    color: var(--muted);
    font-size: var(--body);
}

/* Focus-States */
.block-p:focus,
.block-h1:focus,
.block-h2:focus,
.block-quote:focus {
    outline: none;
}

/* Placeholder für leere Blöcke */
.block-p:empty:before,
.block-h1:empty:before,
.block-h2:empty:before,
.block-quote:empty:before {
    content: attr(data-placeholder);
    color: var(--muted);
    opacity: 0.5;
}

/* Tiptap Editor Styles */
.text-block-wrapper {
    position: relative;
    width: 100%;
    max-width: 100%;
    padding-left: 0; /* Wird vom editor-block gehandhabt */
}

.tiptap-editor {
    outline: none;
    min-height: 1.5em;
}

.tiptap-editor:focus {
    outline: none;
}

/* Tiptap ProseMirror Styles */
.ProseMirror {
    outline: none;
}

.ProseMirror p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--muted);
    pointer-events: none;
    height: 0;
    opacity: 0.5;
}

.ProseMirror h1.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--muted);
    pointer-events: none;
    height: 0;
    opacity: 0.5;
}

.ProseMirror h2.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--muted);
    pointer-events: none;
    height: 0;
    opacity: 0.5;
}

.ProseMirror blockquote.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    color: var(--muted);
    pointer-events: none;
    height: 0;
    opacity: 0.5;
}

/* Text Block Loading */
.text-block-loading {
    min-height: 2em;
    display: flex;
    align-items: center;
    padding: var(--space-2) 0;
}

.loading-spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Block Placeholder */
.block-placeholder {
    padding: var(--space-4);
    background: var(--bg);
    border: 1px dashed var(--border);
    border-radius: var(--r-sm);
    color: var(--muted);
    text-align: center;
    font-style: italic;
}

/* Plus-Button am Ende */
.editor-block-end {
    position: relative;
    margin-top: var(--space-4);
    padding: var(--space-2) 0;
}

.block-add-button-end {
    position: absolute;
    left: calc(-1 * var(--space-6) - 16px);
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
    z-index: 150;
}

.editor-block-end:hover .block-add-button-end {
    opacity: 1;
}

.block-add-button-end:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    opacity: 1;
}

.block-add-button-end:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    opacity: 1;
}

/* Text Block Error */
.text-block-error {
    padding: var(--space-4);
    background: #fee;
    border: 1px solid var(--danger);
    border-radius: var(--r-sm);
    color: var(--danger);
    text-align: center;
    font-size: var(--body);
}

/* Responsive: Auf kleineren Bildschirmen volle Breite */
@media (max-width: 1400px) {
    .editor-block,
    .editor-block-chart {
        max-width: 100%;
    }
    
    .model-table-block {
        max-width: 100%;
    }
}

/* Wenn Sidebar collapsed (60px) */
.sidebar.collapsed ~ .main-content .editor-block,
.sidebar.collapsed ~ .main-content .editor-block-chart,
.sidebar.collapsed ~ .main-content .model-table-block {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 768px) {
    .editor-block,
    .editor-block-chart {
        padding-left: var(--space-1);
    }
    
    .model-table-block {
        margin-left: var(--space-1);
    }
}

