/* Keep the conversation card compact; scroll the message history inside it. */
.fox-messages-page .fox-dialog-layout {
    align-items: start;
    min-height: 0;
}
.fox-messages-page .fox-dialog-conversation {
    align-self: start;
    height: auto;
    min-height: 0;
    overflow: hidden;
}
.fox-messages-page #place_for_messages {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    max-width: 100%;
}
.fox-messages-page #place_for_messages #chat,
.fox-messages-page #place_for_messages #chat form {
    height: auto;
    min-height: 0;
    max-height: none;
}
.fox-messages-page #place_for_messages #chat #drop_zone {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: hidden;
}
.fox-messages-page #place_for_messages #messages {
    flex: 0 0 auto;
    height: clamp(260px, 48dvh, 520px);
    min-height: 260px;
    max-height: 520px;
    overflow-x: hidden;
    overflow-y: scroll;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}
.fox-messages-page #place_for_messages #messages .im_message {
    position: relative;
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    max-width: 82%;
    overflow: visible;
}
.fox-messages-page #place_for_messages #messages .im_message > div,
.fox-messages-page #place_for_messages #messages .im_message .with_code {
    min-width: 0;
    max-width: 100%;
    height: auto;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.fox-messages-page #place_for_messages #messages .im_message pre {
    max-width: 100%;
    overflow-x: auto;
}
.fox-messages-page #fox-dialog-list {
    min-height: 0;
    max-height: min(65vh, 650px);
    max-height: min(65dvh, 650px);
    overflow-y: auto;
}

/* Highlight the custom scrollbar during wheel, keyboard, touch and thumb scrolling. */
.fox-messages-page .fox-message-scroll-rail,
.fox-messages-page .fox-message-scroll-rail__thumb {
    transition: border-color .22s ease, background .22s ease, box-shadow .22s ease, opacity .22s ease;
}
.fox-messages-page .fox-message-scroll-rail.is-scrolling:not(.is-idle),
.fox-messages-page .fox-message-scroll-rail.is-dragging {
    opacity: 1;
    border-color: var(--fox-tone-as4l17, #e8bcff);
    background: rgba(var(--fox-rgb-as2l7, 91, 35, 150), .84);
    box-shadow: 0 0 0 2px rgba(var(--fox-rgb-gs4l14, 195, 119, 249), clamp(0, calc(.2 * var(--fox-glow-strength, 1)), 1)), 0 0 19px rgba(var(--fox-rgb-gs4l14, 191, 105, 255), clamp(0, calc(.72 * var(--fox-glow-strength, 1)), 1)), inset 0 0 10px rgba(var(--fox-rgb-gs4l15, 200, 137, 255), clamp(0, calc(.29 * var(--fox-glow-strength, 1)), 1));
}
.fox-messages-page .fox-message-scroll-rail.is-scrolling:not(.is-idle) .fox-message-scroll-rail__thumb,
.fox-messages-page .fox-message-scroll-rail.is-dragging .fox-message-scroll-rail__thumb {
    background: linear-gradient(180deg, var(--fox-tone-ts4l19, #fff0ff), var(--fox-tone-ts4l17, #e2aaff) 49%, var(--fox-tone-ts3l13, #a65bec));
    box-shadow: 0 0 8px rgba(var(--fox-rgb-gs4l18, 244, 207, 255), clamp(0, calc(.95 * var(--fox-glow-strength, 1)), 1)), 0 0 19px rgba(var(--fox-rgb-gs4l13, 187, 85, 255), clamp(0, calc(.88 * var(--fox-glow-strength, 1)), 1));
}
@media (prefers-reduced-motion: reduce) {
    .fox-messages-page .fox-message-scroll-rail,
    .fox-messages-page .fox-message-scroll-rail__thumb { transition: none; }
}

/* The home chat input stays inside its card even with a long message. */
.fox-chat-panel,
.fox-chat-panel #chat,
.fox-chat-panel #chat form,
.fox-chat-panel #chat #drop_zone,
.fox-chat-panel #chat #chat_messages {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
}
.fox-chat-panel #chat #chat_messages .chat_message,
.fox-chat-panel #chat #chat_messages .chat_message .message,
.fox-chat-panel #chat #chat_messages .chat_message .with_code {
    box-sizing: border-box;
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.fox-chat-panel #chat #chat_messages .chat_message .with_code {
    white-space: normal;
}
.fox-chat-panel #chat .fox-chat-compose:not(.fox-chat-compose--guest) {
    grid-template-columns: minmax(0, 1fr) 40px 104px;
    column-gap: 6px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}
.fox-chat-panel #chat .fox-chat-compose--guest {
    grid-template-columns: minmax(0, 1fr) auto;
}
.fox-chat-panel #chat .fox-chat-compose .smile_input,
.fox-chat-panel #chat .fox-chat-compose #chat_message_input {
    min-width: 0 !important;
    max-width: 100%;
}
.fox-chat-panel #chat .fox-chat-compose #chat_message_input {
    padding-right: 12px;
}
/* The legacy smile control remains as a sticker-picker anchor in forum and PM markup. */
body #smile_btn { display: none !important; }
.fox-chat-panel #chat .fox-chat-compose #send_button {
    box-sizing: border-box;
    width: 104px;
    min-width: 104px;
    max-width: 100%;
    padding: 6px !important;
    white-space: nowrap;
}

/* Stage 4 / 1.6: a compact sticker icon, with no visible button frame. */
.fox-chat-panel #chat .fox-chat-compose #fox-chat-sticker-toggle {
    width: 40px;
    border: 0;
    background: transparent;
    box-shadow: none;
    color: var(--fox-tone-as4l16, #cda0fa);
    font-size: 22px;
    transition: color .2s ease, text-shadow .2s ease;
}
.fox-chat-panel #chat .fox-chat-compose #fox-chat-sticker-toggle:hover,
.fox-chat-panel #chat .fox-chat-compose #fox-chat-sticker-toggle[aria-expanded="true"] {
    background: transparent;
    color: var(--fox-tone-as4l18, #eac9ff);
    text-shadow: 0 0 9px rgba(var(--fox-rgb-gs4l14, 193, 104, 255), clamp(0, calc(.45 * var(--fox-glow-strength, 1)), 1));
}
@media (prefers-reduced-motion: reduce) {
    .fox-chat-panel #chat .fox-chat-compose #fox-chat-sticker-toggle { transition: none; }
}

/* Restore the illustrated banner even when the older home partial has no art rule. */
body #fox-sticker-panel {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    background: radial-gradient(ellipse at 50% 0%, rgba(var(--fox-rgb-ts2l7, 91, 40, 143), .25), transparent 75%), var(--fox-tone-ts2l1, #0b0816);
}
body #fox-sticker-panel::before,
body #fox-sticker-panel::after {
    position: absolute;
    inset: 0;
    z-index: 0;
    border-radius: inherit;
    content: '';
    pointer-events: none;
}
body #fox-sticker-panel::before {
    height: 100%;
    max-height: 440px;
    background-image: linear-gradient(90deg, rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .22), rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .07) 48%, rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .27)), url('../img/fox/sticker-kitsune-samurai.webp?v=stage3t12_6fix');
    background-position: center top;
    background-size: cover;
    background-repeat: no-repeat;
    -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 48%, transparent 100%);
    mask-image: linear-gradient(180deg, #000 0%, #000 48%, transparent 100%);
}
body #fox-sticker-panel::after {
    background: linear-gradient(180deg, rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .13), rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .24) 35%, rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .58) 73%, rgba(var(--fox-rgb-ts2l1, 9, 6, 20), .79));
}
body #fox-sticker-panel > .fox-sticker-shop {
    position: relative;
    z-index: 1;
    min-width: 0;
}
#fox-sticker-panel .fox-sticker-shop__details[hidden] { display: none !important; }
#fox-sticker-panel .fox-sticker-shop__details-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}
#fox-sticker-panel .fox-sticker-shop__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 100px;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid rgba(var(--fox-rgb-as4l15, 201, 129, 252), .72);
    border-radius: 9px;
    background: rgba(var(--fox-rgb-as2l6, 74, 35, 119), .38);
    box-shadow: inset 0 1px rgba(var(--fox-rgb-gs4l18, 245, 208, 255), clamp(0, calc(.13 * var(--fox-glow-strength, 1)), 1));
    color: var(--fox-tone-as4l18, #efd6ff);
    font: 700 13px Rubik, sans-serif;
    cursor: pointer;
}
#fox-sticker-panel .fox-sticker-shop__close:hover { border-color: var(--fox-tone-as4l17, #e0adff); background: rgba(var(--fox-rgb-as2l10, 135, 57, 200), .34); }
#fox-sticker-panel .fox-sticker-shop__close:focus-visible { outline: 2px solid var(--fox-tone-as4l18, #e9c9ff); outline-offset: 2px; }

@media (max-width: 760px) {
    .fox-messages-page #fox-dialog-list { max-height: 208px; }
    .fox-messages-page #place_for_messages #messages {
        height: clamp(230px, 45dvh, 440px);
        min-height: 230px;
        max-height: 440px;
    }
    .fox-messages-page #place_for_messages #messages .im_message { max-width: 100%; }
}
@media (max-width: 440px) {
    .fox-chat-panel #chat .fox-chat-compose:not(.fox-chat-compose--guest) {
        grid-template-columns: minmax(0, 1fr) 40px 92px;
        column-gap: 6px;
        align-items: center;
    }
    .fox-chat-panel #chat .fox-chat-compose .smile_input { grid-column: 1; }
    .fox-chat-panel #chat .fox-chat-compose #fox-chat-sticker-toggle { grid-column: 2; }
    .fox-chat-panel #chat .fox-chat-compose #send_button { grid-column: 3; width: 92px; min-width: 92px; padding: 6px 4px !important; }
    body #fox-sticker-panel::before {
        max-height: clamp(175px, 48vw, 210px);
        background-position: center top, 62% top;
        -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 60%, transparent 100%);
        mask-image: linear-gradient(180deg, #000 0%, #000 60%, transparent 100%);
    }
}

/* Stage 4, 12.1: let the conversation size the shared desktop row. */
@media (min-width: 761px) {
    .fox-messages-page .fox-dialog-layout {
        align-items: stretch;
    }
    .fox-messages-page .fox-dialog-sidebar,
    .fox-messages-page .fox-dialog-conversation {
        align-self: stretch;
        min-height: 0;
        height: auto;
        max-height: none;
    }
    .fox-messages-page .fox-dialog-sidebar > .fox-dialog-heading {
        flex: 0 0 auto;
    }
    .fox-messages-page #fox-dialog-list {
        /* Exclude dialog count from the row's intrinsic height. */
        flex: 1 1 0;
        height: 0;
        min-height: 0;
        max-height: none;
        overflow-y: auto;
    }
}
