/* Assistant mobile par étapes — facture, devis, avoir, achat.
   Le desktop conserve le formulaire complet : les étapes sont alors
   transparentes dans le flux (display: contents). */

.wizard-step {
  display: contents;
}

/* Rail de progression statique, hors formulaire (recherche de société). */
.wizard-stage-rail {
  display: block; margin: 0 0 16px;
}
.wizard-stage-rail .wizard-head-top {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 8px;
}
.wizard-stage-rail .wizard-kicker {
  text-transform: uppercase; letter-spacing: .06em;
  font-size: 11px; font-weight: 800; color: var(--muted);
}
.wizard-stage-rail .wizard-label {
  font-size: 15px; font-weight: 800; color: var(--ink);
}
.wizard-stage-rail .wizard-track {
  height: 6px; min-width: 220px; max-width: 420px;
}
.wizard-stage-rail .wizard-track i {
  display: block; width: 0; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), #4f8dff);
}

/* La barre d'étapes n'existe que lorsque le JS a activé le mode mobile. */
.wizard-head,
.wizard-nav {
  display: none;
}

/* Version desktop forcée : data-wizard-mode="always" (wizard Qonto).
   Les mêmes règles que mobile, sans le media query. */
.wizard-desktop.wizard-mode .wizard-step { display: none; }
.wizard-desktop.wizard-mode .wizard-step.is-active {
  display: block;
  animation: wizard-step-in 0.2s ease both;
  background: var(--card, #fff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 14px;
  padding: 20px 22px;
  margin: 0 0 14px;
}
.wizard-desktop.wizard-mode .form-actions-bar { display: none; }
.wizard-desktop.wizard-mode .wizard-head { display: block; margin: 0 0 18px; }
.wizard-desktop.wizard-mode .wizard-nav { display: grid; }
.wizard-desktop.wizard-mode .wizard-step-title { font-size: 20px; margin: 0 0 4px; color: var(--ink); }
.wizard-desktop.wizard-active .wizard-track,
.wizard-desktop .wizard-track { height: 6px; min-width: 260px; max-width: 420px; }

@media (min-width: 769px) {
  .wizard-desktop.wizard-mode .wizard-head-top {
    display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  }
  .wizard-desktop.wizard-mode .wizard-kicker {
    text-transform: uppercase; letter-spacing: .06em;
    font-size: 11px; font-weight: 800; color: var(--muted);
  }
  .wizard-desktop.wizard-mode .wizard-label { font-size: 15px; font-weight: 800; color: var(--ink); }
  .wizard-desktop.wizard-mode .wizard-track i {
    display: block; width: 0; height: 100%; border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), #4f8dff);
    transition: width 0.25s var(--ease, ease);
  }
  .wizard-desktop.wizard-mode .wizard-nav {
    grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
    margin-top: 18px; padding: 14px 0 0; border-top: 1px solid var(--line);
  }
  .wizard-desktop.wizard-mode .wizard-position {
    color: var(--muted); font-size: 12px; font-weight: 700;
    text-align: center; font-variant-numeric: tabular-nums;
  }
  .wizard-desktop.wizard-mode .wizard-nav .btn { min-height: 44px; white-space: nowrap; }
  .wizard-desktop.wizard-mode .wizard-nav .wizard-back { justify-self: start; }
  .wizard-desktop.wizard-mode .wizard-nav .wizard-next { justify-self: end; }
  .wizard-desktop.wizard-mode .wizard-nav .wizard-submit {
    grid-column: 1 / -1; width: 100%; justify-content: center;
  }
}

@media (max-width: 768px) {
  .wizard-active .page-head .sub {
    display: none;
  }

  .wizard-mode .wizard-step {
    display: none;
  }

  .wizard-mode .wizard-step.is-active {
    display: block;
    animation: wizard-step-in 0.18s ease both;
  }

  .wizard-mode .form-actions-bar {
    display: none;
  }

  .wizard-mode .wizard-head {
    display: block;
    margin: 0 0 16px;
  }

  .wizard-head-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
  }

  .wizard-kicker {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .wizard-label {
    color: var(--ink);
    font-size: 15px;
    font-weight: 800;
    text-align: right;
  }

  .wizard-track {
    height: 6px;
    margin-top: 9px;
    overflow: hidden;
    border-radius: 99px;
    background: var(--line);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  }

  .wizard-track i {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), #4f8dff);
    transition: width 0.25s var(--ease, ease);
  }

  .wizard-mode .wizard-nav {
    position: static;
    z-index: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 8px;
    margin-top: 18px;
    padding: 12px 0 0;
    border-top: 1px solid var(--line);
    background: transparent;
  }

  .wizard-nav .btn {
    min-height: 44px;
    margin: 0;
    white-space: nowrap;
  }

  .wizard-nav .wizard-back {
    justify-self: start;
  }

  .wizard-nav .wizard-next {
    justify-self: end;
  }

  .wizard-nav .wizard-position {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  .wizard-nav .wizard-submit {
    grid-column: 1 / -1;
    width: 100%;
    justify-content: center;
  }

  .wizard-nav .wizard-cancel {
    grid-column: 1 / -1;
    justify-self: center;
    padding: 2px 8px;
    color: var(--muted);
    font-size: 12.5px;
    text-decoration: underline;
  }

  .wizard-nav [hidden] {
    display: none !important;
  }

  /* Les cartes imbriquées deviennent de simples blocs dans une étape. */
  .wizard-mode .invoice-advanced {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .wizard-mode .invoice-advanced > summary {
    display: none;
  }

  .wizard-mode .invoice-advanced-body {
    padding: 0;
  }

  .wizard-mode .invoice-lines-card {
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  .wizard-mode .invoice-lines-head {
    padding: 0 0 10px;
  }

  .wizard-mode .invoice-lines-head .sub {
    display: none;
  }

  .wizard-mode .invoice-lines-toolbar {
    padding: 12px 0 0;
  }

  .wizard-recap {
    display: grid;
    gap: 8px;
    margin-bottom: 18px;
  }

  .wizard-recap-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
  }

  .wizard-recap-row span {
    flex: 0 0 auto;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
  }

  .wizard-recap-row strong {
    min-width: 0;
    color: var(--ink);
    font-size: 13.5px;
    text-align: right;
    overflow-wrap: anywhere;
  }

  .wizard-recap-total {
    border-color: transparent;
    background: var(--blue-pale);
  }

  .wizard-recap-total strong {
    color: var(--blue);
    font-size: 17px;
  }
}

@keyframes wizard-step-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .wizard-mode .wizard-step.is-active {
    animation: none;
  }
}

/* Étape Informations : chips d'échéance et champ date maîtrisés, jamais de
   débordement (le sélecteur de date natif iOS dépasse souvent sa grille). */
.wizard-mode .due-quick {
  gap: 5px;
  margin-bottom: 12px;
}
.wizard-mode .due-chip {
  padding: 7px 13px;
  font-size: 12.5px;
  white-space: nowrap;
}
.wizard-mode .wizard-step [name$="due_date"],
.wizard-mode .wizard-step input[type="date"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  height: 44px;
  padding: 8px 10px;
  font-size: 15px;
  text-overflow: ellipsis;
  appearance: none;
  -webkit-appearance: none;
}
.wizard-mode .wizard-step .card {
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
.wizard-mode .wizard-step .card label {
  font-size: 12.5px;
  margin-bottom: 4px;
}
.wizard-mode .wizard-step .wizard-step-title,
.wizard-mode .wizard-step .micro {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* ---------- Style fintech : barre d'action pleine largeur fixée ----------
   Inspirée des apps bancaires : un seul grand bouton en bas, le retour en
   pastille flottante en haut, les échéances et fiches en cartes tapables. */
@media (max-width: 768px) {
  .wizard-mode .wizard-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: var(--m-footer-h);
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -14px 34px -20px rgba(15, 23, 42, 0.4);
    z-index: var(--z-m-footer, 40);
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border-radius: 0;
  }

  .wizard-mode .wizard-nav .wizard-position,
  .wizard-mode .wizard-nav .wizard-cancel {
    display: none !important;
  }

  .wizard-mode .wizard-nav .wizard-back,
  .wizard-mode .wizard-nav .wizard-next,
  .wizard-mode .wizard-nav .wizard-submit {
    grid-column: auto;
    width: 100%;
    min-height: 52px;
    border-radius: 14px;
    font-size: 15.5px;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    white-space: nowrap;
  }

  .wizard-mode .wizard-nav .wizard-back {
    border: 1px solid var(--line-2);
    background: var(--surface);
    color: var(--ink);
  }

  .wizard-mode .wizard-nav .wizard-next::after {
    content: "→";
    font-weight: 800;
  }

  .wizard-mode .wizard-nav [hidden] {
    display: none !important;
  }

  .wizard-mode.wizard-desktop .wizard-nav .wizard-back {
    border: 1px solid var(--line-2);
    background: var(--surface);
    color: var(--ink);
  }
}

html[data-theme="dark"] .wizard-mode .wizard-nav {
  background: #121214;
  box-shadow: 0 -14px 34px -18px rgba(0, 0, 0, 0.7);
}

@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  .wizard-mode .wizard-step.is-active {
    animation: none;
  }
}
