/* ============================================================================
   AGENT RUN - SINGLE SOURCE OF TRUTH
   ----------------------------------------------------------------------------
   The entire agent run (header + tool rows + notes) renders as ONE card:
   the group container's .message-content is the box; tool cards and notes are
   nested inside .timeline-rows. This file is the ONLY place the run's box,
   header and rows are styled - all older duplicated/scattered rules were removed.

   Sections:
     1. Box container
     2. Header (Worked for Ns · status)
     3. Rows holder + collapse
     4. Tool row (dot, label, chip, right cluster, chevron)
     5. Assistant note
     6. Output drawer (expand on click)
     7. Nested-row chrome reset + dividers
     8. Timeline-adjacent spacing (thinking / final answer)
     9. Animations
    10. Drawer-content utilities (rendered inside an expanded row)
   ============================================================================ */

:root {
    --run-box-bg: rgba(14, 23, 46, 0.55);
    --run-box-border: rgba(108, 140, 205, 0.18);
    --run-box-divider: rgba(108, 140, 205, 0.10);
    --run-box-radius: 14px;
    --run-dot-run: #5be0d2;
    --run-dot-done: #4fd6a0;
    --run-dot-fail: #ff6b7a;
    --run-text: #eaf1ff;
    --run-text-dim: #9fbbe2;
    --run-text-faint: #5f7599;
}

.chat-main,
.chat-messages {
    background: radial-gradient(circle at top, #101936 0%, #070b18 55%, #050812 100%) !important;
}

/* ============================ 1. BOX CONTAINER ============================ */
/* The group message-content wraps the header + all rows as a single card. */
.automation-group-message .message-content {
    position: relative;
    width: calc(100% - 48px);
    max-width: 980px;
    margin: 0 0 0 24px;
    padding: 0;
    overflow: hidden;
    background: var(--run-box-bg);
    border: 1px solid var(--run-box-border);
    border-radius: var(--run-box-radius);
    box-shadow: 0 10px 30px rgba(3, 10, 24, 0.22);
}
/* No stray timeline rail / avatar pseudo-lines on the run. */
.automation-group-message .message-content::before,
.automation-group-message .message-content::after,
.timeline-rows .message-content::before,
.timeline-rows .message-content::after { content: none; display: none; }

/* ============================ 2. HEADER ============================ */
.automation-group-bar {
    display: block;
    padding: 12px 16px;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    cursor: pointer;
}
.automation-group-message:not(.collapsed) .automation-group-bar {
    border-bottom: 1px solid var(--run-box-divider);
}
.automation-group-bar .group-center {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
}
.automation-group-bar .group-mainline {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 10px;
    flex-wrap: nowrap;
}
.automation-group-bar .group-label {
    font-size: 14.5px;
    font-weight: 750;
    line-height: 1.1;
    color: #eff6ff;
    white-space: nowrap;
}
.automation-group-bar .group-stats {
    font-size: 13px;
    color: var(--run-text-dim);
    white-space: nowrap;
}
.automation-group-bar .group-chevron {
    margin-left: auto;
    font-size: 12px;
    color: #7f97bd;
    transition: transform 200ms ease;
}
.automation-group-message.collapsed .group-chevron { transform: rotate(-90deg); }

/* Leading status square: pulsing teal dot while running, green check when done. */
.automation-group-bar .group-mainline::before {
    content: "";
    width: 18px;
    height: 18px;
    flex: none;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    color: var(--run-dot-run);
    background: radial-gradient(circle at center, var(--run-dot-run) 0 3px, rgba(91, 224, 210, 0.14) 3.5px);
    animation: runDotPulse 1.6s ease-in-out infinite;
}
.automation-group-bar.group-completed .group-mainline::before,
.automation-group-bar.done .group-mainline::before {
    content: "\2713";
    background: rgba(79, 214, 160, 0.16);
    color: var(--run-dot-done);
    animation: none;
}

/* ============================ 3. ROWS HOLDER + COLLAPSE ============================ */
.timeline-rows { display: flex; flex-direction: column; }
.timeline-rows.rows-collapsed { display: none; }

/* ============================ 4. TOOL ROW ============================ */
.timeline-rows .mini-row {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background .15s ease;
}
.timeline-rows .mini-row:hover,
.timeline-rows .automation-card-message.expanded .mini-row {
    background: rgba(126, 184, 255, 0.05);
}

/* status-icon → small colored dot driven by the row's status class */
.timeline-rows .status-icon {
    width: 8px;
    height: 8px;
    min-width: 8px;
    flex: none;
    padding: 0;
    border-radius: 50%;
    background: var(--row-dot, var(--run-dot-done));
    display: inline-block;
}
.timeline-rows .status-icon i { display: none; }
.timeline-rows .timeline-tool-card.status-completed { --row-dot: var(--run-dot-done); }
.timeline-rows .timeline-tool-card.status-pending,
.timeline-rows .timeline-tool-card.status-in_progress,
.timeline-rows .timeline-tool-card.status-running,
.timeline-rows .timeline-tool-card.status-retrying { --row-dot: var(--run-dot-run); }
.timeline-rows .timeline-tool-card.status-failed,
.timeline-rows .timeline-tool-card.status-error,
.timeline-rows .timeline-tool-card.status-cancelled,
.timeline-rows .timeline-tool-card.status-stopped { --row-dot: var(--run-dot-fail); }
.timeline-rows .timeline-tool-card.status-pending .status-icon,
.timeline-rows .timeline-tool-card.status-in_progress .status-icon,
.timeline-rows .timeline-tool-card.status-running .status-icon {
    box-shadow: 0 0 0 4px rgba(91, 224, 210, 0.14);
    animation: runDotPulse 1.6s ease-in-out infinite;
}

/* label + mono tool chip (single line) */
.timeline-rows .mini-main {
    display: flex;
    flex-direction: row;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    gap: 9px;
}
.timeline-rows .tool-title-row {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 9px;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
}
.timeline-rows .automation-summary {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--run-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}
.timeline-rows .tool-chip {
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 11.5px;
    font-weight: 600;
    color: #8fe8ce;
    background: rgba(91, 224, 210, 0.10);
    border: none;
    padding: 1px 7px;
    border-radius: 6px;
    flex: none;
}

/* right cluster: time · badge · chevron on ONE inline row */
.timeline-rows .mini-right {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex: none;
}
.timeline-rows .timeline-tool-time {
    font-size: 12px;
    color: var(--run-text-faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.timeline-rows .mini-status {
    font-size: 10.5px;
    letter-spacing: .04em;
    font-weight: 600;
    text-transform: lowercase;
    padding: 2px 9px;
    border-radius: 999px;
    background: rgba(143, 165, 200, 0.12);
    color: var(--run-text-dim);
    border: none;
    white-space: nowrap;
}
.timeline-rows .timeline-tool-card.status-completed .mini-status { color: var(--run-dot-done); background: rgba(79, 214, 160, 0.12); }
.timeline-rows .timeline-tool-card.status-pending .mini-status,
.timeline-rows .timeline-tool-card.status-in_progress .mini-status,
.timeline-rows .timeline-tool-card.status-running .mini-status { color: var(--run-dot-run); background: rgba(91, 224, 210, 0.12); }
.timeline-rows .timeline-tool-card.status-failed .mini-status,
.timeline-rows .timeline-tool-card.status-error .mini-status,
.timeline-rows .timeline-tool-card.status-cancelled .mini-status,
.timeline-rows .timeline-tool-card.status-stopped .mini-status { color: var(--run-dot-fail); background: rgba(255, 107, 122, 0.12); }
.timeline-rows .tool-chevron {
    font-size: 10px;
    color: var(--run-text-faint);
    transition: transform .2s ease;
    flex: none;
}
.timeline-rows .automation-card-message.expanded .tool-chevron { transform: rotate(90deg); }

/* ============================ 5. ASSISTANT NOTE ============================ */
.timeline-rows .tool-assistant-note {
    margin: 0 16px 8px 35px;
    padding: 0;
    background: transparent;
    border: none;
}
.timeline-rows .tool-assistant-note-label {
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #6f86ab;
    margin-bottom: 2px;
}
.timeline-rows .tool-assistant-note-text {
    font-size: 12.5px;
    color: var(--run-text-dim);
    line-height: 1.5;
}

/* ============================ 6. OUTPUT DRAWER ============================ */
.timeline-rows .automation-details-body {
    display: none;
    margin: 0 16px 10px 35px;
    padding: 11px 13px;
    background: #070f20;
    border: 1px solid rgba(122, 150, 214, 0.14);
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.6;
    max-height: 340px;
    overflow: auto;
}
.timeline-rows .automation-card-message.expanded .automation-details-body { display: block; }
.timeline-rows .automation-mini-actions { padding: 0 16px 6px 35px; }
.timeline-rows .automation-progress-track,
.timeline-rows .automation-log-container { display: none; }

/* ============================ 7. NESTED-ROW CHROME RESET ============================ */
/* Nested tool cards / notes are no longer chat bubbles: strip all bubble chrome
   so only the row content shows, flush inside the box. */
.timeline-rows .automation-card-message,
.timeline-rows .automation-note-message {
    margin: 0;
    max-width: none;
    width: 100%;
}
.timeline-rows .automation-card-message .message-content,
.timeline-rows .automation-note-message .message-content {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: none;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}
.timeline-rows .automation-card .automation-card,
.timeline-rows .timeline-tool-card,
.timeline-rows .automation-mini-card {
    min-height: 0;
    margin: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    backdrop-filter: none;
}
.timeline-rows .timeline-tool-card::before,
.timeline-rows .timeline-tool-card::after { content: none; display: none; }
/* hairline divider between consecutive rows */
.timeline-rows .automation-card-message + .automation-card-message .message-content,
.timeline-rows .automation-card-message + .automation-note-message .message-content,
.timeline-rows .automation-note-message + .automation-card-message .message-content,
.timeline-rows .automation-note-message + .automation-note-message .message-content {
    border-top: 1px solid var(--run-box-divider);
}
/* empty answer body left inside tool cards (answer renders in its own bubble) */
.timeline-rows .message-text-body:empty,
.timeline-rows .message-text-body.empty { display: none; }
/* inline note card (rare) */
.timeline-rows .timeline-note-card {
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    padding: 10px 16px;
}
.timeline-rows .timeline-note-label { color: #a78bfa; font-weight: 700; font-size: 12px; }
.timeline-rows .timeline-note-text { color: #dbe8ff; font-size: 13px; line-height: 1.45; }
.timeline-rows .timeline-note-time { color: #8eaacf; font-size: 12px; }
.timeline-rows .timeline-note-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }

/* ============================ 8. TIMELINE-ADJACENT SPACING ============================ */
/* The chat list uses a 20px flex `gap` between messages. The thinking card, the
   run box and the final answer form ONE visual group, so pull them tight with a
   negative margin (offsets the gap → ~6px) instead of the default spacing. */
.thinking-message + .automation-group-message {
    margin-top: -14px;
}
.automation-group-message + .message.assistant:not(.automation-final-response) {
    margin-top: -14px;
}
.automation-group-message + .message.assistant:not(.automation-final-response) .message-content {
    padding-top: 0;
}

/* Smooth collapse for any legacy per-item hide (kept harmless). */
.timeline-hidden {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

/* ============================ 9. ANIMATIONS ============================ */
@keyframes runDotPulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes timelineSpin { to { transform: rotate(360deg); } }
@keyframes cardSlideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ============================================================================
   10. DRAWER-CONTENT UTILITIES
   Rendered INSIDE an expanded tool row's output drawer. These do not affect the
   row/box layout - they style the detail payloads (tool meta, search results,
   file previews, command output, progress, logs). Defined once, here only.
   ============================================================================ */
.content-area {
    font-size: 12px;
    color: #a5bfdf;
    line-height: 1.5;
    max-height: 320px;
    overflow: auto;
}

.automation-tool-meta {
    margin-top: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(64, 224, 208, 0.22);
    border-radius: 8px;
    background: rgba(10, 22, 42, 0.55);
}
.automation-detail-row { font-size: 12px; line-height: 1.45; color: #a5bfdf; margin: 2px 0; }
.automation-k { color: #7ce9df; font-weight: 600; margin-right: 6px; }
.automation-v { color: #d4e8ff; word-break: break-word; }
.automation-snippet .automation-v {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    color: #bcd6ff;
}
.automation-diff-add { color: #69e8a2; font-weight: 700; }
.automation-diff-del { color: #ff9ca2; font-weight: 700; margin-left: 8px; }

.automation-hit-list { margin-top: 6px; border-top: 1px solid rgba(125, 160, 220, 0.2); padding-top: 6px; }
.automation-hit-list summary { cursor: pointer; color: #9fd3ff; font-size: 12px; }
.automation-hit-list ul { margin: 6px 0 0; padding-left: 16px; }
.automation-hit-item { margin: 4px 0; color: #cde1ff; font-size: 12px; }
.automation-hit-loc {
    display: inline-block;
    min-width: 180px;
    color: #84d8ce;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

.automation-cmd-controls { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.automation-cmd-btn {
    border: 1px solid rgba(140, 180, 240, 0.32);
    background: rgba(18, 36, 66, 0.75);
    color: #d4e6ff;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.automation-cmd-btn.stop { border-color: rgba(255, 116, 116, 0.35); color: #ffc6c6; }
.automation-cmd-btn.disabled, .automation-cmd-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.automation-cmd-output {
    margin: 8px 0 0;
    max-height: 260px;
    overflow: auto;
    background: rgba(7, 14, 30, 0.9);
    border: 1px solid rgba(125, 160, 220, 0.25);
    border-radius: 8px;
    padding: 8px;
    color: #cfe1ff;
    font-size: 12px;
    line-height: 1.35;
    white-space: pre-wrap;
    word-break: break-word;
}
.automation-cmd-preview {
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(115, 174, 255, 0.14);
}
.automation-cmd-preview-title {
    color: #7edcda;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 6px;
}
.automation-cmd-preview-output {
    margin: 0;
    max-height: 180px;
    overflow: auto;
    color: #cdddf6;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.automation-progress-track {
    margin-top: 8px;
    height: 6px;
    width: 100%;
    border-radius: 999px;
    background: rgba(91, 136, 208, 0.2);
    overflow: hidden;
}
.automation-progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4da3ff, #2a74ff);
    transition: width 220ms ease;
}
.automation-card-log-item { color: #b7cae9; font-size: 12px; line-height: 1.4; padding: 4px 0; }

/* web-search / file-search / file-preview payloads */
.automation-web-search-meta,
.automation-file-search-meta,
.automation-file-preview-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid rgba(100, 201, 255, 0.22);
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(10, 25, 48, 0.72), rgba(7, 18, 34, 0.66));
}
.automation-web-search-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; }
.automation-web-search-summary { color: #cddffc; font-size: 12px; line-height: 1.4; opacity: 0.95; }
.automation-web-search-more { color: #8fb3e3; font-size: 11px; letter-spacing: 0.02em; opacity: 0.9; }
.automation-search-results { display: grid; gap: 8px; }
.automation-search-result,
.automation-file-result {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(115, 174, 255, 0.14);
}
.automation-file-result { cursor: pointer; }
.automation-search-result:hover,
.automation-file-result:hover { background: rgba(255, 255, 255, 0.05); border-color: rgba(118, 191, 255, 0.28); }
.automation-search-result-head,
.automation-file-result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 4px; }
.automation-search-result-title {
    color: #eef5ff; font-size: 13px; font-weight: 650; line-height: 1.35;
    display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.automation-search-result-time,
.automation-file-result-type { color: #7edcda; font-size: 11px; white-space: nowrap; opacity: 0.85; }
.automation-search-result-excerpt {
    color: #bcd0ef; font-size: 12px; line-height: 1.45;
    display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.automation-search-result-source { margin-top: 6px; color: #8cb6ff; font-size: 11px; line-height: 1.3; word-break: break-all; opacity: 0.9; }
.automation-file-result-path { color: #eef5ff; font-size: 13px; font-weight: 650; line-height: 1.35; word-break: break-word; }
.automation-file-result-label { color: #bcd0ef; font-size: 12px; line-height: 1.45; }
.automation-file-preview-block {
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(115, 174, 255, 0.14);
    color: #cdddf6;
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 220px;
    overflow: auto;
}

/* thin scrollbars inside drawers */
.timeline-rows .automation-details-body::-webkit-scrollbar,
.content-area::-webkit-scrollbar { width: 8px; }
.timeline-rows .automation-details-body::-webkit-scrollbar-thumb,
.content-area::-webkit-scrollbar-thumb { background: rgba(104, 150, 223, 0.42); border-radius: 8px; }
