/* =============================================
   PuffCase — chat.css
   Chat en vivo: panel lateral izquierdo,
   mensajes, popup de usuario, tip, mute
   ============================================= */

/* ── LAYOUT GENERAL ──────────────────────────── */
/* Cuando el chat está activo, el body usa un layout flex */
body.chat-activo {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: 100vh;
}

/* El contenido principal ocupa el resto */
body.chat-activo #page-main {
    flex: 1;
    min-width: 0;
    overflow-x: clip; /* clip en lugar de hidden: no crea scroll container, preserva position:sticky del header */
}

/* ── PANEL DEL CHAT ───────────────────────────── */
.chat-panel {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 280px;
    height: calc(100vh - var(--header-h));
    background: var(--purple-dark);
    border-right: 1px solid var(--purple-border);
    display: flex;
    flex-direction: column;
    z-index: 150;
    transition: transform .3s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,.35);
}

.chat-panel--cerrado {
    transform: translateX(-268px); /* deja solo el botón visible */
}

/* ── CABECERA DEL CHAT ────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--purple-border);
    background: rgba(0,0,0,.2);
    flex-shrink: 0;
}
.chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Rajdhani', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    color: var(--white);
    letter-spacing: 0.5px;
}
.chat-header-dot {
    width: 8px; height: 8px;
    background: #4caf7d;
    border-radius: 50%;
    box-shadow: 0 0 6px #4caf7d;
    animation: chat-pulse 2s infinite;
}
@keyframes chat-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

/* Botón toggle (flecha) */
.chat-toggle-btn {
    position: absolute;
    right: -28px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 56px;
    background: var(--purple-dark);
    border: 1px solid var(--purple-border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    color: var(--gray-light);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    transition: background .2s, color .2s;
    flex-shrink: 0;
}
.chat-toggle-btn:hover { background: var(--purple-mid); color: var(--white); }

/* ── LISTA DE MENSAJES ────────────────────────── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: var(--purple-border) transparent;
    list-style: none;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--purple-border); border-radius: 2px; }

/* ── MENSAJE INDIVIDUAL ───────────────────────── */
.chat-msg {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    animation: chat-msg-in .2s ease;
}
@keyframes chat-msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-msg-body { flex: 1; min-width: 0; }

.chat-msg-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
}
.chat-msg-nombre {
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
    transition: color .15s;
    display: flex;
    align-items: center;
    gap: 3px;
}
.chat-msg-nombre:hover { text-decoration: underline; }

/* Colores por rol en el nombre */
.chat-rol--owner    { color: #f0c040; font-weight: bold; text-shadow: 0 0 5px rgba(255, 215, 0, 0.4); /* Efecto de brillo dorado */ }
.chat-rol--admin    { color: var(--purple-glow); font-weight: bold; }
.chat-rol--mod      { color: #7dd3fc; font-weight: bold; }
.chat-rol--youtuber { color: #ff0000; font-weight: bold; } /* Rojo YouTube */
.chat-rol--streamer { color: #a970ff; font-weight: bold; } /* Morado Twitch */
.chat-rol--vip      { color: #ffd700; }
.chat-rol--user     { color: var(--gray-light); }

.chat-rol-icon { font-size: 0.72rem; }

/* Badge VIP animado según tier */
.chat-nombre-rgb--plata .chat-rol-icon {
    animation: badge-plata-glow 3s ease-in-out infinite;
}
.chat-nombre-rgb--oro .chat-rol-icon {
    animation: badge-oro-pulse 1.8s ease-in-out infinite;
}
@keyframes badge-plata-glow {
    0%,100% { filter: drop-shadow(0 0 2px rgba(200,200,215,.3)); }
    50%      { filter: drop-shadow(0 0 6px rgba(220,220,240,.8)) brightness(1.2); }
}
@keyframes badge-oro-pulse {
    0%,100% { filter: drop-shadow(0 0 3px rgba(255,215,0,.4)); transform: scale(1); }
    50%      { filter: drop-shadow(0 0 10px rgba(255,215,0,1)) brightness(1.4); transform: scale(1.18); }
}

.chat-msg-hora {
    font-size: 0.67rem;
    color: var(--gray-mid);
    flex-shrink: 0;
    margin-left: auto;
}

.chat-msg-texto {
    font-size: 0.82rem;
    color: var(--gray-light);
    line-height: 1.45;
    word-break: break-word;
    background: rgba(255,255,255,.04);
    border-radius: 0 8px 8px 8px;
    padding: 7px 10px;
}

/* Mis propios mensajes */
.chat-msg--mio .chat-msg-texto {
    background: rgba(124,58,237,.18);
    border: 1px solid rgba(124,58,237,.2);
}

/* Mensaje de sistema */
.chat-msg-sistema {
    text-align: center;
    font-size: 0.75rem;
    color: var(--gray-mid);
    padding: 4px 8px;
    background: rgba(255,255,255,.04);
    border-radius: 20px;
    align-self: center;
    animation: chat-msg-in .2s ease;
}

/* ── FORMULARIO DE ENVÍO ──────────────────────── */
.chat-form-wrap {
    padding: 10px;
    border-top: 1px solid var(--purple-border);
    background: rgba(0,0,0,.15);
    flex-shrink: 0;
}

.chat-form {
    display: flex;
    gap: 6px;
    align-items: flex-end;
}

.chat-input-wrap { flex: 1; position: relative; }

.chat-input {
    width: 100%;
    background: var(--purple-deep);
    border: 1px solid var(--gray-dark);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--white);
    font-size: 0.83rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    resize: none;
    max-height: 80px;
    min-height: 36px;
    transition: border-color .2s, box-shadow .2s;
    line-height: 1.4;
}
.chat-input:focus {
    border-color: var(--purple-accent);
    box-shadow: 0 0 0 2px rgba(124,58,237,.2);
}
.chat-input::placeholder { color: var(--gray-mid); font-size: 0.8rem; }
.chat-input:disabled { opacity: .5; cursor: not-allowed; }

.chat-char-count {
    position: absolute;
    bottom: 4px;
    right: 8px;
    font-size: 0.62rem;
    color: var(--gray-mid);
    pointer-events: none;
}

.chat-send-btn {
    background: var(--purple-accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s, transform .15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-send-btn:hover:not(:disabled) {
    background: var(--purple-bright);
    transform: translateY(-1px);
}
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }

.chat-cooldown {
    font-size: 0.72rem;
    color: var(--gray-mid);
    text-align: center;
    margin-top: 5px;
    display: none;
}

/* Login prompt */
.chat-login-prompt {
    text-align: center;
    padding: 12px;
    font-size: 0.8rem;
    color: var(--gray-mid);
    border-top: 1px solid var(--purple-border);
    background: rgba(0,0,0,.15);
}
.chat-login-prompt a {
    color: var(--purple-glow);
    text-decoration: none;
    font-weight: 600;
}
.chat-login-prompt a:hover { text-decoration: underline; }

/* ── POPUP DE USUARIO ─────────────────────────── */
.chat-user-popup {
    position: fixed;
    left: 290px;
    top: 50%;
    transform: translateY(-50%);
    width: 240px;
    background: var(--purple-mid);
    border: 1px solid var(--purple-border);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0,0,0,.6);
    z-index: 300;
    padding: 20px;
    display: none;
    animation: chat-popup-in .18s ease;
}
@keyframes chat-popup-in {
    from { opacity: 0; transform: translateY(-50%) scale(.95); }
    to   { opacity: 1; transform: translateY(-50%) scale(1); }
}

.chat-popup-close {
    position: absolute;
    top: 10px; right: 12px;
    background: none;
    border: none;
    color: var(--gray-mid);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all .15s;
    font-family: inherit;
}
.chat-popup-close:hover { color: var(--white); background: rgba(255,255,255,.08); }

.chat-popup-loading {
    text-align: center;
    color: var(--gray-mid);
    padding: 20px 0;
    font-size: 0.85rem;
}

.chat-popup-user {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid rgba(61,42,110,.5);
}
.chat-popup-avatar {
    width: 42px; height: 42px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--purple-border);
    flex-shrink: 0;
}
.chat-popup-nombre {
    font-size: 0.88rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--white);
}
.chat-popup-rol {
    font-size: 0.72rem;
    color: var(--gray-mid);
    margin-top: 2px;
}

.chat-popup-acciones { display: flex; flex-direction: column; gap: 14px; }

/* Tip */
.chat-popup-tip-title,
.chat-popup-mod-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gray-light);
    margin-bottom: 8px;
    letter-spacing: 0.3px;
}
.chat-popup-tip-row {
    display: flex;
    gap: 6px;
}
.chat-popup-tip-input {
    flex: 1;
    background: var(--purple-deep);
    border: 1px solid var(--gray-dark);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--white);
    font-size: 0.82rem;
    font-family: 'Inter', sans-serif;
    outline: none;
    min-width: 0;
    transition: border-color .2s;
}
.chat-popup-tip-input:focus { border-color: var(--purple-accent); }
.chat-popup-tip-input::-webkit-inner-spin-button { opacity: .5; }

.chat-popup-tip-btn {
    background: var(--purple-accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}
.chat-popup-tip-btn:hover { background: var(--purple-bright); }

.chat-popup-tip-msg {
    font-size: 0.75rem;
    margin-top: 6px;
    min-height: 16px;
}
.chat-popup-tip-msg.ok    { color: #4caf7d; }
.chat-popup-tip-msg.error { color: #f44336; }

/* Mute */
.chat-popup-mod { border-top: 1px solid rgba(61,42,110,.5); padding-top: 12px; }
.chat-popup-mod-btn {
    width: 100%;
    background: rgba(244,67,54,.12);
    border: 1px solid rgba(244,67,54,.35);
    color: #f44336;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    transition: all .2s;
}
.chat-popup-mod-btn:hover { background: rgba(244,67,54,.25); }
.chat-popup-mod-btn--desmutar {
    background: rgba(76,175,125,.12);
    border-color: rgba(76,175,125,.35);
    color: #4caf7d;
}
.chat-popup-mod-btn--desmutar:hover { background: rgba(76,175,125,.25); }

/* ── RESPONSIVE ───────────────────────────────── */
@media (max-width: 900px) {
    .chat-panel {
        width: 260px;
        top: 0;
    }
    .chat-panel--cerrado { transform: translateX(-248px); }
    .chat-user-popup { left: 270px; }
}

@media (max-width: 640px) {
    .chat-panel {
        width: 85vw;
        max-width: 300px;
    }
    .chat-panel--cerrado { transform: translateX(calc(-85vw + 12px)); }
    .chat-user-popup {
        left: 50%;
        top: auto;
        bottom: 80px;
        transform: translateX(-50%);
    }
    @keyframes chat-popup-in {
        from { opacity: 0; transform: translateX(-50%) scale(.95); }
        to   { opacity: 1; transform: translateX(-50%) scale(1); }
    }
}

/* ── Marco del avatar (por encima del avatar) ── */
.cpu-marco-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 84px;
    height: 84px;
    object-fit: contain;
    pointer-events: none;
    z-index: 2; /* Por ENCIMA del avatar */
}

/* ── Avatar (por debajo del marco) ── */
.cpu-avatar {
    position: relative;
    width: 62px; height: 62px;
    border-radius: 12px;
    border: 3px solid #120d24;
    object-fit: cover;
    box-shadow: 0 4px 16px rgba(0,0,0,.5);
    z-index: 1; /* Por DEBAJO del marco */
}

/* ── Nivel Badge (por encima de todo) ── */
.cpu-nivel-badge {
    z-index: 3; /* Por encima de todo */
}

/* ── Marco en mensajes del chat ── */
.chat-avatar-wrap {
    position: relative;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    cursor: pointer;
}
.chat-msg-avatar {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--purple-border);
    position: relative;
    z-index: 1; /* Por DEBAJO del marco */
    transition: border-color .2s, transform .15s;
}
.chat-msg-avatar:hover { border-color: var(--purple-accent); transform: scale(1.08); }
.chat-marco-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 50px;
    height: 50px;
    object-fit: contain;
    pointer-events: none;
    z-index: 2; /* Por ENCIMA del avatar */
}

.chat-nombre-rgb,
.chat-nombre-rgb--bronce,
.chat-nombre-rgb--plata,
.chat-nombre-rgb--oro {
    font-weight: 700;
    background-size: 300% auto;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent !important;
    animation: rgb-nombre-scroll 3s linear infinite;
}
.chat-nombre-rgb,
.chat-nombre-rgb--bronce {
    background-image: linear-gradient(90deg, #8b4513, #cd7f32, #e8a050, #ffd700, #e8a050, #cd7f32, #8b4513);
}
.chat-nombre-rgb--plata {
    background-image: linear-gradient(90deg, #808090, #b0b0c0, #e0e0ec, #ffffff, #e0e0ec, #b0b0c0, #808090);
}
.chat-nombre-rgb--oro {
    background-image: linear-gradient(90deg, #b8860b, #ffd700, #ffec6e, #ffffff, #ffec6e, #ffd700, #b8860b);
}

@keyframes rgb-nombre-scroll {
    from { background-position: 0% center; }
    to { background-position: 300% center; }
}
@keyframes vip-rgb-scroll {
    from { background-position: 0% center; }
    to { background-position: 300% center; }
}