/* =========================================================
   Zeands Assistant — floating chatbot widget
   ========================================================= */

.z-chatbot {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 9400;
  font-family: var(--font);
}

/* --- Launcher FAB --- */
.z-chat-launcher {
  position: relative;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--gradient);
  color: #0D0D0D;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.z-chat-launcher:hover { transform: scale(1.06); }
.z-chat-launcher:focus-visible { outline: 2px solid var(--accent-ink); outline-offset: 3px; }
.z-launcher-icon svg { width: 26px; height: 26px; }
.z-open .z-launcher-icon svg { display: none; }
.z-chatbot:not(.z-open) .z-chat-launcher::after { content: ''; }

.z-launcher-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
  animation: zBadgePulse 1.8s ease-in-out infinite;
}
@keyframes zBadgePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* --- Panel --- */
.z-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(58px + 14px);
  width: 380px;
  max-width: calc(100vw - 36px);
  height: min(560px, 72vh);
  max-height: calc(100vh - 120px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: zPanelIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes zPanelIn {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.z-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.z-chat-header-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.z-chat-avatar {
  width: 32px; height: 32px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--border);
}
.z-chat-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.z-chat-header-text { display: flex; flex-direction: column; min-width: 0; }
.z-chat-header-text strong { font-size: 0.92rem; color: var(--text); }
.z-chat-status { display: flex; align-items: center; gap: 5px; font-size: 0.74rem; color: var(--text-muted); }
.z-status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); flex-shrink: 0; }

.z-chat-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0; transition: background-color 0.2s ease, color 0.2s ease;
}
.z-chat-close:hover { background: rgba(13,13,13,0.06); color: var(--text); }
.z-chat-close svg { width: 16px; height: 16px; }

.z-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.z-msg { display: flex; align-items: flex-end; gap: 8px; }
.z-msg--user { justify-content: flex-end; }
.z-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  border: 1px solid var(--border);
}
.z-msg-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.z-msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.88rem;
  line-height: 1.5;
  max-width: 78%;
}
.z-msg--bot .z-msg-bubble {
  background: var(--dark);
  color: var(--text);
  border-bottom-left-radius: 5px;
}
.z-msg--bot .z-msg-bubble a { color: var(--accent-ink); font-weight: 600; }
.z-msg--user .z-msg-bubble {
  background: var(--gradient);
  color: #0D0D0D;
  font-weight: 600;
  border-bottom-right-radius: 5px;
}

.z-msg--typing .z-typing {
  display: flex; align-items: center; gap: 4px;
  background: var(--dark);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  padding: 12px 14px;
}
.z-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: zTypingBounce 1.1s infinite ease-in-out;
}
.z-typing span:nth-child(2) { animation-delay: 0.15s; }
.z-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes zTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.z-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.z-chip {
  background: var(--surface-solid);
  border: 1px solid var(--border-2, var(--border));
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.z-chip:hover { background: var(--accent-light); border-color: var(--accent); transform: translateY(-1px); }

.z-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.z-chat-input-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 100px;
  padding: 10px 16px;
  font-size: 0.88rem;
  font-family: inherit;
}
.z-chat-input-row input:focus { outline: none; border-color: var(--accent-ink); }
.z-chat-send {
  width: 38px; height: 38px; border-radius: 50%; border: none; flex-shrink: 0;
  background: var(--gradient); color: #0D0D0D; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease;
}
.z-chat-send:hover { transform: scale(1.06); }
.z-chat-send svg { width: 16px; height: 16px; }

@media (max-width: 480px) {
  .z-chatbot { right: 12px; bottom: 12px; }
  .z-chat-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }
  .z-chat-launcher { width: 52px; height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  .z-chat-panel { animation: none; }
  .z-typing span { animation: none; }
  .z-launcher-badge { animation: none; }
}
