/* Mobi corner greeter + chat (js/mobi-buddy.js). Ported from the BTSanTech SanBuddy styles.
   5 moods x 4 s, CSS only. Clicks pass through except the mascot, its chat and the close button. */
.sb {
  /* the site's palette (css/site-shell.css): ink, lime buttons with ink text, grey-green lines */
  --c-deep: #1c272d;
  --c-action: #d4fb03;
  --c-action-hover: #b8ef00;
  --c-on-action: #121919;
  --c-mark: #b2d700; /* lime underline under ink links */
  --c-pale: #f2f5f3;
  --c-line: #e3e8e4;
  --c-line-strong: #cdd6cf;
  --c-ink: #1c272d;
  --c-ink-muted: #5f6a6f;
  --c-white: #fff;
  --c-sky: #f2b632; /* sparkles: the gold ring round Mobi's face */
  position: fixed;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex; /* bubble, then the mascot in the corner */
  align-items: flex-end;
  pointer-events: none;
  font-family: Outfit, Anuphan, sans-serif;
}
.sb[data-out] {
  visibility: hidden;
}
.sb button { font-family: inherit; }
.sb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.sb-say {
  display: grid;
  max-width: min(13rem, 52vw);
  margin: 0 -0.25rem 3.25rem 0;
  padding: 0.5rem 0.875rem;
  border: 1px solid var(--c-line);
  border-radius: 1rem 1rem 0.25rem 1rem;
  background: var(--c-white);
  box-shadow: 0 4px 14px rgb(28 39 45 / 0.12);
  font-size: 0.875rem;
  line-height: 1.6;
  font-weight: 600;
  color: var(--c-deep);
  text-align: center;
}
.sb-fig {
  position: relative;
  display: grid;
  width: clamp(6.5rem, 9vw, 7.5rem);
  padding: 0;
  border: 0;
  border-radius: 1rem;
  background: none;
  cursor: pointer;
  pointer-events: auto;
  filter: drop-shadow(0 6px 8px rgb(28 39 45 / 0.2));
}
.sb-ask {
  position: absolute;
  left: 50%;
  bottom: -0.125rem;
  translate: -50% 0;
  padding: 0.0625rem 0.625rem;
  border-radius: 1rem;
  background: var(--c-action);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  color: var(--c-on-action);
}
.sb-fig:hover > .sb-ask {
  background: var(--c-action-hover);
}
/* chat panel above the mascot */
.sb-chat {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.5rem);
  display: flex;
  flex-direction: column;
  width: min(25rem, calc(100vw - 1.5rem));
  /* mascot + bottom gap + the fixed site header + air, so the chat head never slides under it */
  max-height: min(40rem, calc(100dvh - 14.5rem));
  overflow: hidden;
  border: 1px solid var(--c-line);
  border-radius: 1rem;
  background: var(--c-white);
  box-shadow: 0 10px 30px rgb(28 39 45 / 0.2);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--c-ink);
  pointer-events: auto;
}
.sb-chat p {
  margin: 0;
}
.sb-chat-head {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 0.75rem 0.75rem 1rem;
  background: var(--c-deep);
  color: var(--c-white);
}
.sb-chat-head > img {
  border-radius: 50%;
  background: var(--c-pale);
}
.sb-chat-head > p {
  flex: 1;
  font-size: 1.0625rem;
}
.sb-chat-head button {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: none;
  color: inherit;
  cursor: pointer;
}
.sb-chat-head button:hover {
  background: rgb(255 255 255 / 0.15);
}
.sb-chat-head button:focus-visible {
  outline: 2px solid var(--c-white);
}
.sb-log:focus-visible {
  outline: 2px solid var(--c-deep);
  outline-offset: -2px;
}
.sb-log {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 6rem;
  overflow-y: auto;
  padding: 1rem;
}
.sb-msg {
  align-self: flex-start;
  max-width: 88%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.25rem 1rem 1rem 1rem;
  background: var(--c-pale);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sb-msg.sb-me {
  align-self: flex-end;
  border-radius: 1rem 0.25rem 1rem 1rem;
  background: var(--c-action);
  color: var(--c-on-action);
}
.sb-msg.sb-wait {
  color: var(--c-ink-muted);
}
.sb-msg > a {
  display: block;
  margin-top: 0.25rem;
  font-weight: 600;
  color: var(--c-deep);
  text-decoration: underline 2px var(--c-mark);
  text-underline-offset: 0.2em;
}
.sb-handoff {
  align-self: flex-start;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--c-deep);
  text-decoration: underline 2px var(--c-mark);
  text-underline-offset: 0.2em;
}
.sb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.sb-chips > button {
  min-height: 2.5rem;
  padding: 0.25rem 1rem;
  border: 1px solid var(--c-line-strong);
  border-radius: 1.25rem;
  background: var(--c-white);
  font: inherit;
  color: var(--c-deep);
  cursor: pointer;
}
.sb-chips > button:hover {
  border-color: var(--c-action-hover);
  background: var(--c-action);
}
.sb-direct {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--c-line);
}
.sb-direct > p {
  grid-column: 1 / -1;
  font-size: 0.875rem;
  color: var(--c-ink-muted);
}
.sb-direct > a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 1.25rem;
  font-weight: 600;
  color: var(--c-white);
  text-decoration: none;
  white-space: nowrap;
}
.sb-direct > .sb-line { background: #007f37; }
.sb-direct > .sb-phone { background: var(--c-deep); }
.sb-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--c-line);
}
.sb-note { margin: -0.5rem 0 0; padding: 0 1rem 0.75rem; font-size: 0.75rem; line-height: 1.5; color: var(--c-ink-muted); }
.sb-note > a { color: inherit; }
.sb-form > input {
  flex: 1;
  min-width: 0;
  height: 3rem;
  padding: 0 0.875rem;
  border: 1px solid var(--c-line-strong);
  border-radius: 0.5rem;
  background: var(--c-white);
  font: inherit;
  font-size: 1rem; /* under 16px iOS zooms the page on focus */
  color: var(--c-ink);
}
.sb-form > button {
  height: 3rem;
  padding: 0 0.875rem;
  border: 0;
  border-radius: 0.5rem;
  background: var(--c-action);
  font: inherit;
  font-weight: 600;
  color: var(--c-on-action);
  cursor: pointer;
}
.sb-form > button:enabled:hover {
  background: var(--c-action-hover);
}
.sb-form > button:disabled {
  background: var(--c-line);
  color: var(--c-ink-muted);
  cursor: default;
}
/* voice call: replaces the form while a call is on; --lvl (0-1) is the louder voice, set by mobi-buddy.js */
.sb-call {
  display: grid;
  gap: 0.625rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--c-line);
}
.sb-call[hidden] { display: none; }
.sb-call-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.sb-call-status {
  margin: 0;
  font-weight: 600;
  color: var(--c-ink);
}
.sb-call-lvl {
  flex: none;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  background: var(--c-mark);
  box-shadow: 0 0 0 calc(var(--lvl, 0) * 0.5rem) rgb(212 251 3 / 0.45);
  transition: box-shadow 0.1s linear;
}
.sb-call button {
  flex: 1;
  height: 3rem;
  padding: 0 1rem;
  border-radius: 1.25rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.sb-call-row > button:first-child {
  border: 1px solid var(--c-line-strong);
  background: var(--c-white);
  color: var(--c-ink);
}
.sb-call-row > button[aria-pressed='true'] { background: var(--c-pale); }
.sb-call-end {
  border: 0;
  background: #b42318;
  color: var(--c-white);
}
.sb-call-end:hover { background: #912018; }
.sb-call-unblock {
  border: 0;
  background: var(--c-action);
  color: var(--c-on-action);
}
.sb-call-unblock[hidden] { display: none; }
.sb-call-note {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--c-ink-muted);
}
/* phones: the open chat fills the screen (over the header and the mascot); the head's close button folds it away */
@media (max-width: 639.98px) {
  .sb:has(.sb-chat) {
    z-index: 70;
  }
  .sb .sb-chat {
    position: fixed;
    inset: 0;
    z-index: 1;
    width: auto;
    max-height: none;
    border: 0;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sb-chat-head {
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }
  .sb-log {
    overscroll-behavior: contain;
  }
  .sb-form {
    padding-bottom: 0.75rem;
  }
}
.sb-say > span,
.sb-fig > img {
  grid-area: 1 / 1;
}
.sb-say > span + span,
.sb-fig > img + img {
  opacity: 0; /* reduced motion: the first greeting stays, nothing cycles */
}
.sb-say > [data-say]::before {
  content: attr(data-say);
}
.sb-fig > img {
  width: 100%;
  height: auto;
}
/* chat open: the mascot holds the face that fits the chat instead of cycling */
.sb[data-mood] .sb-fig > img {
  opacity: 0;
}
.sb[data-mood] .sb-fig > img[data-on] {
  opacity: 1;
}
.sb-x {
  position: absolute;
  right: 0;
  bottom: calc(clamp(6.5rem, 9vw, 7.5rem) - 1.25rem); /* on the mascot's top corner, however tall the bubble gets */
  display: grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid var(--c-line-strong);
  border-radius: 50%;
  background: var(--c-white);
  color: var(--c-deep);
  cursor: pointer;
  pointer-events: auto;
}
.sb-x:hover {
  background: var(--c-pale);
}
@media (prefers-reduced-motion: no-preference) {
  /* in and out of the corner in one continuous move */
  .sb {
    transition: translate 0.7s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.4s, visibility 0s;
  }
  .sb[data-out] {
    translate: 0 calc(100% + 1.5rem);
    opacity: 0;
    transition: translate 0.5s ease-in, opacity 0.4s 0.1s, visibility 0s 0.5s;
  }
  @starting-style {
    .sb {
      translate: 0 calc(100% + 1.5rem);
      opacity: 0;
    }
  }
  .sb-say > span,
  .sb-say > span + span {
    opacity: 0;
    animation: sb-turn 20s infinite both;
  }
  .sb-fig > img,
  .sb-fig > img + img {
    opacity: 0;
    transform-origin: 50% 90%;
    /* one shared 4s sway; its low point (inline delay -3.75s) sits on each picture swap */
    animation: sb-fade 20s infinite both, sb-sway 4s ease-in-out infinite;
  }
  /* chat-only faces never join the greeter cycle */
  .sb-fig > img[data-chat] {
    animation-name: none, sb-sway;
  }
  /* mood change: the new face fades in first and the old one leaves after it, so the figure never goes see-through */
  .sb[data-mood] .sb-fig > img {
    animation-name: none, sb-sway;
    transition: opacity 0.2s 0.25s;
  }
  .sb[data-mood] .sb-fig > img[data-on] {
    transition: opacity 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .sb-chat-head > img {
    animation: sb-face 0.35s cubic-bezier(0.22, 1, 0.36, 1), sb-sway 4s ease-in-out infinite;
  }
  @keyframes sb-face {
    from {
      transform: scale(0.8);
    }
  }
  @keyframes sb-turn {
    0% {
      opacity: 0;
      transform: translateY(0.4rem) scale(0.9);
    }
    3%,
    18.5% {
      opacity: 1;
      transform: none;
    }
    20%,
    100% {
      opacity: 0;
      transform: translateY(-0.4rem) scale(0.96);
    }
  }
  @keyframes sb-fade {
    0%,
    22.5%,
    100% {
      opacity: 0;
    }
    1.5%,
    21% {
      opacity: 1;
    }
  }
  @keyframes sb-sway {
    0%,
    100% {
      transform: translateY(0.25rem) scale(1.03, 0.95);
    }
    30% {
      transform: translateY(-0.3rem) scale(0.99, 1.02) rotate(2deg);
    }
    65% {
      transform: translateY(-0.1rem) rotate(-2deg);
    }
  }
  .sb-fig:active {
    scale: 0.95;
  }
  .sb-chips > button,
  .sb-direct > a,
  .sb-form > button {
    transition: translate 0.2s, background-color 0.2s, box-shadow 0.2s;
  }
  .sb-x,
  .sb-chat-head button {
    transition: rotate 0.3s, background-color 0.2s;
  }
  @media (hover: hover) {
    .sb-chips > button:hover,
    .sb-direct > a:hover,
    .sb-form > button:enabled:hover {
      translate: 0 -2px;
    }
    .sb-fig:hover {
      scale: 1.06;
    }
    .sb-x:hover,
    .sb-chat-head button:hover {
      rotate: 90deg;
    }
  }
  /* the bubble floats with the sway, two gold sparkles twinkle beside Mobi, a glint crosses the "ask" pill */
  .sb-say {
    animation: sb-bob 4s ease-in-out -3.75s infinite;
  }
  @keyframes sb-bob {
    0%,
    100% {
      transform: translateY(2px);
    }
    40% {
      transform: translateY(-3px);
    }
  }
  .sb-fig {
    transform-origin: 50% 100%;
    transition: scale 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .sb-fig::before,
  .sb-fig::after {
    content: "";
    position: absolute;
    left: 2%;
    top: 16%;
    width: 0.75rem;
    height: 0.75rem;
    background: var(--c-sky);
    clip-path: polygon(50% 0, 62% 38%, 100% 50%, 62% 62%, 50% 100%, 38% 62%, 0 50%, 38% 38%);
    pointer-events: none;
    animation: sb-twinkle 4s ease-in-out infinite both;
  }
  .sb-fig::after {
    left: 46%;
    top: -4%;
    width: 0.5rem;
    height: 0.5rem;
    animation-delay: 2s;
  }
  @keyframes sb-twinkle {
    0%,
    55%,
    100% {
      opacity: 0;
      transform: scale(0.2);
    }
    28% {
      opacity: 1;
      transform: scale(1) rotate(90deg);
    }
  }
  .sb-ask {
    overflow: hidden;
  }
  .sb-ask::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgb(255 255 255 / 0.45) 50%, transparent 65%);
    animation: sb-shine 4s ease-in-out infinite;
  }
  @keyframes sb-shine {
    0%,
    55% {
      transform: translateX(-110%);
    }
    85%,
    100% {
      transform: translateX(110%);
    }
  }
  /* the panel unfolds from the mascot and folds back into it (the script waits for the fold before removing it) */
  .sb-chat {
    transform-origin: calc(100% - 3.5rem) 100%;
    animation: sb-chat-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
  }
  .sb-chat[data-shut] {
    animation: sb-chat-out 0.22s ease-in both;
  }
  @keyframes sb-chat-in {
    from {
      opacity: 0;
      transform: translateY(1rem) scale(0.88);
    }
  }
  @keyframes sb-chat-out {
    to {
      opacity: 0;
      transform: translateY(1rem) scale(0.88);
    }
  }
  .sb-msg,
  .sb-chips > button,
  .sb-direct {
    animation: sb-up 0.35s cubic-bezier(0.2, 0.8, 0.3, 1) backwards;
  }
  .sb-msg.sb-me {
    animation-name: sb-up-me;
  }
  .sb-msg:first-child {
    animation-delay: 0.15s;
  }
  .sb-chips > button {
    animation-delay: 0.25s;
  }
  .sb-chips > button:nth-child(2) {
    animation-delay: 0.31s;
  }
  .sb-chips > button:nth-child(3) {
    animation-delay: 0.37s;
  }
  .sb-chips > button:nth-child(4) {
    animation-delay: 0.43s;
  }
  .sb-direct {
    animation-delay: 0.5s;
  }
  @keyframes sb-up {
    from {
      opacity: 0;
      transform: translateY(0.6rem);
    }
  }
  @keyframes sb-up-me {
    from {
      opacity: 0;
      transform: translate(0.8rem, 0.3rem) scale(0.95);
    }
  }
  /* waiting for an answer: three dots hop in turn after "typing" */
  .sb-wait::after {
    content: "";
    display: inline-block;
    width: 1.5rem;
    height: 0.75rem;
    margin-left: 0.375rem;
    background: radial-gradient(circle, currentColor 0.14rem, transparent 0.16rem) 0 100% / 0.5rem 0.5rem no-repeat,
      radial-gradient(circle, currentColor 0.14rem, transparent 0.16rem) 50% 100% / 0.5rem 0.5rem no-repeat,
      radial-gradient(circle, currentColor 0.14rem, transparent 0.16rem) 100% 100% / 0.5rem 0.5rem no-repeat;
    animation: sb-typing 1.1s ease-in-out infinite;
  }
  @keyframes sb-typing {
    0%,
    60%,
    100% {
      background-position: 0 100%, 50% 100%, 100% 100%;
    }
    15% {
      background-position: 0 0, 50% 100%, 100% 100%;
    }
    30% {
      background-position: 0 100%, 50% 0, 100% 100%;
    }
    45% {
      background-position: 0 100%, 50% 100%, 100% 0;
    }
  }
}
