/* ── Base ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

.bulletin-body {
  margin: 0;
  background: #d6dde5;
  font-family: "Times New Roman", Georgia, serif;
  color: #111;
}

/* ── Barre d'outils ────────────────────────────────────────────────────────── */
.bulletin-toolbar {
  background: #fff;
  border-bottom: 1px solid #ccc;
  position: sticky;
  top: 0;
  z-index: 100;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.82rem;
}
.toolbar-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
}
.btn-back {
  text-decoration: none;
  color: #444;
  border: 1px solid #bbb;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.78rem;
  white-space: nowrap;
}
.toolbar-selectors { display: flex; gap: 12px; }
.toolbar-selectors label { display: flex; align-items: center; gap: 5px; color: #555; }
.toolbar-selectors select { font-size: 0.82rem; padding: 2px 4px; border: 1px solid #ccc; border-radius: 3px; }
.bulletin-status-pill {
  background: #1a7a3c;
  color: #fff;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.btn-print {
  margin-left: auto;
  background: #1a7a3c;
  color: #fff;
  border: none;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}
.btn-print:hover { background: #155f30; }

/* ── Pages ─────────────────────────────────────────────────────────────────── */
#bulletin-root {
  max-width: 960px;
  margin: 20px auto 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.bpage {
  background: #fff;
  padding: 22px 30px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  font-size: 0.72rem;
  line-height: 1.4;
  position: relative;
}

.page-number {
  position: absolute;
  bottom: 10px;
  right: 16px;
  font-size: 0.65rem;
  font-family: Arial, sans-serif;
  color: #888;
}

/* ── Masthead ───────────────────────────────────────────────────────────────── */
.masthead {
  width: 100%;
  border: 3px double #1a7a3c;
  border-collapse: collapse;
  margin-bottom: 8px;
}
.masthead td {
  vertical-align: middle;
  padding: 8px 10px;
  text-align: center;
  line-height: 1.5;
}
.mh-left  { width: 38%; border-right: 1px solid #1a7a3c; text-align: center; vertical-align: middle; }
.mh-right { width: 28%; border-left:  1px solid #1a7a3c; text-align: center; vertical-align: top; padding-top: 12px; }
.mh-center { width: 34%; }
.mh-bold  { font-weight: 700; }
.mh-line  { font-size: 0.7rem; }
.mh-sep   { color: #1a7a3c; font-size: 0.6rem; letter-spacing: -1px; }

/* Emblème Gabon simplifié */
.gabon-emblem { text-align: center; }
.emblem-flag  { width: 72px; height: 48px; margin: 0 auto 4px; border: 1px solid #999; display: flex; flex-direction: column; }
.flag-green   { flex: 1; background: #009e49; }
.flag-yellow  { flex: 1; background: #fcd116; }
.flag-blue    { flex: 1; background: #3a75c4; }
.emblem-text  { font-size: 0.6rem; font-weight: 700; }
.emblem-sub   { font-size: 0.58rem; color: #555; }

/* ── Titre publication ─────────────────────────────────────────────────────── */
.pub-title {
  border: 2px solid #1a7a3c;
  text-align: center;
  padding: 7px 10px;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.pub-title-main { font-weight: 700; font-size: 0.82rem; }
.pub-title-sub  { font-weight: 700; font-size: 0.78rem; margin-top: 2px; }

/* ── Avertissement ─────────────────────────────────────────────────────────── */
.avertissement {
  border: 1px solid #888;
  padding: 8px 12px;
  margin-bottom: 12px;
  text-align: justify;
}
.avert-title { font-weight: 700; text-align: center; font-size: 0.75rem; margin-bottom: 6px; }
.avertissement p { margin: 0 0 5px; font-size: 0.68rem; }

/* ── Tables de données ─────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border: 3px double #1a7a3c;
  border-collapse: collapse;
  margin-bottom: 4px;
}
.data-table th,
.data-table td {
  border: 1px solid #1a7a3c;
  padding: 2px 4px;
  text-align: center;
  vertical-align: middle;
}
.data-table .thead-top th { background: #dff0e8; font-weight: 700; font-size: 0.68rem; }
.data-table .thead-months th { background: #eaf5ee; font-size: 0.67rem; font-weight: 700; }
.data-table .grp-head { font-weight: 700; }

.col-code   { text-align: left; width: 32px; font-weight: 700; }
.col-label  { text-align: left; }
.col-pond   { width: 52px; }
.col-idx    { width: 48px; }
.col-m      { background: #fffde8; font-weight: 700; }
.col-var    { width: 44px; }
.col-group  { text-align: left; font-weight: 700; }
.col-cat    { text-align: left; }
.col-reg    { width: 60px; }
.col-product { text-align: left; }
.col-unit   { width: 38px; }

/* Lignes */
.row-total td { font-weight: 700; background: #fdf8e1; }
.row-main  td { font-weight: 700; }
.row-sec   td { font-weight: 400; }
.row-contrib td { font-style: italic; font-size: 0.67rem; }

.var-pos { color: #1a6e1a; }
.var-neg { color: #b30000; }

/* Sous-lignes de détail (01xx, 04xx, 07xx) */
.row-detail td { font-size: 0.64rem; color: #333; background: #f9f9f9; }
.detail-code { font-size: 0.6rem !important; color: #666; padding-left: 8px !important; }
.detail-label { padding-left: 14px !important; font-style: italic; }
.no-data { text-align: left; color: #888; font-style: italic; padding: 8px; }

.table-source {
  font-size: 0.6rem;
  color: #666;
  font-family: Arial, sans-serif;
  margin-top: 2px;
  margin-bottom: 2px;
}

/* ── Titres de section ─────────────────────────────────────────────────────── */
.section-title {
  font-weight: 700;
  text-align: center;
  font-size: 0.82rem;
  margin: 14px 0 8px;
  font-family: Arial, Helvetica, sans-serif;
}
.mt-section { margin-top: 20px; }

/* ── Graphique ─────────────────────────────────────────────────────────────── */
.chart-wrap { margin-bottom: 12px; }
#bar-chart { width: 100%; display: block; overflow: visible; }
#bar-chart .axis-line  { stroke: #999; stroke-width: 1; }
#bar-chart .bar-prev   { fill: #2d6b3f; }
#bar-chart .bar-cur    { fill: #d8b800; }
#bar-chart .bar-label  { font-size: 9.5px; font-family: Arial, sans-serif; fill: #111; }
#bar-chart .bar-val    { font-size: 8.5px; font-family: Arial, sans-serif; fill: #333; }

.chart-legend {
  display: flex;
  gap: 16px;
  justify-content: center;
  font-size: 0.68rem;
  font-family: Arial, sans-serif;
  margin-top: 4px;
}
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-box  { width: 14px; height: 10px; display: inline-block; }
.legend-box.cur-month  { background: #d8b800; }
.legend-box.prev-month { background: #2d6b3f; }

/* ── CEMAC table ───────────────────────────────────────────────────────────── */
.cemac-table th, .cemac-table td { font-size: 0.65rem; padding: 2px 3px; }
.cemac-table .col-label { text-align: left; font-weight: 700; min-width: 180px; }

/* ── Commentaire ───────────────────────────────────────────────────────────── */
.comment-block { margin-bottom: 8px; }
.comment-cols  { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; text-align: justify; }
.comment-col p { font-size: 0.72rem; margin: 0 0 7px; line-height: 1.48; }

/* ── Tableau prix ──────────────────────────────────────────────────────────── */
.prices-table th, .prices-table td { font-size: 0.65rem; padding: 2px 3px; }

/* ── Bloc personnel ─────────────────────────────────────────────────────────── */
.staff-block { font-size: 0.62rem; color: #444; margin: 8px 0; font-family: Arial, sans-serif; }
.staff-block p { margin: 2px 0; line-height: 1.5; }

/* ── Pied de page ──────────────────────────────────────────────────────────── */
.pub-footer {
  margin-top: 16px;
  border-top: 1px solid #ccc;
  padding-top: 8px;
  font-family: Arial, sans-serif;
}
.pub-footer p { font-size: 0.62rem; color: #555; margin: 2px 0; }

.pub-footer-framed {
  border: 2px solid #1a7a3c;
  border-radius: 4px;
  padding: 10px 14px;
  margin-top: 16px;
}

/* ── Impression ────────────────────────────────────────────────────────────── */
@page {
  size: A4;
  margin: 10mm 8mm;
}

@media print {
  .no-print { display: none !important; }
  .bulletin-body { background: #fff; }
  #bulletin-root { margin: 0; max-width: none; gap: 0; }
  .bpage {
    box-shadow: none;
    padding: 8px 12px;
    page-break-after: always;
    break-after: page;
  }
  .bpage:last-child { page-break-after: auto; break-after: auto; }
  .data-table { font-size: 0.64rem; }
  .comment-cols { grid-template-columns: 1fr 1fr; }

  /* Forcer l'impression des couleurs d'arrière-plan */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  /* Drapeau et emblème */
  .flag-green  { background: #009e49 !important; }
  .flag-yellow { background: #fcd116 !important; }
  .flag-blue   { background: #3a75c4 !important; }

  /* Légende graphique */
  .legend-box.cur-month  { background: #d8b800 !important; }
  .legend-box.prev-month { background: #2d6b3f !important; }

  /* Compacité page 1 */
  .masthead { margin-bottom: 5px; }
  .masthead td { padding: 4px 6px; }
  .pub-title { padding: 4px 8px; margin-bottom: 5px; }
  .avertissement { padding: 5px 8px; margin-bottom: 6px; }
  .avertissement p { font-size: 0.63rem; margin: 0 0 3px; }

  /* Carte Leaflet en impression */
  .map-bulletin-wrap { page-break-inside: avoid; }

  /* Titres de section ne doivent jamais être orphelins */
  .section-title {
    break-after: avoid;
    page-break-after: avoid;
  }
  /* Le contenu juste après un titre reste avec lui */
  .section-title + .chart-wrap,
  .section-title + .data-table,
  .section-title + .comment-block,
  .section-title + .map-bulletin-wrap {
    break-before: avoid;
    page-break-before: avoid;
  }

  /* Graphique : rester ensemble (titre + barres) */
  .chart-wrap {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Bloc commentaire entier */
  .comment-block {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* CEMAC : petit tableau, pas de coupure */
  .cemac-table {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* En-têtes de tableau répétés sur chaque page */
  .data-table thead { display: table-header-group; }

  /* Pied de page encadré : pas de coupure */
  .pub-footer-framed {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
