/**
 * Persistent Audio Player Styles
 * Ajuste 9: herdaça de cores via variáveis CSS do tema ativo
 */

/* ── Variáveis do Player — sobrepostas pelo getThemeCSS() or fallback ── */
:root {
    --player-bg:           var(--glass-bg, rgba(18, 18, 20, 0.92));
    --player-text:         var(--text-primary, #ffffff);
    --player-text-sub:     var(--text-secondary, rgba(255,255,255,0.65));
    --player-icon-color:   var(--text-primary, #ffffff);
    --player-icon-muted:   var(--text-muted, rgba(255,255,255,0.45));
    --player-border:       var(--glass-border, rgba(255,255,255,0.08));
    --player-btn-bg:       rgba(255, 255, 255, 0.12);
    --player-btn-hover-bg: rgba(255, 255, 255, 0.20);
}

.player {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--player-height);
    background: var(--player-bg, var(--glass-bg)); /* Ajuste 9: herda cor do tema */
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-top: 1px solid var(--player-border, var(--glass-border));
    z-index: 1100;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
}

.player-wrapper {
    max-width: var(--container-width);
    margin: 0 auto;
    height: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
}

/* Artwork */
.player-artwork {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid var(--border-color);
    position: relative;
}

.player-artwork img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.player-artwork i {
    font-size: 1.5rem;
    color: var(--text-muted);
}

.player-artwork.has-image i {
    display: none;
}

/* Player Info */
.player-info {
    flex: 1;
    min-width: 0;
}

.player-status {
    margin-bottom: 4px;
}

.live-badge,
.player .live-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 20px;
    font-size: 0.65rem;
    font-weight: 600;
    color: #ef4444;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-direction: row !important;
}

.pulse {
    width: 6px;
    height: 6px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

/* Dynamic Badge States */
.live-badge.state-idle {
    background: rgba(156, 163, 175, 0.2);
    border-color: rgba(156, 163, 175, 0.3);
    color: #9ca3af;
}

.live-badge.state-idle .pulse {
    background: #9ca3af;
    animation: none;
    opacity: 0.5;
}

.live-badge.state-connecting {
    background: rgba(251, 191, 36, 0.2);
    border-color: rgba(251, 191, 36, 0.3);
    color: #fbbf24;
}

.live-badge.state-connecting .pulse {
    background: #fbbf24;
    animation: pulse 1.5s infinite;
}

.live-badge.state-buffering {
    background: rgba(59, 130, 246, 0.2);
    border-color: rgba(59, 130, 246, 0.3);
    color: #3b82f6;
}

.live-badge.state-buffering .pulse {
    background: #3b82f6;
    animation: spin-badge 1s linear infinite;
}

.live-badge.state-transmitting {
    background: rgba(var(--primary-rgb), 0.2);
    border-color: rgba(var(--primary-rgb), 0.3);
    color: var(--primary-color);
}

.live-badge.state-transmitting .pulse {
    background: var(--primary-color);
    animation: pulse 2s infinite;
}

.live-badge.state-reconnecting {
    background: rgba(245, 158, 11, 0.2);
    border-color: rgba(245, 158, 11, 0.3);
    color: #f59e0b;
}

.live-badge.state-reconnecting .pulse {
    background: #f59e0b;
    animation: spin-badge 1s linear infinite;
}

.live-badge.state-no_connection {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.live-badge.state-no_connection .pulse {
    background: #ef4444;
    animation: pulse 0.8s infinite;
}

.live-badge.state-error {
    background: rgba(220, 38, 38, 0.2);
    border-color: rgba(220, 38, 38, 0.3);
    color: #dc2626;
}

.live-badge.state-error .pulse {
    background: #dc2626;
    animation: pulse 0.8s infinite;
}

@keyframes spin-badge {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.player-title {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
    line-height: 1.3;
    color: var(--player-text, var(--text-primary)); /* Ajuste 9 */
}

.player-artist {
    color: var(--player-text-sub, var(--text-secondary)); /* Ajuste 9 */
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

/* Controls */
.player-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.player-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    box-shadow: 0 4px 15px rgba(var(--primary-rgb), 0.4);
    /* Ajuste 9: borda de segurança visível em qualquer fundo */
    border: 2px solid rgba(255, 255, 255, 0.35);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.player-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(var(--primary-rgb), 0.5);
    border-color: rgba(255, 255, 255, 0.6); /* Ajuste 9: borda mais visível no hover */
}

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

.volume-control {
    display: flex;
    align-items: center;
    gap: 10px;
}

.volume-btn {
    width: 40px;
    height: 40px;
    background: var(--player-btn-bg, rgba(255, 255, 255, 0.1)); /* Ajuste 9 */
    color: var(--player-icon-muted, var(--text-secondary));
    font-size: 1rem;
    box-shadow: none;
}

.volume-btn:hover {
    background: var(--player-btn-hover-bg, rgba(255, 255, 255, 0.15)); /* Ajuste 9 */
    color: var(--player-text, var(--text-primary));
    box-shadow: none;
}

/* Video Button */
.video-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    font-size: 1rem;
    box-shadow: none;
    text-decoration: none;
    border: none;
    cursor: pointer;
    position: relative;
}

.video-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    box-shadow: none;
    transform: scale(1.08);
}

.video-btn::after {
    content: "";
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@media (max-width: 768px) {
    .video-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .video-btn::after {
        width: 6px;
        height: 6px;
        top: 3px;
        right: 3px;
    }
}

.volume-slider {
    width: 100px;
    height: 5px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    cursor: pointer;
}

.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.5);
    transition: var(--transition-fast);
}

.volume-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.volume-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

/* Visualizer */
.player-visualizer {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 40px;
    padding: 0 10px;
}

.player-visualizer span {
    width: 4px;
    background: var(--primary-color);
    border-radius: 2px;
    animation: none;
}

.player-visualizer.playing span {
    animation: visualizer 0.8s ease-in-out infinite;
}

.player-visualizer span:nth-child(1) {
    animation-delay: 0s;
    height: 15px;
}

.player-visualizer span:nth-child(2) {
    animation-delay: 0.1s;
    height: 25px;
}

.player-visualizer span:nth-child(3) {
    animation-delay: 0.2s;
    height: 35px;
}

.player-visualizer span:nth-child(4) {
    animation-delay: 0.3s;
    height: 20px;
}

.player-visualizer span:nth-child(5) {
    animation-delay: 0.4s;
    height: 30px;
}

@keyframes visualizer {

    0%,
    100% {
        transform: scaleY(0.3);
    }

    50% {
        transform: scaleY(1);
    }
}

/* Responsive */
@media (max-width: 1024px), (pointer: coarse) and (max-width: 1366px) {
    .player {
        height: 72px;
    }

    .player-wrapper {
        gap: 12px;
        padding: 0 16px;
    }

    .player-artwork {
        width: 48px;
        height: 48px;
    }

    .player-title {
        font-size: 0.82rem;
    }

    .player-artist {
        font-size: 0.72rem;
    }

    .live-badge,
    .player .live-badge {
        padding: 2px 6px;
        font-size: 0.58rem;
        gap: 4px;
    }

    .pulse {
        width: 5px;
        height: 5px;
    }

    .volume-control {
        display: none;
    }

    .player-visualizer {
        display: none;
    }

    .player-btn {
        width: 42px;
        height: 42px;
        font-size: 0.95rem;
    }

    .player-connection-status {
        font-size: 0.65rem;
        margin-top: 1px;
    }
}

/* Connection Status */
.player-connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 3px;
    transition: all 0.3s ease;
}

.player-connection-status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.5;
}

/* Idle State */
.player-connection-status.idle {
    color: var(--text-muted);
}

.player-connection-status.idle::before {
    background: var(--text-muted);
    opacity: 0.5;
}

/* Connecting State */
.player-connection-status.connecting {
    color: #fbbf24;
}

.player-connection-status.connecting::before {
    background: #fbbf24;
    animation: pulse-fade 1.5s ease-in-out infinite;
}

/* Buffering State */
.player-connection-status.buffering {
    color: #3b82f6;
}

.player-connection-status.buffering::before {
    background: #3b82f6;
    animation: spin-pulse 1s linear infinite;
}

/* Transmitting State */
.player-connection-status.transmitting {
    color: var(--primary-color);
}

.player-connection-status.transmitting::before {
    background: var(--primary-color);
    animation: pulse-fade 2s ease-in-out infinite;
}

/* Reconnecting State */
.player-connection-status.reconnecting {
    color: #f59e0b;
}

.player-connection-status.reconnecting::before {
    background: #f59e0b;
    animation: spin-pulse 1s linear infinite;
}

/* No Connection State */
.player-connection-status.no_connection {
    color: #ef4444;
}

.player-connection-status.no_connection::before {
    background: #ef4444;
    animation: pulse-warning 0.8s ease-in-out infinite;
}

/* Error State */
.player-connection-status.error {
    color: #dc2626;
}

.player-connection-status.error::before {
    background: #dc2626;
}

/* Animations */
@keyframes pulse-fade {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.8);
    }
}

@keyframes spin-pulse {
    0% {
        transform: rotate(0deg) scale(1);
        opacity: 1;
    }

    50% {
        transform: rotate(180deg) scale(0.8);
        opacity: 0.6;
    }

    100% {
        transform: rotate(360deg) scale(1);
        opacity: 1;
    }
}

@keyframes pulse-warning {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.3;
        transform: scale(1.2);
    }
}

/* =======================================
   Integração Global: Data-Status de Conexão
   ======================================= */
[data-status="transmitting"], [data-status="idle"] { color: var(--cor-sucesso, var(--primary-color, #1DB954)) !important; }
[data-status="error"], [data-status="no_connection"] { color: var(--cor-erro, #ef4444) !important; }
[data-status="reconnecting"], [data-status="connecting"], [data-status="buffering"] { color: var(--cor-atencao, #f59e0b) !important; }