/**
 * Platform Assistant widget (pa- prefix).
 * Mounted on document.body, outside #view-container, so it persists across
 * SPA navigation.
 *
 * Z-order contract (keep in sync with utils/toast.js):
 *   app shell            <  10000
 *   modals               10000-10399  (layout/modal.js stack 10100+, custom
 *                                      modals 10000-10300)
 *   assistant panel      100500       (must stay usable above ANY modal,
 *                                      docked or floating)
 *   notifications        100600+      (toasts / bell / tn-panel / tn-confirm
 *                                      stay visible above the assistant)
 */

#assistant-widget-root {
    position: fixed;
    top: 0;
    right: 0;
    /* Above every modal tier (see contract above); the launcher itself is
       appended to body and carries its own z-index. */
    z-index: 100500;
    pointer-events: none;
    font-family: 'Inter', system-ui, sans-serif;
}

#assistant-widget-root > * {
    pointer-events: auto;
}

/* ── Launcher ──
   Fixed at the very top-right, immediately left of the persistent
   notifications bell (#tn-bell in toast.js: top:12px; right:16px;
   36x36; z-index:100610). Mirrors its geometry, styling and tier. */

.pa-launcher {
    position: fixed;
    top: 12px;
    right: 56px;
    z-index: 100610;
    width: 36px;
    height: 36px;
    border-radius: 9999px;
    border: none;
    background: transparent;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s ease, background 0.15s ease;
}

.pa-launcher:hover {
    color: #111827;
}

.pa-launcher-open {
    background: #e5e7eb;
    color: #111827;
}

/* ── Panel (drops down from the launcher, top-right) ── */

.pa-panel {
    position: fixed;
    top: 56px;
    right: 16px;
    /* Stacks inside #assistant-widget-root's context (100500) — this value
       only orders the panel against root-internal siblings. */
    z-index: 1;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: min(640px, calc(100vh - 76px));
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pa-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: transparent;
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.pa-dragging .pa-header {
    cursor: grabbing;
}

.pa-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
    flex-shrink: 0;
}

.pa-header-actions {
    display: flex;
    gap: 4px;
    /* The action buttons must NEVER be pushed out of view by the meters —
       they don't shrink, and margin-left:auto keeps them pinned right even
       when the meters between title and actions are hidden. */
    flex-shrink: 0;
    margin-left: auto;
}

/* Narrow panel: the meters are informational — the action buttons are not.
   The panel is the size container; as it narrows degrade gracefully:
   1) compact the context meter (icon+bar only; numbers stay in the tooltip),
   2) drop the usage chip, 3) drop the context meter entirely.
   !important beats the JS-managed inline display. */
.pa-panel { container-type: inline-size; }
@container (max-width: 500px) {
    .pa-context-meter-label { display: none !important; }
}
@container (max-width: 430px) {
    .pa-usage-chip { display: none !important; }
}
@container (max-width: 330px) {
    .pa-context-meter { display: none !important; }
}

/* Auto-compaction context-fill meter (labeled pill) */
.pa-context-meter {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 22px;
    padding: 0 8px;
    margin: 0 6px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.07);
    color: #6b7280;
    flex-shrink: 0;
    cursor: default;
    transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.pa-context-meter-icon {
    display: inline-flex;
    align-items: center;
    color: #9ca3af;
    transition: color 0.25s ease;
}
.pa-context-meter-bar {
    width: 42px;
    height: 5px;
    border-radius: 3px;
    background: rgba(0, 0, 0, 0.12);
    overflow: hidden;
}
.pa-context-meter-fill {
    height: 100%;
    width: 0%;
    background: var(--pa-accent, #4f46e5);
    border-radius: 3px;
    transition: width 0.35s ease, background-color 0.35s ease;
}
.pa-context-meter-label {
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #6b7280;
    white-space: nowrap;
    transition: color 0.25s ease;
}
.pa-context-meter.is-warning {
    background: rgba(217, 119, 6, 0.10);
    border-color: rgba(217, 119, 6, 0.25);
}
.pa-context-meter.is-warning .pa-context-meter-label,
.pa-context-meter.is-warning .pa-context-meter-icon { color: #b45309; }
.pa-context-meter.is-critical {
    background: rgba(220, 38, 38, 0.10);
    border-color: rgba(220, 38, 38, 0.28);
}
.pa-context-meter.is-critical .pa-context-meter-label,
.pa-context-meter.is-critical .pa-context-meter-icon { color: #dc2626; }

/* Compacting: pulsing accent border + adjacent indicator */
.pa-context-meter.is-compacting {
    border-color: var(--pa-accent, #4f46e5);
    animation: pa-compact-pulse 1.1s ease-in-out infinite;
}
@keyframes pa-compact-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.0); border-color: rgba(79, 70, 229, 0.35); }
    50%      { box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18); border-color: var(--pa-accent, #4f46e5); }
}
/* Real session token-usage counter (▲in ▼out · $cost) — ticks live as
   workflow nodes complete. Distinct from the context-fill meter, but styled
   IDENTICALLY to it (same pill tokens) so the header reads as one family. */
.pa-usage-chip {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    margin: 0 6px 0 0;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.07);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: #6b7280;
    white-space: nowrap;
    flex-shrink: 0;
    cursor: default;
}

.pa-usage-chip.pa-usage-tick {
    animation: pa-usage-tick 0.6s ease-out;
}

@keyframes pa-usage-tick {
    0%   { border-color: var(--pa-accent, #4f46e5); color: var(--pa-accent, #4f46e5); }
    100% { border-color: rgba(0, 0, 0, 0.07); color: #6b7280; }
}

.pa-compacting {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    color: var(--pa-accent, #4f46e5);
    white-space: nowrap;
    margin-left: 2px;
}
.pa-compacting::before {
    content: '';
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: pa-compact-dot 1s ease-in-out infinite;
}
@keyframes pa-compact-dot {
    0%, 100% { opacity: 0.3; transform: scale(0.85); }
    50%      { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .pa-context-meter.is-compacting { animation: none; border-color: var(--pa-accent, #4f46e5); }
    .pa-compacting::before { animation: none; opacity: 0.8; }
}

.pa-icon-btn {
    border: none;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
}

.pa-icon-btn:hover {
    background: #e5e7eb;
    color: #111827;
}

.pa-icon-btn-active {
    background: #e5e7eb;
    color: #111827;
}

/* ── Docked mode: full height, glued to the right edge ──
   While docked AND open, the app shell reserves the panel's width so page
   content shifts left instead of being covered. */

body.pa-dock-active #dashboard-container {
    margin-right: var(--pa-dock-width, 420px);
    transition: margin-right 0.15s ease;
}

/* While docked, full-screen modal overlays end at the dock edge so their
   tint and (flex-centered) dialog boxes position within the visible page
   area — window width minus the docked assistant — not the full viewport.
   Covers the shared modal.js overlays (.modal-overlay) and every custom
   overlay built as a Tailwind `fixed inset-0` div (agent wizard, agent
   test, collection/test-suite/kb wizards, users/settings/runs dialogs,
   json-viewer, markdown-editor, …). The [class*=…] pair intentionally
   requires BOTH tokens so absolutely-positioned in-card `inset-0` covers
   are not affected. */
body.pa-dock-active .modal-overlay,
body.pa-dock-active [class*="fixed"][class*="inset-0"] {
    right: var(--pa-dock-width, 420px);
}

/* Modal boxes sized in viewport units would overflow the narrowed overlay;
   remap them to percentages of the (already narrowed) overlay. */
body.pa-dock-active .modal-overlay .max-w-\[95vw\] {
    max-width: 95%;
}
body.pa-dock-active .modal-overlay .max-w-\[1670px\] {
    max-width: min(1670px, 95%);
}
body.pa-dock-active .modal-overlay .w-\[95vw\] {
    width: 95%;
}
body.pa-dock-active .aef-modal {
    width: 100%; /* fills its raw container, which is %-sized while docked */
}

/* No transition lag while actively resizing the dock */
body.pa-dock-active.pa-dragging #dashboard-container {
    transition: none;
}

.pa-panel.pa-docked {
    /* Full viewport height, glued to the right edge. The fixed top-right
       icons (assistant launcher + notifications bell) shift left together
       with the page content while docked — see the pa-dock-active rules. */
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
    height: 100vh !important;
    max-width: none;
    border-radius: 0;
    border: none;
    border-left: 1px solid #e5e7eb;
    box-shadow: none;
}

/* Docked header: same height as the page header so the two read as one
   continuous bar, with icons sized like the fixed launcher/bell buttons. */
.pa-docked .pa-header {
    height: var(--header-height); 
    padding: 0 16px;
}

.pa-docked .pa-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
}

.pa-docked .pa-icon-btn {
    width: 36px;
    height: 36px;
    justify-content: center;
    border-radius: 9999px;
}

.pa-docked .pa-icon-btn svg {
    width: 18px;
    height: 18px;
}

/* While docked and open, the fixed top-right icons (and the notifications
   history panel) move left by the dock width so they stay over the page
   content instead of being covered by the panel. */
body.pa-dock-active .pa-launcher {
    right: calc(56px + var(--pa-dock-width, 420px));
    transition: right 0.15s ease;
}

body.pa-dock-active #tn-bell {
    right: calc(16px + var(--pa-dock-width, 420px));
    transition: right 0.15s ease;
}

body.pa-dock-active #tn-panel {
    right: calc(16px + var(--pa-dock-width, 420px));
}

/* Toasts (and confirm toasts) anchor below the notifications bell, so they
   shift left together with it instead of covering the docked panel. */
body.pa-dock-active #tn-toast-container,
body.pa-dock-active .tn-confirm {
    right: calc(16px + var(--pa-dock-width, 420px));
}

/* No transition lag while actively resizing the dock */
body.pa-dock-active.pa-dragging .pa-launcher,
body.pa-dock-active.pa-dragging #tn-bell {
    transition: none;
}

/* ── Resize handles ── */

.pa-rz {
    position: absolute;
    z-index: 5;
    touch-action: none;
}

.pa-rz-n  { top: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.pa-rz-s  { bottom: -3px; left: 10px; right: 10px; height: 7px; cursor: ns-resize; }
.pa-rz-e  { right: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.pa-rz-w  { left: -3px; top: 10px; bottom: 10px; width: 7px; cursor: ew-resize; }
.pa-rz-ne { top: -4px; right: -4px; width: 14px; height: 14px; cursor: nesw-resize; }
.pa-rz-nw { top: -4px; left: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.pa-rz-se { bottom: -4px; right: -4px; width: 14px; height: 14px; cursor: nwse-resize; }
.pa-rz-sw { bottom: -4px; left: -4px; width: 14px; height: 14px; cursor: nesw-resize; }

/* Docked: only the left edge resizes (width) */
.pa-docked .pa-rz { display: none; }
.pa-docked .pa-rz-w { display: block; top: 0; bottom: 0; }

/* Dragging near the right edge: hint that dropping will dock */
.pa-panel.pa-dock-preview {
    outline: 2px solid #6b7280;
    outline-offset: 2px;
}

/* While dragging/resizing: suppress selection and let events flow to window */
body.pa-dragging {
    user-select: none;
}

body.pa-dragging .pa-panel iframe,
body.pa-dragging .pa-messages {
    pointer-events: none;
}

/* ── Conversation history (dropdown under the header) ──
   Reads as a distinct elevated layer over the conversation: tinted
   background, its own section header, card-style entries, and a drop
   shadow separating it from the messages below. */

.pa-history-list {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    max-height: 50%;
    background: #f3f4f6;
    border-bottom: 1px solid #d1d5db;
    box-shadow: 0 10px 18px -12px rgba(17, 24, 39, 0.35);
    position: relative;
    z-index: 2;
}

.pa-history-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px 6px;
    flex-shrink: 0;
}

.pa-history-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
}

.pa-history-count {
    font-size: 11px;
    color: #9ca3af;
}

.pa-history-items {
    overflow-y: auto;
    padding: 2px 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.pa-history-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    text-align: left;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.pa-history-item:hover {
    border-color: #9ca3af;
    box-shadow: 0 1px 4px rgba(17, 24, 39, 0.08);
}

.pa-history-item-active {
    border-color: #111827;
    box-shadow: inset 3px 0 0 0 #111827;
}

.pa-history-title {
    font-size: 13px;
    color: #111827;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.pa-history-meta {
    font-size: 11px;
    color: #9ca3af;
}

.pa-history-empty {
    font-size: 12px;
    color: #9ca3af;
    text-align: center;
    padding: 6px 0 16px;
}

/* ── Messages ── */

.pa-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.pa-bubble {
    max-width: 92%;
    font-size: 13px;
    line-height: 1.5;
}

.pa-bubble-content {
    padding: 8px 12px;
    border-radius: 10px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.pa-bubble-user {
    align-self: flex-end;
}

.pa-bubble-user .pa-bubble-content {
    background: #1f2937;
    color: #f9fafb;
    border-bottom-right-radius: 3px;
}

.pa-bubble-assistant {
    align-self: flex-start;
}

.pa-bubble-assistant .pa-bubble-content {
    background: #f3f4f6;
    color: #111827;
    border-bottom-left-radius: 3px;
}

.pa-bubble-assistant .pa-bubble-content a {
    color: #b45309;
    text-decoration: underline;
}

/* Copy answer button */

.pa-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 4px;
    padding: 2px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #6b7280;
    font-size: 11px;
    line-height: 1.4;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.pa-bubble-assistant:hover .pa-copy-btn,
.pa-copy-btn:focus-visible {
    opacity: 1;
}

.pa-copy-btn:hover {
    color: #111827;
    border-color: #d1d5db;
}

.pa-copy-btn.pa-copy-done {
    opacity: 1;
    color: #059669;
    border-color: #a7f3d0;
}

.pa-copy-icon {
    width: 12px;
    height: 12px;
    display: inline-block;
    background-color: currentColor;
    -webkit-mask: no-repeat center / contain;
    mask: no-repeat center / contain;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='9' y='9' width='13' height='13' rx='2' ry='2'/%3E%3Cpath d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/%3E%3C/svg%3E");
}

.pa-copy-done .pa-copy-icon {
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
}

.pa-bubble-system {
    align-self: center;
    max-width: 100%;
}

.pa-bubble-system .pa-bubble-content {
    background: transparent;
    color: #6b7280;
    font-size: 12px;
    text-align: center;
}

.pa-bubble-error {
    align-self: center;
    max-width: 100%;
}

.pa-bubble-error .pa-bubble-content {
    background: #fef2f2;
    color: #b91c1c;
    font-size: 12px;
    border: 1px solid #fecaca;
}

/* Code inside assistant messages */

.pa-pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
    margin: 6px 0;
}

.pa-inline {
    background: #e5e7eb;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* ── Narratives (agent process) ── */

.pa-narrative-container {
    font-size: 12px;
    color: #4b5563;
}

.pa-narrative-collapsed .pa-bubble-content {
    display: none;
}

.pa-narrative-toggle {
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 11px;
    cursor: pointer;
    padding: 2px 0;
    text-align: left;
}

.pa-narrative-toggle:hover {
    color: #111827;
}

/* ── Follow-up chips ── */

.pa-followups {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
}

.pa-followup-chip {
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    text-align: left;
}

.pa-followup-chip:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* ── Activity banner (page-level "assistant is working" indicator) ──
   Sits ABOVE all modals (10000-10399) but below the assistant panel
   (100500) and notifications (100600+) — see the z-order contract at the
   top of this file. Non-interactive; centered in the content area (shifts
   with the docked panel via --pa-dock-width). */

.pa-activity {
    position: fixed;
    top: 14px;
    left: 50%;
    z-index: 100400;
    transform: translateX(-50%) translateY(-160%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: min(360px, 80vw);
    padding: 11px 24px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #ffffff;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    max-width: min(80vw, 680px);
    overflow: hidden;
    pointer-events: none;
    opacity: 0;
    box-shadow:
        0 10px 34px rgba(79, 70, 229, 0.5),
        0 0 0 4px rgba(99, 102, 241, 0.12);
    /* white shimmer sweep over a saturated indigo→violet gradient */
    background:
        linear-gradient(110deg,
            rgba(255, 255, 255, 0) 38%,
            rgba(255, 255, 255, 0.35) 50%,
            rgba(255, 255, 255, 0) 62%) 0 0 / 220% 100% no-repeat,
        linear-gradient(90deg, #4f46e5, #7c3aed 55%, #4f46e5);
    transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.5, 1), opacity 0.22s ease;
}

.pa-activity-visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    animation: pa-activity-shimmer 2s linear infinite;
}

/* backend plane: warm amber — data/processes are being touched */
.pa-activity[data-plane="backend"] {
    box-shadow:
        0 10px 34px rgba(217, 119, 6, 0.5),
        0 0 0 4px rgba(217, 119, 6, 0.12);
    background:
        linear-gradient(110deg,
            rgba(255, 255, 255, 0) 38%,
            rgba(255, 255, 255, 0.35) 50%,
            rgba(255, 255, 255, 0) 62%) 0 0 / 220% 100% no-repeat,
        linear-gradient(90deg, #d97706, #ea580c 55%, #d97706);
}

@keyframes pa-activity-shimmer {
    from { background-position: 120% 0, 0 0; }
    to   { background-position: -120% 0, 0 0; }
}

.pa-activity-icon {
    display: inline-flex;
    animation: pa-activity-pulse 1.6s ease-in-out infinite;
}

@keyframes pa-activity-pulse {
    0%, 100% { transform: scale(1); opacity: 0.75; }
    50%      { transform: scale(1.18) rotate(8deg); opacity: 1; }
}

.pa-activity-label {
    overflow: hidden;
    text-overflow: ellipsis;
}

.pa-activity-plane {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.22);
}

.pa-activity-dots {
    display: inline-flex;
    gap: 3px;
}

.pa-activity-dots i {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.4;
    animation: pa-activity-dot 1.2s ease-in-out infinite;
}

.pa-activity-dots i:nth-child(2) { animation-delay: 0.15s; }
.pa-activity-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes pa-activity-dot {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50%      { transform: translateY(-3px); opacity: 1; }
}

/* Docked assistant: center within the remaining content area */
body.pa-dock-active .pa-activity {
    left: calc((100vw - var(--pa-dock-width, 0px)) / 2);
}

/* ── Highlight flash (assistant `highlight` command target) ── */

.pa-highlight-flash {
    animation: pa-highlight-pulse 2.5s ease-out;
    scroll-margin: 80px;
}

@keyframes pa-highlight-pulse {
    0%   { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.75), 0 0 24px rgba(99, 102, 241, 0.45); }
    60%  { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4), 0 0 12px rgba(99, 102, 241, 0.2); }
    100% { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0), 0 0 0 rgba(99, 102, 241, 0); }
}

/* ── UI command chips (audit trail for assistant actions) ── */

.pa-cmd-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    padding: 2px 0;
}

.pa-cmd-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid #d1d5db;
    background: #fff;
    color: #374151;
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 999px;
    max-width: 100%;
}

.pa-cmd-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pa-cmd-icon::before {
    font-size: 11px;
    line-height: 1;
}

.pa-cmd-running { border-color: #93c5fd; background: #eff6ff; color: #1d4ed8; }
.pa-cmd-running .pa-cmd-icon::before { content: '⏳'; }

.pa-cmd-done { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.pa-cmd-done .pa-cmd-icon::before { content: '✓'; }

.pa-cmd-failed { border-color: #fca5a5; background: #fef2f2; color: #b91c1c; }
.pa-cmd-failed .pa-cmd-icon::before { content: '✗'; }

.pa-cmd-unsupported { border-color: #fcd34d; background: #fffbeb; color: #b45309; }
.pa-cmd-unsupported .pa-cmd-icon::before { content: '⚠'; }

.pa-cmd-declined { border-color: #d1d5db; background: #f9fafb; color: #6b7280; }
.pa-cmd-declined .pa-cmd-icon::before { content: '⊘'; }

.pa-cmd-history { border-color: #e5e7eb; background: #f9fafb; color: #9ca3af; }
.pa-cmd-history .pa-cmd-icon::before { content: '⚡'; }

/* ── Pending-action confirmation card (phase A3) ──
   Writes NEVER auto-execute: this card's Confirm button is the only
   trigger (deterministic endpoint, no LLM in the execute path). */

.pa-confirm-card {
    align-self: stretch;
    margin: 6px 4px;
    padding: 10px 12px;
    border: 1px solid #fbbf24;
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
    background: #fffbeb;
    font-size: 12.5px;
}

.pa-confirm-head {
    font-weight: 600;
    color: #92400e;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}

.pa-confirm-summary {
    color: #1f2937;
    line-height: 1.45;
    margin-bottom: 8px;
    white-space: pre-wrap;
    word-break: break-word;
}

.pa-confirm-actions { display: flex; gap: 8px; align-items: center; }

.pa-confirm-actions button {
    font-size: 12px;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.pa-confirm-actions button:disabled { opacity: 0.5; cursor: default; }

.pa-confirm-yes { background: #059669; color: #fff; }
.pa-confirm-yes:hover:not(:disabled) { background: #047857; }

.pa-confirm-no { background: #fff; color: #4b5563; border-color: #d1d5db; }
.pa-confirm-no:hover:not(:disabled) { background: #f3f4f6; }

.pa-confirm-outcome { font-size: 12px; font-weight: 500; }

.pa-confirm-done { border-color: #6ee7b7; border-left-color: #059669; background: #ecfdf5; }
.pa-confirm-done .pa-confirm-outcome { color: #047857; }

.pa-confirm-declined { border-color: #d1d5db; border-left-color: #9ca3af; background: #f9fafb; }
.pa-confirm-declined .pa-confirm-outcome { color: #6b7280; }

.pa-confirm-failed { border-color: #fca5a5; border-left-color: #dc2626; background: #fef2f2; }
.pa-confirm-failed .pa-confirm-outcome { color: #b91c1c; }

/* ── Confirm-card diff (per-section before→after, content-edit actions) ── */

.pa-confirm-diff { margin: 0 0 8px; }

.pa-confirm-diff > summary {
    font-size: 11.5px;
    font-weight: 600;
    color: #92400e;
    cursor: pointer;
    user-select: none;
}
.pa-confirm-diff > summary:hover { color: #78350f; }

.pa-diff-body {
    margin-top: 6px;
    max-height: 260px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pa-diff-row {
    border: 1px solid #fde68a;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
}

.pa-diff-name {
    font-size: 11px;
    font-weight: 600;
    color: #374151;
    padding: 4px 8px;
    background: #fef3c7;
}

.pa-diff-count { font-weight: 500; color: #92400e; }

.pa-diff-before pre, .pa-diff-after pre {
    margin: 0;
    padding: 4px 8px 6px;
    font-size: 11px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 96px;
    overflow-y: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pa-diff-tag {
    display: block;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 3px 8px 0;
}

.pa-diff-before { background: #fef2f2; }
.pa-diff-before .pa-diff-tag { color: #b91c1c; }
.pa-diff-before pre { color: #7f1d1d; }

.pa-diff-after { background: #ecfdf5; border-top: 1px solid #d1fae5; }
.pa-diff-after .pa-diff-tag { color: #047857; }
.pa-diff-after pre { color: #064e3b; }

.pa-diff-note {
    font-size: 10.5px;
    color: #92400e;
    font-style: italic;
    padding: 2px 0;
}

/* ── Typing indicator ── */

.pa-typing {
    align-self: flex-start;
    font-size: 12px;
    color: #6b7280;
    padding: 4px 12px;
}

.pa-typing-text::after {
    content: '';
    animation: pa-dots 1.4s infinite;
}

@keyframes pa-dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

.pa-typing-bar {
    margin-top: 4px;
    height: 3px;
    width: 160px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.pa-typing-bar-fill {
    height: 100%;
    background: #6b7280;
    transition: width 0.3s ease;
}

/* ── Input ── */

.pa-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}

.pa-input {
    flex: 1;
    resize: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 120px;
    background: #fff;
    color: #111827;
}

.pa-input:focus {
    outline: none;
    border-color: #6b7280;
}

.pa-send {
    border: none;
    background: #1f2937;
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.pa-send:hover:not(:disabled) {
    background: #111827;
}

.pa-send:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ── Small screens ── */

@media (max-width: 480px) {
    .pa-panel {
        right: 8px;
        top: 56px;
        width: calc(100vw - 16px);
    }
}

/* ── Agentic turn steps (phase A5.1) ── */

.pa-step-divider {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 4px 6px;
    font-size: 11px;
    color: #6b7280;
}

.pa-step-divider::before {
    content: '';
    flex: 0 0 14px;
    border-top: 1px dashed #d1d5db;
}

.pa-step-divider::after {
    content: '';
    flex: 1;
    border-top: 1px dashed #d1d5db;
}

.pa-step-badge {
    flex-shrink: 0;
    background: #eef2ff;
    color: #4f46e5;
    border: 1px solid #c7d2fe;
    border-radius: 999px;
    padding: 1px 8px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    font-size: 10px;
}

.pa-step-reason {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

/* ── Working bar + stop button (agentic turn UX) ── */

.pa-working-bar {
    height: 4px;
    flex-shrink: 0;
    background: linear-gradient(90deg, #6366f1, #a855f7, #ec4899, #f59e0b, #6366f1);
    background-size: 300% 100%;
    animation: pa-roll 1.1s linear infinite;
    border-radius: 2px;
}

@keyframes pa-roll {
    0% { background-position: 0% 0; }
    100% { background-position: 300% 0; }
}

.pa-send.pa-send-stop {
    background: #dc2626;
}

.pa-send.pa-send-stop:hover:not(:disabled) {
    background: #b91c1c;
}

/* ── Task plan checklist (agentic turn A5.2) ── */

.pa-plan-card {
    margin: 10px 4px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-left: 3px solid #6366f1;
    border-radius: 8px;
    background: #fafafe;
}

.pa-plan-head {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6366f1;
    margin-bottom: 6px;
}

.pa-plan-list { list-style: none; margin: 0; padding: 0; }

.pa-plan-item {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    font-size: 13px;
    line-height: 1.4;
    padding: 2px 0;
    color: #374151;
}

.pa-plan-tick { flex-shrink: 0; width: 14px; text-align: center; font-weight: 700; }

.pa-plan-done .pa-plan-tick { color: #16a34a; }
.pa-plan-done .pa-plan-title { color: #9ca3af; text-decoration: line-through; }
.pa-plan-in_progress .pa-plan-tick { color: #6366f1; }
.pa-plan-in_progress .pa-plan-title { font-weight: 600; color: #111827; }
.pa-plan-failed .pa-plan-tick { color: #dc2626; }
.pa-plan-failed .pa-plan-title { color: #dc2626; }
.pa-plan-pending .pa-plan-tick { color: #d1d5db; }

.pa-plan-note {
    margin-top: 6px;
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
}
