/* ===================================================================
   PTS Innovations — Chat Widget (AI Assistant)
   ใช้ token สีและฟอนต์ชุดเดียวกับ css/theme.css ของเว็บหลัก
   =================================================================== */

.pts-chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147483000;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--primary-color, #6f6f71);
  color: #fff;
  border: 2px solid #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  overflow: hidden;
  box-shadow: var(--shadow-card-hover, 0 8px 24px rgba(0,0,0,0.2));
  transition: transform .15s ease, box-shadow .15s ease;
}
.pts-chat-fab:hover { transform: translateY(-2px) scale(1.04); }
.pts-chat-fab-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  border-radius: 50%;
}
.pts-chat-fab .fa-times { display: none; }
.pts-chat-fab.is-open .pts-chat-fab-avatar { display: none; }
.pts-chat-fab.is-open .fa-times { display: block; }

.pts-chat-panel {
  position: fixed;
  right: 22px;
  bottom: 92px;
  z-index: 2147483000;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: min(600px, calc(100vh - 140px));
  background: #fff;
  border-radius: var(--radius, 10px);
  box-shadow: var(--shadow-card-hover, 0 8px 24px rgba(0,0,0,0.2));
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-body, 'Sarabun', 'Segoe UI', sans-serif);
}
.pts-chat-panel.is-open { display: flex; }

.pts-chat-header {
  background: var(--primary-color, #6f6f71);
  color: #fff;
  padding: 14px 16px;
  flex: none;
}
.pts-chat-header-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pts-chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 30%;
  border: 2px solid rgba(255,255,255,0.6);
  flex: none;
}
.pts-chat-header h3 {
  margin: 0;
  font-family: var(--font-display, 'Prompt', sans-serif);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .5px;
  color: #fff;
}
.pts-chat-header p {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: #e9e9ea;
}

.pts-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--light-bg, #f4f4f5);
}

.pts-chat-msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.pts-chat-msg.bot {
  align-self: flex-start;
  background: #fff;
  color: var(--secondary-color, #4a4a4a);
  border: 1px solid var(--primary-tint, #d9d9da);
  border-bottom-left-radius: 3px;
}
.pts-chat-msg.user {
  align-self: flex-end;
  background: var(--primary-color, #6f6f71);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.pts-chat-msg.error {
  align-self: flex-start;
  background: #fdecea;
  color: #92221a;
  border: 1px solid #f3c3bd;
}

.pts-chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--primary-tint, #d9d9da);
  border-radius: 12px;
  border-bottom-left-radius: 3px;
}
.pts-chat-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--primary-color, #6f6f71);
  opacity: .4;
  animation: pts-chat-blink 1.1s infinite;
}
.pts-chat-typing span:nth-child(2) { animation-delay: .18s; }
.pts-chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes pts-chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: .9; } }

.pts-chat-form {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--primary-tint, #d9d9da);
  background: #fff;
}
.pts-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--primary-tint, #d9d9da);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: var(--font-body, 'Sarabun', sans-serif);
  font-size: 14px;
  line-height: 1.5;
  max-height: 90px;
  color: var(--secondary-color, #4a4a4a);
}
.pts-chat-input:focus { outline: none; border-color: var(--primary-color, #6f6f71); }
.pts-chat-send {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--primary-color, #6f6f71);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.pts-chat-send:hover { background: var(--primary-dark, #565658); }
.pts-chat-send:disabled { opacity: .5; cursor: default; }

.pts-chat-footnote {
  flex: none;
  font-size: 10.5px;
  color: #999;
  text-align: center;
  padding: 4px 8px 8px;
  background: #fff;
}

@media (max-width: 480px) {
  .pts-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
    height: min(70vh, calc(100vh - 120px));
  }
  .pts-chat-fab { right: 16px; bottom: 16px; }
}
