/* ── YoungDynamics Chat Widget ─────────────────────────────────────── */

/* Inline chat trigger (contact section) */
.yd-chat-inline-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  background: #2563EB;
  border: none;
  border-radius: 50px;
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.1px;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
  box-shadow: 0 4px 16px rgba(37,99,235,0.35);
  white-space: nowrap;
}
.yd-chat-inline-trigger:hover  { background: #1D4ED8; transform: translateY(-1px); box-shadow: 0 6px 24px rgba(37,99,235,0.5); }
.yd-chat-inline-trigger:focus-visible { outline: 3px solid #60A5FA; outline-offset: 3px; }
.yd-chat-inline-trigger svg    { flex-shrink: 0; }

#yd-chat-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(59,130,246,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}
#yd-chat-launcher:hover  { transform: scale(1.08); box-shadow: 0 6px 28px rgba(59,130,246,0.55); }
#yd-chat-launcher:focus-visible { outline: 3px solid #60A5FA; outline-offset: 3px; }
#yd-chat-launcher svg    { width: 24px; height: 24px; fill: #fff; }

#yd-chat-launcher .yd-badge {
  position: absolute;
  top: 0; right: 0;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid var(--yd-surface-0, #0a0a0b);
  display: none;
}
#yd-chat-launcher.has-unread .yd-badge { display: block; }

@media (prefers-reduced-motion: reduce) {
  #yd-chat-launcher { transition: none; }
}

/* ── Chat panel ───────────────────────────────────────────────────── */

#yd-chat-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  z-index: 9001;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--yd-surface-1, #111113);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
}
#yd-chat-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}
@media (prefers-reduced-motion: reduce) {
  #yd-chat-panel { transition: none; }
}

/* Header */
.yd-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  background: var(--yd-surface-2, #1a1a1e);
  flex-shrink: 0;
}
.yd-chat-header-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3B82F6 0%, #8B5CF6 100%);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.yd-chat-header-icon svg { width: 18px; height: 18px; fill: #fff; }
.yd-chat-header-text     { flex: 1; min-width: 0; }
.yd-chat-header-title    { font-family: 'Poppins', sans-serif; font-size: 0.875rem; font-weight: 600; color: #fff; line-height: 1.2; }
.yd-chat-header-subtitle { font-size: 0.75rem; color: var(--yd-text-muted, #888); margin-top: 2px; }
.yd-chat-close-btn {
  background: none; border: none; cursor: pointer; padding: 6px;
  color: var(--yd-text-muted, #888); border-radius: 8px;
  display: flex; align-items: center;
  transition: color 0.15s, background 0.15s;
}
.yd-chat-close-btn:hover       { color: #fff; background: rgba(255,255,255,0.07); }
.yd-chat-close-btn:focus-visible { outline: 2px solid #60A5FA; }
.yd-chat-close-btn svg         { width: 18px; height: 18px; }

/* Status dot */
.yd-status-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  margin-left: 4px;
}
.yd-status-dot.online  { background: #22c55e; }
.yd-status-dot.offline { background: var(--yd-text-muted, #888); }

/* Body */
.yd-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.yd-chat-body::-webkit-scrollbar        { width: 4px; }
.yd-chat-body::-webkit-scrollbar-track  { background: transparent; }
.yd-chat-body::-webkit-scrollbar-thumb  { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* Pre-chat intro */
.yd-chat-intro {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}
.yd-chat-intro-text {
  font-size: 0.875rem;
  color: var(--yd-text-secondary, #ccc);
  line-height: 1.55;
}
.yd-chat-field label {
  display: block;
  font-size: 0.75rem;
  color: var(--yd-text-muted, #888);
  margin-bottom: 5px;
  font-family: 'Poppins', sans-serif;
}
.yd-chat-field input,
.yd-chat-field textarea {
  width: 100%;
  background: var(--yd-surface-3, #222226);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #fff;
  font-size: 0.875rem;
  font-family: 'Poppins', sans-serif;
  padding: 9px 12px;
  box-sizing: border-box;
  transition: border-color 0.15s;
  resize: none;
}
.yd-chat-field input:focus,
.yd-chat-field textarea:focus {
  outline: none;
  border-color: rgba(96,165,250,0.6);
}
.yd-chat-field textarea { height: 80px; }

/* Messages */
.yd-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
}
.yd-msg.visitor  { align-self: flex-end; align-items: flex-end; }
.yd-msg.operator { align-self: flex-start; align-items: flex-start; }
.yd-msg.system   { align-self: center; align-items: center; max-width: 100%; }

.yd-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}
.yd-msg.visitor  .yd-msg-bubble { background: #2563EB; color: #fff; border-bottom-right-radius: 4px; }
.yd-msg.operator .yd-msg-bubble { background: var(--yd-surface-3, #222226); color: #fff; border-bottom-left-radius: 4px; }
.yd-msg.system   .yd-msg-bubble { background: transparent; color: var(--yd-text-muted, #888); font-size: 0.78rem; font-style: italic; }

.yd-msg-meta {
  font-size: 0.7rem;
  color: var(--yd-text-muted, #888);
  padding: 0 3px;
}

/* Typing indicator */
.yd-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--yd-surface-3, #222226);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}
.yd-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--yd-text-muted, #888);
  animation: yd-bounce 1.2s infinite ease-in-out;
}
.yd-typing span:nth-child(2) { animation-delay: 0.2s; }
.yd-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes yd-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40%           { transform: translateY(-5px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .yd-typing span { animation: none; opacity: 0.6; }
}

/* Footer / input */
.yd-chat-footer {
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.07);
  padding: 12px 14px;
  background: var(--yd-surface-2, #1a1a1e);
}
.yd-chat-inputrow {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.yd-chat-input {
  flex: 1;
  background: var(--yd-surface-3, #222226);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  padding: 9px 12px;
  resize: none;
  height: 38px;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  transition: border-color 0.15s, height 0.1s;
  box-sizing: border-box;
}
.yd-chat-input:focus { outline: none; border-color: rgba(96,165,250,0.6); }
.yd-chat-input::placeholder { color: var(--yd-text-muted, #888); }

.yd-chat-send {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: #2563EB;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.yd-chat-send:hover   { background: #1D4ED8; }
.yd-chat-send:disabled { background: var(--yd-surface-4, #2a2a30); cursor: not-allowed; }
.yd-chat-send svg     { width: 18px; height: 18px; fill: #fff; }

/* Submit button (pre-chat) */
.yd-chat-btn {
  display: block;
  width: 100%;
  padding: 11px;
  border-radius: 10px;
  background: #2563EB;
  color: #fff;
  border: none;
  cursor: pointer;
  font-family: 'Poppins', sans-serif;
  font-size: 0.875rem;
  font-weight: 600;
  text-align: center;
  transition: background 0.15s;
  margin-top: 4px;
}
.yd-chat-btn:hover    { background: #1D4ED8; }
.yd-chat-btn:disabled { background: var(--yd-surface-4, #2a2a30); cursor: not-allowed; }
.yd-chat-btn:focus-visible { outline: 2px solid #60A5FA; }

/* Offline fallback strip */
.yd-chat-offline {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  text-align: center;
}
.yd-chat-offline p {
  font-size: 0.875rem;
  color: var(--yd-text-muted, #888);
  line-height: 1.5;
  margin: 0;
}
.yd-chat-offline-link {
  font-size: 0.875rem;
  color: #60A5FA;
  text-decoration: underline;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
}

/* Closed state */
.yd-chat-closed {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1;
  color: var(--yd-text-muted, #888);
  font-size: 0.875rem;
  text-align: center;
  padding: 16px;
}

/* Error banner */
.yd-chat-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: 8px;
  color: #f87171;
  font-size: 0.8rem;
  padding: 8px 12px;
  margin: 0 0 8px;
}

/* Mobile */
@media (max-width: 480px) {
  #yd-chat-launcher { bottom: 20px; right: 16px; }
  #yd-chat-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%;
    border-radius: 16px 16px 0 0;
    height: 70vh;
    max-height: 70vh;
  }
}

/* Live region for screen reader announcements */
#yd-chat-aria-live {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
