/* static/css/workflow_editor.css */

.page-wrapper {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 95px);
    overflow: hidden;
}

.page-header {
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
}

.tabs {
    display: flex;
}

.tab-button {
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.tab-button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.page-content {
    flex-grow: 1;
    overflow: hidden;
}

.page-panel {
    display: none;
    height: 100%;
    width: 100%;
}

.page-panel.active {
    display: block;
}

.editor-wrapper {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100%;
    overflow: hidden;
}

.sidebar {
    background-color: var(--header-bg);
    border-right: 1px solid var(--header-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--header-border);
    flex-shrink: 0;
}

.sidebar-header h3 {
    font-size: 1.2rem;
    font-weight: 600;
}

.sidebar-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.list-item {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    border: 1px solid var(--surface-border);
    background-color: var(--surface);
    transition: background-color 0.2s, border-color 0.2s;
}

.list-item:hover {
    background-color: var(--bg-alt);
}

.list-item.active {
    background-color: var(--accent-light);
    border-color: var(--accent);
}

.list-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.list-item-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.4rem;
    border-radius: 1rem;
    background-color: var(--danger-light);
    color: var(--danger-text);
}

.status-indicator.enabled {
    background-color: var(--success-light);
    color: var(--success-text);
}

.list-item-description {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item-hg {
    font-size: 0.7rem;
    font-family: 'Fira Code', monospace;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.sidebar-placeholder {
    color: var(--text-muted);
    padding: 1rem;
    text-align: center;
}

.main-content {
    background-color: var(--bg);
    overflow-y: auto;
    padding: 1.5rem 2rem;
}

#editor-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

#editor-placeholder svg {
    margin-bottom: 1rem;
}
#editor-placeholder h2 {
    font-size: 1.5rem;
}

#workflow-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--header-border);
}

.form-header h2 {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

#run-workflow-btn-main {
    gap: 0.5rem;
}
#run-workflow-btn-main::before {
    content: '▶';
    font-size: 0.8rem;
}

.form-section {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.form-section h3 {
    font-size: 1.2rem;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.form-section-header {
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.trigger-actions-container {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px dashed var(--border);
}

#trigger-test-results-container {
    margin-top: 1rem;
    background-color: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden; /* Important for collapsing animation */
}

#trigger-test-results-container.hidden {
    display: none;
}

.collapsible-header {
    padding: 0.75rem 1rem;
    background-color: var(--bg-alt);
    cursor: pointer;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.collapsible-header::before {
    content: '▶';
    display: inline-block;
    transition: transform 0.2s ease-in-out;
}
.collapsible-header.is-expanded::before {
    transform: rotate(90deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding 0.4s ease-in-out;
    padding: 0 1rem;
}
.collapsible-header.is-expanded + .collapsible-content {
    max-height: 1000px; /* Large enough to fit content */
    padding: 1rem;
}

#trigger-test-results-summary {
    font-weight: 500;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.trigger-results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

.results-column, .results-final {
    display: flex;
    flex-direction: column;
}

.results-column h4, .results-final h4 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

#inclusion-results-output, #exclusion-results-output, #final-results-output {
    max-height: 300px;
    overflow-y: auto;
    padding: 0.75rem;
    background-color: var(--bg);
    border-radius: 0.375rem;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    border: 1px solid var(--surface-border);
    min-height: 100px; /* Give it some base height */
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background-color: var(--input-bg);
    color: var(--text);
}
.form-group small {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.form-group-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.switch-label {
    font-weight: 500;
}


/* Actions */
#actions-container, #on-success-events-container, #on-failure-events-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.action-block, .event-block {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background-color: var(--bg-alt);
    transition: opacity 0.2s, background-color 0.2s, border-color 0.2s;
}

.action-header, .event-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    border-radius: 0.5rem 0.5rem 0 0;
}

.action-header {
    cursor: grab;
}

.action-header:active {
    cursor: grabbing;
}
.action-header-left, .event-header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.2rem;
    padding-right: 0.5rem;
}
.drag-handle:active {
    cursor: grabbing;
}
.action-header h4, .event-header h4 {
    font-weight: 600;
}

.action-header-controls, .event-header-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.delete-action-btn, .delete-event-btn {
    font-size: 1.5rem;
    color: var(--text-muted);
}
.delete-action-btn:hover, .delete-event-btn:hover {
    color: var(--danger-text);
}
.action-block.dragging {
    opacity: 0.5;
    background: var(--bg);
    border: 1px dashed var(--accent);
}

.action-body, .event-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.action-events-section {
    border-top: 1px dashed var(--border);
    margin-top: 1rem;
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-left: 1.5rem;
    border-left: 4px solid var(--border);
}
.action-events-section h5 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: -0.5rem;
}
.action-events-section .btn-sm {
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
}

.action-events-section .on-success-events-container,
.action-events-section .on-failure-events-container,
.action-events-section .add-action-container {
    padding-left: 1.5rem;
}

.action-events-section .on-success-events-container,
.action-events-section .on-failure-events-container {
    border-left: 2px dotted var(--border);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}


.add-action-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
    display: flex;
    gap: 0.5rem;
}

#add-action-select {
    flex-grow: 1;
    padding: 0.6rem 0.75rem;
    border-radius: 0.375rem;
    border: 1px solid var(--border);
    background-color: var(--input-bg);
    color: var(--text);
}


/* --- Live Status Styles --- */
#live-status-panel {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
#live-status-panel.active {
    display: flex;
}

.status-panel-header {
    padding: 1rem 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.system-status-banner {
    display: none;
    padding: 0.75rem 1.5rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    background-color: var(--warning-light);
    color: var(--warning-text);
    border: 1px solid var(--warning);
    border-radius: 0.5rem;
}
.system-status-banner.visible {
    display: block;
}

#workflow-pipeline-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "scheduled running";
}

#workflow-log-viewer {
    margin: 1rem 1.5rem 0;
}

.running-card .card-status-line, .running-card .card-sleep-timer {
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    margin-top: 0.5rem;
    color: var(--text-muted);
}
.running-card .card-sleep-timer {
    color: var(--info-text);
    font-weight: 600;
}

.running-card .card-progress {
    margin-top: 0.5rem;
}

.card-progress-text {
    font-size: 0.75rem;
    font-family: 'Fira Code', monospace;
    text-align: right;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.card-progress-bar {
    width: 100%;
    height: 8px;
    background-color: var(--bg-alt);
    border-radius: 4px;
    overflow: hidden;
}

.card-progress-bar-inner {
    height: 100%;
    background-color: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.run-workflow-btn-list,
.run-now-btn-list {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--success-text);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 0;
}
.run-workflow-btn-list svg,
.run-now-btn-list svg {
    width: 14px;
    height: 14px;
}
.list-item:hover .run-workflow-btn-list,
.scheduled-card:hover .run-now-btn-list {
    opacity: 1;
}
.run-workflow-btn-list:hover,
.run-now-btn-list:hover {
    background-color: var(--success-light);
    border-color: var(--success);
    transform: scale(1.1);
}

#scheduled-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    align-content: start;
    gap: 0.75rem;
}
.scheduled-card {
    display: flex;
    flex-direction: column;
}
.scheduled-card .card-timeline {
    display: block;
    margin-top: auto; /* Push to bottom */
    padding-top: 0.5rem;
}
.scheduled-card .timeline-track {
    width: 100%; height: 6px; background-color: var(--bg-alt); border-radius: 3px; position: relative; overflow: hidden; margin-top: 0.25rem;
}
.scheduled-card .timeline-progress {
    position: absolute;
    height: 100%;
    right: 0;
    top: 0;
    background-color: var(--accent);
    border-radius: 3px;
    transition: width 1s linear;
}

/* Specific to Live Status UI */
.card-workflow-id {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#scheduled-list .scheduled-card .card-scheduled-time {
display: block;
font-family: 'Fira Code', monospace;
font-size: 0.8rem;
margin-top: 0.5rem;
color: var(--text-muted);
}
.action-status-list {
    list-style: none;
    padding: 0;
    margin: 0.75rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.action-status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.action-status-icon {
    font-family: 'Fira Code', monospace;
    font-weight: 600;
}

.action-status-item.status-pending .action-status-icon::before { content: '○'; color: var(--text-muted); }
.action-status-item.status-running .action-status-icon::before { content: '►'; color: var(--accent); animation: pulse 1.5s infinite; }
.action-status-item.status-success .action-status-icon::before { content: '✅'; }
.action-status-item.status-failed .action-status-icon::before { content: '❌'; }

.action-status-item.status-running {
    color: var(--text);
    font-weight: 600;
}