/*
 * Horizontal forms (FrankenUI): .row + label + .uk-form-controls — ohne Flex
 * nimmt die Steuer-Spalte die intrinsische Mindestbreite des Trix (Toolbar)
 * an und zerstört das Layout. Gleiches gilt für Grid-Kinder (min-width:auto).
 */
form.uk-form-horizontal .row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    column-gap: 1rem;
    row-gap: 0.25rem;
    min-width: 0;
    width: 100%;
}

form.uk-form-horizontal .row > .uk-form-label {
    flex: 0 0 clamp(8.5rem, 26vw, 13rem);
    max-width: 100%;
    padding-top: 0.35rem;
}

form.uk-form-horizontal .row > .uk-form-controls {
    flex: 1 1 0%;
    min-width: 0;
    max-width: 100%;
}

/* Stimulus-Trix-Wrapper: in Grids/Flex nie breiter als die Spalte */
[data-controller="trix-editor"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

[data-controller="trix-editor"] trix-toolbar,
[data-controller="trix-editor"] trix-editor {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

/* Trix Editor Base Styling */
trix-editor {
    display: block !important;
    min-height: 120px;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    padding: 12px;
    background: white;
    font-family: inherit;
    line-height: 1.6;
    font-size: 14px;
    max-height: 300px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-y: auto;
}

/* Toolbar: umbrechen statt eine Zeile mit unendlicher Breite */
trix-toolbar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center;
    gap: 0.25rem 0.35rem;
    max-width: 100%;
    box-sizing: border-box;
}

.uk-form-controls trix-toolbar {
    max-width: 100%;
    box-sizing: border-box;
}

trix-editor:focus {
    outline: none;
    border-color: #1e87f0;
    box-shadow: 0 0 0 3px rgba(30, 135, 240, 0.1);
}

/* Trix Toolbar - Light Mode */
.trix-button-group {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    margin-bottom: 8px;
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px;
    margin-right: 8px;
    max-width: 100%;
}

.trix-button {
    border: none;
    background: transparent;
    color: #495057;
    padding: 8px 10px;
    border-radius: 4px;
    transition: all 0.2s;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.trix-button:hover {
    background: #e9ecef;
    color: #212529;
}

.trix-button.trix-active {
    background: #1e87f0;
    color: white;
}

.trix-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Image Gallery Styling */
.image-collection {
    border: 2px dashed #e5e5e5;
    border-radius: 8px;
    padding: 20px;
    background: #fafbfc;
}

.image-item {
    border-left: 4px solid #1e87f0;
    transition: all 0.2s ease;
}

.image-item:hover {
    background-color: #f8f9fa;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.image-item.dragging {
    opacity: 0.5;
    transform: rotate(5deg);
}

/* Sortable indicators */
.uk-sortable .image-item {
    cursor: move;
}

.uk-sortable .image-item:before {
    content: '';
    position: absolute;
    left: -4px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(45deg, #1e87f0, #0066cc);
}

/* File input styling */
.file-input {
    border: 2px dashed #d1d5db;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    transition: border-color 0.2s;
}

.file-input:hover {
    border-color: #1e87f0;
    background-color: #f8fafc;
}

/* Form sections */
.uk-heading-line > span {
    background: white;
    padding: 0 1rem;
    color: #1e87f0;
    font-weight: 600;
}

/* Help text styling */
.uk-form-help {
    color: #6b7280;
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Light Mode - Explicit styles to ensure proper display */
:root trix-editor,
html:not(.dark) trix-editor,
body:not(.dark) trix-editor,
[data-theme="light"] trix-editor {
    background: white;
    border-color: #e5e5e5;
    color: #212529;
}

:root trix-editor:focus,
html:not(.dark) trix-editor:focus,
body:not(.dark) trix-editor:focus,
[data-theme="light"] trix-editor:focus {
    border-color: #1e87f0;
    box-shadow: 0 0 0 3px rgba(30, 135, 240, 0.1);
}

:root .trix-button-group,
html:not(.dark) .trix-button-group,
body:not(.dark) .trix-button-group,
[data-theme="light"] .trix-button-group {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

:root .trix-button,
html:not(.dark) .trix-button,
body:not(.dark) .trix-button,
[data-theme="light"] .trix-button {
    color: #495057;
}

:root .trix-button:hover,
html:not(.dark) .trix-button:hover,
body:not(.dark) .trix-button:hover,
[data-theme="light"] .trix-button:hover {
    background: #e9ecef;
    color: #212529;
}

:root .trix-button.trix-active,
html:not(.dark) .trix-button.trix-active,
body:not(.dark) .trix-button.trix-active,
[data-theme="light"] .trix-button.trix-active {
    background: #1e87f0;
    color: white;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    trix-editor {
        background: #374151;
        border-color: #4b5563;
        color: #f9fafb;
    }
    
    trix-editor:focus {
        border-color: #60a5fa;
        box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1);
    }
    
    .trix-button-group {
        background: #4b5563;
        border: 1px solid #6b7280;
    }
    
    .trix-button {
        color: #f9fafb;
    }
    
    .trix-button:hover {
        background: #6b7280;
    }
    
    .trix-button.trix-active {
        background: #60a5fa;
        color: #111827;
    }
    
    .image-collection {
        background: #374151;
        border-color: #4b5563;
    }
    
    .uk-heading-line > span {
        background: #111827;
        color: #60a5fa;
    }
}

/* Class-based dark theme support */
.dark trix-editor,
[data-theme="dark"] trix-editor,
html.dark trix-editor,
body.dark trix-editor {
    background: #374151 !important;
    border-color: #4b5563 !important;
    color: #f9fafb !important;
}

.dark trix-editor:focus,
[data-theme="dark"] trix-editor:focus,
html.dark trix-editor:focus,
body.dark trix-editor:focus {
    border-color: #60a5fa !important;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1) !important;
}

.dark .trix-button-group,
[data-theme="dark"] .trix-button-group,
html.dark .trix-button-group,
body.dark .trix-button-group {
    background: #4b5563 !important;
    border: 1px solid #6b7280;
}

.dark .trix-button,
[data-theme="dark"] .trix-button,
html.dark .trix-button,
body.dark .trix-button {
    color: #f9fafb !important;
}

.dark .trix-button:hover,
[data-theme="dark"] .trix-button:hover,
html.dark .trix-button:hover,
body.dark .trix-button:hover {
    background: #6b7280 !important;
}

.dark .trix-button.trix-active,
[data-theme="dark"] .trix-button.trix-active,
html.dark .trix-button.trix-active,
body.dark .trix-button.trix-active {
    background: #60a5fa !important;
    color: #111827 !important;
}

/* Hide attachment button and related elements */
.trix-button--icon-attach,
.trix-button-group--file-tools {
    display: none !important;
}

/* Custom scrollbar for dark theme */
.dark trix-editor::-webkit-scrollbar,
[data-theme="dark"] trix-editor::-webkit-scrollbar {
    width: 8px;
}

.dark trix-editor::-webkit-scrollbar-track,
[data-theme="dark"] trix-editor::-webkit-scrollbar-track {
    background: #4b5563;
    border-radius: 4px;
}

.dark trix-editor::-webkit-scrollbar-thumb,
[data-theme="dark"] trix-editor::-webkit-scrollbar-thumb {
    background: #6b7280;
    border-radius: 4px;
}

.dark trix-editor::-webkit-scrollbar-thumb:hover,
[data-theme="dark"] trix-editor::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/*
 * Tailwind @layer base (Preflight) setzt u. a. h1–h6 auf font-size/font-weight inherit
 * und ol/ul auf list-style: none. Trix setzt für Listen kein list-style — dann wirken
 * Überschriften/Listen/Zitate/Code im Editor „kaputt“, obwohl das Markup stimmt.
 */
trix-editor h1 {
    font-size: 1.5rem !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
    margin: 0.5em 0 !important;
}

trix-editor h2 {
    font-size: 1.35rem !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
    margin: 0.5em 0 !important;
}

trix-editor h3 {
    font-size: 1.2rem !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
    margin: 0.5em 0 !important;
}

trix-editor blockquote {
    border: 0 solid #ccc !important;
    border-left-width: 0.25em !important;
    margin: 0.75em 0 0.75em 0.3em !important;
    padding-left: 0.75em !important;
    color: #4b5563 !important;
}

trix-editor pre {
    display: inline-block !important;
    width: 100% !important;
    box-sizing: border-box !important;
    vertical-align: top !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
    font-size: 0.875em !important;
    padding: 0.65em 0.85em !important;
    white-space: pre !important;
    background-color: #f3f4f6 !important;
    border-radius: 0.375rem !important;
    overflow-x: auto !important;
}

.dark trix-editor blockquote,
[data-theme="dark"] trix-editor blockquote,
html.dark trix-editor blockquote,
body.dark trix-editor blockquote {
    border-left-color: #6b7280 !important;
    color: #d1d5db !important;
}

.dark trix-editor pre,
[data-theme="dark"] trix-editor pre,
html.dark trix-editor pre,
body.dark trix-editor pre {
    background-color: #374151 !important;
}

trix-editor ul {
    list-style-type: disc !important;
    padding-inline-start: 1.5rem !important;
    margin: 0.5em 0 !important;
}

trix-editor ol {
    list-style-type: decimal !important;
    padding-inline-start: 1.5rem !important;
    margin: 0.5em 0 !important;
}

trix-editor li {
    margin: 0.15em 0 !important;
}

trix-editor ul ul {
    list-style-type: circle !important;
}

trix-editor ul ul ul {
    list-style-type: square !important;
}