:root {
  --bg-deep: #05050d;
  --bg-mid: #0c0c1e;
  --text: #ecedf5;
  --text-dim: #7a7a95;
}

/* La page graphs s'intègre dans global_base.html: le navbar Bootstrap reste en haut,
   et tout le rendu interactif (chrome + SVG) est confiné dans .graph-stage. */
.graph-stage {
  position: relative;
  width: 100%;
  /* --nav-height est défini en JS au chargement et au resize (fallback 80px).
     100dvh (dynamic viewport height) prend en compte la barre d'outils Safari
     qui apparaît / disparaît sur iOS, donc les contrôles en bas restent visibles. */
  height: calc(100dvh - var(--nav-height, 80px));
  min-height: 420px;
  overflow: hidden;
  border-radius: 14px;
  color: var(--text);
  font-family: 'Inter', 'SF Pro Display', -apple-system, system-ui, sans-serif;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 184, 69, 0.08), transparent 35%),
    radial-gradient(ellipse 60% 50% at 20% 80%, rgba(78, 201, 255, 0.05), transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(199, 125, 255, 0.05), transparent 60%),
    radial-gradient(ellipse 50% 40% at 50% 15%, rgba(125, 255, 142, 0.04), transparent 60%),
    radial-gradient(ellipse at center, var(--bg-mid) 0%, var(--bg-deep) 70%);
}
.graph-stage * { box-sizing: border-box; margin: 0; padding: 0; }
.graph-stage::before {
  content: '';
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.012) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.012) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.nav-menu {
  position: absolute; top: 28px; left: 32px; z-index: 11;
}
.nav-menu summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: inline-flex; align-items: center;
}
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-btn::after {
  content: '\25BE';
  margin-left: 10px;
  font-size: 10px;
  opacity: 0.6;
  transition: transform 0.2s ease;
}
.nav-menu[open] .nav-btn::after {
  transform: rotate(180deg);
}
.nav-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  min-width: 280px;
  padding: 14px;
  background: rgba(8, 8, 22, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  display: flex; flex-direction: column; gap: 4px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
}
.nav-title {
  font-size: 10px; font-weight: 600; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--text-dim);
  padding: 4px 10px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 6px;
}
.nav-item {
  position: relative;
  display: flex; flex-direction: column; gap: 3px;
  padding: 10px 12px;
  border-radius: 9px;
  text-decoration: none;
  color: var(--text);
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}
a.nav-item:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.08);
}
.nav-item.current {
  background: rgba(255, 184, 69, 0.08);
  border-color: rgba(255, 184, 69, 0.25);
}
.nav-item-eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--text-dim);
}
.nav-item-title {
  font-size: 14px; font-weight: 400;
}
.nav-item-title strong { color: #FFB845; font-weight: 600; }
.header {
  position: absolute; top: 84px; left: 32px; z-index: 10;
  pointer-events: none;
}
.header .eyebrow {
  font-size: 11px; font-weight: 600; letter-spacing: 0.25em;
  text-transform: uppercase; color: var(--text-dim);
}
.header h1 {
  font-size: 11px; font-weight: 600; letter-spacing: 0.04em;
  margin-top: 4px; color: var(--text);
  text-transform: uppercase;
}
.header h1 strong { font-weight: 700; color: #FFB845; }
.header .sub {
  font-size: 12px; color: var(--text-dim);
  margin-top: 6px; max-width: 380px; line-height: 1.5;
}

.legend {
  position: absolute; top: 28px; right: 32px; z-index: 11;
}
.legend summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: inline-flex; align-items: center;
}
.legend summary::-webkit-details-marker { display: none; }
.legend-btn::after {
  content: '\25BE';
  margin-left: 10px;
  font-size: 10px;
  opacity: 0.6;
  transition: transform 0.2s ease;
}
.legend[open] .legend-btn::after {
  transform: rotate(180deg);
}
.legend-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 14px 18px;
  background: rgba(8, 8, 22, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55);
  font-size: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.legend-item { display: flex; align-items: center; gap: 12px; }
.legend-dot {
  width: 10px; height: 10px; border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 10px currentColor, 0 0 20px currentColor;
}
.legend-label { color: var(--text); }

.controls {
  position: absolute; bottom: 28px; left: 32px; z-index: 10;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.btn {
  padding: 10px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s ease;
}
.btn:hover {
  background: rgba(255,255,255,0.09);
  border-color: rgba(255,255,255,0.14);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }

.btn-group {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  margin-left: 4px;
}
.btn-group .btn {
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 14px;
  color: var(--text-dim);
}
.btn-group .btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text);
  transform: none;
  border-color: transparent;
}
.btn-group .btn.active {
  background: rgba(255, 184, 69, 0.14);
  border-color: rgba(255, 184, 69, 0.35);
  color: #FFB845;
}

.tooltip {
  position: fixed; pointer-events: none;
  padding: 12px 16px;
  background: rgba(5, 5, 13, 0.92);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  font-size: 13px;
  max-width: 320px;
  opacity: 0;
  transition: opacity 0.15s ease;
  backdrop-filter: blur(12px);
  z-index: 100;
  line-height: 1.55;
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.tooltip .tt-name {
  font-weight: 600; font-size: 14px;
  display: block; margin-bottom: 4px;
}
.tooltip .tt-desc { color: var(--text-dim); font-size: 12px; }

.preview {
  position: fixed;
  pointer-events: none;
  width: 360px;
  background: rgba(5, 5, 13, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 14px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  z-index: 110;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}
.preview.visible {
  opacity: 1;
  transform: translateY(0);
}
.preview .pv-body { padding: 16px 18px; }
.preview .pv-eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.preview .pv-favicon {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex-shrink: 0;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.06);
  object-fit: contain;
}
.preview .pv-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.35;
}
.preview .pv-desc {
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.preview .pv-desc.pv-loading { font-style: italic; opacity: 0.7; }
.preview .pv-note {
  font-size: 11px;
  color: #ffb845;
  opacity: 0.85;
  margin-bottom: 10px;
}
.preview .pv-hint {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-dim);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding-top: 10px;
}

svg { width: 100%; height: 100%; display: block; cursor: grab; position: relative; z-index: 1; }
svg:active { cursor: grabbing; }

.ring {
  fill: none;
  stroke: rgba(255, 255, 255, 0.04);
  stroke-dasharray: 2 7;
}

.link {
  fill: none;
  stroke-opacity: 0.4;
  stroke-linecap: round;
  transition: stroke-opacity 0.25s ease, stroke-width 0.25s ease;
}
.link.dim { stroke-opacity: 0.06; }
.link.highlight { stroke-opacity: 0.95; stroke-width: 2.5; }

.node-group circle.node-halo { transition: opacity 0.25s ease; }
.node-group circle.node-ring-circle { transition: opacity 0.25s ease, stroke-width 0.25s ease; cursor: pointer; }
.node-group circle.node-core { transition: opacity 0.25s ease; pointer-events: none; }
.node-group text {
  font-size: 12.5px; font-weight: 500;
  fill: var(--text);
  pointer-events: none;
  transition: opacity 0.25s ease;
  paint-order: stroke;
  stroke: rgba(5,5,13,0.9);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}
.node-group.dim circle.node-halo,
.node-group.dim circle.node-core,
.node-group.dim text { opacity: 0.15; }
.node-group.dim circle.node-ring-circle { opacity: 0.2; }

.node-group.highlight circle.node-ring-circle { stroke-width: 3.5px; }

.footer {
  position: absolute; bottom: 28px; right: 32px; z-index: 10;
  font-size: 11px; color: var(--text-dim);
  pointer-events: none;
  letter-spacing: 0.05em;
}

/* --- Tablet et mobile (< 992px) --- */
/* Le navbar global passe en mode flottant sous lg: le logo (~40px) et le
   hamburger sont fixed dans les coins du viewport. On pousse les chips du
   graph (nav-menu à gauche, legend à droite) sous cette bande pour ne pas
   se chevaucher. */
@media (max-width: 991.98px) {
  .nav-menu { top: 56px; left: 12px; }
  .header { top: 100px; }
  .legend { top: 56px; right: 12px; }
  /* La série Radial / Vertical / Horizontal est masquée: le JS choisit
     automatiquement entre lr (portrait) et tb (landscape). */
  .layout-group { display: none; }
}

/* --- Mobile (< 768px) --- */
@media (max-width: 768px) {
  .nav-menu { top: 56px; left: 10px; }
  .nav-btn { padding: 7px 11px; font-size: 11px; }
  .nav-panel {
    min-width: 240px;
    max-width: calc(100vw - 20px);
  }
  .nav-item-title { font-size: 13px; }

  .header { top: 100px; left: 10px; right: 10px; }
  .header .eyebrow { font-size: 10px; letter-spacing: 0.2em; }
  .header h1 { font-size: 11px; }
  .header .sub { font-size: 11px; max-width: none; line-height: 1.4; }

  .legend { top: 56px; right: 10px; }
  .legend-btn { padding: 7px 11px; font-size: 11px; }
  .legend-panel {
    min-width: 200px;
    max-width: calc(100vw - 20px);
    max-height: 50vh;
    font-size: 11px;
    padding: 12px 14px;
    gap: 8px;
  }

  .controls {
    bottom: 10px; left: 10px; right: 10px;
    gap: 5px;
  }
  .controls .btn { padding: 6px 10px; font-size: 11px; }
  .btn-group { padding: 2px; }
  .btn-group .btn { padding: 5px 8px; font-size: 10px; }

  .preview { width: calc(100vw - 20px); max-width: 360px; }

  .footer { display: none; }
}
