/* ───────────────────────────────────────────────────────────────────────────
   Session status — the creator-owned editorial axis.

   Loaded after workflow-studio-premium.css so the card metadata row can be
   re-laid-out over the premium treatment. Two pieces:
     · .wf-session-card__meta   metadata row, now a sibling of the open surface
     · .wf-status               the status chip + its menu (card and header)
   Plus the resume progress bar on unfinished cards.
   ─────────────────────────────────────────────────────────────────────────── */

/* Per-status accent, one property for chip tint, icon and menu highlight.
   The default rung stays deliberately neutral — it is where every session
   starts, so colouring it would just add noise to a grid of untouched cards.
   Only the two states a creator actually moves a session into carry colour. */
.wf-status,
.wf-status__option {
    --wf-status-color: var(--color-text-secondary);
    --wf-status-tint: 0%;
}

.wf-status[data-status-value='ready_for_review'],
.wf-status__option[data-status-value='ready_for_review'] {
    --wf-status-color: var(--color-primary);
    --wf-status-tint: 100%;
}

.wf-status[data-status-value='done'],
.wf-status__option[data-status-value='done'] {
    --wf-status-color: var(--color-success, #16a34a);
    --wf-status-tint: 100%;
}

/* ─── Card metadata row ────────────────────────────────────────────────────── */

/* The row moved out of the open-surface <button> so it can hold a real control.
   It carries the body's padding itself so the two rows stay aligned. */
#workflow-studio-view .wf-session-card__body {
    padding-bottom: 0;
}

#workflow-studio-view .wf-session-card__meta {
    padding: 9px 8px 8px;
    gap: 10px;
    flex-wrap: nowrap;
    min-width: 0;
}

#workflow-studio-view .wf-session-card__source {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Status chip ──────────────────────────────────────────────────────────── */

.wf-status {
    position: relative;
    display: inline-flex;
    flex: none;
}

.wf-status__trigger {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 100%;
    min-height: 22px;
    padding: 0 5px 0 7px;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--color-border-light) 78%, transparent);
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: 0.72rem;
    font-weight: 560;
    line-height: 1;
    letter-spacing: -0.005em;
    cursor: pointer;
    transition:
        background 170ms ease,
        border-color 170ms ease,
        color 170ms ease,
        box-shadow 170ms ease;
}

/* Coloured rungs read as a state; the neutral default reads as metadata. */
.wf-status[data-status-value='ready_for_review'] .wf-status__trigger,
.wf-status[data-status-value='done'] .wf-status__trigger {
    border-color: color-mix(in srgb, var(--wf-status-color) 26%, transparent);
    background: color-mix(in srgb, var(--wf-status-color) 8%, transparent);
    color: color-mix(in srgb, var(--wf-status-color) 76%, var(--color-text-primary));
}

.wf-status__trigger:hover,
.wf-status.is-open .wf-status__trigger {
    border-color: color-mix(in srgb, var(--wf-status-color) 40%, var(--color-border-light));
    background: color-mix(in srgb, var(--wf-status-color) 12%, var(--color-bg-secondary));
    color: color-mix(in srgb, var(--wf-status-color) 84%, var(--color-text-primary));
}

.wf-status__trigger:focus-visible {
    outline: 2px solid var(--wf-status-color);
    outline-offset: 2px;
}

.wf-status__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* All three glyphs are in the DOM; the active status reveals its own. */
.wf-status__icon {
    display: none;
    flex: none;
    width: 12px;
    height: 12px;
    color: var(--wf-status-color);
    opacity: 0.9;
}

.wf-status[data-status-value='in_progress'] > .wf-status__trigger .wf-status__icon[data-status-icon='in_progress'],
.wf-status[data-status-value='ready_for_review'] > .wf-status__trigger .wf-status__icon[data-status-icon='ready_for_review'],
.wf-status[data-status-value='done'] > .wf-status__trigger .wf-status__icon[data-status-icon='done'] {
    display: block;
}

.wf-status__chevron {
    flex: none;
    width: 11px;
    height: 11px;
    opacity: 0.5;
    transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1), opacity 170ms ease;
}

.wf-status__trigger:hover .wf-status__chevron,
.wf-status.is-open .wf-status__chevron {
    opacity: 0.85;
}

.wf-status.is-open .wf-status__chevron {
    transform: rotate(180deg);
}

/* Confirmation after a pick — a single soft ring, so no toast is needed. */
@media (prefers-reduced-motion: no-preference) {
    .wf-status.is-just-set .wf-status__trigger {
        animation: wf-status-confirm 720ms cubic-bezier(0.22, 1, 0.36, 1);
    }
}

@keyframes wf-status-confirm {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--wf-status-color) 40%, transparent); }
    65% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--wf-status-color) 0%, transparent); }
    100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--wf-status-color) 0%, transparent); }
}

/* ─── Menu ─────────────────────────────────────────────────────────────────── */

.wf-status__menu {
    position: absolute;
    right: 0;
    z-index: 40;
    min-width: 186px;
    padding: 4px;
    display: grid;
    gap: 1px;
    border-radius: 10px;
    border: 1px solid color-mix(in srgb, var(--color-border-light) 66%, transparent);
    background: var(--color-surface-elevated);
    box-shadow:
        0 1px 1px rgba(15, 23, 42, 0.04),
        0 18px 38px -24px rgba(15, 23, 42, 0.32);
    /* visibility rather than [hidden] so the open/close transition can run */
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        opacity 150ms ease,
        transform 190ms cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0s linear 190ms;
}

/* The chip sits on the card's last row, so the menu opens upward — downward
   would clip against the grid's lower edge on the bottom row of cards. */
.wf-status--card .wf-status__menu {
    bottom: calc(100% + 6px);
    transform-origin: bottom right;
    transform: translateY(4px) scale(0.97);
}

.wf-status--header .wf-status__menu {
    top: calc(100% + 7px);
    transform-origin: top right;
    transform: translateY(-4px) scale(0.97);
}

.wf-status.is-open .wf-status__menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition-delay: 0s;
}

.wf-status__option {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 32px;
    padding: 0 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--color-text-secondary);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 540;
    text-align: left;
    cursor: pointer;
    transition: background 140ms ease, color 140ms ease;
}

/* Hover stays neutral. Reserving colour for the selected row keeps a
   three-colour menu from looking like a sticker sheet. */
.wf-status__option:hover,
.wf-status__option:focus-visible {
    background: color-mix(in srgb, var(--color-bg-secondary) 82%, transparent);
    color: var(--color-text-primary);
    outline: none;
}

.wf-status__option[aria-selected='true'] {
    background: color-mix(in srgb, var(--wf-status-color) calc(9% * var(--wf-status-tint) / 100%), var(--color-bg-secondary));
    color: color-mix(in srgb, var(--wf-status-color) 82%, var(--color-text-primary));
    font-weight: 620;
}

.wf-status__option-icon {
    flex: none;
    width: 13px;
    height: 13px;
    color: var(--wf-status-color);
    opacity: 0.55;
    transition: opacity 140ms ease;
}

.wf-status__option:hover .wf-status__option-icon,
.wf-status__option[aria-selected='true'] .wf-status__option-icon {
    opacity: 1;
}

.wf-status__option-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wf-status__check {
    flex: none;
    width: 12px;
    height: 12px;
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 150ms ease, transform 220ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.wf-status__option[aria-selected='true'] .wf-status__check {
    opacity: 1;
    transform: scale(1);
}

/* Options settle in one after another as the menu opens. */
@media (prefers-reduced-motion: no-preference) {
    .wf-status.is-open .wf-status__option {
        animation: wf-status-option-in 230ms cubic-bezier(0.22, 1, 0.36, 1) both;
        animation-delay: calc(var(--wf-status-index, 0) * 34ms + 25ms);
    }

    .wf-status--card.is-open .wf-status__option {
        /* Opening upward, so the rows should rise into place, not drop. */
        animation-name: wf-status-option-in-up;
    }
}

@keyframes wf-status-option-in {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes wf-status-option-in-up {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Raise the whole card while its menu is out, or neighbours overlap it. */
#workflow-studio-view .wf-session-card.is-status-open {
    z-index: 34;
}

/* ─── Resume progress on unfinished cards ──────────────────────────────────── */

#workflow-studio-view .wf-session-card__progress {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 4;
    height: 3px;
    background: rgba(17, 19, 22, 0.22);
}

#workflow-studio-view .wf-session-card__progress > span {
    display: block;
    height: 100%;
    width: var(--wf-progress, 0%);
    border-radius: 0 999px 999px 0;
    background: linear-gradient(
        90deg,
        color-mix(in srgb, var(--color-primary) 70%, transparent),
        var(--color-primary)
    );
    box-shadow: 0 0 10px -2px color-mix(in srgb, var(--color-primary) 80%, transparent);
}

@media (prefers-reduced-motion: no-preference) {
    #workflow-studio-view .wf-session-card__progress > span {
        animation: wf-progress-fill 760ms cubic-bezier(0.22, 1, 0.36, 1) both;
    }
}

@keyframes wf-progress-fill {
    from { width: 0%; }
    to { width: var(--wf-progress, 0%); }
}

/* A card the active Status filter no longer matches leaves before the redraw. */
#workflow-studio-view .wf-session-card.is-leaving {
    pointer-events: none;
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 200ms ease, transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* ─── In-session header control ────────────────────────────────────────────── */

.wf-session-header-status[hidden] {
    display: none;
}

.wf-session-header-status {
    display: inline-flex;
    align-items: center;
}

.wf-status--header .wf-status__trigger {
    min-height: 30px;
    padding: 0 8px 0 10px;
    border-radius: 8px;
    gap: 7px;
    font-size: 0.78rem;
}

.wf-status--header .wf-status__icon {
    width: 13px;
    height: 13px;
}

/* Nudge the creator exactly once, at the moment the script lands. */
@media (prefers-reduced-motion: no-preference) {
    .wf-session-header-status.is-attention .wf-status__trigger {
        animation: wf-status-confirm 1500ms cubic-bezier(0.22, 1, 0.36, 1) 2;
    }
}

/* ─── Dark theme ───────────────────────────────────────────────────────────── */

[data-theme='dark'] .wf-status__menu {
    background: var(--color-surface-elevated);
    border-color: color-mix(in srgb, var(--color-border-light) 46%, transparent);
    box-shadow: 0 24px 50px -28px rgba(0, 0, 0, 0.76);
}

[data-theme='dark'] .wf-status__trigger {
    border-color: color-mix(in srgb, var(--color-border-light) 52%, transparent);
}

[data-theme='dark'] .wf-status__option:hover,
[data-theme='dark'] .wf-status__option:focus-visible {
    background: color-mix(in srgb, var(--color-bg-secondary) 60%, transparent);
}

[data-theme='dark'] #workflow-studio-view .wf-session-card__progress {
    background: rgba(255, 255, 255, 0.14);
}

/* ─── Narrow screens ───────────────────────────────────────────────────────── */

@media (max-width: 640px) {
    #workflow-studio-view .wf-session-card__meta {
        gap: 8px;
    }

    .wf-status__label {
        max-width: 92px;
    }
}
