/* ============================================
   XIAMACH Chat Widget Styles
   Color: #22397E (Primary Deep Blue)
   ============================================ */

:root {
  --cw-primary: #22397E;
  --cw-primary-hover: #1a2d66;
  --cw-red: #ea281b;
  --cw-white: #ffffff;
  --cw-bg: #f5f6f8;
  --cw-text: #333333;
  --cw-gray: #999999;
  --cw-light-gray: #e0e0e0;
  --cw-border: #dcdcdc;
  --cw-online: #4caf50;
  --cw-offline: #bdbdbd;
  --cw-whatsapp: #25D366;
  --cw-whatsapp-hover: #1ebe56;
}

/* ---------- Toggle Button ---------- */
.chat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--cw-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(34, 57, 126, 0.35);
  z-index: 9999;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.chat-toggle-btn:hover {
  transform: scale(1.08);
  background: var(--cw-primary-hover);
  box-shadow: 0 6px 22px rgba(34, 57, 126, 0.45);
}
.chat-toggle-btn svg {
  width: 26px;
  height: 26px;
  fill: var(--cw-white);
  transition: transform 0.25s ease;
}
/* Active state – rotates icon */
.chat-toggle-btn.active {
  background: var(--cw-red);
}
.chat-toggle-btn.active svg {
  transform: rotate(90deg);
}

/* ---------- Tooltip ---------- */
.chat-tooltip {
  position: fixed;
  bottom: 88px;
  right: 20px;
  background: var(--cw-white);
  color: var(--cw-text);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 8px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.15);
  z-index: 9998;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  pointer-events: none;
}
/* Small triangle arrow */
.chat-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 20px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--cw-white);
}
.chat-toggle-btn:hover + .chat-tooltip,
.chat-tooltip.show {
  opacity: 1;
  visibility: visible;
}

/* ---------- Popup Window ---------- */
.chat-popup {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 520px;
  background: var(--cw-white);
  border-radius: 16px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--cw-border);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  overflow: hidden;
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
}
.chat-popup.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* ---------- Header ---------- */
.chat-header {
  background: var(--cw-primary);
  color: var(--cw-white);
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chat-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}
.chat-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online {
  background: var(--cw-online);
  box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}
.status-dot.offline {
  background: var(--cw-offline);
}
.chat-close-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--cw-white);
  font-size: 22px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-close-btn:hover {
  background: rgba(255,255,255,0.3);
}

/* ---------- FAQ Quick Buttons ---------- */
.chat-faq {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px;
  background: var(--cw-white);
  border-bottom: 1px solid var(--cw-light-gray);
  flex-shrink: 0;
}
.faq-btn {
  font-size: 11px;
  padding: 6px 12px;
  border-radius: 14px;
  border: 1px solid var(--cw-primary);
  background: transparent;
  color: var(--cw-primary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 30px;
}
.faq-btn:hover {
  background: var(--cw-primary);
  color: var(--cw-white);
}

/* ---------- Messages Area ---------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  background: var(--cw-bg);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-messages::-webkit-scrollbar {
  width: 5px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 10px;
}

/* Individual message */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.agent {
  align-self: flex-start;
}
.chat-msg.user {
  align-self: flex-end;
}
.msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
}
.chat-msg.agent .msg-bubble {
  background: var(--cw-white);
  color: var(--cw-text);
  border: 1px solid var(--cw-light-gray);
  border-bottom-left-radius: 4px;
}
.chat-msg.user .msg-bubble {
  background: var(--cw-primary);
  color: var(--cw-white);
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 10px;
  color: var(--cw-gray);
  margin-top: 3px;
  padding: 0 4px;
}
.chat-msg.agent .msg-time {
  text-align: left;
}
.chat-msg.user .msg-time {
  text-align: right;
}

/* System message */
.chat-msg.system {
  align-self: center;
  max-width: 100%;
}
.chat-msg.system .msg-bubble {
  background: transparent;
  color: var(--cw-gray);
  font-size: 11px;
  border: none;
  padding: 4px;
  text-align: center;
}

/* ---------- Offline Form ---------- */
.chat-offline-form {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--cw-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-offline-form h4 {
  font-size: 14px;
  color: var(--cw-text);
  margin: 0;
  text-align: center;
}
.chat-offline-form p {
  font-size: 12px;
  color: var(--cw-gray);
  margin: 0;
  text-align: center;
}
.offline-input,
.offline-select,
.offline-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--cw-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
  transition: border-color 0.2s;
}
.offline-input:focus,
.offline-select:focus,
.offline-textarea:focus {
  outline: none;
  border-color: var(--cw-primary);
}
.offline-textarea {
  resize: vertical;
  min-height: 70px;
}
.offline-submit {
  background: var(--cw-primary);
  color: var(--cw-white);
  border: none;
  border-radius: 8px;
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 44px;
}
.offline-submit:hover {
  background: var(--cw-primary-hover);
}
.offline-success {
  text-align: center;
  padding: 20px 10px;
}
.offline-success h4 {
  font-size: 16px;
  color: var(--cw-primary);
  margin: 0 0 8px 0;
}
.offline-success p {
  font-size: 13px;
  color: var(--cw-text);
  margin: 0;
}

/* ---------- WhatsApp Bar ---------- */
.chat-whatsapp {
  padding: 0 14px 6px;
  background: var(--cw-white);
  flex-shrink: 0;
}
.whatsapp-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--cw-whatsapp);
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 8px;
  transition: background 0.2s;
}
.whatsapp-btn:hover {
  background: var(--cw-whatsapp-hover);
}
.whatsapp-btn svg {
  width: 18px;
  height: 18px;
  fill: #fff;
  flex-shrink: 0;
}

/* ---------- Input Area ---------- */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--cw-white);
  border-top: 1px solid var(--cw-light-gray);
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--cw-border);
  border-radius: 22px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
  min-height: 40px;
  box-sizing: border-box;
}
.chat-input:focus {
  border-color: var(--cw-primary);
}
.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--cw-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-send-btn:hover {
  background: var(--cw-primary-hover);
}
.chat-send-btn svg {
  width: 18px;
  height: 18px;
  fill: var(--cw-white);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .chat-popup {
    width: 60vw;
    right: 10px;
    bottom: 80px;
  }
}
@media (max-width: 480px) {
  .chat-toggle-btn {
    width: 48px;
    height: 48px;
    bottom: 16px;
    right: 16px;
  }
  .chat-toggle-btn svg {
    width: 22px;
    height: 22px;
  }
  .chat-tooltip {
    bottom: 72px;
    right: 12px;
  }
  .chat-popup {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }
  .chat-popup.open {
    transform: none;
  }
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  .chat-popup,
  .chat-toggle-btn,
  .chat-toggle-btn svg,
  .chat-toggle-btn.active svg {
    transition: none;
  }
  .chat-msg {
    animation: none;
  }
}
