/* Noeuds : width max-content obligatoire. Leur conteneur (.gr-noeuds) a une largeur nulle ; sans elle, la largeur
   disponible d'un noeud diminue quand on le deplace vers la droite et son titre se replie mot par mot (texte « vertical »). */
/* GRAPH (graph/index.php) : l'application occupe toute la page sous le menu Ninou².
   La position exacte (haut, gauche, droite, bas) est posee par graph/js/graph.js
   d'apres la place reelle du menu (#mainHeader), qui peut etre en haut, en bas ou sur le cote. */

body.graph-page { overflow: hidden; }
body.graph-page .footer, body.graph-page #debug { display: none !important; }

.gr-app { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1020; display: flex; flex-direction: column; background: #f4f6f8; }

/* ---------- Barre d'outils du graphe ---------- */
.gr-barre { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 8px; background: #fff; border-bottom: 1px solid #dee2e6; box-shadow: 0 2px 6px rgba(0,0,0,.05); z-index: 3; }
.gr-logo { font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #343a40; white-space: nowrap; }
.gr-nom { width: 14em; max-width: 40vw; flex: 0 1 auto; }
.gr-groupe { display: inline-flex; flex-wrap: wrap; gap: 4px; padding-left: 6px; border-left: 1px solid #e9ecef; }
.gr-etat { margin-left: auto; font-size: .85rem; color: #6c757d; white-space: nowrap; }
.gr-etat.modifie { color: #d9822b; }
#gr-relier.active { color: #fff; background: #007bff; }
@media (max-width: 767px) {
	.gr-lib { display: none; }
	.gr-logo { display: none; }
	.gr-nom { width: 9em; }
}

/* ---------- Zone de dessin ---------- */
.gr-zone { position: relative; flex: 1 1 auto; overflow: hidden; cursor: grab; touch-action: none; outline: none;
	background-color: #f4f6f8; background-image: radial-gradient(circle, #cfd6dd 1px, transparent 1.2px); background-size: 24px 24px; }
.gr-zone.glisse { cursor: grabbing; }
.gr-zone.relier { cursor: crosshair; }
.gr-monde { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
/* overflow visible obligatoire, et plus fort que « svg:not(:root) { overflow: hidden } » de Bootstrap :
   sinon le SVG (1 px) coupe tous les liens et rien n'apparait. */
.gr-zone svg.gr-liens { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible !important; }
.gr-noeuds { position: absolute; left: 0; top: 0; }

.gr-lien { fill: none; stroke-width: 2.2; }
.gr-lien-touche { fill: none; stroke: transparent; stroke-width: 16; cursor: pointer; pointer-events: stroke; }
.gr-lien-g.choisi .gr-lien { stroke-width: 3.6; filter: drop-shadow(0 0 3px rgba(0,123,255,.8)); }
.gr-lien-nom-fond { fill: #fff; stroke: #dee2e6; stroke-width: 1; }
.gr-lien-nom { font-size: 13px; fill: #343a40; dominant-baseline: central; text-anchor: middle; cursor: pointer; user-select: none; }
/* Carres du lien selectionne : les tirer courbe le lien (points de passage). */
.gr-poignee { fill: #adb5bd; stroke: #495057; cursor: move; }
.gr-poignee:hover { fill: #007bff; stroke: #0056b3; }
/* Bouts du lien selectionne : les tirer change son depart ou son arrivee. */
.gr-bout { fill: #007bff; stroke: #fff; cursor: grab; }
.gr-bout:hover { fill: #0056b3; }
.gr-lien-provisoire { fill: none; stroke: #007bff; stroke-width: 2; stroke-dasharray: 6 5; pointer-events: none; }
/* Cardinalites aux bouts d'un lien ; soulignees en pointille si une description (infobulle) existe. */
.gr-card { font-size: 12px; font-weight: 700; fill: #343a40; dominant-baseline: central; paint-order: stroke; stroke: #f4f6f8; stroke-width: 4px; stroke-linejoin: round; cursor: pointer; user-select: none; }
.gr-card.a-desc { text-decoration: underline dotted; cursor: help; }
.gr-card-bulle { position: absolute; z-index: 3; max-width: min(280px, 80%); padding: 6px 10px; background: #343a40; color: #fff; border-radius: 6px; font-size: .85rem; line-height: 1.35;
	white-space: pre-wrap; overflow-wrap: anywhere; pointer-events: none; box-shadow: 0 3px 10px rgba(0,0,0,.25); }
.gr-card-bloc { margin-bottom: .5rem; }
.gr-card-lib { display: block; margin-bottom: 2px; font-size: .85rem; }
.gr-card-lib span { font-weight: 600; }

.gr-noeud { position: absolute; transform: translate(-50%, -50%); display: flex; align-items: center; justify-content: center; width: max-content; min-width: 60px; max-width: 320px; padding: .45em .9em; border: 3px solid #343a40; border-radius: 14px;
	background: #fff; color: #212529; font-weight: 600; line-height: 1.2; text-align: center; white-space: pre-wrap; overflow-wrap: normal; word-break: normal;
	box-shadow: 0 2px 8px rgba(0,0,0,.12); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none; transition: box-shadow .15s; }
/* Taille choisie (bordure tiree) : le titre reste centre verticalement et horizontalement, le surplus est coupe. */
.gr-noeud.dimensionne { min-width: 0; max-width: none; }
.gr-noeud.dimensionne .gr-titre { max-width: 100%; max-height: 100%; overflow: hidden; }
.gr-noeud.dimensionne .gr-a-desc { top: 2px; right: 2px; }
/* Carres d'ancrage au milieu de chaque cote : tirer de l'un a celui d'un autre noeud cree un lien. */
.gr-ancre { position: absolute; width: 10px; height: 10px; background: #adb5bd; border: 1px solid #6c757d; border-radius: 2px; cursor: crosshair; z-index: 1; touch-action: none; transition: transform .1s, background-color .1s; }
.gr-ancre-n { top: -1.5px; left: 50%; transform: translate(-50%, -50%); }
.gr-ancre-s { bottom: -1.5px; left: 50%; transform: translate(-50%, 50%); }
.gr-ancre-e { right: -1.5px; top: 50%; transform: translate(50%, -50%); }
.gr-ancre-o { left: -1.5px; top: 50%; transform: translate(-50%, -50%); }
.gr-ancre:hover, .gr-ancre.cible { background: #007bff; border-color: #0056b3; }
.gr-ancre-n:hover, .gr-ancre-n.cible { transform: translate(-50%, -50%) scale(1.5); }
.gr-ancre-s:hover, .gr-ancre-s.cible { transform: translate(-50%, 50%) scale(1.5); }
.gr-ancre-e:hover, .gr-ancre-e.cible { transform: translate(50%, -50%) scale(1.5); }
.gr-ancre-o:hover, .gr-ancre-o.cible { transform: translate(-50%, -50%) scale(1.5); }
.gr-zone.tirage, .gr-zone.tirage .gr-noeud { cursor: crosshair !important; }
@media (pointer: coarse) { .gr-ancre { width: 16px; height: 16px; } }
.gr-noeud:hover { box-shadow: 0 3px 14px rgba(0,0,0,.22); }
.gr-noeud.choisi { box-shadow: 0 0 0 4px rgba(0,123,255,.45), 0 3px 14px rgba(0,0,0,.2); }
.gr-noeud.source { box-shadow: 0 0 0 4px rgba(40,167,69,.6), 0 3px 14px rgba(0,0,0,.2); }
.gr-noeud.vide { font-style: italic; font-weight: 400; opacity: .75; }
.gr-noeud:not(.a-desc) .gr-a-desc { display: none; }
.gr-noeud .gr-a-desc { position: absolute; top: -7px; right: -7px; width: 16px; height: 16px; border-radius: 50%; background: #17a2b8; color: #fff; font-size: 10px; line-height: 16px; font-style: normal; font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.3); }

/* Description : visible seulement au clic sur le noeud */
.gr-bulle { position: absolute; z-index: 2; max-width: min(360px, 80%); max-height: 45%; overflow: auto; padding: 10px 12px; background: #fffef3; border: 1px solid #e0d98c; border-radius: 10px;
	box-shadow: 0 4px 16px rgba(0,0,0,.18); font-size: .95rem; white-space: pre-wrap; overflow-wrap: anywhere; pointer-events: auto; cursor: default; }
.gr-bulle b { display: block; margin-bottom: 4px; }

.gr-vide { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center; color: #6c757d; }
.gr-aide { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 2; padding: 6px 14px; border-radius: 20px; background: #007bff; color: #fff; font-size: .9rem; box-shadow: 0 2px 8px rgba(0,0,0,.2); }

/* ---------- Panneau des proprietes ---------- */
.gr-panneau { position: absolute; right: 10px; bottom: 10px; z-index: 4; width: 300px; max-height: calc(100% - 70px); overflow: auto; padding: 10px 12px; background: #fff; border: 1px solid #dee2e6; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.18); }
.gr-panneau-titre { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 6px; }
.gr-panneau .form-group { margin-bottom: 8px; }
.gr-panneau label { margin-bottom: 2px; font-size: .9rem; }
.gr-ligne { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.gr-ligne label { margin: 0; }
.gr-couleur { width: 42px; height: 32px; padding: 2px; border: 1px solid #ced4da; border-radius: 6px; background: #fff; cursor: pointer; }
.gr-palette { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.gr-palette button { width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 3px solid; cursor: pointer; }
.gr-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 575px) {
	.gr-panneau { left: 6px; right: 6px; bottom: 6px; width: auto; max-height: 50%; }
}

/* ---------- Liste des graphes enregistres ---------- */
.gr-liste-ligne { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid #f1f3f5; }
.gr-liste-ligne:last-child { border-bottom: 0; }
.gr-liste-ligne.courant { background: #eef6ff; border-radius: 8px; }
.gr-liste-nom { flex: 1 1 auto; min-width: 0; }
.gr-liste-nom b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-liste-nom small { color: #6c757d; }

/* ---------- Raccourcis clavier ---------- */
.gr-rac-ligne { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f1f3f5; }
.gr-rac-lib { flex: 1 1 auto; min-width: 0; font-size: .95rem; }
.gr-rac-fixes { margin-top: 10px; padding-top: 6px; border-top: 2px solid #e9ecef; color: #6c757d; }
.gr-rac-fixes .gr-rac-ligne:last-child { border-bottom: 0; }
.gr-rac-defaut { padding: 0 4px; font-size: .8rem; white-space: nowrap; }
.gr-touche { flex: 0 0 auto; min-width: 5.5em; padding: 3px 10px; border: 1px solid #adb5bd; border-bottom-width: 3px; border-radius: 6px; background: #f8f9fa;
	font-family: SFMono-Regular, Menlo, Consolas, monospace; font-size: .9rem; font-weight: 600; color: #212529; text-align: center; cursor: pointer; white-space: nowrap; }
button.gr-touche:hover { background: #e9f2ff; border-color: #007bff; }
.gr-touche.attente { background: #fff3cd; border-color: #e0a800; font-family: inherit; font-weight: 400; animation: grClignote 1s infinite; }
.gr-touche.vide { color: #adb5bd; font-style: italic; font-weight: 400; }
.gr-touche.fixe { cursor: default; font-weight: 400; font-family: inherit; font-size: .8rem; background: #fff; }
@keyframes grClignote { 50% { background: #ffe8a1; } }

/* ===================== Lot « nouvelles fonctions » (formes, cadres, selection, recherche, mini-carte, theme) ===================== */
.gr-barre .dropdown { display: inline-block; }
.gr-barre .dropdown-menu { z-index: 1060; max-height: 75vh; overflow-y: auto; }
.gr-barre .btn.active { color: #fff; background: #6c757d; border-color: #6c757d; }
#gr-relier.active { background: #007bff; border-color: #007bff; }
.gr-recherche { align-items: center; }
.gr-recherche input { width: 10em; }
.gr-chercher-nb { font-size: .8rem; color: #6c757d; min-width: 2.2em; text-align: center; }
.gr-etat.erreur { color: #dc3545; }
@media (max-width: 767px) { .gr-recherche input { width: 6.5em; } }

/* Mode selection (rectangle) */
.gr-zone.mode-sel { cursor: crosshair; }
.gr-rect-sel { position: absolute; z-index: 2; border: 1px dashed #007bff; background: rgba(0,123,255,.08); pointer-events: none; }

/* Noeud : icone, lien web, replier */
.gr-noeud .gr-icone { margin-right: .3em; font-weight: 400; }
/* Retour a la ligne seulement entre deux mots : un mot trop long fait reduire le titre (ajusterTitre dans graph.js). */
.gr-noeud .gr-titre { position: relative; min-width: 0; max-width: 100%; overflow-wrap: normal; word-break: normal; }
.gr-noeud .gr-a-lien { position: absolute; top: -8px; left: -8px; font-size: 13px; line-height: 1; cursor: pointer; filter: drop-shadow(0 1px 1px rgba(0,0,0,.3)); z-index: 2; }
.gr-noeud:not(.a-lien) .gr-a-lien { display: none; }
.gr-noeud .gr-replier { position: absolute; right: -10px; bottom: -10px; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 10px; background: #495057; color: #fff;
	font: 700 12px/20px system-ui, sans-serif; text-align: center; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.3); z-index: 2; }
.gr-noeud .gr-replier:hover { background: #007bff; }
.gr-noeud .gr-replier[hidden] { display: none; }
.gr-noeud.trouve { outline: 3px solid #ffc107; outline-offset: 3px; }
.gr-noeud.trouve-courant { outline-color: #fd7e14; outline-width: 4px; }

/* Formes */
.gr-noeud.forme-rect { border-radius: 3px; }
.gr-noeud.forme-ovale { border-radius: 50%; padding: .7em 1.4em; }
.gr-noeud .gr-fond-forme { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; display: none; z-index: -1; }
.gr-noeud .gr-fond-forme path { stroke-width: 3; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.gr-noeud.forme-svg { background: transparent !important; border-color: transparent !important; box-shadow: none; z-index: 0; }
.gr-noeud.forme-svg .gr-fond-forme { display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,.15)); }
.gr-noeud.forme-svg:hover { box-shadow: none; }
.gr-noeud.forme-svg.choisi { box-shadow: none; }
.gr-noeud.forme-svg.choisi .gr-fond-forme { filter: drop-shadow(0 0 3px rgba(0,123,255,.9)) drop-shadow(0 0 6px rgba(0,123,255,.6)); }
.gr-noeud.forme-svg.source .gr-fond-forme { filter: drop-shadow(0 0 5px rgba(40,167,69,.9)); }
.gr-noeud.forme-losange { padding: 1.3em 2.3em; min-width: 110px; min-height: 70px; }
.gr-noeud.forme-nuage { padding: 1.3em 1.9em; min-width: 100px; min-height: 64px; }
.gr-noeud.forme-note { padding: .9em 1.2em; min-width: 90px; min-height: 60px; border-radius: 0; }
/* Taille choisie (bordure tiree) : marges fixes, qui ne grossissent pas avec le titre, pour lui laisser la place. */
.gr-noeud.dimensionne { padding: 4px 8px; }
.gr-noeud.dimensionne.forme-ovale { padding: 6% 13%; }
.gr-noeud.dimensionne.forme-losange { padding: 16% 22%; }
.gr-noeud.dimensionne.forme-nuage { padding: 12% 15%; }
.gr-noeud.dimensionne.forme-note { padding: 6px 10px; }

/* Cadres (groupes) : sous les liens et les noeuds ; seuls le titre et le coin reagissent */
.gr-cadres { position: absolute; left: 0; top: 0; }
.gr-cadre { position: absolute; border: 2px solid #6c757d; border-radius: 10px; pointer-events: none; }
.gr-cadre.choisi { box-shadow: 0 0 0 3px rgba(0,123,255,.45); }
.gr-cadre-titre { position: absolute; left: 8px; top: -14px; max-width: calc(100% - 16px); padding: 2px 10px; border-radius: 8px; font-weight: 700; font-size: 14px;
	white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: move; pointer-events: auto; user-select: none; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.gr-cadre-coin { position: absolute; right: -7px; bottom: -7px; width: 14px; height: 14px; border-radius: 3px; background: #adb5bd; border: 1px solid #6c757d; cursor: nwse-resize; pointer-events: auto; }
.gr-cadre.choisi .gr-cadre-coin, .gr-cadre:hover .gr-cadre-coin { background: #007bff; border-color: #0056b3; }

/* Reperes d'alignement */
.gr-guide { stroke: #e83e8c; stroke-dasharray: 4 3; pointer-events: none; }

/* Mini-carte */
.gr-minicarte { position: absolute; left: 10px; bottom: 10px; z-index: 3; width: 200px; height: 130px; border: 1px solid #ced4da; border-radius: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.15); cursor: pointer; touch-action: none; }
@media (max-width: 575px) { .gr-minicarte { width: 140px; height: 91px; } }

/* Bulle : description en texte enrichi et lien */
.gr-bulle { white-space: normal; }
.gr-bulle-lien { display: block; margin-bottom: 6px; font-size: .85rem; word-break: break-all; }
.gr-bulle-desc ul, .gr-bulle-desc ol { margin: 0 0 .3em; padding-left: 1.3em; }
.gr-bulle-desc p { margin: 0 0 .4em; }

/* Panneau */
.gr-etiquette { display: block; font-size: .9rem; margin-bottom: 2px; }
.gr-formes .btn { font-size: 1rem; line-height: 1; padding: .3rem .45rem; }
.gr-icone-btn { min-width: 4em; font-size: 1rem; }
.gr-icones { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; margin-bottom: 8px; padding: 4px; border: 1px solid #dee2e6; border-radius: 8px; }
.gr-icones button { border: 0; background: none; font-size: 1.15rem; padding: 2px; border-radius: 6px; cursor: pointer; }
.gr-icones button:hover { background: #e9ecef; }
.gr-select { width: auto; flex: 1 1 auto; }
.gr-desc-outils { margin-bottom: 4px; flex-wrap: wrap; }
.gr-desc { height: auto; min-height: 5.5em; max-height: 14em; overflow: auto; white-space: normal; }
.gr-desc:focus { outline: none; }
.gr-desc ul, .gr-desc ol { margin: 0; padding-left: 1.3em; }

/* ===================== Theme sombre ===================== */
body.gr-sombre .gr-app { background: #1e2227; }
body.gr-sombre .gr-barre { background: #2b3035; border-bottom-color: #3a4048; }
body.gr-sombre .gr-logo { color: #e9ecef; }
body.gr-sombre .gr-barre .form-control { background: #1e2227; color: #e9ecef; border-color: #495057; }
body.gr-sombre .gr-barre .btn-outline-secondary { color: #ced4da; border-color: #6c757d; }
body.gr-sombre .gr-barre .btn-outline-secondary:hover, body.gr-sombre .gr-barre .btn.active { color: #fff; background: #6c757d; }
body.gr-sombre .gr-groupe { border-left-color: #3a4048; }
body.gr-sombre .gr-zone { background-color: #1e2227; background-image: radial-gradient(circle, #3a4048 1px, transparent 1.2px); }
body.gr-sombre .gr-lien-nom-fond { fill: #2b3035; stroke: #495057; }
body.gr-sombre .gr-lien-nom { fill: #e9ecef; }
body.gr-sombre .gr-card { fill: #e9ecef; stroke: #1e2227; }
body.gr-sombre .gr-card-bulle { background: #f8f9fa; color: #212529; }
body.gr-sombre .gr-panneau { background: #2b3035; color: #e9ecef; border-color: #3a4048; }
body.gr-sombre .gr-panneau .form-control, body.gr-sombre .gr-panneau .custom-select { background: #1e2227; color: #e9ecef; border-color: #495057; }
body.gr-sombre .gr-panneau .close { color: #e9ecef; }
body.gr-sombre .gr-panneau .text-muted { color: #adb5bd !important; }
body.gr-sombre .gr-bulle { background: #343a40; color: #f8f9fa; border-color: #495057; }
body.gr-sombre .gr-bulle a { color: #8ec5ff; }
body.gr-sombre .gr-vide { color: #adb5bd; }
body.gr-sombre .gr-minicarte { border-color: #495057; }
body.gr-sombre .gr-icones { border-color: #495057; }
body.gr-sombre .gr-icones button:hover { background: #495057; }

/* Lecture seule (graph/voir.php) */
.gr-titre-lecture { font-weight: 700; font-size: 1.05rem; color: #343a40; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.gr-sombre .gr-titre-lecture { color: #e9ecef; }
.graph-lecture .gr-noeud { cursor: pointer; }
