/* Message level of the tessairact|code chat (W2.1–W2.7, W3.x): rich text, code highlighting, emoji,
   GIFs, link cards, the message menu, results under a message, the agent request line and the
   work-item panel. Tokens come from chat.css. */

/* Rich text */

.chat-text > * + * {
  margin-top: 4px;
}

.chat-text p.chat-rich-p {
  margin: 0;
}

.chat-text pre.chat-codeblock {
  margin: 4px 0;
  max-height: 420px;
  overflow: auto;
}

.chat-text pre.chat-codeblock code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
  white-space: pre;
}

.chat-quote {
  margin: 2px 0;
  padding: 1px 0 1px 10px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted-bright);
}

.chat-rich-list {
  margin: 2px 0;
  padding-left: 22px;
}

.chat-rich-list li + li {
  margin-top: 1px;
}

.chat-hl-keyword { color: var(--purple); font-weight: 600; }
.chat-hl-string { color: var(--lime); }
.chat-hl-comment { color: var(--muted); font-style: italic; }
.chat-hl-number,
.chat-hl-variable { color: var(--amber); }
.chat-hl-literal { color: var(--blue); }
.chat-hl-key { color: var(--cyan); }
.chat-hl-meta { color: var(--blue); }
.chat-hl-added { background: rgba(53, 111, 29, 0.12); color: var(--lime); }
.chat-hl-removed { background: rgba(180, 35, 24, 0.1); color: var(--red); }

/* Work-item chips open the side panel */

button.chat-chip {
  font: inherit;
  font-size: 13px;
  line-height: inherit;
  cursor: pointer;
}

button.chat-chip:hover,
button.chat-chip:focus-visible {
  border-color: var(--cyan);
}

/* Emoji */

.chat-emoji-custom img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: -4px;
}

.chat-reaction .chat-emoji-custom img {
  width: 16px;
  height: 16px;
  vertical-align: -3px;
}

.chat-emoji-picker,
.chat-gif-picker,
.chat-menu {
  position: fixed;
  z-index: 40;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--panel-solid);
  box-shadow: 0 12px 32px rgba(20, 33, 38, 0.2);
}

.chat-emoji-picker {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 6px;
  width: min(340px, calc(100vw - 16px));
  height: min(390px, 70vh);
  padding: 8px;
}

.chat-emoji-search,
.chat-gif-search,
.chat-forward-filter,
.chat-forward-comment {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-solid);
}

.chat-emoji-nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
}

.chat-emoji-tab {
  flex: none;
  width: 30px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
}

.chat-emoji-tab:hover,
.chat-emoji-option:hover,
.chat-emoji-option:focus-visible {
  background: var(--cyan-soft);
}

.chat-emoji-body {
  min-height: 0;
  overflow-y: auto;
}

.chat-emoji-heading {
  position: sticky;
  top: 0;
  margin: 0;
  padding: 4px 2px 2px;
  background: var(--panel-solid);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
}

.chat-emoji-option {
  display: grid;
  place-items: center;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.chat-emoji-option img {
  width: 22px;
  height: 22px;
  object-fit: contain;
}

.chat-emoji-preview,
.chat-emoji-status {
  min-height: 16px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* GIF picker */

.chat-gif-picker {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 6px;
  width: min(420px, calc(100vw - 16px));
  height: min(460px, 75vh);
  padding: 8px;
}

.chat-gif-scroll {
  min-height: 0;
  overflow-y: auto;
}

.chat-gif-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.chat-gif-tile {
  height: 96px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 6px;
  background: var(--panel-raised);
  cursor: pointer;
}

.chat-gif-tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-gif-tile:focus-visible {
  outline-offset: -2px;
}

.chat-gif-sentinel {
  height: 1px;
}

.chat-gif-more {
  display: block;
  margin: 6px auto 0;
}

.chat-gif-foot {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.chat-gif-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.chat-gif-brand {
  flex: none;
  color: var(--text);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

/* Composer: formatting bar, emoji and GIF buttons, upload progress */

.chat-composer-box > .chat-format-bar {
  display: flex;
  grid-column: 1 / -1;
  gap: 2px;
  margin: -2px 0 0 -4px;
  overflow-x: auto;
}

.chat-format-button {
  flex: none;
  min-width: 28px;
  height: 24px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-bright);
  font-size: 13px;
  cursor: pointer;
}

.chat-format-button:hover {
  background: var(--cyan-soft);
  color: var(--text);
}

.chat-format-button[data-format="bold"] { font-weight: 800; }
.chat-format-button[data-format="italic"] { font-style: italic; font-family: Georgia, serif; }
.chat-format-button[data-format="strike"] { text-decoration: line-through; }
.chat-format-button[data-format="code"] { font-family: var(--mono); font-size: 12px; }

.chat-composer-emoji {
  font-size: 17px;
}

.chat-composer-gif {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}

.chat-attachment-progress {
  width: 100%;
  height: 4px;
  margin-top: 3px;
  accent-color: var(--cyan);
}

/* Link cards */

.chat-link-cards {
  display: grid;
  gap: 6px;
  max-width: 560px;
  margin-top: 6px;
}

.chat-link-card {
  display: grid;
  gap: 2px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--cyan);
  border-radius: 8px;
  background: var(--panel-raised);
  color: inherit;
  text-decoration: none;
}

a.chat-link-card[href]:hover {
  border-color: var(--cyan);
}

.chat-link-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  align-items: baseline;
}

.chat-link-card-author {
  font-weight: 700;
}

.chat-link-card-meta {
  color: var(--muted);
  font-size: 12px;
}

.chat-link-card-text {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.chat-link-card-missing {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

/* Message menu */

.chat-menu {
  display: grid;
  min-width: 230px;
  padding: 4px;
}

.chat-menu-item {
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.chat-menu-item:hover:not(:disabled),
.chat-menu-item:focus-visible {
  background: var(--cyan-soft);
}

.chat-menu-item:disabled {
  color: var(--muted);
  cursor: default;
}

.chat-menu-note {
  margin: 4px 10px;
  color: var(--red);
  font-size: 12px;
}

/* Results under a message */

.chat-message-extras {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.chat-translation {
  display: grid;
  gap: 2px;
  padding: 4px 10px;
  border-left: 3px solid var(--blue);
  border-radius: 0 6px 6px 0;
  background: rgba(36, 95, 190, 0.06);
  justify-items: start;
}

.chat-translation[data-state="failed"],
.chat-suggestions[data-state="failed"] {
  border-left-color: var(--red);
}

.chat-extra-label {
  color: var(--muted);
  font-size: 12px;
}

.chat-translation-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chat-suggestion {
  max-width: 100%;
  padding: 3px 10px;
  border: 1px solid var(--cyan);
  border-radius: 999px;
  background: var(--panel-solid);
  color: var(--cyan);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.chat-suggestion:hover {
  background: var(--cyan-soft);
}

.chat-extra-close {
  min-height: 22px;
  padding: 0 6px;
  font-size: 12px;
}

.chat-extra-notice {
  margin: 0;
  color: var(--muted-bright);
  font-size: 12px;
  overflow-wrap: anywhere;
}

/* Agent request line */

div.chat-request {
  flex-wrap: wrap;
  row-gap: 4px;
}

.chat-request-usage {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chat-request-stop,
.chat-request-continue {
  min-height: 24px;
  padding: 1px 8px;
  font-size: 12px;
}

.chat-request-stop {
  color: var(--red);
}

/* Work-item panel */

.chat-work-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  width: min(400px, 100vw);
  padding: 14px 16px 20px;
  overflow-y: auto;
  border-left: 1px solid var(--line-strong);
  background: var(--panel-solid);
  box-shadow: -12px 0 32px rgba(20, 33, 38, 0.16);
}

.chat-work-head {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-work-id {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chat-work-close {
  margin-left: auto;
}

.chat-work-title {
  margin: 8px 0 6px;
  font-size: 18px;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.chat-work-summary {
  margin: 0 0 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-work-facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}

.chat-work-facts dt {
  color: var(--muted);
}

.chat-work-facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.chat-work-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 4px;
}

.chat-work-actions a.chat-button {
  text-decoration: none;
}

.chat-work-note {
  color: var(--muted-bright);
  font-size: 12px;
}

.chat-work-subhead {
  margin: 16px 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-work-discussions {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chat-work-discussion {
  display: grid;
  gap: 2px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.chat-work-discussion:hover {
  border-color: var(--cyan);
}

.chat-work-discussion-meta,
.chat-work-muted {
  color: var(--muted);
  font-size: 12px;
}

.chat-work-discussion-text {
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* Forward dialog and admin emoji */

.chat-forward-list {
  display: grid;
  gap: 2px;
  max-height: 240px;
  margin: 8px 0;
  overflow-y: auto;
}

.chat-forward-option {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.chat-forward-option:hover {
  background: var(--panel-raised);
}

.chat-forward-comment {
  resize: vertical;
}

.chat-emoji-admin-image {
  flex: none;
  width: 28px;
  height: 28px;
  object-fit: contain;
}

/* Message text may use italic and bold even where the font has no such face. */

.chat-text,
.chat-link-card-text,
.chat-translation-text {
  font-synthesis: weight style;
}

/* Narrow screens: the composer's buttons get their own row under the text. */

@media (max-width: 640px) {
  .chat-composer-box {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-composer-tools {
    justify-content: flex-end;
  }
}

/* ---------------------------------------------------------------------------------------------
   Touch layouts (EPIC 0caed80242c8, plan items 3 and 5). mobile_shell.js marks
   <html data-chat-layout="phone|tablet">; desktop and the chat panel of the map pages have no such
   mark and keep the rules above. Phones: no action bar under messages (a long press opens the
   action sheet, message_touch.js), 15 px message text, targets of at least 44 x 44 px in the message
   list. The action sheet and the pickers and panels shown as sheets are styled in message_sheets.css. */

/* The "Message actions" button: for keyboards and screen readers on a phone, shown only with focus. */
.chat-message-actions-open {
  display: none;
}

html[data-chat-layout="phone"] .chat-message .chat-actions {
  display: none;
}

html[data-chat-layout="phone"] .chat-message-actions-open {
  position: absolute;
  top: 4px;
  right: 12px;
  z-index: 2;
  display: inline-flex;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip-path: inset(50%);
  white-space: nowrap;
}

html[data-chat-layout="phone"] .chat-message-actions-open:focus-visible {
  width: auto;
  height: auto;
  min-height: 44px;
  padding: 0 14px;
  overflow: visible;
  border: 1px solid var(--line-strong);
  clip-path: none;
  box-shadow: 0 4px 14px rgba(20, 33, 38, 0.14);
}

/* The press state of a long press; it shows only once the finger rests (a scroll starts sooner). */
html:is([data-chat-layout="phone"], [data-chat-layout="tablet"]) .chat-message {
  transition: background-color 120ms ease;
}

html:is([data-chat-layout="phone"], [data-chat-layout="tablet"]) .chat-message[data-press="on"] {
  background: var(--cyan-soft);
  transition-delay: 90ms;
}

/* The message whose action sheet is open stays marked behind the sheet. */
.chat-message[data-sheet="open"] {
  background: var(--cyan-soft);
}

/* A long press opens the sheet, not the text selection or the browser's link menu (the sheet copies
   the text); edit boxes inside a message keep both. */
html[data-chat-layout="phone"] .chat-message {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: none) and (pointer: coarse) {
  html[data-chat-layout="tablet"] .chat-message {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

html:is([data-chat-layout="phone"], [data-chat-layout="tablet"]) .chat-message :is(input, textarea, [contenteditable]) {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Phone: reading sizes of the message list. */
html[data-chat-layout="phone"] .chat-message {
  padding: 8px 16px;
}

html[data-chat-layout="phone"] .chat-author {
  font-size: 15px;
}

html[data-chat-layout="phone"] .chat-message :is(.chat-time, .chat-edited) {
  font-size: 13px;
}

html[data-chat-layout="phone"] :is(.chat-text, .chat-deleted, .chat-translation-text, .chat-link-card-text) {
  font-size: 15px;
}

html[data-chat-layout="phone"] .chat-text code,
html[data-chat-layout="phone"] .chat-codeblock {
  font-size: 14px;
}

html[data-chat-layout="phone"] .chat-day {
  margin: 14px 16px 6px;
  font-size: 13px;
}

html[data-chat-layout="phone"] :is(.chat-link-card-meta, .chat-extra-label, .chat-extra-notice) {
  font-size: 13px;
}

/* Phone: reactions keep a small pill inside a 44 px target; a tap toggles one as before. */
html[data-chat-layout="phone"] .chat-reactions {
  gap: 0 6px;
  margin-top: 2px;
}

html[data-chat-layout="phone"] .chat-reaction {
  position: relative;
  isolation: isolate;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

html[data-chat-layout="phone"] .chat-reaction::before {
  position: absolute;
  inset: 6px 0;
  z-index: -1;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-solid);
  content: "";
}

html[data-chat-layout="phone"] .chat-reaction[aria-pressed="true"]::before {
  border-color: var(--cyan);
  background: var(--cyan-soft);
}

html[data-chat-layout="phone"] .chat-reaction-count {
  font-size: 14px;
}

html[data-chat-layout="phone"] .chat-reaction .chat-emoji-custom img {
  width: 20px;
  height: 20px;
}

/* Phone: the other controls inside the message list. */
html[data-chat-layout="phone"] :is(.chat-thread-link, .chat-older .chat-button, .chat-confirm .chat-button) {
  min-height: 44px;
  padding: 0 14px;
  font-size: 15px;
}

html[data-chat-layout="phone"] .chat-thread-link {
  margin-left: -10px;
}

html[data-chat-layout="phone"] .chat-confirm {
  font-size: 15px;
}

html[data-chat-layout="phone"] :is(.chat-extra-close, .chat-suggestion, .chat-request-stop, .chat-request-continue) {
  min-height: 44px;
  padding: 0 14px;
  font-size: 14px;
}

html[data-chat-layout="phone"] .chat-request {
  font-size: 14px;
}

/* Phone: the forward dialog (a full-screen dialog there). */
html[data-chat-layout="phone"] :is(.chat-forward-option, .chat-forward-filter) {
  min-height: 44px;
}

html[data-chat-layout="phone"] .chat-forward-list {
  max-height: none;
}

