/* ─────────────────────────────────────────────────────────────────────────
   Forge help concierge widget
   ─────────────────────────────────────────────────────────────────────────
   Footer-anchored tab that opens a chat panel above the footer. The tab
   (`.forge-help-tab`) lives inline in the footer flex flow, styled to sit
   alongside `.conn-status-trigger` so the two read as a single status / help
   cluster at the bottom-right.

   Panel visual language mirrors the workspace step chat (`.ws-msg-*`,
   `.ws-chat-input-box`) so the two surfaces feel like the same product.
   Tokens come from site.css.

   Open/close animation: panel grows up from the footer tab on open and
   shrinks back down to it on close, anchored via `transform-origin: bottom right`.

   Name-agnostic — the bot's display name lives in the persona markdown file,
   not in any class name or rule here. CSS prefix is `forge-help-`.
   ───────────────────────────────────────────────────────────────────────── */

#forge-help-widget {
    /* Container for the panel only — the trigger (footer tab for signed-in,
       floating FAB for anonymous) is rendered separately by either
       _ForgeHelpTab.cshtml or _PublicHelpFab.cshtml. */
    position: relative;
}

/* ── Public-bot floating action button ─────────────────────────────────────
   Anonymous-visitor surface. Floats above the footer at bottom-right like a
   classic site chat avatar. Signed-in users get the inline `.forge-help-tab`
   below instead. Both share `#forge-help-toggle` so the JS bindings are
   identical; only one renders per page. */

.forge-help-fab {
    position: fixed;
    /* Floats above the footer with a comfortable gap. Right inset matches the
       footer's right padding so the FAB and the panel both sit on the same
       16px gutter when the panel opens above the FAB. */
    bottom: calc(var(--footer-height) + 16px);
    right: 16px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 1px solid var(--accent-blue-dim);
    background: var(--accent-blue);
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Sits just below the panel's base z-index (1001) so the panel always
       overlays the FAB when open. */
    z-index: 1000;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35), 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
}

.forge-help-fab:hover {
    background: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4), 0 3px 6px rgba(0, 0, 0, 0.25);
}

.forge-help-fab:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 2px;
}

/* Open state — subtle press effect so the user has a clear "the panel is
   showing" cue while the panel is overlaid. */
.forge-help-fab[aria-expanded="true"] {
    background: var(--accent-light);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3) inset;
    transform: translateY(0);
}

.forge-help-fab svg { flex-shrink: 0; }

/* ── Footer tab (signed-in surface) ─────────────────────────────────────── */

.forge-help-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 2px 10px;
    margin-left: 12px;            /* matches `.conn-status` left-margin for consistent spacing */
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color var(--transition), color var(--transition), background var(--transition);
}

.forge-help-tab:hover {
    border-color: var(--accent-blue-dim);
    color: var(--text-primary);
}

.forge-help-tab:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 1px;
}

/* Pressed / open state — gives the user a clear "the panel is showing" cue. */
.forge-help-tab[aria-expanded="true"] {
    border-color: var(--accent-blue-dim);
    color: var(--accent-light);
    background: var(--accent-glow, rgba(77, 142, 247, 0.1));
}

.forge-help-tab svg {
    flex-shrink: 0;
}

/* ── Panel ─────────────────────────────────────────────────────────────── */

.forge-help-panel {
    position: fixed;
    /* Sits directly above the footer's top edge, with a 4px gap so the panel
       doesn't visually touch the footer border. Right edge inset matches the
       footer's 16px right padding so the panel aligns under the Help tab. */
    bottom: calc(var(--footer-height) + 4px);
    right: 16px;
    /* 360×480 — width unchanged from prior iteration; compact help surface,
       not a full chat window. */
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 480px;
    max-height: calc(100vh - var(--footer-height) - 24px);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 4px 12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1001;
    font-family: var(--font-sans);
    color: var(--text-primary);
    /* Anchor at bottom-right so the open/close scale animations grow from
       and shrink to the footer tab's location. */
    transform-origin: bottom right;
    animation: forge-help-open 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* Closing state — applied by JS just before hiding the panel. The animationend
   listener removes the class and sets `hidden`. */
.forge-help-panel.closing {
    animation: forge-help-close 260ms cubic-bezier(0.4, 0, 0.6, 1);
}

/* Pronounced grow / shrink so the panel visibly emerges from (and collapses into)
   the footer tab. 40px translate + 0.7 → 1 scale produces a clearly readable motion
   even on a quick toggle. */
@keyframes forge-help-open {
    from { opacity: 0; transform: translateY(40px) scale(0.7); }
    to   { opacity: 1; transform: translateY(0)    scale(1);   }
}

@keyframes forge-help-close {
    from { opacity: 1; transform: translateY(0)    scale(1);   }
    to   { opacity: 0; transform: translateY(40px) scale(0.7); }
}

/* ── Panel header ──────────────────────────────────────────────────────── */

.forge-help-panel-header {
    padding: 12px 14px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.forge-help-panel-identity {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.forge-help-panel-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-glow-strong, rgba(77, 142, 247, 0.2));
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.forge-help-panel-titlewrap {
    min-width: 0;
}

.forge-help-panel-title {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
    line-height: 1.2;
}

.forge-help-panel-subtitle {
    font-size: 11px;
    color: var(--text-muted);
    margin: 2px 0 0;
    line-height: 1;
}

.forge-help-panel-actions {
    display: flex;
    gap: 4px;
}

.forge-help-iconbtn {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
}

.forge-help-iconbtn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.forge-help-iconbtn:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 1px;
}

/* ── Messages area ─────────────────────────────────────────────────────── */

.forge-help-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 14px 4px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
    background: var(--bg-deep);
}

.forge-help-messages::-webkit-scrollbar { width: 4px; }
.forge-help-messages::-webkit-scrollbar-track { background: transparent; }
.forge-help-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.forge-help-messages::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }

/* ── Message rows — mirror .ws-msg flat row layout (avatar + body) ─────── */

.forge-help-msg {
    display: flex;
    gap: 8px;
    max-width: 100%;
    animation: forge-help-msg-in 0.25s ease-out;
}

@keyframes forge-help-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0);    }
}

.forge-help-msg-avatar {
    width: 22px;
    height: 22px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}

.forge-help-msg-avatar.user {
    background: var(--accent-glow-strong, rgba(77, 142, 247, 0.2));
    color: var(--accent-blue);
    border: 1px solid var(--accent-blue-dim);
}

.forge-help-msg-avatar.forge {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.forge-help-msg-body {
    flex: 1;
    min-width: 0;
}

.forge-help-msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
}

.forge-help-msg-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-primary);
}

.forge-help-msg-text {
    font-size: 13px;
    line-height: 1.55;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Rendered-Markdown elements inside bot replies — mirror .ws-msg-text rules so the
   formatting language is consistent between workspace chat and help chat. */
.forge-help-msg-text strong { color: var(--text-primary); font-weight: 600; }
.forge-help-msg-text code {
    font-family: var(--font-mono);
    font-size: 11.5px;
    padding: 1px 5px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--accent-light);
}
.forge-help-msg-text pre {
    font-family: var(--font-mono);
    font-size: 11.5px;
    padding: 8px 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    overflow-x: auto;
    margin: 6px 0;
}
.forge-help-msg-text pre code {
    padding: 0;
    background: none;
    border: none;
    color: inherit;
}
.forge-help-msg-text a {
    color: var(--accent-light);
    text-decoration: underline;
}
.forge-help-msg-text ul,
.forge-help-msg-text ol {
    padding-left: 18px;
    margin: 4px 0 8px;
}
.forge-help-msg-text li { margin: 2px 0; }

/* Streaming indicator — three horizontal dots that bounce on a staggered loop while
   the bot is "thinking" (i.e., the SSE stream has opened but no content has arrived
   yet). Each dot animates the same keyframe with a 0.16s offset so the bounce ripples
   left-to-right. Injected into the message text element by renderBotShell() in
   forge-help.js and wiped automatically on the first 'content' frame. */
.forge-help-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 1.55em;             /* matches `.forge-help-msg-text` line-height */
    padding: 0 2px;
}

.forge-help-dots > span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-light);
    opacity: 0.4;
    animation: forge-help-dot-bounce 1.2s ease-in-out infinite;
}

.forge-help-dots > span:nth-child(2) { animation-delay: 0.16s; }
.forge-help-dots > span:nth-child(3) { animation-delay: 0.32s; }

@keyframes forge-help-dot-bounce {
    0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
    30%           { transform: translateY(-6px); opacity: 1;   }
}

/* Error variant — bot row with a tinted text block. */
.forge-help-msg.bot.error .forge-help-msg-text {
    color: var(--danger);
    font-style: italic;
}

/* ── Greeting + suggested-question chips ───────────────────────────────── */

.forge-help-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 4px 0 6px;
    justify-content: center;
}

.forge-help-chip {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 11.5px;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
    font-family: inherit;
}

.forge-help-chip:hover {
    background: var(--bg-hover);
    border-color: var(--accent-blue-dim);
    color: var(--text-primary);
}

.forge-help-chip:focus-visible {
    outline: 2px solid var(--accent-light);
    outline-offset: 1px;
}

/* ── Composer — mirrors .ws-chat-input-box ─────────────────────────────── */

.forge-help-composer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-primary);
}

.forge-help-composer-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 10px;
    transition: border-color var(--transition);
}

.forge-help-composer-box:focus-within {
    border-color: var(--accent-blue-dim);
}

.forge-help-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
    resize: none;
    max-height: 100px;
    min-height: 20px;
    overflow-y: auto;
}

.forge-help-input::placeholder { color: var(--text-muted); }

.forge-help-send {
    width: 26px;
    height: 26px;
    border-radius: var(--radius-sm);
    background: var(--accent-blue);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all var(--transition);
}

.forge-help-send:hover:not(:disabled) { background: var(--accent-light); }
.forge-help-send:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 1px; }
.forge-help-send:disabled {
    opacity: 0.4;
    cursor: default;
}
.forge-help-send svg { width: 13px; height: 13px; }

.forge-help-hint {
    font-size: 10.5px;
    color: var(--text-muted);
    margin: 6px 2px 0;
    line-height: 1.2;
    font-family: var(--font-mono);
}

/* Accessibility-only label helper. */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Mobile responsive ─────────────────────────────────────────────────── */

@media (max-width: 640px) {
    /* Tab stays in the footer (just slightly tighter spacing); panel goes full-screen. */
    .forge-help-tab { margin-left: 8px; padding: 2px 8px; }

    /* Slightly smaller FAB on mobile to free up bottom-right thumb area, kept above
       the footer with the same 16px gap. */
    .forge-help-fab {
        width: 44px;
        height: 44px;
        right: 12px;
        bottom: calc(var(--footer-height) + 12px);
    }
    /* When the panel goes full-screen, the FAB would otherwise sit on top of it.
       Hide it while open — the panel has its own minimize button. */
    .forge-help-fab[aria-expanded="true"] { display: none; }

    .forge-help-panel {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
        transform-origin: bottom center;
    }
}

/* ── Prefers-reduced-motion ────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .forge-help-panel,
    .forge-help-panel.closing { animation: none; }
    /* Static dots — drop the bounce but keep them fully visible so users still get
       a "still responding" cue without the motion. */
    .forge-help-dots > span {
        animation: none;
        opacity: 0.8;
    }
    .forge-help-msg { animation: none; }
}
