:root {
    --primary: #1a56db;
    --primary-light: #e8f0fe;
    --bg: #f5f7fa;
    --white: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --ai-bubble: #ffffff;
    --user-bubble: #1a56db;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

.page { display: none; height: 100dvh; }
.page.active { display: flex; flex-direction: column; }

/* ===== 登录页 ===== */
.login-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.login-header {
    text-align: center;
    margin-bottom: 40px;
}

.logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: var(--primary);
    color: white;
    font-size: 20px;
    font-weight: 700;
    border-radius: 16px;
    margin-bottom: 16px;
    letter-spacing: 1px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-light);
    font-size: 14px;
}

.login-form {
    width: 100%;
    max-width: 320px;
}

.login-form label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text);
}

.login-form input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.login-form input:focus {
    border-color: var(--primary);
}

.suggestions {
    margin-top: 4px;
    max-height: 160px;
    overflow-y: auto;
    border-radius: 8px;
    background: var(--white);
    box-shadow: var(--shadow);
    display: none;
}

.suggestions.show { display: block; }

.suggestion-item {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid var(--border);
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item:active { background: var(--primary-light); }

#start-btn {
    width: 100%;
    padding: 12px;
    margin-top: 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s;
}

#start-btn:disabled { opacity: 0.5; cursor: not-allowed; }
#start-btn:hover:not(:disabled) { opacity: 0.9; }

.error-text {
    color: #dc2626;
    font-size: 13px;
    margin-top: 8px;
    text-align: center;
    min-height: 20px;
}

/* ===== 聊天页 ===== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--white);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
}

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

.step-badge {
    background: var(--primary);
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
}

.step-name {
    font-size: 13px;
    color: var(--text-light);
}

.progress-bar {
    height: 3px;
    background: var(--border);
    flex-shrink: 0;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.5s ease;
}

/* 消息区域 */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

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

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

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

.message .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.ai .avatar {
    background: var(--primary-light);
    color: var(--primary);
    margin-right: 8px;
}

.message .bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
}

.message.ai .bubble {
    background: var(--ai-bubble);
    color: var(--text);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow);
}

.message.user .bubble {
    background: var(--user-bubble);
    color: white;
    border-top-right-radius: 4px;
}

/* 打字指示器 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #d1d5db;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* 步骤完成提示 */
.step-complete-notice {
    text-align: center;
    padding: 12px;
    margin: 8px 0;
    color: var(--primary);
    font-size: 13px;
    font-weight: 500;
}

/* 输入区域 */
.input-area {
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    background: var(--white);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg);
    border-radius: 20px;
    padding: 4px 4px 4px 16px;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
    padding: 8px 0;
    font-family: inherit;
}

#send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}

#send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* 弹窗 */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.show { display: flex; }

.modal-content {
    background: var(--white);
    border-radius: 20px;
    padding: 32px 24px;
    text-align: center;
    max-width: 340px;
    width: 100%;
}

.modal-icon { font-size: 48px; margin-bottom: 16px; }
.modal-content h2 { font-size: 20px; margin-bottom: 8px; }
.modal-content p { color: var(--text-light); font-size: 14px; margin-bottom: 24px; }

.download-btn {
    display: block;
    padding: 12px;
    background: var(--primary);
    color: white;
    text-decoration: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 12px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 14px;
    cursor: pointer;
    padding: 8px;
}

/* ===== 重试按钮 ===== */
.retry-prompt {
    text-align: center;
    padding: 12px 16px;
}
.retry-prompt p {
    color: #dc2626;
    font-size: 13px;
    margin-bottom: 8px;
}
.retry-btn {
    padding: 8px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
}
.retry-btn:active {
    opacity: 0.8;
}

/* ===== 等待提示文字 ===== */
.typing-tip {
    display: block;
    font-size: 12px;
    color: var(--text-light);
    margin-top: 6px;
}

/* ===== 手机端适配 ===== */
@media (max-width: 480px) {
    .login-header { margin-bottom: 24px; }
    .login-header h1 { font-size: 20px; }
    .logo { width: 52px; height: 52px; font-size: 16px; }

    .chat-header { padding: 10px 12px; }
    .header-title { font-size: 15px; }
    .step-badge { font-size: 11px; padding: 2px 6px; }
    .step-name { font-size: 12px; }

    .messages { padding: 12px 8px; }
    .message.ai .bubble,
    .message.user .bubble {
        max-width: 88%;
        font-size: 14px;
        padding: 10px 12px;
        line-height: 1.6;
    }
    .avatar { width: 28px; height: 28px; font-size: 11px; flex-shrink: 0; }

    .input-area { padding: 8px; }
    .input-wrapper textarea {
        font-size: 16px; /* 防止iOS自动缩放 */
        padding: 10px 12px;
    }

    .pdf-prompt p { font-size: 13px; }
    .pdf-btn { font-size: 14px; padding: 10px 20px; width: 100%; }
    .retry-btn { width: 100%; }
}

/* iOS键盘弹出时的安全区域 */
.input-area {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

/* 防止iOS橡皮筋滚动影响布局 */
.messages {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
