/* XSSM voice messages */

#chat-view .voice-playback-dock {
    --voice-dock-accent: #a88cff;
    position: relative;
    z-index: 36;
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto 34px;
    align-items: center;
    gap: 11px;
    min-height: 66px;
    margin: 3px 12px 5px;
    padding: 8px 10px 8px 9px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.105);
    border-radius: 19px;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.055), transparent 45%),
        rgba(10, 13, 26, 0.76);
    box-shadow:
        0 14px 34px rgba(0, 0, 0, 0.24),
        inset 0 1px 0 rgba(255, 255, 255, 0.075);
    -webkit-backdrop-filter: blur(32px) saturate(165%);
    backdrop-filter: blur(32px) saturate(165%);
    opacity: 0;
    transform: translateY(-8px) scale(0.985);
    transition:
        opacity 190ms ease,
        transform 240ms var(--spring, cubic-bezier(0.16, 1, 0.3, 1));
}

#chat-view .voice-playback-dock[hidden] {
    display: none !important;
}

#chat-view .voice-playback-dock.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

#chat-view .voice-playback-dock::after {
    content: "";
    position: absolute;
    inset: auto 18% -1px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(168, 140, 255, 0.66), transparent);
    pointer-events: none;
}

#chat-view .voice-dock-aurora {
    position: absolute;
    top: -58px;
    left: -8px;
    width: 190px;
    height: 120px;
    border-radius: 50%;
    background: rgba(139, 105, 244, 0.17);
    filter: blur(36px);
    pointer-events: none;
}

#chat-view .voice-dock-play,
#chat-view .voice-dock-close,
#chat-view .voice-dock-speed,
#chat-view .voice-dock-copy {
    -webkit-tap-highlight-color: transparent;
    font: inherit;
}

#chat-view .voice-dock-play {
    position: relative;
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border: 0;
    border-radius: 15px;
    background: linear-gradient(145deg, #b49cff, #785bea);
    color: #fff;
    box-shadow:
        0 8px 19px rgba(91, 64, 196, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.32);
    cursor: pointer;
    isolation: isolate;
    transition: transform 160ms ease, box-shadow 180ms ease;
}

#chat-view .voice-dock-play:hover {
    transform: translateY(-1px);
    box-shadow:
        0 11px 24px rgba(91, 64, 196, 0.43),
        inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

#chat-view .voice-dock-play:active {
    transform: scale(0.93);
}

#chat-view .voice-dock-play i {
    position: relative;
    z-index: 2;
    font-size: 0.88rem;
}

#chat-view .voice-dock-play .fa-play {
    margin-left: 2px;
}

#chat-view .voice-dock-play-ring {
    position: absolute;
    inset: 4px;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
}

#chat-view .voice-playback-dock.is-playing .voice-dock-play-ring {
    animation: voiceDockRing 1.7s ease-in-out infinite;
}

@keyframes voiceDockRing {
    0%, 100% { opacity: 0.38; transform: scale(0.88); }
    50% { opacity: 0.95; transform: scale(1); }
}

#chat-view .voice-dock-content {
    display: grid;
    min-width: 0;
    gap: 4px;
}

#chat-view .voice-dock-copy {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    text-align: left;
}

#chat-view .voice-dock-status {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 5px;
    color: rgba(188, 171, 247, 0.82);
    font-size: 0.58rem;
    font-weight: 720;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

#chat-view .voice-dock-live-dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #aa8cff;
    box-shadow: 0 0 0 3px rgba(170, 140, 255, 0.1), 0 0 9px rgba(170, 140, 255, 0.62);
}

#chat-view .voice-playback-dock.is-playing .voice-dock-live-dot {
    animation: voiceLiveDot 1.4s ease-in-out infinite;
}

@keyframes voiceLiveDot {
    50% { opacity: 0.45; transform: scale(0.75); }
}

#chat-view .voice-dock-title {
    min-width: 0;
    overflow: hidden;
    color: rgba(249, 247, 255, 0.94);
    font-size: 0.78rem;
    font-weight: 680;
    letter-spacing: -0.012em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-view .voice-dock-timeline {
    display: grid;
    grid-template-columns: minmax(72px, 1fr) auto;
    align-items: center;
    gap: 9px;
}

#chat-view .voice-dock-progress {
    --voice-progress: 0;
    width: 100%;
    height: 14px;
    margin: 0;
    overflow: hidden;
    border: 0;
    border-radius: 999px;
    background:
        linear-gradient(90deg, var(--voice-dock-accent), #7b63e8) no-repeat,
        rgba(255, 255, 255, 0.095);
    background-size: calc(var(--voice-progress) * 100%) 100%, 100% 100%;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

#chat-view .voice-dock-progress::-webkit-slider-runnable-track {
    height: 3px;
    background: transparent;
}

#chat-view .voice-dock-progress::-webkit-slider-thumb {
    width: 12px;
    height: 12px;
    margin-top: -4.5px;
    border: 2px solid rgba(255, 255, 255, 0.86);
    border-radius: 50%;
    background: var(--voice-dock-accent);
    box-shadow: 0 2px 8px rgba(103, 76, 211, 0.55);
    -webkit-appearance: none;
    appearance: none;
}

#chat-view .voice-dock-progress::-moz-range-track {
    height: 3px;
    border: 0;
    background: transparent;
}

#chat-view .voice-dock-progress::-moz-range-thumb {
    width: 9px;
    height: 9px;
    border: 2px solid rgba(255, 255, 255, 0.86);
    border-radius: 50%;
    background: var(--voice-dock-accent);
}

#chat-view .voice-dock-progress:focus-visible {
    box-shadow: 0 0 0 3px rgba(168, 140, 255, 0.18);
}

#chat-view .voice-dock-time {
    color: rgba(218, 213, 232, 0.58);
    font-size: 0.61rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

#chat-view .voice-dock-speed {
    min-width: 38px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid rgba(174, 151, 246, 0.18);
    border-radius: 10px;
    background: rgba(154, 126, 239, 0.095);
    color: rgba(225, 215, 255, 0.9);
    font-size: 0.67rem;
    font-weight: 780;
    cursor: pointer;
    transition: transform 150ms ease, background 160ms ease, border-color 160ms ease;
}

#chat-view .voice-dock-speed:hover {
    transform: translateY(-1px);
    border-color: rgba(184, 159, 255, 0.32);
    background: rgba(154, 126, 239, 0.17);
}

#chat-view .voice-dock-close {
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: rgba(215, 210, 228, 0.48);
    cursor: pointer;
    font-size: 0.72rem;
    transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

#chat-view .voice-dock-close:hover {
    background: rgba(255, 255, 255, 0.065);
    color: rgba(246, 243, 252, 0.9);
}

#chat-view .voice-dock-close:active {
    transform: scale(0.9);
}

/* Voice bubble */
#chat-view .message-voice {
    position: relative;
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    width: clamp(245px, 30vw, 326px);
    min-width: 0;
    padding: 4px 2px;
    isolation: isolate;
}

#chat-view .message-voice::before {
    content: "";
    position: absolute;
    z-index: -1;
    top: 6px;
    left: 22px;
    width: 80px;
    height: 38px;
    border-radius: 50%;
    background: rgba(151, 119, 240, 0.12);
    filter: blur(17px);
    opacity: 0;
    transition: opacity 180ms ease;
}

#chat-view .message-voice.is-playing::before {
    opacity: 1;
}

#chat-view .voice-play-btn {
    position: relative;
    display: grid;
    width: 46px;
    height: 46px;
    flex: 0 0 auto;
    place-items: center;
    margin: 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(145deg, #b398ff, #7657e5);
    color: #fff;
    box-shadow:
        0 7px 17px rgba(91, 62, 198, 0.34),
        inset 0 1px 0 rgba(255, 255, 255, 0.27);
    cursor: pointer;
    transition: transform 160ms ease, box-shadow 180ms ease;
}

#chat-view .message-wrapper.received .voice-play-btn {
    background: linear-gradient(145deg, #9d82f0, #6349c9);
}

#chat-view .voice-play-btn:hover {
    transform: scale(1.045);
    box-shadow:
        0 9px 22px rgba(91, 62, 198, 0.44),
        inset 0 1px 0 rgba(255, 255, 255, 0.31);
}

#chat-view .voice-play-btn:active {
    transform: scale(0.92);
}

#chat-view .voice-play-btn i {
    position: relative;
    z-index: 2;
    font-size: 0.86rem;
}

#chat-view .voice-play-btn .fa-play {
    margin-left: 2px;
}

#chat-view .voice-play-halo {
    position: absolute;
    inset: 5px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 50%;
}

#chat-view .message-voice.is-playing .voice-play-halo {
    animation: voiceBubbleHalo 1.5s ease-in-out infinite;
}

@keyframes voiceBubbleHalo {
    0%, 100% { opacity: 0.35; transform: scale(0.82); }
    50% { opacity: 1; transform: scale(1); }
}

#chat-view .voice-body {
    display: grid;
    min-width: 0;
    gap: 5px;
}

#chat-view .voice-waveform {
    display: flex;
    width: 100%;
    height: 31px;
    align-items: center;
    gap: 2px;
    margin: 0;
    padding: 1px 1px;
    overflow: hidden;
    border: 0;
    background: transparent;
    cursor: pointer;
    touch-action: manipulation;
}

#chat-view .voice-waveform::after {
    content: "";
    position: absolute;
}

#chat-view .voice-bar {
    display: block;
    width: 3px;
    min-width: 2px;
    height: var(--voice-bar, 10px) !important;
    flex: 1 1 3px;
    border-radius: 999px;
    background: rgba(219, 211, 235, 0.29);
    opacity: 0.72;
    transform: scaleY(0.88);
    transition: background 110ms linear, opacity 110ms linear, transform 120ms ease;
}

#chat-view .message-wrapper.sent .voice-bar {
    background: rgba(255, 255, 255, 0.34);
}

#chat-view .voice-bar.active {
    background: linear-gradient(180deg, #c5b3ff, #9275ee);
    opacity: 1;
    transform: scaleY(1);
    box-shadow: 0 0 5px rgba(164, 135, 247, 0.28);
}

#chat-view .message-wrapper.sent .voice-bar.active {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.22);
}

#chat-view .voice-waveform:hover .voice-bar:not(.active) {
    opacity: 0.9;
}

#chat-view .voice-waveform:focus-visible {
    border-radius: 7px;
    outline: 2px solid rgba(168, 140, 255, 0.42);
    outline-offset: 2px;
}

#chat-view .voice-footer {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 6px;
}

#chat-view .voice-time {
    color: rgba(217, 211, 229, 0.57);
    font-size: 0.64rem;
    font-weight: 560;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

#chat-view .message-wrapper.sent .voice-time {
    color: rgba(255, 255, 255, 0.66);
}

#chat-view .voice-kind {
    display: inline-flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 4px;
    overflow: hidden;
    color: rgba(205, 198, 221, 0.42);
    font-size: 0.59rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-view .voice-kind i {
    color: rgba(171, 143, 250, 0.66);
    font-size: 0.54rem;
}

#chat-view .message-wrapper.sent .voice-kind,
#chat-view .message-wrapper.sent .voice-kind i {
    color: rgba(255, 255, 255, 0.52);
}

#chat-view .voice-speed-btn {
    min-width: 30px;
    height: 20px;
    padding: 0 6px;
    border: 1px solid rgba(176, 151, 246, 0.17);
    border-radius: 7px;
    background: rgba(153, 124, 235, 0.09);
    color: rgba(205, 192, 244, 0.82);
    font: inherit;
    font-size: 0.57rem;
    font-weight: 780;
    cursor: pointer;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

#chat-view .voice-speed-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(182, 157, 249, 0.29);
    background: rgba(153, 124, 235, 0.16);
}

#chat-view .message-wrapper.sent .voice-speed-btn {
    border-color: rgba(255, 255, 255, 0.13);
    background: rgba(255, 255, 255, 0.085);
    color: rgba(255, 255, 255, 0.83);
}

#chat-view .message-voice.e2e-loading {
    display: flex;
    width: clamp(245px, 30vw, 326px);
    min-height: 54px;
    align-items: center;
}

#chat-view .voice-decrypt-state {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(224, 218, 237, 0.8);
}

#chat-view .voice-decrypt-state > span:last-child {
    display: grid;
    gap: 2px;
}

#chat-view .voice-decrypt-state strong {
    font-size: 0.68rem;
    font-weight: 660;
}

#chat-view .voice-decrypt-state small {
    color: rgba(205, 198, 220, 0.44);
    font-size: 0.58rem;
}

#chat-view .voice-decrypt-orbit {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 1px solid rgba(165, 139, 242, 0.19);
    border-radius: 50%;
    background: rgba(146, 116, 230, 0.08);
    color: rgba(187, 163, 255, 0.86);
    animation: voiceDecryptPulse 1.7s ease-in-out infinite;
}

@keyframes voiceDecryptPulse {
    50% { border-color: rgba(174, 148, 249, 0.42); box-shadow: 0 0 16px rgba(144, 112, 235, 0.18); }
}

#chat-view .message-wrapper.voice-focus-pulse .message-bubble {
    animation: voiceFocusPulse 1.35s ease;
}

@keyframes voiceFocusPulse {
    0%, 100% { box-shadow: var(--message-shadow, 0 4px 14px rgba(0, 0, 0, 0.16)); }
    35% { box-shadow: 0 0 0 4px rgba(177, 149, 255, 0.24), 0 10px 30px rgba(70, 46, 151, 0.25); }
}

/* Light surface */
[data-theme="light"] #chat-view .voice-playback-dock {
    border-color: rgba(77, 60, 130, 0.1);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.46)),
        rgba(244, 241, 251, 0.86);
    box-shadow:
        0 13px 31px rgba(70, 50, 112, 0.11),
        inset 0 1px 0 rgba(255, 255, 255, 0.92);
}

[data-theme="light"] #chat-view .voice-dock-title {
    color: rgba(37, 29, 56, 0.9);
}

[data-theme="light"] #chat-view .voice-dock-status {
    color: rgba(105, 75, 191, 0.82);
}

[data-theme="light"] #chat-view .voice-dock-time {
    color: rgba(68, 56, 91, 0.58);
}

[data-theme="light"] #chat-view .voice-dock-progress {
    background:
        linear-gradient(90deg, #8d6eea, #6c55ce) no-repeat,
        rgba(83, 64, 127, 0.12);
    background-size: calc(var(--voice-progress) * 100%) 100%, 100% 100%;
}

[data-theme="light"] #chat-view .voice-dock-speed {
    border-color: rgba(103, 76, 177, 0.14);
    background: rgba(116, 86, 196, 0.07);
    color: rgba(78, 54, 148, 0.82);
}

[data-theme="light"] #chat-view .voice-dock-close {
    color: rgba(59, 47, 82, 0.48);
}

[data-theme="light"] #chat-view .message-wrapper.received .voice-bar {
    background: rgba(75, 61, 101, 0.25);
}

[data-theme="light"] #chat-view .message-wrapper.received .voice-bar.active {
    background: linear-gradient(180deg, #987cec, #7558d1);
}

[data-theme="light"] #chat-view .message-wrapper.received .voice-time {
    color: rgba(61, 49, 82, 0.58);
}

[data-theme="light"] #chat-view .message-wrapper.received .voice-kind {
    color: rgba(71, 58, 93, 0.43);
}

/* Phone: the dock becomes a compact native player, never covering messages. */
@media (max-width: 768px) {
    #chat-view .voice-playback-dock {
        grid-template-columns: 42px minmax(0, 1fr) auto 30px;
        gap: 8px;
        min-height: 59px;
        margin: 2px 8px 4px;
        padding: 7px 8px 7px 7px;
        border-radius: 17px;
    }

    #chat-view .voice-dock-play {
        width: 42px;
        height: 42px;
        border-radius: 14px;
    }

    #chat-view .voice-dock-status {
        font-size: 0.52rem;
    }

    #chat-view .voice-dock-title {
        font-size: 0.72rem;
    }

    #chat-view .voice-dock-time {
        font-size: 0.56rem;
    }

    #chat-view .voice-dock-speed {
        min-width: 34px;
        height: 28px;
        padding-inline: 6px;
        font-size: 0.61rem;
    }

    #chat-view .voice-dock-close {
        width: 29px;
        height: 29px;
    }

    #chat-view .message-voice,
    #chat-view .message-voice.e2e-loading {
        width: min(72vw, 294px);
        grid-template-columns: 44px minmax(0, 1fr);
        gap: 9px;
    }

    #chat-view .voice-play-btn {
        width: 43px;
        height: 43px;
    }

    #chat-view .voice-waveform {
        height: 29px;
        gap: 1.6px;
    }

    #chat-view .voice-bar {
        min-width: 1.5px;
    }
}

@media (max-width: 390px) {
    #chat-view .voice-playback-dock {
        grid-template-columns: 40px minmax(0, 1fr) auto 27px;
        gap: 6px;
        margin-inline: 6px;
    }

    #chat-view .voice-dock-play {
        width: 40px;
        height: 40px;
    }

    #chat-view .voice-dock-status {
        display: none;
    }

    #chat-view .voice-dock-content {
        gap: 5px;
    }

    #chat-view .voice-dock-timeline {
        grid-template-columns: minmax(50px, 1fr) auto;
        gap: 6px;
    }

    #chat-view .voice-dock-time {
        font-size: 0.52rem;
    }

    #chat-view .message-voice,
    #chat-view .message-voice.e2e-loading {
        width: min(74vw, 268px);
    }
}

@media (prefers-reduced-motion: reduce) {
    #chat-view .voice-playback-dock,
    #chat-view .voice-playback-dock *,
    #chat-view .message-voice,
    #chat-view .message-voice * {
        scroll-behavior: auto !important;
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 1ms !important;
    }
}
