/* ═══════════════════════════════════════════════════════════════════════════
   Voice System Styles — web/static/css/voice.css
   语音模块独立样式。变量复用 design-system.css 的 CSS 自定义属性。
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── 语音条消息 (.msg-voice) ─────────────────────────────────────── */

.msg-voice.collecting { outline: 1.5px dashed var(--accent-ring); outline-offset: 2px; }

.msg-voice {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 14px;
    margin: 2px 0;
    max-width: 280px;
    border-radius: 18px;
    background: transparent;
    border: none;
    transition: background 0.2s;
}
.msg-voice.user-voice {
    cursor: default;
}
/* 用户语音条：去掉外层 bubble 的背景和边框 */
.msg-user .bubble:has(.msg-voice.user-voice) {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
}

/* ── 用户语音条 mic 图标 ─────────────────────────────────────── */

.voice-mic-icon {
    display: none;
}
.msg-voice[data-state="playing"] {
    background: color-mix(in srgb, var(--accent) 8%, var(--bg-surface));
    border-color: var(--accent);
}
.msg-voice[data-state="queued"] {
    opacity: 0.6;
}

/* ── 播放按钮 ────────────────────────────────────────────────────── */

.voice-play-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
}
.voice-play-btn:active {
    transform: scale(0.93);
}
.voice-play-btn svg {
    width: 12px;
    height: 12px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── 波纹动画条 ──────────────────────────────────────────────────── */

.voice-wave-bar {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 18px;
    flex: 1;
    min-width: 40px;
}
.voice-wave-line {
    display: inline-block;
    width: 3px;
    border-radius: 1.5px;
    background: var(--accent);
    opacity: 0.5;
    transition: height 0.15s, opacity 0.15s;
    height: 6px;
}
[data-state="playing"] .voice-wave-line {
    animation: voice-wave-pulse 1.2s ease-in-out infinite;
}
[data-state="playing"] .voice-wave-line:nth-child(1) { animation-delay: 0s; }
[data-state="playing"] .voice-wave-line:nth-child(2) { animation-delay: 0.15s; }
[data-state="playing"] .voice-wave-line:nth-child(3) { animation-delay: 0.3s; }
[data-state="playing"] .voice-wave-line:nth-child(4) { animation-delay: 0.45s; }
[data-state="playing"] .voice-wave-line:nth-child(5) { animation-delay: 0.6s; }

@keyframes voice-wave-pulse {
    0%, 100% { height: 4px; opacity: 0.4; }
    50%      { height: 16px; opacity: 1; }
}

/* ── 时长 ────────────────────────────────────────────────────────── */

.voice-duration {
    font-size: 12px;
    color: var(--text-faint);
    flex-shrink: 0;
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ── 折叠文字 ────────────────────────────────────────────────────── */

.voice-text {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}
.msg-voice .voice-text.collapsed {
    display: none;
}
.msg-voice .voice-text.expanded {
    display: block;
    width: 100%;
    margin-top: 2px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: normal;
    max-height: 300px;
    overflow-y: auto;
}
.msg-voice .voice-expand-btn {
    flex-shrink: 0;
}

/* 旧版兼容：语音条内文字默认折叠 */
.voice-text.collapsed {
    display: none;
}
.voice-text.expanded {
    display: block;
    margin-top: 6px;
    white-space: normal;
    max-height: 300px;
    overflow-y: auto;
}

/* ── 展开按钮 ────────────────────────────────────────────────────── */

.voice-expand-btn {
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 4px;
    flex-shrink: 0;
    border-radius: 4px;
    transition: color 0.15s;
}
.voice-expand-btn:hover {
    color: var(--text-secondary);
}

/* ── 排队指示器 ──────────────────────────────────────────────────── */

.voice-queue-badge {
    display: inline-block;
    font-size: 10px;
    color: var(--text-faint);
    margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════════════════
   Voice Settings 面板 — 全屏覆盖层
   ═══════════════════════════════════════════════════════════════════ */

#voiceSettingsPanel,
#searchSettingsPanel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 400;
    background: var(--bg-primary);
    flex-direction: column;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
#voiceSettingsPanel.show,
#searchSettingsPanel.show {
    display: flex;
}
#voiceSettingsPanel .panel-header,
#searchSettingsPanel .panel-header {
    display: grid;
    grid-template-columns: 48px 1fr 48px;
    align-items: center;
    padding: 12px 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
#voiceSettingsPanel .panel-title,
#searchSettingsPanel .panel-title {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#voiceSettingsPanel .panel-close-button,
#voiceSettingsPanel .profile-back-button,
#searchSettingsPanel .panel-close-button,
#searchSettingsPanel .profile-back-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
    margin: 0 auto;
}
#voiceSettingsPanel .panel-close-button:hover,
#voiceSettingsPanel .profile-back-button:hover,
#searchSettingsPanel .panel-close-button:hover,
#searchSettingsPanel .profile-back-button:hover {
    background: var(--bg-surface);
}

/* 暗色模式 */
@media (prefers-color-scheme: dark) {
    #voiceSettingsPanel,
    #searchSettingsPanel {
        background: var(--bg-primary);
    }
}

/* ═══════════════════════════════════════════════════════════════════
   Voice Provider 配置页
   卡片样式复用现有 .profile-card / .profile-page 体系，
   新增的类名用 voice-config- 前缀避免冲突。
   ═══════════════════════════════════════════════════════════════════ */

.voice-config-page {
    padding-bottom: 80px;
}
.voice-config-page .section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 8px;
}
.voice-config-page .section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.voice-config-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--card-radius);
    margin: 8px 16px;
    overflow: hidden;
    transition: border-color 0.2s;
}
.voice-config-card.expanded {
    border-color: var(--accent);
}

.voice-config-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    user-select: none;
}
.voice-config-card-header .card-title {
    flex: 1;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.voice-config-card-header .card-subtitle {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 1px;
}
.voice-config-card-header .card-arrow {
    color: var(--text-faint);
    transition: transform 0.2s;
    width: 16px;
    height: 16px;
}
.voice-config-card.expanded .card-arrow {
    transform: rotate(180deg);
}

.voice-config-card-body {
    display: none;
    padding: 0 14px 14px;
}
.voice-config-card.expanded .voice-config-card-body {
    display: block;
}

.voice-config-field {
    margin-bottom: 10px;
}
.voice-config-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.voice-config-field input,
.voice-config-field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s;
}
.voice-config-field input:focus,
.voice-config-field select:focus {
    border-color: var(--accent);
}
.voice-config-field input::placeholder {
    color: var(--text-faint);
}
.voice-config-field .voice-config-select-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-primary);
    color: var(--text-primary);
    box-sizing: border-box;
    cursor: pointer;
    text-align: left;
}
.voice-config-field .voice-config-select-caret {
    color: var(--text-faint);
    font-size: 12px;
    margin-left: 8px;
}
.voice-config-field input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    display: inline-block;
    vertical-align: middle;
    width: calc(100% - 60px);
    height: 6px;
    border: none;
    padding: 0;
    border-radius: 999px;
    background: var(--border);
    cursor: pointer;
    margin-top: 6px;
}
.voice-config-field input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
.voice-config-field input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
}
.voice-config-range-val {
    display: inline-block;
    vertical-align: middle;
    width: 52px;
    text-align: right;
    font-size: 12px;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}
.voice-config-field-hint {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 3px;
}

.voice-config-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.voice-config-actions button {
    flex: 1;
    padding: 8px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
}
.voice-config-actions button:hover {
    background: var(--bg-surface);
}
.voice-config-actions button.danger {
    color: var(--danger);
    border-color: var(--danger-soft);
}
.voice-config-actions button.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.voice-config-actions button.primary:hover {
    opacity: 0.9;
}

.voice-config-toggle {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    letter-spacing: 0.04em;
    transition: background 0.15s, color 0.15s;
}
.voice-config-toggle.on {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}
.voice-config-toggle.off {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

.voice-config-default-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(217, 119, 6, 0.12);
    color: var(--accent);
    cursor: pointer;
    user-select: none;
}

.voice-config-empty {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-faint);
}
.voice-config-empty p {
    margin: 4px 0;
    font-size: 14px;
}
.voice-config-empty .add-first-btn {
    margin-top: 16px;
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    cursor: pointer;
}

.voice-config-fetch-status {
    font-size: 12px;
    color: var(--text-faint);
    margin-top: 4px;
}
.voice-config-fetch-status.error {
    color: var(--danger);
}

.voice-config-fetched-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 6px;
}
.voice-config-fetched-list .voice-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}
.voice-config-fetched-list .voice-option:last-child {
    border-bottom: none;
}
.voice-config-fetched-list .voice-option:hover {
    background: var(--bg-surface);
}
.voice-config-fetched-list .voice-option.selected {
    background: rgba(217, 119, 6, 0.08);
}

/* ── 麦克风录音状态 ────────────────────────────────────────── */

#micButton.recording {
    color: var(--danger);
    animation: mic-pulse 1s ease-in-out infinite;
}
#micButton.analyzing {
    opacity: 0.5;
    pointer-events: none;
}
@keyframes mic-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ── 录音状态条 ─────────────────────────────────────────────── */

.mic-status-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom) + 72px);
    z-index: 10;
    display: flex;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}
.mic-status-bar.show {
    opacity: 1;
    transform: translateY(0);
}

.mic-status-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    border-radius: 999px;
    background: rgba(28, 25, 23, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    color: #fff;
    font-size: 14px;
}

.mic-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    animation: mic-dot-blink 1s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes mic-dot-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.mic-status-timer {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    min-width: 36px;
}

.mic-status-hint {
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    transition: color 0.15s;
}
.mic-status-hint.cancel {
    color: var(--danger);
    font-weight: 500;
}

/* ── 语音条禁选（长按收藏不被 WebView 原生文本选择打断）───────────────
   语音条的长按手势是收藏，文字选复制让位（要复制可点展开看文本）。
   !important 压过 app.css 的 `.msg-claude .md *` 开启选择。 */
.msg-voice,
.msg-voice * {
    -webkit-user-select: none !important;
    user-select: none !important;
    -webkit-touch-callout: none !important;
}

/* ── 语音收藏分类弹层（自建；WebView 原生 prompt 被驳回不弹窗）──────── */

.radio-collect-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: radioCollectFade 150ms ease-out;
}
.radio-collect-panel {
    width: min(320px, 100%);
    padding: 20px 18px 16px;
    border-radius: 24px;
    /* --glass-bg-strong 半透明透出后面内容，弹层用实色底更干净 */
    background: var(--surface-raised);
    border: 1px solid var(--glass-border);
    color: var(--text-primary);
    box-shadow: var(--shadow-xl);
    animation: radioCollectPop 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.radio-collect-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 14px;
}
.radio-collect-cats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}
.radio-collect-cat {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: background 200ms ease, color 200ms ease;
}
.radio-collect-cat.active {
    background: var(--accent-muted);
    border-color: var(--accent-ring);
    color: #fff;
}
.radio-collect-input {
    width: 100%;
    box-sizing: border-box;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 14px;
    padding: 0 14px;
    outline: 0;
    margin-bottom: 14px;
}
.radio-collect-input:focus {
    border-color: var(--accent-ring);
}
.radio-collect-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.radio-collect-btn {
    padding: 8px 18px;
    border-radius: 999px;
    border: 0;
    font-size: 14px;
    cursor: pointer;
}
.radio-collect-btn.cancel {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}
.radio-collect-btn.ok {
    background: var(--accent);
    color: #fff;
}
@keyframes radioCollectFade {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes radioCollectPop {
    from { opacity: 0; transform: scale(0.96) translateY(6px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}
