/**
 * Custom Quill Editor Styles for FÖMA Portal
 */

/* Main Editor Container */
.quill-editor-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.quill-main-editor {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* Toolbar Styling */
.ql-toolbar.ql-snow {
    border: 1px solid #ddd;
    border-radius: 4px 4px 0 0;
    background: #f8f8f8;
}

.ql-container.ql-snow {
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    font-family: inherit;
    font-size: 14px;
}

/* HTML Source Editor */
.quill-html-source-editor {
    width: 100%;
    min-height: 200px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f5f5f5;
    resize: vertical;
}

.quill-html-source-editor.inline-html-source {
    min-height: 150px;
}

/* Custom HTML Source Button */
.ql-html-source {
    width: auto !important;
    padding: 0 5px;
    font-weight: bold;
    font-family: monospace;
}

.ql-html-source.ql-active {
    color: #06c;
    background: #e6f2ff;
}

/* Inline Editable Text */
.quill-editable-text {
    position: relative;
    transition: background-color 0.3s ease;
    cursor: default;
}

.quill-editable-text:hover {
    background-color: rgba(255, 243, 224, 0.3);
}

/* Edit Button for Inline Editing */
.quill-edit-btn {
    position: absolute;
    top: 0;
    right: -30px;
    padding: 4px 8px;
    background: #5cb85c;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 100;
}

.quill-editable-text:hover + .quill-edit-btn,
.quill-edit-btn:hover {
    opacity: 1;
}

.quill-edit-btn:hover {
    background: #4cae4c;
}

/* Inline Editor Container */
.quill-inline-editor {
    margin: 10px 0;
    padding: 10px;
    background: #f9f9f9;
    border: 2px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.quill-inline-wrapper {
    background: white;
    border-radius: 4px;
}

.quill-inline-wrapper .ql-toolbar {
    border-radius: 4px 4px 0 0;
    padding: 5px;
}

.quill-inline-wrapper .ql-container {
    min-height: 100px;
    max-height: 300px;
    overflow-y: auto;
    border-radius: 0 0 4px 4px;
}

/* Editor Buttons */
.quill-editor-buttons {
    margin-top: 10px;
    text-align: right;
}

.quill-editor-buttons button {
    margin-left: 5px;
}

/* Save Success/Error States */
.save-success {
    background-color: #5cb85c !important;
    border-color: #4cae4c !important;
}

.save-error {
    background-color: #d9534f !important;
    border-color: #d43f3a !important;
}

/* AWS/FÖMA Portal Specific Overrides */
.control-grey .ql-toolbar {
    background: #f0f0f0;
}

.control-grey .ql-container {
    background: #fafafa;
}

/* Responsive Design */
@media (max-width: 768px) {
    .quill-edit-btn {
        right: 0;
        top: -25px;
    }
    
    .ql-toolbar {
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* Editor Focus States */
.ql-container.ql-snow:focus-within {
    border-color: #66afe9;
    outline: 0;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px rgba(102,175,233,.6);
}

/* Placeholder Styling */
.ql-editor.ql-blank::before {
    color: #999;
    font-style: italic;
}

/* Readonly State */
.ql-container.ql-disabled {
    background: #eee;
    opacity: 0.6;
}

.ql-toolbar.ql-snow .ql-formats button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Loading State */
.quill-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.quill-loading::after {
    content: "Wird geladen...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.9);
    padding: 10px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 1000;
}

/* Content Alignment in Editor */
.ql-editor {
    line-height: 1.6;
}

.ql-editor h1 { font-size: 2em; margin: 0.67em 0; }
.ql-editor h2 { font-size: 1.5em; margin: 0.75em 0; }
.ql-editor h3 { font-size: 1.17em; margin: 0.83em 0; }
.ql-editor h4 { font-size: 1em; margin: 1.12em 0; }
.ql-editor h5 { font-size: 0.83em; margin: 1.5em 0; }
.ql-editor h6 { font-size: 0.75em; margin: 1.67em 0; }

.ql-editor p {
    margin-bottom: 10px;
}

.ql-editor blockquote {
    border-left: 4px solid #ccc;
    padding-left: 16px;
    margin: 10px 0;
}

/* Integration with Bootstrap Forms */
.form-group .quill-editor-wrapper {
    margin-top: 5px;
}

.form-group label + .quill-editor-wrapper {
    margin-top: 5px;
}

/* Editable Label Styling for input-line */
.editable-label-container {
    display: inline-block;
    position: relative;
    z-index: 1000; /* Bring to front */
}

.editable-label-container .quill-editable-text {
    display: inline-block;
    min-width: 100px;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
    color: #333;
}

.editable-label-container .quill-editable-text:hover {
    background-color: rgba(91, 192, 222, 0.1);
}

.editable-label-container .label-colon {
    margin-left: 2px;
    font-weight: bold;
    color: #333;
}

.editable-label-container .quill-edit-btn {
    top: -2px;
    right: -25px;
    font-size: 11px;
    padding: 2px 6px;
}

.editable-label-container .quill-inline-editor {
    min-width: 200px;
    margin: 5px 0;
    position: relative;
    z-index: 1001; /* Higher than container */
    background: white;
    border: 2px solid #5cb85c;
    border-radius: 4px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.2); /* Strong shadow for prominence */
}

.editable-label-container .quill-inline-wrapper .ql-container {
    min-height: 60px;
    max-height: 150px;
    z-index: 1002;
    position: relative;
}

.editable-label-container .quill-inline-wrapper .ql-toolbar {
    z-index: 1003; /* Toolbar above everything */
    position: relative;
    background: white;
    border-bottom: 1px solid #ccc;
}

/* Ensure Quill toolbar buttons are clickable */
.editable-label-container .ql-toolbar .ql-formats button,
.editable-label-container .ql-toolbar .ql-formats .ql-picker {
    z-index: 1004;
    position: relative;
}

/* Label Edit Mode Indicator */
.label-edit-mode-active {
    border-left: 3px solid #5cb85c;
    padding-left: 10px;
}

/* High z-index for overlays and modals */
.modal .editable-label-container .quill-inline-editor,
.panel .editable-label-container .quill-inline-editor,
.tab-content .editable-label-container .quill-inline-editor {
    z-index: 10000; /* Very high for modals */
}

.modal .editable-label-container .ql-toolbar,
.panel .editable-label-container .ql-toolbar,
.tab-content .editable-label-container .ql-toolbar {
    z-index: 10001;
}

/* Prevent interference from Bootstrap elements */
.form-horizontal .form-group .editable-label-container {
    z-index: 1000;
    position: relative;
}

/* Responsive adjustments for editable labels */
@media (max-width: 768px) {
    .editable-label-container .quill-edit-btn {
        right: 0;
        top: -20px;
    }
    
    .editable-label-container .quill-inline-editor {
        min-width: 150px;
        z-index: 1500; /* Even higher on mobile */
    }
}

/* Label Edit Toggle Button Styling */
.label-edit-toggle-container {
    margin: 10px 0;
    text-align: left;
}

.label-edit-toggle-btn {
    transition: all 0.3s ease;
    border-radius: 4px;
    font-weight: 500;
}

.label-edit-toggle-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.label-edit-toggle-btn.btn-success {
    background-color: #5cb85c;
    border-color: #4cae4c;
    color: white;
}

.label-edit-toggle-btn.btn-success:hover {
    background-color: #4cae4c;
    border-color: #398439;
}

.label-edit-toggle-btn.btn-default {
    background-color: #f8f9fa;
    border-color: #dee2e6;
    color: #495057;
}

.label-edit-toggle-btn.btn-default:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

.label-edit-toggle-btn .glyphicon {
    margin-right: 5px;
}

.edit-mode-status {
    display: block;
    margin-top: 5px;
    font-style: italic;
    color: #666;
}

/* Positioning options */
.label-edit-toggle.label-edit-toggle-top-right {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 1000;
}

.label-edit-toggle.label-edit-toggle-top-left {
    position: fixed;
    top: 80px;
    left: 20px;
    z-index: 1000;
}

.label-edit-toggle.label-edit-toggle-bottom-right {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

/* Floating toggle button styling */
.label-edit-toggle-top-right .label-edit-toggle-container,
.label-edit-toggle-top-left .label-edit-toggle-container,
.label-edit-toggle-bottom-right .label-edit-toggle-container {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 10px;
    border: 1px solid #dee2e6;
}

/* Animation for edit mode activation */
.label-edit-mode-transition {
    transition: border-color 0.3s ease, background-color 0.3s ease;
}

/* Responsive adjustments for toggle button */
@media (max-width: 768px) {
    .label-edit-toggle.label-edit-toggle-top-right,
    .label-edit-toggle.label-edit-toggle-bottom-right {
        right: 10px;
    }
    
    .label-edit-toggle.label-edit-toggle-top-left {
        left: 10px;
    }
    
    .label-edit-toggle-btn .button-text {
        display: none;
    }
}

/* Error States */
.has-error .ql-toolbar,
.has-error .ql-container {
    border-color: #a94442;
}

.has-error .ql-container.ql-snow:focus-within {
    border-color: #843534;
    box-shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px #ce8483;
}