/* Page-specific layout. Shared controls and palettes come from styles.css.
   Three panes, like a chat assistant: conversation history on the left,
   newest first, the conversation in the middle with the composer at the
   bottom, and a document panel on the right for the guide, files, and long
   messages. Surfaces use the page background; code uses the theme's code
   tokens, so the light palette and dark mode both apply. */
#messages [hidden] { display: none !important; }
/* Script-limited font faces preserve the site's Latin typography. The same
   licensed font is bundled locally inside the isolated Markdown renderer. */
#messages { --msg-font: "Vazirmatn Persian", "Persian Tahoma", var(--site-font-body); font-family: var(--msg-font); }
#messages .msg-rich, #messages .msg-rich :is(p,h1,h2,h3,h4,h5,h6,li,blockquote),
#messages .ql-editor, #messages .ql-editor :is(p,h1,h2,h3,h4,h5,h6,li,blockquote),
#messages .msg-preview-summary, #messages :is(h1,h2,h3,h4,h5,h6,button,input,textarea) { font-family: var(--msg-font); }
#messages .msg-rich [dir="rtl"], #messages .ql-editor [dir="rtl"] { line-height: 1.85; letter-spacing: normal; }
/* Full window, without the site menu (app-mode.css hides it). A slim top bar
   carries the way home, the status line, privacy notes, and the profile. */
.msg-shell { display: flex; flex-direction: column; gap: 8px; padding: 8px 12px 12px; }
.msg-topbar { flex: 0 0 auto; display: flex; align-items: center; gap: 14px; min-height: 36px; }
.msg-pill { position: static; margin: 0; flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--site-control-border); border-radius: 8px; }
#messages .tool-status { flex: 1 1 auto; min-width: 0; margin: 0; font-size: .85rem; color: var(--bs-secondary-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#messages .tool-status:empty { display: block; }
.msg-pop { position: relative; flex: 0 0 auto; align-self: center; margin: 0; line-height: 1.2; }
.msg-pop > summary, .msg-agent summary, .msg-files details summary { cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--bs-secondary-color); }
.msg-pop > summary { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-pop-body { position: absolute; z-index: 40; top: calc(100% + 8px); right: 0; width: min(26rem, calc(100vw - 24px)); padding: .8rem 1rem; border: 1px solid var(--site-control-border); border-radius: 10px; background: var(--site-surface); box-shadow: 0 6px 22px rgba(0, 0, 0, .18); }
.msg-pop-body ul { margin: 0; padding-inline-start: 1.2rem; }
.msg-pop-body .tool-label { margin-top: 0; }
.msg-pop-body .tool-input { padding: 6px 10px; font-size: 14px; }
.msg-login { margin: auto; max-width: 34rem; padding: 1.5rem; text-align: center; }
.msg-login .tool-actions { justify-content: center; }

/* Chat window */
/* Keep the history compact. Chat receives 40% of the remaining desktop
   width, twice its previous share, with a readable 360px minimum for both panes. Narrow
   screens use the existing tap-to-open document overlay. */
.msg-app { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 280.5px minmax(360px, 2fr) 7px var(--msg-preview-width, minmax(360px, 3fr)); grid-template-rows: minmax(0, 1fr); border: 1.5px solid var(--site-control-border); border-radius: 12px; overflow: hidden; background: transparent; }
.msg-split { cursor: col-resize; touch-action: none; background: transparent; border-inline: 1px solid transparent; transition: background .15s; }
.msg-split::after { content: ""; display: block; width: 1.5px; height: 100%; margin: 0 auto; background: var(--site-control-border); }
.msg-split:hover, .msg-split:focus-visible, .msg-split.msg-dragging { background: var(--site-accent-soft); outline: none; }
.msg-split:hover::after, .msg-split:focus-visible::after, .msg-split.msg-dragging::after { background: var(--site-accent); }
#msg-panel-close { display: none; }
.msg-panel-empty { margin: 2rem auto; text-align: center; }

#messages .msg-app h2 { border-bottom: 0; padding-bottom: 0; }
/* Honey echoes the pale-gold page; slate blue supplies a quiet cool contrast.
   Clay distinguishes assistant replies. Dark mode retains these hue roles
   on deeper surfaces instead of inverting the light colors. Explicit sRGB
   values keep rendering predictable. Body text exceeds 7:1 and metadata
   exceeds 4.5:1 in both modes. Names, placement, and the AI label identify
   senders independently of these decorative hues. */
#messages {
  --msg-mine-bg: #F6E5BE; --msg-mine-border: #CBB37D;
  --msg-peer-bg: #E7EDF5; --msg-peer-border: #B7C5D7;
  --msg-assistant-bg: #F1E6E0; --msg-assistant-border: #CDB5AB;
  --msg-meta: #555A5D; --msg-selected-bg: rgba(128, 128, 128, .14);
}
body.quarto-dark #messages {
  --msg-mine-bg: #3E3426; --msg-mine-border: #7A694B;
  --msg-peer-bg: #293746; --msg-peer-border: #586E85;
  --msg-assistant-bg: #3E2E32; --msg-assistant-border: #80616A;
  --msg-meta: #C9CDD3; --msg-selected-bg: rgba(255, 255, 255, .09);
}

/* History column */
.msg-sidebar { min-height: 0; display: flex; flex-direction: column; padding: .8rem; gap: .6rem; background: transparent; border-inline-end: 1.5px solid var(--site-control-border); }
.msg-sidebar-head { display: flex; }
#msg-new { flex: 1 1 auto; justify-content: flex-start; padding: 8px 12px; font-size: 14px; }
.msg-sidebar-head h2 { margin: 0; font-size: .95rem; font-weight: 600; color: var(--bs-secondary-color); }
.msg-new-panel { padding: .6rem; border: 1.5px solid var(--site-control-border); border-radius: 8px; }
.msg-new-panel .tool-label { margin-top: 0; }
.msg-new-panel .tool-input { padding: 6px 10px; font-size: 14px; }
.msg-new-panel .tool-note { margin: .4rem 0 0; }
.msg-people { list-style: none; margin: .5rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .4rem; }
.msg-people li { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; overflow-wrap: anywhere; }
.msg-inbox { flex: 1 1 auto; min-height: 0; overflow-y: auto; list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-inbox button { display: flex; flex-direction: column; align-items: stretch; width: 100%; padding: .5rem .65rem; border: 0; border-radius: 8px; background: transparent; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.msg-inbox button:hover { background: var(--site-accent-muted); }
.msg-inbox button[aria-current="true"] { background: var(--msg-selected-bg); }
.msg-inbox-peer { font-size: .9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-inbox-title { font-size: .8rem; color: var(--bs-secondary-color); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-empty { margin: 0; }

/* Conversation column */
.msg-conversation { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.msg-thread-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .7rem 1rem; border-bottom: 1px solid var(--site-control-border); }
.msg-thread-heading { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: .2rem .8rem; }
.msg-thread-heading h2 { margin: 0; font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }
.msg-thread-heading .tool-note { margin: 0; font-size: .78rem; }
.msg-thread-heading .tool-note:empty { display: none; }
.msg-conversation > .tool-warning { margin: .6rem 1rem 0; }
.msg-agent { margin: 0; padding: .5rem 1rem; border-bottom: 1px solid var(--site-control-border); }
.msg-agent .tool-note { margin: .4rem 0; }
.msg-request-status { margin: .5rem 0 0; padding-block-start: .4rem; border-block-start: 1px solid currentColor; color: var(--msg-meta); font-size: .78rem; overflow-wrap: anywhere; }
.msg-task-card { max-width: 100%; min-width: 0; border-inline-start: 4px solid var(--site-accent); }
.msg-task-card p { margin: .35rem 0; font-size: .8rem; }
.msg-task-card pre, .msg-task-card code { font-size: .75rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-task-card .tool-button { max-width: 100%; margin-block-start: .35rem; padding: .3rem .5rem; white-space: normal; overflow-wrap: anywhere; font-size: .8rem; }
.msg-task-card summary { cursor: pointer; font-size: .8rem; }
.msg-assistant-mode { display: inline-flex; gap: .3rem; align-items: center; font-size: .8rem; }
.msg-agent-owner .tool-input { max-width: 7rem; padding: 6px 10px; font-size: 14px; }

/* Messages, oldest at the top and newest at the bottom */
.msg-feed { flex: 1 1 0; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; gap: .8rem; padding: 1rem; }
.msg-feed:empty::before { content: attr(data-empty); margin: auto; color: var(--bs-secondary-color); font-size: .9rem; }
.msg-new-messages { align-self: center; margin: .25rem .5rem; padding: .25rem .6rem; font-size: .8rem; }
.msg-card { padding: .6rem .9rem; border: 1px solid var(--msg-peer-border); border-radius: 14px; border-end-start-radius: 4px; background: var(--msg-peer-bg); max-width: min(80%, 760px); align-self: start; overflow-wrap: anywhere; }
.msg-card.msg-mine { align-self: end; background: var(--msg-mine-bg); border-color: var(--msg-mine-border); border-end-start-radius: 14px; border-end-end-radius: 4px; }
.msg-card.msg-assistant { background: var(--msg-assistant-bg); border-color: var(--msg-assistant-border); }
.msg-chip { display: flex; align-items: center; justify-content: space-between; gap: .8rem; width: min(100%, 22rem); border-radius: 10px; border-inline-start: 4px solid var(--site-accent); background: transparent; }
.msg-card header { display: flex; gap: .5rem; flex-wrap: wrap; align-items: baseline; margin-bottom: .2rem; font-size: .75rem; color: var(--msg-meta); }
.msg-card header strong { color: var(--bs-body-color); font-size: .8rem; }
.msg-card-actions { display: inline-flex; gap: .3rem; margin-inline-start: auto; }
@media (hover: hover) {
  .msg-card .msg-card-actions { opacity: 0; transition: opacity .15s; }
  .msg-card:hover .msg-card-actions, .msg-card:focus-within .msg-card-actions { opacity: 1; }
}
.msg-armed, .msg-armed:hover { border-color: #b42318; color: #b42318; }
.msg-card-actions .tool-button { padding: 1px 8px; font-size: 12px; }
/* Reactions release 2026-10-08. Native picker expands inside the bubble, including narrow touch screens.
   Shared palette tokens keep chips readable in light and dark mode. */
.msg-reactions { display: flex; flex-wrap: wrap; align-items: start; gap: .3rem; margin-top: .45rem; }
.msg-reaction-picker { margin: 0; min-width: 0; max-width: 100%; }
.msg-reaction-picker > summary { cursor: pointer; padding: .3rem .5rem; color: var(--msg-meta); font-size: .75rem; border-radius: 8px; }
.msg-reaction-choices { display: flex; flex-wrap: wrap; gap: .3rem; padding-top: .3rem; }
#messages .msg-reaction { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-width: 36px; min-height: 36px; padding: .25rem .5rem; border: 1px solid var(--site-control-border); border-radius: 999px; background: transparent; color: var(--bs-body-color); font: inherit; cursor: pointer; }
#messages .msg-reaction:hover { background: var(--msg-selected-bg); }
#messages .msg-reaction[aria-pressed="true"] { border-color: var(--site-accent); background: var(--msg-selected-bg); box-shadow: inset 0 0 0 1px var(--site-accent); }
.msg-reaction-count { font-size: .75rem; }
.msg-reaction:focus-visible, .msg-reaction-picker > summary:focus-visible { outline: 2px solid var(--site-accent); outline-offset: 2px; }
@media (forced-colors: active) { #messages .msg-reaction[aria-pressed="true"] { border: 2px solid Highlight; } }
.msg-card h3, .msg-card h4 { margin-block: .8rem .4rem; }
.msg-message-preview { display: flex; flex-direction: column; gap: .35rem; width: 100%; padding: .15rem 0; border: 0; background: transparent; color: inherit; font: inherit; text-align: start; cursor: pointer; }
.msg-preview-summary { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.msg-preview-label { font-size: .75rem; color: var(--msg-meta); }
.msg-message-preview:focus-visible { outline: 2px solid var(--site-accent); outline-offset: 4px; border-radius: 4px; }
.msg-preview-selected { box-shadow: 0 0 0 2px var(--site-accent-ring); }
.msg-preview-selected .msg-preview-label { color: var(--site-accent); }
.msg-file p { margin: .2rem 0 .4rem; font-size: .85rem; color: var(--msg-meta); }
.msg-rich p { margin-block: .2rem; white-space: pre-wrap; }
.msg-rich pre { direction: ltr; text-align: left; white-space: pre-wrap; color: var(--site-code-fg); background: var(--site-code-bg); border: 1px solid var(--site-code-border); padding: .8rem; border-radius: 8px; }
.msg-rich code { padding: 0 .25em; border-radius: 4px; color: var(--site-inline-code-fg); background: var(--site-inline-code-bg); }
.msg-rich pre code { padding: 0; color: inherit; background: none; }
.msg-rich blockquote { border-inline-start: 3px solid var(--site-accent); padding-inline-start: .8rem; }
.msg-rich ul, .msg-rich ol { margin-block: .4rem; padding-inline-start: 1.7rem; }

/* Composer. Nothing in the conversation column shrinks; the feed has its own height. */
.msg-conversation > :not(.msg-feed) { flex-shrink: 0; }
.msg-files { max-height: 45%; overflow-y: auto; }
#messages .ql-container { height: auto; }
.msg-compose { padding: .6rem 1rem .4rem; border-top: 1px solid var(--site-control-border); }
.msg-compose-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: .5rem; }
.msg-bar-gap { flex: 1 1 auto; }
.msg-format { font-weight: 700; min-width: 2.4rem; }
.msg-format[aria-pressed="true"] { border-color: var(--site-accent); color: var(--site-accent); }
/* The toolbar stays out of sight until Aa is pressed. */
#msg-compose:not(.msg-formatting) .ql-toolbar { display: none; }
#msg-compose:not(.msg-formatting) .ql-container { border-top: 1px solid var(--bs-border-color); border-radius: 10px; }
.msg-files { padding: .6rem 1rem .8rem; border-top: 1px dashed var(--site-control-border); }
.msg-files h3 { margin: 0 0 .4rem; font-size: .85rem; font-weight: 600; color: var(--bs-secondary-color); }
.msg-files .tool-input { padding: 6px 10px; font-size: 14px; }
.msg-files details { margin-top: .4rem; }
.msg-check { display: flex; align-items: center; gap: .5rem; margin-block: .6rem; font-size: .9rem; }
#msg-editor { font-family: inherit; font-size: 1rem; }
#messages .ql-toolbar { border-radius: 8px 8px 0 0; background: transparent; padding: 4px 6px; }
#messages .ql-container { border-radius: 0 0 8px 8px; color: var(--bs-body-color); border-color: var(--bs-border-color); }
#messages .ql-toolbar { border-color: var(--bs-border-color); }
#messages .ql-picker-options { border-color: var(--bs-border-color); background: var(--site-surface); }
#messages .ql-picker, #messages .ql-picker-label { color: var(--bs-body-color); }
#messages .ql-stroke { stroke: var(--bs-body-color); }
#messages .ql-fill { fill: var(--bs-body-color); }
#messages .ql-editor { min-height: 64px; max-height: 30vh; overflow-y: auto; }
#messages .ql-editor.ql-blank::before { color: var(--bs-secondary-color); }
#messages .ql-editor pre, #messages .ql-code-block-container { direction: ltr; text-align: left; }

/* Document panel */
.msg-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.msg-panel-head { display: flex; align-items: center; flex-wrap: wrap; gap: .25rem .5rem; padding: .35rem .65rem; border-bottom: 1px solid var(--site-control-border); }
.msg-panel-head h2 { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-panel-actions { display: inline-flex; gap: .3rem; }
.msg-panel-tabs { display: flex; gap: .3rem; padding: 0; }
.msg-panel-tabs:not(:has(button:not([hidden]))) { display: none; }
.msg-tab { padding: .15rem .35rem; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--bs-secondary-color); font: inherit; font-size: .75rem; cursor: pointer; }
.msg-tab[aria-pressed="true"] { color: var(--bs-body-color); border-bottom-color: var(--site-accent); }
.msg-panel-meta { color: var(--bs-secondary-color); font-size: .7rem; white-space: nowrap; }
.msg-panel-meta:empty { display: none; }
.msg-panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: .35rem .7rem; overflow-wrap: anywhere; }
.msg-panel-body > .tool-note:first-child { margin-top: 0; }
/* Let the isolated renderer use the complete panel below its header. The
   frame owns document scrolling, so the parent does not add a second scroll. */
.msg-panel-body:has(> .msg-render-frame) { display: flex; flex-direction: column; overflow: hidden; }
.msg-render-frame { display: block; flex: 1 1 0; width: 100%; min-height: 0; height: 100%; margin: 0; border: 0; border-radius: 8px; }
.msg-panel-body .msg-rich h3 { font-size: 1.3rem; }
.msg-panel-body .msg-rich h4 { font-size: 1.1rem; }
.msg-person-actions { display: flex; gap: 6px; }
.msg-group-form { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--site-control-border); }
.msg-group-people { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.msg-chip-person { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border: 1px solid var(--site-control-border); border-radius: 999px; font-size: .85rem; }
.msg-chip-person .tool-button { padding: 0 6px; border: 0; background: none; font-size: 15px; }
.msg-member-list { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.msg-member-list li { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .45rem .7rem; border: 1px solid var(--site-control-border); border-radius: 8px; }
.msg-group-manage { margin-bottom: .8rem; }
.msg-group-manage .tool-input { padding: 6px 10px; font-size: 14px; }
.msg-file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .6rem; }
.msg-file-list li { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .8rem; padding: .6rem .8rem; border: 1px solid var(--site-control-border); border-radius: 10px; }
.msg-file-list li strong { flex: 1 1 100%; font-size: .9rem; }

/* Narrower screens: the panel covers the conversation until closed */
@media (max-width: 1100px) {
  .msg-app { grid-template-columns: 221px minmax(0, 1fr); }
  .msg-split { display: none; }
  .msg-app:not(.msg-panel-open) .msg-panel { display: none; }
  #msg-panel-close { display: inline-flex; }
  .msg-panel { position: fixed; inset: 0; z-index: 1100; height: auto; min-height: 0; border: 0; background: var(--site-surface); }
}

/* Phones: history above the conversation, each with its own height */
@media (max-width: 800px) {
  .msg-shell { overflow-y: auto; }
  .msg-topbar { flex-wrap: wrap; gap: 8px 12px; }
  #messages .tool-status { flex-basis: 100%; order: 5; white-space: normal; }
  .msg-app { flex: 0 0 auto; grid-template-rows: auto; }
  .msg-app, .msg-app.msg-panel-open { grid-template-columns: 1fr; }
  .msg-sidebar { height: auto; min-height: 0; border-inline-end: 0; border-bottom: 1.5px solid var(--site-control-border); }
  .msg-inbox { max-height: 220px; }
  .msg-feed { flex: none; height: clamp(240px, 60vh, 560px); }
  .msg-card { max-width: 92%; }
}
/* The command result is local to the authenticated viewer, outside stored chat. */
.msg-bill { padding: .8rem 1rem; margin: .5rem 0; border: 1px solid var(--site-accent); border-radius: .6rem; background: var(--site-surface); max-height: 18rem; overflow: auto; }
.msg-bill header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.msg-bill p, .msg-bill ul { margin: .5rem 0; }
/* Status meaning stays visible in text as well as color in both themes. */
#messages .msg-bill-checked { color: #17653a; font-weight: 600; }
#messages .msg-bill-next-refresh { color: #a32525; font-weight: 600; }
body.quarto-dark #messages .msg-bill-checked { color: #82d6a3; }
body.quarto-dark #messages .msg-bill-next-refresh { color: #ff9b96; }
.msg-command-hint { margin: .35rem .6rem; }

/* Unread state uses both a count and an accessible label, not color alone. */
.msg-unread-total, .msg-unread-badge { display: inline-flex; align-items: center; justify-content: center; border-radius: 999px; background: var(--site-accent); color: var(--site-accent-contrast); font-size: .75rem; font-weight: 600; padding: .12rem .5rem; white-space: nowrap; }
.msg-unread-total { flex: 0 0 auto; }
.msg-inbox-peer-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.msg-inbox-peer-row .msg-inbox-peer { min-width: 0; }
.msg-notice { position: fixed; z-index: 60; inset-block-start: 3.5rem; inset-inline-end: 1rem; max-width: calc(100vw - 2rem); display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .7rem; border: 1.5px solid var(--site-accent); border-radius: 10px; background: var(--site-surface); color: var(--bs-body-color); box-shadow: 0 4px 18px rgba(0,0,0,.15); }
.msg-notice .tool-button { font-size: .8rem; padding: .3rem .6rem; }
@media (max-width: 600px) { .msg-unread-total { font-size: .65rem; padding: .1rem .35rem; } .msg-topbar { gap: .5rem; } }

/* Staged filenames remain readable in the narrow conversation column. */
#msg-file-name { overflow-wrap: anywhere; }
