/* Wanda chat. Closed by default: the host stays hidden and empty until the
   owner opens it from a Wanda button, a question toast, or a control. */
#wanda-chat-host[hidden] {
    display: none;
}

.wanda-chat {
    position: fixed;
    z-index: 55;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 32px));
    max-height: min(560px, calc(100dvh - 32px - env(safe-area-inset-bottom)));
    animation: wanda-chat-expand 180ms cubic-bezier(0.16, 1, 0.3, 1);
    border: 2px solid var(--wanda-iris, #4c91b0);
    border-radius: var(--button-radius);
    background: var(--canvas);
    box-shadow: 0 12px 32px color-mix(in srgb, var(--scrim) 18%, transparent);
}

.wanda-chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}

.wanda-chat-title {
    display: flex;
    align-items: baseline;
    gap: 8px;
    min-width: 0;
}

.wanda-chat-eye {
    display: block;
    flex-shrink: 0;
    width: 46px;
    height: 32px;
}
.wanda-chat-eye .wanda-eye { width: 46px; height: 32px; }
.wanda-chat-name {
    flex-shrink: 0;
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--ink);
}

.wanda-chat-context {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--muted);
}

.wanda-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: var(--button-height);
    height: var(--button-height);
    border: 0;
    border-radius: var(--control-radius);
    background: none;
    color: var(--muted);
    cursor: pointer;
}

.wanda-icon-button:hover {
    background: var(--hover);
    color: var(--ink);
}

.wanda-chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
}

.wanda-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.wanda-chat-message {
    max-width: 85%;
    padding: 8px 10px;
    border-radius: var(--control-radius);
    font-size: 13px;
    overflow-wrap: anywhere;
}

/* Keep these bubble pairings in both appearances. Wanda follows her iris. */
.wanda-chat-user {
    align-self: flex-end;
    background: #f0f0f0;
    color: #242424;
}

.wanda-chat-assistant {
    align-self: flex-start;
    background: var(--wanda-iris, #4c91b0);
    color: #fff;
}

.wanda-chat-text {
    margin: 0;
}

.wanda-chat-text > :first-child { margin-top: 0; }
.wanda-chat-text > :last-child { margin-bottom: 0; }
.wanda-chat-text p { margin-block: 0 0.8em; }
.wanda-chat-text :is(ul, ol) { margin-block: 0.8em; padding-inline-start: 1.4em; }
.wanda-chat-text ul { list-style-type: disc; }
.wanda-chat-text ol { list-style-type: decimal; }
.wanda-chat-text li + li { margin-top: 0.3em; }
.wanda-chat-text pre { white-space: pre-wrap; }
.wanda-chat-text a[href] {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}
.wanda-chat-text a[href]:hover { text-decoration-thickness: 2px; }
.wanda-chat-text a[href]:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    border-radius: 2px;
}

.wanda-chat-empty {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.wanda-chat-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    padding: 12px;
    border-top: 1px solid var(--line);
}

@media (pointer: coarse) {
    .wanda-icon-button {
        width: var(--touch-target);
        height: var(--touch-target);
    }
}

/* The toast stack and the chat panel both live bottom-right, so while chat
   is open the stack moves aside rather than covering the panel's controls. */
@media (min-width: 900px) {
    body.wanda-chat-open .toast-stack {
        right: calc(min(400px, calc(100vw - 32px)) + 32px);
    }
}

@media (max-width: 899px) {
    body.wanda-chat-open .toast-stack {
        bottom: calc(min(560px, calc(100dvh - 32px)) + 28px);
    }
}

.wanda-chat-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.wanda-chat-failure { background: var(--danger-bg); color: var(--ink); }
.wanda-chat-failure > .wanda-chat-text { color: var(--danger); }
.wanda-error-details { margin-top: 8px; }
.wanda-error-details > summary { display: flex; align-items: center; gap: 6px; width: fit-content; min-height: var(--button-height); padding: 6px 10px; border-radius: var(--control-radius); font-size: 13px; cursor: pointer; list-style: none; }
.wanda-error-details > summary::-webkit-details-marker { display: none; }
.wanda-error-details > summary:hover { background: var(--hover); }
.wanda-error-details > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.wanda-error-details[open] > summary svg { transform: rotate(90deg); }
.wanda-error-details > pre { margin-top: 8px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (pointer: coarse) { .wanda-error-details > summary { min-height: var(--touch-target); } }

/* Ask Wanda. Icon-only, named for assistive technology rather than spelled
   out in the chrome, and sized to the AMMO control metrics. */
.wanda-ask {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    /* A note row makes the whole row clickable with an ::after overlay at
       z-index 1, which would otherwise swallow every click on this control. */
    z-index: 2;
    width: var(--button-height);
    height: var(--button-height);
    padding: 0;
    border: 1px solid var(--control-border);
    border-radius: var(--button-radius);
    background: var(--canvas);
    color: var(--ink);
    cursor: pointer;
}

.wanda-ask:hover:not(:disabled) {
    border-color: var(--primary-fill);
    color: var(--primary-fill);
}

.wanda-ask:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wanda-ask-small {
    width: 24px;
    height: 24px;
    border-radius: var(--control-radius);
}

@media (pointer: coarse) {
    .wanda-ask {
        min-width: var(--touch-target);
        min-height: var(--touch-target);
    }
}

/* Text buttons inside the chat panel. */
.wanda-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-shrink: 0;
    min-height: var(--button-height);
    padding: 6px 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--button-radius);
    background: var(--canvas);
    color: var(--ink);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
}

.wanda-button[hidden] { display: none; }

.wanda-button:hover:not(:disabled) {
    border-color: var(--primary-fill);
    color: var(--primary-fill);
}

.wanda-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.wanda-button-small {
    padding: 4px 8px;
    font-size: 11px;
}

@media (pointer: coarse) {
    .wanda-button {
        min-height: var(--touch-target);
    }
}

/* The chat composer's field. */
.wanda-chat-input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--control-border);
    border-radius: var(--control-radius);
    background: var(--control-bg);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
    resize: none;
}

@media (pointer: coarse) {
    .wanda-chat-input {
        font-size: 16px;
    }
}

.wanda-open-asks {
    border-bottom: 1px solid var(--line);
    padding-bottom: 16px;
}
.wanda-open-asks > ul {
    max-height: 360px;
    overflow-y: auto;
    padding: 4px;
}

/* Her small corner seat stays separate from the hours and the work itself. */
.wanda-companion {
    position: fixed;
    z-index: 54;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 32px);
}
/* Invisible padding keeps the eye easy to click and drag without a shell. */
.wanda-companion-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 74px;
    min-height: 56px;
    max-width: 100%;
    padding: 7px 6px;
    border: 0;
    border-radius: var(--control-radius);
    background: transparent;
    color: var(--ink);
    font: inherit;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.wanda-companion-button.wanda-buddy-dragging { cursor: grabbing; }
.wanda-companion-button:focus-visible,
.wanda-ask:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}
/* The fixed eye contour holds visible lids around a moving aperture. Only
   the lids and their attached lashes move; the iris is never stretched. */
.wanda-eye {
    --wanda-iris: #4c91b0;
    position: relative;
    display: block;
    flex-shrink: 0;
    width: 62px;
    height: 42px;
    color: var(--ink);
}
.wanda-eye-drawing { display: block; width: 100%; height: 100%; overflow: visible; }
.wanda-eye-attention {
    position: absolute;
    right: -2px;
    bottom: 0;
    display: none;
    width: 16px;
    height: 16px;
    color: var(--warning);
    pointer-events: none;
}
.wanda-eye-attention svg { display: block; width: 100%; height: 100%; }
.wanda-eye[data-needs-user="true"] .wanda-eye-attention { display: block; }
.wanda-chat-eye .wanda-eye-attention { width: 14px; height: 14px; bottom: -1px; }
/* Lift only the drawing: her click/drag target and saved position stay put. */
.wanda-eye {
    --wanda-attention-rise: -6px;
    --wanda-attention-settle: -2px;
}
.wanda-chat-eye .wanda-eye {
    --wanda-attention-rise: -3px;
    --wanda-attention-settle: -1px;
}
.wanda-eye[data-expression="needs-user"] .wanda-eye-drawing {
    animation: wanda-needs-user-hop 1640ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes wanda-needs-user-hop {
    0%, 38%, 86%, 100% { transform: translateY(0); }
    14% { transform: translateY(var(--wanda-attention-rise)); }
    58% { transform: translateY(var(--wanda-attention-settle)); }
}
.wanda-pane-moving .wanda-eye-drawing,
.wanda-buddy-dragging .wanda-eye-drawing { animation: none; }
@media (prefers-reduced-motion: reduce) {
    .wanda-eye[data-expression="needs-user"] .wanda-eye-drawing { animation: none; }
}

.wanda-eye-skin { fill: color-mix(in srgb, var(--surface) 65%, var(--wanda-iris)); }
.wanda-eye-white { fill: #fffdf7; }
.wanda-eye-outline { stroke: currentColor; stroke-width: 0.7; stroke-linejoin: round; }
.wanda-eye-lid-rim { stroke: currentColor; stroke-opacity: 0.65; stroke-width: 0.6; stroke-linejoin: round; }
.wanda-eye-lashes { fill: currentColor; }
.wanda-eye-iris {
    transform: translate(var(--wanda-gaze-x, 0px), var(--wanda-gaze-y, 0px));
    transition: transform 100ms cubic-bezier(0.16, 1, 0.3, 1);
}
.wanda-eye-colour { fill: var(--wanda-iris); }
.wanda-eye-pupil { fill: #111820; }
.wanda-eye-glint { fill: #fff; }
.wanda-eye-palette[hidden],
[data-wanda-companion-status][hidden] { display: none; }
.wanda-eye-palette {
    position: fixed;
    z-index: 56;
    width: 206px;
    padding: 12px;
    border: 1px solid var(--control-border);
    border-radius: var(--button-radius);
    background: var(--canvas);
    color: var(--ink);
}
.wanda-eye-palette-label { display: block; margin-bottom: 8px; font-size: 13px; font-weight: 600; }
.wanda-eye-swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.wanda-eye-swatch {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: var(--control-radius);
    background: none;
    cursor: pointer;
}
.wanda-eye-swatch::before {
    content: "";
    width: 24px;
    height: 24px;
    border: 2px solid color-mix(in srgb, var(--swatch), #111820 40%);
    border-radius: 50%;
    background: var(--swatch);
}
.wanda-eye-swatch:hover { background: var(--hover); }
.wanda-eye-swatch[aria-pressed="true"] { border-color: var(--ink); }
.wanda-eye-swatch:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
@media (prefers-reduced-motion: reduce) {
    .wanda-eye-iris { transition: none; transform: none; }
}
body:has(.wanda-companion) .wanda-shell > footer { padding-bottom: 96px; }
body:has(.wanda-companion) .toast-stack { bottom: 88px; }
/* One corner presence: opening chat replaces the buddy at the same anchor. */
body.wanda-chat-open .wanda-companion { display: none; }
/* Navigation restores the pane without another expand gesture or buddy flash. */
body.wanda-chat-restoring .wanda-companion { visibility: hidden; }
#wanda-chat-host[data-wanda-restored] .wanda-chat { animation: none; }
@keyframes wanda-chat-expand {
    from {
        clip-path: inset(
            var(--wanda-buddy-top, calc(100% - var(--wanda-buddy-height, 56px)))
            var(--wanda-buddy-right, 0px)
            var(--wanda-buddy-bottom, 0px)
            var(--wanda-buddy-left, calc(100% - var(--wanda-buddy-width, 74px))) round 28px
        );
    }
    to { clip-path: inset(0 round var(--button-radius)); }
}
@media (max-width: 899px) {
    body.wanda-chat-open:has(.wanda-companion) .toast-stack {
        bottom: auto;
        top: 80px;
    }
}
@media (prefers-reduced-motion: reduce) {
    .wanda-chat {
        animation: none;
    }
}


/* The header moves the pane; its entire border resizes it. */
.wanda-chat-head,
.wanda-chat-form { flex-shrink: 0; }
.wanda-chat-title {
    flex: 1;
    align-items: center;
    align-self: stretch;
    border: 0;
    border-radius: var(--control-radius);
    padding: 0;
    background: none;
    color: inherit;
    text-align: left;
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.wanda-chat-title:focus-visible,
.wanda-icon-button:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}
/* Pointer focus stays quiet during and after a drag; keys restore the ring. */
.wanda-pane-moving .wanda-chat-title,
.wanda-pane-pointer-focus .wanda-chat-title { outline: none; }
.wanda-pane-moving,
.wanda-pane-moving * {
    user-select: none;
    cursor: var(--wanda-pane-cursor);
}
/* Invisible hit areas straddle the border, leaving the chat controls clear. */
.wanda-pane-edge,
.wanda-pane-corner {
    position: absolute;
    touch-action: none;
}
.wanda-pane-edge { z-index: 1; }
.wanda-pane-corner { z-index: 2; width: 18px; height: 18px; }
[data-wanda-resize="n"],
[data-wanda-resize="s"] { left: 12px; right: 12px; height: 10px; cursor: ns-resize; }
[data-wanda-resize="e"],
[data-wanda-resize="w"] { top: 12px; bottom: 12px; width: 10px; cursor: ew-resize; }
[data-wanda-resize="n"] { top: -5px; }
[data-wanda-resize="s"] { bottom: -5px; }
[data-wanda-resize="e"] { right: -5px; }
[data-wanda-resize="w"] { left: -5px; }
[data-wanda-resize="nw"] { top: -5px; left: -5px; cursor: nwse-resize; }
[data-wanda-resize="ne"] { top: -5px; right: -5px; cursor: nesw-resize; }
[data-wanda-resize="sw"] { bottom: -5px; left: -5px; cursor: nesw-resize; }
[data-wanda-resize="se"] { bottom: -5px; right: -5px; cursor: nwse-resize; }

/* Status travels with the single eye, from the corner into the chat header. */
.wanda-eye-working,
.wanda-eye-replying,
.wanda-eye-asks {
    position: absolute;
    right: -3px;
    bottom: -2px;
    display: none;
    align-items: center;
    justify-content: center;
    height: 18px;
    min-width: 18px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--canvas);
    color: var(--info-ink);
    pointer-events: none;
}
.wanda-eye-working { width: 18px; }
.wanda-eye-working svg { width: 14px; height: 14px; animation: wanda-working-turn 1.4s linear infinite; }
.wanda-eye-replying { gap: 3px; padding: 0 4px; }
.wanda-eye-replying i {
    display: block;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: currentColor;
    animation: wanda-replying-dots 1.2s ease-in-out infinite;
}
.wanda-eye-replying i:nth-child(2) { animation-delay: 150ms; }
.wanda-eye-replying i:nth-child(3) { animation-delay: 300ms; }
.wanda-eye-asks {
    padding: 0 4px;
    background: var(--warning-bg);
    border-color: var(--warning-border);
    color: var(--warning);
    font-size: 10px;
    line-height: 16px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.wanda-eye[data-activity="working"] .wanda-eye-working,
.wanda-eye[data-activity="replying"] .wanda-eye-replying,
.wanda-eye[data-activity="idle"]:not([data-open-asks="0"]) .wanda-eye-asks { display: inline-flex; }
.wanda-pane-moving .wanda-eye-working svg,
.wanda-pane-moving .wanda-eye-replying i,
.wanda-eye[data-motion-paused="true"] .wanda-eye-working svg,
.wanda-eye[data-motion-paused="true"] .wanda-eye-replying i { animation-play-state: paused; }
@keyframes wanda-working-turn { to { transform: rotate(360deg); } }
@keyframes wanda-replying-dots {
    0%, 60%, 100% { transform: translateY(0); opacity: .55; }
    30% { transform: translateY(-2px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    .wanda-eye-working svg,
    .wanda-eye-replying i { animation: none; }
}

/* Conversation controls and the owner's persistent action ledger. */
.wanda-chat-actions { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 12px; }
.wanda-chat-submit { margin-left: auto; }
.wanda-chat-actions .wanda-icon-button svg { width: 20px; height: 20px; }
.wanda-history { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 12px; color: var(--ink); }
.wanda-history[hidden], .wanda-chat-form[hidden], .wanda-chat-body[hidden] { display: none; }
.wanda-history-heading, .wanda-history-meta, .wanda-history-pages { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.wanda-history-heading h2 { margin: 0; font-size: 16px; font-weight: 700; }
.wanda-history-list { list-style: none; margin: 12px 0; padding: 0; }
.wanda-history-entry { padding: 16px 0; border-bottom: 1px solid var(--line); }
.wanda-history-meta, .wanda-history-hint { font-size: 12px; color: var(--muted); }
.wanda-history-summary { margin: 6px 0 10px; font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.wanda-history summary { cursor: pointer; font-size: 13px; padding: 8px 0; }
.wanda-history-change { padding: 8px 0; font-size: 13px; }
.wanda-history-change a { color: var(--ink); text-decoration: underline; overflow-wrap: anywhere; }
.wanda-history-change h3 { margin-top: 12px; font-size: 12px; color: var(--muted); }
.wanda-history-change pre { margin: 4px 0; padding: 8px; background: var(--hover); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow: auto; }
.wanda-history-entry form { margin-top: 10px; }
.wanda-history-error { font-size: 13px; border-left: 2px solid var(--ink); padding-left: 10px; }
.wanda-history-page { max-width: 800px; margin: 0; padding: 24px 0; color: var(--ink); }
.wanda-history-page [data-wanda-history-back] { display: none; }
.wanda-icon-button:disabled { opacity: .45; cursor: default; }

/* Snapped chat owns a column of the app and resizes only at its left edge. */
.wanda-shell > main { min-width: 0; }
body.wanda-chat-docked .wanda-shell > :is(main, footer) { margin-right: var(--wanda-dock-width); }
.wanda-chat[data-docked] {
    border-width: 0 0 0 2px;
    border-radius: 0;
    box-shadow: none;
    animation: none;
    z-index: 35;
}
.wanda-chat[data-docked] .wanda-chat-title { cursor: default; touch-action: auto; }
.wanda-chat[data-docked] :is(.wanda-pane-edge, .wanda-pane-corner) { display: none; }
.wanda-chat[data-docked][data-dock-resizable] [data-wanda-resize="w"] { display: block; top: 0; bottom: 0; }
.wanda-chat[data-docked] [data-wanda-resize="w"] { outline: none; }
.wanda-chat[data-docked]:not(.wanda-pane-pointer-focus) [data-wanda-resize="w"]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.wanda-chat[data-docked] .wanda-chat-form { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.wanda-chat-tools { flex-shrink: 0; }
.wanda-undock-icon { display: none; }
[data-wanda-dock][aria-pressed="true"] .wanda-dock-icon { display: none; }
[data-wanda-dock][aria-pressed="true"] .wanda-undock-icon { display: inline-flex; }
/* Below a usable two-column width, the dock becomes the content view.
   Minimise or Unsnap brings the page back without losing its state. */
body.wanda-chat-compact .wanda-shell > :is(main, footer) { display: none; }
body.wanda-chat-docked .toast-stack { right: calc(var(--wanda-dock-width) + 16px); }
body.wanda-chat-compact .toast-stack { right: 16px; }
.wanda-chat-files { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 8px; padding: 0; list-style: none; }
.wanda-chat-files li { display: flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: var(--control-radius); padding-left: 8px; font-size: 12px; }
.wanda-chat-files :is(a, span) { min-width: 0; overflow-wrap: anywhere; }
.wanda-chat-sources { display: flex; flex-wrap: wrap; gap: 4px 12px; list-style: none; padding: 0; margin: 8px 0 0; font-size: 12px; }
.wanda-chat-files a, .wanda-chat-sources a { color: inherit; text-decoration: underline; text-underline-offset: 3px; }
