/* Carrier <-> staff messages. Theme tokens only: every brand, light and dark. */
.message-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-field);
  color: var(--color-text);
}
.message-link:hover { background: var(--color-hover); }
.message-link:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.message-link[aria-current="page"] { border-color: var(--color-primary); color: var(--color-primary); }
.message-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--color-danger);
  color: var(--color-danger-contrast);
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.message-threads { list-style: none; margin: 0; padding: 0; }
.message-thread + .message-thread { border-top: 1px solid var(--color-border); }
.message-thread > a {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  color: var(--color-text);
  text-decoration: none;
}
.message-thread > a:hover { background: var(--color-hover); }
.message-thread > a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: -2px; }
.message-thread-avatar { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 50%; background: var(--color-primary-soft); color: var(--color-primary); }
.message-thread-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.message-thread-title { font-weight: 600; }
.message-thread-preview { color: var(--color-text-muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-thread.is-unread .message-thread-preview { color: var(--color-text); font-weight: 600; }
.message-thread-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; color: var(--color-text-muted); font-size: 12px; white-space: nowrap; }
.message-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--color-primary); color: var(--color-primary-contrast); font-size: 11px; font-weight: 700; line-height: 20px; text-align: center; }

.message-empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 32px 16px; text-align: center; color: var(--color-text-muted); }
.message-empty strong { color: var(--color-text); }

/* ---------- Conversation (modern chat) ---------- */
.chat {
  --chat-theirs: color-mix(in srgb, var(--color-text) 8%, var(--color-surface));
  --chat-radius: 18px;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 104px);
  min-height: 460px;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background: var(--color-surface);
  overflow: hidden;
  position: relative;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 92%, var(--color-primary));
}
.chat-back { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; color: var(--color-text-muted); }
.chat-back:hover { background: var(--color-hover); color: var(--color-text); }
.chat-header-avatar, .chat-avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-primary-contrast);
  font-weight: 700;
}
.chat-header-avatar { width: 40px; height: 40px; font-size: 17px; }
.chat-online { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid var(--color-surface); }
.chat-header-text { min-width: 0; }
.chat-title { margin: 0; font-size: 16px; line-height: 1.2; color: var(--color-text); }
.chat-status { margin: 2px 0 0; font-size: 12px; color: var(--color-text-muted); }
.chat-status.is-typing { color: var(--color-primary); font-weight: 600; }
.chat-alert { margin: 0; padding: 8px 16px; background: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface)); color: var(--color-text); font-size: 13px; }

.chat-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; padding: 16px 16px 8px; scroll-behavior: auto; }
.chat-log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.chat-older { align-self: center; margin-bottom: 12px; }
.chat-older-button { border: 1px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: 12px; cursor: pointer; }
.chat-older-button:hover { color: var(--color-text); background: var(--color-hover); }
.chat-divider { display: flex; justify-content: center; margin: 14px 0 10px; }
.chat-divider span { padding: 3px 12px; border-radius: 999px; background: var(--chat-theirs); color: var(--color-text-muted); font-size: 11px; font-weight: 600; letter-spacing: .02em; }

.chat-row { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; animation: chat-in .18s ease-out; }
.chat-row.is-continued { margin-top: 2px; }
.chat-row.is-mine { justify-content: flex-end; }
.chat-row .chat-avatar { width: 28px; height: 28px; font-size: 12px; }
.chat-row.is-theirs.has-next .chat-avatar { visibility: hidden; }
.chat-stack { display: flex; flex-direction: column; gap: 4px; max-width: min(72%, 560px); min-width: 0; }
.chat-row.is-mine .chat-stack { align-items: flex-end; }
.chat-bubble { padding: 9px 14px; border-radius: var(--chat-radius); line-height: 1.45; overflow-wrap: anywhere; box-shadow: 0 1px 1px color-mix(in srgb, var(--color-text) 6%, transparent); }
.chat-bubble p { margin: 0; }
.chat-row.is-theirs .chat-bubble { background: var(--chat-theirs); color: var(--color-text); border-bottom-left-radius: 6px; }
.chat-row.is-mine .chat-bubble { background: var(--color-primary); color: var(--color-primary-contrast); border-bottom-right-radius: 6px; }
.chat-row.is-theirs.is-continued .chat-bubble { border-top-left-radius: 6px; }
.chat-row.is-mine.is-continued .chat-bubble { border-top-right-radius: 6px; }
.chat-meta { display: flex; gap: 6px; align-items: center; font-size: 11px; color: var(--color-text-muted); padding: 0 4px; }
.chat-row.has-next .chat-meta { display: none; }
.chat-seen { display: none; font-weight: 600; }
.chat-row.show-seen .chat-seen { display: inline; }
.chat-row.show-seen .chat-meta { display: flex; }
.chat-row.is-pending .chat-stack { opacity: .65; }
.chat-row.is-failed .chat-bubble { background: color-mix(in srgb, var(--color-danger) 18%, var(--color-surface)); color: var(--color-text); }
.chat-failed { color: var(--color-danger); }
.chat-retry { border: 0; background: none; padding: 0; color: var(--color-primary); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

.chat-images { display: grid; gap: 4px; border-radius: var(--chat-radius); overflow: hidden; max-width: 320px; }
.chat-images-2 { grid-template-columns: 1fr 1fr; }
.chat-image { display: block; background: var(--chat-theirs); }
.chat-image img { display: block; width: 100%; height: 100%; max-height: 260px; object-fit: cover; aspect-ratio: auto; }
.chat-images-2 .chat-image img { aspect-ratio: 1; }
.chat-file { display: flex; align-items: center; gap: 10px; min-width: 220px; max-width: 320px; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: 14px; background: var(--color-surface); color: var(--color-text); text-decoration: none; }
.chat-file:hover { background: var(--color-hover); }
.chat-file-icon { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 44px; flex-shrink: 0; border-radius: 6px; background: color-mix(in srgb, var(--color-danger) 14%, var(--color-surface)); color: var(--color-danger); font-size: 10px; font-weight: 800; }
.chat-file-text { display: flex; flex-direction: column; min-width: 0; }
.chat-file-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-size { font-size: 11px; color: var(--color-text-muted); }

.chat-typing { display: flex; align-items: flex-end; gap: 8px; margin-top: 10px; }
.chat-typing[hidden] { display: none; }
.chat-typing .chat-avatar { width: 28px; height: 28px; font-size: 12px; }
.chat-dots { display: inline-flex; gap: 4px; padding: 12px 14px; border-radius: var(--chat-radius); border-bottom-left-radius: 6px; background: var(--chat-theirs); }
.chat-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--color-text-muted); animation: chat-dot 1.2s infinite ease-in-out; }
.chat-dots i:nth-child(2) { animation-delay: .15s; }
.chat-dots i:nth-child(3) { animation-delay: .3s; }

.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; height: 100%; min-height: 220px; text-align: center; color: var(--color-text-muted); }
.chat-empty[hidden] { display: none; }
.chat-empty strong { color: var(--color-text); font-size: 16px; }
.chat-empty-art { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; margin-bottom: 6px; border-radius: 50%; background: var(--color-primary-soft); color: var(--color-primary); }

.chat-jump { position: sticky; bottom: 8px; left: 50%; transform: translateX(-50%); display: block; margin: 8px auto 0; padding: 7px 14px; border: 0; border-radius: 999px; background: var(--color-primary); color: var(--color-primary-contrast); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; box-shadow: 0 4px 14px color-mix(in srgb, var(--color-text) 20%, transparent); }
.chat-jump[hidden] { display: none; }
.chat-drop { position: absolute; inset: 8px; display: flex; align-items: center; justify-content: center; border: 2px dashed var(--color-primary); border-radius: 14px; background: color-mix(in srgb, var(--color-surface) 88%, var(--color-primary)); color: var(--color-primary); font-weight: 700; pointer-events: none; }
.chat-drop[hidden] { display: none; }

.chat-compose { border-top: 1px solid var(--color-border); padding: 10px 12px 12px; background: var(--color-surface); }
.chat-error { margin: 0 4px 8px; color: var(--color-danger); font-size: 13px; }
.chat-chips { list-style: none; display: flex; gap: 8px; margin: 0 0 8px; padding: 0; overflow-x: auto; }
.chat-chips[hidden] { display: none; }
.chat-chip { position: relative; display: flex; align-items: center; gap: 8px; max-width: 220px; padding: 6px 30px 6px 6px; border: 1px solid var(--color-border); border-radius: 12px; background: var(--color-field); flex-shrink: 0; }
.chat-chip img, .chat-chip-icon { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.chat-chip-icon { display: inline-flex; align-items: center; justify-content: center; background: color-mix(in srgb, var(--color-danger) 14%, var(--color-surface)); color: var(--color-danger); font-size: 10px; font-weight: 800; }
.chat-chip-text { display: flex; flex-direction: column; min-width: 0; }
.chat-chip-name { font-size: 12px; font-weight: 600; color: var(--color-text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-chip-size { font-size: 11px; color: var(--color-text-muted); }
.chat-chip-remove { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border: 0; border-radius: 50%; background: var(--color-hover); color: var(--color-text); font-size: 14px; line-height: 20px; cursor: pointer; }
.chat-compose-row { display: flex; align-items: flex-end; gap: 8px; padding: 4px 4px 4px 6px; border: 1px solid var(--color-control-border, var(--color-border)); border-radius: 24px; background: var(--color-field); }
.chat-compose-row:focus-within { border-color: var(--color-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent); }
.chat-compose textarea { flex: 1; min-height: 24px; max-height: 160px; margin: 8px 0; padding: 0 4px; border: 0; outline: 0; resize: none; background: transparent; color: var(--color-text); font: inherit; line-height: 1.4; }
.chat-attach { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: 50%; color: var(--color-text-muted); cursor: pointer; }
.chat-attach:hover, .chat-attach:focus-within { background: var(--color-hover); color: var(--color-primary); }
.chat-attach input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.chat-send { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--color-primary); color: var(--color-primary-contrast); cursor: pointer; transition: transform .12s ease; }
.chat-send:hover { transform: scale(1.05); }
.chat-send:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.chat-lightbox { max-width: min(92vw, 1100px); max-height: 92vh; padding: 0; border: 0; border-radius: 14px; background: #000; overflow: hidden; }
.chat-lightbox::backdrop { background: rgb(0 0 0 / .78); }
.chat-lightbox img { display: block; max-width: min(92vw, 1100px); max-height: 84vh; object-fit: contain; }
.chat-lightbox-close { position: absolute; top: 10px; right: 10px; display: inline-flex; width: 36px; height: 36px; align-items: center; justify-content: center; border: 0; border-radius: 50%; background: rgb(0 0 0 / .55); color: #fff; cursor: pointer; }
.chat-lightbox-open { display: block; padding: 10px; color: #fff; text-align: center; font-size: 13px; }

@keyframes chat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes chat-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .chat-row, .chat-dots i { animation: none; } }

.message-thread-avatar { background: var(--color-primary); color: var(--color-primary-contrast); font-weight: 700; }

@media (max-width: 720px) {
  .message-link { width: 40px; height: 40px; }
  .chat { height: calc(100dvh - 150px); min-height: 380px; border-radius: 0; border-left: 0; border-right: 0; margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) 0; }
  .chat-body { padding: 12px 10px 6px; }
  .chat-stack { max-width: 84%; }
  .chat-file { min-width: 0; max-width: 100%; }
}
