/* Modern TipTap Editor Styles */
.tiptap-editor-wrapper {
    border-radius: 0.75rem;
    overflow: visible;
    box-shadow: 0 20px 25px -5px rgba(var(--depth-shadow-rgb), 0.1), 0 10px 10px -5px rgba(var(--depth-shadow-rgb), 0.04);
    position: relative;
}

.simple-editor-menubar {
    align-items: center;
    background: var(--header-n1-bg);
    border-bottom: 1px solid var(--surface-highlight);
    border-radius: 0.75rem 0.75rem 0 0;
    display: flex;
    flex-wrap: wrap;
    flex: 0 0 auto;
    padding: 0.5rem;
    gap: 0.125rem;
    min-height: 2.5rem;
}

.simple-editor-menubar .menu-item {
    background: transparent;
    border: 0;
    border-radius: 0.375rem;
    color: var(--sidebar-muted);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    height: 2rem;
    padding: 0 0.5rem;
    min-width: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.simple-editor-menubar .menu-item svg {
    width: 1.125rem;
    height: 1.125rem;
}

.simple-editor-menubar .menu-item:hover {
    background-color: var(--sidebar-row-hover);
    color: var(--header-n1-text);
}

.simple-editor-menubar .menu-item.is-active {
    background-color: var(--color-primary-600);
    color: var(--header-n1-text);
}

.simple-editor-menubar .menu-item.is-active:hover {
    background-color: var(--color-primary-700);
}

.simple-editor-menubar .menu-item.is-disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.simple-editor-menubar .menu-item.is-disabled:hover {
    background-color: transparent;
    color: var(--sidebar-muted);
}

.simple-editor-menubar .separator {
    background-color: var(--surface-highlight);
    height: 1.5rem;
    margin: 0 0.25rem;
    width: 1px;
}

.ProseMirror {
    outline: none;
    background: transparent;
    flex: 1 1 auto;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    line-height: 1.5;
}

/* Dark theme for light mode */
.dark .tiptap-editor-wrapper {
    background: var(--header-n1-bg);
}

.dark .simple-editor-menubar {
    background: var(--header-n1-bg);
    border-bottom-color: var(--surface-highlight);
}

.dark .ProseMirror {
    background: color-mix(in srgb, var(--header-n1-bg) 78%, black);
    color: var(--header-n1-muted);
}

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

/* Prose styling */
.ProseMirror h1 {
    font-size: 1.875rem;
    font-weight: bold;
    line-height: 2.25rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.ProseMirror h1:first-child {
    margin-top: 0;
}

.ProseMirror h2 {
    font-size: 1.5rem;
    font-weight: bold;
    line-height: 2rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.ProseMirror h2:first-child {
    margin-top: 0;
}

.ProseMirror p {
    margin-bottom: 0.5rem;
}

.ProseMirror p:last-child {
    margin-bottom: 0;
}

.ProseMirror ul, .ProseMirror ol {
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
    margin-top: 0.25rem;
}

.ProseMirror ul {
    list-style-type: disc;
}

.ProseMirror ol {
    list-style-type: decimal;
}

.ProseMirror li {
    margin-bottom: 0.125rem;
    display: list-item;
}

.ProseMirror li p {
    margin-bottom: 0;
}

.ProseMirror blockquote {
    border-left: 4px solid var(--surface-line);
    padding-left: 1rem;
    margin-left: 0;
    margin-right: 0;
    font-style: italic;
    margin-bottom: 1rem;
}

.ProseMirror hr {
    border: none;
    height: 2px;
    background-color: var(--surface-line);
    margin: 2rem 0;
}

.ProseMirror code {
    background-color: var(--panel-tint-strong);
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
}

.dark .ProseMirror code {
    background-color: var(--header-n2-bg);
}

/* Variables en pastilles insécables, reprises de Paravenda : dans l'éditeur riche
   (contrôleur tiptap) et dans le texte d'une ligne (PlaceholderTextType, contrôleur
   placeholder-text). Couleurs par rôles : la pastille suit la couleur primaire de
   la charte du tenant. */
.tiptap-placeholder {
    display: inline-flex;
    align-items: center;
    margin-inline: 0.125rem;
    border: 1px solid rgba(var(--color-primary-rgb), 0.3);
    border-radius: 999px;
    background: rgba(var(--color-primary-rgb), 0.1);
    padding: 0.0625rem 0.45rem;
    color: var(--color-primary-700);
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.35rem;
    user-select: none;
    cursor: default;
}

.dark .tiptap-placeholder {
    border-color: rgba(var(--color-primary-rgb), 0.45);
    background: rgba(var(--color-primary-rgb), 0.25);
    color: var(--header-n1-text);
}

.tiptap-placeholder-menu {
    position: relative;
    margin-left: auto;
}

.simple-editor-menubar .tiptap-placeholder-trigger {
    gap: 0.375rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.tiptap-placeholder-trigger[aria-expanded="true"] {
    background-color: var(--sidebar-row-hover);
    color: var(--header-n1-text);
}

.tiptap-placeholder-dropdown {
    position: absolute;
    top: calc(100% + 0.375rem);
    right: 0;
    z-index: 30;
    width: min(18rem, calc(100vw - 3rem));
    max-height: 18rem;
    overflow-y: auto;
    border: 1px solid var(--surface-line);
    border-radius: 0.75rem;
    background: var(--panel-bg);
    padding: 0.25rem;
    box-shadow: 0 18px 40px rgba(var(--depth-shadow-rgb), 0.2);
}

.tiptap-placeholder-option {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    padding: 0.625rem 0.75rem;
    color: var(--ink);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.tiptap-placeholder-option:hover,
.tiptap-placeholder-option:focus-visible {
    background: var(--panel-tint);
    outline: none;
}

.tiptap-placeholder-option code {
    color: var(--ink-subtle);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.6875rem;
}

/* Texte d'une ligne avec variables : le cadre est celui d'un champ du formulaire
   (kiarana-form-control), le bouton « Variable » se loge à droite. */
.placeholder-text {
    position: relative;
    margin-top: 0.125rem;
    margin-bottom: 0.125rem;
    overflow: visible;
}

.placeholder-text:focus-within {
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 1px var(--color-primary-500);
}

.placeholder-text-editor {
    min-height: 2.25rem;
    overflow-x: auto;
    padding: 0.375rem 7rem 0.375rem 0.625rem;
    color: var(--form-control-text);
    font-size: 0.875rem;
    line-height: 1.5rem;
    cursor: text;
}

.placeholder-text-prosemirror {
    min-width: max-content;
    min-height: 1.5rem;
    outline: 0;
    white-space: pre;
}

.placeholder-text-menu {
    position: absolute;
    top: 50%;
    right: 0.375rem;
    z-index: 20;
    transform: translateY(-50%);
}

.placeholder-text-menu .tiptap-placeholder-dropdown {
    top: calc(100% + 0.5rem);
}

.placeholder-text-trigger {
    display: inline-flex;
    height: 1.75rem;
    align-items: center;
    gap: 0.375rem;
    border: 0;
    border-radius: 0.5rem;
    background: var(--panel-tint-strong);
    padding: 0 0.625rem;
    color: var(--ink-muted);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease;
}

.placeholder-text-trigger:hover,
.placeholder-text-trigger[aria-expanded="true"] {
    background: rgba(var(--color-primary-rgb), 0.12);
    color: var(--color-primary-700);
}

/* Dropdown styles */
.dropdown-container {
    position: relative;
    display: inline-block;
}

.dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: auto;
}

.dropdown-toggle span {
    font-size: 0.875rem;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 1000;
    min-width: 250px;
    background: var(--header-n1-bg);
    border: 1px solid var(--surface-highlight);
    border-radius: 0.375rem;
    padding: 0.5rem;
    display: none;
    box-shadow: 0 10px 15px -3px rgba(var(--depth-shadow-rgb), 0.3), 0 4px 6px -2px rgba(var(--depth-shadow-rgb), 0.05);
    max-height: 300px;
    overflow-y: auto;
}

.dropdown-menu.show {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem;
    background: transparent;
    border: none;
    border-radius: 0.25rem;
    color: var(--header-n1-muted);
    text-align: left;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.dropdown-item:hover {
    background: var(--sidebar-row-hover);
}

.dropdown-item.is-active {
    background: var(--color-primary-600);
    color: var(--header-n1-text);
}

.dropdown-item svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* Task list styles */
.ProseMirror ul[data-type="taskList"] {
    list-style: none;
    padding: 0;
}

.ProseMirror ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
}

.ProseMirror ul[data-type="taskList"] li > label {
    flex: 0 0 auto;
    margin-right: 0.5rem;
    user-select: none;
}

.ProseMirror ul[data-type="taskList"] li > label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary-600);
}

.ProseMirror ul[data-type="taskList"] li > div {
    flex: 1 1 auto;
}

/* Ensure buttons in editor are visible */
.ProseMirror button {
    background: var(--color-primary-600) !important;
    color: var(--header-n1-text) !important;
    padding: 0.5rem 1rem !important;
    border-radius: 0.375rem !important;
    border: none !important;
    cursor: pointer !important;
    font-weight: 500 !important;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.ProseMirror button:hover {
    background: var(--color-primary-700) !important;
}

/* Ensure checkboxes are visible */
.ProseMirror input[type="checkbox"] {
    width: 1rem !important;
    height: 1rem !important;
    accent-color: var(--color-primary-600) !important;
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    cursor: pointer !important;
}

/* Rendu en lecture du texte riche saisi dans l'application : consignes de site,
   affichées au collaborateur sur son passage. */
.tiptap-rendered p {
    margin: 0 0 0.5rem;
}

.tiptap-rendered p:last-child {
    margin-bottom: 0;
}

.tiptap-rendered ul,
.tiptap-rendered ol {
    margin: 0 0 0.5rem 1.25rem;
    list-style: revert;
}

.tiptap-rendered h2,
.tiptap-rendered h3,
.tiptap-rendered h4 {
    margin: 0.75rem 0 0.25rem;
    font-weight: 600;
}

.tiptap-rendered blockquote {
    margin: 0 0 0.5rem;
    border-left: 3px solid currentColor;
    padding-left: 0.75rem;
    opacity: 0.85;
}

.tiptap-rendered img,
.tiptap-editor-wrapper img.tiptap-image {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 0.5rem 0;
    border-radius: 0.5rem;
}

.tiptap-rendered a {
    text-decoration: underline;
}
