/*
 * Help chat on the registration page (partials/chatbot.php).
 *
 * Uses the app.css tokens. A small launcher sits bottom-right; the panel opens
 * above it on wider screens and as a bottom sheet on a phone. The page gets
 * extra bottom padding so the launcher never sits over the form's buttons.
 */
.has-chatbot .page { padding-bottom: 104px; }

.chatbot {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  font-size: 14px;
  line-height: 1.5;
}

.chatbot__launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--orange);
  color: #fff;
  font: inherit;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .35);
  cursor: pointer;
  transition: background-color .15s, transform .15s;
}

.chatbot__launcher:hover { background: var(--orange-dark); }
.chatbot__launcher:focus-visible { outline: 3px solid rgba(255, 51, 0, .35); outline-offset: 3px; }

.chatbot__icon { width: 24px; height: 24px; fill: currentColor; }
.chatbot__icon--close,
.chatbot.is-open .chatbot__icon--open { display: none; }
.chatbot.is-open .chatbot__icon--close { display: block; }
.chatbot.is-open .chatbot__launcher-label { display: none; }
.chatbot.is-open .chatbot__launcher { padding: 0 14px; }

.chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 66px;
  display: flex;
  flex-direction: column;
  width: 360px;
  max-height: min(560px, calc(100vh - 110px));
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .4);
}

.chatbot__panel[hidden] { display: none; }

.chatbot__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--black);
  color: #fff;
}

.chatbot__avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--orange);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: -.5px;
}

/* The approved JBL logo (final logo.png) replaces the old text mark. Aspect ratio is kept.
   Shown whole: the image has the ® in a strip right of the orange box, and rounding/clipping cut that side off. */
.chatbot__avatar { width: auto; height: auto; border-radius: 0; background: transparent; overflow: visible; }
.chatbot__avatar img { display: block; width: auto; height: 42px; max-width: none; }

.chatbot__head > div { flex: 1; min-width: 0; }
.chatbot__title { margin: 0; font-size: 15px; line-height: 1.2; }
.chatbot__status { margin: 2px 0 0; color: #bdbdbd; font-size: 12px; }

.chatbot__close {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.chatbot__close:hover { background: rgba(255, 255, 255, .12); }

.chatbot__log {
  position: relative;
  flex: 1 1 auto;
  min-height: 90px;
  padding: 14px;
  overflow-y: auto;
  background: var(--soft);
  overscroll-behavior: contain;
}

.chatbot__msg {
  max-width: 88%;
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 12px;
}

.chatbot__msg > :first-child { margin-top: 0; }
.chatbot__msg > :last-child { margin-bottom: 0; }
.chatbot__msg p { margin: 0 0 8px; }
.chatbot__msg ol,
.chatbot__msg ul { margin: 0 0 8px; padding-left: 18px; }
.chatbot__msg li { margin-bottom: 4px; }
.chatbot__msg a { color: var(--orange); font-weight: 700; }

.chatbot__msg--bot {
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  background: #fff;
}

.chatbot__msg--user {
  margin-left: auto;
  border-bottom-right-radius: 4px;
  background: var(--orange);
  color: #fff;
  font-weight: 700;
}

.chatbot__action {
  display: inline-block;
  padding: 7px 12px;
  border: 1px solid var(--orange);
  border-radius: 8px;
  background: #fff;
  color: var(--orange);
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.chatbot__msg a.chatbot__action { text-decoration: none; }
.chatbot__action:hover { background: #fff3ef; }

.chatbot__topics {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 150px;
  padding: 10px 12px 12px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  background: #fff;
}

.chatbot__chip {
  padding: 6px 11px;
  border: 1px solid #f0c7bc;
  border-radius: 999px;
  background: #fff3ef;
  color: #7d2816;
  font: inherit;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
}

.chatbot__chip:hover,
.chatbot__chip:focus-visible { border-color: var(--orange); background: var(--orange); color: #fff; outline: none; }

/* Phone: a smaller launcher, and the panel as a sheet across the bottom. */
@media (max-width: 560px) {
  .has-chatbot .page { padding-bottom: 88px; }
  .chatbot { right: 14px; bottom: 14px; }
  .chatbot__launcher { min-height: 48px; padding: 0 14px 0 12px; }

  .chatbot__panel {
    position: fixed;
    right: 8px;
    bottom: 72px;
    left: 8px;
    width: auto;
    max-height: calc(100vh - 96px);
    max-height: calc(100dvh - 96px);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .chatbot__panel:not([hidden]) { animation: chatbot-in .16s ease-out; }
  @keyframes chatbot-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

/* "Chat with an admin": the entry button, and the live conversation that replaces the topics. */
.chatbot__live-cta {
  flex: none;
  padding: 10px 12px 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.chatbot__livebtn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--black);
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.chatbot__livebtn:hover { background: #262626; }
.chatbot__livebtn:focus-visible { outline: 3px solid rgba(255, 51, 0, .35); outline-offset: 2px; }
.chatbot__livebtn-text { display: grid; gap: 1px; }
.chatbot__livebtn-text strong { font-size: 14px; }
.chatbot__livebtn-text small { color: #bdbdbd; font-size: 11.5px; }
.chatbot__livebtn-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--orange); }

/* Unread reply: a dot on the launcher and on the panel's chat button. */
.chatbot.has-unread .chatbot__launcher { position: relative; }
.chatbot.has-unread .chatbot__launcher::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: #1fb15a;
}

.chatbot.is-live .chatbot__log,
.chatbot.is-live .chatbot__live-cta,
.chatbot.is-live .chatbot__topics { display: none; }

.chatlive { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; background: #fff; }
.chatlive[hidden], .chatlive [hidden] { display: none !important; }

.chatlive__bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--soft); }
.chatlive__link { padding: 4px 6px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.chatlive__link:hover { color: var(--orange); }
.chatlive__link--end { color: var(--danger); }

.chatlive__banner { padding: 9px 14px; font-size: 12.5px; line-height: 1.45; }
.chatlive__banner--waiting { background: #fff3ef; color: #7d2816; border-bottom: 1px solid #f0c7bc; }
.chatlive__banner--seen { background: #eef6ff; color: #174a7c; border-bottom: 1px solid #cfe2f5; }
.chatlive__banner--ended { background: #f0f0f0; color: #555; border-bottom: 1px solid var(--line); }

.chatlive__start { display: grid; gap: 10px; padding: 14px; overflow-y: auto; }
.chatlive__lead { margin: 0; color: #444; font-size: 13px; }
.chatlive__field { display: grid; gap: 4px; font-size: 12.5px; font-weight: 800; }
.chatlive__field input,
.chatlive__field textarea { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid #bbb; border-radius: 8px; background: #fff; color: var(--ink); font: inherit; font-size: 14px; font-weight: 400; }
.chatlive__field textarea { resize: vertical; }
.chatlive__field input:focus,
.chatlive__field textarea:focus,
.chatlive__composer textarea:focus { outline: 3px solid rgba(255, 51, 0, .2); border-color: var(--orange); }
.chatlive__trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.chatlive__note { margin: 0; color: var(--muted); font-size: 11.5px; text-align: center; }

.chatlive__send { min-height: 40px; padding: 8px 16px; border: 0; border-radius: 8px; background: var(--orange); color: #fff; font: inherit; font-weight: 800; cursor: pointer; }
.chatlive__send:hover { background: var(--orange-dark); }
.chatlive__send:disabled { opacity: .6; cursor: wait; }

.chatlive__error { margin: 0; padding: 6px 14px; color: var(--danger); font-size: 12.5px; }
.chatlive__start .chatlive__error { padding: 0; }

.chatlive__convo { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }
.chatlive__log { flex: 1 1 auto; min-height: 150px; padding: 12px 14px; overflow-y: auto; background: var(--soft); overscroll-behavior: contain; }

.chatlive__msg { display: flex; flex-direction: column; max-width: 86%; margin-bottom: 10px; }
.chatlive__msg p { margin: 0; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chatlive__msg small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.chatlive__msg--admin p { border: 1px solid var(--line); border-bottom-left-radius: 4px; background: #fff; }
.chatlive__msg--me { margin-left: auto; align-items: flex-end; }
.chatlive__msg--me p { border-bottom-right-radius: 4px; background: var(--orange); color: #fff; }
.chatlive__receipt { margin-top: 1px; color: var(--muted); font-size: 11px; font-weight: 700; }
.chatlive__receipt.is-seen { color: #1b7f45; }

.chatlive__composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-top: 1px solid var(--line); background: #fff; }
.chatlive__composer textarea { flex: 1; min-height: 40px; max-height: 96px; padding: 9px 10px; border: 1px solid #bbb; border-radius: 8px; font: inherit; font-size: 14px; resize: none; }
.chatlive__sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Photos (assets/chat-live.js): the camera button, the photo waiting to be sent, and photos in the conversation. */
.chatlive__attach { position: relative; display: inline-flex; flex: none; align-items: center; justify-content: center; width: 40px; height: 40px; border: 1px solid #bbb; border-radius: 8px; background: #fff; color: #555; cursor: pointer; }
.chatlive__attach:hover { border-color: var(--orange); color: var(--orange); }
.chatlive__attach:focus-within { outline: 3px solid rgba(255, 51, 0, .2); border-color: var(--orange); }
.chatlive__attach svg { width: 21px; height: 21px; fill: currentColor; }
.chatlive__attach:has(input:disabled) { opacity: .5; cursor: wait; }
.chatlive__pending { display: flex; gap: 10px; align-items: center; padding: 8px 12px; border-top: 1px solid var(--line); background: #fff; }
.chatlive__pending-img { flex: none; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 6px; object-fit: cover; background: var(--soft); }
.chatlive__pending-text { flex: 1; min-width: 0; overflow: hidden; color: #444; font-size: 12.5px; text-overflow: ellipsis; white-space: nowrap; }
.chatlive__pending-remove { flex: none; width: 30px; height: 30px; border: 0; border-radius: 50%; background: var(--soft); color: #444; font-size: 20px; line-height: 1; cursor: pointer; }
.chatlive__pending-remove:hover { background: #eee; color: var(--danger); }
.chatlive__img { display: block; max-width: 100%; margin-bottom: 4px; line-height: 0; }
.chatlive__img img { display: block; max-width: 100%; height: auto; max-height: 220px; border: 1px solid var(--line); border-radius: 12px; background: #fff; object-fit: contain; }
.chatlive__msg--me .chatlive__img img { border-bottom-right-radius: 4px; }
.chatlive__msg--admin .chatlive__img img { border-bottom-left-radius: 4px; }

.chatlive__ended { display: grid; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: #fff; text-align: center; }
.chatlive__ended p { margin: 0; color: var(--muted); }

.chatbot.is-live .chatbot__panel { height: min(560px, calc(100vh - 110px)); }

@media (max-width: 560px) {
  .chatbot.is-live .chatbot__panel { height: calc(100vh - 96px); height: calc(100dvh - 96px); }
}

/*
 * AI assistant (assets/ai-chat.js). Only on a page rendered with .chatbot--ai.
 * The box to type in sits under the topic buttons, which become one row that scrolls
 * sideways so the conversation keeps most of the panel.
 */
.chatbot--ai .chatbot__log { order: 1; min-height: 150px; }
.chatbot--ai .chatbot__topics { order: 2; flex-wrap: nowrap; max-height: none; padding: 8px 12px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.chatbot--ai .chatbot__chip { flex: none; white-space: nowrap; }
.chatbot--ai .aichat__composer { order: 3; }
.chatbot--ai .aichat__note { order: 4; }
.chatbot--ai .chatbot__live-cta { order: 5; padding-bottom: 10px; }
.chatbot--ai .chatbot__livebtn { padding: 8px 14px; }
.chatbot--ai .chatbot__livebtn-text small { display: none; }
.chatbot--ai .chatlive { order: 1; }

.aichat__composer { display: flex; flex: none; gap: 8px; align-items: flex-end; padding: 10px 12px 4px; border-top: 1px solid var(--line); background: #fff; }
.aichat__composer textarea { flex: 1; min-height: 40px; max-height: 96px; padding: 9px 10px; border: 1px solid #bbb; border-radius: 8px; font: inherit; font-size: 14px; resize: none; }
.aichat__composer textarea:focus { outline: 3px solid rgba(255, 51, 0, .2); border-color: var(--orange); }
.aichat__composer.is-busy textarea { background: var(--soft); }

.aichat__note { flex: none; margin: 0; padding: 0 14px 8px; background: #fff; color: var(--muted); font-size: 11px; line-height: 1.35; text-align: center; }

.aichat__text { white-space: pre-wrap; overflow-wrap: anywhere; }
.chatbot__msg--error { border-color: #f0c7bc; background: #fff3ef; }

.aichat__typing { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.aichat__typing i { width: 7px; height: 7px; border-radius: 50%; background: #9a9a9a; opacity: .45; }
@media (prefers-reduced-motion: no-preference) {
  .aichat__typing i { animation: aichat-dot 1s infinite ease-in-out; }
  .aichat__typing i:nth-child(2) { animation-delay: .15s; }
  .aichat__typing i:nth-child(3) { animation-delay: .3s; }
  @keyframes aichat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
}

.chatbot.is-live .aichat__composer,
.chatbot.is-live .aichat__note { display: none; }
