/* ==========================================================================
   CHATBOX TƯ VẤN BẤT ĐỘNG SẢN ĐÀ NẴNG 247
   Bảng màu 60-30-10: Nền trắng, Xanh Cổ Vịt (#003C47), Vàng Cam (#FF9900)
   Phông chữ: Roboto | Chuẩn Native CSS Nesting
   ========================================================================== */

:root {
  --cb-primary: #003C47;
  --cb-primary-dark: #00272E;
  --cb-primary-hover: #002B33;
  --cb-primary-light: rgba(0, 60, 71, 0.08);
  --cb-accent: #FF9900;
  --cb-accent-hover: #E68A00;
  --cb-accent-light: rgba(255, 153, 0, 0.12);
  --cb-bg-panel: #ffffff;
  --cb-bg-messages: #f4f8f9;
  --cb-text-dark: #1f2937;
  --cb-text-muted: #64748b;
  --cb-border: rgba(0, 60, 71, 0.12);
  --cb-radius: 12px;
  --cb-font: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* 1. NÚT CHATBOT NỔI (FLOATING BUTTON) */
.cb-floating-btn {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-dark) 100%);
  border: 2px solid rgba(255, 255, 255, 0.28);
  box-shadow: 0 6px 22px rgba(0, 60, 71, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99998;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  outline: none;
  overflow: visible !important;

  &:hover {
    transform: scale(1.08) translateY(-3px);
    box-shadow: 0 10px 28px rgba(0, 60, 71, 0.6), 0 0 16px rgba(0, 60, 71, 0.45);
    border-color: rgba(255, 255, 255, 0.6);
  }

  &.active {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45) !important;

    .cb-icon-bot {
      display: none !important;
    }

    .cb-icon-close {
      display: flex !important;
      transform: rotate(90deg);
    }

    .cb-ping-dot {
      display: none !important;
    }
  }

  .cb-icon-bot {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease;

    .cb-svg-bot {
      width: 28px;
      height: 28px;
      color: #ffffff;
      stroke: #ffffff;
      transition: transform 0.25s ease;
      filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
    }
  }

  &:hover .cb-icon-bot .cb-svg-bot {
    transform: scale(1.08);
  }

  .cb-icon-close {
    display: none !important;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease;

    svg {
      width: 24px;
      height: 24px;
      stroke: #ffffff;
      stroke-width: 2.2;
      fill: none;
    }
  }
}

/* Chấm trạng thái Online nhấp nháy màu Vàng Cam thương hiệu */
.cb-ping-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background-color: var(--cb-accent);
  border: 2px solid #ffffff;
  border-radius: 50%;
  animation: cbPulsePing 2s infinite;
  z-index: 2;
}

@keyframes cbPulsePing {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 153, 0, 0.85);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(255, 153, 0, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 153, 0, 0);
  }
}

/* 2. KHUNG PANEL CHATBOT CHÍNH */
.cb-chat-panel {
  position: fixed;
  bottom: 164px;
  right: 24px;
  width: 395px;
  height: 590px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 180px);
  background-color: var(--cb-bg-panel);
  border-radius: var(--cb-radius);
  box-shadow: 0 16px 40px rgba(0, 43, 51, 0.22), 0 2px 8px rgba(0, 0, 0, 0.08);
  border: 1px solid var(--cb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  font-family: var(--cb-font);
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.96);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none !important;

  &:focus,
  &:focus-visible {
    outline: none !important;
  }

  &.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
  }
}

/* 3. HEADER PANEL */
.cb-header {
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-dark) 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e2e8f0;

  .cb-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .cb-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.15);
    border: 1.5px solid rgba(255, 255, 255, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  .cb-header-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .cb-header-title {
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.2px;
    line-height: 1.2;
  }

  .cb-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: rgba(255, 255, 255, 0.85);

    .cb-status-dot {
      width: 7px;
      height: 7px;
      background-color: #22c55e;
      border-radius: 50%;
      display: inline-block;
      box-shadow: 0 0 6px #22c55e;
    }

    .cb-header-subtitle {
      max-width: 220px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  .cb-close-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #ffffff;
    transition: all 0.2s ease;

    svg {
      width: 18px;
      height: 18px;
      stroke: #ffffff;
      stroke-width: 2.2;
      fill: none;
    }

    &:hover {
      background: rgba(255, 255, 255, 0.25);
      transform: rotate(90deg);
    }
  }
}

/* 4. KHUNG TIN NHẮN (MESSAGES BODY) */
.cb-messages {
  flex: 1;
  padding: 16px;
  background-color: var(--cb-bg-messages);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;

  &::-webkit-scrollbar {
    width: 5px;
  }
  &::-webkit-scrollbar-track {
    background: transparent;
  }
  &::-webkit-scrollbar-thumb {
    background: rgba(0, 60, 71, 0.15);
    border-radius: 4px;
  }
}

/* Dòng tin nhắn */
.cb-msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 88%;
  animation: cbFadeInUp 0.25s ease-out forwards;

  &.user {
    align-self: flex-end;
    flex-direction: row-reverse;
  }

  .cb-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: #ffffff;
    border: 1px solid var(--cb-border);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}

@keyframes cbFadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Bong bóng tin nhắn */
.cb-bubble {
  padding: 12px 15px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;

  a {
    color: var(--cb-primary);
    font-weight: 600;
    text-decoration: underline;

    &:hover {
      color: var(--cb-accent);
    }
  }

  b, strong {
    font-weight: 700;
  }

  &.cb-bubble-bot {
    background-color: #ffffff;
    color: var(--cb-text-dark);
    border: 1px solid var(--cb-border);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 60, 71, 0.05);

    b {
      color: var(--cb-primary);
    }
  }

  &.cb-bubble-user {
    background: linear-gradient(135deg, var(--cb-primary) 0%, var(--cb-primary-dark) 100%);
    color: #ffffff;
    border-top-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(0, 60, 71, 0.25);

    a {
      color: #ffd280;
    }
  }
}

/* Follow-up question pills */
.cb-followup-wrap {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(0, 60, 71, 0.15);

  .cb-followup-title {
    display: block;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--cb-text-muted);
    margin-bottom: 7px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
  }

  .cb-followup-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .cb-followup-pill {
    background-color: var(--cb-primary-light);
    border: 1px solid rgba(0, 60, 71, 0.18);
    color: var(--cb-primary);
    padding: 5px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    outline: none;

    &:hover {
      background-color: var(--cb-primary);
      color: #ffffff;
      border-color: var(--cb-primary);
      transform: translateY(-1px);
      box-shadow: 0 2px 6px rgba(0, 60, 71, 0.2);
    }
  }
}

/* 5. THANH GỢI Ý NHANH KÉO CUỘN NGANG (QUICK BAR) */
.cb-quick-bar {
  padding: 8px 12px;
  background-color: #ffffff;
  border-top: 1px solid var(--cb-border);
  overflow: hidden;

  .cb-quick-scroll {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
    padding-bottom: 2px;
    cursor: grab;
    scrollbar-width: none;

    &::-webkit-scrollbar {
      display: none;
    }

    &:active {
      cursor: grabbing;
    }
  }

  .cb-chip-btn {
    background-color: #f8fafc;
    border: 1px solid var(--cb-border);
    color: var(--cb-primary);
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    outline: none;

    svg {
      width: 14px;
      height: 14px;
      stroke: var(--cb-accent);
      stroke-width: 2;
      fill: none;
      flex-shrink: 0;
    }

    &:hover {
      background-color: var(--cb-primary);
      color: #ffffff;
      border-color: var(--cb-primary);

      svg {
        stroke: #ffffff;
      }
    }
  }
}

/* 6. FORM NHẬP TIN NHẮN (INPUT FORM) */
.cb-input-wrap {
  padding: 10px 14px;
  background-color: #ffffff;
  border-top: 1px solid var(--cb-border);

  .cb-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: #f8fafc;
    border: 1.5px solid rgba(0, 60, 71, 0.15);
    border-radius: 12px;
    padding: 3px 6px 3px 14px;
    transition: all 0.2s ease;

    &:focus-within {
      border-color: #008489 !important;
      background-color: #ffffff !important;
      box-shadow: 0 0 0 3.5px rgba(0, 132, 137, 0.15) !important;
    }
  }

  .cb-input-field {
    flex: 1;
    border: none !important;
    background: transparent !important;
    font-size: 13.5px;
    color: var(--cb-text-dark);
    outline: none !important;
    box-shadow: none !important;
    padding: 8px 0;
    font-family: var(--cb-font);

    &:focus,
    &:focus-visible {
      outline: none !important;
      border: none !important;
      box-shadow: none !important;
    }

    &::placeholder {
      color: #94a3b8;
    }
  }

  .cb-submit-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--cb-accent) 0%, var(--cb-accent-hover) 100%);
    border: none;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(255, 153, 0, 0.35);
    outline: none;

    svg {
      width: 17px;
      height: 17px;
      stroke: #ffffff;
      stroke-width: 2.2;
      fill: none;
      transform: translateX(1px);
    }

    &:hover {
      transform: scale(1.06);
      box-shadow: 0 4px 12px rgba(255, 153, 0, 0.5);
    }

    &:active {
      transform: scale(0.95);
    }
  }
}

/* Typing Animation Indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;

  span {
    width: 6px;
    height: 6px;
    background-color: var(--cb-primary);
    border-radius: 50%;
    display: inline-block;
    opacity: 0.5;
    animation: cbTypingBounce 1.4s infinite ease-in-out both;

    &:nth-child(1) {
      animation-delay: -0.32s;
    }
    &:nth-child(2) {
      animation-delay: -0.16s;
    }
  }
}

@keyframes cbTypingBounce {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* 7. RESPONSIVE CHO THIẾT BỊ DI ĐỘNG */
@media (max-width: 480px) {
  .cb-floating-btn {
    bottom: 136px;
    right: 16px;
    width: 52px;
    height: 52px;
    overflow: visible !important;

    .cb-icon-bot .cb-svg-bot {
      width: 25px;
      height: 25px;
    }
  }

  .cb-chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
}
