
  #htdh-widget * { box-sizing: border-box; margin: 0; padding: 0; }
  #htdh-widget {
    position: fixed; bottom: 20px; right: 20px; z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  }

  .htdh-idle {
    background: linear-gradient(135deg, #1a1f3a 0%, #0f1424 100%);
    border-radius: 50px; padding: 10px 18px 10px 10px;
    display: flex; align-items: center; gap: 12px;
    cursor: pointer; color: white; max-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 0 0 1px rgba(255,255,255,0.08);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .htdh-idle:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 40px rgba(102,126,234,0.35), 0 0 0 1px rgba(102,126,234,0.4);
  }
  .htdh-idle-avatar {
    position: relative; width: 44px; height: 44px; border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
    border: 2px solid rgba(255,255,255,0.1);
  }
  .htdh-idle-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .htdh-idle-avatar-fallback { font-size: 22px; }
  .htdh-online-dot {
    position: absolute; bottom: 0; right: 0;
    width: 12px; height: 12px; border-radius: 50%;
    background: #10b981; border: 2px solid #1a1f3a;
    animation: htdh-pulse-dot 2s infinite;
  }
  @keyframes htdh-pulse-dot {
    0%,100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.7); }
    50% { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  }
  .htdh-idle-text { min-width: 0; }
  .htdh-idle-name { font-size: 14px; font-weight: 700; line-height: 1.2; }
  .htdh-idle-tagline {
    font-size: 11px; color: #94a3b8; margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .htdh-idle-online {
    display: inline-block; width: 6px; height: 6px;
    background: #10b981; border-radius: 50%; margin-right: 4px;
    animation: htdh-pulse-mini 2s infinite;
  }
  @keyframes htdh-pulse-mini { 0%,100% {opacity:1;} 50% {opacity:0.4;} }

  .htdh-proactive {
    position: absolute; bottom: 80px; right: 0;
    background: white; color: #1e293b;
    padding: 14px 16px; border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.18);
    max-width: 280px; font-size: 13px;
    animation: htdh-slide-up 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e2e8f0;
  }
  .htdh-proactive::after {
    content:''; position: absolute; bottom: -8px; right: 30px;
    width: 0; height: 0;
    border-left: 8px solid transparent; border-right: 8px solid transparent;
    border-top: 8px solid white;
  }
  @keyframes htdh-slide-up { from {opacity:0; transform:translateY(20px);} to {opacity:1; transform:translateY(0);} }
  .htdh-proactive-close {
    position: absolute; top: 4px; right: 6px;
    background: none; border: none; cursor: pointer;
    font-size: 18px; color: #94a3b8; line-height: 1;
    width: 20px; height: 20px; border-radius: 50%;
  }
  .htdh-proactive-close:hover { background: #f1f5f9; color: #475569; }
  .htdh-proactive-greeting { font-weight: 700; color: #1e293b; margin-bottom: 4px; }
  .htdh-proactive-msg { color: #64748b; line-height: 1.4; margin-bottom: 8px; }
  .htdh-proactive-cta {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white; border: none; padding: 7px 14px;
    border-radius: 20px; font-size: 12px; font-weight: 600;
    cursor: pointer; transition: transform 0.15s;
  }
  .htdh-proactive-cta:hover { transform: scale(1.05); }

  .htdh-menu {
    background: linear-gradient(160deg, #1a1f3a, #0f1424);
    border-radius: 20px; width: 340px; max-width: calc(100vw - 40px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.08);
    color: white; overflow: hidden;
    animation: htdh-menu-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  @keyframes htdh-menu-in { from {opacity:0; transform:translateY(20px) scale(0.96);} to {opacity:1; transform:translateY(0) scale(1);} }
  .htdh-menu-header {
    padding: 18px 20px 16px; display: flex; align-items: center; gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
  }
  .htdh-menu-avatar {
    position: relative; width: 48px; height: 48px; border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; overflow: hidden;
    border: 2px solid rgba(255,255,255,0.15);
  }
  .htdh-menu-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .htdh-menu-avatar-fallback { font-size: 24px; }
  .htdh-menu-title { flex: 1; min-width: 0; }
  .htdh-menu-name { font-size: 16px; font-weight: 700; }
  .htdh-menu-sub { font-size: 12px; color: #94a3b8; margin-top: 2px; }
  .htdh-menu-close {
    background: rgba(255,255,255,0.06); border: none; color: #cbd5e1;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
  }
  .htdh-menu-close:hover { background: rgba(255,255,255,0.12); color: white; }
  .htdh-menu-body { padding: 14px 16px 6px; }

  .htdh-ai-card {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 14px; padding: 14px 16px;
    cursor: pointer; transition: all 0.2s;
    position: relative; overflow: hidden;
  }
  .htdh-ai-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(102,126,234,0.5); }
  .htdh-ai-card::before {
    content:''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: htdh-shimmer 3s infinite;
  }
  @keyframes htdh-shimmer { to { left: 100%; } }
  .htdh-ai-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
  .htdh-ai-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
  .htdh-ai-badge {
    background: rgba(255,255,255,0.25); color: white; font-size: 10px;
    padding: 2px 8px; border-radius: 10px; font-weight: 700; letter-spacing: 0.5px;
  }
  .htdh-ai-desc { font-size: 12px; opacity: 0.92; }

  .htdh-divider {
    font-size: 10px; color: #64748b; font-weight: 700;
    letter-spacing: 1px; margin: 16px 4px 8px;
  }

  .htdh-channel {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 12px;
    cursor: pointer; transition: all 0.15s;
    text-decoration: none; color: white;
    border-left: 3px solid transparent; margin-bottom: 4px;
  }
  .htdh-channel:hover {
    background: rgba(255,255,255,0.05);
    border-left-color: #667eea; transform: translateX(2px);
  }
  .htdh-channel-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; font-size: 20px;
  }
  .htdh-channel-icon.zalo { background: #0068ff; color: white; font-weight: 700; font-size: 14px; }
  .htdh-channel-icon.telegram { background: #229ED9; color: white; }
  .htdh-channel-icon.whatsapp { background: #25D366; color: white; }
  .htdh-channel-icon.phone { background: #10b981; color: white; }
  .htdh-channel-info { flex: 1; min-width: 0; }
  .htdh-channel-name { font-size: 14px; font-weight: 600; }
  .htdh-channel-sub { font-size: 11px; color: #94a3b8; margin-top: 1px; }
  .htdh-channel-arrow { color: #475569; font-size: 14px; }

  .htdh-trust {
    background: rgba(255,255,255,0.03);
    padding: 12px 16px; text-align: center;
    font-size: 11px; color: #94a3b8;
    border-top: 1px solid rgba(255,255,255,0.05);
    line-height: 1.6;
  }

  .htdh-chat {
    background: white; border-radius: 20px;
    width: 380px; height: 600px;
    max-width: calc(100vw - 40px); max-height: calc(100vh - 100px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.35);
    display: flex; flex-direction: column; overflow: hidden;
    animation: htdh-menu-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .htdh-chat-header {
    background: linear-gradient(135deg, #1a1f3a, #0f1424);
    color: white; padding: 14px 16px;
    display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  }
  .htdh-chat-back, .htdh-chat-close {
    background: rgba(255,255,255,0.1); border: none; color: white;
    width: 32px; height: 32px; border-radius: 50%;
    cursor: pointer; font-size: 14px;
    display: flex; align-items: center; justify-content: center;
  }
  .htdh-chat-header-info { flex: 1; min-width: 0; }
  .htdh-chat-title { font-size: 14px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
  .htdh-chat-status { font-size: 11px; color: #94a3b8; }
  .htdh-chat-status .htdh-online-dot {
    position: static; display: inline-block; width: 6px; height: 6px;
    margin-right: 4px; border: none;
  }

  /* ⭐ FIX #1: Khung chat KHÔNG bị cắt */
  .htdh-chat-messages {
    flex: 1; overflow-y: auto; padding: 16px;
    padding-bottom: 24px;
    background: #f8fafc;
    min-height: 0;
    scroll-behavior: smooth;
  }
  .htdh-chat-messages::after {
    content: ''; display: block; height: 8px;
  }

  .htdh-msg { margin-bottom: 14px; display: flex; gap: 8px; }
  .htdh-msg.user { flex-direction: row-reverse; }
  .htdh-msg-avatar {
    width: 30px; height: 30px; border-radius: 50%;
    flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    font-size: 14px; overflow: hidden;
  }
  .htdh-msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
  .htdh-msg-avatar.bot { background: linear-gradient(135deg, #667eea, #764ba2); color: white; }
  .htdh-msg-avatar.user { background: #e0e7ff; }
  .htdh-msg-bubble {
    max-width: 78%; padding: 10px 14px; border-radius: 14px;
    font-size: 13px; line-height: 1.55; word-wrap: break-word;
  }
  .htdh-msg-bubble.bot { background: white; border: 1px solid #e2e8f0; color: #1e293b; border-top-left-radius: 4px; }
  .htdh-msg-bubble.user { background: linear-gradient(135deg, #667eea, #764ba2); color: white; border-top-right-radius: 4px; }
  .htdh-msg-bubble strong { font-weight: 700; }
  .htdh-msg-bubble ul, .htdh-msg-bubble ol { margin: 6px 0 6px 18px; }
  .htdh-msg-bubble code { background: #f1f5f9; padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 12px; }
  .htdh-msg-bubble a { color: #667eea; text-decoration: underline; font-weight: 600; }
  .htdh-msg-bubble a:hover { color: #4338ca; }

  .htdh-quick-replies { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  .htdh-quick-chip {
    background: white; border: 1px solid #c7d2fe; color: #4338ca;
    padding: 6px 12px; border-radius: 14px; font-size: 12px;
    cursor: pointer; font-weight: 600; transition: all 0.15s;
  }
  .htdh-quick-chip:hover { background: #eef2ff; transform: translateY(-1px); }

  .htdh-thinking { display: inline-flex; gap: 4px; padding: 6px 0; }
  .htdh-thinking span {
    width: 6px; height: 6px; background: #cbd5e1; border-radius: 50%;
    animation: htdh-bounce 1.2s infinite;
  }
  .htdh-thinking span:nth-child(2) { animation-delay: 0.15s; }
  .htdh-thinking span:nth-child(3) { animation-delay: 0.3s; }
  @keyframes htdh-bounce { 0%,80%,100% {transform:translateY(0); opacity:0.5;} 40% {transform:translateY(-6px); opacity:1;} }

  .htdh-thinking-text {
    font-size: 11px; color: #94a3b8; margin-top: 4px; font-style: italic;
  }

  .htdh-chat-input-wrap {
    padding: 12px 14px; border-top: 1px solid #e2e8f0;
    background: white; flex-shrink: 0;
  }
  .htdh-chat-input-row { display: flex; gap: 8px; align-items: flex-end; }
  .htdh-chat-input {
    flex: 1; padding: 10px 14px;
    border: 1.5px solid #cbd5e1; border-radius: 20px;
    font-family: inherit; font-size: 13px; resize: none;
    outline: none; max-height: 100px; transition: border-color 0.2s;
  }
  .htdh-chat-input:focus { border-color: #667eea; }
  .htdh-chat-send {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white; border: none; width: 38px; height: 38px;
    border-radius: 50%; cursor: pointer; font-size: 14px; flex-shrink: 0;
  }
  .htdh-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
  .htdh-chat-footer { font-size: 10px; color: #94a3b8; text-align: center; margin-top: 6px; }

  @media (max-width: 480px) {
    #htdh-widget { bottom: 12px; right: 12px; left: 12px; }
    .htdh-menu, .htdh-chat { width: 100%; }
    .htdh-chat { height: calc(100vh - 80px); }
    .htdh-idle { max-width: 100%; }
  }
