/*
 * FABBRAIN: the "Não confirmado" mark wherever marked content is rendered.
 * THE one definition (fix wave of phase 2): the note on screen (rich text and
 * the Markdown preview), the task list, the link preview, the revisions page,
 * the global Tasks page, the shared page, the exports and print all draw the
 * mark from this file and nowhere else (tests/fabbrain-tema.test.php refuses a
 * [data-nc] rule in any other stylesheet).
 *
 * Who loads it: index.php (index_css.php), every page of css_assets.php (the
 * shared pages take only tokens, faces, base, this file and fabbrain-publico.css)
 * and the HTML exports (api_export_note.php inlines it).
 *
 * The look ("variação B", chosen by the owner), tuned ONLY through the
 * --fb-nc-* tokens of fabbrain-tokens.css:
 *   - at rest the passage's text carries a dotted underline (--fb-nc-underline,
 *     -thickness, -offset), with no ground, no box, no bar and no visible label;
 *     a block where underlined text makes no sense (a code block, a table row,
 *     an image or an embed alone) gets a dotted outline of the same colour;
 *   - a small dashed circle sits in the left margin, on the first line of a
 *     run of marked blocks, one per run (--fb-nc-symbol, -size, -opacity,
 *     -gutter = its distance from the text);
 *   - on hover or focus the run's text gets a soft highlight behind the text
 *     run only (--fb-nc-hover-bg), the symbol goes to full opacity and a
 *     tooltip "Não confirmado" shows beside it (the prototype's .tip).
 *
 * Who draws what:
 *   - js/fabbrain-nc-visual.js (index.php, revisions, Tasks, the shared page):
 *     the symbol is a real <button> (focusable, accessible name "Não
 *     confirmado", its tooltip a child span) in an overlay layer
 *     (.fabbrain-nc-camada) inserted BEFORE the rendered note, never inside it:
 *     the rich-text editor saves the innerHTML of .noteentry only, so the
 *     symbol, its label and its tooltip can never reach the saved content, a
 *     copy of the text or what the sync service reads. The highlight of a whole
 *     run is the CSS Custom Highlight API (::highlight(fabbrain-nc)): ranges
 *     over the text, no element, no attribute. html.fabbrain-nc-js says the
 *     script runs.
 *   - without that script (an exported file) or on paper: the symbol is the
 *     block's ::after (generated content, never text); the hover highlight of
 *     the one block is a thick underline in the highlight colour behind the
 *     glyphs (it follows every line of the text, as box-decoration-break: clone
 *     does for an inline ground).
 *   - a marked row of a task list (the note, the link preview, the revisions
 *     page, the Tasks page) is not saved as HTML: its symbol button is a child
 *     of the row (.fabbrain-nc-linha), its text is .fabbrain-nc-texto (an
 *     inline element: the real highlight with box-decoration-break: clone).
 *
 * The label's words: "fabbrain.trecho.label" of the i18n strings (js reads it
 * with window.t; the CSS fallback reads --fabbrain-nc-label, set on <html> by
 * js/fabbrain-trecho.js, else "Não confirmado").
 *
 * Selector prefix: two ids inside :not() (2,1,0), so the mark wins over every
 * region rule (at most (1,3,2)) without !important. Values are tokens.
 */

/* ---- At rest: the dotted underline on the passage's text ------------------ */

:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] {
    --fabbrain-indent: 0px;
    position: relative;
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--fb-nc-underline);
    text-decoration-thickness: var(--fb-nc-underline-thickness);
    text-underline-offset: var(--fb-nc-underline-offset);
    text-decoration-skip-ink: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* A link inside keeps its own underline where it was */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] a {
    text-underline-offset: auto;
}

/* Marks never nest: the outer block already underlines the text */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] [data-nc="1"] {
    text-decoration-line: none;
}

/* A list item: the symbol clears the list's indent and its marker */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) li[data-nc="1"] {
    --fabbrain-indent: var(--fb-nc-li-indent);
}

/* Where underlining text makes no sense: a dotted outline around the block */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) :is(pre, table, tr, figure, iframe, img)[data-nc="1"],
:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"]:has(> :is(img, iframe, video, svg, canvas, .excalidraw-container):only-child) {
    text-decoration-line: none;
    outline: var(--fb-nc-underline-thickness) dotted var(--fb-nc-underline);
    outline-offset: var(--fb-space-1);
}

:root:not(#fabbrain-trecho):not(#fabbrain-nc) :is(pre, table, tr, figure, iframe, img)[data-nc="1"]:hover,
:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"]:has(> :is(img, iframe, video, svg, canvas, .excalidraw-container):only-child):hover {
    background-color: var(--fb-nc-hover-bg);
}

/* A table row draws its outline on its cells (a row box paints none) */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) tr[data-nc="1"] > :is(td, th) {
    border-top: var(--fb-nc-underline-thickness) dotted var(--fb-nc-underline);
    border-bottom: var(--fb-nc-underline-thickness) dotted var(--fb-nc-underline);
}

/* The Markdown sentinels themselves are never shown in a rendering */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) .fabbrain-nc-sentinela {
    display: none;
}

/* The same, in the Markdown editor's live views: the sentinel lines are an empty block widget (build/markdown-editor,
   live-preview.js). Taken out of sight, not out of the layout, so nothing in the editor moves under the caret. */
:root:not(#fabbrain-trecho):not(#fabbrain-nc) .cm-fabbrain-nc-sentinela {
    display: block;
    height: 0;
    overflow: hidden;
}

/* ---- Hover: the soft highlight behind the text run ------------------------ */

/* With the script: the whole run, through the Custom Highlight API */
::highlight(fabbrain-nc) {
    background-color: var(--fb-nc-hover-bg);
}

/* Without it (an exported file, an old browser): the one block under the pointer.
   The highlight is a thick underline in its colour behind the glyphs. */
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-hl) [data-nc="1"]:hover {
    text-decoration-style: solid;
    text-decoration-color: var(--fb-nc-hover-bg);
    text-decoration-thickness: var(--fb-nc-hover-band);
    text-underline-offset: var(--fb-nc-hover-band-offset);
}

/* ---- The symbol as generated content (no script, and print) -------------- */

:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"]::after {
    content: "";
    position: absolute;
    top: calc((1lh - var(--fb-nc-symbol-size)) / 2);
    left: calc(-1 * (var(--fabbrain-indent) + var(--fb-nc-symbol-gutter) + var(--fb-nc-symbol-size)));
    width: var(--fb-nc-symbol-size);
    height: var(--fb-nc-symbol-size);
    background-color: var(--fb-nc-symbol);
    /* FABBRAIN (fase 4c, Tarefa 2): the robot, not the dashed circle */
    -webkit-mask: var(--fb-icon-robot) center / contain no-repeat;
    mask: var(--fb-icon-robot) center / contain no-repeat;
    opacity: var(--fb-nc-symbol-opacity);
    pointer-events: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"]:hover::after {
    opacity: 1;
}

/* One symbol per run of consecutive marked blocks; none inside a marked block,
   none on a table row (its first cell is not a line of text) */
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"] + [data-nc="1"]::after,
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"] + :is(ul, ol) > li[data-nc="1"]:first-child::after,
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"] [data-nc="1"]::after {
    content: none;
}

/* The tooltip without the script: ::before of a block that is not a list item
   (upstream numbers an ordered list with ::before) */
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-js) [data-nc="1"]:not(li):hover::before {
    content: var(--fabbrain-nc-label, "Feito por IA"); /* FABBRAIN (fase 4c, Tarefa 1): the seal's words */
    position: absolute;
    bottom: calc(100% - (1lh - var(--fb-nc-symbol-size)) / 2 + var(--fb-space-2));
    left: calc(-1 * (var(--fb-nc-symbol-gutter) + var(--fb-nc-symbol-size)));
    z-index: 2;
    padding: var(--fb-space-utag-y) var(--fb-space-4);
    border-radius: var(--fb-radius-sm);
    background: var(--fb-text);
    color: var(--fb-bg);
    font-family: var(--fb-font-sans);
    font-size: var(--fb-text-xs);
    font-style: normal;
    font-weight: var(--fb-weight-regular);
    line-height: var(--fb-leading-heading);
    text-decoration: none;
    white-space: nowrap;
    pointer-events: none;
}

/* ---- The symbol as an element (js/fabbrain-nc-visual.js) ------------------ */

/* The layer: a zero-size box in the flow, before the rendered note; the
   symbols are placed in it from the passages' boxes */
.fabbrain-nc-camada {
    position: relative;
    z-index: 3;
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    pointer-events: none;
}

.fabbrain-nc-simbolo {
    position: absolute;
    z-index: 1;
    display: block;
    width: var(--fb-nc-symbol-size);
    min-width: 0;
    height: var(--fb-nc-symbol-size);
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--fb-radius-round);
    background: transparent;
    box-shadow: none;
    opacity: var(--fb-nc-symbol-opacity);
    cursor: default;
    pointer-events: auto;
    transition: opacity var(--fb-dur-fast) var(--fb-ease);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.fabbrain-nc-simbolo[hidden] {
    display: none;
}

/* FABBRAIN (fase 4c, Tarefa 2): the robot of the prototype's .circ (was the dashed circle) */
.fabbrain-nc-simbolo::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: var(--fb-nc-symbol);
    -webkit-mask: var(--fb-icon-robot) center / contain no-repeat;
    mask: var(--fb-icon-robot) center / contain no-repeat;
}

/* the hit area: 28px around the 16px glyph */
.fabbrain-nc-simbolo::after {
    content: "";
    position: absolute;
    inset: calc((var(--fb-nc-symbol-size) - var(--fb-hit-min)) / 2);
}

.fabbrain-nc-simbolo:focus-visible {
    outline: var(--fb-focus-ring) solid var(--fb-accent);
    outline-offset: var(--fb-space-1);
}

/* The tooltip: the prototype's .tip, above the symbol */
.fabbrain-nc-dica {
    position: absolute;
    bottom: calc(100% + var(--fb-space-2));
    left: 0;
    z-index: 2;
    padding: var(--fb-space-utag-y) var(--fb-space-4);
    border-radius: var(--fb-radius-sm);
    background: var(--fb-text);
    color: var(--fb-bg);
    --note-font-size: var(--fb-text-xs);
    font-family: var(--fb-font-sans);
    font-size: var(--fb-text-xs);
    font-style: normal;
    font-weight: var(--fb-weight-regular);
    line-height: var(--fb-leading-heading);
    letter-spacing: 0;
    text-decoration: none;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--fb-dur-fast) var(--fb-ease), visibility 0s linear var(--fb-dur-fast);
}

/* Active: under the pointer, focused, tapped open, or flashed on arrival */
.fabbrain-nc-simbolo:is(:hover, :focus-visible, .is-ativo, .is-aberto) {
    opacity: 1;
}

/* FABBRAIN (fase 4c, Tarefa 2): the prototype's .circ:hover, a tinted 22px circle around the 15px robot; a click reviews */
.fabbrain-nc-simbolo:not([data-fabbrain-nc-linha]):hover {
    background: var(--fb-warn-soft);
    box-shadow: 0 0 0 var(--fb-nc-symbol-halo) var(--fb-warn-soft);
    cursor: pointer;
}

.fabbrain-nc-simbolo:is(:hover, :focus-visible, .is-ativo, .is-aberto) .fabbrain-nc-dica {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--fb-dur-fast) var(--fb-ease), visibility 0s;
}

/* ---- A marked row of a list of tasks ---------------------------------------- */

:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"].fabbrain-nc-linha {
    position: relative;
    text-decoration-line: none;
    outline: 0;
}

:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"].fabbrain-nc-linha::before,
:root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"].fabbrain-nc-linha::after {
    content: none;
}

:root:not(#fabbrain-trecho):not(#fabbrain-nc) .fabbrain-nc-linha .fabbrain-nc-texto {
    border-radius: var(--fb-nc-highlight-radius);
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--fb-nc-underline);
    text-decoration-thickness: var(--fb-nc-underline-thickness);
    text-underline-offset: var(--fb-nc-underline-offset);
    text-decoration-skip-ink: none;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    transition: background-color var(--fb-dur-fast) var(--fb-ease);
}

/* (with the script the row's text is lit by ::highlight(fabbrain-nc), which
   follows the lines of a text that is a flex item; this ground is the fallback) */
:root:not(#fabbrain-trecho):not(#fabbrain-nc):not(.fabbrain-nc-hl) .fabbrain-nc-linha:is(:hover, :focus-within) .fabbrain-nc-texto {
    background-color: var(--fb-nc-hover-bg);
    box-shadow: 0 0 0 var(--fb-nc-highlight-reach) var(--fb-nc-hover-bg);
}

/* the row's symbol, in the margin on its first line */
.fabbrain-nc-linha > .fabbrain-nc-simbolo {
    top: calc((1lh - var(--fb-nc-symbol-size)) / 2);
    left: calc(-1 * (var(--fb-nc-symbol-gutter) + var(--fb-nc-symbol-size)));
}

/* a row in a box with no margin to its left: the symbol just inside its edge */
.fabbrain-nc-sem-margem .fabbrain-nc-linha > .fabbrain-nc-simbolo {
    left: calc(-1 * var(--fb-nc-symbol-size) - var(--fb-space-1));
}

.fabbrain-nc-linha:is(:hover, :focus-within) > .fabbrain-nc-simbolo {
    opacity: 1;
}

.fabbrain-nc-linha:hover > .fabbrain-nc-simbolo .fabbrain-nc-dica {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--fb-dur-fast) var(--fb-ease), visibility 0s;
}

/* ---- The label as an element ------------------------------------------------- */
/* The note-level "Não confirmado" outside the note header: the link preview's
   header, the revisions page; on its tint (.fabbrain-nc-chip-cartao) on a card
   or a snippet whose note is unconfirmed or holds a marked passage (dashboard,
   kanban, backlinks, search). */

.fabbrain-nc-chip {
    display: inline-flex;
    flex: none;
    align-self: flex-start;
    align-items: center;
    width: fit-content;
    gap: var(--fb-space-2);
    max-width: 100%;
    padding: var(--fb-space-utag-y) var(--fb-space-utag-x);
    border-radius: var(--fb-radius-sm);
    background: transparent;
    color: var(--fb-nc-label-color);
    /* upstream sizes everything in a note through --note-font-size, with !important */
    --note-font-size: var(--fb-text-xs);
    font-family: var(--fb-font-sans);
    font-size: var(--fb-text-xs);
    font-style: normal;
    font-weight: var(--fb-weight-medium);
    line-height: var(--fb-leading-heading);
    letter-spacing: 0;
    text-decoration: none;
    text-transform: none;
    white-space: nowrap;
    vertical-align: middle;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.fabbrain-nc-chip::before {
    content: "";
    flex: none;
    width: var(--fb-icon-xs);
    height: var(--fb-icon-xs);
    background-color: var(--fb-nc-symbol);
    -webkit-mask: var(--fb-icon-dotted) center / contain no-repeat;
    mask: var(--fb-icon-dotted) center / contain no-repeat;
}

.fabbrain-nc-chip.fabbrain-nc-chip-cartao {
    background: var(--fb-warn-soft);
}

.fabbrain-nc-chip[hidden] {
    display: none;
}

/* ---- A line of the revisions comparison ------------------------------------- */

:root:not(#fabbrain-trecho):not(#fabbrain-nc) .fabbrain-nc-linha-diff {
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-color: var(--fb-nc-underline);
    text-decoration-thickness: var(--fb-nc-underline-thickness);
    text-underline-offset: var(--fb-nc-underline-offset);
    text-decoration-skip-ink: none;
}

/* ---- Motion ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
    .fabbrain-nc-simbolo,
    .fabbrain-nc-dica,
    :root:not(#fabbrain-trecho):not(#fabbrain-nc) .fabbrain-nc-linha .fabbrain-nc-texto {
        transition: none;
    }
}

/* ---- Print ------------------------------------------------------------------ */
/* No hover on paper: the underline, the symbol (generated) and a light
   highlight are always on, and a passage is not split across pages */
@media print {
    .fabbrain-nc-camada {
        display: none;
    }

    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"]:not(tr, .fabbrain-nc-linha) {
        background-color: var(--fb-nc-hover-bg);
        break-inside: avoid;
    }

    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] [data-nc="1"] {
        background-color: transparent;
    }

    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"]:not(tr, .fabbrain-nc-linha)::after {
        content: "";
        position: absolute;
        top: calc((1lh - var(--fb-nc-symbol-size)) / 2);
        left: calc(-1 * (var(--fabbrain-indent) + var(--fb-nc-symbol-gutter) + var(--fb-nc-symbol-size)));
        width: var(--fb-nc-symbol-size);
        height: var(--fb-nc-symbol-size);
        background-color: var(--fb-nc-symbol);
        -webkit-mask: var(--fb-icon-dotted) center / contain no-repeat;
        mask: var(--fb-icon-dotted) center / contain no-repeat;
        opacity: 1;
    }

    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] + [data-nc="1"]::after,
    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] + :is(ul, ol) > li[data-nc="1"]:first-child::after,
    :root:not(#fabbrain-trecho):not(#fabbrain-nc) [data-nc="1"] [data-nc="1"]::after {
        content: none;
    }

    :root:not(#fabbrain-trecho):not(#fabbrain-nc) .fabbrain-nc-linha .fabbrain-nc-texto {
        background-color: var(--fb-nc-hover-bg);
    }
}
