<?php
// includes/distribution/distribution-release-tracker.php
//
// Release Tracker visual moderno estilo TuneCore/DistroKid.
// Timeline de 5 etapas + cards de histórico com eventos de DSP + estados alternativos.
//
// Etapas:
//   1. Submetido        (artista clicou "Finalizar e enviar")
//   2. Em revisão       (admin está a analisar)
//   3. Aprovado         (admin aprovou, UPC/ISRCs gerados)
//   4. Entregue DSPs    (lançamento enviado aos agregadores)
//   5. Ao vivo          (disponível pelo menos num DSP)
//
// Estados alternativos (fora da linha principal):
//   - returned          (painel vermelho separado, tracker em pausa)
//   - rejected          (estado terminal vermelho)
//   - taken_down        (estado terminal cinza)

if ( ! defined( 'ABSPATH' ) ) exit;


/* ============================================================================
 * MAPEAMENTO STATUS → ETAPA
 * ============================================================================ */
function rmbz_tracker_phase_from_status( $status ) {
    $map = [
        'incomplete'         => 0, // não mostra tracker
        'pendente'           => 2, // em revisão
        'pending'            => 2,
        'submitted'          => 2,
        'returned'           => 2, // volta para revisão após correcções
        'approved'           => 3, // aprovado mas ainda não entregue
        'delivered'          => 4, // entregue aos DSPs
        'live'               => 5, // ao vivo
        'distribuido'        => 5,
        'rejected'           => -1, // estado terminal fora da linha
        'rejeitado'          => -1,
        'takedown_requested' => -2,
        'taken_down'         => -2,
    ];
    return $map[ $status ] ?? 0;
}


/* ============================================================================
 * DSPs COM ÍCONES (para mostrar no passo "Ao vivo")
 * ============================================================================ */
function rmbz_tracker_dsp_icons() {
    return [
        'spotify'     => ['label' => 'Spotify',      'color' => '#1DB954', 'initial' => 'S'],
        'apple_music' => ['label' => 'Apple Music',  'color' => '#FC3C44', 'initial' => 'A'],
        'youtube'     => ['label' => 'YouTube Music','color' => '#FF0000', 'initial' => 'Y'],
        'amazon'      => ['label' => 'Amazon Music', 'color' => '#00A8E1', 'initial' => 'a'],
        'tidal'       => ['label' => 'Tidal',        'color' => '#000000', 'initial' => 'T'],
        'deezer'      => ['label' => 'Deezer',       'color' => '#A238FF', 'initial' => 'D'],
        'boomplay'    => ['label' => 'Boomplay',     'color' => '#00B46A', 'initial' => 'B'],
        'audiomack'   => ['label' => 'Audiomack',    'color' => '#FFA500', 'initial' => 'AM'],
    ];
}


/* ============================================================================
 * HISTÓRICO — lê rmbz_distro_status_history + infere eventos derivados
 * ============================================================================ */
function rmbz_tracker_get_history( $release_id ) {
    global $wpdb;
    $t = $wpdb->prefix . 'rmbz_distro_status_history';
    if ( $wpdb->get_var("SHOW TABLES LIKE '$t'") !== $t ) return [];

    return $wpdb->get_results( $wpdb->prepare(
        "SELECT id, from_status, to_status, reason_code, reason_text, changed_by, created_at
         FROM $t WHERE release_id = %d ORDER BY created_at ASC",
        $release_id
    ) ) ?: [];
}


/* ============================================================================
 * LABEL e DESCRIÇÃO por evento histórico
 * ============================================================================ */
function rmbz_tracker_event_info( $history_row ) {
    $to = $history_row->to_status;
    $from = $history_row->from_status ?: 'criação';

    $events = [
        'pendente'   => ['✓', 'Submetido para distribuição', 'O lançamento entrou na fila de aprovação.'],
        'pending'    => ['✓', 'Submetido para distribuição', 'O lançamento entrou na fila de aprovação.'],
        'submitted'  => ['✓', 'Submetido para distribuição', 'O lançamento entrou na fila de aprovação.'],
        'returned'   => ['⟲', 'Devolvido para correcção',    'A equipa identificou pontos a corrigir antes da aprovação.'],
        'approved'   => ['✓', 'Aprovado pela equipa 1MZ',    'Análise completa. O lançamento vai ser enviado aos DSPs.'],
        'delivered'  => ['🚀','Entregue aos DSPs',            'Ficheiros enviados para Spotify, Apple Music e outros.'],
        'live'       => ['🎉','Ao vivo nas lojas',            'A tua música já pode ser ouvida pelos fãs!'],
        'distribuido'=> ['🎉','Ao vivo nas lojas',            'A tua música já pode ser ouvida pelos fãs!'],
        'rejected'   => ['✗', 'Rejeitado',                    'O lançamento não pôde ser distribuído.'],
        'takedown_requested' => ['🗑','Takedown solicitado', 'Pedido de remoção em processamento.'],
        'taken_down' => ['🗑','Removido das lojas',           'O lançamento já não está disponível.'],
    ];

    if ( isset($events[$to]) ) {
        return [
            'icon' => $events[$to][0],
            'title' => $events[$to][1],
            'desc'  => $events[$to][2],
        ];
    }

    return [
        'icon' => '•',
        'title' => ucfirst( str_replace('_', ' ', $to) ),
        'desc'  => 'Transição de ' . $from . ' para ' . $to . '.',
    ];
}


/* ============================================================================
 * RENDER PRINCIPAL — chamada a partir de distribution-single-view.php
 * ============================================================================ */
function rmbz_render_release_tracker( $release ) {
    if ( ! $release || empty($release->status) ) return;

    $status = $release->status;
    $current_phase = rmbz_tracker_phase_from_status( $status );

    // Não mostrar tracker para rascunhos
    if ( $current_phase === 0 ) return;

    $phases = [
        1 => ['label' => 'Submetido',    'sub' => 'Entregue'],
        2 => ['label' => 'Em revisão',   'sub' => 'Equipa 1MZ'],
        3 => ['label' => 'Aprovado',     'sub' => 'Pronto para DSPs'],
        4 => ['label' => 'Entregue',     'sub' => 'A caminho das lojas'],
        5 => ['label' => 'Ao vivo',      'sub' => 'Disponível 🎉'],
    ];

    $history = rmbz_tracker_get_history( $release->id );

    // Detectar se chegou alguma vez à "Ao vivo" (para mostrar ícones DSP)
    $went_live = ( $current_phase >= 5 );

    // Badge de estado global
    $state_label = '';
    $state_class = '';
    if ( $current_phase === -1 ) {
        $state_label = '✗ Lançamento rejeitado';
        $state_class = 'rejected';
    } elseif ( $current_phase === -2 ) {
        $state_label = '🗑 Removido das lojas';
        $state_class = 'takedown';
    } elseif ( $status === 'returned' ) {
        $state_label = '⟲ Devolvido para correcção';
        $state_class = 'returned';
    } elseif ( $current_phase === 5 ) {
        $state_label = '🎉 Ao vivo';
        $state_class = 'live';
    } elseif ( $current_phase === 4 ) {
        $state_label = '🚀 Entregue aos DSPs';
        $state_class = 'delivered';
    } elseif ( $current_phase === 3 ) {
        $state_label = '✓ Aprovado';
        $state_class = 'approved';
    } else {
        $state_label = '⚡ Em revisão · Etapa 2 de 5';
        $state_class = 'reviewing';
    }

    // Progresso da barra (em % da largura disponível entre os 5 círculos)
    $max_phase = max(1, min(5, $current_phase));
    $progress_pct = ($current_phase <= 0) ? 0 : ( ($max_phase - 1) / 4 * 100 );
    ?>

    <div class="rmbz-tracker">
        <div class="rmbz-tracker-head">
            <div>
                <div class="rmbz-tracker-kicker">Release tracker</div>
                <h2 class="rmbz-tracker-title"><?php echo esc_html($release->title ?: 'Sem título'); ?></h2>
            </div>
            <div class="rmbz-tracker-state <?php echo esc_attr($state_class); ?>">
                <?php echo esc_html($state_label); ?>
            </div>
        </div>

        <?php if ( $current_phase > 0 ): ?>
        <div class="rmbz-tracker-timeline">
            <div class="rmbz-tt-rail"></div>
            <div class="rmbz-tt-fill" style="width: calc(<?php echo number_format($progress_pct, 2); ?>% * 0.9);"></div>

            <?php foreach ( $phases as $p => $info ):
                $is_done    = ($current_phase > $p);
                $is_current = ($current_phase == $p);
                $is_future  = ($current_phase < $p);
                $cls = $is_done ? 'done' : ($is_current ? 'current' : 'future');
            ?>
                <div class="rmbz-tt-step <?php echo $cls; ?>">
                    <div class="rmbz-tt-dot">
                        <?php if ( $is_done ): ?>
                            <span class="ico">✓</span>
                        <?php elseif ( $is_current ): ?>
                            <span class="pulse"></span>
                            <span class="ico"><?php echo (int) $p; ?></span>
                        <?php else: ?>
                            <span class="ico"><?php echo (int) $p; ?></span>
                        <?php endif; ?>
                    </div>
                    <div class="rmbz-tt-label"><?php echo esc_html($info['label']); ?></div>
                    <div class="rmbz-tt-sub"><?php echo esc_html($info['sub']); ?></div>
                </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>

        <?php if ( $went_live ):
            // Contagem rápida para ajustar o título
            $exact_count = 0;
            foreach ( ( $tracker_links ?? [] ) as $ld ) {
                if ( ! empty($ld['is_exact']) ) $exact_count++;
            }
            if ( ! isset($tracker_links) ) {
                $tracker_links = function_exists('rmbz_release_get_links_for_tracker')
                    ? rmbz_release_get_links_for_tracker( $release )
                    : [];
                foreach ( $tracker_links as $ld ) {
                    if ( ! empty($ld['is_exact']) ) $exact_count++;
                }
            }
            $dsps_title = $exact_count === 0
                ? 'Ouvir nas lojas · links a serem confirmados'
                : 'Disponível em:';
        ?>
        <div class="rmbz-tracker-dsps">
            <div class="rmbz-dsps-title"><?php echo esc_html($dsps_title); ?></div>
            <div class="rmbz-dsps-list">
                <?php
                // ========================================================
                // Integração com o novo módulo de workflow (distribution-
                // release-workflow.php). Cada DSP tem link exacto (colado
                // pelo admin) OU link de pesquisa automático como fallback
                // (modo "híbrido"). O tracker mostra sempre os 8 chips.
                // ========================================================
                $tracker_links = function_exists('rmbz_release_get_links_for_tracker')
                    ? rmbz_release_get_links_for_tracker( $release )
                    : [];

                /* [1.5.164] Mapping para os slugs canónicos do helper rmbz_service_logo:
                   o tracker usa 'youtube'/'amazon' mas o helper usa 'youtube_music'/'amazon_music' */
                $tracker_logo_map = [
                    'spotify'     => 'spotify',
                    'apple_music' => 'apple_music',
                    'youtube'     => 'youtube_music',
                    'amazon'      => 'amazon_music',
                    'tidal'       => 'tidal',
                    'deezer'      => 'deezer',
                    'boomplay'    => 'boomplay',
                    'audiomack'   => 'audiomack',
                ];

                foreach ( rmbz_tracker_dsp_icons() as $key => $dsp ):
                    $link_data = $tracker_links[$key] ?? null;
                    $url = $link_data['url'] ?? '';
                    $is_exact = ! empty( $link_data['is_exact'] );
                    $has_url = ! empty($url);
                    $logo_slug = $tracker_logo_map[$key] ?? $key;
                    $has_svg_logo = function_exists('rmbz_service_logo');
                ?>
                    <?php if ( $has_url ): ?>
                        <a href="<?php echo esc_url($url); ?>" target="_blank" rel="noopener"
                           class="rmbz-dsp-chip active<?php echo $is_exact ? '' : ' rmbz-dsp-search'; ?>"
                           style="--dsp-color: <?php echo esc_attr($dsp['color']); ?>;"
                           title="<?php echo esc_attr($dsp['label'] . ($is_exact ? '' : ' (pesquisa)')); ?>">
                            <?php if ( $has_svg_logo ): ?>
                                <span class="chip-logo"><?php echo rmbz_service_logo($logo_slug, ['size' => 22]); ?></span>
                            <?php else: ?>
                                <span class="chip-initial"><?php echo esc_html($dsp['initial']); ?></span>
                            <?php endif; ?>
                            <span class="chip-label">
                                <?php echo esc_html($dsp['label']); ?>
                                <?php if ( ! $is_exact ): ?><span class="chip-search-badge" title="Link de pesquisa — o link exacto ainda não foi confirmado pela equipa">🔍</span><?php endif; ?>
                            </span>
                        </a>
                    <?php else: ?>
                        <div class="rmbz-dsp-chip pending" title="<?php echo esc_attr($dsp['label']); ?> (em breve)">
                            <?php if ( $has_svg_logo ): ?>
                                <span class="chip-logo"><?php echo rmbz_service_logo($logo_slug, ['size' => 22]); ?></span>
                            <?php else: ?>
                                <span class="chip-initial"><?php echo esc_html($dsp['initial']); ?></span>
                            <?php endif; ?>
                            <span class="chip-label"><?php echo esc_html($dsp['label']); ?></span>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
            </div>
        </div>
        <?php endif; ?>

        <?php if ( ! empty($history) ): ?>
        <div class="rmbz-tracker-events">
            <div class="rmbz-events-title">Histórico</div>
            <?php
            $sorted_history = array_reverse($history);
            foreach ( $sorted_history as $idx => $h ):
                $ev = rmbz_tracker_event_info( $h );
                $is_latest = ($idx === 0);
                $accent = 'neutral';
                if ( in_array($h->to_status, ['live','distribuido'], true) )        $accent = 'success';
                elseif ( in_array($h->to_status, ['approved'], true) )              $accent = 'success';
                elseif ( in_array($h->to_status, ['returned'], true) )              $accent = 'warning';
                elseif ( in_array($h->to_status, ['rejected','rejeitado','taken_down'], true) ) $accent = 'danger';
                elseif ( in_array($h->to_status, ['delivered'], true) )             $accent = 'info';
                elseif ( in_array($h->to_status, ['pendente','pending','submitted'], true) ) $accent = 'progress';
            ?>
                <div class="rmbz-event <?php echo esc_attr($accent); ?> <?php echo $is_latest ? 'latest' : 'past'; ?>">
                    <div class="rmbz-event-icon"><?php echo esc_html($ev['icon']); ?></div>
                    <div class="rmbz-event-body">
                        <div class="rmbz-event-head">
                            <strong><?php echo esc_html($ev['title']); ?></strong>
                            <time><?php echo esc_html( rmbz_tracker_fmt_date($h->created_at) ); ?></time>
                        </div>
                        <p><?php echo esc_html($ev['desc']); ?></p>
                        <?php if ( ! empty($h->reason_text) ): ?>
                            <div class="rmbz-event-note">
                                <?php if ( ! empty($h->reason_code) ): ?>
                                    <span class="code">[<?php echo esc_html($h->reason_code); ?>]</span>
                                <?php endif; ?>
                                <?php echo esc_html($h->reason_text); ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>

    <?php rmbz_tracker_render_styles(); ?>
    <?php
}


/* ============================================================================
 * FORMATADOR DE DATA (curto, relativo se recente)
 * ============================================================================ */
function rmbz_tracker_fmt_date( $datetime ) {
    $ts = strtotime($datetime);
    if ( ! $ts ) return '';
    $diff = time() - $ts;

    if ( $diff < 60 )      return 'agora mesmo';
    if ( $diff < 3600 )    return floor($diff/60) . ' min atrás';
    if ( $diff < 86400 )   return floor($diff/3600) . 'h atrás';
    if ( $diff < 604800 )  return floor($diff/86400) . ' dia' . (floor($diff/86400) === 1 ? '' : 's') . ' atrás';

    return date('d/m/Y H:i', $ts);
}


/* ============================================================================
 * CSS — inline para não mexer no distribution.css global
 * ============================================================================ */
function rmbz_tracker_render_styles() {
    static $rendered = false;
    if ( $rendered ) return;
    $rendered = true;
    ?>
    <style>
    .rmbz-tracker { background: var(--rmbz-bg-elevated, #141414); border: 1px solid #2a2a2a; border-radius: 12px; padding: 20px; margin-bottom: 24px; color: var(--rmbz-text-primary, #fff); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

    .rmbz-tracker-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
    .rmbz-tracker-kicker { color: var(--rmbz-text-muted, #888); font-size: 10px; text-transform: uppercase; letter-spacing: 1.5px; margin-bottom: 4px; }
    .rmbz-tracker-title { color: var(--rmbz-text-primary, #fff); font-size: 20px; margin: 0; font-weight: 500; line-height: 1.2; }
    .rmbz-tracker-state { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 500; white-space: nowrap; }
    .rmbz-tracker-state.reviewing { background: rgba(240,185,11,0.12); border: 1px solid #f0b90b; color: var(--rmbz-brand, #f0b90b); }
    .rmbz-tracker-state.approved  { background: rgba(46,204,113,0.12); border: 1px solid #2ecc71; color: var(--rmbz-success, #10b981); }
    .rmbz-tracker-state.delivered { background: rgba(52,152,219,0.12); border: 1px solid #3498db; color: var(--rmbz-info, #3b82f6); }
    .rmbz-tracker-state.live      { background: rgba(46,204,113,0.2);  border: 1px solid #2ecc71; color: var(--rmbz-success, #10b981); }
    .rmbz-tracker-state.returned  { background: rgba(231,76,60,0.12);  border: 1px solid #e74c3c; color: var(--rmbz-danger, #ef4444); }
    .rmbz-tracker-state.rejected  { background: rgba(231,76,60,0.15);  border: 1px solid #e74c3c; color: var(--rmbz-danger, #ef4444); }
    .rmbz-tracker-state.takedown  { background: rgba(136,136,136,0.12);border: 1px solid #888;    color: var(--rmbz-text-muted, #888); }

    .rmbz-tracker-timeline { position: relative; padding: 20px 0 10px 0; margin-bottom: 24px; display: flex; justify-content: space-between; }
    .rmbz-tt-rail { position: absolute; top: 32px; left: 10%; right: 10%; height: 3px; background: var(--rmbz-bg-elevated, #2a2a2a); border-radius: 2px; }
    .rmbz-tt-fill { position: absolute; top: 32px; left: 10%; max-width: 80%; height: 3px; background: linear-gradient(90deg, #2ecc71, #f0b90b); border-radius: 2px; transition: width 0.6s ease; }

    .rmbz-tt-step { display: flex; flex-direction: column; align-items: center; position: relative; z-index: 2; flex: 1; min-width: 0; }
    .rmbz-tt-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; font-size: 13px; font-weight: 700; position: relative; }

    .rmbz-tt-step.done .rmbz-tt-dot    { background: var(--rmbz-success, #10b981); color: #000; }
    .rmbz-tt-step.current .rmbz-tt-dot { background: var(--rmbz-brand, #f0b90b); color: #000; }
    .rmbz-tt-step.future .rmbz-tt-dot  { background: var(--rmbz-bg-surface, #1a1a1a); color: var(--rmbz-text-muted, #666); border: 2px solid #333; }

    .rmbz-tt-step.current .pulse { position: absolute; inset: -6px; border-radius: 50%; border: 2px solid #f0b90b; animation: rmbz-pulse 2s infinite; }
    @keyframes rmbz-pulse { 0% { transform: scale(1); opacity: 0.8; } 50% { transform: scale(1.3); opacity: 0; } 100% { transform: scale(1); opacity: 0; } }

    .rmbz-tt-label { color: var(--rmbz-text-primary, #fff); font-size: 11px; font-weight: 500; text-align: center; padding: 0 4px; }
    .rmbz-tt-step.done .rmbz-tt-label    { color: var(--rmbz-success, #10b981); }
    .rmbz-tt-step.current .rmbz-tt-label { color: var(--rmbz-brand, #f0b90b); }
    .rmbz-tt-step.future .rmbz-tt-label  { color: var(--rmbz-text-muted, #666); }
    .rmbz-tt-sub { color: var(--rmbz-text-muted, #666); font-size: 10px; text-align: center; margin-top: 2px; padding: 0 4px; }

    .rmbz-tracker-dsps { background: rgba(46,204,113,0.05); border: 1px solid rgba(46,204,113,0.2); border-radius: 8px; padding: 14px 16px; margin-bottom: 20px; }
    .rmbz-dsps-title { color: var(--rmbz-success, #10b981); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px; font-weight: 600; }
    .rmbz-dsps-list { display: flex; flex-wrap: wrap; gap: 8px; }
    .rmbz-dsp-chip { display: flex; align-items: center; gap: 7px; padding: 6px 12px 6px 6px; border-radius: 18px; background: var(--rmbz-bg-surface, #1a1a1a); border: 1px solid #2a2a2a; transition: all 0.2s; text-decoration: none; font-size: 11px; color: var(--rmbz-text-primary, #fff); }
    .rmbz-dsp-chip .chip-initial { width: 22px; height: 22px; border-radius: 50%; background: var(--dsp-color, #888); display: flex; align-items: center; justify-content: center; color: var(--rmbz-text-primary, #fff); font-weight: 700; font-size: 11px; flex-shrink: 0; }
    /* [1.5.164] Wrapper do SVG logo no chip — substitui visualmente o chip-initial */
    .rmbz-dsp-chip .chip-logo { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
    .rmbz-dsp-chip .chip-logo svg { display: block; width: 100%; height: 100%; border-radius: 50%; }
    .rmbz-dsp-chip.active { cursor: pointer; }
    .rmbz-dsp-chip.active:hover { background: var(--rmbz-bg-elevated, #222); border-color: var(--dsp-color); transform: translateY(-1px); }
    .rmbz-dsp-chip.pending { opacity: 0.35; cursor: default; }
    .rmbz-dsp-chip.pending .chip-initial { background: var(--rmbz-border-strong, #444); }
    .rmbz-dsp-chip.pending .chip-label { color: var(--rmbz-text-muted, #888); }
    .rmbz-dsp-chip.rmbz-dsp-search { opacity: 0.75; }
    .rmbz-dsp-chip.rmbz-dsp-search:hover { opacity: 1; }
    .chip-search-badge { font-size: 9px; margin-left: 4px; opacity: 0.7; }

    .rmbz-tracker-events { display: flex; flex-direction: column; gap: 8px; }
    .rmbz-events-title { color: var(--rmbz-text-muted, #888); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; font-weight: 600; }
    .rmbz-event { background: var(--rmbz-bg-elevated, #141414); border: 1px solid #2a2a2a; border-radius: 10px; padding: 12px 14px; display: flex; gap: 12px; align-items: flex-start; border-left: 3px solid #333; transition: opacity 0.2s; }
    .rmbz-event.past { opacity: 0.6; }
    .rmbz-event.success  { border-left-color: var(--rmbz-success, #10b981); }
    .rmbz-event.warning  { border-left-color: var(--rmbz-brand, #f0b90b); }
    .rmbz-event.danger   { border-left-color: var(--rmbz-danger, #ef4444); }
    .rmbz-event.info     { border-left-color: var(--rmbz-info, #3b82f6); }
    .rmbz-event.progress { border-left-color: var(--rmbz-brand, #f0b90b); }
    .rmbz-event-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--rmbz-bg-surface, #1a1a1a); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
    .rmbz-event-body { flex: 1; min-width: 0; }
    .rmbz-event-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 4px; }
    .rmbz-event-head strong { color: var(--rmbz-text-primary, #fff); font-size: 13px; font-weight: 500; }
    .rmbz-event-head time { color: var(--rmbz-text-muted, #666); font-size: 11px; white-space: nowrap; }
    .rmbz-event-body p { color: var(--rmbz-text-muted, #aaa); font-size: 12px; margin: 0; line-height: 1.5; }
    .rmbz-event-note { margin-top: 6px; padding: 6px 10px; background: rgba(0,0,0,0.3); border-radius: 4px; font-size: 11px; color: var(--rmbz-text-secondary, #ccc); line-height: 1.5; }
    .rmbz-event-note .code { color: var(--rmbz-brand, #f0b90b); font-family: monospace; font-size: 10px; margin-right: 4px; }

    @media (max-width: 640px) {
        .rmbz-tracker-timeline { padding: 12px 0 6px 0; }
        .rmbz-tt-rail, .rmbz-tt-fill { left: 8%; right: 8%; top: 24px; }
        .rmbz-tt-dot { width: 22px; height: 22px; font-size: 11px; margin-bottom: 6px; }
        .rmbz-tt-label { font-size: 10px; }
        .rmbz-tt-sub { display: none; }
        .rmbz-dsp-chip .chip-label { display: none; }
        .rmbz-dsp-chip { padding: 4px; }
    }
    </style>
    <?php
}
