/* ============================================
   CHAT WIDGET — 小问 Xiǎo Wèn
   ============================================ */

.chat-widget {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    font-family: var(--font-body, 'Inter', sans-serif);
}

/* ---- FAB Button ---- */
.chat-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #C41E3A 0%, #8B0000 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(196, 30, 58, 0.4);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    overflow: hidden;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 30px rgba(196, 30, 58, 0.5);
}

.fab-icon {
    font-family: 'Noto Serif SC', serif;
    font-size: 1.6rem;
    font-weight: 900;
    transition: all 0.3s ease;
}

.fab-close {
    position: absolute;
    font-size: 1.8rem;
    font-weight: 300;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
    transition: all 0.3s ease;
}

.chat-widget.open .fab-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.chat-widget.open .fab-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse animation when closed */
.chat-fab::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid rgba(196, 30, 58, 0.3);
    animation: fab-ping 2.5s ease-in-out infinite;
}

.chat-widget.open .chat-fab::before {
    animation: none;
    opacity: 0;
}

@keyframes fab-ping {
    0%, 100% { transform: scale(1); opacity: 0.6; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* ---- Chat Window ---- */
.chat-window {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: 380px;
    max-height: 520px;
    background: #fff;
    border: 1px solid #e0e0e0;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.chat-widget.open .chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ---- Header ---- */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    background: linear-gradient(135deg, #C41E3A 0%, #8B0000 100%);
    color: #fff;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.chat-avatar {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255,255,255,0.4);
    font-family: 'Noto Serif SC', serif;
    font-size: 1rem;
    font-weight: 900;
    flex-shrink: 0;
}

.chat-name {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.02em;
}

.chat-status {
    display: block;
    font-size: 0.7rem;
    opacity: 0.7;
}

.chat-minimize {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 0 0.3rem;
}

.chat-minimize:hover {
    opacity: 1;
}

/* ---- Messages ---- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    min-height: 250px;
    max-height: 340px;
    background: #fafafa;
}

.chat-msg {
    display: flex;
    gap: 0.5rem;
    max-width: 88%;
    animation: msg-in 0.3s ease;
}

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Noto Serif SC', serif;
    font-size: 0.75rem;
    font-weight: 900;
    flex-shrink: 0;
    background: #C41E3A;
    color: #fff;
}

.chat-msg.user .msg-avatar {
    background: #2E4057;
}

.msg-bubble {
    padding: 0.7rem 1rem;
    font-size: 0.88rem;
    line-height: 1.6;
    border: 1px solid #e8e8e8;
    background: #fff;
    color: #333;
    word-break: break-word;
}

.chat-msg.user .msg-bubble {
    background: #C41E3A;
    color: #fff;
    border-color: #C41E3A;
}

.msg-bubble strong {
    color: #C41E3A;
}

.chat-msg.user .msg-bubble strong {
    color: #ffd;
}

/* Streaming cursor */
.msg-bubble .stream-cursor::after {
    content: '▊';
    animation: blink-cursor 0.7s step-end infinite;
    color: #C41E3A;
    font-size: 0.85em;
}

.chat-msg.user .msg-bubble .stream-cursor::after {
    color: #ffd;
}

@keyframes blink-cursor {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Suggestions ---- */
.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid #f0f0f0;
    background: #fff;
    flex-shrink: 0;
}

.sug-btn {
    padding: 0.3rem 0.7rem;
    border: 1px solid #e0e0e0;
    background: #fff;
    cursor: pointer;
    font-size: 0.75rem;
    color: #666;
    font-family: inherit;
    transition: all 0.2s;
}

.sug-btn:hover {
    border-color: #C41E3A;
    color: #C41E3A;
}

/* ---- Input ---- */
.chat-input-area {
    display: flex;
    align-items: center;
    padding: 0.6rem;
    border-top: 1px solid #eee;
    background: #fff;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input-area input {
    flex: 1;
    padding: 0.6rem 0.8rem;
    border: 1px solid #e0e0e0;
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    transition: border-color 0.2s;
    background: #fafafa;
}

.chat-input-area input:focus {
    border-color: #C41E3A;
    background: #fff;
}

.chat-send {
    width: 36px;
    height: 36px;
    border: none;
    background: #C41E3A;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chat-send:hover {
    background: #8B0000;
}

.chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    .chat-window {
        width: calc(100vw - 2rem);
        right: -0.5rem;
        max-height: 70vh;
    }

    .chat-widget {
        bottom: 1rem;
        right: 1rem;
    }
}
