/*
 * Maple Admin — composants partagés par tous les écrans. Une feuille d'écran n'ajoute que sa
 * mise en page propre, sans redéfinir un composant. Référence : docs/architecture/adminweb.md.
 */

/* ---- Boutons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text);
  font-size: var(--text-14);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}

.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-strong); color: var(--on-accent); }

.btn--secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.btn--secondary:hover { background: var(--surface-hover); color: var(--text); }

.btn--ghost { color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--text); }

.btn--danger { background: var(--danger); color: var(--on-danger); }
.btn--danger:hover { background: var(--danger-strong); color: var(--on-danger); }

.btn--danger-ghost { color: var(--danger); }
.btn--danger-ghost:hover { background: var(--danger-tint); color: var(--danger-strong); }

.btn--link {
  height: auto;
  padding: 0;
  color: var(--accent);
  font-weight: 500;
}

.btn--link:hover { color: var(--accent-strong); text-decoration: underline; }

.btn--sm { height: var(--control-height-sm); padding: 0 10px; font-size: var(--text-12); }
.btn--lg { height: var(--control-height-lg); padding: 0 var(--space-4); }
.btn--block { width: 100%; }

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--control-height);
  height: var(--control-height);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--text-2);
}

.icon-button:hover { background: var(--surface-hover); color: var(--text); }
.icon-button--sm { width: var(--control-height-sm); height: var(--control-height-sm); }
.icon-button--xs { width: 24px; height: 24px; }
.icon-button--bordered { border-color: var(--border-strong); background: var(--surface); }

.icon-button__dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--danger);
}

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--text-3);
  font-family: var(--font-ui);
  font-size: var(--text-12);
  line-height: 1;
}

/* ---- Statuts : forme et couleur, jamais la couleur seule ---- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  white-space: nowrap;
}

.status::before {
  content: "";
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status[data-status="running"]::before,
.status[data-status="active"]::before {
  background: var(--status-running);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.status[data-status="queued"]::before { border: 2px solid var(--status-queued); }
.status[data-status="pending"]::before { border: 2px dashed var(--status-pending); }

.status[data-status="suspended"]::before {
  border: 2px solid var(--status-suspended);
  background: radial-gradient(circle, var(--status-suspended) 0 2px, transparent 2.5px);
}

.status[data-status="completed"]::before,
.status[data-status="failed"]::before,
.status[data-status="cancelled"]::before,
.status[data-status="deleted"]::before,
.status[data-status="paused"]::before,
.status[data-status="stopping"]::before {
  width: 14px;
  height: 14px;
  border-radius: 0;
  -webkit-mask: var(--glyph) center / contain no-repeat;
  mask: var(--glyph) center / contain no-repeat;
}

.status[data-status="completed"]::before { --glyph: var(--i-check); background: var(--status-completed); }
.status[data-status="failed"]::before { --glyph: var(--i-alert-solid); background: var(--status-failed); }
.status[data-status="cancelled"]::before { --glyph: var(--i-slash); background: var(--status-cancelled); }
.status[data-status="deleted"]::before { --glyph: var(--i-archive); background: var(--status-deleted); }
.status[data-status="paused"]::before { --glyph: var(--i-pause); background: var(--attention); }
.status[data-status="stopping"]::before { --glyph: var(--i-stop); background: var(--attention); }

.status[data-status="failed"] { color: var(--danger); }
.status[data-status="cancelled"],
.status[data-status="deleted"] { color: var(--text-2); }
.status[data-status="paused"],
.status[data-status="stopping"] { color: var(--attention-ink); }

.status--sm { font-size: var(--text-12); }

/* ---- Pastilles ---- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--text-12);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}

.badge--accent { border-color: transparent; background: var(--accent-tint); color: var(--accent-strong); }
.badge--attention { border-color: transparent; background: var(--attention-tint); color: var(--attention-ink); }
.badge--danger { border-color: transparent; background: var(--danger-tint); color: var(--danger-strong); }
.badge--quiet { border-color: transparent; background: var(--surface-sunken); color: var(--text-2); }

/* Niveau d'offre d'une target (scenario lite, pro, business) : remplissage gradué. */
.tier {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  color: var(--text-2);
  font-family: var(--font-display);
  font-size: var(--text-12);
  font-weight: 600;
  line-height: 1;
}

.tier[data-tier="pro"] { border-color: transparent; background: var(--surface-sunken); color: var(--text); }
.tier[data-tier="business"] { border-color: var(--text); background: var(--text); color: var(--surface); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  height: 24px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-sunken);
  font-size: var(--text-12);
}

.tag__key { color: var(--text-3); }
.tag__value { overflow: hidden; color: var(--text); text-overflow: ellipsis; white-space: nowrap; }

/* Puce d'état de la barre supérieure (Planificateur) et puces cliquables. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-14);
  text-decoration: none;
  white-space: nowrap;
}

.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip__label { color: var(--chip-label); }
.chip--attention { border-color: transparent; background: var(--attention-tint); color: var(--attention-ink); }

.freshness {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-3);
  font-size: var(--text-12);
}

.freshness::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.freshness--stale::before { background: var(--attention); }

/* ---- Panneaux et mises en page ---- */

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.panel__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel__title { font-size: var(--text-16); }

.panel__subtitle {
  color: var(--text-3);
  font-size: var(--text-12);
  line-height: 16px;
}

.panel__body { padding: var(--space-5); }
.panel__body--flush { padding: 0; }

.panel__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
}

.grid { display: grid; align-items: start; gap: var(--space-5); }
.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid--side-main { grid-template-columns: 240px minmax(0, 1fr); }

.section { display: flex; flex-direction: column; gap: var(--space-4); }
.section + .section { margin-top: var(--space-6); }

.divider { height: 1px; margin: 0; border: 0; background: var(--border); }

/* ---- Tableaux ---- */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.table th {
  position: sticky;
  top: var(--topbar-height);
  z-index: 1;
  height: 36px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  color: var(--text-3);
  font-size: var(--text-12);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

/* Un .table-wrap défile horizontalement : il devient le conteneur de défilement de l'en-tête
   collant, qui se colle alors à son bord haut. Le décalage de la barre supérieure y ferait
   recouvrir la première ligne par l'en-tête. */
.table-wrap .table th { top: 0; }

.table td {
  height: var(--row-height);
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-hover); }
.table tr[aria-selected="true"] td { background: var(--accent-tint); }
/* Sur la ligne sélectionnée, la pastille d'accent prendrait la teinte de la ligne : elle garde un fond distinct. */
.table tr[aria-selected="true"] .badge--accent { background: var(--surface); }
.table .is-num { text-align: right; font-variant-numeric: tabular-nums; }
.table .is-actions { width: 1%; text-align: right; white-space: nowrap; }
.table--compact td { height: 36px; padding-top: 4px; padding-bottom: 4px; }

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
}

.th-sort:hover { color: var(--text); }
th[aria-sort="ascending"] .th-sort,
th[aria-sort="descending"] .th-sort { color: var(--text); }

.cell-title {
  color: var(--text);
  font-weight: 500;
  text-decoration: none;
}

a.cell-title:hover { color: var(--accent-strong); text-decoration: underline; }

.cell-sub {
  display: block;
  color: var(--text-3);
  font-size: var(--text-12);
  line-height: 16px;
}

/* ---- Onglets, segments, barre de filtres ---- */

.tabs {
  display: flex;
  gap: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text-2);
  font-weight: 500;
  text-decoration: none;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }

.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: -1px;
  left: 0;
  height: 2px;
  background: var(--accent);
}

.tab__count {
  color: var(--text-3);
  font-size: var(--text-12);
  font-variant-numeric: tabular-nums;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-sunken);
}

.segmented button {
  height: 26px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--text-12);
  font-weight: 500;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(22, 32, 30, 0.12);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

/* ---- Formulaires ---- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4) var(--space-5);
}

.form-grid .span-2 { grid-column: 1 / -1; }

.form-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

.form-section:first-child { padding-top: 0; border-top: 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field__label { color: var(--text); font-weight: 500; }
.field__optional { color: var(--text-3); font-weight: 400; }

.field__hint {
  color: var(--text-3);
  font-size: var(--text-12);
  line-height: 16px;
}

.field__error {
  display: flex;
  gap: 4px;
  color: var(--danger);
  font-size: var(--text-12);
  line-height: 16px;
}

.input,
.select,
.textarea {
  width: 100%;
  height: var(--control-height);
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--text);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: var(--space-2) 10px;
  font-family: var(--font-mono);
  font-size: var(--text-12);
  line-height: 18px;
  resize: vertical;
}

.input::placeholder,
.textarea::placeholder { color: var(--text-3); }

.input:hover,
.select:hover,
.textarea:hover { border-color: var(--text-3); }

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.input[readonly] { background: var(--surface-sunken); color: var(--text-2); }
.field--error .input,
.field--error .select,
.field--error .textarea { border-color: var(--danger); }

.select { appearance: none; padding-right: 32px; }

.select-wrap,
.input-icon { position: relative; }

.select-wrap::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 10px;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  background: var(--text-3);
  -webkit-mask: var(--i-chevron-down) center / contain no-repeat;
  mask: var(--i-chevron-down) center / contain no-repeat;
  pointer-events: none;
}

.input-icon > .icon {
  position: absolute;
  top: 50%;
  left: 10px;
  margin-top: -8px;
  color: var(--text-3);
}

.input-icon > .input { padding-left: 32px; }

.switch {
  position: relative;
  flex: none;
  width: 32px;
  height: 18px;
  margin: 0;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  appearance: none;
}

.switch::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform var(--duration-fast) var(--ease-out);
}

.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(14px); }

.checkbox {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.listbox {
  display: flex;
  flex-direction: column;
  max-height: 280px;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-popover);
  list-style: none;
}

.option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 3px;
}

.option[aria-selected="true"],
.option:hover { background: var(--surface-hover); }

/* ---- Sélection avancée : recherche, saisie assistée, tri, présélection ----
 * Un champ (.combobox__control) et une liste (.listbox) groupée ; une option montre ce qui
 * distingue deux homonymes (.option__sub, .option__meta). */

.combobox { position: relative; }

.combobox__control {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 6px 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--surface);
}

.combobox__control:hover { border-color: var(--text-3); }

.combobox__control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.combobox__control > .icon { flex: none; color: var(--text-3); }

.combobox__control > input {
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--control-height) - 2px);
  padding: 0;
  border: 0;
  background: transparent;
  outline: none;
}

/* Le champ porte déjà l'anneau de focus du contrôle. */
.combobox__control > input:focus-visible { box-shadow: none; }

/* Saisie assistée : la partie proposée suit le texte saisi, à l'encre secondaire. Balisage :
   .combobox__control > input + .combobox__completion. Le champ suivi d'une complétion prend la
   largeur de son texte et la complétion, collée à lui (l'écart du contrôle est annulé), le reste
   du contrôle ; sinon le champ occupe toute la largeur et la complétion part au bord droit. */
.combobox__control > input:has(+ .combobox__completion) {
  flex: none;
  min-width: 1ch;
  field-sizing: content;
}

.combobox__completion {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--text-3);
  white-space: nowrap;
}

.combobox__control > input + .combobox__completion { margin-left: calc(-1 * var(--space-2)); }

.combobox__panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  left: 0;
  z-index: calc(var(--z-sticky) + 1);
}

.listbox__group {
  padding: var(--space-2) 10px var(--space-1);
  color: var(--text-3);
  font-size: var(--text-12);
  line-height: 16px;
}

.option__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.option__title {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.option__sub { color: var(--text-3); font-size: var(--text-12); line-height: 16px; }

.option__meta {
  display: flex;
  flex: none;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-3);
  font-size: var(--text-12);
}

.option mark { background: transparent; color: var(--accent-strong); font-weight: 600; }
.option[aria-selected="true"] { box-shadow: inset 2px 0 0 var(--accent); }

.listbox__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin: var(--space-1) calc(-1 * var(--space-1)) calc(-1 * var(--space-1));
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: var(--text-12);
}

/* ---- Listes de valeurs ---- */

.kv {
  display: grid;
  grid-template-columns: minmax(120px, max-content) minmax(0, 1fr);
  gap: var(--space-2) var(--space-5);
  margin: 0;
}

.kv dt { color: var(--text-3); line-height: 20px; }
.kv dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }

.facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
}

.fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fact__label { color: var(--text-3); font-size: var(--text-12); line-height: 16px; }
.fact__value { font-size: var(--text-16); font-weight: 500; font-variant-numeric: tabular-nums; }

.figure {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.figure__value {
  font-family: var(--font-display);
  font-size: var(--text-36);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.figure__unit { color: var(--text-3); font-size: var(--text-16); font-weight: 500; }
.figure__label { color: var(--text-3); font-size: var(--text-12); }

.copy-id {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
}

/* ---- Progression ---- */

.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.progress__track {
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  box-shadow: inset 0 0 0 1px var(--border);
}

.progress__bar {
  width: var(--value, 0%);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.progress--attention .progress__bar { background: var(--attention); }
.progress--danger .progress__bar { background: var(--danger); }

/* Compteurs inconnus (exécution legacy non convertie) : rayures, aucune valeur inventée. */
.progress--unknown .progress__track {
  background: repeating-linear-gradient(135deg, var(--surface-sunken) 0 6px, var(--border) 6px 8px);
}

.progress--unknown .progress__bar { display: none; }

.progress__label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--text-3);
  font-size: var(--text-12);
  line-height: 16px;
  font-variant-numeric: tabular-nums;
}

.progress__label strong { color: var(--text); font-weight: 600; }

/* ---- Chaîne de production : quatre emplacements d'exécution ---- */

.bays {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.bay {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
  min-height: 212px;
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-right: 1px solid var(--border);
}

.bay:last-child { border-right: 0; }

.bay__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.bay__elapsed {
  color: var(--text-3);
  font-size: var(--text-12);
  font-variant-numeric: tabular-nums;
}

.bay__title {
  overflow: hidden;
  font-family: var(--font-display);
  font-size: var(--text-21);
  font-weight: 600;
  line-height: var(--leading-snug);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bay__client { color: var(--text-2); }

.bay__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: auto;
}

.bay--stopping { background: linear-gradient(var(--attention-tint), var(--attention-tint)) top / 100% 3px no-repeat; }
.bay--running { background: linear-gradient(var(--accent), var(--accent)) top / 100% 3px no-repeat; }

.bay--idle {
  align-items: flex-start;
  justify-content: center;
  background: repeating-linear-gradient(135deg, transparent 0 10px, var(--surface-sunken) 10px 12px);
  color: var(--text-3);
}

/* ---- File d'attente FIFO : la position est une vraie séquence ---- */

.queue { list-style: none; }

.queue__item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.queue__item:last-child { border-bottom: 0; }

.queue__position {
  color: var(--text-3);
  font-family: var(--font-display);
  font-size: var(--text-16);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.queue__main { display: flex; flex-direction: column; min-width: 0; }
.queue__side { display: flex; align-items: center; gap: var(--space-2); }

/* ---- Registre des comptes par statut ---- */

.ledger {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.ledger__cell {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-4) var(--space-5);
  border-right: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}

.ledger__cell:last-child { border-right: 0; }
a.ledger__cell:hover { background: var(--surface-hover); }

.ledger__value {
  font-family: var(--font-display);
  font-size: var(--text-24);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ledger__note { color: var(--text-3); font-size: var(--text-12); line-height: 16px; }

/* ---- Échéancier et listes ---- */

.timeline { list-style: none; }

.timeline__item {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.timeline__item:last-child { border-bottom: 0; }

.timeline__date {
  display: flex;
  flex-direction: column;
  font-variant-numeric: tabular-nums;
}

.timeline__day { font-weight: 500; }
.timeline__time { color: var(--text-3); font-size: var(--text-12); line-height: 16px; }

.list { list-style: none; }

.list__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

.list__item:last-child { border-bottom: 0; }

/* ---- États : vide, erreur, chargement, alertes ---- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-5);
}

.empty > .icon { color: var(--text-3); }
.empty__title { font-family: var(--font-display); font-size: var(--text-16); font-weight: 600; }
.empty__text { color: var(--text-2); }
.empty__actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }

.alert {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  gap: var(--space-1) var(--space-3);
  align-items: start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface-sunken);
}

.alert > .icon { margin-top: 2px; color: var(--text-3); }
.alert__title { font-weight: 600; }
.alert__text { grid-column: 2; color: var(--text-2); }
.alert__actions { grid-column: 2; display: flex; gap: var(--space-3); margin-top: var(--space-1); }

.alert--attention { border-color: var(--attention); background: var(--attention-tint); }
.alert--attention > .icon { color: var(--attention-ink); }
.alert--danger { border-color: var(--danger); background: var(--danger-tint); }
.alert--danger > .icon { color: var(--danger); }
.alert--accent { border-color: transparent; background: var(--accent-tint); }
.alert--accent > .icon { color: var(--accent); }

.skeleton {
  display: block;
  height: 12px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--surface-sunken) 0%, var(--surface-hover) 50%, var(--surface-sunken) 100%);
  background-size: 200% 100%;
  animation: skeleton-sweep 1.4s linear infinite;
}

.skeleton--title { height: 20px; }
.skeleton--line { height: 12px; }
.skeleton--block { height: 72px; }

@keyframes skeleton-sweep {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ---- Code et JSON ---- */

.code {
  max-height: 360px;
  margin: 0;
  padding: var(--space-3) var(--space-4);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface-sunken);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--text-12);
  line-height: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code .k { color: var(--accent-strong); }
.code .s { color: var(--text); }
.code .n { color: var(--attention-ink); }

/* ---- Surcouches : dialogue, menu, info-bulle ---- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: var(--z-dialog);
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: var(--scrim);
}

.dialog {
  display: flex;
  flex-direction: column;
  width: min(520px, 100%);
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius-overlay);
  background: var(--surface);
  box-shadow: var(--shadow-overlay);
}

.dialog--wide { width: min(720px, 100%); }

.dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4) var(--space-3) var(--space-5);
}

.dialog__title { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-18); }
.dialog--danger .dialog__title > .icon { color: var(--danger); }
.dialog--attention .dialog__title > .icon { color: var(--attention); }

.dialog__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: 0 var(--space-5) var(--space-5);
  overflow-y: auto;
}

.dialog__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius-overlay) var(--radius-overlay);
  background: var(--surface-sunken);
}

/* Conséquences d'une action, listées avant confirmation. */
.impact {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-control);
  background: var(--surface-sunken);
  list-style: none;
}

.impact li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: var(--space-2); }
.impact .icon { margin-top: 2px; color: var(--text-3); }

.menu {
  display: flex;
  flex-direction: column;
  min-width: 200px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-popover);
  color: var(--text);
  list-style: none;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 3px;
  background: none;
  color: var(--text);
  text-align: left;
  text-decoration: none;
}

.menu__item:hover { background: var(--surface-hover); color: var(--text); }
.menu__item .icon { color: var(--text-3); }
.menu__item--danger,
.menu__item--danger .icon { color: var(--danger); }
.menu__label { padding: 6px 10px 2px; color: var(--text-3); font-size: var(--text-12); }
.menu__separator { height: 1px; margin: 4px 0; background: var(--border); }

.tooltip {
  display: inline-block;
  max-width: 280px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--text);
  color: var(--surface);
  font-size: var(--text-12);
  line-height: 16px;
}

/* ---- Pagination ---- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  color: var(--text-2);
}

.pagination__range { font-variant-numeric: tabular-nums; }
.pagination__controls { display: flex; align-items: center; gap: var(--space-2); }

/* ---- Accordéons et navigation de sections ---- */

.disclosure { border-bottom: 1px solid var(--border); }

.disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) 0;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.disclosure > summary::-webkit-details-marker { display: none; }

.disclosure > summary::after {
  content: "";
  flex: none;
  width: 16px;
  height: 16px;
  background: var(--text-3);
  -webkit-mask: var(--i-chevron-down) center / contain no-repeat;
  mask: var(--i-chevron-down) center / contain no-repeat;
  transition: transform var(--duration-fast) var(--ease-out);
}

.disclosure[open] > summary::after { transform: rotate(180deg); }
.disclosure__body { padding: 0 0 var(--space-4); }

.section-nav {
  position: sticky;
  top: calc(var(--topbar-height) + var(--space-5));
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-self: start;
}

.section-nav a {
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--text-2);
  text-decoration: none;
}

.section-nav a:hover { background: var(--surface-hover); color: var(--text); }
.section-nav a[aria-current="true"] { background: var(--accent-tint); color: var(--accent-strong); }

/* ---- Adaptation à la largeur ---- */

/* Tableau de bord et bilans en cours dans une colonne principale resserrée (conteneur « supervision », screens.css) :
   emplacements en 2 × 2, comptes sur trois colonnes, colonnes empilées. Placé avant les règles de fenêtre, qui gardent
   le dernier mot sous 640 px (une colonne). */
@container supervision (max-width: 900px) {
  .bays { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bay:nth-child(2n) { border-right: 0; }
  .bay:nth-child(-n + 2) { border-bottom: 1px solid var(--border); }
  .ledger { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ledger__cell:nth-child(3n) { border-right: 0; }
  .ledger__cell:nth-child(-n + 3) { border-bottom: 1px solid var(--border); }
  .grid--main-side { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1180px) {
  .grid--2,
  .grid--3,
  .grid--main-side,
  .grid--side-main { grid-template-columns: minmax(0, 1fr); }

  .bays { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bay:nth-child(2n) { border-right: 0; }
  .bay:nth-child(-n + 2) { border-bottom: 1px solid var(--border); }
  .ledger { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .section-nav { position: static; flex-direction: row; flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .bays,
  .ledger,
  .form-grid { grid-template-columns: minmax(0, 1fr); }

  .bay { border-right: 0; border-bottom: 1px solid var(--border); }
  .ledger__cell { border-right: 0; border-bottom: 1px solid var(--border); }
  .dialog { width: 100%; }
  .pagination { flex-direction: column; align-items: flex-start; }
}
