/*!
 * ChatWidget.css — Travel Hub AI v2
 * khanhhoatravel.com.vn / khanhhoa-travel-schema-engine
 * C6 — Chat Widget Styles (redesigned)
 *
 * @since 1.1.0
 */

/* ── Custom properties ───────────────────────────────────────────────────── */
#kht-chat-wrap {
  --kht-primary:      #0077B6;
  --kht-primary-dk:   #005f94;
  --kht-primary-lt:   #e0f2fe;
  --kht-accent:       #00B4D8;
  --kht-accent2:      #0096c7;
  --kht-bg:           #ffffff;
  --kht-bg-user:      linear-gradient(135deg, #0077B6 0%, #0096c7 100%);
  --kht-bg-bot:       #f0f7ff;
  --kht-text:         #1e293b;
  --kht-text-muted:   #64748b;
  --kht-text-light:   #94a3b8;
  --kht-border:       #e2eef8;
  --kht-shadow-sm:    0 2px 8px rgba(0,119,182,0.10);
  --kht-shadow:       0 8px 40px rgba(0,119,182,0.18), 0 2px 12px rgba(0,0,0,0.06);
  --kht-shadow-btn:   0 4px 20px rgba(0,119,182,0.40);
  --kht-radius:       20px;
  --kht-radius-msg:   18px;
  --kht-radius-sm:    12px;
  --kht-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --kht-fz:           14px;
  --kht-z:            999999;
  --kht-btn-size:     60px;
  --kht-win-w:        390px;
  --kht-win-h:        600px;
  --kht-header-h:     68px;
  --kht-avatar-size:  32px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
#kht-chat-wrap *,
#kht-chat-wrap *::before,
#kht-chat-wrap *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── Root wrapper ────────────────────────────────────────────────────────── */
#kht-chat-wrap {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--kht-z);
  font-family: var(--kht-font);
  font-size: var(--kht-fz);
  line-height: 1.6;
  color: var(--kht-text);
}

/* ── Toggle button ───────────────────────────────────────────────────────── */
#kht-chat-btn {
  width:  var(--kht-btn-size);
  height: var(--kht-btn-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--kht-shadow-btn);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  outline: none;
  position: relative;
}
#kht-chat-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(0,119,182,0.55);
}
#kht-chat-btn:focus-visible {
  outline: 3px solid var(--kht-accent);
  outline-offset: 3px;
}
#kht-chat-btn.is-open {
  background: linear-gradient(135deg, var(--kht-primary-dk) 0%, var(--kht-primary) 100%);
  transform: scale(0.95);
}

/* Notification badge */
#kht-chat-btn::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: 50%;
  border: 2px solid #fff;
  opacity: 0;
  transition: opacity 0.3s;
}
#kht-chat-btn.has-badge::after { opacity: 1; }

/* Pulse ring */
@keyframes kht-pulse {
  0%   { box-shadow: var(--kht-shadow-btn), 0 0 0 0    rgba(0,119,182,0.50); }
  70%  { box-shadow: var(--kht-shadow-btn), 0 0 0 16px rgba(0,119,182,0);    }
  100% { box-shadow: var(--kht-shadow-btn), 0 0 0 0    rgba(0,119,182,0);    }
}
#kht-chat-btn:not(.is-open) {
  animation: kht-pulse 3s ease-in-out infinite;
}

/* ── Chat window ─────────────────────────────────────────────────────────── */
#kht-chat-window {
  position: absolute;
  bottom: calc(var(--kht-btn-size) + 16px);
  right: 0;
  width: var(--kht-win-w);
  max-height: var(--kht-win-h);
  display: flex;
  flex-direction: column;
  background: var(--kht-bg);
  border-radius: var(--kht-radius);
  box-shadow: var(--kht-shadow);
  border: 1px solid rgba(0,119,182,0.10);
  overflow: hidden;
  transform-origin: bottom right;
}
#kht-chat-window[hidden] { display: none; }

@keyframes kht-slide-in {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);     }
}
#kht-chat-window:not([hidden]) {
  animation: kht-slide-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#kht-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  color: #fff;
  min-height: var(--kht-header-h);
  position: relative;
  overflow: hidden;
}

/* Decorative circle */
#kht-chat-header::before {
  content: '';
  position: absolute;
  right: -30px;
  top: -30px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  pointer-events: none;
}
#kht-chat-header::after {
  content: '';
  position: absolute;
  right: 40px;
  bottom: -40px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  pointer-events: none;
}

/* Bot avatar in header */
#kht-header-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: 2px solid rgba(255,255,255,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
#kht-header-avatar svg {
  width: 22px;
  height: 22px;
  opacity: 0.95;
}
/* Online indicator on avatar */
#kht-header-avatar::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  background: #4ade80;
  border-radius: 50%;
  border: 2px solid var(--kht-primary);
}

#kht-chat-title-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
#kht-chat-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#kht-chat-subtitle {
  font-size: 11.5px;
  opacity: 0.82;
  margin-top: 2px;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 5px;
}
#kht-chat-subtitle::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
}
#kht-chat-close,
#kht-clear-history {
  flex-shrink: 0;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.15s;
  line-height: 1;
  position: relative;
  z-index: 1;
}
#kht-chat-close:hover,
#kht-clear-history:hover {
  background: rgba(255,255,255,0.3);
  color: #fff;
  transform: scale(1.08);
}
#kht-chat-close:focus-visible,
#kht-clear-history:focus-visible { outline: 2px solid rgba(255,255,255,0.75); }
/* Clear history: slightly smaller icon */
#kht-clear-history { width: 30px; height: 30px; opacity: 0.75; }
#kht-clear-history:hover { opacity: 1; }

/* ── Tone bar ────────────────────────────────────────────────────────────── */
#kht-tone-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 4px;
  padding: 8px 14px;
  background: #f8fbff;
  border-bottom: 1px solid var(--kht-border);
  overflow-x: auto;
  scrollbar-width: none;
}
#kht-tone-bar::-webkit-scrollbar { display: none; }

.kht-tone-label {
  font-size: 11px;
  color: var(--kht-text-light);
  white-space: nowrap;
  flex-shrink: 0;
  margin-right: 2px;
}
.kht-tone-btn {
  font-size: 11.5px;
  font-family: var(--kht-font);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1.5px solid var(--kht-border);
  background: #fff;
  color: var(--kht-text-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.18s ease;
  font-weight: 500;
}
.kht-tone-btn:hover {
  border-color: var(--kht-accent);
  color: var(--kht-accent2);
  background: #f0faff;
}
.kht-tone-btn.active {
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  border-color: transparent;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0,119,182,0.25);
}
.kht-tone-btn:focus-visible {
  outline: 2px solid var(--kht-accent);
  outline-offset: 1px;
}

/* ── Message list ────────────────────────────────────────────────────────── */
#kht-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
  background: #fafcff;
}
#kht-messages::-webkit-scrollbar { width: 4px; }
#kht-messages::-webkit-scrollbar-track { background: transparent; }
#kht-messages::-webkit-scrollbar-thumb {
  background: rgba(0,119,182,0.15);
  border-radius: 4px;
}

/* ── Welcome message ─────────────────────────────────────────────────────── */
.kht-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 20px 12px 8px;
  gap: 10px;
}
.kht-welcome-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0,119,182,0.30);
}
.kht-welcome-icon svg { width: 26px; height: 26px; color: #fff; }
.kht-welcome h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--kht-text);
  margin: 0;
}
.kht-welcome p {
  font-size: 13px;
  color: var(--kht-text-muted);
  line-height: 1.5;
  margin: 0;
}
.kht-welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}
.kht-chip {
  background: #fff;
  border: 1.5px solid var(--kht-border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--kht-primary);
  cursor: pointer;
  transition: all 0.18s;
  font-family: var(--kht-font);
  font-weight: 500;
}
.kht-chip:hover {
  background: var(--kht-primary);
  border-color: var(--kht-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,119,182,0.25);
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */
@keyframes kht-msg-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

.kht-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: kht-msg-in 0.2s ease-out;
}
.kht-msg--user {
  align-self: flex-end;
  align-items: flex-end;
}
.kht-msg--assistant {
  align-self: flex-start;
  align-items: flex-start;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
}
.kht-msg--error {
  align-self: stretch;
  max-width: 100%;
}

/* Bot avatar beside message */
.kht-msg-avatar {
  flex-shrink: 0;
  width: var(--kht-avatar-size);
  height: var(--kht-avatar-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2px;
  box-shadow: 0 2px 6px rgba(0,119,182,0.25);
}
.kht-msg-avatar svg { width: 16px; height: 16px; color: #fff; }

.kht-msg-body {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.kht-bubble {
  padding: 10px 14px;
  border-radius: var(--kht-radius-msg);
  font-size: var(--kht-fz);
  word-break: break-word;
  white-space: normal;
  line-height: 1.6;
}
.kht-bubble br { display: block; content: ""; margin-bottom: 2px; }

.kht-msg--user .kht-bubble {
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent2) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 10px rgba(0,119,182,0.22);
}
.kht-msg--assistant .kht-msg-body .kht-bubble {
  background: #fff;
  color: var(--kht-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--kht-border);
  box-shadow: var(--kht-shadow-sm);
}
.kht-msg--error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: var(--kht-radius-sm);
  padding: 10px 14px;
  color: #c53030;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kht-msg--error::before {
  content: '⚠️';
  flex-shrink: 0;
}

/* Timestamp */
.kht-msg-time {
  font-size: 10px;
  color: var(--kht-text-light);
  padding: 0 2px;
}

/* ── Feedback buttons ────────────────────────────────────────────────────── */
.kht-feedback {
  display: flex;
  gap: 2px;
  margin-top: 4px;
}
.kht-fb-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 6px;
  border-radius: 6px;
  opacity: 0.4;
  transition: opacity 0.15s, transform 0.15s, background 0.15s;
  line-height: 1;
}
.kht-fb-btn:hover {
  opacity: 1;
  transform: scale(1.3);
  background: rgba(0,119,182,0.08);
}
.kht-fb-btn:focus-visible { outline: 2px solid var(--kht-accent); }
.kht-fb-thanks {
  font-size: 11px;
  color: var(--kht-text-muted);
  align-self: center;
  padding: 2px 4px;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
#kht-typing {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 8px;
}
#kht-typing[hidden] { display: none; }

.kht-typing-avatar {
  width: var(--kht-avatar-size);
  height: var(--kht-avatar-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,119,182,0.25);
}
.kht-typing-avatar svg { width: 14px; height: 14px; color: #fff; }

.kht-typing-bubble {
  background: #fff;
  border: 1px solid var(--kht-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 9px 14px;
  box-shadow: var(--kht-shadow-sm);
  display: flex;
  align-items: center;
  gap: 4px;
}
.kht-dots span {
  width: 6px;
  height: 6px;
  background: var(--kht-accent);
  border-radius: 50%;
  display: inline-block;
  opacity: 0.4;
  animation: kht-bounce 1.4s infinite ease-in-out;
}
.kht-dots span:nth-child(2) { animation-delay: 0.18s; }
.kht-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes kht-bounce {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0);    }
  30%            { opacity: 1;    transform: translateY(-5px); }
}

/* ── Input form ──────────────────────────────────────────────────────────── */
#kht-input-form {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 10px 12px 12px;
  background: #fff;
  border-top: 1px solid var(--kht-border);
}
#kht-input {
  flex: 1;
  resize: none;
  overflow-y: auto;
  max-height: 120px;
  border: 1.5px solid var(--kht-border);
  border-radius: 22px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13.5px;
  color: var(--kht-text);
  background: #f8fafc;
  outline: none;
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  line-height: 1.5;
}
#kht-input:focus {
  border-color: var(--kht-primary);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(0,119,182,0.10);
}
#kht-input:disabled { opacity: 0.5; cursor: not-allowed; }
#kht-input::placeholder { color: var(--kht-text-light); }
#kht-input::-webkit-scrollbar { width: 3px; }
#kht-input::-webkit-scrollbar-thumb { background: var(--kht-border); border-radius: 2px; }

#kht-send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,119,182,0.30);
  transition: transform 0.18s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.18s, opacity 0.18s;
  align-self: flex-end;
  margin-bottom: 0;
}
#kht-send-btn:hover:not(:disabled) {
  transform: scale(1.12);
  box-shadow: 0 4px 16px rgba(0,119,182,0.45);
}
#kht-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
#kht-send-btn:focus-visible { outline: 2px solid var(--kht-accent); outline-offset: 2px; }

/* ── Lead capture form ───────────────────────────────────────────────────── */
.kht-lead-form {
  border: 1.5px solid #bae6fd;
  border-radius: var(--kht-radius-sm);
  padding: 16px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  animation: kht-slide-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--kht-shadow-sm);
}
.kht-lead-title {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--kht-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kht-lead-title::before { content: '✨'; }
.kht-lead-inner { display: flex; flex-direction: column; gap: 9px; }
.kht-lead-inner input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid #bae6fd;
  border-radius: var(--kht-radius-sm);
  font: inherit;
  font-size: 13px;
  color: var(--kht-text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.kht-lead-inner input:focus {
  border-color: var(--kht-primary);
  box-shadow: 0 0 0 3px rgba(0,119,182,0.10);
}
.kht-lead-inner input::placeholder { color: var(--kht-text-light); }
.kht-lead-err { font-size: 12px; color: #c53030; }
.kht-lead-err[hidden] { display: none; }
.kht-lead-actions { display: flex; gap: 8px; }
.kht-lead-submit {
  flex: 1;
  background: linear-gradient(135deg, var(--kht-primary) 0%, var(--kht-accent) 100%);
  color: #fff;
  border: none;
  border-radius: var(--kht-radius-sm);
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,119,182,0.25);
  transition: opacity 0.15s, transform 0.15s;
}
.kht-lead-submit:hover:not(:disabled) { opacity: 0.9; transform: translateY(-1px); }
.kht-lead-submit:disabled { opacity: 0.55; cursor: not-allowed; }
.kht-lead-skip {
  background: #fff;
  border: 1.5px solid var(--kht-border);
  border-radius: var(--kht-radius-sm);
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--kht-text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.kht-lead-skip:hover { border-color: var(--kht-text-muted); color: var(--kht-text); }
.kht-lead-success {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #065f46;
  padding: 10px 0;
}

/* ── Clickable links inside bot bubbles ──────────────────────────────────── */
.kht-bubble .kht-link {
  color: var(--kht-primary);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 2px;
  word-break: break-all;
  transition: color 0.15s;
}
.kht-bubble .kht-link:hover {
  color: var(--kht-accent2);
  text-decoration-style: solid;
}
/* Trong user bubble (white on blue): lighter underline */
.kht-msg--user .kht-bubble .kht-link {
  color: rgba(255,255,255,0.92);
  text-decoration-color: rgba(255,255,255,0.55);
}
.kht-msg--user .kht-bubble .kht-link:hover {
  color: #fff;
  text-decoration-color: rgba(255,255,255,0.8);
}

/* ── Chat history separator ──────────────────────────────────────────────── */
.kht-history-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--kht-text-light);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 4px 0;
}
.kht-history-sep::before,
.kht-history-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--kht-border);
}
.kht-history-sep--new {
  color: var(--kht-primary);
  opacity: 0.65;
}

/* ── Date divider ────────────────────────────────────────────────────────── */
.kht-divider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--kht-text-light);
  font-size: 11px;
}
.kht-divider::before,
.kht-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--kht-border);
}

/* ── Responsive — mobile ─────────────────────────────────────────────────── */
@media (max-width: 479px) {
  #kht-chat-wrap { bottom: 0; right: 0; left: 0; }
  #kht-chat-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
  }
  #kht-chat-window {
    position: fixed;
    inset: 0;
    width: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
    height: 100dvh;
    max-height: 100dvh;
  }
}

/* ── Prefers-reduced-motion ──────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #kht-chat-btn,
  #kht-chat-btn:not(.is-open),
  #kht-chat-window:not([hidden]),
  .kht-msg,
  .kht-lead-form,
  .kht-welcome { animation: none !important; }
  .kht-dots span, .kht-fb-btn, #kht-send-btn { transition: none !important; animation: none !important; }
}
