/* ============================================================
   DMATICS AI — chat widget
   Self-contained: reads the design-system vars from main.css
   (--void, --carbon, --graphite, --line, --steel, --white, --signal, fonts).
   ============================================================ */

#dm-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 200;
  font-family: var(--font-body);
}

/* ---------- Bubble (minimized state) ---------- */
.dm-chat-bubble {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--signal);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 12px 32px rgba(229, 72, 77, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}
.dm-chat-bubble:hover { transform: scale(1.06); }
.dm-chat-bubble svg { width: 26px; height: 26px; color: #fff; }
.dm-chat-bubble .dm-chat-dot {
  position: absolute;
  top: -2px; right: -2px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #58d68d;
  border: 2px solid var(--void);
}
#dm-chat.is-open .dm-chat-bubble { display: none; }

/* ---------- Panel ---------- */
.dm-chat-panel {
  display: none;
  flex-direction: column;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 350px;
  height: 380px;
  background: var(--carbon);
  border: 1px solid var(--line);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  transition: height 0.4s var(--ease), width 0.4s var(--ease);
}
#dm-chat.is-open .dm-chat-panel { display: flex; }
#dm-chat.is-open.is-expanded .dm-chat-panel { width: 380px; height: 560px; }

.dm-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--graphite);
  flex-shrink: 0;
}
.dm-chat-head-info { display: flex; align-items: center; gap: 10px; }
.dm-chat-live {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #58d68d;
  flex-shrink: 0;
  animation: dmPulse 2.2s ease-in-out infinite;
}
@keyframes dmPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(88, 214, 141, 0.5); }
  50% { box-shadow: 0 0 0 6px rgba(88, 214, 141, 0); }
}
.dm-chat-head-info strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--white);
  letter-spacing: 0.01em;
}
.dm-chat-head-info span {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--steel-dim);
  margin-top: 2px;
}
.dm-chat-min {
  background: none;
  border: 1px solid var(--line);
  color: var(--steel);
  width: 28px; height: 28px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, border-color 0.2s;
}
.dm-chat-min:hover { color: var(--white); border-color: var(--steel); }

.dm-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dm-chat-body::-webkit-scrollbar { width: 6px; }
.dm-chat-body::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.dm-msg {
  max-width: 86%;
  font-size: 0.86rem;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
}
.dm-msg.bot {
  align-self: flex-start;
  background: var(--graphite);
  color: var(--white);
  border: 1px solid var(--line-soft);
}
.dm-msg.user {
  align-self: flex-end;
  background: var(--signal);
  color: #fff;
}
.dm-msg.typing { display: flex; gap: 4px; align-items: center; padding: 12px 14px; }
.dm-msg.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--steel);
  animation: dmTyping 1.1s ease-in-out infinite;
}
.dm-msg.typing span:nth-child(2) { animation-delay: 0.15s; }
.dm-msg.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dmTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ---------- WhatsApp nudge ---------- */
.dm-chat-whatsapp {
  flex-shrink: 0;
  border-top: 1px solid var(--line-soft);
  padding: 10px 14px;
}
.dm-chat-whatsapp a {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: #58d68d;
  transition: color 0.2s;
}
.dm-chat-whatsapp a:hover { color: #7ee6ab; }
.dm-chat-whatsapp svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- Input ---------- */
.dm-chat-form {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
  background: var(--carbon);
}
.dm-chat-form input {
  flex: 1;
  background: var(--void);
  border: 1px solid var(--line);
  color: var(--white);
  font-family: var(--font-body);
  font-size: 0.86rem;
  padding: 9px 12px;
  border-radius: 6px;
  outline: none;
  transition: border-color 0.2s;
  min-width: 0;
}
.dm-chat-form input:focus { border-color: var(--signal); }
.dm-chat-form button {
  background: var(--signal);
  border: none;
  color: #fff;
  width: 36px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.2s;
}
.dm-chat-form button:hover { background: #f0555a; }
.dm-chat-form button:disabled { opacity: 0.5; cursor: not-allowed; }

@media (max-width: 480px) {
  #dm-chat { right: 14px; bottom: 14px; }
  .dm-chat-panel, #dm-chat.is-open.is-expanded .dm-chat-panel {
    width: calc(100vw - 28px);
    height: min(72vh, 560px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .dm-chat-panel { transition: none; }
  .dm-chat-live, .dm-msg.typing span { animation: none; }
}
