/*
 * CrashDesk chat — main chat and DMs, ported from chat.bosseo.com's light
 * transcript surface.
 *
 * Every value is a var(): this stylesheet is new, so the design audit holds it
 * at zero token debt. The chat-specific vocabulary (23px avatars, the 9px row
 * rhythm, the dark send button, the unread glow) is declared as a
 * `--cdchat-*` family in app/design-tokens.css rather than inlined here.
 *
 * The panel is a full-surface overlay rather than a workspace, because chat is
 * not one of the eight CrashDesk workspaces and must be reachable from all of
 * them without losing the screen underneath.
 */

/* ── Top-bar launcher ─────────────────────────────────────────── */

.cdchat-launcher {
  display: flex;
  align-items: center;
  gap: var(--cd-space-2);
}

.cdchat-launch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--cdchat-gap-tight);
  height: var(--cd-control-h);
  padding-inline: var(--cd-space-3);
  border: var(--cd-hairline) solid var(--cd-border);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface);
  color: var(--cd-ink-strong);
  font-size: var(--cd-text-control);
  font-weight: var(--cd-weight-medium);
  transition: border-color var(--cd-motion) var(--cd-ease), box-shadow var(--cd-motion) var(--cd-ease);
}

.cdchat-launch:hover {
  border-color: var(--cd-border-strong);
}

.cdchat-launch:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-launch[aria-pressed="true"] {
  border-color: var(--cd-primary);
  color: var(--cd-primary);
  background: var(--cd-primary-surface);
}

/*
 * Unread, lifted from chat.bosseo.com — a coloured border plus a slow
 * breathing glow. The animation is the signal an operator catches out of the
 * corner of an eye; the border is what remains when motion is reduced, so the
 * state is never conveyed by movement alone.
 */
.cdchat-launch.is-unread {
  border-color: var(--cdchat-unread);
  box-shadow: inset 0 0 0 var(--cd-hairline) var(--cdchat-unread-inset), 0 0 0 var(--cd-space-half) var(--cdchat-unread-ring);
  animation: cdchat-unread-glow 1.6s var(--cd-ease) infinite;
}

@keyframes cdchat-unread-glow {
  0%, 100% { box-shadow: inset 0 0 0 var(--cd-hairline) var(--cdchat-unread-inset), 0 0 0 var(--cd-space-half) var(--cdchat-unread-ring); }
  50% { box-shadow: inset 0 0 0 var(--cd-hairline) var(--cdchat-unread-glow), 0 0 0 var(--cd-space-1) var(--cdchat-unread-glow-wide); }
}

.cdchat-launch-count {
  display: inline-grid;
  place-items: center;
  min-width: var(--cd-space-5);
  height: var(--cd-space-5);
  padding-inline: var(--cd-space-1);
  border-radius: var(--cd-radius-pill);
  background: var(--cd-danger);
  color: var(--cd-ink-inverse);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  font-style: normal;
}

/* ── Avatars ──────────────────────────────────────────────────── */

.cdchat-avatar {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cdchat-avatar);
  height: var(--cdchat-avatar);
  border-radius: var(--cdchat-avatar-radius);
  color: var(--cd-ink-inverse);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  letter-spacing: 0;
  background: var(--cdchat-tone-slate);
}

.cdchat-avatar.is-lg {
  width: var(--cdchat-avatar-lg);
  height: var(--cdchat-avatar-lg);
}

.cdchat-avatar[data-tone="coral"] { background: var(--cdchat-tone-coral); }
.cdchat-avatar[data-tone="blue"] { background: var(--cdchat-tone-blue); }
.cdchat-avatar[data-tone="gold"] { background: var(--cdchat-tone-gold); }
.cdchat-avatar[data-tone="violet"] { background: var(--cdchat-tone-violet); }
.cdchat-avatar[data-tone="mint"] { background: var(--cdchat-tone-mint); }
.cdchat-avatar[data-tone="slate"] { background: var(--cdchat-tone-slate); }
.cdchat-avatar[data-tone="ink"] { background: var(--cdchat-tone-ink); }

.cdchat-online-dot {
  position: absolute;
  right: calc(-1 * var(--cd-space-half));
  bottom: calc(-1 * var(--cd-space-half));
  width: var(--cd-space-2);
  height: var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-surface);
  border-radius: var(--cd-radius-pill);
  background: var(--cd-success);
}

/* ── Panel shell ──────────────────────────────────────────────── */

.cdchat-scrim {
  position: fixed;
  inset: 0;
  z-index: var(--cd-layer-dialog);
  display: grid;
  place-items: center;
  padding: var(--cd-space-4);
  background: var(--cd-scrim);
}

.cdchat-panel {
  display: grid;
  grid-template-columns: var(--cdchat-rail-w) 1fr;
  width: var(--cdchat-panel-w);
  height: var(--cdchat-panel-h);
  overflow: hidden;
  border-radius: var(--cd-radius-xl);
  background: var(--cdchat-surface);
  box-shadow: var(--cd-shadow-overlay);
}

.cdchat-panel:focus-visible {
  outline: none;
}

/* ── Rail ─────────────────────────────────────────────────────── */

.cdchat-rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: var(--cd-hairline) solid var(--cdchat-divider);
  background: var(--cdchat-rail-bg);
}

.cdchat-rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cd-space-2);
  height: var(--cdchat-header-h);
  padding-inline: var(--cd-space-4);
  border-bottom: var(--cd-hairline) solid var(--cdchat-divider);
}

.cdchat-rail-title {
  color: var(--cd-ink-heading);
  font-size: var(--cd-text-control);
  font-weight: var(--cd-weight-heavy);
  letter-spacing: var(--cd-tracking-section);
}

.cdchat-rail-body {
  flex: 1;
  min-height: 0;
  padding: var(--cd-space-3);
  overflow-y: auto;
}

.cdchat-rail-label {
  margin: 0 0 var(--cd-space-2);
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  letter-spacing: var(--cd-tracking-kicker);
  text-transform: uppercase;
}

.cdchat-channels {
  display: flex;
  flex-direction: column;
  gap: var(--cd-space-1);
  margin: 0 0 var(--cd-space-5);
  padding: 0;
  list-style: none;
}

.cdchat-channel {
  display: flex;
  align-items: center;
  gap: var(--cdchat-gap);
  width: 100%;
  padding: var(--cdchat-row-pad);
  border: var(--cd-hairline) solid transparent;
  border-radius: var(--cdchat-row-radius);
  background: transparent;
  color: var(--cd-ink-strong);
  font-size: var(--cd-text-small);
  font-weight: var(--cd-weight-medium);
  text-align: left;
  transition: background-color var(--cd-motion-fast) var(--cd-ease), border-color var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-channel:hover {
  background: var(--cd-surface);
}

.cdchat-channel:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-channel[aria-current="true"] {
  border-color: var(--cd-border);
  background: var(--cd-surface);
  font-weight: var(--cd-weight-strong);
}

.cdchat-channel-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdchat-channel-count {
  display: grid;
  place-items: center;
  min-width: var(--cd-space-5);
  height: var(--cd-space-5);
  padding-inline: var(--cd-space-1);
  border-radius: var(--cd-radius-pill);
  background: var(--cd-danger);
  color: var(--cd-ink-inverse);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
}

/* Daily stat tiles on the main-chat rail. */
/* ── Today's numbers, in the header ───────────────────────────── */

/* Four equal columns, so the values read as one strip and the widest number
 * cannot shove the others out of alignment as the day goes on. */
.cdchat-head-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(var(--cdchat-stat-col), 1fr));
  align-items: start;
  gap: var(--cdchat-gap);
  padding: var(--cd-space-1) var(--cd-space-3);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cdchat-rail-bg);
}

.cdchat-head-stats.is-quiet {
  display: block;
  border-color: transparent;
  background: transparent;
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

.cdchat-stat {
  min-width: 0;
  text-align: center;
}

.cdchat-stat-value {
  display: block;
  color: var(--cd-ink-heading);
  font-size: var(--cd-text-lead);
  font-weight: var(--cd-weight-heavy);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--cd-tracking-section);
  line-height: var(--cd-leading-tight);
}

.cdchat-stat-label {
  display: block;
  color: var(--cd-ink-muted);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  letter-spacing: var(--cd-tracking-kicker);
  text-transform: uppercase;
}

.cdchat-stat-note {
  display: block;
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-body);
}

.cdchat-stat-note.is-bad {
  color: var(--cd-danger-ink);
}

/* ── Conversation ─────────────────────────────────────────────── */

.cdchat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

/* Title, then the daily numbers, then the controls.
 *
 * Both outer columns are 1fr so the middle one is centred on the panel rather
 * than on whatever is left over — a title that grows with a long teammate name
 * would otherwise walk the numbers off-centre. */
.cdchat-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: var(--cdchat-gap);
  min-height: var(--cdchat-header-h);
  padding-block: var(--cd-space-2);
  padding-inline: var(--cd-space-5);
  border-bottom: var(--cd-hairline) solid var(--cdchat-divider);
}

.cdchat-head-text {
  min-width: 0;
}

.cdchat-head-mid {
  display: flex;
  justify-content: center;
  min-width: 0;
}

.cdchat-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--cd-space-2);
  min-width: 0;
}

.cdchat-head-title {
  display: block;
  overflow: hidden;
  color: var(--cd-ink-heading);
  font-size: var(--cd-text-lead);
  font-weight: var(--cd-weight-heavy);
  letter-spacing: var(--cd-tracking-section);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdchat-head-sub {
  display: block;
  margin-top: var(--cd-space-half);
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-body);
}

.cdchat-close {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cd-control-h);
  height: var(--cd-control-h);
  padding: 0;
  border: var(--cd-hairline) solid var(--cd-border);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface);
  color: var(--cd-ink-muted);
  font-size: var(--cd-text-body);
  font-weight: var(--cd-weight-strong);
}

.cdchat-close:hover {
  border-color: var(--cd-border-strong);
  color: var(--cd-ink-strong);
}

.cdchat-close:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-transcript {
  flex: 1;
  min-height: 0;
  padding: var(--cd-space-4) var(--cd-space-4) var(--cd-space-2);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cdchat-older {
  display: block;
  width: 100%;
  margin-bottom: var(--cd-space-3);
  padding: var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-sm);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-muted);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-medium);
}

.cdchat-older:hover {
  border-color: var(--cd-border);
  color: var(--cd-ink-strong);
}

.cdchat-older:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-divider {
  display: flex;
  align-items: center;
  gap: var(--cd-space-3);
  margin: var(--cd-space-4) 0 var(--cd-space-3);
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  letter-spacing: var(--cd-tracking-kicker);
  text-transform: uppercase;
}

.cdchat-divider::before,
.cdchat-divider::after {
  flex: 1;
  height: var(--cd-hairline);
  background: var(--cdchat-divider);
  content: "";
}

/*
 * The message row. 36px avatar column, flexible body, 25px time gutter — the
 * source product's grid. Consecutive messages from one person are deliberately
 * not collapsed: an alert card landing between two of a rep's own lines would
 * otherwise read as if the rep had written it.
 */
/* Avatar, then everything else. The old third column existed to hold the time
 * and was too narrow to hold it; the time now sits beside the name, so the
 * trailing gutter only has to clear the hover controls. */
.cdchat-row {
  display: grid;
  position: relative;
  grid-template-columns: var(--cd-space-8) minmax(0, 1fr);
  gap: 0 var(--cdchat-gap-row);
  padding: var(--cdchat-row-pad);
  padding-right: var(--cdchat-row-gutter);
  border-radius: var(--cdchat-row-radius);
  transition: background-color var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-row:hover {
  background: var(--cdchat-row-hover);
}

.cdchat-row.is-pending {
  opacity: 0.55;
}

.cdchat-row.is-failed {
  background: var(--cd-danger-surface);
}

.cdchat-row-avatar {
  grid-row: 1 / span 2;
}

.cdchat-row-head {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--cdchat-gap-tight);
  min-width: 0;
}

.cdchat-row-name {
  color: var(--cd-ink-heading);
  font-size: var(--cdchat-text-name);
  font-weight: var(--cd-weight-strong);
}

.cdchat-row-edited {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-body);
  font-style: italic;
}

.cdchat-row-time {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-body);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cdchat-row-body {
  grid-column: 2;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--cd-ink-strong);
  font-size: var(--cdchat-text-body);
  font-weight: var(--cd-weight-body);
  line-height: var(--cdchat-leading-body);
  white-space: pre-wrap;
}

.cdchat-row-body a {
  color: var(--cdchat-link);
  text-decoration: underline;
}

/* Author controls appear on hover and on keyboard focus, never on touch-only
 * hover emulation alone, so they stay reachable without a pointer. */
.cdchat-row-tools {
  display: flex;
  position: absolute;
  top: var(--cd-space-1);
  right: var(--cd-space-1);
  gap: var(--cd-space-1);
  opacity: 0;
  transition: opacity var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-row:hover .cdchat-row-tools,
.cdchat-row:focus-within .cdchat-row-tools {
  opacity: 1;
}

.cdchat-row-tool {
  padding: var(--cd-space-half) var(--cd-space-1);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-xs);
  background: var(--cd-surface);
  color: var(--cd-ink-muted);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-medium);
}

.cdchat-row-tool:hover {
  color: var(--cd-ink-strong);
}

.cdchat-row-tool:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-edit {
  grid-column: 2;
  display: grid;
  gap: var(--cd-space-2);
}

.cdchat-edit-field {
  width: 100%;
  padding: var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cdchat-composer-border);
  border-radius: var(--cd-radius-sm);
  color: var(--cd-ink-strong);
  font-family: var(--cd-font-sans);
  font-size: var(--cdchat-text-body);
  resize: vertical;
}

.cdchat-edit-field:focus-visible {
  outline: none;
  border-color: var(--cdchat-accent);
  box-shadow: 0 0 0 var(--cd-space-half) var(--cdchat-accent-ring);
}

.cdchat-edit-actions {
  display: flex;
  gap: var(--cd-space-2);
}

/* ── Deeplink chips ───────────────────────────────────────────── */

.cdchat-refs {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: var(--cd-space-1);
  margin-top: var(--cdchat-gap-tight);
}

.cdchat-ref {
  display: inline-flex;
  align-items: center;
  gap: var(--cdchat-gap-tight);
  max-width: 100%;
  padding: var(--cd-space-1) var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-border);
  border-radius: var(--cd-radius-pill);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-strong);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-medium);
  transition: border-color var(--cd-motion-fast) var(--cd-ease), background-color var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-ref:hover {
  border-color: var(--cd-primary);
  background: var(--cd-primary-surface);
  color: var(--cd-primary-dark);
}

.cdchat-ref:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-ref-kind {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-strong);
  letter-spacing: var(--cd-tracking-kicker);
  text-transform: uppercase;
}

.cdchat-ref-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Alert card ───────────────────────────────────────────────── */

.cdchat-alert {
  grid-column: 2;
  margin-top: var(--cdchat-gap-tight);
  padding: var(--cdchat-gap) var(--cd-space-3);
  border: var(--cd-hairline) solid var(--cd-border);
  border-left: var(--cd-space-half) solid var(--cd-ink-muted);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface-subtle);
}

.cdchat-alert[data-severity="ok"] {
  border-left-color: var(--cd-success);
  background: var(--cd-success-surface);
}

.cdchat-alert[data-severity="warn"] {
  border-left-color: var(--cd-warning);
  background: var(--cd-warning-surface);
}

.cdchat-alert[data-severity="error"] {
  border-left-color: var(--cd-danger);
  background: var(--cd-danger-surface);
}

.cdchat-alert-title {
  display: block;
  color: var(--cd-ink-heading);
  font-size: var(--cd-text-small);
  font-weight: var(--cd-weight-heavy);
}

.cdchat-alert-summary {
  display: block;
  margin-top: var(--cd-space-half);
  color: var(--cd-ink-strong);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-body);
}

.cdchat-alert-fields {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cd-space-1);
  margin: var(--cd-space-2) 0 0;
  padding: 0;
  list-style: none;
}

.cdchat-alert-field {
  padding: var(--cd-space-half) var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-pill);
  background: var(--cd-surface);
  font-size: var(--cdchat-text-meta);
}

.cdchat-alert-field b {
  color: var(--cd-ink-quiet);
  font-weight: var(--cd-weight-strong);
  letter-spacing: var(--cd-tracking-kicker);
  text-transform: uppercase;
}

.cdchat-alert-field span {
  color: var(--cd-ink-strong);
  font-weight: var(--cd-weight-medium);
}

/* ── Composer ─────────────────────────────────────────────────── */

.cdchat-composer {
  display: grid;
  gap: var(--cd-space-2);
  padding: var(--cd-space-3) var(--cd-space-4) var(--cd-space-4);
  border-top: var(--cd-hairline) solid var(--cdchat-divider);
  background: var(--cdchat-surface);
}

.cdchat-composer-refs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cd-space-1);
}

.cdchat-composer-box {
  display: flex;
  align-items: flex-end;
  gap: var(--cd-space-2);
  padding: var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cdchat-composer-border);
  border-radius: var(--cd-radius-lg);
  background: var(--cd-surface);
  transition: border-color var(--cd-motion-fast) var(--cd-ease), box-shadow var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-composer-box:focus-within {
  border-color: var(--cdchat-accent);
  box-shadow: 0 0 0 var(--cd-space-half) var(--cdchat-accent-ring);
}

.cdchat-input {
  flex: 1;
  min-height: var(--cd-control-h-sm);
  max-height: var(--cdchat-composer-max);
  padding: var(--cd-space-2);
  border: 0;
  background: transparent;
  color: var(--cd-ink-strong);
  font-family: var(--cd-font-sans);
  font-size: var(--cd-text-small);
  line-height: var(--cdchat-leading-body);
  resize: none;
}

.cdchat-input:focus-visible {
  outline: none;
}

.cdchat-attach {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cd-control-h-sm);
  height: var(--cd-control-h-sm);
  padding: 0;
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-sm);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-muted);
  font-size: var(--cd-text-control);
  font-weight: var(--cd-weight-strong);
}

.cdchat-attach:hover {
  border-color: var(--cd-primary);
  color: var(--cd-primary);
}

.cdchat-attach:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

/* ── Attachments ──────────────────────────────────────────────── */

.cdchat-attachments {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: var(--cdchat-gap-tight);
  margin-top: var(--cd-space-1);
}

.cdchat-composer-files {
  display: flex;
  flex-wrap: wrap;
  gap: var(--cdchat-gap-tight);
  margin-bottom: var(--cd-space-2);
}

/* A fixed frame rather than the image's own size: the transcript stays a tidy
 * strip whatever shape the screenshots are, and nothing reflows as they load. */
.cdchat-shot {
  display: block;
  overflow: hidden;
  width: var(--cdchat-shot-w);
  height: var(--cdchat-shot-h);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface-subtle);
}

.cdchat-shot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cdchat-shot:hover {
  border-color: var(--cd-primary);
}

.cdchat-shot:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-shot-wrap {
  position: relative;
}

.cdchat-shot-download {
  position: absolute;
  inset: auto 6px 6px auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  background: var(--cd-surface);
  color: var(--cd-primary);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-sm);
}

.cdchat-shot-download:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-file-chip {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--cdchat-gap-tight);
  max-width: var(--cdchat-file-chip-max);
  padding: var(--cd-space-1) var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-strong);
  text-decoration: none;
}

a.cdchat-file-chip:hover {
  border-color: var(--cd-primary);
}

a.cdchat-file-chip:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-file-chip.is-uploading {
  grid-template-columns: 1fr;
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

.cdchat-file-glyph {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-chip);
}

.cdchat-file-thumb {
  width: var(--cdchat-thumb);
  height: var(--cdchat-thumb);
  border-radius: var(--cd-radius-xs);
  object-fit: cover;
}

.cdchat-file-text {
  min-width: 0;
}

.cdchat-file-text b {
  display: block;
  overflow: hidden;
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdchat-file-text small {
  display: block;
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

/* ── Mentions and emoji ───────────────────────────────────────── */

.cdchat-mention {
  padding: 0 var(--cd-space-half);
  border-radius: var(--cd-radius-xs);
  background: var(--cdchat-accent-ring);
  color: var(--cdchat-accent);
  font-weight: var(--cd-weight-strong);
}

/* Being named is the one thing a rep must not scroll past. */
.cdchat-mention.is-me {
  background: var(--cd-warning-surface);
  color: var(--cd-warning-ink);
}

.cdchat-menu {
  display: grid;
  gap: var(--cd-space-half);
  max-height: var(--cdchat-menu-max);
  margin-bottom: var(--cd-space-2);
  padding: var(--cd-space-1);
  overflow-y: auto;
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface);
  box-shadow: var(--cd-shadow-sm);
}

.cdchat-menu-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--cdchat-gap-tight);
  padding: var(--cd-space-1) var(--cd-space-2);
  border: 0;
  border-radius: var(--cd-radius-sm);
  background: transparent;
  text-align: left;
}

.cdchat-menu-row:hover,
.cdchat-menu-row[aria-selected="true"] {
  background: var(--cd-surface-subtle);
}

.cdchat-menu-row:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-menu-name {
  overflow: hidden;
  color: var(--cd-ink-strong);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cdchat-menu-handle {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

.cdchat-emoji {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: var(--cd-space-half);
  margin-bottom: var(--cd-space-2);
  padding: var(--cd-space-1);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface);
  box-shadow: var(--cd-shadow-sm);
}

.cdchat-emoji-key {
  height: var(--cd-control-h-sm);
  border: 0;
  border-radius: var(--cd-radius-sm);
  background: transparent;
  font-size: var(--cd-text-lead);
  line-height: 1;
}

.cdchat-emoji-key:hover {
  background: var(--cd-surface-subtle);
}

.cdchat-emoji-key:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-attach.is-open {
  border-color: var(--cd-primary);
  color: var(--cd-primary);
}

/* ── Dictation ────────────────────────────────────────────────── */

.cdchat-mic {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cd-control-h-sm);
  height: var(--cd-control-h-sm);
  padding: 0;
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-sm);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-muted);
  transition:
    border-color var(--cd-motion-fast) var(--cd-ease),
    background-color var(--cd-motion-fast) var(--cd-ease),
    color var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-mic:hover:not(:disabled) {
  border-color: var(--cd-primary);
  color: var(--cd-primary);
}

.cdchat-mic:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

/* Drawn rather than iconised: a capsule over a stand is unmistakably a mic at
 * this size, and it takes no icon set and no extra request. */
.cdchat-mic-glyph {
  position: relative;
  width: var(--cdchat-mic-w);
  height: var(--cdchat-mic-h);
  border-radius: var(--cdchat-mic-w);
  background: currentcolor;
}

.cdchat-mic-glyph::after {
  content: "";
  position: absolute;
  bottom: calc(-1 * var(--cdchat-mic-stand));
  left: 50%;
  width: var(--cdchat-mic-stand);
  height: var(--cdchat-mic-stand);
  transform: translateX(-50%);
  border-radius: 1px;
  background: currentcolor;
}

.cdchat-mic.is-listening {
  border-color: var(--cd-danger-ink);
  background: var(--cd-danger-surface);
  color: var(--cd-danger-ink);
  animation: cdchat-mic-live 1.4s var(--cd-ease) infinite;
}

.cdchat-mic.is-starting,
.cdchat-mic.is-transcribing {
  border-color: var(--cdchat-accent);
  color: var(--cdchat-accent);
}

@keyframes cdchat-mic-live {
  0%, 100% { box-shadow: 0 0 0 0 var(--cd-danger-surface); }
  50% { box-shadow: 0 0 0 var(--cdchat-mic-pulse) transparent; }
}

.cdchat-voice-hint {
  margin: var(--cd-space-1) 0 0;
  color: var(--cdchat-accent);
  font-size: var(--cdchat-text-meta);
  font-weight: var(--cd-weight-medium);
}

.cdchat-voice-hint.is-error {
  color: var(--cd-danger-ink);
}

.cdchat-send {
  display: grid;
  flex: none;
  place-items: center;
  width: var(--cdchat-send-size);
  height: var(--cd-control-h-sm);
  padding: 0;
  border: 0;
  border-radius: var(--cd-radius-sm);
  background: var(--cdchat-send-bg);
  color: var(--cd-ink-inverse);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-strong);
  transition: background-color var(--cd-motion-fast) var(--cd-ease);
}

.cdchat-send:hover:not(:disabled) {
  background: var(--cdchat-send-bg-hover);
}

.cdchat-send:disabled {
  background: var(--cd-border-strong);
}

.cdchat-send:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-composer-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--cd-space-3);
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

.cdchat-count.is-over {
  color: var(--cd-danger-ink);
  font-weight: var(--cd-weight-strong);
}

/* ── Ref picker ───────────────────────────────────────────────── */

.cdchat-picker {
  display: grid;
  gap: var(--cd-space-2);
  padding: var(--cd-space-3);
  border: var(--cd-hairline) solid var(--cd-border);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface-subtle);
}

.cdchat-picker-field {
  width: 100%;
  height: var(--cd-control-h-sm);
  padding-inline: var(--cd-control-pad-x);
  border: var(--cd-hairline) solid var(--cdchat-composer-border);
  border-radius: var(--cd-radius-sm);
  background: var(--cd-surface);
  color: var(--cd-ink-strong);
  font-family: var(--cd-font-sans);
  font-size: var(--cd-text-small);
}

.cdchat-picker-field:focus-visible {
  outline: none;
  border-color: var(--cdchat-accent);
  box-shadow: 0 0 0 var(--cd-space-half) var(--cdchat-accent-ring);
}

.cdchat-picker-results {
  display: grid;
  gap: var(--cd-space-1);
  max-height: var(--cdchat-composer-max);
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.cdchat-picker-hit {
  display: grid;
  gap: var(--cd-space-half);
  width: 100%;
  padding: var(--cd-space-2);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-sm);
  background: var(--cd-surface);
  text-align: left;
}

.cdchat-picker-hit:hover {
  border-color: var(--cd-primary);
  background: var(--cd-primary-surface);
}

.cdchat-picker-hit:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

.cdchat-picker-hit strong {
  color: var(--cd-ink-heading);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-strong);
}

.cdchat-picker-hit span {
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-meta);
}

/* ── States ───────────────────────────────────────────────────── */

.cdchat-note {
  margin: var(--cd-space-4) 0;
  padding: var(--cd-space-4);
  border: var(--cd-hairline) solid var(--cd-border-quiet);
  border-radius: var(--cd-radius-md);
  background: var(--cd-surface-subtle);
  color: var(--cd-ink-muted);
  font-size: var(--cd-text-small);
  text-align: center;
}

.cdchat-note.is-error {
  border-color: var(--cd-danger);
  background: var(--cd-danger-surface);
  color: var(--cd-danger-ink);
}

.cdchat-remove {
  padding: 0 var(--cd-space-1);
  border: 0;
  background: transparent;
  color: var(--cd-ink-quiet);
  font-size: var(--cdchat-text-chip);
  font-weight: var(--cd-weight-strong);
}

.cdchat-remove:hover {
  color: var(--cd-danger);
}

.cdchat-remove:focus-visible {
  outline: none;
  box-shadow: var(--cd-focus-ring);
}

/* ── Scrollbars ───────────────────────────────────────────────── */

.cdchat-transcript,
.cdchat-rail-body,
.cdchat-picker-results {
  scrollbar-color: var(--cdchat-scroll-thumb) transparent;
  scrollbar-width: thin;
}

.cdchat-transcript::-webkit-scrollbar,
.cdchat-rail-body::-webkit-scrollbar,
.cdchat-picker-results::-webkit-scrollbar {
  width: var(--cdchat-scroll-size);
  height: var(--cdchat-scroll-size);
}

.cdchat-transcript::-webkit-scrollbar-thumb,
.cdchat-rail-body::-webkit-scrollbar-thumb,
.cdchat-picker-results::-webkit-scrollbar-thumb {
  border-radius: var(--cd-radius-pill);
  background: var(--cdchat-scroll-thumb);
}

.cdchat-transcript::-webkit-scrollbar-thumb:hover,
.cdchat-rail-body::-webkit-scrollbar-thumb:hover,
.cdchat-picker-results::-webkit-scrollbar-thumb:hover {
  background: var(--cdchat-scroll-thumb-hover);
}

.cdchat-transcript::-webkit-scrollbar-track,
.cdchat-rail-body::-webkit-scrollbar-track,
.cdchat-picker-results::-webkit-scrollbar-track {
  background: transparent;
}

/* ── Responsive ───────────────────────────────────────────────── */

@media (max-width: 900px) {
  .cdchat-panel {
    grid-template-columns: 1fr;
  }

  /* Three across stops fitting here, so the numbers take their own row under
   * the title rather than squeezing it to nothing. Still four columns. */
  .cdchat-head {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .cdchat-head-mid {
    grid-row: 2;
    grid-column: 1 / -1;
  }

  .cdchat-head-stats {
    width: 100%;
  }

  .cdchat-rail {
    display: none;
  }

  .cdchat-rail.is-open {
    display: flex;
  }

}

@media (max-width: 640px) {
  .cdchat-scrim {
    padding: 0;
  }

  .cdchat-panel {
    width: 100%;
    height: 100%;
    border-radius: 0;
  }

  .cdchat-launch-text {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cdchat-launch.is-unread,
  .cdchat-mic.is-listening {
    animation: none;
  }
}
