:root {
  --rapport-vert: #0f5f42;
  --rapport-vert-sombre: #0b3f31;
  --rapport-encre: #102238;
  --rapport-texte: #26342f;
  --rapport-muet: #6b7773;
  --rapport-bordure: #d6dedb;
  --rapport-fond: #f3f6f5;
  --rapport-rouge: #c3212b;
}

.rapport-apercu-boite {
  width: min(940px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.rapport-apercu-entete,
.rapport-apercu-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: #fff;
}

.rapport-apercu-entete {
  justify-content: space-between;
  border-bottom: 1px solid var(--rapport-bordure);
}

.rapport-apercu-entete h3 { margin: 0; }

.rapport-apercu-zone {
  padding: 22px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100vh - 164px);
  background: #e9efec;
}

.rapport-apercu-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
  border-top: 1px solid var(--rapport-bordure);
}

.rapport-apercu-aide {
  margin: 0 auto 0 0;
  color: #52615b;
  font-size: 13px;
}

.rapport-feuille {
  box-sizing: border-box;
  width: min(210mm, 100%);
  min-height: 297mm;
  margin: 0 auto;
  padding: 14mm;
  background: #fff;
  color: var(--rapport-texte);
  font-family: Inter, Arial, sans-serif;
  font-size: 10.5pt;
  line-height: 1.35;
  box-shadow: 0 6px 24px rgba(16, 34, 56, 0.14);
}

.rapport-marque {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18mm;
  padding-bottom: 8mm;
}

.rapport-marque h1 {
  margin: 3mm 0 0;
  color: var(--rapport-encre);
  font-size: 25pt;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.04;
  text-transform: uppercase;
}

.rapport-marque > p {
  min-width: 34mm;
  margin: 2mm 0 0;
  color: var(--rapport-muet);
  font-size: 9pt;
  text-align: right;
}

.rapport-logo {
  margin: 0;
  color: var(--rapport-vert);
  font-size: 13pt;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.rapport-identification {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2.5mm 18mm;
  margin-bottom: 4mm;
  padding: 4mm 0 5mm;
  border-top: 1px solid var(--rapport-bordure);
  border-bottom: 1px solid var(--rapport-bordure);
}

.rapport-identification div {
  display: flex;
  gap: 3mm;
  min-width: 0;
}

.rapport-identification span {
  flex: 0 0 27mm;
  color: var(--rapport-muet);
}

.rapport-identification strong {
  min-width: 0;
  color: var(--rapport-texte);
  font-weight: 650;
  overflow-wrap: anywhere;
}

.rapport-section {
  margin-top: 4.5mm;
  break-inside: avoid;
  page-break-inside: avoid;
}

.rapport-section-fluide {
  break-inside: auto;
  page-break-inside: auto;
}

.rapport-section h2 {
  margin: 0 0 1.5mm;
  color: var(--rapport-vert);
  font-size: 13pt;
  font-weight: 900;
  letter-spacing: 0;
  line-height: 1.1;
  text-transform: uppercase;
}

.rapport-tableau {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 10.2pt;
}

.rapport-tableau tr {
  border-bottom: 1px solid var(--rapport-bordure);
}

.rapport-tableau td {
  padding: 1.45mm 2mm 1.45mm 0;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.rapport-tableau td:first-child {
  width: 64%;
  color: #404f4a;
}

.rapport-tableau td:first-child span {
  display: block;
}

.rapport-tableau small {
  display: block;
  margin-top: 0.6mm;
  color: var(--rapport-muet);
  font-size: 8.3pt;
}

.rapport-valeur {
  color: var(--rapport-encre);
  font-weight: 800;
  text-align: right;
}

.rapport-valeur-positive { color: var(--rapport-vert); }
.rapport-valeur-negative { color: var(--rapport-rouge); }

.rapport-vide,
.rapport-note,
.rapport-date-releve {
  margin: 0;
}

.rapport-vide {
  padding: 3mm;
  color: var(--rapport-muet);
  border: 1px dashed var(--rapport-bordure);
  background: var(--rapport-fond);
}

.rapport-note {
  padding-top: 1mm;
  white-space: pre-wrap;
}

.rapport-date-releve {
  margin-bottom: 2mm;
  color: var(--rapport-muet);
  font-weight: 700;
}

.rapport-pied {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8mm;
  margin-top: 12mm;
  padding-top: 3mm;
  color: var(--rapport-muet);
  border-top: 1px solid var(--rapport-bordure);
  font-size: 8.6pt;
}

.rapport-pied strong {
  color: var(--rapport-encre);
}

.rapport-kpi {
  break-inside: avoid;
  page-break-inside: avoid;
}

.rapport-impression {
  margin: 0;
  background: #fff;
}

.rapport-impression .rapport-feuille {
  box-shadow: none;
}

@media (max-width: 600px) {
  #modal-rapport-bande {
    align-items: stretch;
    justify-content: flex-start;
    padding: env(safe-area-inset-top, 0) 0 0;
  }

  .rapport-apercu-boite {
    width: 100vw;
    max-height: calc(100dvh - env(safe-area-inset-top, 0));
    border-radius: 0;
  }

  .rapport-apercu-zone {
    padding: 10px;
    max-height: none;
  }

  .rapport-apercu-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    flex: 0 0 auto;
    padding: 12px 12px calc(18px + env(safe-area-inset-bottom, 0));
  }

  .rapport-apercu-aide {
    grid-column: 1 / -1;
  }

  .rapport-apercu-actions .btn {
    width: 100%;
  }

  .rapport-feuille {
    min-height: 0;
    padding: 18px;
    font-size: 10pt;
  }

  .rapport-marque {
    flex-direction: column;
    gap: 8px;
    padding-bottom: 18px;
  }

  .rapport-marque h1 { font-size: 21pt; }
  .rapport-marque > p {
    min-width: 0;
    text-align: left;
  }

  .rapport-identification {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .rapport-identification div {
    display: block;
  }

  .rapport-identification span {
    display: block;
    margin-bottom: 2px;
  }

  .rapport-tableau td:first-child {
    width: 56%;
  }

  .rapport-pied {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}

@media print {
  @page { size: A4 portrait; margin: 0; }

  :root {
    --rapport-vert: #174c3d;
    --rapport-vert-sombre: #174c3d;
    --rapport-encre: #111;
    --rapport-texte: #111;
    --rapport-muet: #555;
    --rapport-bordure: #aaa;
    --rapport-fond: #f2f2f2;
    --rapport-rouge: #a00000;
  }

  body { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .rapport-feuille { width: 210mm; min-height: 297mm; margin: 0; box-shadow: none; }
  .rapport-section, .rapport-kpi, .rapport-tableau tr { break-inside: avoid; page-break-inside: avoid; }
}
