/* ============================================================
   v6 Refine progress overlay
   ============================================================
   Floating card at top-center. Replaces the v5 inline indicator
   modal — non-blocking so the user can watch their grids
   update underneath as the refine runs.
*/

@layer v6-components {

  .v6-refine-progress {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translate(-50%, -8px);
    z-index: var(--z-modal, 900);
    pointer-events: none;
    opacity: 0;
    transition:
      opacity var(--duration-base, 180ms) var(--ease-out-quart),
      transform var(--duration-base, 180ms) var(--ease-out-quart);
  }
  .v6-refine-progress--visible {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
  }

  .v6-refine-progress__card {
    width: 460px;
    max-width: calc(100vw - 32px);
    padding: 16px;
    background: var(--v6-panel, var(--surface-300, #18181b));
    border: 1px solid var(--v6-border-strong, rgba(255, 255, 255, 0.14));
    border-radius: var(--radius-lg, 8px);
    box-shadow: var(--shadow-4, 0 24px 64px rgba(0,0,0,0.7));
    color: var(--text-primary, #fafafa);
    font-family: var(--font-sans, system-ui);

    /* Subtle accent border that brightens on completion */
    box-shadow:
      var(--shadow-4, 0 24px 64px rgba(0,0,0,0.7)),
      inset 0 0 0 1px rgba(139, 92, 246, 0.25);
    transition: box-shadow var(--duration-slow, 260ms);
  }

  .v6-refine-progress--done .v6-refine-progress__card {
    box-shadow:
      var(--shadow-4),
      inset 0 0 0 1px rgba(34, 197, 94, 0.45),
      0 0 24px rgba(34, 197, 94, 0.2);
  }
  .v6-refine-progress--failed .v6-refine-progress__card {
    box-shadow:
      var(--shadow-4),
      inset 0 0 0 1px rgba(239, 68, 68, 0.45),
      0 0 24px rgba(239, 68, 68, 0.2);
  }
  /* Bundle B (v7.7) — score-floor retry / floor-missed states */
  .v6-refine-progress--warn .v6-refine-progress__card {
    box-shadow:
      var(--shadow-4),
      inset 0 0 0 1px rgba(245, 158, 11, 0.5),
      0 0 24px rgba(245, 158, 11, 0.18);
  }
  .v6-refine-progress--warn .v6-refine-progress__spinner {
    background: var(--accent-warn, #f59e0b);
  }

  .v6-refine-progress__head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
  }

  /* Animated spinner — gradient ring */
  .v6-refine-progress__spinner {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: conic-gradient(
      from 0deg,
      rgba(139, 92, 246, 0.0) 0deg,
      rgba(139, 92, 246, 1.0) 270deg,
      rgba(139, 92, 246, 0.0) 360deg
    );
    mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
    animation: v6-refine-spin 0.9s linear infinite;
    flex-shrink: 0;
  }
  .v6-refine-progress--done .v6-refine-progress__spinner {
    background: var(--accent-success, #22c55e);
    animation: none;
  }
  .v6-refine-progress--failed .v6-refine-progress__spinner {
    background: var(--accent-danger, #ef4444);
    animation: none;
  }
  /* R3 — the run finished and the user is worse off than a clean win: either
     the kept candidate never cleared the score floor, or it cleared the floor
     and the composite still FELL (80 -> 60 clears a floor of 50). Every retry
     was a charged song call, so this is amber, not the green of --done.
     Declared AFTER the --done rules on purpose: the card carries both classes,
     and at equal specificity the later rule is the one that paints. */
  .v6-refine-progress--missed .v6-refine-progress__card {
    box-shadow:
      var(--shadow-4),
      inset 0 0 0 1px rgba(245, 158, 11, 0.5),
      0 0 24px rgba(245, 158, 11, 0.18);
  }
  .v6-refine-progress--missed .v6-refine-progress__spinner {
    background: var(--accent-warn, #f59e0b);
    animation: none;
  }
  @keyframes v6-refine-spin {
    to { transform: rotate(360deg); }
  }
  @media (prefers-reduced-motion: reduce) {
    .v6-refine-progress__spinner { animation: none; }
  }

  .v6-refine-progress__title {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
  }
  .v6-refine-progress__title strong {
    font-size: var(--text-base, 14px);
    font-weight: 600;
    color: var(--text-primary, #fafafa);
  }
  .v6-refine-progress__phase {
    font-size: 11px;
    color: var(--text-secondary, #a1a1aa);
    line-height: 1.3;
  }

  .v6-refine-progress__close {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--v6-border-faint, rgba(255,255,255,0.04));
    border-radius: var(--radius-sm, 4px);
    color: var(--text-muted, #71717a);
    cursor: pointer;
    transition: background var(--duration-fast, 120ms), color var(--duration-fast, 120ms);
  }
  .v6-refine-progress__close:hover {
    background: var(--surface-500, #27272b);
    color: var(--text-primary, #fafafa);
  }

  /* ============================================================
     Focused-axes chip row (e.g., "Voice leading", "Chord alignment")
     ============================================================ */
  .v6-refine-progress__axes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
  }
  .v6-refine-progress__axis-chip {
    display: inline-block;
    padding: 3px 8px;
    background: rgba(139, 92, 246, 0.15);
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 999px;
    font-family: var(--font-mono, monospace);
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-primary, #8b5cf6);
    letter-spacing: 0.02em;
    text-transform: uppercase;
  }

  /* ============================================================
     Score bars — 5 dimensions
     ============================================================ */
  .v6-refine-progress__scores {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .v6-refine-progress__score {
    display: grid;
    grid-template-columns: 56px 1fr 32px;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary, #a1a1aa);
  }
  .v6-refine-progress__score-label {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    font-size: 10px;
    color: var(--text-muted, #71717a);
  }
  .v6-refine-progress__score-track {
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
  }
  .v6-refine-progress__score-fill {
    height: 100%;
    background: linear-gradient(90deg, #8b5cf6, #ec4899);
    border-radius: 3px;
    transition: width var(--duration-slow, 260ms) var(--ease-out-quart);
  }
  .v6-refine-progress__score-value {
    font-family: var(--font-mono, monospace);
    font-size: 11px;
    color: var(--text-primary, #fafafa);
    text-align: right;
    font-weight: 500;
  }

  /* ============================================================
     Notes from AI
     ============================================================ */
  .v6-refine-progress__notes {
    margin-top: 10px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.3);
    border-left: 2px solid var(--accent-primary, #8b5cf6);
    border-radius: var(--radius-sm, 4px);
    font-size: 12px;
    color: var(--text-secondary, #a1a1aa);
    line-height: 1.4;
    white-space: pre-wrap;
  }
}
