/*
 * Workflow Companion — feuille intégrée à l’application (palette Stitch MAD TRADING).
 * Les couleurs héritent des variables de index.html quand elles existent.
 * Le composant React standalone (workflow-companion/) garde sa propre charte.
 */
:root {
  --wc-panel: #ffffff;
  --wc-panel-muted: var(--surface-2, #f5f4ef);
  --wc-border: var(--line, #e5e3dd);
  --wc-ink: var(--ink, #0f1f38);
  --wc-muted: var(--ink-2, #303e55);
  --wc-muted-soft: var(--muted, #667184);
  --wc-upcoming-bg: #f1f5f9;
  --wc-upcoming-border: var(--line, #e5e3dd);
  --wc-upcoming-ink: var(--muted, #667184);
  --wc-active: var(--brand, #1d637a);
  --wc-active-halo: rgba(29, 99, 122, 0.16);
  --wc-complete: var(--ok, #0a7a56);
  --wc-complete-gradient: #10b981;
  --wc-note-bg: var(--warn-bg, #fef4e6);
  --wc-note-border: #d9770b;
  --wc-note-ink: #92400e;
  --wc-note-icon: var(--warn, #b45309);
  --wc-line: var(--line, #e5e3dd);
  --wc-alert: var(--bad, #be123c);
  --wc-alert-bg: var(--bad-bg, #fdeef1);
}

/* Accents par workflow : pastille active + halo, contrastes AA vérifiés sur blanc. */
.workflow-companion[data-accent="finance"] { --wc-active: var(--brand, #1d637a); --wc-active-halo: rgba(29, 99, 122, 0.16); }
.workflow-companion[data-accent="stock"] { --wc-active: var(--ink, #0f1f38); --wc-active-halo: rgba(15, 31, 56, 0.14); }
.workflow-companion[data-accent="commercial"] { --wc-active: #b93a2b; --wc-active-halo: rgba(185, 58, 43, 0.15); }

/* V2-C1 : le composant occupe toute la largeur utile — plus de colonne morte. */
.workflow-companion {
  box-sizing: border-box;
  width: 100%;
  padding: 12px 16px 14px;
  color: var(--wc-ink);
  background: var(--wc-panel);
  border: 1px solid var(--wc-border);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(15, 31, 56, 0.07), 0 1px 2px rgba(15, 31, 56, 0.04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.workflow-companion *,
.workflow-companion *::before,
.workflow-companion *::after { box-sizing: border-box; }

.workflow-companion--compact { width: 240px; padding: 16px; }

/* Dans les grilles .two-col de l'app, le panneau ne s'étire pas à la hauteur de la colonne voisine. */
.two-col > .workflow-companion { align-self: start; }

/* V2-C1 — en-tête compact : titre à gauche, fiche suivie + progression + outils à droite. */
.wc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  flex-wrap: wrap;
}

.wc-heading h2 {
  margin: 0;
  color: var(--wc-ink);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  letter-spacing: -0.015em;
}

.wc-heading p {
  margin: 2px 0 0;
  color: var(--wc-muted-soft);
  font-size: 10.5px;
  line-height: 1.4;
}

.wc-note-trigger {
  margin: 0 0 0 5px;
  padding: 2px;
  color: var(--wc-note-icon);
  background: none;
  border: 0;
  cursor: help;
  vertical-align: -2px;
}

.wc-head-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.wc-subject-select {
  max-width: 300px;
  height: 32px;
  padding: 0 28px 0 10px;
  color: var(--wc-ink);
  background-color: var(--wc-panel-muted);
  border: 1px solid var(--wc-border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.wc-progress-inline { display: flex; align-items: center; gap: 8px; }
.wc-progress-num { color: var(--wc-muted-soft); font-size: 11px; font-weight: 600; white-space: nowrap; }
.wc-progress-inline .wc-progress-track { width: 88px; height: 6px; margin: 0; }
.wc-progress-inline .wc-progress-track > span { transition: width 300ms ease-out; }

.wc-icon-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  flex: none;
  place-items: center;
  padding: 0;
  color: var(--wc-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: color 200ms ease-out, background-color 200ms ease-out, border-color 200ms ease-out, transform 200ms ease-out;
}

.wc-icon-button:hover { color: var(--wc-active); background: var(--wc-panel-muted); border-color: var(--wc-border); }
.wc-icon-button:focus-visible { outline: 3px solid var(--wc-active-halo); outline-offset: 2px; }
.wc-toggle svg { transition: transform 200ms ease-out; }
.wc-toggle.is-open svg { transform: rotate(180deg); }
.workflow-companion:not(.workflow-companion--narrow) .wc-toggle { display: none; }

.wc-content { display: flex; flex-direction: column; gap: 16px; }
.wc-content[hidden], .wc-help-copy[hidden] { display: none !important; }

.wc-subject {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  color: var(--wc-ink);
  background: var(--wc-panel-muted);
  border: 1px solid var(--wc-border);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}
.wc-subject svg { flex: none; color: var(--wc-active); }
.wc-subject span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wc-alert {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  color: var(--wc-alert);
  background: var(--wc-alert-bg);
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.35;
}
.wc-alert svg { flex: none; }

.wc-progress { display: flex; flex-direction: column; gap: 7px; }
.wc-progress-copy { display: flex; justify-content: space-between; gap: 8px; color: var(--wc-muted-soft); font-size: 11px; line-height: 1.3; }
.wc-progress-track { height: 4px; overflow: hidden; background: var(--wc-upcoming-bg); border-radius: 99px; }
.wc-progress-track span { display: block; height: 100%; background: linear-gradient(90deg, var(--wc-active), var(--wc-complete-gradient)); border-radius: inherit; transition: width 250ms ease-out; }

.wc-timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.wc-step {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  min-width: 0;
}

/* Chaque segment s’arrête au centre du marqueur suivant, même si le texte se replie. */
.wc-step:not(:last-child)::after {
  position: absolute;
  z-index: 0;
  top: 32px;
  bottom: -26px;
  left: 15px;
  width: 2px;
  content: "";
  background: var(--wc-line);
  border-radius: 2px;
}

.wc-step-marker {
  position: relative;
  z-index: 1;
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--wc-upcoming-ink);
  background: var(--wc-upcoming-bg);
  border: 1px solid var(--wc-upcoming-border);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 650;
  line-height: 1;
  transition: color 200ms ease-out, background-color 200ms ease-out, border-color 200ms ease-out, box-shadow 200ms ease-out, transform 200ms ease-out;
}

.wc-step--active .wc-step-marker {
  position: relative;
  color: #ffffff;
  background: var(--stage, var(--wc-active));
  border-color: var(--stage, var(--wc-active));
  box-shadow: 0 0 0 4px var(--wc-active-halo);
}

.wc-step--active .wc-step-marker::after {
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 4px var(--wc-active-halo);
  content: "";
  pointer-events: none;
  animation: wc-pulse 2s ease-in-out infinite;
}

.wc-step--complete .wc-step-marker {
  color: #ffffff;
  background: var(--stage, var(--wc-complete));
  border-color: var(--stage, var(--wc-complete));
}

@keyframes wc-pulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.wc-step-card {
  min-width: 0;
  margin: -4px 0 0;
  padding: 5px 7px 7px;
  border-radius: 8px;
  transition: background-color 200ms ease-out, transform 200ms ease-out;
}
.wc-step:hover .wc-step-card { background: var(--wc-panel-muted); transform: translateX(2px); }
.wc-step--active .wc-step-card { background: var(--wc-panel-muted); }

.wc-step-title-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.wc-step-icon { display: inline-flex; flex: none; color: var(--wc-active); }
.wc-step-title-row h3 { margin: 0; color: var(--wc-ink); font-size: 14px; font-weight: 650; line-height: 1.3; }
.wc-step-subtitle { margin: 4px 0 0 25px; color: var(--wc-muted-soft); font-size: 12px; line-height: 1.35; }
.wc-step-description {
  display: -webkit-box;
  overflow: hidden;
  margin: 4px 0 0 25px;
  color: var(--wc-muted);
  font-size: 12px;
  line-height: 1.4;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.wc-regulatory {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: start;
  gap: 8px;
  padding: 10px 10px 10px 9px;
  background: var(--wc-note-bg);
  border-left: 3px solid var(--wc-note-border);
  border-radius: 0 8px 8px 0;
}
.wc-regulatory-icon { display: inline-flex; margin-top: 1px; color: var(--wc-note-icon); }
.wc-regulatory p { margin: 0; color: var(--wc-note-ink); font-size: 11px; font-style: italic; line-height: 1.4; }
.wc-help-copy { margin: -5px 0 0; padding: 9px 10px; color: var(--wc-muted); background: var(--wc-panel-muted); border-radius: 8px; font-size: 12px; line-height: 1.45; }

@media (max-width: 1023px) {
  .workflow-companion--narrow { width: 100%; padding: 14px 16px; border-radius: 10px; }
  .workflow-companion--narrow .wc-header { align-items: center; margin-bottom: 0; }
  .workflow-companion--narrow .wc-heading h2 { font-size: 15px; }
  .workflow-companion--narrow .wc-content { padding-top: 14px; }
}

.workflow-companion--compact .wc-content { gap: 12px; }
.workflow-companion--compact .wc-header { margin-bottom: 12px; }
.workflow-companion--compact .wc-step { gap: 9px; }
.workflow-companion--compact .wc-step-title-row { align-items: flex-start; gap: 5px; }
.workflow-companion--compact .wc-step-title-row h3 { font-size: 13px; }
.workflow-companion--compact .wc-step-subtitle { margin-left: 23px; }
.workflow-companion--compact .wc-step-description { display: none; }
.workflow-companion--compact .wc-timeline { gap: 8px; }
.workflow-companion--compact .wc-regulatory { padding: 8px; }

@media (prefers-reduced-motion: reduce) {
  .workflow-companion *, .workflow-companion *::before, .workflow-companion *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   V2-C1 — Stepper horizontal plein largeur (composant partagé).
   Connecteurs entre pastilles, étape courante en surbrillance,
   description longue en infobulle (title), seule l'étape courante
   affiche sa description courte sous son libellé.
   ============================================================ */
.wc-stepper {
  display: flex;
  align-items: flex-start;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.wc-stepper[hidden] { display: none !important; }

.wc-hstep {
  position: relative;
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  padding: 0 6px;
  text-align: center;
}
/* Connecteur horizontal entre la pastille précédente et celle-ci. */
.wc-hstep ~ .wc-hstep::before {
  content: "";
  position: absolute;
  top: 13px;
  left: calc(-50% + 17px);
  right: calc(50% + 17px);
  height: 2px;
  background: var(--wc-line);
}

.wc-hmarker {
  position: relative;
  z-index: 1;
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  color: var(--wc-upcoming-ink);
  background: var(--wc-upcoming-bg);
  border: 1px solid var(--wc-upcoming-border);
  border-radius: 50%;
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1;
  transition: color 200ms ease-out, background-color 200ms ease-out, border-color 200ms ease-out, box-shadow 200ms ease-out;
}
.wc-hstep--complete .wc-hmarker {
  color: #ffffff;
  background: var(--stage, var(--wc-complete));
  border-color: var(--stage, var(--wc-complete));
}
.wc-hstep--active .wc-hmarker {
  color: #ffffff;
  background: var(--stage, var(--wc-active));
  border-color: var(--stage, var(--wc-active));
  box-shadow: 0 0 0 4px var(--wc-active-halo);
}

.wc-hbody { display: flex; min-width: 0; flex-direction: column; align-items: center; margin-top: 6px; }
.wc-hlabel {
  max-width: 100%;
  overflow: hidden;
  color: var(--wc-muted);
  font-size: 11.5px;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wc-hstep--active .wc-hlabel { color: var(--wc-ink); }
.wc-hstep--complete .wc-hlabel { color: var(--wc-muted-soft); }
.wc-hdesc {
  color: var(--wc-muted-soft);
  font-size: 10.5px;
  line-height: 1.3;
}
.wc-hstep:focus-visible { outline: 3px solid var(--wc-active-halo); outline-offset: 2px; border-radius: 8px; }

/* V2-C4 — sous 768 px : version verticale compacte (pas de description permanente). */
@media (max-width: 767px) {
  .wc-stepper { flex-direction: column; align-items: stretch; gap: 0; }
  .wc-hstep {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    text-align: left;
  }
  .wc-hstep ~ .wc-hstep::before {
    top: -14px;
    left: 13px;
    right: auto;
    bottom: auto;
    width: 2px;
    height: 16px;
  }
  .wc-hbody { align-items: flex-start; margin-top: 0; }
  .wc-hlabel { white-space: normal; }
  .wc-head { align-items: flex-start; }
}
