/* =====================================================================
   TRỢ LÝ AI – nút chat góc phải dưới + khung chat
   ===================================================================== */
/* Màu riêng của khung chat – cố định, không ăn theo giao diện (giao diện đêm làm chữ bị chìm) */
:root { --ai-main: #2563eb; --ai-deep: #1e3a8a; --ai-link: #1d4ed8; }

body.has-ai #backToTop { bottom: calc(86px + env(safe-area-inset-bottom)); }

.ai-fab {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1035;
    width: 58px; height: 58px; border: 0; border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-main), var(--ai-deep));
    color: #fff; font-size: 24px; padding: 0;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .28), 0 0 0 4px rgba(255, 255, 255, .6);
    display: flex; align-items: center; justify-content: center;
    transition: transform .2s;
}
.ai-fab:hover { transform: scale(1.06); }
.ai-fab .ai-whale { width: 48px; height: 35px; animation: aiSwim 3.2s ease-in-out infinite; }
.ai-avatar .ai-whale { width: 30px; height: 22px; }
@keyframes aiSwim { 50% { transform: translateY(-3px) rotate(-4deg); } }
.ai-spark { transform-box: fill-box; transform-origin: center; animation: aiSpark 2.4s ease-in-out infinite; }
.ai-spark2 { animation-delay: 1.2s; }
@keyframes aiSpark { 50% { transform: scale(.55); opacity: .6; } }
@media (prefers-reduced-motion: reduce) { .ai-fab .ai-whale, .ai-spark { animation: none; } }
.ai-fab .ai-fab-dot {
    position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%;
    background: #22c55e; border: 2px solid #fff;
}
.ai-fab-hint {
    position: fixed; right: 84px; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 1035;
    background: #fff; color: #0f172a; font-size: 13px; font-weight: 600;
    padding: 8px 12px; border-radius: 12px 12px 2px 12px; box-shadow: 0 6px 20px rgba(15, 23, 42, .18);
    max-width: 220px; cursor: pointer; animation: aiHint .4s ease;
}
@keyframes aiHint { from { opacity: 0; transform: translateY(8px); } }
body.ai-open .ai-fab, body.ai-open .ai-fab-hint, body.ai-open #backToTop { display: none !important; }

.ai-panel {
    position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 1060;
    width: 380px; height: min(600px, calc(100vh - 110px)); height: min(600px, calc(100dvh - 110px));
    display: none; flex-direction: column; overflow: hidden;
    background: #fff; border-radius: 20px; box-shadow: 0 20px 60px rgba(15, 23, 42, .35);
    font-size: 14.5px; color: #0f172a;
}
body.ai-open .ai-panel { display: flex; animation: aiIn .22s ease; }
@keyframes aiIn { from { opacity: 0; transform: translateY(16px) scale(.98); } }

.ai-head {
    display: flex; align-items: center; gap: 10px; padding: 12px 14px; color: #fff;
    background: linear-gradient(135deg, var(--ai-main), var(--ai-deep));
}
.ai-avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .22); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.ai-head b { display: block; font-size: 15px; line-height: 1.2; }
.ai-head small { opacity: .85; font-size: 12px; }
.ai-head button { margin-left: auto; background: rgba(255, 255, 255, .18); color: #fff; border: 0; width: 34px; height: 34px; border-radius: 10px; }
.ai-head button + button { margin-left: 6px; }

.ai-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; overscroll-behavior: contain; }
.ai-msg { max-width: 86%; padding: 9px 12px; border-radius: 16px; line-height: 1.5; word-wrap: break-word; white-space: pre-wrap; }
.ai-msg.bot { background: #fff; border: 1px solid #e2e8f0; border-bottom-left-radius: 4px; align-self: flex-start; }
.ai-msg.me { background: var(--ai-main); color: #fff; border-bottom-right-radius: 4px; align-self: flex-end; }
.ai-msg.err { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; align-self: flex-start; }
.ai-msg a { color: var(--ai-link); font-weight: 600; text-decoration: underline; }
.ai-msg.me a { color: #fff; }
.ai-typing span { display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%; background: #94a3b8; animation: aiDot 1s infinite; }
.ai-typing span:nth-child(2) { animation-delay: .15s; } .ai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes aiDot { 50% { transform: translateY(-4px); opacity: .5; } }

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-chips button { border: 1px solid #cbd5e1; background: #fff; color: #1e293b; border-radius: 999px; padding: 5px 11px; font-size: 13px; }
.ai-chips button:hover { border-color: var(--ai-main); color: var(--ai-link); }

.ai-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e2e8f0; background: #fff; }
.ai-form textarea {
    flex: 1; resize: none; border: 1px solid #cbd5e1; border-radius: 14px; padding: 9px 12px;
    font-size: 16px; line-height: 1.35; max-height: 110px; outline: none;
}
.ai-form textarea:focus { border-color: var(--ai-main); box-shadow: 0 0 0 3px rgba(59, 130, 246, .15); }
.ai-form button { width: 44px; border: 0; border-radius: 14px; background: var(--ai-main); color: #fff; font-size: 17px; flex-shrink: 0; }
.ai-form button:disabled { opacity: .5; }
.ai-note { text-align: center; font-size: 11px; color: #94a3b8; padding: 0 10px 8px; background: #fff; }

@media (max-width: 575px) {
    .ai-panel { right: 0; left: 0; bottom: 0; width: auto; height: 82vh; height: 82dvh; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
