/**
 * TipTap Menus - Context Menu & Bubble Menu
 * Menu contextuel personnalisé et bubble menu de formatage
 */

/* ============================================================================
   MENU CONTEXTUEL
   ============================================================================ */

.tiptap-context-menu {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

.ctx-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.15s ease;
    text-align: left;
    position: relative;
    font-size: 0.85rem;
    color: var(--text-primary, #212529);
}

.ctx-menu-item .ctx-menu-arrow {
    margin-left: auto;
    font-size: 12px;
    opacity: 0.5;
}

.ctx-menu-item:hover:not(:disabled) {
    background: var(--hover-bg, rgba(0, 0, 0, 0.05));
}

.ctx-menu-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ctx-menu-item i {
    width: 16px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted, #6c757d);
}

.ctx-menu-item span {
    color: inherit;
}

.ctx-menu-divider {
    margin: 4px 0;
    border: none;
    border-top: 1px solid var(--border-color, #e9ecef);
}

/* Section synonymes */
.ctx-menu-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
}

.ctx-menu-back {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: background 0.15s;
}

.ctx-menu-back:hover {
    background: #f3f4f6;
}

.ctx-menu-word {
    font-weight: 600;
    color: #111827;
}

.ctx-menu-synonyms-list {
    max-height: 300px;
    overflow-y: auto;
}

.ctx-menu-synonym {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    border-radius: 6px;
    transition: background 0.15s;
    color: #374151;
}

.ctx-menu-synonym:hover {
    background: #eff6ff;
    color: var(--zk-yellow);
}

.ctx-menu-loading,
.ctx-menu-empty,
.ctx-menu-error {
    padding: 16px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

.ctx-menu-error {
    color: var(--bs-danger-text-emphasis);
}

/* ============================================================================
   SOUS-MENU SYNONYMES (FLYOUT)
   ============================================================================ */

.tiptap-synonyms-submenu {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

.ctx-menu-word-label {
    display: block;
    padding: 8px 12px;
    font-weight: 600;
    color: #111827;
    font-size: 13px;
}

.tiptap-synonyms-submenu .ctx-menu-synonym {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    border-radius: 6px;
    transition: background 0.15s;
    color: #374151;
}

.tiptap-synonyms-submenu .ctx-menu-synonym:hover {
    background: #eff6ff;
    color: var(--zk-yellow);
}

.tiptap-synonyms-submenu .ctx-menu-loading,
.tiptap-synonyms-submenu .ctx-menu-empty,
.tiptap-synonyms-submenu .ctx-menu-error {
    padding: 16px;
    text-align: center;
    color: #6b7280;
    font-size: 13px;
}

.tiptap-synonyms-submenu .ctx-menu-error {
    color: var(--bs-danger-text-emphasis);
}

/* ============================================================================
   BUBBLE MENU
   ============================================================================ */

.tiptap-bubble-menu {
    align-items: center;
    position: fixed;
    z-index: 10000;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 4px;
    gap: 2px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tiptap-bubble-menu[style*="display: flex"] {
    display: flex;
}

.tiptap-bubble-menu[style*="display: none"] {
    display: none;
}

/* Triangle pointant vers la sélection */
.tiptap-bubble-menu::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid white;
}

.bubble-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}

.bubble-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.bubble-btn.active {
    background: #eff6ff;
    color: var(--zk-yellow);
}

.bubble-btn i {
    font-size: 16px;
}

.bubble-divider {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
    margin: 0 4px;
}

/* ============================================================================
   THÈMES
   ============================================================================ */

/* Thème Dark */
html[data-theme="dark"] .tiptap-context-menu {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .ctx-menu-item {
    color: #e5e5e5;
}

html[data-theme="dark"] .ctx-menu-item:hover:not(:disabled) {
    background: rgba(242, 209, 35, 0.15);
    color: #f2d123;
}

html[data-theme="dark"] .ctx-menu-item i {
    color: #9ca3af;
}

html[data-theme="dark"] .ctx-menu-item:hover i {
    color: #f2d123;
}

html[data-theme="dark"] .ctx-menu-divider {
    border-color: #333;
}

html[data-theme="dark"] .ctx-menu-header {
    border-bottom-color: #374151;
}

html[data-theme="dark"] .ctx-menu-word {
    color: #f9fafb;
}

html[data-theme="dark"] .ctx-menu-synonym {
    color: #e5e7eb;
}

html[data-theme="dark"] .ctx-menu-synonym:hover {
    background: #1e3a8a;
    color: #93c5fd;
}

html[data-theme="dark"] .ctx-menu-back:hover {
    background: #374151;
}

html[data-theme="dark"] .tiptap-bubble-menu {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .tiptap-bubble-menu::after {
    border-top-color: #1f2937;
}

html[data-theme="dark"] .bubble-btn {
    color: #9ca3af;
}

html[data-theme="dark"] .bubble-btn:hover {
    background: #374151;
    color: #e5e7eb;
}

html[data-theme="dark"] .bubble-btn.active {
    background: rgba(59, 130, 246, 0.2);
    color: var(--zk-yellow);
}

html[data-theme="dark"] .bubble-divider {
    background: #374151;
}

html[data-theme="dark"] .tiptap-synonyms-submenu {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .ctx-menu-word-label {
    color: #f9fafb;
}

html[data-theme="dark"] .tiptap-synonyms-submenu .ctx-menu-synonym {
    color: #e5e7eb;
}

html[data-theme="dark"] .tiptap-synonyms-submenu .ctx-menu-synonym:hover {
    background: #1e3a8a;
    color: #93c5fd;
}

/* Thème Zkriva */
html[data-theme="zkriva"] .tiptap-context-menu {
    background: #fffbf5;
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .ctx-menu-item {
    color: #1c1917;
}

html[data-theme="zkriva"] .ctx-menu-item:hover:not(:disabled) {
    background: rgba(210, 180, 145, 0.12);
    color: #d2b491;
}

html[data-theme="zkriva"] .ctx-menu-item i {
    color: #78716c;
}

html[data-theme="zkriva"] .ctx-menu-item:hover i {
    color: #d2b491;
}

html[data-theme="zkriva"] .ctx-menu-divider {
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .ctx-menu-synonym:hover {
    background: rgba(210, 180, 145, 0.12);
    color: #d2b491;
}

html[data-theme="zkriva"] .bubble-btn.active {
    background: rgba(210, 180, 145, 0.2);
    color: #e5cdb3;
}

html[data-theme="zkriva"] .tiptap-bubble-menu {
    background: #fffbf5;
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .tiptap-bubble-menu::after {
    border-top-color: #fffbf5;
}

html[data-theme="zkriva"] .bubble-btn {
    color: #57534e;
}

html[data-theme="zkriva"] .bubble-btn:hover {
    background: rgba(210, 180, 145, 0.08);
    color: #1c1917;
}

html[data-theme="zkriva"] .bubble-divider {
    background: #e7e5e4;
}

html[data-theme="zkriva"] .tiptap-synonyms-submenu {
    background: #fffbf5;
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .ctx-menu-word-label {
    color: #1c1917;
}

html[data-theme="zkriva"] .tiptap-synonyms-submenu .ctx-menu-synonym {
    color: #57534e;
}

html[data-theme="zkriva"] .tiptap-synonyms-submenu .ctx-menu-synonym:hover {
    background: rgba(210, 180, 145, 0.12);
    color: #d2b491;
}

/* ============================================================================
   MENU IMAGE
   ============================================================================ */

.tiptap-image-menu {
    position: fixed;
    z-index: 10001;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 8px;
    display: none;
    min-width: 280px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
}

.img-menu-section {
    margin-bottom: 8px;
}

.img-menu-section:last-child {
    margin-bottom: 0;
}

.img-menu-label {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding: 0 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.img-menu-width-display {
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    text-transform: none;
}

.img-menu-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e5e7eb;
    outline: none;
    -webkit-appearance: none;
    margin-bottom: 8px;
}

.img-menu-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--zk-yellow);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.img-menu-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--zk-yellow);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.img-menu-btn-sm {
    font-size: 11px;
    padding: 0 8px;
}

.img-menu-btn-group {
    display: flex;
    gap: 4px;
}

.img-menu-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    font-weight: 500;
    color: #374151;
}

.img-menu-btn:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.img-menu-btn.active {
    background: #eff6ff;
    border-color: var(--zk-yellow);
    color: var(--zk-yellow);
}

.img-menu-btn i {
    font-size: 18px;
}

.img-menu-btn-full {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid #fca5a5;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    color: var(--bs-danger-text-emphasis);
}

.img-menu-btn-full:hover {
    background: #fef2f2;
    border-color: var(--bs-danger-border-subtle);
}

.img-menu-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 8px 0;
}

/* Style des images dans l'éditeur */
.tiptap-image,
.ProseMirror img {
    max-width: 100%;
    height: auto;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

.tiptap-image:hover,
.ProseMirror img:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Thème Dark */
html[data-theme="dark"] .tiptap-image-menu {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .img-menu-label {
    color: #9ca3af;
}

html[data-theme="dark"] .img-menu-width-display {
    color: #e5e7eb;
}

html[data-theme="dark"] .img-menu-slider {
    background: #374151;
}

html[data-theme="dark"] .img-menu-slider::-webkit-slider-thumb {
    background: var(--zk-yellow);
    border-color: #1f2937;
}

html[data-theme="dark"] .img-menu-slider::-moz-range-thumb {
    background: var(--zk-yellow);
    border-color: #1f2937;
}

html[data-theme="dark"] .img-menu-btn {
    background: #111827;
    border-color: #374151;
    color: #e5e7eb;
}

html[data-theme="dark"] .img-menu-btn:hover {
    background: #374151;
    border-color: #4b5563;
}

html[data-theme="dark"] .img-menu-btn.active {
    background: #1e3a8a;
    border-color: var(--zk-yellow);
    color: #93c5fd;
}

html[data-theme="dark"] .img-menu-btn-full {
    background: #111827;
    border-color: #991b1b;
}

html[data-theme="dark"] .img-menu-btn-full:hover {
    background: #450a0a;
}

html[data-theme="dark"] .img-menu-divider {
    background: #374151;
}

/* Thème Zkriva */
html[data-theme="zkriva"] .tiptap-image-menu {
    background: #fffbf5;
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .img-menu-btn:hover {
    background: rgba(210, 180, 145, 0.08);
}

html[data-theme="zkriva"] .img-menu-btn.active {
    background: rgba(210, 180, 145, 0.12);
    border-color: #d2b491;
    color: #d2b491;
}

html[data-theme="zkriva"] .img-menu-width-display {
    color: #1c1917;
}

html[data-theme="zkriva"] .img-menu-slider {
    background: #e7e5e4;
}

html[data-theme="zkriva"] .img-menu-slider::-webkit-slider-thumb {
    background: #d2b491;
    border-color: #fffbf5;
}

html[data-theme="zkriva"] .img-menu-slider::-moz-range-thumb {
    background: #d2b491;
    border-color: #fffbf5;
}

/* ============================================================================
   IMAGE TOOLBAR (NOUVELLE - Style maquette)
   ============================================================================ */

.tiptap-image-toolbar {
    position: fixed;
    z-index: 10002;
    display: none;
    align-items: center;
    gap: 2px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.img-toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}

.img-toolbar-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.img-toolbar-btn.active {
    background: #eff6ff;
    color: var(--zk-yellow);
}

.img-toolbar-btn-accent {
    color: #f97316 !important;
}

.img-toolbar-btn-accent:hover {
    background: #fff7ed !important;
}

.img-toolbar-btn i {
    font-size: 16px;
}

.img-toolbar-divider {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
    margin: 0 4px;
}

/* ============================================================================
   RESIZE HANDLES (8 poignées)
   ============================================================================ */

.img-resize-handle {
    position: fixed;
    width: 8px;
    height: 8px;
    background: var(--zk-yellow);
    border: 2px solid white;
    border-radius: 2px;
    z-index: 10001;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.img-resize-handle:hover {
    background: var(--zk-yellow);
    transform: scale(1.3);
}

/* Image sélectionnée */
.img-selected {
    outline: 2px solid var(--zk-yellow);
    outline-offset: -2px;
}

/* ============================================================================
   CAPTION INPUT (en dessous de l'image)
   ============================================================================ */

.img-caption-wrapper {
    display: block !important;
    margin: 1rem auto !important;
    max-width: 100% !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.img-caption-container {
    display: block !important;
    margin-top: 12px !important;
    padding: 0 !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
}

.img-caption-input {
    display: block !important;
    width: 100% !important;
    background: #ffffff !important;
    border: 2px solid var(--zk-yellow) !important;
    border-radius: 6px !important;
    padding: 12px 16px !important;
    font-size: 15px !important;
    font-weight: 400 !important;
    color: #111827 !important;
    outline: none !important;
    transition: all 0.2s !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    min-height: 44px !important;
    z-index: 10000 !important;
    position: relative !important;
}

.img-caption-input:focus {
    background: #ffffff;
    border-color: var(--zk-yellow);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1);
}

.img-caption-input::placeholder {
    color: #9ca3af;
}

/* ============================================================================
   THÈMES - Image Toolbar
   ============================================================================ */

/* Dark */
html[data-theme="dark"] .tiptap-image-toolbar {
    background: #1f2937;
    border-color: #374151;
}

html[data-theme="dark"] .img-toolbar-btn {
    color: #9ca3af;
}

html[data-theme="dark"] .img-toolbar-btn:hover {
    background: #374151;
    color: #e5e7eb;
}

html[data-theme="dark"] .img-toolbar-btn.active {
    background: #1e3a8a;
    color: #93c5fd;
}

html[data-theme="dark"] .img-toolbar-btn-accent {
    color: #fb923c !important;
}

html[data-theme="dark"] .img-toolbar-btn-accent:hover {
    background: #431407 !important;
}

html[data-theme="dark"] .img-toolbar-divider {
    background: #374151;
}

html[data-theme="dark"] .img-resize-handle {
    background: var(--zk-yellow);
    border-color: #1f2937;
}

html[data-theme="dark"] .img-selected {
    outline-color: var(--zk-yellow);
}

/* Zkriva */
html[data-theme="zkriva"] .tiptap-image-toolbar {
    background: #fffbf5;
    border-color: #e7e5e4;
}

html[data-theme="zkriva"] .img-toolbar-btn {
    color: #57534e;
}

html[data-theme="zkriva"] .img-toolbar-btn:hover {
    background: rgba(210, 180, 145, 0.08);
    color: #1c1917;
}

html[data-theme="zkriva"] .img-toolbar-btn.active {
    background: rgba(210, 180, 145, 0.12);
    color: #d2b491;
}

html[data-theme="zkriva"] .img-toolbar-divider {
    background: #e7e5e4;
}

html[data-theme="zkriva"] .img-resize-handle {
    background: #d2b491;
    border-color: #fffbf5;
}

html[data-theme="zkriva"] .img-selected {
    outline-color: #d2b491;
}

/* ============================================================================
   THÈMES - Caption Input
   ============================================================================ */

/* Dark */
html[data-theme="dark"] .img-caption-input {
    background: #1f2937;
    border-color: #4b5563;
    color: #f9fafb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .img-caption-input:focus {
    background: #1f2937;
    border-color: var(--zk-yellow);
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.1), 0 1px 3px rgba(0, 0, 0, 0.5);
}

html[data-theme="dark"] .img-caption-input::placeholder {
    color: #6b7280;
}

/* Zkriva */
html[data-theme="zkriva"] .img-caption-input {
    background: #fffbf5;
    border-color: #e7e5e4;
    color: #1c1917;
}

html[data-theme="zkriva"] .img-caption-input:focus {
    background: #fffbf5;
    border-color: #d2b491;
    box-shadow: 0 0 0 3px rgba(210, 180, 145, 0.1), 0 1px 3px rgba(0, 0, 0, 0.1);
}

html[data-theme="zkriva"] .img-caption-input::placeholder {
    color: #a8a29e;
}
