/* ==========================================================================
   Chatbot - 小黑 | Glassmorphism Chat Interface
   ========================================================================== */

/* Google Font */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap');

/* ---- Layout ---- */
.chatbot-container {
    max-width: 860px;
    margin: 40px auto;
    padding: 20px;
    animation: containerFadeIn 0.8s ease-out;
    font-family: 'Noto Sans SC', sans-serif;
}

@keyframes containerFadeIn {
    from { opacity: 0; transform: translateY(30px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---- Glass Card ---- */
.chatbot-card {
    background: rgba(255, 255, 255, 0.45);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(255, 183, 197, 0.18),
                inset 0 0 0 1px rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.25);
    display: flex;
    flex-direction: column;
    height: 80vh;
    min-height: 540px;
    max-height: 820px;
}

.dark-mode .chatbot-card {
    background: rgba(16, 24, 40, 0.55);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45),
                inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.06);
}

/* ---- Header ---- */
.chatbot-header {
    padding: 24px 28px;
    display: flex;
    align-items: center;
    gap: 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.18);
    background: linear-gradient(135deg, rgba(255, 183, 197, 0.12), rgba(255, 255, 255, 0.06));
    flex-shrink: 0;
}

.dark-mode .chatbot-header {
    border-bottom-color: rgba(255, 255, 255, 0.06);
    background: linear-gradient(135deg, rgba(255, 183, 197, 0.06), rgba(16, 24, 40, 0.1));
}

/* Avatar */
.character-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(255, 105, 180, 0.25);
    border: 2.5px solid rgba(255, 183, 197, 0.6);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.character-avatar:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(255, 105, 180, 0.4);
}

.character-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-text h1 {
    margin: 0;
    color: var(--link-color);
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.header-text p {
    margin: 4px 0 0;
    font-style: italic;
    color: var(--text-color);
    opacity: 0.7;
    font-size: 0.88rem;
}

/* ---- Status Indicator ---- */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 6px;
    animation: pulse 2s infinite;
    vertical-align: middle;
}

@keyframes pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
    50%      { opacity: 0.7; box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}

/* ---- Chat Body (Messages) ---- */
.chatbot-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 183, 197, 0.3) transparent;
}

.chatbot-body::-webkit-scrollbar {
    width: 6px;
}

.chatbot-body::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-body::-webkit-scrollbar-thumb {
    background: rgba(255, 183, 197, 0.3);
    border-radius: 3px;
}

.dark-mode .chatbot-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
}

/* ---- Welcome Message ---- */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-color);
    opacity: 0.6;
    font-size: 0.92rem;
    line-height: 1.8;
}

.welcome-message .welcome-emoji {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 12px;
}

/* ---- Message Bubbles ---- */
.message-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    animation: messageSlideIn 0.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    opacity: 0;
}

.message-row.user-row {
    flex-direction: row-reverse;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-bubble {
    max-width: 72%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.94rem;
    line-height: 1.7;
    word-break: break-word;
    position: relative;
}

/* Bot message */
.bot-message .message-bubble {
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 18px 18px 18px 4px;
    color: var(--text-color);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
}

.dark-mode .bot-message .message-bubble {
    background: rgba(30, 40, 60, 0.6);
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

/* User message */
.user-message .message-bubble {
    background: linear-gradient(135deg, #FFB7C5 0%, #FF8FAB 100%);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    border: none;
    box-shadow: 0 4px 16px rgba(255, 143, 171, 0.3);
}

.dark-mode .user-message .message-bubble {
    background: linear-gradient(135deg, #c77dba 0%, #9b59b6 100%);
    box-shadow: 0 4px 16px rgba(155, 89, 182, 0.3);
}

/* ---- Typing Indicator ---- */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 20px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--link-color);
    opacity: 0.5;
    animation: typingBounce 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-8px); opacity: 1; }
}

/* ---- Input Area ---- */
.chatbot-input-area {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-shrink: 0;
}

.dark-mode .chatbot-input-area {
    border-top-color: rgba(255, 255, 255, 0.06);
    background: rgba(16, 24, 40, 0.35);
}

#chat-input {
    flex: 1;
    padding: 12px 18px;
    border-radius: 16px;
    border: 1.5px solid rgba(255, 183, 197, 0.35);
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    font-size: 0.95rem;
    font-family: 'Noto Sans SC', sans-serif;
    color: var(--text-color);
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
    resize: none;
    min-height: 20px;
    max-height: 100px;
    line-height: 1.5;
}

#chat-input::placeholder {
    color: var(--text-color);
    opacity: 0.4;
}

#chat-input:focus {
    border-color: var(--link-color);
    box-shadow: 0 0 0 3px rgba(255, 105, 180, 0.12);
    background: rgba(255, 255, 255, 0.7);
}

.dark-mode #chat-input {
    background: rgba(30, 40, 60, 0.5);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-mode #chat-input:focus {
    border-color: var(--link-color);
    box-shadow: 0 0 0 3px rgba(255, 183, 197, 0.1);
    background: rgba(30, 40, 60, 0.7);
}

/* Send button */
#chat-send {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #FFB7C5, #FF69B4);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.3s, opacity 0.3s;
    box-shadow: 0 4px 14px rgba(255, 105, 180, 0.3);
    flex-shrink: 0;
}

#chat-send:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(255, 105, 180, 0.45);
}

#chat-send:active:not(:disabled) {
    transform: scale(0.95);
}

#chat-send:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.dark-mode #chat-send {
    background: linear-gradient(135deg, #c77dba, #9b59b6);
    box-shadow: 0 4px 14px rgba(155, 89, 182, 0.3);
}

/* Send icon SVG */
#chat-send svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Loading animation inside send button */
.send-loading {
    display: flex;
    gap: 3px;
    align-items: center;
}

.send-loading span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #fff;
    animation: typingBounce 1.2s infinite;
}

.send-loading span:nth-child(2) { animation-delay: 0.15s; }
.send-loading span:nth-child(3) { animation-delay: 0.3s; }

/* ---- Footer ---- */
.chatbot-footer {
    padding: 14px 20px;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-color);
    opacity: 0.45;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

/* ---- Connection Status Bar ---- */
.connection-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 28px;
    background: rgba(255, 255, 255, 0.12);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    font-size: 0.78rem;
    min-height: 32px;
}

.dark-mode .connection-bar {
    background: rgba(0, 0, 0, 0.15);
}

.conn-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-color);
    opacity: 0.7;
}

.conn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9ca3af;
    transition: background 0.4s, box-shadow 0.4s;
    flex-shrink: 0;
}

.conn-dot.conn-online {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.6);
    animation: connPulse 2.5s infinite;
}

.conn-dot.conn-offline {
    background: #ef4444;
    box-shadow: 0 0 4px rgba(239, 68, 68, 0.4);
}

.conn-dot.conn-warn {
    background: #f59e0b;
    box-shadow: 0 0 4px rgba(245, 158, 11, 0.4);
}

@keyframes connPulse {
    0%, 100% { box-shadow: 0 0 6px rgba(34, 197, 94, 0.6); }
    50%      { box-shadow: 0 0 12px rgba(34, 197, 94, 0.3); }
}

.conn-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    letter-spacing: 0.5px;
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-color);
    opacity: 0.5;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: all 0.4s;
}

.conn-badge svg {
    flex-shrink: 0;
}

.conn-badge.badge-online {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
    color: #16a34a;
    opacity: 0.85;
}

.dark-mode .conn-badge.badge-online {
    background: rgba(34, 197, 94, 0.1);
    color: #4ade80;
}

.conn-badge.badge-offline {
    background: rgba(239, 68, 68, 0.06);
    border-color: rgba(239, 68, 68, 0.15);
    color: #dc2626;
    opacity: 0.7;
}

.dark-mode .conn-badge.badge-offline {
    color: #fca5a5;
}

.conn-badge.badge-warn {
    background: rgba(245, 158, 11, 0.06);
    border-color: rgba(245, 158, 11, 0.15);
    color: #d97706;
    opacity: 0.7;
}

.dark-mode .conn-badge {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.06);
}

/* ---- Thinking Indicator ---- */
.thinking-bubble {
    display: flex;
    align-items: center;
}

.thinking-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--link-color);
    opacity: 0.5;
    animation: typingBounce 1.4s infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.thinking-text {
    font-size: 0.82rem;
    color: var(--text-color);
    opacity: 0.55;
    font-style: italic;
    animation: thinkFade 2s ease-in-out infinite;
}

@keyframes thinkFade {
    0%, 100% { opacity: 0.55; }
    50%      { opacity: 0.3; }
}

/* ---- Markdown Content Styling ---- */
.message-bubble p {
    margin: 0 0 8px 0;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'Consolas', 'Monaco', monospace;
}

.dark-mode .message-bubble code {
    background: rgba(255, 255, 255, 0.08);
}

.message-bubble pre {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    padding: 14px;
    overflow-x: auto;
    margin: 8px 0;
}

.dark-mode .message-bubble pre {
    background: rgba(0, 0, 0, 0.25);
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble ul, .message-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}

.message-bubble blockquote {
    border-left: 3px solid var(--link-color);
    margin: 8px 0;
    padding: 4px 12px;
    opacity: 0.85;
}

/* ---- Error message ---- */
.error-bubble .message-bubble {
    background: rgba(239, 68, 68, 0.12) !important;
    border-color: rgba(239, 68, 68, 0.25) !important;
    color: #dc2626;
}

.dark-mode .error-bubble .message-bubble {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #fca5a5;
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .chatbot-container {
        margin: 16px auto;
        padding: 10px;
    }

    .chatbot-card {
        border-radius: 18px;
        height: 85vh;
    }

    .chatbot-header {
        padding: 16px 18px;
        gap: 12px;
    }

    .character-avatar {
        width: 48px;
        height: 48px;
    }

    .header-text h1 {
        font-size: 1.2rem;
    }

    .chatbot-body {
        padding: 16px 14px;
    }

    .message-bubble {
        max-width: 84%;
        font-size: 0.9rem;
    }

    .chatbot-input-area {
        padding: 12px 14px;
    }

    #chat-input {
        padding: 10px 14px;
    }

    .connection-bar {
        padding: 6px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .conn-badge {
        font-size: 0.65rem;
    }
}

