/* Workflow Manager Pill */
.workflow-manager-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    background-color: rgba(255, 140, 0, 0.1);
    color: #ff8c00;
    border-color: rgba(255, 140, 0, 0.2);
}

.workflow-manager-pill:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--shadow-color);
    border-color: #ff8c00;
    background-color: rgba(255, 140, 0, 0.15);
}

/* Modal Container - FULLSCREEN */
.workflow-manager-modal-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

/* Modal Content - renamed and now can be as wide as needed */
.workflow-manager-modal-content {
    width: 100vw;
    max-width: 1800px;
    height: 94vh;
    background: var(--bg-primary);
    border-radius: 12px;
    display: flex;
    position: relative;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

/* Close Button */
.workflow-modal-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.workflow-modal-close:hover {
    background: rgba(255, 140, 0, 0.2);
    border-color: #ff8c00;
}

/* Left Panel - Labels */
.workflow-modal-left {
    width: 18%;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    padding: 20px 16px; /* Match top padding with right panel */
    overflow-y: auto;
    position: relative;
}

.workflow-modal-section-title {
    color: #ff8c00;
    font-size: 18px;
    margin: 0 0 12px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    height: 32px; /* Match close button height for alignment */
}

.workflow-modal-section-title svg {
    flex-shrink: 0;
}

.workflow-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ff8c00;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    padding: 0;
    border: none;
}

.workflow-section-header svg {
    flex-shrink: 0;
}

.workflow-add-label-btn {
    background: transparent;
    border: 1px solid var(--text-tertiary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    transition: all 0.2s;
}

.workflow-add-label-btn:hover {
    color: #ff8c00;
    border-color: #ff8c00;
    background: rgba(255, 140, 0, 0.1);
}

/* More compact label items */
.workflow-label-item {
    display: flex;
    align-items: center;
    gap: 6px; /* Reduced from 8px */
    padding: 6px 8px; /* Reduced padding */
    margin-bottom: 4px; /* Reduced gap between items */
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    font-size: 13px; /* Slightly smaller text */
}

.workflow-label-icon {
    width: 14px; /* Slightly smaller icon */
    height: 14px;
    flex-shrink: 0;
}

.workflow-label-item:hover {
    background: var(--link-hover-bg);
}

.workflow-label-item:hover {
    background: var(--link-hover-bg);
}

.workflow-label-name {
    flex: 1;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workflow-label-name:hover {
    color: #ff8c00;
    text-decoration: underline;
}

.workflow-label-delete {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    padding: 2px; /* Smaller padding */
    transition: all 0.2s;
}

.workflow-no-labels {
    text-align: center;
    color: var(--text-tertiary);
    padding: 16px 8px;
    font-style: italic;
    font-size: 13px;
}

.workflow-label-delete svg {
    width: 12px; /* Smaller delete icon */
    height: 12px;
}

.workflow-label-item:hover .workflow-label-delete {
    opacity: 0.6;
}

.workflow-label-delete:hover {
    opacity: 1 !important;
    color: var(--error-color);
}

/* Right Panel - Chains */
.workflow-modal-right {
    flex: 1;
    padding: 20px 24px 24px 24px; /* Adjusted top padding */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* --- Custom minimal scroll bar --- */

/* For contentOutput - Applied to both left and right modals */
.workflow-modal-left::-webkit-scrollbar,
.workflow-modal-left *::-webkit-scrollbar,
.workflow-modal-right::-webkit-scrollbar,
.workflow-modal-right *::-webkit-scrollbar {
    width: 1px !important;
    height: 0 !important;
}

.workflow-modal-left::-webkit-scrollbar-track,
.workflow-modal-left *::-webkit-scrollbar-track,
.workflow-modal-right::-webkit-scrollbar-track,
.workflow-modal-right *::-webkit-scrollbar-track {
    background: transparent !important;
}

.workflow-modal-left::-webkit-scrollbar-thumb,
.workflow-modal-left *::-webkit-scrollbar-thumb,
.workflow-modal-right::-webkit-scrollbar-thumb,
.workflow-modal-right *::-webkit-scrollbar-thumb {
    background: var(--text-stream) !important;
    border-radius: 1px !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
}

.workflow-modal-left:hover::-webkit-scrollbar-thumb,
.workflow-modal-left *:hover::-webkit-scrollbar-thumb,
.workflow-modal-right:hover::-webkit-scrollbar-thumb,
.workflow-modal-right *:hover::-webkit-scrollbar-thumb {
    opacity: 0.4 !important;
}

.workflow-modal-left::-webkit-scrollbar-thumb:hover,
.workflow-modal-left *::-webkit-scrollbar-thumb:hover,
.workflow-modal-right::-webkit-scrollbar-thumb:hover,
.workflow-modal-right *::-webkit-scrollbar-thumb:hover {
    opacity: 0.6 !important;
}

.workflow-modal-left,
.workflow-modal-left *,
.workflow-modal-right,
.workflow-modal-right * {
    scrollbar-width: thin !important;
    scrollbar-color: transparent transparent !important;
    transition: scrollbar-color 0.3s ease !important;
}

.workflow-modal-left:hover,
.workflow-modal-left *:hover,
.workflow-modal-right:hover,
.workflow-modal-right *:hover {
    scrollbar-color: var(--text-stream) transparent !important;
}


/* Ensure search container doesn't overlap */
.workflow-search-container {
    position: relative;
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    width: 100%; /* Full width */
}

.workflow-search-input {
    flex: 1;
    padding: 10px 64px 10px 16px;
    font-size: 14px;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s;
}

.workflow-search-input:focus {
    outline: none;
    border-color: #ff8c00;
}

.workflow-search-input:disabled {
    background-color: rgba(255, 140, 0, 0.1);
    color: #ff8c00;
    border-color: #ff8c00;
}

/* Search Buttons - FIXED positioning */
.workflow-search-clear,
.workflow-search-submit {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-tertiary);
    transition: all 0.2s;
}

.workflow-search-clear {
    right: 34px;
}

.workflow-search-submit {
    right: 4px;
}

.workflow-search-clear:hover,
.workflow-search-submit:hover {
    color: #ff8c00;
    background: rgba(255, 140, 0, 0.1);
}

.workflow-search-submit:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.workflow-search-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-tertiary);
    border-top-color: #ff8c00;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Chains Grid */
.workflow-chains-grid {
    display: grid;
    gap: 20px;
    padding: 4px;
    grid-template-columns: repeat(5, 1fr); /* default */
}

/* Adjust based on viewport width which changes with zoom */
@media (max-width: 1000px) {
    .workflow-chains-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 700px) {
    .workflow-chains-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
    .workflow-chains-grid { grid-template-columns: repeat(1, 1fr); }
}

@media (min-width: 2000px) {
    .workflow-chains-grid { grid-template-columns: repeat(5, 1fr); }
}

/* IMPROVED Workflow Card */
.workflow-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    transition: all 0.2s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    min-height: 320px;  /* Increased from 280px */
}

.workflow-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    border-color: #ff8c00;
}

.workflow-card-header {
    padding: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.workflow-card-label {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    transition: all 0.2s;
}

.workflow-card-label.labeled {
    color: #ff8c00;
}

.workflow-card-label:hover {
    transform: scale(1.1);
}

.workflow-card-time {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
}

.workflow-card-delete {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    opacity: 0.6;
    transition: all 0.2s;
}

.workflow-card-delete:hover {
    color: var(--error-color);
    opacity: 1;
}

.workflow-card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 12px;
    overflow: hidden;  /* Prevent overflow */
}

.workflow-card-preview {
    height: 140px;  /* Increased from 120px */
    background: var(--bg-primary);
    border-radius: 6px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}

.workflow-preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.workflow-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
    flex-shrink: 0;
}

.workflow-card-info span {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.workflow-card-thread {
    color: #ff8c00;
    font-weight: 500;
}

.workflow-card-label-name {
    color: #ff8c00 !important;
    font-weight: 500;
}

.workflow-card-task {
    flex: 1;
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    max-height: calc(1.4em * 3); /* Exactly 3 lines */
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px; /* Space for scrollbar */
    word-wrap: break-word;
    scrollbar-width: thin;
    scrollbar-color: var(--text-tertiary) transparent;
}

/* Custom scrollbar for task text */
.workflow-card-task::-webkit-scrollbar {
    width: 4px;
}

.workflow-card-task::-webkit-scrollbar-track {
    background: transparent;
}

.workflow-card-task::-webkit-scrollbar-thumb {
    background-color: var(--text-tertiary);
    border-radius: 2px;
    opacity: 0.5;
}

.workflow-card-task::-webkit-scrollbar-thumb:hover {
    opacity: 0.7;
}

/* Visual indicator that there's more text (optional) */
.workflow-card-task.has-overflow::after {
    content: '...';
    position: absolute;
    bottom: 0;
    right: 8px;
    background: linear-gradient(to right, transparent, var(--bg-secondary) 20%);
    padding-left: 20px;
    pointer-events: none;
}

/* Label Selector Dropdown for cards */
.workflow-label-selector {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 4px 12px var(--shadow-color);
    min-width: 150px;
    max-width: 250px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10001;
}

.workflow-label-option {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 14px;
    color: var(--text-primary);
    transition: background 0.2s;
}

.workflow-label-option:hover {
    background: var(--link-hover-bg);
    color: #ff8c00;
}

.workflow-label-option.selected {
    background: rgba(255, 140, 0, 0.1);
    color: #ff8c00;
    font-weight: 500;
}

.workflow-label-separator {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Loading States */
.workflow-loading,
.workflow-no-chains,
.workflow-no-labels,
.workflow-preview-loading,
.workflow-preview-empty,
.workflow-preview-error {
    text-align: center;
    color: var(--text-tertiary);
    padding: 20px;
    font-style: italic;
}

/* Responsive */
@media (max-width: 1400px) {
    .workflow-chains-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .workflow-chains-grid {
        grid-template-columns: 1fr;
    }
    
    .workflow-modal-left {
        width: 30%;
    }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Inline Add Label Container */
.workflow-add-label-container {
    display: flex;
    gap: 6px; /* Reduced gap */
    margin-bottom: 12px; /* Space before labels list */
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.workflow-new-label-input {
    flex: 1;
    padding: 6px 10px; /* Reduced padding */
    font-size: 13px; /* Slightly smaller */
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.workflow-new-label-input:focus {
    outline: none;
    border-color: #ff8c00;
}

.workflow-new-label-input::placeholder {
    color: var(--text-tertiary);
    font-style: italic;
}

.workflow-add-label-submit {
    padding: 6px; /* Smaller button */
    background: transparent;
    border: 1px solid var(--text-tertiary);
    border-radius: 6px;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.workflow-add-label-submit:hover {
    background: rgba(255, 140, 0, 0.1);
    border-color: #ff8c00;
    color: #ff8c00;
}

.workflow-add-label-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Thread Navigation */
.workflow-thread-nav {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.workflow-back-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.workflow-back-btn:hover {
    background: rgba(255, 140, 0, 0.1);
    border-color: #ff8c00;
    color: #ff8c00;
    transform: translateX(-2px);
}

.workflow-thread-title {
    font-size: 16px;
    color: #ff8c00;
    font-weight: 500;
}

/* View Chains Button */
.workflow-view-chains-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: rgba(255, 140, 0, 0.1);
    border: 1px solid rgba(255, 140, 0, 0.3);
    border-radius: 6px;
    color: #ff8c00;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-left: auto;
    margin-right: 8px;
}

.workflow-view-chains-btn:hover {
    background: rgba(255, 140, 0, 0.2);
    border-color: #ff8c00;
    transform: scale(1.05);
}

/* Ensure proper spacing when in thread view */
.workflow-modal-right .workflow-thread-nav + .workflow-chains-grid {
    margin-top: 0;
}

.workflow-modal-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

/* Card Footer for Replay Button */
.workflow-card-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-start;
}

.workflow-card-replay {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 4px;
    transition: all 0.2s;
    opacity: 0.6;
}

.workflow-card-replay:hover {
    color: #1E90FF;
    opacity: 1;
    transform: scale(1.1);
}

/* Replay View Theme (keep blue for titles/icons etc., not for the close button base) */
.workflow-replay-theme {
    color: #1E90FF !important;
}

.workflow-modal-section-title.workflow-replay-theme svg,
.workflow-section-header.workflow-replay-theme svg {
    stroke: #1E90FF;
}

/* Close button in replay: neutral by default, blue on hover */
.workflow-modal-close.workflow-replay-theme {
    /* inherit base look (neutral/grey) */
    color: var(--text-primary);
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
}

.workflow-modal-close.workflow-replay-theme:hover {
    background: rgba(30, 144, 255, 0.2);
    border-color: #1E90FF;
    color: #1E90FF;
}

/* Replay Navigation - matching thread view style (grey divider) */
.workflow-replay-nav {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 16px 4px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.workflow-back-replay {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.workflow-back-replay:hover {
    background: rgba(30, 144, 255, 0.1);
    border-color: #1E90FF;
    color: #1E90FF;
    transform: translateX(-2px);
}

.workflow-replay-title {
    font-size: 16px;
    color: #1E90FF;
    font-weight: 500;
}

/* Light theme adjustments */
body.light-theme .workflow-replay-theme {
    color: #0064FF !important;
}

body.light-theme .workflow-modal-section-title.workflow-replay-theme svg,
body.light-theme .workflow-section-header.workflow-replay-theme svg {
    stroke: #0064FF;
}

/* Close button in replay (light theme): neutral by default, blue on hover only */
body.light-theme .workflow-modal-close.workflow-replay-theme {
    color: var(--text-primary);
    border-color: rgba(0, 0, 0, 0.15); /* typical light border; adjust to your base if different */
    background: rgba(0, 0, 0, 0.04);   /* match your base light background */
}

body.light-theme .workflow-modal-close.workflow-replay-theme:hover {
    background: rgba(0, 100, 255, 0.2);
    border-color: #0064FF;
    color: #0064FF;
}

body.light-theme .workflow-back-replay:hover {
    background: rgba(0, 100, 255, 0.1);
    border-color: #0064FF;
    color: #0064FF;
}

body.light-theme .workflow-replay-title {
    color: #0064FF;
}

body.light-theme .workflow-card-replay:hover {
    color: #0064FF;
}
