/* ====== Base ====== */
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

:root {
  /* Ajuster selon la nouvelle taille réduite des barres */
  --topbar-h: 56px;      /* Hauteur de la barre sticky (.topbar) */
  --pageheader-h: 44px;  /* Hauteur réduite de la .page-header */
}

/* ====== Header page simplifié ====== */
.page-header {
  padding: 8px 20px 12px; /* Réduction du padding vertical */
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: relative;
  z-index: 5;
}

.page-header h1 {
  margin: 0 0 4px 0; /* Réduction de la marge */
  font-size: 24px;
  font-weight: 700;
  color: #1f2937;
}

.subtitle {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
  line-height: 1.4;
}

/* ====== Layout principal ====== */
.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 420px;
  gap: 16px;
  padding: 16px;
}

.sidebar {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
}

/* ====== Panneau graphe ====== */
.graph-panel {
  position: relative;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  /* évite le clipping du panneau flottant */
  overflow: visible;
}

/* ====== NOUVEAU: Contrôles du graphe ====== */
.graph-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 15; /* Réduire pour éviter conflit avec nodePanel z-index: 20 */
  display: flex;
  gap: 8px;
}

.control-btn {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s ease;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 1);
  border-color: #2563eb;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.control-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.fullscreen-icon {
  font-size: 18px;
  display: inline-block;
}

/* ====== Graphe Cytoscape ====== */
#cy {
  /* Hauteur quasi plein écran : viewport - topbar - header - marge */
  height: calc(100svh - var(--topbar-h, 56px) - var(--pageheader-h, 44px) - 24px);
  min-height: 720px; /* plancher confortable */
  border-radius: 12px;
}

/* ====== NOUVEAU: Mode plein écran ====== */
.fullscreen-mode {
  overflow: hidden;
}

.fullscreen-mode .topbar,
.fullscreen-mode .page-header,
.fullscreen-mode .sidebar,
.fullscreen-mode .matrix-panel,
.fullscreen-mode .page-footer {
  display: none !important;
}

.fullscreen-mode .layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  grid-template-columns: 1fr;
  padding: 0;
  margin: 0;
  gap: 0;
}

.fullscreen-mode .graph-panel {
  border-radius: 0;
  border: none;
}

.fullscreen-mode #cy {
  height: 100vh;
  border-radius: 0;
}

.fullscreen-mode .graph-controls {
  top: 20px;
  right: 20px;
}

/* ====== Panneau info nœud ====== */
#nodePanel {
  position: absolute;       /* relatif à .graph-panel (desktop) */
  right: 12px;
  top: 12px;
  width: 340px;
  max-height: calc(100svh - 24px); /* évite d'être tronqué en bas */
  overflow: auto;           /* scroll interne si contenu long */
  z-index: 20;              /* au-dessus du canvas Cytoscape */
  background: #fffffff2;
  backdrop-filter: blur(6px);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.12);
}

.fullscreen-mode #nodePanel {
  top: 80px;
  right: 20px;
}

#closePanel {
  position: absolute;
  top: 6px;
  right: 8px;
  border: 0;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

/* ====== NOUVEAU: Matrice avec contrôles améliorés ====== */
.matrix-panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
  max-width: 100%;
  overflow: auto;
  transition: all 0.3s ease;
  resize: vertical; /* Permettre le redimensionnement vertical natif par défaut */
  min-height: 150px;
}

/* Désactiver le resize quand un mode spécifique est actif */
.matrix-panel.matrix-compact,
.matrix-panel.matrix-medium,
.matrix-panel.matrix-expanded,
.matrix-panel.matrix-collapsed {
  resize: none;
}

.matrix-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 8px;
}

.matrix-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
}

.matrix-controls {
  display: flex;
  gap: 4px;
}

.matrix-controls .control-btn {
  padding: 4px 8px;
  font-size: 14px;
  min-width: 28px;
  text-align: center;
  position: relative;
}

/* États actifs des boutons de matrice */
.matrix-panel:not(.matrix-compact):not(.matrix-medium):not(.matrix-expanded):not(.matrix-collapsed) #normalMatrix,
.matrix-panel.matrix-compact #compactMatrix,
.matrix-panel.matrix-medium #mediumMatrix,
.matrix-panel.matrix-expanded #expandMatrix,
.matrix-panel.matrix-collapsed #collapseMatrix {
  background: #dbeafe;
  border-color: #2563eb;
  color: #1d4ed8;
}

/* Contenu des icônes des boutons */
#normalMatrix { font-size: 14px; }
#normalMatrix::after { content: "⋮⋮"; }

#compactMatrix { font-size: 16px; }
#compactMatrix::after { content: "≡"; }

#mediumMatrix { font-size: 16px; }
#mediumMatrix::after { content: "☰"; }

#expandMatrix { font-size: 14px; }
#expandMatrix::after { content: "□"; }

#collapseMatrix { font-size: 14px; }
#collapseMatrix::after { content: "▲"; }
.matrix-panel.matrix-collapsed #collapseMatrix::after { content: "▼"; }

/* États de la matrice améliorés */
.matrix-panel.matrix-compact {
  height: 200px !important;
  overflow-y: auto;
  resize: none;
}

.matrix-panel.matrix-medium {
  height: 350px !important;
  overflow-y: auto;
  resize: none;
}

.matrix-panel.matrix-expanded {
  position: fixed !important;
  top: 80px;
  left: 20px;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-height: none;
  height: auto !important;
  background: #fff;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  resize: none;
}

.matrix-panel.matrix-collapsed {
  height: 60px !important;
  overflow: hidden;
  resize: none;
}

.matrix-panel.matrix-collapsed .matrix {
  display: none;
}

.matrix-panel.matrix-collapsed .matrix-header {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

/* ====== Matrice / tableaux ====== */
.matrix {
  transition: all 0.3s ease;
}

table { 
  width: 100%; 
  border-collapse: collapse; 
  font-size: 14px; 
}
th, td { 
  border-bottom: 1px solid #e5e7eb; 
  padding: 8px 6px; 
  text-align: left; 
}
tr { 
  cursor: pointer; 
}
tr:hover { 
  background: #f8fafc; 
}

/* ====== Filtres, légendes, pills ====== */
.filters label { display: block; margin: 6px 0; }
.density { margin: 12px 0; }

.legend .pill {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 6px;
  margin-right: 6px;
  vertical-align: middle;
}

.pill-config{background:#1d4ed8}
.pill-threshold{background:#6b7280}
.pill-domain{background:#15803d}
.pill-mechanism{background:#ea580c}
.pill-vector{background:#6d28d9}
.pill-example{background:#7e22ce}
.pill-lever{background:#0891b2}
.pill-author{background:#334155}
.pill-stakeholder{background:#475569}

/* ====== NOUVEAU: Note sur le modèle déroulante ====== */
.model-note-section {
  margin-top: 20px;
}

.model-note-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.model-note-toggle:hover {
  color: #2563eb;
}

.model-note-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}

.model-note-arrow {
  font-size: 12px;
  transition: transform 0.2s ease;
}

.model-note-toggle[aria-expanded="true"] .model-note-arrow {
  transform: rotate(180deg);
}

.model-note-content {
  margin-top: 12px;
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  background: #f8fafc;
  transition: all 0.3s ease;
  font-size: 14px;
  line-height: 1.6;
}

.model-note-content[hidden] {
  display: none !important;
}

.model-note-content p {
  margin: 0 0 12px 0;
}

.model-note-content p:last-child {
  margin-bottom: 0;
}

/* ====== NOUVEAU: Menu références ====== */
.refs-section {
  margin-top: 20px;
}

.refs-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
  cursor: pointer;
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.refs-toggle:hover {
  color: #2563eb;
}

.refs-toggle:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}

.refs-arrow {
  font-size: 12px;
  transition: transform 0.2s ease;
}

.refs-toggle[aria-expanded="true"] .refs-arrow {
  transform: rotate(180deg);
}

.refs-content {
  margin-top: 12px;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  transition: all 0.3s ease;
}

.refs-content[hidden] {
  display: none !important;
}

.refs-content h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
  font-weight: 600;
  color: #374151;
}

.refs-content ul {
  margin: 0 0 16px 0;
  padding: 0;
  list-style: none;
}

.refs-content li {
  margin: 4px 0;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
}

.refs-content li:hover {
  background: #e5e7eb;
}

.refs-content li:focus {
  background: #dbeafe;
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

/* ====== Bouton Réinitialiser la vue ====== */
#resetView{
  display:block;
  width:100%;
  padding:10px 12px;
  border:1px solid #1f2937;      /* contraste AA */
  border-radius:10px;
  background:#ffffff;
  color:#1f2937;
  font-weight:600;
  cursor:pointer;
}
#resetView:hover{ background:#f3f4f6; }
#resetView:focus-visible{
  outline:2px solid #1d4ed8;
  outline-offset:2px;
}
#resetView:active{ transform: translateY(1px); }

/* ====== Topbar site ====== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 1000; /* au-dessus du graphe/panneaux */
  background: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

.topbar__container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.topbar__brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  min-height: 44px; /* bon alignement */
}

/* Taille du logo bornée et responsive */
.topbar__logo{
  display: block;
  height: clamp(28px, 6vw, 40px);  /* pas <28px, pas >40px */
  width: auto;
  max-width: 220px;                /* sécurité si ratio atypique */
  object-fit: contain;             /* ne pas déformer */
}

/* Nav desktop */
.topbar__nav {
  display: none; /* caché par défaut (mobile) */
  gap: 20px;
  justify-content: flex-end;
  align-items: center;
}
.topbar__link {
  color: #374151; text-decoration: none; font-weight: 500; font-size: 14px;
}
.topbar__link:hover { color: #2563eb; }
.topbar__link--primary { font-weight: 700; }
.topbar__link--active { color: #2563eb; }

/* Bouton menu mobile */
.topbar__menu-btn {
  justify-self: end;
  border: none; background: transparent; cursor: pointer;
  width: 40px; height: 40px; border-radius: 8px;
}
.topbar__menu-btn:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.topbar__menu-icon,
.topbar__menu-icon::before,
.topbar__menu-icon::after {
  content: ""; display: block; width: 22px; height: 2px; background: #374151; margin: 5px auto;
  border-radius: 1px;
}

/* Menu mobile */
.topbar__mobile {
  padding: 8px 16px 16px 16px;
  border-top: 1px solid rgba(0,0,0,0.06);
  background: #fff;
}
.topbar__mobile[hidden] { display: none !important; }
.topbar__mobile-link {
  display: block; padding: 10px 8px; text-decoration: none; color: #374151; font-weight: 500; font-size: 14px;
}
.topbar__mobile-link:hover { color: #2563eb; }
.topbar__mobile-link--primary { font-weight: 700; }
.topbar__mobile-link--active { color: #2563eb; }

/* ====== Responsive ====== */
@media (min-width: 960px) {
  .topbar__menu-btn { display: none; }
  .topbar__nav { display: inline-flex; }
  .topbar__mobile { display: none !important; }
}

@media (max-width: 1280px) {
  .layout { grid-template-columns: 240px minmax(0, 1fr) 360px; }
}

@media (max-width: 1100px) {
  .layout { 
    grid-template-columns: 1fr; 
    grid-template-rows: auto auto auto;
  }
  .sidebar { 
    order: 1; 
    grid-row: 1;
  }
  .graph-panel { 
    order: 2; 
    overflow: visible; 
    grid-row: 2;
  }
  .matrix-panel { 
    order: 3; 
    grid-column: 1; 
    grid-row: 3;
  }

  #nodePanel {
    position: fixed;      /* bottom-sheet */
    right: 10px;
    left: 10px;
    bottom: 10px;
    top: auto;
    width: auto;
    max-height: 65svh;
    overflow: auto;
    z-index: 25; /* Assurer qu'il reste au-dessus en mobile */
  }

  .graph-controls {
    top: 8px;
    right: 8px;
    z-index: 16; /* Maintenir sous le panneau de nœud */
  }

  .control-btn {
    padding: 6px 10px;
    font-size: 14px;
  }

  /* Adaptation mobile pour les références */
  .refs-content {
    max-height: 200px;
  }

  /* Adaptation mobile pour la matrice améliorée */
  .matrix-panel.matrix-expanded {
    top: 60px;
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .matrix-panel.matrix-medium {
    height: 250px !important;
  }

  .matrix-panel.matrix-compact {
    height: 150px !important;
  }

  /* Adaptation mobile pour la note sur le modèle */
  .model-note-content {
    max-height: 200px;
    padding: 12px;
  }

  /* Adaptation mobile pour les contrôles de matrice */
  .matrix-controls {
    gap: 2px;
    flex-wrap: wrap;
  }

  .matrix-controls .control-btn {
    padding: 3px 6px;
    font-size: 12px;
    min-width: 24px;
  }
}

/* ====== Utilitaire accessibilité ====== */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 1px, 1px); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
  width: auto;
  height: auto;
  padding: 8px 12px;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  z-index: 1001;
  text-decoration: none;
}

/* ====== Animations et transitions ====== */
@media (prefers-reduced-motion: no-preference) {
  .matrix-panel,
  .refs-content,
  .control-btn,
  .graph-controls,
  .refs-arrow {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .matrix-panel {
    transition: height 0.3s ease, max-height 0.3s ease, opacity 0.2s ease;
  }

  .refs-arrow {
    transition: transform 0.2s ease;
  }
}

/* Respecter les préférences de mouvement réduit */
@media (prefers-reduced-motion: reduce) {
  .matrix-panel,
  .refs-content,
  .control-btn,
  .graph-controls,
  .refs-arrow {
    transition: none;
  }
}

/* ====== Améliorations visuelles ====== */
.error-banner {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #dc2626;
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  z-index: 10000;
  max-width: 90%;
  text-align: center;
}

/* Focus visible amélioré */
*:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}

/* Amélioration du style des liens */
.link-like {
  background: none;
  border: none;
  color: #2563eb;
  cursor: pointer;
  text-decoration: underline;
  font: inherit;
}

.link-like:hover {
  color: #1d4ed8;
}