/* Shared chat surface for coach and patient dialogs. */

#m-chat::before,
#plan-chat-scrim.pchat-scrim {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.opchat [hidden] { display: none !important; }
.opchat:focus { outline: none; }
.opchat-grab { flex: 0 0 20px; display: grid; place-items: center; touch-action: none; }
.opchat-grab span { width: 36px; height: 4px; border-radius: 4px; background: #424951; }
.opchat-row, .opchat-day { flex-shrink: 0; }
.opchat button:focus-visible, .opchat-history:focus-visible { outline: 2px solid #73b5ff; outline-offset: -2px; }
#plan-chat-drawer.opchat textarea:focus { border-color: #1684ff !important; background: #171a1f !important; }

#m-chat .chat-sheet.opchat,
#plan-chat-drawer.opchat {
  --chat-graphite: #101216;
  --chat-history: #0a0c0f;
  --chat-received: #20252b;
  --chat-outgoing: #123c66;
  --chat-platinum: rgba(214, 224, 235, .16);
  --chat-platinum-soft: rgba(214, 224, 235, .08);
  --chat-blue: #1684ff;
  --chat-drag: 0px;
  --chat-safe-bottom: env(safe-area-inset-bottom, 0px);

  position: fixed;
  left: 50%;
  right: auto;
  bottom: var(--chat-bottom, 0px);
  z-index: 260;
  display: flex;
  flex-direction: column;
  width: min(520px, calc(100vw - 24px));
  height: min(var(--chat-height, 720px), calc(var(--chat-viewport-height, 100dvh) - max(12px, env(safe-area-inset-top, 0px))));
  max-width: 520px;
  max-height: calc(var(--chat-viewport-height, 100dvh) - max(12px, env(safe-area-inset-top, 0px)));
  min-height: 0;
  padding: 0;
  overflow: hidden;
  visibility: hidden;
  background: var(--chat-graphite);
  border: 1px solid var(--chat-platinum);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -18px 44px rgba(0, 0, 0, .42);
  transform: translateX(-50%) translateY(calc(105% + var(--chat-drag, 0px)));
  transition: transform .32s cubic-bezier(.32, 1, .36, 1), visibility 0s linear .32s;
  will-change: transform;
}

#m-chat.open .chat-sheet.opchat,
#plan-chat-drawer.opchat.is-open {
  visibility: visible;
  transform: translateX(-50%) translateY(var(--chat-drag, 0px));
  transition-delay: 0s;
}

#m-chat .chat-sheet.opchat.is-dragging,
#plan-chat-drawer.opchat.is-dragging {
  transition: none;
}

#m-chat .chat-sheet.opchat *,
#plan-chat-drawer.opchat * {
  box-sizing: border-box;
}

/* The patient scrim is promoted with the drawer when the drawer moves to body. */
#plan-chat-scrim {
  position: fixed;
  inset: 0;
  z-index: 259;
  background: rgba(0, 0, 0, .62);
  opacity: 0;
  pointer-events: none;
  transition: opacity .24s ease;
}

#plan-chat-scrim.is-on {
  opacity: 1;
  pointer-events: auto;
}

.opchat-head {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 0 0 auto;
  min-height: 68px;
  padding: 11px 13px 10px;
  background: var(--chat-graphite);
  border-bottom: 1px solid var(--chat-platinum-soft);
  touch-action: none;
}

.opchat-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid rgba(108, 177, 255, .32);
  border-radius: 50%;
  background: #123c66;
  color: #f4f8fc;
  font: 800 13px/1 "Inter", sans-serif;
}

.opchat-identity {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
}

.opchat-identity strong,
.opchat-identity small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opchat-identity strong {
  color: #f3f6fa;
  font: 750 15px/1.2 "Inter", sans-serif;
}

.opchat-identity small,
.opchat-status {
  color: rgba(230, 237, 245, .56);
  font: 500 11px/1.3 "Inter", sans-serif;
}

.opchat-close,
.opchat-send,
.opchat-template-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  flex: 0 0 44px;
  padding: 0;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.opchat-close {
  border: 1px solid var(--chat-platinum-soft);
  border-radius: 12px;
  background: rgba(255, 255, 255, .035);
  color: rgba(239, 245, 252, .68);
}

.opchat-close:active,
.opchat-template-toggle:active {
  background: rgba(255, 255, 255, .09);
}

.opchat-history {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 4px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 16px 13px 12px;
  background: var(--chat-history);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: rgba(214, 224, 235, .22) transparent;
  scrollbar-width: thin;
}

.opchat-history::-webkit-scrollbar {
  width: 5px;
}

.opchat-history::-webkit-scrollbar-thumb {
  border-radius: 5px;
  background: rgba(214, 224, 235, .22);
}

.opchat-day {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  margin: 5px 0 7px;
  color: rgba(230, 237, 245, .46);
  font: 700 10px/1.2 "Inter", sans-serif;
  letter-spacing: 0;
  text-transform: uppercase;
}

.opchat-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  margin: 0;
}

.opchat-row.is-me {
  align-items: flex-end;
}

.opchat-bubble {
  max-width: min(82%, 430px);
  padding: 9px 12px 7px;
  border: 1px solid rgba(214, 224, 235, .09);
  border-radius: 14px 14px 14px 5px;
  background: var(--chat-received);
  color: #ebf0f5;
  overflow-wrap: anywhere;
}

.opchat-row.is-me .opchat-bubble {
  border-color: rgba(129, 193, 255, .28);
  border-radius: 14px 14px 5px 14px;
  background: var(--chat-outgoing);
  color: #f7fbff;
}

.opchat-text {
  display: block;
  color: inherit;
  font: 400 14.5px/1.46 "Barlow", sans-serif;
  white-space: pre-wrap;
}

.opchat-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 14px;
  margin-top: 4px;
  color: rgba(230, 237, 245, .5);
  font: 600 10px/1.2 "Inter", sans-serif;
}

.opchat-row.is-me .opchat-meta {
  color: rgba(226, 241, 255, .64);
}

.opchat-row.is-failed .opchat-bubble {
  border-color: rgba(255, 136, 128, .48);
}

.opchat-row.is-failed .opchat-meta {
  color: #ff9c92;
}

.opchat-loading,
.opchat-empty {
  display: flex;
  flex: 1 1 auto;
  min-height: 180px;
  align-items: center;
  justify-content: center;
  color: rgba(230, 237, 245, .52);
  text-align: center;
  font: 500 13px/1.45 "Inter", sans-serif;
}

.opchat-empty {
  flex-direction: column;
  gap: 6px;
  padding: 20px;
}

.opchat-empty strong {
  color: #edf3f8;
  font-size: 14px;
  font-weight: 750;
}

.opchat-empty small {
  color: rgba(230, 237, 245, .46);
  font-size: 12px;
}

.opchat-footer {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 8px 11px calc(10px + var(--chat-safe-bottom, env(safe-area-inset-bottom, 0px)));
  background: var(--chat-graphite);
  border-top: 1px solid var(--chat-platinum-soft);
}

.opchat-status {
  display: block;
  min-height: 14px;
  margin: 0 3px 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.opchat-status:empty { display: none; }

.opchat-templates {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 7px;
  overflow-x: auto;
  scrollbar-width: none;
}

.opchat-templates::-webkit-scrollbar {
  display: none;
}

.opchat-template,
.opchat-template-toggle {
  color: rgba(235, 242, 249, .74);
  font: 600 11px/1.2 "Inter", sans-serif;
  white-space: nowrap;
}

.opchat-template {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--chat-platinum-soft);
  border-radius: 10px;
  background: rgba(255, 255, 255, .035);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.opchat-template:active {
  background: rgba(255, 255, 255, .09);
}

.opchat-template-toggle {
  border-radius: 11px;
  background: transparent;
}

.opchat-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.opchat-compose textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  max-height: 112px;
  resize: none;
  overflow-y: auto;
  padding: 11px 13px;
  border: 1px solid var(--chat-platinum);
  border-radius: 14px;
  outline: 0;
  background: #171a1f;
  color: #f1f5f9;
  font: 400 16px/1.35 "Barlow", sans-serif;
  -webkit-appearance: none;
}

.opchat-compose textarea::placeholder {
  color: rgba(230, 237, 245, .4);
}

.opchat-compose textarea:focus {
  border-color: rgba(22, 132, 255, .72);
  box-shadow: 0 0 0 2px rgba(22, 132, 255, .14);
}

.opchat-send {
  border-radius: 13px;
  background: var(--chat-blue);
  color: #fff;
  box-shadow: 0 6px 16px rgba(22, 132, 255, .24);
}

.opchat-send:active {
  transform: scale(.94);
}

.opchat-send:disabled,
.opchat-send[disabled] {
  cursor: default;
  opacity: .44;
  pointer-events: none;
}

.opchat-latest {
  position: absolute;
  right: 12px;
  bottom: calc(100% + 8px);
  min-height: 36px;
  max-width: calc(100% - 24px);
  padding: 0 12px;
  border: 1px solid rgba(129, 193, 255, .38);
  border-radius: 10px;
  background: #123c66;
  color: #f5faff;
  font: 700 11px/1.2 "Inter", sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.opchat-latest:active {
  background: #185184;
}

@media (max-height: 640px) {
  .opchat-head {
    min-height: 60px;
    padding-block: 7px;
  }

  .opchat-history {
    padding-block: 11px 8px;
  }

  .opchat-footer {
    padding-top: 6px;
  }
}

@media (max-width: 360px) {
  #m-chat .chat-sheet.opchat,
  #plan-chat-drawer.opchat {
    width: calc(100vw - 16px);
  }

  .opchat-head {
    gap: 9px;
    padding-inline: 10px;
  }

  .opchat-history {
    padding-inline: 9px;
  }

  .opchat-bubble {
    max-width: 88%;
  }

  .opchat-footer {
    padding-inline: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #m-chat .chat-sheet.opchat,
  #plan-chat-drawer.opchat,
  #plan-chat-scrim {
    transition: none;
  }
}
