/* ==========================================================================
   myLims — Composants partagés
   Toutes les variantes réutilisent ces briques. Une variante ne fait que
   les agencer (layout) et ajuster quelques variables locales.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
:focus-visible { outline: 0.125rem solid var(--focus); outline-offset: 1px; }
.mono { font-family: var(--font-mono); font-size: .95em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: var(--gap); }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.spacer { flex: 1; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.375rem;
  height: var(--control-h); padding: 0 0.75rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { color: var(--err); }
.btn.sm { height: calc(var(--control-h) - 0.375rem); padding: 0 0.5rem; font-size: var(--fs-sm); }
.btn.icon { width: var(--control-h); padding: 0; }
.btn kbd { margin-left: 0.25rem; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-group .btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); z-index: 1; }

kbd {
  display: inline-block; min-width: 1.125rem; padding: 0 0.3125rem;
  border: 1px solid var(--border-strong); border-bottom-width: 0.125rem; border-radius: 0.25rem;
  background: var(--surface-2); color: var(--text-muted);
  font: 500 0.6562rem/1rem var(--font-mono); text-align: center;
}

/* ---------- Champs ---------- */
.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 0.5rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--input-bg); color: var(--text); font: inherit;
}
.textarea { height: auto; min-height: calc(var(--control-h) * 2); padding: 0.375rem 0.5rem; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 0.1875rem var(--accent-soft);
}
.input[readonly] { background: var(--input-readonly); color: var(--text-muted); }
.input.invalid { border-color: var(--err); box-shadow: 0 0 0 0.1875rem var(--err-soft); }

/* Champ généré par Kit.renderForm : label + contrôle + aide */
.field { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.field > label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted); }
.field.required > label::after { content: " *"; color: var(--required); }
.field .hint { font-size: var(--fs-xs); color: var(--text-faint); }
.field .err-msg { font-size: var(--fs-xs); color: var(--err); }
.field .control { display: flex; gap: 0.375rem; align-items: center; }
.field .control .unit { color: var(--text-muted); font-size: var(--fs-sm); }
.field.span-2 { grid-column: span 2; }
.field.span-3 { grid-column: span 3; }
.field.span-all { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 0.375rem; cursor: pointer; }
.check input { accent-color: var(--accent); width: 0.9375rem; height: 0.9375rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.375rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 0.125rem 0.5rem;
  border: 1px solid var(--border-strong); border-radius: 62.4375rem;
  background: var(--surface-2); font-size: var(--fs-sm); cursor: pointer;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* Grille de formulaire : le nombre de colonnes est piloté par la variante */
.form-section { display: grid; grid-template-columns: repeat(var(--form-cols, 3), minmax(0, 1fr)); gap: var(--field-gap); }
.form-section-title {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 0.5rem;
  font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted);
}
/* Libellés à gauche (style ERP) : <div class="form labels-left"> */
.labels-left .field { display: grid; grid-template-columns: var(--label-w, 8.125rem) minmax(0, 1fr); align-items: center; column-gap: 0.5rem; }
.labels-left .field > label { text-align: right; }
.labels-left .field .hint, .labels-left .field .err-msg { grid-column: 2; }

/* ---------- Cartes, panneaux ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-h { display: flex; align-items: center; gap: 0.5rem; padding: 0.625rem var(--pad); border-bottom: 1px solid var(--border); }
.card-h h2, .card-h h3 { flex: 1; }
.card-b { padding: var(--pad); }
.panel-title { font-size: var(--fs-sm); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }

/* ---------- Badges / statuts ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 0.25rem; padding: 1px 0.5rem;
  border-radius: 62.4375rem; font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-muted);
}
.badge::before { content: ""; width: 0.375rem; height: 0.375rem; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow: auto; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th {
  position: sticky; top: 0; z-index: 1; height: var(--row-h); padding: 0 0.625rem;
  background: var(--surface-2); color: var(--text-muted); font-size: var(--fs-sm); font-weight: 600;
  text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none;
}
.table th.sortable { cursor: pointer; }
.table th.sortable:hover { color: var(--text); }
.table th .sort { opacity: .6; margin-left: 0.125rem; }
.table td { height: var(--row-h); padding: 0 0.625rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tbody tr { cursor: default; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr.selected td { background: var(--accent-soft); }
.table tbody tr.selected td:first-child { box-shadow: inset 0.1875rem 0 0 var(--accent); }
.table td.num, .table th.num { text-align: right; }
.table tr.out td { color: var(--err); }
.table tfoot td { font-weight: 600; background: var(--surface-2); }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 0.125rem; border-bottom: 1px solid var(--border); }
.tab {
  padding: 0.5rem 0.75rem; border: 0; background: none; color: var(--text-muted);
  font: inherit; font-weight: 500; cursor: pointer; border-bottom: 0.125rem solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count { margin-left: 0.25rem; padding: 0 0.375rem; border-radius: 62.4375rem; background: var(--surface-3); font-size: var(--fs-xs); }

/* ---------- Barre d'outils, fil d'Ariane ---------- */
.toolbar { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.crumbs { display: flex; gap: 0.375rem; align-items: center; color: var(--text-muted); font-size: var(--fs-sm); }
.crumbs span + span::before { content: "/"; margin-right: 0.375rem; color: var(--text-faint); }
.search {
  display: flex; align-items: center; gap: 0.375rem; height: var(--control-h); padding: 0 0.5rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--input-bg); color: var(--text-faint);
}
.search input { border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; width: 100%; min-width: 0; text-overflow: ellipsis; }
.search > svg, .search > kbd { flex-shrink: 0; }   /* le texte se coupe avant l'icône et le raccourci */

/* ---------- Visionneuse PDF (maquette HTML d'un rapport A4) ---------- */
.pdf-viewer { display: flex; flex-direction: column; background: var(--viewer-bg); min-height: 0; }
.pdf-toolbar {
  display: flex; align-items: center; gap: 0.375rem; padding: 0.375rem 0.625rem;
  background: rgba(0, 0, 0, .35); color: #e8ecf3; font-size: var(--fs-sm);
}
.pdf-toolbar .btn { background: transparent; color: #e8ecf3; border-color: rgba(255, 255, 255, .2); }
.pdf-toolbar .btn:hover { background: rgba(255, 255, 255, .1); }
.pdf-pages { flex: 1; overflow: auto; padding: 1.125rem; display: flex; flex-direction: column; align-items: center; gap: 1.125rem; }
.pdf-page {
  width: 37.1875rem; min-height: 52.625rem; flex-shrink: 0; padding: 2.75rem 3rem; transform-origin: top center;
  background: var(--paper); color: var(--paper-text); box-shadow: 0 0.25rem 1.125rem rgba(0, 0, 0, .35);
  font: 0.625rem/1.45 "Segoe UI", Arial, sans-serif;
}
.pdf-page h1 { font-size: 0.9375rem; letter-spacing: .02em; }
.pdf-page h2 { font-size: 0.6875rem; margin: 0.875rem 0 0.375rem; text-transform: uppercase; color: #334; border-bottom: 1px solid #ccd; padding-bottom: 0.1875rem; }
.pdf-page table { width: 100%; border-collapse: collapse; }
.pdf-page th, .pdf-page td { border: 1px solid #cfd5df; padding: 0.1875rem 0.3125rem; text-align: left; }
.pdf-page th { background: #eef1f6; font-weight: 600; }
.pdf-page td.num { text-align: right; }
.pdf-page .out { color: #b00; font-weight: 700; }
.pdf-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding-bottom: 0.625rem; border-bottom: 0.125rem solid #1b2232; }
.pdf-logo { font: 800 1.125rem/1 "Segoe UI", sans-serif; color: #1b2232; }
.pdf-logo small { display: block; font-weight: 400; font-size: 0.5625rem; color: #667; margin-top: 0.1875rem; }
.pdf-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 0.25rem 1.125rem; margin-top: 0.625rem; }
.pdf-meta div span { color: #667; }
.pdf-foot { margin-top: 1.125rem; padding-top: 0.5rem; border-top: 1px solid #ccd; color: #667; font-size: 0.5312rem; }
.pdf-sign { display: flex; justify-content: flex-end; margin-top: 1.125rem; }
.pdf-sign div { width: 12.5rem; border: 1px dashed #aab; padding: 0.5rem; text-align: center; color: #445; }
.pdf-total { margin-left: auto; width: 14.375rem; margin-top: 0.625rem; }
.pdf-total td { border: 0; padding: 0.125rem 0.25rem; }
.pdf-total tr.grand td { border-top: 0.125rem solid #1b2232; font-weight: 700; font-size: 0.6875rem; padding-top: 0.3125rem; }
.pdf-watermark { position: relative; }
.pdf-watermark::after {
  content: attr(data-mark); position: absolute; inset: 40% 0 auto; text-align: center;
  font: 800 3.375rem/1 "Segoe UI", sans-serif; color: rgba(192, 38, 45, .12); transform: rotate(-24deg); pointer-events: none;
}

/* ---------- Divers ---------- */
.kpi { display: flex; flex-direction: column; gap: 0.125rem; }
.kpi .v { font-size: var(--fs-2xl); font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: var(--fs-sm); color: var(--text-muted); }
.empty { padding: 2.5rem; text-align: center; color: var(--text-faint); }
.divider { height: 1px; background: var(--border); margin: var(--gap) 0; }
.avatar {
  display: inline-grid; place-items: center; width: 1.5rem; height: 1.5rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: 0.625rem; font-weight: 700;
}
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 0.75rem 1.125rem; font-size: var(--fs-sm); }
.timeline li::before { content: ""; position: absolute; left: 0.25rem; top: 0.3125rem; width: 0.4375rem; height: 0.4375rem; border-radius: 50%; background: var(--accent); }
.timeline li::after { content: ""; position: absolute; left: 0.4375rem; top: 0.875rem; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }

/* Toast */
.toast-host { position: fixed; right: 1rem; bottom: 5.75rem; z-index: 1000; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  min-width: 15rem; padding: 0.625rem 0.875rem; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  background: var(--text); color: var(--bg); font-size: var(--fs-sm); animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { transform: translateY(0.5rem); opacity: 0; } }

/* Modale / palette (réutilisable) */
.overlay { position: fixed; inset: 0; z-index: 900; background: rgba(10, 14, 22, .45); display: none; align-items: flex-start; justify-content: center; padding-top: 12vh; }
.overlay.open { display: flex; }
.dialog { width: min(38.75rem, calc(100vw - 2rem)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden; }

/* ---------- Barre « studio » injectée par kit.js (hors maquette) ---------- */
.studio {
  position: fixed; right: 0.75rem; bottom: 2.5rem; z-index: 2000;
  display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem 0.375rem 0.75rem;
  background: #0b1020; color: #cfd6e4; border-radius: 62.4375rem; box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, .35);
  font: 0.75rem/1 "Segoe UI", system-ui, sans-serif; max-width: calc(100vw - 1.5rem); flex-wrap: wrap;
}
.studio b { color: #fff; font-weight: 600; }
.studio a { color: #9fb7ff; }
.studio select {
  height: 1.625rem; border: 1px solid #2c3550; border-radius: 62.4375rem; padding: 0 0.5rem;
  background: #151c33; color: #e6eaf2; font: inherit;
}
.studio .sep { width: 1px; height: 1rem; background: #2c3550; }
/* Réglages de démonstration propres à une page (état simulé, droits) */
.studio .studio-extra { display: flex; align-items: center; gap: 0.5rem; }
.studio .studio-extra label { display: flex; align-items: center; gap: 0.25rem; color: #8d97ad; }
/* Réduite par défaut (pastille « Démo ») pour ne masquer aucune zone de la maquette ; survol = dépliée, clic = épinglée */
.studio:not(.pinned):not(:hover):not(:focus-within) { padding: 0.375rem 0.625rem; }
.studio:not(.pinned):not(:hover):not(:focus-within) > :not(.studio-toggle) { display: none; }
.studio-toggle { background: none; border: 0; color: #8d97ad; cursor: pointer; font: inherit; padding: 0 0.25rem; }
@media print { .studio, .toast-host { display: none; } }
