/* The Rusty column beside every wiki page, and the chat page's own top bar and history popup
   (15 November 2026). Colours are theme variables throughout. */

/* Three columns: the wiki sidebar, the page, Rusty. The page keeps two thirds of what is left. */
.rusty-column {
    flex: 0 0 clamp(320px, 31%, 500px);
    position: sticky;
    z-index: 60;
    top: 0;
    height: 100vh;
    border-left: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
}

.rusty-column[hidden] { display: none; }

.rusty-column iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: transparent;
}

.wiki-shell--rusty .main-content { min-width: 0; }

/* Keep the support bar behind Rusty, including the desktop column's composer. */
.wiki-shell--rusty ~ .donate-sticky { z-index: 44; }

/* The toggle in the topbar shows its state */
#btnRustyToggle[aria-pressed="true"] {
    background: color-mix(in oklab, var(--color-primary) 16%, transparent);
    box-shadow: 0 0 0 1px color-mix(in oklab, var(--color-primary) 40%, transparent);
}

@media (width >= 1350px) {
    .admin-rusty-column .rusty-column {
        position: fixed;
        inset: 0 0 0 auto;
        width: clamp(320px, 31vw, 500px);
    }

    .rusty-open body:has(.admin-rusty-column) { margin-right: clamp(320px, 31vw, 500px); }
}

/* A narrower screen cannot hold three columns: Rusty slides over the page from the right. */
@media (width < 1350px) {
    .rusty-column {
        position: fixed;
        inset: 0 0 0 auto;
        width: min(calc(100% - 28px), 440px);
        z-index: 60;
        box-shadow: -20px 0 60px -30px rgba(var(--black-rgb),0.7);
    }
}

/* Edge arrows stay reachable when the overlay covers the page toolbar. */
.rusty-expand-btn,
.rusty-collapse-btn {
    position: fixed;
    top: 64px;
    right: 0;
    z-index: 61;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 40px;
    border: 1px solid var(--color-border);
    border-radius: 8px 0 0 8px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
}
.rusty-open .rusty-expand-btn { display: none; }
.rusty-collapse-btn {
    position: absolute;
    top: 64px;
    right: 100%;
}

/* The chat page in embed mode: nothing but the chat, edge to edge. */
.wiki-shell--embedded .main-content { margin-left: 0; min-height: 100vh; }
.wiki-shell--embedded .donate-sticky { display: none; }

/* The chat's own top bar */
.chat-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    position: relative;
    z-index: 5;
}

.chat-topbar-pug { width: 28px; height: 28px; border-radius: 50%; }
.chat-topbar-title { font-weight: 700; font-size: 1rem; }

.chat-topbar-page {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.chat-topbar-page[hidden] { display: none; }
.chat-topbar-title + .chat-topbar-btn { margin-left: auto; }

.chat-topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm, 8px);
    border: 1px solid transparent;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background var(--transition), color var(--transition);
}

.chat-topbar-btn:hover {
    background: color-mix(in oklab, var(--color-primary) 12%, transparent);
    color: var(--color-text);
    text-decoration: none;
}

/* The history, dropped down from the clock button */
.chat-history-popup {
    /* Placed under the clock button by placeHistory() in Chat/Index; these are the fallback. */
    position: absolute;
    top: 56px;
    left: 12px;
    width: min(360px, calc(100vw - 16px));
    max-height: min(70vh, 560px);
    overflow: auto;
    z-index: 40;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 26px 60px -30px rgba(var(--black-rgb),0.8);
    padding: 8px;
}

.chat-history-popup[hidden] { display: none; }

.chat-sidebar-shelf {
    margin: 10px 8px 4px;
    font-size: 0.68rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

/* Search: Rusty's entries */
.search-result-pug { width: 22px; height: 22px; border-radius: 50%; display: block; }
.search-result-rusty { background: color-mix(in oklab, var(--color-primary) 7%, transparent); }
.search-result-rusty-hint { color: var(--color-primary); }

.chat-topbar-follow {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 8px);
    background: var(--color-surface);
    color: var(--color-text);
    padding: 5px 8px;
    font-size: 0.75rem;
    white-space: nowrap;
    cursor: pointer;
}
.chat-topbar-follow[hidden] { display: none; }

/* The out-of-tokens treat button. The base rule in bedrock.css lost to the theme's link colour
   ([data-theme] a, which outranks a lone class), so the text came out the same colour as the
   pill: a blank, oversized cyan lozenge breaking the sentence in two. This selector outranks
   every theme's link rule, and the button sits on its own line at button size. */
.chat-message-content a.chat-exhausted-treat,
.chat-message-content a.chat-exhausted-treat:visited {
    display: flex;
    width: fit-content;
    align-items: center;
    margin: 0.6rem 0 0.2rem;
    padding: 0.35rem 0.9rem;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-primary);
    background: var(--color-primary);
    color: var(--color-primary-text, var(--color-white));
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    text-shadow: none;
    box-shadow: none;
}

.chat-message-content a.chat-exhausted-treat:hover,
.chat-message-content a.chat-exhausted-treat:focus-visible {
    color: var(--color-primary-text, var(--color-white));
    filter: brightness(1.08);
    text-decoration: none;
}

/* Fresh chat sits beside send, quiet like the attach button. */
.chat-fresh-btn[hidden] { display: none; }

/* Expanded out of a page's column: the way back to that page. */
.chat-topbar-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 40%;
    padding: 4px 10px 4px 6px;
    border-radius: var(--radius-md, 8px);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 0.85rem;
    text-decoration: none;
    white-space: nowrap;
}
.chat-topbar-back span { overflow: hidden; text-overflow: ellipsis; }
.chat-topbar-back:hover { border-color: var(--color-primary); color: var(--color-primary); text-decoration: none; }

/* Side column to full width (+ or a free-floating chat) and back (show_page). */
@media (prefers-reduced-motion: no-preference) {
    .rusty-column { transition: flex-basis 0.36s ease, width 0.36s ease; }
    html.rusty-expanding .rusty-column { flex-basis: 100%; width: 100%; }
    html.rusty-expanding .wiki-shell--rusty .main-content { opacity: 0.25; transition: opacity 0.3s ease; }
    .chat-shell { max-width: 100%; transition: max-width 0.36s ease, margin 0.36s ease; }
    .chat-shell.chat-shell-shrinking { max-width: clamp(320px, 31%, 500px); margin-left: auto; }
}

/* Rusty's entry at the top of the wiki tree: a tree row, with his face for the icon. */
.tree-item-rusty .tree-rusty-pug { width: 18px; height: 18px; border-radius: 50%; display: block; object-fit: cover; }
.tree-item-rusty { margin-bottom: 4px; }

/* Rusty sniffing out an answer: what a reader sees instead of the model's thinking. One line,
   theme colours, a gentle nose bob that stops for reduced motion and when the answer starts. */
.chat-sniffing {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 2px 0 8px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-sniffing-count { color: var(--color-primary); font-variant-numeric: tabular-nums; }
.chat-sniffing-done { font-size: 0.78rem; opacity: 0.8; }
.chat-sniffing-done .chat-sniffing-nose { display: none; }
.chat-sniffing-done .chat-sniffing-count { color: var(--color-text-muted); }
@media (prefers-reduced-motion: no-preference) {
    .chat-sniffing:not(.chat-sniffing-done) .chat-sniffing-nose { display: inline-block; animation: chat-sniff 1.1s ease-in-out infinite; }
}
@keyframes chat-sniff {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-2px) rotate(-8deg); }
}

/* The portrait, name and tint describe the active Rusty mode together. */
.chat-shell[data-rusty-mode] { --rusty-mode-color: var(--color-primary); }
.chat-shell[data-rusty-mode="chat"] { --rusty-mode-color: rgb(var(--brand-magenta-rgb)); }
.chat-shell[data-rusty-mode="workshop"] { --rusty-mode-color: var(--warning); }
.chat-shell[data-rusty-mode="training"] { --rusty-mode-color: color-mix(in srgb, rgb(var(--brand-magenta-rgb)) 50%, var(--rs-accent-blue)); }
.chat-shell[data-rusty-mode] .chat-main {
    background: linear-gradient(155deg, color-mix(in srgb, var(--rusty-mode-color) 13%, var(--color-bg)), var(--color-bg) 70%);
}
.chat-shell[data-rusty-mode] .chat-topbar {
    background: color-mix(in srgb, var(--rusty-mode-color) 10%, var(--color-surface));
    border-bottom-color: color-mix(in srgb, var(--rusty-mode-color) 40%, var(--color-border));
}
.chat-topbar-title { min-width: 0; font-size: 0.85rem; }
.chat-topbar-pug, .chat-topbar-btn { flex-shrink: 0; }
.chat-shell .chat-topbar-follow,
.chat-shell .chat-topbar-back,
.chat-shell .chat-topbar-back:visited {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}
.chat-shell .chat-topbar-follow:hover,
.chat-shell .chat-topbar-back:hover {
    background: var(--accent-hover);
    color: var(--on-accent);
}
.chat-pug-emoji[src*="/rusty-"],
.chat-empty-state-icon[src*="/rusty-"],
.chat-welcome-icon[src*="/rusty-"] { border-radius: 50%; }

.chat-shell[data-rusty-persona] { --rusty-mode-color: var(--rusty-persona-colour); }
.chat-persona-status { font-size: 0.75rem; color: var(--color-text-muted); }
.chat-persona-status[hidden] { display: none; }
