/* =================================================================
   THE HELP COPILOT PANEL (docs/claude/USER-GUIDES.md section 8) - the dock behind the rail's Help, the "?" dialog's Ask
   Help, a guide's Ask Help about this and the palette's Ask Help. Every class here is helpai-* and is owned by this file
   alone; every colour is a --wf-* / --theme-* token, so the panel follows the tenant's theme and dark mode. It docks on
   the right under the shell bar (--wf-dock-top, set on .wf-shell) above the Ask dock (1026) and below the shell's
   layers (1030); in the builder it docks under the builder's header; on a phone it is the whole screen.
   ================================================================= */
/* @tokens-only */

.helpai-dock {
    position: fixed;
    top: var(--wf-dock-top, 64px);
    right: 16px;
    bottom: 16px;
    z-index: 1027;
    display: flex;
    flex-direction: column;
    width: 420px;
    max-width: calc(100vw - 32px);
    overflow: hidden;
    border: 1px solid var(--wf-line);
    border-radius: var(--wf-radius-lg);
    background: var(--wf-card);
    box-shadow: var(--wf-elev-3);
    color: var(--theme-text);
    animation: helpai-in 200ms var(--wf-ease) both;
}

.helpai-dock.is-builder { top: 64px; }

@keyframes helpai-in {
    from { opacity: 0; transform: translateX(12px); }
    to { opacity: 1; transform: none; }
}

/* The head: the life-ring tile, Help and its kicker, then Start over / All guides / Close. */
.helpai-head {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--wf-space-3);
    padding: var(--wf-space-3) var(--wf-space-3) var(--wf-space-3) var(--wf-space-4);
    border-bottom: 1px solid var(--wf-line);
    background: var(--wf-brand-wash), var(--wf-card);
}

.helpai-head-icon {
    display: grid;
    flex: none;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--wf-radius-tile);
    background: var(--wf-primary-soft);
    color: var(--wf-primary-ink);
    font-size: 18px;
}

.helpai-head-text { flex: 1; min-width: 0; }

.helpai-kicker {
    margin: 0;
    color: var(--theme-text-muted);
    font-size: var(--wf-text-xs);
    font-weight: 600;
}

.helpai-title {
    margin: 0;
    color: var(--theme-text-emphasis);
    font-size: var(--wf-text-h3);
    font-weight: 650;
    line-height: 1.25;
}

.helpai-head-actions { display: flex; flex: none; align-items: center; gap: 2px; }

/* The guide the conversation is about. */
.helpai-context {
    display: flex;
    flex: none;
    align-items: center;
    gap: var(--wf-space-2);
    min-width: 0;
    padding: var(--wf-space-2) var(--wf-space-4);
    border-bottom: 1px solid var(--wf-line);
    background: var(--wf-sheet);
    color: var(--theme-text-muted);
    font-size: var(--wf-text-sm);
}

.helpai-context-label { flex: none; }

.helpai-context-link {
    overflow: hidden;
    color: var(--wf-primary-ink);
    font-weight: 600;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.helpai-context-link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* The conversation. */
.helpai-log {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: var(--wf-space-4);
    min-height: 0;
    padding: var(--wf-space-4);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.helpai-hello-text { margin: 0 0 var(--wf-space-3); color: var(--theme-text-secondary); line-height: 1.55; }

.helpai-suggestions { display: flex; flex-direction: column; gap: var(--wf-space-2); }

.helpai-suggestion {
    display: flex;
    align-items: center;
    gap: var(--wf-space-2);
    width: 100%;
    padding: var(--wf-space-2) var(--wf-space-3);
    border: 1px solid var(--wf-line);
    border-radius: var(--wf-radius-md);
    background: var(--wf-card);
    color: var(--theme-text);
    font-size: var(--wf-text-sm);
    text-align: left;
    cursor: pointer;
    transition: background-color var(--wf-motion), border-color var(--wf-motion);
}

.helpai-suggestion .bi { color: var(--wf-primary-ink); }
.helpai-suggestion:hover { border-color: var(--wf-line-strong); background: var(--wf-card-hover); }
.helpai-suggestion:focus-visible { outline: 2px solid var(--wf-primary-ink); outline-offset: 2px; }

/* A screen reader hears who speaks; the eye sees it from the shape. */
.helpai-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.helpai-ask {
    align-self: flex-end;
    max-width: 86%;
    padding: var(--wf-space-2) var(--wf-space-3);
    border-radius: var(--wf-radius-lg) var(--wf-radius-lg) var(--wf-radius-xs) var(--wf-radius-lg);
    background: var(--wf-primary-soft);
    color: var(--theme-text-emphasis);
}

.helpai-ask p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.helpai-answer { max-width: 100%; }

.helpai-answer.is-note .helpai-md {
    padding: var(--wf-space-3);
    border: 1px dashed var(--wf-line-strong);
    border-radius: var(--wf-radius-md);
    background: var(--wf-sheet);
}

/* The answer's words (Shared.Markdown, no pictures): a reading rhythm that fits a narrow dock. */
.helpai-md { color: var(--theme-text); font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.helpai-md > :first-child { margin-top: 0; }
.helpai-md > :last-child { margin-bottom: 0; }
.helpai-md p { margin: 0 0 var(--wf-space-2); }
.helpai-md h4,
.helpai-md h5,
.helpai-md h6 { margin: var(--wf-space-3) 0 var(--wf-space-1); color: var(--theme-text-emphasis); font-size: 14px; font-weight: 650; }
.helpai-md ol,
.helpai-md ul { margin: 0 0 var(--wf-space-2); padding-left: 1.3rem; }
.helpai-md li { margin: 2px 0; }
.helpai-md ol > li::marker { color: var(--wf-primary-ink); font-weight: 650; }
.helpai-md strong { color: var(--theme-text-emphasis); font-weight: 650; }
.helpai-md a { color: var(--wf-primary-ink); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.helpai-md code {
    padding: 0 .3em;
    border-radius: var(--wf-radius-xs);
    background: var(--wf-inset);
    font-size: .92em;
}
.helpai-md pre {
    margin: 0 0 var(--wf-space-2);
    padding: var(--wf-space-2) var(--wf-space-3);
    overflow-x: auto;
    border-radius: var(--wf-radius-sm);
    background: var(--wf-inset);
    font-size: 13px;
}
.helpai-md pre code { padding: 0; background: none; }
.helpai-md blockquote {
    margin: 0 0 var(--wf-space-2);
    padding: var(--wf-space-2) var(--wf-space-3);
    border-left: 3px solid var(--wf-primary-ink);
    border-radius: 0 var(--wf-radius-sm) var(--wf-radius-sm) 0;
    background: var(--wf-primary-soft);
}
.helpai-md table { display: block; max-width: 100%; margin: 0 0 var(--wf-space-2); overflow-x: auto; border-collapse: collapse; font-size: 13px; }
.helpai-md th,
.helpai-md td { padding: var(--wf-space-1) var(--wf-space-2); border: 1px solid var(--wf-line); text-align: left; }

/* THE HANDOFF - one card under the answer: who can do it, the request waiting for them, one button. */
.helpai-handoff {
    margin-top: var(--wf-space-3);
    padding: var(--wf-space-3);
    border: 1px solid var(--wf-line);
    border-radius: var(--wf-radius-md);
    background: var(--wf-sheet);
}

.helpai-handoff.is-latest { border-color: var(--wf-line-strong); box-shadow: var(--wf-elev-1); }

.helpai-handoff-lead {
    display: flex;
    align-items: flex-start;
    gap: var(--wf-space-2);
    margin: 0 0 var(--wf-space-2);
    color: var(--theme-text-emphasis);
    font-size: var(--wf-text-sm);
    font-weight: 600;
}

.helpai-handoff-lead .bi { color: var(--wf-accent-ink); }

.helpai-handoff-prompt {
    margin: 0 0 var(--wf-space-1);
    padding: var(--wf-space-2) var(--wf-space-3);
    border-left: 3px solid var(--wf-accent-ink);
    border-radius: 0 var(--wf-radius-sm) var(--wf-radius-sm) 0;
    background: var(--wf-accent-soft);
    color: var(--theme-text);
    font-size: var(--wf-text-sm);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.helpai-handoff-note { margin: 0 0 var(--wf-space-2); color: var(--theme-text-muted); font-size: var(--wf-text-xs); }

.helpai-handoff-go { display: inline-flex; align-items: center; gap: var(--wf-space-2); }

/* Reading the guides - three quiet dots. */
.helpai-busy { display: flex; align-items: center; gap: var(--wf-space-2); color: var(--theme-text-muted); font-size: var(--wf-text-sm); }
.helpai-dots { display: inline-flex; gap: 3px; }
.helpai-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--wf-primary-ink);
    animation: helpai-dot 1.1s var(--wf-ease) infinite;
}
.helpai-dots i:nth-child(2) { animation-delay: .15s; }
.helpai-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes helpai-dot {
    0%, 80%, 100% { opacity: .25; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

/* The box. */
.helpai-compose {
    display: flex;
    flex: none;
    align-items: flex-end;
    gap: var(--wf-space-2);
    padding: var(--wf-space-3) var(--wf-space-3) var(--wf-space-1);
    border-top: 1px solid var(--wf-line);
}

.helpai-input {
    flex: 1;
    min-height: 44px;
    max-height: 160px;
    padding: var(--wf-space-2) var(--wf-space-3);
    border: 1px solid var(--wf-line-strong);
    border-radius: var(--wf-radius-md);
    background: var(--wf-card);
    color: var(--theme-text);
    font: inherit;
    font-size: 14px;
    line-height: 1.45;
    resize: none;
}

.helpai-input:focus { border-color: var(--wf-primary-ink); outline: none; box-shadow: 0 0 0 3px var(--wf-primary-soft); }

.helpai-send {
    display: grid;
    flex: none;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: var(--wf-radius-pill);
    background: var(--theme-primary);
    color: var(--theme-text-on-primary);
    font-size: 17px;
    cursor: pointer;
}

.helpai-send:disabled { opacity: .45; cursor: default; }
.helpai-send:focus-visible { outline: 2px solid var(--wf-primary-ink); outline-offset: 2px; }

.helpai-foot {
    flex: none;
    margin: 0;
    padding: var(--wf-space-1) var(--wf-space-4) var(--wf-space-3);
    color: var(--theme-text-muted);
    font-size: var(--wf-text-xs);
}

/* Phone: the whole screen. */
@media (max-width: 767.98px) {
    .helpai-dock,
    .helpai-dock.is-builder {
        inset: 0;
        width: auto;
        max-width: none;
        border: 0;
        border-radius: 0;
        z-index: 1045;
    }
    .helpai-md { font-size: 15px; }
    .helpai-input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
    .helpai-dock { animation: none; }
    .helpai-dots i { animation: none; opacity: .7; }
    .helpai-suggestion { transition: none; }
}

/* @end-tokens-only */
