/* =================================================================
   WF Portal — Copilot Slide-Out Panel
   ================================================================= */

.copilot-panel {
    position: fixed;
    top: 3.5rem;
    right: 0;
    bottom: 0;
    width: 380px;
    z-index: 1025;
    background: var(--theme-background-raised);
    border-left: 1px solid var(--theme-border);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    transition: transform 200ms ease;
}

.copilot-panel.hidden {
    transform: translateX(100%);
}

.copilot-panel.show {
    transform: translateX(0);
}

/* Push the canvas left when the copilot panel is open so its right edge
   isn't clipped underneath the fixed panel. Mirrors the has-runner pattern
   in runner-panel.css. The :not(.has-runner) guard avoids stacking margins
   when the runner panel is also open — runner is wider (420px) and wins. */
.canvas-main-area:has(.copilot-panel.show):not(.has-runner) {
    margin-right: 380px;
}

/* POP-OUT mode (Kirk 2026-07-10): the copilot's answers got long-form (plans,
   sharp questions, build summaries) and 380px squeezes them into unreadable
   nested lists. The header's expand toggle widens the panel to a reading pane;
   collapse returns to the slim dock. The canvas push mirrors the width. */
.copilot-panel.wide {
    width: min(760px, 85vw);
}

.canvas-main-area:has(.copilot-panel.show.wide):not(.has-runner) {
    margin-right: min(760px, 85vw);
}

/* Floating tab — always visible, sticks out from panel left edge */
.copilot-tab {
    position: absolute;
    left: -40px;
    top: 0.75rem;
    width: 40px;
    height: 40px;
    border: 1px solid var(--theme-border);
    border-right: none;
    border-radius: var(--theme-radius) 0 0 var(--theme-radius);
    background: var(--theme-primary);
    color: var(--theme-text-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.1rem;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    pointer-events: auto;
    transition: background 150ms ease;
}

.copilot-tab:hover {
    background: var(--theme-primary-hover);
}

/* Header */
.copilot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--theme-border);
    flex-shrink: 0;
}

.copilot-title {
    font-weight: 600;
    font-size: var(--theme-font-size-base);
    color: var(--theme-text);
}

/* Header icon buttons (copy transcript, new chat) */
.copilot-hdr-btn {
    border: none;
    background: none;
    color: var(--theme-text-muted);
    cursor: pointer;
    padding: 0.15rem 0.3rem;
    font-size: 0.95rem;
    line-height: 1;
    transition: color 150ms ease;
}

.copilot-hdr-btn:hover:not(:disabled) {
    color: var(--theme-text);
}

.copilot-hdr-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Messages area */
.copilot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Empty state */
.copilot-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--theme-text-muted);
    gap: 0.5rem;
}

.copilot-empty-icon {
    font-size: 2rem;
    opacity: 0.4;
}

.copilot-empty p {
    margin: 0;
    font-size: var(--theme-font-size-sm);
}

/* Message bubbles */
.copilot-msg {
    display: flex;
    max-width: 90%;
}

.copilot-msg-user {
    align-self: flex-end;
}

.copilot-msg-assistant {
    align-self: flex-start;
}

.copilot-msg-content {
    padding: 0.5rem 0.75rem;
    border-radius: var(--theme-radius);
    font-size: var(--theme-font-size-sm);
    line-height: 1.45;
    word-break: break-word;
}

.copilot-msg-user .copilot-msg-content {
    background: var(--theme-primary);
    color: var(--theme-text-on-primary);
}

.copilot-msg-assistant .copilot-msg-content {
    background: var(--theme-background-subtle);
    color: var(--theme-text);
}

/* Collapsible "Actions executed" disclosure. The raw tool-call results
   are long + noisy when Copilot chains scan_for_drift / validate_*,
   so they render as a <details> element the user can open on demand. */
.copilot-actions {
    margin: 0;
}

.copilot-actions > summary {
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--theme-text-muted);
    list-style: none;
    padding: 0.15rem 0;
    user-select: none;
    opacity: 0.85;
    transition: opacity 0.15s ease;
}

.copilot-actions > summary:hover {
    opacity: 1;
    color: var(--theme-text);
}

/* Strip the default disclosure triangle + render a custom chevron so
   the bar stays visually quiet in the chat stream. */
.copilot-actions > summary::-webkit-details-marker {
    display: none;
}

.copilot-actions > summary::before {
    content: "▸ ";
    display: inline-block;
    width: 0.85em;
    transition: transform 0.15s ease;
}

.copilot-actions[open] > summary::before {
    content: "▾ ";
}

.copilot-actions-body {
    margin-top: 0.35rem;
    padding: 0.4rem 0.6rem;
    background: var(--theme-background);
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    font-size: 0.8rem;
    color: var(--theme-text-muted);
}

.copilot-actions-body ul {
    margin: 0;
    padding-left: 1.2rem;
}

/* Typing indicator */
.copilot-typing {
    display: flex;
    gap: 0.25rem;
    padding: 0.65rem 0.75rem;
}

.copilot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--theme-text-muted);
    animation: copilot-bounce 1.2s infinite ease-in-out;
}

.copilot-typing span:nth-child(2) { animation-delay: 0.2s; }
.copilot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes copilot-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Input area */
.copilot-input {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--theme-border);
    flex-shrink: 0;
    align-items: flex-end;
}

.copilot-input textarea {
    flex: 1;
    resize: none;
    font-size: var(--theme-font-size-sm);
    min-height: 80px;
    border-radius: 4px;
}

.copilot-input .btn {
    flex-shrink: 0;
    padding: 0.4rem 0.6rem;
}

/* ── Attachment pad (PDF / image drop + library) ───────────────────────── */
.copilot-attach {
    padding: 0.5rem 1rem 0;
    flex-shrink: 0;
}

/* Slim row: a drop/click target + a "from library" button. */
.copilot-attach-pad {
    display: flex;
    gap: 0.4rem;
    align-items: stretch;
}

/* The drop zone wraps a transparent full-bleed <input type=file> so a drop
   anywhere on the label lands on the input (WASM can't read @ondrop bytes). */
.copilot-attach-drop {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    border: 1px dashed var(--theme-border);
    border-radius: var(--theme-radius);
    color: var(--theme-text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    transition: border-color 150ms ease, color 150ms ease, background 150ms ease;
}

.copilot-attach-drop:hover {
    border-color: var(--theme-primary);
    color: var(--theme-text);
    background: var(--theme-background-subtle);
}

.copilot-attach-drop input[type="file"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.copilot-attach-drop i {
    font-size: 0.95rem;
}

.copilot-attach-lib {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-raised);
    color: var(--theme-text-muted);
    cursor: pointer;
    transition: border-color 150ms ease, color 150ms ease;
}

.copilot-attach-lib:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}

/* Queued-file chips (and the sent-chips echoed inside a user bubble). */
.copilot-attach-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.4rem;
}

.copilot-attach-chips-sent {
    margin: 0.35rem 0 0;
}

.copilot-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    max-width: 100%;
    padding: 0.2rem 0.45rem;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-subtle);
    color: var(--theme-text);
    font-size: 0.72rem;
}

.copilot-chip i {
    flex-shrink: 0;
    color: var(--theme-primary);
}

.copilot-chip-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 9rem;
}

.copilot-chip-size {
    flex-shrink: 0;
    color: var(--theme-text-muted);
    font-size: 0.66rem;
}

.copilot-chip-x {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    border: none;
    background: none;
    padding: 0;
    color: var(--theme-text-muted);
    cursor: pointer;
    line-height: 1;
}

.copilot-chip-x:hover {
    color: var(--theme-danger, #c0392b);
}

/* Sent chips inside a user bubble sit on the primary background. */
.copilot-msg-user .copilot-chip {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.35);
    color: var(--theme-text-on-primary);
}

.copilot-msg-user .copilot-chip i {
    color: var(--theme-text-on-primary);
}

.copilot-attach-error {
    margin-bottom: 0.4rem;
    font-size: 0.72rem;
    color: var(--theme-danger, #c0392b);
}

/* Responsive — full width on mobile */
@media (max-width: 576px) {
    .copilot-panel {
        width: 100%;
    }
}

/* Live build progress (async Copilot build poll) - one line per executed tool. */
.copilot-progress {
    margin: 0.25rem 0 0.5rem 0;
    padding: 0.4rem 0.6rem;
    border-left: 2px solid var(--theme-primary);
    background: var(--theme-surface-2, rgba(0,0,0,0.03));
    border-radius: 0 var(--theme-radius, 6px) var(--theme-radius, 6px) 0;
    font-size: 0.78rem;
}
.copilot-progress-line {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    color: var(--theme-text-muted, #555);
    line-height: 1.35;
}
.copilot-progress-line i {
    color: var(--theme-success, #198754);
    flex: 0 0 auto;
    margin-top: 0.1rem;
}
.copilot-progress-more {
    margin-top: 0.2rem;
    color: var(--theme-text-muted, #777);
    font-style: italic;
}

/* ── THE JUDGE — Harvey-ball task rating bar ────────────────────────────────
   Anchored inside the panel between the messages and the input box. One row
   per dimension, five tappable SVG Harvey glyphs each; auto-submits after the
   last tap; collapses to a "Rated" chip. All paint from --theme-* tokens.
   Spec: docs/internal/copilot-judge-harvey-flywheel-design-2026-07-04.md §2. */
.copilot-judge {
    padding: 0.5rem 1rem 0;
    flex-shrink: 0;
}

.harvey-bar {
    padding: 0.5rem 0.65rem 0.4rem;
    border: 1px solid var(--theme-border);
    border-radius: var(--theme-radius);
    background: var(--theme-background-raised, var(--theme-background-subtle));
    box-shadow: 0 -2px 10px color-mix(in srgb, var(--theme-text) 7%, transparent);
    animation: harvey-rise 180ms ease-out;
}

@keyframes harvey-rise {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.harvey-bar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.harvey-bar-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--theme-text-muted);
}

.harvey-bar-x {
    display: inline-flex;
    align-items: center;
    border: none;
    background: none;
    padding: 0;
    color: var(--theme-text-muted);
    cursor: pointer;
    line-height: 1;
    font-size: 1rem;
    opacity: 0.7;
}

.harvey-bar-x:hover {
    opacity: 1;
    color: var(--theme-text);
}

.harvey-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.1rem 0;
}

.harvey-row-label {
    font-size: 0.78rem;
    color: var(--theme-text);
    white-space: nowrap;
}

.harvey-glyphs {
    display: flex;
    align-items: center;
    gap: 0.15rem;
}

.harvey-glyph {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 120ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.harvey-glyph:hover {
    background: var(--theme-background-subtle);
}

.harvey-glyph:focus-visible {
    outline: 2px solid var(--theme-primary);
    outline-offset: 1px;
}

/* The glyph SVG paints: ring from the border token, pie fill muted until the
   glyph is the row's selection - then the theme accent + a 1.15x spring. An
   unrated row invites the tap with a dashed ring. */
.harvey-svg .harvey-ring {
    stroke: var(--theme-border);
}

.harvey-svg .harvey-fill {
    fill: color-mix(in srgb, var(--theme-text-muted) 55%, transparent);
}

.harvey-glyph.unset .harvey-ring {
    stroke-dasharray: 2.5 2;
}

.harvey-glyph.selected .harvey-ring {
    stroke: var(--theme-primary);
    stroke-dasharray: none;
}

.harvey-glyph.selected .harvey-fill {
    fill: var(--theme-primary);
}

.harvey-glyph.selected {
    transform: scale(1.15);
}

/* Siblings dim once the row has a selection. */
.harvey-glyph:not(.unset):not(.selected) {
    opacity: 0.45;
}

/* Collapsed "Rated" chip - same pill styling as the attachment chips. */
.harvey-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.55rem;
    border: 1px solid var(--theme-border);
    border-radius: 999px;
    background: var(--theme-background-subtle);
    color: var(--theme-text);
    font-size: 0.72rem;
    cursor: pointer;
    animation: harvey-rise 180ms ease-out;
}

.harvey-chip:hover {
    border-color: var(--theme-primary);
}

.harvey-chip i {
    color: var(--theme-success, #198754);
}

.harvey-chip-label {
    color: var(--theme-text-muted);
}

.harvey-chip-glyph {
    display: inline-flex;
    align-items: center;
}

.harvey-chip .harvey-svg .harvey-fill {
    fill: var(--theme-primary);
}

.harvey-chip .harvey-svg .harvey-ring {
    stroke: var(--theme-border);
}

@media (prefers-reduced-motion: reduce) {
    .harvey-bar,
    .harvey-chip {
        animation: none;
    }

    .harvey-glyph {
        transition: none;
    }
}

/* ── Tap-to-reply quick chips + real markdown tables (wave 14) ─────────── */

.copilot-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.15rem 0.75rem 0.6rem;
}

.copilot-quick-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    border: 1px solid var(--theme-primary);
    color: var(--theme-primary);
    background: var(--theme-surface);
    border-radius: 999px;
    padding: 0.25rem 0.8rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.copilot-quick-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.copilot-quick-chip:hover {
    background: var(--theme-primary);
    color: var(--theme-surface);
    transform: translateY(-1px);
}

.copilot-quick-chip i {
    font-size: 0.75rem;
}

.copilot-table-wrap {
    overflow-x: auto;
    margin: 0.4rem 0;
}

.copilot-table {
    border-collapse: collapse;
    font-size: 0.85rem;
    width: 100%;
}

.copilot-table th,
.copilot-table td {
    border: 1px solid var(--theme-border);
    padding: 0.3rem 0.5rem;
    text-align: left;
    vertical-align: top;
    color: var(--theme-text);
}

.copilot-table th {
    background: var(--theme-surface);
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .copilot-quick-chip {
        transition: none;
    }
}

/* Per-message tools (assistant bubbles): copy the deliverable / save as .md.
   Quiet by default, visible on bubble hover. */
.copilot-msg-tools {
    display: flex;
    gap: 0.25rem;
    justify-content: flex-end;
    margin-top: 0.3rem;
    opacity: 0;
    transition: opacity 120ms ease;
}

.copilot-msg:hover .copilot-msg-tools,
.copilot-msg:focus-within .copilot-msg-tools {
    opacity: 1;
}

.copilot-msg-tool {
    border: 1px solid var(--theme-border, #e5e7eb);
    background: var(--theme-surface, #ffffff);
    color: var(--theme-text-muted, #6b7280);
    border-radius: 6px;
    padding: 0.1rem 0.4rem;
    font-size: 0.8rem;
    cursor: pointer;
}

.copilot-msg-tool:hover {
    color: var(--theme-primary, #2563eb);
    border-color: var(--theme-primary, #2563eb);
}

/* The collapsed build narration above a final review. */
.copilot-narration {
    margin-bottom: 0.5rem;
}

.copilot-narration > summary {
    color: var(--theme-text-muted, #6b7280);
    font-size: 0.82rem;
}
