/* ========================================
   手机版聊天页面样式
   ======================================== */

:root {
    --primary: #8b5cf6;
    --primary-light: #a78bfa;
    --bg-dark: #0a0a0f;
    --bg-card: #13131a;
    --bg-input: #1f1f2e;
    --bg-hover: #252536;
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --border: #27272a;
    --success: #22c55e;
    --accent: #06b6d4;
    --gradient-1: linear-gradient(135deg, #8b5cf6 0%, #06b6d4 100%);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
}

/* ========== 顶部导航栏 ========== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    font-size: 24px;
}

.title {
    font-size: 18px;
    font-weight: 600;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 环境切换按钮 */
.env-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.env-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.env-dot.prod {
    background: var(--accent);
}

/* 小图标按钮 */
.icon-btn {
    width: 36px;
    height: 36px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 菜单按钮 */
.menu-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ========== 菜单面板 ========== */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 100;
}

.menu-overlay.open {
    opacity: 1;
    visibility: visible;
}

.menu-panel {
    position: fixed;
    top: 60px;
    right: 10px;
    width: 200px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 0;
    transform: translateY(-10px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 101;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.menu-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

.menu-item:active {
    background: var(--bg-hover);
}

.mode-check {
    margin-left: auto;
    color: var(--primary);
    font-weight: bold;
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 8px 0;
}

/* ========== 对话区域 ========== */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 欢迎页 */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
}

.welcome-icon {
    width: 64px;
    height: 64px;
    background: var(--gradient-1);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.3);
}

.welcome h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome p {
    color: var(--text-secondary);
    font-size: 15px;
    margin-bottom: 30px;
}

/* 快捷查询 */
.quick-queries {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 320px;
}

.quick-query {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 14px 12px;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    transition: all 0.15s;
}

.quick-query:active {
    background: var(--bg-hover);
    border-color: var(--primary);
    transform: scale(0.98);
}

/* ========== 消息样式 ========== */
.message {
    max-width: 85%;
    animation: slideIn 0.25s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-bubble {
    padding: 14px 16px;
    border-radius: 18px;
}

.message.user .message-bubble {
    background: var(--gradient-1);
    color: white;
    border-bottom-right-radius: 6px;
}

.message.assistant .message-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

/* Markdown 样式覆盖 */
.message.assistant .markdown-body {
    background: transparent !important;
    color: var(--text-primary) !important;
    font-size: 14px;
    line-height: 1.6;
}

.message.assistant .markdown-body p {
    margin-bottom: 10px;
}

.message.assistant .markdown-body p:last-child {
    margin-bottom: 0;
}

.message.assistant .markdown-body pre {
    background: var(--bg-dark) !important;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    font-size: 12px;
}

.message.assistant .markdown-body code {
    background: var(--bg-input) !important;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message.assistant .markdown-body table {
    font-size: 13px;
    display: block;
    overflow-x: auto;
}

.message.assistant .markdown-body ul,
.message.assistant .markdown-body ol {
    padding-left: 20px;
}

/* 加载动画 */
.loading-dots {
    display: flex;
    gap: 6px;
    padding: 4px 0;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.2s infinite ease-in-out;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.3s;
}

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

@keyframes pulse {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 进度提示点点闪烁动画 */
@keyframes blink {

    0%,
    100% {
        opacity: 0.2;
    }

    50% {
        opacity: 1;
    }
}

/* ========== 输入区域 ========== */
.input-area {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 6px 6px 16px;
    align-items: flex-end;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
}

.input-field {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 0;
    color: var(--text-primary);
    font-size: 16px;
    resize: none;
    min-height: 24px;
    max-height: 100px;
    font-family: inherit;
    line-height: 1.4;
}

.input-field:focus {
    outline: none;
}

.input-field::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--gradient-1);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.send-btn:disabled {
    background: var(--bg-hover);
    box-shadow: none;
}

.send-btn:active {
    transform: scale(0.95);
}

/* 发送按钮加载动画 */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ========== 浅色主题 ========== */
body.light-theme {
    --bg-dark: #f8fafc;
    --bg-card: #ffffff;
    --bg-input: #f1f5f9;
    --bg-hover: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
}

body.light-theme .title {
    background: var(--primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

body.light-theme .message.assistant .markdown-body {
    color: var(--text-primary) !important;
}

body.light-theme .message.assistant .markdown-body pre {
    background: #f1f5f9 !important;
    border-color: var(--border);
}

body.light-theme .message.assistant .markdown-body code {
    background: #e2e8f0 !important;
}

/* ========== 历史对话弹窗 ========== */
.history-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
    z-index: 300;
    padding: 20px;
}

.history-modal.open {
    opacity: 1;
    visibility: visible;
}

.history-modal-content {
    background: var(--bg-card);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-primary);
}

.history-modal-header button {
    width: 32px;
    height: 32px;
    background: var(--bg-input);
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 16px;
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px;
    border-radius: 10px;
    margin-bottom: 4px;
    position: relative;
    transition: background 0.15s;
}

.history-item:active {
    background: var(--bg-hover);
}

.history-item-title {
    flex: 1;
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 30px;
}

.history-item-time {
    font-size: 12px;
    color: var(--text-muted);
    width: 100%;
    margin-top: 4px;
}

.history-item-delete {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
}

.history-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 14px;
}