/* n8n Chat for WordPress - frontend styles
 *
 * The conversation itself is rendered by the official @n8n/chat widget and
 * themed through its CSS custom properties. Those, and our own --ck-* tokens,
 * are generated from the Appearance settings and printed inline on the
 * .chatkit-scope class (see ChatKit_WordPress::build_theme_css()).
 *
 * This file holds the layout: the floating launcher + panel, the inline
 * embedded container, and a few refinements on top of n8n's defaults.
 */

/* ------------------------------------------------------------------ */
/* Shared scope                                                        */
/* ------------------------------------------------------------------ */

.chatkit-scope,
.chatkit-scope * {
  box-sizing: border-box;
}

.chatkit-scope {
  font-family: var(--ck-font, inherit);
  font-size: var(--ck-font-size, 15px);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.chatkit-scope .n8n-chat {
  width: 100%;
  height: 100%;
}

/* Keep the message list as the single internal scroll area (n8n issue #16287).
 * The font falls back to the page's own when no family is configured. */
.chatkit-scope .chat-layout {
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  font-family: var(--ck-font, inherit);
}

.chatkit-scope .chat-layout .chat-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--ck-border) transparent;
}

/* n8n header (used by the inline embed; the floating panel draws its own). */
.chatkit-scope .chat-layout .chat-header {
  gap: 2px;
}

.chatkit-scope .chat-layout .chat-header h1 {
  margin: 0;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.chatkit-scope .chat-layout .chat-header p {
  margin: 0;
  opacity: 0.82;
}

/* Messages */
.chatkit-scope .chat-message {
  box-shadow: none;
  font-family: inherit;
}

.chatkit-scope .chat-message.chat-message-from-bot {
  border-bottom-left-radius: 4px;
}

.chatkit-scope .chat-message.chat-message-from-user {
  border-bottom-right-radius: 4px;
}

.chatkit-scope .chat-message-markdown a {
  color: var(--ck-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatkit-scope .chat-message.chat-message-from-user .chat-message-markdown a {
  color: inherit;
}

.chatkit-scope .chat-message-markdown p {
  margin: 0 0 0.6em;
}

.chatkit-scope .chat-message-markdown p:last-child {
  margin-bottom: 0;
}

.chatkit-scope .chat-message-markdown ul,
.chatkit-scope .chat-message-markdown ol {
  margin: 0.4em 0;
  padding-left: 1.3em;
}

.chatkit-scope .chat-message-markdown code {
  font-size: 0.9em;
}

.chatkit-scope .chat-message-typing {
  padding: 12px 16px;
}

/* Input */
.chatkit-scope .chat-inputs {
  align-items: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chatkit-scope .chat-inputs:focus-within {
  border-color: var(--ck-accent);
  box-shadow: 0 0 0 3px var(--ck-accent-ring);
}

.chatkit-scope .chat-inputs textarea {
  background: transparent;
  color: var(--ck-input-color);
  font-family: inherit;
}

.chatkit-scope .chat-inputs textarea::placeholder {
  color: var(--ck-muted);
  opacity: 1;
}

.chatkit-scope .chat-inputs textarea:focus,
.chatkit-scope .chat-inputs textarea:focus-visible {
  outline: none;
  box-shadow: none;
}

.chatkit-scope .chat-inputs .chat-input-send-button,
.chatkit-scope .chat-inputs .chat-input-file-button {
  margin: 0 2px 0 4px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.chatkit-scope .chat-inputs .chat-input-send-button:not([disabled]):hover {
  transform: scale(1.04);
}

.chatkit-scope .chat-inputs .chat-input-send-button[disabled] {
  background: transparent;
  color: var(--chat--color-disabled);
}

.chatkit-scope .chat-inputs .chat-input-send-button:focus-visible,
.chatkit-scope .chat-inputs .chat-input-file-button:focus-visible {
  outline: 2px solid var(--ck-accent);
  outline-offset: 2px;
}

/* Persistent footer line under the input (n8n only shows its footer on the
 * optional welcome screen, so we render our own). */
.chatkit-scope .chatkit-custom-footer {
  flex: 0 0 auto;
  padding: 6px 12px 8px;
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
  color: var(--ck-muted);
  background: var(--ck-input-bg);
}

/* ------------------------------------------------------------------ */
/* Inline embedded chat: [chatkit_embedded]                             */
/* ------------------------------------------------------------------ */

.chatkit-embedded-wrapper {
  position: relative;
  /* Paint above later page sections: themes that pull the next block up with a
   * negative (often viewport-based) margin would otherwise cover the input bar. */
  z-index: 1;
  display: block;
  overflow: hidden;
  border-radius: var(--ck-radius-panel, 20px);
  box-shadow: var(--ck-shadow);
  border: 1px solid var(--ck-border);
  background: var(--ck-body-bg, #fff);
  padding: 0;
  /* width/height are set inline from the shortcode atts */
}

.chatkit-embedded {
  width: 100%;
  height: 100%;
  display: block;
  padding: 0;
  margin: 0;
}

/* ------------------------------------------------------------------ */
/* Floating widget: [chatkit] / "show on all pages"                     */
/* ------------------------------------------------------------------ */

.chatkit-widget {
  --ck-adminbar: 0px;
  position: fixed;
  z-index: var(--ck-z, 9999);
  bottom: var(--ck-offset-y, 24px);
  right: var(--ck-offset-x, 24px);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  max-width: calc(100vw - var(--ck-offset-x, 24px) * 2);
  pointer-events: none;
}

.chatkit-widget > * {
  pointer-events: auto;
}

.chatkit-widget--left {
  right: auto;
  left: var(--ck-offset-x, 24px);
  align-items: flex-start;
}

body.admin-bar .chatkit-widget {
  --ck-adminbar: 32px;
}

/* Launcher ---------------------------------------------------------- */

.chatkit-launcher {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: var(--ck-launcher-size, 56px);
  min-width: var(--ck-launcher-size, 56px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: var(--ck-radius-launcher, 999px);
  background: var(--ck-launcher-bg);
  color: var(--ck-launcher-color);
  box-shadow: var(--ck-shadow-launcher);
  cursor: pointer;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background-color 0.2s ease;
}

.chatkit-widget--launcher-label .chatkit-launcher,
.chatkit-widget--launcher-icon-label .chatkit-launcher {
  padding: 0 22px 0 18px;
}

.chatkit-widget--launcher-label .chatkit-launcher {
  padding: 0 22px;
}

.chatkit-launcher:hover {
  background: var(--ck-launcher-bg-hover, var(--ck-launcher-bg));
  transform: translateY(-2px) scale(1.03);
  box-shadow: var(--ck-shadow-launcher), 0 0 0 6px var(--ck-accent-ring);
}

.chatkit-launcher:active {
  transform: scale(0.96);
  transition-duration: 0.08s;
}

.chatkit-launcher:focus {
  outline: none;
}

.chatkit-launcher:focus-visible {
  outline: 3px solid var(--ck-accent);
  outline-offset: 3px;
}

.chatkit-launcher__icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
}

.chatkit-launcher__icon-open,
.chatkit-launcher__icon-close {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.2s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chatkit-launcher__icon svg {
  width: 26px;
  height: 26px;
  display: block;
}

.chatkit-launcher__img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  border-radius: 50%;
  display: block;
}

.chatkit-launcher__icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.chatkit-widget--open .chatkit-launcher__icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.chatkit-widget--open .chatkit-launcher__icon-close {
  opacity: 1;
  transform: none;
}

.chatkit-launcher__label {
  display: inline-block;
}

/* Attention pulse until the first interaction */
.chatkit-launcher::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 var(--ck-launcher-bg);
  opacity: 0;
  pointer-events: none;
}

.chatkit-widget--pulse .chatkit-launcher::before {
  animation: chatkit-pulse 2.4s ease-out 1.2s 3;
}

@keyframes chatkit-pulse {
  0%   { opacity: 0.55; box-shadow: 0 0 0 0 var(--ck-launcher-bg); }
  70%  { opacity: 0;    box-shadow: 0 0 0 16px var(--ck-launcher-bg); }
  100% { opacity: 0;    box-shadow: 0 0 0 16px var(--ck-launcher-bg); }
}

/* Teaser bubble ----------------------------------------------------- */

.chatkit-teaser {
  position: relative;
  display: flex;
  align-items: flex-start;
  max-width: min(280px, calc(100vw - 48px));
  background: var(--ck-bot-bg, #fff);
  color: var(--ck-bot-color, #111);
  border: 1px solid var(--ck-border);
  border-radius: var(--ck-radius-msg, 14px);
  border-bottom-right-radius: 4px;
  box-shadow: var(--ck-shadow);
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

.chatkit-widget--left .chatkit-teaser {
  border-bottom-right-radius: var(--ck-radius-msg, 14px);
  border-bottom-left-radius: 4px;
  transform-origin: bottom left;
}

.chatkit-teaser.is-visible {
  opacity: 1;
  transform: none;
}

.chatkit-teaser[hidden] {
  display: none;
}

.chatkit-teaser__body {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  margin: 0;
  padding: 12px 8px 12px 16px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
}

.chatkit-teaser__close {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  margin: 6px 6px 0 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ck-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.chatkit-teaser__close svg {
  width: 14px;
  height: 14px;
}

.chatkit-teaser__close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--ck-bot-color);
}

.chatkit-teaser__body:focus-visible,
.chatkit-teaser__close:focus-visible {
  outline: 2px solid var(--ck-accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* Panel ------------------------------------------------------------- */

.chatkit-panel {
  width: min(var(--ck-panel-width, 400px), calc(100vw - var(--ck-offset-x, 24px) * 2));
  height: min(
    var(--ck-panel-height, 640px),
    calc(100vh - var(--ck-offset-y, 24px) - var(--ck-launcher-size, 56px) - 28px - var(--ck-adminbar))
  );
  height: min(
    var(--ck-panel-height, 640px),
    calc(100dvh - var(--ck-offset-y, 24px) - var(--ck-launcher-size, 56px) - 28px - var(--ck-adminbar))
  );
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--ck-body-bg, #fff);
  color: var(--ck-bot-color, #111);
  border: 1px solid var(--ck-border);
  border-radius: var(--ck-radius-panel, 20px);
  box-shadow: var(--ck-shadow);
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(16px) scale(0.94);
  transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform, opacity;
}

.chatkit-widget--left .chatkit-panel {
  transform-origin: bottom left;
}

.chatkit-panel.is-open {
  opacity: 1;
  transform: none;
}

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

/* Header */
.chatkit-panel__header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px 14px 18px;
  background: var(--ck-header-bg);
  color: var(--ck-header-color);
}

.chatkit-panel__avatar {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  overflow: visible;
}

.chatkit-panel__avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.chatkit-panel__avatar svg {
  width: 22px;
  height: 22px;
}

.chatkit-panel__status {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--ck-header-bg);
}

.chatkit-panel__titles {
  flex: 1 1 auto;
  min-width: 0;
}

.chatkit-panel__title,
.chatkit-panel__subtitle {
  margin: 0;
  font-family: inherit;
  color: inherit;
}

.chatkit-panel__title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatkit-panel__subtitle {
  margin-top: 2px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--ck-header-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chatkit-panel__btn {
  -webkit-appearance: none;
  appearance: none;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0.85;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.chatkit-panel__btn svg {
  width: 18px;
  height: 18px;
}

.chatkit-panel__btn:hover {
  background: var(--ck-header-hover);
  opacity: 1;
}

.chatkit-panel__btn:active {
  transform: scale(0.92);
}

.chatkit-panel__btn:focus-visible {
  outline: 2px solid var(--ck-header-color);
  outline-offset: 2px;
}

/* Body */
.chatkit-panel__body {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

.chatkit-panel__mount {
  position: absolute;
  inset: 0;
}

/* The panel draws its own header, so hide n8n's inside it. */
.chatkit-panel .chat-layout .chat-header {
  display: none;
}

.chatkit-panel__loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--ck-body-bg);
  transition: opacity 0.2s ease;
  z-index: 1;
}

.chatkit-panel--ready .chatkit-panel__loader {
  opacity: 0;
  pointer-events: none;
}

.chatkit-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--ck-border);
  border-top-color: var(--ck-accent);
  animation: chatkit-spin 0.8s linear infinite;
}

@keyframes chatkit-spin {
  to { transform: rotate(360deg); }
}

.chatkit-panel__error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--ck-muted);
  background: var(--ck-body-bg);
  z-index: 2;
}

/* Mobile: the panel takes the whole screen; the launcher steps aside. */
@media (max-width: 640px) {
  .chatkit-widget {
    bottom: 16px;
    right: 16px;
    max-width: calc(100vw - 32px);
  }

  .chatkit-widget--left {
    right: auto;
    left: 16px;
  }

  .chatkit-widget--open .chatkit-panel {
    position: fixed;
    inset: var(--ck-adminbar) 0 0 0;
    width: auto;
    height: auto;
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .chatkit-widget--open .chatkit-launcher,
  .chatkit-widget--open .chatkit-teaser {
    display: none;
  }

  .chatkit-widget--hide-mobile {
    display: none !important;
  }

  .chatkit-embedded-wrapper {
    width: 100% !important;
    max-width: 100% !important;
  }
}

@media screen and (max-width: 782px) {
  body.admin-bar .chatkit-widget {
    --ck-adminbar: 46px;
  }
}

html.chatkit-lock,
html.chatkit-lock body {
  overflow: hidden !important;
  overscroll-behavior: none;
}

/* ------------------------------------------------------------------ */
/* Accessibility / media                                                */
/* ------------------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
  .chatkit-launcher,
  .chatkit-launcher__icon-open,
  .chatkit-launcher__icon-close,
  .chatkit-teaser,
  .chatkit-panel,
  .chatkit-panel__btn {
    transition: none !important;
  }

  .chatkit-widget--pulse .chatkit-launcher::before,
  .chatkit-spinner {
    animation-duration: 0.01s !important;
    animation-iteration-count: 1 !important;
  }
}

@media (prefers-contrast: high) {
  .chatkit-launcher,
  .chatkit-panel,
  .chatkit-embedded-wrapper {
    border: 2px solid currentColor;
  }
}

@media print {
  .chatkit-widget,
  .chatkit-embedded-wrapper {
    display: none !important;
  }
}
