/* Composants partagés par toutes les pages. */

/* ---------- Boutons ---------- */
.btn {
  --btn-bg: var(--popover);
  --btn-fg: var(--foreground);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--control-h);
  padding: 0 var(--sp-3);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition: transform var(--dur-press) var(--ease-out), background-color var(--dur-press) var(--ease-out);
}
.btn .icon { width: 16px; height: 16px; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; }
.btn--primary { --btn-bg: var(--secondary); --btn-fg: #fff; --btn-bd: var(--secondary); }
.btn--brand { --btn-bg: var(--primary); --btn-fg: var(--foreground); --btn-bd: var(--primary); }
.btn--danger { --btn-bg: var(--danger-text); --btn-fg: #fff; --btn-bd: var(--danger-text); }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn--quiet { --btn-bd: var(--border); }
.btn--sm { min-height: 28px; padding: 0 var(--sp-2); font-size: var(--fs-12); border-radius: var(--radius-xs); }
.btn--icon { width: var(--control-h); padding: 0; }
.btn--sm.btn--icon { width: 28px; }
.btn--block { width: 100%; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover:not(:disabled) { --btn-bg: var(--accent); }
  .btn--primary:hover:not(:disabled) { --btn-bg: color-mix(in srgb, var(--secondary) 86%, #fff); }
  .btn--brand:hover:not(:disabled) { --btn-bg: color-mix(in srgb, var(--primary) 88%, #000); }
  .btn--danger:hover:not(:disabled) { --btn-bg: color-mix(in srgb, var(--danger-text) 88%, #000); }
}
.btn[aria-busy="true"] { position: relative; color: transparent; pointer-events: none; }
.btn[aria-busy="true"]::after {
  content: "";
  position: absolute;
  width: 16px; height: 16px;
  border: 2px solid var(--btn-fg);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.btn-row--end { justify-content: flex-end; }
.btn-row .spacer { flex: 1; }

/* ---------- Champs ---------- */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.field > label, .field > .label, legend.label { font-weight: 500; }
.field .req { color: var(--danger-text); margin-left: 2px; }
.field .hint { color: var(--text-muted); font-size: var(--fs-12); }
.field .error { color: var(--danger-text); font-size: var(--fs-12); font-weight: 500; }
.field .error:empty { display: none; }

.input, .select, .textarea {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--input);
  color: var(--foreground);
  transition: background-color var(--dur-press) var(--ease-out);
}
.textarea { padding: var(--sp-2) var(--sp-3); min-height: 84px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230f1419' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
}
.input:focus, .select:focus, .textarea:focus { background-color: #fff; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--destructive); border-width: 2px; }
.input:read-only:not([type="date"]):not(.input--search), .textarea:read-only { background: var(--card); border-style: dashed; }
.input:disabled, .select:disabled, .textarea:disabled { opacity: .45; }
.input--num { text-align: right; font-variant-numeric: tabular-nums; }
.input--sm { min-height: 30px; padding: 0 var(--sp-2); font-size: var(--fs-14); border-radius: var(--radius-xs); }
.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group > .addon {
  display: inline-flex; align-items: center; padding: 0 var(--sp-3);
  border: 1px solid var(--border-strong); border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--card); color: var(--text-muted); white-space: nowrap;
}
.search-box { position: relative; min-width: 0; }
.search-box .icon { position: absolute; left: 10px; top: 50%; translate: 0 -50%; width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.search-box .input { padding-left: 34px; }

@media (pointer: coarse) {
  .input, .select, .textarea { font-size: var(--fs-16); }
}

.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; min-height: 28px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: none; }
.check--block { display: flex; }

fieldset { border: 0; padding: 0; min-width: 0; }
.form-section { display: grid; gap: var(--sp-4); padding-block: var(--sp-5); border-bottom: 1px solid var(--border); }
.form-section:first-child { padding-top: 0; }
.form-section:last-of-type { border-bottom: 0; }
.form-section > legend, .form-section > h2 { font-size: var(--fs-16); font-weight: 600; padding: 0; margin-bottom: var(--sp-1); }
.form-section > legend + * { margin-top: 0; }
.form-grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 767px) { .form-grid .span-2 { grid-column: auto; } }
.form-errors {
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--destructive);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--destructive) 8%, #fff);
}
.form-errors ul { padding-left: var(--sp-5); }

/* ---------- Pastilles de statut ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--tint, var(--muted));
  color: var(--foreground);
  font-size: var(--fs-12);
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
}
.pill::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--tone, var(--border-strong));
  flex: none;
}
.pill--plain::before { display: none; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px;
  border: 1px solid var(--border); border-radius: var(--radius-xs);
  font-size: var(--fs-12); color: var(--text-muted); white-space: nowrap; background: #fff;
}
.tag--demo { border-color: var(--chart-3); color: var(--foreground); background: color-mix(in srgb, var(--chart-3) 12%, #fff); }
.trade-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--trade, var(--border-strong)); flex: none; }

/* ---------- Cartes ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  min-width: 0;
}
.card--white { background: #fff; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-3); min-height: 28px; }
.card__head h2, .card__head h3 { font-size: var(--fs-14); font-weight: 600; }
.card__head .sub { color: var(--text-muted); font-size: var(--fs-12); }
.card__head .actions { margin-left: auto; display: flex; gap: var(--sp-2); align-items: center; }
.card--flush > .card__head { padding: var(--sp-3) var(--sp-4) 0; }

/* Description lists */
.dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--sp-2) var(--sp-4); }
.dl dt { color: var(--text-muted); }
.dl dd { min-width: 0; overflow-wrap: anywhere; }
.dl--stack { grid-template-columns: 1fr; gap: 2px; }
.dl--stack dd { margin-bottom: var(--sp-2); }

/* ---------- KPI ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
@media (max-width: 1023px) { .stat-strip { --cols: 2 !important; } }
@media (max-width: 559px) { .stat-strip { --cols: 1 !important; } }
.stat {
  display: grid;
  align-content: start;
  gap: 6px;
  padding: var(--sp-4);
  background: var(--card);
  min-width: 0;
  text-decoration: none;
}
a.stat:hover { background: var(--accent); }
.stat__label { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-weight: 500; }
.stat__label .icon { width: 16px; height: 16px; }
.stat__value { font-size: var(--fs-24); font-weight: 600; letter-spacing: -.02em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stat__value--hero { font-size: var(--fs-32); }
.stat__foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--text-muted); font-size: var(--fs-12); }
.stat__value .unknown { color: var(--text-muted); font-weight: 500; font-size: var(--fs-16); letter-spacing: 0; }

.delta {
  display: inline-flex; align-items: center; gap: 3px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--tint, var(--muted)); color: var(--foreground);
  font-size: var(--fs-12); font-weight: 500; font-variant-numeric: tabular-nums;
}
.delta .icon { width: 12px; height: 12px; color: var(--tone, var(--foreground)); stroke-width: 2.5; }

/* Chiffres roulants (references-21st §4, option B) */
@property --d { syntax: "<number>"; inherits: true; initial-value: 0; }
.nr {
  display: inline-flex; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums;
  padding-block: .2em; margin-block: -.2em;
  mask-repeat: no-repeat;
  -webkit-mask-image: linear-gradient(transparent, #000 .2em, #000 calc(100% - .2em), transparent);
  mask-image: linear-gradient(transparent, #000 .2em, #000 calc(100% - .2em), transparent);
}
.nr__d, .nr__s { display: inline-block; position: relative; overflow-x: clip; }
.nr__d { --c: calc(var(--v) + var(--d)); }
.nr__d > span { display: inline-block; --o: calc(mod(var(--n) - var(--c) + 5, 10) - 5); transform: translateY(clamp(-100%, var(--o) * 100%, 100%)); opacity: calc(1 - clamp(0, var(--o), 1) - clamp(0, -1 * var(--o), 1)); }
.nr__d > span:not(:first-child) { position: absolute; inset: 0; }
.nr__s { white-space: pre; }

/* Barre empilée par métier ou par poste */
.alloc { display: flex; gap: 2px; height: 10px; border-radius: 999px; overflow: hidden; background: var(--muted); }
.alloc > span { flex-grow: var(--w); flex-basis: 0; background: var(--c); min-width: 3px; }
.legend { display: grid; gap: var(--sp-2); margin-top: var(--sp-3); }
.legend li { display: grid; grid-template-columns: auto 1fr auto auto; gap: var(--sp-2); align-items: center; list-style: none; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.legend .v { font-variant-numeric: tabular-nums; font-weight: 500; }
.legend .p { font-variant-numeric: tabular-nums; color: var(--text-muted); min-width: 3.5em; text-align: right; }
ul.legend { padding: 0; }

/* Barre de progression */
progress.bar {
  appearance: none; width: 100%; height: 6px; border: 0; border-radius: 999px;
  background: var(--muted); overflow: hidden; color: var(--primary);
}
progress.bar::-webkit-progress-bar { background: var(--muted); border-radius: 999px; }
progress.bar::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress.bar::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
.progress-cell { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-2); align-items: center; min-width: 110px; }

/* ---------- Graphiques ---------- */
.chart-card { margin: 0; display: flex; flex-direction: column; }
.chart-card figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); }
.chart-card figcaption h2 { font-size: var(--fs-14); font-weight: 600; }
.chart-card figcaption .sub { color: var(--text-muted); font-size: var(--fs-12); flex-basis: 100%; order: 3; }
.chart-card figcaption .actions { margin-left: auto; display: flex; gap: var(--sp-2); }
/* La zone de tracé occupe la hauteur laissée par la carte voisine (grille), jamais moins que --h. */
.chart-box { position: relative; flex: 1 0 auto; height: var(--h, 240px); min-height: var(--h, 240px); }
.chart-card:has(.chart-table:not([hidden])) .chart-box { flex-grow: 0; }
.chart-box canvas { width: 100% !important; height: 100% !important; }
.chart-box[aria-busy="true"] canvas { opacity: .45; }
.chart-table { margin-top: var(--sp-3); }
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-2); margin: calc(-1 * var(--sp-1)) 0 var(--sp-2) calc(-1 * var(--sp-2)); font-size: var(--fs-12); color: var(--foreground); }
.chart-legend span, .chart-legend .btn { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .btn { font-size: var(--fs-12); font-weight: 500; min-height: 28px; }
.chart-legend .btn[aria-pressed="false"] { color: var(--text-muted); text-decoration: line-through; }
.chart-legend .btn[aria-pressed="false"] i { opacity: .35; }
.chart-box > div { position: absolute; inset: 0; display: grid; place-items: center; }
.chart-box > div[hidden] { display: none; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.chart-legend i.line { height: 2px; border-radius: 1px; }
.chart-legend i.dash { height: 0; border-top: 2px dashed var(--c); background: none; }

/* ---------- Segmented et toggles ---------- */
.segmented {
  position: relative;
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  padding: 2px;
  border-radius: var(--radius-sm);
  background: var(--muted);
  isolation: isolate;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.segmented label { position: relative; z-index: 1; display: grid; place-items: center; min-height: 28px; padding: 0 var(--sp-3); border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; color: var(--text-muted); }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { color: var(--foreground); background: #fff; box-shadow: 0 1px 2px rgb(15 20 25 / .12); }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--foreground); outline-offset: 1px; }
@media (pointer: coarse) { .segmented label { min-height: 40px; } }

.toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 var(--sp-3);
  border: 1px solid var(--border); border-radius: 999px; background: #fff; color: var(--foreground);
  font-weight: 500; font-size: var(--fs-12); white-space: nowrap;
}
.toggle .icon { width: 14px; height: 14px; }
.toggle[aria-pressed="true"] { background: var(--secondary); border-color: var(--secondary); color: #fff; }
.toggle .count { font-variant-numeric: tabular-nums; color: inherit; opacity: .75; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
  padding: 0 var(--sp-3); color: var(--text-muted); font-weight: 500; white-space: nowrap; text-decoration: none;
}
.tab .count { font-size: var(--fs-12); font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 999px; background: var(--muted); color: var(--foreground); }
.tab[aria-selected="true"], .tab[aria-current="page"] { color: var(--foreground); }
.tab[aria-selected="true"]::after, .tab[aria-current="page"]::after {
  content: ""; position: absolute; left: var(--sp-3); right: var(--sp-3); bottom: -1px; height: 2px; background: var(--foreground); border-radius: 2px;
}
@media (hover: hover) and (pointer: fine) { .tab:hover { color: var(--foreground); } }
.tab-panel { padding-top: var(--sp-5); }
.tab-panel:focus-visible { outline-offset: 4px; }

/* ---------- Tableaux ---------- */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius-md); background: #fff; min-width: 0; }
/* overflow-x crée un conteneur de défilement : l'en-tête collant s'y rapporte, pas à la fenêtre (pas de décalage de la barre du haut). */
.table-wrap--scroll { overflow-x: auto; --sticky-top: 0px; }
.table { width: 100%; font-variant-numeric: tabular-nums; }
.table th, .table td { height: var(--row-h); padding: 0 var(--sp-3); text-align: left; border-bottom: 1px solid var(--border); line-height: 1.4; }
.table td { padding-block: 6px; }
.table thead th {
  position: sticky; top: var(--sticky-top, 0); z-index: var(--z-sticky);
  background: var(--card); color: var(--text-muted); font-weight: 500; font-size: var(--fs-12); white-space: nowrap;
}
.table-wrap > .table thead th:first-child { border-top-left-radius: var(--radius-md); }
.table-wrap > .table thead th:last-child { border-top-right-radius: var(--radius-md); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tfoot td { background: var(--card); font-weight: 600; border-bottom: 0; border-top: 1px solid var(--border); }
.table .num, .table th.num { text-align: right; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; width: 1%; }
.table .shrink { width: 1%; white-space: nowrap; }
.table .cell-main { font-weight: 500; }
.table .cell-sub { display: block; color: var(--text-muted); font-size: var(--fs-12); font-weight: 400; }
.table a.row-link { text-decoration: none; font-weight: 500; }
.table a.row-link::after { content: ""; position: absolute; inset: 0; }
.table tbody tr { position: relative; }
@media (hover: hover) and (pointer: fine) {
  .table tbody tr:hover td { background: var(--accent); }
  .table a.row-link:hover { text-decoration: underline; text-decoration-color: var(--primary); text-decoration-thickness: 2px; text-underline-offset: 3px; }
}
.table tbody tr:focus-within td { background: var(--accent); }
.table .actions .btn, .table .actions a, .table .actions button { position: relative; z-index: 1; }
.table th[aria-sort] { padding: 0; }
.table th .sort {
  display: inline-flex; align-items: center; gap: 4px; width: 100%; height: var(--row-h); padding: 0 var(--sp-3);
  font: inherit; color: inherit; justify-content: inherit;
}
.table th.num .sort { justify-content: flex-end; }
.table th .sort .icon { width: 12px; height: 12px; opacity: .4; }
.table th[aria-sort="ascending"] .sort .icon, .table th[aria-sort="descending"] .sort .icon { opacity: 1; color: var(--foreground); }
.table th[aria-sort="descending"] .sort .icon { transform: rotate(180deg); }
.table--compact th, .table--compact td { height: 32px; padding-inline: var(--sp-2); }
.table--plain { background: transparent; }

.table-foot { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--border); color: var(--text-muted); font-size: var(--fs-12); }
.table-foot .btn-row { margin-left: auto; }

/* Liste en cartes sous 768px pour les tableaux marqués .table--cards */
@media (max-width: 767px) {
  .table--cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; width: 100%; }
  .table--cards tbody tr { padding: var(--sp-3); border-bottom: 1px solid var(--border); }
  .table--cards tbody tr:last-child { border-bottom: 0; }
  .table--cards td { height: auto; padding: 2px 0; border: 0; text-align: left !important; }
  .table--cards td[data-label]:not(.cell-primary)::before { content: attr(data-label) " : "; color: var(--text-muted); }
  .table--cards td.actions { width: auto; padding-top: var(--sp-2); }
  .table--cards td:empty { display: none; }
  .table--cards tfoot { display: block; }
  .table--cards tfoot tr { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding: var(--sp-3); }
  .table--cards tfoot td { display: inline; }
}

/* ---------- Dialogues ---------- */
dialog {
  border: 0;
  padding: 0;
  color: var(--foreground);
  background: #fff;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px);
}
dialog::backdrop { background: rgb(15 20 25 / .4); }
.modal {
  width: min(560px, calc(100vw - 32px));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-float);
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-modal) var(--ease-out), transform var(--dur-modal) var(--ease-out), overlay var(--dur-modal) allow-discrete, display var(--dur-modal) allow-discrete;
}
.modal--wide { width: min(880px, calc(100vw - 32px)); }
.modal--narrow { width: min(420px, calc(100vw - 32px)); }
.modal:not([open]) { opacity: 0; transform: translateY(8px) scale(.98); }
@starting-style { .modal[open] { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal::backdrop { transition: opacity var(--dur-modal) var(--ease-out), overlay var(--dur-modal) allow-discrete, display var(--dur-modal) allow-discrete; }
.modal:not([open])::backdrop { opacity: 0; }
@starting-style { .modal[open]::backdrop { opacity: 0; } }
.modal__form { display: flex; flex-direction: column; max-height: calc(100dvh - 32px); }
.modal__head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal__head h2 { font-size: var(--fs-16); }
.modal__head .btn { margin-left: auto; }
.modal__body { padding: var(--sp-5); overflow-y: auto; display: grid; gap: var(--sp-4); }
.modal__foot { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end; padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--card); border-radius: 0 0 var(--radius-md) var(--radius-md); }
.modal__foot .spacer { flex: 1; }
.modal--confirm .modal__body { gap: var(--sp-2); }

/* ---------- Toasts ---------- */
.toaster {
  position: fixed; inset: auto var(--sp-4) var(--sp-4) auto; margin: 0; padding: 0; border: 0; background: transparent;
  display: grid; gap: var(--sp-2); width: min(380px, calc(100vw - 32px)); overflow: visible;
}
.toaster:not(:popover-open) { display: none; }
.toast {
  display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--secondary); color: #fff; border-radius: var(--radius-sm); box-shadow: var(--shadow-float);
  animation: toast-in var(--dur-modal) var(--ease-out);
}
.toast .icon { width: 18px; height: 18px; margin-top: 1px; }
.toast--good .icon { color: var(--chart-2); }
.toast--bad .icon { color: #ff8a93; }
.toast--warn .icon { color: var(--chart-3); }
.toast__msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast__action { color: #fff; font-weight: 600; text-decoration: underline; text-decoration-color: var(--primary); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.toast__close { color: #fff; opacity: .7; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Menus ---------- */
.menu {
  position: fixed; inset: auto; margin: 0; min-width: 200px; padding: 4px;
  border: 0; border-radius: var(--radius-sm); background: #fff; box-shadow: var(--shadow-float);
}
.menu:popover-open { display: grid; }
.menu button, .menu a {
  display: flex; align-items: center; gap: var(--sp-2); width: 100%; min-height: 34px; padding: 0 var(--sp-3);
  border-radius: 8px; text-align: left; text-decoration: none; color: var(--foreground); white-space: nowrap;
}
.menu .icon { width: 16px; height: 16px; color: var(--text-muted); }
.menu button:hover, .menu a:hover, .menu button:focus-visible, .menu a:focus-visible { background: var(--accent); box-shadow: none; outline: none; }
.menu .danger { color: var(--danger-text); }
.menu .danger .icon { color: var(--danger-text); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }

/* ---------- États ---------- */
.empty {
  position: relative;
  display: grid; justify-items: center; gap: var(--sp-2); padding: var(--sp-8) var(--sp-4);
  text-align: center; isolation: isolate;
}
.empty::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 24px 24px; background-position: center;
  -webkit-mask-image: radial-gradient(ellipse 50% 60% at 50% 40%, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse 50% 60% at 50% 40%, #000 0%, transparent 75%);
  opacity: .7;
}
.empty h2, .empty h3 { font-size: var(--fs-16); }
.empty p { color: var(--text-muted); max-width: 46ch; }
.empty .btn-row { margin-top: var(--sp-2); justify-content: center; }
.ring-ico {
  display: grid; place-items: center; width: 56px; height: 56px; margin-bottom: var(--sp-2);
  border-radius: 50%; background: #fff; color: var(--foreground);
  box-shadow: 0 0 0 1px var(--border), 0 0 0 8px color-mix(in srgb, var(--card) 90%, transparent), 0 0 0 9px var(--border);
}
.ring-ico .icon { width: 22px; height: 22px; }
.empty--compact { padding: var(--sp-5) var(--sp-3); }
.empty--compact::before { display: none; }

.notice {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-sm); background: var(--tint, var(--accent)); border: 1px solid color-mix(in srgb, var(--tone, var(--primary)) 35%, #fff);
}
.notice > .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--tone, var(--primary)); flex: none; }
.notice__body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.notice__body strong { font-weight: 600; }
.notice .btn-row { margin-top: var(--sp-2); }

.skeleton { display: block; border-radius: 6px; background: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
.skeleton--text { height: 12px; width: var(--w, 60%); }
.skeleton--value { height: 28px; width: var(--w, 50%); }
.skeleton--row { height: var(--row-h); }
@keyframes pulse { 50% { opacity: .55; } }

.spinner { width: 18px; height: 18px; border: 2px solid var(--border-strong); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }

/* Alertes du tableau de bord */
.alert-list { list-style: none; padding: 0; display: grid; }
.alert-list li + li { border-top: 1px solid var(--border); }
.alert-item { display: grid; grid-template-columns: auto 1fr auto; gap: var(--sp-3); align-items: start; padding: var(--sp-3) 0; text-decoration: none; }
.alert-item .dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: var(--tone); }
.alert-item .t { font-weight: 500; }
.alert-item .d { color: var(--text-muted); font-size: var(--fs-12); }
.alert-item .a { font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
a.alert-item:hover .t { text-decoration: underline; text-decoration-color: var(--primary); text-decoration-thickness: 2px; text-underline-offset: 3px; }

/* Activité */
.feed { list-style: none; padding: 0; display: grid; gap: var(--sp-3); }
.feed li { display: grid; grid-template-columns: 28px 1fr auto; gap: var(--sp-3); align-items: start; }
.feed .ico { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #fff; border: 1px solid var(--border); }
.feed .ico .icon { width: 14px; height: 14px; }
.feed time { color: var(--text-muted); font-size: var(--fs-12); white-space: nowrap; }

/* Heatmap Lun–Sam */
.heatmap { display: grid; grid-auto-flow: column; grid-template-rows: repeat(6, 12px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heatmap i { width: 12px; height: 12px; border-radius: 3px; background: var(--muted); }
.heatmap i[data-l="1"] { background: color-mix(in srgb, var(--primary) 30%, #fff); }
.heatmap i[data-l="2"] { background: color-mix(in srgb, var(--primary) 55%, #fff); }
.heatmap i[data-l="3"] { background: color-mix(in srgb, var(--primary) 80%, #fff); }
.heatmap i[data-l="4"] { background: var(--primary); }

/* Totaux de document */
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px var(--sp-6); margin-left: auto; width: min(100%, 360px); font-variant-numeric: tabular-nums; }
.totals dt { color: var(--text-muted); }
.totals dd { text-align: right; white-space: nowrap; }
.totals .grand { font-weight: 600; font-size: var(--fs-16); padding-top: 6px; border-top: 1px solid var(--border); color: var(--foreground); }

/* Éditeur de lignes (devis, factures, commandes) */
.lines { width: 100%; }
.lines th { font-size: var(--fs-12); color: var(--text-muted); font-weight: 500; text-align: left; padding: 6px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.lines td { padding: 4px 6px; vertical-align: top; border-bottom: 1px solid var(--border); }
.lines .num { text-align: right; }
.lines .row-section td { background: var(--card); }
.lines .row-section .input { font-weight: 600; }
.lines .row-text .input { color: var(--text-muted); }
.lines .handle { color: var(--text-muted); cursor: grab; }
.lines .total-cell { padding-top: 10px; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; font-weight: 500; }
@media (max-width: 1023px) {
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr { display: block; }
  .lines tr { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; padding: var(--sp-2) 0; border-bottom: 1px solid var(--border); }
  .lines td { border: 0; padding: 0; }
  .lines td.c-designation { grid-column: 1 / -1; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: var(--fs-12); color: var(--text-muted); }
  .lines .c-qty, .lines .c-unit, .lines .c-price { grid-column: span 2; }
  .lines .c-disc, .lines .c-vat { grid-column: span 2; }
  .lines .total-cell { grid-column: span 2; padding-top: 18px; }
  .lines .c-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 4px; }
}

/* Découpage en colonnes */
.cols { display: grid; gap: var(--sp-4); grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); }
@media (max-width: 1023px) { .cols { grid-template-columns: minmax(0, 1fr); } }
.cols--aside { grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1199px) { .cols--aside { grid-template-columns: minmax(0, 1fr); } }
.stack { display: grid; gap: var(--sp-4); align-content: start; min-width: 0; }
.stack--sm { gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; min-width: 0; }

/* Barre de filtres */
.filters { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.filters .search-box { flex: 1 1 240px; max-width: 360px; }
.filters .select { width: auto; min-width: 150px; }
.filters .spacer { flex: 1; }
.filters .count { color: var(--text-muted); font-size: var(--fs-12); }

/* Kanban simple */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: var(--sp-3); overflow-x: auto; padding-bottom: var(--sp-2); }
.kanban__col { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--sp-3); display: grid; gap: var(--sp-2); align-content: start; min-height: 120px; }
.kanban__col h3 { display: flex; align-items: center; justify-content: space-between; font-size: var(--fs-12); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kanban__card { display: grid; gap: 4px; padding: var(--sp-3); background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; }
.kanban__card:hover { border-color: var(--border-strong); }

/* Carte Leaflet */
.map { height: var(--h, 520px); border-radius: var(--radius-md); border: 1px solid var(--border); overflow: hidden; background: var(--card); z-index: 0; }
.map-pin { width: 14px; height: 14px; border-radius: 50%; background: var(--tone); border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(15 20 25 / .5); }
.leaflet-container { font: inherit; }
.leaflet-popup-content { margin: 12px 14px; font-size: var(--fs-14); line-height: 1.45; }
.leaflet-popup-content-wrapper { border-radius: var(--radius-sm); box-shadow: var(--shadow-float); }

/* Texte secondaire hors tableau */
.cell-sub { color: var(--text-muted); font-size: var(--fs-12); }

/* ======================================================================
   Bibliothèques partagées : éditeur de lignes, sélecteurs, documents,
   onglets et historique (lines.js, pickers.js, documents.js, tabs.js, history.js)
   ====================================================================== */

/* Éditeur de lignes */
.lines-editor { display: grid; gap: var(--sp-3); min-width: 0; }
.lines-wrap { min-width: 0; overflow-x: auto; }
.lines .select--sm { min-height: 30px; padding-left: var(--sp-2); padding-right: 28px; font-size: var(--fs-14); border-radius: var(--radius-xs); background-position: right 6px center; }
.lines .lines-desc { min-height: 30px; margin-top: 4px; padding: 4px var(--sp-2); font-size: var(--fs-12); border-radius: var(--radius-xs); }
.lines .lines-content { display: flex; gap: 4px; }
.lines .lines-content > .input { flex: 1 1 64px; min-width: 0; }
.lines .lines-content > .select { flex: 0 0 76px; }
.lines .lines-detail { margin-top: 4px; color: var(--text-muted); font-size: var(--fs-12); }
.lines .lines-detail:empty { display: none; }
.lines .lines-ro-desc { white-space: pre-line; }
.lines .row-deduction td { background: var(--card); }
.lines .row-deduction .total-cell { color: var(--text-muted); }
.lines .row-empty td { padding: var(--sp-4) 6px; color: var(--text-muted); text-align: center; }
.lines .c-actions { white-space: nowrap; }
.lines-add { justify-content: flex-start; }
.lines-hint { color: var(--text-muted); font-size: var(--fs-12); }
.lines-foot { display: grid; gap: var(--sp-2); justify-items: end; }
@media (min-width: 1024px) {
  .lines .c-qty, .lines .c-needed, .lines .c-ordered { width: 92px; }
  .lines .c-unit { width: 96px; }
  .lines .c-price { width: 124px; }
  .lines .c-disc { width: 84px; }
  .lines .c-vat { width: 96px; }
  .lines .c-content { width: 170px; }
  .lines .total-cell { width: 112px; }
  .lines .c-actions { width: 1%; }
}
@media (max-width: 1023px) {
  .lines td.c-full { grid-column: 1 / -1; }
  .lines--order .c-needed, .lines--order .c-ordered { grid-column: span 2; }
  .lines--order .c-content, .lines--order .c-price { grid-column: span 3; }
  .lines .row-empty td { text-align: left; padding: var(--sp-2) 0; }
}

/* Sélecteur d'entité (combobox) */
.picker__box { position: relative; display: flex; align-items: center; min-width: 0; }
.picker__box .picker__ico { position: absolute; left: 10px; width: 16px; height: 16px; color: var(--text-muted); pointer-events: none; }
.picker__input { padding-left: 34px; padding-right: 36px; text-overflow: ellipsis; }
.picker__clear { position: absolute; right: 4px; }
.picker__list {
  position: fixed; inset: auto; margin: 0; max-height: min(320px, 50vh); overflow-y: auto; padding: 4px; list-style: none;
  border: 0; border-radius: var(--radius-sm); background: #fff; box-shadow: var(--shadow-float); z-index: var(--z-overlay);
}
.picker__list:popover-open { display: grid; }
.picker__option { display: grid; gap: 2px; padding: 6px var(--sp-3); border-radius: 8px; cursor: pointer; }
.picker__option[aria-selected="true"] { background: var(--accent); }
@media (hover: hover) and (pointer: fine) { .picker__option:hover { background: var(--accent); } }
.picker__main { font-weight: 500; overflow-wrap: anywhere; }
.picker__sub { color: var(--text-muted); font-size: var(--fs-12); }
.picker__create { display: flex; align-items: center; gap: var(--sp-2); border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; margin-top: 2px; }
.picker__create .icon { color: var(--text-muted); }
.picker__status { display: flex; align-items: center; gap: var(--sp-2); padding: 8px var(--sp-3); color: var(--text-muted); font-size: var(--fs-12); }

/* Documents */
.doc-panel { display: grid; gap: var(--sp-3); min-width: 0; }
.doc-panel__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; }
.doc-panel__head h3 { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-16); }
.doc-panel__head .count:not(:empty) { font-size: var(--fs-12); font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 999px; background: var(--muted); font-weight: 500; }
.doc-drop {
  display: grid; justify-items: center; gap: 4px; padding: var(--sp-4); text-align: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius-md); background: var(--card); color: var(--text-muted);
  transition: background-color var(--dur-press) var(--ease-out), border-color var(--dur-press) var(--ease-out);
}
.doc-drop .icon { width: 20px; height: 20px; }
.doc-drop p { color: var(--foreground); }
.doc-drop .hint { color: var(--text-muted); font-size: var(--fs-12); }
.doc-drop[data-state="over"] { border-color: var(--foreground); border-style: solid; background: #fff; }
.doc-progress { list-style: none; padding: 0; display: grid; gap: 4px; }
.doc-progress:empty { display: none; }
.doc-progress li { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-muted); font-size: var(--fs-12); }
.doc-name { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.doc-name .icon { flex: none; color: var(--text-muted); }
.doc-name .link { text-align: left; overflow-wrap: anywhere; }

/* Onglets : jeu complet */
.tabset { display: grid; min-width: 0; }
.tab .count[hidden] { display: none; }
.tab .icon { width: 16px; height: 16px; }

/* Historique */
.history__feed > li { grid-template-columns: 28px minmax(0, 1fr) auto; }
.history__feed > li[data-action="delete"] .ico { color: var(--danger-text); }
.history__body { display: grid; gap: 2px; min-width: 0; }
.history__what { font-weight: 500; overflow-wrap: anywhere; }
.history__who { color: var(--text-muted); font-size: var(--fs-12); }
.history__changes { list-style: none; padding: 0; margin-top: 4px; display: grid; gap: 2px; font-size: var(--fs-12); }
.history__changes li { display: block; overflow-wrap: anywhere; }
.history__field { color: var(--text-muted); }
.history__before { text-decoration: line-through; text-decoration-color: var(--border-strong); color: var(--text-muted); }
.history__arrow { color: var(--text-muted); }
.history__after { color: var(--foreground); font-weight: 500; }
.history__more { margin-top: var(--sp-3); justify-content: center; }
@media (max-width: 767px) {
  .history__feed > li { grid-template-columns: 28px minmax(0, 1fr); }
  .history__feed > li > time { grid-column: 2; }
}
