/* ELIZA Tiptap Editor PoC Styles */

/* Toolbar */
.tiptap-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 8px;
    border-bottom: 1px solid #cfd8e3;
    background: #f5faff;
    border-radius: 4px 4px 0 0;
}

.tiptap-toolbar button {
    border: none;
    background: none;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 3px;
    color: #555;
    display: flex;
    align-items: center;
    position: relative;
}

/* Schnelle Tooltips (erscheinen sofort statt nach Browser-Delay) */
.tiptap-toolbar button[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    font-size: 12px;
    padding: 3px 8px;
    border-radius: 3px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s;
    z-index: 100;
}

.tiptap-toolbar button:hover::after {
    opacity: 1;
}

.tiptap-toolbar button i.material-icons {
    font-size: 22px;
}

.tiptap-toolbar button:hover {
    background: #e3eef7;
}

.tiptap-toolbar button.is-active {
    background: #d6e7f4;
    color: #006699;
}

.tiptap-toolbar button:disabled {
    cursor: not-allowed;
    opacity: 0.3;
}

.tiptap-toolbar .tiptap-separator {
    width: 1px;
    height: 24px;
    background: #cfd8e3;
    margin: 0 4px;
    align-self: center;
}

/* Editor Content Area */
.tiptap-editor-content {
    padding: 12px 16px;
    min-height: 150px;
    border: 1px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 4px 4px;
}

/* Source View — Quelltext-Anzeige unter dem Editor (Constance: TIPTAP_SOURCE_VIEW_ENABLED) */
.tiptap-source-view {
    margin: 8px 0 0;
    padding: 12px 16px;
    background: #f5f5f5;
    color: #333;
    border: 1px solid #cfd8e3;
    border-radius: 4px;
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    max-height: 300px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.tiptap-editor-content .ProseMirror {
    outline: none;
    min-height: 120px;
}

.tiptap-editor-content .ProseMirror:focus {
    outline: none;
}

/* Typography - gleiche Schrift wie im View (.card-content) */
.tiptap-prose {
    font-size: 1rem;
    line-height: 1.6;
}

.tiptap-prose h1 { font-size: 1.8em; font-weight: 600; margin: 0.8em 0 0.4em; color: #333; }
.tiptap-prose h2 { font-size: 1.4em; font-weight: 600; margin: 0.6em 0 0.3em; color: #333; }
.tiptap-prose h3 { font-size: 1.2em; font-weight: 600; margin: 0.5em 0 0.2em; color: #333; }
.tiptap-prose p { margin: 0.4em 0; line-height: 1.6; }

/* Lists - MaterializeCSS Override (ul:not(.browser-default) > li entfernt list-style mit Spezifität 0,1,2) */
.tiptap-prose ul { padding-left: 1.5em; margin: 0.4em 0; list-style-type: disc; }
.tiptap-prose ol { padding-left: 1.5em; margin: 0.4em 0; list-style-type: decimal; }
.tiptap-prose ul ul { list-style-type: circle; }
.tiptap-prose ul ul ul { list-style-type: square; }
.tiptap-prose ul > li { margin: 0.2em 0; list-style-type: inherit; }
.tiptap-prose ol > li { margin: 0.2em 0; list-style-type: inherit; }
.tiptap-prose li p { margin: 0; }

/* Task List (Checkliste) — gilt im Editor (.tiptap-prose) und im
   gerenderten Markdown (.markdown), damit Detail-Views (z.B. Newskanal-
   Beiträge) die Tiptap-Checklisten gleich darstellen wie der Editor. */
.tiptap-prose ul[data-type="taskList"],
.markdown ul[data-type="taskList"] {
    list-style: none;
    padding-left: 0;
    margin: 0.4em 0;
}

.tiptap-prose ul[data-type="taskList"] li,
.markdown ul[data-type="taskList"] li {
    display: flex;
    align-items: flex-start;
    gap: 0.5em;
    margin: 0.3em 0;
}

.tiptap-prose ul[data-type="taskList"] li label,
.markdown ul[data-type="taskList"] li label {
    margin-top: 0.2em;
    flex-shrink: 0;
}

.tiptap-prose ul[data-type="taskList"] li label input[type="checkbox"],
.markdown ul[data-type="taskList"] li label input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
    accent-color: #006699;
    /* MaterializeCSS Override: Standard-Checkbox statt verstecktes Checkbox */
    opacity: 1 !important;
    position: relative !important;
    pointer-events: auto !important;
    appearance: auto !important;
    -webkit-appearance: checkbox !important;
    margin: 0 !important;
}

/* MaterializeCSS Pseudo-Elemente innerhalb Task-Listen komplett deaktivieren */
.tiptap-prose ul[data-type="taskList"] [type="checkbox"] + span:not(.lever):before,
.tiptap-prose ul[data-type="taskList"] [type="checkbox"] + span:not(.lever):after,
.tiptap-prose ul[data-type="taskList"] [type="checkbox"]:not(.filled-in) + span:not(.lever):after,
.markdown ul[data-type="taskList"] [type="checkbox"] + span:not(.lever):before,
.markdown ul[data-type="taskList"] [type="checkbox"] + span:not(.lever):after,
.markdown ul[data-type="taskList"] [type="checkbox"]:not(.filled-in) + span:not(.lever):after {
    display: none !important;
}

.tiptap-prose ul[data-type="taskList"] [type="checkbox"] + span:not(.lever),
.markdown ul[data-type="taskList"] [type="checkbox"] + span:not(.lever) {
    padding-left: 0 !important;
    height: auto !important;
    line-height: normal !important;
}

.tiptap-prose ul[data-type="taskList"] li div,
.markdown ul[data-type="taskList"] li div {
    flex: 1;
}

/* Durchgestrichener Text bei erledigten Tasks — TipTap-TaskList-Format
   (data-checked) z.B. innerhalb von Tabellen, wo der HTML-Fallback greift */
.tiptap-prose ul[data-type="taskList"] li[data-checked="true"] > div > p,
.markdown ul[data-type="taskList"] li[data-checked="true"] > div > p {
    text-decoration: line-through;
    color: #999;
}

/* Durchgestrichener Text bei erledigten Tasks — GFM-Markdown-Format
   (`- [x] Item`), das markdown2 mit `task_list`-Extra ausserhalb von
   Tabellen erzeugt: <li><p><input class="task-list-item-checkbox" checked> Item</p></li>.
   Trello/Planner-konform: angehakte Items werden durchgestrichen.
   :has() seit Chrome 105+, Safari 15.4+, Firefox 121+ supported. */
.markdown li:has(input.task-list-item-checkbox:checked),
.tiptap-prose li:has(input.task-list-item-checkbox:checked) {
    text-decoration: line-through;
    color: #999;
}

/* Blockquote */
.tiptap-prose blockquote {
    border-left: 3px solid #006699;
    padding: 0.4em 1em;
    margin: 0.5em 0;
    background: #f5f9fc;
    color: #555;
}

/* Code */
.tiptap-prose code {
    background: #f4f4f4;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.9em;
}

.tiptap-prose pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px 16px;
    border-radius: 4px;
    font-family: 'Menlo', 'Consolas', monospace;
    font-size: 0.85em;
    overflow-x: auto;
}

.tiptap-prose pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* Table */
.tiptap-prose table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
    overflow: hidden;
}

.tiptap-prose th, .tiptap-prose td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: left;
    vertical-align: top;
    position: relative;
    min-width: 80px;
}

.tiptap-prose th {
    background: #f5f5f5;
    font-weight: 600;
}

/* Selected cell highlight */
.tiptap-prose td.selectedCell,
.tiptap-prose th.selectedCell {
    background: #e3f2fd;
}

/* Column resize handle */
.tiptap-prose .column-resize-handle {
    position: absolute;
    right: -2px;
    top: 0;
    bottom: 0;
    width: 4px;
    background: #006699;
    cursor: col-resize;
    z-index: 10;
}

.tiptap-prose .tableWrapper {
    overflow-x: auto;
    margin: 0.5em 0;
}

.tiptap-prose table p {
    margin: 0;
}

/* Listen in Tabellenzellen — kompakter, damit Bullets in engen Spalten nicht abgeschnitten werden */
.tiptap-prose td ul,
.tiptap-prose td ol,
.tiptap-prose th ul,
.tiptap-prose th ol {
    margin: 0.25em 0;
    padding-left: 1.2em;
}

.tiptap-prose td li,
.tiptap-prose th li {
    margin: 0.1em 0;
}

.tiptap-prose td li p,
.tiptap-prose th li p {
    margin: 0;
}

/* Images - im Editor */
.tiptap-prose img {
    max-width: 100%;
    max-height: 400px;
    height: auto;
    border-radius: 4px;
    margin: 0.5em 0;
    cursor: pointer;
    object-fit: contain;
}

.tiptap-prose img.ProseMirror-selectednode {
    outline: 2px solid #006699;
    outline-offset: 2px;
}

/* Bild-Resize via Toolbar-Buttons (imageOnly) - keine separaten DOM-Elemente nötig */

/* Images - im gerendertem Markdown (Detail-Views) und im TipTap-Editor.
   Selektoren bleiben breit (.card-content, .left-panel), damit auch
   Markdown-Renderings ohne expliziten .markdown-Wrapper (z.B. Forms-
   Fragetexte/Hilfetexte) eingebettete Bilder begrenzen. */
.card-content img:not(.avatar):not(.circle):not(.brand-logo):not(.materialboxed),
.left-panel img:not(.avatar):not(.circle):not(.brand-logo):not(.materialboxed) {
    max-width: 100%;
    max-height: 500px;
    height: auto;
    object-fit: contain;
}

/* .card-image-fixed (von Tutorials genutzt) von der breiten Begrenzung
   ausnehmen — sonst sprengen z.B. quadratische Defaults (900x900) das
   Card-Layout und der Titel verschwindet ausserhalb der Karte. !important
   nötig, weil die Markdown-Regel oben durch die :not()-Kette eine sehr
   hohe Spezifität (0,5,1) hat.

   Anmerkung: .card .card-image img wird hier bewusst NICHT global
   überschrieben. Templates wie issues/tracker_list.html haben bereits
   eigene !important-Workarounds (Kommentar im Template referenziert
   genau diese Regel), und ein globaler object-fit: cover-Override würde
   bestehende object-fit: contain-Renderings (tracker_list, streams etc.)
   ungefragt verändern. */
.card-image-fixed img {
    height: 350px !important;
    max-height: none !important;
    object-fit: cover !important;
}

/* Horizontal Rule */
.tiptap-prose hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 1em 0;
}

/* Link */
.tiptap-prose a {
    color: #006699;
    text-decoration: underline;
}

/* Bold, Italic */
.tiptap-prose strong { font-weight: 600; }
.tiptap-prose em { font-style: italic; }

/* Placeholder */
.tiptap-prose p.is-editor-empty:first-child::before {
    content: 'Text eingeben...';
    color: #aaa;
    float: left;
    height: 0;
    pointer-events: none;
}

/* Dark Mode Support */
html[theme="dark"] .tiptap-toolbar { background: #1e1e1e; border-color: #444; }
html[theme="dark"] .tiptap-toolbar button { color: #ccc; }
html[theme="dark"] .tiptap-toolbar button:hover { background: #333; }
html[theme="dark"] .tiptap-toolbar button.is-active { background: #333; color: #4da6cc; }
html[theme="dark"] .tiptap-toolbar .tiptap-separator { background: #444; }
html[theme="dark"] .tiptap-editor-content { background: #1e1e1e; border-color: #444; color: #e0e0e0; }
html[theme="dark"] .tiptap-prose h1, html[theme="dark"] .tiptap-prose h2, html[theme="dark"] .tiptap-prose h3 { color: #e0e0e0; }
html[theme="dark"] .tiptap-prose blockquote { background: #252525; border-color: #006699; }
html[theme="dark"] .tiptap-prose code { background: #333; }
html[theme="dark"] .tiptap-prose th { background: #333; }
html[theme="dark"] .tiptap-prose td, html[theme="dark"] .tiptap-prose th { border-color: #444; }
html[theme="dark"] .tiptap-prose td.selectedCell, html[theme="dark"] .tiptap-prose th.selectedCell { background: #1a3a4a; }
html[theme="dark"] .tiptap-source-view { background: #1e1e1e; color: #e0e0e0; border-color: #444; }

/* ===== Mention (@-Funktion im Editor) ===== */

/* Mention-Chip im Editor und im gerenderten Verlauf */
.tiptap-prose .mention,
.markdown-content .mention,
.card-panel .mention,
.markdown .mention,
span.mention,
a.mention {
    display: inline-block;
    background: rgba(25, 118, 210, 0.10);
    color: #1565c0;
    padding: 1px 8px;
    margin: 0 1px;
    border-radius: 12px;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.5;
    transition: background-color 0.15s ease, color 0.15s ease;
}

a.mention:hover,
a.mention:focus {
    background: rgba(25, 118, 210, 0.22);
    color: #0d47a1;
    text-decoration: none;
    outline: none;
}

/* Externer Kontakt: andere Farbe */
.mention[data-mention-type="contact"],
a.mention[data-mention-type="contact"] {
    background: rgba(230, 81, 0, 0.10);
    color: #e65100;
}

a.mention[data-mention-type="contact"]:hover,
a.mention[data-mention-type="contact"]:focus {
    background: rgba(230, 81, 0, 0.22);
    color: #bf360c;
}

/* Dropdown-Popup für Vorschläge (Tippy-Container) */
.mention-dropdown {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px;
}

.mention-dropdown .mention-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}

.mention-dropdown .mention-item:hover,
.mention-dropdown .mention-item.is-selected {
    background: #f5f5f5;
}

.mention-dropdown .mention-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: #fff;
    font-weight: 600;
    font-size: 12px;
    flex-shrink: 0;
}

.mention-dropdown .mention-name {
    flex: 1;
    color: #212121;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mention-dropdown .mention-eye {
    font-size: 14px;
    opacity: 0.85;
    flex-shrink: 0;
}

.mention-dropdown .mention-tag {
    font-size: 10px;
    padding: 2px 6px;
    background: #fff3e0;
    color: #e65100;
    border-radius: 8px;
    flex-shrink: 0;
}

.mention-dropdown .mention-empty {
    padding: 10px 12px;
    color: #888;
    font-size: 13px;
    text-align: center;
}

/* Tippy-Hülle ohne Eigen-Styles für unser Dropdown */
.tippy-box[data-theme~='light-border'] {
    background: transparent;
    border: 0;
    box-shadow: none;
    color: inherit;
}
.tippy-box[data-theme~='light-border'] .tippy-content {
    padding: 0;
}

/* Dark Mode */
html[theme="dark"] .tiptap-prose .mention,
html[theme="dark"] .markdown-content .mention,
html[theme="dark"] .card-panel .mention,
html[theme="dark"] .markdown .mention,
html[theme="dark"] span.mention,
html[theme="dark"] a.mention {
    background: rgba(100, 181, 246, 0.18);
    color: #90caf9;
}

html[theme="dark"] a.mention:hover,
html[theme="dark"] a.mention:focus {
    background: rgba(100, 181, 246, 0.30);
    color: #bbdefb;
}

html[theme="dark"] .mention[data-mention-type="contact"],
html[theme="dark"] a.mention[data-mention-type="contact"] {
    background: rgba(255, 152, 0, 0.18);
    color: #ffb74d;
}

html[theme="dark"] a.mention[data-mention-type="contact"]:hover,
html[theme="dark"] a.mention[data-mention-type="contact"]:focus {
    background: rgba(255, 152, 0, 0.30);
    color: #ffcc80;
}

html[theme="dark"] .mention-dropdown {
    background: #1e1e1e;
    border-color: #444;
}

html[theme="dark"] .mention-dropdown .mention-item:hover,
html[theme="dark"] .mention-dropdown .mention-item.is-selected {
    background: #2a2a2a;
}

html[theme="dark"] .mention-dropdown .mention-name {
    color: #e0e0e0;
}

html[theme="dark"] .mention-dropdown .mention-empty {
    color: #aaa;
}

html[theme="dark"] .mention-dropdown .mention-tag {
    background: #4e342e;
    color: #ffcc80;
}
