/* ==================== 主题变量定义 ==================== */

/* 默认主题：蓝色（商务蓝） */
:root,
.theme-blue {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #6366f1;
    --primary-soft: #eef2ff;
    --primary-bg: #f5f7fb;
    --gradient-start: #4f46e5;
    --gradient-end: #7c3aed;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --card-bg: #ffffff;
    --user-msg-bg: #4f46e5;
    --bot-msg-bg: #f3f4f6;
    --hover-bg: #f9fafb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* 红色主题（活力红） */
.theme-red {
    --primary: #dc2626;
    --primary-dark: #b91c1c;
    --primary-light: #ef4444;
    --primary-soft: #fef2f2;
    --primary-bg: #fef2f2;
    --gradient-start: #dc2626;
    --gradient-end: #b91c1c;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #fecaca;
    --card-bg: #ffffff;
    --user-msg-bg: #dc2626;
    --bot-msg-bg: #fef2f2;
    --hover-bg: #fef2f2;
    --shadow: 0 1px 3px rgba(220,38,38,0.1);
}

/* 绿色主题（自然绿） */
.theme-green {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #34d399;
    --primary-soft: #ecfdf5;
    --primary-bg: #ecfdf5;
    --gradient-start: #10b981;
    --gradient-end: #059669;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #a7f3d0;
    --card-bg: #ffffff;
    --user-msg-bg: #10b981;
    --bot-msg-bg: #ecfdf5;
    --hover-bg: #ecfdf5;
    --shadow: 0 1px 3px rgba(16,185,129,0.1);
}

/* 橙色主题（暖橙） */
.theme-orange {
    --primary: #f59e0b;
    --primary-dark: #d97706;
    --primary-light: #fbbf24;
    --primary-soft: #fffbeb;
    --primary-bg: #fffbeb;
    --gradient-start: #f59e0b;
    --gradient-end: #d97706;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #fde68a;
    --card-bg: #ffffff;
    --user-msg-bg: #f59e0b;
    --bot-msg-bg: #fffbeb;
    --hover-bg: #fffbeb;
    --shadow: 0 1px 3px rgba(245,158,11,0.1);
}

/* 黑灰主题（商务黑） */
.theme-dark {
    --primary: #374151;
    --primary-dark: #1f2937;
    --primary-light: #4b5563;
    --primary-soft: #f3f4f6;
    --primary-bg: #f9fafb;
    --gradient-start: #374151;
    --gradient-end: #1f2937;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-light: #9ca3af;
    --border: #d1d5db;
    --card-bg: #ffffff;
    --user-msg-bg: #374151;
    --bot-msg-bg: #f3f4f6;
    --hover-bg: #f9fafb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ==================== 全局样式 ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background: var(--primary-bg);
    transition: background 0.2s ease;
}

/* ==================== 主题切换按钮 ==================== */
.theme-switcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    gap: 8px;
    background: var(--card-bg);
    padding: 8px 12px;
    border-radius: 40px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border: 1px solid var(--border);
}

.theme-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--primary);
}

.theme-blue-btn { background: #4f46e5; }
.theme-red-btn { background: #dc2626; }
.theme-green-btn { background: #10b981; }
.theme-orange-btn { background: #f59e0b; }
.theme-dark-btn { background: #374151; }

/* 桌面端显示在右上角 */
@media (min-width: 768px) {
    .theme-switcher {
        position: fixed;
        top: 20px;
        right: 20px;
        bottom: auto;
        background: rgba(255,255,255,0.9);
        backdrop-filter: blur(8px);
    }
}

/* ==================== 聊天容器 ==================== */
.chat-container {
    width: 100%;
    max-width: 800px;
    height: 100%;
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: none;
    transition: background 0.2s ease;
}

@media (min-width: 768px) {
    body {
        padding: 16px;
        height: 100vh;
    }
    .chat-container {
        height: calc(100vh - 32px);
        border-radius: 28px;
        box-shadow: var(--shadow);
    }
}

/* ==================== 头部 ==================== */
.chat-header {
    background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
    color: white;
    padding: 16px 20px;
    text-align: center;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.chat-header h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
    font-weight: 600;
}

.chat-header p {
    font-size: 0.75rem;
    opacity: 0.9;
}

.header-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.header-btn {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    backdrop-filter: blur(4px);
    padding: 6px 14px;
    border-radius: 40px;
    font-size: 0.7rem;
    text-decoration: none;
    color: white;
    font-weight: 500;
    transition: 0.2s;
}

.header-btn:active {
    background: rgba(255,255,255,0.3);
    transform: scale(0.96);
}

/* ==================== 消息区域 ==================== */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--primary-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
    transition: background 0.2s ease;
}

.message {
    display: flex;
    animation: fadeInUp 0.2s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px);}
    to { opacity: 1; transform: translateY(0);}
}

.user-message {
    justify-content: flex-end;
}

.bot-message {
    justify-content: flex-start;
}

.bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    line-height: 1.45;
    word-wrap: break-word;
    word-break: break-word;
}

.user-message .bubble {
    background: var(--user-msg-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.bot-message .bubble {
    background: var(--bot-msg-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.bubble a {
    color: var(--primary);
    text-decoration: none;
    word-break: break-all;
}

.bubble a:active {
    opacity: 0.7;
}

.bubble img {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 6px;
}

.reply-content {
    word-break: break-word;
}

/* ==================== 输入区域 ==================== */
.input-area {
    background: var(--card-bg);
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
    transition: background 0.2s ease;
}

.input-area input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 30px;
    font-size: 1rem;
    outline: none;
    transition: 0.2s;
    background: var(--primary-bg);
    font-family: inherit;
    -webkit-appearance: none;
    color: var(--text-primary);
}

.input-area input:focus {
    border-color: var(--primary);
    background: var(--card-bg);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.input-area button {
    background: var(--primary);
    border: none;
    color: white;
    padding: 0 18px;
    height: 46px;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.9rem;
    font-family: inherit;
    flex-shrink: 0;
}

.input-area button:active {
    transform: scale(0.96);
    background: var(--primary-dark);
}

.clear-btn {
    background: var(--border) !important;
    color: var(--text-secondary) !important;
}

.clear-btn:active {
    background: var(--text-light) !important;
}

.empty-chat {
    text-align: center;
    color: var(--text-light);
    margin-top: 60px;
    font-size: 0.85rem;
}

.footer-tip {
    font-size: 0.65rem;
    text-align: center;
    padding: 8px 12px;
    color: var(--text-light);
    background: var(--primary-bg);
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    transition: background 0.2s ease;
}

/* ==================== 滚动条 ==================== */
.messages-area::-webkit-scrollbar {
    width: 4px;
}

.messages-area::-webkit-scrollbar-track {
    background: var(--border);
    border-radius: 4px;
}

.messages-area::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 4px;
}

/* ==================== 表单样式 ==================== */
details summary {
    cursor: pointer;
    outline: none;
    font-size: 0.85rem;
}

details summary::-webkit-details-marker {
    color: var(--primary);
}

.loading-dots {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light);
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}
