/* The agents module's pages. Linked by the shell (<ModuleStyles />) while the module is on.
   Colours come from the shell's tokens, so light and dark follow by construction; the one
   colours the shell has no token for - purple, "waiting for a person", and orange, "a question
   waiting for an answer" - are mixed here. */

.agents-light-yellow { --agents-light: var(--shell-warning-fg, #9a6206); }
.agents-light-green  { --agents-light: var(--shell-success-fg, #147a4b); }
.agents-light-blue   { --agents-light: var(--shell-accent, #4453cf); }
.agents-light-purple { --agents-light: #7b4fd6; }
.agents-light-orange { --agents-light: #d2600f; }
.agents-light-red    { --agents-light: var(--shell-danger-fg, #bf3838); }
.agents-light-grey   { --agents-light: var(--shell-content-tertiary, #767d8e); }

html.theme-dark .agents-light-purple { --agents-light: #b39af0; }
html.theme-dark .agents-light-orange { --agents-light: #f0a060; }

.agents-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.agents-project-picker { min-width: 16rem; }

.agents-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-left: auto;
    font-size: 0.8125rem;
    color: var(--shell-content-secondary);
}

.agents-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.agents-dot {
    display: inline-block;
    width: 0.65rem;
    height: 0.65rem;
    border-radius: 50%;
    background: var(--agents-light);
    flex: none;
}

/* The canvas: a plane of absolutely placed blocks over one SVG of lines, scrolled when wider
   than the page. Geometry comes from CanvasLayout, never from CSS. */
.agents-canvas {
    overflow: auto;
    max-height: 70vh;
}

.agents-canvas-plane { position: relative; }

.agents-canvas-lines {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.agents-line {
    fill: none;
    stroke: var(--shell-border-strong);
    stroke-width: 1.5;
}

.agents-line-back { stroke-dasharray: 5 4; }

.agents-canvas-lines marker path { fill: var(--shell-border-strong); }

.agents-block {
    position: absolute;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.6rem 0.75rem;
    text-align: left;
    font: inherit;
    color: var(--shell-content);
    background: var(--shell-surface);
    border: 1px solid var(--shell-border);
    border-left: 4px solid var(--agents-light);
    border-radius: 6px;
    cursor: pointer;
}

.agents-block:hover { border-color: var(--agents-light); }

.agents-block-selected {
    box-shadow: 0 0 0 2px var(--agents-light);
}

.agents-block-head {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.agents-block-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agents-block-percent {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1;
}

.agents-bar {
    display: block;
    height: 4px;
    border-radius: 2px;
    background: var(--shell-surface-muted);
    overflow: hidden;
}

.agents-bar > span {
    display: block;
    height: 100%;
    background: var(--agents-light);
}

.agents-block-foot {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--shell-content-secondary);
}

.agents-attention {
    color: var(--shell-danger-fg);
    font-weight: 600;
}

/* The selected block's tasks. */
.agents-tasks {
    width: 100%;
    border-collapse: collapse;
}

.agents-tasks th,
.agents-tasks td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--shell-border);
    text-align: left;
    vertical-align: middle;
}

.agents-tasks th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--shell-content-secondary);
}

.agents-tasks .agents-num { text-align: right; white-space: nowrap; }
.agents-tasks .agents-due { white-space: nowrap; }
.agents-tasks .agents-overdue { color: var(--shell-danger-fg); font-weight: 600; }

.agents-tasks .agents-actions { text-align: right; white-space: nowrap; }

.agents-chip {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--agents-light);
    background: color-mix(in srgb, var(--agents-light) 14%, var(--shell-surface));
    white-space: nowrap;
}

.agents-muted { color: var(--shell-content-secondary); }
.agents-section-title { margin: 1.5rem 0 0.25rem; font-size: 1.1rem; font-weight: 600; }
.agents-workers-toolbar { margin: 0.5rem 0; }
.agents-work-folder { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: baseline; word-break: break-all; }

.agents-empty {
    margin: 0;
    padding: 1rem;
    color: var(--shell-content-secondary);
}

/* The task dialog. */
.agents-detail h4 {
    margin: 1rem 0 0.25rem;
    font-size: 0.8125rem;
    color: var(--shell-content-secondary);
}

.agents-detail p { margin: 0 0 0.5rem; }

.agents-detail-state {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.agents-pre { white-space: pre-wrap; }

.agents-callout {
    margin: 0.5rem 0;
    padding: 0.6rem 0.75rem;
    border-left: 4px solid var(--agents-light);
    background: color-mix(in srgb, var(--agents-light) 8%, var(--shell-surface));
    border-radius: 4px;
}

.agents-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.agents-links { margin: 0; padding-left: 1.2rem; }

/* The task dialog scrolls inside itself, so its title and close button stay on the screen. */
.agents-popup-body {
    max-height: calc(100vh - 10rem);
    overflow-y: auto;
    overflow-x: hidden;
}

/* The task dialog's four parts: one strip of tabs, one pane that scrolls, the gestures that apply everywhere under it. */
.agents-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border-bottom: 1px solid var(--shell-border);
}

.agents-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem 0.75rem;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    background: none;
    color: var(--shell-content-secondary);
    font: inherit;
    font-size: 0.875rem;
    cursor: pointer;
}

.agents-tab:hover { color: var(--shell-content); }

.agents-tab-active {
    color: var(--shell-content);
    font-weight: 600;
    border-bottom-color: var(--shell-accent, #4453cf);
}

.agents-tab-count {
    padding: 0 0.4rem;
    border-radius: 999px;
    font-size: 0.75rem;
    background: var(--shell-border);
}

.agents-tab-attention {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--agents-light);
}

/* Same height whichever part is open, so the dialog does not jump. */
.agents-tab-pane {
    height: min(30rem, calc(100vh - 20rem));
    padding-top: 0.75rem;
}

.agents-tab-pane > h4:first-child { margin-top: 0; }

.agents-gesture {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.agents-task-foot {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--shell-border);
}

/* The arrows into a task: what it waits for, and the picker that adds one. */
.agents-deps { margin-top: 0.75rem; }

.agents-deps-list {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
}

.agents-deps-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0;
}

.agents-deps-add {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.agents-deps-picker { min-width: 14rem; max-width: 100%; }

.agents-history {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.8125rem;
}

.agents-history li {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--shell-border);
}

.agents-history-when { color: var(--shell-content-tertiary); white-space: nowrap; }

.agents-history-what { font-weight: 600; }

.agents-history-message { flex-basis: 100%; white-space: pre-wrap; }

/* Starting an agent from the canvas (docs/agent-runner.md). */
.agents-run {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0.25rem 0;
}

.agents-run-live {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background: var(--shell-accent, #4453cf);
    animation: agents-pulse 1.4s ease-in-out infinite;
}

@keyframes agents-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* The agent's verdict in one line, the long account behind Details. */
.agents-outcome {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    font-weight: 600;
}

.agents-outcome-complete { --agents-light: #2e8b57; }

html.theme-dark .agents-outcome-complete { --agents-light: #6cc596; }

.agents-details summary {
    cursor: pointer;
    color: var(--shell-content-secondary);
    font-size: 0.8125rem;
}

/* The live view of a run: the last steps read from its log, newest at the bottom. */
.agents-steps-list {
    margin: 0.25rem 0 0;
    padding-left: 1.25rem;
    font-size: 0.8125rem;
}

.agents-steps-list li { padding: 0.1rem 0; overflow-wrap: anywhere; }

.agents-step-tool { font-family: var(--shell-font-mono, ui-monospace, monospace); color: var(--shell-content-secondary); }

/* The task's conversation with people: what the agent said on one side, what people said on the other. */
.agents-conversation {
    list-style: none;
    margin: 0 0 0.5rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.875rem;
}

.agents-conversation li {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    max-width: 85%;
    padding: 0.4rem 0.6rem;
    border-radius: 0.5rem;
    border: 1px solid var(--shell-border);
}

.agents-said-agent { align-self: flex-start; background: var(--shell-surface); }

.agents-said-person {
    align-self: flex-end;
    background: color-mix(in srgb, var(--shell-accent, #4453cf) 10%, var(--shell-surface));
}

/* A rejection is a verdict, not a message: it reads as one even when its words repeat a message's. */
.agents-conversation li.agents-said-review {
    border-left: 4px solid var(--shell-danger-fg, #c4314b);
    background: color-mix(in srgb, var(--shell-danger-fg, #c4314b) 8%, var(--shell-surface));
}

.agents-conversation .agents-history-when { font-size: 0.75rem; white-space: normal; }

.agents-conversation-text { white-space: pre-wrap; overflow-wrap: anywhere; }

.agents-message-send {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0.25rem 0 0.5rem;
    font-size: 0.8125rem;
}

/* The project's repository dialog: one line for the project, one per area. */
.agents-repos {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0 1rem;
    font-size: 0.875rem;
}

.agents-repos th {
    text-align: left;
    font-weight: 600;
    color: var(--shell-content-secondary);
    padding: 0.25rem 0.5rem;
}

.agents-repos td {
    padding: 0.375rem 0.5rem;
    vertical-align: middle;
    border-top: 1px solid var(--shell-border);
}

.agents-repos td:nth-child(2) {
    width: 50%;
}

.agents-repo-actions {
    white-space: nowrap;
}

/* The approved branches waiting to be merged. */
.agents-merges .agents-overdue {
    color: var(--shell-danger-fg);
}

.agents-merges code {
    word-break: break-all;
}

/* Errors from the project's applications. */
.agents-issues td:nth-child(2) {
    width: auto;
}

.agents-issue-status {
    display: inline-block;
    padding: 0 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--agents-issue, var(--shell-content-secondary));
    background: color-mix(in srgb, var(--agents-issue, var(--shell-content-secondary)) 14%, var(--shell-surface));
}

.agents-issue-pending   { --agents-issue: var(--shell-warning-fg, #9a6206); }
.agents-issue-regressed { --agents-issue: var(--shell-danger-fg, #bf3838); }
.agents-issue-promoted  { --agents-issue: var(--shell-accent, #4453cf); }
.agents-issue-resolved  { --agents-issue: var(--shell-success-fg, #147a4b); }
.agents-issue-ignored   { --agents-issue: var(--shell-content-tertiary, #767d8e); }

.agents-issues .agents-overdue,
.agents-repos .agents-overdue {
    color: var(--shell-danger-fg);
}

.agents-issue-samples td {
    background: var(--shell-surface-muted);
}

.agents-issue-sample + .agents-issue-sample {
    margin-top: 0.75rem;
}

.agents-issue-sample pre {
    max-height: 16rem;
    overflow: auto;
    margin: 0.25rem 0 0;
    font-size: 0.75rem;
    white-space: pre-wrap;
    word-break: break-all;
}

.agents-issue-key {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.75rem;
    border: 1px solid var(--shell-warning-fg, #9a6206);
    border-radius: 6px;
}

.agents-issue-key p {
    margin: 0 0 0.25rem;
}

.agents-issue-key code {
    word-break: break-all;
    user-select: all;
}

/* The status page (/agents/status): one row per agent or place, a light, and what it means.
   A list rather than a grid, so it reads on a phone. */
.agents-status-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.agents-status-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--shell-border);
}

.agents-status-row:last-child { border-bottom: none; }

.agents-status-dot {
    width: 0.9rem;
    height: 0.9rem;
    margin-top: 0.25rem;
}

.agents-status-body {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.agents-status-key { margin-left: 0.4rem; font-size: 0.85em; }

.agents-status-word {
    margin-left: 0.4rem;
    font-size: 0.8em;
    color: var(--shell-content-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.agents-status-places {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.9rem;
    margin-top: 0.25rem;
    font-size: 0.9em;
    color: var(--shell-content-secondary);
}

.agents-setup details {
    margin: 0.5rem 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--shell-border);
    border-radius: 6px;
}

.agents-setup summary { cursor: pointer; font-weight: 600; }

.agents-setup ol { padding-left: 1.25rem; }

.agents-setup li { margin: 0.5rem 0; }

.agents-setup pre {
    margin: 0.4rem 0 0;
    padding: 0.6rem 0.75rem;
    overflow-x: auto;
    font-size: 0.8rem;
    background: var(--shell-surface-muted);
    border-radius: 4px;
    white-space: pre;
}

.agents-setup-who {
    margin: 0.5rem 0 0;
    padding: 0.4rem 0.6rem;
    border-left: 3px solid var(--shell-accent, #4453cf);
    background: var(--shell-surface-muted);
}

/* Agent start-up (/admin/agents/runner) */

.agents-runner-form { display: grid; gap: 0.75rem; max-width: 40rem; }

.agents-runner-field { display: grid; gap: 0.2rem; min-width: 12rem; }

.agents-runner-field > span { font-weight: 600; font-size: 0.85rem; }

.agents-runner-list { list-style: none; margin: 0; padding: 0; }

.agents-runner-row { padding: 0.6rem 0; border-bottom: 1px solid var(--shell-border); }

.agents-runner-row:last-child { border-bottom: none; }

.agents-runner-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 0.75rem;
    margin: 0.5rem 0 0 1.6rem;
}

.agents-runner-actions { margin: 1rem 0; }

.agents-runner-picked {
    padding-left: 0.5rem;
    border-left: 3px solid var(--shell-accent, #4453cf);
    background: var(--shell-surface-muted);
}

.agents-where-link { margin-left: 0.5rem; font-size: 0.85rem; }
