@page {
  size: A4;
  margin: 17mm 15mm 22mm 15mm;

  @bottom-left {
    content: "Maths Terminale SM";
    color: #64748b;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8.5pt;
    font-weight: 700;
  }

  @bottom-right {
    content: "Page " counter(page) " / " counter(pages);
    color: #64748b;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8.5pt;
    font-weight: 700;
  }
}

@page cover {
  size: A4;
  margin: 15mm;

  @bottom-left {
    content: "";
  }

  @bottom-right {
    content: "";
  }
}

@page :first {
  @bottom-left {
    content: "";
  }

  @bottom-right {
    content: "";
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  color: #0f172a;
  background: #ffffff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 11.2pt;
  line-height: 1.55;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.print-document {
  counter-reset: section;
}

/* =========================================================
   Masquage des éléments interactifs
   ========================================================= */

.premium-nav,
.chapter-sidebar,
.search-box,
.btn,
.chapter-topbar,
.chapter-breadcrumb,
.chapter-navigation,
.exercise-actions,
.exercise-hint-slot,
.exercise-solution-slot,
.htmx-indicator {
  display: none !important;
}

.app-shell {
  display: block !important;
  padding: 0 !important;
  background: #ffffff !important;
}

.chapter-panel {
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
}

/* =========================================================
   Conteneurs principaux et fragmentation
   ========================================================= */

.print-content,
.print-chapter,
.chapter-article {
  position: relative;
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  break-inside: auto !important;
  page-break-inside: auto !important;
}

.chapter-article {
  padding: 0 !important;
  border: 0 !important;
  max-width: none !important;
  background: #ffffff !important;
}

.chapter-article,
.chapter-synthesis,
.math-card,
.exercise-card,
.markdown-blockquote,
.pedagogical-quote,
.variation-table-wrap,
.curve-frame {
  box-shadow: none !important;
}

.variation-object,
.curve-object {
  margin: 14px 0 18px;
  break-inside: avoid;
  page-break-inside: avoid;
}

.variation-title,
.curve-title {
  margin-bottom: 7px;
  color: #12385b;
  font-size: 9pt;
  font-weight: 800;
  text-transform: uppercase;
}

.variation-table-wrap,
.curve-frame {
  overflow: visible !important;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
}

.variation-table {
  width: 100%;
  min-width: 0 !important;
  border-collapse: collapse;
  table-layout: fixed;
}

.variation-table th,
.variation-table td {
  padding: 5px 4px;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
  text-align: center;
}

.variation-table th {
  width: 28mm;
  background: #eaf2ff;
  color: #12385b;
  font-weight: 800;
}

.variation-direction {
  color: #087d5b;
  font-size: 20pt;
  font-weight: 800;
  line-height: 1;
}

.curve-frame {
  padding: 6px;
}

.curve-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 105mm;
}

.curve-background {
  fill: #ffffff;
  stroke: #cbd5e1;
}

.curve-grid {
  stroke: #e2e8f0;
}

.curve-axis {
  stroke: #173b70;
  stroke-width: 3;
}

.curve-line {
  fill: none;
  stroke: #2456d6;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.curve-expression {
  padding-top: 5px;
  text-align: center;
  font-weight: 700;
}

.page-break-before {
  break-before: page;
  page-break-before: always;
}

/*
 * Le sommaire impose déjà un saut de page. Le premier chapitre
 * ne doit pas ajouter un second saut.
 */
.print-content > .print-chapter:first-child,
.print-content > .print-chapter:first-child.page-break-before {
  break-before: auto !important;
  page-break-before: auto !important;
}

/* Les chapitres suivants commencent sur une nouvelle page. */
.print-content > .print-chapter + .print-chapter,
.print-content > .print-chapter + .print-chapter.page-break-before {
  break-before: page !important;
  page-break-before: always !important;
}

/* =========================================================
   Typographie
   ========================================================= */

.chapter-header {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid #174ea6;
}

.chapter-number-badge {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eff6ff;
  color: #174ea6;
  font-size: 8.8pt;
  font-weight: 800;
  text-transform: uppercase;
}

.eyebrow,
.chapter-header .eyebrow {
  color: #008060;
  font-size: 9pt;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

h1 {
  margin: 6px 0 8px;
  color: #0f172a;
  font-size: 25pt;
  line-height: 1.12;
  font-weight: 850;
}

h2 {
  margin: 22px 0 10px;
  color: #0f172a;
  font-size: 16.5pt;
  line-height: 1.25;
  font-weight: 800;
  break-after: avoid-page;
  page-break-after: avoid;
}

h3 {
  margin: 16px 0 8px;
  color: #0f172a;
  font-size: 13pt;
  line-height: 1.25;
  font-weight: 800;
  break-after: avoid-page;
  page-break-after: avoid;
}

p {
  margin: 0 0 9px;
}

strong {
  font-weight: 800;
}

em {
  color: #334155;
}

.inline-code {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 5px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #0f172a;
  font-family: Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
  font-weight: 700;
}

.markdown-link {
  color: #174ea6;
  font-weight: 800;
  text-decoration: none;
  border-bottom: 1px solid #93c5fd;
}

.markdown-link::after,
.markdown-link-internal::after,
.markdown-link-external::after {
  content: "" !important;
}

/* =========================================================
   Couverture
   ========================================================= */

.pdf-cover {
  page: cover;
  min-height: 245mm;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24mm 8mm;
  break-after: page;
  page-break-after: always;
  border: 2px solid #174ea6;
  background:
    radial-gradient(circle at top left, #dbeafe, transparent 35%),
    radial-gradient(circle at bottom right, #ccfbf1, transparent 30%),
    #ffffff;
}

.pdf-cover-kicker {
  color: #008060;
  font-size: 13pt;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pdf-cover h1 {
  margin: 12px 0 14px;
  max-width: 155mm;
  color: #0f172a;
  font-size: 34pt;
  line-height: 1.05;
  font-weight: 900;
}

.pdf-cover-subtitle {
  max-width: 145mm;
  color: #475569;
  font-size: 13pt;
  line-height: 1.55;
  font-weight: 600;
}

.pdf-cover-author-block {
  margin-top: 18px;
  padding: 12px 14px;
  max-width: 90mm;
  border-left: 4px solid #008060;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.72);
}

.pdf-cover-author-label {
  margin-bottom: 4px;
  color: #008060;
  font-size: 8.8pt;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pdf-cover-author-name {
  color: #0f172a;
  font-size: 12pt;
  font-weight: 850;
}

.pdf-cover-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.pdf-cover-pill {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
  font-size: 9.5pt;
  font-weight: 750;
}

.pdf-cover-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
  padding-top: 20mm;
  color: #64748b;
  font-size: 10pt;
  font-weight: 700;
}

/* =========================================================
   Sommaire
   ========================================================= */

.print-toc {
  break-after: page;
  page-break-after: always;
}

.print-toc h2 {
  margin-top: 0;
  padding-bottom: 8px;
  border-bottom: 2px solid #174ea6;
  font-size: 22pt;
}

.print-toc-list {
  margin: 16px 0 0;
  padding-left: 0;
  list-style: none;
}

.print-toc-list li {
  display: grid;
  grid-template-columns: 24mm minmax(0, 1fr);
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px solid #e2e8f0;
}

.print-toc-number {
  color: #174ea6;
  font-weight: 850;
}

.print-toc-title {
  color: #0f172a;
  font-weight: 800;
}

.print-toc-part {
  grid-column: 2;
  color: #64748b;
  font-size: 9.2pt;
  font-weight: 650;
}

/* =========================================================
   Cartes pédagogiques
   ========================================================= */

.math-card,
.math-card-body,
.exercise-card,
.exercise-statement,
.exercise-solution,
.exercise-hint,
.exercise-correction,
.quiz-card,
.quiz-question,
.quiz-print-answer,
.chapter-synthesis,
.chapter-synthesis-card {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: visible !important;
  break-inside: auto !important;
  page-break-inside: auto !important;
}

.math-card {
  margin: 13px 0;
  padding: 12px 13px;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #174ea6;
  border-radius: 9px;
  background: #f8fafc;
}

.math-card-title {
  padding: 0 !important;
  margin-bottom: 7px;
  border-radius: 0 !important;
  background: transparent !important;
  color: #174ea6;
  font-size: 9pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  break-after: avoid-page;
  page-break-after: avoid;
}

.math-card-body p:last-child {
  margin-bottom: 0;
}

/* =========================================================
   Exercices
   ========================================================= */

.exercise-card {
  margin: 15px 0;
  overflow: visible !important;
  border: 1px solid #cbd5e1;
  border-radius: 11px;
  background: #ffffff;
}

.exercise-card-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
  break-after: avoid-page;
  page-break-after: avoid;
}

.exercise-eyebrow {
  color: #174ea6;
  font-size: 8.7pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.exercise-title {
  margin: 4px 0 0;
  color: #0f172a;
  font-size: 12.5pt;
  font-weight: 850;
}

.exercise-badges,
.exercise-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.exercise-level,
.exercise-difficulty,
.exercise-solution-status,
.exercise-tag {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 8pt;
  font-weight: 750;
}

.exercise-tags {
  padding: 9px 13px 0;
}

.exercise-statement {
  padding: 11px 13px 13px;
}

/* =========================================================
   Quiz
   ========================================================= */

.quiz-card {
  margin: 15px 0;
  border: 1px solid #c4b5fd;
  border-left: 4px solid #6d28d9;
  border-radius: 11px;
  background: #ffffff;
}

.quiz-card-header {
  padding: 11px 13px;
  border-bottom: 1px solid #ddd6fe;
  background: #f5f3ff;
  break-after: avoid-page;
  page-break-after: avoid;
}

.quiz-eyebrow {
  color: #6d28d9;
  font-size: 8.7pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.quiz-title {
  margin: 4px 0 0;
  color: #0f172a;
  font-size: 12.5pt;
  font-weight: 850;
}

.quiz-question {
  padding: 11px 13px 4px;
}

.quiz-print-choices {
  margin: 6px 13px 12px;
  padding-left: 22px;
}

.quiz-print-choices li {
  margin: 5px 0;
}

.quiz-print-answer {
  margin: 10px 13px 13px;
  padding: 9px 11px;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  background: #f0fdf4;
}

.quiz-print-explanation {
  margin-top: 7px;
}

/* =========================================================
   Mathématiques
   ========================================================= */

.math-display {
  margin: 11px 0;
  padding: 9px;
  max-width: 100%;
  overflow: visible !important;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  background: #f8fafc;
  text-align: center;
  break-inside: avoid-page;
  page-break-inside: avoid;
}

.katex-display {
  margin: 0.8em 0;
  max-width: 100%;
  overflow: visible !important;
}

/* =========================================================
   Listes
   ========================================================= */

.markdown-list,
.chapter-synthesis-list {
  margin: 7px 0 11px;
  padding-left: 20px;
}

.markdown-list li,
.chapter-synthesis-list li {
  margin: 4px 0;
  line-height: 1.5;
}

.markdown-list-ol,
.chapter-synthesis-list {
  list-style-type: decimal;
}

.markdown-list-ul {
  list-style-type: disc;
}

/* =========================================================
   Citations
   ========================================================= */

.markdown-blockquote,
.pedagogical-quote {
  break-inside: avoid-page;
  page-break-inside: avoid;
}

.markdown-blockquote {
  margin: 12px 0;
  padding: 11px 13px;
  border-left: 4px solid #174ea6;
  border-radius: 8px;
  background: #f8fafc;
}

.markdown-blockquote-mark {
  display: none;
}

.markdown-blockquote-body {
  color: #334155;
  font-weight: 600;
}

.pedagogical-quote {
  margin: 13px 0;
  padding: 13px;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #008060;
  border-radius: 10px;
  background: #f8fafc;
}

.pedagogical-quote-label {
  margin-bottom: 7px;
  color: #008060;
  font-size: 8.8pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pedagogical-quote-body {
  margin: 0;
}

.pedagogical-quote-caption {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #cbd5e1;
  color: #475569;
  font-size: 9pt;
  font-weight: 700;
}

/* =========================================================
   Synthèse
   ========================================================= */

.chapter-synthesis {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 2px solid #174ea6;
  background: #ffffff !important;
  border-radius: 0 !important;
}

.chapter-synthesis-header {
  display: none !important;
}

.chapter-synthesis-grid {
  display: block !important;
}

.chapter-synthesis-card {
  margin-bottom: 11px;
  padding: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  background: #ffffff;
}

.chapter-synthesis-card-main {
  background: #f0fdfa;
  border-color: #99f6e4;
}

.chapter-synthesis-card-title {
  margin-bottom: 7px;
  color: #174ea6;
  font-size: 8.8pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  break-after: avoid-page;
  page-break-after: avoid;
}

.chapter-synthesis-card p {
  margin: 0;
  color: #334155;
  font-weight: 600;
}

.chapter-synthesis-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chapter-synthesis-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
  font-size: 8.3pt;
  font-weight: 750;
}

.chapter-synthesis-pill-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ffffff;
  color: #174ea6;
  font-weight: 850;
}

/* =========================================================
   Figures pédagogiques
   ========================================================= */

.pedagogic-figure {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 7mm 0;
  break-inside: avoid-page;
  page-break-inside: avoid;
}

.pedagogic-figure-header {
  margin-bottom: 3mm;
}

.pedagogic-figure-title {
  color: #174ea6;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 9pt;
  font-weight: 850;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.pedagogic-figure-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  overflow: hidden;
  padding: 3.5mm;
  border: 0.35mm solid #cbd5e1;
  border-radius: 4mm;
  background: #ffffff !important;
  box-shadow: none !important;
}

.pedagogic-figure-image {
  display: block;
  width: auto !important;
  max-width: 100% !important;
  height: auto !important;
  max-height: 155mm !important;
  margin: 0 auto;
  object-fit: contain;
}

.pedagogic-figure-wide .pedagogic-figure-image {
  width: 100% !important;
  max-height: 130mm !important;
}

.pedagogic-figure-wide .pedagogic-figure-image {
  width: 100% !important;
  height: auto !important;
  max-height: 130mm !important;
  object-fit: contain;
}

.pedagogic-figure-tall .pedagogic-figure-image {
  width: auto !important;
  max-height: 205mm !important;
}

.pedagogic-figure-compact .pedagogic-figure-image {
  max-width: 78% !important;
  max-height: 115mm !important;
}

.pedagogic-figure-caption {
  margin-top: 3mm;
  padding: 0 1mm;
  color: #475569;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 8.8pt;
  line-height: 1.45;
}

.pedagogic-figure-caption > :last-child {
  margin-bottom: 0;
}

/* =========================================================
   Aperçu écran
   ========================================================= */

@media screen {
  body.paged-ready {
    background: #f1f5f9;
  }

  body.paged-ready .pagedjs_pages {
    margin: 24px auto;
  }

  body.paged-ready .pagedjs_page {
    margin: 18px auto;
    background: #ffffff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
  }
}

/* =========================================================
   Impression
   ========================================================= */

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
  }

  .pagedjs_pages,
  .pagedjs_page {
    margin: 0 !important;
    box-shadow: none !important;
  }
}

/* =========================================================
   Indices et corrigés dans les exports PDF
   ========================================================= */

.exercise-print-hint,
.exercise-print-solution {
  margin: 4mm 3.5mm;
  padding: 3.5mm 4mm;
  overflow: visible;
  break-inside: auto;
  page-break-inside: auto;
}

.exercise-print-hint {
  border: 0.35mm solid #f59e0b;
  border-left: 1.2mm solid #f59e0b;
  border-radius: 3mm;
  background: #fffbeb;
}

.exercise-print-solution {
  border: 0.35mm solid #10b981;
  border-left: 1.2mm solid #10b981;
  border-radius: 3mm;
  background: #f0fdf4;
}

.exercise-print-section-title {
  margin-bottom: 2mm;
  font-size: 9pt;
  font-weight: 850;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.exercise-print-hint .exercise-print-section-title {
  color: #b45309;
}

.exercise-print-solution .exercise-print-section-title {
  color: #047857;
}

.exercise-print-section-body {
  color: #1e293b;
}

.exercise-print-section-body > :last-child {
  margin-bottom: 0;
}

.exercise-print-hints-list {
  margin: 0;
  padding-left: 6mm;
}

.exercise-print-hints-list > li {
  margin-bottom: 2mm;
}

/* =========================================================
   Tableaux Markdown — impression
   ========================================================= */

.markdown-table-wrap {
  width: 100%;
  margin: 4mm 0;
  overflow: visible;
  border: 0.3mm solid #cbd5e1;
  border-radius: 3mm;
  background: #ffffff;
  break-inside: avoid-page;
  page-break-inside: avoid;
}

.markdown-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  color: #0f172a;
  font-size: 9.3pt;
}

.markdown-table thead {
  display: table-header-group;
}

.markdown-table tr {
  break-inside: avoid-page;
  page-break-inside: avoid;
}

.markdown-table th,
.markdown-table td {
  padding: 2.2mm 2.5mm;
  border: 0.25mm solid #cbd5e1;
  vertical-align: middle;
}

.markdown-table th {
  background: #eff6ff;
  color: #12385b;
  font-weight: 800;
}

.markdown-table tbody tr:nth-child(even) td {
  background: #f8fafc;
}

.markdown-table th > p,
.markdown-table td > p {
  margin: 0;
}

.markdown-table-align-left {
  text-align: left;
}

.markdown-table-align-center {
  text-align: center;
}

.markdown-table-align-right {
  text-align: right;
}
