/* ==========================================================================
   Domo — composants : boutons, champs, interrupteurs, cartes, badges,
   feuilles (dialog), toasts, squelettes, états vides
   ========================================================================== */

/* ---------- Boutons ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-bd: var(--border);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--r-s);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 620;
  font-size: var(--fs-m);
  line-height: 1.1;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), opacity var(--t-fast);
}
.btn:hover { text-decoration: none; filter: brightness(1.03); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn--primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bd: transparent; box-shadow: 0 6px 16px -8px var(--primary); }
.btn--primary:hover { --btn-bg: var(--primary-hover); }
.btn--danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-bd: transparent; }
.btn--danger-solid { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: transparent; }
.btn--ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-2); }
.btn--ghost:hover { --btn-bg: var(--surface-2); --btn-fg: var(--text); }
.btn--soft { --btn-bg: var(--primary-soft); --btn-fg: var(--primary); --btn-bd: transparent; }
.btn--block { width: 100%; white-space: normal; text-align: center; }
.btn--l { min-height: 52px; font-size: var(--fs-l); border-radius: var(--r-m); padding: 0 22px; }
.btn--s { min-height: 36px; padding: 0 12px; font-size: var(--fs-s); }
.btn--icon { width: 44px; padding: 0; }
.btn--icon.btn--s { width: 36px; }
.btn--round { border-radius: var(--r-full); }
.btn.is-busy { color: transparent !important; pointer-events: none; }
.btn.is-busy > .spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  color: var(--btn-fg);
}

.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 32px;
  padding: 0 4px;
  color: var(--primary);
  font-weight: 600;
  font-size: var(--fs-s);
  border-radius: var(--r-xs);
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.link-btn--danger { color: var(--danger); }

/* ---------- Spinner ---------- */
.spinner {
  width: 20px; height: 20px;
  flex: none;
  animation: spin 0.8s linear infinite;
}
.spinner circle { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 44 100; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Champs de formulaire ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field__label { font-size: var(--fs-s); font-weight: 620; color: var(--text-2); }
.field__label .opt { font-weight: 500; color: var(--text-3); }
.field__help { font-size: var(--fs-s); color: var(--text-3); }
.field__error { font-size: var(--fs-s); color: var(--danger); font-weight: 560; }
.field__row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border-radius: var(--r-s);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem; /* 16 px : évite le zoom auto d'iOS */
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.textarea { padding: 12px 14px; min-height: 96px; resize: vertical; }
.input::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.input:disabled, .select:disabled { opacity: 0.6; }
.input--code { letter-spacing: 0.35em; font-variant-numeric: tabular-nums; text-align: center; font-size: 1.25rem; font-weight: 600; }
.input--mono { font-family: var(--font-mono); font-size: 0.95rem; }
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.input-group { position: relative; display: flex; }
.input-group .input { padding-right: 52px; }
.input-group__btn {
  position: absolute; right: 2px; top: 2px; bottom: 2px;
  width: 44px;
  display: grid; place-items: center;
  border-radius: var(--r-s);
  color: var(--text-3);
}
.input-group__btn:hover { color: var(--text); }

.form-grid { display: grid; gap: 16px; }
@media (min-width: 640px) { .form-grid--2 { grid-template-columns: 1fr 1fr; } }

.form-error {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--r-s);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 560;
  font-size: var(--fs-s);
}

/* ---------- Interrupteur (checkbox) ---------- */
.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 52px; height: 32px;
  margin: 0;
  border-radius: var(--r-full);
  background: var(--surface-3);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background-color var(--t-med) var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.25);
  transition: transform var(--t-med) var(--ease-spring);
}
.switch:checked { background: var(--accent, var(--success)); }
.switch:checked::after { transform: translateX(20px); }
.switch:disabled { opacity: 0.5; cursor: default; }
.switch:focus-visible { outline-offset: 3px; border-radius: var(--r-full); }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 52px;
  cursor: pointer;
}
.switch-row__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.switch-row__text small { color: var(--text-3); font-size: var(--fs-s); }

/* Case à cocher simple */
.check {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px;
  padding: 6px 12px;
  border-radius: var(--r-s);
  cursor: pointer;
}
.check:hover { background: var(--surface-2); }
.check input {
  appearance: none; -webkit-appearance: none;
  flex: none;
  width: 22px; height: 22px; margin: 0;
  border-radius: 7px;
  border: 2px solid var(--border-strong);
  background: var(--surface);
  display: grid; place-items: center;
  transition: background-color var(--t-fast), border-color var(--t-fast);
}
.check input::after {
  content: "";
  width: 10px; height: 6px;
  border-left: 2.5px solid #fff; border-bottom: 2.5px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px) scale(0);
  transition: transform var(--t-fast) var(--ease-spring);
}
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { transform: rotate(-45deg) translate(1px, -1px) scale(1); }
.check input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Contrôle segmenté ---------- */
.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: var(--r-m);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.segmented--block { display: flex; }
.segmented--block > * { flex: 1 1 0; }
.segmented button {
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--r-s);
  color: var(--text-2);
  font-weight: 600;
  font-size: var(--fs-s);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-checked="true"], .segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-1);
}

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-1);
  padding: 18px;
}
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.card__title { font-size: var(--fs-l); font-weight: 650; }
.card__desc { color: var(--text-2); font-size: var(--fs-s); margin-top: 2px; }
.card + .card { margin-top: 14px; }
.cards { display: grid; gap: 14px; }
@media (min-width: 720px) { .cards--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .cards--2 > .card + .card { margin-top: 0; } }
.cards > .card + .card { margin-top: 0; }

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

/* Puce d'icône colorée (accent) */
.chip-icon {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border-radius: 14px;
  color: var(--accent, var(--primary));
  background: var(--surface-2);
  background: color-mix(in srgb, var(--accent, var(--primary)) 15%, transparent);
}
.chip-icon--s { width: 36px; height: 36px; border-radius: 11px; }
.chip-icon--s .icon { width: 19px; height: 19px; }

/* Avatar (initiales) */
.avatar {
  display: grid; place-items: center;
  flex: none;
  width: 44px; height: 44px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
  background: var(--surface-2);
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
.avatar--s { width: 34px; height: 34px; font-size: 0.8rem; }
.avatar--l { width: 64px; height: 64px; font-size: 1.35rem; }

/* ---------- Badges / pastilles ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 24px;
  padding: 0 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
  letter-spacing: 0.01em;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge--primary { background: var(--primary-soft); color: var(--primary); }
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }

.dot {
  display: inline-block;
  flex: none;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-3);
}
.dot--ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.dot--warn { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.dot--err { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot--idle { background: var(--text-3); }
.dot--pulse { animation: pulse 1.6s var(--ease) infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 30px;
  padding: 0 12px 0 10px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: var(--fs-s);
  font-weight: 620;
  color: var(--text-2);
}

/* ---------- Feuille / boîte de dialogue (élément <dialog>) ---------- */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - var(--safe-top) - 24px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sheet:not([open]) { display: none; }
.sheet::backdrop {
  background: var(--overlay);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.sheet[open] { animation: sheet-up var(--t-slow) var(--ease) both; }
.sheet[open]::backdrop { animation: fade-in var(--t-med) var(--ease) both; }
.sheet.is-closing { animation: sheet-down var(--t-med) var(--ease) both; }
.sheet.is-closing::backdrop { animation: fade-out var(--t-med) var(--ease) both; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheet-down { to { transform: translateY(40px); opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

.sheet__grabber {
  width: 40px; height: 5px;
  margin: 8px auto 0;
  border-radius: var(--r-full);
  background: var(--surface-3);
  flex: none;
}
.sheet__head {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 8px 20px;
  flex: none;
}
.sheet__title { flex: 1; min-width: 0; font-size: var(--fs-l); font-weight: 680; }
.sheet__subtitle { font-size: var(--fs-s); color: var(--text-2); font-weight: 500; }
.sheet__body {
  padding: 8px 20px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.sheet__foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 12px 20px calc(var(--safe-bottom) + 16px);
  border-top: 1px solid var(--border);
  flex: none;
}
.sheet__foot .btn { flex: 1 1 0; }
.sheet__body:last-child { padding-bottom: calc(var(--safe-bottom) + 24px); }

@media (min-width: 720px) {
  .sheet {
    inset: 0;
    margin: auto;
    width: min(540px, calc(100vw - 48px));
    max-height: min(86vh, 860px);
    height: fit-content;
    border-radius: 26px;
  }
  .sheet--wide { width: min(760px, calc(100vw - 48px)); }
  .sheet__grabber { display: none; }
  .sheet__head { padding: 18px 14px 8px 24px; }
  .sheet__body { padding: 8px 24px 24px; }
  .sheet__foot { padding: 14px 24px 18px; }
  .sheet__foot .btn { flex: 0 0 auto; }
  .sheet[open] { animation-name: dialog-in; }
  .sheet.is-closing { animation-name: dialog-out; }
}
@keyframes dialog-in { from { transform: scale(0.96) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes dialog-out { to { transform: scale(0.97); opacity: 0; } }

.confirm-text { color: var(--text-2); font-size: var(--fs-m); }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed;
  z-index: 200;
  top: calc(var(--safe-top) + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px;
  padding: 10px 10px 10px 14px;
  border-radius: var(--r-m);
  background: #1c2030;
  color: #f1f3f8;
  box-shadow: var(--shadow-3);
  font-size: var(--fs-m);
  font-weight: 540;
  pointer-events: auto;
  animation: toast-in var(--t-slow) var(--ease-spring) both;
}
:root[data-theme="dark"] .toast { background: #2a3040; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .toast { background: #2a3040; } }
.toast.is-leaving { animation: toast-out var(--t-med) var(--ease) both; }
.toast__icon { flex: none; width: 22px; height: 22px; }
.toast--success .toast__icon { color: #4ade80; }
.toast--error .toast__icon { color: #f87171; }
.toast--info .toast__icon { color: #93c5fd; }
.toast__msg { flex: 1; min-width: 0; }
.toast__action {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--r-s);
  background: rgb(255 255 255 / 0.12);
  color: #fff;
  font-weight: 650;
  font-size: var(--fs-s);
}
.toast__close { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r-s); color: rgb(255 255 255 / 0.6); }
.toast__close:hover { color: #fff; background: rgb(255 255 255 / 0.08); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-12px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-8px) scale(0.98); } }

/* ---------- Squelettes de chargement ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-s);
}
.skeleton::after {
  content: "";
  position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.35), transparent);
  animation: shimmer 1.5s var(--ease) infinite;
}
:root[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.05), transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .skeleton::after { background: linear-gradient(90deg, transparent, rgb(255 255 255 / 0.05), transparent); } }
@keyframes shimmer { to { transform: translateX(100%); } }
.skeleton-line { height: 14px; border-radius: 7px; }
.skeleton-line--w60 { width: 60%; }
.skeleton-line--w40 { width: 40%; }
.skeleton-line--w80 { width: 80%; }
.skeleton-row { display: flex; align-items: center; gap: 14px; padding: 14px 0; }
.skeleton-row .skeleton-circle { width: 44px; height: 44px; border-radius: 14px; flex: none; }
.skeleton-row .lines { flex: 1; display: flex; flex-direction: column; gap: 8px; }

/* ---------- États vides / erreurs ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px;
  padding: 48px 20px;
  border-radius: var(--r-xl);
  border: 1.5px dashed var(--border-strong);
  color: var(--text-2);
}
.empty__art {
  display: grid; place-items: center;
  width: 72px; height: 72px;
  margin-bottom: 6px;
  border-radius: 22px;
  background: var(--primary-soft);
  color: var(--primary);
}
.empty__art .icon { width: 34px; height: 34px; stroke-width: 1.75; }
.empty--error .empty__art { background: var(--danger-soft); color: var(--danger); }
.empty__title { font-size: var(--fs-l); font-weight: 680; color: var(--text); }
.empty__text { max-width: 420px; }
.empty .btn { margin-top: 8px; }

/* ---------- Listes ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  min-height: 64px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-item__title { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item__sub { font-size: var(--fs-s); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item__aside { flex: none; display: flex; align-items: center; gap: 6px; }
button.list-item, a.list-item { width: 100%; text-align: left; color: inherit; text-decoration: none; transition: background-color var(--t-fast); }
button.list-item:hover, a.list-item:hover { background: var(--surface-2); }

/* Détails repliables */
.disclosure { border-top: 1px solid var(--border); margin-top: 16px; }
.disclosure > summary {
  display: flex; align-items: center; gap: 8px;
  min-height: 48px;
  cursor: pointer;
  list-style: none;
  font-weight: 620;
  color: var(--text-2);
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary .icon { transition: transform var(--t-med) var(--ease); }
.disclosure[open] > summary .icon { transform: rotate(90deg); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: var(--fs-s); }
.kv dt { color: var(--text-3); }
.kv dd { color: var(--text); word-break: break-word; }
.code-block {
  margin: 8px 0 0;
  padding: 12px;
  border-radius: var(--r-s);
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow: auto;
}

/* ---------- Mouvement réduit : garder les indicateurs essentiels ---------- */
@media (prefers-reduced-motion: reduce) {
  .spinner.spinner { animation-duration: 1.4s !important; animation-iteration-count: infinite !important; }
  .skeleton.skeleton::after { animation: none !important; }
  .dot.dot--pulse { animation: none !important; }
}
