/* ==========================================================================
   CMS Assistant chat widget — see js/chat.js. Uses the brand tokens from
   styles.css.
   ========================================================================== */

.cms-chat {
  --chat-gap: max(16px, env(safe-area-inset-right));
  position: fixed;
  right: var(--chat-gap);
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 150;
  font-family: var(--font-body);
}

/* ---------- Launcher ---------- */
.cms-chat__launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--teal);
  color: var(--white);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lift);
  transition: transform 0.2s ease, background 0.2s ease;
  margin-left: auto;
}
.cms-chat__launcher i { font-size: 30px; }
.cms-chat__launcher:hover { background: var(--teal-deep); transform: translateY(-2px); }
.cms-chat__launcher:active { transform: scale(0.95); }

/* ---------- Panel ---------- */
.cms-chat__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  height: min(600px, calc(100dvh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
  animation: cms-chat-in 0.22s ease-out;
}
.cms-chat__panel[hidden] { display: none; }

@keyframes cms-chat-in {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Phones: take over the screen like a native chat, launcher hidden. */
@media (max-width: 639px) {
  .cms-chat.is-open { inset: 0; }
  .cms-chat.is-open .cms-chat__launcher { display: none; }
  .cms-chat__panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.cms-chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--teal-deep);
  color: var(--white);
}
.cms-chat__logo { width: 32px; height: 32px; flex-shrink: 0; }
.cms-chat__titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.cms-chat__titles strong { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; }
.cms-chat__titles span { font-family: var(--font-mono); font-size: 0.72rem; opacity: 0.8; }
.cms-chat__close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--white);
}
.cms-chat__close i { font-size: 20px; }
.cms-chat__close:hover { background: rgba(255, 255, 255, 0.12); }

/* ---------- Messages ---------- */
.cms-chat__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cms-chat__msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.94rem;
  line-height: 1.5;
}
.cms-chat__msg p + p,
.cms-chat__msg ul + p,
.cms-chat__msg p + ul { margin-top: 6px; }
.cms-chat__msg ul { list-style: disc; padding-left: 18px; }
.cms-chat__msg li + li { margin-top: 2px; }

.cms-chat__msg--bot {
  align-self: flex-start;
  background: var(--white);
  border: 1px solid var(--hairline);
  border-bottom-left-radius: 4px;
}
.cms-chat__msg--user {
  align-self: flex-end;
  background: var(--teal);
  color: var(--white);
  border-bottom-right-radius: 4px;
  overflow-wrap: anywhere;
}

.cms-chat__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.cms-chat__action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--teal);
  color: var(--teal-deep);
  font-size: 0.86rem;
  font-weight: 600;
  transition: background 0.15s ease;
}
.cms-chat__action:hover { background: var(--teal-tint); }
.cms-chat__action--primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.cms-chat__action--primary:hover { background: #cf9636; }
.cms-chat__action i { font-size: 1.1em; }

.cms-chat__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.cms-chat__chip {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--teal-tint);
  color: var(--teal-deep);
  font-size: 0.84rem;
  font-weight: 500;
  transition: background 0.15s ease;
}
.cms-chat__chip:hover { background: #bcdcd3; }

.cms-chat__typing { display: flex; gap: 4px; padding: 14px; }
.cms-chat__typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-soft);
  opacity: 0.4;
  animation: cms-chat-dot 1s infinite ease-in-out;
}
.cms-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.cms-chat__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes cms-chat-dot {
  0%, 100% { opacity: 0.3; transform: none; }
  50% { opacity: 0.9; transform: translateY(-3px); }
}

/* ---------- Input ---------- */
.cms-chat__form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--hairline);
  background: var(--white);
}
.cms-chat__input {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  font: inherit;
  font-size: 16px; /* stops iOS zooming in on focus */
  color: var(--ink);
  background: var(--paper);
}
.cms-chat__input:focus { outline: none; border-color: var(--teal); }
.cms-chat__send {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--teal);
  color: var(--white);
  display: grid;
  place-items: center;
}
.cms-chat__send:hover { background: var(--teal-deep); }
.cms-chat__send i { font-size: 20px; }

/* ---------- Pop-up greeting ---------- */
.cms-chat__greeting {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: max-content;
  max-width: min(280px, calc(100vw - 32px));
  animation: cms-chat-in 0.3s ease-out;
}
.cms-chat__greeting-text {
  display: block;
  text-align: left;
  padding: 12px 34px 12px 14px;
  background: var(--white);
  border: 1px solid var(--hairline);
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-card);
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink);
}
.cms-chat__greeting-text:hover { border-color: var(--teal); }
.cms-chat__greeting-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
}
.cms-chat__greeting-close:hover { background: var(--teal-tint); }
.cms-chat__greeting-close i { font-size: 14px; }
.cms-chat.is-open .cms-chat__greeting { display: none; }
