#moaws-chatbot-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  font-family: inherit;
}

@media (max-width: 800px) {
  #moaws-chatbot-root {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  #moaws-chatbot-root.cb-root-open .cb-toggle-btn {
    visibility: hidden;
    pointer-events: none;
  }
}

.cb-toggle-btn {
  width: 56px;
  height: 56px;
  background-color: var(--color-ink, #2B2B2B);
  color: var(--color-cream, #FFFBF5);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 4px 4px 0px rgba(43, 43, 43, 0.2);
  cursor: pointer;
  border: 1px solid var(--color-ink, #2B2B2B);
  transition: all 0.2s ease;
  visibility: visible;
  pointer-events: auto;
}

.cb-toggle-btn:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0px rgba(43, 43, 43, 0.3);
}

/* ── Desktop: popup nổi ── */
.cb-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 360px;
  height: 560px;
  max-height: 75vh;
  background: var(--color-cream, #FFFBF5);
  border: 1px solid var(--color-ink, #2B2B2B);
  border-radius: 8px;
  box-shadow: 8px 8px 0px rgba(43, 43, 43, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.cb-window.cb-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ── Mobile: full-screen cố định, KHÔNG dịch chuyển theo bàn phím ── */
@media (max-width: 768px) {
  .cb-window {
    position: fixed;
    /* FIX CHÍNH: dùng inset: 0 cứng, không để JS override bottom/maxHeight */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    /* dvh = dynamic viewport height — tự co theo khi bàn phím bật/tắt
       fallback về 100vh cho browser cũ */
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    box-shadow: none;
    /* FIX: không dùng transform translateY làm lộ nền.
       Dùng opacity + scale nhẹ để animation mượt mà */
    transform: scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10002;
    /* FIX: ngăn scroll lan ra ngoài window */
    overscroll-behavior: contain;
  }

  .cb-window.cb-open {
    transform: scale(1);
  }
}

/* Header */
.cb-header-minimal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px 0;
  background: transparent;
  min-height: 48px;
  /* FIX: thêm safe-area top cho iPhone có notch */
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
}

/* Nút back — chỉ hiện trên mobile */
.cb-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--color-ink, #2B2B2B);
  cursor: pointer;
  padding: 4px 6px;
  opacity: 0.7;
  line-height: 1;
  transition: opacity 0.2s;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
}

.cb-back-btn:hover { opacity: 1; }

@media (max-width: 768px) {
  .cb-back-btn { display: flex; }
  .cb-close { display: none; }
}

.cb-close {
  background: none;
  border: none;
  color: var(--color-ink, #2B2B2B);
  font-size: 28px;
  cursor: pointer;
  opacity: 0.4;
  line-height: 1;
  transition: opacity 0.2s;
  margin-left: auto;
}

.cb-close:hover { opacity: 1; }

/* Body scroll */
.cb-body {
  flex: 1;
  padding: 0 20px 20px;
  overflow-y: auto;
  /* FIX: ngăn scroll bounce của iOS lan ra ngoài */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

/* Welcome Screen */
#cbWelcomeScreen {
  margin-top: 10px;
  margin-bottom: 20px;
}

.cb-greet-title {
  font-size: 28px;
  font-weight: 600;
  color: var(--color-ink, #2B2B2B);
  margin: 0 0 8px 0;
  letter-spacing: -0.02em;
}

.cb-greet-subtitle {
  font-size: 15px;
  color: rgba(43, 43, 43, 0.7);
  margin: 0 0 24px 0;
}

/* Quick suggest buttons */
.cb-suggest-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid rgba(43, 43, 43, 0.15);
  padding: 14px 16px;
  border-radius: 6px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  color: var(--color-ink, #2B2B2B);
  transition: all 0.2s ease;
}

.cb-suggest-btn:hover {
  background: rgba(43, 43, 43, 0.04);
  border-color: rgba(43, 43, 43, 0.4);
}

.cb-suggest-btn svg { opacity: 0.5; flex-shrink: 0; }
.cb-suggest-btn:hover svg { opacity: 1; transform: translateX(2px); transition: 0.2s; }

/* Chat messages */
#cbChatHistory {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cb-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  line-height: 1.5;
}

.cb-msg-bot {
  background: transparent;
  border: 1px solid rgba(43, 43, 43, 0.15);
  color: var(--color-ink, #2B2B2B);
  align-self: flex-start;
}

.cb-msg-user {
  background: var(--color-ink, #2B2B2B);
  color: var(--color-cream, #FFFBF5);
  align-self: flex-end;
}

.typing {
  font-style: italic;
  color: rgba(43, 43, 43, 0.5);
  padding: 4px 16px;
  border: none;
}

/* Input area */
.cb-input-area {
  padding: 16px;
  background: #fff;
  border-top: 1px solid rgba(43, 43, 43, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  /* FIX: safe-area bottom cho iPhone */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  /* FIX: không bị bàn phím đè lên — luôn hiển thị */
  flex-shrink: 0;
}

.cb-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--color-cream, #FFFBF5);
  border: 1px solid rgba(43, 43, 43, 0.2);
  border-radius: 24px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: 0.2s;
  /* FIX: tắt zoom iOS khi focus input */
  font-size: max(16px, 14px);
}

.cb-input:focus {
  border-color: var(--color-ink, #2B2B2B);
  background: #fff;
}

.cb-send-btn {
  background: var(--color-ink, #2B2B2B);
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
}

.cb-send-btn:hover { opacity: 0.8; }

.cb-btn-primary {
  background: var(--color-ink, #2B2B2B) !important;
  color: var(--color-cream, #FFFBF5) !important;
  font-weight: 500;
  width: 100%;
  padding: 14px;
  text-align: center;
  border-radius: 6px;
  display: block;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-decoration: none;
  transition: opacity 0.2s;
}

.cb-btn-primary:hover { opacity: 0.85; }