/* Chat dock — right-edge tab + full-height slide drawer */

.chat-parties {
  --party-accent: var(--winter-edge, var(--accent));
  --party-edge: color-mix(in srgb, var(--party-accent) 52%, transparent);
  --party-ink: var(--winter-ink, var(--text));
  --party-surface: color-mix(in srgb, var(--card) 94%, white);
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--card) 94%, var(--accent));
  border-bottom: 1px solid var(--line);
  padding: .4rem .75rem;
}
.chat-parties > summary {
  cursor: pointer;
  font-weight: 800;
  padding: .35rem 0;
}
.chat-parties-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .3rem 0 .65rem;
  border-bottom: 1px solid var(--party-edge);
}
.chat-parties-copy-status:not(:empty) {
  padding: .45rem 0 .15rem;
  color: var(--party-ink);
  font-size: .78rem;
  font-weight: 800;
}
.chat-parties-content, .chat-party-form, .chat-party-card {
  display: grid;
  gap: .55rem;
}
.chat-parties-content {
  max-height: min(52dvh, 30rem);
  overflow-y: auto;
  padding: .55rem .2rem .4rem .05rem;
}
.chat-party-form, .chat-party-card {
  min-width: 0;
  border: 1px solid var(--party-edge);
  border-radius: .8rem;
  padding: .7rem;
  background: var(--card);
  overflow-wrap: anywhere;
}
.chat-party-form {
  justify-items: start;
  background: color-mix(in srgb, var(--card) 90%, var(--accent));
}
.chat-party-card {
  gap: .65rem;
  background: var(--party-surface);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--party-accent) 30%, transparent);
}
.chat-party-card-head, .chat-party-meta, .chat-party-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem .65rem;
}
.chat-party-card-head {
  justify-content: space-between;
  align-items: flex-start;
  margin: -.7rem -.7rem 0;
  padding: .65rem .7rem;
  border-bottom: 1px solid var(--party-edge);
  border-radius: .75rem .75rem 0 0;
  background: linear-gradient(110deg, color-mix(in srgb, var(--party-accent) 48%, var(--card)),
    color-mix(in srgb, var(--party-accent) 16%, var(--card)));
}
.chat-party-card-head h3 {
  margin: 0;
  color: var(--party-ink);
  font-size: 1.15rem;
  font-weight: 900;
  line-height: 1.25;
}
.chat-party-game {
  display: inline-block;
  margin-top: .25rem;
  padding: .1rem .45rem;
  border-radius: .35rem;
  background: var(--party-surface);
  color: var(--party-ink);
  font-size: .77rem;
  font-weight: 800;
}
.chat-party-schedule {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 6.2rem), 1fr));
  gap: .4rem;
  margin: 0;
}
.chat-party-schedule > div {
  padding: .34rem .5rem;
  border-radius: .45rem;
  background: color-mix(in srgb, var(--party-accent) 16%, var(--party-surface));
}
.chat-party-schedule dt { color: var(--muted); font-size: .72rem; }
.chat-party-schedule dd {
  margin: .05rem 0 0;
  color: var(--party-ink);
  font-size: .85rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}
.chat-party-status {
  padding: .16rem .52rem;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--party-surface);
  color: var(--muted);
  font-size: .75rem;
  font-weight: 800;
}
.chat-party-status.is-online {
  background: #d9f3e2;
  border-color: #a7cfb7;
  color: #235638;
}
.chat-party-comment {
  padding: .45rem .6rem;
  border-inline-start: 2px solid var(--party-edge);
  background: color-mix(in srgb, var(--card) 95%, var(--accent));
  color: var(--party-ink);
  font-size: .88rem;
  white-space: pre-line;
}
.chat-party-connection {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .4rem;
  border: 1px solid var(--party-edge);
  border-radius: .65rem;
  background: color-mix(in srgb, var(--party-accent) 27%, var(--party-surface));
}
.chat-party-copy {
  display: grid;
  gap: .12rem;
  align-content: center;
  min-width: 0;
  min-height: 2.75rem;
  padding: .3rem .55rem;
  border: 1px solid var(--party-edge);
  border-radius: .5rem;
  background: var(--party-surface);
  color: var(--party-ink);
  font: inherit;
  text-align: start;
  cursor: copy;
}
.chat-party-copy:first-child { flex: 1 1 8rem; }
.chat-party-copy:hover {
  background: color-mix(in srgb, var(--card) 76%, var(--winter-edge, var(--accent)));
}
.chat-party-copy:focus-visible { outline: 2px solid var(--party-ink); }
.chat-party-copy span { font-size: .72rem; font-weight: 800; }
.chat-party-copy code { font-size: .95rem; font-weight: 800; overflow-wrap: anywhere; }
.chat-party-form label, .chat-party-form input, .chat-party-form select, .chat-party-form textarea {
  width: 100%;
  min-width: 0;
}
.chat-party-form label { display: grid; gap: .25rem; }
.chat-party-form textarea { resize: vertical; }
.chat-party-card > .chat-party-actions {
  padding-top: .55rem;
  border-top: 1px solid var(--party-edge);
}
.chat-party-actions .btn, .chat-parties-toolbar .btn { min-height: 2.5rem; }
.chat-parties p { margin: 0; }
.chat-party-archive, .chat-party-discussion {
  display: grid;
  gap: .5rem;
  min-width: 0;
  padding-top: .6rem;
  border-top: 1px solid var(--party-edge);
}
.chat-party-archive > h3 { margin: 0; font-size: 1rem; }
.chat-party-archive > .btn, .chat-party-discussion > .btn { justify-self: start; }
.chat-party-messages {
  display: grid;
  gap: .4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}
.chat-party-messages > li {
  padding: .42rem .55rem;
  border-radius: .5rem;
  background: color-mix(in srgb, var(--card) 92%, var(--winter-edge, var(--accent)));
  font-size: .86rem;
}
.chat-party-messages p { white-space: pre-wrap; }
.chat-party-message-form {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}
.chat-party-message-form input { flex: 1 1 10rem; width: 100%; min-width: 0; }

.chat-dock {
  --chat-tab-w: 2.4rem;
  --chat-panel-w: min(38rem, 44vw);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  /* Never cover the site: only tab (+ panel when open) */
  width: var(--chat-tab-w);
  z-index: 60;
  pointer-events: none;
  font-family: Nunito, system-ui, sans-serif;
}
.chat-dock.is-open {
  width: calc(var(--chat-panel-w) + var(--chat-tab-w));
}

.chat-dock-rail {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  pointer-events: none;
  /* closed: only the tab peeks from the right edge */
  transform: translateX(var(--chat-panel-w));
  transition: transform .34s cubic-bezier(.22, 1, .36, 1);
  will-change: transform;
}

.chat-dock.is-open .chat-dock-rail {
  transform: translateX(0);
}

/* When open, hide the edge tab — close only via × so site clicks don't collapse chat */
.chat-dock.is-open .chat-dock-tab {
  visibility: hidden;
  pointer-events: none;
  width: 0;
  min-width: 0;
  flex-basis: 0;
  padding: 0;
  border: 0;
  margin: 0;
  overflow: hidden;
}
.chat-dock.is-open {
  width: var(--chat-panel-w);
}

.chat-dock-tab {
  pointer-events: auto;
  align-self: center;
  position: relative;
  flex: 0 0 var(--chat-tab-w);
  width: var(--chat-tab-w);
  min-height: 7.75rem;
  padding: .9rem .15rem;
  border: 3px solid #3d6c22;
  border-right: 0;
  border-radius: 12px 0 0 12px;
  background: linear-gradient(180deg, #8fd36a 0%, #4e9a3a 100%);
  box-shadow: -3px 4px 0 #2a4f18, -6px 8px 16px rgba(40, 80, 30, .22);
  color: #14320f;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  transition: filter .15s ease;
  z-index: 2;
}

.chat-dock-tab:hover {
  filter: brightness(1.06);
}

.chat-dock-tab-icon {
  display: grid;
  place-items: center;
  line-height: 0;
}

.chat-dock-tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: Oxanium, Nunito, sans-serif;
  font-weight: 800;
  font-size: .78rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.chat-dock.has-raid-tab {
  --chat-tab-w: clamp(1.92rem, 2.76vw, 2.52rem);
}

.chat-dock .chat-dock-raid-tab[class] {
  --raid-paper: #ffe3b2;
  --raid-border: #542b29;
  min-height: clamp(4.5rem, 13.2vh, 6.15rem);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.chat-dock-raid-tab::before {
  /* Keep a 44px-wide tap target at the default font size. */
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: max(100%, 2.75rem);
}

.chat-dock .chat-dock-raid-tab.raid-moth { --raid-paper: #fae2ed; --raid-border: #442350; }
.chat-dock .chat-dock-raid-tab.raid-frost { --raid-paper: #e0f6f5; --raid-border: #183a55; }

.chat-dock-raid-tab:focus-visible {
  outline: 3px solid var(--raid-paper);
  outline-offset: -3px;
}

.chat-dock-raid-art {
  --raid-boss-size: clamp(3.78rem, 7.8vw, 6.24rem);
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.chat-dock-raid-boss {
  position: absolute;
  bottom: -.24rem;
  right: calc(100% - .72rem);
  width: var(--raid-boss-size);
  animation: chat-raid-peek .45s ease-out both;
}

.chat-dock-raid-boss img { display: block; width: 100%; height: auto; }

.chat-dock-raid-face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  z-index: 1;
}

.chat-dock-raid-speech {
  position: absolute;
  bottom: calc(var(--raid-boss-size) + .3rem);
  right: .45rem;
  padding: .22rem .46rem;
  border: 2px solid var(--raid-border);
  border-radius: .54rem;
  box-shadow: 0 2px 0 var(--raid-border);
  background: var(--raid-paper);
  color: var(--raid-border);
  font-weight: 900;
  font-size: .76rem;
  line-height: 1.3;
  white-space: nowrap;
  z-index: 2;
}

.chat-dock-raid-speech::after {
  content: "";
  position: absolute;
  bottom: -.34rem;
  right: 1.9rem;
  width: .52rem;
  height: .52rem;
  border-right: 2px solid var(--raid-border);
  border-bottom: 2px solid var(--raid-border);
  background: var(--raid-paper);
  transform: rotate(45deg);
}

@keyframes chat-raid-peek {
  from { opacity: 0; transform: translateX(.9rem); }
  to { opacity: 1; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .chat-dock-raid-boss { animation: none; }
}

.chat-dock-panel {
  width: var(--chat-panel-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  background:
    linear-gradient(180deg, rgba(255,255,255,.72), rgba(245,252,240,.78)),
    url("/assets/ui/mc/blocks/grass.png");
  background-size: auto, 48px 48px;
  border-left: 3px solid #3d6c22;
  box-shadow: -10px 0 28px rgba(30, 60, 20, .22);
  overflow: hidden;
}

.chat-dock:not(.is-open) .chat-dock-panel {
  pointer-events: none;
}

.chat-dock-badge {
  position: absolute;
  top: .3rem;
  left: -.4rem;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 .28rem;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-size: .7rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
  border: 2px solid #fff;
  cursor: pointer;
  pointer-events: auto;
  z-index: 3;
}
.chat-dock-badge.inline {
  position: static;
  margin-left: auto;
  flex: 0 0 auto;
}
/* Plain unread messages sit next to mentions but must not shout like them. */
.chat-dock-badge.inline.is-plain {
  margin-left: 4px;
  background: #2d6cdf;
}
/* Same blue for the dock tab when there are only plain unread messages. */
.chat-dock-badge.is-plain {
  background: #2d6cdf;
}
.chat-dock-badge:hover {
  filter: brightness(1.08);
}
.chat-dock-unread-jump {
  flex: 0 0 auto;
  min-width: 1.55rem;
  height: 1.55rem;
  padding: 0 .4rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: #c0392b;
  color: #fff;
  font: inherit;
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(160, 40, 30, .35);
}
.chat-dock-unread-jump:hover {
  filter: brightness(1.08);
}

.chat-dock.is-shake .chat-dock-tab {
  animation: chat-shake .55s ease;
}

@keyframes chat-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}

.chat-dock-head {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem .8rem;
  background: linear-gradient(180deg, #6db84f, #3f8a30);
  color: #0f2810;
  border-bottom: 3px solid #2a4f18;
  flex-shrink: 0;
}

.chat-dock-head-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.chat-dock-head-main strong { line-height: 1.1; }
.chat-dock-back,
.chat-dock-close {
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  cursor: pointer;
  color: inherit;
  line-height: 1;
  padding: .15rem .35rem;
}

.chat-dock-toast {
  margin: .4rem .65rem 0;
  padding: .55rem .7rem;
  background: rgba(20, 50, 15, .92);
  color: #e8ffe0;
  border-radius: 10px;
  font-size: .86rem;
  font-weight: 650;
  flex-shrink: 0;
  box-shadow: 0 6px 18px rgba(20, 40, 10, .28);
  opacity: 1;
  transition: opacity .85s ease;
}
.chat-dock-toast.is-fading {
  opacity: 0;
}

.chat-cmd-suggest button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: .1rem;
  width: 100%;
  text-align: left;
}
.chat-cmd-suggest code {
  font-weight: 800;
  color: #1a5fb4;
}

.chat-dock-rooms {
  flex: 1;
  overflow: auto;
  padding: .55rem;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.chat-rules-gate {
  flex: 1;
  overflow: auto;
  padding: .85rem .9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  background: linear-gradient(180deg, #fffaf0 0%, #f3efe4 100%);
  color: #1a2b3c;
}
.chat-rules-gate h3 {
  margin: 0;
  font-size: 1.05rem;
  color: #3f9e3a;
}
.chat-rules-body {
  white-space: pre-wrap;
  font-size: .88rem;
  line-height: 1.45;
  flex: 1;
  overflow: auto;
  padding: .55rem .65rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, .72);
  border: 1px solid rgba(26, 43, 60, .12);
}
.chat-rules-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.chat-rules-gate .error {
  color: #c0392b;
  margin: 0;
}

.chat-room-item {
  display: flex;
  align-items: center;
  gap: .55rem;
  width: 100%;
  text-align: left;
  padding: .55rem .65rem;
  border: 2px solid rgba(61, 108, 34, .35);
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  cursor: pointer;
}
.chat-room-item-row {
  display: flex;
  align-items: stretch;
  gap: .35rem;
}
.chat-room-item-row .chat-room-item {
  flex: 1;
  min-width: 0;
}
.chat-notify-btn {
  flex: 0 0 auto;
  width: 2.4rem;
  border: 2px solid rgba(61, 108, 34, .35);
  border-radius: 10px;
  background: rgba(255,255,255,.72);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.chat-notify-btn:hover { background: rgba(255,255,255,.95); }
.chat-notify-btn.is-muted {
  background: rgba(0,0,0,.06);
  opacity: .85;
}
.chat-dock-head .chat-notify-btn {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
}
.chat-room-item:hover { background: rgba(255,255,255,.92); }
.chat-room-emoji {
  flex: 0 0 auto;
  width: 2.2rem;
  height: 2.2rem;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: 10px;
  background: rgba(61, 108, 34, .12);
}
.chat-room-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: .05rem;
}
.chat-room-name { font-weight: 800; color: #1d3d16; }
.chat-room-meta { margin-left: 0; }
.chat-room-lock { opacity: .55; font-size: .85rem; flex: 0 0 auto; }

.chat-dock-thread {
  flex: 1;
  overflow: auto;
  padding: .55rem .65rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  background: rgba(255,255,255,.42);
}

.chat-load-more { align-self: center; margin-bottom: .25rem; }

.chat-day-group {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  min-width: 0;
}
/* Sticky is limited to this group, so older days scroll away instead of stacking. */
.chat-day-sep {
  display: flex;
  justify-content: center;
  position: sticky;
  top: .35rem;
  z-index: 3;
  margin: 0;
  pointer-events: none;
}
.chat-day-sep span {
  background: rgba(26, 43, 60, .92);
  color: #fff;
  font-size: .75rem;
  font-weight: 750;
  letter-spacing: .01em;
  line-height: 1.2;
  padding: .22rem .72rem;
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .14);
}

.chat-msg {
  padding: .5rem .55rem;
  border-radius: 10px;
  background: rgba(255,255,255,.55);
  scroll-margin: 2rem;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.chat-msg-row {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding-bottom: .35rem; /* room for badge under the frame */
}
.chat-msg-main { min-width: 0; flex: 1; }
/* Keep frame + badge readable: do not squash the stage to a tiny box */
.chat-msg .avatar-stage.mini {
  width: auto;
  height: auto;
  flex: 0 0 auto;
  --frame-pad: 7px;
  --frame-radius: 10px;
  margin-top: .05rem;
}
.chat-msg .avatar-stage.mini .avatar-ring {
  width: 52px;
  height: 52px;
}
.chat-msg .avatar-stage.mini .avatar-fallback {
  font-size: .92rem;
}
.chat-msg .avatar-frame-badge.mini,
.chat-msg .avatar-stage.mini .avatar-frame-badge {
  right: 1px;
  bottom: -5px;
  min-height: 1.05rem;
  padding: .14rem .34rem .16rem;
  font-size: .42rem;
  border-radius: 4px;
  max-width: calc(100% - 4px);
  letter-spacing: .02em;
}
.chat-ctx-head .avatar-frame-badge.mini {
  right: 1px;
  bottom: -4px;
}
.chat-msg.is-selected {
  background: rgba(110, 180, 80, .28);
  box-shadow: inset 0 0 0 2px rgba(61, 108, 34, .45);
}
.chat-msg-check {
  flex: 0 0 auto;
  width: 1.1rem;
  text-align: center;
  color: #24501c;
  font-size: 1rem;
  line-height: 1.4;
  margin-top: .2rem;
}
.chat-msg-fwd {
  margin-bottom: .15rem;
  color: #3a6a8a;
  font-weight: 700;
}
.chat-msg-reply-quote {
  display: grid;
  gap: .05rem;
  width: 100%;
  text-align: left;
  margin: 0 0 .35rem;
  padding: .3rem .45rem;
  border: 0;
  border-left: 3px solid #4e9a3a;
  border-radius: 0 6px 6px 0;
  background: rgba(78, 154, 58, .12);
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.chat-msg-reply-quote strong {
  color: #24501c;
  font-size: .78rem;
}
.chat-msg-reply-quote span {
  color: #3a5234;
  font-size: .78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-select-bar,
.chat-reply-bar {
  display: flex;
  align-items: center;
  gap: .45rem;
  padding: .4rem .6rem;
  background: rgba(255,255,255,.82);
  border-top: 2px solid rgba(61, 108, 34, .28);
  flex-shrink: 0;
}
.chat-select-bar { justify-content: space-between; font-weight: 750; color: #1d3d16; }
.chat-edit-bar {
  border-top-color: rgba(196, 132, 22, .55);
  background: rgba(255, 248, 226, .92);
}
.chat-edit-bar .chat-reply-bar-text strong { color: #7a4c07; }
.chat-reply-bar-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .05rem;
}
.chat-reply-bar-text strong { color: #24501c; font-size: .85rem; }
.chat-forward-picker {
  position: fixed;
  z-index: 82;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(22rem, calc(100vw - 1.5rem));
  max-height: min(28rem, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  padding: .45rem;
  border: 3px solid #3d6c22;
  border-radius: 12px;
  background: linear-gradient(180deg, #f7fff0, #e4f4d2);
  box-shadow: 0 12px 32px rgba(30, 60, 20, .35);
  pointer-events: auto;
}
.chat-forward-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .25rem .35rem .45rem;
  border-bottom: 1px solid rgba(61,108,34,.25);
  margin-bottom: .35rem;
  color: #1d3d16;
}
.chat-forward-picker-list {
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  padding: .1rem;
}
.chat-ctx-head {
  padding-bottom: .7rem;
}
.chat-ctx-head .avatar-stage.mini {
  position: relative;
  overflow: visible;
}
.chat-msg.bot { background: rgba(230, 245, 255, .7); border-left: 3px solid #2a7ab8; }
.chat-msg.system { background: rgba(255, 248, 220, .75); }
.chat-msg.is-hl { outline: 2px solid #f0c040; animation: chat-hl 1.2s ease; }
.chat-msg.mentions-me { box-shadow: inset 0 0 0 1px rgba(192, 57, 43, .35); }

.chat-ctx-scrim {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(20, 40, 15, .18);
  pointer-events: auto;
}
.chat-ctx-menu {
  position: fixed;
  z-index: 81;
  min-width: 14.5rem;
  max-width: min(18rem, calc(100vw - 1rem));
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: .45rem;
  border: 3px solid #3d6c22;
  border-radius: 12px;
  background: linear-gradient(180deg, #f7fff0, #e4f4d2);
  box-shadow: 0 10px 28px rgba(30, 60, 20, .32);
  display: flex;
  flex-direction: column;
  gap: .2rem;
  pointer-events: auto;
}
.chat-ctx-head {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .35rem .4rem .55rem;
  border-bottom: 1px solid rgba(61,108,34,.28);
  margin-bottom: .2rem;
}
.chat-ctx-head .avatar-stage.mini {
  flex: 0 0 auto;
  --frame-pad: 6px;
}
.chat-ctx-head .avatar-stage.mini .avatar-ring {
  width: 44px;
  height: 44px;
}
.chat-ctx-head .avatar-stage.mini .avatar-fallback {
  font-size: .82rem;
}
.chat-ctx-head .avatar-frame-badge.mini {
  font-size: .5rem;
  min-height: 1.05rem;
  padding: .12rem .3rem;
}
.chat-ctx-head-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: .05rem;
}
.chat-ctx-head-text strong {
  color: #1d3d16;
  font-size: .95rem;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  max-width: 100%;
}
.chat-ctx-reacts {
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-between;
  gap: .2rem;
  padding: .15rem .2rem .45rem;
  border-bottom: 1px solid rgba(61,108,34,.22);
  margin-bottom: .15rem;
}
.chat-ctx-react {
  flex: 1 1 0;
  min-width: 0;
  border: 0;
  background: rgba(255,255,255,.45);
  border-radius: 8px;
  padding: .35rem .1rem;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease, transform .12s ease;
}
.chat-ctx-react:hover {
  background: rgba(110, 180, 80, .35);
  transform: scale(1.08);
}
.chat-ctx-react.is-mine {
  background: rgba(110, 180, 80, .55);
  box-shadow: inset 0 0 0 1.5px rgba(45, 100, 30, .55);
}
.chat-msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: .28rem;
  margin-top: .4rem;
}
.chat-react-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  border: 1px solid rgba(61,108,34,.28);
  background: rgba(255,255,255,.55);
  border-radius: 999px;
  padding: .12rem .4rem .12rem .32rem;
  font: inherit;
  font-size: .88rem;
  line-height: 1.2;
  color: #1d3d16;
  cursor: pointer;
}
.chat-react-chip:hover {
  background: rgba(110, 180, 80, .28);
}
.chat-react-chip.is-mine {
  background: rgba(110, 180, 80, .42);
  border-color: rgba(45, 100, 30, .55);
  font-weight: 750;
}
.chat-react-chip.is-readonly {
  cursor: default;
  opacity: .85;
  pointer-events: none;
}
.chat-react-chip.is-readonly:hover {
  background: rgba(255,255,255,.55);
}
.chat-react-count {
  font-size: .72rem;
  font-weight: 800;
  color: #3d5a32;
  min-width: .7rem;
}
.chat-ctx-item {
  border: 0;
  background: transparent;
  text-align: left;
  padding: .55rem .65rem;
  border-radius: 8px;
  font: inherit;
  font-weight: 750;
  color: #1d3d16;
  cursor: pointer;
}
.chat-ctx-item:hover:not(:disabled) { background: rgba(110, 180, 80, .28); }
.chat-ctx-menu .inline-form .chat-ctx-item { width: 100%; }
.chat-ctx-item:disabled { opacity: .55; cursor: default; }
.chat-ctx-item.danger { color: #8b1e1e; }
.chat-ctx-item.danger:hover:not(:disabled) { background: rgba(192, 57, 43, .16); }
.chat-ctx-item.muted-action {
  color: #5a6e52;
  font-weight: 650;
  margin-top: .1rem;
}

@keyframes chat-hl {
  from { background: rgba(255, 230, 120, .85); }
  to { background: rgba(255,255,255,.55); }
}

.chat-msg-meta {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  margin-bottom: .15rem;
}
.chat-msg-author { font-weight: 800; color: #24501c; font-size: .88rem; }
.chat-msg.chat-style-pixel {
  border-inline-start: 3px solid #517e98;
}
.chat-msg.chat-style-pixel:not(.is-selected) {
  background: linear-gradient(105deg, #d6edf9, #edf7fc);
}
@property --guardian-trace-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}
@property --guardian-crystal-glow {
  syntax: "<number>";
  inherits: false;
  initial-value: .12;
}
.chat-msg.chat-style-guardian {
  --guardian-face: #0d2d27;
  --guardian-outline: #38856a;
  --guardian-perimeter: 8px 0, calc(100% - 8px) 0,
    calc(100% - 8px) 4px, calc(100% - 4px) 4px, calc(100% - 4px) 8px, 100% 8px,
    100% calc(100% - 8px), calc(100% - 4px) calc(100% - 8px),
    calc(100% - 4px) calc(100% - 4px), calc(100% - 8px) calc(100% - 4px),
    calc(100% - 8px) 100%, 8px 100%, 8px calc(100% - 4px), 4px calc(100% - 4px),
    4px calc(100% - 8px), 0 calc(100% - 8px), 0 8px, 4px 8px, 4px 4px, 8px 4px;
  position: relative;
  isolation: isolate;
  border: 0;
  background: transparent;
  padding: .65rem .75rem;
}
.chat-msg.chat-style-guardian.is-selected {
  --guardian-face: #17483b;
  --guardian-outline: #65bb94;
}
.chat-style-guardian .chat-msg-body {
  color: #edf9f2;
}
.chat-style-guardian .chat-msg-author,
.chat-style-guardian .chat-msg-reply-quote strong,
.chat-style-guardian .chat-msg-check {
  color: #b8f5d8;
}
.chat-style-guardian .chat-msg-meta > .muted,
.chat-style-guardian .chat-msg-fwd,
.chat-style-guardian .chat-msg-reply-quote span {
  color: #d1e9dc;
}
.chat-style-guardian .chat-msg-reply-quote {
  background: rgba(4, 23, 19, .52);
  border-inline-start-color: #61ba95;
}
.chat-style-guardian .chat-msg-body :is(.chat-mention, .chat-cmd) {
  color: #a4e7ff;
  border-bottom-color: currentColor;
}
.chat-msg.chat-style-guardian::before,
.chat-msg.chat-style-guardian::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.chat-msg.chat-style-guardian::before {
  z-index: -2;
  clip-path: polygon(var(--guardian-perimeter));
  image-rendering: pixelated;
  background:
    url('./assets/ui/frames/admin-pixel-guardian-crystals.png') right 12px center / min(144px, 45%) auto no-repeat,
    radial-gradient(ellipse 52px 32px at calc(100% - 42px) 50%,
      rgb(132 255 200 / var(--guardian-crystal-glow, .12)), transparent),
    linear-gradient(90deg, rgba(43, 105, 83, .42), rgba(30, 78, 64, .32) 52%, transparent),
    repeating-conic-gradient(transparent 0% 25%, rgba(105, 199, 166, .085) 0% 50%) 0 0 / 16px 16px,
    var(--guardian-face);
  animation: chat-guardian-crystals 4.4s ease-in-out infinite alternate;
}
.chat-msg.chat-style-guardian::after {
  z-index: -1;
  clip-path: polygon(evenodd, var(--guardian-perimeter), 8px 0, 12px 4px,
    calc(100% - 12px) 4px, calc(100% - 12px) 8px, calc(100% - 8px) 8px,
    calc(100% - 8px) 12px, calc(100% - 4px) 12px, calc(100% - 4px) calc(100% - 12px),
    calc(100% - 8px) calc(100% - 12px), calc(100% - 8px) calc(100% - 8px),
    calc(100% - 12px) calc(100% - 8px), calc(100% - 12px) calc(100% - 4px),
    12px calc(100% - 4px), 12px calc(100% - 8px), 8px calc(100% - 8px),
    8px calc(100% - 12px), 4px calc(100% - 12px), 4px 12px, 8px 12px, 8px 8px, 12px 8px, 12px 4px);
  background:
    conic-gradient(from var(--guardian-trace-angle), transparent 0deg 5deg,
      #368d68 5deg 9deg, #65c49b 9deg 14deg, #d6ffe8 14deg 18deg, transparent 18deg),
    repeating-conic-gradient(rgba(108, 209, 162, .42) 0% 25%, transparent 0% 50%) 0 0 / 8px 8px,
    var(--guardian-outline);
  animation: chat-guardian-trace 5.6s steps(112) infinite;
}
@keyframes chat-guardian-trace {
  to { --guardian-trace-angle: 1turn; }
}
@keyframes chat-guardian-crystals {
  to { --guardian-crystal-glow: .34; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-msg.chat-style-guardian::before,
  .chat-msg.chat-style-guardian::after { animation: none; }
}
.chat-bot-badge {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: .08rem .32rem;
  border-radius: 4px;
  background: #2a7ab8;
  color: #fff;
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .06em;
  line-height: 1.2;
  vertical-align: middle;
  transform: translateY(-1px);
}
.chat-msg-body { font-size: .92rem; color: #1a2e14; word-break: break-word; line-height: 1.35; }
.chat-mention {
  color: #1a5fb4;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed rgba(26, 95, 180, .4);
}
a.chat-mention:hover {
  color: #0d47a1;
  border-bottom-style: solid;
}
a.chat-cmd {
  color: #1a5fb4;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border-bottom: 1px dashed rgba(26, 95, 180, .45);
}
a.chat-cmd:hover {
  color: #0d47a1;
  border-bottom-style: solid;
}

.chat-inline-kb { display: flex; flex-direction: column; gap: .25rem; margin-top: .35rem; }
.chat-inline-row { display: flex; flex-wrap: wrap; gap: .25rem; }

.chat-dock-compose {
  display: flex;
  gap: .4rem;
  padding: .55rem .6rem;
  border-top: 2px solid rgba(61, 108, 34, .35);
  background: rgba(255,255,255,.7);
  align-items: center;
  flex-shrink: 0;
}
.chat-compose-tools {
  display: flex;
  align-items: center;
  gap: .2rem;
  flex: 0 0 auto;
}
.chat-compose-tool {
  width: 2.35rem;
  height: 2.35rem;
  padding: 0;
  border: 2px solid rgba(61, 108, 34, .45);
  border-radius: 8px;
  background: rgba(255,255,255,.85);
  color: #1d3d16;
  font-size: 1.05rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.chat-compose-tool:hover { background: rgba(110, 180, 80, .22); }
.chat-compose-wrap { flex: 1; position: relative; min-width: 0; }
.chat-input {
  width: 100%;
  resize: none;
  min-height: 2.6rem;
  max-height: 5.5rem;
  box-sizing: border-box;
}
.chat-dock-compose > .btn.primary {
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  min-width: 2.6rem;
  padding: 0;
  display: grid;
  place-items: center;
  align-self: center;
  line-height: 1;
  font-size: 1.15rem;
}
.chat-emoji-pop {
  position: absolute;
  left: 0;
  bottom: calc(100% + .35rem);
  z-index: 5;
  width: min(18rem, 100%);
  max-height: 11rem;
  overflow: auto;
  padding: .4rem;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: .2rem;
  border: 2px solid #3d6c22;
  border-radius: 10px;
  background: #f4ffe8;
  box-shadow: 0 8px 18px rgba(30, 60, 20, .22);
}
.chat-emoji-pop button {
  border: 0;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
  border-radius: 6px;
  padding: .2rem;
}
.chat-emoji-pop button:hover { background: rgba(110, 180, 80, .25); }
.chat-compose-preview {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .45rem .65rem;
  margin: .25rem .55rem 0;
  background: rgba(255,255,255,.82);
  border: 2px solid rgba(61,108,34,.28);
  border-radius: 12px;
}
.chat-compose-preview.is-loading {
  border-style: dashed;
}
.chat-compose-preview img {
  width: 4.2rem;
  height: 4.2rem;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid rgba(61,108,34,.35);
  flex: 0 0 auto;
}
.chat-compose-preview-meta {
  display: grid;
  gap: .12rem;
  min-width: 0;
  flex: 1;
}
.chat-compose-preview-meta strong {
  color: #1d3d16;
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-compose-preview-spinner {
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 50%;
  border: 2px solid rgba(61,108,34,.25);
  border-top-color: #3d6c22;
  animation: chat-spin .7s linear infinite;
  flex: 0 0 auto;
}
@keyframes chat-spin {
  to { transform: rotate(360deg); }
}
.chat-msg-image {
  margin: .35rem 0 .15rem;
  max-width: 100%;
}
.chat-msg-image-btn {
  display: block;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  max-width: 100%;
}
.chat-msg-image img {
  display: block;
  max-width: min(100%, 16rem);
  max-height: 14rem;
  border-radius: 10px;
  border: 2px solid rgba(61,108,34,.3);
}
.chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 12000;
  background: rgba(8, 14, 12, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  cursor: zoom-out;
  pointer-events: auto;
}
.chat-lightbox img {
  max-width: min(96vw, 1100px);
  max-height: 92vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  cursor: default;
  background: rgba(255,255,255,.04);
}
.chat-lightbox-close {
  position: absolute;
  top: .75rem;
  right: .85rem;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.45);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.chat-lightbox-close:hover {
  background: rgba(0,0,0,.65);
}
.chat-backup-card {
  margin-top: .4rem;
  padding: .55rem .65rem;
  border: 2px solid rgba(61, 108, 34, .35);
  border-radius: 10px;
  background: rgba(255,255,255,.78);
  display: grid;
  gap: .35rem;
}
.chat-backup-card strong { color: #1d3d16; }
.chat-file-card strong { word-break: break-word; }
.chat-file-bundle-open {
  display: grid;
  gap: .2rem;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.chat-file-select-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .15rem .35rem .35rem;
}
.chat-compose-files {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  align-items: center;
  padding: .25rem 0 .15rem;
}
.chat-share-progress {
  display: grid;
  gap: .35rem;
  padding: .45rem .55rem;
  margin: .15rem 0 .35rem;
  border: 2px solid rgba(61, 108, 34, .28);
  border-radius: 12px;
  background: rgba(255, 255, 255, .88);
}
.chat-share-progress-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem .55rem;
  align-items: baseline;
  color: #1d3d16;
}
.chat-share-progress-bar {
  height: .55rem;
  border-radius: 999px;
  background: rgba(61, 108, 34, .12);
  overflow: hidden;
}
.chat-share-progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5dbd3a, #3f9e3a);
  transition: width .2s ease;
}
.chat-share-progress-fill.indeterminate {
  width: 35%;
  animation: chat-share-indeterminate 1.1s ease-in-out infinite;
}
@keyframes chat-share-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.chat-share-progress-foot {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.chat-compose-file-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  max-width: 100%;
  padding: .2rem .45rem;
  border: 2px solid rgba(61, 108, 34, .3);
  border-radius: 999px;
  background: rgba(255,255,255,.85);
  font-size: .82rem;
  font-weight: 700;
  color: #1d3d16;
}
.chat-compose-file-x {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  padding: 0 .1rem;
  color: #7a2a1c;
}
.chat-file-list-item,
.chat-file-row {
  cursor: default;
}
.chat-room-item.selected {
  border-color: #3f9e3a;
  background: rgba(93, 189, 58, .12);
}
.chat-room-item.attached {
  opacity: .92;
}
.chat-room-item.attached:not(.selected) {
  border-color: rgba(61, 108, 34, .35);
}
.chat-backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
}
.chat-suggest {
  list-style: none;
  margin: 0;
  padding: .2rem;
  position: absolute;
  left: 0; right: 0; bottom: 100%;
  background: #fff;
  border: 2px solid #3d6c22;
  border-radius: 8px;
  max-height: 8rem;
  overflow: auto;
  z-index: 2;
}
.chat-suggest button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: .35rem .45rem;
  cursor: pointer;
  font: inherit;
}
.chat-suggest button:hover { background: rgba(110, 180, 80, .2); }
.chat-readonly-hint { padding: .55rem .75rem; margin: 0; text-align: center; flex-shrink: 0; }

@media (max-width: 1100px) {
  .chat-dock {
    --chat-panel-w: min(32rem, 52vw);
  }
}

@media (max-width: 900px) {
  .chat-dock {
    --chat-panel-w: min(28rem, 78vw);
  }
  .chat-msg .avatar-stage.mini .avatar-ring {
    width: 46px;
    height: 46px;
  }
}

@media (max-width: 720px) {
  .chat-dock {
    --chat-panel-w: calc(100vw - var(--chat-tab-w));
  }
}

/* Floating message toasts — bottom-right */
.chat-msg-popups {
  position: fixed;
  right: 3.2rem;
  bottom: 1rem;
  z-index: 72;
  display: flex;
  flex-direction: column-reverse;
  align-items: stretch;
  gap: .55rem;
  width: min(22rem, calc(100vw - 4.5rem));
  max-height: min(70vh, 28rem);
  overflow: hidden;
  pointer-events: none;
}
.chat-msg-popups.dock-open {
  right: calc(min(38rem, 44vw) + .75rem);
}
.chat-msg-popup {
  pointer-events: auto;
  width: 100%;
  margin: 0;
  border: 0;
  text-align: left;
  font: inherit;
  box-shadow: 0 10px 28px rgba(20, 40, 30, .22), 0 2px 6px rgba(20, 40, 30, .12);
  cursor: pointer;
  animation: chat-popup-in .38s cubic-bezier(.22, 1, .36, 1);
  opacity: 1;
  transition: opacity .4s ease, transform .4s ease;
}
.chat-msg-popup:hover {
  filter: brightness(1.03);
}
.chat-msg-popup.is-fading {
  opacity: 0;
  transform: translateY(10px) scale(.98);
}
.chat-msg-popup .chat-msg-body {
  text-align: left;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-msg-popup .avatar-stage.mini .avatar-ring {
  width: 42px;
  height: 42px;
}
.chat-msg-popup .chat-msg-row {
  padding-bottom: .1rem;
}

@keyframes chat-popup-in {
  from {
    opacity: 0;
    transform: translateY(18px) scale(.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1100px) {
  .chat-msg-popups.dock-open {
    right: calc(min(32rem, 52vw) + .75rem);
  }
}
@media (max-width: 900px) {
  .chat-msg-popups.dock-open {
    right: calc(min(28rem, 78vw) + .75rem);
  }
}
@media (max-width: 720px) {
  .chat-msg-popups {
    right: .75rem;
    bottom: .75rem;
    width: min(22rem, calc(100vw - 1.5rem));
  }
  .chat-msg-popups.dock-open {
    right: .75rem;
    bottom: .75rem;
    /* keep above closed content; dock is full-bleed on mobile */
    max-width: calc(100vw - 1.5rem);
  }
}
