/* RTM messages — the side-docked module (chat.js). Self-contained: every page, whatever its own styles. */
#rtmchat-tab, #rtmchat-panel, #msgpop, #rtmchat-share, #rtmchat-send, #rtmchat-ctx {
  --rc-bg: #fff; --rc-ink: #1b2430; --rc-muted: #5b6675; --rc-line: #dde2e8; --rc-accent: #0b5cad; --rc-accent-ink: #fff;
  --rc-chip: #eef3f9; --rc-warn: #b03a3a;
  font: calc(14px * var(--fs, 1))/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--rc-ink); box-sizing: border-box;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #rtmchat-tab, :root:not([data-theme="light"]) #rtmchat-panel, :root:not([data-theme="light"]) #msgpop,
  :root:not([data-theme="light"]) #rtmchat-share, :root:not([data-theme="light"]) #rtmchat-send, :root:not([data-theme="light"]) #rtmchat-ctx {
    --rc-bg: #1a2029; --rc-ink: #e6ebf1; --rc-muted: #9aa6b4; --rc-line: #2c3542; --rc-accent: #5aa2ef; --rc-accent-ink: #0b1420;
    --rc-chip: #232c38; --rc-warn: #f08a8a;
  }
}
:root[data-theme="dark"] #rtmchat-tab, :root[data-theme="dark"] #rtmchat-panel, :root[data-theme="dark"] #msgpop,
:root[data-theme="dark"] #rtmchat-share, :root[data-theme="dark"] #rtmchat-send, :root[data-theme="dark"] #rtmchat-ctx {
    --rc-bg: #1a2029; --rc-ink: #e6ebf1; --rc-muted: #9aa6b4; --rc-line: #2c3542; --rc-accent: #5aa2ef; --rc-accent-ink: #0b1420;
    --rc-chip: #232c38; --rc-warn: #f08a8a;
  }
#rtmchat-tab *, #rtmchat-panel *, #msgpop *, #rtmchat-share *, #rtmchat-send *, #rtmchat-ctx * { box-sizing: border-box; }
#rtmchat-tab[hidden], #rtmchat-panel[hidden], #rtmchat-panel [hidden], #rtmchat-share[hidden], #rtmchat-send [hidden] { display: none !important; }

/* Closed: a slim tab on the right edge, with the unread count. */
#rtmchat-tab {
  position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 2147483000;
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px;
  background: var(--rc-accent); color: var(--rc-accent-ink); border: 0; border-radius: 8px 0 0 8px; cursor: pointer;
  box-shadow: -2px 2px 10px rgba(0, 0, 0, .2);
}
#rtmchat-tab .lbl { writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 600; font-size: calc(13px * var(--fs, 1)); letter-spacing: .03em; }
#rtmchat-tab .n, #rtmchat-panel .conv .n {
  min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--rc-warn); color: #fff; font-size: calc(11px * var(--fs, 1)); font-weight: 700; text-align: center;
}

/* Open: a side panel — the conversations, then a chat. */
#rtmchat-panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(360px, 100vw); z-index: 2147483001;
  display: flex; flex-direction: column; background: var(--rc-bg); border-left: 1px solid var(--rc-line);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .25); transform: translateX(100%); transition: transform .18s ease-out;
}
#rtmchat-panel.open { transform: none; }
#rtmchat-panel .hd { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--rc-line); }
#rtmchat-panel .hd .ttl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rtmchat-panel .hd .ctx a { font-size: calc(12px * var(--fs, 1)); color: var(--rc-accent); }
#rtmchat-panel button { font: inherit; color: inherit; cursor: pointer; }
#rtmchat-panel .hd .x, #rtmchat-panel .hd .back { border: 0; background: none; padding: 2px 6px; color: var(--rc-muted); }
#rtmchat-panel .body { flex: 1; overflow: auto; padding: 8px 12px; }
#rtmchat-panel .muted { color: var(--rc-muted); }
#rtmchat-panel .err { color: var(--rc-warn); }
#rtmchat-panel .conv {
  display: grid; grid-template-columns: 1fr auto auto; gap: 2px 8px; width: 100%; text-align: left; padding: 8px 6px;
  border: 0; border-bottom: 1px solid var(--rc-line); background: none;
}
#rtmchat-panel .conv:hover { background: var(--rc-chip); }
#rtmchat-panel .conv .who { font-weight: 600; }
#rtmchat-panel .conv .t { color: var(--rc-muted); font-size: calc(12px * var(--fs, 1)); }
#rtmchat-panel .conv .last { grid-column: 1 / -1; color: var(--rc-muted); font-size: calc(13px * var(--fs, 1)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rtmchat-panel .m { margin: 6px 0; max-width: 85%; }
#rtmchat-panel .m.mine { margin-left: auto; text-align: right; }
#rtmchat-panel .m .b { display: inline-block; padding: 6px 9px; border-radius: 10px; background: var(--rc-chip); white-space: pre-wrap; text-align: left; }
#rtmchat-panel .m.mine .b { background: color-mix(in srgb, var(--rc-accent) 22%, transparent); }
#rtmchat-panel .m .w { font-size: calc(11px * var(--fs, 1)); color: var(--rc-muted); }
#rtmchat-panel .m .w a { color: var(--rc-accent); }
#rtmchat-panel .send { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--rc-line); }
#rtmchat-panel .send textarea {
  flex: 1; min-height: 40px; resize: vertical; font: inherit; color: var(--rc-ink); background: var(--rc-bg);
  border: 1px solid var(--rc-line); border-radius: 6px; padding: 6px 8px;
}
#rtmchat-panel .send button, #msgpop .respond {
  background: var(--rc-accent); color: var(--rc-accent-ink); border: 1px solid var(--rc-accent); border-radius: 6px; padding: 6px 12px;
}

/* A new message: the pop-up, top right. */
#msgpop {
  position: fixed; top: 70px; right: 20px; width: min(380px, calc(100vw - 32px)); z-index: 2147483002;
  background: var(--rc-bg); border: 1px solid var(--rc-line); border-radius: 8px; padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35);
}
#msgpop .from { color: var(--rc-muted); font-size: calc(12px * var(--fs, 1)); }
#msgpop .text { white-space: pre-wrap; margin-top: 6px; }
#msgpop .todo { border-left: 3px solid var(--rc-accent); padding: 6px 10px; margin: 8px 0; background: var(--rc-chip); border-radius: 4px; }
#msgpop .todo a { color: var(--rc-accent); }
#msgpop .desc { color: var(--rc-muted); white-space: pre-wrap; font-size: calc(13px * var(--fs, 1)); max-height: 120px; overflow: auto; }
#msgpop .acts { margin: 10px 0 0; }
#msgpop button { font: inherit; cursor: pointer; }
#msgpop .dismiss { background: none; color: var(--rc-ink); border: 1px solid var(--rc-line); border-radius: 6px; padding: 6px 12px; }

/* Reactions, as iMessage's tapbacks: a badge on the bubble's outer top corner, and the six above it. */
#rtmchat-panel .m .bw { position: relative; display: inline-block; max-width: 100%; }
#rtmchat-panel .m .rx {
  position: absolute; top: -10px; right: -8px; display: flex; gap: 1px; padding: 1px 4px; border-radius: 10px;
  background: var(--rc-bg); border: 1px solid var(--rc-line); font-size: calc(12px * var(--fs, 1)); line-height: 1.4;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
#rtmchat-panel .m.mine .rx { right: auto; left: -8px; }
#rtmchat-panel .m .rx span.me { filter: drop-shadow(0 0 1px var(--rc-accent)); }
#rtmchat-panel .m .rxbtn {
  position: absolute; top: 50%; right: -26px; transform: translateY(-50%); opacity: 0; transition: opacity .12s;
  border: 0; background: none; padding: 2px; color: var(--rc-muted); font-size: calc(15px * var(--fs, 1)); line-height: 1;
}
#rtmchat-panel .m.mine .rxbtn { right: auto; left: -26px; }
#rtmchat-panel .m:hover .rxbtn, #rtmchat-panel .m .rxbtn:focus-visible { opacity: 1; }
#rtmchat-panel .m .b { cursor: default; user-select: text; }
#rtmchat-panel .rxpick {
  position: absolute; bottom: calc(100% + 6px); left: 0; z-index: 2; display: flex; gap: 2px; padding: 4px 6px;
  border-radius: 20px; background: var(--rc-bg); border: 1px solid var(--rc-line); box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
  animation: rc-pop .12s ease-out;
}
#rtmchat-panel .m.mine .rxpick { left: auto; right: 0; }
#rtmchat-panel .rxpick button {
  border: 0; background: none; padding: 3px 5px; border-radius: 50%; font-size: calc(18px * var(--fs, 1)); line-height: 1;
  transition: transform .1s;
}
#rtmchat-panel .rxpick button:hover { transform: scale(1.25); }
#rtmchat-panel .rxpick button.on { background: color-mix(in srgb, var(--rc-accent) 25%, transparent); }
@keyframes rc-pop { from { opacity: 0; transform: translateY(4px) scale(.95); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #rtmchat-panel .rxpick { animation: none; } #rtmchat-panel .rxpick button { transition: none; } }

/* Emoji: ☺ beside Send, + on the tapback row, and the picker above the reply box (smileys and thumbs first). */
#rtmchat-panel .send .embtn {
  background: none; color: var(--rc-muted); border: 1px solid var(--rc-line); padding: 4px 9px; font-size: calc(17px * var(--fs, 1)); line-height: 1;
}
#rtmchat-panel .send .embtn:hover { color: var(--rc-ink); background: var(--rc-chip); }
#rtmchat-panel .rxpick .rxmore { font-size: calc(16px * var(--fs, 1)); color: var(--rc-muted); font-weight: 600; }
#rtmchat-panel .empick {
  position: absolute; left: 8px; right: 8px; bottom: 64px; z-index: 3; height: min(320px, 55vh); display: flex; flex-direction: column;
  background: var(--rc-bg); border: 1px solid var(--rc-line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
  animation: rc-pop .12s ease-out; overflow: hidden;
}
#rtmchat-panel .empick .emq {
  margin: 8px 8px 4px; padding: 5px 8px; font: inherit; color: var(--rc-ink); background: var(--rc-chip);
  border: 1px solid var(--rc-line); border-radius: 8px;
}
#rtmchat-panel .empick .emtabs { display: flex; gap: 1px; padding: 0 6px 4px; border-bottom: 1px solid var(--rc-line); overflow-x: auto; }
#rtmchat-panel .empick .emtabs button {
  border: 0; background: none; padding: 4px 5px; border-radius: 6px; font-size: calc(16px * var(--fs, 1)); line-height: 1; opacity: .6;
}
#rtmchat-panel .empick .emtabs button[aria-selected="true"] { opacity: 1; background: var(--rc-chip); box-shadow: inset 0 -2px 0 var(--rc-accent); }
#rtmchat-panel .empick .emtabs button:hover { opacity: 1; }
#rtmchat-panel .empick .emgrid {
  flex: 1; overflow-y: auto; padding: 4px 6px 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); align-content: start;
}
#rtmchat-panel .empick .emcat {
  grid-column: 1 / -1; padding: 4px 2px; font-size: calc(11px * var(--fs, 1)); font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--rc-muted);
}
#rtmchat-panel .empick .emgrid p { grid-column: 1 / -1; margin: 8px 4px; }
#rtmchat-panel .empick .emgrid button {
  border: 0; background: none; padding: 4px 0; border-radius: 8px; font-size: calc(22px * var(--fs, 1)); line-height: 1.2; transition: transform .08s;
}
#rtmchat-panel .empick .emgrid button:hover { background: var(--rc-chip); transform: scale(1.15); }
@media (prefers-reduced-motion: reduce) { #rtmchat-panel .empick { animation: none; } #rtmchat-panel .empick .emgrid button { transition: none; } }

/* Pictures: waiting above the reply box with ×, in a bubble below its words, and large on a click. */
#rtmchat-panel .send { flex-wrap: wrap; }
#rtmchat-panel .send .pend { flex-basis: 100%; display: flex; gap: 6px; flex-wrap: wrap; }
#rtmchat-panel .send .pend .pp { position: relative; width: 56px; height: 56px; border: 1px solid var(--rc-line); border-radius: 6px; overflow: hidden; background: var(--rc-chip); }
#rtmchat-panel .send .pend .pp img { width: 100%; height: 100%; object-fit: cover; display: block; }
#rtmchat-panel .send .pend .pp.busy img { opacity: .45; }
#rtmchat-panel .send .pend .pp button {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; padding: 0; border-radius: 50%; line-height: 16px; font-size: calc(13px * var(--fs, 1));
  background: rgba(0, 0, 0, .6); color: #fff; border: 0;
}
#rtmchat-panel .send .atbtn {
  background: none; color: var(--rc-muted); border: 1px solid var(--rc-line); padding: 4px 8px; font-size: calc(15px * var(--fs, 1)); line-height: 1;
}
#rtmchat-panel .send .atbtn:hover { color: var(--rc-ink); background: var(--rc-chip); }
#rtmchat-panel.drop { outline: 2px dashed var(--rc-accent); outline-offset: -6px; }
#rtmchat-panel .pics, #msgpop .pics { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
#rtmchat-panel .pics img, #msgpop .pics img { max-width: 220px; max-height: 180px; border-radius: 6px; cursor: zoom-in; display: block; background: var(--rc-chip); min-width: 40px; min-height: 30px; }
#rtmchat-panel a.req, #msgpop a.req { color: var(--rc-accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
#rtmchat-view { position: fixed; inset: 0; z-index: 100000; background: rgba(0, 0, 0, .8); display: flex; align-items: center; justify-content: center; cursor: zoom-out; }
#rtmchat-view img { max-width: 94vw; max-height: 92vh; border-radius: 6px; box-shadow: 0 10px 40px rgba(0, 0, 0, .5); }

/* Send a link: the tab under Messages (this page), right-click a section (that section), then who to send it to. */
#rtmchat-share {
  position: fixed; right: 0; top: calc(50% + 74px); z-index: 2147483000; padding: 10px 6px; cursor: pointer;
  background: var(--rc-bg); color: var(--rc-accent); border: 1px solid var(--rc-accent); border-right: 0; border-radius: 8px 0 0 8px;
  box-shadow: -2px 2px 10px rgba(0, 0, 0, .15); display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#rtmchat-share .lbl { writing-mode: vertical-rl; transform: rotate(180deg); font-weight: 600; font-size: calc(12px * var(--fs, 1)); }
#rtmchat-ctx, #rtmchat-send {
  position: fixed; z-index: 2147483001; background: var(--rc-bg); color: var(--rc-ink); border: 1px solid var(--rc-line); border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}
#rtmchat-ctx { padding: 4px; min-width: 230px; }
#rtmchat-ctx button { display: block; width: 100%; text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
#rtmchat-ctx button:hover, #rtmchat-ctx button:focus { background: var(--rc-chip); outline: none; }
#rtmchat-ctx .what { display: block; color: var(--rc-muted); font-size: calc(11px * var(--fs, 1)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
#rtmchat-send { width: 320px; max-width: calc(100vw - 16px); padding: 10px; display: flex; flex-direction: column; gap: 8px; max-height: min(460px, calc(100vh - 16px)); }
#rtmchat-send .hd { display: flex; gap: 8px; align-items: baseline; }
#rtmchat-send .hd b { flex: 1; }
#rtmchat-send .hd .x { background: none; border: 0; color: var(--rc-muted); cursor: pointer; font-size: calc(15px * var(--fs, 1)); }
#rtmchat-send .what { color: var(--rc-muted); font-size: calc(12px * var(--fs, 1)); overflow-wrap: anywhere; }
#rtmchat-send input { font: inherit; color: var(--rc-ink); background: var(--rc-bg); border: 1px solid var(--rc-line); border-radius: 6px; padding: 6px 8px; }
#rtmchat-send .who { overflow: auto; display: grid; gap: 2px; }
#rtmchat-send .who .grp { color: var(--rc-muted); font-size: calc(11px * var(--fs, 1)); text-transform: uppercase; letter-spacing: .04em; margin-top: 4px; }
#rtmchat-send .who button { text-align: left; background: none; border: 0; color: inherit; font: inherit; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
#rtmchat-send .who button:hover, #rtmchat-send .who button:focus { background: var(--rc-chip); outline: none; }
#rtmchat-send .who button span { color: var(--rc-muted); font-size: calc(11px * var(--fs, 1)); margin-left: 6px; }
#rtmchat-send .err { color: var(--rc-warn); margin: 0; }
.rtmchat-here { outline: 3px solid #6078ea !important; outline-offset: 4px; border-radius: 6px; transition: outline-color 1.5s ease-in 1.5s; }
.rtmchat-here.fade { outline-color: transparent !important; }
#rtmchat-panel a.url, #msgpop a.url { color: var(--rc-accent); text-decoration: underline; overflow-wrap: anywhere; }
