/* ====================================================================
 * Canvas — free-form 2D pattern boards.
 * Tokens inherit from #page-notes (notes.css).
 * ==================================================================== */

#page-notes .cv-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: var(--bg-0);
}

#page-notes .notes-shell[data-view="canvas"] .notes-main { padding: 0; }
#page-notes .notes-shell[data-view="canvas"] .notes-tabs { display: none; }
#page-notes .notes-shell[data-view="canvas"] .notes-editor {
    padding: 0;
    overflow: hidden;
}

/* ── Toolbar ────────────────────────────────────────────────── */

#page-notes .cv-toolbar {
    height: 44px;
    flex-shrink: 0;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-1);
    display: flex;
    align-items: center;
    gap: 10px;
}
#page-notes .cv-tb-icon {
    font-size: 14px;
    color: var(--accent);
    line-height: 1;
}
#page-notes .cv-title {
    flex: 0 0 auto;
    width: 240px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 4px 8px;
    border-radius: 3px;
}
#page-notes .cv-title:hover,
#page-notes .cv-title:focus {
    border-color: var(--border);
    background: var(--surface);
    outline: none;
}
#page-notes .cv-meta {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}
#page-notes .cv-tb-spacer { flex: 1; }
#page-notes .cv-tb-btn {
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--text-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 5px 10px;
    cursor: pointer;
    line-height: 1;
}
#page-notes .cv-tb-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--surface-alt);
}
#page-notes .cv-tb-btn-back {
    border-color: var(--accent);
    color: var(--accent);
}
#page-notes .cv-tb-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 4px;
}
#page-notes .cv-status {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    min-width: 48px;
    text-align: right;
}
#page-notes .cv-status-err {
    color: var(--bad);
}

/* ── Stage ─────────────────────────────────────────────────── */

#page-notes .cv-stage {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-0);
    user-select: none;
    -webkit-user-select: none;
}
#page-notes .cv-pan-cursor { cursor: grab; }
#page-notes .cv-pan-active { cursor: grabbing !important; }

#page-notes .cv-grid {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#page-notes .cv-world {
    position: absolute;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
}

/* SVG layer used for arrows. The world is unbounded, so we make a giant
 * absolutely-positioned canvas that the world transform pans across. */
#page-notes .cv-edges {
    position: absolute;
    left: -10000px;
    top: -10000px;
    width: 20000px;
    height: 20000px;
    pointer-events: none;
}
#page-notes .cv-edges path {
    pointer-events: stroke;
}
#page-notes .cv-cards,
#page-notes .cv-groups {
    position: absolute;
    left: 0;
    top: 0;
}

/* ── Group containers ─────────────────────────────────────── */

#page-notes .cv-group {
    position: absolute;
    background: rgba(15, 19, 26, 0.5);
    border: 1.5px dashed rgba(79, 195, 247, 0.35);
    border-radius: 6px;
    cursor: move;
    box-sizing: border-box;
}
#page-notes .cv-group.selected {
    box-shadow: 0 0 0 2px var(--accent);
}
#page-notes .cv-group.cv-color-bad { border-color: rgba(248, 113, 113, 0.4); }
#page-notes .cv-group.cv-color-warn { border-color: rgba(251, 191, 36, 0.4); }
#page-notes .cv-group.cv-color-good { border-color: rgba(74, 222, 128, 0.4); }
#page-notes .cv-group.cv-color-accent { border-color: rgba(79, 195, 247, 0.4); }
#page-notes .cv-group-title {
    position: absolute;
    top: 10px;
    left: 14px;
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.18em;
    color: var(--text-secondary);
}
#page-notes .cv-group.cv-color-bad .cv-group-title { color: var(--bad); }
#page-notes .cv-group.cv-color-warn .cv-group-title { color: var(--warn); }
#page-notes .cv-group.cv-color-good .cv-group-title { color: var(--good); }
#page-notes .cv-group.cv-color-accent .cv-group-title { color: var(--accent); }

/* ── Cards ────────────────────────────────────────────────── */

#page-notes .cv-card {
    position: absolute;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    cursor: move;
    box-sizing: border-box;
    transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
#page-notes .cv-card.selected {
    box-shadow: 0 0 0 2px var(--accent), 0 4px 12px rgba(0, 0, 0, 0.6);
}
#page-notes .cv-card.cv-color-bad { border-left-color: var(--bad); }
#page-notes .cv-card.cv-color-warn { border-left-color: var(--warn); }
#page-notes .cv-card.cv-color-good { border-left-color: var(--good); }
#page-notes .cv-card.cv-color-accent { border-left-color: var(--accent); }
#page-notes .cv-card.cv-color-neutral { border-left-color: var(--text-muted); }

#page-notes .cv-card-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    margin-bottom: 5px;
    word-break: break-word;
}
#page-notes .cv-card-body {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.45;
    margin-bottom: 6px;
    word-break: break-word;
    white-space: pre-wrap;
}
#page-notes .cv-card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
#page-notes .cv-card-tag {
    font-family: var(--font-mono);
    font-size: 9px;
    padding: 1px 5px;
    background: var(--bg-0);
    color: var(--text-muted);
    border-radius: 2px;
}
#page-notes .cv-card-text .cv-card-body {
    margin: 0;
    color: var(--text-primary);
    font-weight: 500;
}
#page-notes .cv-card-image {
    padding: 0;
    overflow: hidden;
}
#page-notes .cv-card-img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
#page-notes .cv-card-img-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ── Connection handles (card edges) ─────────────────────── */

#page-notes .cv-card-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent);
    border: 2px solid var(--bg-0);
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.1s ease;
    cursor: crosshair;
    z-index: 2;
}
#page-notes .cv-card:hover .cv-card-handle {
    opacity: 0.85;
}
#page-notes .cv-card-handle:hover { opacity: 1; transform: scale(1.15); }
#page-notes .cv-card-handle-r { right: -6px; top: 50%; transform: translateY(-50%); }
#page-notes .cv-card-handle-l { left: -6px; top: 50%; transform: translateY(-50%); }
#page-notes .cv-card-handle-t { left: 50%; top: -6px; transform: translateX(-50%); }
#page-notes .cv-card-handle-b { left: 50%; bottom: -6px; transform: translateX(-50%); }

/* ── Resize handle (bottom-right corner) ─────────────────── */

#page-notes .cv-resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    cursor: nwse-resize;
    z-index: 2;
}
#page-notes .cv-resize-br {
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, transparent 50%, var(--border-strong) 50%);
    border-radius: 0 0 4px 0;
    opacity: 0;
    transition: opacity 0.1s ease;
}
#page-notes .cv-card:hover .cv-resize-br,
#page-notes .cv-group:hover .cv-resize-br { opacity: 1; }

/* ── Marquee selection ───────────────────────────────────── */

#page-notes .cv-marquee {
    position: absolute;
    border: 1px dashed var(--accent);
    background: rgba(79, 195, 247, 0.08);
    pointer-events: none;
    z-index: 3;
}

/* ── Zoom controls (bottom-left) ─────────────────────────── */

#page-notes .cv-zoom {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    align-items: center;
    background: rgba(15, 19, 26, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 4px;
    z-index: 5;
}
#page-notes .cv-zoom-btn {
    background: transparent;
    border: 0;
    border-left: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    line-height: 1;
}
#page-notes .cv-zoom-btn:first-child { border-left: 0; }
#page-notes .cv-zoom-btn:hover {
    color: var(--text-primary);
    background: var(--surface);
}
#page-notes .cv-zoom-fit {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}
#page-notes .cv-zoom-val {
    padding: 6px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    border-left: 1px solid var(--border);
    min-width: 56px;
    text-align: center;
}

/* ── Mini-map (bottom-right) ─────────────────────────────── */

#page-notes .cv-mini {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 180px;
    height: 120px;
    background: rgba(15, 19, 26, 0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 6px;
    z-index: 5;
}
#page-notes .cv-mini-inner {
    position: relative;
    width: 100%;
    height: 100%;
    background: var(--bg-0);
    border-radius: 2px;
    cursor: pointer;
    overflow: hidden;
}
#page-notes .cv-mini-node {
    position: absolute;
    border-radius: 1px;
}
#page-notes .cv-mini-vp {
    position: absolute;
    border: 1.5px solid var(--accent);
    background: rgba(79, 195, 247, 0.1);
    pointer-events: none;
    box-sizing: border-box;
}

/* ── Edge context menu ───────────────────────────────────── */

#page-notes .cv-edge-menu {
    position: absolute;
    background: var(--bg-1);
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 8px 10px;
    z-index: 10;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    min-width: 220px;
}
#page-notes .cv-edge-menu-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
#page-notes .cv-edge-menu-label {
    font-family: var(--font-display);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    text-transform: uppercase;
    width: 50px;
}
#page-notes .cv-color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: transform 0.1s ease;
}
#page-notes .cv-color-dot:hover {
    transform: scale(1.15);
    border-color: var(--text-primary);
}
#page-notes .cv-edge-menu-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 11px;
    cursor: pointer;
}
#page-notes .cv-edge-menu-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--surface-alt);
}
#page-notes .cv-edge-menu-del {
    background: transparent;
    border: 1px solid var(--bad);
    color: var(--bad);
    border-radius: 3px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    margin-left: auto;
}
#page-notes .cv-edge-menu-del:hover {
    background: var(--bad);
    color: var(--bg-0);
}

/* ── Loading / error / list ──────────────────────────────── */

#page-notes .cv-loading,
#page-notes .cv-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
    padding: 32px;
    gap: 12px;
}
#page-notes .cv-error-icon {
    font-size: 24px;
    color: var(--warn);
}
#page-notes .cv-error-title {
    font-family: var(--font-display);
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 600;
}
#page-notes .cv-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    border-radius: 3px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
}
#page-notes .cv-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent);
}
#page-notes .cv-btn-primary {
    background: var(--accent);
    color: var(--bg-0);
    border-color: var(--accent);
    font-weight: 600;
}
#page-notes .cv-btn-primary:hover {
    background: var(--accent-hot);
    border-color: var(--accent-hot);
    color: var(--bg-0);
}

/* ── Canvas list ─────────────────────────────────────────── */

#page-notes .cv-list-wrap {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-0);
}
#page-notes .cv-list-head {
    flex-shrink: 0;
    height: 44px;
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-1);
}
#page-notes .cv-list-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.14em;
    color: var(--text-primary);
    text-transform: uppercase;
}
#page-notes .cv-list-body {
    flex: 1;
    overflow: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    align-content: start;
}
#page-notes .cv-list-loading,
#page-notes .cv-list-error,
#page-notes .cv-list-empty {
    grid-column: 1 / -1;
    color: var(--text-muted);
    text-align: center;
    padding: 48px 16px;
}
#page-notes .cv-list-empty-glyph {
    font-size: 36px;
    color: var(--text-muted);
    margin-bottom: 12px;
}
#page-notes .cv-list-empty-title {
    font-family: var(--font-display);
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 4px;
}
#page-notes .cv-list-empty-body {
    font-size: 12px;
    color: var(--text-secondary);
    max-width: 480px;
    margin: 0 auto;
    line-height: 1.5;
}
#page-notes .cv-list-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.12s ease, background 0.12s ease;
}
#page-notes .cv-list-card:hover {
    border-color: var(--border-strong);
    background: var(--surface-alt);
}
#page-notes .cv-list-card-glyph {
    font-size: 22px;
    color: var(--accent);
    line-height: 1;
}
#page-notes .cv-list-card-meta {
    flex: 1;
    min-width: 0;
}
#page-notes .cv-list-card-title {
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--text-primary);
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#page-notes .cv-list-card-sub {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}
#page-notes .cv-list-card-del {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 26px;
    height: 26px;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1;
    font-size: 14px;
    flex-shrink: 0;
}
#page-notes .cv-list-card-del:hover {
    color: var(--bad);
    border-color: var(--bad);
}
