/**
 * Flow Control Widget Styles
 */

.flow-config-widget,
.flow-control-widget {
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.flow-stages {
    flex-wrap: wrap;
}

.stage-name-wrap {
    display: inline-flex;
    align-items: center;
    min-width: 0;
}

.stage-name-short {
    display: none;
}

.flow-control-segments {
    display: grid;
    grid-template-columns: repeat(var(--flow-segment-count, 1), minmax(0, 1fr));
    gap: 0.3rem;
    padding: 0;
    margin: 0;
    background: transparent;
    border-radius: 999px;
}

.flow-progress-segment {
    display: block;
    min-width: 0;
    height: 0.5rem;
    border-radius: 999px;
    border: 1px solid rgba(164, 180, 204, 0.22);
    background: rgba(83, 96, 114, 0.24);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.flow-progress-segment.is-complete {
    background: #39d98a;
    border-color: rgba(57, 217, 138, 0.95);
}

.flow-progress-segment.is-running {
    background: linear-gradient(90deg,
            #39d98a 0,
            #39d98a var(--flow-segment-progress, 45%),
            rgba(83, 96, 114, 0.22) var(--flow-segment-progress, 45%),
            rgba(83, 96, 114, 0.22) 100%);
    border-color: rgba(57, 217, 138, 0.72);
}

.flow-progress-segment.is-paused {
    background: rgba(255, 193, 7, 0.34);
    border-color: rgba(255, 193, 7, 0.7);
}

.flow-progress-segment.is-error {
    background: rgba(220, 53, 69, 0.48);
    border-color: rgba(220, 53, 69, 0.78);
}

.flow-progress-segment.is-skipped {
    background: rgba(120, 131, 145, 0.18);
    border-color: rgba(160, 173, 189, 0.22);
}

.flow-stage-item {
    position: relative;
}

.stage-box {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.6rem;
    background: var(--bs-light, #f8f9fa);
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.8rem;
    position: relative;
}

.stage-box:hover {
    background: var(--bs-gray-200, #e9ecef);
}

.stage-box.stage-disabled {
    opacity: 0.5;
    text-decoration: line-through;
    background: var(--bs-gray-300, #dee2e6);
}

.stage-box.stage-click-opens-view {
    cursor: pointer;
}

.stage-box.stage-current {
    box-shadow: 0 0 0 2px var(--bs-primary, #0d6efd);
}

.stage-box.stage-viewing::after {
    content: '';
    position: absolute;
    left: 0.45rem;
    right: 0.45rem;
    bottom: 0.24rem;
    height: 0.18rem;
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(255, 214, 102, 0.98), rgba(245, 158, 11, 0.98));
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.15), 0 4px 10px rgba(245, 158, 11, 0.28);
    pointer-events: none;
}

/* Status-based colors */
.stage-box-secondary {
    border-color: var(--bs-secondary, #6c757d);
}

.stage-box-primary {
    border-color: var(--bs-primary, #0d6efd);
    background: rgba(13, 110, 253, 0.1);
}

.stage-box-primary .stage-icon {
    animation: spin 1s linear infinite;
}

.stage-box-warning {
    border-color: var(--bs-warning, #ffc107);
    background: rgba(255, 193, 7, 0.15);
}

/* Resume button - prominent yellow action button */
.stage-box.resume-flow-btn {
    background: var(--bs-warning, #ffc107);
    border-color: var(--bs-warning, #ffc107);
    color: #212529;
    padding: 0.4rem 1rem;
    font-weight: 500;
}

.stage-box.resume-flow-btn .stage-icon,
.stage-box.resume-flow-btn .stage-name {
    color: #212529;
}

.stage-box.resume-flow-btn:hover {
    background: #e0a800;
    border-color: #d39e00;
}

.stage-box.resume-flow-btn.resuming {
    opacity: 0.7;
    pointer-events: none;
}

/* Complete button - green indicator for finished flows */
.stage-box.stage-box-complete {
    background: var(--bs-success, #198754);
    border-color: var(--bs-success, #198754);
    color: #fff;
    padding: 0.4rem 1rem;
    font-weight: 500;
    cursor: default;
}

.stage-box.stage-box-complete .stage-icon,
.stage-box.stage-box-complete .stage-name {
    color: #fff;
}

.stage-box-success {
    border-color: var(--bs-success, #198754);
    background: rgba(25, 135, 84, 0.1);
}

.stage-box-success .stage-icon {
    color: var(--bs-success, #198754);
}

.stage-box-danger {
    border-color: var(--bs-danger, #dc3545);
    background: rgba(220, 53, 69, 0.1);
}

.stage-box-danger .stage-icon {
    color: var(--bs-danger, #dc3545);
}

.stage-icon {
    font-size: 0.9rem;
}

.stage-name {
    white-space: nowrap;
}

.stage-progress {
    font-size: 0.7rem;
    color: var(--bs-secondary, #6c757d);
    margin-left: 0.25rem;
}

/* Pause toggle button */
.pause-toggle {
    padding: 0.1rem 0.25rem;
    margin-left: 0.25rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    color: var(--bs-secondary, #6c757d);
    opacity: 0.5;
    transition: all 0.15s ease;
}

.pause-toggle:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
}

.pause-toggle.pause-active {
    opacity: 1;
    color: var(--bs-warning, #ffc107);
    background: rgba(255, 193, 7, 0.2);
    border-color: var(--bs-warning, #ffc107);
}

.pause-toggle:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Restart button */
.restart-stage-btn {
    padding: 0.1rem 0.25rem;
    margin-left: 0.15rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    color: var(--bs-secondary, #6c757d);
    opacity: 0.5;
    transition: all 0.15s ease;
}

.restart-stage-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.1);
    color: var(--bs-info, #0dcaf0);
}

/* Non-skippable stages */
.stage-box.stage-non-skippable {
    cursor: default;
}

.stage-box.stage-non-skippable.stage-click-opens-view {
    cursor: pointer;
}

/* Arrow between stages */
.flow-stage-item .bi-arrow-right {
    font-size: 0.75rem;
    opacity: 0.5;
}

/* Resume button */
.resume-flow-btn {
    font-size: 0.85rem;
}

/* Animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Match app-level dark theme (UNCEN sets body.bg-dark regardless of OS color scheme). */
body.bg-dark .flow-config-widget,
body.bg-dark .flow-control-widget {
    background: rgba(255, 255, 255, 0.05);
}

body.bg-dark .stage-box {
    background: var(--bs-dark, #212529);
    border-color: var(--bs-gray-700, #495057);
}

/* Preserve semantic action colors in dark theme for primary flow controls. */
body.bg-dark .stage-box.resume-flow-btn {
    background: var(--bs-warning, #ffc107);
    border-color: var(--bs-warning, #ffc107);
    color: #212529;
}

body.bg-dark .stage-box.resume-flow-btn .stage-icon,
body.bg-dark .stage-box.resume-flow-btn .stage-name {
    color: #212529;
}

body.bg-dark .stage-box.resume-flow-btn:hover {
    background: #e0a800;
    border-color: #d39e00;
}

body.bg-dark .stage-box.stage-box-complete {
    background: var(--bs-success, #198754);
    border-color: var(--bs-success, #198754);
    color: #fff;
}

body.bg-dark .stage-box.stage-box-complete .stage-icon,
body.bg-dark .stage-box.stage-box-complete .stage-name {
    color: #fff;
}

body.bg-dark .stage-box:hover {
    background: var(--bs-gray-800, #343a40);
}

body.bg-dark .stage-box.stage-disabled {
    background: var(--bs-gray-900, #212529);
}

/* Simple mode compact styling */
.flow-control-simple .flow-stages {
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
    gap: 0.35rem !important;
}

.flow-control-simple .flow-stage-item {
    flex: 1 1 0;
    min-width: 0;
    container-type: inline-size;
}

.flow-control-simple .flow-stage-item-action {
    flex: 0 0 auto;
    position: relative;
    z-index: 1;
    min-width: max-content;
}

.flow-control-simple .flow-stage-item-action .stage-box {
    width: auto;
    min-width: max-content;
    flex: 0 0 auto;
    justify-content: center;
    white-space: nowrap;
}

.flow-control-simple .flow-stage-item-action .stage-arrow {
    flex: 0 0 auto;
    white-space: nowrap;
}

.flow-control-simple .stage-box {
    width: 100%;
    min-width: 0;
    padding: 0.32rem 0.45rem;
    gap: 0.28rem;
    justify-content: space-between;
}

.flow-control-simple .stage-main {
    display: flex;
    align-items: center;
    gap: 0.28rem;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
}

.flow-control-simple .stage-text {
    display: flex;
    align-items: center;
    gap: 0.28rem;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
}

.flow-control-simple .stage-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.15rem;
    flex: 0 0 auto;
    margin-left: auto;
}

.flow-control-simple .stage-name-wrap,
.flow-control-simple .stage-name,
.flow-control-simple .stage-progress-group {
    min-width: 0;
}

.flow-control-simple .stage-name-wrap {
    flex: 0 1 auto;
    overflow: hidden;
}

.flow-control-simple .stage-progress-group {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    flex: 0 1 auto;
}

.flow-control-simple .stage-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-control-simple .stage-progress {
    margin-left: 0;
    flex: 0 1 auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-control-simple .stage-progress-compact {
    display: none;
}

.flow-control-simple .pause-toggle,
.flow-control-simple .restart-stage-btn {
    flex: 0 0 auto;
    margin-left: 0;
}

.flow-control-simple .flow-settings-btn {
    padding: 0.28rem 0.45rem;
}

.flow-control-simple .stage-box {
    font-size: 0.75rem;
}

.flow-control-simple .stage-icon {
    font-size: 0.8rem;
}

.flow-control-simple .pause-toggle {
    padding: 0.05rem 0.2rem;
    font-size: 0.7rem;
}

@container (max-width: 220px) {
    .flow-control-simple .flow-stage-item .bi-arrow-right {
        display: none;
    }
}

.flow-control-simple .flow-stage-item[data-stage-layout="short"] .stage-name-full {
    display: none;
}

.flow-control-simple .flow-stage-item[data-stage-layout="short"] .stage-name-short {
    display: inline;
}

.flow-control-simple .flow-stage-item[data-stage-layout="short"] .stage-progress-full {
    display: none;
}

.flow-control-simple .flow-stage-item[data-stage-layout="short"] .stage-progress-compact {
    display: inline;
}

.flow-control-simple .flow-stage-item[data-stage-layout="icon"] .stage-name-wrap,
.flow-control-simple .flow-stage-item[data-stage-layout="icon"] .stage-progress-group {
    display: none;
}

.flow-control-simple .flow-stage-item[data-stage-actions="pause"] .restart-stage-btn {
    display: none;
}

.flow-control-simple .flow-stage-item[data-stage-actions="restart"] .pause-toggle {
    display: none;
}

.flow-control-simple .flow-stage-item[data-stage-actions="none"] .pause-toggle,
.flow-control-simple .flow-stage-item[data-stage-actions="none"] .restart-stage-btn {
    display: none;
}

@media (max-width: 1200px) {
    .flow-control-simple .flow-stage-item .bi-arrow-right,
    .flow-control-simple .stage-arrow {
        display: none;
    }

    /* Collapse "Resume" / "Complete" text to icon-only */
    .flow-control-simple .resume-flow-btn .stage-name,
    .flow-control-simple .flow-complete-btn .stage-name {
        display: none;
    }

    .flow-control-simple .resume-flow-btn,
    .flow-control-simple .flow-complete-btn {
        padding: 0.32rem 0.5rem;
        min-width: 2rem;
    }
}

@media (max-width: 768px) {
    .flow-control-simple .flow-stages {
        gap: 0.25rem !important;
    }

    .flow-control-simple .stage-box {
        padding: 0.26rem 0.3rem;
        gap: 0.18rem;
        font-size: 0.68rem;
    }

    .flow-control-simple .stage-icon {
        font-size: 0.76rem;
    }

    .flow-control-simple .pause-toggle,
    .flow-control-simple .restart-stage-btn,
    .flow-control-simple .flow-settings-btn {
        padding: 0.04rem 0.14rem;
        font-size: 0.62rem;
    }
}
