/* Live chat widget. Self-contained so it looks right over every theme; it only
   borrows the site's primary colour. */
.jn-chat {
  --jc-accent: rgb(var(--clr-primary-code, 53, 143, 128));
  --jc-ink: #0b1b2b;
  --jc-muted: #5b6b7a;
  --jc-line: #e3e8ee;
  --jc-surface: #fff;
  --jc-soft: #f4f6f8;
  --jc-shadow: 0 24px 60px -12px rgba(11, 27, 43, .32), 0 0 0 1px rgba(11, 27, 43, .06);
  position: fixed;
  inset-block-end: 20px;
  inset-inline-end: 20px;
  z-index: 1045;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--jc-ink);
}

.dark-mode .jn-chat {
  --jc-ink: #eef2f8;
  --jc-muted: #a0acbf;
  --jc-line: #26324a;
  --jc-surface: #121b2d;
  --jc-soft: #0d1526;
}

/* The scroll-to-top button shares this corner. */
body:has(.jn-chat) #scrtop {
  bottom: 92px !important;
}

.jn-chat *,
.jn-chat *::before,
.jn-chat *::after {
  box-sizing: border-box;
}

.jn-chat-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Launcher */
.jn-chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin-inline-start: auto;
  border: 0;
  border-radius: 50%;
  background: var(--jc-accent);
  color: #fff;
  box-shadow: 0 12px 28px -6px rgba(11, 27, 43, .4);
  cursor: pointer;
  transition: transform .18s;
}

.jn-chat-launcher:hover {
  transform: scale(1.05);
}

.jn-chat-icon-close,
.jn-chat.is-open .jn-chat-icon-open {
  display: none;
}

.jn-chat.is-open .jn-chat-icon-close {
  display: block;
}

.jn-chat-badge {
  position: absolute;
  inset-block-start: -2px;
  inset-inline-end: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid #fff;
  border-radius: 99px;
  background: #e5484d;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

/* Panel */
.jn-chat-panel {
  position: absolute;
  inset-block-end: 76px;
  inset-inline-end: 0;
  display: flex;
  flex-direction: column;
  width: 370px;
  height: min(580px, calc(100vh - 120px));
  overflow: hidden;
  border-radius: 20px;
  background: var(--jc-surface);
  box-shadow: var(--jc-shadow);
  animation: jn-chat-in .18s ease-out;
}

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

@keyframes jn-chat-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
}

.jn-chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  background: var(--jc-accent);
  color: #fff;
}

.jn-chat-avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #fff;
  object-fit: contain;
}

.jn-chat-head-text {
  flex: 1;
  min-width: 0;
}

.jn-chat-head-text strong,
.jn-chat-head-text span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
}

.jn-chat-head-text strong {
  font-size: 16px;
}

.jn-chat-head-text span {
  font-size: 13px;
  opacity: .9;
}

.jn-chat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-inline-end: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

.jn-chat-back,
.jn-chat-close {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  cursor: pointer;
}

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

.jn-chat-back:hover,
.jn-chat-close:hover {
  background: rgba(255, 255, 255, .16);
}

.jn-chat-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px;
}

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

.jn-chat-greeting {
  margin: 0 0 16px;
  padding: 14px;
  border-radius: 14px;
  background: var(--jc-soft);
  color: var(--jc-ink);
}

/* Channels */
.jn-chat-channel {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--jc-line);
  border-radius: 14px;
  background: var(--jc-surface);
  color: var(--jc-ink);
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
  transition: border-color .15s, transform .15s;
}

.jn-chat-channel:hover {
  border-color: var(--jc-ink);
  color: var(--jc-ink);
  transform: translateY(-1px);
}

.jn-chat-channel strong,
.jn-chat-channel small {
  display: block;
}

.jn-chat-channel small {
  color: var(--jc-muted);
  font-size: 13px;
}

.jn-chat-channel-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #fff;
}

.jn-chat-channel-live .jn-chat-channel-icon {
  background: var(--jc-accent);
}

.jn-chat-channel-wa .jn-chat-channel-icon {
  background: #1fa855;
}

.jn-chat-channel-fb .jn-chat-channel-icon {
  background: #0866ff;
}

/* Forms */
.jn-chat-start label {
  display: block;
  margin-bottom: 12px;
  color: var(--jc-ink);
  font-size: 14px;
  font-weight: 600;
}

.jn-chat-start :is(input, textarea),
.jn-chat-composer textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--jc-line);
  border-radius: 12px;
  background: var(--jc-surface);
  color: var(--jc-ink);
  font: inherit;
  font-size: 16px;
  resize: none;
}

.jn-chat-start :is(input, textarea):focus,
.jn-chat-composer textarea:focus {
  outline: 2px solid var(--jc-accent);
  outline-offset: 0;
  border-color: transparent;
}

.jn-chat-submit {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--jc-accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.jn-chat-submit:disabled,
.jn-chat-composer button:disabled {
  opacity: .6;
  cursor: wait;
}

.jn-chat-error {
  margin: 0 0 12px;
  color: #d13438;
  font-size: 14px;
}

.jn-chat-thread .jn-chat-error {
  margin: 0;
  padding: 0 16px 10px;
}

/* Thread */
.jn-chat-thread {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.jn-chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  margin: 0;
  padding: 18px 16px;
  overflow-y: auto;
  list-style: none;
  background: var(--jc-soft);
}

.jn-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}

.jn-chat-msg p {
  margin: 0;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.jn-chat-msg.is-admin {
  align-self: flex-start;
}

.jn-chat-msg.is-admin p {
  border-end-start-radius: 4px;
  background: var(--jc-surface);
  color: var(--jc-ink);
  box-shadow: 0 1px 0 rgba(11, 27, 43, .06);
}

.jn-chat-msg.is-visitor {
  align-self: flex-end;
  align-items: flex-end;
}

.jn-chat-msg.is-visitor p {
  border-end-end-radius: 4px;
  background: var(--jc-accent);
  color: #fff;
}

.jn-chat-meta {
  margin-top: 4px;
  padding: 0 4px;
  color: var(--jc-muted);
  font-size: 12px;
}

.jn-chat-closed {
  margin: 0;
  padding: 10px 16px;
  background: #fff7e6;
  color: #7a4b00;
  font-size: 13px;
}

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

.jn-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--jc-line);
  background: var(--jc-surface);
}

.jn-chat-composer textarea {
  flex: 1;
  margin: 0;
  min-height: 44px;
  max-height: 120px;
}

.jn-chat-composer button {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--jc-accent);
  color: #fff;
  cursor: pointer;
}

.jn-chat :is(button, a, input, textarea):focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

@media (max-width: 480px) {
  .jn-chat {
    inset-block-end: 12px;
    inset-inline-end: 12px;
  }

  .jn-chat-panel {
    position: fixed;
    inset: 0;
    width: auto;
    height: auto;
    border-radius: 0;
  }

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

@media (prefers-reduced-motion: reduce) {
  .jn-chat-panel {
    animation: none;
  }

  .jn-chat-launcher,
  .jn-chat-channel {
    transition: none;
  }
}
