/* Conversation geometry: the log takes the space left by real content. */
#nodeCommentsPanel { container-type: size; container-name: chat-panel; }
/* Discord's sizes (Mikko 27.10.2026: "pitäisi kyllä isontaa tekstejä ja emoja
   yms entisestään. chatissa napit yms on liian pientä" — "discord on hyvä refe"):
   its text 16 px where ours was 14, buttons about 40. One scale for the whole
   conversation — words, names, faces, buttons, emoji — on a desktop, as the
   toolbar's comfort scale (app.css); DragPanel and HistoryView measure it. Its
   place is said in the screen's pixels: top and bottom divided by the scale. */
/* Its width by its right edge (chat/PanelWidth.js, Mikko 28.10.2026: "pitäisikö
   chat paneeli olla myös resize?"): --chat-panel-w in its own pixels, the
   window caps it, and closed it slides out by it — the side panel's -460 px
   would leave a wider one showing. */
@media (min-width: 769px) {
    #nodeCommentsPanel { width: min(var(--chat-panel-w, 440px), calc(100vw - 40px)); left: calc(-1 * min(var(--chat-panel-w, 440px), calc(100vw - 40px)) - 40px); }
}
@media (min-width: 769px) and (min-height: 501px) {   /* (a short landscape screen keeps the full-width layout below, unscaled) */
    #nodeCommentsPanel { zoom: 1.15; top: calc(130px / 1.15); bottom: calc(140px / 1.15);
        width: min(var(--chat-panel-w, 440px), calc((100vw - 40px) / 1.15)); left: calc(-1 * min(var(--chat-panel-w, 440px), calc((100vw - 40px) / 1.15)) - 40px); }
    #nodeCommentsPanel.open { left: calc(20px / 1.15); }
}
/* The edge you take it by: just outside the panel, clear of the log's scrollbar. */
#nodeCommentsPanel .chat-resize-handle { position: absolute; top: 14px; bottom: 14px; right: -6px; width: 10px; cursor: ew-resize; z-index: 6; touch-action: none; }
#nodeCommentsPanel .chat-resize-handle::after { content: ''; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px; border-radius: 1px; background: transparent; transition: background 0.15s ease; }
@media (hover: hover) { #nodeCommentsPanel .chat-resize-handle:hover::after { background: rgba(var(--ui-accent-rgb), 0.55); } }
#nodeCommentsPanel.chat-resizing .chat-resize-handle::after { background: rgba(var(--ui-accent-rgb), 0.85); }
#nodeCommentsPanel.chat-resizing { user-select: none; }
#nodeCommentsPanel.chat-fullscreen .chat-resize-handle { display: none; }
@media (max-width: 768px), (max-width: 950px) and (max-height: 500px) {
    #nodeCommentsPanel .chat-resize-handle { display: none; }
}
/* Full screen on a desktop too (Mikko 28.10.2026: "Voisiko chat ikkunassa olla
   fullscreen moodi?" — it was the phone's alone): the whole window under the
   toolbar, the panel's own 20 px around it. Closed, it slides a whole window
   out, not the side panel's 460 px, or the rest of it would still show. Under
   the scale its place is said in the scale's pixels, as above. (A phone's:
   app.css.) */
@media (min-width: 769px) {
    #nodeCommentsPanel.chat-fullscreen { top: calc(var(--toolbar-height, 60px) + 8px); bottom: 16px; left: -100vw; width: calc(100vw - 40px); max-width: none; }
    #nodeCommentsPanel.chat-fullscreen.open { left: 20px; }
    /* What is left over it: a toast comes over the chat — it is often the
       chat's own (the AI asleep, a send failed); the coordinates, of a canvas
       now out of sight, would sit on the panel's × ; the SmartBar on the
       composer. */
    body:has(#nodeCommentsPanel.chat-fullscreen.open) .info-widget.toast-active { z-index: var(--z-panel, 1000); }
    body:has(#nodeCommentsPanel.chat-fullscreen.open) #locationContainer,
    body:has(#nodeCommentsPanel.chat-fullscreen.open) #smartBar { display: none !important; }
    #nodeCommentsPanel[data-drag-held] [data-drag-handle] { cursor: default !important; }
}
@media (min-width: 769px) and (min-height: 501px) {
    #nodeCommentsPanel.chat-fullscreen { top: calc((var(--toolbar-height, 60px) + 8px) / 1.15); bottom: calc(16px / 1.15); left: calc(-100vw / 1.15); width: calc((100vw - 40px) / 1.15); }
    #nodeCommentsPanel.chat-fullscreen.open { left: calc(20px / 1.15); }
}
#spaceChatTabContent, #directChatTabContent {
    position: absolute;
    inset: var(--chat-header-height, 66px) 0 0;
    min-height: 0;
}
#spaceChatTabContent[style*="block"], #dmActiveView[style*="block"] {
    display: flex !important;
    flex-direction: column;
    min-height: 0;
}
#dmActiveView { height: 100%; }
#spaceChatSearchBar { top: 0 !important; }
#spacePinnedPill { top: 8px !important; }
#spacePinnedPopover { top: 40px !important; }
#spaceChatMessages, #directChatMessages {
    position: relative !important;
    inset: auto !important;
    flex: 1;
    min-height: 0;
    overscroll-behavior: contain;
    overflow-anchor: auto;
}
#spaceChatTyping, #directChatTyping {
    position: relative !important;
    inset: auto !important;
    flex: none;
    height: 16px;
    margin: 0 12px 4px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
#spaceChatTyping:empty, #directChatTyping:empty { display: none; }
#nodeCommentsPanel .chat-composer {
    position: relative !important;
    inset: auto !important;
    flex: none;
    min-width: 0;
    max-height: 70%;
    overflow-y: auto;
    padding: 8px 12px max(10px, env(safe-area-inset-bottom)) !important;
}
#nodeCommentsPanel .chat-composer-field {
    display: grid;
    grid-template-columns: repeat(4, 36px) 1fr;
    gap: 2px;
    padding: 4px;
    border-radius: 12px;
}
#nodeCommentsPanel .chat-composer-field:focus-within {
    border-color: var(--ui-accent);
    box-shadow: 0 0 0 2px rgba(var(--ui-accent-rgb), .12);
}
#nodeCommentsPanel .chat-composer-field textarea {
    grid-column: 1 / -1;
    width: 100%;
    box-sizing: border-box;
    font-size: 14px !important;
    line-height: 1.45;
    max-height: 120px !important;
}
#nodeCommentsPanel .chat-composer-field textarea:focus-visible { outline: none; }
#nodeCommentsPanel .chat-composer-field .chat-input-btn {
    width: 36px;
    height: 36px;
    color: var(--ui-text-muted);
}
#nodeCommentsPanel .chat-message-text:not(.chat-jumbo) { font-size: 14px !important; line-height: 1.55 !important; }
#nodeCommentsPanel .chat-message-text { overflow-wrap: anywhere; }
#nodeCommentsPanel .chat-message-text pre { max-width: 100%; overflow-x: auto; }
#nodeCommentsPanel .chat-attachments { min-width: 0; }
#nodeCommentsPanel .chat-attachments > div { max-width: 100% !important; }
#nodeCommentsPanel .chat-attachments img { max-width: 100% !important; }
#nodeCommentsPanel :is(button, textarea, [tabindex]):focus-visible, .message-actions button:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 2px;
}
.chat-history-state { padding: 24px 18px; color: var(--ui-text-muted); font-size: 14px; line-height: 1.5; text-align: center; }
.chat-history-state button { display: block; margin: 10px auto 0; }

/* Who reads the room's chat (chat/SpaceAudience.js, Mikko 30.9.). */
/* A thin line under the header, a flex child of the pane above the log. */
.chat-here-strip {
    flex: none; align-items: center; gap: 0; width: 100%; min-height: 30px; padding: 4px 14px;
    border: 0; border-bottom: 1px solid var(--ui-border-faint); background: transparent;
    color: var(--ui-text-muted); font: inherit; font-size: 11.5px; text-align: left; cursor: pointer; white-space: nowrap;
}
.chat-here-strip:hover { background: rgba(var(--ui-accent-rgb), 0.06); color: var(--ui-text); }
.chat-here-count { flex: none; color: var(--ui-text); }
.chat-here-note { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; padding-left: 5px; color: var(--ui-text-dim); }
/* The pinned pill floats at the pane's top right: clear of the line. */
#spaceChatTabContent:has(> .chat-here-strip[style*="flex"]) #spacePinnedPill { top: 38px !important; }
#spaceChatTabContent:has(> .chat-here-strip[style*="flex"]) #spacePinnedPopover { top: 70px !important; }
.chat-here-face {
    display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: none;
    border-radius: 50%; font-size: 16px; line-height: 1; background: rgba(var(--ui-surface-rgb), 1);
    box-shadow: 0 0 0 1.5px rgba(var(--ui-surface-rgb), 1); overflow: hidden;
}
.chat-here-strip .chat-here-face { width: 18px; height: 18px; font-size: 14px; }
.chat-here-strip .chat-here-face + .chat-here-face { margin-left: -5px; }
.chat-here-face + .chat-here-count { padding-left: 6px; }
.chat-here-menu { max-width: 300px; }
.chat-here-menu-note { padding: 9px 14px 8px; font-size: 11.5px; line-height: 1.45; color: var(--ui-text-muted); border-bottom: 1px solid var(--ui-border-faint); margin-bottom: 4px; }
.chat-here-menu-empty { padding: 8px 14px; font-size: 12px; color: var(--ui-text-dim); }
.chat-here-menu-row {
    display: flex; align-items: center; gap: 9px; width: 100%; min-height: 40px; padding: 6px 14px;
    border: 0; background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.chat-here-menu-row:hover { background: rgba(var(--ui-accent-rgb), 0.1); }
.chat-here-menu-row .chat-here-face { width: 26px; height: 26px; font-size: 21px; }
.chat-here-menu-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-here-menu-go { display: inline-flex; color: var(--ui-text-dim); }
/* A name or face in the room's chat opens that person's menu. */
#spaceChatMessages .chat-msg:not([data-own]) :is(.chat-msg-sender, .chat-sender-avatar) { cursor: pointer; }
#spaceChatMessages .chat-msg:not([data-own]) .chat-msg-sender:hover { text-decoration: underline; text-underline-offset: 2px; }
/* The room's chat narrowed to two: the way to Direct, offered above the field. */
.chat-direct-hint { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.chat-direct-hint-go {
    flex: 1; min-width: 0; display: inline-flex; align-items: center; gap: 7px; min-height: 32px; padding: 5px 11px;
    border: 1px solid rgba(var(--ui-accent-rgb), 0.28); border-radius: 999px; background: rgba(var(--ui-accent-rgb), 0.08);
    color: var(--ui-text); font: inherit; font-size: 12px; text-align: left; cursor: pointer;
}
.chat-direct-hint-go > span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-direct-hint-go:hover { background: rgba(var(--ui-accent-rgb), 0.16); }
.chat-direct-hint-x {
    flex: none; width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent;
    color: var(--ui-text-dim); font-size: 17px; line-height: 1; cursor: pointer;
}
.chat-direct-hint-x:hover { background: rgba(var(--ui-text-rgb), 0.08); color: var(--ui-text); }
.chat-outbox { max-height: 110px; overflow-y: auto; }
.chat-outbox-entry { display: flex; gap: 8px; align-items: center; padding: 7px 0; color: var(--ui-text); font-size: 12px; }
.chat-outbox-entry > span { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-outbox-entry button { flex: none; }
#directChatHeader { flex: none; gap: 8px; }
#directChatHeader > div:first-child, #dmUserChip { min-width: 0; }
/* The person up in the panel's header, beside "← Direct" (ConversationList.js
   wirePersonInHeader): the room between the way back and the panel's buttons. */
#chatHeaderPerson { flex: 1; min-width: 0; align-items: center; }
#chatHeaderPerson #directChatHeader { flex: 1; min-width: 0; padding: 0 !important; border-bottom: 0 !important; }
.chat-person-up #conversationBackBtn { font-size: 0 !important; width: 36px; padding: 0 !important; justify-content: center; }
.chat-person-up #conversationBackBtn::before { content: '←'; font-size: 20px; }
#directChatUserName { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The picker as wide as the panel lets it be and most of its height (Mikko
   27.10.2026: "emojivalikko voisi olla kyllä isompi" — it was 300 × 300), the
   emoji a size larger to hit. (Over ChatSystem's inline 320 × 350.) */
#nodeCommentsPanel .chat-emoji-popup {
    position: absolute !important;
    bottom: calc(var(--space-composer-height, 100px) + 8px) !important;
    left: 12px;
    right: auto !important;
    box-sizing: border-box;
    width: min(440px, calc(100% - 24px));
    max-width: none !important;
    /* (never over the header: what is between it and the composer) */
    max-height: min(460px, calc(100% - var(--chat-header-height, 56px) - var(--space-composer-height, 100px) - 16px)) !important;
}
#nodeCommentsPanel .chat-emoji-popup [data-emoji] { font-size: 28px !important; padding: 5px !important; }
/* A message's reaction picker and its hover bar live on <body>, outside the
   panel's scale: as large as the panel's by their own sizes. */
.chat-reaction-picker [data-emoji] { font-size: 30px !important; padding: 5px !important; }
.message-actions button { padding: 7px 9px !important; }
.message-actions button svg { width: 21px; height: 21px; }
#nodeCommentsPanel #directChatEmojiPicker {
    bottom: calc(var(--dm-composer-height, 100px) + 8px) !important;
    max-height: min(460px, calc(100% - var(--chat-header-height, 56px) - var(--dm-composer-height, 100px) - 16px)) !important;
}
#nodeCommentsPanel:has(#spaceChatTabContent[style*="none"]) #spaceChatEmojiPicker,
#nodeCommentsPanel:has(#directChatTabContent[style*="none"]) #directChatEmojiPicker { display: none !important; }
@media (max-width: 768px) {
    #nodeCommentsPanel {
        height: min(72dvh, calc(100dvh - var(--toolbar-height, 64px) - var(--kb-inset, 0px) - 8px));
        max-height: calc(100dvh - var(--toolbar-height, 64px) - var(--kb-inset, 0px) - 8px);
        padding-bottom: 0;
        box-sizing: border-box;
    }
    #nodeCommentsPanel.chat-fullscreen { height: auto; max-height: none; }
    #nodeCommentsPanel .chat-composer-field { grid-template-columns: repeat(4, 40px) 1fr; }
    #nodeCommentsPanel .chat-composer-field textarea { font-size: 16px !important; }
    /* A phone's messages at Discord's 16 px too (the desktop scales the whole panel, above). */
    #nodeCommentsPanel .chat-message-text:not(.chat-jumbo) { font-size: 16px !important; }
    #nodeCommentsPanel .chat-composer-field .chat-input-btn { width: 40px; height: 40px; }
    #nodeCommentsPanel .chat-send-btn--fab { width: 44px; height: 44px; }
    #conversationBackBtn { font-size: 0 !important; width: 40px; height: 40px; padding: 0 !important; }
    #conversationBackBtn::before { content: '←'; font-size: 24px; }
    #remoteChatVisitBtn { padding: 0 8px !important; }
    #chatHeaderContext { gap: 6px !important; }
    #chatHeaderContext > svg { display: none; }
    #nodeCommentsPanel > div:first-child { padding: 8px !important; gap: 4px !important; }
}
@media (pointer: coarse) {
    .message-actions button { min-width: 44px; min-height: 44px; }
    #spaceChatPending button, #dmChatPending button { min-width: 28px; min-height: 28px; top: 0 !important; right: 0 !important; }
}
@media (max-height: 650px) and (min-width: 769px) {
    #nodeCommentsPanel { top: calc(76px / 1.15); bottom: calc(76px / 1.15); }   /* (its scale: above) */
}
@media (max-height: 500px) {
    #nodeCommentsPanel .chat-composer-field textarea { max-height: 64px !important; overflow-y: auto !important; }
    #nodeCommentsPanel .chat-composer { padding-top: 4px !important; padding-bottom: 4px !important; }
}
@media (max-width: 950px) and (max-height: 500px) {
    #nodeCommentsPanel {
        top: calc(var(--toolbar-height, 64px) + 8px);
        bottom: var(--kb-inset, 0px);
        height: auto;
        max-height: none;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    #nodeCommentsPanel.open { left: 0; }
}
@media (prefers-reduced-motion: reduce) {
    #nodeCommentsPanel, #nodeCommentsPanel *, .message-actions { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
/* A keyboard can leave a very short panel even on a tall layout viewport. */
@container chat-panel (max-height: 320px) {
    #nodeCommentsPanel #spaceChatEmojiPicker, #nodeCommentsPanel #directChatEmojiPicker { top: var(--chat-header-height, 56px); bottom: 4px !important; max-height: none !important; }
    #nodeCommentsPanel > div:first-child { padding: 2px 6px !important; }
    #directChatHeader { padding: 3px 8px !important; }
    #nodeCommentsPanel .chat-composer { padding: 4px 8px !important; }
    #nodeCommentsPanel .chat-composer-field { padding: 2px; grid-template-columns: repeat(4, 30px) 1fr; }
    #nodeCommentsPanel .chat-composer-field textarea { min-height: 32px !important; max-height: 44px !important; padding: 4px 6px !important; overflow-y: auto !important; }
    #nodeCommentsPanel .chat-composer-field .chat-input-btn { width: 30px; height: 30px; }
    #spaceChatReplyIndicator, #directReplyIndicator { padding: 2px 4px !important; margin-bottom: 2px !important; max-height: 20px; overflow: hidden; }
}
/* Canvas references have the same identity for every media type. Regular
   chat attachments deliberately do not carry this frame or navigation. */
.chat-canvas-card {
    display:inline-flex; flex-direction:column; width:300px; max-width:100%;
    margin:6px 0; overflow:hidden; vertical-align:top;
    border:1px solid var(--ui-border-accent); border-radius:10px;
    background:var(--ui-bg-panel, #10252d); text-align:left;
}
.chat-canvas-card-kind { padding:7px 10px; font-size:10px; font-weight:600; color:var(--ui-teal); letter-spacing:.03em; }
.chat-canvas-card > .chat-canvas-card-content { box-sizing:border-box; width:100%; max-width:100% !important; min-width:0 !important; margin:0 !important; border:0 !important; border-radius:0 !important; }
.chat-canvas-card-content > img, .chat-canvas-card-content > video { width:100%; max-width:100% !important; max-height:200px !important; object-fit:contain; border-radius:0 !important; }
.chat-canvas-card-action { display:flex; flex-direction:column; gap:4px; width:100%; padding:9px 10px; border:0; border-top:1px solid var(--ui-border); background:transparent; color:var(--ui-text); text-align:left; cursor:pointer; font:inherit; }
.chat-canvas-card-action strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; max-width:100%; font-size:12px; }
.chat-canvas-card-action > span { font-size:11px; color:var(--ui-accent); }
.chat-canvas-card-action:hover { background:rgba(var(--ui-accent-rgb),.09); }
.chat-canvas-card-action:focus-visible { outline:2px solid var(--ui-accent); outline-offset:-3px; }
.chat-canvas-preview { display:block; background:rgba(var(--ui-text-rgb),.035); }
.chat-canvas-preview > img, .chat-canvas-preview > video { display:block; }
.chat-canvas-preview > audio { display:block; width:100%; height:40px; }
.chat-canvas-file-preview { display:flex; align-items:center; gap:12px; padding:14px; color:var(--ui-text-muted); font:600 14px monospace; }
.chat-canvas-file-preview > img { width:40px; height:40px; object-fit:contain; }
.chat-canvas-note-preview { padding:12px; font-size:12px; color:var(--ui-text-muted); max-height:100px; overflow:hidden; overflow-wrap:anywhere; }
.chat-history-nav { display:block; margin:8px auto; }
.chat-history-latest { position:sticky; bottom:6px; z-index:3; background:var(--ui-bg-panel, #10252d) !important; box-shadow:0 2px 8px #0004; }

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