/* ============================================================
   Merlin Chat Panel
   ============================================================ */

.merlin-chat {
  position: fixed;
  bottom: 160px;
  right: 20px;
  width: 340px;
  max-height: 420px;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  border: 1px solid #d8d4cc;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease;
  transform-origin: bottom right;
}

/* closed state */
.merlin-chat--closed {
  opacity: 0;
  transform: scale(0.9) translateY(12px);
  pointer-events: none;
}

/* speech tail pointing toward Merlin */
.merlin-chat::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 40px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-right: 1px solid #d8d4cc;
  border-bottom: 1px solid #d8d4cc;
  transform: rotate(45deg);
}

/* ---- Header ---- */

.merlin-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #1a2f4a;
  color: #fff;
  flex-shrink: 0;
}

.merlin-chat__title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.merlin-chat__close {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.merlin-chat__close:hover {
  opacity: 1;
}

/* ---- Messages ---- */

.merlin-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
  max-height: 300px;
}

.merlin-chat__msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 10px;
  word-wrap: break-word;
}

.merlin-chat__msg--bot {
  align-self: flex-start;
  background: #f0f4fa;
  color: #1a1a1a;
  border-bottom-left-radius: 3px;
}

.merlin-chat__msg--user {
  align-self: flex-end;
  background: #1a2f4a;
  color: #fff;
  border-bottom-right-radius: 3px;
}

.merlin-chat__msg--error {
  align-self: flex-start;
  background: #fef2f2;
  color: #7f1d1d;
  border-bottom-left-radius: 3px;
  font-style: italic;
}

/* typing indicator */
.merlin-chat__typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 14px;
  align-self: flex-start;
  background: #f0f4fa;
  border-radius: 10px;
  border-bottom-left-radius: 3px;
}

.merlin-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6b6b6b;
  animation: merlin-dot 1.2s ease-in-out infinite;
}

.merlin-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.merlin-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes merlin-dot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ---- Input row ---- */

.merlin-chat__input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #d8d4cc;
  flex-shrink: 0;
}

.merlin-chat__input {
  flex: 1;
  resize: none;
  border: 1px solid #d8d4cc;
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s;
  max-height: 72px;
}

.merlin-chat__input:focus {
  border-color: #c49a2a;
}

.merlin-chat__send {
  background: #c49a2a;
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.merlin-chat__send:disabled {
  opacity: 0.4;
  cursor: default;
}

.merlin-chat__send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  .merlin-chat {
    width: calc(100vw - 24px);
    right: 12px;
    bottom: 100px;
  }

  .merlin-chat::after {
    right: 20px;
  }
}
