/* ============================================
   AUDIO MESSAGING STYLES
   Modern, clean audio UI with stability
   ============================================ */

/* ========================================
   AUDIO RECORDING BUTTON
   ======================================== */

/* Audio button in chat input */
.audio-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    transition: all 0.2s ease;
    border-radius: 50%;
    width: 36px;
    height: 36px;
}

.audio-btn:hover {
    background: rgba(233, 30, 99, 0.1);
    color: #E91E63;
    transform: scale(1.1);
}

.audio-btn:active {
    transform: scale(0.95);
}

/* ========================================
   RECORDING UI (REPLACES INPUT)
   ======================================== */

.audio-recording-ui {
    display: none; /* Hidden by default */
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 16px;
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.recording-pulse {
    width: 12px;
    height: 12px;
    background: #F44336;
    border-radius: 50%;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.2);
    }
}

.recording-timer {
    font-size: 16px;
    font-weight: 600;
    color: #F44336;
    font-variant-numeric: tabular-nums;
    min-width: 48px;
}

.recording-waveform {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 2px;
    height: 32px;
    padding: 0 16px;
}

.recording-bar {
    width: 3px;
    background: #E91E63;
    border-radius: 2px;
    animation: waveform 1s ease-in-out infinite;
}

.recording-bar:nth-child(1) { height: 12px; animation-delay: 0s; }
.recording-bar:nth-child(2) { height: 20px; animation-delay: 0.1s; }
.recording-bar:nth-child(3) { height: 28px; animation-delay: 0.2s; }
.recording-bar:nth-child(4) { height: 16px; animation-delay: 0.3s; }
.recording-bar:nth-child(5) { height: 24px; animation-delay: 0.4s; }

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

.recording-actions {
    display: flex;
    gap: 8px;
}

.recording-cancel-btn,
.recording-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.recording-cancel-btn {
    background: #f5f5f5;
    color: #666;
}

.recording-cancel-btn:hover {
    background: #e0e0e0;
    transform: scale(1.05);
}

.recording-send-btn {
    background: linear-gradient(135deg, #E91E63, #F06292);
    color: white;
    box-shadow: 0 2px 8px rgba(233, 30, 99, 0.3);
}

.recording-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(233, 30, 99, 0.4);
}

.recording-send-btn:active,
.recording-cancel-btn:active {
    transform: scale(0.95);
}

/* ========================================
   AUDIO MESSAGE BUBBLE
   ======================================== */

/* Audio container - FIXED HEIGHT for stability */
.message-audio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    min-width: 240px;
    max-width: 320px;
    height: 56px; /* FIXED HEIGHT - NO LAYOUT SHIFTS */
}

/* Sent audio bubbles (right) */
.message.sent .message-audio {
    background: linear-gradient(135deg, #E91E63, #F06292);
    color: white;
}

/* Received audio bubbles (left) */
.message.received .message-audio {
    background: white;
    color: #1a1a1a;
    border: 1px solid #e0e0e0;
}

/* Play/Pause Button */
.audio-play-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

/* Sent audio: white button */
.message.sent .audio-play-btn {
    background: rgba(255, 255, 255, 0.3);
    color: white;
}

.message.sent .audio-play-btn:hover {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(1.05);
}

/* Received audio: pink button */
.message.received .audio-play-btn {
    background: rgba(233, 30, 99, 0.1);
    color: #E91E63;
}

.message.received .audio-play-btn:hover {
    background: rgba(233, 30, 99, 0.2);
    transform: scale(1.05);
}

.audio-play-btn:active {
    transform: scale(0.95);
}

/* Waveform Container */
.audio-waveform {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* Progress Bar */
.audio-progress {
    position: relative;
    height: 4px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.message.sent .audio-progress {
    background: rgba(255, 255, 255, 0.3);
}

.audio-progress-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: currentColor;
    border-radius: 2px;
    transition: width 0.1s linear;
}

.message.sent .audio-progress-bar {
    background: white;
}

.message.received .audio-progress-bar {
    background: #E91E63;
}

/* Duration */
.audio-duration {
    font-size: 13px;
    font-weight: 500;
    opacity: 0.9;
    font-variant-numeric: tabular-nums;
}

/* Hide actual audio element */
audio {
    display: none;
}

/* ========================================
   ANIMATIONS
   ======================================== */

/* Audio bubble entrance */
.message-audio {
    animation: audioSlideIn 0.3s ease;
}

@keyframes audioSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Playing animation (subtle pulse on button) */
.audio-play-btn.playing {
    animation: playPulse 1s ease-in-out infinite;
}

@keyframes playPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(233, 30, 99, 0.4);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(233, 30, 99, 0);
    }
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 600px) {
    .message-audio {
        min-width: 200px;
        max-width: 280px;
        gap: 10px;
        padding: 10px 12px;
    }

    .audio-play-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    .audio-btn {
        width: 32px;
        height: 32px;
    }

    .recording-waveform {
        padding: 0 8px;
    }

    .recording-bar {
        width: 2px;
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.audio-play-btn:focus {
    outline: 2px solid #E91E63;
    outline-offset: 2px;
}

.audio-btn:focus {
    outline: 2px solid #E91E63;
    outline-offset: 2px;
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .message-audio {
        border: 2px solid currentColor;
    }

    .audio-progress {
        border: 1px solid currentColor;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .recording-pulse,
    .recording-bar,
    .message-audio,
    .audio-play-btn {
        animation: none !important;
        transition: none !important;
    }
}

/* ========================================
   LOADING STATES
   ======================================== */

/* Audio loading spinner */
.audio-loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   LAYOUT STABILITY
   ======================================== */

/* Ensure audio bubbles don't cause layout shifts */
.message-audio {
    contain: layout style; /* CSS containment */
    will-change: transform;
}

/* Reserve space for audio bubbles during load */
.message-audio.loading {
    min-height: 56px;
    background: rgba(0, 0, 0, 0.05);
}

/* Prevent bubble size changes during playback */
.audio-play-btn,
.audio-waveform {
    flex-shrink: 0;
}

/* ========================================
   DARK MODE SUPPORT (Future)
   ======================================== */

@media (prefers-color-scheme: dark) {
    .message.received .message-audio {
        background: #2a2a2a;
        color: white;
        border-color: #444;
    }

    .audio-btn {
        color: #ccc;
    }

    .audio-btn:hover {
        color: #F06292;
    }
}
