/* ═══════════════════════════════════════════════════════════════════════
   Sub-agent progress panel (subagents.js)

   Right-hand side panel that streams a spawn_agent sub-agent's work live,
   opened by clicking its chip in the chat. Uses the chat surface tokens
   (tokens.css / dark-theme.css) so it follows the theme automatically.
   ═══════════════════════════════════════════════════════════════════ */

/* ── Chip affordances ── */
.subagent-chip { cursor: pointer; }
.subagent-chip:hover { border-color: var(--chat-accent, #6366f1); }
.subagent-chip-view {
    display: inline-flex;
    align-items: center;
    margin-left: .15rem;
    padding: .1rem .45rem;
    font-size: .68rem;
    color: var(--chat-accent, #6366f1);
    background: var(--chat-accent-subtle, rgba(99, 102, 241, .08));
    border-radius: 50px;
    flex: 0 0 auto;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.subagent-chip-view:hover {
    background: var(--chat-accent, #6366f1);
    color: #fff;
}

/* ── Panel ── */
.subagent-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 1044; /* above the chat, below Bootstrap modals (1055) */
    display: flex;
    flex-direction: column;
    width: min(30rem, 100vw);
    background: var(--chat-bg, #fff);
    border-left: 1px solid var(--chat-border, #e5e7eb);
    box-shadow: var(--chat-shadow-xl, 0 20px 60px rgba(0, 0, 0, .1));
    transform: translateX(105%);
    transition: transform .25s cubic-bezier(.4, 0, .2, 1), width .2s ease;
}
.subagent-panel.open { transform: translateX(0); }
.subagent-panel.wide { width: min(46rem, 100vw); }

.sap-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--chat-border, #e5e7eb);
    flex: 0 0 auto;
}
.sap-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 600;
    font-size: .95rem;
    color: var(--chat-text, #1a1d26);
}
.sap-title i { color: var(--chat-accent, #6366f1); }
.sap-actions { display: flex; gap: .25rem; }
.sap-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    border: 0;
    border-radius: var(--chat-radius-xs, 6px);
    background: transparent;
    color: var(--chat-text-secondary, #6b7280);
    font-size: .82rem;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}
.sap-btn:hover {
    background: var(--chat-surface, #f4f5f7);
    color: var(--chat-text, #1a1d26);
}

/* ── Tabs (only with 2+ agents) ── */
.sap-tabs {
    display: flex;
    gap: .35rem;
    padding: .55rem 1rem 0;
    flex: 0 0 auto;
    flex-wrap: wrap;
}
.sap-tab {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    max-width: 12rem;
    padding: .25rem .7rem;
    font-size: .76rem;
    font-weight: 500;
    color: var(--chat-text-secondary, #6b7280);
    background: var(--chat-surface, #f4f5f7);
    border: 1px solid var(--chat-border, #e5e7eb);
    border-radius: 50px;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}
.sap-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sap-tab:hover { border-color: var(--chat-accent, #6366f1); }
.sap-tab.active {
    color: var(--chat-accent, #6366f1);
    border-color: var(--chat-accent, #6366f1);
    background: var(--chat-accent-subtle, rgba(99, 102, 241, .08));
}
.sap-tab .fa-check { color: #1a7f37; }
.sap-tab .fa-exclamation-circle { color: #cf222e; }

/* ── Meta (role, status, model & cost badges, task) ── */
.sap-meta {
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--chat-border, #e5e7eb);
    flex: 0 0 auto;
}
.sap-meta-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .6rem;
}
.sap-role {
    font-weight: 600;
    font-size: .92rem;
    color: var(--chat-text, #1a1d26);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sap-status {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .76rem;
    font-weight: 600;
    padding: .15rem .6rem;
    border-radius: 50px;
    flex: 0 0 auto;
}
.sap-status.running { color: var(--chat-accent, #6366f1); background: var(--chat-accent-subtle, rgba(99, 102, 241, .08)); }
.sap-status.done { color: #1a7f37; background: rgba(26, 127, 55, .1); }
.sap-status.error { color: #cf222e; background: rgba(207, 34, 46, .1); }

.sap-badges {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    margin-top: .5rem;
}
.sap-badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .15rem .6rem;
    font-size: .72rem;
    font-weight: 500;
    color: var(--chat-text-secondary, #6b7280);
    background: var(--chat-surface, #f4f5f7);
    border: 1px solid var(--chat-border, #e5e7eb);
    border-radius: 50px;
}
.sap-badge i { font-size: .66rem; color: var(--chat-accent, #6366f1); }

.sap-task { margin-top: .55rem; font-size: .8rem; }
.sap-task summary {
    cursor: pointer;
    user-select: none;
    color: var(--chat-text-secondary, #6b7280);
    font-weight: 500;
    list-style: none;
}
.sap-task summary::-webkit-details-marker { display: none; }
.sap-task summary::before {
    content: '\f054';
    font-family: 'Font Awesome 5 Free', 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: .6rem;
    margin-right: .4rem;
    display: inline-block;
    transition: transform .15s ease;
}
.sap-task[open] summary::before { transform: rotate(90deg); }
/* Read-only quote, not an input: no boxed border (that read as a textarea),
   muted text, accent quote bar. */
.sap-task div {
    margin-top: .4rem;
    padding: .15rem .7rem;
    color: var(--chat-text-secondary, #6b7280);
    border-left: 3px solid var(--chat-border, #e5e7eb);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 10rem;
    overflow-y: auto;
    cursor: default;
}

/* ── Transcript body ── */
.sap-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .9rem 1rem 1.2rem;
    overscroll-behavior: contain;
}

/* Scrollbars match the left sidebar's (.chats-scroll-area): 4px, trackless. */
.sap-body, .sap-task div {
    scrollbar-width: thin;
    scrollbar-color: rgb(0 0 0 / .12) transparent;
}
.sap-body::-webkit-scrollbar, .sap-task div::-webkit-scrollbar { width: 4px; }
.sap-body::-webkit-scrollbar-track, .sap-task div::-webkit-scrollbar-track { background: transparent; }
.sap-body::-webkit-scrollbar-thumb, .sap-task div::-webkit-scrollbar-thumb {
    background: rgb(0 0 0 / .12);
    border-radius: 4px;
}
[data-theme=dark] .sap-body, body.dark-theme .sap-body, .dark-theme .sap-body,
[data-theme=dark] .sap-task div, body.dark-theme .sap-task div, .dark-theme .sap-task div {
    scrollbar-color: rgba(255, 255, 255, .1) transparent;
}
[data-theme=dark] .sap-body::-webkit-scrollbar-thumb, body.dark-theme .sap-body::-webkit-scrollbar-thumb, .dark-theme .sap-body::-webkit-scrollbar-thumb,
[data-theme=dark] .sap-task div::-webkit-scrollbar-thumb, body.dark-theme .sap-task div::-webkit-scrollbar-thumb, .dark-theme .sap-task div::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .1);
}
.sap-transcript {
    font-size: .88rem;
    line-height: 1.6;
    color: var(--chat-text, #1a1d26);
    word-break: break-word;
}
.sap-transcript pre {
    max-width: 100%;
    overflow-x: auto;
    border-radius: var(--chat-radius-sm, 8px);
}
/* The panel is much narrower than a chat card, so the sub-agent's own tool
   chips must be allowed to wrap between their parts (label / code / badges)
   instead of crushing the label text letter-by-letter. */
.sap-transcript .tool-done-chip {
    flex-wrap: wrap;
    row-gap: .15rem;
    white-space: nowrap;
}
.sap-transcript .tool-done-chip code {
    flex: 0 1 auto;
    max-width: 100%;
}
.sap-transcript img { max-width: 100%; }
.sap-transcript > :first-child { margin-top: 0; }

.sap-notice {
    display: flex;
    gap: .5rem;
    align-items: flex-start;
    margin: .8rem 0 0;
    padding: .6rem .8rem;
    font-size: .82rem;
    color: var(--chat-text, #1a1d26);
    background: var(--chat-surface, #f4f5f7);
    border: 1px solid var(--chat-border, #e5e7eb);
    border-left: 3px solid var(--chat-accent, #6366f1);
    border-radius: var(--chat-radius-sm, 8px);
}
.sap-notice i { color: var(--chat-accent, #6366f1); margin-top: .15rem; }

/* While the panel is open, slide the chat's floating Share button (fixed,
   z-index 1060) out from underneath it instead of fighting its z-order. */
body.subagent-panel-open .share-floating-btn {
    right: calc(min(30rem, 100vw) + 20px);
    transition: right .25s cubic-bezier(.4, 0, .2, 1);
}
body.subagent-panel-open.subagent-panel-wide .share-floating-btn {
    right: calc(min(46rem, 100vw) + 20px);
}
@media (max-width: 640px) {
    body.subagent-panel-open .share-floating-btn { display: none; }
}

/* ── Minimized dock pill ── */
.subagent-dock {
    position: fixed;
    right: 1rem;
    /* Above the scroll-to-latest button (fixed at bottom 92px + 42px tall). */
    bottom: 9.5rem;
    z-index: 1044;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .95rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--chat-text, #1a1d26);
    background: var(--chat-bg, #fff);
    border: 1px solid var(--chat-border, #e5e7eb);
    border-radius: 50px;
    box-shadow: var(--chat-shadow-lg, 0 8px 30px rgba(0, 0, 0, .08));
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease;
}
.subagent-dock:hover { border-color: var(--chat-accent, #6366f1); transform: translateY(-1px); }
.subagent-dock .fa-robot { color: var(--chat-accent, #6366f1); }
.subagent-dock .fa-circle-notch { color: var(--chat-accent, #6366f1); font-size: .74rem; }
.subagent-dock .fa-check { color: #1a7f37; font-size: .74rem; }

/* ── Dark theme ── */
[data-theme=dark] .sap-status.done, body.dark-theme .sap-status.done, .dark-theme .sap-status.done { color: #3fb950; background: rgba(46, 160, 67, .15); }
[data-theme=dark] .sap-status.error, body.dark-theme .sap-status.error, .dark-theme .sap-status.error { color: #f85149; background: rgba(248, 81, 73, .15); }
[data-theme=dark] .sap-tab .fa-check, body.dark-theme .sap-tab .fa-check, .dark-theme .sap-tab .fa-check { color: #3fb950; }
[data-theme=dark] .sap-tab .fa-exclamation-circle, body.dark-theme .sap-tab .fa-exclamation-circle, .dark-theme .sap-tab .fa-exclamation-circle { color: #f85149; }
[data-theme=dark] .subagent-dock .fa-check, body.dark-theme .subagent-dock .fa-check, .dark-theme .subagent-dock .fa-check { color: #3fb950; }

/* ── Small screens: full-width overlay ── */
@media (max-width: 640px) {
    .subagent-panel, .subagent-panel.wide { width: 100vw; }
}
