.chat-button {
  position: relative;
}

.chat-unread-badge {
  align-items: center;
  background: #dc2626;
  border: 2px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  display: inline-flex;
  font-size: 10px;
  font-weight: 800;
  height: 18px;
  justify-content: center;
  line-height: 1;
  min-width: 18px;
  padding: 0 4px;
  position: absolute;
  right: -5px;
  top: -5px;
}

.chat-dialog {
  background: #ffffff;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 28px 90px rgb(15 23 42 / 28%);
  color: #1e293b;
  height: min(85dvh, 820px);
  max-height: calc(100dvh - 48px);
  max-width: calc(100vw - 48px);
  overflow: hidden;
  padding: 0;
  width: min(1180px, calc(100vw - 48px));
}

.chat-dialog::backdrop {
  background: rgb(15 23 42 / 52%);
}

.chat-shell {
  display: grid;
  grid-template-columns: minmax(320px, 350px) minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  position: relative;
}

.chat-dialog-close {
  align-items: center;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  color: #64748b;
  display: inline-flex;
  height: 38px;
  justify-content: center;
  min-height: 38px;
  padding: 0;
  position: absolute;
  right: 20px;
  top: 19px;
  width: 38px;
  z-index: 4;
}

.chat-dialog-close:hover,
.chat-dialog-close:focus-visible {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #0f172a;
}

.chat-dialog-close svg,
.chat-mobile-back svg,
.chat-new-conversation svg,
.chat-search-wrap svg,
.chat-send svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.chat-dialog-close svg {
  height: 18px;
  width: 18px;
}

.chat-mobile-back {
  display: none;
}

.chat-sidebar {
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.chat-sidebar-header {
  display: grid;
  gap: 14px;
  padding: 20px 18px 16px;
}

.chat-sidebar-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.chat-sidebar-heading h2 {
  color: #0f172a;
  font-size: 22px;
  line-height: 1.2;
  margin: 0;
}

.chat-new-conversation {
  align-items: center;
  background: #2563eb;
  border-radius: 8px;
  display: inline-flex;
  flex: 0 0 auto;
  gap: 7px;
  min-height: 38px;
  padding: 0 12px;
}

.chat-new-conversation:hover,
.chat-new-conversation:focus-visible {
  background: #1d4ed8;
}

.chat-new-conversation.is-active {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #334155;
}

.chat-new-conversation.is-active:hover,
.chat-new-conversation.is-active:focus-visible {
  background: #f1f5f9;
  color: #0f172a;
}

.chat-new-conversation svg {
  height: 16px;
  width: 16px;
}

.chat-search-wrap {
  color: #64748b;
  display: block;
  position: relative;
}

.chat-search-wrap svg {
  height: 17px;
  left: 12px;
  pointer-events: none;
  position: absolute;
  top: calc(50% - 8px);
  width: 17px;
}

.chat-search-wrap input {
  background: #ffffff;
  border-color: #dbe3ec;
  border-radius: 9px;
  min-height: 42px;
  padding-left: 38px;
}

.chat-search-wrap input::placeholder {
  color: #64748b;
}

.chat-sidebar-feedback {
  color: #64748b;
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
  padding: 0 18px 10px;
}

.chat-sidebar-feedback.is-error {
  color: #b42318;
}

.chat-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.chat-conversation-item,
.chat-member-item {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #1e293b;
  display: flex;
  flex: 0 0 auto;
  gap: 11px;
  min-height: 68px;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.chat-conversation-item:hover,
.chat-conversation-item:focus-visible,
.chat-member-item:hover,
.chat-member-item:focus-visible {
  background: #eef2f7;
  color: #0f172a;
}

.chat-conversation-item.is-selected {
  background: #e8efff;
  border-color: #c7d7fe;
  color: #0f172a;
}

.chat-avatar {
  align-items: center;
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: #1d4ed8;
  display: inline-flex;
  flex: 0 0 42px;
  font-size: 13px;
  font-weight: 850;
  height: 42px;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 42px;
}

.chat-avatar img {
  height: 100%;
  inset: 0;
  object-fit: cover;
  position: absolute;
  width: 100%;
}

.chat-avatar.is-large {
  flex-basis: 46px;
  height: 46px;
  width: 46px;
}

.chat-avatar.is-message {
  flex-basis: 30px;
  font-size: 10px;
  height: 30px;
  margin-bottom: 2px;
  width: 30px;
}

.chat-conversation-copy,
.chat-member-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.chat-conversation-copy {
  flex: 1;
}

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

.chat-conversation-preview-row .chat-conversation-preview {
  flex: 1;
  min-width: 0;
}

.chat-conversation-unread {
  align-items: center;
  background: #2563eb;
  border-radius: 999px;
  color: #ffffff;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 800;
  height: 20px;
  justify-content: center;
  line-height: 1;
  min-width: 20px;
  padding: 0 6px;
}

.chat-conversation-item.is-unread .chat-conversation-preview,
.chat-conversation-item.is-unread .chat-conversation-heading strong {
  color: #0f172a;
  font-weight: 800;
}

.chat-conversation-heading {
  align-items: baseline;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
}

.chat-conversation-heading strong,
.chat-member-copy strong {
  color: #0f172a;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-conversation-heading time {
  color: #64748b;
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 600;
}

.chat-conversation-preview,
.chat-member-copy span {
  color: #64748b;
  display: block;
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-member-copy {
  flex: 1;
}

.chat-member-action {
  color: #2563eb;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 800;
}

.chat-list-empty {
  color: #64748b;
  font-size: 13px;
  line-height: 1.55;
  margin: auto;
  max-width: 240px;
  padding: 32px 18px;
  text-align: center;
}

.chat-list-action {
  align-self: center;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #2563eb;
  margin-top: 4px;
  min-height: 38px;
}

.chat-list-action:hover,
.chat-list-action:focus-visible {
  background: #eff6ff;
  color: #1d4ed8;
}

.chat-list-skeleton {
  align-items: center;
  display: grid;
  gap: 8px 12px;
  grid-template-columns: 42px 1fr;
  min-height: 68px;
  padding: 10px;
}

.chat-list-skeleton::before,
.chat-list-skeleton span {
  animation: chat-skeleton-pulse 1200ms ease-in-out infinite alternate;
  background: #e2e8f0;
  border-radius: 999px;
  content: '';
}

.chat-list-skeleton::before {
  grid-row: 1 / 3;
  height: 42px;
  width: 42px;
}

.chat-list-skeleton span {
  height: 10px;
  width: 70%;
}

.chat-list-skeleton span:last-child {
  opacity: 0.7;
  width: 92%;
}

@keyframes chat-skeleton-pulse {
  to { opacity: 0.48; }
}

.chat-main {
  background: #ffffff;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.chat-empty-state {
  align-items: center;
  color: #64748b;
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
  text-align: center;
}

.chat-empty-icon {
  align-items: center;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  color: #2563eb;
  display: inline-flex;
  height: 64px;
  justify-content: center;
  margin-bottom: 18px;
  width: 64px;
}

.chat-empty-icon svg {
  fill: none;
  height: 28px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 28px;
}

.chat-empty-state h3 {
  color: #0f172a;
  font-size: 20px;
  margin: 0 0 8px;
}

.chat-empty-state p {
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  max-width: 320px;
}

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

.chat-conversation-header {
  align-items: center;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex: 0 0 auto;
  gap: 12px;
  min-height: 78px;
  padding: 14px 72px 14px 24px;
}

.chat-peer-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chat-peer-copy h3 {
  color: #0f172a;
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-peer-job,
.chat-peer-availability {
  color: #64748b;
  font-size: 12px;
  line-height: 1.35;
}

.chat-peer-availability {
  align-items: center;
  display: inline-flex;
  gap: 6px;
}

.chat-peer-availability::before {
  background: #22c55e;
  border-radius: 999px;
  content: '';
  flex: 0 0 7px;
  height: 7px;
  width: 7px;
}

.chat-peer-availability.is-unavailable::before {
  background: #94a3b8;
}

.chat-history-toolbar {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  justify-content: center;
  min-height: 38px;
  padding: 8px 24px 0;
}

.chat-load-older,
.chat-history-retry {
  background: transparent;
  color: #2563eb;
  font-size: 12px;
  min-height: 30px;
  padding: 0 10px;
}

.chat-load-older:hover,
.chat-load-older:focus-visible,
.chat-history-retry:hover,
.chat-history-retry:focus-visible {
  background: #eff6ff;
  color: #1d4ed8;
}

.chat-history-feedback {
  color: #64748b;
  font-size: 12px;
  margin: 0;
  text-align: center;
}

.chat-history-feedback.is-error {
  color: #b42318;
}

.chat-history {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 28px 24px;
}

.chat-new-messages {
  align-items: center;
  align-self: center;
  background: #2563eb;
  border: 1px solid #1d4ed8;
  border-radius: 999px;
  bottom: 92px;
  box-shadow: 0 8px 24px rgb(37 99 235 / 24%);
  color: #ffffff;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  justify-content: center;
  left: 50%;
  min-height: 36px;
  padding: 0 15px;
  position: absolute;
  transform: translateX(-50%);
  transition: background-color 180ms ease, box-shadow 180ms ease;
  z-index: 3;
}

.chat-new-messages:hover,
.chat-new-messages:focus-visible {
  background: #1d4ed8;
  box-shadow: 0 10px 28px rgb(37 99 235 / 32%);
}

.chat-history-empty {
  color: #64748b;
  font-size: 14px;
  line-height: 1.5;
  margin: auto;
  max-width: 300px;
  text-align: center;
}

.chat-date-separator {
  align-self: center;
  background: #eef2f7;
  border-radius: 999px;
  color: #64748b;
  font-size: 11px;
  font-weight: 800;
  margin: 8px 0 10px;
  padding: 5px 10px;
}

.chat-message {
  align-items: flex-end;
  display: flex;
  gap: 8px;
  justify-content: flex-start;
  width: 100%;
}

.chat-message.is-own {
  justify-content: flex-end;
}

.chat-message-bubble {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 17px 17px 17px 6px;
  box-shadow: 0 2px 8px rgb(15 23 42 / 5%);
  display: grid;
  gap: 6px;
  max-width: min(74%, 560px);
  min-width: 112px;
  padding: 10px 12px 8px;
}

.chat-message.is-own .chat-message-bubble {
  background: #eef2ff;
  border-color: #dbe3ff;
  border-radius: 17px 17px 6px 17px;
}

.chat-message-text {
  color: #1e293b;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-message-time {
  color: #64748b;
  font-size: 10px;
  justify-self: end;
}

.chat-composer {
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: grid;
  flex: 0 0 auto;
  gap: 8px;
  padding: 14px 24px 18px;
}

.chat-composer-row {
  align-items: flex-end;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 13px;
  display: flex;
  gap: 10px;
  padding: 8px;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.chat-composer-row:focus-within {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgb(37 99 235 / 14%);
}

.chat-composer textarea {
  background: transparent;
  border: 0;
  color: #1e293b;
  flex: 1;
  font: inherit;
  line-height: 1.45;
  max-height: 144px;
  min-height: 40px;
  min-width: 0;
  overflow-y: auto;
  padding: 9px 8px 6px;
  resize: none;
}

.chat-composer textarea:focus-visible {
  outline: none;
}

.chat-composer textarea::placeholder {
  color: #64748b;
}

.chat-send {
  align-items: center;
  border-radius: 9px;
  display: inline-flex;
  flex: 0 0 42px;
  height: 42px;
  justify-content: center;
  min-height: 42px;
  padding: 0;
  width: 42px;
}

.chat-send svg {
  height: 19px;
  width: 19px;
}

.chat-composer-meta {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-height: 20px;
}

.chat-composer-hint {
  color: #64748b;
  font-size: 11px;
  line-height: 1.4;
  margin: 0;
}

.chat-composer-error-wrap {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-left: auto;
  min-width: 0;
}

.chat-composer-error {
  color: #b42318;
  flex: 1 1 auto;
  font-size: 12px;
  line-height: 1.4;
  margin: 0;
  overflow-wrap: anywhere;
  text-align: right;
}

.chat-retry-send {
  background: transparent;
  color: #b42318;
  font-size: 12px;
  min-height: 28px;
  padding: 0 8px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-retry-send:hover,
.chat-retry-send:focus-visible {
  background: #fff1f2;
  color: #991b1b;
}

@media (max-width: 760px) {
  .chat-dialog {
    border-radius: 0;
    height: 100vh;
    height: 100dvh;
    inset: 0;
    margin: 0;
    max-height: none;
    max-width: none;
    overscroll-behavior: none;
    position: fixed;
    width: 100vw;
  }

  .chat-shell {
    display: block;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
    width: 100%;
  }

  .chat-sidebar,
  .chat-main {
    height: 100%;
    inset: 0;
    max-width: 100%;
    position: absolute;
    width: 100%;
  }

  .chat-sidebar {
    border-right: 0;
    display: flex;
  }

  .chat-main {
    display: none;
  }

  .chat-shell.is-mobile-conversation .chat-sidebar {
    display: none;
  }

  .chat-shell.is-mobile-conversation .chat-main {
    display: flex;
  }

  .chat-dialog-close {
    height: 44px;
    min-height: 44px;
    right: max(12px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
    width: 44px;
  }

  .chat-sidebar-header {
    gap: 12px;
    padding: max(16px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 14px max(14px, env(safe-area-inset-left));
  }

  .chat-sidebar-heading {
    align-items: stretch;
    display: grid;
    gap: 12px;
    padding-right: 54px;
  }

  .chat-sidebar-heading h2 {
    align-items: center;
    display: flex;
    min-height: 44px;
  }

  .chat-new-conversation {
    justify-content: center;
    min-height: 44px;
    width: 100%;
  }

  .chat-search-wrap input {
    min-height: 44px;
  }

  .chat-list {
    overscroll-behavior: contain;
    padding: 4px max(8px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .chat-conversation-item,
  .chat-member-item {
    min-height: 72px;
    touch-action: manipulation;
  }

  .chat-list-action,
  .chat-load-older,
  .chat-history-retry,
  .chat-retry-send,
  .chat-new-messages {
    min-height: 44px;
    touch-action: manipulation;
  }

  .chat-new-messages {
    bottom: max(92px, calc(82px + env(safe-area-inset-bottom)));
    max-width: calc(100vw - 32px);
  }

  .chat-conversation-header {
    gap: 10px;
    min-height: calc(68px + env(safe-area-inset-top));
    padding: max(12px, env(safe-area-inset-top)) max(66px, calc(58px + env(safe-area-inset-right))) 10px max(10px, env(safe-area-inset-left));
  }

  .chat-mobile-back {
    align-items: center;
    align-self: center;
    background: transparent;
    color: #2563eb;
    display: inline-flex;
    flex: 0 0 auto;
    gap: 3px;
    min-height: 44px;
    padding: 0 7px 0 3px;
    touch-action: manipulation;
  }

  .chat-mobile-back:hover,
  .chat-mobile-back:focus-visible {
    background: #eff6ff;
    color: #1d4ed8;
  }

  .chat-mobile-back svg {
    height: 22px;
    width: 22px;
  }

  .chat-mobile-back span {
    font-size: 14px;
    font-weight: 800;
  }

  .chat-conversation-header > .chat-avatar {
    display: none;
  }

  .chat-peer-copy {
    flex: 1;
  }

  .chat-peer-copy h3 {
    font-size: 15px;
  }

  .chat-peer-job,
  .chat-peer-availability {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-history-toolbar {
    min-height: 44px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  .chat-history {
    max-width: 100%;
    overflow-x: hidden;
    padding: 12px max(12px, env(safe-area-inset-right)) 18px max(12px, env(safe-area-inset-left));
  }

  .chat-message-bubble {
    max-width: 86%;
  }

  .chat-message-text {
    font-size: 16px;
    line-height: 1.45;
  }

  .chat-composer {
    padding: 10px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .chat-composer-row {
    min-width: 0;
    padding: 6px;
  }

  .chat-composer textarea {
    font-size: 16px;
    min-height: 44px;
    padding: 10px 7px 7px;
  }

  .chat-send {
    flex-basis: 44px;
    height: 44px;
    min-height: 44px;
    touch-action: manipulation;
    width: 44px;
  }

  .chat-composer-meta {
    align-items: stretch;
    flex-direction: column;
    gap: 4px;
  }

  .chat-composer-hint {
    font-size: 12px;
  }

  .chat-composer-error-wrap {
    flex-wrap: wrap;
    justify-content: space-between;
    margin-left: 0;
  }

  .chat-composer-error {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-list-skeleton::before,
  .chat-list-skeleton span,
  .chat-new-messages {
    animation: none;
    scroll-behavior: auto;
    transition: none;
  }
}
