/* ============================================
   Dark Mode - Note Editor & Content
   ============================================ */

/* Note card and inner note */
html[data-theme='dark'] .notecard {
    background-color: var(--pz-bg);
}

html[data-theme='dark'] .innernote {
    color: var(--pz-text);
}

/* No own background under a workspace background image, as in the light
   theme: .innernote is positioned, so an opaque background paints over the
   image layer (js/background-settings.js, z-index 0) and hid it, and the
   sticky header sits above that layer too. */
html[data-theme='dark'] body:not(.has-background-image) .innernote {
    background-color: var(--pz-bg);
}

/* Note header and toolbar - apply dark background immediately */
html[data-theme='dark'] body:not(.has-background-image) .note-header {
    background-color: var(--pz-bg) !important;
}

html[data-theme='dark'] body:not(.has-background-image) .note-edit-toolbar {
    background-color: var(--pz-bg);
}

html[data-theme='dark'] body:not(.has-background-image) .note-header-spacer {
    background-color: var(--pz-bg);
}

/* Note title */
html[data-theme='dark'] .css-title {
    background-color: var(--pz-bg);
    color: var(--pz-text);
}

/* Note entry content */
html[data-theme='dark'] .noteentry {
    color: var(--pz-text) !important;
}

/* Inside the positioned .innernote, so it would cover the workspace
   background image too (transparent in the light theme). */
html[data-theme='dark'] body:not(.has-background-image) .noteentry {
    background-color: var(--pz-bg);
}

html[data-theme='dark'] .note-scroll-edge-btn,
html[data-theme='dark'] .pz-edge-btn {
    background: color-mix(in srgb, var(--pz-surface) 96%, transparent);
    border-color: var(--pz-border);
    color: var(--pz-accent-text);
    box-shadow: 0 5px 14px rgba(var(--pz-shadow-rgb), 0.26);
}

/* The floating stack buttons only take the accent on hover */
html[data-theme='dark'] .pz-edge-btn {
    color: var(--pz-text-muted);
}

html[data-theme='dark'] .pz-edge-btn:hover,
html[data-theme='dark'] .pz-edge-btn:focus {
    color: var(--pz-accent-text);
}

/* The Markdown view button stays lit outside its classic state (live
   rendering, split view): the muted colour above outweighed its light rule. */
html[data-theme='dark'] .pz-edge-view-btn.is-active {
    color: var(--pz-accent-text);
}

html[data-theme='dark'] .note-scroll-edge-btn:hover,
html[data-theme='dark'] .note-scroll-edge-btn:focus,
html[data-theme='dark'] .pz-edge-btn:hover,
html[data-theme='dark'] .pz-edge-btn:focus {
    background: var(--pz-surface-hover);
}

/* Readable text colors: preserve inline color styles, links, syntax highlighting
   and Mermaid labels (js/mermaid-theme.js picks those against their fill).
   Inline formatting inside a coloured run is left alone too: bolding part of a
   coloured span nests a style-less <b> in it, which has to inherit that colour
   instead of being painted back to the default text colour (#1401).
   The controls in a code block's corner keep their own colours (the red bin,
   the faint grey of the others, css/code-blocks.css): they are the app's, not
   the note's text, and so do their icons, which draw in currentColor. They
   are whatever the block's action host holds besides the <pre>
   (js/copy-code-on-focus.js). :where() so the exception adds no weight to
   this rule. */
html[data-theme='dark'] .noteentry *:not([style*="color"]):not(:is(b, strong, i, em, u, s, strike, del, ins, sub, sup, small, span, font):is([style*="color"] *)):not(a):not([class*="hljs"]):not(code[class*="language-"]):not(.code-line):not(.search-highlight):not(.search-highlight-active):not([class^="md-"]):not([class*=" md-"]):not(.markdown-codemirror-host *):not(.mermaid *):not(:where(.code-block-actions-host > :not(pre), .code-block-actions-host > :not(pre) *)) {
    color: var(--pz-text) !important;
}

/* Note placeholder */
html[data-theme='dark'] div[contentEditable=true]:empty:before {
    color: var(--pz-border-strong);
}

/* ============================================
   Code Blocks
   ============================================ */

/* Pre blocks */
html[data-theme='dark'] .noteentry pre {
    background-color: var(--pz-code-bg) !important;
    border-color: var(--pz-border) !important;
    color: var(--pz-text-muted) !important;
}

/* Line-number gutter (code_block_line_numbers setting) */
html[data-theme='dark'] .noteentry pre code.code-line-numbers .code-line::before {
    color: var(--pz-text-muted);
    opacity: 0.55;
}

/* Highlighted text inside a code block is left to the colour the picker wrote,
   like anywhere else in the note. The palette's soft tokens are mixed against
   the page background, so they are already dark here; the legacy pastel
   highlights below get their text colour fixed by the rules further down.
   The fixed yellow gradient this rule used to paint turned every colour yellow
   and stayed visible after a highlight was removed (#1425). */

/* Inline code only (not inside pre blocks with syntax highlighting) */
html[data-theme='dark'] .noteentry code:not([class*="hljs"]):not([class*="language-"]) {
    background-color: var(--pz-surface) !important;
    color: var(--pz-text);
    border-color: var(--pz-border) !important;
}

html[data-theme='dark'] .noteentry pre code:not([class*="hljs"]):not([class*="language-"]) {
    background-color: transparent !important;
    color: var(--pz-text-muted) !important;
    border-color: transparent !important;
}

/* Code blocks with language class - readable text before highlight.js processes */
html[data-theme='dark'] .noteentry pre code[class*="language-"],
html[data-theme='dark'] .noteentry code[class*="language-"] {
    color: var(--pz-syntax-text) !important;
}

/* Code block copy button */
html[data-theme='dark'] .code-block-copy-btn,
html[data-theme='dark'] .noteentry pre .code-block-copy-btn,
html[data-theme='dark'] .public-note .content pre .code-block-copy-btn,
html[data-theme='dark'] .code-block-actions-host > .code-block-copy-btn,
html[data-theme='dark'] .code-block-actions-host > .code-block-delete-btn,
html[data-theme='dark'] .code-block-line-numbers-btn,
html[data-theme='dark'] .noteentry pre .code-block-line-numbers-btn,
html[data-theme='dark'] .code-block-actions-host > .code-block-line-numbers-btn,
html[data-theme='dark'] .code-block-wrap-btn {
    background: transparent !important;
    border: none !important;
    opacity: 0.55 !important;
}

html[data-theme='dark'] .code-block-copy-btn svg,
html[data-theme='dark'] .code-block-delete-btn svg,
html[data-theme='dark'] .code-block-line-numbers-btn svg,
html[data-theme='dark'] .code-block-wrap-btn svg {
    stroke: currentColor !important;
}

/* The grey buttons keep the light grey they had while the note's text colour
   reached them (the .noteentry * rule above now leaves them alone, so the bin
   can be red): the subtle grey of the light theme fades out on a dark ground */
html[data-theme='dark'] .code-block-actions-host > :is(.code-block-copy-btn, .code-block-line-numbers-btn, .code-block-wrap-btn, .code-block-collapse-btn) {
    color: var(--pz-text) !important;
}

html[data-theme='dark'] .code-block-delete-btn,
html[data-theme='dark'] .noteentry pre .code-block-delete-btn,
html[data-theme='dark'] .public-note .content pre .code-block-delete-btn,
html[data-theme='dark'] .code-block-actions-host > .code-block-delete-btn {
    color: var(--pz-danger-text) !important;
}

html[data-theme='dark'] .code-block-copy-btn:hover,
html[data-theme='dark'] .noteentry pre .code-block-copy-btn:hover,
html[data-theme='dark'] .public-note .content pre .code-block-copy-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-copy-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-delete-btn:hover,
html[data-theme='dark'] .code-block-line-numbers-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-line-numbers-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-wrap-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-collapse-btn:hover {
    background: transparent !important;
    color: var(--pz-text-strong) !important;
    opacity: 1 !important;
}

html[data-theme='dark'] .code-block-delete-btn:hover,
html[data-theme='dark'] .noteentry pre .code-block-delete-btn:hover,
html[data-theme='dark'] .public-note .content pre .code-block-delete-btn:hover,
html[data-theme='dark'] .code-block-actions-host > .code-block-delete-btn:hover {
    color: var(--pz-danger-text) !important;
}

html[data-theme='dark'] .code-block-copy-btn.copied,
html[data-theme='dark'] .noteentry pre .code-block-copy-btn.copied {
    background: transparent !important;
    color: var(--pz-success-text-hover) !important;
    border: none !important;
    opacity: 1 !important;
}

/* ============================================
   Links in Notes
   ============================================ */

html[data-theme='dark'] .noteentry a {
    color: var(--pz-accent-text-hover) !important;
}

/* Audio player */
html[data-theme='dark'] .noteentry .note-audio-embed,
html[data-theme='dark'] .noteentry audio {
    background: var(--pz-surface);
}

html[data-theme='dark'] .note-attachment-preview {
    border-color: var(--pz-border);
    background: var(--pz-surface);
}

html[data-theme='dark'] .note-attachment-preview-file-card:hover,
html[data-theme='dark'] .note-attachment-preview-file-card:focus {
    color: var(--pz-accent-text);
}

html[data-theme='dark'] .note-attachment-preview-caption {
    border-top-color: var(--pz-border);
}

html[data-theme='dark'] .note-attachment-preview-caption a:hover,
html[data-theme='dark'] .note-attachment-preview-caption a:focus {
    color: var(--pz-accent-text) !important;
}

/* ============================================
   Highlighting
   ============================================
   Selected text is themed once for both modes, through --pz-selection and the
   global rule in css/components/selection.css. */

/* Search highlights */
:where(html[data-theme='dark']) mark,
html[data-theme='dark'] .highlight {
    background-color: var(--pz-warning-soft);
    color: var(--pz-warning-text);
}

/* Highlighting inside code blocks (search/highlight marks, not syntax) */
:where(html[data-theme='dark']) pre mark[style*="background"],
:where(html[data-theme='dark']) code mark[style*="background"] {
    background-color: var(--pz-warning-soft) !important;
    background-image: none !important;
    color: var(--pz-warning-text) !important;
}

/* Yellow highlighter tool */
:where(html[data-theme='dark']) [style*="background-color: rgb(255, 224, 102)"],
html[data-theme='dark'] [style*="background-color:#ffe066"],
html[data-theme='dark'] [style*="background-color: #ffe066"] {
    background-color: var(--pz-warning-soft) !important;
    color: var(--pz-warning-text) !important;
}

/* Highlighter tool — other colors.
   The picker applies light pastel backgrounds; in dark mode the note text is
   light, so force dark text on those spans to keep the highlighted text
   readable while preserving the chosen highlight color. */
html[data-theme='dark'] .noteentry [style*="background-color: rgb(255, 168, 168)"],
html[data-theme='dark'] .noteentry [style*="background-color:#ffa8a8"],
html[data-theme='dark'] .noteentry [style*="background-color: #ffa8a8"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(178, 242, 187)"],
html[data-theme='dark'] .noteentry [style*="background-color:#b2f2bb"],
html[data-theme='dark'] .noteentry [style*="background-color: #b2f2bb"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(165, 216, 255)"],
html[data-theme='dark'] .noteentry [style*="background-color:#a5d8ff"],
html[data-theme='dark'] .noteentry [style*="background-color: #a5d8ff"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(255, 201, 222)"],
html[data-theme='dark'] .noteentry [style*="background-color:#ffc9de"],
html[data-theme='dark'] .noteentry [style*="background-color: #ffc9de"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(255, 216, 168)"],
html[data-theme='dark'] .noteentry [style*="background-color:#ffd8a8"],
html[data-theme='dark'] .noteentry [style*="background-color: #ffd8a8"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(208, 191, 255)"],
html[data-theme='dark'] .noteentry [style*="background-color:#d0bfff"],
html[data-theme='dark'] .noteentry [style*="background-color: #d0bfff"],
html[data-theme='dark'] .noteentry [style*="background-color: rgb(222, 226, 230)"],
html[data-theme='dark'] .noteentry [style*="background-color:#dee2e6"],
html[data-theme='dark'] .noteentry [style*="background-color: #dee2e6"] {
    color: var(--pz-bg) !important;
}

/* Horizontal rules */
:where(html[data-theme='dark']) hr {
    border-color: var(--pz-border);
}

/* ============================================
   Toolbar Buttons
   ============================================ */

html[data-theme='dark'] .toolbar-btn {
    background-color: var(--pz-surface);
    color: var(--pz-text);
    border-color: var(--pz-border);
}

html[data-theme='dark'] .toolbar-btn:hover {
    background-color: var(--pz-surface-hover);
}

/* ============================================
   Toolbar Popups & Menus
   ============================================ */

/* Color palette popup */
html[data-theme='dark'] .color-palette-popup {
    background-color: var(--pz-surface);
    border-color: var(--pz-border);
}

html[data-theme='dark'] .color-palette-popup .color-grid {
    background: var(--pz-surface);
}

/* Outline swatches so dark ones (e.g. the black text color) stay visible
   against the dark popup background. */
html[data-theme='dark'] .color-palette-popup .color-swatch {
    border: 1px solid rgba(var(--pz-highlight-rgb), 0.35);
}

/* Font size popup */
html[data-theme='dark'] .font-size-popup {
    background-color: var(--pz-bg);
    border-color: var(--pz-border);
}

html[data-theme='dark'] .font-size-popup .font-size-item:hover {
    background-color: rgba(var(--pz-highlight-rgb), 0.1);
}

html[data-theme='dark'] .font-size-popup .size-preview {
    border-color: var(--pz-border);
    background-color: var(--pz-bg);
}

/* Blockquotes */
html[data-theme='dark'] .noteentry blockquote {
    border-left-color: var(--pz-border);
    color: var(--pz-text);
}
