/* Chat panel — anchored below header, top-right */
#ai-panel {
  position: fixed;
  top: 90px;
  right: 24px;
  width: min(340px, calc(100vw - 32px));
  height: 530px;
  max-height: calc(100vh - 100px);
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#ai-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

/* Header */
#ai-header {
  background: #0A1628;
  padding: 16px 20px;
  flex-shrink: 0;
}

#ai-header-name {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  margin: 0;
  line-height: 1.3;
}

#ai-header-sub {
  color: #8b9ab5;
  font-size: 12px;
  margin: 3px 0 0;
}

/* Messages area */
#ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#ai-messages::-webkit-scrollbar {
  width: 4px;
}

#ai-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* Chat bubbles */
.ai-bubble {
  max-width: 82%;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

.ai-bubble.bot {
  background: #F1F3F5;
  color: #1a1a1a;
  border-radius: 14px 14px 14px 4px;
  align-self: flex-start;
}

.ai-bubble.user {
  background: #0A1628;
  color: #fff;
  border-radius: 14px 14px 4px 14px;
  align-self: flex-end;
}

/* Starter chips */
#ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 2px 0 4px;
  align-self: flex-start;
}

.ai-chip {
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  cursor: pointer;
  color: #0A1628;
  font-family: inherit;
  transition: background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.ai-chip:hover {
  background: #f0f2f5;
  border-color: #0A1628;
}

/* Typing indicator */
.ai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: #F1F3F5;
  border-radius: 14px 14px 14px 4px;
  align-self: flex-start;
  width: fit-content;
}

.ai-typing span {
  width: 6px;
  height: 6px;
  background: #888;
  border-radius: 50%;
  display: inline-block;
  animation: ai-dot-bounce 1s infinite;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes ai-dot-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* Input row */
#ai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}

#ai-textarea {
  flex: 1;
  resize: none;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
  font-family: inherit;
  outline: none;
  color: #1a1a1a;
  transition: border-color 0.15s ease;
}

#ai-textarea:focus {
  border-color: #0A1628;
}

#ai-send {
  width: 36px;
  height: 36px;
  background: #0A1628;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

#ai-send:hover {
  opacity: 0.82;
}

/* Medium screens: tighten right margin */
@media (max-width: 600px) {
  #ai-panel {
    right: 16px;
    width: calc(100vw - 32px);
    top: 76px;
  }
}

/* Mobile: full-width sheet from bottom */
@media (max-width: 440px) {
  #ai-panel {
    width: 100vw;
    right: 0;
    top: auto;
    bottom: 0;
    border-radius: 16px 16px 0 0;
    height: 75vh;
    max-height: none;
    transform: translateY(16px);
  }
}
