/* Quill Editor Custom Styles */
.ql-container {
    border: none !important;
    font-family: inherit;
    font-size: 1rem;
}

.ql-editor {
    min-height: 200px;
    padding: 1rem 1.5rem;
    line-height: 1.6;
}

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

.ql-editor.ql-blank::before {
    font-style: normal;
    color: #9ca3af;
    left: 1.5rem;
}

.ql-toolbar.ql-snow {
    border: none !important;
    padding: 0;
}

.ql-toolbar .ql-formats {
    margin-right: 0.5rem;
}

.ql-snow .ql-picker {
    color: #374151;
}

.ql-snow .ql-stroke {
    stroke: #374151;
}

.ql-snow .ql-fill {
    fill: #374151;
}

.ql-snow button:hover .ql-stroke,
.ql-snow .ql-picker-label:hover .ql-stroke {
    stroke: #2563eb;
}

.ql-snow button:hover .ql-fill,
.ql-snow .ql-picker-label:hover .ql-fill {
    fill: #2563eb;
}

.ql-snow button.ql-active .ql-stroke {
    stroke: #2563eb;
}

.ql-snow button.ql-active .ql-fill {
    fill: #2563eb;
}

.ql-snow .ql-picker-options {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Quill Tooltip (for link insertion) */
.ql-snow .ql-tooltip {
    z-index: 9999 !important;
    background-color: #fff;
    border: 1px solid #d1d5db;
    box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15);
    padding: 10px 14px;
    border-radius: 6px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Cacher le tooltip par défaut */
.ql-snow .ql-tooltip.ql-hidden {
    display: none !important;
}

/* Texte "Enter link:" ou "Visit URL:" */
.ql-snow .ql-tooltip::before {
    content: "Lien:";
    margin-right: 4px;
    color: #374151;
    font-size: 13px;
}

.ql-snow .ql-tooltip[data-mode="link"]::before {
    content: "Entrer le lien:";
}

.ql-snow .ql-tooltip input[type="text"] {
    display: inline-block !important;
    border: 1px solid #d1d5db;
    padding: 8px 12px;
    font-size: 14px;
    width: 280px;
    border-radius: 4px;
    outline: none;
    background: #fff;
}

.ql-snow .ql-tooltip input[type="text"]:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Bouton Save */
.ql-snow .ql-tooltip a.ql-action::after {
    content: "Sauvegarder";
}

.ql-snow .ql-tooltip a.ql-action,
.ql-snow .ql-tooltip a.ql-remove {
    display: inline-block !important;
    padding: 8px 16px;
    background: #2563eb;
    color: #fff !important;
    border-radius: 4px;
    text-decoration: none !important;
    font-size: 13px;
    cursor: pointer;
    border: none;
    line-height: 1;
    font-weight: 500;
}

.ql-snow .ql-tooltip a.ql-action:hover {
    background: #1d4ed8;
}

/* Bouton Remove */
.ql-snow .ql-tooltip a.ql-remove::before {
    content: "Supprimer";
}

.ql-snow .ql-tooltip a.ql-remove {
    background: #dc2626;
    margin-left: 4px;
}

.ql-snow .ql-tooltip a.ql-remove:hover {
    background: #b91c1c;
}

/* Lien preview dans le tooltip */
.ql-snow .ql-tooltip a.ql-preview {
    color: #2563eb;
    text-decoration: underline;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
}

/* Cacher le bouton Edit quand on visualise un lien existant */
.ql-snow .ql-tooltip:not(.ql-editing) a.ql-action {
    display: none !important;
}

/* Cacher le bouton Remove quand on crée un nouveau lien */
.ql-snow .ql-tooltip.ql-editing a.ql-remove {
    display: none !important;
}

/* Dark mode */
.dark .ql-container {
    background-color: #111827;
    color: #fff;
}

.dark .ql-editor {
    color: #fff;
}

.dark .ql-editor.ql-blank::before {
    color: #6b7280;
}

.dark .ql-snow .ql-picker {
    color: #d1d5db;
}

.dark .ql-snow .ql-stroke {
    stroke: #d1d5db;
}

.dark .ql-snow .ql-fill {
    fill: #d1d5db;
}

.dark .ql-snow button:hover .ql-stroke,
.dark .ql-snow .ql-picker-label:hover .ql-stroke {
    stroke: #60a5fa;
}

.dark .ql-snow button:hover .ql-fill,
.dark .ql-snow .ql-picker-label:hover .ql-fill {
    fill: #60a5fa;
}

.dark .ql-snow button.ql-active .ql-stroke {
    stroke: #60a5fa;
}

.dark .ql-snow button.ql-active .ql-fill {
    fill: #60a5fa;
}

.dark .ql-snow .ql-picker-options {
    background: #1f2937;
    border-color: #4b5563;
}

.dark .ql-snow .ql-picker-item {
    color: #d1d5db;
}

.dark .ql-snow .ql-picker-item:hover {
    color: #60a5fa;
}

.dark .ql-snow .ql-tooltip {
    background: #1f2937;
    border-color: #4b5563;
    color: #d1d5db;
}

.dark .ql-snow .ql-tooltip input[type="text"] {
    background: #111827;
    border-color: #4b5563;
    color: #fff;
}

/* Toolbar separator */
.toolbar-separator {
    width: 1px;
    height: 24px;
    background-color: #d1d5db;
    margin: 0 0.5rem;
}

.dark .toolbar-separator {
    background-color: #4b5563;
}

/* Font sizes */
.ql-snow .ql-picker.ql-font {
    width: 100px;
}

.ql-snow .ql-picker.ql-size {
    width: 70px;
}

.ql-size-small {
    font-size: 0.75em;
}

.ql-size-large {
    font-size: 1.25em;
}

.ql-size-huge {
    font-size: 1.5em;
}

/* Autocomplete dropdown */
.variable-autocomplete {
    position: absolute;
    z-index: 100;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    max-height: 280px;
    overflow-y: auto;
    min-width: 280px;
}

.dark .variable-autocomplete {
    background: #1f2937;
    border-color: #374151;
}

.variable-autocomplete-header {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dark .variable-autocomplete-header {
    color: #9ca3af;
    border-bottom-color: #374151;
}

.variable-autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.15s;
}

.variable-autocomplete-item:hover,
.variable-autocomplete-item.selected {
    background-color: #eff6ff;
}

.dark .variable-autocomplete-item:hover,
.dark .variable-autocomplete-item.selected {
    background-color: #1e3a5f;
}

.variable-autocomplete-item code {
    color: #2563eb;
    font-size: 0.875rem;
    font-weight: 500;
}

.dark .variable-autocomplete-item code {
    color: #60a5fa;
}

.variable-autocomplete-item .description {
    font-size: 0.75rem;
    color: #6b7280;
    margin-left: 1rem;
}

.dark .variable-autocomplete-item .description {
    color: #9ca3af;
}

.variable-autocomplete-empty {
    padding: 1rem;
    text-align: center;
    color: #9ca3af;
    font-size: 0.875rem;
}

.variable-autocomplete-hint {
    padding: 0.5rem 0.75rem;
    font-size: 0.7rem;
    color: #9ca3af;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 1rem;
}

.dark .variable-autocomplete-hint {
    border-top-color: #374151;
}

.variable-autocomplete-hint kbd {
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-size: 0.65rem;
}

.dark .variable-autocomplete-hint kbd {
    background: #374151;
}

/* Variable Badge Styles */
.ql-variable-badge {
    background-color: #dbeafe;
    color: #2563eb;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-block;
    margin: 0 0.125rem;
    cursor: default;
    user-select: none;
}

.ql-variable-badge:hover {
    background-color: #bfdbfe;
}

/* Dark mode */
.dark .ql-variable-badge {
    background-color: #1e3a8a;
    color: #93c5fd;
}

.dark .ql-variable-badge:hover {
    background-color: #1e40af;
}

/* ========== Bouton correction IA ========== */
.ai-correct-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 6px 14px;
    background-color: #667eea !important;
    color: #fff !important;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.ai-correct-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    background-color: #5a67d8 !important;
    color: #fff !important;
}

.ai-correct-btn:active:not(:disabled) {
    transform: translateY(0);
}

.ai-correct-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.ai-correct-btn .btn-text {
    display: inline-block;
}

/* Dark mode */
.dark .ai-correct-btn {
    background: linear-gradient(135deg, #5a67d8 0%, #6b46c1 100%);
    box-shadow: 0 2px 4px rgba(90, 103, 216, 0.3);
}

.dark .ai-correct-btn:hover:not(:disabled) {
    box-shadow: 0 4px 12px rgba(90, 103, 216, 0.5);
}

/* ========== Modal de prévisualisation IA ========== */
.ai-preview-modal {
    backdrop-filter: blur(4px);
}

.ai-preview-modal.hidden {
    display: none;
}

/* Prose styling pour le contenu HTML */
.prose {
    max-width: none;
}

.prose p {
    margin-bottom: 0.75rem;
}

.prose strong {
    font-weight: 600;
}

.prose a {
    color: #2563eb;
    text-decoration: underline;
}

.dark .prose {
    color: #d1d5db;
}

.dark .prose a {
    color: #60a5fa;
}

/* Variables badges dans la prévisualisation */
.prose .ql-variable-badge {
    background-color: #dbeafe;
    color: #2563eb;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-family: ui-monospace, monospace;
    font-size: 0.875rem;
    font-weight: 500;
    display: inline-block;
    margin: 0 0.125rem;
}

.dark .prose .ql-variable-badge {
    background-color: #1e3a8a;
    color: #93c5fd;
}