:root {
  --bg: #f6f5f0;
  --panel: #ffffff;
  --ink: #22201d;
  --ink-soft: #6b6862;
  --border: #e2e6dc;
  --accent: #4b7a5a;
  --accent-dark: #375c42;
  --accent-soft: #eef3ea;
  --red: #b3413a;
  --red-bg: #fbe9e7;
  --green: #2f7a6b;
  --green-bg: #e5f2ee;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: 'Georgia', 'Times New Roman', serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}
.brand-logo { height: 46px; width: auto; flex-shrink: 0; }
.brand-text {
  font-size: 0.95rem;
  color: var(--ink-soft);
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

header.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  font-weight: 600;
  letter-spacing: 0.02em;
}

nav.steps {
  display: flex;
  gap: 6px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.82rem;
}

nav.steps a {
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  border: 1px solid transparent;
}

nav.steps a.active {
  background: var(--accent);
  color: #fff;
}

nav.steps a.disabled {
  pointer-events: none;
  opacity: 0.45;
}

main {
  max-width: 980px;
  margin: 28px auto;
  padding: 0 20px 60px;
}

main.wide { max-width: 1280px; }

.table-scroll {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 8px;
  scrollbar-width: none;
}
.table-scroll::-webkit-scrollbar { display: none; }
.table-scroll > table { margin: 0 auto; }
.index-name-cell { position: sticky; left: 0; background: var(--panel); z-index: 2; }

.floating-scrollbar {
  position: fixed;
  bottom: 0;
  height: 18px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--panel);
  border-top: 1px solid var(--border);
  z-index: 50;
  display: none;
  /* Firefox : scrollbar toujours visible et colorée */
  scrollbar-width: auto;
  scrollbar-color: var(--accent) var(--bg);
}
.floating-scrollbar.visible { display: block; }
.floating-scrollbar-inner { height: 1px; }
/* Chrome/Edge/Safari : par défaut, une scrollbar "overlay" (macOS, ou
   réglage "masquer automatiquement" sous Windows) reste invisible tant
   qu'on ne la survole pas — ce qui la rendait ici indétectable. On force
   donc un curseur épais et coloré, toujours visible, plutôt que la
   scrollbar native. */
.floating-scrollbar::-webkit-scrollbar { height: 12px; }
.floating-scrollbar::-webkit-scrollbar-track { background: var(--bg); }
.floating-scrollbar::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 6px; border: 2px solid var(--bg); }
.floating-scrollbar::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
}

h2 { font-size: 1.1rem; margin-top: 0; }
h3 { font-size: 0.95rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }

input[type=text], input[type=date], input[type=number], select {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.92rem;
  width: 100%;
}

label { font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 0.82rem; color: var(--ink-soft); display: block; margin-bottom: 4px; }

button {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: var(--accent-dark); }
button.secondary { background: transparent; color: var(--accent-dark); border: 1px solid var(--border); }
button.secondary:hover { background: #f0eee8; }
button.small { padding: 5px 10px; font-size: 0.78rem; }

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.patient-list { list-style: none; padding: 0; margin: 0; }
.patient-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-family: 'Helvetica Neue', Arial, sans-serif;
}
.patient-list li:hover { background: #f5f3ee; }
.patient-list .meta { color: var(--ink-soft); font-size: 0.82rem; }
.patient-item-info { display: flex; flex-direction: column; gap: 2px; flex: 1; cursor: pointer; }
.patient-delete-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.patient-delete-btn:hover { color: var(--red); background: var(--red-bg); }
.patient-edit-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.patient-edit-btn:hover { color: var(--accent-dark); background: var(--accent-soft); }

.radio-row { display: flex; gap: 16px; font-family: 'Helvetica Neue', Arial, sans-serif; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--ink); }

/* Certains thèmes/extensions WordPress remplacent l'apparence de TOUTES les
   cases à cocher et boutons radio de la page par un style personnalisé, en
   s'appuyant sur une structure HTML précise (icône, span supplémentaire...).
   Si notre propre structure ne correspond pas exactement à ce qu'ils
   attendent, la case peut devenir invisible sans que son remplacement ne
   s'affiche. On force donc leur apparence native du navigateur, immunisée
   contre ce genre d'interférence. */
input[type="checkbox"], input[type="radio"] {
  all: revert !important;
}

table.index-table { border-collapse: collapse; font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 0.88rem; table-layout: fixed; }
table.index-table td, table.index-table th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.index-table td.index-name-cell, table.index-table th:first-child { white-space: normal; }
table.index-table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; color: var(--ink-soft); padding: 6px 6px; border-bottom: 1px solid var(--border); }
table.index-table td { padding: 7px 6px; border-bottom: 1px solid #f0eee8; }
table.index-table tr.incomplete td { color: #b8b3a8; font-style: italic; }

.status-normal { background: #ffffff; }
.status-haut { background: var(--red-bg); color: var(--red); font-weight: 600; }
.status-bas { background: var(--green-bg); color: var(--green); font-weight: 600; }

.section-title { margin-top: 26px; margin-bottom: 6px; font-size: 1rem; border-bottom: 2px solid var(--accent); padding-bottom: 4px; }

[data-tooltip] { cursor: help; border-bottom: 1px dotted var(--ink-soft); }

.js-tooltip {
  position: fixed;
  z-index: 1000;
  background: #2b2924;
  color: #fff;
  padding: 8px 10px;
  border-radius: 6px;
  max-width: 320px;
  font-size: 0.78rem;
  line-height: 1.4;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25);
  pointer-events: none;
}

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

.sort-columns { display: flex; gap: 16px; align-items: flex-start; }
.sort-pool, .sort-section {
  background: #fbfaf7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  min-height: 120px;
}
.sort-pool { flex: 1.2; }
.sort-section { flex: 1; margin-bottom: 12px; }
.sort-section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sort-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  margin-bottom: 6px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.82rem;
  cursor: grab;
}
.sort-item.dragging { opacity: 0.4; }
.sort-item.disabled { color: #b8b3a8; }
.sort-list.drag-over { background: #f0eee8; outline: 2px dashed var(--accent); outline-offset: -2px; }

table.norms-table { width: 100%; border-collapse: collapse; font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 0.9rem; }
table.norms-table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; color: var(--ink-soft); padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.norms-table td { padding: 6px 8px; border-bottom: 1px solid #f0eee8; }
table.norms-table td:first-child { width: 55%; }
table.norms-table input { width: 100%; }

td.preset-cell {
  border-left: 1px solid var(--border);
  padding-left: 12px;
  position: relative;
}
.preset-btn { white-space: nowrap; }

.preset-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.18);
  z-index: 30;
  min-width: 260px;
  padding: 10px;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  text-align: left;
}
.preset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 4px 2px;
  border-bottom: 1px solid #f0eee8;
}
.preset-row:last-of-type { border-bottom: none; }
.preset-select {
  background: none;
  border: none;
  color: var(--ink);
  padding: 4px;
  text-align: left;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.preset-select:hover { background: var(--accent-soft); border-radius: 6px; }
.preset-delete {
  background: none;
  color: var(--ink-soft);
  border: none;
  padding: 4px 6px;
  font-size: 0.8rem;
}
.preset-delete:hover { color: var(--red); background: var(--red-bg); border-radius: 6px; }

.preset-form {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preset-form input[type=text] { width: 100%; }
.preset-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.preset-form-grid input { width: 100%; margin-top: 2px; }

.hint { font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 0.8rem; color: var(--ink-soft); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-family: 'Helvetica Neue', Arial, sans-serif; background: #eee; color: var(--ink-soft); }

.date-menu {
  position: fixed;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  min-width: 130px;
  font-weight: normal;
  text-align: left;
}
.date-menu button {
  background: none;
  color: var(--ink);
  border: none;
  border-radius: 0;
  padding: 8px 12px;
  text-align: left;
  font-size: 0.82rem;
}
.date-menu button:hover { background: #f5f3ee; }
.date-menu button[data-act=delete] { color: var(--red); }

.bilan-selector { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.bilan-chip {
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.82rem;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
}
.bilan-chip:hover { background: var(--accent-soft); }
.bilan-chip.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

th.date-header { cursor: pointer; position: relative; }

.backup-banner {
  background: #fbf0dc;
  color: #6b4f1d;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.85rem;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  max-width: 440px;
  width: 90%;
  font-family: 'Helvetica Neue', Arial, sans-serif;
  box-shadow: 0 12px 32px rgba(0,0,0,0.25);
}
.modal-box button { width: 100%; text-align: left; white-space: normal; }
.modal-box button .hint { display: block; font-size: 0.75rem; margin-top: 2px; }
.modal-box button.secondary .hint { color: var(--ink-soft); }
.modal-box button:not(.secondary) .hint { color: rgba(255,255,255,0.85); }

.print-header { display: none; }
#printBatches { display: none; }

/* ---------------------------------------------------------------------- */
/* Impression : couleurs forcées, mise en page compacte, pas de coupures  */
/* de ligne au milieu d'une rangée, pas plus de 2-3 pages pour 172 index. */
/* ---------------------------------------------------------------------- */
@media print {
  @page { size: A4 portrait; margin: 12mm; }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body { background: #fff; }

  header.topbar,
  nav.steps,
  .backup-banner,
  .floating-scrollbar,
  .no-print,
  #emptyStateBtn,
  #sectionsContainer,
  #rawParamsContainer { display: none !important; }

  #printBatches { display: block; }
  .print-batch-break { break-before: page; }

  .print-header {
    display: block;
    font-family: 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 10px;
    text-align: center;
  }

  main.wide { max-width: none; margin: 0; padding: 0; }

  .panel {
    border: none;
    box-shadow: none;
    padding: 0;
    margin-bottom: 8px;
    /* Pas de "break-inside: avoid-page" ici : une section ne doit pas
       sauter entièrement à la page suivante si elle tient partiellement
       sur la page en cours — seul le titre isolé doit être évité (ci-dessous). */
  }

  .section-title { break-after: avoid; margin-top: 10px; text-align: center; }

  /* Largeurs fixes dédiées à l'impression (plus compactes qu'à l'écran, pour
     que plusieurs bilans tiennent sur une même largeur de page portrait) —
     identiques pour TOUS les tableaux, jamais étirées pour remplir la page.
     Le nombre de colonnes "col" varie selon le nombre de bilans du lot, mais
     leur largeur individuelle reste constante : ":first-child" = colonne
     Index, les suivantes = colonnes de valeur (Structure/Fonction/Mini/Maxi
     pour les tableaux d'index ; une par bilan, deux fois plus large, pour le
     tableau des paramètres bruts, afin de rester aligné avec les paires). */
  table.index-table { width: auto !important; margin: 0 auto; }
  table.index-table col:first-child { width: 160px !important; }
  table.index-table:not(.raw-table) col:not(:first-child) { width: 42px !important; }
  table.raw-table col:not(:first-child) { width: 84px !important; }
  .table-scroll { overflow: visible; display: flex; justify-content: center; }
  table.index-table tr { break-inside: avoid; }
  .index-name-cell { position: static; }

  table.index-table td, table.index-table th { padding: 3px 5px; font-size: 8.5px; }
  .section-title { font-size: 10px; }
  h2, .hint { font-size: 9px; }
}
