/* ======================================
   GRAPHE DES NOTES — Cytoscape.js
   Style Obsidian-like (fond sombre)
   ====================================== */

/* ---------- Conteneur principal ---------- */
.notes-graph-container {
    display: none;
    flex-direction: column;
    position: relative;
    /* Responsive comme .xmind-container (public/xmind-style.css), qui n'a
       jamais ce problème : une hauteur fixe ne remplit pas tout l'espace
       disponible sur les grands écrans (constaté sur iPad, hors plein
       écran — bibliothèque/xmind s'adaptent déjà correctement). Le fix
       ponctuel dans mes-notes-mobile.css (max-width:500px) ne couvrait
       que le téléphone, pas le bloc tablette (769-1024px), qui n'avait
       aucune règle et retombait donc sur ce 700px fixe. */
    height: calc(100vh - 120px);
    height: calc(100dvh - 120px);
    min-height: 700px;
    border-radius: 12px;
    overflow: hidden;
    background: var(--notes-graph-bg, #1a2628);
    /* iOS : désactive l'effet de rebond élastique en bord de conteneur */
    overscroll-behavior: none;
}

/* ── Thèmes pour le graphe des notes ── */
body.theme-blanc .notes-graph-container { --notes-graph-bg: #f0f0f0; --notes-graph-ctrl-bg: #f0f0f0; --notes-graph-ctrl-border: rgba(0,0,0,0.08); --notes-graph-text: #333; --notes-graph-text-dim: #888; --notes-graph-panel-bg: #fff; --notes-graph-panel-border: rgba(0,0,0,0.1); --notes-graph-panel-text: #333; --notes-graph-panel-muted: #666; --notes-graph-tag-bg: rgba(25,118,210,0.1); --notes-graph-tag-color: #1976d2; --notes-graph-tag-border: rgba(25,118,210,0.2); --notes-graph-accent: #f9a825; --notes-graph-check-accent: #3c8c6c; --notes-graph-btn-bg: rgba(0,0,0,0.04); --notes-graph-btn-border: rgba(0,0,0,0.1); --notes-graph-btn-color: #666; }
body.theme-beige .notes-graph-container { --notes-graph-bg: var(--panel); --notes-graph-ctrl-bg: #e2cc9f; --notes-graph-ctrl-border: rgba(196,165,114,0.3); --notes-graph-text: var(--text-primary); --notes-graph-text-dim: #8B7355; --notes-graph-panel-bg: var(--panel-light); --notes-graph-panel-border: #C4A572; --notes-graph-panel-text: var(--text-primary); --notes-graph-panel-muted: #6B5B45; --notes-graph-tag-bg: rgba(25,118,210,0.1); --notes-graph-tag-color: #1976d2; --notes-graph-tag-border: rgba(25,118,210,0.2); --notes-graph-accent: #c5983b; --notes-graph-check-accent: var(--accent); --notes-graph-btn-bg: rgba(0,0,0,0.04); --notes-graph-btn-border: rgba(196,165,114,0.3); --notes-graph-btn-color: #6B5B45; }
body.theme-noir .notes-graph-container  { --notes-graph-bg: #1a2628; --notes-graph-ctrl-bg: #1a2628; --notes-graph-ctrl-border: rgba(255,255,255,0.08); --notes-graph-text: #e8e8e8; --notes-graph-text-dim: #b0b8bc; --notes-graph-panel-bg: #2a3a3d; --notes-graph-panel-border: rgba(255,255,255,0.1); --notes-graph-panel-text: #e8e8e8; --notes-graph-panel-muted: #6b7b80; --notes-graph-tag-bg: rgba(74,145,120,0.15); --notes-graph-tag-color: #5aab8a; --notes-graph-tag-border: rgba(74,145,120,0.25); --notes-graph-accent: #4a9178; --notes-graph-check-accent: #4a9178; --notes-graph-btn-bg: rgba(255,255,255,0.06); --notes-graph-btn-border: rgba(255,255,255,0.12); --notes-graph-btn-color: rgba(255,255,255,0.6); }

/* ── Filigrane logo en arrière-plan du graphe des notes ── */
.notes-graph-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    /* tuiles décalées en quinconce — tile avec padding intégré, logo à ~200px */
    background-image: url('/assets/brand/logo-watermark-tile.svg'), url('/assets/brand/logo-watermark-tile.svg');
    background-repeat: repeat;
    background-size: 440px 194px;
    background-position: 0 0, 220px 97px;
    transform: rotate(-22deg);
    pointer-events: none;
    z-index: 0;
    /* fond sombre par défaut et theme-noir → or brut du SVG (#b89e14) */
    filter: none;
    opacity: 0.05;
}
body.theme-blanc .notes-graph-container::before,
body.theme-beige .notes-graph-container::before {
    filter: grayscale(1) brightness(0.4);
    opacity: 0.05;
}

.notes-graph-container.active {
    display: flex;
}

/* Graphe D3 : remplit l'espace restant sous la barre de contrôles.
   flex:1 + min-height:0 sont requis dans un conteneur flex-direction:column
   pour que clientHeight soit correct dès le premier rendu (évite le collapse
   à 0px et les nœuds rendus hors viewport). */
#cytoscape-graph {
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ---------- Barre de contrôles ---------- */
/* Style « glass » cohérent — s'adapte au thème via --notes-graph-* */
.graph-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--notes-graph-ctrl-bg, #1e1e2e);
    border-bottom: 1px solid var(--notes-graph-ctrl-border, rgba(255, 255, 255, 0.08));
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    flex-wrap: wrap;
    /* Même correctif que .xmind-controls (xmind-style.css) — voir son
       commentaire détaillé. Ici touch-action:none n'est posé que sur le SVG
       (.cytoscape-canvas .d3-graph-svg, pas cette barre), donc probablement
       pas le même mécanisme, mais défensif et sans risque. */
    touch-action: manipulation;
    transition: opacity 0.3s, transform 0.3s;
}

.graph-group-label {
    font-size: 0.82rem;
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.6));
    white-space: nowrap;
    font-weight: 500;
    font-family: 'Inter', sans-serif;
}

/* ── Checklist de regroupement ── */
.graph-checklist {
    display: flex;
    align-items: center;
    gap: 12px;
}

.graph-check-item {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--notes-graph-text, #cdd6f4);
    font-family: 'Inter', sans-serif;
    user-select: none;
    transition: color 0.2s;
}

.graph-check-item:hover {
    color: var(--notes-graph-check-accent, #89b4fa);
}

.graph-check-item input[type="checkbox"] {
    display: none;
}

.graph-check-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--notes-graph-btn-border, rgba(255, 255, 255, 0.25));
    border-radius: 4px;
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.06));
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

.graph-check-item input[type="checkbox"]:checked+.graph-check-mark {
    background: color-mix(in srgb, var(--notes-graph-check-accent, #89b4fa) 25%, transparent);
    border-color: var(--notes-graph-check-accent, #89b4fa);
}

.graph-check-item input[type="checkbox"]:checked+.graph-check-mark::after {
    content: '';
    display: block;
    width: 4px;
    height: 8px;
    border: solid var(--notes-graph-check-accent, #89b4fa);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}

.graph-check-item:has(input[type="checkbox"]:not(:checked)) {
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.4));
    opacity: 0.65;
}

.graph-separator {
    display: inline-block;
    width: 1px;
    height: 18px;
    background: var(--notes-graph-btn-border, rgba(255, 255, 255, 0.12));
    margin: 0 4px;
    vertical-align: middle;
}

.graph-ctrl-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    border: 1px solid var(--notes-graph-btn-border, rgba(255, 255, 255, 0.12));
    border-radius: 6px;
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.06));
    color: var(--notes-graph-btn-color, rgba(255, 255, 255, 0.6));
    cursor: pointer;
    transition: all 0.2s;
}

.graph-ctrl-btn:hover {
    background: var(--notes-graph-btn-hover-bg, rgba(255, 255, 255, 0.12));
    color: var(--notes-graph-text, rgba(255, 255, 255, 0.9));
    border-color: var(--notes-graph-btn-hover-border, rgba(255, 255, 255, 0.2));
}

/* Reveal button : état actif (animation en cours) */
.graph-ctrl-btn.graph-reveal-active {
    background: var(--notes-graph-btn-hover-bg, rgba(255,255,255,0.14));
    color: var(--notes-graph-text, rgba(255,255,255,0.92));
    border-color: var(--notes-graph-btn-hover-border, rgba(255,255,255,0.22));
}

/* Fullscreen button adapts to its SVG content instead of fixed 32x32 */
#graphFullscreenBtn {
    width: auto;
    height: auto;
    padding: 6px 10px;
}

/* ── Conteneur zoom (slider + boutons centrer/plein écran) ── */
.graph-zoom-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.06));
    border: 1px solid var(--notes-graph-btn-border, rgba(255, 255, 255, 0.12));
    border-radius: 6px;
}

.graph-zoom-label {
    font-size: 12px;
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.5));
    font-weight: 500;
    min-width: 16px;
    text-align: center;
    user-select: none;
}

/* Boutons zoom +/- */
.graph-zoom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--notes-graph-btn-border, rgba(255, 255, 255, 0.12));
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.06));
    color: var(--notes-graph-btn-color, rgba(255, 255, 255, 0.6));
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
}

.graph-zoom-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--notes-graph-text, #cdd6f4);
    transform: scale(1.15);
}

.graph-zoom-btn:active {
    transform: scale(0.9);
}

.graph-zoom-slider {
    width: 120px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--notes-graph-btn-border, rgba(255, 255, 255, 0.15));
    outline: none;
    border-radius: 2px;
    cursor: pointer;
}

.graph-zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent, #2E4A40);
    border: 2px solid var(--notes-graph-ctrl-bg, rgba(30, 30, 46, 0.95));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.graph-zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.graph-zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent, #2E4A40);
    border: 2px solid var(--notes-graph-ctrl-bg, rgba(30, 30, 46, 0.95));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
}

.graph-zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.15);
}

.graph-zoom-level {
    font-size: 12px;
    font-weight: 600;
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.5));
    min-width: 40px;
    text-align: center;
}

/* ---------- Canvas D3 (remplace Cytoscape) ---------- */
.cytoscape-canvas {
    flex: 1;
    width: 100%;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

/* SVG racine du graphe D3 */
.cytoscape-canvas .d3-graph-svg {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none; /* permettre le pinch-to-zoom D3 */
}

/* Nœud "vide" */
.cytoscape-canvas .graph-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--notes-graph-text-dim, rgba(255,255,255,0.45));
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
}

/* Nœud note en cours de drag */
.gnode.dragging .node-circle {
    stroke-width: 2 !important;
    stroke: rgba(255,255,255,0.7) !important;
}

/* Transition de transparence au highlight (géré en JS, mais smooth via CSS) */
.gnode, .glink {
    transition: opacity 0.15s ease;
}

/* ---------- Spinner de chargement ---------- */
@keyframes graphSpin {
    to { transform: rotate(360deg); }
}

/* ---------- Fullscreen ---------- */
.notes-graph-container:fullscreen,
.notes-graph-container.simulated-fullscreen {
    height: 100vh !important;
    height: 100dvh !important;
    min-height: unset !important;
    max-height: none !important;
    border-radius: 0 !important;
}

.notes-graph-container.simulated-fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-height: unset !important;
    z-index: 99999 !important;
    display: flex !important;
}

/* .simulated-fullscreen (repli CSS iOS) ne peut jamais masquer le chrome
   Safari (barre d'adresse/barre d'outils) — une marge sur les 4 côtés évite
   que le contenu soit collé à ce chrome. Pas nécessaire pour :fullscreen
   natif (chrome déjà masqué). box-sizing:border-box (global) évite tout
   dépassement du width/height 100vw/100dvh défini ci-dessus. Ce padding ne
   profite qu'au contenu en flux normal (#cytoscape-graph) — .graph-controls
   étant en position:absolute, son containing block est le padding BOX
   (qui INCLUT le padding), donc top:0/left:0/right:0 reste collé au bord
   réel malgré ce padding. */
.notes-graph-container.simulated-fullscreen {
    padding: 20px !important;
}

/* La bande garde sa position de base (haut/gauche/droite à 0) pour occuper
   tout l'espace jusqu'aux bords — plus de vide visible dans les coins.
   C'est son PROPRE padding (et non plus un décalage de position) qui pousse
   les contrôles à 20px des bords réels. */
.notes-graph-container:fullscreen .graph-controls,
.notes-graph-container.simulated-fullscreen .graph-controls {
    padding: 30px 36px 10px;
    justify-content: center;
    /* Fond opaque (.graph-controls de base) + padding agrandi ci-dessus =
       grand bandeau plein-largeur en plein écran — transparent ici : les
       boutons (qui ont déjà leur propre fond, cf. --notes-graph-btn-bg)
       flottent directement sur la carte mentale au lieu d'un bandeau
       plaqué dessus. Même traitement que .xmind-controls (xmind-style.css). */
    background: transparent;
    border-bottom: none;
}

.notes-graph-container:fullscreen .cytoscape-canvas,
.notes-graph-container.simulated-fullscreen .cytoscape-canvas {
    height: calc(100vh - 50px);
    height: calc(100dvh - 50px);
}

.notes-graph-container:fullscreen .d3-graph-svg,
.notes-graph-container.simulated-fullscreen .d3-graph-svg {
    height: 100%;
}

/* Auto-hide en plein écran */
.notes-graph-container:fullscreen .graph-controls.controls-hidden,
.notes-graph-container.simulated-fullscreen .graph-controls.controls-hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-100%);
}

/* ---------- Tooltip (hover sur nœud) ---------- */
.graph-tooltip {
    position: absolute;
    z-index: 1000;
    max-width: 340px;
    min-width: 180px;
    background: var(--notes-graph-panel-bg, #2a2a3c);
    border: 1px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.1));
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    pointer-events: none;
    font-size: 13px;
    color: var(--notes-graph-panel-text, #cdd6f4);
    line-height: 1.45;
    animation: graphTooltipFade 0.15s ease-out;
}

@keyframes graphTooltipFade {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.graph-tooltip .tooltip-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.5));
}

.graph-tooltip .tooltip-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.15));
}

.graph-tooltip .tooltip-book-title {
    font-weight: 600;
    color: var(--notes-graph-text, rgba(255, 255, 255, 0.75));
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.graph-tooltip .tooltip-date {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.35));
}

.graph-tooltip .tooltip-selected-text {
    font-style: italic;
    color: var(--notes-graph-accent, #f9e2af);
    border-left: 3px solid var(--notes-graph-accent, #f9e2af);
    padding-left: 8px;
    margin-bottom: 6px;
    font-size: 12.5px;
    line-height: 1.4;
}

.graph-tooltip .tooltip-content {
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.6));
    font-size: 12px;
    margin-bottom: 6px;
    line-height: 1.4;
}

.graph-tooltip .tooltip-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.graph-tooltip .tooltip-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    color: #fff;
    font-weight: 500;
    opacity: 0.85;
}

/* ---------- Panneau de détail de note ---------- */
.note-mm-modal {
    display: none;
    position: absolute;
    left: 20px;
    bottom: 20px;
    z-index: 100;
    background: var(--notes-graph-panel-bg, #2a2a3c);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    width: fit-content;
    min-width: 220px;
    max-width: 320px;
    max-height: 85%;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    color: var(--notes-graph-panel-text, #cdd6f4);
}

.note-mm-modal.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.note-mm-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 60;
}

.note-mm-selected-text {
    font-style: italic;
    font-size: 0.85rem;
    color: var(--notes-graph-accent, #f9e2af);
    padding: 8px 12px;
    border-left: 4px solid var(--notes-graph-accent, #f9e2af);
    background: color-mix(in srgb, var(--notes-graph-accent, #f9e2af) 8%, transparent);
    border-radius: 0 6px 6px 0;
    margin-bottom: 10px;
    line-height: 1.4;
    word-break: break-word;
    max-height: 40vh;
    overflow-y: auto;
}

#note-mm-modal .note-mm-content {
    font-size: 0.8rem;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.65));
    padding: 8px 10px;
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.04));
    border-radius: 6px;
    margin-bottom: 10px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

.note-mm-book-title {
    font-size: 0.8rem;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.5));
    margin-bottom: 4px;
    padding-right: 30px;
}

.note-mm-date {
    font-size: 0.75rem;
    color: var(--notes-graph-text-dim, rgba(255, 255, 255, 0.35));
    margin-bottom: 8px;
}

.note-mm-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 10px;
}

.note-mm-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    background: var(--notes-graph-tag-bg, rgba(137, 180, 250, 0.15));
    color: var(--notes-graph-tag-color, #89b4fa);
    border: 1px solid var(--notes-graph-tag-border, rgba(137, 180, 250, 0.2));
}

.note-mm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0.75rem;
}

/* ── Boutons modaux (note + livre) : icônes uniquement ── */
.note-mm-actions .btn,
.notes-graph-container .modal-actions .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--btn-color) 30%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--btn-color) 14%, transparent);
    color: var(--btn-color);
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.note-mm-actions .btn svg,
.notes-graph-container .modal-actions .btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.note-mm-actions .btn:hover,
.notes-graph-container .modal-actions .btn:hover {
    background: color-mix(in srgb, var(--btn-color) 22%, transparent);
    border-color: color-mix(in srgb, var(--btn-color) 50%, transparent);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px color-mix(in srgb, var(--btn-color) 22%, transparent);
    filter: none;
}

.note-mm-actions .btn:active,
.notes-graph-container .modal-actions .btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px color-mix(in srgb, var(--btn-color) 25%, transparent);
}

.note-mm-actions .btn:focus-visible,
.notes-graph-container .modal-actions .btn:focus-visible {
    outline: 2px solid var(--btn-color);
    outline-offset: 2px;
}

/* Couleurs des boutons de notes (CSS variable consommée par les règles ci-dessus) */
.note-mm-btn-edit,
.note-mm-btn-book   { --btn-color: var(--accent, #1A5238); }
.note-mm-btn-color  { --btn-color: var(--notes-graph-accent, #f9e2af); }
.note-mm-btn-delete { --btn-color: #dc4c5e; }

body.theme-noir .note-mm-btn-edit,
body.theme-noir .note-mm-btn-book { --btn-color: var(--accent-gold, #b89e14); }

/* ---------- Panneau livre ---------- */
.notes-graph-container .book-modal {
    display: none;
    position: absolute;
    left: 20px;
    bottom: 20px;
    z-index: 100;
    background: var(--notes-graph-panel-bg, #2a2a3c);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    width: 320px;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    color: var(--notes-graph-panel-text, #cdd6f4);
}

.notes-graph-container .book-modal.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.notes-graph-container .modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 60;
}

.notes-graph-container .modal-book-info {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.notes-graph-container .modal-book-cover {
    width: 60px;
    height: 90px;
    object-fit: cover;
    border-radius: var(--cover-radius, 4px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.notes-graph-container .modal-book-details {
    flex: 1;
    min-width: 0;
}

.notes-graph-container .modal-book-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.4rem 0;
    color: var(--notes-graph-panel-text, #cdd6f4);
    line-height: 1.3;
    padding-right: 40px;
    word-break: break-word;
}

.notes-graph-container .modal-book-meta {
    font-size: 0.8rem;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.5));
    margin: 0.3rem 0;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.notes-graph-container .modal-book-category {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.7rem;
}

.notes-graph-container .modal-book-description {
    font-size: 0.8rem;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.6));
    margin: 0.4rem 0 0 0;
    line-height: 1.4;
}

.notes-graph-container .modal-book-author {
    color: var(--notes-graph-check-accent, #89b4fa);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.notes-graph-container .modal-book-author:hover {
    color: var(--notes-graph-text, #b4d0fb);
    text-decoration: underline;
}

.notes-graph-container .modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 0.75rem;
}

/* Hérite du design tinté défini plus haut (.notes-graph-container .modal-actions .btn) */

/* ---------- Panneau tag ---------- */
.tag-mm-modal {
    display: none;
    position: absolute;
    left: 20px;
    bottom: 20px;
    z-index: 100;
    background: var(--notes-graph-panel-bg, #2a2a3c);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    width: 300px;
    max-height: 85%;
    overflow-y: auto;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.1));
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    color: var(--notes-graph-panel-text, #cdd6f4);
}

.tag-mm-modal.active {
    display: block;
    opacity: 1;
    pointer-events: auto;
}

.tag-mm-modal-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 60;
}

.tag-mm-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.tag-mm-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tag-mm-name {
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}

.tag-mm-count {
    font-size: 0.85rem;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.55));
    display: flex;
    align-items: center;
    gap: 6px;
}

.tag-mm-count svg {
    opacity: 0.6;
}

/* ── Édition du tag : input renommer ── */
.tag-mm-name-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tag-mm-name-input {
    flex: 1;
    min-width: 0;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1.5px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.15));
    background: var(--notes-graph-btn-bg, rgba(255, 255, 255, 0.06));
    color: var(--notes-graph-panel-text, #cdd6f4);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.tag-mm-name-input:focus {
    border-color: var(--notes-graph-check-accent, #5aab8a);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--notes-graph-check-accent, #5aab8a) 25%, transparent);
}

/* ── Bouton stylo pour éditer le nom ── */
.tag-mm-btn-edit-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.55));
    cursor: pointer;
    transition: color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

.tag-mm-btn-edit-icon:hover {
    color: var(--notes-graph-panel-text, #cdd6f4);
}

.tag-mm-btn-edit-icon:active {
    transform: scale(0.92);
}

/* ── Palette de couleurs (clic = applique immédiatement) ── */
.tag-mm-colors {
    margin-top: 10px;
}

.tag-mm-colors-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.45));
    margin-bottom: 6px;
    font-weight: 600;
}

.tag-mm-colors-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.tag-mm-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    background-clip: padding-box;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.tag-mm-swatch:hover {
    transform: scale(1.12);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.tag-mm-swatch.selected {
    border-color: var(--notes-graph-panel-text, #fff);
    box-shadow: 0 0 0 2px var(--notes-graph-panel-bg, #2a3a3d), 0 0 0 4px var(--notes-graph-check-accent, #5aab8a);
}

/* Bouton « Auto » (reset à la couleur hash par défaut) */
.tag-mm-swatch-auto {
    background: repeating-conic-gradient(#888 0% 25%, #ccc 0% 50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.12s ease, border-color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.tag-mm-swatch-auto::after {
    content: "↺";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.tag-mm-swatch-auto:hover {
    transform: scale(1.12);
}

.tag-mm-swatch-auto.selected {
    border-color: var(--notes-graph-panel-text, #fff);
    box-shadow: 0 0 0 2px var(--notes-graph-panel-bg, #2a3a3d), 0 0 0 4px var(--notes-graph-check-accent, #5aab8a);
}

/* ── Bouton "+" pour couleur personnalisée ── */
.tag-mm-swatch-add {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--notes-graph-panel-border, rgba(255, 255, 255, 0.15));
    cursor: pointer;
    padding: 0;
    background: transparent;
    color: var(--notes-graph-panel-muted, rgba(255, 255, 255, 0.55));
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.12s ease, border-color 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tag-mm-swatch-add:hover {
    transform: scale(1.12);
    border-color: var(--notes-graph-panel-text, #fff);
    color: var(--notes-graph-panel-text, #cdd6f4);
}

.tag-mm-swatch-add svg {
    width: 12px;
    height: 12px;
}

/* ── Boutons d'action du tag : hérite du design tinté ── */
.tag-mm-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.tag-mm-actions .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    min-height: 38px;
    border: 1px solid color-mix(in srgb, var(--btn-color) 30%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--btn-color) 14%, transparent);
    color: var(--btn-color);
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.tag-mm-actions .btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    stroke: currentColor;
}

.tag-mm-actions .btn:hover {
    background: color-mix(in srgb, var(--btn-color) 22%, transparent);
    border-color: color-mix(in srgb, var(--btn-color) 50%, transparent);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px color-mix(in srgb, var(--btn-color) 22%, transparent);
}

.tag-mm-actions .btn:active {
    transform: translateY(0);
}

.tag-mm-actions .btn:focus-visible {
    outline: 2px solid var(--btn-color);
    outline-offset: 2px;
}

.tag-mm-btn-rename { --btn-color: var(--notes-graph-accent, #f9e2af); }
.tag-mm-btn-save   { --btn-color: #5aab8a; }
.tag-mm-btn-cancel { --btn-color: #8a8a8a; }

/* ---------- Scrollbar sombre pour les panneaux ---------- */
.note-mm-modal::-webkit-scrollbar,
.notes-graph-container .book-modal::-webkit-scrollbar,
.tag-mm-modal::-webkit-scrollbar {
    width: 5px;
}

.note-mm-modal::-webkit-scrollbar-track,
.notes-graph-container .book-modal::-webkit-scrollbar-track,
.tag-mm-modal::-webkit-scrollbar-track {
    background: transparent;
}

.note-mm-modal::-webkit-scrollbar-thumb,
.notes-graph-container .book-modal::-webkit-scrollbar-thumb,
.tag-mm-modal::-webkit-scrollbar-thumb {
    background: var(--notes-graph-panel-border, rgba(255,255,255,0.15));
    border-radius: 3px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .notes-graph-container {
        height: calc(100dvh - 200px);
        min-height: 350px;
        border-radius: 8px;
    }

    /* Contrôles du graphe : mise en page mobile */
    .graph-controls {
        flex-wrap: wrap;
        padding: 8px 10px;
        gap: 6px;
    }

    .graph-group-label {
        font-size: 0.75rem;
        flex-basis: auto;
    }

    .graph-checklist {
        gap: 8px;
    }

    .graph-check-item {
        font-size: 0.75rem;
        gap: 4px;
    }

    .graph-separator {
        display: none;
    }

    .graph-zoom-container {
        gap: 6px;
        padding: 3px 8px;
    }

    .graph-zoom-slider {
        width: 90px;
    }

    .graph-zoom-level {
        font-size: 10px;
        min-width: 28px;
    }

    .graph-ctrl-btn {
        width: 36px;
        height: 36px;
    }

    /* Modals pleine largeur en bas sur mobile */
    .note-mm-modal,
    .notes-graph-container .book-modal,
    .tag-mm-modal {
        left: 8px !important;
        right: 8px !important;
        bottom: 8px !important;
        max-width: none;
        max-height: 45vh;
        overflow-y: auto;
        border-radius: 10px;
        padding: 0.75rem 1rem;
    }

    .notes-graph-container .popup-close-btn {
        width: 28px;
        height: 28px;
    }

    .note-mm-selected-text {
        font-size: 0.8rem;
        max-height: 20vh;
    }

    /* Mobile : boutons d'action en grille 2 colonnes, cibles tactiles ≥44px */
    .note-mm-actions,
    .notes-graph-container .modal-actions,
    .tag-mm-actions {
        gap: 8px;
        margin-top: 0.85rem;
    }

    .note-mm-actions .btn,
    .notes-graph-container .modal-actions .btn,
    .tag-mm-actions .btn {
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        padding: 0;
        min-height: unset;
        border-radius: 10px;
    }

    .note-mm-actions .btn svg,
    .notes-graph-container .modal-actions .btn svg,
    .tag-mm-actions .btn svg {
        width: 18px;
        height: 18px;
    }

    /* Plus grands swatches sur mobile */
    .tag-mm-swatch,
    .tag-mm-swatch-auto {
        width: 30px;
        height: 30px;
    }

    .notes-graph-container .modal-book-cover {
        width: 48px;
        height: 72px;
    }

    .notes-graph-container .modal-book-title {
        font-size: 0.85rem;
        padding-right: 28px;
    }

    /* Tooltip : caché sur mobile (tap-to-click remplace le hover) */
    .graph-tooltip {
        display: none !important;
    }

    /* Fullscreen mobile */
    .notes-graph-container:fullscreen .graph-controls {
        padding: 6px 10px;
        gap: 6px;
    }
}

/* ===== PETIT MOBILE ≤ 480px ===== */
@media (max-width: 480px) {
    .notes-graph-container {
        height: calc(100dvh - 160px);
        min-height: 300px;
        border-radius: 6px;
    }

    .graph-controls {
        padding: 6px 8px;
        gap: 4px;
    }

    .graph-group-label {
        font-size: 0.7rem;
    }

    .graph-checklist {
        gap: 6px;
    }

    .graph-check-item {
        font-size: 0.7rem;
    }

    .note-mm-modal,
    .notes-graph-container .book-modal,
    .tag-mm-modal {
        left: 4px !important;
        right: 4px !important;
        bottom: 4px !important;
        max-height: 40vh;
        padding: 0.6rem 0.75rem;
    }

    /* Petit mobile : conserver cible tactile 44px mais réduire le padding horizontal */
    .note-mm-actions .btn,
    .notes-graph-container .modal-actions .btn,
    .tag-mm-actions .btn {
        min-height: 44px;
        padding: 10px 8px;
        font-size: 0.78rem;
        gap: 5px;
    }

    .tag-mm-header {
        gap: 6px;
    }

    .tag-mm-icon {
        width: 28px;
        height: 28px;
    }

    .tag-mm-name {
        font-size: 0.85rem;
    }

    .tag-mm-btn-edit-icon {
        width: 24px;
        height: 24px;
    }

    .tag-mm-swatch,
    .tag-mm-swatch-auto,
    .tag-mm-swatch-add {
        width: 30px;
        height: 30px;
    }

    .tag-mm-swatch-add svg {
        width: 14px;
        height: 14px;
    }
}

/* ===== TABLETTE 769px – 1024px ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    .notes-graph-container {
        height: 550px;
    }

    .note-mm-modal,
    .notes-graph-container .book-modal,
    .tag-mm-modal {
        width: 300px;
    }
}

/* ===== ORIENTATION PAYSAGE MOBILE ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .notes-graph-container {
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px); /* iOS : suit la hauteur réellement visible */
        min-height: 220px;
    }

    .graph-controls {
        padding: 4px 8px;
        gap: 4px;
    }

    .note-mm-modal,
    .notes-graph-container .book-modal,
    .tag-mm-modal {
        max-height: 50vh;
    }
}