/* Chat (docs/chat.md, design/chat): the Messages page, a ticket's Chat tab,
   the @ list and alert settings. Chat's own accent is the label-4 ink blue,
   so a person's message never reads as the sage agent panel. Every value
   comes from a token in organic.css, canopy.css or theme-dark.css. */

:root {
  --ch-accent: var(--cnpy-label-4-fg);
  --ch-accent-soft: var(--cnpy-label-4-bg);
  --ch-on-accent: var(--cnpy-canvas);
  --ch-me-wash: color-mix(in srgb, var(--cnpy-label-4-bg) 55%, var(--cnpy-card));
  --ch-list-w: 312px;
  --ch-av: 36px;
}

/* the page: list and conversation side by side, as tall as the window */
.ch-page {
  display: grid; grid-template-columns: var(--ch-list-w) minmax(0, 1fr);
  height: calc(100dvh - 2 * clamp(16px, 2.6vw, 36px)); min-height: 480px;
  background: var(--cnpy-card); border: 1px solid var(--cnpy-line); border-radius: 22px; box-shadow: var(--cnpy-elev-1); overflow: hidden;
  container: ch-page / inline-size;
}
/* with the agent panel open beside it, the list gives the conversation room */
@container ch-page (max-width: 820px) {
  .ch-list-head { padding: 14px 10px 8px 14px; }
  .ch-row-time { display: none; }
}
@media (min-width: 861px) and (max-width: 1500px) {
  .ch-page { --ch-list-w: 272px; }
}
.ch-list { display: flex; flex-direction: column; min-height: 0; background: var(--cnpy-canvas); border-right: 1px solid var(--cnpy-line); }
.ch-list-head { padding: 18px 14px 10px 18px; display: flex; flex-direction: column; gap: 12px; }
.ch-list-title { display: flex; align-items: center; gap: 8px; }
.ch-list-title h1 { margin: 0; flex: 1; font-size: var(--cnpy-fs-2xl); font-weight: var(--cnpy-w-bold); letter-spacing: -0.02em; }
.ch-icon-btn { color: var(--cnpy-muted); }
.ch-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.ch-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--cnpy-line-strong); background: var(--cnpy-card); color: var(--cnpy-text-2);
  font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); text-decoration: none;
}
.ch-chip:hover { background: var(--cnpy-hover); }
.ch-chip[aria-current="page"] { background: var(--cnpy-text); border-color: var(--cnpy-text); color: var(--cnpy-canvas); }
.ch-n, .ch-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--ch-accent); color: var(--ch-on-accent); font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-bold); line-height: 1;
}
.ch-chip[aria-current="page"] .ch-n { background: var(--cnpy-canvas); color: var(--cnpy-text); }

.ch-sections { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 14px; }
.ch-sec + .ch-sec { margin-top: 4px; }
.ch-sec-head {
  display: flex; align-items: center; gap: 6px; padding: 10px 10px 4px; cursor: pointer; list-style: none;
  font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-semibold); letter-spacing: 0.07em; text-transform: uppercase; color: var(--cnpy-muted);
}
.ch-sec-head::-webkit-details-marker { display: none; }
.ch-sec-head .ch-ico { transition: transform var(--cnpy-dur-1) var(--cnpy-ease); }
.ch-sec:not([open]) .ch-sec-head .ch-ico { transform: rotate(-90deg); }
.ch-rows { list-style: none; margin: 0; padding: 0; }
.ch-row {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 7px 10px; border-radius: 12px;
  color: var(--cnpy-text); text-decoration: none;
}
.ch-row:hover { background: var(--cnpy-hover); }
.ch-row[aria-current="page"] { background: var(--cnpy-card); box-shadow: var(--cnpy-elev-1); }
.ch-row-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.ch-row-top { display: flex; align-items: baseline; gap: 8px; }
.ch-row-name { flex: 1; min-width: 0; font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-medium); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-row-time { font-size: var(--cnpy-fs-tag); color: var(--cnpy-muted); }
.ch-row-prev { font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-row-unread .ch-row-name { font-weight: var(--cnpy-w-bold); }
.ch-row-unread .ch-row-prev { color: var(--cnpy-text-2); }
.ch-row-muted { opacity: 0.62; }
.ch-row-at {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 999px;
  background: var(--ch-accent-soft); color: var(--ch-accent); font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-bold);
}
.ch-dot-unread { width: 9px; height: 9px; border-radius: 999px; background: var(--ch-accent); flex: none; }
.ch-list-empty { margin: 14px 12px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }

/* avatars: people get initials on the label palette; agents keep the spark */
.ch-av {
  width: var(--ch-av); height: var(--ch-av); flex: none; border-radius: 999px; display: grid; place-items: center;
  font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-bold); letter-spacing: -0.01em;
}
.ch-av-sm { width: 30px; height: 30px; font-size: var(--cnpy-fs-micro); }
.ch-av-0 { background: var(--cnpy-label-0-bg); color: var(--cnpy-label-0-fg); }
.ch-av-1 { background: var(--cnpy-label-1-bg); color: var(--cnpy-label-1-fg); }
.ch-av-3 { background: var(--cnpy-label-3-bg); color: var(--cnpy-label-3-fg); }
.ch-av-4 { background: var(--cnpy-label-4-bg); color: var(--cnpy-label-4-fg); }
.ch-av-5 { background: var(--cnpy-label-5-bg); color: var(--cnpy-label-5-fg); }
.ch-av-6 { background: var(--cnpy-label-6-bg); color: var(--cnpy-label-6-fg); }
.ch-av-chan { background: var(--cnpy-well); color: var(--cnpy-text-2); border-radius: 10px; }
/* the way into a new DM, always last under Direct messages */
.ch-av-start { background: var(--ch-accent-soft); color: var(--ch-accent); border-radius: 10px; }
.ch-row-start { min-height: 0; }
.ch-row-start .ch-row-name { color: var(--ch-accent); font-weight: var(--cnpy-w-semibold); }
.ch-av-agent { background: var(--color-accent-2-600); color: var(--color-neutral-100); }

/* the conversation */
.ch-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--cnpy-card); }
.ch-conv { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--cnpy-card); }
.ch-conv-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--cnpy-line); }
.ch-back { display: none; }
.ch-conv-title { min-width: 0; flex: 1; }
.ch-conv-name {
  margin: 0; display: flex; align-items: center; gap: 8px; font-size: var(--cnpy-fs-lg); font-weight: var(--cnpy-w-bold);
  letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ch-conv-meta { margin: 4px 0 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-scope {
  display: inline-flex; align-items: center; gap: 4px; min-height: 24px; padding: 0 10px; border-radius: 999px;
  background: var(--cnpy-well); color: var(--cnpy-text-2); font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); text-decoration: none;
}
.ch-scope:hover { background: var(--cnpy-press); }
.ch-mono { font-family: var(--cnpy-font-mono); font-size: 0.92em; }
.ch-level {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--cnpy-line-strong); color: var(--cnpy-text-2); font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); white-space: nowrap;
}

.ch-bar { display: flex; align-items: center; gap: 10px; padding: 9px 18px; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); }
.ch-bar[hidden] { display: none; }
.ch-bar-offline { background: var(--cnpy-label-3-bg); color: var(--cnpy-label-3-fg); }
.ch-bar-degraded { background: var(--cnpy-well); color: var(--cnpy-text-2); font-weight: var(--cnpy-w-medium); }

.ch-thread { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 18px 12px; display: flex; flex-direction: column; overscroll-behavior: contain; }
.ch-thread > :first-child { margin-top: auto; }
.ch-thread-top > :first-child { margin-top: 0; }
.ch-older { display: flex; justify-content: center; padding: 8px 0; }
.ch-btn-sm { min-height: 32px; font-size: var(--cnpy-fs-sm); }
.ch-day { display: flex; align-items: center; gap: 12px; margin: 14px 0 6px; font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-muted); }
.ch-day::before, .ch-day::after { content: ""; flex: 1; height: 1px; background: var(--cnpy-line); }
.ch-new { display: flex; align-items: center; gap: 10px; margin: 10px 0 4px; font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-bold); color: var(--ch-accent); }
.ch-new::after { content: ""; flex: 1; height: 1px; background: var(--ch-accent); opacity: 0.4; }

.ch-msg {
  position: relative; display: grid; grid-template-columns: var(--ch-av) minmax(0, 1fr); column-gap: 12px;
  padding: 6px 8px; margin: 0 -8px; border-radius: 12px;
}
.ch-msg:hover, .ch-msg:focus-within { background: var(--cnpy-hover); }
.ch-msg:target { background: var(--ch-me-wash); }
.ch-msg-me { background: var(--ch-me-wash); }
.ch-msg-gutter { display: none; }
.ch-msg-cont { padding-top: 1px; padding-bottom: 1px; }
.ch-msg-cont > .ch-av { visibility: hidden; height: 0; }
.ch-msg-cont .ch-msg-head { display: none; }
.ch-msg-cont .ch-msg-gutter {
  display: block; grid-column: 1; grid-row: 1; align-self: start; padding-top: 3px; text-align: right;
  font-size: var(--cnpy-fs-micro); color: transparent;
}
.ch-msg-cont:hover .ch-msg-gutter, .ch-msg-cont:focus-within .ch-msg-gutter { color: var(--cnpy-muted); }
.ch-msg-main { min-width: 0; grid-column: 2; }
.ch-msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.ch-msg-name { font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-bold); }
.ch-msg-time, .ch-edited { font-size: var(--cnpy-fs-tag); color: var(--cnpy-muted); }
.ch-msg-body { font-size: var(--cnpy-fs-base); line-height: var(--cnpy-lh-body); overflow-wrap: anywhere; }
.ch-msg-body > :first-child { margin-top: 0; }
.ch-msg-body > :last-child { margin-bottom: 0; }
.ch-msg-body p { margin: 0 0 4px; }
.ch-msg-gone { margin: 0; font-style: italic; color: var(--cnpy-muted); }
.ch-msg-deleted .ch-msg-name { color: var(--cnpy-text-2); }
.ch-mention { padding: 0 4px; border-radius: 6px; background: var(--cnpy-well); font-weight: var(--cnpy-w-semibold); }
.ch-mention-me { background: var(--ch-accent-soft); color: var(--ch-accent); }
.ch-agent-tag {
  font-size: var(--cnpy-fs-micro); font-weight: var(--cnpy-w-bold); letter-spacing: 0.04em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 6px; background: var(--color-accent-2-200); color: var(--color-accent-2-800);
}
/* an agent's reply while it is written: the card holds a still "working"
   line until the first words arrive, then the words with a small ellipsis
   under them (the dots are the typing dots, and still under reduced motion) */
.ch-working { display: flex; align-items: center; gap: 8px; min-height: 40px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-text-2); }
.ch-writing { display: flex; align-items: center; gap: 8px; margin: 4px 0 0 4px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-msg-streaming .ch-agent-card { border-style: dashed; }

/* what a send says about itself, to the sender alone */
.ch-notices { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.ch-notices:empty { display: none; }
.ch-note {
  display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 8px 8px 8px 12px; border-radius: 10px;
  background: var(--cnpy-well); border: 1px solid var(--cnpy-line-strong); font-size: var(--cnpy-fs-sm); color: var(--cnpy-text);
  transition: opacity var(--cnpy-dur-2) var(--cnpy-ease-out), transform var(--cnpy-dur-2) var(--cnpy-ease-out);
}
.ch-note span { flex: 1; padding-top: 4px; }
.ch-note-close { flex: none; width: 28px; height: 28px; min-height: 28px; color: var(--cnpy-muted); }
@starting-style { .ch-note { opacity: 0; transform: translateY(4px); } }

.ch-agent-card { margin-top: 4px; padding: 10px 14px; border-radius: 14px; border-top-left-radius: 6px; background: var(--cnpy-sage-wash); border: 1px solid var(--cnpy-sage-line); }

.ch-msg-actions {
  position: absolute; right: 10px; top: -14px; display: none; gap: 2px; padding: 2px;
  border-radius: 10px; background: var(--cnpy-card); border: 1px solid var(--cnpy-line-strong); box-shadow: var(--cnpy-elev-2);
}
.ch-msg:hover .ch-msg-actions, .ch-msg:focus-within .ch-msg-actions { display: flex; }
.ch-msg-actions form { display: contents; }
.ch-act { width: 32px; height: 32px; min-height: 32px; border-radius: 8px; color: var(--cnpy-muted); }
.ch-act:hover { color: var(--cnpy-text); background: var(--cnpy-hover); }
.ch-msg.ch-msg-editing .ch-msg-actions, .ch-msg.ch-msg-editing:hover .ch-msg-actions, .ch-msg.ch-msg-editing:focus-within .ch-msg-actions { display: none; }
.ch-edit { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.ch-edit-input { min-height: 72px; max-height: calc(6 * var(--cnpy-lh-ui) * 1em + 20px); padding: 8px 12px; border-radius: 12px; resize: vertical; font-size: var(--cnpy-fs-base); line-height: var(--cnpy-lh-ui); }
.ch-edit-foot { display: flex; align-items: center; gap: 8px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-edit-foot .btn { min-height: 32px; font-size: var(--cnpy-fs-sm); }

/* a message being sent: dimmed until the server confirms it */
.ch-msg-pending .ch-msg-main { opacity: 0.6; transition: opacity var(--cnpy-dur-2) var(--cnpy-ease-out); }
.ch-msg-pending.ch-msg-failed .ch-msg-main { opacity: 1; }
.ch-msg-pending.ch-msg-failed .ch-msg-body { color: var(--cnpy-text-2); }
.ch-msg-plain { white-space: pre-wrap; }
.ch-send-state { margin: 2px 0 0; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-send-state:empty { display: none; }
.ch-msg-failed .ch-send-state { color: var(--cnpy-danger); font-weight: var(--cnpy-w-semibold); }
.ch-send-state button {
  padding: 0; border: 0; background: none; font: inherit; color: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.ch-failed { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-danger); }
.ch-failed button {
  padding: 0; border: 0; background: none; font: inherit; color: inherit; text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}

/* a month older than two years: its divider offers the month's summary */
.ch-month { margin: 18px 0 6px; }
.ch-month-bar { display: flex; align-items: center; gap: 12px; font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-muted); }
.ch-month-bar::before, .ch-month-bar::after { content: ""; flex: 1; height: 1px; background: var(--cnpy-line); }
.ch-summary-btn {
  flex: none; min-height: 32px; padding: 0 12px; border-radius: 999px; background: var(--cnpy-well); border: 1px solid var(--cnpy-line-strong);
  font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-text-2); text-decoration: none;
}
.ch-summary-btn:hover, .ch-summary-btn:focus-visible { color: var(--cnpy-text); background: var(--cnpy-hover); }
.ch-summary-btn[aria-busy="true"] { opacity: 0.6; cursor: progress; }
.ch-summary {
  margin: 8px 0 4px; padding: 12px 16px; border-radius: 14px; background: var(--cnpy-well); border: 1px solid var(--cnpy-line-strong);
  transition: opacity var(--cnpy-dur-2) var(--cnpy-ease-out), transform var(--cnpy-dur-2) var(--cnpy-ease-out);
}
.ch-summary[hidden] { display: none; }
@starting-style { .ch-summary { opacity: 0; transform: translateY(-4px); } }
.ch-summary-card > :first-child { margin-top: 0; }
.ch-summary-note { margin: 8px 0 0; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-summary-card { max-width: 72ch; }

.ch-typing { display: flex; align-items: center; gap: 8px; min-height: 24px; padding: 0 18px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-dots { display: inline-flex; gap: 3px; }
.ch-dots i { width: 5px; height: 5px; border-radius: 999px; background: currentColor; opacity: 0.55; }

/* messages that arrived while you were scrolled up */
.ch-newpill {
  position: relative; align-self: center; margin: -44px auto 8px; z-index: 2; min-height: 32px; padding: 0 14px; border-radius: 999px;
  border: 0; background: var(--ch-accent); color: var(--ch-on-accent); box-shadow: var(--cnpy-elev-2);
  font: inherit; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); cursor: pointer;
  transition: opacity var(--cnpy-dur-2) var(--cnpy-ease-out), transform var(--cnpy-dur-2) var(--cnpy-ease-out);
}
.ch-newpill[hidden] { display: none; }
@starting-style { .ch-newpill { opacity: 0; transform: translateY(6px); } }

/* the edit window's last five minutes */
.ch-edit-left { align-self: center; padding: 0 6px 0 8px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); white-space: nowrap; }

/* the composer, just after a mention went in */
.ch-composer-picked { animation: ch-picked var(--cnpy-dur-2) var(--cnpy-ease-out); }
@keyframes ch-picked { from { box-shadow: 0 0 0 5px var(--ch-accent-soft); } }

/* a message opened from a link: highlighted, fading over 1.2 s */
.ch-msg-flash { animation: ch-flash 1.2s var(--cnpy-ease-out); }
@keyframes ch-flash { from { background: var(--ch-accent-soft); } }

/* a badge whose count went up: one small spring */
.cnpy-bump { animation: cnpy-bump var(--cnpy-dur-3) var(--cnpy-ease-spring); }
@keyframes cnpy-bump { 40% { transform: scale(1.22); } }

/* on phones a long press shows a message's actions */
.ch-msg-touched .ch-msg-actions { display: flex; }

/* asking for sound, in context: at the top, so it never covers the toast
   stack at the bottom that the same message just added to */
.ch-ask {
  position: fixed; left: 50%; top: max(72px, calc(env(safe-area-inset-top) + 64px)); transform: translateX(-50%); z-index: 91;
  width: min(420px, calc(100vw - 24px)); padding: 14px 16px; border-radius: 16px;
  background: var(--cnpy-card); border: 1px solid var(--cnpy-line-strong); box-shadow: var(--cnpy-elev-3);
  transition: opacity var(--cnpy-dur-3) var(--cnpy-ease-out), transform var(--cnpy-dur-3) var(--cnpy-ease-out);
}
@starting-style { .ch-ask { opacity: 0; transform: translate(-50%, -10px); } }
.ch-ask p { margin: 0 0 10px; font-size: var(--cnpy-fs-md); }
.ch-ask-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.ch-ask-yes { background: var(--ch-accent); border-color: var(--ch-accent); color: var(--ch-on-accent); }

/* the composer: one line that grows as you type */
.ch-composer-wrap { padding: 0 18px 14px; }
.ch-hint { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; padding: 8px 12px; border-radius: 10px; background: var(--cnpy-well); font-size: var(--cnpy-fs-sm); color: var(--cnpy-text-2); }
.ch-hint span { flex: 1; }
.ch-hint-close { width: 28px; height: 28px; min-height: 28px; }
.ch-composer {
  position: relative; display: flex; align-items: flex-end; gap: 6px; padding: 5px 5px 5px 14px;
  border: 1px solid var(--cnpy-field-line); border-radius: 22px; background: var(--cnpy-card); box-shadow: var(--cnpy-elev-1);
}
.ch-composer:focus-within { border-color: var(--ch-accent); box-shadow: 0 0 0 3px var(--ch-accent-soft); }
.ch-input {
  flex: 1; min-height: 38px; max-height: calc(6 * var(--cnpy-lh-ui) * 1em + 16px); overflow-y: auto; padding: 8px 0; border: 0; outline: 0; resize: none; background: transparent;
  color: var(--cnpy-text); font: inherit; font-size: var(--cnpy-fs-base); line-height: var(--cnpy-lh-ui);
}
.ch-input::placeholder { color: var(--cnpy-muted); }
.ch-attach { width: 38px; height: 38px; min-height: 38px; border-radius: 999px; color: var(--cnpy-muted); flex: none; }
.ch-attach:hover { color: var(--cnpy-text); }
.ch-input[data-image-drop] { background: var(--cnpy-well); border-radius: var(--cnpy-radius-ctl); }
.ch-input[data-uploading] + .ch-attach { color: var(--ch-accent); }
.ch-msg-body .md-picture img { max-height: 280px; }
.ch-msg-body .md-gallery { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); max-width: 480px; }
.ch-msg-body .md-gallery .md-picture img { height: 96px; }
.ch-send { width: 38px; height: 38px; min-height: 38px; border-radius: 999px; background: var(--ch-accent); color: var(--ch-on-accent); flex: none; }
.ch-send:hover { background: var(--cnpy-text); color: var(--cnpy-canvas); }
.ch-send[disabled] { background: var(--cnpy-well); color: var(--cnpy-muted); }
.ch-composer-foot { margin: 6px 0 0 14px; font-size: var(--cnpy-fs-tag); color: var(--cnpy-muted); }
.ch-readonly { display: flex; align-items: center; gap: 8px; margin: 0 18px 16px; padding: 10px 14px; border-radius: 12px; background: var(--cnpy-well); font-size: var(--cnpy-fs-sm); color: var(--cnpy-text-2); }

/* the @ list, above the composer */
.ch-suggest {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 8px); z-index: 20; max-width: 420px;
  background: var(--cnpy-card); border: 1px solid var(--cnpy-line-strong); border-radius: 16px; box-shadow: var(--cnpy-elev-3); overflow: hidden;
}
.ch-suggest[hidden] { display: none; }
.ch-suggest-head { padding: 9px 14px 4px; font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-muted); }
.ch-suggest ul { list-style: none; margin: 0; padding: 0 0 6px; }
.ch-opt { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 14px; cursor: pointer; }
.ch-opt[aria-selected="true"] { background: var(--ch-accent-soft); }
.ch-opt[aria-disabled="true"] { cursor: default; opacity: 0.6; }
.ch-opt-body { min-width: 0; display: flex; flex-direction: column; }
.ch-opt-name { font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-opt-hint { font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-opt[aria-disabled="true"] .ch-opt-hint { color: var(--cnpy-danger); font-weight: var(--cnpy-w-semibold); }
.ch-suggest-empty { padding: 12px 14px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }

/* states */
.ch-empty { margin: auto; max-width: 380px; padding: 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ch-empty-thread { margin: auto; }
.ch-empty-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--ch-accent-soft); color: var(--ch-accent); }
.ch-empty-title { margin: 0; font-size: var(--cnpy-fs-lg); font-weight: var(--cnpy-w-bold); }
.ch-empty-text { margin: 0; font-size: var(--cnpy-fs-md); color: var(--cnpy-muted); }
.ch-empty-go { margin-top: 8px; display: inline-flex; align-items: center; gap: 8px; }
.ch-loading { display: grid; grid-template-columns: 36px 1fr; gap: 8px 12px; padding: 16px 0; }
.ch-skel { display: block; border-radius: 8px; background: var(--cnpy-well); }
.ch-skel-av { width: 36px; height: 36px; border-radius: 999px; grid-row: span 2; }
.ch-skel-line { height: 12px; margin-top: 4px; }
.ch-skel-short { width: 55%; }
@media (prefers-reduced-motion: no-preference) {
  .ch-skel { animation: ch-pulse 1.4s var(--cnpy-ease-in-out) infinite; }
  .ch-msg-arrived { animation: ch-in var(--cnpy-dur-3) var(--cnpy-ease-out); }
  /* The live list: a new conversation fades in, a row that moved slides. */
  .ch-row-arrived { animation: ch-in var(--cnpy-dur-3) var(--cnpy-ease-out); }
  .ch-row-moving { transition: transform var(--cnpy-dur-4) var(--cnpy-ease-out); }
}
@keyframes ch-pulse { 50% { opacity: 0.55; } }
@keyframes ch-in { from { opacity: 0; transform: translateY(6px); } }

.ch-mentioned { padding: 8px 0; border-bottom: 1px solid var(--cnpy-line); }
.ch-mentioned-where { display: inline-block; margin: 0 0 4px 48px; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-ink); }

/* the Messages badge in the nav, in chat's colour on the dark nav */
.cnpy-count.ch-nav-count,
.cnpy-navitem[aria-current="page"] .cnpy-count.ch-nav-count { background: var(--cnpy-label-4-bg); color: var(--cnpy-label-4-fg); }

/* a ticket's Comments and Chat tabs */
.ch-tabs { display: flex; gap: 4px; flex: 1; border-bottom: 1px solid var(--cnpy-line); margin-bottom: 4px; }
.ch-tab {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 12px; margin-bottom: -1px;
  border-bottom: 2px solid transparent; color: var(--cnpy-muted); font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-semibold); text-decoration: none;
}
.ch-tab:hover { color: var(--cnpy-text); }
.ch-tab[aria-selected="true"] { color: var(--cnpy-text); border-bottom-color: var(--ch-accent); }
.ch-tab-n { font-size: var(--cnpy-fs-tag); color: var(--cnpy-muted); }
.ch-tabpanel[hidden], [data-ch-tabs] [role="tabpanel"][hidden] { display: none; }
.ch-tabpanel-body { min-height: 120px; }
.ch-panel-note { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); }
.ch-conv-compact { max-height: min(560px, 70dvh); min-height: 240px; margin: 0 -4px; border: 1px solid var(--cnpy-line); border-radius: 16px; overflow: hidden; }
.ch-conv-compact .ch-thread > :first-child { margin-top: 0; }
.ch-conv-compact .ch-thread { padding: 6px 14px 10px; }
.ch-conv-compact .ch-composer-wrap { padding: 0 12px 12px; }

/* a new DM: pick a person */
.ch-new-page { max-width: 640px; }
.ch-backlink { display: inline-flex; align-items: center; gap: 6px; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-text-2); text-decoration: none; }
.ch-new-title { margin: 10px 0 14px; font-size: var(--cnpy-fs-title); }
.ch-new-find { margin-bottom: 10px; }
.ch-people { list-style: none; margin: 0; padding: 0; }

/* account: message alerts */
.ch-alerts { display: flex; flex-direction: column; gap: 12px; }
.ch-alerts-help { display: block; font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); font-weight: var(--cnpy-w-regular); }
.ch-alerts-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Account: notifications when Canopy is closed */
.ch-push { display: flex; flex-direction: column; gap: 14px; }
.ch-push-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.ch-push-state { margin: 0; font-weight: var(--cnpy-w-medium); }
.ch-push-ios { padding: 12px 14px; border-radius: 12px; background: var(--cnpy-card); box-shadow: var(--cnpy-elev-1); font-size: var(--cnpy-fs-sm); }
.ch-push-ios p { margin: 0 0 6px; }
.ch-push-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* an alert toast carries a link to the message, and a click opens it */
.cnpy-notice-go .cnpy-notice-text { cursor: pointer; }
.cnpy-notice-link { font-weight: var(--cnpy-w-bold); color: inherit; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.cnpy-notice-title { display: block; font-weight: var(--cnpy-w-bold); }

@media (prefers-reduced-motion: no-preference) {
  .ch-dots i { animation: ch-dot 1.2s var(--cnpy-ease-in-out) infinite; }
  .ch-dots i:nth-child(2) { animation-delay: 0.15s; }
  .ch-dots i:nth-child(3) { animation-delay: 0.3s; }
}
@keyframes ch-dot { 30% { opacity: 1; transform: translateY(-2px); } }
/* reduced motion: every moving piece has a still version */
@media (prefers-reduced-motion: reduce) {
  .ch-dots i { animation: none !important; opacity: 0.55; }
  .ch-msg-flash { animation: none !important; background: var(--ch-accent-soft); }
  .cnpy-bump, .ch-composer-picked { animation: none !important; }
}

/* opening a conversation: the list stays put and only the conversation
   pane moves (a cross-document view transition) */
.ch-list { view-transition-name: ch-list; }
.ch-pane { view-transition-name: ch-pane; }
::view-transition-old(ch-pane) { animation: var(--cnpy-dur-2) var(--cnpy-ease-out) both ch-pane-out; }
::view-transition-new(ch-pane) { animation: var(--cnpy-dur-3) var(--cnpy-ease-out) both ch-pane-in; }
@keyframes ch-pane-out { to { opacity: 0; } }
@keyframes ch-pane-in { from { opacity: 0; transform: translateX(12px); } }

@media (max-width: 860px) {
  .ch-page { grid-template-columns: minmax(0, 1fr); height: calc(var(--ch-vv, 100dvh) - 56px - 2 * clamp(16px, 2.6vw, 36px)); border-radius: 18px; }
  .ch-page-open .ch-list { display: none; }
  .ch-page:not(.ch-page-open) .ch-pane { display: none; }
  .ch-back { display: inline-flex; margin-left: -8px; }
  .ch-conv-head { padding: 8px 12px; }
  .ch-thread { padding: 6px 12px 10px; }
  .ch-composer-wrap { padding: 0 10px 10px; }
  .ch-composer-foot { display: none; }
  .ch-input { font-size: 16px; }
  .ch-send { width: 44px; height: 44px; }
  .ch-attach { width: 44px; height: 44px; }
  .ch-row { min-height: 60px; }
  .ch-opt { min-height: 56px; }
  .ch-level:not(summary) { display: none; }
  .ch-suggest { max-width: none; }
}

/* phase 3 (docs/chat.md): search, Browse channels, the bell, handles in
   the @ list, the # list, epic chat, quiet hours and People, Teams */

/* search, at the top of the list */
.ch-search {
  display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--cnpy-field-line); background: var(--cnpy-card); color: var(--cnpy-muted);
}
.ch-search:focus-within { border-color: var(--ch-accent); box-shadow: 0 0 0 3px var(--ch-accent-soft); }
.ch-search-input { flex: 1; min-width: 0; height: 36px; border: 0; outline: 0; background: transparent; color: var(--cnpy-text); font: inherit; font-size: var(--cnpy-fs-md); }
.ch-search-input::placeholder { color: var(--cnpy-muted); }
.ch-browse {
  display: flex; align-items: center; gap: 8px; margin: 8px 2px 0; padding: 9px 10px; border-radius: 12px;
  color: var(--cnpy-text-2); font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); text-decoration: none;
}
.ch-browse:hover { background: var(--cnpy-hover); color: var(--cnpy-text); }
.ch-new-lede { margin: -6px 0 14px; font-size: var(--cnpy-fs-md); color: var(--cnpy-muted); }

/* the bell: a disclosure with three choices */
.ch-bell { position: relative; flex: none; }
summary.ch-level { cursor: pointer; list-style: none; background: var(--cnpy-card); transition: background var(--cnpy-dur-1) var(--cnpy-ease-out); }
summary.ch-level::-webkit-details-marker { display: none; }
summary.ch-level:hover, .ch-bell[open] > summary.ch-level { background: var(--cnpy-hover); }
.ch-bell-ico { display: inline-grid; }
.ch-bell-ico > .ch-ico { grid-area: 1 / 1; }
.ch-bell-ico > .ch-ico:last-child, .ch-bell-ico[data-ch-bell-ico="none"] > .ch-ico:first-child { visibility: hidden; }
.ch-bell-ico[data-ch-bell-ico="none"] > .ch-ico:last-child { visibility: visible; }
.ch-bell-ico[data-ch-bell-ico="all"] { color: var(--ch-accent); }
.ch-bell-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 300px; padding: 6px;
  background: var(--cnpy-card); border: 1px solid var(--cnpy-line-strong); border-radius: 16px; box-shadow: var(--cnpy-elev-3);
  transition: opacity var(--cnpy-dur-2) var(--cnpy-ease-out), transform var(--cnpy-dur-2) var(--cnpy-ease-out);
}
@starting-style { .ch-bell[open] .ch-bell-menu { opacity: 0; transform: translateY(-4px); } }
.ch-bell-title { margin: 6px 10px 4px; font-size: var(--cnpy-fs-tag); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-muted); }
.ch-bell-opt {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; min-height: 48px; padding: 8px 10px; border: 0; border-radius: 10px;
  background: none; color: var(--cnpy-text); font: inherit; text-align: left; cursor: pointer;
}
.ch-bell-opt:hover, .ch-bell-opt:focus-visible { background: var(--cnpy-hover); }
.ch-bell-opt[aria-pressed="true"] { background: var(--ch-accent-soft); }
.ch-bell-tick { width: 16px; padding-top: 2px; color: var(--ch-accent); visibility: hidden; }
.ch-bell-opt[aria-pressed="true"] .ch-bell-tick { visibility: visible; }
.ch-bell-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ch-bell-name { font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-semibold); }
.ch-bell-help { font-size: var(--cnpy-fs-sm); color: var(--cnpy-muted); line-height: var(--cnpy-lh-ui); }

/* the @ and # lists: teams, roles and channels have a square mark */
.ch-av-xs { width: 24px; height: 24px; font-size: var(--cnpy-fs-micro); }
.ch-av-team { background: var(--ch-accent-soft); color: var(--ch-accent); border-radius: 10px; }
.ch-opt-handle { margin-left: 2px; font-weight: var(--cnpy-w-regular); color: var(--cnpy-muted); font-size: var(--cnpy-fs-sm); }
.ch-opt-key { font-family: var(--cnpy-font-mono); font-size: 0.92em; color: var(--cnpy-muted); }

/* links in a message: tickets, epics and channels read as small chips */
.ch-msg-body a.cnpy-mention, .ch-msg-body a[href^="/messages/"] {
  display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 7px;
  background: var(--cnpy-well); color: var(--cnpy-text); font-weight: var(--cnpy-w-semibold); text-decoration: none;
}
.ch-msg-body a.cnpy-mention:hover, .ch-msg-body a[href^="/messages/"]:hover { background: var(--cnpy-press); }
.ch-msg-body a.cnpy-mention { font-family: var(--cnpy-font-mono); font-size: 0.92em; }

/* an epic's chat, inside its open row on Epics */
.ch-epic { margin-top: 14px; }
.ch-epic-body { min-height: 120px; }
.ch-mini-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--cnpy-line); }
.ch-mini-title { flex: 1; min-width: 0; }
.ch-mini-name { margin: 0; display: flex; align-items: center; gap: 8px; font-size: var(--cnpy-fs-md); font-weight: var(--cnpy-w-bold); }
.ch-mini-head .ch-conv-meta { margin-top: 2px; }

/* account: quiet hours */
.ch-quiet { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; }
.ch-quiet-times { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; padding-left: 30px; }
.ch-quiet-times[hidden] { display: none; }
.ch-quiet-time .input { width: 124px; }
.ch-quiet-zone { flex-basis: 100%; }
.ch-quiet-error { margin: 0 0 0 30px; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-danger); }

/* People, Teams */
.team-tabs { margin-bottom: 18px; }
.team-notice {
  display: flex; align-items: center; gap: 8px; margin: 0 0 16px; padding: 10px 14px; border-radius: 12px;
  background: var(--ch-accent-soft); color: var(--ch-accent); font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold);
}
.team-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); gap: 24px; align-items: start; }
.team-main { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.team-lede { margin: 0; font-size: var(--cnpy-fs-md); }
.team-table .team-name { font-weight: var(--cnpy-w-semibold); color: var(--cnpy-text); text-decoration: none; }
.team-table .team-name:hover { text-decoration: underline; text-underline-offset: 2px; }
.team-row-open { background: var(--ch-accent-soft); }
.team-handle { font-family: var(--cnpy-font-mono); font-size: var(--cnpy-fs-sm); color: var(--cnpy-text-2); }
.team-reach { display: inline-flex; align-items: center; gap: 8px; }
.team-stack { display: inline-flex; }
.team-stack .ch-av { box-shadow: 0 0 0 2px var(--cnpy-card); }
.team-stack .ch-av + .ch-av { margin-left: -6px; }
.team-empty { padding: 18px; border-radius: 14px; background: var(--cnpy-well); }
.team-empty-title { margin: 0 0 4px; font-weight: var(--cnpy-w-semibold); }
.team-form { display: flex; flex-direction: column; gap: 12px; }
.team-form .ws-h4 { margin: 0; }
.team-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.team-fields .field { display: flex; flex-direction: column; gap: 6px; }
.team-at {
  display: flex; align-items: center; gap: 2px; min-height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--cnpy-field-line); background: var(--cnpy-card); color: var(--cnpy-muted);
}
.team-at:focus-within { border-color: var(--ch-accent); box-shadow: 0 0 0 3px var(--ch-accent-soft); }
.team-at-error { border-color: var(--cnpy-danger); }
.team-at-input { flex: 1; min-width: 0; height: 38px; border: 0; outline: 0; background: transparent; color: var(--cnpy-text); font: inherit; }
.team-error { margin: 0; font-size: var(--cnpy-fs-sm); font-weight: var(--cnpy-w-semibold); color: var(--cnpy-danger); }
.team-card { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 16px; }
.team-card-head { display: flex; align-items: center; gap: 10px; }
.team-card-title { flex: 1; min-width: 0; }
.team-card-name { margin: 0; font-size: var(--cnpy-fs-lg); font-weight: var(--cnpy-w-bold); }
.team-rename > summary { list-style: none; cursor: pointer; }
.team-rename > summary::-webkit-details-marker { display: none; }
.team-rename-form { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.team-rename-form .field { display: flex; flex-direction: column; gap: 6px; }
.team-rename-actions { display: flex; gap: 8px; }
.team-delete { margin-top: 8px; color: var(--cnpy-danger); }
.team-add { display: flex; align-items: flex-end; gap: 8px; }
.team-add .field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.team-members { list-style: none; margin: 0; padding: 0; }
.team-member { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 0; border-top: 1px solid var(--cnpy-line); }
.team-member form { display: contents; }
.team-member-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.team-member-name { font-weight: var(--cnpy-w-semibold); }
.team-empty-members { margin: 0; }
.team-fields .input[aria-invalid="true"] { border-color: var(--cnpy-danger); }

/* phones: after the rules above, so these win */
@media (max-width: 860px) {
  summary.ch-level { width: 40px; height: 40px; padding: 0; justify-content: center; }
  summary.ch-level [data-ch-level-text] { display: none; }
  .ch-bell-menu { width: min(300px, calc(100vw - 48px)); }
  .team-grid { grid-template-columns: minmax(0, 1fr); }
  .team-fields { grid-template-columns: minmax(0, 1fr); }
  .team-card { position: static; }
  .ch-quiet-times { padding-left: 0; }
}
