/* Primitives d'interface : boutons, champs, pastilles, cartes, tableaux, retours visibles. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 15px/23px var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 24px; line-height: 32px; }
h2 { font-size: 18px; line-height: 26px; }
h3 { font-size: 15px; line-height: 22px; }
p, ul, ol { margin: 0; }
ul, ol { padding-left: 1.15em; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-underline-offset: 3px; }
small, .muted { color: var(--ink-muted); font-size: 12.5px; line-height: 18px; }
.mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* — Boutons — */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--control-border); background: var(--bg); color: var(--ink);
  font-size: 14px; line-height: 20px; font-weight: 500;
  transition: background .14s ease, border-color .14s ease, filter .14s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn--ghost { border-color: transparent; background: transparent; color: var(--ink-muted); }
.btn--ghost:hover { background: var(--surface-hover); color: var(--ink); }
.btn--danger { border-color: var(--danger); color: var(--danger); background: var(--bg); }
.btn--danger:hover { background: var(--danger-soft); }
.btn--sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn--icon { width: 38px; min-height: 38px; padding: 0; border-radius: 10px; }
.btn[disabled], .btn[aria-busy="true"] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; flex: none; }

/* — Champs — */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 13.5px; font-weight: 500; color: var(--ink); }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--control-border); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
.field textarea { resize: vertical; min-height: 90px; line-height: 22px; }
.input::placeholder { color: var(--ink-muted); opacity: .8; }
.field__hint { color: var(--ink-muted); font-size: 12px; line-height: 17px; }
.input--code {
  font-family: var(--mono); font-size: 22px; letter-spacing: .38em;
  text-align: center; padding-left: .38em;
}
.form-error { color: var(--danger); font-size: 13px; line-height: 19px; }

/* — Pastilles, jetons — */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-muted);
  font-size: 11.5px; line-height: 17px; font-weight: 600; white-space: nowrap;
}
.badge--ready { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge--pending { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge--error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.badge--dark { background: var(--logo-bg); border-color: transparent; color: var(--white); }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--border); font-size: 12px; color: var(--ink-muted);
}
.cite {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--ink-muted); font-size: 12px; line-height: 17px;
}
.cite:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.cite b { font-weight: 600; color: var(--ink); }
.cite:hover b { color: inherit; }

/* — Cartes, tableaux — */
.card { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--bg); }
.card__head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card__body { padding: 18px; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; color: var(--ink-muted); padding: 10px 12px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.list td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
table.list td.actions { text-align: right; white-space: nowrap; }
table.list td.actions .btn { margin-left: 6px; }
table.list input.input { min-height: 34px; padding: 4px 8px; font-size: 13px; }
.table-wrap { overflow-x: auto; }

/* — Bandeau d'erreur (jamais silencieux) — */
.banner {
  position: fixed; inset: 0 0 auto 0; z-index: 300;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 11px 18px; background: var(--danger); color: #fff;
  font-size: 14px; line-height: 20px; box-shadow: var(--shadow-menu);
}
[data-theme="dark"] .banner { color: #2B0B08; font-weight: 500; }
.banner__msg { flex: 1; }
.banner__close {
  width: 26px; height: 26px; display: grid; place-items: center;
  border-radius: 6px; color: inherit; opacity: .85; flex: none;
}
.banner__close:hover { opacity: 1; background: #FFFFFF26; }

/* — Toasts — */
#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px; z-index: 290;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  max-width: min(520px, 92vw); padding: 10px 16px; border-radius: 999px;
  background: var(--logo-bg); color: #fff; font-size: 13.5px; line-height: 20px;
  box-shadow: var(--shadow-dialog); animation: toast-in .18s ease-out;
}
.toast--error { background: var(--danger); }
[data-theme="dark"] .toast--error { color: #2B0B08; font-weight: 500; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* — Dialogues — */
dialog.sheet {
  width: min(520px, 94vw); padding: 0; border: 1px solid var(--border);
  border-radius: var(--radius-lg); background: var(--bg); color: var(--ink);
  box-shadow: var(--shadow-dialog);
}
dialog.sheet::backdrop { background: var(--scrim); }
.sheet__head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 22px 0; }
.sheet__head h2 { flex: 1; }
.sheet__body { padding: 16px 22px; }
.sheet__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; }

/* — Divers — */
.empty-state { padding: 40px 20px; text-align: center; color: var(--ink-muted); }
.empty-state h3 { color: var(--ink); margin-bottom: 6px; }
.drop {
  border: 1.5px dashed var(--control-border); border-radius: var(--radius-lg);
  padding: 26px 20px; text-align: center; color: var(--ink-muted);
  background: var(--surface); transition: border-color .15s, background .15s;
}
.drop.is-over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.drop strong { color: var(--ink); font-weight: 600; }
.drop.is-over strong { color: inherit; }
.spin {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 2px solid currentColor; border-top-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
