/* ========== 语音通话页面 ========== */

.voice-call-page {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: none;
    flex-direction: column;
    z-index: 1000;
    overflow: hidden;
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 0.4s cubic-bezier(0.16,1,0.3,1),
                transform 0.4s cubic-bezier(0.16,1,0.3,1);
}

/* 语音开始前的 AI 边界与文字稿留存确认 */
.voice-preflight-overlay {
    position: fixed;
    inset: 0;
    z-index: 3300;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(25, 20, 18, 0.56);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.voice-preflight-overlay.active { display: flex; }

.voice-preflight-modal {
    width: min(480px, 100%);
    padding: 24px;
    border: 1px solid var(--color-separator);
    border-radius: 22px;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-xl);
}

.voice-preflight-modal h2 { margin: 0 0 12px; font-size: 1.25rem; }
.voice-preflight-boundary { color: var(--color-text-secondary); line-height: 1.65; }
.voice-preflight-processors {
    color: var(--color-text-secondary);
    font-size: 0.86rem;
    line-height: 1.65;
}
.voice-preflight-retention {
    margin: 16px 0;
    padding: 14px;
    border-radius: 12px;
    background: var(--color-bg-secondary);
    line-height: 1.6;
}
.voice-preflight-retention.is-retained { border: 1px solid rgba(184, 149, 110, 0.38); }
.voice-preflight-retention.is-error { color: #b42318; }
.voice-preflight-actions { display: flex; justify-content: flex-end; gap: 10px; }
.voice-boundary-note {
    flex: 0 0 auto;
    padding: 8px 16px;
    border-bottom: 1px solid var(--color-separator);
    background: rgba(255, 255, 255, 0.45);
    color: var(--color-text-secondary);
    text-align: center;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
}
[data-theme="dark"] .voice-boundary-note { background: rgba(0, 0, 0, 0.16); }

@media (max-width: 600px) {
    .voice-preflight-overlay { padding: 16px; }
    .voice-preflight-modal { padding: 20px; }
    .voice-preflight-actions { flex-direction: column-reverse; }
    .voice-preflight-actions button { width: 100%; }
}

[data-theme="dark"] .voice-call-page {
    background: var(--color-bg);
}

.voice-call-page.active {
    display: flex;
    opacity: 1;
    transform: scale(1);
}

/* ===== AI 说话时的流动波浪背景 ===== */
.voice-call-page.ai-speaking {
    background: linear-gradient(
        180deg,
        var(--color-bg) 0%,
        rgba(232,150,91,0.04) 30%,
        rgba(232,150,91,0.03) 60%,
        var(--color-bg) 100%
    );
    background-size: 100% 300%;
    animation: voiceBgFlow 4s ease-in-out infinite;
}

[data-theme="dark"] .voice-call-page.ai-speaking {
    background: linear-gradient(
        180deg,
        var(--color-bg) 0%,
        rgba(232,150,91,0.06) 30%,
        rgba(232,150,91,0.04) 60%,
        var(--color-bg) 100%
    );
    background-size: 100% 300%;
}

@keyframes voiceBgFlow {
    0%, 100% { background-position: 0% 0%; }
    50% { background-position: 0% 100%; }
}

/* 底部波浪 */
.voice-call-page.ai-speaking::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 120px;
    z-index: 0;
    pointer-events: none;
    opacity: 0.4;
    background: linear-gradient(0deg,
        rgba(232,150,91,0.12) 0%,
        transparent 80%);
    animation: wavePulse 2.5s ease-in-out infinite;
}

@keyframes wavePulse {
    0%, 100% { height: 80px; opacity: 0.25; }
    50% { height: 140px; opacity: 0.5; }
}

/* ===== Header: Logo + 状态 ===== */
.voice-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 8px;
    flex-shrink: 0;
}

.voice-header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--shadow-md);
    background: var(--color-bg-card);
}

.voice-header-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.voice-header-info {
    flex: 1;
    min-width: 0;
}

.voice-header-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--color-text);
    letter-spacing: 0.01em;
}

.voice-mode-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
    vertical-align: middle;
    background: var(--color-accent-subtle);
    color: var(--color-accent);
}

.voice-mode-badge.call-mode {
    background: var(--color-accent-subtle);
    color: var(--color-accent);
}

[data-theme="dark"] .voice-header-name {
    color: #fff;
}

.voice-header-desc {
    font-size: 0.7rem;
    font-weight: 400;
    color: rgba(44,24,16,0.4);
    margin-top: 1px;
}

[data-theme="dark"] .voice-header-desc {
    color: rgba(255,255,255,0.3);
}

.voice-header-status {
    font-size: 0.78rem;
    color: rgba(44,24,16,0.55);
    font-weight: 400;
    margin-top: 1px;
    transition: color 0.3s;
}

[data-theme="dark"] .voice-header-status {
    color: rgba(255,255,255,0.5);
}

.voice-header-timer {
    font-size: 0.8rem;
    font-weight: 500;
    color: rgba(44,24,16,0.4);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

[data-theme="dark"] .voice-header-timer {
    color: rgba(255,255,255,0.35);
}

/* ===== 对话消息区 ===== */
.voice-conversation {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.voice-conversation::-webkit-scrollbar {
    width: 0;
}

/* ===== 连接中状态 ===== */
.voice-connecting {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 60px 0;
}

.voice-connecting.active {
    display: flex;
}

.voice-connecting-spinner {
    width: 28px;
    height: 28px;
    border: 2.5px solid var(--color-separator);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

[data-theme="dark"] .voice-connecting-spinner {
    border-color: rgba(255,255,255,0.1);
    border-top-color: var(--color-accent);
}

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

.voice-connecting-text {
    font-size: 0.85rem;
    color: rgba(44,24,16,0.5);
}

[data-theme="dark"] .voice-connecting-text {
    color: rgba(255,255,255,0.4);
}

/* ===== 消息气泡（对齐文本对话样式） ===== */
.voice-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: msgEnter 0.3s ease;
    margin-bottom: 4px;
}

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

.voice-msg-label {
    font-size: 0.68rem;
    font-weight: 600;
    color: rgba(44,24,16,0.35);
    margin-bottom: 2px;
    padding: 0 6px;
    letter-spacing: 0.03em;
}

[data-theme="dark"] .voice-msg-label {
    color: rgba(255,255,255,0.3);
}

.voice-msg-bubble {
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.7;
    word-wrap: break-word;
    word-break: break-word;
}

/* AI 消息 — 左侧 */
.voice-msg-ai { align-items: flex-start; align-self: flex-start; }
.voice-msg-ai .voice-msg-bubble {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 6px;
}

[data-theme="dark"] .voice-msg-ai .voice-msg-bubble {
    background: var(--color-bg-card);
    border-color: var(--color-border);
    color: var(--color-text);
}

/* 用户消息 — 右侧 */
.voice-msg-user { align-items: flex-end; align-self: flex-end; }
.voice-msg-user .voice-msg-bubble {
    background: var(--color-primary);
    color: white;
    border-bottom-right-radius: 6px;
}

[data-theme="dark"] .voice-msg-user .voice-msg-bubble {
    background: var(--color-primary-dark);
    color: white;
}

/* AI 消息流式输入中的字符动画 */
.voice-msg-ai.is-streaming .voice-msg-bubble {
    background: var(--color-bg-card);
}

[data-theme="dark"] .voice-msg-ai.is-streaming .voice-msg-bubble {
    background: var(--color-bg-secondary);
}

.subtitle-char {
    display: inline-block;
    opacity: 0;
    animation: charEnter 0.45s cubic-bezier(0.16,1,0.3,1) forwards;
    white-space: pre-wrap;
}

@keyframes charEnter {
    0% {
        opacity: 0;
        transform: translateY(6px);
        filter: blur(3px);
    }
    60% {
        opacity: 0.8;
        filter: blur(0);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

/* ===== AI 思考指示器 ===== */
.voice-thinking {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    align-self: flex-start;
}

.voice-thinking.active {
    display: flex;
}

.voice-thinking span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-accent);
    animation: thinkBounce 1.4s ease-in-out infinite;
}

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

@keyframes thinkBounce {
    0%, 80%, 100% {
        transform: scale(0.7);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ===== 底部控制区 ===== */
/* ===== 实时通话UI（语音通话模式专用） ===== */
.voice-call-ui {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.call-status-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px 20px;
}

.call-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(184, 149, 110, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s;
}

.call-avatar.speaking {
    animation: avatarPulse 1.5s ease-in-out infinite;
}

@keyframes avatarPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(232,150,91,0.3); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 12px rgba(232,150,91,0); }
}

.call-status-text {
    font-size: 1.1rem;
    color: rgba(44,24,16,0.6);
    font-weight: 400;
}

[data-theme="dark"] .call-status-text {
    color: rgba(255,255,255,0.5);
}

.call-subtitle {
    font-size: 1.15rem;
    color: var(--color-text);
    text-align: center;
    max-width: 320px;
    line-height: 1.6;
    min-height: 1.6em;
    transition: color 0.3s;
}

[data-theme="dark"] .call-subtitle {
    color: #E5E5EA;
}

.call-waveform {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 24px;
}

.call-waveform span {
    display: inline-block;
    width: 3px;
    border-radius: 2px;
    background: var(--color-accent);
    animation: waveAnim 0.8s ease-in-out infinite;
}

.call-waveform span:nth-child(1) { height: 8px; animation-delay: 0s; }
.call-waveform span:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.call-waveform span:nth-child(3) { height: 12px; animation-delay: 0.2s; }
.call-waveform span:nth-child(4) { height: 20px; animation-delay: 0.3s; }
.call-waveform span:nth-child(5) { height: 10px; animation-delay: 0.4s; }

@keyframes waveAnim {
    0%, 100% { transform: scaleY(0.5); opacity: 0.4; }
    50% { transform: scaleY(1); opacity: 1; }
}

.call-waveform.active span {
    animation-play-state: running;
}

/* ===== 底部控制区 ===== */
.voice-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 20px 20px 44px;
    flex-shrink: 0;
}

.voice-ctrl-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: none;
    background: transparent;
    color: #2c2c2c;
    cursor: pointer;
    transition: opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
}

[data-theme="dark"] .voice-ctrl-btn {
    color: #fff;
}

.voice-ctrl-btn svg {
    width: 56px;
    height: 56px;
    padding: 14px;
    background: rgba(44,44,44,0.08);
    border-radius: 50%;
    transition: all 0.2s;
}

[data-theme="dark"] .voice-ctrl-btn svg {
    background: rgba(255,255,255,0.14);
}

.voice-ctrl-btn:hover svg {
    background: rgba(44,44,44,0.14);
}

[data-theme="dark"] .voice-ctrl-btn:hover svg {
    background: rgba(255,255,255,0.22);
}

.voice-ctrl-btn:active svg {
    transform: scale(0.94);
}

.voice-ctrl-btn span {
    font-size: 0.7rem;
    font-weight: 500;
    color: rgba(44,44,44,0.6);
}

[data-theme="dark"] .voice-ctrl-btn span {
    color: rgba(255,255,255,0.7);
}

/* 挂断按钮 */
.voice-ctrl-btn-end svg {
    background: #FF453A;
    box-shadow: 0 4px 16px rgba(255,69,58,0.3);
    color: #fff;
}

.voice-ctrl-btn-end:hover svg {
    background: #FF5A50;
}

/* 静音/扬声器激活 */
.voice-ctrl-btn.muted svg,
.voice-ctrl-btn.speaker-on svg {
    background: var(--color-text);
    color: #fff;
}

[data-theme="dark"] .voice-ctrl-btn.muted svg,
[data-theme="dark"] .voice-ctrl-btn.speaker-on svg {
    background: var(--color-bg-card);
    color: var(--color-bg);
}

/* ===== 响应式 ===== */
@media (min-width: 769px) {
    .voice-header {
        padding: 16px 32px 8px;
    }

    .voice-header-logo {
        width: 48px;
        height: 48px;
    }

    .voice-header-name {
        font-size: 1.15rem;
    }

    .voice-conversation {
        padding: 12px 32px 20px;
    }

    .voice-msg {
        max-width: 65%;
    }

    .voice-controls {
        gap: 56px;
        padding: 24px 20px 60px;
    }

    .voice-ctrl-btn svg {
        width: 64px;
        height: 64px;
        padding: 16px;
    }
}

@media (max-width: 375px) {
    .voice-header {
        padding: 48px 16px 10px;
    }

    .voice-msg {
        max-width: 88%;
    }

    .voice-msg-bubble {
        font-size: 0.95rem;
        padding: 10px 14px;
    }

    .voice-controls {
        gap: 30px;
        padding: 16px 16px 40px;
    }

    .voice-ctrl-btn svg {
        width: 48px;
        height: 48px;
        padding: 11px;
    }
}

/* ========== 通话警告提示 ========== */
#voiceWarning {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 10001;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 59, 48, 0.15);
    color: #C42B1C;
    font-size: 0.875rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 59, 48, 0.2);
    max-width: calc(100vw - 32px);
}

[data-theme="dark"] #voiceWarning {
    background: rgba(255, 59, 48, 0.2);
    color: #FF8A82;
    border: 1px solid rgba(255, 59, 48, 0.25);
}

/* ============================================
   Apple-inspired voice refinement layer
   ============================================ */
.voice-call-page {
    background:
        radial-gradient(circle 64vmax at 50% -24%, rgba(232,150,91,0.08) 0%, transparent 48%),
        var(--color-bg);
}

[data-theme="dark"] .voice-call-page {
    background:
        radial-gradient(circle 64vmax at 50% -24%, rgba(232,150,91,0.06) 0%, transparent 48%),
        var(--color-bg);
}

.voice-call-page.ai-speaking,
[data-theme="dark"] .voice-call-page.ai-speaking {
    background:
        radial-gradient(circle 64vmax at 50% -24%, rgba(232,150,91,0.11) 0%, transparent 48%),
        var(--color-bg);
    animation: none;
}

.voice-call-page.ai-speaking::after {
    display: none;
}

.voice-header {
    min-height: 64px;
    background: var(--material-bg);
    border-bottom: 1px solid var(--material-border);
    backdrop-filter: blur(var(--material-blur)) saturate(160%);
    -webkit-backdrop-filter: blur(var(--material-blur)) saturate(160%);
}

.voice-header-logo {
    box-shadow: none;
    border: 1px solid var(--material-border);
}

.voice-header-name {
    font-weight: 650;
    letter-spacing: 0;
}

.voice-mode-badge {
    background: var(--color-accent-subtle);
    border: 1px solid rgba(var(--color-primary-rgb), 0.12);
    border-radius: var(--radius-full);
    color: var(--color-accent);
}

.voice-header-desc,
.voice-header-status,
.voice-header-timer {
    color: var(--color-text-tertiary);
}

.voice-conversation {
    gap: 8px;
    padding-bottom: 18px;
}

.voice-msg {
    margin-bottom: 2px;
}

.voice-msg-bubble {
    background: var(--material-bg-strong);
    border: 1px solid var(--material-border);
    border-radius: 18px;
    box-shadow: none;
}

.voice-msg-ai .voice-msg-bubble,
.voice-msg-user .voice-msg-bubble {
    border-radius: 18px;
}

.voice-msg-user .voice-msg-bubble {
    background: var(--color-text);
    color: var(--color-bg-card);
    border-color: transparent;
}

[data-theme="dark"] .voice-msg-user .voice-msg-bubble {
    background: var(--color-text);
    color: var(--color-bg);
}

.subtitle-char {
    animation: none;
    opacity: 1;
    transform: none;
    filter: none;
}

.voice-thinking span,
.call-waveform span {
    background: var(--color-accent);
}

.call-status-area {
    gap: 16px;
}

.call-avatar {
    background: var(--material-bg-strong);
    border: 1px solid var(--material-border);
}

.call-avatar.speaking {
    animation: avatarPulse 1.8s ease-in-out infinite;
}

.call-status-text,
.call-subtitle {
    color: var(--color-text-secondary);
}

.call-subtitle {
    font-size: clamp(1.05rem, 3vw, 1.4rem);
    color: var(--color-text);
}

.voice-controls {
    background: transparent;
}

.voice-ctrl-btn svg {
    background: var(--material-bg-strong);
    border: 1px solid var(--material-border);
    box-shadow: none;
}

.voice-ctrl-btn:hover svg {
    background: var(--color-accent-subtle);
}

.voice-ctrl-btn-end svg {
    background: var(--color-danger);
    border-color: transparent;
    box-shadow: none;
}

#voiceWarning {
    background: var(--material-bg-strong);
    border: 1px solid var(--material-border);
    box-shadow: none;
    backdrop-filter: blur(var(--material-blur)) saturate(160%);
    -webkit-backdrop-filter: blur(var(--material-blur)) saturate(160%);
}

#voiceWarning {
    color: var(--color-danger);
    border-color: rgba(255, 59, 48, 0.22);
}
