/* =========================================================
   Melodía — the clinic's chat window (see chat.js)
   Colours and font come from CHAT_CONFIG in chat.js as --mc-* variables.
   ========================================================= */
.mchat {
  --mc-radius: 24px;
  --mc-line: color-mix(in srgb, var(--mc-dark) 12%, transparent);
  --mc-ease: cubic-bezier(.22, 1, .36, 1);
  --mc-bottom: max(26px, env(safe-area-inset-bottom, 0px));
  font-family: var(--mc-font);
  color: var(--mc-ink);
  -webkit-font-smoothing: antialiased;
}
.mchat *, .mchat *::before, .mchat *::after { box-sizing: border-box; }
.mchat [hidden] { display: none !important; }
.mchat :where(button, textarea) { font: inherit; color: inherit; }
.mchat :focus-visible { outline: 2px solid var(--mc-main); outline-offset: 2px; }

/* ---------- launcher ---------- */
.mchat__launcher {
  position: fixed; right: 22px; bottom: var(--mc-bottom); z-index: 70;
  width: 60px; height: 60px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: var(--mc-light);
  background: linear-gradient(135deg, var(--mc-main), var(--mc-dark));
  box-shadow: 0 16px 34px -12px color-mix(in srgb, var(--mc-dark) 80%, transparent), 0 0 0 1px rgba(255,255,255,.14), inset 0 1px 0 rgba(255,255,255,.2);
  transition: transform .35s var(--mc-ease), box-shadow .35s var(--mc-ease), opacity .4s var(--mc-ease), visibility .4s;
}
.mchat__launcher:hover { transform: translateY(-2px); }
.mchat__launcher:focus-visible { outline-color: var(--mc-accent); outline-offset: 3px; }
.mchat__ico { grid-area: 1 / 1; display: grid; transition: opacity .25s, transform .35s var(--mc-ease); }
.mchat__ico svg { width: 28px; height: 28px; }
.mchat__ico--down { opacity: 0; transform: rotate(-90deg) scale(.6); }
.mchat.is-open .mchat__ico--chat { opacity: 0; transform: rotate(90deg) scale(.6); }
.mchat.is-open .mchat__ico--down { opacity: 1; transform: none; }
.mchat__badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: #E5484D; color: #fff; font-size: 11.5px; font-weight: 700; line-height: 20px; text-align: center;
  box-shadow: 0 0 0 2px var(--mc-light);
}

/* ---------- teaser ---------- */
.mchat__teaser {
  position: fixed; right: 22px; bottom: calc(var(--mc-bottom) + 74px); z-index: 70;
  display: flex; align-items: flex-start; max-width: min(290px, calc(100vw - 44px));
  border-radius: 18px 18px 6px 18px; background: var(--mc-light);
  box-shadow: 0 18px 44px -16px color-mix(in srgb, var(--mc-dark) 55%, transparent), 0 0 0 1px var(--mc-line);
  opacity: 0; transform: translateY(8px) scale(.96); transform-origin: bottom right;
  transition: opacity .4s var(--mc-ease), transform .4s var(--mc-ease);
}
.mchat__teaser.is-shown { opacity: 1; transform: none; }
.mchat__teaser-open {
  display: flex; align-items: center; gap: 10px; padding: 12px 6px 12px 12px; border: 0; background: none;
  text-align: left; cursor: pointer; font-size: 14.5px; font-weight: 500; line-height: 1.35; border-radius: inherit;
}
.mchat__teaser-open img { flex: none; width: 30px; height: 30px; padding: 3px; border-radius: 50%; background: var(--mc-soft); }
.mchat__teaser-x {
  flex: none; display: grid; place-items: center; width: 30px; height: 30px; margin: 6px 6px 0 0; padding: 0;
  border: 0; border-radius: 50%; background: none; color: color-mix(in srgb, var(--mc-ink) 55%, transparent); cursor: pointer;
}
.mchat__teaser-x:hover { background: var(--mc-soft); color: var(--mc-ink); }
.mchat__teaser-x svg { width: 16px; height: 16px; }
.mchat.is-open .mchat__teaser { display: none; }

/* ---------- window ---------- */
.mchat__window {
  position: fixed; right: 22px; bottom: calc(var(--mc-bottom) + 76px); z-index: 71;
  width: 380px; height: min(600px, calc(100dvh - var(--mc-bottom) - 100px));
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: var(--mc-radius); background: var(--mc-light);
  box-shadow: 0 32px 80px -24px color-mix(in srgb, var(--mc-dark) 60%, transparent), 0 0 0 1px var(--mc-line);
  transform-origin: bottom right; animation: mchat-in .38s var(--mc-ease);
}
@keyframes mchat-in { from { opacity: 0; transform: translateY(14px) scale(.96); } }

.mchat__head {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 16px 10px 16px 16px;
  color: var(--mc-light);
  background:
    radial-gradient(130% 150% at 100% 0%, color-mix(in srgb, var(--mc-accent) 30%, transparent), transparent 55%),
    linear-gradient(135deg, var(--mc-dark), var(--mc-main));
}
.mchat__face { position: relative; flex: none; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: var(--mc-light); box-shadow: 0 0 0 3px rgba(255,255,255,.22); }
.mchat__face img { width: 34px; height: 34px; }
.mchat__face::after {
  content: ""; position: absolute; right: -1px; bottom: 0; width: 12px; height: 12px; border-radius: 50%;
  background: #34D399; box-shadow: 0 0 0 2.5px var(--mc-dark);
}
.mchat.is-offline .mchat__face::after { background: #9AA9B5; }
.mchat__who { min-width: 0; flex: 1; }
.mchat__name { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; color: inherit; }
.mchat__status { margin: 2px 0 0; font-size: 13px; line-height: 1.3; color: rgba(255,255,255,.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mchat__actions { display: flex; align-items: center; gap: 4px; }
.mchat__btn {
  display: inline-grid; place-items: center; height: 36px; border: 0; border-radius: 999px; cursor: pointer;
  background: rgba(255,255,255,.12); color: var(--mc-light); text-decoration: none; transition: background-color .2s;
}
.mchat__btn:hover { background: rgba(255,255,255,.24); }
.mchat__btn:focus-visible { outline-color: var(--mc-light); }
.mchat__btn--icon { width: 36px; }
.mchat__btn--icon svg { width: 19px; height: 19px; }
.mchat__btn--end { padding: 0 13px; font-size: 13px; font-weight: 600; }
.mchat__min { background: none; }

/* ---------- messages ---------- */
.mchat__log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 14px 10px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--mc-soft);
}
.mchat__row { display: grid; justify-items: start; max-width: 86%; }
.mchat__row.is-first { margin-top: 10px; }
.mchat__row:first-child { margin-top: 0; }
.mchat__row--bot { grid-template-columns: 30px 1fr; column-gap: 8px; align-self: flex-start; }
.mchat__row--bot > :not(.mchat__mini) { grid-column: 2; }
.mchat__row--me { align-self: flex-end; justify-items: end; margin-top: 8px; }
.mchat__row--me + .mchat__row--me { margin-top: 0; }
.mchat__mini { grid-column: 1; grid-row: 1 / span 2; align-self: start; width: 30px; height: 30px; margin-top: 20px; display: grid; place-items: center; border-radius: 50%; background: var(--mc-light); box-shadow: 0 0 0 1px var(--mc-line); }
.mchat__mini img { width: 22px; height: 22px; }
.mchat__by { font-size: 12px; font-weight: 600; color: color-mix(in srgb, var(--mc-ink) 60%, transparent); margin: 0 0 4px 4px; }
.mchat__bubble {
  padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.mchat__row--bot .mchat__bubble { background: var(--mc-light); color: var(--mc-ink); border-top-left-radius: 6px; box-shadow: 0 1px 2px color-mix(in srgb, var(--mc-dark) 8%, transparent), 0 0 0 1px var(--mc-line); }
.mchat__row--bot:not(.is-first) .mchat__bubble { border-top-left-radius: 18px; border-bottom-left-radius: 6px; }
.mchat__row--me .mchat__bubble { background: var(--mc-main); color: var(--mc-light); border-bottom-right-radius: 6px; }
.mchat__bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.mchat__row--me.is-failed .mchat__bubble { opacity: .6; }
.mchat__retry { margin-top: 4px; padding: 2px 4px; border: 0; background: none; color: #B42318; font-size: 12.5px; cursor: pointer; }

/* typing dots */
.mchat__dots { display: inline-flex; gap: 5px; padding: 14px 16px; }
.mchat__dots i { width: 7px; height: 7px; border-radius: 50%; background: color-mix(in srgb, var(--mc-main) 70%, transparent); animation: mchat-dot 1.2s infinite ease-in-out; }
.mchat__dots i:nth-child(2) { animation-delay: .15s; }
.mchat__dots i:nth-child(3) { animation-delay: .3s; }
@keyframes mchat-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* quick replies */
.mchat__pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mchat__pill {
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600; line-height: 1.2;
  background: var(--mc-light); color: var(--mc-main); border: 1.5px solid color-mix(in srgb, var(--mc-main) 45%, transparent);
  transition: background-color .2s, color .2s, border-color .2s;
}
.mchat__pill:hover { background: var(--mc-main); border-color: var(--mc-main); color: var(--mc-light); }

/* chat ended / chat unavailable */
.mchat__notice { align-self: stretch; margin: 14px 4px 4px; padding: 16px; border-radius: 18px; text-align: center; background: var(--mc-light); box-shadow: 0 0 0 1px var(--mc-line); }
.mchat__notice p { margin: 0 0 12px; font-size: 14.5px; line-height: 1.45; }
.mchat__choices { display: grid; justify-items: center; gap: 6px; }
.mchat__action {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 22px;
  border: 0; border-radius: 999px; cursor: pointer; text-decoration: none; font-size: 15px; font-weight: 600;
  background: linear-gradient(135deg, var(--mc-main), var(--mc-dark)); color: var(--mc-light);
}
.mchat__action svg { width: 18px; height: 18px; }
.mchat__link { padding: 6px 10px; border: 0; background: none; color: var(--mc-main); font-size: 14px; font-weight: 600; cursor: pointer; }

/* ---------- composer ---------- */
.mchat__composer {
  display: flex; align-items: flex-end; gap: 8px; margin: 0; padding: 10px 10px 10px 16px;
  background: var(--mc-light); border-top: 1px solid var(--mc-line);
}
.mchat__input {
  flex: 1; min-height: 44px; max-height: 132px; padding: 11px 0; border: 0; outline: none; resize: none;
  background: none; font-size: 15px; line-height: 1.45;
}
.mchat__input::placeholder { color: color-mix(in srgb, var(--mc-ink) 50%, transparent); }
.mchat__input:focus-visible { outline: none; }
.mchat__composer:focus-within { box-shadow: inset 0 2px 0 var(--mc-main); }
.mchat__send {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--mc-main); color: var(--mc-light); transition: background-color .2s, opacity .2s;
}
.mchat__send svg { width: 20px; height: 20px; margin-left: -2px; }
.mchat__send:hover { background: var(--mc-dark); }
.mchat__send:disabled { cursor: default; opacity: .35; background: var(--mc-main); }
.mchat__composer.is-off { opacity: .5; pointer-events: none; }
.mchat__note { margin: 0; padding: 0 16px 10px; background: var(--mc-light); font-size: 11.5px; text-align: center; color: color-mix(in srgb, var(--mc-ink) 52%, transparent); }

/* ---------- phones: the window fills the screen ---------- */
@media (max-width: 560px), (max-height: 520px) {
  .mchat__window {
    inset: var(--mc-vt, 0px) 0 auto 0; width: auto; height: 100%; height: var(--mc-vh, 100dvh); border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px); background: var(--mc-light);
    animation-name: mchat-up;
  }
  .mchat__head { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .mchat.is-open .mchat__launcher { opacity: 0; visibility: hidden; }
  .mchat-open, .mchat-open body { overflow: hidden; }
  .mchat__row { max-width: 90%; }
}
@keyframes mchat-up { from { opacity: 0; transform: translateY(24px); } }

@media (prefers-reduced-motion: reduce) {
  .mchat__window { animation: none; }
  .mchat__teaser, .mchat__ico, .mchat__launcher { transition: none; }
  .mchat__dots i { animation-duration: 2.4s; }
}

/* ---------- voice call with Melodía ---------- */
.mchat__call {
  position: absolute; inset: 78px 0 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 24px 20px 28px;
  text-align: center; color: var(--mc-light);
  background:
    radial-gradient(120% 80% at 50% 0%, color-mix(in srgb, var(--mc-accent) 22%, transparent), transparent 60%),
    linear-gradient(180deg, var(--mc-main), var(--mc-dark));
  animation: mchat-fade .3s var(--mc-ease);
}
@keyframes mchat-fade { from { opacity: 0; } }
.mchat__call-face {
  position: relative; display: grid; place-items: center; width: 104px; height: 104px; margin-bottom: 10px;
  border-radius: 50%; background: var(--mc-light); box-shadow: 0 0 0 6px rgba(255,255,255,.14);
}
.mchat__call-face img { width: 64px; height: 64px; }
.mchat__window.is-calling .mchat__call-face::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35);
  animation: mchat-ring 1.8s var(--mc-ease) infinite;
}
@keyframes mchat-ring { from { transform: scale(1); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
.mchat__call-name { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.mchat__call-state { margin: 0 0 18px; max-width: 280px; font-size: 14.5px; line-height: 1.45; color: rgba(255,255,255,.85); font-variant-numeric: tabular-nums; }
.mchat__call-buttons { display: flex; gap: 22px; }
.mchat__call-btn {
  display: grid; place-items: center; width: 60px; height: 60px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: rgba(255,255,255,.16); color: var(--mc-light); transition: background-color .2s, transform .2s var(--mc-ease);
}
.mchat__call-btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.26); }
.mchat__call-btn:focus-visible { outline-color: var(--mc-light); outline-offset: 3px; }
.mchat__call-btn svg { width: 26px; height: 26px; }
.mchat__call-mute.is-on { background: var(--mc-light); color: var(--mc-dark); }
.mchat__call-hang { background: #E5484D; }
.mchat__call-hang:hover { background: #D93D42; }
.mchat__call-hang.is-close { background: rgba(255,255,255,.16); }
.mchat__call-clinic { margin-top: 22px; font-size: 13px; color: rgba(255,255,255,.75); text-decoration: underline; text-underline-offset: 3px; }
.mchat__call-clinic:hover { color: var(--mc-light); }
.mchat__call-audio { display: none; }
@media (prefers-reduced-motion: reduce) {
  .mchat__window.is-calling .mchat__call-face::before { animation: none; }
}

/* ---------- lists Melodía sends: treatment bubbles and doctor cards ---------- */
.mchat__list { margin-top: 8px; width: 100%; }
.mchat__list--treatments, .mchat__list--lang { display: flex; flex-wrap: wrap; gap: 6px; }
.mchat__list--lang .mchat__chip { cursor: pointer; font: inherit; font-size: 13.5px; font-weight: 600; }
.mchat__chip {
  display: inline-flex; align-items: center; padding: 7px 13px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--mc-main) 35%, transparent); background: var(--mc-light);
  color: var(--mc-dark); font-size: 13.5px; font-weight: 600; line-height: 1.2; text-decoration: none;
  transition: background-color .2s, color .2s, border-color .2s, transform .2s var(--mc-ease);
}
.mchat__chip:hover { background: var(--mc-main); border-color: var(--mc-main); color: var(--mc-light); transform: translateY(-1px); }
.mchat__list--team {
  display: grid; overflow: hidden; border-radius: 16px; background: var(--mc-light);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--mc-dark) 8%, transparent), 0 0 0 1px var(--mc-line);
}
.mchat__person {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; color: var(--mc-ink); text-decoration: none;
  transition: background-color .2s;
}
.mchat__person + .mchat__person { border-top: 1px solid var(--mc-line); }
.mchat__person:hover { background: var(--mc-soft); }
.mchat__person img { flex: none; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; object-position: top; background: var(--mc-soft); }
.mchat__person-text { display: grid; min-width: 0; }
.mchat__person-name { font-size: 14px; font-weight: 700; line-height: 1.3; }
.mchat__person-role { font-size: 12.5px; line-height: 1.35; color: color-mix(in srgb, var(--mc-ink) 62%, transparent); }
.mchat__more {
  padding: 10px 12px; border: 0; border-top: 1px solid var(--mc-line); background: none; cursor: pointer;
  color: var(--mc-main); font-size: 13px; font-weight: 700; text-align: center;
}
.mchat__more:hover { background: var(--mc-soft); }
.mchat__row:has(.mchat__list) { max-width: 94%; }
.mchat__row:has(.mchat__list--team) { width: 94%; }

/* during a call the chat's own header buttons would only confuse: the call screen has its own */
.mchat__window.has-call .mchat__btn--end,
.mchat__window.has-call .mchat__btn--call { visibility: hidden; }
