/* =============================================================================
   ZenAI Chatbox – Frontend Styles
   ============================================================================= */

/* CSS Custom Properties */
:root {
  --zenai-primary: #007bff;
  --zenai-primary-dark: #0056d6;
  --zenai-primary-light: #e8f0fe;
  --zenai-ai-bg: #f0f4ff;
  --zenai-user-bg: #007bff;
  --zenai-admin-bg: #28a745;
  --zenai-white: #ffffff;
  --zenai-text: #1a1a2e;
  --zenai-text-muted: #6b7280;
  --zenai-border: #e5e7eb;
  --zenai-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  --zenai-radius: 16px;
  --zenai-radius-msg: 18px;
  --zenai-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --zenai-z: 99999;
  --zenai-width: 360px;
  --zenai-height: 520px;
  --zenai-toggle-size: 56px;
}

/* ---- Wrapper ---------------------------------------------------------------- */
.zenai-chatbox {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--zenai-z);
  font-family: var(--zenai-font);
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Toggle Button ---------------------------------------------------------- */
.zenai-toggle {
  width: var(--zenai-toggle-size);
  height: var(--zenai-toggle-size);
  border-radius: 50%;
  background: var(--zenai-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 123, 255, 0.5);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.2s ease;
  position: relative;
  margin-left: auto;
}

.zenai-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0, 123, 255, 0.65);
}

.zenai-toggle svg {
  width: 22px;
  height: 22px;
  color: #fff;
  transition: opacity 0.2s, transform 0.2s;
}

.zenai-icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg);
}

/* When open, swap icons */
.zenai-chatbox.is-open .zenai-icon-chat {
  opacity: 0;
  transform: rotate(90deg);
}

.zenai-chatbox.is-open .zenai-icon-close {
  opacity: 1;
  transform: rotate(0);
}

/* Unread badge */
.zenai-unread-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: zenai-pulse 2s infinite;
}

@keyframes zenai-pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.15);
  }
}

/* ---- Chat Window ------------------------------------------------------------ */
.zenai-window {
  width: var(--zenai-width);
  height: var(--zenai-height);
  background: var(--zenai-white);
  border-radius: var(--zenai-radius);
  box-shadow: var(--zenai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: absolute;
  bottom: calc(var(--zenai-toggle-size) + 12px);
  right: 0;
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Hidden state */
.zenai-window[hidden] {
  display: flex !important;
  /* Override HTML hidden for animation */
  opacity: 0;
  transform: scale(0.85) translateY(10px);
  pointer-events: none;
}

/* Visible state */
.zenai-chatbox.is-open .zenai-window {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: all;
}

/* ---- Header ----------------------------------------------------------------- */
.zenai-header {
  background: var(--zenai-primary);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.zenai-header__avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.zenai-header__avatar svg {
  width: 22px;
  height: 22px;
  fill: #fff;
}

.zenai-header__info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.zenai-header__name {
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
}

.zenai-header__status {
  color: rgba(255, 255, 255, 0.85);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.zenai-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
  display: inline-block;
  animation: zenai-dot-pulse 2s infinite;
}

@keyframes zenai-dot-pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.5;
  }
}

/* ---- Messages Area ---------------------------------------------------------- */
.zenai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.zenai-messages::-webkit-scrollbar {
  width: 4px;
}

.zenai-messages::-webkit-scrollbar-track {
  background: transparent;
}

.zenai-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* ---- Individual Message Bubbles --------------------------------------------- */
.zenai-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: zenai-msg-in 0.25s ease;
}

@keyframes zenai-msg-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* User message — right aligned */
.zenai-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}

/* AI / Admin messages — left aligned */
.zenai-msg--ai,
.zenai-msg--admin {
  align-self: flex-start;
  align-items: flex-start;
}

.zenai-msg__bubble {
  padding: 10px 14px;
  border-radius: var(--zenai-radius-msg);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.zenai-msg--user .zenai-msg__bubble {
  background: var(--zenai-user-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.zenai-msg--ai .zenai-msg__bubble {
  background: var(--zenai-ai-bg);
  color: var(--zenai-text);
  border-bottom-left-radius: 4px;
  /* border: 1px solid #dbeafe; */
}

.zenai-msg--admin .zenai-msg__bubble {
  /* background: #f0fdf4;
  color: var(--zenai-text); */
  background: var(--zenai-ai-bg);
  color: var(--zenai-text);
  border-bottom-left-radius: 4px;
  /* border: 1px solid #bbf7d0; */
}

.zenai-msg__bubble p {
  margin: 0;
}

.zenai-msg__meta {
  font-size: 10.5px;
  color: var(--zenai-text-muted);
  margin-top: 3px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.zenai-msg__sender {
  font-weight: 600;
  font-size: 11px;
  color: var(--zenai-text-muted);
  margin-bottom: 3px;
  padding: 0 4px;
}

/* ---- Typing Indicator ------------------------------------------------------- */
.zenai-typing {
  padding: 8px 18px 4px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.zenai-typing[hidden] {
  display: none;
}

.zenai-typing span {
  width: 7px;
  height: 7px;
  background: var(--zenai-primary);
  border-radius: 50%;
  display: inline-block;
  animation: zenai-bounce 1.2s infinite ease-in-out;
  opacity: 0.7;
}

.zenai-typing span:nth-child(1) {
  animation-delay: 0s;
}

.zenai-typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.zenai-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes zenai-bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
  }

  30% {
    transform: translateY(-6px);
  }
}

/* ---- Lead Capture Form ------------------------------------------------------ */
.zenai-lead-form {
  background: #f9fafb;
  border-top: 1px solid var(--zenai-border);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: zenai-msg-in 0.3s ease;
}

.zenai-lead-form[hidden] {
  display: none;
}

.zenai-lead-form__headline {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: 13px;
  color: var(--zenai-text);
}

.zenai-lead-form input {
  border: 1px solid var(--zenai-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: #fff;
}

.zenai-lead-form input:focus {
  border-color: var(--zenai-primary);
  box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
}

.zenai-lead-form__btn {
  background: var(--zenai-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s;
}

.zenai-lead-form__btn:hover {
  background: var(--zenai-primary-dark);
}

/* ---- Input Area & Row ------------------------------------------------------- */
.zenai-input-area {
  padding: 12px 14px;
  background: var(--zenai-white);
  border-top: 1px solid var(--zenai-border);
  position: relative;
  flex-shrink: 0;
}

.zenai-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.zenai-input {
  flex: 1;
  border: 1px solid var(--zenai-border);
  border-radius: 20px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  background: #f8f9fa;
  transition: border-color 0.2s, background 0.2s;
  line-height: 1.4;
  outline: none;
  overflow: hidden;
  /* Ẩn thanh cuộn mặc định */
}

.zenai-input:focus {
  border-color: var(--zenai-primary);
  background: #fff;
}

.zenai-icon-btn {
  background: none;
  border: none;
  padding: 5px;
  cursor: pointer;
  color: var(--zenai-text-muted);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, transform 0.1s;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.zenai-icon-btn:hover {
  color: var(--zenai-primary);
}

.zenai-icon-btn svg {
  width: 20px;
  height: 20px;
}

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

.zenai-send-btn:hover {
  background: var(--zenai-primary-dark);
  transform: scale(1.05);
}

.zenai-send-btn svg {
  width: 17px;
  height: 17px;
}

/* ---- Emoji Picker ----------------------------------------------------------- */
.zenai-emoji-picker {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 10px;
  right: 10px;
  background: #fff;
  border: 1px solid var(--zenai-border);
  border-radius: 12px;
  box-shadow: 0 -5px 25px rgba(0, 0, 0, 0.15);
  z-index: 10;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 240px;
  animation: zenaiSlideUp 0.15s ease-out;
}

.zenai-emoji-picker[hidden] {
  display: none !important;
}

@keyframes zenaiSlideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.zenai-emoji-cats {
  display: flex;
  background: #f3f4f6;
  border-bottom: 1px solid var(--zenai-border);
  padding: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.zenai-emoji-cats::-webkit-scrollbar {
  display: none;
}

.zenai-emoji-cat-btn {
  background: none;
  border: none;
  padding: 5px 8px;
  font-size: 1rem;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}

.zenai-emoji-cat-btn.active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.zenai-emoji-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
}

.zenai-emoji-item {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zenai-emoji-item:hover {
  background: #f0f7ff;
}

/* ---- Image Bubbles ---------------------------------------------------------- */
.zenai-msg__bubble--img {
  padding: 4px !important;
  max-width: 220px;
}

.zenai-msg__img {
  cursor: zoom-in;
  transition: opacity 0.2s;
}

.zenai-msg__img:hover {
  opacity: 0.9;
}

/* ---- System / greeting message ---------------------------------------------- */
.zenai-msg--system .zenai-msg__bubble {
  background: transparent;
  color: var(--zenai-text-muted);
  font-style: italic;
  font-size: 12.5px;
  text-align: center;
  border: none;
  padding: 4px 0;
}

.zenai-msg--system {
  align-self: center;
  max-width: 100%;
}

/* ---- Mobile Responsive ------------------------------------------------------ */
@media (max-width: 480px) {
  .zenai-chatbox {
    bottom: 16px;
    right: 16px;
  }

  .zenai-window {
    width: calc(100vw - 32px);
    right: -8px;
  }
}

/* ---- Product Cards ---------------------------------------------------------- */
.zenai-product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
  width: 100%;
}

.zenai-product-card {
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--zenai-border);
  border-radius: 12px;
  overflow: hidden;
  text-decoration: none;
  color: var(--zenai-text);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.zenai-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.zenai-product-card img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}

.zenai-product-no-img {
  width: 100%;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  font-size: 2rem;
}

.zenai-product-info {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.zenai-product-name {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--zenai-text);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.zenai-product-price {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--zenai-primary);
}

/* AI bubble code styling */
.zenai-msg__bubble code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.82em;
  font-family: monospace;
}

.zenai-msg__bubble a {
  color: var(--zenai-primary);
  text-decoration: underline;
}

.zenai-msg--ai .zenai-msg__bubble a {
  color: var(--zenai-primary-dark);
}