/* Telegram-style navigation in the existing forest-green palette. */
.chat-page-head {
  margin-bottom: 18px;
}
.chat.workspace-chat {
  display: grid;
  grid-template-columns: clamp(350px, 32vw, 440px) minmax(0, 1fr);
  gap: 0;
  background: #fff;
  border: 1px solid #d6e2dc;
  border-radius: 14px;
  overflow: hidden;
  height: clamp(530px, calc(100dvh - 180px), 850px);
  min-width: 0;
  font-family: var(--ui-font);
}
.workspace-chat .chat-sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid #dce6e0;
  background: #fff;
}
.chat-search {
  padding: 17px 16px 10px;
}
.chat-search label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  padding: 0 12px;
  border-radius: 9px;
  background: #f1f5f3;
  color: var(--ui-muted);
}
.chat-search input {
  border: 0;
  background: none;
  margin: 0;
  box-shadow: none;
  min-width: 0;
  padding: 12px 0;
  font: var(--ui-caption) var(--ui-font);
}
.chat-search label:focus-within {
  outline: 2px solid #528570;
  outline-offset: 1px;
}
.chat-folder-tabs {
  display: flex;
  overflow: auto;
  flex: none;
  gap: 17px;
  padding: 0 16px;
  scrollbar-width: thin;
  border-bottom: 1px solid #e9eeeb;
}
.chat-folder-tabs button {
  padding: 12px 0 10px;
  flex: none;
  white-space: nowrap;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  font: var(--ui-caption) var(--ui-font);
  color: #637871;
}
.chat-folder-tabs button.active {
  border-bottom-color: #285b47;
  color: #234c3c;
  font-weight: 700;
}
.chat-list-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 12px;
  border-bottom: 1px solid #edf1ee;
}
.chat-list-tools select {
  border: 0;
  background: #f7f9f8;
  font: var(--ui-caption) var(--ui-font);
  margin: 0;
  min-width: 0;
  padding: 8px 4px;
  flex: 1;
}
.chat-tool-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  background: none;
  padding: 6px;
  color: #57796a;
}
.chat-tool-icon:hover {
  background: #edf5ef;
}
.workspace-chat .chatlist {
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  flex: 1;
  min-height: 0;
  padding: 6px 0;
  scrollbar-width: thin;
}
.workspace-chat .chat-contact {
  display: grid;
  position: relative;
  grid-template-columns: 40px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 92px;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 13px 16px;
  margin: 0;
  background: #fff;
  color: #223e36;
  text-align: left;
  white-space: normal;
}
.workspace-chat .chat-contact:hover {
  background: #f0f6f3;
}
.workspace-chat .chat-contact.selected {
  background: #e5f0ea;
  box-shadow: inset 3px 0 #2f7156;
}
.chat-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e6eeeb;
  color: #3d715c;
  font: 600 var(--ui-caption) var(--ui-font);
}
.chat-avatar.group-avatar {
  background: #e8eaf6;
  color: #596d8a;
}
.chat-contact-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
}
.chat-contact-copy strong {
  display: block;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font: 600 var(--ui-caption)/var(--ui-leading) var(--ui-font);
}
.chat-contact-role {
  color: #667b72;
  font-size: var(--ui-caption);
  line-height: var(--ui-leading);
  padding-right: 70px;
}
.chat-preview {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
  line-height: var(--ui-leading);
  padding-right: 38px;
}
.chat-contact.selected .chat-preview {
  color: #637d70;
}
.chat-contact-meta {
  position: absolute;
  right: 16px;
  top: 38px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  color: var(--ui-muted);
  font: var(--ui-caption) var(--ui-font);
}
.chat-unread {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 12px;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  background: #36775c;
  color: #fff;
  font-size: var(--ui-caption);
  font-weight: 700;
}
.chat-list-empty {
  padding: 35px 20px;
  text-align: center;
  font-size: var(--ui-caption);
  color: var(--ui-muted);
  line-height: var(--ui-leading);
}
.chat-sidebar-footer {
  display: flex;
  gap: 8px;
  flex: none;
  padding: 12px;
  border-top: 1px solid #e4ece7;
  background: #fbfcfb;
}
.chat-sidebar-footer button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 5px;
  font: var(--ui-caption) var(--ui-font);
  white-space: nowrap;
  background: #fff;
  border-color: #d7e4dc;
}
.chat-sidebar-footer svg {
  width: 17px;
  height: 17px;
}
.workspace-chat .chat-conversation {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: #f2f6f3;
}
.chat-thread-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 83px;
  padding: 16px 22px;
  background: #fff;
  border-bottom: 1px solid #dfe8e2;
  flex: none;
}
.chat-thread-title {
  flex: 1;
  min-width: 0;
}
.chat-thread-title h2 {
  margin: 0 0 5px !important;
  font: 600 var(--ui-body)/var(--ui-leading) var(--ui-font);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #213f33;
}
.chat-thread-title > span {
  font: var(--ui-caption) var(--ui-font);
  color: var(--ui-muted);
}
.chat-thread-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}
.chat-thread-tools button {
  font-size: var(--ui-caption);
  padding: 7px 10px;
}
.chat-thread-tools .chat-tool-icon {
  padding: 6px;
}
.chat-back {
  display: none;
}
.workspace-chat .messages {
  flex: 1;
  height: auto;
  min-height: 0;
  overflow: auto;
  padding: 22px 26px;
  background: #f2f6f3;
  border: 0;
  border-radius: 0;
  margin: 0;
}
.workspace-chat .messages > .muted {
  padding: 30px 0;
  text-align: center;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.workspace-chat .bubble {
  width: fit-content;
  max-width: min(80%, 650px);
  padding: 12px 15px;
  border: 1px solid #e4ece7;
  border-radius: 12px 12px 12px 3px;
  box-shadow: 0 1px 2px #234c3c08;
  margin-bottom: 12px;
  font: var(--ui-caption)/var(--ui-leading) var(--ui-font);
  white-space: normal;
}
.workspace-chat .bubble.mine {
  border-radius: 12px 12px 3px 12px;
  background: #dfeee3;
  border-color: #d6e7dc;
}
.workspace-chat .bubble small {
  color: var(--ui-muted);
  font-size: var(--ui-caption);
  margin-top: 6px;
}
.chat-sender {
  display: block;
  font-size: var(--ui-caption);
  color: #357654;
  margin-bottom: 5px;
}
.workspace-chat .message-text {
  overflow-wrap: anywhere;
}
.workspace-chat .chat-conversation > form {
  flex: none;
  padding: 12px 18px;
  background: #f2f6f3;
}
.workspace-chat .compose-bar {
  border-radius: 12px;
}
.workspace-chat .compose-bar textarea {
  font-size: var(--ui-caption);
}
.workspace-chat .chat-conversation > p {
  padding: 14px;
}
.chat-editor-modal {
  max-width: 700px;
  font: var(--ui-caption)/var(--ui-leading) var(--ui-font);
}
.chat-editor-modal .muted {
  font-size: var(--ui-caption);
  margin: 12px 0;
}
.chat-editor-modal label {
  font-family: var(--ui-font);
}
.chat-picker-search input {
  margin-top: 6px;
}
.chat-picker {
  max-height: min(380px, 45vh);
  overflow: auto;
  border: 1px solid #dce6df;
  border-radius: 8px;
  background: #fff;
}
.chat-pick-row {
  display: flex !important;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  margin: 0 !important;
  border-bottom: 1px solid #edf1ee;
}
.chat-pick-row:last-child {
  border: 0;
}
.chat-pick-row[hidden] {
  display: none !important;
}
.chat-pick-row input {
  width: 17px;
  height: 17px;
  flex: none;
  margin: 0;
  accent-color: #285b47;
}
.chat-pick-row > span {
  min-width: 0;
}
.chat-pick-row strong {
  display: block;
  font-size: var(--ui-caption);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.chat-pick-row small {
  display: block;
  margin-top: 3px;
  color: var(--ui-muted);
  font-size: var(--ui-caption);
}
.chat-picker-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
  font-size: var(--ui-caption);
  color: #64796f;
}
.chat-picker-summary > span {
  margin-right: auto;
}
.chat-picker-summary button {
  font-size: var(--ui-caption);
  padding: 5px 8px;
}
.chat-folder-manager > div {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid #dae5dc;
}
.chat-folder-manager strong {
  flex: 1;
  overflow-wrap: anywhere;
}
.chat-folder-manager button {
  padding: 6px 9px;
  font-size: var(--ui-caption);
}
@media (max-width: 1100px) {
  .chat.workspace-chat {
    grid-template-columns: 350px minmax(0, 1fr);
  }
  .chat-thread-tools button[data-action='client'] {
    display: none;
  }
  .chat-thread-header {
    padding: 14px;
    gap: 9px;
  }
  .workspace-chat .messages {
    padding: 16px;
  }
  .chat-thread-header .chat-avatar {
    display: none;
  }
}
@media (max-width: 900px) {
  .chat.workspace-chat {
    display: block;
    height: calc(100dvh - var(--chat-top, 180px) - 16px);
    min-height: 350px;
  }
  .workspace-chat .chat-sidebar {
    height: 100%;
    border: 0;
  }
  .workspace-chat .chat-conversation {
    display: none;
    height: 100%;
  }
  .workspace-chat.is-conversation .chat-sidebar {
    display: none;
  }
  .workspace-chat.is-conversation .chat-conversation {
    display: flex;
  }
  .chat-back {
    display: flex;
    border: 0;
    background: none;
    padding: 7px;
    color: #3d715c;
  }
  .chat-contact-copy strong {
    font-size: var(--ui-caption);
  }
  .chat-thread-title h2 {
    font-size: var(--ui-caption);
  }
  .workspace-chat .bubble {
    max-width: 90%;
  }
  .workspace-chat .chat-conversation > form {
    padding: 10px;
  }
  .chat-thread-header {
    min-height: 70px;
  }
  .chat-thread-tools button {
    font-size: var(--ui-caption);
  }
  .chat-editor-modal {
    padding: 18px;
  }
  .chat-sidebar-footer button {
    font-size: var(--ui-caption);
  }
}

.chat-reply-action {
  display: block;
  background: transparent;
  border: 0;
  padding: 4px 0;
  margin-top: 3px;
  color: #517365;
  font-size: var(--ui-caption, 13px);
}
.chat-reply-quote {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  background: rgba(76, 117, 95, 0.07);
  border: 0;
  border-left: 3px solid #709783;
  border-radius: 4px;
  padding: 7px 10px;
  margin: 0 0 8px;
  max-width: 100%;
  min-width: 0;
  color: inherit;
  overflow: hidden;
}
.chat-reply-quote strong {
  color: #3b6b54;
  font-size: var(--ui-caption, 14px);
}
.chat-reply-quote span {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--ui-caption, 14px);
  max-height: 4.4em;
  overflow: hidden;
}
.chat-reply-preview {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px 0;
}
.chat-reply-preview .chat-reply-quote {
  flex: 1;
  margin: 0;
}
.chat-reply-preview > button[data-action='message-reply-cancel'] {
  background: transparent;
  border: 0;
  padding: 4px 8px;
  font-size: 22px;
}
@keyframes chat-reply-flash {
  0%,
  40% {
    outline: 2px solid #85aa92;
    background-color: #e5efd9;
  }
  100% {
    outline: 2px solid transparent;
  }
}
.chat-message-highlight {
  animation: chat-reply-flash 1.8s ease-out;
}
@media (prefers-reduced-motion: reduce) {
  .chat-message-highlight {
    animation-duration: 0.1s;
  }
}

/* Explicit quote, aligned left for both client and staff. */
body.ui-readable .workspace-chat .chat-reply-selected {
  flex: 1;
  min-width: 0;
  text-align: left;
}
body.ui-readable .workspace-chat .chat-reply-selected > small {
  display: block;
  color: var(--ui-muted);
  margin-bottom: 3px;
}
body.ui-readable .workspace-chat .chat-reply-quote {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  text-align: left;
  width: 100%;
  margin: 0 0 6px;
  padding: 7px 10px;
  border-left: 3px solid #709783;
  background: #edf3ef;
  white-space: normal;
}
body.ui-readable .workspace-chat .chat-reply-quote :is(strong, span) {
  width: 100%;
  text-align: left;
}

.staff-chat-sidebar .chat-unread {
  background: #bd3943;
  color: #fff;
}

.chat-delete-one {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-width: 32px;
  min-height: 32px;
  background: transparent;
  color: #8e4e48;
  border: 0;
  margin-left: 6px;
}
.chat-message-select {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 5px;
  color: #526c61;
}
.chat-message-select input {
  width: 18px;
  height: 18px;
  margin: 0;
}
.chat-thread-tools {
  flex-wrap: wrap;
}
.chat-thread-tools [data-action='message-delete-selected'] {
  font-size: var(--ui-caption);
  padding: 6px;
}
