/* Markdown note styles */

/* Hide separator, emoji and table buttons for markdown notes */
.innernote[data-markdown-note="true"] .btn-separator,
.innernote[data-markdown-note="true"] .btn-emoji,
.innernote[data-markdown-note="true"] .btn-table,
.innernote[data-markdown-note="true"] .btn-checklist {
    display: none !important;
}

.markdown-preview {
    /* padding: 5px; */
    min-height: 100px;
}

.markdown-editor {
    padding: 10px;
    min-height: 100px;
    font-family: 'Courier New', Courier, monospace;
    white-space: pre-wrap;
    word-wrap: break-word;
    background-color: transparent;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    /* Prevent parent container from scrolling when cursor moves */
    overflow-anchor: none;
}

.markdown-editor:focus {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
}

.markdown-editor:empty:before {
    content: attr(data-ph);
    color: #999;
}

/* Markdown rendered content styles */
.markdown-preview h1 {
    font-size: 2em;
    font-weight: bold;
    margin: 0.67em 0;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.3em;
}

.markdown-preview h2 {
    font-size: 1.5em;
    font-weight: bold;
    margin: 0.75em 0;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.3em;
}

.markdown-preview h3 {
    font-size: 1.25em;
    font-weight: bold;
    margin: 0.83em 0;
}

.markdown-preview h4 {
    font-size: 1em;
    font-weight: bold;
    margin: 1em 0;
}

.markdown-preview h5 {
    font-size: 0.875em;
    font-weight: bold;
    margin: 1.33em 0;
}

.markdown-preview h6 {
    font-size: 0.75em;
    font-weight: bold;
    margin: 1.67em 0;
    color: #666;
}

.markdown-preview p {
    margin: 0 0 1em 0;
    line-height: 1.6;
}

/* Blank lines to preserve spacing in markdown */
.markdown-preview p.blank-line {
    margin: 0;
    min-height: 1.6em;
    /* Match the line-height */
    line-height: 1.6;
}

.markdown-preview p:first-child {
    margin-top: 0;
}

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

.markdown-preview code {
    background-color: #f4f4f4;
    padding: 2px 6px;
    /* border-radius: 3px; */
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #333;
}

.markdown-preview pre {
    background-color: #f4f4f4;
    padding: 12px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 1em 0 !important;
}

.markdown-preview pre code {
    background-color: transparent;
    padding: 0;
    color: inherit;
    border-radius: 0;
}

.markdown-preview blockquote,
.noteentry blockquote {
    border-left: 4px solid #ddd;
    padding-left: 16px;
    margin: 1em 0;
    color: #666;
    font-style: italic;
}

.markdown-preview ul,
.markdown-preview ol {
    margin: 1em 0;
    padding-left: 2em;
}

.markdown-preview li {
    margin: 0.5em 0;
    line-height: 1.6;
}

.markdown-preview ul {
    list-style-type: disc;
}

.markdown-preview ol {
    list-style-type: decimal;
}

.markdown-preview a {
    color: #007bff;
    text-decoration: none;
}

.markdown-preview a:hover {
    text-decoration: underline;
}

.markdown-preview img,
.markdown-preview iframe {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 1em 0;
}

.markdown-preview iframe {
    border: none;
}

.markdown-preview video {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1em 0;
    background: #000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.markdown-preview audio,
.markdown-preview .note-audio-embed {
    max-width: 280px;
    display: block;
    margin: 8px 0;
    border-radius: 8px;
    background: #f1f3f4;
}

@media screen and (max-width: 768px) {

    .markdown-preview audio,
    .markdown-preview .note-audio-embed {
        max-width: 240px;
    }
}

.markdown-preview iframe[data-is-audio] {
    max-width: 280px;
    width: 100%;
    height: 54px;
    display: block;
    overflow: hidden;
    margin: 8px 0;
    border: none;
    border-radius: 8px;
    background: transparent;
}

.markdown-preview iframe.note-audio-embed {
    max-width: 280px;
    width: 100%;
    height: 54px;
    display: block;
    overflow: hidden;
    margin: 8px 0;
    border: none;
    border-radius: 8px;
    background: transparent;
}

@media screen and (max-width: 768px) {
    .markdown-preview iframe[data-is-audio] {
        max-width: 240px;
    }

    .markdown-preview iframe.note-audio-embed {
        max-width: 240px;
    }
}

.markdown-preview hr {
    border: 0;
    border-top: 2px solid #e0e0e0;
    margin: 2em 0;
}

.markdown-preview strong {
    font-weight: bold;
}

.markdown-preview em {
    font-style: italic;
}

.markdown-preview del {
    text-decoration: line-through;
    color: #999;
}

.markdown-preview table {
    border-collapse: collapse;
    width: 100%;
    margin: 1em 0;
}

.markdown-preview table th,
.markdown-preview table td {
    border: 1px solid #ddd;
    padding: 8px 12px;
    text-align: left;
}

.markdown-preview table th {
    background-color: #f4f4f4;
    font-weight: bold;
}

.markdown-preview table tr:nth-child(even) {
    background-color: #f9f9f9;
}

/* Task lists (checkboxes) */
.markdown-preview ul.task-list {
    list-style: none;
    padding-left: 0;
}

.markdown-preview li.task-list-item {
    list-style: none;
    position: relative;
    padding-left: 0;
}

.markdown-preview li.task-list-item input[type="checkbox"] {
    margin-right: 0.5em;
    cursor: pointer;
    vertical-align: middle;
}

/* Interactive markdown checkbox styling */
.markdown-preview .markdown-task-checkbox {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: #007DB8;
}

.markdown-preview .markdown-task-checkbox:hover {
    transform: scale(1.1);
    transition: transform 0.1s ease;
}

/* Nested task lists need indentation */
.markdown-preview li.task-list-item>ul.task-list,
.markdown-preview li.task-list-item>ul,
.markdown-preview li.task-list-item>ol {
    padding-left: 1.5em;
    margin: 0.5em 0;
}

/* Style for checked task items */
.markdown-preview li.task-list-item input[type="checkbox"]:checked+span {
    text-decoration: line-through;
    color: #888;
}

/* Click-to-navigate hint in split mode */
.noteentry.markdown-split-mode .markdown-preview [data-line]:not(.markdown-task-checkbox):not(summary):not(details) {
    transition: background-color 0.15s ease;
}

.noteentry.markdown-split-mode .markdown-preview [data-line]:not(.markdown-task-checkbox):not(summary):not(details):hover {
    background-color: rgba(0, 125, 184, 0.05);
    border-radius: 3px;
}

/* Indicateur visuel pour le drag & drop */
.noteentry.drag-over {
    border: 2px dashed #007DB8 !important;
    background-color: rgba(0, 125, 184, 0.05) !important;
    transition: all 0.2s ease;
}

.noteentry.drag-over .markdown-editor {
    background-color: rgba(0, 125, 184, 0.02);
    transition: background-color 0.2s ease;
}

/* Style pour le texte de chargement d'upload */
.markdown-editor {
    position: relative;
}

/* Supprimer complètement tous les cadres en mode édition markdown */
.noteentry[data-note-type="markdown"] .markdown-editor:focus {
    box-shadow: none !important;
    border: none !important;
    outline: none !important;
}

/* Supprimer aussi le cadre sur l'élément parent noteentry quand on édite du markdown */
.noteentry[data-note-type="markdown"]:focus {
    border: none !important;
    border-bottom: none !important;
    outline: none !important;
}

/* Placeholder for empty preview */
.markdown-preview-placeholder {
    color: #999;
    padding: 10px;
    text-align: left;
    opacity: 0.6;
}

.markdown-preview.empty {
    display: flex !important;
    align-items: flex-start;
    justify-content: flex-start;
}


/* Mermaid diagrams */
.mermaid {
    margin: 1em 0;
    text-align: center;
    background-color: white;
    /* Ensure visibility in dark mode if mermaid doesn't handle it */
    padding: 10px;
    border-radius: 4px;
}

/* Dark mode adjustment for mermaid container */
[data-theme='dark'] .mermaid {
    background-color: #333333;
}

/* Math equations styling */
.math-block {
    display: block;
    margin: 1em 0;
    padding: 0.5em 0;
    text-align: center;
    overflow-x: auto;
    overflow-y: hidden;
}

.math-inline {
    display: inline;
    margin: 0 0.2em;
}

/* KaTeX font adjustments for better readability */
.katex {
    font-size: 1.1em;
}

.math-block .katex {
    font-size: 1.21em;
}

/* Math error styling */
.math-block span[style*="color: #cc0000"],
.math-inline span[style*="color: #cc0000"] {
    font-family: monospace;
    font-size: 0.9em;
}

/* Dark mode adjustments for math */
[data-theme='dark'] .katex {
    color: #e0e0e0;
}

/* Split view mode styles */
.noteentry.markdown-split-mode {
    display: flex !important;
    flex-direction: row !important;
    gap: 0 !important;
    align-items: stretch !important;
    overflow: hidden !important;
    height: auto !important;
}

/* Hide overflow on parent containers when in split mode */
.innernote:has(.noteentry.markdown-split-mode) {
    overflow: hidden !important;
}

#right_col:has(.noteentry.markdown-split-mode) {
    overflow: hidden !important;
}

/* Fix for toolbar space in split view with tabs */
body.has-internal-tabs .innernote:has(.noteentry.markdown-split-mode) .note-header {
    top: 0 !important;
    position: relative !important;
}

.noteentry.markdown-split-mode .markdown-editor-container,
.noteentry.markdown-split-mode .markdown-editor {
    flex: 1 1 50% !important;
    width: 50% !important;
    min-width: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    border-right: 1px solid #e0e0e0 !important;
    box-sizing: border-box !important;
    max-height: calc(100vh - 200px) !important;
}

.noteentry.markdown-split-mode .markdown-preview {
    flex: 1 1 50% !important;
    width: 50% !important;
    min-width: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 10px 10px 10px 20px !important;
    box-sizing: border-box !important;
    max-height: calc(100vh - 200px) !important;
}

/* Dark mode border for split view */
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor-container,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor {
    border-right-color: #404040 !important;
}

/* Scrollbar styling for split view columns */
.noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar,
.noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar,
.noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar {
    width: 0;
    display: none;
}

.noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-track,
.noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-track,
.noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-track {
    display: none;
}

.noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-thumb,
.noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-thumb,
.noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-thumb {
    display: none;
}

.noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-thumb:hover,
.noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-thumb:hover,
.noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-thumb:hover {
    display: none;
}

/* Dark mode scrollbar for split view */
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-track,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-track,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-track {
    display: none;
}

[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-thumb,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-thumb,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-thumb {
    display: none;
}

[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor-container::-webkit-scrollbar-thumb:hover,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor::-webkit-scrollbar-thumb:hover,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-preview::-webkit-scrollbar-thumb:hover {
    display: none;
}

/* Firefox scrollbar styling for split view */
.noteentry.markdown-split-mode .markdown-editor-container,
.noteentry.markdown-split-mode .markdown-editor,
.noteentry.markdown-split-mode .markdown-preview {
    scrollbar-width: none;
}

[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor-container,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-editor,
[data-theme='dark'] .noteentry.markdown-split-mode .markdown-preview {
    scrollbar-width: none;
}