/* ================================================================
   Agent widget — floating bubble + expandable panel.
   Loaded on role/flow pages (not the home page S8 embed).
   ================================================================ */

.agent-widget-shell {
    position: fixed;
    right: 24px;
    bottom: 24px;
    /* F-21 (2026-05-21): bumped z-index above modal/lightbox layers so the
       widget never gets occluded by hub video overlays, scrim layers, or
       any future hero treatment that wants to paint over the page. */
    z-index: 9000;
    font-family: var(--font-sans, system-ui, -apple-system, Segoe UI, Roboto, sans-serif);
}

/* F-25 (2026-05-30): circular agent-portrait launcher. Big avatar, a
   pulsing "live" ring + a mic badge (voice cue), and the role name only on
   hover — no permanent "Talk to {Role} Agent" text. */
.agent-widget-launch {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 92px;
    height: 92px;
    padding: 0;
    background: #0a0a1a;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.28);
    cursor: pointer;
    line-height: 1;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.agent-widget-launch:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.34);
}

/* Pulsing "live / tap to talk" ring around the circle. */
.agent-widget-launch-ring {
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid rgba(81, 161, 255, 0.55);
    pointer-events: none;
    animation: agent-widget-ring 2.4s ease-out infinite;
}

@keyframes agent-widget-ring {
    0%   { transform: scale(1);    opacity: 0.7; }
    70%  { transform: scale(1.18); opacity: 0; }
    100% { transform: scale(1.18); opacity: 0; }
}

/* Legacy fallback when no avatar is provided. */
.agent-widget-launch-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #27c093;
    box-shadow: 0 0 0 0 rgba(39, 192, 147, 0.6);
    animation: agent-widget-pulse 2.2s ease-out infinite;
}

@keyframes agent-widget-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(39, 192, 147, 0.55); }
    70%  { box-shadow: 0 0 0 10px rgba(39, 192, 147, 0); }
    100% { box-shadow: 0 0 0 0 rgba(39, 192, 147, 0); }
}

/* The agent portrait fills the circle. */
.agent-widget-launch-avatar {
    width: 84px;
    height: 84px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

/* Mic badge — bottom-right of the circle, signals you can talk/hear it. */
.agent-widget-launch-mic {
    position: absolute;
    right: -1px;
    bottom: -1px;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #50d5ff, #acb9ff);
    color: #0a0a1a;
    border: 2px solid #0a0a1a;
}

@media (prefers-reduced-motion: reduce) {
    .agent-widget-launch-ring,
    .agent-widget-launch-dot {
        animation: none;
    }
}

.agent-widget-shell.is-open .agent-widget-launch {
    display: none;
}

/* F-29 (2026-05-30): "Talk or Type" chooser. The panel opens in `.is-choosing`
   (set in buildPanel); the conversation UI is hidden until the visitor picks a
   mode, at which point JS removes `is-choosing`. */
.agent-box-widget.is-choosing .agent-conversation {
    display: none;
}
.agent-box-widget:not(.is-choosing) .agent-mode-chooser {
    display: none;
}
/* F-29: the wrapper takes over the flex-column role `.agent-box-widget` used to
   play directly, so the transcript still flexes to fill and the text input stays
   pinned to the bottom of the chat area. */
.agent-conversation {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
/* F-29: once the visitor picks "Type" (or falls back to text after a denied
   mic), there is no "talk" option — hide the mic control + the voice
   visualizer canvas so the panel reads as a clean text chat. */
.agent-box-widget.is-text-only .agent-controls,
.agent-box-widget.is-text-only #visualizer {
    display: none;
}

/* F-29: breathing room + a subtle separator above the input row so the
   transcript text doesn't butt right up against the input + Send. */
.agent-box-widget .agent-text-input {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* F-29: nicer Send — a brand-gradient icon button (paper-plane) instead of
   the plain text button. Stretches to match the input height. */
.agent-box-widget .text-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    padding: 0;
    flex-shrink: 0;
    background: linear-gradient(135deg, #50d5ff, #acb9ff);
    color: #0a0a1a;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.15s ease;
}
.agent-box-widget .text-send-btn:hover {
    filter: brightness(1.06);
    transform: translateY(-1px);
    background: linear-gradient(135deg, #50d5ff, #acb9ff);
}
.agent-box-widget .text-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}
.agent-box-widget .text-send-btn svg { display: block; }

/* F-29: connecting spinner — replaces the "Connecting..." status text. */
.agent-spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(255, 255, 255, 0.18);
    border-top-color: #51a1ff;
    border-radius: 50%;
    animation: agent-spin 0.7s linear infinite;
    vertical-align: middle;
}
@keyframes agent-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .agent-spinner { animation: none; }
}
.agent-mode-chooser {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 48px 24px;
    text-align: center;
}
.agent-mode-prompt {
    margin: 0;
    color: #fff;
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}
.agent-mode-buttons {
    display: flex;
    gap: 14px;
}
.agent-mode-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 116px;
    padding: 20px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 14px;
    color: #fff;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}
.agent-mode-btn:hover,
.agent-mode-btn:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.32);
    transform: translateY(-1px);
    outline: none;
}
.agent-mode-btn svg {
    width: 26px;
    height: 26px;
}
/* Talk gets a subtle brand accent so the voice path reads as the lead option. */
.agent-mode-talk {
    border-color: rgba(81, 161, 255, 0.4);
}
.agent-mode-talk:hover,
.agent-mode-talk:focus-visible {
    border-color: rgba(81, 161, 255, 0.7);
}

.agent-widget-panel {
    position: absolute;
    right: 0;
    bottom: 0;
    /* F-21 (2026-05-21): nudged width 360→380 so the avatar + name + tagline
       header no longer ellipses on common hub agents whose taglines run
       slightly long ("AI Operator for Engineering teams", etc.). */
    width: 380px;
    max-width: calc(100vw - 32px);
    /* F-21: dropped the panel max-height to leave room for the launcher
       below it and ~16px of breathing room above the viewport top so the
       panel doesn't feel slammed against the OS chrome on Safari. */
    max-height: calc(100vh - 64px);
    background: #0a0a1a;
    color: #e8e8f0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.agent-widget-panel[hidden] {
    display: none !important;
}

.agent-widget-panel-head {
    display: flex;
    align-items: center;
    gap: 12px;
    /* F-21 (2026-05-21): a touch more horizontal padding so the close
       button sits clear of the panel's rounded corner and the head's
       three flex children (avatar, identity, close) breathe. */
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.02);
}

.agent-widget-panel-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    flex-shrink: 0;
}

.agent-widget-panel-identity {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.agent-widget-panel-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-widget-panel-tagline {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.02em;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Legacy selector kept for any third-party reference; no longer rendered
   by the widget. Safe to remove once we confirm nothing externally hooks it. */
.agent-widget-panel-title {
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.7);
}

.agent-widget-close {
    background: transparent;
    border: 0;
    color: rgba(255, 255, 255, 0.55);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    /* F-21 (2026-05-21): grew the hit target to 36×36 so the close
       affordance survives Fitts's law on touch + small mice. */
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s ease, color 0.15s ease;
}

.agent-widget-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.06);
}

.agent-widget-close:focus-visible {
    outline: 2px solid rgba(151, 199, 255, 0.6);
    outline-offset: 2px;
}

/* Panel content uses the shared agent CSS rules (agent.css) inside
   the .agent-box wrapper. A few overrides tighten things for the
   narrower bubble panel. */

.agent-box-widget {
    /* F-21 (2026-05-22): flex column with `flex: 1; min-height: 0;` so the
       box fills the panel below the head, and the transcript-area child
       below stretches to absorb extra space. Without this, content packed
       from the top and the text-input bar floated mid-panel whenever the
       conversation was short. */
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 16px 16px 20px;
    gap: 14px;
}

.agent-box-widget #visualizer {
    width: 160px;
    height: 160px;
}

.agent-box-widget .agent-status {
    font-size: 0.82rem;
}

.agent-box-widget .mic-btn {
    width: 56px;
    height: 56px;
}

.agent-box-widget .agent-transcript-area {
    /* F-21 (2026-05-22): was `max-height: 180px` — became a flex child that
       fills the space between the mic controls (above) and the text input
       (below). The transcript still scrolls internally when it overflows
       (overflow-y: auto is inherited from agent.css). Result: text input
       always sits at the bottom of the panel; transcript grows to fill. */
    flex: 1;
    min-height: 0;
    max-height: none;
}

.agent-box-widget .transcript-text {
    font-size: 0.82rem;
}

@media (max-width: 480px) {
    .agent-widget-shell {
        right: 12px;
        bottom: 12px;
    }
    .agent-widget-panel {
        width: calc(100vw - 24px);
        /* F-21 (2026-05-21): on phones, account for the bottom UI bar
           (iOS Safari especially) so the panel doesn't reserve more
           height than the visible viewport. dvh = dynamic viewport
           height — collapses to the real visible area in Safari. */
        max-height: calc(100dvh - 80px);
    }
    .agent-box-widget #visualizer {
        width: 140px;
        height: 140px;
    }
    .agent-widget-launch-label {
        display: none;
    }
    .agent-widget-launch {
        padding: 14px;
    }
}
