/* ===== Markdown-Note-Editor (note/*) =====
   Live-Preview-Dekorationen, Quelltext, Leseansicht, Properties-Panel,
   Outline, Slash-/Wikilink-Popup, AI-Ghost-Text. Nutzt die Design-Tokens
   aus style.css; dunkel ist Default, [data-theme=light] kippt automatisch. */

.v-note { display: flex; flex-direction: column; height: 100%; }
.v-note-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.v-note-modes {
  display: inline-flex; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 2px;
}
.v-note-mode {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  padding: 4px 12px; border-radius: 6px; font-size: 12.5px;
}
.v-note-mode:hover { color: var(--text); }
.v-note-mode.is-active { background: var(--panel2); color: var(--accent); }

.v-note-main { flex: 1 1 auto; min-height: 0; display: flex; }
.v-note-editor { flex: 1 1 auto; min-width: 0; overflow: hidden; }
.v-note-reading { flex: 1 1 auto; min-width: 0; overflow: auto; }

/* ===== Properties-Panel (Frontmatter) ===== */
.note-props {
  border-bottom: 1px solid var(--line); background: var(--panel);
  padding: 6px 18px 8px; display: flex; flex-direction: column; gap: 2px;
}
.note-props:empty { display: none; }
.note-prop { display: flex; align-items: center; gap: 10px; min-height: 28px; }
.note-prop-k {
  flex: 0 0 130px; color: var(--muted); font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-prop-v { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; }
.note-prop-v input[type="text"], .note-prop-v input[type="number"],
.note-prop-v input[type="date"], .note-prop-v select {
  background: none; border: 1px solid transparent; border-radius: 6px;
  color: var(--text); padding: 3px 7px; font: inherit; font-size: 13px;
  width: 100%; max-width: 340px; outline: none; color-scheme: dark;
}
[data-theme="light"] .note-prop-v input, [data-theme="light"] .note-prop-v select { color-scheme: light; }
.note-prop-v input:hover, .note-prop-v select:hover { border-color: var(--line); }
.note-prop-v input:focus, .note-prop-v select:focus { border-color: var(--accent); background: var(--bg); }
.note-prop-v input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }
.note-prop-v select option { background: var(--panel); }
.note-prop-tags { flex-wrap: wrap; }
.note-prop-tag {
  background: var(--accent-dim); color: var(--text); border-radius: 20px;
  padding: 1px 8px; font-size: 12px; white-space: nowrap;
}
.note-prop-tag .np-tag-x {
  border: 0; background: none; color: inherit; cursor: pointer;
  padding: 0 0 0 2px; opacity: .65; font-size: 12px;
}
.note-prop-tag .np-tag-x:hover { opacity: 1; color: var(--err); }
.np-tag-input {
  background: none; border: 0; outline: none; color: var(--text);
  font: inherit; font-size: 12.5px; width: 70px;
}
.note-prop-x { visibility: hidden; font-size: 13px; padding: 2px 6px; }
.note-prop:hover .note-prop-x { visibility: visible; }
.note-prop-add {
  align-self: flex-start; border: 0; background: none; color: var(--muted);
  cursor: pointer; font-size: 12px; padding: 3px 0; border-radius: 6px;
}
.note-prop-add:hover { color: var(--accent); }

/* ===== CodeMirror-Grundgerüst ===== */
.v-note .cm-editor { height: 100%; background: transparent; }
.v-note .cm-editor.cm-focused { outline: none; }
.v-note .cm-scroller { overflow: auto; padding: 24px 0 30vh; line-height: 1.6; }
.v-note .cm-content {
  max-width: 780px; margin: 0 auto; padding: 0 28px;
  caret-color: var(--accent); font-size: 15px;
}
.v-note .cm-line { padding: 0; }
.v-note .cm-selectionBackground,
.v-note .cm-content ::selection { background: var(--accent-dim) !important; }
.v-note .cm-cursor { border-left-color: var(--accent); }
.v-note .cm-placeholder { color: var(--muted); font-style: italic; }
.v-note .cm-gutters { background: var(--bg); border-right: 1px solid var(--line); color: var(--muted); }
.v-note .cm-activeLineGutter { background: var(--panel2); color: var(--text); }
.v-note .cm-activeLine { background: rgba(255,255,255,.03); }
[data-theme="light"] .v-note .cm-activeLine { background: rgba(0,0,0,.04); }

/* Quelltext-Modus: Mono-Schrift */
.v-note[data-mode="source"] .cm-content {
  font-family: ui-monospace, 'Cascadia Code', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 13.5px; max-width: none;
}

/* ===== Live-Preview-Dekorationen ===== */
.v-note .cm-heading { font-weight: 700; line-height: 1.3; }
.v-note .cm-headline-1 { font-size: 1.9em; }
.v-note .cm-headline-2 { font-size: 1.55em; }
.v-note .cm-headline-3 { font-size: 1.3em; }
.v-note .cm-headline-4 { font-size: 1.12em; }
.v-note .cm-headline-5 { font-size: 1em; }
.v-note .cm-headline-6 { font-size: .92em; color: var(--muted); }
.v-note .cm-h1, .v-note .cm-h2, .v-note .cm-h3,
.v-note .cm-h4, .v-note .cm-h5, .v-note .cm-h6 { font-weight: 700; }

.v-note .cm-inline-code, .v-note .cm-md-code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 5px; padding: 0 4px;
}
.v-note .cm-codeblock-line {
  background: var(--panel); border-left: 2px solid var(--line);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
}
.v-note .cm-codeblock-line .cm-inline-code,
.v-note .cm-codeblock-line .cm-md-code { background: transparent; border: 0; padding: 0; }

.v-note .cm-quote-line {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--muted); background: rgba(91,157,255,.06);
}
.v-note .cm-callout-warning, .v-note .cm-callout-caution { border-left-color: var(--warn); background: rgba(245,185,65,.08); }
.v-note .cm-callout-danger, .v-note .cm-callout-error, .v-note .cm-callout-bug { border-left-color: var(--err); background: rgba(255,93,93,.08); }
.v-note .cm-callout-tip, .v-note .cm-callout-success, .v-note .cm-callout-info { border-left-color: var(--ok); background: rgba(63,207,142,.08); }

.v-note .cm-bullet { color: var(--accent); padding-right: 2px; }
.v-note .cm-task-box {
  width: 15px; height: 15px; vertical-align: -2px; margin-right: 4px;
  cursor: pointer; accent-color: var(--accent);
}
.v-note .cm-md-link, .v-note .cm-rendered-link {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-dim); cursor: pointer;
}
.v-note .cm-rendered-link:hover { background: var(--accent-dim); }
.v-note .cm-md-url { color: var(--muted); }
.v-note .cm-md-quote { color: var(--muted); }
.v-note .cm-md-listmark { color: var(--accent); }

.v-note .cm-render-hr { display: block; height: 0; border-top: 2px solid var(--line); margin: 10px 0; }
.v-note .cm-render-img-wrap, .v-note .cm-render-table, .v-note .cm-render-mermaid,
.v-note .cm-render-embed, .v-note .cm-math-block { display: block; margin: 6px 0; }
.v-note .cm-render-img { max-width: 100%; height: auto; border-radius: 8px; }
.v-note .cm-math-error, .mermaid-error { color: var(--err); font-family: ui-monospace, monospace; font-size: .85em; }

.v-note .cm-frontmatter {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82em;
  color: var(--muted); background: var(--panel);
}

/* ===== AI-Ghost-Text ===== */
.cm-ghost-text { color: var(--muted); opacity: .75; font-style: italic; white-space: pre-wrap; }
.cm-ghost-text::after {
  content: 'Tab ⇥'; font-size: .72em; font-style: normal; color: var(--accent);
  border: 1px solid var(--accent-dim); border-radius: 4px; padding: 0 4px;
  margin-left: 6px; vertical-align: 1px;
}

/* ===== Wikilinks ===== */
a.wikilink {
  color: var(--accent); text-decoration: none; cursor: pointer;
  border-bottom: 1px dashed var(--accent-dim);
}
a.wikilink:hover { background: var(--accent-dim); border-bottom-style: solid; }

/* ===== Caret-Popup (Wikilink-Autocomplete + Slash-Menü) ===== */
.note-popup {
  position: fixed; z-index: 650; width: 320px; max-height: 300px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px;
}
.note-popup-item {
  display: flex; align-items: center; gap: 9px; padding: 6px 10px;
  border-radius: 7px; cursor: pointer; font-size: 13px;
}
.note-popup-item.sel { background: var(--panel2); }
.note-popup-item .np-icon {
  flex: 0 0 26px; text-align: center; font-size: 12px; color: var(--muted);
}
.note-popup-item .np-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-popup-item .np-sub {
  color: var(--muted); font-size: 11px; max-width: 40%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.note-popup-empty { padding: 8px 12px; color: var(--muted); font-size: 12.5px; }

/* ===== Leseansicht ===== */
.v-reading-paper { max-width: 780px; margin: 0 auto; padding: 24px 28px 30vh; font-size: 15px; line-height: 1.65; }
.v-reading-paper > :first-child { margin-top: 0; }
.v-reading-paper h1 { font-size: 1.9em; }
.v-reading-paper h2 { font-size: 1.55em; }
.v-reading-paper h3 { font-size: 1.3em; }
.v-reading-paper h4 { font-size: 1.12em; }
.v-reading-paper h1, .v-reading-paper h2 { padding-bottom: .2em; border-bottom: 1px solid var(--line); }
.v-reading-paper a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-dim); }
.v-reading-paper a:hover { background: var(--accent-dim); }
.v-reading-paper img { max-width: 100%; height: auto; border-radius: 8px; }
.v-reading-paper hr { border: 0; border-top: 2px solid var(--line); margin: 18px 0; }
.v-reading-paper blockquote {
  margin: 1em 0; padding: 2px 14px; border-left: 3px solid var(--accent);
  color: var(--muted); background: rgba(91,157,255,.06);
}
.v-reading-paper table { border-collapse: collapse; margin: 1em 0; display: block; overflow-x: auto; }
.v-reading-paper th, .v-reading-paper td { border: 1px solid var(--line); padding: 6px 10px; }
.v-reading-paper th { background: var(--panel2); }
.v-reading-paper code {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .88em;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px;
}
.v-reading-paper pre code { background: none; border: 0; padding: 0; font-size: inherit; }
.v-reading-paper ul.contains-task-list { list-style: none; padding-left: 1.2em; }
.v-reading-paper input[type="checkbox"] {
  width: 15px; height: 15px; vertical-align: -2px; margin-right: 5px;
  cursor: pointer; accent-color: var(--accent);
}
.v-note-reading.readonly input[type="checkbox"] { pointer-events: none; }

/* ===== Callouts (Leseansicht + Embeds) ===== */
.callout {
  border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 10px 14px; margin: 1em 0;
  background: rgba(91,157,255,.07); color: var(--text);
}
.callout-title { font-weight: 700; margin-bottom: 4px; color: var(--accent); }
.callout-warning, .callout-caution { border-left-color: var(--warn); background: rgba(245,185,65,.08); }
.callout-warning .callout-title, .callout-caution .callout-title { color: var(--warn); }
.callout-danger, .callout-error, .callout-bug { border-left-color: var(--err); background: rgba(255,93,93,.08); }
.callout-danger .callout-title, .callout-error .callout-title, .callout-bug .callout-title { color: var(--err); }
.callout-tip, .callout-success, .callout-info { border-left-color: var(--ok); background: rgba(63,207,142,.08); }
.callout-tip .callout-title, .callout-success .callout-title, .callout-info .callout-title { color: var(--ok); }

/* ===== Embeds ![[…]] ===== */
.note-embed { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); margin: 8px 0; overflow: hidden; }
.note-embed-head { font-size: 12px; padding: 6px 12px; border-bottom: 1px solid var(--line); background: var(--panel2); }
.note-embed-body { padding: 12px 18px; max-height: 360px; overflow: auto; font-size: 14px; }
.note-embed-img { display: block; max-width: 100%; height: auto; }
.note-embed-link { display: inline-block; padding: 10px 14px; color: var(--accent); }
.note-embed-missing { padding: 10px 14px; color: var(--muted); font-size: 13px; }
.note-embed input[type="checkbox"] { pointer-events: none; } /* Embeds nur lesend */

/* ===== Mermaid / Mathe ===== */
.mermaid-block { display: flex; justify-content: center; padding: 8px 0; }
.mermaid-block svg { max-width: 100%; }
.cm-math-block, .v-reading-paper .katex-display { overflow-x: auto; }

/* ===== Code-Highlighting (hljs) ===== */
pre.hljs, .v-reading-paper pre {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; overflow-x: auto;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.5;
}
.hljs-comment, .hljs-quote { color: #8b949e; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-name { color: #ff7b72; }
.hljs-string, .hljs-attr, .hljs-template-tag { color: #a5d6ff; }
.hljs-number, .hljs-literal, .hljs-type { color: #79c0ff; }
.hljs-title, .hljs-section, .hljs-function .hljs-title { color: #d2a8ff; }
.hljs-attribute, .hljs-variable, .hljs-tag { color: #ffa657; }
[data-theme="light"] .hljs-comment, [data-theme="light"] .hljs-quote { color: #8a8f98; }
[data-theme="light"] .hljs-keyword, [data-theme="light"] .hljs-selector-tag,
[data-theme="light"] .hljs-built_in, [data-theme="light"] .hljs-name { color: #8250df; }
[data-theme="light"] .hljs-string, [data-theme="light"] .hljs-attr,
[data-theme="light"] .hljs-template-tag { color: #1d7a4f; }
[data-theme="light"] .hljs-number, [data-theme="light"] .hljs-literal,
[data-theme="light"] .hljs-type { color: #b8860b; }
[data-theme="light"] .hljs-title, [data-theme="light"] .hljs-section,
[data-theme="light"] .hljs-function .hljs-title { color: #0550ae; }
[data-theme="light"] .hljs-attribute, [data-theme="light"] .hljs-variable,
[data-theme="light"] .hljs-tag { color: #c0392b; }

/* ===== Outline ===== */
.v-note-outline {
  flex: 0 0 230px; border-left: 1px solid var(--line); background: var(--panel);
  overflow: auto; padding: 12px 6px;
}
.v-note-outline-empty { color: var(--muted); font-size: 12.5px; padding: 6px 10px; }
.v-note-ol {
  display: block; padding: 4px 10px; border-radius: 6px; color: var(--muted);
  font-size: 13px; text-decoration: none; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.v-note-ol:hover { background: var(--panel2); color: var(--accent); }
.v-note-ol-2 { padding-left: 22px; } .v-note-ol-3 { padding-left: 34px; }
.v-note-ol-4 { padding-left: 46px; } .v-note-ol-5, .v-note-ol-6 { padding-left: 58px; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .v-note-outline {
    position: absolute; right: 0; top: 0; bottom: 0; z-index: 20;
    box-shadow: var(--shadow);
  }
  .v-note-main { position: relative; }
  .note-prop-k { flex-basis: 90px; }
  .v-reading-paper, .v-note .cm-content { padding-left: 16px; padding-right: 16px; }
}

/* ===== Editierbare Tabellen im Live-Modus (Obsidian-artig) ===== */
.cm-table-edit { position: relative; margin: 6px 0; }
.cm-table-edit table {
  border-collapse: collapse; font-size: .95em; width: max-content; max-width: 100%;
}
.cm-table-edit th, .cm-table-edit td {
  border: 1px solid var(--line); padding: 5px 10px; min-width: 56px;
  vertical-align: top; text-align: left; outline: none;
}
.cm-table-edit th { background: rgba(127,127,127,.1); font-weight: 600; }
.cm-table-edit th:focus, .cm-table-edit td:focus {
  border-color: var(--accent); background: var(--accent-dim);
}
.cm-table-tools {
  display: none; gap: 4px; margin-top: 3px;
}
.cm-table-edit:hover .cm-table-tools,
.cm-table-edit:focus-within .cm-table-tools { display: flex; }
.cm-table-tools button {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 6px;
  color: var(--muted); font-size: 11px; padding: 2px 8px; cursor: pointer;
}
.cm-table-tools button:hover { color: var(--text); border-color: var(--accent); }

/* ===== Remote-Cursor (Co-Editing-Präsenz) ===== */
.cm-remote-caret {
  position: relative; border-left: 2px solid var(--warn);
  margin-left: -1px; pointer-events: none;
}
.cm-remote-flag {
  position: absolute; top: -1.25em; left: -2px;
  background: var(--warn); color: #1b1b1f; border-radius: 4px 4px 4px 0;
  font-size: 9.5px; font-weight: 700; padding: 0 4px; white-space: nowrap;
  pointer-events: none;
}
