.results-conversation-app {
  border: 1px solid #d9d9d9;
  border-radius: 10px 10px 0 0;
  background: #fff;
  padding: 14px;
}

.results-conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  min-height: 32px;
}

.results-conversation-header h3 {
  margin: 0;
  font-size: 1.8rem;
  font-weight: 500;
  line-height: 1.2;
}

.results-conversation-header h5 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.2;
}

/* ─── Header left section ─── */
.rchat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

/* ─── Patient Last Seen (review-results) ─── */
.rchat-last-seen {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 1.4rem;
  color: #999;
  white-space: nowrap;
  flex-shrink: 0;
}

.rchat-last-seen .fa-circle {
  font-size: 0.7rem;
}

.rchat-last-seen--online {
  color: #22c55e;
}

/* ─── Patient Unread Banner (review-results) ─── */
.rchat-patient-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  margin-top: 10px;
  flex-shrink: 0;
}

.rchat-banner-text {
  flex: 1;
  font-size: 1.2rem;
  color: #6d4c00;
  line-height: 1.3;
  padding-left: 14px;
  text-indent: -14px;
}

.rchat-banner-text::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.rchat-banner-btn {
  background: #667eea;
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 1.0rem;
  font-weight: 400;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.rchat-banner-btn:hover {
  background: #5569d4 !important;
  color: #fff !important;
}

.rchat-banner-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.rchat-banner-btn--sent {
  background: #22c55e;
}

.rchat-banner-btn--sent:hover {
  background: #22c55e;
}

/* ─── Read Receipt Ticks (review-results) ─── */
.rchat-msg-status {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  margin-left: 4px;
  vertical-align: middle;
}

.rchat-msg-status .fa-check {
  font-size: 0.9rem;
}

.rchat-msg-status--sent .fa-check {
  color: #9ca3af;
}

.rchat-msg-status--sent .fa-check:last-child {
  color: #fff;
}

.rchat-msg-status--read .fa-check {
  color: #3b82f6;
}

/* ─── Unread red dot on staff bubbles ─── */
.conversation-message.mine.rchat-unread .conversation-message-bubble {
  position: relative;
}

.conversation-message.mine.rchat-unread .conversation-message-bubble::after {
  content: '';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
}
.results-conversation-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #666;
  font-size: 1.4rem;
  line-height: 1;
}

.rchat-sound-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: #22a95a;
  font-size: 1.6rem;
  padding: 4px 6px;
  border-radius: 5px;
  line-height: 1;
  transition: color 0.2s, background 0.2s;
  opacity: 0.85;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
}

.rchat-sound-toggle:hover {
  background: rgba(0,0,0,0.06);
  opacity: 1;
}

.rchat-sound-toggle--muted {
  color: #b8b8b8;
}

.rchat-ws-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #b8b8b8;
  display: inline-block;
}

.rchat-ws-dot.online,
.rchat-ws-dot--live {
  background: #22a95a;
}

.results-conversation-messages-wrapper {
  position: relative;
  margin-bottom: 10px;
}

.results-conversation-messages-wrapper::before,
.results-conversation-messages-wrapper::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 24px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.results-conversation-messages-wrapper::before {
  top: 0;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(to bottom, #fbfbfb 0%, transparent 100%);
}

.results-conversation-messages-wrapper::after {
  bottom: 0;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(to top, #fbfbfb 0%, transparent 100%);
}

.results-conversation-messages-wrapper.fade-top::before {
  opacity: 1;
}

.results-conversation-messages-wrapper.fade-bottom::after {
  opacity: 1;
}

.results-conversation-messages {
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  background: #fbfbfb;
  padding: 10px;
  min-height: 280px;
  max-height: 460px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conversation-message {
  max-width: 85%;
  position: relative;
}

.conversation-message.other {
  align-self: flex-start;
}

.conversation-message.mine {
  align-self: flex-end;
}

.conversation-message-sender {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.75;
  display: flex;
  align-items: center;
  gap: 5px;
}

.conversation-message.mine .conversation-message-sender {
  justify-content: flex-end;
}

.sender-presence-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  flex-shrink: 0;
}

.conversation-message-bubble {
  border-radius: 12px;
  padding: 8px 12px;
  line-height: 1.45;
  word-wrap: break-word;
  font-size: 1.4rem;
}

.conversation-message.mine .conversation-message-bubble {
  background: #e4e4e4;
  color: #333;
  border-bottom-right-radius: 4px;
}

.conversation-message.other .conversation-message-bubble {
  background: #f0f0f0;
  color: #333;
  border-bottom-left-radius: 4px;
}

.conversation-message-bubble a {
  color: inherit;
  text-decoration: underline;
  word-break: break-all;
}

.conversation-message.mine .conversation-message-bubble a {
  color: #1768c6;
}

.conversation-message-time {
  font-size: 1.0rem;
  opacity: 0.55;
  margin-top: 0px;
  text-align: right;
}

/* Date dividers between message groups */
.conversation-date-divider {
  text-align: center;
  font-size: 1.1rem;
  color: #aaa;
  padding: 10px 0 4px;
  position: relative;
}

.conversation-date-divider::before,
.conversation-date-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: #ddd;
}

.conversation-date-divider::before { left: 0; }
.conversation-date-divider::after { right: 0; }

.results-conversation-typing {
  min-height: 20px;
  margin-top: 10px;
  color: #6b6b6b;
  font-size: 1.2rem;
}

.results-conversation-form {
  margin-top: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* ── Formatting Toolbar ── */
.rchat-format-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: #f0f2f5;
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  flex-wrap: wrap;
}

.rchat-format-toolbar button {
  border: none;
  background: none;
  color: black;
  cursor: pointer;
  padding: 4px 7px;
  font-size: 1.3rem;
  height: 24px;
  margin-bottom: 0;
  border-radius: 4px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.rchat-format-toolbar button:hover {
  background: #dde3ee;
  color: #1768c6;
}

.rchat-format-toolbar button.rchat-cmd-active {
  background: #d0daf0;
  color: #1768c6;
  box-shadow: inset 0 -2px 0 #1768c6;
}

.rchat-toolbar-divider {
  width: 1px;
  height: 18px;
  background: #ccc;
  margin: 0 4px;
}

/* ── Swatch color picker wrapper ── */
.rchat-swatch-wrap {
  position: relative;
  display: inline-flex;
}

.rchat-color-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 1.3rem;
  color: #555;
  border: none;
  background: none;
  transition: background 0.15s, color 0.15s;
}

.rchat-color-btn:hover {
  background: #dde3ee;
  color: #1768c6;
}

.rchat-swatch-wrap.rchat-cmd-active .rchat-color-btn {
  background: #e8ecf4;
  /* box-shadow set dynamically by JS with the selected color */
}

/* ── Swatch dropdown panel ── */
.rchat-swatch-panel {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px;
  gap: 5px;
  flex-wrap: wrap;
  z-index: 20;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  white-space: nowrap;
}

.rchat-swatch-wrap.rchat-swatch-open .rchat-swatch-panel {
  display: flex;
}

/* ── Individual swatch circles ── */
.rchat-swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  box-sizing: border-box;
}

.rchat-swatch:hover {
  border-color: #1768c6;
  transform: scale(1.15);
}

/* "Remove" swatch for highlight */
.rchat-swatch-none {
  background: #f0f0f0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #888;
}

.rchat-swatch-none:hover {
  color: #c0392b;
}

.results-conversation-input-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #f6f8ff;
  border: 1px solid #ddd;
  border-radius: 0 0 12px 12px;
  padding: 6px 8px 6px 14px;
}

/* ── Rich-text contenteditable input ── */
.rchat-rich-input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 1.4rem;
  line-height: 1.3;
  outline: none;
  overflow-y: auto;
  min-height: 1.4em;
  max-height: 120px;
  box-sizing: border-box;
  margin-bottom: 0;
  padding-top: 15px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.rchat-rich-input:empty::before {
  content: attr(data-placeholder);
  color: #aaa;
  pointer-events: none;
}

/* ── Composition area vertical resize handle ── */
.rchat-compose-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 12px;
  cursor: ns-resize;
  background: #eef0f5;
  border: 1px solid #ddd;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  color: #bbb;
  font-size: 9px;
  user-select: none;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
  margin-top: 4px;
  margin-bottom: 0;
}

.rchat-compose-resize-handle:hover {
  background: #dde0e8;
  color: #888;
}

.rchat-compose-resize-handle:active {
  background: #cdd0d8;
  color: #555;
}

/* When compose handle is present, remove top border-radius and top border from toolbar */
.rchat-compose-resize-handle + .results-conversation-form .rchat-format-toolbar {
  border-radius: 0;
  border-top: none;
}

.rchat-rich-input ul,
.rchat-rich-input ol {
  margin: 2px 0;
  padding-left: 20px;
}

.rchat-rich-input li {
  margin-bottom: 0;
  line-height: 1.3;
}

.rchat-rich-input code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.9em;
}

.results-conversation-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.3;
  outline: none;
  overflow-y: auto;
  min-height: 0;
  max-height: 120px;
  box-sizing: border-box;
  margin-bottom:0;
}

/* ── Rich-text styles inside message bubbles ── */
.conversation-message-bubble b,
.conversation-message-bubble strong {
  font-weight: 700;
}

.conversation-message-bubble i,
.conversation-message-bubble em {
  font-style: italic;
}

.conversation-message-bubble u {
  text-decoration: underline;
}

.conversation-message-bubble s,
.conversation-message-bubble strike,
.conversation-message-bubble del {
  text-decoration: line-through;
}

.conversation-message-bubble ul,
.conversation-message-bubble ol {
  margin: 4px 0;
  padding-left: 20px;
}

.conversation-message-bubble li {
  margin-bottom: 2px;
}

.conversation-message-bubble code {
  background: rgba(0,0,0,0.08);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.conversation-message.mine .conversation-message-bubble code {
  background: rgba(0,0,0,0.08);
}

/* ── Rich-text highlight spans: slight rounded look ── */
.conversation-message-bubble span[style*="background-color"] {
  border-radius: 2px;
  padding: 0 2px;
}

.results-conversation-help-text {
  display: block;
  color: #bbb;
  font-size: 1.1rem;
  margin-top: 4px;
  margin-bottom: 0;
  line-height: 1.3;
  text-align: center;
}

.results-conversation-help-text strong {
  font-weight: 500;
  color: #999;
}

.results-conversation-input-wrapper > button {
  border: 0;
  border-radius: 50%;
  background: none;
  color: #1768c6;
  cursor: pointer;
  padding: 4px;
  font-size: 1.8rem;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}

.results-conversation-input-wrapper > button:hover {
  color: #0e4f96;
}

.results-conversation-input-wrapper > button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.conversation-share-lock {
  border: 1px dashed #ccc;
  border-radius: 8px;
  padding: 16px;
  color: #666;
  background: #fafafa;
}

/* ── Mobile-only back bar (hidden on desktop) ── */
.conversation-mobile-bar {
  display: none;
}

@media (max-width: 768px) {

  /* Hide formatting toolbar on mobile for patients (non-staff) */
  .results-conversation-app[data-is-staff="0"] .rchat-format-toolbar {
    display: none;
  }

  /* Show mobile bar */
  .conversation-mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 0 10px;
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 10px;
  }

  .conversation-back-btn {
    background: none;
    border: none;
    color: #1768c6;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 8px;
    white-space: nowrap;
  }

  .conversation-mobile-title {
    font-size: 1.6rem;
    font-weight: 500;
    flex: 1;
  }

  /* Hide the desktop header on mobile — mobile bar replaces it */
  .results-conversation-header {
    display: none;
  }

  /* ── Full-screen conversation mode ── */
  body.conversation-mode .header {
    display: none !important;
  }

  body.conversation-mode footer,
  body.conversation-mode .footer {
    display: none !important;
  }

  body.conversation-mode .test-title {
    display: none !important;
  }

  body.conversation-mode .top-info {
    display: none !important;
  }

  body.conversation-mode .bottom-info-title,
  body.conversation-mode .bottom-info-disclaimer {
    display: none !important;
  }

  body.conversation-mode .tabset > label {
    display: none !important;
  }

  /* Hide share/print icons on mobile */
  .results-actions-icons {
    display: none !important;
  }

  body.conversation-mode .tab-panel {
    border-top: none;
    padding-top: 0;
  }

  body.conversation-mode {
    overflow: hidden;
  }

  body.conversation-mode main,
  body.conversation-mode .main-container {
    padding: 0 !important;
    margin: 0 !important;
  }

  body.conversation-mode .test-container {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none;
  }

  body.conversation-mode .tabset {
    margin: 0;
    padding: 0;
  }

  body.conversation-mode .tab-panels {
    padding: 0;
    margin: 0;
  }

  body.conversation-mode .results-conversation-app {
    border: none;
    border-radius: 0;
    padding: 10px 10px 5px 10px;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
  }

  body.conversation-mode .conversation-mobile-bar {
    flex-shrink: 0;
  }

  body.conversation-mode .results-conversation-messages-wrapper {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  body.conversation-mode .results-conversation-messages {
    height: 100%;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    margin-bottom: 5px;
  }

  body.conversation-mode .results-conversation-typing {
    flex-shrink: 0;
  }

  body.conversation-mode .results-conversation-form {
    flex-shrink: 0;
    margin-top: 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
  }

  body.conversation-mode .rchat-attachment-previews {
    flex-shrink: 0;
  }
}

/* ═════════════════════════════════════════════════════════════════
   Attachment button
   ═════════════════════════════════════════════════════════════════ */
.rchat-attach-btn {
  border: 0;
  background: none;
  color: #888;
  cursor: pointer;
  padding: 4px;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}

.rchat-attach-btn:hover {
  color: #1768c6;
}

/* ═════════════════════════════════════════════════════════════════
   Attachment preview strip (above compose area)
   ═════════════════════════════════════════════════════════════════ */
.rchat-attachment-previews {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 10px;
  background: #f6f8ff;
  border: 1px solid #ddd;
  border-radius: 8px;
  margin-bottom: 6px;
}

.rchat-preview-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 1.2rem;
  max-width: 180px;
}

.rchat-preview-item img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.rchat-preview-item .rchat-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
  color: #444;
}

.rchat-preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.rchat-preview-file-icon {
  font-size: 2rem;
  color: #888;
  flex-shrink: 0;
}

/* ═════════════════════════════════════════════════════════════════
   Upload progress bar
   ═════════════════════════════════════════════════════════════════ */
.rchat-upload-progress {
  height: 3px;
  background: #e0e0e0;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}

.rchat-upload-progress-bar {
  height: 100%;
  background: #1768c6;
  width: 0%;
  transition: width 0.2s ease;
  border-radius: 2px;
}

/* ═════════════════════════════════════════════════════════════════
   Attachments rendered outside message bubbles
   ═════════════════════════════════════════════════════════════════ */
.rchat-msg-attachments {
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rchat-msg-attachment-image {
  max-width: 280px;
  max-height: 240px;
  width: auto;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  transition: opacity 0.2s;
}

.rchat-msg-attachment-image:hover {
  opacity: 0.85;
}

.rchat-msg-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 1.2rem;
  text-decoration: none;
  transition: background 0.15s;
  max-width: 260px;
}

.conversation-message.mine .rchat-msg-attachment-file {
  background: #1768c6;
  color: #fff;
}

.conversation-message.mine .rchat-msg-attachment-file:hover {
  background: #1258a8;
}

.conversation-message.other .rchat-msg-attachment-file {
  background: #e8e8e8;
  color: #333;
}

.conversation-message.other .rchat-msg-attachment-file:hover {
  background: #ddd;
}

.rchat-msg-attachment-file .rchat-file-icon {
  font-size: 1.6rem;
  flex-shrink: 0;
}

.rchat-msg-attachment-file .rchat-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.rchat-msg-attachment-file .rchat-file-size {
  font-size: 1.0rem;
  opacity: 0.7;
  white-space: nowrap;
}

/* ═════════════════════════════════════════════════════════════════
   Drag-and-drop overlay
   ═════════════════════════════════════════════════════════════════ */
.rchat-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(23, 104, 198, 0.08);
  border: 2px dashed #1768c6;
  border-radius: 8px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: #1768c6;
  font-weight: 500;
  pointer-events: none;
}

/* ═════════════════════════════════════════════════════════════════
   Lightbox (full-size image viewer)
   ═════════════════════════════════════════════════════════════════ */
.rchat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rchat-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: pointer;
}

.rchat-lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
}

.rchat-lightbox-content img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.rchat-lightbox-close-btn {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 2.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: background 0.15s;
}

.rchat-lightbox-close-btn:hover {
  background: rgba(0,0,0,0.8);
}

.rchat-lightbox-filename {
  color: #ddd;
  font-size: 1.2rem;
  margin-top: 8px;
  text-align: center;
}

