/* =============================================================================
 * 通义千问 Demo 公共样式
 *
 * 设计说明：
 *   - 深色主题，CSS 变量集中管理颜色，后续改主题只改 :root
 *   - 类名约定：demo-* 页面结构，msg.* 聊天气泡，btn 按钮，hints 快捷提示
 * ============================================================================= */

/* --- 主题色变量 --- */
:root {
    --bg: #0f0f1a;
    --bg-card: #1a1a2e;
    --bg-input: #16213e;
    --border: #2a2a4a;
    --text: #e8e8f0;
    --text-muted: #8888aa;
    --primary: #6366f1;
    --primary-light: #818cf8;
    --accent: #a78bfa;
    --success: #34d399;
    --warning: #fbbf24;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* --- 全局重置与页面基础 --- */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 布局 ===== */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}

/* --- 顶栏导航 --- */
.navbar {
    background: rgba(26, 26, 46, 0.95);
    border-bottom: 1px solid var(--border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.navbar .logo {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.navbar .logo:hover {
    color: var(--text);
    text-decoration: none;
}

.navbar .logo-img {
    height: 28px;
    width: auto;
    display: block;
    object-fit: contain;
}

.navbar .back {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-left: auto;
}

.navbar .back:hover { color: var(--primary-light); text-decoration: none; }

/* --- 模型切换 --- */
.nav-model, .model-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.nav-model { flex: 1; justify-content: center; max-width: 420px; margin: 0 auto; }

.model-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 28px;
}

.model-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.model-select {
    flex: 1;
    min-width: 200px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 0.85rem;
    outline: none;
}

.model-select:focus { border-color: var(--primary); }

.model-tip {
    width: 100%;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
}

.media-preview {
    margin-top: 16px;
    text-align: center;
}

.media-preview img, .media-preview video {
    max-width: 100%;
    max-height: 480px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.upload-zone:hover { border-color: var(--primary); }

.upload-zone img {
    max-height: 200px;
    max-width: 100%;
    border-radius: 6px;
    margin-top: 8px;
}

/* --- 主页 Hero 与 Demo 卡片 --- */
.hero {
    text-align: center;
    padding: 48px 0 36px;
}

.hero h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #818cf8, #c084fc, #f472b6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

.hero p {
    color: var(--text-muted);
    font-size: 1rem;
    max-width: 520px;
    margin: 0 auto;
}

/* ===== Demo 卡片网格 ===== */
.demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 32px;
}

.demo-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    cursor: pointer;
    display: block;
    color: var(--text);
    text-decoration: none;
}

.demo-card:hover {
    transform: translateY(-3px);
    border-color: var(--primary);
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.2);
    text-decoration: none;
}

.demo-card .icon { font-size: 2rem; margin-bottom: 12px; }

.demo-card h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.demo-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.demo-card .tag {
    display: inline-block;
    margin-top: 14px;
    padding: 3px 10px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary-light);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* ===== Demo 页面通用 ===== */
.demo-header {
    margin-bottom: 28px;
}

.demo-header h1 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.demo-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.demo-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

/* --- Demo 子页：聊天气泡与输入区 --- */
.chat-box {
    min-height: 280px;
    max-height: 420px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
}

.msg.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.msg.assistant {
    align-self: flex-start;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.msg.system-info {
    align-self: center;
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary-light);
    font-size: 0.8rem;
    border-radius: 20px;
    padding: 4px 14px;
}

/* ===== 输入区 ===== */
.input-row {
    display: flex;
    gap: 10px;
}

.input-row input,
.input-row textarea,
.input-row select {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 14px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.input-row input:focus,
.input-row textarea:focus,
.input-row select:focus {
    border-color: var(--primary);
}

.input-row textarea,
.demo-panel > textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 14px;
    font-size: 0.9rem;
    outline: none;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
    margin-bottom: 0;
}

.btn {
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    white-space: nowrap;
}

.btn:hover { background: var(--primary-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn-secondary:hover {
    border-color: var(--primary);
    color: var(--primary-light);
    background: rgba(99, 102, 241, 0.08);
}

/* ===== 输出区 ===== */
.output-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    min-height: 120px;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: "SF Mono", "Fira Code", monospace;
    color: #c4b5fd;
    overflow-x: auto;
}

.output-box.empty {
    color: var(--text-muted);
    font-family: inherit;
    font-style: italic;
}

/* --- Function Calling 工具步骤展示 --- */
.steps {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.step-item {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.85rem;
}

.step-item .step-title {
    color: var(--warning);
    font-weight: 600;
    margin-bottom: 4px;
}

.step-item .step-body {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 0.8rem;
}

/* ===== 角色选择 ===== */
.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.role-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, background 0.2s;
    color: var(--text);
    font-size: 0.85rem;
}

.role-btn:hover, .role-btn.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.12);
}

.role-btn .role-icon { font-size: 1.4rem; display: block; margin-bottom: 4px; }

/* ===== 提示词示例 ===== */
.hints {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.hint-chip {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.3);
    color: var(--primary-light);
    border-radius: 20px;
    padding: 4px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.hint-chip:hover { background: rgba(99, 102, 241, 0.25); }

/* ===== 加载动画 ===== */
.loading::after {
    content: "▋";
    animation: blink 0.8s infinite;
    color: var(--primary-light);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== 移动端适配 ===== */
@media (max-width: 768px) {
    .navbar {
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 8px;
    }

    .navbar .logo {
        font-size: 0.95rem;
    }

    .navbar .logo-img {
        height: 24px;
    }

    /* 页面内已有模型选择器时，隐藏导航栏重复项 */
    .demo-page.has-page-model .nav-model {
        display: none;
    }

    .navbar .back {
        margin-left: auto;
        font-size: 0.85rem;
    }

    .container {
        padding: 16px 12px 40px;
    }

    .hero {
        padding: 28px 0 20px;
    }

    .hero h1 {
        font-size: 1.45rem;
    }

    .demo-header h1 {
        font-size: 1.25rem;
    }

    .demo-panel {
        padding: 16px;
    }

    .model-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
        margin-bottom: 16px;
    }

    .model-select {
        min-width: 0;
        width: 100%;
    }

    .input-row {
        flex-direction: column;
    }

    .input-row .btn {
        width: 100%;
    }

    .upload-zone {
        padding: 16px 12px;
    }

    .media-preview audio {
        width: 100%;
    }

    .chat-box {
        min-height: 140px;
        max-height: 320px;
    }

    .msg {
        max-width: 92%;
    }

    .demo-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* ===== 语音助手：录音 / 实时通话 切换 ===== */
.voice-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.voice-tab {
    flex: 1;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 15px;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.voice-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.voice-panel {
    display: none;
}

.voice-panel.active {
    display: block;
}

.demo-textarea {
    width: 100%;
    margin: 8px 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-family: inherit;
    resize: vertical;
}

.rt-call-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.btn-call {
    background: var(--success);
    color: #0f0f1a;
    font-weight: 600;
}

.btn-call:hover {
    filter: brightness(1.08);
}

.btn.is-busy {
    opacity: 0.65;
    cursor: wait;
}

#panel-realtime.rt-locked .model-select,
#panel-realtime.rt-locked .demo-textarea {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
}

.rt-status {
    color: var(--text-muted);
    font-size: 14px;
}

.rt-status.active { color: var(--success); }
.rt-status.listening { color: var(--primary-light); }
.rt-status.thinking { color: var(--warning); }
.rt-status.error { color: #f87171; }

.rt-backend-hint {
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fca5a5;
    font-size: 14px;
}
