/* ══════════════════════════════════════
   n8n CHATBOX PLUGIN — STYLES
   Version: 1.0.0
   ══════════════════════════════════════ */

/* ── CSS Custom Properties (set by JS from admin config) ── */
:root {
  --n8n-primary: #4F46E5;
  --n8n-primary-dark: #4338CA;
  --n8n-primary-light: #6366F1;
  --n8n-primary-glow: rgba(79, 70, 229, 0.45);
  --n8n-primary-soft: rgba(99, 102, 241, 0.12);
  --n8n-bg-chat: #F3F4F6;
  --n8n-bg-bubble-bot: #ffffff;
  --n8n-text-dark: #1F2937;
  --n8n-text-muted: #9CA3AF;
  --n8n-border: #E5E7EB;
}

/* ══════════════════════════════════════
   CONTAINER
   ══════════════════════════════════════ */
#n8n-chatbox-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  direction: ltr;
}

#n8n-chatbox-container.n8n-pos-bottom-left {
  right: auto;
  left: 24px;
}

/* ══════════════════════════════════════
   TOGGLE BUTTON
   ══════════════════════════════════════ */
#n8n-chat-toggle {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--n8n-primary-light), var(--n8n-primary));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px var(--n8n-primary-glow);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  position: absolute;
  bottom: 0;
  right: 0;
  padding: 0;
}

.n8n-pos-bottom-left #n8n-chat-toggle {
  right: auto;
  left: 0;
}

#n8n-chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(79, 70, 229, 0.55);
}

#n8n-chat-toggle svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Notification dot */
#n8n-chat-toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #EF4444;
  border-radius: 50%;
  border: 2.5px solid white;
  animation: n8n-pulse 2s infinite;
}

#n8n-chat-toggle.n8n-opened::after {
  display: none;
}

@keyframes n8n-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.2); opacity: 0.7; }
}

/* ══════════════════════════════════════
   CHAT WINDOW
   ══════════════════════════════════════ */
#n8n-chat-window {
  display: none;
  flex-direction: column;
  width: 400px;
  height: 560px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  position: absolute;
  bottom: 80px;
  right: 0;
  animation: n8n-window-in 0.3s ease;
}

.n8n-pos-bottom-left #n8n-chat-window {
  right: auto;
  left: 0;
}

@keyframes n8n-window-in {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ══════════════════════════════════════
   HEADER
   ══════════════════════════════════════ */
#n8n-chat-header {
  background: linear-gradient(135deg, var(--n8n-primary-light), var(--n8n-primary));
  color: white;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.n8n-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.n8n-chat-avatar {
  font-size: 22px;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.n8n-chat-title {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.n8n-chat-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.n8n-chat-status::before {
  content: "";
  width: 8px;
  height: 8px;
  background: #34D399;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.6);
}

#n8n-chat-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  line-height: 1;
  padding: 0;
}

#n8n-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ══════════════════════════════════════
   MESSAGES AREA
   ══════════════════════════════════════ */
#n8n-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  background: var(--n8n-bg-chat);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ── Message Row ── */
.n8n-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  animation: n8n-msg-in 0.35s ease;
}

.n8n-msg-row-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.n8n-msg-row-bot {
  align-self: flex-start;
}

.n8n-msg-row-user + .n8n-msg-row-bot,
.n8n-msg-row-bot + .n8n-msg-row-user {
  margin-top: 16px;
}

.n8n-msg-row-user + .n8n-msg-row-user,
.n8n-msg-row-bot + .n8n-msg-row-bot {
  margin-top: 3px;
}

/* ── Mini Avatar ── */
.n8n-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--n8n-primary);
  color: white;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.n8n-msg-row-bot + .n8n-msg-row-bot .n8n-msg-avatar {
  visibility: hidden;
}

.n8n-msg-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

/* ── Bubbles ── */
.n8n-chat-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.55;
  font-size: 14px;
}

.n8n-chat-user {
  background: var(--n8n-primary);
  color: #ffffff;
  border-bottom-right-radius: 6px;
}

.n8n-msg-row-user + .n8n-msg-row-user .n8n-chat-user {
  border-top-right-radius: 6px;
}

.n8n-chat-bot {
  background: var(--n8n-bg-bubble-bot);
  color: var(--n8n-text-dark);
  border: 1px solid var(--n8n-border);
  border-bottom-left-radius: 6px;
}

.n8n-msg-row-bot + .n8n-msg-row-bot .n8n-chat-bot {
  border-top-left-radius: 6px;
}

/* ── Timestamp ── */
.n8n-msg-time {
  font-size: 11px;
  color: var(--n8n-text-muted);
  padding: 0 4px;
  margin-top: 2px;
}

.n8n-msg-row-user .n8n-msg-time { text-align: right; }
.n8n-msg-row-bot .n8n-msg-time { text-align: left; }

.n8n-msg-row-user + .n8n-msg-row-user .n8n-msg-time,
.n8n-msg-row-bot + .n8n-msg-row-bot .n8n-msg-time {
  display: none;
}

@keyframes n8n-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════
   RICH MARKDOWN INSIDE BOT BUBBLES
   ══════════════════════════════════════ */

/* ── Paragraphs ── */
.n8n-chat-bot p {
  margin: 0 0 12px 0;
  line-height: 1.65;
}

.n8n-chat-bot p:last-child {
  margin-bottom: 0;
}

/* ── Bold ── */
.n8n-chat-bot strong {
  color: var(--n8n-primary);
  font-weight: 700;
}

/* ── Italic ── */
.n8n-chat-bot em {
  font-style: italic;
  color: #6B7280;
}

/* ── Unordered Lists ── */
.n8n-chat-bot ul {
  margin: 10px 0 14px 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.n8n-chat-bot ul li {
  position: relative;
  padding: 10px 12px 10px 32px;
  background: #F8F9FB;
  border-radius: 12px;
  border-left: 3px solid var(--n8n-primary);
  line-height: 1.6;
  font-size: 13.5px;
}

.n8n-chat-bot ul li::before {
  content: "🔹";
  position: absolute;
  left: 8px;
  top: 10px;
  font-size: 12px;
}

/* ── Ordered Lists ── */
.n8n-chat-bot ol {
  margin: 10px 0 14px 0;
  padding: 0;
  list-style: none;
  counter-reset: step-counter;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.n8n-chat-bot ol li {
  position: relative;
  padding: 10px 12px 10px 40px;
  background: #F8F9FB;
  border-radius: 12px;
  border-left: 3px solid var(--n8n-primary);
  line-height: 1.6;
  font-size: 13.5px;
  counter-increment: step-counter;
}

.n8n-chat-bot ol li::before {
  content: counter(step-counter);
  position: absolute;
  left: 10px;
  top: 10px;
  width: 22px;
  height: 22px;
  background: var(--n8n-primary);
  color: white;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Bold inside list items (product names / prices) ── */
.n8n-chat-bot li strong {
  color: #312E81;
  font-weight: 700;
}

.n8n-chat-bot li strong:last-of-type {
  color: #059669;
}

/* ── Headings ── */
.n8n-chat-bot h1,
.n8n-chat-bot h2,
.n8n-chat-bot h3,
.n8n-chat-bot h4 {
  margin: 16px 0 8px 0;
  color: #312E81;
  line-height: 1.3;
  font-weight: 700;
}

.n8n-chat-bot h1 { font-size: 16px; }
.n8n-chat-bot h2 { font-size: 15px; }
.n8n-chat-bot h3 { font-size: 14.5px; }
.n8n-chat-bot h4 { font-size: 14px; }

.n8n-chat-bot h1:first-child,
.n8n-chat-bot h2:first-child,
.n8n-chat-bot h3:first-child {
  margin-top: 0;
}

/* ── Horizontal Rule ── */
.n8n-chat-bot hr {
  border: none;
  height: 1px;
  background: var(--n8n-border);
  margin: 14px 0;
}

/* ── Inline Code ── */
.n8n-chat-bot code {
  background: rgba(99, 102, 241, 0.1);
  color: #4338CA;
  padding: 2px 7px;
  border-radius: 5px;
  font-family: "SF Mono", Monaco, Consolas, "Courier New", monospace;
  font-size: 12.5px;
}

/* ── Code Block ── */
.n8n-chat-bot pre {
  background: #1F2937;
  color: #E5E7EB;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 12.5px;
  line-height: 1.5;
}

.n8n-chat-bot pre code {
  background: none;
  color: inherit;
  padding: 0;
}

/* ── Blockquote ── */
.n8n-chat-bot blockquote {
  margin: 12px 0;
  padding: 10px 14px;
  background: linear-gradient(135deg, #EEF2FF, #E0E7FF);
  border-left: 4px solid var(--n8n-primary);
  border-radius: 0 12px 12px 0;
  color: #3730A3;
  font-size: 13.5px;
}

.n8n-chat-bot blockquote p { margin: 0; }

/* ── Links ── */
.n8n-chat-bot a {
  color: var(--n8n-primary);
  text-decoration: underline;
  text-decoration-color: rgba(79, 70, 229, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.2s;
}

.n8n-chat-bot a:hover {
  text-decoration-color: var(--n8n-primary);
}

/* ── Table ── */
.n8n-chat-bot table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  border-radius: 8px;
  overflow: hidden;
}

.n8n-chat-bot th,
.n8n-chat-bot td {
  padding: 8px 10px;
  border: 1px solid var(--n8n-border);
  text-align: left;
}

.n8n-chat-bot th {
  background: #EEF2FF;
  font-weight: 700;
  color: #312E81;
}

/* ══════════════════════════════════════
   CALLOUT BOXES (auto-detected)
   ══════════════════════════════════════ */

/* Important callout */
.n8n-callout-important {
  background: #FEF3C7 !important;
  border-left: 4px solid #F59E0B !important;
  padding: 12px 14px !important;
  border-radius: 0 12px 12px 0 !important;
  margin: 12px 0 !important;
  font-size: 13.5px !important;
  color: #92400E !important;
  display: block !important;
}

.n8n-callout-important strong {
  color: #B45309 !important;
}

/* Tip callout */
.n8n-callout-tip {
  background: #D1FAE5 !important;
  border-left: 4px solid #10B981 !important;
  padding: 12px 14px !important;
  border-radius: 0 12px 12px 0 !important;
  margin: 12px 0 !important;
  font-size: 13.5px !important;
  color: #065F46 !important;
  display: block !important;
}

.n8n-callout-tip strong {
  color: #047857 !important;
}

/* ══════════════════════════════════════
   TYPING INDICATOR
   ══════════════════════════════════════ */
#n8n-chat-typing {
  display: none;
  padding: 8px 16px 12px;
  background: var(--n8n-bg-chat);
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.n8n-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 18px;
  background: white;
  border: 1px solid var(--n8n-border);
  border-radius: 18px;
  width: fit-content;
}

.n8n-typing-indicator span {
  width: 8px;
  height: 8px;
  background: #B0B5C0;
  border-radius: 50%;
  animation: n8n-bounce 1.4s infinite ease-in-out;
}

.n8n-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.n8n-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes n8n-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-7px); }
}

/* ══════════════════════════════════════
   INPUT FORM
   ══════════════════════════════════════ */
#n8n-chat-form {
  display: flex;
  padding: 12px 14px;
  border-top: 1px solid var(--n8n-border);
  background: #ffffff;
  gap: 10px;
  flex-shrink: 0;
  align-items: center;
}

#n8n-chat-input {
  flex: 1;
  border: 1.5px solid #D1D5DB;
  border-radius: 24px;
  padding: 10px 18px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  background: #F9FAFB;
  -webkit-appearance: none;
}

#n8n-chat-input:focus {
  border-color: var(--n8n-primary);
  box-shadow: 0 0 0 3px var(--n8n-primary-soft);
  background: #fff;
}

#n8n-chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--n8n-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  flex-shrink: 0;
  padding: 0;
}

#n8n-chat-send:hover {
  background: var(--n8n-primary-dark);
  transform: scale(1.05);
}

#n8n-chat-send:active {
  transform: scale(0.95);
}

#n8n-chat-send svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: white;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ══════════════════════════════════════
   SCROLLBAR
   ══════════════════════════════════════ */
#n8n-chat-messages::-webkit-scrollbar { width: 5px; }
#n8n-chat-messages::-webkit-scrollbar-track { background: transparent; }
#n8n-chat-messages::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 10px; }
#n8n-chat-messages::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ══════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════ */
@media (max-width: 480px) {
  #n8n-chatbox-container {
    bottom: 12px;
    right: 12px;
  }

  #n8n-chatbox-container.n8n-pos-bottom-left {
    left: 12px;
  }

  #n8n-chat-window {
    width: calc(100vw - 24px);
    height: 80vh;
    right: -6px;
    bottom: 76px;
    border-radius: 16px;
  }

  .n8n-pos-bottom-left #n8n-chat-window {
    left: -6px;
    right: auto;
  }

  .n8n-msg-row {
    max-width: 92%;
  }
}