/* ===========================
   Chat widget — floating button + panel
   =========================== */
.chat-fab {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 45;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(230,57,70,0.35);
  font-weight: 700;
  font-family: inherit;
  font-size: .95rem;
  transition: transform .18s, box-shadow .18s;
  animation: fab-bounce 2.6s ease-in-out infinite;
}
.chat-fab:hover { transform: scale(1.05); box-shadow: 0 14px 30px rgba(230,57,70,0.4); }
.chat-fab.hidden { display: none !important; }
.chat-fab-icon { font-size: 1.3rem; }

@keyframes fab-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.chat-panel {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 46;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 48px);
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.22);
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: chat-open .22s ease;
  border: 1px solid rgba(0,0,0,0.06);
}
.chat-panel.hidden { display: none !important; }

@keyframes chat-open {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
}
.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
}
.chat-title { font-weight: 700; font-size: 1rem; }
.chat-status { font-size: .78rem; opacity: .95; display: flex; align-items: center; gap: 6px; }
.dot-online {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 6px #4ade80;
}
.chat-close {
  background: rgba(255,255,255,0.18); border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 1rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.chat-close:hover { background: rgba(255,255,255,0.3); }

.chat-body {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(180deg, #fafafa 0%, #fff 100%);
}

.msg { display: flex; gap: 8px; align-items: flex-end; animation: msg-in .22s ease; }
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.msg-bubble {
  max-width: 78%; padding: 10px 14px;
  border-radius: 16px;
  font-size: .92rem; line-height: 1.55;
  word-wrap: break-word; white-space: pre-wrap;
}
.msg.bot .msg-bubble {
  background: #f0f0f0;
  border-bottom-right-radius: 4px;
  color: var(--text);
}
.msg.user .msg-bubble {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border-bottom-left-radius: 4px;
}
.msg.error .msg-bubble {
  background: #fff0f0; color: #c1121f; border: 1px solid #ffcdd2;
}

.msg-bubble.rich { white-space: normal; }
.msg-bubble.rich .section-title {
  font-weight: 700; color: var(--primary-dark); margin: 8px 0 4px;
}
.msg-bubble.rich .section-title:first-child { margin-top: 0; }
.msg-bubble.rich .item-name-line {
  font-weight: 700; margin-top: 8px; margin-bottom: 2px;
}
.msg-bubble.rich .item-desc-line {
  color: var(--text-muted); font-size: .82rem; margin: 2px 0;
}
.msg-bubble.rich .item-prices-line {
  display: inline-block;
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 10px;
  font-size: .82rem; font-weight: 600;
  margin: 4px 0; line-height: 1.5;
}
.msg-bubble.rich .plain-line { margin: 4px 0; }

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.typing .msg-bubble {
  padding: 12px 16px; display: flex; gap: 4px; align-items: center;
}
.typing-dot {
  width: 7px; height: 7px; background: #aaa; border-radius: 50%;
  animation: t-bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes t-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

.chat-quick {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 8px 12px; background: #fafafa; border-top: 1px solid var(--border);
}
.chat-quick button {
  background: #fff; border: 1px solid var(--border-strong);
  border-radius: 999px; padding: 5px 12px; font-family: inherit;
  font-size: .78rem; cursor: pointer; color: var(--text);
  transition: all .15s;
}
.chat-quick button:hover {
  background: var(--primary); color: #fff; border-color: transparent;
}

.chat-input {
  display: flex; gap: 8px; padding: 10px 12px;
  background: #fff; border-top: 1px solid var(--border);
  align-items: center;
}
.chat-input input {
  flex: 1; padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px; font-family: inherit; font-size: .93rem;
  background: #fafafa; outline: none;
  transition: all .18s;
}
.chat-input input:focus { border-color: var(--primary); background: #fff; }
.chat-input button {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff; border: 0;
  width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .12s;
}
.chat-input button:hover:not([disabled]) { transform: scale(1.05); }
.chat-input button[disabled] { opacity: .55; cursor: not-allowed; }

/* Responsive */
@media (max-width: 480px) {
  .chat-fab {
    bottom: 16px; left: 16px;
    padding: 12px 16px;
  }
  .chat-fab-text { display: none; }
  .chat-fab-icon { font-size: 1.4rem; }
  .chat-panel {
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: 0;
  }
}
