/* ============================================
   AI Chatbox – Tuồng Huế Knowledge Assistant
   ============================================ */

/* Google Font for chat */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ---------- Floating toggle button ---------- */
.chatbox-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FFB800 0%, #FF8C00 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(255, 184, 0, 0.45),
                0 2px 8px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: transform 0.35s cubic-bezier(.4,0,.2,1),
                box-shadow 0.35s ease;
    animation: chatPulse 2.5s ease-in-out infinite;
}
.chatbox-toggle:hover {
    transform: scale(1.12);
    box-shadow: 0 8px 28px rgba(255, 184, 0, 0.55),
                0 4px 12px rgba(0, 0, 0, 0.35);
    animation: none;
}
.chatbox-toggle i {
    font-size: 26px;
    color: #1a1a1a;
    transition: transform 0.3s ease;
}
.chatbox-toggle.active i {
    transform: rotate(90deg);
}

@keyframes chatPulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(255, 184, 0, 0.45), 0 2px 8px rgba(0,0,0,0.3); }
    50% { box-shadow: 0 6px 30px rgba(255, 184, 0, 0.65), 0 4px 14px rgba(0,0,0,0.35); }
}

/* Badge – new msg indicator */
.chatbox-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ff3d3d;
    border-radius: 50%;
    border: 2px solid #1a1a1a;
    display: none;
    animation: badgePop 0.3s ease;
}
@keyframes badgePop {
    0% { transform: scale(0); }
    60% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ---------- Chatbox panel ---------- */
.chatbox-panel {
    position: fixed;
    bottom: 100px;
    right: 28px;
    width: 480px;
    max-height: 680px;
    background: rgba(22, 22, 26, 0.96);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border-radius: 20px;
    border: 1px solid rgba(255, 184, 0, 0.18);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55),
                0 0 0 1px rgba(255, 255, 255, 0.04);
    z-index: 10001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(.4,0,.2,1),
                transform 0.35s cubic-bezier(.4,0,.2,1);
}
.chatbox-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ---------- Header ---------- */
.chatbox-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, rgba(255,184,0,0.12) 0%, rgba(255,140,0,0.06) 100%);
    border-bottom: 1px solid rgba(255,184,0,0.12);
    flex-shrink: 0;
}
.chatbox-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #FFB800 0%, #FF8C00 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.chatbox-avatar i {
    font-size: 18px;
    color: #1a1a1a;
}
.chatbox-header-info {
    flex: 1;
    min-width: 0;
}
.chatbox-header-info h4 {
    margin: 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #f0f0f0;
    line-height: 1.2;
}
.chatbox-header-info span {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    color: #62d96b;
    display: flex;
    align-items: center;
    gap: 5px;
}
.chatbox-header-info span::before {
    content: '';
    width: 6px;
    height: 6px;
    background: #62d96b;
    border-radius: 50%;
    display: inline-block;
    animation: statusBlink 1.8s ease-in-out infinite;
}
@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}
.chatbox-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255,255,255,0.06);
    color: #aaa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 14px;
}
.chatbox-close:hover {
    background: rgba(255,60,60,0.15);
    color: #ff6b6b;
}

/* ---------- Messages area ---------- */
.chatbox-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    min-height: 360px;
    max-height: 480px;
}
.chatbox-messages::-webkit-scrollbar {
    width: 6px;
}
.chatbox-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chatbox-messages::-webkit-scrollbar-thumb {
    background: rgba(255,184,0,0.25);
    border-radius: 10px;
}
.chatbox-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255,184,0,0.35);
}

/* Individual message */
.chat-msg {
    display: flex;
    gap: 8px;
    animation: msgSlideIn 0.3s ease;
    max-width: 100%;
}
@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.chat-msg.bot {
    align-self: flex-start;
}
.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    margin-top: 2px;
}
.chat-msg.bot .chat-msg-avatar {
    background: linear-gradient(135deg, #FFB800, #FF8C00);
    color: #1a1a1a;
}
.chat-msg.user .chat-msg-avatar {
    background: rgba(100, 140, 255, 0.2);
    color: #648cff;
}
.chat-msg-bubble {
    padding: 12px 16px;
    border-radius: 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    line-height: 1.6;
    max-width: 85%;
    word-wrap: break-word;
}
.chat-msg.bot .chat-msg-bubble {
    background: rgba(255,255,255,0.06);
    color: #e0e0e0;
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(255,255,255,0.05);
}
.chat-msg.user .chat-msg-bubble {
    background: linear-gradient(135deg, rgba(255,184,0,0.18) 0%, rgba(255,140,0,0.12) 100%);
    color: #f5f5f5;
    border-bottom-right-radius: 4px;
    border: 1px solid rgba(255,184,0,0.15);
}

/* Result cards inside bot messages */
.chat-result-card {
    display: block;
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(255,184,0,0.07);
    border: 1px solid rgba(255,184,0,0.12);
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.25s ease;
}
.chat-result-card:hover {
    background: rgba(255,184,0,0.14);
    border-color: rgba(255,184,0,0.25);
    transform: translateX(3px);
}
.chat-result-card .card-type {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #FFB800;
    background: rgba(255,184,0,0.1);
    padding: 2px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
}
.chat-result-card .card-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #f0f0f0;
    margin: 4px 0 2px;
    line-height: 1.3;
}
.chat-result-card .card-excerpt {
    font-size: 0.73rem;
    color: #999;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 14px;
}
.chat-typing .dot {
    width: 7px;
    height: 7px;
    background: #FFB800;
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
}
.chat-typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Suggested questions (chips) */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}
.chat-chip {
    display: inline-block;
    padding: 5px 12px;
    background: rgba(255,184,0,0.08);
    border: 1px solid rgba(255,184,0,0.18);
    border-radius: 20px;
    color: #FFB800;
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}
.chat-chip:hover {
    background: rgba(255,184,0,0.18);
    border-color: rgba(255,184,0,0.35);
    transform: translateY(-1px);
}

/* ---------- Input area ---------- */
.chatbox-input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid rgba(255,255,255,0.06);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}
.chatbox-input {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px 16px;
    color: #e0e0e0;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    resize: none;
    min-height: 44px;
    max-height: 100px;
}
.chatbox-input::placeholder {
    color: #666;
}
.chatbox-input:focus {
    border-color: rgba(255,184,0,0.4);
    box-shadow: 0 0 0 3px rgba(255,184,0,0.1);
}
.chatbox-send {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #FFB800 0%, #FF8C00 100%);
    color: #1a1a1a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    transition: all 0.25s ease;
    flex-shrink: 0;
}
.chatbox-send:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(255,184,0,0.35);
}
.chatbox-send:active {
    transform: scale(0.95);
}
.chatbox-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    .chatbox-panel {
        right: 8px;
        left: 8px;
        bottom: 90px;
        width: auto;
        max-height: 70vh;
        border-radius: 16px;
    }
    .chatbox-toggle {
        bottom: 18px;
        right: 18px;
        width: 54px;
        height: 54px;
    }
}
