/*
 * 小星 UI 统一组件样式
 * 作用域：chat-bubble / article-companion / ai-voice-assistant
 * 设计原则：接入 shared/design-tokens.css，玻璃态 + 顶边高光 + 柔和阴影
 */

/* ── 公共悬浮按钮 ── */
.xiaoxing-trigger {
    position: fixed;
    z-index: 9998;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--c-primary, #6366f1), var(--c-secondary, #8b5cf6));
    color: white;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.35);
    transition: transform var(--transition-fast, 150ms), box-shadow var(--transition-fast, 150ms);
    line-height: 1;
}

.xiaoxing-trigger:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.xiaoxing-trigger .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    font-size: 10px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* 动画 */
@keyframes xiaoxingSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes xiaoxingMicPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ── AI小星 对话框 ── */
#chat-bubble-root {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9998;
    font-family: var(--font-body, system-ui, -apple-system, sans-serif);
}

#chat-panel {
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 380px;
    height: min(540px, calc(100vh - 120px));
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(99, 102, 241, 0.22);
    border-radius: var(--radius-xl, 20px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: xiaoxingSlideUp 0.3s ease;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

#chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.12);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.08), transparent);
}

#chat-header .chat-header-meta {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chat-header .chat-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary, #6366f1), var(--c-secondary, #8b5cf6));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

#chat-header .chat-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #e2e8f0;
    line-height: 1.3;
}

#chat-header .chat-subtitle {
    font-size: 0.7rem;
    color: #94a3b8;
    line-height: 1.2;
}

#chat-header .chat-actions {
    display: flex;
    gap: 4px;
    align-items: center;
}

#chat-header .chat-actions button,
#chat-header .chat-actions a {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 6px;
    border-radius: 8px;
    transition: color var(--transition-fast, 150ms), background var(--transition-fast, 150ms);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#chat-header .chat-actions button:hover,
#chat-header .chat-actions a:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.chat-welcome {
    text-align: center;
    padding: 30px 16px;
}

.chat-welcome .welcome-icon {
    font-size: 2rem;
    margin-bottom: 8px;
}

.chat-welcome p {
    color: #94a3b8;
    font-size: 0.85rem;
    margin: 0;
    line-height: 1.5;
}

.chat-welcome p + p {
    margin-top: 6px;
}

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

.chat-msg.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--c-primary, #6366f1), var(--c-secondary, #8b5cf6));
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: rgba(99, 102, 241, 0.1);
    color: #e2e8f0;
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-bottom-left-radius: 4px;
}

.chat-msg.typing { opacity: 0.7; }

.chat-msg a { color: #818cf8; text-decoration: underline; }

.chat-msg img.chat-msg-img {
    display: block;
    max-width: 180px;
    max-height: 140px;
    border-radius: 8px;
    margin-bottom: 4px;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.06);
}

/* 建议 chips */
#chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
}

.chat-suggest-btn {
    padding: 6px 12px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 14px;
    color: #818cf8;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background var(--transition-fast, 150ms), border-color var(--transition-fast, 150ms);
}

.chat-suggest-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.35);
}

/* 语音工具条 */
#chat-voice-bar {
    display: none;
    gap: 12px;
    padding: 8px 14px;
    border-top: 1px solid rgba(99, 102, 241, 0.1);
    align-items: center;
    font-size: 0.75rem;
    color: #94a3b8;
    flex-shrink: 0;
    background: rgba(99, 102, 241, 0.04);
}

#chat-voice-bar .voice-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    padding: 4px 6px;
    border-radius: 8px;
    transition: background var(--transition-fast, 150ms);
}

#chat-voice-bar .voice-control:hover {
    background: rgba(255, 255, 255, 0.05);
}

#chat-voice-bar input[type="checkbox"] { margin: 0; }

#chat-mic-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(99, 102, 241, 0.3);
    background: rgba(99, 102, 241, 0.1);
    color: #a5b4fc;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast, 150ms);
}

#chat-mic-btn:hover { background: rgba(99, 102, 241, 0.2); }
#chat-mic-btn.listening {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
    animation: xiaoxingMicPulse 1.2s ease-in-out infinite;
}

#chat-voice-status {
    margin-left: auto;
    color: #fbbf24;
    font-size: 0.72rem;
}

/* 图片预览 */
#chat-image-preview {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 0;
    flex-shrink: 0;
}

#chat-image-preview.visible { display: flex; }

#chat-image-thumb {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid rgba(99, 102, 241, 0.35);
    background: #1e293b;
}

#chat-image-hint {
    font-size: 0.72rem;
    color: #64748b;
    flex: 1;
}

#chat-image-remove {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    font-size: 0.9rem;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast, 150ms);
}

#chat-image-remove:hover { background: rgba(239, 68, 68, 0.35); }

/* 输入区 */
#chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid rgba(99, 102, 241, 0.1);
    flex-shrink: 0;
    align-items: flex-end;
    background: rgba(99, 102, 241, 0.04);
}

#chat-image-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(99, 102, 241, 0.25);
    background: rgba(99, 102, 241, 0.08);
    color: #a5b4fc;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition-fast, 150ms);
}

#chat-image-btn:hover { background: rgba(99, 102, 241, 0.2); }

#chat-input {
    flex: 1;
    resize: none;
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 12px;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.5);
    color: #e2e8f0;
    font-size: 0.88rem;
    max-height: 80px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color var(--transition-fast, 150ms), background var(--transition-fast, 150ms);
}

#chat-input:focus {
    border-color: var(--c-primary, #6366f1);
    background: rgba(15, 23, 42, 0.7);
}

#chat-input::placeholder { color: var(--form-placeholder, rgba(255, 255, 255, 0.7)); }

#chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--c-primary, #6366f1);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast, 150ms), transform var(--transition-fast, 150ms);
    flex-shrink: 0;
}

#chat-send-btn:disabled {
    background: #334155;
    cursor: not-allowed;
}

#chat-send-btn:not(:disabled):hover {
    background: var(--c-primary-dark, #4f46e5);
    transform: scale(1.05);
}

/* 移动端适配 */
@media (max-width: 768px) {
    #chat-bubble-root { bottom: 12px; right: 12px; }
    .xiaoxing-trigger { width: 44px; height: 44px; font-size: 1.1rem; }
    #chat-panel {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        right: -4px;
        bottom: 56px;
    }
}

/* 减少动画 */
@media (prefers-reduced-motion: reduce) {
    .xiaoxing-trigger,
    #chat-panel,
    #chat-send-btn,
    .chat-suggest-btn { transition: none; }
    #chat-panel { animation: none; }
}

/* ── AI伴读 面板 ── */
#companion-root {
    position: fixed;
    bottom: 120px;
    right: 16px;
    z-index: 9998;
    font-family: var(--font-body, system-ui, -apple-system, sans-serif);
}

#companion-root .xiaoxing-trigger {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.35);
}

#companion-root .xiaoxing-trigger:hover {
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.45);
}

#companion-panel {
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 360px;
    height: min(500px, calc(100vh - 160px));
    background: rgba(15, 23, 42, 0.92);
    border: 1px solid rgba(245, 158, 11, 0.22);
    border-radius: var(--radius-xl, 20px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: xiaoxingSlideUp 0.3s ease;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

#companion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(245, 158, 11, 0.1);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(245, 158, 11, 0.06), transparent);
}

#companion-header .companion-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #e2e8f0;
}

#companion-header .companion-title .companion-tag {
    font-weight: 400;
    font-size: 0.7rem;
    color: #94a3b8;
    margin-left: 6px;
}

#companion-header .companion-close {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    border-radius: 8px;
    transition: color var(--transition-fast, 150ms), background var(--transition-fast, 150ms);
}

#companion-header .companion-close:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.06);
}

#companion-tabs {
    display: flex;
    border-bottom: 1px solid rgba(245, 158, 11, 0.1);
    flex-shrink: 0;
    padding: 0 12px;
    gap: 6px;
}

.comp-tab {
    padding: 10px 12px;
    border: none;
    background: none;
    color: #94a3b8;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--transition-fast, 150ms), border-color var(--transition-fast, 150ms);
}

.comp-tab:hover { color: #e2e8f0; }

.comp-tab.active {
    color: #f59e0b;
    border-bottom-color: #f59e0b;
}

#comp-content {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #334155 transparent;
}

#comp-content::-webkit-scrollbar { width: 4px; }
#comp-content::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }

.comp-pane { display: none; }
.comp-pane.active { display: block; }

#comp-qa-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 14px;
}

#comp-qa-history {
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#companion-qa-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid rgba(245, 158, 11, 0.1);
    background: rgba(245, 158, 11, 0.04);
}

#comp-qa-input {
    flex: 1;
    padding: 8px 12px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 10px;
    color: #e2e8f0;
    font-size: 0.85rem;
    outline: none;
    transition: border-color var(--transition-fast, 150ms), background var(--transition-fast, 150ms);
}

#comp-qa-input:focus {
    border-color: #f59e0b;
    background: rgba(15, 23, 42, 0.7);
}

#companion-qa-input-row .companion-ask-btn {
    padding: 8px 16px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: none;
    border-radius: 10px;
    color: white;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform var(--transition-fast, 150ms), box-shadow var(--transition-fast, 150ms);
}

#companion-qa-input-row .companion-ask-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

@media (max-width: 480px) {
    #companion-panel {
        width: calc(100vw - 24px);
        height: min(60vh, calc(100vh - 140px));
        right: -4px;
        bottom: 56px;
    }
    #companion-root .xiaoxing-trigger { width: 44px; height: 44px; }
}

/* ── AI语音助手页 局部优化 ── */
.ai-voice-mockup {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: 16px;
    padding: 16px;
}

.ai-voice-mockup .mock-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-voice-mockup .mock-row.reverse {
    flex-direction: row-reverse;
}

.ai-voice-mockup .mock-icon {
    font-size: 1.3rem;
}

.ai-voice-mockup .mock-bubble {
    flex: 1;
    height: 30px;
    border-radius: 15px;
    background: rgba(139, 92, 246, 0.2);
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 0.75rem;
    color: #cbd5e1;
}

.ai-voice-mockup .mock-bubble.secondary {
    background: rgba(99, 102, 241, 0.2);
}

.ai-voice-mockup .mock-mic {
    text-align: center;
    font-size: 1.6rem;
    padding: 4px 0;
}

/* 通用小星按钮变体（语音助手页可复用） */
.xiaoxing-btn-ghost {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #e2e8f0;
    border-radius: var(--radius-btn, 12px);
    padding: 8px 14px;
    cursor: pointer;
    transition: background var(--transition-fast, 150ms), border-color var(--transition-fast, 150ms);
}

.xiaoxing-btn-ghost:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.18);
}
