/* ==========================================================================
   AJ Associates — Smart Chat Assistant widget
   Uses brand tokens from premium-theme.css with safe fallbacks.
   ========================================================================== */

.ajc-root {
  --ajc-red: var(--color-primary-red, #ED1018);
  --ajc-red-dark: var(--color-red-hover, #C90B14);
  --ajc-red-soft: var(--color-light-red, #FFF1F2);
  --ajc-ink: var(--color-corporate-black, #111111);
  --ajc-body: var(--color-body-gray, #52525B);
  --ajc-muted: var(--color-muted-gray, #71717A);
  --ajc-line: var(--color-border-gray, #E5E7EB);
  --ajc-bg: #FFFFFF;
  --ajc-bg-soft: #F7F7F9;
  --ajc-radius: 18px;
  --ajc-font: var(--font-body, 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
  --ajc-font-head: var(--font-heading, 'Manrope', var(--ajc-font));
  font-family: var(--ajc-font);
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1100;
  -webkit-font-smoothing: antialiased;
}

.ajc-root *,
.ajc-root *::before,
.ajc-root *::after {
  box-sizing: border-box;
}

/* ---------- Launcher ---------- */
.ajc-launcher {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  background: linear-gradient(145deg, var(--ajc-red), var(--ajc-red-dark));
  color: #fff;
  box-shadow: 0 10px 28px rgba(237, 16, 24, 0.38), 0 4px 10px rgba(17, 17, 17, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ajc-launcher:hover { transform: translateY(-2px) scale(1.04); }
.ajc-launcher:focus-visible { outline: 3px solid rgba(237, 16, 24, 0.35); outline-offset: 3px; }
.ajc-launcher svg { width: 28px; height: 28px; transition: transform 0.25s ease, opacity 0.2s ease; }
.ajc-launcher .ajc-icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.ajc-root.is-open .ajc-launcher .ajc-icon-chat { opacity: 0; transform: rotate(90deg); }
.ajc-root.is-open .ajc-launcher .ajc-icon-close { opacity: 1; transform: rotate(0); }

.ajc-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--ajc-red);
  animation: ajc-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
.ajc-root.is-open .ajc-launcher::after,
.ajc-root.has-opened .ajc-launcher::after { display: none; }

@keyframes ajc-pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}

.ajc-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--ajc-ink);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
}
.ajc-root.is-open .ajc-badge { display: none; }

/* ---------- Teaser bubble ---------- */
.ajc-teaser {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 260px;
  background: var(--ajc-bg);
  color: var(--ajc-ink);
  border: 1px solid var(--ajc-line);
  border-radius: 16px 16px 4px 16px;
  padding: 14px 34px 14px 16px;
  font-size: 14px;
  line-height: 1.45;
  box-shadow: 0 12px 32px rgba(17, 17, 17, 0.14);
  cursor: pointer;
  animation: ajc-rise 0.35s ease both;
}
.ajc-teaser strong { color: var(--ajc-red); }
.ajc-teaser-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--ajc-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
}
.ajc-teaser-close:hover { background: var(--ajc-bg-soft); }

/* ---------- Panel ---------- */
.ajc-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: 384px;
  height: min(620px, calc(100vh - 120px));
  background: var(--ajc-bg);
  border-radius: var(--ajc-radius);
  box-shadow: 0 24px 60px rgba(17, 17, 17, 0.22), 0 6px 18px rgba(17, 17, 17, 0.08);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(17, 17, 17, 0.06);
}
.ajc-root.is-open .ajc-panel { display: flex; animation: ajc-rise 0.28s ease both; }

@keyframes ajc-rise {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.ajc-header {
  background: linear-gradient(135deg, var(--ajc-ink) 0%, #2a2a2e 100%);
  color: #fff;
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ajc-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.ajc-avatar img { width: 34px; height: 34px; object-fit: contain; }
.ajc-avatar-fallback { color: var(--ajc-red); font-weight: 800; font-family: var(--ajc-font-head); font-size: 15px; }
.ajc-online-dot {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid #fff;
}
.ajc-title { flex: 1; min-width: 0; }
.ajc-title strong { display: block; font-family: var(--ajc-font-head); font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.ajc-title span { display: block; font-size: 12px; color: rgba(255, 255, 255, 0.72); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ajc-head-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease;
  flex-shrink: 0;
}
.ajc-head-btn:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }
.ajc-head-btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ajc-head-btn svg { width: 18px; height: 18px; }
.ajc-head-btn.is-wa { background: #25D366; }
.ajc-head-btn.is-wa:hover { background: #1ebe5b; }

/* Messages */
.ajc-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  background: var(--ajc-bg-soft);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.ajc-msg {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  animation: ajc-rise 0.22s ease both;
}
.ajc-msg.is-user { justify-content: flex-end; }
.ajc-bubble {
  max-width: 84%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.ajc-msg.is-bot .ajc-bubble {
  background: var(--ajc-bg);
  color: var(--ajc-ink);
  border: 1px solid var(--ajc-line);
  border-bottom-left-radius: 4px;
}
.ajc-msg.is-user .ajc-bubble {
  background: var(--ajc-red);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ajc-bubble p { margin: 0 0 8px; }
.ajc-bubble p:last-child { margin-bottom: 0; }
.ajc-bubble ul, .ajc-bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.ajc-bubble li { margin: 2px 0; }
.ajc-bubble strong { font-weight: 700; }
.ajc-bubble a { color: var(--ajc-red); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.ajc-msg.is-user .ajc-bubble a { color: #fff; }
.ajc-time { display: block; font-size: 10.5px; color: var(--ajc-muted); margin-top: 4px; }
.ajc-msg.is-user .ajc-time { color: rgba(255, 255, 255, 0.75); text-align: right; }

.ajc-mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--ajc-red);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  font-family: var(--ajc-font-head);
}

/* Typing indicator */
.ajc-typing .ajc-bubble { display: inline-flex; gap: 4px; padding: 14px 16px; }
.ajc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ajc-muted);
  animation: ajc-bounce 1.2s infinite ease-in-out;
}
.ajc-typing span:nth-child(2) { animation-delay: 0.15s; }
.ajc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ajc-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Suggestion chips */
.ajc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 2px 0 10px 36px;
}
.ajc-chip {
  border: 1px solid rgba(237, 16, 24, 0.35);
  background: var(--ajc-bg);
  color: var(--ajc-red-dark);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.3;
}
.ajc-chip:hover { background: var(--ajc-red); color: #fff; border-color: var(--ajc-red); }
.ajc-chip:focus-visible { outline: 2px solid var(--ajc-red); outline-offset: 2px; }
.ajc-chip.is-primary { background: var(--ajc-red); color: #fff; border-color: var(--ajc-red); }
.ajc-chip.is-primary:hover { background: var(--ajc-red-dark); }

/* Composer */
.ajc-footer {
  border-top: 1px solid var(--ajc-line);
  background: var(--ajc-bg);
  padding: 10px 12px 8px;
  flex-shrink: 0;
}
.ajc-form { display: flex; align-items: flex-end; gap: 8px; }
.ajc-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--ajc-line);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 110px;
  min-height: 42px;
  color: var(--ajc-ink);
  background: var(--ajc-bg-soft);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.ajc-input:focus { border-color: var(--ajc-red); background: #fff; }
.ajc-send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 0;
  background: var(--ajc-red);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
.ajc-send:hover:not(:disabled) { background: var(--ajc-red-dark); transform: scale(1.05); }
.ajc-send:disabled { opacity: 0.45; cursor: not-allowed; }
.ajc-send svg { width: 18px; height: 18px; }
.ajc-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--ajc-muted);
}
.ajc-link-btn {
  border: 0;
  background: none;
  color: var(--ajc-red-dark);
  font-weight: 600;
  font-size: 11.5px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}
.ajc-link-btn:hover { text-decoration: underline; }

/* Lead (callback) form */
.ajc-lead {
  position: absolute;
  inset: 74px 0 0 0;
  background: var(--ajc-bg);
  padding: 20px 18px;
  overflow-y: auto;
  display: none;
  animation: ajc-rise 0.22s ease both;
}
.ajc-panel.show-lead .ajc-lead { display: block; }
.ajc-lead h3 { font-family: var(--ajc-font-head); font-size: 18px; margin: 0 0 4px; color: var(--ajc-ink); }
.ajc-lead > p { margin: 0 0 16px; font-size: 13px; color: var(--ajc-body); }
.ajc-field { margin-bottom: 12px; }
.ajc-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ajc-ink); margin-bottom: 4px; }
.ajc-field label em { color: var(--ajc-red); font-style: normal; }
.ajc-field input,
.ajc-field select,
.ajc-field textarea {
  width: 100%;
  border: 1px solid var(--ajc-line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ajc-ink);
  background: #fff;
  outline: none;
}
.ajc-field input:focus,
.ajc-field select:focus,
.ajc-field textarea:focus { border-color: var(--ajc-red); box-shadow: 0 0 0 3px rgba(237, 16, 24, 0.1); }
.ajc-field textarea { resize: vertical; min-height: 70px; }
.ajc-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; overflow: hidden; }
.ajc-lead-actions { display: flex; gap: 8px; margin-top: 6px; }
.ajc-btn {
  flex: 1;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
}
.ajc-btn-primary { background: var(--ajc-red); color: #fff; }
.ajc-btn-primary:hover:not(:disabled) { background: var(--ajc-red-dark); }
.ajc-btn-primary:disabled { opacity: 0.6; cursor: wait; }
.ajc-btn-ghost { background: #fff; color: var(--ajc-ink); border-color: var(--ajc-line); }
.ajc-btn-ghost:hover { background: var(--ajc-bg-soft); }
.ajc-error { color: var(--ajc-red-dark); font-size: 12.5px; margin: 4px 0 8px; min-height: 1em; }
.ajc-privacy { font-size: 11px; color: var(--ajc-muted); margin-top: 10px; }

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .ajc-root { right: 14px; bottom: 14px; }
  .ajc-launcher { width: 56px; height: 56px; }
  .ajc-root.is-open { right: 0; bottom: 0; left: 0; top: 0; }
  .ajc-root.is-open .ajc-launcher { display: none; }
  .ajc-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    bottom: 0;
  }
  .ajc-teaser { width: min(260px, calc(100vw - 28px)); bottom: 70px; }
  .ajc-input { font-size: 16px; } /* prevents iOS zoom on focus */
}

@media (prefers-reduced-motion: reduce) {
  .ajc-root *, .ajc-root *::after { animation: none !important; transition: none !important; }
}

@media print {
  .ajc-root { display: none !important; }
}
