/* =============================================================================
   CONVENTION.CSS — Page detail : synthese d'une convention
   ============================================================================= */

/* ===== LAYOUT PRINCIPAL ===== */
/* Forcer un layout contenu dans le viewport pour empecher
   le parent iframe de gonfler la hauteur a 200000px.
   Le scroll se fait a l'interieur de .content-scroll uniquement. */
html.page-convention,
html.page-convention body {
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Zone contenu + sidebar cote a cote */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ===== SIDEBAR (DROITE) ===== */
.sidebar {
  width: 290px;
  flex-shrink: 0;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease;
  z-index: 30;
}

/* Recherche sidebar */
.sidebar-search {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
}
.sidebar-search input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
}
.sidebar-search input:focus {
  outline: none;
  border-color: var(--accent);
}
.sidebar-search input::placeholder {
  color: var(--text3);
}

/* Navigation sidebar */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-group {
  margin-bottom: 2px;
}
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}
.nav-group-header:hover {
  background: var(--bg);
}
.nav-group-header .icon {
  font-size: 14px;
  flex-shrink: 0;
}
.nav-group-header .label {
  flex: 1;
  min-width: 0;
}
.nav-group-header .chevron {
  font-size: 10px;
  color: var(--text3);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
.nav-group.open .chevron {
  transform: rotate(180deg);
}
.nav-group-header .num {
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
  min-width: 18px;
}

.nav-children {
  display: none;
  padding-bottom: 4px;
}
.nav-group.open .nav-children {
  display: block;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 16px 5px 32px;
  font-size: 12px;
  color: var(--text2);
  cursor: pointer;
  transition: all var(--transition);
  border-right: 2px solid transparent;
}
.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent-dark);
  border-right-color: var(--accent);
  font-weight: 500;
}
.nav-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.nav-item .dot.empty {
  background: var(--border);
}
.nav-item .nav-num {
  color: var(--text3);
  font-size: 11px;
  min-width: 26px;
  font-weight: 500;
}
.nav-item .nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== ZONE PRINCIPALE ===== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Barre d'actions (pleine largeur, fixee en haut du layout flex) */
.action-bar {
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 40;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.action-bar-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.action-btns {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Zone de scroll — seul element qui scrolle */
.content-scroll {
  flex: 1;
  padding: 24px;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ===== GROUPES ET SECTIONS ===== */
.section-group {
  margin-bottom: 36px;
}
.group-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 8px;
  border-bottom: 3px solid var(--accent);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.group-title .group-num {
  color: var(--accent);
  font-weight: 700;
  min-width: 28px;
}
.group-title .group-icon {
  font-size: 20px;
}

.section-block {
  margin-bottom: 28px;
  scroll-margin-top: 16px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title .sec-num {
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  min-width: 32px;
}

/* ===== BOUTON MOBILE ===== */
.mobile-toc-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 60;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  transition: transform var(--transition);
}
.mobile-toc-toggle:hover {
  transform: scale(1.1);
}

/* Overlay mobile */
.toc-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 45;
}
.toc-overlay.visible {
  display: block;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  .app-body {
    margin-right: 0; /* pas de sidebar visible en mobile */
  }
  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100vh;
    transform: translateX(100%);
    z-index: 50;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .mobile-toc-toggle {
    display: flex;
  }
  .content-scroll {
    padding: 16px;
  }
  .action-bar {
    padding: 10px 16px;
  }
  .action-bar-title {
    font-size: 13px;
  }
}

/* ===== PRINT ===== */
@media print {
  /* === APPROCHE RADICALE : #app est cache, #print-wrapper est affiche === */
  #app {
    display: none !important;
  }
  #print-wrapper {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }
  html, body {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    font-size: 10px !important;
  }
  .sidebar,
  .action-bar,
  .mobile-toc-toggle,
  .toc-overlay,
  .btn-compare,
  .compare-panel {
    display: none !important;
  }

  /* --- Marges reduites --- */
  @page {
    margin: 10mm 10mm 10mm 10mm;
  }
  .print-page-footer {
    display: none !important;
  }
  .content-scroll {
    padding: 4px !important;
  }

  /* --- Coupures de page --- */
  .section-group {
    page-break-inside: auto;
  }
  .group-title {
    page-break-after: avoid;
    font-size: 13px !important;
    padding-bottom: 4px !important;
    margin-bottom: 8px !important;
  }
  .section-block {
    margin-bottom: 12px !important;
  }
  .section-title {
    page-break-after: avoid;
    font-size: 11px !important;
    margin-bottom: 4px !important;
    padding-bottom: 2px !important;
  }
  /* Cartes et articles insecables */
  .content-card {
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 6px !important;
    padding: 6px 8px !important;
  }
  .articles-block {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  /* Tableaux : insecables, pas de coupure entre 2 pages */
  .content-body table {
    page-break-inside: avoid;
    break-inside: avoid;
    font-size: 9px !important;
  }
  .content-body thead th {
    padding: 4px 6px !important;
    font-size: 8.5px !important;
  }
  .content-body td {
    padding: 3px 6px !important;
    font-size: 9px !important;
  }

  /* --- Polices reduites pour le contenu --- */
  .content-theme {
    font-size: 11px !important;
    margin-bottom: 4px !important;
  }
  .content-body {
    font-size: 10.5px !important;
    line-height: 1.5 !important;
  }
  .content-body p {
    margin-bottom: 3px !important;
  }
  .articles-title {
    font-size: 10px !important;
  }
  .article-item {
    font-size: 9px !important;
    padding: 2px 6px !important;
  }
  .sec-num {
    font-size: 11px !important;
  }

  /* Page de garde pour impression */
  .print-cover {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 90vh;
    text-align: center;
    page-break-after: always;
  }

  /* Table des matieres pour impression — 1 page, 2 colonnes */
  .print-toc {
    display: block !important;
    page-break-after: always;
    page-break-inside: avoid;
    padding: 30px 20px;
  }
  .print-toc-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e2028;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 3px solid #42D80F;
  }
  .print-toc-list {
    columns: 2;
    column-gap: 30px;
  }
  .print-toc-group {
    margin-bottom: 4px;
    break-inside: avoid;
  }
  .print-toc-group-link {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 5px 0 2px;
    text-decoration: none;
    color: #1e2028;
    font-weight: 600;
    font-size: 11.5px;
    border-bottom: 1px solid #e5e7ec;
  }
  .print-toc-num {
    color: #42D80F;
    font-weight: 700;
    min-width: 18px;
  }
  .print-toc-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 1px 0 1px 20px;
    text-decoration: none;
    color: #4a4e5a;
    font-size: 10px;
  }
  .print-toc-sub-num {
    color: #7a7e8a;
    min-width: 24px;
    font-size: 9.5px;
  }
  .print-toc-sub-label {
    flex: 1;
  }
}

/* Cacher la page de garde, TdM et footer pagination en mode ecran */
.print-cover,
.print-toc,
.print-page-footer {
  display: none;
}
