* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden; /* 防止移动端整体页面回弹和滚动 */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 50%, #fef3c7 100%);
    color: #334155;
}

/* 聊天页面样式 */
.chat-page {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(229, 231, 235, 0.5);
    z-index: 10;
    padding-top: max(16px, env(safe-area-inset-top));
}

.chat-logo {
    width: 149px;
    height: 40px;
    border-radius: 8px;
    padding: 4px 8px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)) 
            drop-shadow(0 0 2px rgba(0, 0, 0, 0.2));
}

.chat-title {
    font-size: 18px;
    font-weight: 600;
    color: #334155;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.new-chat-btn {
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
    border: none;
    padding: 10px 20px;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: white;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.new-chat-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
    background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
}

.chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    overflow: hidden; /* 内部内容滚动 */
    position: relative;
}

.welcome-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    width: 100%;
    padding: 40px 20px;
    overflow-y: auto;
}

.welcome-logo {
    width: 149px;
    height: 40px;
    border-radius: 8px;
    padding: 4px 8px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)) drop-shadow(0 0 2px rgba(0, 0, 0, 0.2));
}

.welcome-title {
    font-size: 22px;
    font-weight: 600;
    color: #1f2937;
    letter-spacing: 0.5px;
    margin-top: 8px;
}

.input-section {
    flex-shrink: 0;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 20px 40px 20px;
}

.input-wrapper {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 24px;
    padding: 12px 20px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.2);
}

.input-field {
    width: 100%;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    background: transparent;
    color: #1f2937;
    padding: 8px 0;
    line-height: 1.5;
}

.input-field::placeholder {
    color: #9ca3af;
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f3f4f6;
}

.quick-tags {
    display: flex;
    gap: 6px;
}

.quick-tag {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.quick-tag:hover {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #3b82f6;
}

.send-btn {
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: white;
    position: relative;
}

.send-btn:hover:not(:disabled):not(.stop-btn) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.send-btn:disabled {
    opacity: 0.4 !important;
    cursor: not-allowed !important;
    background: #d1d5db !important;
}

/* 停止按钮样式 */
.send-btn.stop-btn {
    background: linear-gradient(135deg, #f87171 0%, #ef4444 100%) !important;
    cursor: pointer !important;
    opacity: 1 !important;
}

.send-btn.stop-btn:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
}

.stop-btn-tooltip {
    position: absolute;
    bottom: 48px;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.send-btn.stop-btn:hover .stop-btn-tooltip {
    opacity: 1;
}

/* 消息列表 */
.messages-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 20px 20px 20px;
    display: none;
    scroll-behavior: smooth;
    /* 隐藏滚动条 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.messages-container::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.message {
    display: flex;
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}

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

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
    margin-right: 16px;
}

.user-message .message-avatar {
    background: linear-gradient(135deg, #94a3b8 0%, #cbd5e1 100%);
    color: white;
    order: 2;
    margin-right: 0;
    margin-left: 16px;
}

.ai-message .message-avatar {
    background: linear-gradient(135deg, #38bdf8 0%, #0ea5e9 100%);
    color: white;
}

.message-content {
    max-width: 85%;
    background: white;
    padding: 16px 20px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
    color: #334155;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.15);
}

.user-message {
    justify-content: flex-end;
}

.user-message .message-content {
    background: linear-gradient(135deg, #e0f2fe 0%, #f0f9ff 100%);
    color: #0c4a6e;
    border: 1px solid rgba(14, 165, 233, 0.2);
}

.ai-message .message-content {
    border: 1px solid rgba(148, 163, 184, 0.15);
}

/* Markdown 样式 */
.message-content.markdown {
    line-height: 1.7;
}

.message-content.markdown h1,
.message-content.markdown h2,
.message-content.markdown h3,
.message-content.markdown h4 {
    margin: 12px 0 8px 0;
    color: #0284c7;
    font-weight: 600;
}

.message-content.markdown h1 { font-size: 1.2em; }
.message-content.markdown h2 { font-size: 1.15em; }
.message-content.markdown h3 { font-size: 1.1em; }

.message-content.markdown p {
    margin: 8px 0;
}

.message-content.markdown ul,
.message-content.markdown ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-content.markdown li {
    margin: 4px 0;
}

.message-content.markdown strong {
    font-weight: 600;
    color: #0284c7;
}

.message-content.markdown code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', monospace;
    font-size: 0.9em;
    color: #475569;
}

.message-content.markdown pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.message-content.markdown pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.message-content.markdown blockquote {
    border-left: 3px solid #0ea5e9;
    padding-left: 12px;
    margin: 8px 0;
    color: #64748b;
    background: #f8fafc;
    padding: 8px 12px;
    border-radius: 0 8px 8px 0;
}

.message-content.markdown a {
    color: #0284c7;
    text-decoration: underline;
}

.message-content.markdown hr {
    border: none;
    border-top: 1px solid rgba(148, 163, 184, 0.3);
    margin: 10px 0;
}

.message-content.markdown table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}

.message-content.markdown th,
.message-content.markdown td {
    border: 1px solid rgba(148, 163, 184, 0.3);
    padding: 8px 12px;
    text-align: left;
}

.message-content.markdown th {
    background: #f1f5f9;
    font-weight: 600;
}

.error-message {
    color: #dc2626;
    background: #fef2f2;
    border-left: 3px solid #dc2626;
}

.loading-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 6px 0;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

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

@keyframes blink {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8);}
    40% { opacity: 1; transform: scale(1);}
}

.input-section.fixed-input {
    /* 在新弹性布局下，不再需要 position: fixed */
    padding: 12px 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

/* 响应式 */
@media (max-width: 768px) {
    .input-section.fixed-input {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    .chat-header {
        padding: 12px 16px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .chat-logo {
        width: 100px;
        height: 32px;
    }

    .chat-title {
        font-size: 15px;
    }

    .new-chat-btn {
        padding: 8px 16px;
        font-size: 14px;
    }

    .welcome-section {
        padding: 20px 16px;
        gap: 16px;
    }

    .welcome-logo {
        width: 120px;
        height: 36px;
    }

    .welcome-title {
        font-size: 18px;
        text-align: center;
        padding: 0 20px;
    }

    .input-section {
        padding: 0 12px 20px 12px;
    }

    .input-wrapper {
        padding: 10px 16px;
        border-radius: 20px;
    }

    .input-field {
        font-size: 15px;
    }

    .quick-tags {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        -ms-overflow-style: none;
        scrollbar-width: none;
        gap: 6px;
    }

    .quick-tags::-webkit-scrollbar {
        display: none;
    }

    .quick-tag {
        flex-shrink: 0;
        padding: 6px 12px;
        font-size: 12px;
    }

    .messages-container {
        padding: 16px 12px 16px 12px;
    }

    .message {
        margin-bottom: 16px;
    }

    .message-content {
        max-width: 95%;
        font-size: 16px;
        padding: 14px 18px;
        line-height: 1.6;
        border-radius: 18px;
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
        margin-right: 10px;
    }
    
    .user-message .message-avatar {
        margin-left: 10px;
        margin-right: 0;
    }
}

@media (max-width: 480px) {
    .chat-title {
        display: none; /* 小屏幕隐藏文字标题，保留 Logo */
    }

    .welcome-title {
        font-size: 16px;
    }

    .message-content {
        max-width: 92%;
    }
}
