/* Omni CRM chat shell — Apple HIG materials (system type, quiet surfaces) */

/* Allmatch dark theme tokens scoped to inbox chat shell */
.chat-layout {
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --r-xs: 6px;
  --r-sm: 8px;
  --r-pill: 8px;
  --nav-indicator-dur: 0.28s;
  --nav-indicator-ease: cubic-bezier(0.25, 0.1, 0.25, 1);

  --canvas: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --border: rgba(84, 84, 88, 0.65);
  --border-strong: rgba(84, 84, 88, 0.85);
  --text: #f5f5f7;
  --text-2: #98989d;
  --text-3: #636366;
  --text-faint: #48484a;

  --accent: #d4893a;
  --accent-hover: #e49a4c;
  --accent-weak: rgba(212, 137, 58, 0.18);
  --accent-weak-2: rgba(212, 137, 58, 0.28);
  --on-accent: #1a1208;
  --blue: #d4893a;
  --blue-weak: rgba(212, 137, 58, 0.18);
  --ok: #30d158;
  --ok-weak: rgba(48, 209, 88, 0.18);
  --warn: #ffd60a;
  --warn-weak: rgba(255, 214, 10, 0.18);
  --danger: #ff453a;
  --danger-weak: rgba(255, 69, 58, 0.18);

  --chat-bubble-out-bg: #2a2723;
  --chat-bubble-out-fg: #f2f0eb;
  /* Incoming must read clearly on dark canvas (was nearly same as bg). */
  --chat-bubble-in-bg: #2c2c2e;
  --chat-bubble-in-fg: #f5f5f7;
  --chat-bubble-in-border: rgba(84, 84, 88, 0.65);
  --chat-meta-out: #8a8680;
  --chat-meta-in: #8e8e93;
  --chat-check-out: #c4bfb6;

  font-family: var(--font-ui);
  color: var(--text);
  background: var(--canvas);
  /* Full-bleed under CRM topbar - no outer card frame */
  border: none;
  border-radius: 0;
  overflow: hidden;
  height: 100%;
  min-height: 0;
  flex: 1;
}

.chat-layout .row { display: flex; align-items: center; }
.chat-layout .col { display: flex; flex-direction: column; }
.chat-layout .grow { flex: 1; min-width: 0; }
.chat-layout .gap1 { gap: 4px; }
.chat-layout .gap2 { gap: 8px; }
.chat-layout .gap3 { gap: 12px; }
.chat-layout .faint { color: var(--text-3); }

.chat-layout .avatar {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--accent-weak);
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 800;
}

.chat-layout .avatar__initials {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.chat-layout .avatar__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.06);
  transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.chat-layout .avatar__img.is-loaded {
  opacity: 1;
  transform: scale(1);
}

.chat-layout {
  display: flex;
  --chat-header-pad-y: 12px;
  --chat-header-avatar: 44px;
  --chat-header-h: calc(var(--chat-header-pad-y) * 2 + var(--chat-header-avatar));
}

.chat-list {
  display: flex;
  width: 340px; /* keep in sync with CHAT_LIST_DEFAULT_WIDTH in app.js */
  flex: none;
  flex-direction: column;
  background: var(--surface);
  min-width: 0;
  --chat-list-x: 10px;
  --chat-list-icon-col: 44px;
  --chat-list-col-gap: 10px;
}

.chat-list__header {
  flex: none;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  min-height: var(--chat-header-h);
  padding: var(--chat-header-pad-y) var(--chat-list-x);
  border-bottom: 1px solid var(--border);
}

.chat-list__icon-col {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--chat-list-icon-col);
  flex: none;
}

.chat-list__search {
  display: grid;
  grid-template-columns: var(--chat-list-icon-col) minmax(0, 1fr);
  column-gap: var(--chat-list-col-gap);
  align-items: center;
  width: 100%;
  min-width: 0;
  height: var(--chat-header-avatar);
  border: 0;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  cursor: text;
  transition: background 0.15s ease;
}

.chat-list__search:focus-within {
  background: var(--surface-3);
}

.chat-list__search-icon {
  height: var(--chat-header-avatar);
  color: var(--text-3);
  pointer-events: none;
}

.chat-list__search-input {
  width: 100%;
  min-width: 0;
  height: var(--chat-header-avatar);
  padding: 0 14px 0 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
}

.chat-list__search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.chat-inline-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 13px;
}

.chat-inline-loading__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in oklch, var(--text-3) 28%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-loader-spin 0.75s linear infinite;
}

.chat-list__loading {
  width: 100%;
  height: var(--chat-header-avatar);
  border-radius: var(--r-pill);
  background: var(--surface-2);
}

.chat-list__header--workspace {
  justify-content: flex-start;
}

.chat-list__workspace-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.chat-list__workspace-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

.chat-list__workspace-action {
  flex: none;
  min-width: 36px;
  padding: 6px 10px;
}

.crm-detail-thread {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.crm-detail-thread.is-open {
  display: flex;
}

.crm-detail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 24px;
  background: var(--canvas);
}

.crm-detail-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.crm-detail-tab {
  border: none;
  background: var(--surface-2);
  color: var(--text-2);
  border-radius: 8px;
  padding: 6px 13px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 510;
  transition: background 0.15s ease, color 0.15s ease;
}

.crm-detail-tab:hover {
  background: color-mix(in oklch, var(--accent-weak) 55%, var(--surface));
  color: var(--text);
}

.crm-detail-tab.is-active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.chat-list__scroll {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding-bottom: 6px;
}

.chat-list-resizer {
  flex: none;
  width: 1px;
  align-self: stretch;
  background: var(--border);
  cursor: col-resize;
  position: relative;
  z-index: 2;
  touch-action: none;
  user-select: none;
  transition: background 0.15s ease, width 0.15s ease;
}

.chat-list-resizer::after {
  content: "";
  position: absolute;
  inset: 0 -6px;
}

.chat-list-resizer:hover,
body.chat-list-resizing .chat-list-resizer {
  width: 3px;
  margin-inline: -1px;
  background: color-mix(in oklch, var(--accent) 72%, var(--border));
}

body.chat-list-resizing {
  cursor: col-resize;
  user-select: none;
}

body.chat-list-resizing * {
  cursor: col-resize !important;
}

.chat-list-ratio-menu {
  position: fixed;
  z-index: 120;
  min-width: 232px;
  padding: 8px;
  border-radius: 14px;
  border: 1px solid color-mix(in oklch, var(--accent) 22%, var(--border));
  background: color-mix(in oklch, var(--surface-2) 94%, var(--canvas));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 16px 40px color-mix(in oklch, var(--canvas) 58%, transparent),
    0 0 0 1px color-mix(in oklch, var(--border) 40%, transparent);
  animation: site-select-menu-in 0.18s ease;
}

.chat-list-ratio-menu__title {
  padding: 6px 10px 8px;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.chat-list-ratio-menu__item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.chat-list-ratio-menu__item:hover,
.chat-list-ratio-menu__item:focus-visible {
  background: color-mix(in oklch, var(--surface) 88%, var(--accent-weak));
  outline: none;
}

.chat-list-ratio-menu__item--active {
  background: color-mix(in oklch, var(--accent-weak) 88%, var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--accent) 28%, var(--border));
}

.chat-list-ratio-menu__ratio {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.chat-list-ratio-menu__caption {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.3;
}

.chat-conversation {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  background: var(--canvas);
}

.chat-conversation__auth {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 16px;
  background: var(--canvas);
}

.chat-conversation__auth.is-open,
.chat-conversation__auth:not([hidden]) {
  display: flex;
}

.chat-conversation__auth[hidden] {
  display: none !important;
}

.agent-auth-head {
  width: min(380px, 100%);
  margin: 0 auto 4px;
  text-align: center;
  flex: none;
}

.agent-auth-title {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.25;
}

.agent-auth-sub {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text3, #8b8b8b);
}

.agent-auth-sub[hidden] {
  display: none !important;
}

.agent-factory {
  width: min(420px, 100%);
  margin: 0 auto 8px;
  padding: 10px 12px;
  border: 1px solid var(--border, rgba(255,255,255,0.08));
  border-radius: 12px;
  background: var(--surface2, rgba(255,255,255,0.03));
  flex: none;
}

.agent-factory__bar {
  height: 3px;
  border-radius: 2px;
  background: rgba(120, 120, 128, 0.24);
  overflow: hidden;
}

.agent-factory__bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--accent, #d4893a);
  transition: width 0.28s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.agent-factory__pct {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2, #cfcfcf);
}

.agent-factory__msg {
  margin-top: 2px;
  font-size: 12px;
  line-height: 1.3;
  color: var(--text);
}

.agent-factory__msg[hidden] {
  display: none !important;
}

.agent-factory__stages {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 3px;
}

.agent-factory__stages li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text3, #8b8b8b);
}

.agent-factory__stages li::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  flex: none;
}

.agent-factory__stages li.is-done {
  color: var(--green, #30d158);
}
.agent-factory__stages li.is-done::before { background: var(--green, #30d158); }

.agent-factory__stages li.is-current {
  color: var(--text);
  font-weight: 600;
}
.agent-factory__stages li.is-current::before {
  background: #d4893a;
  box-shadow: 0 0 0 3px rgba(212, 137, 58, 0.25);
}

.agent-factory__stages li.is-failed {
  color: var(--red, #ff453a);
}
.agent-factory__stages li.is-failed::before { background: var(--red, #ff453a); }

.agent-factory__persona {
  margin-top: 6px;
  font-size: 11px;
  line-height: 1.35;
  color: var(--text2, #cfcfcf);
}

.agent-factory__err {
  margin-top: 10px;
  font-size: 12px;
  color: var(--red, #ff453a);
  white-space: pre-wrap;
}

.agent-factory__retry {
  margin-top: 10px;
  width: 100%;
}

.agent-factory__err[hidden],
.agent-factory__persona[hidden] {
  display: none !important;
}

.chat-conversation__header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  min-height: var(--chat-header-h);
  padding: var(--chat-header-pad-y) 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.chat-conversation__header .row.gap3 {
  min-width: 0;
}

.chat-presence-status {
  position: relative;
  display: inline-block;
  max-width: 100%;
  padding-right: 11px;
  font-size: 12.5px;
  line-height: 1.35;
}

.chat-presence-status__text {
  display: inline-block;
  max-width: 100%;
}

.chat-presence-status__dot {
  position: absolute;
  top: 0;
  right: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--surface) 80%, transparent);
}

.chat-presence-status__dot--online {
  background: #22c55e;
}

.chat-list-item {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 8px var(--chat-list-x);
  color: var(--text);
  text-align: left;
  min-width: 0;
  cursor: pointer;
  transition: background 0.12s ease;
}

.chat-list-item:hover {
  background: color-mix(in oklch, var(--surface-2) 72%, transparent);
}

.chat-list-item__row {
  display: grid;
  grid-template-columns: var(--chat-list-icon-col, 44px) minmax(0, 1fr);
  column-gap: var(--chat-list-col-gap, 10px);
  align-items: center;
  min-width: 0;
}

.chat-list-item__body {
  min-width: 0;
  flex: 1;
}

.chat-list-item__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chat-list-item__meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  margin-left: auto;
  max-width: 55%;
}

.chat-list-item__unread {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}

.chat-list-item--unread .chat-list-item__name,
.chat-list-item__preview--unread {
  font-weight: 700;
  color: var(--text);
}

.chat-list-item__name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.25;
}

.chat-list-item__preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.25;
}

.chat-list-item.active {
  background: var(--accent-weak);
}

.chat-list-item.active:hover {
  background: var(--accent-weak);
}

.chat-ai-matching-panel {
  animation: appSlideIn var(--nav-indicator-dur) var(--nav-indicator-ease) both;
}

@media (prefers-reduced-motion: reduce) {
  .chat-ai-matching-panel {
    animation: none;
  }
}

.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  padding: 12px 14px 8px;
  background: var(--canvas);
  min-height: 0;
}

.chat-messages__feed {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  margin-top: auto; /* short threads sit above the dock, not under the header */
  animation: chat-messages-feed-in 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-messages__tail {
  flex: none;
  height: 8px;
}

.chat-messages__older-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 0 14px;
  color: var(--text-3);
  font-size: 12.5px;
}

.chat-messages__loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 160px;
  color: var(--text-3);
  font-size: 13px;
}

.chat-messages__loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid color-mix(in oklch, var(--text-3) 28%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-loader-spin 0.75s linear infinite;
}

@keyframes chat-loader-spin {
  to { transform: rotate(360deg); }
}

@keyframes chat-messages-feed-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Анимация появления элементов списка чатов отключена -
   прогонялась при дозагрузке диалогов с сервера и мозолила глаз. */

@media (prefers-reduced-motion: reduce) {
  .chat-messages__loading-spinner,
  .chat-messages__feed,
  .chat-list__scroll--ready .chat-list-item {
    animation: none;
  }
}
.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.message-row {
  display: grid;
  width: 100%;
  margin-bottom: 8px;
}

.message-row--grouped.message-row--group-first,
.message-row--grouped.message-row--group-mid {
  margin-bottom: 4px;
}

.message-row__avatar,
.message-row__avatar-spacer {
  align-self: flex-end;
  margin-bottom: 1px;
  width: 34px;
  height: 34px;
  flex: none;
}

.message-row__avatar .avatar {
  width: 34px;
  height: 34px;
  font-size: 13px;
}

.message-row.me,
.message-row--outgoing {
  grid-template-columns: minmax(0, 1fr);
}

.message-row.them,
.message-row.ai,
.message-row--incoming {
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: flex-end;
}

.message-row--enter {
  animation: chat-message-in 0.44s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.message-row--enter.message-row--outgoing {
  transform-origin: bottom right;
  animation-name: chat-message-out;
}

.message-row--enter.message-row--incoming,
.message-row--enter.them,
.message-row--enter.ai {
  transform-origin: bottom left;
  animation-name: chat-message-in;
}

@keyframes chat-message-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes chat-message-out {
  from {
    opacity: 0;
    transform: translateY(10px) translateX(8px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) translateX(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .message-row--enter {
    animation: none;
  }
}

.chat-messages__status {
  flex: none;
  min-height: 0;
}

.chat-messages__status:empty {
  display: none;
}

.message-bubble-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  width: fit-content;
  min-width: 0;
  max-width: min(75%, 560px);
}

.message-row.me .message-bubble-wrap,
.message-row--outgoing .message-bubble-wrap {
  grid-column: 1;
  justify-self: end;
  align-items: flex-end;
}

.message-row.them .message-bubble-wrap,
.message-row.ai .message-bubble-wrap,
.message-row--incoming .message-bubble-wrap {
  grid-column: 2;
  justify-self: start;
  align-items: flex-start;
}

.message-bubble-wrap--pending {
  padding-bottom: 18px;
  animation: chat-message-pending 0.36s ease-out both;
}

@keyframes chat-message-pending {
  from {
    opacity: 0.72;
    transform: scale(0.98);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.message-send-status {
  position: absolute;
  left: 0;
  bottom: 0;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  color: var(--text-3);
  opacity: 0.88;
}

.message-bubble {
  width: fit-content;
  max-width: 100%;
  border-radius: 12px;
  padding: 5px 10px 6px;
  background: var(--chat-bubble-in-bg);
  color: var(--chat-bubble-in-fg);
  font-size: 14.5px;
  line-height: 1.35;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.message-bubble--album {
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
}

.message-row.me .message-bubble--album,
.message-row--outgoing .message-bubble--album {
  background: var(--chat-bubble-out-bg);
  color: var(--chat-bubble-out-fg);
}

.message-row.them .message-bubble--album,
.message-row.ai .message-bubble--album,
.message-row--incoming .message-bubble--album {
  background: var(--chat-bubble-in-bg);
}

.message-bubble-album {
  position: relative;
  min-width: 0;
}

.message-bubble-album--solo {
  position: relative;
}

.message-bubble-caption-wrap {
  position: relative;
  padding: 4px 10px 6px;
}

.message-bubble-caption {
  display: block;
  padding-right: 54px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message-bubble-caption-wrap .message-bubble-meta {
  position: absolute;
  right: 8px;
  bottom: 6px;
}

.message-bubble-meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  line-height: 1;
  user-select: none;
  vertical-align: bottom;
}

.message-bubble-meta--overlay {
  position: absolute;
  right: 7px;
  bottom: 7px;
  z-index: 2;
  padding: 2px 7px 2px 8px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
}

.message-bubble-meta--out .message-bubble-meta__time {
  color: var(--chat-meta-out);
}

.message-bubble-meta--out .message-bubble-meta__status {
  color: var(--chat-check-out);
}

.message-bubble-meta--in .message-bubble-meta__time {
  color: var(--chat-meta-in);
}

.message-bubble-meta__status svg,
.message-bubble-meta__status-pending {
  width: 14px;
  height: 14px;
  display: block;
  flex: none;
}

.message-bubble-meta__status-pending {
  opacity: 0.72;
}

.message-bubble-meta__status--failed {
  color: #ff8a70 !important;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  width: 14px;
  text-align: center;
}

.message-delivery-label {
  font-size: 11px;
  line-height: 1.3;
  margin: 4px 6px 0;
  max-width: min(92%, 420px);
  opacity: 0.92;
}

.message-delivery-label--failed {
  color: #ff8a70;
}

.message-delivery-label--pending {
  color: rgba(255, 255, 255, 0.55);
}

.delivery-flash {
  position: absolute;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%);
  z-index: 40;
  max-width: min(92%, 420px);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 8px 28px rgba(0,0,0,0.35);
  pointer-events: none;
}

.delivery-flash--ok {
  background: rgba(48, 209, 88, 0.18);
  color: #7dff9a;
  border: 1px solid rgba(48, 209, 88, 0.35);
}

.delivery-flash--warn {
  background: rgba(255, 107, 74, 0.18);
  color: #ffb0a0;
  border: 1px solid rgba(255, 107, 74, 0.4);
}

.delivery-flash--info {
  background: rgba(10, 132, 255, 0.16);
  color: #9ec9ff;
  border: 1px solid rgba(10, 132, 255, 0.35);
}

#thread {
  position: relative;
}

.message-bubble-meta__time {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.message-bubble-text .message-bubble-meta,
.message-bubble-text--plain > .message-bubble-meta {
  flex: 0 0 auto;
  align-self: flex-end;
  margin-left: auto;
  white-space: nowrap;
}

.message-bubble-sender {
  font-size: 11px;
  line-height: 1.25;
  color: rgba(255, 255, 255, 0.58);
  margin: 0 4px 2px 6px;
  max-width: min(92%, 420px);
}

.message-bubble-sender--stale {
  color: #ffb86c;
}

.message-row.from-me .message-bubble-sender {
  margin-left: auto;
  margin-right: 6px;
  text-align: right;
}

.message-bubble-text__content {
  flex: 1 1 auto;
  min-width: 0;
  word-break: break-word;
  color: inherit;
  opacity: 1;
  white-space: pre-wrap;
}

.message-bubble-text {
  white-space: normal;
}

.message-bubble-text--plain {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  column-gap: 8px;
  row-gap: 2px;
  max-width: 100%;
}

.message-bubble-text--plain > .message-bubble-text__content {
  display: block;
  flex: 1 1 auto;
  min-width: 40%;
}

.message-bubble-text--plain > .message-bubble-meta {
  display: inline-flex;
  align-items: center;
  float: none;
  margin: 0 0 0 auto;
}

.message-bubble-text p {
  margin: 0 0 10px;
}

.message-bubble-text p:last-child {
  margin-bottom: 0;
}

.message-bubble-text ul {
  margin: 0 0 10px;
  padding-left: 1.15em;
  list-style: disc;
}

.message-bubble-text li {
  margin: 0 0 6px;
}

.message-bubble-text li:last-child {
  margin-bottom: 0;
}

.message-bubble-text strong {
  font-weight: 650;
}

.message-row.me .message-bubble,
.message-row--outgoing .message-bubble {
  background: var(--chat-bubble-out-bg);
  color: var(--chat-bubble-out-fg);
}

.message-row--outgoing.message-row--solo .message-bubble,
.message-row--outgoing.message-row--group-first .message-bubble {
  border-radius: 12px 12px 4px 12px;
}

.message-row--outgoing.message-row--group-mid .message-bubble {
  border-radius: 4px 12px 4px 12px;
}

.message-row--outgoing.message-row--group-last .message-bubble {
  border-radius: 4px 12px 4px 12px;
}

.message-row--outgoing.message-row--solo .message-bubble--album,
.message-row--outgoing.message-row--group-first .message-bubble--album {
  border-radius: 12px 12px 4px 12px;
}

.message-row--outgoing.message-row--group-mid .message-bubble--album,
.message-row--outgoing.message-row--group-last .message-bubble--album {
  border-radius: 4px 12px 4px 12px;
}

.message-bubble--card {
  padding: 0;
  background: transparent !important;
  box-shadow: none;
  overflow: visible;
}

.message-row.me .message-bubble--card {
  color: inherit;
}

.chat-biz-card-slot {
  width: 278px;
  max-width: min(278px, 100%);
}

.chat-biz-card-slot .biz-card--chat {
  width: 278px;
  height: 170px;
  max-width: 100%;
  aspect-ratio: auto;
  flex-shrink: 0;
}

.chat-biz-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
}

.chat-biz-card-link:hover .biz-card {
  transform: translateY(-1px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.04) inset,
    0 22px 48px rgba(0, 0, 0, 0.34),
    0 6px 16px rgba(0, 0, 0, 0.22);
}

.chat-biz-card-link .biz-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.message-bubble-text .chat-biz-card-slot:not(:last-child) {
  margin-bottom: 10px;
}

.message-row.me .message-bubble--card .message-bubble-text > span {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px 7px;
  border-radius: 12px 12px 4px 12px;
  background: var(--chat-bubble-out-bg);
  color: var(--chat-bubble-out-fg);
  max-width: 278px;
}

.message-row.them .message-bubble,
.message-row.ai .message-bubble,
.message-row--incoming .message-bubble {
  background: var(--chat-bubble-in-bg);
  color: var(--chat-bubble-in-fg);
  border: 1px solid var(--chat-bubble-in-border);
}

.message-row.me .message-bubble,
.message-row--outgoing .message-bubble {
  border: 1px solid color-mix(in oklch, var(--accent) 70%, #fff 12%);
}

.message-row--incoming.message-row--solo .message-bubble,
.message-row--incoming.message-row--group-first .message-bubble {
  border-radius: 12px 12px 12px 4px;
}

.message-row--incoming.message-row--group-mid .message-bubble {
  border-radius: 12px 4px 12px 4px;
}

.message-row--incoming.message-row--group-last .message-bubble {
  border-radius: 4px 12px 12px 4px;
}

.message-row--incoming.message-row--solo .message-bubble--album,
.message-row--incoming.message-row--group-first .message-bubble--album {
  border-radius: 12px 12px 12px 4px;
}

.message-row--incoming.message-row--group-mid .message-bubble--album {
  border-radius: 12px 4px 12px 4px;
}

.message-row--incoming.message-row--group-last .message-bubble--album {
  border-radius: 4px 12px 12px 4px;
}


/* --- CRM adaptations on Allmatch chat shell --- */
#panel-inbox.tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin-top: 0;
  padding: 0;
}

.chat-list__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px var(--chat-list-x);
  border-bottom: 1px solid var(--border);
  flex: none;
  align-items: stretch;
}

.chat-filter {
  position: relative;
  flex: 1 1 calc(50% - 4px);
  min-width: 0;
}

.chat-filter[data-filter="bot"] {
  flex: 1 1 100%;
}

.chat-filter[data-filter="segment"],
.chat-filter[data-filter="status"] {
  flex: 1 1 100%;
}

.chat-filter__native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Custom filter select (Allmatch site-select style) */
.chat-filter .site-select {
  position: relative;
  width: 100%;
  min-width: 0;
}

.chat-filter .site-select--open {
  z-index: 30;
}

.chat-filter .site-select__trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 7px 10px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  line-height: 1.25;
  text-align: left;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    box-shadow 0.15s ease;
}

.chat-filter .site-select__trigger:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
}

.chat-filter .site-select__value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
}

.chat-filter .site-select__value--placeholder {
  color: var(--text-3);
}

.chat-filter .site-select__chevron {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--text-3);
  transition: transform 0.22s ease, color 0.22s ease;
}

.chat-filter .site-select--open .site-select__chevron {
  transform: rotate(180deg);
  color: var(--accent);
}

.chat-filter .site-select--open .site-select__trigger {
  border-color: color-mix(in oklch, var(--accent) 70%, var(--border));
  background: var(--surface-3);
  box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent-weak) 70%, transparent);
}

.chat-filter .site-select__menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: min(260px, 45vh);
  overflow-y: auto;
  border: 1px solid color-mix(in oklch, var(--accent) 28%, var(--border));
  border-radius: 12px;
  background: color-mix(in oklch, var(--surface-2) 92%, var(--canvas));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow:
    0 14px 36px color-mix(in oklch, var(--canvas) 62%, transparent),
    0 0 0 1px color-mix(in oklch, var(--border) 35%, transparent),
    0 0 18px color-mix(in oklch, var(--accent) 8%, transparent);
  animation: site-select-menu-in 0.18s ease;
}

@keyframes site-select-menu-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-filter .site-select__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.chat-filter .site-select__option:hover,
.chat-filter .site-select__option:focus-visible {
  background: var(--accent-weak);
  color: var(--text);
  outline: none;
}

.chat-filter .site-select__option--active {
  background: color-mix(in oklch, var(--accent-weak) 88%, var(--surface));
  color: var(--accent);
  font-weight: 650;
  box-shadow: inset 0 0 0 1px var(--accent-weak-2);
}

.chat-filter .site-select__opt-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: inherit;
  display: flex;
  align-items: baseline;
  gap: 0;
}

.chat-filter .site-select__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-filter .site-select__counts {
  flex: 0 0 auto;
  white-space: nowrap;
}

.chat-filter .site-select__queue {
  color: var(--text3, #8b8b8b);
  font-weight: 500;
}

.chat-filter .site-select__meta {
  flex: 0 0 auto;
  font: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  line-height: 1;
}

.chat-filter .site-select__meta.is-live { color: #34c759; }
.chat-filter .site-select__meta.is-freeze { color: #ff6b4a; font-weight: 650; }
.chat-filter .site-select__meta.is-retired { color: var(--text3, #8b8b8b); }
.chat-filter .site-select__meta.is-stub { color: var(--text3, #8b8b8b); }
.chat-filter .site-select__meta--new { color: var(--accent); }
.chat-filter .site-select__option--add .site-select__opt-label { color: var(--accent); font-weight: 650; }

.chat-filter .site-select__sep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 6px 4px;
  padding: 2px 4px;
  list-style: none;
  font-family: inherit;
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-3, var(--text3, #8b8b8b));
  pointer-events: none;
  line-height: 1.2;
}

.chat-filter .site-select__sep span {
  flex: none;
  font: inherit;
  white-space: nowrap;
}

.chat-filter .site-select__sep::before,
.chat-filter .site-select__sep::after {
  content: "";
  flex: 1 1 auto;
  height: 1px;
  background: var(--border, rgba(255, 255, 255, 0.12));
}

.chat-filter .site-select__row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.chat-filter .site-select__row .site-select__option {
  flex: 1 1 auto;
  min-width: 0;
}

.chat-filter .site-select__remove {
  flex: 0 0 auto;
  width: 26px;
  height: 28px;
  margin-right: 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #ff6b4a;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.9;
}
.chat-filter .site-select__remove:hover,
.chat-filter .site-select__remove:focus-visible {
  background: rgba(255, 107, 74, 0.18);
  opacity: 1;
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .chat-filter .site-select__menu {
    animation: none;
  }
  .chat-filter .site-select__chevron {
    transition: none;
  }
  .chat-list-resizer {
    transition: none;
  }
}

.chat-list-item__time {
  flex: none;
  font-size: 12px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chat-list-item__chips {
  display: inline-flex;
  gap: 4px;
  margin-left: 6px;
  flex: none;
}

.chat-layout .pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.chat-layout .pill-A { background: var(--ok-weak); color: var(--ok); }
.chat-layout .pill-B { background: var(--warn-weak); color: var(--warn); }
.chat-layout .pill-C { background: var(--danger-weak); color: var(--danger); }
.chat-layout .pill-demo { background: color-mix(in oklch, var(--blue-weak) 80%, transparent); color: #9ec5ff; }
.chat-layout .pill-live { background: color-mix(in oklch, var(--ok-weak) 80%, transparent); color: #7ddea0; }
.chat-layout .pill-closed { background: var(--surface-3); color: var(--text-3); }

.chat-layout .pill-lane-cold { background: color-mix(in oklch, #ff6b4a 22%, transparent); color: #ff8a70; }
.chat-layout .pill-lane-warm { background: color-mix(in oklch, var(--accent-weak) 70%, transparent); color: var(--accent); }
.chat-layout .pill-lane-reply { background: color-mix(in oklch, var(--ok-weak) 70%, transparent); color: var(--ok); }

.chat-layout .pill-outcome-new { background: var(--surface-3); color: var(--text-3); }
.chat-layout .pill-outcome-undelivered { background: color-mix(in oklch, #ff6b4a 18%, transparent); color: #ff8a70; }
.chat-layout .pill-outcome-awaiting { background: color-mix(in oklch, var(--warn-weak) 80%, transparent); color: var(--warn); }
.chat-layout .pill-outcome-active { background: color-mix(in oklch, var(--ok-weak) 80%, transparent); color: var(--ok); }
.chat-layout .pill-outcome-ready {
  background: #e53935;
  color: #fff;
}
.chat-layout .pill-outcome-opt_out,
.chat-layout .pill-outcome-closed { background: var(--surface-3); color: var(--text-3); }
.chat-layout .pill-outcome-funnel_done { background: color-mix(in oklch, var(--ok-weak) 80%, transparent); color: var(--ok); }

.chat-list-item__badges {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 0;
  flex: none;
  flex-wrap: nowrap;
}

.dialogue-send-hint {
  margin: 6px 12px 0;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.35;
}
.dialogue-send-hint--ok {
  background: color-mix(in oklch, var(--ok-weak) 55%, transparent);
  color: var(--ok);
}
.dialogue-send-hint--warn {
  background: color-mix(in oklch, var(--warn-weak) 55%, transparent);
  color: var(--warn);
}
.dialogue-send-hint--info {
  background: color-mix(in oklch, var(--accent-weak) 45%, transparent);
  color: var(--text-2);
}

.chat-conversation__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 14px;
  background: var(--canvas);
}

/* Prevent empty + open thread stacking (tenant switch left both flex:1 visible). */
.chat-conversation:has(#thread.is-open) > #thread-empty,
.chat-conversation:has(#agent-auth-pane.is-open) > #thread-empty,
.chat-conversation:has(#agent-auth-pane:not([hidden])) > #thread-empty {
  display: none !important;
}

.chat-conversation__thread {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.chat-conversation__thread.is-open {
  display: flex;
}

.chat-thread-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  position: relative;
}

.chat-conversation__thread.is-loading .chat-thread-body,
.chat-conversation__thread.is-loading .chat-conversation__header {
  visibility: hidden;
  pointer-events: none;
}

.thread-loader {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: color-mix(in oklch, var(--canvas) 92%, black);
  color: var(--text-2);
}

.thread-loader[hidden] {
  display: none !important;
}

.thread-loader__spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid color-mix(in oklch, var(--text-3) 30%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chat-loader-spin 0.75s linear infinite;
}

.thread-loader__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.thread-load-error {
  margin: 24px auto;
  max-width: 36ch;
  text-align: center;
  font-size: 13px;
  color: #ff8a80;
  line-height: 1.4;
}

.chat-conversation__title {
  font-weight: 800;
  font-size: 15px;
  line-height: 1.25;
  min-width: 0;
}

.chat-conversation__title a.tg-user {
  color: inherit;
  text-decoration: none;
  font-weight: 800;
}

.chat-conversation__title a.tg-user:hover {
  color: var(--accent);
}

.chat-conversation__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 2px;
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.35;
}

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

.chat-list-item__name a.tg-user {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}

.chat-list-item__name a.tg-user:hover {
  color: var(--accent);
}

.chat-composer {
  padding: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.chat-composer .textarea {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  max-height: 124px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
}

.chat-composer .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.chat-composer .textarea::placeholder {
  color: var(--text-faint);
}

.chat-composer .btn-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 41px;
  height: 41px;
  flex: none;
  align-self: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.14s ease, transform 0.08s ease;
}

.chat-composer .btn-send:hover {
  background: var(--accent-hover);
}

.chat-composer .btn-send:active {
  transform: scale(0.96);
}

.chat-composer .btn-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-composer .btn-send svg {
  width: 16px;
  height: 16px;
  display: block;
}

.chat-composer__row {
  display: flex;
  align-items: center !important;
  gap: 8px;
}

/* CRM lab dock: keep chat readable - dock must not eat the message viewport */
.chat-lab-dock {
  flex: 0 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(48vh, 420px);
  background: var(--canvas);
  padding-top: 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  border-top: none;
  overflow: hidden;
}

.chat-lab-dock--empty {
  padding-top: 0;
  max-height: none;
  overflow: visible;
}

.lab-starters {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border-top: 1px solid oklch(0.34 0.012 55);
  background: oklch(0.19 0.01 55);
  padding: 12px 14px;
}

.lab-replies-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-height: 40px;
  padding: 8px 14px;
  box-sizing: border-box;
  background: oklch(0.19 0.01 55);
  border-top: 1px solid oklch(0.34 0.012 55);
}

.lab-replies-bar__btn {
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid oklch(0.42 0.07 245);
  background: oklch(0.28 0.04 245);
  color: #b8d7ff;
  cursor: pointer;
  line-height: 1.2;
}

.lab-replies-bar__btn:hover {
  background: oklch(0.32 0.05 245);
}

.lab-replies-bar__btn[aria-expanded="true"] {
  border-color: rgba(255, 122, 69, 0.45);
  background: rgba(255, 122, 69, 0.14);
  color: #ffb088;
}

.lab-replies-bar__hint {
  font-size: 11px;
  color: var(--text-3, #8e8e93);
  line-height: 1.2;
}

.lab-replies {
  flex: 1 1 auto;
  min-height: 0;
  max-height: min(32vh, 260px);
  overflow-x: hidden;
  overflow-y: auto;
  border-top: 1px solid oklch(0.28 0.012 55);
  background: oklch(0.19 0.01 55);
  padding: 8px 14px 10px;
}

.lab-replies[hidden],
.lab-replies-bar[hidden],
.lab-starters[hidden] {
  display: none !important;
}

.chat-composer.is-sending {
  opacity: 0.72;
  pointer-events: none;
}

.chat-lab-dock .chat-composer {
  flex: none;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.22);
  padding: 12px 14px 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.chat-lab-dock .chat-composer__row {
  display: flex;
  align-items: center !important;
  min-height: 46px;
  width: 100%;
}

.chat-lab-dock .chat-composer .btn-send {
  width: 41px;
  height: 41px;
  margin: 0;
  flex: none;
  align-self: center !important;
}

/* Simulate inbound - lives in the message feed (incoming side) */
.lab-simulate-row {
  margin-top: 10px;
  margin-bottom: 4px;
}

.lab-simulate-wrap {
  max-width: min(88%, 480px) !important;
  width: 100%;
}

.lab-simulate {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 12px 12px 12px 4px;
  background: var(--chat-bubble-in-bg);
  border: 1px dashed var(--chat-bubble-in-border);
  color: var(--chat-bubble-in-fg);
}

.lab-simulate__hint {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: oklch(0.72 0.02 245);
}

.lab-simulate__row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lab-simulate__input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid oklch(0.42 0.016 55);
  background: oklch(0.22 0.01 55);
  color: oklch(0.96 0.004 70);
}

.lab-simulate__input:focus {
  outline: none;
  border-color: oklch(0.55 0.1 245);
}

.lab-simulate__btn {
  flex: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid oklch(0.42 0.07 245);
  background: oklch(0.32 0.05 245);
  color: #b8d7ff;
  cursor: pointer;
}

.lab-simulate__btn:hover {
  background: oklch(0.36 0.06 245);
}

.lab-starters__head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.lab-starters__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text, #f2f2f4);
}

.lab-starters__sub {
  font-size: 11px;
  color: var(--text3, #8e8e93);
  margin-top: 2px;
  line-height: 1.35;
  max-width: 52ch;
}

.lab-starters__hint {
  font-size: 10px;
  color: #9ec5ff;
  text-align: right;
  max-width: 22ch;
  line-height: 1.3;
}

.lab-starters__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.lab-starter {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  min-width: 0;
}

.lab-starter.is-selected {
  border-color: rgba(255, 122, 69, 0.55);
  background: rgba(255, 122, 69, 0.08);
  box-shadow: inset 0 0 0 1px rgba(255, 122, 69, 0.2);
}

.lab-starter__top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lab-starter__badge {
  font-size: 11px;
  font-weight: 700;
  color: #ffb088;
}

.lab-starter__text {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text, #f2f2f4);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 10px;
}

.lab-starter__text:focus {
  outline: none;
  border-color: rgba(255, 122, 69, 0.45);
}

.lab-starters__notes {
  margin-top: 10px;
}

.lab-starters__notes-input {
  width: 100%;
  font: inherit;
  font-size: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text, #f2f2f4);
}

.lab-starters__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.lab-starters__loading,
.lab-starters__err {
  font-size: 12px;
  color: var(--text3, #8e8e93);
  padding: 8px 0;
}

.lab-starters__err { color: #ff8a80; }

.lab-replies {
  background: oklch(0.19 0.01 55);
  /* max-height / overflow set above in dock section */
}

.lab-replies__title {
  display: none; /* toggle bar already labels the panel */
}

.lab-replies__list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.lab-reply {
  border: 1px solid oklch(0.36 0.014 55);
  background: oklch(0.26 0.012 55);
  border-radius: 10px;
  color: oklch(0.96 0.004 70);
  overflow: hidden;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.lab-reply:hover {
  border-color: oklch(0.5 0.08 245);
  background: oklch(0.28 0.02 245);
}

.lab-reply.is-open {
  border-color: oklch(0.55 0.1 245);
  background: oklch(0.29 0.03 245);
  box-shadow: inset 0 0 0 1px oklch(0.45 0.06 245 / 0.35);
}

.lab-reply.is-used {
  border-color: oklch(0.58 0.12 55);
  box-shadow: inset 0 0 0 1px oklch(0.55 0.1 55 / 0.4);
}

.lab-reply__head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
  padding: 6px 9px;
  border: 0;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-align: left;
}

.lab-reply__head:focus-visible {
  outline: 2px solid oklch(0.62 0.12 245);
  outline-offset: -2px;
}

.lab-reply__idx {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #9ec5ff;
  background: oklch(0.32 0.05 245);
  border: 1px solid oklch(0.42 0.07 245);
  flex: none;
}

.lab-reply__label {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: calc(100% - 40px);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--text-2);
  background: var(--surface-3);
  border: none;
  border-radius: 6px;
  padding: 1px 7px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lab-reply__chev {
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid oklch(0.62 0.04 245);
  border-bottom: 1.5px solid oklch(0.62 0.04 245);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
  flex: none;
  opacity: 0.75;
}

.lab-reply.is-open .lab-reply__chev {
  transform: rotate(225deg);
  margin-top: 3px;
}

.lab-reply__panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.22s ease;
  pointer-events: none;
}

.lab-reply.is-open .lab-reply__panel {
  grid-template-rows: 1fr;
  pointer-events: auto;
}

.lab-reply__body {
  overflow: hidden;
  min-height: 0;
}

.lab-reply__text {
  display: block;
  padding: 0 9px 8px 39px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  color: oklch(0.94 0.005 70);
  white-space: pre-wrap;
  word-break: break-word;
}

.lab-reply__use {
  display: block;
  margin: 0 9px 8px 39px;
  padding: 5px 10px;
  width: calc(100% - 48px);
  max-width: 220px;
  border: 1px solid oklch(0.48 0.08 245);
  border-radius: 8px;
  background: oklch(0.34 0.05 245);
  color: #c8e0ff;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.lab-reply__use:hover {
  background: oklch(0.4 0.07 245);
  border-color: oklch(0.58 0.1 245);
}

.chat-filter--mode-locked {
  opacity: 0.85;
}

.pill-mode {
  background: rgba(255, 122, 69, 0.14);
  color: #ffb088;
}

@media (max-width: 1100px) {
  .lab-starters__grid {
    grid-template-columns: 1fr;
  }
}

.message-bubble-text--plain {
  color: inherit;
}

.chat-list-item {
  font: inherit;
}

@media (max-width: 900px) {
  .chat-layout {
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }
  .chat-list {
    width: 100% !important;
    max-height: 40vh;
    flex: none;
  }
  .chat-conversation {
    flex: 1;
    min-height: 0;
  }
  .chat-list-resizer { display: none; }
}
