/* ==========================================================================
   Chatbot Trợ lý Du lịch Cửa Lò
   ========================================================================== */

#chatbot-widget { --cb-primary: #0ea5e9; --cb-primary-dark: #0369a1; --cb-accent: #14b8a6; --cb-surface: #ffffff; --cb-canvas: #f2f7fb; --cb-border: #e2eaf2; --cb-text: #1f2d3d; --cb-muted: #6b7f95; --cb-radius: 20px; --cb-header-h: 68px; --cb-width: 384px; --cb-height: min(560px, calc(100vh - 150px)); --cb-shadow: 0 24px 60px rgba(9, 47, 76, 0.22), 0 4px 14px rgba(9, 47, 76, 0.12); position: fixed; bottom: 70px; right: 15px; z-index: 9999; font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; }

    #chatbot-widget.is-expanded { --cb-width: min(920px, calc(100vw - 48px)); --cb-height: calc(100vh - 170px); /* widget cách đáy 70px + cửa sổ cách nút 80px, chừa 20px phía trên */ }

/* --------------------------------------------------------- Nút mở chat -- */

.chatbot-launcher { position: relative; width: 62px; height: 62px; padding: 0; border: none; border-radius: 50%; background: linear-gradient(140deg, var(--cb-primary), var(--cb-accent)); box-shadow: 0 10px 24px rgba(2, 132, 199, 0.38); cursor: pointer; transition: transform 0.25s ease, box-shadow 0.25s ease; }

    .chatbot-launcher img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }

    .chatbot-launcher:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 16px 30px rgba(2, 132, 199, 0.45); }

    .chatbot-launcher:focus-visible { outline: 3px solid rgba(14, 165, 233, 0.5); outline-offset: 3px; }

/* Vòng sóng nhẹ để thu hút chú ý khi chat đang đóng */
.chatbot-launcher__ping { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(14, 165, 233, 0.55); animation: cb-ping 2.4s cubic-bezier(0, 0, 0.2, 1) infinite; pointer-events: none; }

#chatbot-widget.is-open .chatbot-launcher__ping { display: none; }

@keyframes cb-ping {
    0% { transform: scale(1); opacity: 0.7; }
    70%, 100% { transform: scale(1.5); opacity: 0; }
}

/* ------------------------------------------------------- Khung cửa sổ -- */

.chatbot-window { position: absolute; right: 0; bottom: 80px; display: flex; flex-direction: column; width: var(--cb-width); height: var(--cb-height); max-width: calc(100vw - 30px); background: var(--cb-surface); border-radius: var(--cb-radius); box-shadow: var(--cb-shadow); overflow: hidden; transform-origin: bottom right; opacity: 0; visibility: hidden; transform: translateY(16px) scale(0.94); pointer-events: none; transition: width 0.32s cubic-bezier(0.22, 1, 0.36, 1), height 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.28s; }

#chatbot-widget.is-open .chatbot-window { opacity: 1; visibility: visible; transform: translateY(0) scale(1); pointer-events: auto; }

#chatbot-widget.is-minimized .chatbot-window { height: var(--cb-header-h); }

/* ------------------------------------------------------------- Header -- */

.chatbot-header { flex: 0 0 var(--cb-header-h); height: var(--cb-header-h); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 0 16px; background: linear-gradient(125deg, #0284c7 0%, #0ea5e9 45%, #14b8a6 100%); color: #fff; }

.chatbot-header__identity { display: flex; align-items: center; gap: 11px; min-width: 0; }

.chatbot-header__avatar { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%; overflow: hidden; background: rgba(255, 255, 255, 0.25); border: 2px solid rgba(255, 255, 255, 0.55); }

    .chatbot-header__avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.chatbot-header__text { display: flex; flex-direction: column; min-width: 0; }

.chatbot-header__title { font-size: 15px; font-weight: 700; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }

.chatbot-header__status { display: flex; align-items: center; gap: 6px; font-size: 11.5px; opacity: 0.9; white-space: nowrap; }

.chatbot-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); animation: cb-pulse 2s infinite; }

@keyframes cb-pulse {
    0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.6); }
    70% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.chatbot-header__actions { display: flex; align-items: center; gap: 2px; }

.chatbot-icon-btn { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 9px; background: transparent; color: #fff; font-size: 14px; cursor: pointer; transition: background 0.2s ease, transform 0.2s ease; }

    .chatbot-icon-btn:hover { background: rgba(255, 255, 255, 0.22); transform: translateY(-1px); }

    .chatbot-icon-btn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }

/* --------------------------------------------------------------- Body -- */

.chatbot-body { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; opacity: 1; transition: opacity 0.2s ease; }

#chatbot-widget.is-minimized .chatbot-body { opacity: 0; pointer-events: none; }

.chatbot-messages { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 18px 16px; overflow-y: auto; overscroll-behavior: contain; background: radial-gradient(circle at 100% 0, rgba(20, 184, 166, 0.08), transparent 42%), radial-gradient(circle at 0 100%, rgba(14, 165, 233, 0.08), transparent 42%), var(--cb-canvas); scrollbar-width: thin; scrollbar-color: #c3d4e2 transparent; }

    .chatbot-messages::-webkit-scrollbar { width: 8px; }
    .chatbot-messages::-webkit-scrollbar-thumb { background: #c8d8e6; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
        .chatbot-messages::-webkit-scrollbar-thumb:hover { background: #a9c1d6; background-clip: content-box; }

/* ---------------------------------------------------------- Tin nhắn -- */

.message { max-width: 86%; font-size: 14.5px; line-height: 1.6; color: var(--cb-text); word-wrap: break-word; overflow-wrap: anywhere; animation: cb-message-in 0.28s ease both; }

@keyframes cb-message-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message__content { padding: 11px 15px; border-radius: 18px; }

.bot-msg { align-self: flex-start; }

    .bot-msg .message__content { background: var(--cb-surface); border: 1px solid var(--cb-border); border-bottom-left-radius: 6px; box-shadow: 0 2px 10px rgba(16, 42, 67, 0.06); }

.user-msg { align-self: flex-end; }

    .user-msg .message__content { background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark)); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 6px 16px rgba(3, 105, 161, 0.28); white-space: pre-wrap; }

.error-msg .message__content { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* Khống chế độ dài dòng chữ khi mở rộng để vẫn dễ đọc */
#chatbot-widget.is-expanded .message { max-width: min(76%, 720px); }

/* Markdown bên trong bong bóng của bot */
.bot-msg .message__content > *:first-child { margin-top: 0; }
.bot-msg .message__content > *:last-child { margin-bottom: 0; }

.bot-msg .message__content p { margin: 0 0 8px; }

.bot-msg .message__content h1,
.bot-msg .message__content h2,
.bot-msg .message__content h3,
.bot-msg .message__content h4,
.bot-msg .message__content h5,
.bot-msg .message__content h6 { margin: 14px 0 8px; font-weight: 700; line-height: 1.35; color: var(--cb-primary-dark); }

.bot-msg .message__content h1 { font-size: 17px; }
.bot-msg .message__content h2 { font-size: 16px; }
.bot-msg .message__content h3,
.bot-msg .message__content h4,
.bot-msg .message__content h5,
.bot-msg .message__content h6 { font-size: 15px; }

.bot-msg .message__content ul,
.bot-msg .message__content ol { margin: 6px 0 10px; padding-left: 20px; }

.bot-msg .message__content li { margin-bottom: 5px; }
    .bot-msg .message__content li::marker { color: var(--cb-accent); }

.bot-msg .message__content blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--cb-accent); background: #f0fdfa; border-radius: 0 8px 8px 0; color: #0f766e; }

.bot-msg .message__content code { padding: 1px 5px; border-radius: 5px; background: #eef2f7; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 12.5px; color: #0f172a; }

.bot-msg .message__content pre { margin: 8px 0; padding: 10px 12px; border-radius: 10px; background: #0f172a; color: #e2e8f0; overflow-x: auto; }

    .bot-msg .message__content pre code { background: transparent; color: inherit; padding: 0; }

.bot-msg .message__content table { width: 100%; margin: 8px 0; border-collapse: collapse; font-size: 13px; }

.bot-msg .message__content th,
.bot-msg .message__content td { padding: 6px 9px; border: 1px solid var(--cb-border); text-align: left; }

.bot-msg .message__content th { background: #eff6fb; font-weight: 600; }

.bot-msg .message__content hr { margin: 12px 0; border: none; border-top: 1px solid var(--cb-border); }

.bot-msg .message__content a { color: var(--cb-primary-dark); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; transition: color 0.2s ease; }

    .bot-msg .message__content a:hover { color: var(--cb-accent); }

/* ------------------------------------------------- Nguồn tham khảo -- */

.bot-sources { margin-top: 8px; padding-left: 4px; }

.bot-sources__label { display: block; margin-bottom: 5px; font-size: 11.5px; font-weight: 700; color: var(--cb-muted); text-transform: uppercase; letter-spacing: 0.03em; }

.bot-sources__list { display: flex; flex-wrap: wrap; gap: 6px; }

.source-link { display: inline-block; max-width: 100%; padding: 4px 11px; border: 1px solid #b9e6f0; border-radius: 999px; background: #ecfeff; color: #0e7490; font-size: 12px; font-weight: 600; text-decoration: none; transition: background 0.2s ease, transform 0.2s ease; }

    .source-link:hover { background: #cffafe; color: #0e7490; transform: translateY(-1px); text-decoration: none; }

/* ------------------------------------------------------ Đang soạn -- */

.typing-dots { display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; }

    .typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--cb-primary); opacity: 0.45; animation: cb-typing 1.3s infinite ease-in-out; }

        .typing-dots i:nth-child(2) { animation-delay: 0.18s; }
        .typing-dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes cb-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ------------------------------------------------- Gợi ý nhanh -- */

.chatbot-suggestions { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 14px 2px; background: var(--cb-surface); }

    .chatbot-suggestions.is-hidden { display: none; }

.chatbot-chip { padding: 6px 13px; border: 1px solid #cfe6f5; border-radius: 999px; background: #f4fbff; color: var(--cb-primary-dark); font-size: 12.5px; font-weight: 600; cursor: pointer; transition: background 0.2s ease, transform 0.2s ease, border-color 0.2s ease; }

    .chatbot-chip:hover { background: #e0f2fe; border-color: var(--cb-primary); transform: translateY(-1px); }

/* ---------------------------------------------------------- Nhập -- */

.chatbot-input { display: flex; align-items: flex-end; gap: 9px; padding: 12px 14px; background: var(--cb-surface); border-top: 1px solid var(--cb-border); }

#chatbot-input-field { flex: 1 1 auto; max-height: 110px; padding: 10px 15px; border: 1px solid var(--cb-border); border-radius: 18px; background: #f7fafc; color: var(--cb-text); font-family: inherit; font-size: 14px; line-height: 1.45; resize: none; outline: none; transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease; }

    #chatbot-input-field:focus { background: #fff; border-color: var(--cb-primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.16); }

#chatbot-send-btn { flex: 0 0 auto; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; border: none; border-radius: 50%; background: linear-gradient(135deg, var(--cb-primary), var(--cb-primary-dark)); color: #fff; font-size: 15px; cursor: pointer; box-shadow: 0 6px 14px rgba(3, 105, 161, 0.3); transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease; }

    #chatbot-send-btn:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(3, 105, 161, 0.36); }

    #chatbot-send-btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

/* ----------------------------------------------------- Responsive -- */

@media (max-width: 640px) {
    #chatbot-widget { bottom: 60px; right: 12px; }

        .chatbot-window,
        #chatbot-widget.is-expanded .chatbot-window { position: fixed; inset: 0; width: 100%; max-width: 100%; height: 100%; border-radius: 0; transform-origin: bottom center; }

        #chatbot-widget.is-minimized .chatbot-window { inset: auto 0 0 0; height: var(--cb-header-h); }

        #chatbot-widget.is-open .chatbot-launcher,
        #chatbot-expand-btn { display: none; }

    /* Chừa chỗ cho thanh home indicator trên iPhone */
    .chatbot-input { padding-bottom: max(12px, env(safe-area-inset-bottom)); }

    .message,
    #chatbot-widget.is-expanded .message { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
    #chatbot-widget *,
    #chatbot-widget *::before,
    #chatbot-widget *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
