.qr-chatbot-hidden {
  display: none !important;
}

/* Ensure consistent sizing */
#qr-chatbot-root, #qr-chatbot-root * {
  box-sizing: border-box;
}

#qr-chatbot-root {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 2147483000; /* very top */
  pointer-events: none;
}

#qr-chatbot-root .qr-chatbot-fab,
#qr-chatbot-root .qr-chatbot-panel {
  pointer-events: auto;
}

.qr-chatbot-fab {
  position: fixed;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1fa2ff, #12d8fa, #a6ffcb);
  border: none;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  z-index: 2147483646; /* above everything except panel */
}

.qr-chatbot-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.22);
}

.qr-chatbot-panel {
  position: fixed;
  width: 320px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px);
  min-height: 420px; /* ensure messages area has room */
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 24px 40px rgba(15, 29, 53, 0.18);
  z-index: 2147483647; /* top-most */
}

.qr-chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #1155cc, #0a84ff);
  color: #fff;
  cursor: move;
}

.qr-chatbot-header .qr-chatbot-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  user-select: none;
}

.qr-chatbot-header .qr-chatbot-name {
  font-weight: 600;
  font-size: 15px;
}

.qr-chatbot-header .qr-chatbot-status {
  font-size: 11px;
  opacity: 0.85;
  text-transform: uppercase;
}

.qr-chatbot-header-buttons {
  display: flex;
  gap: 6px;
}

.qr-chatbot-header-buttons button {
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-chatbot-header-buttons button:hover {
  background: rgba(255, 255, 255, 0.3);
}

.qr-chatbot-body {
  display: flex;
  flex: 1;
  overflow: hidden; /* prevent overlap */
  background: #f7f9fc;
}

.qr-chatbot-sidebar {
  width: 180px;
  background: #eef3ff;
  border-right: 1px solid rgba(17, 85, 204, 0.08);
  display: flex;
  flex-direction: column;
}

.qr-chatbot-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
}

.qr-chatbot-sidebar-header button {
  border: none;
  background: #1251d1;
  color: #fff;
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

.qr-chatbot-conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.qr-chatbot-conversation {
  width: 100%;
  border: none;
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  margin-bottom: 6px;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.qr-chatbot-conversation:hover,
.qr-chatbot-conversation.active {
  background: #dfe9ff;
  box-shadow: inset 0 0 0 1px rgba(17, 85, 204, 0.2);
}

.qr-chatbot-conversation-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.qr-chatbot-conversation-preview {
  font-size: 11px;
  color: #5c6c8a;
}

.qr-chatbot-messages {
  flex: 1 1 auto;
  width: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-height: 160px;
}

.qr-chatbot-message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 92%;
  position: relative;
}

.qr-chatbot-message .qr-chatbot-bubble {
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  display: inline-block;
  max-width: 85%;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  writing-mode: horizontal-tb; /* guard against global vertical writing modes */
}

.qr-chatbot-user .qr-chatbot-bubble {
  align-self: flex-end;
  background: #1155cc;
  color: #fff;
}

.qr-chatbot-assistant .qr-chatbot-bubble {
  align-self: flex-start;
  background: #ffffff;
  border: 1px solid rgba(17, 85, 204, 0.12);
  color: #1a2433;
}

.qr-chatbot-system .qr-chatbot-bubble {
  align-self: center;
  background: #fff8e1;
  border: 1px solid rgba(255, 193, 7, 0.3);
  color: #7a5b00;
}

.qr-chatbot-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.qr-chatbot-actions button {
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  background: #1251d1;
  color: #fff;
  transition: opacity 0.2s ease;
}

.qr-chatbot-actions button[data-action="cancel"],
.qr-chatbot-actions button[data-action="no"] {
  background: #95a2c4;
}

.qr-chatbot-actions button:disabled {
  opacity: 0.6;
  cursor: default;
}

.qr-chatbot-form {
  border-top: 1px solid rgba(17, 85, 204, 0.08);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #fff;
}

.qr-chatbot-form textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(17, 85, 204, 0.2);
  padding: 8px 10px;
  resize: none;
  font-size: 13px;
  line-height: 1.4;
  max-height: 140px;
}

.qr-chatbot-form textarea:focus {
  outline: none;
  border-color: #1155cc;
  box-shadow: 0 0 0 2px rgba(17, 85, 204, 0.18);
}

.qr-chatbot-form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Hide Turnstile visual placeholder inside the widget */
.qr-chatbot-turnstile {
  display: none !important;
  visibility: hidden !important;
}

.qr-chatbot-form button[type="submit"] {
  border: none;
  background: #1155cc;
  color: #fff;
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
}

.qr-chatbot-disabled {
  opacity: 0.6;
}

@media (max-width: 600px) {
  .qr-chatbot-panel {
    width: calc(100vw - 20px);
    right: 10px !important;
    bottom: 100px !important;
  }

  .qr-chatbot-sidebar {
    display: none;
  }
}

/* --- Split mode (mobile top/bottom) -------------------------------------- */
/* When the documentElement has class .qr-chatbot-split, we reserve the TOP
   half for the website and dock the chatbot to the BOTTOM half. */
@media (max-width: 900px) {
  html.qr-chatbot-split, html.qr-chatbot-split body {
    height: 100%;
  }
  html.qr-chatbot-split body {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 50vh; /* reserve bottom half for chatbot */
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }
  html.qr-chatbot-split #qr-chatbot-root .qr-chatbot-panel {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 50vh !important;
    max-height: 50vh !important;
    border-radius: 0 !important;
  }
  html.qr-chatbot-split #qr-chatbot-root .qr-chatbot-fab {
    display: none !important; /* panel is visible, bubble hidden */
  }
}
