/*
 * ═══════════════════════════════════════════════════════════════
 *  LATYNEX AI SALES MANAGER WIDGET  —  ai-widget.css  v2.0
 *  Reusable standalone widget. Drop into any HTML website.
 *  No build process. No dependencies. No framework required.
 *
 *  Brand: Latynex AI Agency
 *  Logo:  Gold geometric LT mark + "Latynex AI" wordmark
 *
 *  Installation:
 *    <link rel="stylesheet" href="ai-widget.css">
 *    <script src="ai-widget.js"></script>
 *
 *  All selectors are namespaced with .lx- to avoid conflicts
 *  with any host website's existing styles.
 * ═══════════════════════════════════════════════════════════════
 */

/* ─────────────────────────────────────────────────────────────
   DESIGN TOKENS
   Edit these variables to retheme the widget for any client.
───────────────────────────────────────────────────────────── */
:root {
  --lx-bg:            #0B1020;
  --lx-bg-surface:    #111827;
  --lx-bg-elevated:   #1A2236;
  --lx-bg-hover:      #1E2A40;
  --lx-border:        #1F2D45;
  --lx-border-hover:  #2E3F5C;
  --lx-cta:           #4F7BFF;
  --lx-cta-hover:     #3D6AEE;
  --lx-cta-dim:       #1A2952;
  --lx-accent:        #4F7BFF;
  --lx-accent-dim:    #2A2210;
  --lx-text:          #F0F4FF;
  --lx-text-muted:    #8899BB;
  --lx-text-dim:      #4A5F82;
  --lx-bubble-user:   #4F7BFF;
  --lx-bubble-ai:     #1A2236;
  --lx-hot:           #FF4D4D;
  --lx-warm:          #4F7BFF;
  --lx-cold:          #4F7BFF;
  --lx-w:             448px;
  --lx-h:             580px;
  --lx-r-lg:          16px;
  --lx-r-md:          10px;
  --lx-r-sm:          8px;
  --lx-font:          -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Helvetica, Arial, sans-serif;
  --lx-z:             2147483647; /* max z-index — stays above everything */
}

/* ─────────────────────────────────────────────────────────────
   KEYFRAMES
───────────────────────────────────────────────────────────── */
@keyframes lx-bounce {
  0%, 80%, 100% { transform: translateY(0);    opacity: 0.35; }
  40%            { transform: translateY(-5px); opacity: 1;    }
}
@keyframes lx-fadeup {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0);    }
}
@keyframes lx-pop {
  0%   { transform: scale(0.82); opacity: 0; }
  65%  { transform: scale(1.04);              }
  100% { transform: scale(1);    opacity: 1; }
}
@keyframes lx-pulse {
  0%, 100% { opacity: 1;    transform: scale(1);    }
  50%       { opacity: 0.55; transform: scale(0.85); }
}
@keyframes lx-slideup {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)     scale(1);   }
}
@keyframes lx-spin {
  to { transform: rotate(360deg); }
}

/* ─────────────────────────────────────────────────────────────
   WIDGET ROOT  —  fixed bottom-right, always on top
───────────────────────────────────────────────────────────── */
#lx-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--lx-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: var(--lx-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─────────────────────────────────────────────────────────────
   LAUNCHER BUTTON
───────────────────────────────────────────────────────────── */
#lx-launcher {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 18px 10px 11px;
  background: var(--lx-bg);
  border: 1px solid var(--lx-border);
  border-radius: 999px;
  box-shadow: 0 8px 32px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.3);
  cursor: pointer;
  animation: lx-pop 0.32s ease-out both;
  transition: box-shadow 0.2s, transform 0.15s, border-color 0.15s;
  font-family: var(--lx-font);
  outline: none;
}
#lx-launcher:hover {
  box-shadow: 0 14px 44px rgba(0,0,0,.65);
  transform: translateY(-2px);
  border-color: var(--lx-border-hover);
}
#lx-launcher:focus-visible {
  outline: 2px solid var(--lx-cta);
  outline-offset: 2px;
}

/* ─────────────────────────────────────────────────────────────
   LOGO MARK  —  SVG-based gold geometric LT
───────────────────────────────────────────────────────────── */
.lx-logo-mark {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  position: relative;
}
.lx-logo-mark svg {
  width: 100%;
  height: 100%;
}

/* Status dot on launcher */
.lx-status-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--lx-cta);
  border: 2px solid var(--lx-bg);
  animation: lx-pulse 2.5s ease infinite;
}

.lx-launcher-info {
  display: flex;
  flex-direction: column;
}
.lx-launcher-name {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--lx-text);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.lx-launcher-status {
  font-size: 11px;
  color: var(--lx-cta);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.lx-pulse-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lx-cta);
  display: inline-block;
  flex-shrink: 0;
  animation: lx-pulse 2.5s ease infinite;
}

/* Unread badge */
#lx-unread-badge {
  display: none;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--lx-accent);
  color: #0B1020;
  font-size: 10px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#lx-unread-badge.visible {
  display: flex;
}

/* ─────────────────────────────────────────────────────────────
   CHAT WINDOW
───────────────────────────────────────────────────────────── */
#lx-chat {
  display: none;
  width: var(--lx-w);
  max-width: calc(100vw - 28px);
  height: var(--lx-h);
  max-height: calc(100dvh - 108px);
  background: var(--lx-bg);
  border-radius: var(--lx-r-lg);
  box-shadow: 0 32px 80px rgba(0,0,0,.65), 0 8px 24px rgba(0,0,0,.4);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--lx-border);
  animation: lx-slideup 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}
#lx-chat.lx-open {
  display: flex;
}

/* ── Header ── */
#lx-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 15px;
  background: var(--lx-bg-surface);
  border-bottom: 1px solid var(--lx-border);
  flex-shrink: 0;
}
.lx-header-left  { display: flex; align-items: center; gap: 11px; }
.lx-header-right { display: flex; align-items: center; gap: 11px; }

.lx-header-logo {
  position: relative;
  flex-shrink: 0;
}
.lx-header-logo .lx-logo-mark {
  width: 38px;
  height: 38px;
}
.lx-header-logo .lx-status-dot {
  border-color: var(--lx-bg-surface);
}

.lx-header-name {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--lx-text);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
.lx-header-role {
  font-size: 11.5px;
  color: var(--lx-text-muted);
  margin-top: 2px;
}

.lx-header-meta { text-align: right; }
.lx-header-avail {
  font-size: 11px;
  color: var(--lx-cta);
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
}
.lx-header-reply {
  font-size: 10px;
  color: var(--lx-text-dim);
  margin-top: 2px;
}

/* Lead quality badge in header */
#lx-lead-badge {
  display: none;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
#lx-lead-badge.hot  { display: inline-flex; background: rgba(255,77,77,.15);  color: var(--lx-hot);    border: 1px solid rgba(255,77,77,.3);  }
#lx-lead-badge.warm { display: inline-flex; background: rgba(212,175,55,.12); color: var(--lx-warm);   border: 1px solid rgba(212,175,55,.3); }
#lx-lead-badge.cold { display: inline-flex; background: rgba(79,123,255,.12); color: var(--lx-cold);   border: 1px solid rgba(79,123,255,.3); }

#lx-close-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--lx-r-sm);
  background: transparent;
  border: 1px solid var(--lx-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--lx-text-muted);
  font-size: 17px;
  font-family: var(--lx-font);
  transition: all 0.15s;
  flex-shrink: 0;
}
#lx-close-btn:hover {
  background: var(--lx-bg-elevated);
  color: var(--lx-text);
  border-color: var(--lx-border-hover);
}
#lx-close-btn:focus-visible {
  outline: 2px solid var(--lx-cta);
  outline-offset: 2px;
}

/* ── Messages pane ── */
#lx-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 15px 0;
  display: flex;
  flex-direction: column;
  background: var(--lx-bg-surface);
  scrollbar-width: thin;
  scrollbar-color: var(--lx-border) transparent;
}
#lx-messages::-webkit-scrollbar       { width: 3px; }
#lx-messages::-webkit-scrollbar-track { background: transparent; }
#lx-messages::-webkit-scrollbar-thumb { background: var(--lx-border); border-radius: 9px; }

/* ── Message rows ── */
.lx-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 10px;
  animation: lx-fadeup 0.22s ease-out both;
}
.lx-msg-row.lx-user { justify-content: flex-end; }

/* Inline AI logo in messages */
.lx-msg-logo {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  margin-top: 2px;
}
.lx-msg-logo svg { width: 100%; height: 100%; }

/* Bubbles */
.lx-bubble {
  max-width: 76%;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
}
.lx-bubble.lx-ai {
  border-radius: 3px 14px 14px 14px;
  background: var(--lx-bubble-ai);
  color: var(--lx-text);
  border: 1px solid var(--lx-border);
}
.lx-bubble.lx-user {
  border-radius: 14px 3px 14px 14px;
  background: var(--lx-bubble-user);
  color: #fff;
}
.lx-bubble strong { font-weight: 600; }
.lx-bubble a { color: var(--lx-cta); }

/* Timestamp */
.lx-msg-time {
  font-size: 10px;
  color: var(--lx-text-dim);
  margin-top: 3px;
  padding: 0 2px;
}
.lx-msg-row.lx-user .lx-msg-time { text-align: right; }

/* ── Quick action buttons ── */
#lx-quick-actions {
  margin-top: 4px;
  margin-bottom: 6px;
  animation: lx-fadeup 0.3s 0.08s ease-out both;
}
.lx-qa-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  background: var(--lx-bg-elevated);
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-r-md);
  cursor: pointer;
  text-align: left;
  margin-bottom: 6px;
  transition: all 0.15s ease;
  font-family: var(--lx-font);
  color: var(--lx-text);
  outline: none;
}
.lx-qa-btn:last-child { margin-bottom: 0; }
.lx-qa-btn:hover {
  background: var(--lx-bg-hover);
  border-color: var(--lx-border-hover);
}
.lx-qa-btn:focus-visible {
  outline: 2px solid var(--lx-cta);
  outline-offset: 2px;
}
.lx-qa-icon  {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
  width: 24px;
  text-align: center;
}
.lx-qa-text  { flex: 1; }
.lx-qa-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--lx-text);
  line-height: 1.3;
}
.lx-qa-desc  {
  font-size: 11.5px;
  color: var(--lx-text-muted);
  margin-top: 2px;
}
.lx-qa-arrow {
  color: var(--lx-text-dim);
  font-size: 15px;
  flex-shrink: 0;
  transition: color 0.15s, transform 0.15s;
}
.lx-qa-btn:hover .lx-qa-arrow {
  color: var(--lx-cta);
  transform: translateX(2px);
}

/* ── Typing indicator ── */
#lx-typing {
  display: none;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 10px;
}
#lx-typing.lx-visible { display: flex; }
.lx-typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 14px;
  background: var(--lx-bubble-ai);
  border: 1px solid var(--lx-border);
  border-radius: 3px 14px 14px 14px;
}
.lx-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--lx-text-dim);
  animation: lx-bounce 1.3s ease-in-out infinite;
}
.lx-dot:nth-child(2) { animation-delay: 0.18s; }
.lx-dot:nth-child(3) { animation-delay: 0.36s; }

/* ── Lead capture form ── */
#lx-lead-form {
  background: var(--lx-bg-elevated);
  border: 1px solid var(--lx-border);
  border-radius: 12px;
  padding: 16px 15px 14px;
  margin-bottom: 8px;
  animation: lx-fadeup 0.22s ease-out both;
}
.lx-form-section-label {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--lx-accent);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* Contact method selector */
.lx-methods {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}
.lx-method-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex: 1;
  padding: 9px 4px;
  background: var(--lx-bg-surface);
  border: 1.5px solid var(--lx-border);
  border-radius: 9px;
  cursor: pointer;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--lx-text-muted);
  font-family: var(--lx-font);
  transition: all 0.15s;
  outline: none;
}
.lx-method-btn:hover { border-color: var(--lx-border-hover); }
.lx-method-btn.lx-selected {
  border-color: var(--lx-cta);
  background: var(--lx-cta-dim);
  color: var(--lx-cta);
}
.lx-method-btn:focus-visible { outline: 2px solid var(--lx-cta); outline-offset: 2px; }
.lx-method-icon { font-size: 18px; line-height: 1; }

/* Form inputs */
.lx-field {
  width: 100%;
  padding: 9px 12px;
  background: var(--lx-bg-surface);
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-r-sm);
  font-size: 13px;
  color: var(--lx-text);
  font-family: var(--lx-font);
  outline: none;
  transition: border-color 0.15s;
  display: block;
  margin-bottom: 7px;
}
.lx-field:focus          { border-color: var(--lx-cta); }
.lx-field::placeholder   { color: var(--lx-text-dim); }
.lx-field:disabled       { opacity: 0.45; cursor: not-allowed; }

/* Submit button */
.lx-submit-btn {
  width: 100%;
  padding: 11px 0;
  background: var(--lx-bg-surface);
  color: var(--lx-text-dim);
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-r-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: not-allowed;
  font-family: var(--lx-font);
  transition: all 0.15s;
  letter-spacing: 0.01em;
}
.lx-submit-btn.lx-ready {
  background: var(--lx-cta);
  color: #fff;
  border-color: var(--lx-cta);
  cursor: pointer;
}
.lx-submit-btn.lx-ready:hover  { background: var(--lx-cta-hover); }
.lx-submit-btn.lx-ready:active { transform: scale(0.98); }
.lx-submit-btn:focus-visible { outline: 2px solid var(--lx-cta); outline-offset: 2px; }

/* Loading spinner inside submit */
.lx-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lx-spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

.lx-form-note {
  font-size: 10.5px;
  color: var(--lx-text-dim);
  text-align: center;
  margin-top: 9px;
}

/* ── Scroll anchor spacer ── */
.lx-anchor { height: 16px; flex-shrink: 0; }

/* ── Input area ── */
#lx-input-area {
  border-top: 1px solid var(--lx-border);
  padding: 11px 13px;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  background: var(--lx-bg);
  flex-shrink: 0;
}
#lx-textbox {
  flex: 1;
  border: 1px solid var(--lx-border);
  border-radius: var(--lx-r-md);
  padding: 10px 13px;
  font-size: 13.5px;
  outline: none;
  resize: none;
  line-height: 1.5;
  font-family: var(--lx-font);
  color: var(--lx-text);
  background: var(--lx-bg-elevated);
  max-height: 88px;
  overflow-y: auto;
  transition: border-color 0.15s;
  scrollbar-width: thin;
}
#lx-textbox:focus       { border-color: var(--lx-cta); }
#lx-textbox::placeholder { color: var(--lx-text-dim); }
#lx-textbox:disabled    { opacity: 0.45; cursor: not-allowed; }

#lx-send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--lx-r-sm);
  background: var(--lx-bg-elevated);
  border: 1px solid var(--lx-border);
  cursor: not-allowed;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  outline: none;
}
#lx-send-btn.lx-active {
  background: var(--lx-cta);
  border-color: var(--lx-cta);
  cursor: pointer;
}
#lx-send-btn.lx-active:hover  { background: var(--lx-cta-hover); }
#lx-send-btn.lx-active:active { transform: scale(0.91); }
#lx-send-btn:focus-visible    { outline: 2px solid var(--lx-cta); }

/* ── Footer ── */
#lx-footer {
  padding: 5px 14px 8px;
  text-align: center;
  background: var(--lx-bg);
  border-top: 1px solid var(--lx-border);
  flex-shrink: 0;
  font-size: 10px;
  color: var(--lx-text-dim);
}
#lx-footer a {
  color: var(--lx-accent);
  text-decoration: none;
  font-weight: 500;
}
#lx-footer a:hover { text-decoration: underline; }

/* ─────────────────────────────────────────────────────────────
   MOBILE  —  full-screen below 520px
───────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  #lx-widget {
    bottom: 0;
    right: 0;
    gap: 0;
  }
  #lx-launcher {
    position: fixed;
    bottom: 18px;
    right: 16px;
  }
  #lx-chat {
    --lx-r-lg: 0px;
    width:      100vw;
    max-width:  100vw;
    height:     100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border-left:   none;
    border-right:  none;
    border-bottom: none;
  }
}

/* ─────────────────────────────────────────────────────────────
   REDUCED MOTION
───────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  #lx-launcher,
  #lx-chat,
  .lx-msg-row,
  #lx-quick-actions,
  #lx-lead-form {
    animation: none !important;
    transition: none !important;
  }
}
