/* ============================================
   BUD CHAT WIDGET - the one stylesheet (BUD-UI-002, Part A)
   Loaded by every page that carries Bud; the portal's own copy is gone.

   Every colour is an Academy token with today's light literal as its
   fallback: on a page with the shared stylesheet the value set follows the
   stamp js/theme.js puts on <html> (THM-R1 to THM-R5, light or dark, and a
   change in another tab arrives through the same attribute); on the public
   front page (index.html: no stylesheet, no stamp, dark by ruling 8) the
   fallbacks render Bud exactly as it rendered before, with two repairs - the
   two invalid nine-digit hex colours and the white-on-white text (the placeholder,
   the welcome text, the sources title, the typing dots) are now readable.
   The launcher keeps the brand gradient in both sets.

   A head-level bootstrap (js/bud-boot.js, the theme.js pattern) puts the
   remembered geometry on <html> before first paint: --bud-x / --bud-y (the
   widget's corner), --bud-w / --bud-h (the panel), data-bud-open and
   data-bud-dock. The rules keyed on those stand until the widget takes over
   with the same values inline.

   BUD-UI-003 (the Medical Director's feedback of 12 November 2026): Minimise is a
   labelled button at the top right and Reset sits beside it, both 44 px tall on
   white ink; the words collapse to their icons only below 360 px of panel (the
   300 px floor is the reason), never at Compact. The messages pane and the message
   box get a 12 px scroll bar on the scroll tokens with a hover state and a stable
   gutter; the right-edge resize zone is the panel's 6 px rim with a clear 6 px gap
   before the scroll bar, so a press on the bar only ever scrolls and a press on the
   rim only ever resizes.
============================================ */

.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    font-family: var(--wc-font-body, 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif);
    cursor: move;
    user-select: none;
}

.chat-widget.dragging {
    opacity: 0.9;
}

.chat-widget.dragging .chat-window {
    pointer-events: none;
}

/* Drag Handle */
.chat-drag-handle {
    position: absolute;
    top: 6px; /* BUD-UI-001: inside the panel, which clips its overflow */
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 6px;
    background: var(--wc-line-strong, rgba(20, 59, 46, 0.13));
    border-radius: 3px;
    cursor: move;
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-window:hover .chat-drag-handle,
.chat-widget.dragging .chat-drag-handle {
    opacity: 1;
}

/* Chat Toggle Button: the brand gradient in every value set */
.chat-toggle {
    touch-action: none; /* BUD-UI-001: a touch here drags Bud, never the page */
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--wc-gradient-brand, linear-gradient(135deg, #338364, #69b445));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(51, 131, 100, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease; /* never `all`: NAV-R16's visibility must change at once */
    position: relative;
}

.chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 30px rgba(51, 131, 100, 0.5);
}

.chat-toggle.active {
    transform: rotate(90deg);
}

.chat-toggle-icon {
    font-size: 1.8rem;
    transition: transform 0.3s ease;
}

.chat-toggle.active .chat-toggle-icon {
    transform: rotate(-90deg);
}

/* Notification Badge */
.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: var(--wc-error, #ef4444);
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 600;
    color: #ffffff;
    display: none;
    align-items: center;
    justify-content: center;
}

/* Chat Window */
.chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    height: 520px;
    background: var(--wc-bg-dark, #f4f8f5);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 20px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--wc-shadow-float, 0 10px 40px rgba(0, 0, 0, 0.4));
    animation: chatSlideUp 0.3s ease;
    /* BUD-UI-003: the resize rim and the gap before a scroll bar; the header's words
       are measured against the panel's width; the body of the panel is not a drag */
    --bud-rim: 6px;
    --bud-rim-gap: 6px;
    container-type: inline-size;
    container-name: bud-panel;
    cursor: default;
}

.chat-window.open {
    display: flex;
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header: the brand gradient carries white ink in both sets */
.chat-header {
    touch-action: none; /* BUD-UI-001: a touch here drags Bud, never the page */
    background: var(--wc-gradient, linear-gradient(135deg, #1f5240, #338364));
    padding: 14px 14px 12px; /* BUD-UI-003: the ne corner handle (14 px) stays clear of Minimise */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    cursor: move;
}

/* BUD-UI-003: the banner (BUD-R15, verbatim, the existing class) is the header's last
   child and takes a row of its own across the full width, so the name and the status
   beside the labelled buttons never squeeze it into a column of broken lines */
.chat-header > .chat-header-status {
    flex: 1 0 100%;
}

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    overflow: hidden; /* BUD-UI-003: a long word wraps or clips here, never past the header */
}

.chat-header-info .chat-header-status {
    overflow-wrap: anywhere;
}

.chat-header-name {
    font-family: var(--wc-font-display, 'Outfit', sans-serif);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--wc-on-fill, #ffffff);
}

.chat-header-status {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--wc-success, #22c55e);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto; /* BUD-UI-003: the controls hold the top right */
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.14);
    border: none;
    color: var(--wc-on-fill, #ffffff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    transition: background 0.2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.24);
}

/* BUD-UI-003: Reset and Minimise - the icon over the word, at least 44 px tall, white
   ink on the gradient with a light edge so each reads as a button in light and dark.
   The floor is 45 px, not 44 (17 Nov 2026): CI's headless Chromium measured the box at
   43.99997 px against the viewer test's 44 px floor (a float at the threshold, the
   layout being exactly min-height), so the rule sits one pixel above the floor. */
.chat-header-btn--labelled {
    width: auto;
    height: auto;
    min-width: 52px;
    min-height: 45px;
    flex-direction: column;
    gap: 3px;
    padding: 4px 7px;
    border: 1px solid;
    border-color: rgba(255, 255, 255, 0.24);
    color: var(--wc-on-fill, #ffffff);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
}

.chat-header-btn-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.chat-header-btn:focus-visible {
    outline: 2px solid var(--wc-on-fill, #ffffff);
    outline-offset: 2px;
}

/* below 360 px of panel the words collapse to the icons (the aria-labels and the
   tooltips stand) and the status line ends in an ellipsis instead of breaking its
   words; above it the words always show - the 300 px floor is the reason. Desktop
   only: the phone's panel is narrower than that and has no Reset, so its header
   has the room and keeps the word (item 5) */
@media (min-width: 501px) {
    @container bud-panel (max-width: 359px) {
        .chat-header-btn-label {
            display: none;
        }
        .chat-header-btn--labelled {
            min-width: 44px;
        }
        .chat-header-info .chat-header-status {
            display: block;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .chat-header-info .status-dot {
            display: inline-block;
            vertical-align: middle;
            margin-right: 4px;
        }
    }
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--wc-white, #ffffff);
    /* BUD-UI-003: the scroll bar sits inside this transparent border, clear of the
       rim by the gap; the gutter is reserved before anything scrolls, so nothing jumps */
    border-right: calc(var(--bud-rim) + var(--bud-rim-gap)) solid transparent;
    scrollbar-gutter: stable;
}

/* BUD-UI-003: a 12 px scroll bar with a thumb that can be seen and taken, on the
   scroll tokens (the front page renders the light literals), a hover on the brand */
.chat-messages::-webkit-scrollbar {
    width: 12px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--wc-scroll-track, #e8f1e9);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--wc-scroll-thumb, #b9cfc0);
    border-radius: 6px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--wc-primary, #338364);
}

/* Message Bubbles */
.chat-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--wc-bg-dark-mid, #e8f1e9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.chat-message.assistant .message-avatar {
    background: var(--wc-gradient-brand, linear-gradient(135deg, #338364, #69b445));
}

.message-content {
    background: var(--wc-bg-dark, #f4f8f5);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 16px;
    padding: 12px 16px;
    color: var(--wc-text-body, #35443d);
    font-size: 0.95rem;
    line-height: 1.5;
    min-width: 0;
}

.chat-message.user .message-content {
    background: var(--wc-gradient, linear-gradient(135deg, #338364, #1f5240));
    border: none;
    color: var(--wc-on-fill, #ffffff);
}

.message-content p {
    margin: 0 0 8px 0;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    color: var(--wc-accent-text, #69b445);
}

/* on the gradient bubble the accent ink would vanish: white, as the rest of the bubble */
.chat-message.user .message-content strong {
    color: var(--wc-on-fill, #ffffff);
}

.message-content ul, .message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-content li {
    margin: 4px 0;
}

.message-content code {
    background: var(--wc-chip, rgba(20, 59, 46, 0.10));
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--wc-font-mono, monospace);
    font-size: 0.9em;
}

/* Message Sources */
.message-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
}

.message-sources-title {
    font-size: 0.75rem;
    color: var(--wc-text-muted, #566159);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.message-sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.message-source {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.2));
    border-radius: 12px;
    font-size: 0.8rem;
    color: var(--wc-accent-text, #69b445);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}

.message-source:hover {
    background: var(--wc-glass-border-hover, rgba(51, 131, 100, 0.3));
    transform: translateY(-1px);
}

.source-icon {
    font-size: 0.9rem;
    flex-shrink: 0;
}

.source-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
}

.source-badge {
    background: var(--wc-chip, rgba(20, 59, 46, 0.13));
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}

/* Typing Indicator */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 10px;
    padding: 0 20px 16px;
}

.typing-indicator.visible {
    display: flex;
}

.typing-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--wc-gradient-brand, linear-gradient(135deg, #338364, #69b445));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.typing-bubble {
    background: var(--wc-bg-dark, #f4f8f5);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 16px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--wc-text-muted, #566159);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Chat Input */
.chat-input-container {
    padding: 16px;
    background: var(--wc-bg-dark, #f4f8f5);
    border-top: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
}

/* BUD-UI-004 Part A (13 Nov 2026): the quick-action row is gone; the three actions sit
   in the Ideas menu beside Send. The wrapper anchors the menu, which is placed above
   the composer and never past the panel's top (the script caps it there). */
.chat-input-wrapper {
    position: relative;
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-ideas-btn {
    flex-shrink: 0;
    min-width: 52px;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 8px;
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
    border: 1px solid var(--wc-glass-border-hover, rgba(51, 131, 100, 0.3));
    border-radius: 12px;
    color: var(--wc-accent-text, #266349);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.chat-ideas-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.chat-ideas-btn:hover:not(:disabled),
.chat-ideas-btn[aria-expanded="true"] {
    background: var(--wc-glass-border-hover, rgba(51, 131, 100, 0.25));
    border-color: var(--wc-primary, #338364);
}

.chat-ideas-btn:focus-visible {
    outline: 2px solid var(--wc-focus, #338364);
    outline-offset: 2px;
}

.chat-ideas-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-ideas-menu {
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    min-width: 200px;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px;
    background: var(--wc-white, #ffffff);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 12px;
    box-shadow: var(--wc-shadow-card, 0 6px 24px rgba(0, 0, 0, 0.16));
    overflow-y: auto;
    z-index: 5;
}

.chat-ideas-menu[hidden] {
    display: none;
}

.chat-ideas-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--wc-text-body, #35443d);
    font-family: inherit;
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
}

.chat-ideas-item:hover:not(:disabled),
.chat-ideas-item:focus-visible {
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
}

.chat-ideas-item:focus-visible {
    outline: 2px solid var(--wc-focus, #338364);
    outline-offset: -2px;
}

.chat-ideas-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-ideas-item-icon {
    font-size: 1rem;
}

/* BUD-UI-004 Part B (13 Nov 2026): the Speak button, built only where the browser turns
   speech into text on the device - the Ideas button's shape, the brand fill while it
   listens, the word itself reading "Listening"; every transition names its properties. */
.chat-mic-btn {
    flex-shrink: 0;
    min-width: 52px;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 4px 8px;
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
    border: 1px solid var(--wc-glass-border-hover, rgba(51, 131, 100, 0.3));
    border-radius: 12px;
    color: var(--wc-accent-text, #266349);
    font-family: inherit;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.1;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.chat-mic-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.chat-mic-btn:hover:not(:disabled) {
    background: var(--wc-glass-border-hover, rgba(51, 131, 100, 0.25));
    border-color: var(--wc-primary, #338364);
}

.chat-mic-btn[aria-pressed="true"] {
    background: var(--wc-primary, #338364);
    border-color: var(--wc-primary, #338364);
    color: var(--wc-on-fill, #ffffff);
}

.chat-mic-btn[aria-pressed="true"] .chat-mic-icon {
    animation: budListening 1.2s ease-in-out infinite;
}

@keyframes budListening {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.75; }
}

.chat-mic-btn:focus-visible {
    outline: 2px solid var(--wc-focus, #338364);
    outline-offset: 2px;
}

.chat-mic-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* the voice line (the notice, the pack ask, a reason) and the dictation tip sit above the
   composer on the context lines' class; unlike a title they wrap rather than ellipsise */
/* the three as suggestions in the welcome area, in one row, while nothing has been said */
.chat-welcome-ideas {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
}

.chat-suggestion--idea {
    flex: 1 1 auto;
    text-align: center;
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
    border-color: var(--wc-glass-border-hover, rgba(51, 131, 100, 0.3));
    color: var(--wc-accent-text, #266349);
    font-weight: 600;
}

/* BUILD-BUD-CLOSE-001 Part E (12 Nov 2026): the box and its grab bar share a column,
   Send stays beside them; the box reads at a comfortable size and line height, and its
   height is the script's - the default three lines, the floor two, the ceiling half
   the panel with 120 px kept for the messages - so no max-height is set here. */
.chat-input-box {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.chat-input {
    flex: 0 0 auto;
    width: 100%;
    box-sizing: border-box;
    background: var(--wc-white, #ffffff);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--wc-text-body, #35443d);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.45;
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    transition: border-color 0.2s;
    scrollbar-gutter: stable; /* BUD-UI-003 */
}

/* the grab bar: at least 10 px to take hold of, a row-resize cursor, a grip mark on the
   scroll-thumb token that turns to the brand under the pointer or the focus ring */
.chat-input-grip {
    height: 14px;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    cursor: row-resize;
    touch-action: none;
}

.chat-input-grip:hover,
.chat-input-grip:focus-visible {
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
}

.chat-input-grip:focus-visible {
    outline: 2px solid var(--wc-focus, #338364);
    outline-offset: 1px;
}

.chat-input-grip-mark {
    width: 44px;
    height: 4px;
    border-radius: 2px;
    background: var(--wc-scroll-thumb, #b9cfc0);
}

.chat-input-grip:hover .chat-input-grip-mark,
.chat-input-grip:focus-visible .chat-input-grip-mark {
    background: var(--wc-primary, #338364);
}

.chat-widget.input-resizing {
    user-select: none;
}

/* BUILD-BUD-CLOSE-001 Part E, at the floor width (the header's own container query,
   placed after the rules it narrows): the rows close up - the composer's and the pane's
   padding, the gaps - so the header, the size bar, a two-line box and Send fit inside
   360 px with the messages pane at its least. BUD-UI-004 Part A took the quick-action
   row and its one-row squeeze out; the close-up stays, since it still buys the
   messages room there, and the Ideas word collapses to its icon as the header's
   words do (the name and the tooltip stand). Send is never pushed out of view. */
@media (min-width: 501px) {
    @container bud-panel (max-width: 359px) {
        .chat-ideas-label {
            display: none;
        }
        .chat-ideas-btn {
            min-width: 44px;
        }
        .chat-messages {
            padding-top: 12px;
            padding-bottom: 12px;
        }
        .chat-input-container {
            padding-top: 10px;
            padding-bottom: 12px;
        }
        .chat-input-grip {
            margin-bottom: 2px;
        }
    }
}

.chat-input::-webkit-scrollbar {
    width: 12px;
}

.chat-input::-webkit-scrollbar-track {
    background: var(--wc-scroll-track, #e8f1e9);
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--wc-scroll-thumb, #b9cfc0);
    border-radius: 6px;
}

.chat-input::-webkit-scrollbar-thumb:hover {
    background: var(--wc-primary, #338364);
}

/* the standard properties only where the pseudo-elements are not drawn: set beside
   them they would switch Chromium's styled scroll bar off */
@supports not selector(::-webkit-scrollbar) {
    .chat-messages,
    .chat-input {
        scrollbar-width: auto;
        scrollbar-color: var(--wc-scroll-thumb, #b9cfc0) var(--wc-scroll-track, #e8f1e9);
    }
}

.chat-input:focus {
    outline: none;
    border-color: var(--wc-focus, #338364);
}

.chat-input::placeholder {
    color: var(--wc-text-muted, #566159);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--wc-gradient-brand, linear-gradient(135deg, #338364, #69b445));
    border: none;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(51, 131, 100, 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Welcome Message */
.chat-welcome {
    text-align: center;
    padding: 30px 20px;
}

.chat-welcome-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--wc-gradient-brand, linear-gradient(135deg, #338364, #69b445));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    margin: 0 auto 16px;
}

.chat-welcome-title {
    font-family: var(--wc-font-display, 'Outfit', sans-serif);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--wc-text-primary, #35443d);
    margin-bottom: 8px;
}

.chat-welcome-text {
    color: var(--wc-text-secondary, #48574f);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 20px;
}

.chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-suggestion {
    padding: 10px 16px;
    background: var(--wc-bg-dark, #f4f8f5);
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    border-radius: 10px;
    color: var(--wc-text-body, #35443d);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    text-align: left;
}

.chat-suggestion:hover {
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.2));
    border-color: var(--wc-primary, #338364);
}

/* ============================================
   CONTEXT LINES (NEWS-R17 "Asking about", BUD-UI-002 Part E "Tagged for Bud")
   Both sit in the input container, on the surface ink - the header's white
   would vanish there - with the quick asks in a row beneath the tag line.
============================================ */
.chat-input-container .chat-header-status {
    color: var(--wc-text-secondary, #48574f);
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.chat-input-container .chat-header-status > span {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-input-container .chat-header-status .chat-header-btn {
    width: auto;
    padding: 0 10px;
    font-size: 0.78rem;
    background: var(--wc-card-tint, rgba(51, 131, 100, 0.15));
    color: var(--wc-accent-text, #266349);
}

/* BUD-UI-004 Part B - the two voice lines in the composer (after the generic rules above,
   which they outrank by order): the text wraps rather than being cut, the button keeps its
   width, and the tip sits low and close over the typing box (a 28-px Dismiss, a 2-px gap)
   so Tall still holds the whole welcome area with the tip shown */
.chat-input-container .chat-voice-line > span,
.chat-input-container .chat-voice-tip > span {
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
}

.chat-input-container .chat-voice-line .chat-header-btn,
.chat-input-container .chat-voice-tip .chat-header-btn {
    flex-shrink: 0;
}

.chat-input-container .chat-voice-tip {
    margin-bottom: 2px;
}

.chat-input-container .chat-voice-tip .chat-header-btn {
    height: 28px;
}

.chat-tag-asks {
    flex: 1 0 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.chat-tag-asks .chat-suggestion {
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* ============================================
   SIZES AND RESIZE (BUD-UI-002 Part B, ruling 6)
   A size bar under the header - Compact, Tall, Side panel, Study mode, the
   active one marked - and eight handles on the panel's edges and corners for
   a resize by pointer. The open panel is its own containing block, so the
   handles and the drag handle sit at its edges whatever its size.
============================================ */
.chat-size-bar {
    display: flex;
    gap: 6px;
    padding: 8px 12px;
    background: var(--wc-bg-dark-mid, #e8f1e9);
    border-bottom: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    flex: 0 0 auto;
}

.chat-size-btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 5px 6px;
    border-radius: 999px;
    border: 1px solid var(--wc-glass-border, rgba(20, 59, 46, 0.13));
    background: var(--wc-white, #ffffff);
    color: var(--wc-text-secondary, #48574f);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.chat-size-btn:hover {
    border-color: var(--wc-primary, #338364);
    color: var(--wc-accent-text, #266349);
}

.chat-size-btn[aria-pressed="true"] {
    background: var(--wc-gradient, linear-gradient(135deg, #1f5240, #338364));
    border-color: transparent;
    color: var(--wc-on-fill, #ffffff);
}

.chat-resize {
    position: absolute;
    z-index: 2;
    touch-action: none;
    background: transparent;
}

.chat-resize[data-edge="n"] { top: 0; left: 14px; right: 14px; height: 5px; cursor: ns-resize; }
.chat-resize[data-edge="s"] { bottom: 0; left: 14px; right: 14px; height: 6px; cursor: ns-resize; }
.chat-resize[data-edge="e"] { right: 0; top: 14px; bottom: 14px; width: var(--bud-rim); cursor: ew-resize; } /* BUD-UI-003: the rim, clear of the scroll bar */
.chat-resize[data-edge="w"] { left: 0; top: 14px; bottom: 14px; width: 6px; cursor: ew-resize; }
.chat-resize[data-edge="ne"] { top: 0; right: 0; width: 14px; height: 14px; cursor: nesw-resize; }
.chat-resize[data-edge="sw"] { bottom: 0; left: 0; width: 14px; height: 14px; cursor: nesw-resize; }
.chat-resize[data-edge="nw"] { top: 0; left: 0; width: 14px; height: 14px; cursor: nwse-resize; }
.chat-resize[data-edge="se"] { bottom: 0; right: 0; width: 14px; height: 14px; cursor: nwse-resize; }

.chat-widget.resizing {
    user-select: none;
}

.chat-widget.resizing .chat-messages,
.chat-widget.resizing .chat-input-container {
    pointer-events: none;
}

/* ============================================
   GEOMETRY BEFORE FIRST PAINT (BUD-UI-002 Part A): the bootstrap's values.
   js/bud-boot.js sets --bud-x / --bud-y / --bud-w / --bud-h on <html> and the
   data-bud-open and data-bud-dock marks from wellcann_bud:<user id>; the
   widget then holds the same values inline. Desktop only: below the phone
   breakpoint the corner layout stands and nothing here applies.
============================================ */
@media (min-width: 501px) {
    :root[data-bud-placed] .chat-widget {
        left: var(--bud-x);
        top: var(--bud-y);
        right: auto;
        bottom: auto;
    }
    :root[data-bud-open="1"] .chat-window {
        display: flex;
    }
    :root[data-bud-sized] .chat-window {
        width: var(--bud-w, 380px);
        height: var(--bud-h, 520px);
    }
    /* the open panel is the whole of Bud: it sits at the widget's corner and the
       small button waits, hidden, until Minimise parks it again */
    :root[data-bud-open="1"] .chat-widget .chat-toggle,
    .chat-widget.is-open .chat-toggle {
        display: none;
    }
    :root[data-bud-open="1"] .chat-window,
    .chat-widget.is-open .chat-window {
        position: relative;
        bottom: auto;
        right: auto;
    }
    /* Side panel: the page's content shifts left by the panel's width where the layout
       allows, so nothing is ever hidden behind Bud; module frames are never touched */
    :root[data-bud-dock="side"]:not([data-wc-surface]) body {
        box-sizing: border-box;
        padding-right: var(--bud-w, 440px);
    }
}

/* Mobile Responsive: today's phone layout stands (ruling 6, item 10) */
@media (max-width: 500px) {
    .chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 75px;
        right: -8px;
        border-radius: 16px;
    }

    .chat-widget {
        bottom: 16px;
        right: 16px;
    }

    .chat-toggle {
        width: 54px;
        height: 54px;
    }

    /* BUD-UI-002 (item 10): no size bar and no resize on the phone */
    .chat-size-bar,
    .chat-resize {
        display: none;
    }

    /* BUD-UI-003: the phone has no sizes to reset; the labelled Minimise stays */
    #chatResetBtn {
        display: none;
    }

    /* BUILD-BUD-CLOSE-001 Part E: the taller default applies; no grab bar on the phone */
    .chat-input-grip {
        display: none;
    }
}


/* BUILD-FBK-002 (PF-DESIGN-FEEDBACK-001 FBK-R6): "Did this help?" under a real answer. Tokens only:
   every --wc-* name below is re-pointed by the dark set, so the thumbs read in both themes
   (the Medical Director's word of 14 Nov 2026); nothing of this sits in the keyed block below. */
.chat-thumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.chat-thumbs__ask { font-size: 0.85rem; color: var(--wc-text-muted, #566159); }
.chat-thumbs__btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--wc-glass-border, #dde7df); background: var(--wc-glass-bg, #ffffff); color: var(--wc-accent-text, #266349); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.chat-thumbs__btn:hover:not(:disabled), .chat-thumbs__btn:focus-visible { border-color: var(--wc-primary, #338364); background: var(--wc-card-tint, rgba(51, 131, 100, 0.10)); outline: none; }
.chat-thumbs__btn:disabled { opacity: 0.5; cursor: default; }
.chat-thumbs__reasons { display: flex; flex-wrap: wrap; gap: 8px; flex-basis: 100%; }
.chat-thumbs__reasons .chat-suggestion { min-height: 44px; }
.chat-thumbs__thanks { font-size: 0.85rem; font-weight: 500; color: var(--wc-text-primary, #1f5240); }

/* ============================================
   APPEARANCE (THM-R1 to THM-R5): the dark value set.
   The rules above read the tokens, so the dark set is the shared stylesheet's
   own: :root[data-theme="dark"] re-points every --wc-* name and Bud follows,
   the launcher keeping the brand gradient (its token is not re-pointed). A
   page with no stamp (index.html, the public front page) renders the light
   fallbacks exactly as before. Any rule that must be keyed on the dark stamp
   belongs here, keyed, and nowhere else.
============================================ */
