/* ============================================================================
   Live engagement — action bar, comments, injection banner, briefing player,
   toasts. Built on top of nyakundi.css tokens. Mobile-first.
   ============================================================================ */

/* --- Unified action bar on every node ------------------------------- */
.live-actions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--outline-variant, #e8e3dc);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
    justify-content: flex-start;
    width: 100%;
}
.live-actions__reactions,
.live-actions__rest {
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 0;
}
.live-actions__reactions { flex: 1 1 auto; }
.live-actions__rest { flex: 0 0 auto; margin-left: auto; }

.live-react,
.live-act {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 34px;
    padding: 5px 11px;
    background: transparent;
    border: 1px solid var(--outline-variant, #e8e3dc);
    border-radius: 999px;
    color: var(--on-surface-variant, #3f3a3b);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 140ms, color 140ms, border-color 140ms, transform 80ms;
}
.live-react svg,
.live-act svg { flex: 0 0 auto; }
.live-react:hover,
.live-act:hover {
    border-color: var(--outline, #5d5557);
    color: var(--on-surface, #14171a);
}
.live-react:active,
.live-act:active { transform: translateY(1px); }
.live-react:focus-visible,
.live-act:focus-visible {
    outline: 2px solid var(--secondary, #b7221e);
    outline-offset: 2px;
}
.live-react.is-active {
    background: color-mix(in srgb, var(--secondary, #b7221e) 10%, transparent);
    border-color: var(--secondary, #b7221e);
    color: var(--secondary, #b7221e);
}
.live-act.is-active {
    background: color-mix(in srgb, var(--secondary, #b7221e) 10%, transparent);
    border-color: var(--secondary, #b7221e);
    color: var(--secondary, #b7221e);
}
.live-react__count,
.live-act__count {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 11px;
}

/* --- Comments tray --------------------------------------------------- */
.live-comments {
    margin-top: 14px;
    padding: 14px 16px;
    background: var(--surface-container-low, #f3f3f3);
    border: 1px solid var(--outline-variant, #e8e3dc);
    border-radius: 10px;
}
.live-comments__head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.live-comments__head strong {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--on-surface, #14171a);
}
.live-comments__hint { font-size: 12px; color: var(--on-surface-variant, #3f3a3b); }
.live-comments__form {
    display: grid; gap: 8px; margin-bottom: 14px;
}
.live-comments__form input,
.live-comments__form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--outline-variant, #e8e3dc);
    background: var(--paper, #fff);
    border-radius: 6px;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--on-surface);
    box-sizing: border-box;
}
.live-comments__form textarea { min-height: 64px; resize: vertical; font-family: var(--font-serif); font-size: 15px; line-height: 1.5; }
.live-comments__form input:focus,
.live-comments__form textarea:focus {
    outline: none;
    border-color: var(--secondary, #b7221e);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--secondary, #b7221e) 20%, transparent);
}
.live-comments__form-actions {
    display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
}
.live-comments__form-actions button {
    padding: 8px 16px; min-height: 38px;
    background: var(--on-surface, #14171a); color: var(--paper, #fff);
    border: 0; border-radius: 999px;
    font-family: var(--font-sans); font-size: 13px; font-weight: 700;
    cursor: pointer;
}
.live-comments__form-actions button:hover { background: var(--secondary, #b7221e); }
.live-comments__form-actions button:disabled { opacity: 0.5; cursor: not-allowed; }
.live-comments__status { font-size: 12px; color: var(--on-surface-variant, #3f3a3b); }

.live-comments__list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.live-comment {
    display: grid;
    grid-template-columns: 32px 1fr;
    gap: 10px;
    padding: 10px 0;
    border-top: 1px solid var(--outline-variant, #e8e3dc);
}
.live-comment:first-child { border-top: 0; padding-top: 0; }
.live-comment__avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--surface-container, #eaeae8);
    color: var(--on-surface, #14171a);
    font-weight: 800; font-size: 11px;
    display: inline-flex; align-items: center; justify-content: center;
}
.live-comment__head {
    margin: 0 0 4px;
    font-family: var(--font-sans); font-size: 13px;
    color: var(--on-surface-variant, #3f3a3b);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.live-comment__head strong { color: var(--on-surface, #14171a); font-weight: 700; }
.live-comment__ago { font-size: 11px; }
.live-comment__chip {
    background: var(--surface-container, #eaeae8);
    color: var(--on-surface-variant, #3f3a3b);
    padding: 1px 7px; border-radius: 999px;
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.06em;
}
.live-comment__text {
    margin: 0; font-family: var(--font-serif);
    font-size: 15px; line-height: 1.55; color: var(--on-surface, #14171a);
    overflow-wrap: anywhere;
}
.live-comment.is-pending { opacity: 0.78; }
.live-comment.is-mine .live-comment__avatar {
    background: color-mix(in srgb, var(--secondary, #b7221e) 14%, var(--paper));
    color: var(--secondary, #b7221e);
}

/* --- "X new updates" injection banner ------------------------------- */
.live-injection {
    position: static;
    top: auto;
    z-index: 30;
    margin: 10px auto 18px;
    padding: 10px 18px;
    background: var(--secondary, #b7221e);
    color: #fff;
    border: 0;
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(183, 34, 30, 0.35);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100% - 24px);
    animation: live-bouncein 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.live-injection__dot {
    width: 7px; height: 7px; background: #fff; border-radius: 50%;
    animation: live-pulse 1.6s ease-in-out infinite;
}
@keyframes live-bouncein {
    0% { transform: translateY(-12px) scale(0.85); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

/* --- Audio briefing player (sticky bottom) ------------------------- */
.live-briefing-player {
    position: fixed;
    left: 24px;
    right: auto;
    bottom: 18px;
    width: min(430px, calc(100vw - 48px));
    transform: none;
    background: var(--on-surface, #14171a);
    color: var(--paper, #fff);
    border-top: 1px solid color-mix(in srgb, var(--paper, #fff) 14%, transparent);
    border-radius: 18px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 40;
    box-shadow: 0 -8px 24px rgba(0,0,0,0.18);
}
.live-briefing-player__play {
    width: 44px; height: 44px;
    border-radius: 50%; border: 0;
    background: var(--secondary, #b7221e); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
}
.live-briefing-player__info { flex: 1 1 auto; min-width: 0; }
.live-briefing-player__title {
    font-size: 13px; font-weight: 700; margin: 0 0 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.live-briefing-player__meta { font-size: 11px; opacity: 0.7; margin: 0; }
.live-briefing-player__progress {
    flex: 0 0 96px; max-width: 96px;
    height: 4px; background: rgba(255,255,255,0.15);
    border-radius: 999px; overflow: hidden;
}
.live-briefing-player__progress-fill {
    height: 100%; width: 0; background: var(--secondary, #b7221e);
    border-radius: 999px; transition: width 150ms linear;
}
.live-briefing-player__close {
    width: 32px; height: 32px; border-radius: 50%;
    background: transparent; border: 0;
    /* Use the player's own text color (--paper) at 70% so it adapts in both themes */
    color: color-mix(in srgb, var(--paper, #fff) 70%, transparent);
    cursor: pointer;
}
@media (max-width: 539px) {
    .live-briefing-player__progress { display: none; }
}
@media (max-width: 959px) {
    .live-briefing-player {
        left: 10px;
        bottom: calc(82px + env(safe-area-inset-bottom, 0px));
        width: calc(100vw - 20px);
        border-radius: 18px;
        padding: 10px 12px;
    }
    .live-briefing-player__play {
        width: 40px;
        height: 40px;
    }
}

@media (max-width: 639px) {
    .live-briefing-player {
        position: static;
        left: auto;
        right: auto;
        bottom: auto;
        width: auto;
        transform: none;
        margin: 18px 16px 0;
        border-radius: 14px;
        box-shadow: none;
    }
}

/* --- Subscribe-for-alerts button ------------------------------------ */
[data-live-subscribe] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    background: var(--on-surface, #14171a);
    color: var(--paper, #fff);
    border: 0;
    border-radius: 999px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}
[data-live-subscribe]:hover { background: var(--secondary, #b7221e); }
[data-live-subscribe].is-on {
    background: color-mix(in srgb, var(--secondary, #b7221e) 14%, var(--paper));
    color: var(--secondary, #b7221e);
}

/* --- Alert/readers strip: aligned with the timeline column ------------ */
.live-engage-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 10px;
    width: min(var(--aj-reading-max, 720px), calc(100vw - 32px));
    margin: 8px auto 14px;
    padding-left: clamp(38px, 6vw, 52px);
}
.live-engage-bar__readers {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--outline-variant, #e8e3dc);
    border-radius: 999px;
    background: var(--paper, #fff);
    color: var(--on-surface-variant, #3f3a3b);
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

/* --- Toasts --------------------------------------------------------- */
.live-toasts {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
    right: 16px;
    z-index: 99;
    display: flex; flex-direction: column; gap: 8px;
}
.live-toast {
    background: var(--on-surface, #14171a);
    color: var(--paper, #fff);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    box-shadow: 0 14px 28px rgba(0,0,0,0.25);
    transform: translateY(8px); opacity: 0;
    transition: transform 220ms, opacity 220ms;
    max-width: min(320px, 88vw);
}
.live-toast.is-visible { transform: translateY(0); opacity: 1; }

/* --- Live readers / bell ------------------------------------------- */
[data-live-readers] {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--on-surface, #14171a);
}

/* --- Filter chips --------------------------------------------------- */
.live-filter-chips {
    display: flex; gap: 8px;
    width: min(var(--aj-reading-max, 720px), calc(100vw - 32px));
    margin: 0 auto 16px;
    padding: 4px 0 4px clamp(38px, 6vw, 52px);
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}
.live-filter-chip {
    padding: 6px 14px;
    background: transparent;
    color: var(--on-surface-variant, #3f3a3b);
    border: 1px solid var(--outline-variant, #e8e3dc);
    border-radius: 999px;
    font-family: var(--font-sans); font-size: 12px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    transition: background-color 140ms, color 140ms, border-color 140ms;
}
.live-filter-chip:hover { color: var(--on-surface, #14171a); border-color: var(--outline, #5d5557); }
.live-filter-chip.is-active {
    background: var(--on-surface, #14171a);
    color: var(--paper, #fff);
    border-color: var(--on-surface, #14171a);
}

/* --- Make sure body has bottom-room for the briefing player -------- */
body.template-live { padding-bottom: 112px !important; }
@media (max-width: 959px) {
    body.template-live {
        padding-bottom: calc(156px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@media (max-width: 639px) {
    body.template-live {
        padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)) !important;
    }
}

@keyframes live-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.4); opacity: 0.65; }
}
@media (prefers-reduced-motion: reduce) {
    .live-injection, .live-injection__dot, .live-toast { animation: none; transition: none; }
}

/* --- Tight phone alignment: no ragged action rows, no bottom-nav clash ---- */
@media (max-width: 639px) {
    .live-engage-bar,
    .live-filter-chips {
        width: 100%;
        padding-left: 32px;
        padding-right: 12px;
    }

    .live-engage-bar {
        justify-content: flex-start;
        margin-top: 2px;
    }

    [data-live-subscribe] {
        min-height: 40px;
        padding-inline: 12px;
    }

    .live-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
        padding-top: 10px;
    }

    .live-actions__reactions,
    .live-actions__rest {
        display: grid;
        width: 100%;
        margin-left: 0;
        gap: 6px;
    }

    .live-actions__reactions { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .live-actions__rest { grid-template-columns: repeat(3, minmax(0, 1fr)); }

    .live-react,
    .live-act {
        min-width: 0;
        min-height: 40px;
        width: 100%;
        padding: 0 6px;
    }

    .live-react__count,
    .live-act__count { font-size: 10px; }

    .live-comments {
        margin-inline: -2px;
        padding: 12px;
        border-radius: 6px;
    }
}

/* Filter chip visibility — class-based, avoids inline style.display */
[data-post-pk].is-hidden { display: none; }
