/* ═══════════════════════════════════════════════════════════════
   KAPI VENTANILLAS v2 (fase VISUAL)
   - Emojis de reacción: del lado izquierdo al DOCK derecho, encima del micrófono (solo quien transmite)
   - Columna vertical de ventanillas (máx. 10) a la izquierda
   - Modal "Invitar a ventanilla"
   ═══════════════════════════════════════════════════════════════ */

/* ─── 1. Emojis dentro del dock del transmisor, arriba del micrófono ─── */
#streaming-stage .broadcaster-controls-bar #live-reactions-bar {
    position: static !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 3px !important;
    background: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: none !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12) !important;
    padding: 0 0 6px 0 !important;
    margin: 0 0 2px 0 !important;
    width: 100%;
    z-index: auto !important;
}

#streaming-stage .broadcaster-controls-bar #live-reactions-bar .reaction-live-btn {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    padding: 0 !important;
    font-size: 13px !important;
    line-height: 1 !important;
    background: rgba(255, 255, 255, 0.06) !important;
    border: none !important;
    border-radius: 50% !important;
    flex-shrink: 0;
}

@media (max-height: 700px) {
    #streaming-stage .broadcaster-controls-bar #live-reactions-bar .reaction-live-btn {
        width: 22px !important;
        height: 22px !important;
        min-width: 22px !important;
        font-size: 11px !important;
    }
}

/* ─── 2. Columna de ventanillas (izquierda) ─── */
#kapi-vent-col {
    position: absolute;
    left: 6px;
    top: 112px;
    max-height: calc(100% - 340px);
    display: none;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    z-index: 56;
    padding: 2px 0;
}

#kapi-vent-col::-webkit-scrollbar { display: none; }

#streaming-stage.kapi-role-broadcaster #kapi-vent-col.has-items,
#streaming-stage.kapi-role-viewer #kapi-vent-col.has-items {
    display: flex;
}

.kapi-vent-count {
    align-self: flex-start;
    font-size: 10px;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    border-radius: 10px;
    padding: 2px 7px;
    flex-shrink: 0;
}

.kapi-vent {
    position: relative;
    width: 56px;
    height: 76px;
    border-radius: 9px;
    background: #2a2e38;
    border: 1px solid rgba(255, 255, 255, 0.22);
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kapi-vent-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #3b4a63;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kapi-vent video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.kapi-vent-name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 17px;
    padding: 0 3px;
    font-size: 9px;
    color: #fff;
    text-align: center;
    text-shadow: 0 1px 3px #000;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kapi-vent-ctrl {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 17px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: rgba(0, 0, 0, 0.6);
}

.kapi-vent-ctrl button {
    background: none;
    border: none;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.kapi-vent-ctrl .material-icons { font-size: 13px; }
.kapi-vent-ctrl button.off { color: #ff6b6b; }
.kapi-vent.cam-off .kapi-vent-avatar { opacity: 0.55; }

/* ─── 3. Modal invitar a ventanilla ─── */
#kapiVentModal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
}

.kvm-box {
    background: #0a1220;
    border: 1px solid rgba(0, 229, 255, 0.25);
    border-radius: 14px;
    width: 320px;
    max-width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.85);
}

.kvm-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0, 229, 255, 0.15);
}

.kvm-head b { font-size: 13px; letter-spacing: 1px; color: #00e5ff; }
.kvm-head span { font-size: 11px; color: #9aa; margin-left: 8px; }
.kvm-x { background: none; border: none; color: #aaa; font-size: 16px; cursor: pointer; }

.kvm-tabs { display: flex; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }

.kvm-tab {
    flex: 1;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #8a96a6;
    font-size: 12px;
    padding: 10px 4px;
    cursor: pointer;
}

.kvm-tab.active { color: #00e5ff; border-bottom-color: #00e5ff; }

.kvm-list { overflow-y: auto; flex: 1; min-height: 120px; }

.kvm-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.kvm-av {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1d2c44;
    color: #00e5ff;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.kvm-name {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kvm-btn {
    background: rgba(0, 229, 255, 0.12);
    border: 1px solid rgba(0, 229, 255, 0.35);
    color: #00e5ff;
    border-radius: 12px;
    padding: 5px 14px;
    font-size: 12px;
    cursor: pointer;
}

.kvm-btn[disabled] { opacity: 0.55; cursor: default; }

.kvm-empty { padding: 26px 16px; text-align: center; color: #778; font-size: 12px; }

.kvm-foot {
    padding: 8px 14px;
    font-size: 11px;
    color: #8a96a6;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    text-align: center;
}

/* ─── 4. Mi cuadrito ("Tú") y nombres sin controles (espectador) ─── */
.kapi-vent.me { border: 2px solid #00e5ff; }
.kapi-vent-name.no-ctrl { bottom: 3px; }
.kapi-vent-flags {
    position: absolute;
    top: 3px;
    right: 3px;
    color: #ff6b6b;
    line-height: 1;
}
.kapi-vent-flags .material-icons { font-size: 13px; }

/* ─── 5. Espectador: botón de ventanilla arriba de la rosa ─── */
#kapi-vent-mic, #kapi-vent-cam { display: none; }
#streaming-stage.kapi-vent-up #kapi-vent-mic,
#streaming-stage.kapi-vent-up #kapi-vent-cam { display: flex; }

#kapi-vent-btn .material-icons { color: #fff; }
#kapi-vent-btn.is-pending { background: #b7791f; }
#kapi-vent-btn.is-up { background: #d93a4a; }
#kapi-vent-mic .material-icons,
#kapi-vent-cam .material-icons { color: #fff; }
#kapi-vent-mic, #kapi-vent-cam { background: #1d9e75; }
#kapi-vent-mic.off, #kapi-vent-cam.off { background: rgba(20, 20, 20, 0.65); }
#kapi-vent-mic.off .material-icons,
#kapi-vent-cam.off .material-icons { color: #ff6b6b; }

/* Barra de emojis oculta mientras el espectador está en ventanilla
   (gana a la regla nativa por especificidad) */
html #streaming-stage.kapi-vent-up #live-reactions-bar { display: none !important; }

/* ─── 6. Transmisor: contador en el botón y aviso en pantalla ─── */
#kapi-pip-btn { position: relative; }
.kapi-vent-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 15px;
    height: 15px;
    border-radius: 8px;
    background: #d93a4a;
    color: #fff;
    font-size: 10px;
    line-height: 15px;
    text-align: center;
    padding: 0 3px;
    box-sizing: border-box;
}

.kapi-vent-aviso {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(10, 18, 32, 0.92);
    border: 1px solid rgba(0, 229, 255, 0.35);
    border-radius: 18px;
    padding: 6px 8px 6px 14px;
    color: #fff;
    font-size: 12px;
    white-space: nowrap;
    max-width: 94%;
}
.kva-t { overflow: hidden; text-overflow: ellipsis; }
.kva-ok {
    background: rgba(0, 229, 255, 0.15);
    border: 1px solid rgba(0, 229, 255, 0.45);
    color: #00e5ff;
    border-radius: 12px;
    padding: 4px 12px;
    font-size: 12px;
}
.kva-x { background: none; border: none; color: #aaa; font-size: 14px; padding: 0 4px; }

/* ─── 7. Modal: 3 pestañas, rechazar solicitud, enlace de prueba ─── */
.kvm-tab { font-size: 11px; padding: 10px 2px; }
.kvm-rej { background: none; border: none; color: #ff6b6b; font-size: 14px; padding: 2px 6px; cursor: pointer; }
.kvm-foot a { color: #00e5ff; text-decoration: underline; }

/* ─── 8. Video real dentro de cada ventanilla ─── */
.kapi-vent video { display: none; }
.kapi-vent.has-video:not(.cam-off) video { display: block; }
.kapi-vent.has-video:not(.cam-off) .kapi-vent-avatar { display: none; }
.kapi-vent.me video { transform: scaleX(-1); }

/* ─── 9. Con la rosa visible + micrófono + cámara + ventanilla (7 botones) en pantallas bajas ─── */
@media (max-height: 760px) {
    #streaming-stage.kapi-vent-up .kapi-viewer-actions { gap: 6px; }
    #streaming-stage.kapi-vent-up .kapi-viewer-actions .kapi-side-btn { width: 36px; height: 36px; }
    #streaming-stage.kapi-vent-up .kapi-viewer-actions .kapi-quick-gift { width: 32px; height: 32px; }
}

/* ─── 10. Abanico "+" del transmisor: va POR ENCIMA del dock (los emojis son solo visuales, quedan debajo) ─── */
#streaming-stage .kapi-fan-menu { z-index: 650; }
#streaming-stage:has(#kapi-fan-menu.open) .broadcaster-controls-bar #live-reactions-bar { opacity: 0.25; pointer-events: none; transition: opacity 0.2s ease; }

/* ─── 11. Invitación a subir (espectador): Aceptar / Rechazar ─── */
.kapi-vent-aviso.inv { flex-wrap: wrap; justify-content: center; white-space: normal; max-width: 90%; padding: 8px 12px; text-align: center; }
.kapi-vent-aviso.inv .kva-t { flex: 1 1 100%; overflow: visible; }
.kapi-vent-aviso .kva-btns { display: flex; gap: 8px; }
.kva-no {
    background: rgba(255, 107, 107, 0.15);
    border: 1px solid rgba(255, 107, 107, 0.5);
    color: #ff6b6b;
    border-radius: 12px;
    padding: 4px 12px;
    font-size: 12px;
}

/* ─── 12. Botón Seguir / Siguiendo ─── */
#streaming-stage .kapi-follow-btn.is-following {
    background: #333;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

/* ═══════════════════════════════════════════════════════════════
   13. DISTRIBUCIÓN FIJA DE LA IZQUIERDA (de arriba hacia abajo)
       · HUD (foto, alias, ❤)                      → arriba
       · Íconos de minijuegos (hasta 3, en fila)   → justo debajo del HUD
       · Columna de ventanillas (con scroll)       → entre los íconos y el chat
       · Chat del live                             → desde la altura del botón del
                                                     micrófono hasta la caja de escribir
   Cada zona tiene su propio tramo: nada se pisa, haya 0 o 10 ventanillas.
   ═══════════════════════════════════════════════════════════════ */
#streaming-stage {
    /* base del dock del transmisor y altura de sus 7 botones (de la base al borde de arriba del micrófono) */
    --kapi-dock-bottom: max(80px, calc(env(safe-area-inset-bottom) + 80px));
    --kapi-chat-h: min(calc(var(--kapi-dock-bottom) + 309px), calc(100% - 340px));
    --kapi-left-top: 112px;
}
#streaming-stage.kapi-has-fabs { --kapi-left-top: 172px; }

/* Ventanillas: arrancan bajo el HUD (o bajo los íconos de minijuegos) y terminan donde empieza el chat */
#streaming-stage #kapi-vent-col {
    top: var(--kapi-left-top);
    max-height: calc(100% - var(--kapi-left-top) - var(--kapi-chat-h) - 8px);
}

/* Íconos de minijuegos: fila compacta bajo el HUD (caben 3), ya no flotan a media altura */
#streaming-stage #kmg-fabs {
    top: 104px !important;
    left: 8px !important;
    flex-direction: row !important;
    align-items: flex-start;
    gap: 6px !important;
    max-width: calc(100% - 80px);
}
#streaming-stage #kmg-fabs .kmg-fab {
    min-width: 54px !important;
    padding: 5px 6px !important;
    font-size: 1.05rem !important;
    border-radius: 14px !important;
}
#streaming-stage #kmg-fabs .kmg-fab span,
#streaming-stage #kmg-fabs .kmg-fab em { font-size: 0.56rem !important; }

/* Chat: más alto (arranca a la altura del micrófono) */
html.kapi-native-app .app-container.streaming-active #pro-chat-sidebar {
    height: var(--kapi-chat-h) !important;
    max-height: var(--kapi-chat-h) !important;
}
/* los mensajes se pegan abajo, junto a la caja de escribir, aunque haya pocos */
#streaming-stage #pro-chat-messages::before { content: ''; margin-top: auto; flex: 0 0 0; }
/* el transmisor no tiene columna de emojis a la izquierda: su chat usa todo el ancho */
html.kapi-native-app #streaming-stage.kapi-role-broadcaster #pro-chat-messages { padding-left: 12px !important; }
