/* ───────────────────────────────────────────────────────────────────────────
   Sessions: the table view, the grid/table switch, and the script-number chip.

   Loaded after workflow-session-status.css so the status control can be
   re-fitted for a table row without touching its card styling.

   Three pieces:
     · .wf-view-toggle     segmented grid/table switch in the controls row
     · .wf-session-number  "#13" — the same chip in both views
     · .wf-sessions-table  the table view itself
   ─────────────────────────────────────────────────────────────────────────── */

#workflow-studio-view .wf-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ─── View toggle ──────────────────────────────────────────────────────────
   Same footprint as the Sort / Filter buttons beside it: shared padding, border,
   radius and surface colour so the controls row reads as one set of controls. */

#workflow-studio-view .wf-view-toggle {
    display: inline-flex;
    flex: none;
    align-items: stretch;
    gap: 0;
    padding: 0;
    border: var(--border-width-thin, 1px) solid var(--color-border-light);
    border-radius: var(--border-radius-base, 8px);
    background: var(--color-surface-elevated);
    overflow: hidden;
}

#workflow-studio-view .wf-view-toggle__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2, 8px);
    /* Match .sort-menu-btn / .filter-menu-btn: same padding + content height. */
    min-height: 44px;
    min-width: 0;
    padding: var(--space-3, 12px) var(--space-4, 16px);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--color-text-primary);
    font-size: var(--font-size-sm, 14px);
    font-weight: var(--font-weight-medium, 500);
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s ease;
}

#workflow-studio-view .wf-view-toggle__btn span {
    display: inline-block;
}

#workflow-studio-view .wf-view-toggle__btn + .wf-view-toggle__btn {
    border-left: var(--border-width-thin, 1px) solid var(--color-border-light);
}

#workflow-studio-view .wf-view-toggle__btn i,
#workflow-studio-view .wf-view-toggle__btn svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

#workflow-studio-view .wf-view-toggle__btn:hover {
    background: var(--color-gray-100, color-mix(in srgb, var(--color-text-primary) 6%, transparent));
    color: var(--color-text-primary);
}

[data-theme="dark"] #workflow-studio-view .wf-view-toggle__btn:hover {
    background: rgba(255, 255, 255, 0.06);
}

#workflow-studio-view .wf-view-toggle__btn.is-active {
    background: var(--color-primary-50, color-mix(in srgb, var(--color-primary) 12%, var(--color-surface-elevated)));
    color: var(--color-primary-600, color-mix(in srgb, var(--color-primary) 78%, var(--color-text-primary)));
}

[data-theme="dark"] #workflow-studio-view .wf-view-toggle__btn.is-active {
    background: var(--color-primary-light, color-mix(in srgb, var(--color-primary) 18%, transparent));
    color: var(--color-primary-400, var(--color-primary));
}

#workflow-studio-view .wf-view-toggle__btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    z-index: 1;
}

/* Under 769px mobile.css stacks the controls row, so the switch becomes a
   full-width segmented control rather than two icons floating in a wide bar. */
@media (max-width: 768px) {
    #workflow-studio-view .wf-view-toggle {
        align-self: stretch;
    }

    #workflow-studio-view .wf-view-toggle__btn {
        flex: 1;
    }
}

/* ─── Script number chip ───────────────────────────────────────────────────
   Deliberately quiet: it is an identifier, not a state. Tabular figures keep a
   column of them optically aligned in the table. */

#workflow-studio-view .wf-session-number {
    display: inline-flex;
    align-items: center;
    flex: none;
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--color-text-secondary);
    background: color-mix(in srgb, var(--color-text-primary) 6%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-border-light) 70%, transparent);
}

#workflow-studio-view .wf-session-number--card {
    /* Sits in the uppercase eyebrow row, so it opts out of that casing. */
    min-height: 17px;
    padding: 0 5px;
    border-radius: 5px;
    font-size: 10.5px;
    letter-spacing: 0;
    text-transform: none;
}

#workflow-studio-view .wf-session-number--table {
    min-height: 22px;
    padding: 0 7px;
    border-radius: 6px;
    font-size: 12px;
}

/* Keep the number + phase together on the left, date on the right. */
#workflow-studio-view .wf-session-card__eyebrow {
    gap: 6px;
}

#workflow-studio-view .wf-session-card__phase {
    margin-right: auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── Table ────────────────────────────────────────────────────────────────
   The list container is the scroller for both axes, which is what lets the
   header row stay stuck while rows pass under it. The shell must therefore not
   create a scroll context of its own — it only draws the frame. */

#workflow-studio-view .wf-sessions-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding-bottom: 20px;
}

#workflow-studio-view .wf-sessions-table__shell {
    min-width: 0;
    width: 100%;
    border: 1px solid color-mix(in srgb, var(--color-border-light) 82%, transparent);
    border-radius: 12px;
    background: var(--color-surface-elevated);
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 10px 26px -24px rgba(15, 23, 42, 0.26);
}

#workflow-studio-view .wf-sessions-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

#workflow-studio-view .wf-sessions-table__th {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 0 14px;
    height: 40px;
    /* Opaque: rows scroll underneath this. */
    background: var(--color-surface-base);
    border-bottom: 1px solid color-mix(in srgb, var(--color-border-light) 88%, transparent);
    color: var(--color-text-tertiary);
    font-size: 11px;
    font-weight: var(--font-weight-semibold, 600);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__th:first-child {
    border-top-left-radius: 12px;
    padding-left: 16px;
}

#workflow-studio-view .wf-sessions-table__th:last-child {
    border-top-right-radius: 12px;
    padding-right: 12px;
}

/* Sortable header: the whole cell is the target, the chevron only shows
   direction once the column is actually the one being sorted by. */
#workflow-studio-view .wf-sessions-table__sort {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 40px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
    transition: color 0.16s ease;
}

#workflow-studio-view .wf-sessions-table__sort:hover {
    color: var(--color-text-primary);
}

#workflow-studio-view .wf-sessions-table__sort:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

#workflow-studio-view .wf-sessions-table__th.is-sorted {
    color: var(--color-text-primary);
}

#workflow-studio-view .wf-sessions-table__sort-icon {
    width: 12px;
    height: 12px;
    opacity: 0;
    transition: opacity 0.16s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

#workflow-studio-view .wf-sessions-table__sort:hover .wf-sessions-table__sort-icon {
    opacity: 0.4;
}

#workflow-studio-view .wf-sessions-table__sort[data-direction='ascending'] .wf-sessions-table__sort-icon,
#workflow-studio-view .wf-sessions-table__sort[data-direction='descending'] .wf-sessions-table__sort-icon {
    opacity: 0.85;
}

#workflow-studio-view .wf-sessions-table__sort[data-direction='ascending'] .wf-sessions-table__sort-icon {
    transform: rotate(180deg);
}

/* ─── Rows ─────────────────────────────────────────────────────────────── */

#workflow-studio-view .wf-sessions-table__row {
    cursor: pointer;
    transition: background 0.16s ease, opacity 0.2s ease, transform 0.2s ease;
}

#workflow-studio-view .wf-sessions-table__row:hover {
    background: color-mix(in srgb, var(--color-primary) 5%, var(--color-surface-elevated));
}

#workflow-studio-view .wf-sessions-table__row:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Opening: the row dims like the cards do, and stops responding. */
#workflow-studio-view .wf-sessions-table__row.is-opening {
    pointer-events: none;
    background: color-mix(in srgb, var(--color-primary) 9%, var(--color-surface-elevated));
}

#workflow-studio-view #wf-sessions-grid.wf-sessions-grid--opening .wf-sessions-table__row:not(.is-opening) {
    opacity: 0.5;
}

/* Matches the card's exit when a status change filters it away. */
#workflow-studio-view .wf-sessions-table__row.is-leaving {
    opacity: 0;
    transform: translateX(10px);
}

#workflow-studio-view .wf-sessions-table__td {
    padding: 10px 14px;
    height: auto;
    min-height: 58px;
    border-bottom: 1px solid color-mix(in srgb, var(--color-border-light) 58%, transparent);
    color: var(--color-text-secondary);
    vertical-align: middle;
}

#workflow-studio-view .wf-sessions-table__td:first-child {
    padding-left: 16px;
}

#workflow-studio-view .wf-sessions-table__td:last-child {
    padding-right: 12px;
}

#workflow-studio-view .wf-sessions-table__row:last-child .wf-sessions-table__td {
    border-bottom: 0;
}

#workflow-studio-view .wf-sessions-table__td--number {
    width: 1%;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__td--type {
    width: 1%;
    white-space: nowrap;
}

/* Compact packaging-type chip — same visual weight as the status control,
   so the row still reads as metadata rather than a dashboard of badges. */
#workflow-studio-view .wf-sessions-table__type {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 6px;
    border: 1px solid color-mix(in srgb, var(--wf-type-color, var(--color-border-light)) 28%, transparent);
    background: color-mix(in srgb, var(--wf-type-color, var(--color-text-secondary)) 8%, transparent);
    color: color-mix(in srgb, var(--wf-type-color, var(--color-text-secondary)) 78%, var(--color-text-primary));
    font-size: 0.72rem;
    font-weight: 560;
    letter-spacing: -0.005em;
    line-height: 1;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__type--problem {
    --wf-type-color: #c2410c;
}

#workflow-studio-view .wf-sessions-table__type--solution {
    --wf-type-color: var(--color-success, #16a34a);
}

#workflow-studio-view .wf-sessions-table__type--outlier {
    --wf-type-color: var(--color-primary);
}

#workflow-studio-view .wf-sessions-table__dash {
    color: var(--color-text-tertiary);
    opacity: 0.6;
}

/* ─── Title / thumb-text cells ─────────────────────────────────────────── */

#workflow-studio-view .wf-sessions-table__td--title,
#workflow-studio-view .wf-sessions-table__td--thumbText {
    min-width: 140px;
    max-width: 320px;
}

#workflow-studio-view .wf-sessions-table__td--title {
    width: 28%;
    max-width: 360px;
}

#workflow-studio-view .wf-sessions-table__clamp,
#workflow-studio-view .wf-sessions-table__title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    word-break: break-word;
    color: var(--color-text-primary);
    font-size: 13px;
    line-height: 1.35;
}

#workflow-studio-view .wf-sessions-table__title {
    font-size: 13.5px;
    font-weight: var(--font-weight-semibold, 600);
    letter-spacing: -0.01em;
}

#workflow-studio-view .wf-sessions-table__td--thumbnail {
    width: 1%;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__thumb-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#workflow-studio-view .wf-sessions-table__thumb {
    position: relative;
    display: grid;
    place-items: center;
    width: 72px;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: 5px;
    background: color-mix(in srgb, var(--color-bg-tertiary) 80%, var(--color-surface-elevated));
    color: var(--color-text-tertiary);
}

#workflow-studio-view .wf-sessions-thumb-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 6px;
    border: 1px solid var(--color-border-light);
    background: var(--color-surface-elevated);
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

#workflow-studio-view .wf-sessions-thumb-link:hover,
#workflow-studio-view .wf-sessions-thumb-link:focus-visible {
    color: var(--color-text-primary);
    border-color: var(--color-border);
    background: color-mix(in srgb, var(--color-bg-tertiary) 55%, var(--color-surface-elevated));
}

#workflow-studio-view .wf-sessions-thumb-link:focus-visible {
    outline: 2px solid var(--color-accent, #3b82f6);
    outline-offset: 2px;
}

#workflow-studio-view .wf-sessions-thumb-link i,
#workflow-studio-view .wf-sessions-thumb-link svg {
    width: 14px;
    height: 14px;
}

#workflow-studio-view .wf-sessions-table__thumb img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* lucide swaps the <i> placeholder for an <svg>, keeping its classes — both
   selectors are needed because the swap happens after the row is inserted. */
#workflow-studio-view .wf-sessions-table__thumb > i,
#workflow-studio-view .wf-sessions-table__thumb > svg {
    width: 15px;
    height: 15px;
    opacity: 0.45;
}

/* The fallback glyph is behind the image; it only shows when there is none. */
#workflow-studio-view .wf-sessions-table__thumb:not(.is-empty) .wf-sessions-table__thumb-fallback {
    display: none;
}

/* ─── Progress cells ───────────────────────────────────────────────────── */

#workflow-studio-view .wf-sessions-table__phase {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

#workflow-studio-view .wf-sessions-table__phase-label {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__bar {
    display: block;
    width: 100%;
    max-width: 128px;
    height: 3px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--color-text-primary) 9%, transparent);
    overflow: hidden;
}

#workflow-studio-view .wf-sessions-table__bar > span {
    display: block;
    width: var(--wf-progress, 0%);
    height: 100%;
    border-radius: inherit;
    background: color-mix(in srgb, var(--color-primary) 72%, transparent);
}

/* A finished script reads as a state, not a bar at 100%. */
#workflow-studio-view .wf-sessions-table__phase--complete {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    color: color-mix(in srgb, var(--color-success, #16a34a) 72%, var(--color-text-primary));
    font-weight: var(--font-weight-medium, 500);
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__phase--complete i,
#workflow-studio-view .wf-sessions-table__phase--complete svg {
    width: 14px;
    height: 14px;
}

/* ─── Status cell ──────────────────────────────────────────────────────── */

#workflow-studio-view .wf-sessions-table__td--status {
    min-width: 152px;
}

#workflow-studio-view .wf-sessions-table__status-placeholder {
    color: var(--color-text-tertiary);
    font-size: 12px;
}

/* The row is a click target, so the control has to look like the exception. */
#workflow-studio-view .wf-status--table .wf-status__trigger {
    min-height: 26px;
    background: var(--color-surface-elevated);
}

#workflow-studio-view .wf-sessions-table__row:hover .wf-status--table .wf-status__trigger {
    border-color: color-mix(in srgb, var(--wf-status-color) 34%, var(--color-border-light));
}

/* Positioned against the viewport by workflowSessionStatus.js — an absolutely
   positioned menu would be clipped by the scrolling list on the outer rows. */
#workflow-studio-view .wf-status--table .wf-status__menu {
    position: fixed;
    right: auto;
    transform-origin: top left;
    transform: translateY(-4px) scale(0.97);
}

#workflow-studio-view .wf-status--table.is-flipped .wf-status__menu {
    transform-origin: bottom left;
    transform: translateY(4px) scale(0.97);
}

#workflow-studio-view .wf-status--table.is-open .wf-status__menu {
    transform: translateY(0) scale(1);
}

/* ─── Actions cell ─────────────────────────────────────────────────────── */

#workflow-studio-view .wf-sessions-table__td--actions {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

#workflow-studio-view .wf-sessions-table__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-tertiary);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.16s ease, color 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

#workflow-studio-view .wf-sessions-table__row:hover .wf-sessions-table__delete,
#workflow-studio-view .wf-sessions-table__delete:focus-visible {
    opacity: 1;
}

#workflow-studio-view .wf-sessions-table__delete:hover {
    color: var(--color-error, #dc2626);
    background: color-mix(in srgb, var(--color-error, #dc2626) 10%, transparent);
    border-color: color-mix(in srgb, var(--color-error, #dc2626) 26%, transparent);
}

#workflow-studio-view .wf-sessions-table__delete i,
#workflow-studio-view .wf-sessions-table__delete svg {
    width: 15px;
    height: 15px;
}

/* Touch and keyboard users never get a hover, so the action must not hide. */
@media (hover: none) {
    #workflow-studio-view .wf-sessions-table__delete {
        opacity: 1;
    }
}

/* Empty state fills the width instead of sitting in a table frame. The button
   rules mirror the grid's (workflow-sessions.css) so both views match. */
#workflow-studio-view .wf-sessions-list .wf-sessions-empty {
    width: 100%;
}

#workflow-studio-view .wf-sessions-list .wf-sessions-empty .empty-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
}

#workflow-studio-view .wf-sessions-list .wf-sessions-empty .empty-actions i,
#workflow-studio-view .wf-sessions-list .wf-sessions-empty .empty-actions [data-lucide] {
    width: 18px;
    height: 18px;
}

/* ─── Narrower viewports ───────────────────────────────────────────────────
   Columns drop in reverse order of how much they help you find a script:
   progress first, then thumb text, then the date. Number, type, title,
   thumbnail and status survive to the smallest size. */

@media (max-width: 1280px) {
    #workflow-studio-view .wf-sessions-table__th--progress,
    #workflow-studio-view .wf-sessions-table__td--progress {
        display: none;
    }
}

@media (max-width: 1100px) {
    #workflow-studio-view .wf-sessions-table__th--thumbText,
    #workflow-studio-view .wf-sessions-table__td--thumbText,
    #workflow-studio-view .wf-sessions-table__th--updated,
    #workflow-studio-view .wf-sessions-table__td--updated {
        display: none;
    }
}

@media (max-width: 760px) {
    #workflow-studio-view .wf-sessions-table__th,
    #workflow-studio-view .wf-sessions-table__td {
        padding: 8px 10px;
    }

    #workflow-studio-view .wf-sessions-table__td--title {
        min-width: 110px;
        max-width: 180px;
    }

    #workflow-studio-view .wf-sessions-table__thumb {
        width: 56px;
    }

    #workflow-studio-view .wf-view-toggle__btn {
        min-width: 44px;
        padding: var(--space-3, 12px) var(--space-3, 12px);
    }
}
