/* Studio du mode Autonome : une carte par piste, l'utilisateur choisit ce qu'il ajoute. */
#autonome-studio-modal { padding: 0.75rem; }

.as-sheet {
  width: 100%;
  max-width: 34rem;
  max-height: calc(100vh - 1.5rem);
  max-height: calc(100dvh - 1.5rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--th-text, #f1f5f9);
  background: var(--th-bg-elevated, #1f2937);
  border: 1px solid var(--th-border, rgba(148, 163, 184, 0.25));
  border-radius: 1rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.as-head { flex: none; padding: 1.1rem 1.25rem 0.5rem; }
.as-title { font-size: 1.2rem; font-weight: 700; }
.as-intro { margin-top: 0.25rem; font-size: 0.85rem; color: var(--th-text-muted, #94a3b8); }

.as-body {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  gap: 0.9rem;
  padding: 0.5rem 1.25rem 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.as-field-label { font-size: 0.8rem; font-weight: 600; color: var(--th-text-muted, #94a3b8); }
.as-req { color: #f87171; }

.as-input {
  width: 100%;
  min-height: 44px;
  margin-top: 0.35rem;
  padding: 0.55rem 0.85rem;
  color: inherit;
  background: var(--th-bg-input, #374151);
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 0.6rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.as-input:focus {
  outline: none;
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.25);
}

.as-cards { display: flex; flex-direction: column; gap: 0.6rem; }

.as-card {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  background: var(--th-bg-card, rgba(255, 255, 255, 0.03));
  border: 1px solid var(--th-border, rgba(148, 163, 184, 0.25));
  border-radius: 0.8rem;
  transition: border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.25s ease;
}
.as-card[data-has-file="true"],
.as-card[data-click-mode="generate"] {
  border-color: rgba(20, 184, 166, 0.65);
  background: rgba(20, 184, 166, 0.07);
}
.as-card.is-dragover {
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.25);
}

.as-card-top { display: flex; align-items: center; gap: 0.65rem; }
.as-titles { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.as-card-title { font-size: 0.95rem; font-weight: 600; }
.as-card-hint { font-size: 0.75rem; color: var(--th-text-muted, #94a3b8); }

.as-icon {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.6rem;
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.15);
}
.as-icon--harmony1 { color: #4ade80; background: rgba(74, 222, 128, 0.15); }
.as-icon--harmony2 { color: #c084fc; background: rgba(192, 132, 252, 0.15); }
.as-icon--chords { color: #facc15; background: rgba(250, 204, 21, 0.15); }
.as-icon--click { color: var(--th-text-muted, #cbd5e1); background: rgba(148, 163, 184, 0.18); }

.as-select {
  min-height: 40px;
  max-width: 8.5rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  color: inherit;
  background: var(--th-bg-input, #374151);
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 0.55rem;
}

.as-drop { display: flex; align-items: stretch; }
.as-pick {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 0;
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  color: #2dd4bf;
  cursor: pointer;
  border: 1px dashed var(--th-border, #4b5563);
  border-radius: 0.65rem;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, flex-basis 0.25s ease, padding 0.25s ease;
}
.as-pick:hover { background: rgba(20, 184, 166, 0.1); border-color: #14b8a6; }
.as-pick-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.as-card[data-has-file="false"] .as-pick { flex: 0 0 44px; gap: 0; padding: 0; }
.as-card[data-has-file="false"] .as-pick-label { display: none; }
.as-card[data-has-file="true"] .as-pick {
  color: var(--th-text, #f1f5f9);
  border-style: solid;
  border-color: rgba(20, 184, 166, 0.5);
}

/* Le bouton de retrait n'occupe de place qu'une fois un fichier choisi */
.as-clear {
  flex: none;
  width: 0;
  margin-left: 0;
  padding: 0;
  overflow: hidden;
  color: var(--th-text-muted, #94a3b8);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0.65rem;
  opacity: 0;
  pointer-events: none;
  transition: width 0.25s ease, margin-left 0.25s ease, opacity 0.2s ease, color 0.2s ease;
}
.as-card[data-has-file="true"] .as-clear {
  width: 44px;
  margin-left: 0.5rem;
  opacity: 1;
  pointer-events: auto;
  border-color: var(--th-border, #4b5563);
}
.as-clear:hover { color: #f87171; }

.as-chip {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 999px;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.as-chip[aria-pressed="true"] {
  color: #2dd4bf;
  background: rgba(20, 184, 166, 0.15);
  border-color: #14b8a6;
}

.as-note {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: -0.6rem;
  opacity: 0;
  transition: grid-template-rows 0.25s ease, margin-top 0.25s ease, opacity 0.2s ease;
}
.as-note > span {
  min-height: 0;
  overflow: hidden;
  font-size: 0.78rem;
  color: var(--th-text-muted, #94a3b8);
}
.as-card[data-click-mode="generate"] .as-note { grid-template-rows: 1fr; margin-top: 0; opacity: 1; }

.as-link {
  align-self: flex-start;
  min-height: 44px;
  padding: 0;
  font-size: 0.85rem;
  color: #2dd4bf;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  background: none;
  border: 0;
}

.as-foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0 0.6rem;
  padding: 0.8rem 1.25rem;
  border-top: 1px solid var(--th-border, rgba(148, 163, 184, 0.25));
}
.as-foot .btn { margin-top: 0; }
.as-foot-hint {
  flex: 1 1 100%;
  max-height: 0;
  margin-bottom: 0;
  overflow: hidden;
  font-size: 0.78rem;
  text-align: right;
  color: var(--th-text-muted, #94a3b8);
  opacity: 0;
  transition: max-height 0.25s ease, margin-bottom 0.25s ease, opacity 0.2s ease;
}
.as-foot-hint.is-visible { max-height: 2.5rem; margin-bottom: 0.5rem; opacity: 1; }

/* Avancement d'analyse par carte */
.as-card[data-state="busy"] { border-color: rgba(20, 184, 166, 0.45); }
.as-card[data-state="error"] { border-color: rgba(239, 68, 68, 0.65); background: rgba(239, 68, 68, 0.06); }

.as-status {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: -0.6rem;
  opacity: 0;
  transition: grid-template-rows 0.25s ease, margin-top 0.25s ease, opacity 0.2s ease;
}
.as-card:not([data-state="idle"]) .as-status { grid-template-rows: 1fr; margin-top: 0; opacity: 1; }
.as-status-inner { display: flex; flex-direction: column; gap: 0.4rem; min-height: 0; overflow: hidden; }
.as-bar { height: 6px; overflow: hidden; background: var(--th-bg-input, #374151); border-radius: 999px; }
.as-bar > span {
  display: block;
  width: 0;
  height: 100%;
  background: #14b8a6;
  border-radius: inherit;
  transition: width 0.5s ease, background-color 0.25s ease;
}
.as-card[data-state="done"] .as-bar > span { background: #22c55e; }
.as-card[data-state="error"] .as-bar > span { background: #ef4444; }
.as-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--th-text-muted, #94a3b8);
}
.as-card[data-state="error"] .as-status-text { color: #f87171; }
.as-retry {
  display: none;
  flex: none;
  align-items: center;
  min-height: 36px;
  padding: 0 0.85rem;
  font-size: 0.8rem;
  color: #2dd4bf;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 999px;
}
.as-card[data-state="error"] .as-retry { display: inline-flex; }

/* Message d'attente d'une analyse longue */
.as-status-note {
  max-height: 0;
  overflow: hidden;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #fbbf24;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease;
}
.as-status-note.is-visible { max-height: 4rem; opacity: 1; }

/* Enregistrement d'une prise */
.as-rec {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 44px;
  width: 44px;
  margin-left: 0.5rem;
  padding: 0;
  font-size: 0.85rem;
  color: inherit;
  cursor: pointer;
  background: transparent;
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 0.65rem;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}
.as-rec i { color: #f87171; transition: transform 0.2s ease; }
.as-rec span { display: none; }
.as-rec:hover:not(:disabled) { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.6); }
.as-rec:disabled { opacity: 0.4; cursor: not-allowed; }
.as-card[data-rec]:not([data-rec="idle"]) .as-rec { color: #fecaca; background: rgba(239, 68, 68, 0.18); border-color: rgba(239, 68, 68, 0.7); }
.as-card[data-rec]:not([data-rec="idle"]) { border-color: rgba(239, 68, 68, 0.6); }

/* Pendant la prise, le choix de fichier est verrouillé */
.as-card[data-rec]:not([data-rec="idle"]) .as-pick,
.as-card[data-rec]:not([data-rec="idle"]) .as-clear,
.as-card[data-rec]:not([data-rec="idle"]) .as-select { pointer-events: none; opacity: 0.5; }

.as-rec-panel {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: -0.6rem;
  opacity: 0;
  transition: grid-template-rows 0.25s ease, margin-top 0.25s ease, opacity 0.2s ease;
}
.as-card[data-rec]:not([data-rec="idle"]) .as-rec-panel { grid-template-rows: 1fr; margin-top: 0; opacity: 1; }
.as-rec-inner { display: flex; flex-direction: column; gap: 0.45rem; min-height: 0; overflow: hidden; }
.as-rec-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.as-rec-text { flex: 1; min-width: 0; }
.as-rec-time { font-variant-numeric: tabular-nums; color: #fca5a5; }
.as-rec-dot {
  flex: none;
  width: 0.6rem;
  height: 0.6rem;
  background: #6b7280;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}
.as-card[data-rec="record"] .as-rec-dot,
.as-card[data-rec="stopping"] .as-rec-dot { background: #ef4444; animation: as-rec-pulse 1.1s ease-in-out infinite; }
.as-rec-meter { height: 6px; overflow: hidden; background: var(--th-bg-input, #374151); border-radius: 999px; }
.as-rec-meter > span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #facc15 75%, #ef4444);
  border-radius: inherit;
  transition: width 0.1s linear;
}
.as-rec-note {
  max-height: 0;
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--th-text-muted, #94a3b8);
  opacity: 0;
  transition: max-height 0.25s ease, opacity 0.2s ease;
}
.as-card[data-rec-guides="true"] .as-rec-note { max-height: 3rem; opacity: 1; }
@keyframes as-rec-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.45; transform: scale(0.8); } }

/* Cases à cocher */
.as-check { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; font-size: 0.85rem; cursor: pointer; }
.as-check-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.as-check-box {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  background: var(--th-bg-input, #374151);
  border: 1px solid var(--th-border, #4b5563);
  border-radius: 0.4rem;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.as-check-box i { font-size: 0.7rem; color: #fff; opacity: 0; transform: scale(0.5); transition: opacity 0.15s ease, transform 0.2s ease; }
.as-check-input:checked + .as-check-box { background: #14b8a6; border-color: #14b8a6; }
.as-check-input:checked + .as-check-box i { opacity: 1; transform: scale(1); }
.as-check-input:focus-visible + .as-check-box { box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.35); }
.as-check-input:disabled + .as-check-box { opacity: 0.45; }

/* Tempo et métronome */
.as-tempo-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.6rem; }
.as-tempo-field { display: flex; flex-direction: column; gap: 0.25rem; }
.as-tempo-row .as-input,
.as-tempo-row .as-select,
.as-tempo-row .as-chip { box-sizing: border-box; height: 44px; min-height: 44px; margin-top: 0; }
.as-tempo-row .as-chip { align-self: flex-end; padding-top: 0; padding-bottom: 0; }
.as-input--small { width: 6.5rem; }
.as-input.is-invalid { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2); }
.as-select--field { max-width: none; }

/* Click : dans la même carte que le tempo */
.as-click { display: flex; flex-direction: column; gap: 0.6rem; padding-top: 0.75rem; border-top: 1px solid var(--th-border, rgba(148, 163, 184, 0.25)); }
.as-click-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.6rem; }

/* Enregistrement à la chaîne */
.as-icon--chain { color: #fb923c; background: rgba(251, 146, 60, 0.15); }
.as-chain[data-running="true"] { border-color: rgba(251, 146, 60, 0.6); background: rgba(251, 146, 60, 0.06); }
.as-chain-help { font-size: 0.78rem; color: var(--th-text-muted, #94a3b8); }
.as-chain-warn {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.78rem;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.35);
  border-radius: 0.6rem;
}
.as-chain-warn i { margin-top: 0.15rem; }
.as-chain-status {
  max-height: 0;
  margin-top: -0.6rem;
  overflow: hidden;
  font-size: 0.85rem;
  opacity: 0;
  transition: max-height 0.25s ease, margin-top 0.25s ease, opacity 0.2s ease;
}
.as-chain-status.is-visible { max-height: 4rem; margin-top: 0; opacity: 1; }
.as-chain-toggle {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 0.5rem;
  min-height: 44px;
  margin-top: 0;
  transition: opacity 0.2s ease, filter 0.2s ease;
}
.as-chain-toggle i { transition: transform 0.2s ease; }
.as-chain-toggle[aria-pressed="true"] { filter: saturate(0.85) brightness(0.95); }
.as-chain-toggle:disabled { opacity: 0.5; cursor: not-allowed; }

/* Contrôle de la synchro : s'ouvre quand une piste est présente */
.as-sync-wrap {
  display: grid;
  grid-template-rows: 0fr;
  margin-top: -0.9rem;
  opacity: 0;
  transition: grid-template-rows 0.3s ease, margin-top 0.3s ease, opacity 0.25s ease;
}
.as-sync-wrap[data-open="true"] { grid-template-rows: 1fr; margin-top: 0; opacity: 1; }
.as-sync-clip { min-height: 0; overflow: hidden; }
.as-icon--sync { color: #38bdf8; background: rgba(56, 189, 248, 0.15); }
.as-sync-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.as-sync-zoom { display: inline-flex; gap: 0.4rem; margin-left: auto; }
.as-chip--icon { width: 44px; padding: 0; justify-content: center; }
.as-sync-controls .as-chip[aria-pressed="true"] { border-color: rgba(20, 184, 166, 0.7); }
.as-sync[data-has-grid="false"] [data-role="sync-metronome"] { opacity: 0.45; }
.as-sync-progress { display: grid; grid-template-columns: auto 1fr auto; align-items: center; column-gap: 0.75rem; }
.as-sync-scroll {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--th-bg-body, #111827);
  border: 1px solid var(--th-border, rgba(148, 163, 184, 0.25));
  border-radius: 0.6rem;
}
.as-sync-stage { position: relative; min-width: 100%; cursor: pointer; }
.as-sync-ruler { display: block; height: 24px; border-bottom: 1px solid var(--th-border, rgba(148, 163, 184, 0.25)); }
.as-sync-lane { position: relative; height: 48px; border-bottom: 1px solid var(--th-border, rgba(148, 163, 184, 0.15)); }
.as-sync-lane:last-child { border-bottom: 0; }
.as-sync-canvas { position: absolute; top: 0; left: 0; height: 48px; }
.as-sync-lane-label {
  position: sticky;
  left: 0.4rem;
  z-index: 2;
  display: inline-block;
  margin: 0.15rem 0 0 0.4rem;
  padding: 0.05rem 0.45rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--as-lane-color, #e2e8f0);
  background: rgba(15, 23, 42, 0.7);
  border-radius: 0.4rem;
  pointer-events: none;
}
.as-sync-head {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 3;
  width: 2px;
  margin-left: -1px;
  background: #f8fafc;
  box-shadow: 0 0 6px rgba(248, 250, 252, 0.8);
  pointer-events: none;
  will-change: transform;
}
.as-sync .as-card-top { flex-wrap: wrap; }
.as-sync-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 0.9rem;
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--th-text-muted, #94a3b8);
}
.as-sync-legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
.as-sync-key { display: inline-block; width: 3px; height: 14px; border-radius: 1px; }
.as-sync-key--measure { background: #fb923c; }
.as-sync-key--beat { width: 2px; background: rgba(148, 163, 184, 0.7); }
.as-sync-key--head { background: #f8fafc; box-shadow: 0 0 5px rgba(248, 250, 252, 0.8); }

/* Carte tempo : se replie quand la chaîne tourne, il ne reste que le titre et un résumé */
.as-fold {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s ease, margin-top 0.3s ease, opacity 0.25s ease;
}
.as-fold-inner {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 0;
  padding: 4px;
  margin: -4px;
  overflow: hidden;
}
[data-folded="true"] > .as-fold { grid-template-rows: 0fr; margin-top: -0.6rem; opacity: 0; }
[data-fold-toggle] { cursor: pointer; border-radius: 0.6rem; }
[data-fold-toggle]:focus-visible { outline: 2px solid #14b8a6; outline-offset: 3px; }
.as-fold-chevron { align-self: center; color: var(--th-text-muted, #94a3b8); transition: transform 0.3s ease; }
[data-folded="true"] > [data-fold-toggle] .as-fold-chevron { transform: rotate(-90deg); }
.as-hint-swap { display: grid; }
.as-hint-swap > * { grid-area: 1 / 1; transition: opacity 0.25s ease; }
.as-tempo-summary { opacity: 0; color: #2dd4bf; }
.as-tempo[data-folded="true"] .as-tempo-summary { opacity: 1; }
.as-tempo[data-folded="true"] [data-role="tempo-hint"] { opacity: 0; }

@media (max-width: 480px) {
  .as-sync-controls .as-chip span { display: none; }
  .as-sync-controls .as-chip { width: 44px; padding: 0; justify-content: center; }
}

@media (max-width: 480px) {
  .as-head { padding: 1rem 1rem 0.4rem; }
  .as-body { padding: 0.5rem 1rem 1rem; }
  .as-foot { padding: 0.7rem 1rem; }
  .as-foot .btn { flex: 1; }
  .as-select { max-width: 7rem; }
}

@media (prefers-reduced-motion: reduce) {
  .as-input, .as-card, .as-pick, .as-clear, .as-chip, .as-note, .as-status, .as-bar > span,
  .as-foot-hint, .as-status-note, .as-rec, .as-rec i, .as-rec-panel, .as-rec-meter > span, .as-rec-note,
  .as-check-box, .as-check-box i, .as-chain-status, .as-chain-toggle, .as-chain-toggle i, .as-sync-wrap, .as-fold, .as-fold-chevron, .as-hint-swap > * { transition: none; }
  .as-card[data-rec="stopping"] .as-rec-dot { animation: none; }
  .as-card[data-rec="record"] .as-rec-dot { animation: none; }
}
