/* Agent Flows tab inside the Workflows page. */

/* Colour comes from the native design tokens (native.css) because the legacy
   aliases (--primary, --light, --white) invert between appearances: in dark
   mode `--primary-dark` resolves to the light text colour. The panel keeps its
   own semantic tokens so it stays readable in both appearances. */
.workflows-agent-flows {
    display: flex;
    flex: 1;
    min-height: 320px;
    overflow: hidden;
    margin-left: 32px;
    --af-screen: #08090b;
    --af-surface: #111216;
    --af-raised: #17181d;
    --af-text: #f5f5f7;
    --af-muted: #9a9aa2;
    --af-border: rgba(255, 255, 255, 0.10);
    --af-divider: rgba(255, 255, 255, 0.075);
    --af-hover: rgba(255, 255, 255, 0.07);
    --af-soft: rgba(255, 255, 255, 0.05);
    --af-accent: #f09024;
    --af-accent-soft: rgba(240, 144, 36, 0.14);
    --af-accent-text: #ffcf8a;
    --af-warning-text: #8a5a00;
    background: var(--af-screen);
    color: var(--af-text);
}

html[data-theme="dark"] .workflows-agent-flows {
    --af-screen: #08090b;
    --af-surface: #111216;
    --af-raised: #17181d;
    --af-text: #f5f5f7;
    --af-muted: #9a9aa2;
    --af-border: rgba(255, 255, 255, 0.10);
    --af-divider: rgba(255, 255, 255, 0.075);
    --af-hover: rgba(255, 255, 255, 0.07);
    --af-soft: rgba(255, 255, 255, 0.05);
    --af-accent-text: #ffcf8a;
    --af-warning-text: #fdd663;
}

.workflows-agent-flows.hidden {
    display: none !important;
}

/* Sidebar */
.af-sidebar {
    width: 250px;
    min-width: 210px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 10px;
    border-right: 1px solid var(--af-border);
    overflow-y: auto;
    background: var(--af-raised);
    color: var(--af-text);
}

.af-side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 6px 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.af-icon-btn {
    border: 1px solid var(--af-border);
    background: transparent;
    color: inherit;
    border-radius: 7px;
    width: 26px;
    height: 26px;
    cursor: pointer;
}

.af-icon-btn:hover {
    background: var(--af-hover);
}

.af-section-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 6px 3px;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--af-muted);
}

.af-runs-label {
    margin-top: 8px;
}

.af-run-count {
    font-weight: 500;
}

.af-flow-list,
.af-run-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.af-flow-item,
.af-run-item {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    width: 100%;
    padding: 7px 8px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font: inherit;
}

.af-flow-item:hover,
.af-run-item:hover {
    background: var(--af-hover);
}

.af-flow-item.active,
.af-run-item.active {
    background: var(--af-accent-soft);
}

.af-flow-item .af-item-body,
.af-run-item .af-item-body {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.af-item-title {
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.af-item-sub {
    font-size: 0.7rem;
    color: var(--af-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Main */
.af-main {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 16px 22px 28px;
}

.af-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--af-muted);
    font-size: 0.9rem;
}

.af-panel {
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.af-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.af-panel-head h2 {
    margin: 0 0 4px;
    font-size: 1.25rem;
    font-weight: 600;
}

.af-panel-head h3 {
    margin: 0 0 8px;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--af-muted);
}

.af-muted {
    color: var(--af-muted);
    font-size: 0.82rem;
    margin: 0;
}

.af-meta {
    font-size: 0.75rem;
    color: var(--af-muted);
    font-family: var(--platform-font-mono, ui-monospace, monospace);
}

.af-default-llm {
    margin-left: 10px;
}

.af-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    border: 1px solid var(--af-border);
    border-radius: 10px;
    background: var(--af-raised);
}

.af-actions .btn-workflow-run {
    margin-left: auto;
}

.af-actions-inline {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.af-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--af-muted);
    cursor: pointer;
}

.af-warning,
.af-error {
    padding: 9px 12px;
    border-radius: 9px;
    font-size: 0.8rem;
    line-height: 1.4;
}

.af-warning {
    color: var(--af-warning-text);
    background: rgba(240, 144, 36, 0.12);
    border: 1px solid rgba(240, 144, 36, 0.28);
}

.af-error {
    color: var(--n-danger, #d70015);
    background: var(--n-danger-soft, rgba(215, 0, 21, 0.10));
    border: 1px solid rgba(239, 83, 80, 0.3);
}

/* Inputs */
.af-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.af-input {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.af-input label {
    font-size: 0.76rem;
    font-weight: 600;
}

.af-input .af-req {
    margin-left: 5px;
    color: var(--af-accent-text);
    font-size: 0.68rem;
    text-transform: uppercase;
}

.af-input .af-hint {
    font-size: 0.7rem;
    color: var(--af-muted);
}

.af-input input,
.af-input textarea,
.af-chat-input textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid var(--af-border);
    border-radius: 8px;
    background: var(--af-surface);
    color: var(--af-text);
    font: inherit;
    font-size: 0.82rem;
    resize: vertical;
}

/* Step cards */
.af-steps {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.af-step {
    border: 1px solid var(--af-border);
    border-radius: 10px;
    padding: 10px 12px;
    background: var(--af-surface);
}

.af-step-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.af-step-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.af-step-id {
    font-family: var(--platform-font-mono);
    font-size: 0.7rem;
    color: var(--af-muted);
}

.af-step-body {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.af-agents {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.af-agent {
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--af-soft);
    color: var(--af-muted);
}

.af-step-tools,
.af-step-changes {
    font-size: 0.72rem;
    color: var(--af-muted);
    font-family: var(--platform-font-mono);
}

.af-step output,
.af-step pre {
    margin: 2px 0 0;
}

.af-step details {
    margin-top: 5px;
}

.af-step summary {
    cursor: pointer;
    font-size: 0.72rem;
    color: var(--af-muted);
}

.af-output {
    margin: 6px 0 0;
    padding: 8px 10px;
    max-height: 260px;
    overflow: auto;
    background: var(--af-raised);
    border-radius: 8px;
    font-size: 0.74rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Status badges */
.af-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    background: var(--af-soft);
    color: var(--af-muted);
    white-space: nowrap;
}

.af-status.completed {
    color: var(--n-success, #248a3d);
    background: var(--n-success-soft, rgba(36, 138, 61, 0.12));
}

.af-status.failed {
    color: var(--n-danger, #d70015);
    background: var(--n-danger-soft, rgba(215, 0, 21, 0.10));
}

.af-status.running {
    color: var(--af-accent-text);
    background: var(--af-accent-soft);
}

.af-status.waiting,
.af-status.waiting_approval {
    color: var(--af-warning-text);
    background: rgba(240, 180, 36, 0.18);
}

.af-status.cancelled,
.af-status.skipped {
    color: var(--af-muted);
    background: var(--af-soft);
}

/* Grid cards */
.af-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 12px;
}

.af-card {
    border: 1px solid var(--af-border);
    border-radius: 10px;
    padding: 12px;
    background: var(--af-surface);
}

.af-card h3 {
    margin: 0 0 8px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--af-muted);
}

.af-tools {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.af-tool-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.76rem;
}

.af-tool-row .af-tool-name {
    font-family: var(--platform-font-mono);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.af-tool-row .af-tool-stat {
    color: var(--af-muted);
    font-size: 0.7rem;
}

.af-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 260px;
    overflow-y: auto;
    font-family: var(--platform-font-mono);
    font-size: 0.68rem;
}

.af-event {
    display: flex;
    gap: 6px;
    align-items: baseline;
    padding: 2px 0;
    border-bottom: 1px solid var(--af-divider);
}

.af-event-type {
    color: var(--af-muted);
    min-width: 108px;
}

.af-event-text {
    color: inherit;
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat */
.af-chat {
    margin-top: 2px;
}

.af-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 8px;
}

.af-chat-msg {
    padding: 8px 10px;
    border-radius: 9px;
    background: var(--af-raised);
    font-size: 0.8rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.af-chat-msg.user {
    background: var(--af-accent-soft);
}

.af-chat-role {
    display: block;
    margin-bottom: 2px;
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--af-muted);
}

.af-chat-input {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.af-chat-input textarea {
    flex: 1;
}

.af-chat-input .btn-workflow {
    white-space: nowrap;
}

.af-approve {
    margin-top: 6px;
    display: flex;
    gap: 6px;
}

@media (max-width: 900px) {
    .workflows-agent-flows {
        flex-direction: column;
        margin-left: 0;
    }
    .af-sidebar {
        width: 100%;
        max-height: 210px;
        border-right: none;
        border-bottom: 1px solid var(--af-border);
    }
    .af-main {
        padding: 12px;
    }
}

/* The Workflows page uses the native dark surface in dark appearance. Keep the
   ghost buttons on the same tokens so they cannot become white-on-white. */
#workflowsPage .af-main .btn-workflow-ghost {
    color: var(--af-text) !important;
    background: var(--af-soft) !important;
    border-color: var(--af-border) !important;
}

#workflowsPage .af-main .af-icon-btn {
    color: var(--af-text);
}
