/* The chat (#/chat): a messenger laid out the way WeChat is. On a computer: the list of chats at the left, the open
 * chat beside it. On a phone: the list is the first screen, and a chat opens over it with a way back.
 * Faces are rounded squares; the other side's words are white bubbles at the left, your own are green at the right;
 * the time and what somebody did sit small and centred. Cards (drawn by code) hang under a helper's bubble.
 * The "back to latest" pill and the file chip are ported from n8n Nod (Apache-2.0); see THIRD-PARTY.md. Loaded last. */
:root { --wx-list: 300px; --wx-head: 56px; --av-risk: #2f5fe0; --av-outreach: #7a4fd6; --av-stock: #0d8f8f; --av-person: #5f6b78; }

/* ---- the pages behind the chat: a slim bar on top, the menu behind its button ---- */
.topbar { display: flex; }
.rail { display: none; inset: 64px 12px auto auto; width: min(20rem, calc(100vw - 24px)); height: auto; max-height: calc(100dvh - 80px); padding: var(--s-4); border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--panel); box-shadow: 0 18px 50px -20px rgb(15 20 25 / 0.4); z-index: 50; }
.rail > .brand { display: none; }
.rail .nav { margin-top: 0; }
.rail .bot { margin-top: var(--s-2); padding-top: var(--s-2); }
body.menu-open .rail { display: flex; }
body.menu-open { overflow: auto; }
.page { margin-left: 0; margin-inline: auto; padding: 5rem 1.5rem 11rem; }
@media (max-width: 899.98px) { .page { padding-inline: var(--s-4); } }

/* ---- the frame of the chat ---- */
body.on-chat .topbar { display: none; }
body.on-chat .rail { inset: calc(var(--wx-head) + 6px) 8px auto auto; }
.page.chat { gap: 14px; max-width: none; margin: 0; padding: calc(var(--wx-head) + var(--s-4)) var(--s-3) 9.5rem; }
.page.chat > * { width: 100%; max-width: 48rem; margin-inline: auto; }
@media (min-width: 900px) {
  /* A computer: the chat fills the room beside the list, the way a desktop messenger does. */
  .page.chat { margin-left: var(--wx-list); padding-inline: var(--s-5); padding-bottom: 11rem; }
  .page.chat > *, body.on-chat .ast-bar { max-width: none; margin-inline: 0; }
  .wx-row > .wx-bub { max-width: min(100%, 42rem); }
  .wx-row > .wx-card { max-width: 54rem; }
  body.on-chat .foot { left: var(--wx-list); padding-inline: var(--s-5); padding-bottom: var(--s-4); }
  body.on-chat .ast-bar textarea { min-height: 76px; }
}

/* ---- faces: a rounded square each ---- */
.wx-av { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 8px; background: var(--av-person); color: #fff; font-weight: 600; line-height: 1; text-decoration: none; }
.av-risk { background: var(--av-risk); } .av-outreach { background: var(--av-outreach); } .av-stock { background: var(--av-stock); }
a.wx-av:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
/* The group's face is its members, small, the way a WeChat group's is. */
.wx-av.av-team { grid-template-columns: 1fr 1fr; gap: 2px; padding: 4px; background: var(--soft); border: 1px solid var(--line); place-items: stretch; }
.wx-av.av-team > span { display: grid; place-items: center; border-radius: 3px; color: #fff; min-height: 0; }
.wx-av.av-team > span:first-child { grid-column: 1 / -1; justify-self: center; width: calc(50% - 1px); }
.wx-av.av-team svg { width: 68%; height: 68%; }

/* ---- the list of chats ---- */
.page.chat > .wx-list { position: fixed; inset: 0 auto 0 0; z-index: 30; display: flex; flex-direction: column; width: var(--wx-list); max-width: none; margin: 0; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.wx-list-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; flex: none; height: var(--wx-head); padding: 0 var(--s-2) 0 var(--s-4); background: var(--panel); border-bottom: 1px solid var(--line); }
.wx-brand { display: flex; align-items: center; gap: var(--s-2); font-size: 1.0625rem; font-weight: 600; }
.wx-more { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border: 0; border-radius: 8px; background: transparent; color: var(--ink); cursor: pointer; }
.wx-more:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
@media (hover: hover) { .wx-more:hover { background: var(--soft); } }
.wx-items { display: grid; }
.wx-item { position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr) auto; column-gap: var(--s-3); row-gap: 2px; align-items: center; padding: var(--s-3) var(--s-4); color: var(--ink); text-decoration: none; transition: background var(--dur) var(--ease); }
.wx-item:hover { text-decoration: none; }
.wx-item + .wx-item::before { content: ""; position: absolute; inset: 0 0 auto 76px; height: 1px; background: var(--line); }
.wx-item[aria-current="page"] { background: color-mix(in srgb, var(--ink) 8%, var(--panel)); }
.wx-item:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.wx-item:active { background: color-mix(in srgb, var(--ink) 8%, var(--panel)); }
@media (hover: hover) { .wx-item:not([aria-current]):hover { background: var(--soft); } }
/* The three boards, under the chats: the way from the first page to the full pages. */
.wx-boards { display: grid; margin-top: auto; padding: var(--s-3) 0 var(--s-4); border-top: 1px solid var(--line); }
.wx-boards-t { margin: 0; padding: var(--s-1) var(--s-4) var(--s-2); font-size: var(--t-xs); font-weight: 600; color: var(--grey); }
.wx-board { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); min-height: 44px; padding: 0 var(--s-3) 0 var(--s-4); color: var(--ink); font-size: var(--t-md); text-decoration: none; transition: background var(--dur) var(--ease); }
.wx-board svg { flex: none; color: var(--grey); }
.wx-board:hover { text-decoration: none; }
.wx-board:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.wx-board:active { background: color-mix(in srgb, var(--ink) 8%, var(--panel)); }
@media (hover: hover) { .wx-board:hover { background: var(--soft); } }
@media (prefers-reduced-motion: reduce) { .wx-board { transition: none; } }
.wx-item-av { position: relative; grid-row: 1 / span 2; }
.wx-item-av .wx-av { width: 48px; height: 48px; border-radius: 10px; }
.wx-badge { position: absolute; top: -6px; right: -6px; display: grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--stop-dot); color: var(--glyph); font-size: 0.75rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; box-shadow: 0 0 0 2px var(--panel); }
.wx-badge.is-dot { top: -4px; right: -4px; min-width: 12px; width: 12px; height: 12px; padding: 0; }
.wx-item-n { font-size: 1.0625rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wx-item-t { font-size: 0.75rem; color: var(--grey); font-variant-numeric: tabular-nums; }
.wx-item-s { grid-column: 2 / -1; font-size: 0.875rem; color: var(--grey); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- the bar over an open chat: its name, and the menu ---- */
.page.chat > .wx-head { position: fixed; inset: 0 0 auto 0; z-index: 30; display: flex; align-items: center; gap: var(--s-1); width: auto; height: var(--wx-head); max-width: none; margin: 0; padding: 0 var(--s-1); background: var(--ground); border-bottom: 1px solid var(--line); }
.wx-back { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 8px; color: var(--ink); }
.wx-back:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.wx-head h1 { flex: 1; min-width: 0; margin: 0; font-size: 1.0625rem; font-weight: 600; letter-spacing: 0; line-height: 1.3; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 900px) {
  .page.chat > .wx-head { left: var(--wx-list); padding: 0 var(--s-2) 0 var(--s-5); }
  .wx-head > .wx-back, .wx-list-head > .wx-more { display: none; }
  .wx-head h1 { text-align: left; }
}

/* ---- a phone: the list is the first screen, alone ---- */
@media (max-width: 899.98px) {
  .page.chat > .wx-list { display: none; }
  body.wx-home .page.chat { padding: 0; }
  body.wx-home .page.chat > .wx-list { position: static; display: flex; width: 100%; min-height: 100dvh; border-right: 0; overflow: visible; }
  body.wx-home .page.chat > .skel { margin: var(--s-4); width: auto; }
  body.on-chat.wx-home .foot { display: none; }
}

/* ---- the thread: a face, a bubble, and cards under it ---- */
.wx-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) 40px; column-gap: 10px; row-gap: 4px; align-items: start; scroll-margin-top: calc(var(--wx-head) + var(--s-4)); }
.wx-row > .wx-av { grid-column: 1; grid-row: 1 / span 2; }
.wx-row > .wx-name { grid-column: 2; padding-left: 2px; font-size: 0.75rem; line-height: 1.3; color: var(--grey); }
.wx-row > .wx-bub { position: relative; grid-column: 2; justify-self: start; max-width: 100%; padding: 9px 13px; background: var(--panel); border-radius: 8px; line-height: 1.55; overflow-wrap: anywhere; }
.wx-row > .wx-bub::before { content: ""; position: absolute; top: 15px; left: -4px; width: 10px; height: 10px; border-radius: 2px; background: inherit; rotate: 45deg; }
.wx-row.is-me > .wx-av { grid-column: 3; }
.wx-row.is-me > .wx-bub { justify-self: end; background: var(--wx-me); color: var(--wx-me-ink); }
.wx-row.is-me > .wx-bub::before { left: auto; right: -4px; }
.wx-row.is-me > .wx-bub ::selection { background: color-mix(in srgb, var(--wx-me-ink) 22%, transparent); }
.wx-row > .wx-card { grid-column: 2 / -1; margin-top: 2px; }
@media (max-width: 599.98px) { .wx-row > .wx-card { grid-column: 1 / -1; margin-top: var(--s-1); } }
.wx-p { margin: 0; white-space: pre-wrap; max-width: 60ch; }
.wx-p .was { color: var(--grey); font-size: var(--t-sm); }
.wx-p .lk { white-space: nowrap; }
.wx-at { color: var(--blue); font-weight: 500; }
.wx-bub .ag-steps { margin: -2px 0 -9px; font-size: var(--t-sm); }
.wx-bub .ag-steps[open] { margin-bottom: 2px; }
.wx-bub .ref { display: inline-grid; place-items: center; min-width: 18px; height: 18px; margin: 0 2px; padding: 0 4px; border-radius: 9px; background: var(--soft); color: var(--blue); font-size: 0.75rem; text-decoration: none; vertical-align: 2px; }
.page.chat > .wx-time, .page.chat > .wx-sys { margin-block: 2px; font-size: 0.75rem; line-height: 1.5; color: var(--grey); text-align: center; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; max-width: 48rem; }
.page.chat > .wx-older { justify-self: center; width: fit-content; min-height: 36px; padding: 0 var(--s-3); border: 0; border-radius: 8px; background: transparent; color: var(--blue); font: inherit; font-size: var(--t-sm); cursor: pointer; }
.wx-older:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) { .msg-in { animation: msg-in 220ms var(--ease); } }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } }
/* "is typing": three dots in a bubble */
.wx-typing { display: flex; align-items: center; gap: 5px; height: 1.55em; }
.wx-typing > i { width: 7px; height: 7px; border-radius: 50%; background: var(--grey); animation: wx-dot 1.2s ease-in-out infinite; }
.wx-typing > i:nth-child(2) { animation-delay: 0.15s; } .wx-typing > i:nth-child(3) { animation-delay: 0.3s; }
@keyframes wx-dot { 0%, 60%, 100% { opacity: 0.3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .wx-typing > i { animation: none; opacity: 0.6; } }

/* ---- a card: white on the ground, one job each ---- */
.ccard { display: grid; gap: var(--s-4); padding: var(--s-4); background: var(--panel); border-radius: 10px; min-width: 0; }
.ccard-t { font-size: var(--t-sm); font-weight: 500; color: var(--grey); }
.ccard-t:not(:first-child) { margin-top: var(--s-2); }
.ccard-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s-3); font-size: var(--t-lg); font-weight: 600; }
.ccard-who .c { font-size: var(--t-sm); font-weight: 400; color: var(--grey); }
.ccard-say { line-height: 1.6; overflow-wrap: anywhere; }
.ccard-btns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-2); }
.ccard-btns.wrap { display: flex; flex-wrap: wrap; }
.ccard-btns .btn { min-height: 48px; }
.cfoot { font-size: var(--t-sm); color: var(--grey); }
.ccard .list { border-bottom: 0; }
.ccard .line:first-child { border-top: 0; padding-top: 0; }

/* clients, emails, shipping: the pictures from thread.css, sized for the chat column */
.ccard .tiles { list-style: none; margin: 0; padding: 0; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); gap: var(--s-2); }
.ccard .tile { min-height: 9.5rem; padding: var(--s-3) var(--s-4); border-radius: 8px; gap: var(--s-2); }
.ccard .tile .n { font-weight: 600; }
.ccard .mcards { grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
.ccard .mcard { box-shadow: none; background: var(--ground); border-radius: 8px; }
.ccard .mcard .mcard-mail > summary, .ccard .mcard .letter { background: var(--panel); }
.ccard .mcard-btns .btn { min-height: 48px; }
.ccard .flow-s { box-shadow: none; background: var(--ground); padding: var(--s-2) var(--s-3); border-radius: 8px; }
.ccard .flow-s.is-now { background: var(--btn); }
.cmiss { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.cmiss li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3); }
.cmiss .name { font-weight: 500; }
.mtag.is-miss { background: color-mix(in srgb, var(--watch-dot) 22%, var(--panel)); }
.chat .ag-card { background: var(--panel); border-color: transparent; border-radius: 10px; }
.chat .ag-card.is-open { border-color: var(--btn); }
.chat .ag-card .row-btns { display: grid; grid-template-columns: 1fr 1fr; }
.chat .ag-card .row-btns .btn { min-height: 48px; }

/* a file that was sent */
.cfile { position: relative; display: inline-flex; align-items: center; gap: var(--s-2); width: fit-content; max-width: 100%; min-height: 36px; padding: 0 var(--s-3); border-radius: var(--r-md); background: var(--soft); overflow: hidden; font-size: var(--t-sm); }
.cfile-n { max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cfile.is-failed { outline: 1px solid var(--stop-dot); }
.cfile-bar { position: absolute; inset: auto 0 0 0; height: 2px; background: var(--line); }
.cfile-bar > span { display: block; width: 35%; height: 100%; background: var(--btn); animation: cfile-go 1.4s ease-in-out infinite; }
@keyframes cfile-go { from { transform: translateX(-100%); } to { transform: translateX(290%); } }

/* "back to latest": floats just over the message box */
.jump-latest { position: absolute; left: 50%; bottom: calc(100% + var(--s-3)); translate: -50% 0; display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 var(--s-4); border: 1px solid var(--line); border-radius: 18px; background: var(--panel); color: var(--ink); font: inherit; font-size: var(--t-sm); white-space: nowrap; cursor: pointer; box-shadow: 0 6px 18px -8px rgb(15 20 25 / 0.35); animation: jump-in 160ms var(--ease); }
.jump-latest svg { rotate: 90deg; }
.jump-latest:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
@keyframes jump-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .jump-latest, .cfile-bar > span { animation: none; } }
