/* ============================================================
   ZPD Chat Widget
   ============================================================ */

:root {
  --zpd-chat-primary:    rgb(50, 145, 165);
  --zpd-chat-primary-dk: #226e80;
  --zpd-chat-bg:         #f0f8fa;
  --zpd-chat-radius:     16px;
  --zpd-chat-shadow:     0 8px 40px rgba(0,0,0,.18);
  --zpd-chat-z:          9999;
}

/* ── Launcher button ── */
#zpd-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--zpd-chat-z);
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--zpd-chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(50,145,165,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  transition: background .2s, transform .15s, box-shadow .2s;
  line-height: 1;
}
#zpd-chat-launcher:hover {
  background: var(--zpd-chat-primary-dk);
  transform: scale(1.07);
  box-shadow: 0 6px 24px rgba(50,145,165,.55);
}
#zpd-chat-launcher:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
#zpd-chat-launcher i {
  transition: transform .25s;
}
#zpd-chat-launcher[aria-expanded="true"] i {
  transform: rotate(90deg) scale(.9);
}

/* Unread badge */
#zpd-chat-badge {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  background: #e74c3c;
  border: 2px solid #fff;
  border-radius: 50%;
}

/* ── Chat panel ── */
#zpd-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: var(--zpd-chat-z);
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100dvh - 110px);
  background: #fff;
  border-radius: var(--zpd-chat-radius);
  box-shadow: var(--zpd-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity .2s, transform .2s;
}
#zpd-chat-panel[hidden] {
  display: none !important;
}

/* ── Header ── */
#zpd-chat-header {
  background: rgba(30, 81, 136, .90);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
#zpd-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
}
#zpd-chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
#zpd-chat-header-text {
  flex: 1;
  min-width: 0;
}
#zpd-chat-header-logo {
  display: block;
  height: 30px;
  width: auto;
  max-width: 100%;
}
#zpd-chat-header-text span {
  font-size: .75rem;
  opacity: .85;
}
#zpd-chat-close,
#zpd-chat-menu-btn {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px;
  border-radius: 6px;
  line-height: 1;
  opacity: .8;
  transition: opacity .15s;
  flex-shrink: 0;
}
#zpd-chat-close:hover,
#zpd-chat-menu-btn:hover { opacity: 1; }
#zpd-chat-close:focus-visible,
#zpd-chat-menu-btn:focus-visible {
  outline: 2px solid rgba(255,255,255,.7);
  outline-offset: 2px;
}

/* Overflow menu */
#zpd-chat-menu-wrap {
  position: relative;
  flex-shrink: 0;
}
#zpd-chat-menu-drop {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  min-width: 148px;
  overflow: hidden;
  z-index: 10;
}
#zpd-chat-menu-drop[hidden] { display: none !important; }
#zpd-chat-new {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 11px 16px;
  border: none;
  background: none;
  color: #2c3e50;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background .12s;
}
#zpd-chat-new:hover { background: #f0f8fa; }
#zpd-chat-new:focus-visible {
  outline: 2px solid var(--zpd-chat-primary);
  outline-offset: -2px;
}

/* ── Messages area ── */
#zpd-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

/* Bubble base */
.zpd-bubble {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: .875rem;
  line-height: 1.5;
  word-break: break-word;
}
/* Bot bubble */
.zpd-bubble-bot {
  background: var(--zpd-chat-bg);
  border: 1px solid #d4e9ed;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  color: #2c3e50;
}
/* User bubble */
.zpd-bubble-user {
  background: var(--zpd-chat-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* Bot row (avatar + bubble) */
.zpd-bot-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.zpd-bot-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  margin-bottom: 2px;
}
.zpd-bot-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Quick replies */
.zpd-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 2px 36px;
}
.zpd-quick-reply {
  background: #fff;
  border: 1.5px solid var(--zpd-chat-primary);
  color: var(--zpd-chat-primary);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
  line-height: 1.3;
}
.zpd-quick-reply:hover,
.zpd-quick-reply:focus-visible {
  background: var(--zpd-chat-primary);
  color: #fff;
  outline: none;
}

/* Typing indicator */
.zpd-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 13px;
}
.zpd-typing span {
  width: 7px;
  height: 7px;
  background: #9cbec4;
  border-radius: 50%;
  animation: zpd-bounce .9s infinite ease-in-out;
}
.zpd-typing span:nth-child(2) { animation-delay: .15s; }
.zpd-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes zpd-bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ── */
#zpd-chat-input-area {
  padding: 10px 12px;
  border-top: 1px solid #e8f0f2;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: #fff;
}
#zpd-chat-input {
  flex: 1;
  border: 1.5px solid #cde4e8;
  border-radius: 22px;
  padding: 9px 15px;
  font-size: .875rem;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  background: #f9fdfd;
  color: #2c3e50;
}
#zpd-chat-input:focus {
  border-color: var(--zpd-chat-primary);
  background: #fff;
}
#zpd-chat-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--zpd-chat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .95rem;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}
#zpd-chat-send:hover { background: var(--zpd-chat-primary-dk); transform: scale(1.05); }
#zpd-chat-send:focus-visible {
  outline: 2px solid var(--zpd-chat-primary);
  outline-offset: 2px;
}
#zpd-chat-send:disabled {
  background: #b0cdd2;
  cursor: default;
  transform: none;
}

/* ── Mobile: full-screen panel ── */
@media (max-width: 575px) {
  #zpd-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }
  /* Prevent iOS Safari from auto-zooming on input focus (requires 16px+) */
  #zpd-chat-input {
    font-size: 16px;
  }
  /* Keep input area above the iPhone home bar */
  #zpd-chat-input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #zpd-chat-launcher {
    bottom: calc(16px + env(safe-area-inset-bottom));
    right: 16px;
  }
}
