/* ════════════════════════════════════════════════════════════════════════
   canvas_editor.css  —  Folio Block-Model Editor
   ────────────────────────────────────────────────────────────────────────
   PURPOSE
   -------
   All styles that belong to the #note-canvas block-model editor live HERE.
   Nothing in styles.css should need to touch block layout, figure flow,
   or drag-drop UI. If you're debugging editor rendering, start in this file.

   ARCHITECTURE SUMMARY (read before editing)
   -------------------------------------------
   #note-canvas
     Not contenteditable itself. It is just a vertical stack of blocks.

   .eb  (editor-block)
     Every direct child of #note-canvas is an .eb.
     Each block owns its own contenteditable state:
       - Text blocks  (.eb-p, .eb-h1…h6, .eb-quote)  → contenteditable="true"
       - Non-text     (.eb-figure, .eb-code, .eb-table, .eb-divider, .eb-todo-list)
                      → contenteditable="false" on the wrapper,
                        contenteditable="true" only on inner editable parts
                        (table cells, code textarea, caption)

   .eb-figure
     A <figure> block sitting in the text flow.
     Alignment is controlled by .eb-align-left / center / right / full.
     NO absolute positioning. NO x/y percentages.
     Width is set via --fig-width CSS variable (default 100%).
     On drag-reorder, JS moves the <figure> element itself in the DOM —
     the figure always stays in the flow, just at a different position.

   DATA ATTRIBUTES on .eb
     data-block-id      Unique stable ID (set by CanvasWorker._stampBlockIds)
     data-block-type    "paragraph" | "heading" | "quote" | "code" |
                        "figure" | "table" | "divider" | "todo-list" | "list"
     data-drag-over     Present during drag-over for the drop indicator

   ════════════════════════════════════════════════════════════════════════ */


/* ══════════════════════════════════════════════════════════════
   1. CANVAS CONTAINER
   ══════════════════════════════════════════════════════════════ */

#note-canvas {
    /* ── Flex child: fills the notetaking-supervisor height ──────────
       styles.css owns the flex container (#notetaking-supervisor).
       This fills remaining height and scrolls internally. */
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;

    /* ── Block model: NOT contenteditable itself ──────────────────────
       contenteditable="true" is set on individual .eb children by CanvasWorker.
       This element is only the scroll + layout container. */
    outline: none;
    position: relative;   /* needed for drag drop-indicators */

    /* ── Layout ───────────────────────────────────────────────────────
       Matches old single-block canvas padding exactly so nothing
       visually shifts during the migration. */
    padding: 12px 0 120px;   /* Step 3: content starts close to top like Notion */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;

    /* ── Typography base (inherited by all .eb children) ─────────── */
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--text);
    line-height: 1.85;
    word-break: break-word;
}

#note-canvas::-webkit-scrollbar       { width: 5px; }
#note-canvas::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Inner content width — blocks left-align from a centred column.
   padding-left matches old canvas left padding so text starts at same point. */
#note-canvas > .eb {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 0;
    padding-right: 0;
    box-sizing: border-box;
}


/* ══════════════════════════════════════════════════════════════
   2. EDITOR BLOCK — BASE
   ══════════════════════════════════════════════════════════════ */

.eb {
    /* Every block sits in normal document flow */
    display: block;
    position: relative;     /* for the drag handle and block toolbar */
    width: 100%;
    margin: 0;
    padding: 1px 0;

    /* Smooth highlight transitions */
    transition: background 0.12s ease;
}

/* ── Block drag handle (shown on hover, left of block) ──────── */
.eb::before {
    content: '⠿';
    position: absolute;
    left: -28px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    text-align: center;
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0;
    cursor: grab;
    transition: opacity 0.15s;
    user-select: none;
    /* Only shown when canvas is in "editing" mode — toggled by JS */
    pointer-events: none;
}

/* Show drag handle on block hover, hide it on figure focus */
.eb:hover > .eb::before,
#note-canvas:hover .eb:hover::before {
    opacity: 0.5;
    pointer-events: auto;
}

.eb.eb-dragging::before {
    opacity: 0 !important;
    cursor: grabbing;
}


/* ── Block drag handle — shown on .eb-figure and .eb-table-wrap hover ──
   A dedicated element (not ::before) so it works on contenteditable=false blocks. */
.eb-block-drag-handle {
    position: absolute;
    top: 6px;
    left: -26px;
    width: 20px;
    height: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: var(--text-muted);
    cursor: grab;
    opacity: 0;
    transition: opacity 0.15s;
    user-select: none;
    z-index: 12;
    pointer-events: all;
}
.eb-figure:hover .eb-block-drag-handle,
.eb-table-wrap:hover .eb-block-drag-handle {
    opacity: 1;
}
.eb-block-drag-handle:active { cursor: grabbing; }

/* ── Active cursor line highlight — transparent, no tint ───── */
.eb.eb-active {
    background: transparent;
    color: var(--text);
}


/* ══════════════════════════════════════════════════════════════
   3. TEXT BLOCKS
   Text blocks have contenteditable="true" directly on the .eb.
   ══════════════════════════════════════════════════════════════ */

/* Shared text block base */
.eb-p,
.eb-h1, .eb-h2, .eb-h3, .eb-h4, .eb-h5, .eb-h6,
.eb-quote {
    font-family: var(--font-family);
    color: var(--text);
    line-height: 1.85;
    word-break: break-word;
    outline: none;
    min-height: 1.6em;

    /* Prevent browser from injecting unwanted block wrappers on Enter.
       We intercept Enter ourselves and create a new .eb-p. */
    white-space: pre-wrap;
}

/* ── Placeholder system ─────────────────────────────────────────────
   Placeholders are CSS-only — zero JavaScript.
   • .eb-p with data-placeholder shows it when the block is :empty or
     contains only a <br> (both mean "nothing typed yet").
   • The FIRST block gets a PERSISTENT placeholder (visible even when
     not focused) so new notes always show "Type '/' for commands…"
   • All other blocks show their placeholder only on :focus.
   • .eb-empty-pad blocks are purely visual — pointer-events:none so
     they can never receive focus or intercept clicks.
─────────────────────────────────────────────────────────────────── */

/* Any empty .eb-p that has a data-placeholder — show on focus */
.eb-p:empty::before,
.eb-p:focus:not(:empty):has(br:only-child)::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary, var(--text-secondary));
    opacity: 0.38;
    font-style: italic;
    pointer-events: none;
    position: absolute;
    left: 0; top: 0;
}
/* .eb-p that contains ONLY a <br> — treat as empty for placeholder */
.eb-p:has(br:only-child)::before {
    content: attr(data-placeholder);
    color: var(--text-tertiary, var(--text-secondary));
    opacity: 0.38;
    font-style: italic;
    pointer-events: none;
    position: absolute;
    left: 0; top: 0;
}
/* Non-focused non-first blocks: hide placeholder until focused */
.eb-p:not(:focus):not(:first-child)::before { opacity: 0; }
.eb-p:not(:focus):not(:first-child):has(br:only-child)::before { opacity: 0; }

/* ── Headings ──────────────────────────────────────────────── */
.eb-h1 { font-size: 2em;    font-weight: 700; line-height: 1.3; margin: 0.7em 0 0.2em; }
.eb-h2 { font-size: 1.5em;  font-weight: 700; line-height: 1.3; margin: 0.6em 0 0.2em;
         border-bottom: 1px solid var(--divider); padding-bottom: 4px; }
.eb-h3 { font-size: 1.2em;  font-weight: 700; line-height: 1.4; margin: 0.5em 0 0.15em; }
.eb-h4 { font-size: 1.05em; font-weight: 700; line-height: 1.5; margin: 0.4em 0 0.1em; }
.eb-h5 { font-size: 0.95em; font-weight: 700; }
.eb-h6 { font-size: 0.9em;  font-weight: 700; color: var(--text-secondary); }

/* ── Blockquote ────────────────────────────────────────────── */
.eb-quote {
    border-left: 3px solid var(--accent);
    margin: 4px 0;
    padding: 8px 16px;
    background: var(--hover);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* ── Inline formatting inside text blocks ──────────────────── */
.eb strong, .eb b   { background: transparent !important; font-weight: 700; }
.eb em,    .eb i    { background: transparent !important; }
.eb u               { background: transparent !important; text-decoration: underline; }
.eb s, .eb del      { text-decoration: line-through; }
.eb mark            { background: rgba(255,220,0,0.35); border-radius: 2px; padding: 0 2px; }
.eb a               { color: var(--accent); text-decoration: underline; }
.eb a:hover         { opacity: 0.8; }
.eb sup             { vertical-align: super; font-size: 0.75em; }
.eb sub             { vertical-align: sub;   font-size: 0.75em; }

/* Inline code inside text blocks */
.eb code:not(.eb-code-inner) {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.88em;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    color: var(--accent);
}


/* ══════════════════════════════════════════════════════════════
   4. LIST BLOCKS
   ══════════════════════════════════════════════════════════════ */

/* ── Legacy list wrapper (kept for backward-compat loading) ── */
.eb-list ul,
.eb-list ol {
    margin: 2px 0;
    padding-left: 28px;
    line-height: 1.85;
}
.eb-list li {
    margin: 2px 0;
    outline: none;
    word-break: break-word;
}

/* ── Step 5: Individual .eb-li blocks (Path A model) ──────────
   Each list item is its own .eb block — predictable Enter/Backspace.
   CSS makes consecutive .eb-li look like a native list visually.
   The data-list-type="ul"|"ol" attribute controls bullet vs number.
   ──────────────────────────────────────────────────────────── */
.eb-li {
    display: list-item;
    list-style-position: outside;
    margin-left: 28px;
    margin-top: 0;
    margin-bottom: 0;
    padding: 1px 0;
    outline: none;
    word-break: break-word;
    line-height: 1.85;
    min-height: 1.6em;
    position: relative;
}

/* Bullet style */
.eb-li[data-list-type="ul"] { list-style-type: disc; }
.eb-li[data-list-type="ol"] { list-style-type: decimal; }

/* Collapse gap between consecutive list items — Notion-like flush list */
.eb-li + .eb-li { margin-top: -1px; }

/* First item in a list run: small gap above */
.eb:not(.eb-li) + .eb-li { margin-top: 6px; }

/* Last item in a list run: small gap below */
.eb-li + .eb:not(.eb-li) { margin-top: 6px; }

/* Ordered list counter — auto-increment within consecutive .eb-li[ol] runs */
#note-canvas {
    counter-reset: eb-ol-counter;
}
.eb-li[data-list-type="ol"] {
    counter-increment: eb-ol-counter;
    list-style-type: none;
}
.eb-li[data-list-type="ol"]::before {
    content: counter(eb-ol-counter) ". ";
    position: absolute;
    left: -28px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    pointer-events: none;
}
/* Reset counter when a non-ol block interrupts the sequence */
.eb:not(.eb-li[data-list-type="ol"]) { counter-reset: eb-ol-counter; }

/* ── To-do list ─────────────────────────────────────────────── */
.eb-todo-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0;
}

.eb-todo-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 2px 0;
}

.eb-checkbox {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1.5px solid var(--border);
    background: var(--bg);
    cursor: pointer;
    transition: all var(--t);
    margin-top: 3px;
    user-select: none;
    /* Force pointer-events even inside contenteditable=false parent */
    pointer-events: all;
    position: relative;
    z-index: 2;
}
.eb-checkbox:hover               { border-color: var(--accent); }
.eb-checkbox.checked             { background: var(--accent); border-color: var(--accent); }
.eb-checkbox.checked::after {
    content: '';
    width: 5px; height: 9px;
    border: 2px solid #fff;
    border-top: none; border-left: none;
    transform: rotate(45deg) translateY(-1px);
    display: block;
}

.eb-todo-text {
    flex: 1;
    outline: none;
    word-break: break-word;
    min-height: 1.4em;
    line-height: 1.7;
}

/* Strike through when done */
.eb-todo-item:has(.eb-checkbox.checked) .eb-todo-text {
    text-decoration: line-through;
    color: var(--text-secondary);
    opacity: 0.7;
}


/* ══════════════════════════════════════════════════════════════
   5. CODE BLOCK
   ══════════════════════════════════════════════════════════════ */

/* Wrapper: not editable itself */
.eb-code-wrap {
    position: relative;
    margin: 8px 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: visible;   /* must NOT be hidden — clips pre height when content has many lines */
}

/* Language label top-left */
.eb-code-lang {
    position: absolute;
    top: 8px; left: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
    user-select: none;
    pointer-events: none;
}

/* Copy button top-right */
.eb-code-copy {
    position: absolute;
    top: 6px; right: 8px;
    font-family: 'Nunito', sans-serif;
    font-size: 11px;
    padding: 3px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: background var(--t);
}
.eb-code-copy:hover { background: var(--hover); color: var(--text); }

/* The actual editable code area */
.eb-code-inner {
    display: block;
    padding: 32px 16px 14px;    /* top padding leaves room for lang+copy */
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);

    /* pre-wrap: preserves ALL whitespace and newlines, wraps at container edge.
       This is the only value that correctly round-trips indentation + newlines
       while still preventing horizontal scrollbar on narrow canvases. */
    white-space: pre-wrap;
    word-break: normal;         /* pre-wrap handles wrapping; break-all breaks indentation */
    overflow-wrap: anywhere;    /* only break truly unbreakable tokens */
    tab-size: 4;
    -moz-tab-size: 4;

    overflow-x: auto;
    outline: none;
    min-height: 2.5em;
}

/* <code> inside pre — transparent, inherits everything */
.eb-code-inner code {
    display: block;
    background: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    white-space: inherit;
    tab-size: inherit;
    -moz-tab-size: inherit;
    padding: 0;
    border: none;
    outline: none;
}


/* ══════════════════════════════════════════════════════════════
   6. DIVIDER BLOCK
   ══════════════════════════════════════════════════════════════ */

.eb-divider {
    display: flex;
    align-items: center;
    padding: 8px 0;
    cursor: default;
}

.eb-divider hr {
    flex: 1;
    border: none;
    border-top: 2px solid var(--divider);
    margin: 0;
}


/* ══════════════════════════════════════════════════════════════
   7. FIGURE BLOCK  ← the main new thing
   ══════════════════════════════════════════════════════════════
   A <figure class="eb eb-figure"> sits in the document flow.
   It pushes text above and below it just like any block element.
   Alignment is handled with CSS only — no absolute positioning,
   no x/y/% coordinates.

   --fig-width is set inline by JS when user resizes.
   Default is 100% (full width = no float).

   Drag-to-reorder works by moving the <figure> element itself
   in the DOM — the browser reflows naturally.
   ══════════════════════════════════════════════════════════════ */

.eb-figure {
    --fig-width: 100%;      /* overridden inline by JS on resize */

    display: block;         /* default: block, full width */
    width: var(--fig-width);
    max-width: 100%;
    margin: 12px 0;

    /* Border + shadow to distinguish from text */
    border: 2px solid transparent;
    border-radius: 8px;
    transition: border-color 0.15s;
    overflow: visible;      /* allow resize handle to overflow */
    position: relative;     /* for resize handle and drag indicator */
    cursor: grab;
}
.eb-figure:active { cursor: grabbing; }

/* Selection/focus ring on figure */
.eb-figure:hover .eb-fig-resize {
    opacity: 1;
    border-color: var(--accent);
}
.eb-figure:focus-within .eb-fig-resize,
.eb-figure.eb-selected .eb-fig-resize {
    opacity: 1;
    border-color: var(--accent);
}

/* Selection/focus ring on figure */
.eb-figure:focus-within,
.eb-figure.eb-selected {
    border-color: var(--accent);
    outline: none;
}

/* ── Alignment variants ─────────────────────────────────────── */
/*
   center  = centered block, no float, width = --fig-width
   left    = float left, text wraps right
   right   = float right, text wraps left
   full    = 100% width, no float (default)
*/

.eb-figure.eb-align-center {
    margin-left: auto;
    margin-right: auto;
    float: none;
    clear: both;
}

.eb-figure.eb-align-left {
    float: left;
    margin-right: 20px;
    margin-bottom: 8px;
    clear: left;
}

.eb-figure.eb-align-right {
    float: right;
    margin-left: 20px;
    margin-bottom: 8px;
    clear: right;
}

.eb-figure.eb-align-full {
    width: 100% !important;  /* override --fig-width */
    float: none;
    clear: both;
}

/* Clearfix: after a floated figure, resume normal block flow */
.eb-figure.eb-align-left + .eb,
.eb-figure.eb-align-right + .eb {
    /* Text blocks following a floated figure wrap around it.
       Non-text blocks (another figure, divider, code) clear the float. */
}
.eb-figure.eb-align-left ~ .eb-figure,
.eb-figure.eb-align-right ~ .eb-figure,
.eb-figure.eb-align-left ~ .eb-divider,
.eb-figure.eb-align-right ~ .eb-divider {
    clear: both;
}

/* ── Figure image ───────────────────────────────────────────── */
.eb-figure img.eb-img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    object-fit: contain;
    pointer-events: none;   /* prevent browser drag-image on the img itself */
    user-select: none;
}

/* ── Figure caption ─────────────────────────────────────────── */
.eb-figcaption {
    display: block;
    font-family: 'Nunito', sans-serif;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    padding: 5px 8px 2px;
    outline: none;
    min-height: 1.2em;
    /* Editable — JS sets contenteditable="true" */
}

.eb-figcaption:empty::before {
    content: 'Caption (optional)';
    opacity: 0.35;
    pointer-events: none;
    font-style: italic;
}

/* ── Figure resize handle — SE corner, Windows-style ───────────
   Two perpendicular lines form an L-shape in the corner.
   Always faintly visible; brightens on figure hover.             */
.eb-fig-resize {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    cursor: se-resize;
    z-index: 5;
    /* L-shape via two borders */
    border-right: 2px solid var(--border);
    border-bottom: 2px solid var(--border);
    border-radius: 0 0 4px 0;
    opacity: 0.5;
    transition: opacity 0.15s, border-color 0.15s;
}

/* ══════════════════════════════════════════════════════════════
   8. TABLE BLOCK
   ══════════════════════════════════════════════════════════════
   The .eb-table-wrap is contenteditable="false".
   Each <td> and <th> has contenteditable="true".
   ══════════════════════════════════════════════════════════════ */

.eb-table-wrap {
    overflow-x: auto;
    margin: 8px 0;
    cursor: grab;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.eb-table {
    border-collapse: collapse;
    width: 100%;
    min-width: 200px;
    font-size: 14px;
}

.eb-table th,
.eb-table td {
    border: 1px solid var(--border);
    padding: 7px 12px;
    text-align: left;
    outline: none;
    min-width: 60px;
    word-break: break-word;
    vertical-align: top;
    line-height: 1.5;
    position: relative;     /* for column resize handle */
}

.eb-table th {
    background: var(--bg-secondary);
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 13px;
    color: var(--text);
    user-select: none;      /* header drag/reorder later */
}

.eb-table td {
    background: var(--bg);
}

.eb-table tr:hover td {
    background: var(--hover);
}

/* Focus ring inside active cell */
.eb-table td:focus,
.eb-table th:focus {
    background: color-mix(in srgb, var(--accent) 8%, var(--bg));
    box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 40%, transparent);
}

/* ── Column resize handle — Windows NCHITTEST style ──────────
   A thin 1px line is always visible on table cell right edge.
   On hover it expands to a 4px grab zone with accent colour.     */
.eb-col-resizer {
    position: absolute;
    top: 0; right: 0;
    width: 4px; height: 100%;
    cursor: col-resize;
    z-index: 4;
    /* Persistent 1px right-edge line — always visible */
    border-right: 1px solid var(--border);
    transition: border-color 0.1s, background 0.1s;
}
.eb-col-resizer::after {
    content: '';
    position: absolute;
    top: 0; right: -2px;
    width: 4px; height: 100%;
    /* Invisible wider hit-area so cursor snaps easily */
}
.eb-col-resizer:hover,
.eb-col-resizer.resizing {
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    border-right-color: var(--accent);
    border-right-width: 2px;
}

/* ── Row resize handle — Windows NCHITTEST style ──────────────
   A thin 1px line always visible at bottom of each row.
   On hover it expands to a 4px grab zone.                        */
.eb-row-resizer {
    position: absolute;
    bottom: 0; left: 0;
    width: 100%; height: 4px;
    cursor: row-resize;
    z-index: 4;
    /* Persistent 1px bottom-edge line */
    border-bottom: 1px solid var(--border);
    transition: border-color 0.1s, background 0.1s;
}
.eb-row-resizer:hover,
.eb-row-resizer.resizing {
    background: color-mix(in srgb, var(--accent) 30%, transparent);
    border-bottom-color: var(--accent);
    border-bottom-width: 2px;
}


/* ══════════════════════════════════════════════════════════════
   9. DRAG-TO-REORDER  (block-level, Notion-style)
   ══════════════════════════════════════════════════════════════
   When user drags a block, a drop indicator line appears between
   blocks to show where it will land.
   JS adds data-drag-over="above" or data-drag-over="below" to the
   target .eb while dragging.
   ══════════════════════════════════════════════════════════════ */

/* The block being dragged: slight fade */
.eb.eb-dragging {
    opacity: 0.4;
    pointer-events: none;
}

/* Drop indicator: a colored line above or below target block */
.eb[data-drag-over="above"]::before {
    content: '';
    display: block;
    position: absolute;
    top: -2px; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

.eb[data-drag-over="below"]::after {
    content: '';
    display: block;
    position: absolute;
    bottom: -2px; left: 0; right: 0;
    height: 3px;
    background: var(--accent);
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}

/* NOTE: .eb::before is also used for the drag handle icon above.
   The [data-drag-over="above"] pseudo overrides that during active drag.
   Keep the JS drag system from setting data-drag-over="above" on
   the dragged block itself to avoid conflict. */


/* ══════════════════════════════════════════════════════════════
   10. FIGURE CONTEXT MENU  (right-click on figure)
   ══════════════════════════════════════════════════════════════
   Replaces the old .ci-ctx-menu for figures specifically.
   Uses the same visual style for consistency.
   ══════════════════════════════════════════════════════════════ */

.eb-fig-ctx {
    position: fixed;        /* fixed so it doesn't scroll with canvas */
    z-index: 9000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 5px;
    min-width: 170px;
    box-shadow: var(--shadow-lg);
    animation: popIn 0.1s ease;
}
.eb-fig-ctx.hidden { display: none; }

.eb-fig-ctx-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    color: var(--text);
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background var(--t);
}
.eb-fig-ctx-item:hover       { background: var(--hover); }
.eb-fig-ctx-item.active      { color: var(--accent); font-weight: 700; }
.eb-fig-ctx-sep              { height: 1px; background: var(--divider); margin: 3px 0; }
.eb-fig-ctx-danger           { color: #E05252; }
.eb-fig-ctx-danger:hover     { background: rgba(224,82,82,0.1); }

/* Section label inside context menu */
.eb-fig-ctx-label {
    padding: 4px 10px 2px;
    font-family: 'Nunito', sans-serif;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    user-select: none;
}


/* ══════════════════════════════════════════════════════════════
   11. EMPTY-CANVAS STATE  &  PADDING BLOCKS
   ══════════════════════════════════════════════════════════════ */

/* ── Trailing padding blocks ──────────────────────────────────
   eb-empty-pad blocks are VISUAL ONLY.
   • contenteditable="false" (set by JS in _ensurePadding)
   • pointer-events: none so they never steal clicks or focus
   • Clicking the canvas below real content is redirected by JS
     to the last real block — see CanvasWorker._bindPadClick()
   ──────────────────────────────────────────────────────────── */
.eb-p.eb-empty-pad {
    min-height: 1.7em;
    color: transparent;
    user-select: none;
    pointer-events: none;   /* ← NEW: clicks fall through to canvas handler */
    cursor: text;
}

/* ── First-block persistent placeholder ───────────────────────
   Always visible on the first block when it is empty, even when
   not focused. This is the "Type here to start" landmark.
   ──────────────────────────────────────────────────────────── */
#note-canvas > .eb-p:first-child:empty::before,
#note-canvas > .eb-p:first-child:has(br:only-child)::before {
    content: attr(data-placeholder);
    color: var(--text-secondary);
    opacity: 0.38;
    font-style: italic;
    pointer-events: none;
    position: absolute;
    left: 0; top: 0;
}


/* ══════════════════════════════════════════════════════════════
   12. SELECTION + FOCUS STATES
   ══════════════════════════════════════════════════════════════ */

/* Text cursor color everywhere in canvas */
#note-canvas [contenteditable] {
    caret-color: var(--accent);
    outline: none;
}

/* Block-level focus ring — transparent, text stays black/theme color */
.eb.eb-active:not(.eb-figure):not(.eb-divider) {
    background: transparent;
    color: var(--text);
}



/* ── Note ribbon — coloured left border on the notetaking supervisor ──
   Applied by NotetakingSupervisor._applyRibbon() when note:ribbon fires.  */
#notetaking-supervisor.ribbon-red    { border-left: 3px solid var(--ribbon-red); }
#notetaking-supervisor.ribbon-amber  { border-left: 3px solid var(--ribbon-amber); }
#notetaking-supervisor.ribbon-green  { border-left: 3px solid var(--ribbon-green); }
#notetaking-supervisor.ribbon-blue   { border-left: 3px solid var(--ribbon-blue); }
#notetaking-supervisor.ribbon-purple { border-left: 3px solid var(--ribbon-purple); }
#notetaking-supervisor.ribbon-teal   { border-left: 3px solid var(--ribbon-teal); }
#notetaking-supervisor.ribbon-pink   { border-left: 3px solid var(--ribbon-pink); }
#notetaking-supervisor.ribbon-none   { border-left: none; }

/* ══════════════════════════════════════════════════════════════
   13. TROUBLESHOOTING HELPERS
   ══════════════════════════════════════════════════════════════
   Add class "debug-blocks" to #note-canvas to reveal block
   boundaries. Useful during development — remove before shipping.

   Usage:
     document.getElementById('note-canvas').classList.add('debug-blocks');
   ══════════════════════════════════════════════════════════════ */

#note-canvas.debug-blocks .eb {
    outline: 1px dashed rgba(201,106,58,0.4);
}

#note-canvas.debug-blocks .eb::after {
    content: attr(data-block-type) ' #' attr(data-block-id);
    position: absolute;
    right: 4px; top: 2px;
    font-family: monospace;
    font-size: 9px;
    color: var(--accent);
    opacity: 0.6;
    pointer-events: none;
}

#note-canvas.debug-blocks .eb-figure {
    outline: 2px dashed rgba(74,142,196,0.6);
}

#note-canvas.debug-blocks .eb-figure::after {
    content: 'figure align=' attr(data-align) ' w=' attr(data-fig-width);
    background: rgba(74,142,196,0.15);
}