/* Pharmafly chat (chat.js). Uses the colour tokens from home.css. */

.chat {
  --chat-gap: 1.25rem;
  font-size: 1rem;
}

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

/* ---------- launcher ---------- */

.chat-launcher {
  position: fixed;
  z-index: 40;
  bottom: var(--chat-gap);
  inset-inline-end: var(--chat-gap);
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding-block: 0.75rem;
  padding-inline: 1.1rem 1.25rem;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  /* white ring keeps it visible over the green band and the dark footer */
  box-shadow: 0 0 0 2px var(--white), 0 0.5rem 1.5rem rgb(18 53 43 / 0.3);
  cursor: pointer;
}

.chat-launcher:hover {
  background: var(--green-deep);
}

.chat-launcher__icon {
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
}

/* someone on the Pharmafly side is online */
.chat--online .chat-launcher::before {
  content: "";
  position: absolute;
  top: 0.45rem;
  inset-inline-start: 2rem;
  width: 0.6rem;
  height: 0.6rem;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #7CF0B8;
}

.chat-badge {
  min-width: 1.5rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--red);
  color: var(--white);
  font-size: 0.8rem;
  text-align: center;
}

.chat--open .chat-launcher {
  display: none;
}

/* ---------- panel ---------- */

.chat-panel {
  position: fixed;
  z-index: 45;
  bottom: var(--chat-gap);
  inset-inline-end: var(--chat-gap);
  display: flex;
  flex-direction: column;
  width: min(24rem, calc(100vw - 2 * var(--chat-gap)));
  height: min(36rem, calc(100vh - 2 * var(--chat-gap)));
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 1.5rem 3rem rgb(18 53 43 / 0.3);
}

@media (prefers-reduced-motion: no-preference) {
  .chat-panel {
    animation: chat-in 0.18s ease-out;
  }
}

@keyframes chat-in {
  from { opacity: 0; transform: translateY(0.75rem); }
  to { opacity: 1; transform: none; }
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.85rem 0.75rem 0.85rem 1rem;
  background: var(--ink);
  color: var(--white);
}

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

.chat-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1.35;
}

.chat-status {
  margin: 0.1rem 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: #CFE3DA;
}

.chat-icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.chat-icon-btn:hover {
  background: rgb(255 255 255 / 0.12);
}

.chat-icon-btn svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
}

[dir="rtl"] .chat-back svg {
  transform: scaleX(-1);
}

.chat :focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.chat-head :focus-visible {
  outline-color: var(--white);
}

/* ---------- staff list ---------- */

.chat-list {
  flex: 1;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.chat-row {
  position: relative;
  display: grid;
  gap: 0.15rem;
  width: 100%;
  padding: 0.8rem 1rem;
  padding-inline-end: 3rem;
  border: 0;
  border-block-end: 1px solid var(--rule);
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.chat-row:hover {
  background: var(--mint);
}

.chat-row__top {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.chat-row__top time {
  flex: none;
  font-size: 0.8rem;
  color: #6B8279;
}

.chat-row__text,
.chat-row__contact {
  overflow: hidden;
  font-size: 0.9rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-row__contact {
  font-size: 0.8rem;
  color: #6B8279;
}

.chat-row--unread .chat-row__text {
  font-weight: 600;
}

.chat-row__unread {
  position: absolute;
  inset-inline-end: 1rem;
  top: 50%;
  min-width: 1.4rem;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: var(--red);
  color: var(--white);
  font-size: 0.75rem;
  text-align: center;
  transform: translateY(-50%);
}

/* ---------- thread ---------- */

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-thread__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: -1rem -1rem 1rem;
  padding: 0.6rem 1rem;
  border-block-end: 1px solid var(--rule);
  background: var(--white);
}

.chat-thread__who {
  display: grid;
  min-width: 0;
  line-height: 1.4;
}

.chat-thread__who span {
  overflow: hidden;
  font-size: 0.85rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #6B8279;
}

.chat-end {
  flex: none;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.chat-empty {
  margin: 2rem 0 0;
  color: #6B8279;
  text-align: center;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chat-msg {
  display: grid;
  gap: 0.2rem;
  max-width: 85%;
}

.chat-msg--own {
  align-self: flex-end;
  justify-items: end;
}

.chat-msg--other {
  align-self: flex-start;
  justify-items: start;
}

.chat-msg__who {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--green);
}

.chat-msg__text {
  margin: 0;
  padding: 0.55rem 0.85rem;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg--own .chat-msg__text {
  background: var(--green);
  color: var(--white);
  border-end-end-radius: 4px;
}

.chat-msg--other .chat-msg__text {
  background: var(--white);
  border: 1px solid var(--rule);
  border-end-start-radius: 4px;
}

.chat-msg__time {
  font-size: 0.75rem;
  color: #6B8279;
}

/* read receipts on your own messages, like WhatsApp: one grey tick sent, two delivered, two blue read */
.chat-tick {
  display: inline-block;
  width: 1.05rem;
  height: 0.7rem;
  margin-inline-start: 0.25rem;
  vertical-align: -0.05rem;
  color: #6B8279;
  transition: color 0.2s;
}

.chat-tick svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-tick--sent .chat-tick__2 {
  display: none;
}

.chat-tick--read {
  color: #1C86D1;
}

.chat-row__text .chat-tick {
  margin-inline: 0 0.25rem;
}

/* "typing…": a bubble of dots under the last message, and the words in the header and chat list */
.chat-typing {
  display: flex;
  gap: 0.25rem;
  width: max-content;
  margin-block-start: 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 14px;
  border-end-start-radius: 4px;
  background: var(--white);
}

.chat-typing[hidden] {
  display: none;
}

.chat-typing span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: #6B8279;
}

@media (prefers-reduced-motion: no-preference) {
  .chat-typing span {
    animation: chat-typing 1.2s ease-in-out infinite;
  }

  .chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
  }

  .chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
  }
}

@keyframes chat-typing {
  0%, 60%, 100% { opacity: 0.35; transform: none; }
  30% { opacity: 1; transform: translateY(-0.2rem); }
}

.chat .chat-row .chat-row__text.chat-row__text--typing, /* green on unread rows too */
.chat-thread__who .chat-typing-text {
  color: var(--green);
  font-weight: 600;
}

/* date between messages of different days */
.chat-day {
  align-self: center;
  margin-block: 0.25rem;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  background: var(--mint);
  color: #355B4D;
  font-size: 0.75rem;
}

/* ---------- compose ---------- */

.chat-compose {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem;
  border-block-start: 1px solid var(--rule);
  background: var(--white);
}

.chat-details {
  display: grid;
  gap: 0.5rem;
}

.chat-compose__row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.chat-compose input[type="text"],
.chat-compose textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--rule);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-compose textarea {
  flex: 1;
  min-height: 2.6rem;
  max-height: 140px;
  overflow-y: hidden;
  resize: none;
}

.chat-send {
  flex: none;
  padding: 0.55rem 1.1rem;
}

.chat-error {
  margin: 0;
  font-size: 0.85rem;
  color: var(--red);
}

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

/* ---------- photos ---------- */

.chat-attach {
  align-self: flex-end;
  width: 2.6rem;
  height: 2.6rem;
  color: var(--green);
}

.chat-attach:hover {
  background: var(--mint);
}

.chat-attach:disabled {
  opacity: 0.45;
  cursor: default;
}

.chat-attach:disabled:hover {
  background: transparent;
}

.chat-msg__photo {
  display: block;
  width: fit-content;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--white);
}

.chat-msg__photo img {
  display: block;
  max-width: min(100%, 16rem);
  max-height: 16rem;
  object-fit: cover;
}

.chat-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
}

.chat-preview img {
  flex: none;
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 8px;
  object-fit: cover;
}

.chat-preview__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chat-preview__actions .btn {
  padding: 0.45rem 1rem;
  font-size: 0.9rem;
}

/* an image is being dragged over the chat */
.chat--drop .chat-panel {
  outline: 3px dashed var(--green);
  outline-offset: -6px;
}

/* ---------- phones: full screen ---------- */

@media (max-width: 40rem) {
  .chat {
    --chat-gap: 1rem;
  }

  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }
}

/* ---------- standalone page (/chat, /en/chat) ---------- */

/* the page is exactly one screen tall: header on top, the chat fills the rest */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat-page-header {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem var(--gutter);
  border-block-end: 1px solid var(--rule);
}

.chat-page-header .brand img {
  width: auto;
  height: 2.25rem;
}

.chat-page-main {
  display: flex;
  flex: 1;
  min-height: 0;
  justify-content: center;
  padding: 1.5rem var(--gutter);
}

.chat--page {
  display: flex;
  width: min(46rem, 100%);
}

.chat--page .chat-panel {
  position: static;
  flex: 1;
  width: 100%;
  height: auto;
  animation: none;
}

@media (max-width: 40rem) {
  .chat-page-main {
    padding: 0;
  }

  .chat--page .chat-panel {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  /* keep the composer clear of the iPhone home bar */
  .chat--page .chat-compose {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}
