/* ==========================================================================
   n8n Chat Modal — widget styles
   Themed via CSS custom properties on .n8ncm-root (set inline by WordPress;
   the values below are standalone fallbacks).
   ========================================================================== */

.n8ncm-root {
  --n8ncm-primary: #b4151b;
  --n8ncm-ink: #1a1f36;
  --n8ncm-surface: #ffffff;
  --n8ncm-muted: #f6f8fb;
  --n8ncm-font: "Sora", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --n8ncm-w: 384px;
  --n8ncm-h: 600px;

  /* Derived (overridable by dark theme) */
  --n8ncm-text: var(--n8ncm-ink);
  --n8ncm-text-soft: color-mix(in srgb, var(--n8ncm-ink), transparent 48%);
  --n8ncm-border: color-mix(in srgb, var(--n8ncm-ink), transparent 90%);
  --n8ncm-primary-deep: color-mix(in srgb, var(--n8ncm-primary), #000 14%);
  --n8ncm-glow: color-mix(in srgb, var(--n8ncm-primary), transparent 72%);
  --n8ncm-link: var(--n8ncm-primary);

  font-family: var(--n8ncm-font);
  font-size: 16px;
  line-height: 1.5;
}

.n8ncm-root, .n8ncm-root * { box-sizing: border-box; }
.n8ncm-root button { font-family: inherit; }

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

.n8ncm-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 999990;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: var(--n8ncm-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px var(--n8ncm-glow), 0 2px 6px rgba(0, 0, 0, .18);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
}
.n8ncm-root[data-pos="left"] .n8ncm-launcher { left: 24px; right: auto; }

.n8ncm-launcher:hover {
  transform: translateY(-2px);
  background: var(--n8ncm-primary-deep);
  box-shadow: 0 8px 22px var(--n8ncm-glow), 0 3px 8px rgba(0, 0, 0, .2);
}
.n8ncm-launcher:focus-visible {
  outline: 2px solid var(--n8ncm-primary);
  outline-offset: 3px;
}

/* v1 button_text back-compat: labeled pill instead of bare disc */
.n8ncm-launcher.has-label {
  width: auto;
  padding: 0 22px 0 18px;
  gap: 9px;
}
.n8ncm-launcher-label { font-size: 15px; font-weight: 600; letter-spacing: .01em; }

/* Icon morph chat <-> close */
.n8ncm-launcher-icon {
  position: absolute;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .18s ease, transform .26s cubic-bezier(.34, 1.4, .64, 1);
}
.n8ncm-launcher.has-label .n8ncm-launcher-icon { position: static; width: 22px; height: 22px; }
.n8ncm-launcher-icon svg { width: 100%; height: 100%; }
.n8ncm-ic-close { opacity: 0; transform: rotate(-60deg) scale(.5); }
.n8ncm-root.is-open .n8ncm-ic-chat { opacity: 0; transform: rotate(60deg) scale(.5); }
.n8ncm-root.is-open .n8ncm-ic-close { opacity: 1; transform: rotate(0) scale(1); }
/* Labeled pill can't overlap icons — swap without rotation */
.n8ncm-launcher.has-label .n8ncm-ic-close { display: none; }
.n8ncm-root.is-open .n8ncm-launcher.has-label .n8ncm-ic-close { display: flex; opacity: 1; transform: none; }
.n8ncm-root.is-open .n8ncm-launcher.has-label .n8ncm-ic-chat { display: none; }

/* Unread badge */
.n8ncm-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #fff;
  color: var(--n8ncm-primary);
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

/* One-time attention pulse */
@keyframes n8ncm-pulse {
  0%   { box-shadow: 0 0 0 0 var(--n8ncm-glow); }
  70%  { box-shadow: 0 0 0 18px rgba(0, 0, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 0, 0, 0); }
}
.n8ncm-launcher.is-pulsing::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  animation: n8ncm-pulse 1.6s ease-out 2;
}

/* --------------------------------------------------------------------------
   Window
   -------------------------------------------------------------------------- */

.n8ncm-window {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 999991;
  width: min(var(--n8ncm-w), calc(100vw - 32px));
  height: min(var(--n8ncm-h), calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--n8ncm-surface);
  color: var(--n8ncm-text);
  border: 1px solid var(--n8ncm-border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(15, 18, 34, .28), 0 6px 18px rgba(15, 18, 34, .14);

  opacity: 0;
  transform: translateY(14px) scale(.96);
  transform-origin: bottom right;
  pointer-events: none;
  visibility: hidden;
  transition:
    transform .38s cubic-bezier(.34, 1.56, .64, 1),
    opacity .2s ease,
    visibility 0s linear .38s;
}
.n8ncm-root[data-pos="left"] .n8ncm-window { left: 24px; right: auto; transform-origin: bottom left; }

.n8ncm-root.is-open .n8ncm-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  visibility: visible;
  transition:
    transform .38s cubic-bezier(.34, 1.56, .64, 1),
    opacity .2s ease,
    visibility 0s;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.n8ncm-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 18px;
  background: var(--n8ncm-ink);
  color: #fff;
  flex: none;
}

.n8ncm-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: color-mix(in srgb, #fff, transparent 86%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
}
.n8ncm-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.n8ncm-avatar svg { width: 22px; height: 22px; }

.n8ncm-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--n8ncm-ink);
}

.n8ncm-heading { flex: 1; min-width: 0; }
.n8ncm-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.3;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.n8ncm-subtitle {
  margin: 1px 0 0;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255, 255, 255, .72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.n8ncm-actions { display: flex; gap: 2px; flex: none; }
.n8ncm-actions button {
  width: 34px;
  height: 34px;
  padding: 6px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, .78);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.n8ncm-actions button:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.n8ncm-actions button:focus-visible { outline: 2px solid #fff; outline-offset: -2px; }
.n8ncm-actions svg { width: 19px; height: 19px; }

/* --------------------------------------------------------------------------
   Messages
   -------------------------------------------------------------------------- */

.n8ncm-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.n8ncm-iframe { width: 100%; height: 100%; border: 0; display: block; flex: 1; }

.n8ncm-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.n8ncm-messages::-webkit-scrollbar { width: 6px; }
.n8ncm-messages::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--n8ncm-text), transparent 82%);
  border-radius: 3px;
}

@keyframes n8ncm-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.n8ncm-msg {
  display: flex;
  flex-direction: column;
  margin-top: 14px;
  animation: n8ncm-msg-in .22s ease both;
}
.n8ncm-msg.is-grouped { margin-top: 4px; }
.n8ncm-msg:first-child { margin-top: 0; }

.n8ncm-bubble {
  max-width: 84%;
  padding: 10px 14px;
  font-size: 14.5px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.n8ncm-msg.bot { align-items: flex-start; }
.n8ncm-msg.bot .n8ncm-bubble {
  background: var(--n8ncm-muted);
  color: var(--n8ncm-text);
  border-radius: 16px 16px 16px 6px;
}

.n8ncm-msg.user { align-items: flex-end; }
.n8ncm-msg.user .n8ncm-bubble {
  background: var(--n8ncm-primary);
  color: #fff;
  border-radius: 16px 16px 6px 16px;
}

/* Markdown inside bot bubbles */
.n8ncm-bubble a { color: var(--n8ncm-link); font-weight: 600; text-decoration: underline; }
.n8ncm-msg.user .n8ncm-bubble a { color: #fff; }
.n8ncm-bubble code {
  font-family: ui-monospace, Consolas, Monaco, monospace;
  font-size: .88em;
  padding: 1px 5px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--n8ncm-text), transparent 90%);
}
.n8ncm-bubble ul { margin: 4px 0; padding-left: 20px; white-space: normal; }
.n8ncm-bubble li { margin: 2px 0; }

/* Timestamp — shown on the last message of a group */
.n8ncm-time {
  font-size: 11px;
  color: var(--n8ncm-text-soft);
  margin: 4px 6px 0;
  display: none;
}
.n8ncm-msg.show-time .n8ncm-time { display: block; }

/* Typing indicator */
.n8ncm-typing .n8ncm-bubble {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding: 13px 16px;
}
@keyframes n8ncm-bounce {
  0%, 70%, 100% { transform: translateY(0); opacity: .45; }
  35% { transform: translateY(-4px); opacity: 1; }
}
.n8ncm-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--n8ncm-text-soft);
  animation: n8ncm-bounce 1.1s infinite ease-in-out;
}
.n8ncm-typing i:nth-child(2) { animation-delay: .14s; }
.n8ncm-typing i:nth-child(3) { animation-delay: .28s; }

/* --------------------------------------------------------------------------
   Quick replies
   -------------------------------------------------------------------------- */

.n8ncm-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 16px 12px;
  flex: none;
}
.n8ncm-quick button {
  padding: 7px 14px;
  border: 1.5px solid var(--n8ncm-primary);
  border-radius: 999px;
  background: transparent;
  color: var(--n8ncm-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.n8ncm-quick button:hover {
  background: var(--n8ncm-primary);
  color: #fff;
  transform: translateY(-1px);
}

/* --------------------------------------------------------------------------
   Composer
   -------------------------------------------------------------------------- */

.n8ncm-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 12px 12px 16px;
  border-top: 1px solid var(--n8ncm-border);
  background: var(--n8ncm-surface);
  flex: none;
}

.n8ncm-input {
  flex: 1;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--n8ncm-text);
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.45;
  max-height: 96px;
  padding: 8px 0;
  outline: none;
}
.n8ncm-input::placeholder { color: var(--n8ncm-text-soft); }

.n8ncm-send {
  width: 38px;
  height: 38px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: var(--n8ncm-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.n8ncm-send svg { width: 17px; height: 17px; margin: 1px 1px 0 0; }
.n8ncm-send:hover:not(:disabled) { background: var(--n8ncm-primary-deep); transform: scale(1.06); }
.n8ncm-send:disabled { opacity: .35; cursor: default; }
.n8ncm-send:focus-visible { outline: 2px solid var(--n8ncm-primary); outline-offset: 2px; }

/* --------------------------------------------------------------------------
   Mobile: full-height sheet
   -------------------------------------------------------------------------- */

@media (max-width: 520px) {
  .n8ncm-window,
  .n8ncm-root[data-pos="left"] .n8ncm-window {
    left: 0;
    right: 0;
    bottom: 0;
    top: 12px;
    width: 100%;
    height: auto;
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    transform: translateY(24px);
    transform-origin: bottom center;
  }
  .n8ncm-root.is-open .n8ncm-window { transform: translateY(0); }
  .n8ncm-launcher,
  .n8ncm-root[data-pos="left"] .n8ncm-launcher { right: 16px; bottom: 16px; }
  .n8ncm-root[data-pos="left"] .n8ncm-launcher { left: 16px; right: auto; }
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .n8ncm-window,
  .n8ncm-root.is-open .n8ncm-window { transition: opacity .15s ease, visibility 0s; transform: none; }
  .n8ncm-msg { animation: none; }
  .n8ncm-launcher, .n8ncm-launcher-icon, .n8ncm-send, .n8ncm-quick button { transition: none; }
  .n8ncm-launcher.is-pulsing::before { animation: none; }
  .n8ncm-typing i { animation-duration: 1.6s; }
}
