/* ============= CHAT DEL EQUIPO ============= */

/* La página del chat ocupa la pantalla: header fijo arriba, mensajes en medio
   y compositor justo encima de la barra de navegación inferior. */
#page-chat.active {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    padding-bottom: 0;
    overflow: hidden;
}
#page-chat .header { flex-shrink: 0; }

/* Mientras el chat está abierto, los elementos flotantes (instalar app y barra
   de sesión en vivo) se ocultan para no tapar el compositor ni el botón de
   enviar. Reaparecen al salir del chat. */
body.chat-page-open .install-float,
body.chat-page-open #live-bar {
    display: none !important;
}

.chat-page-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 56rem;
    margin: 0 auto;
    padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px));
}

/* ---------- Indicador en la barra inferior ---------- */
.chat-nav-badge {
    position: absolute;
    top: 1px;
    right: calc(50% - 20px);
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 8px;
    background: #ef4444;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
    box-shadow: 0 0 0 2px rgba(24, 24, 27, .95);
}
.chat-nav-badge[hidden] { display: none; }

/* ---------- Lista de mensajes ---------- */
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-day {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 12px 0 8px;
}
.chat-day span {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #71717a;
    background: rgba(39, 39, 42, .7);
    border: 1px solid rgba(63, 63, 70, .4);
    border-radius: 999px;
    padding: 3px 10px;
}

.chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 5px 2px;
    max-width: 100%;
}
.chat-msg-own { flex-direction: row-reverse; }

.chat-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .68rem;
    font-weight: 800;
    color: #09090b;
    margin-top: 2px;
    user-select: none;
}

.chat-msg-body {
    min-width: 0;
    max-width: min(78%, 34rem);
    display: flex;
    flex-direction: column;
}
.chat-msg-own .chat-msg-body { align-items: flex-end; }

.chat-msg-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 3px 2px;
    min-width: 0;
}
.chat-msg-own .chat-msg-head { flex-direction: row-reverse; }

.chat-msg-name {
    font-size: .7rem;
    font-weight: 700;
    color: #d4d4d8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 14rem;
}
.chat-msg-time { font-size: .62rem; color: #71717a; flex-shrink: 0; }

.chat-msg-delete {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #52525b;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}
.chat-msg-delete:hover { color: #f87171; background: rgba(248, 113, 113, .12); }

.chat-bubble {
    background: rgba(39, 39, 42, .85);
    border: 1px solid rgba(63, 63, 70, .45);
    border-radius: 4px 14px 14px 14px;
    padding: 8px 11px;
    color: #e4e4e7;
    font-size: .85rem;
    line-height: 1.45;
    max-width: 100%;
    word-break: break-word;
}
.chat-msg-own .chat-bubble {
    background: rgba(52, 153, 128, .18);
    border-color: rgba(52, 153, 128, .38);
    border-radius: 14px 4px 14px 14px;
    color: #ecfdf5;
}

.chat-text { white-space: normal; }
.chat-muted { color: #71717a; font-style: italic; }
.chat-deleted { color: #71717a; font-style: italic; font-size: .78rem; }
.chat-link { color: #41b89c; text-decoration: underline; word-break: break-all; }
.chat-mention {
    color: #86efac;
    font-weight: 700;
    background: rgba(52, 153, 128, .2);
    border-radius: 5px;
    padding: 0 3px;
}

/* ---------- Imágenes y stickers dentro de un mensaje ---------- */
.chat-image-wrap {
    display: block;
    padding: 0;
    margin: 6px 0 0;
    border: none;
    background: transparent;
    cursor: zoom-in;
    max-width: 100%;
}
.chat-image {
    display: block;
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
    object-fit: cover;
    border: 1px solid rgba(63, 63, 70, .5);
}

.chat-sticker-sent {
    display: inline-block;
    padding: 2px 0;
    margin-top: 4px;
    border: none;
    background: transparent;
    cursor: zoom-in;
}
.chat-sticker-sent img {
    display: block;
    width: 96px;
    height: 96px;
    object-fit: contain;
}
.chat-sticker-emoji { font-size: 2.6rem; line-height: 1.15; }

/* ---------- Adjunto (canción / repertorio) ---------- */
.chat-attachment {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    margin-top: 6px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid rgba(52, 153, 128, .3);
    background: rgba(9, 9, 11, .45);
    color: #d4d4d8;
    text-align: left;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.chat-attachment:hover {
    border-color: rgba(52, 153, 128, .6);
    background: rgba(52, 153, 128, .1);
}
.chat-attachment-icon { font-size: 1.1rem; flex-shrink: 0; }
.chat-attachment-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-attachment-label {
    font-size: .6rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #41b89c;
    font-weight: 700;
}
.chat-attachment-title {
    font-size: .8rem;
    font-weight: 600;
    color: #f4f4f5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-attachment-sub { font-size: .66rem; color: #a1a1aa; }
.chat-attachment-arrow { color: #52525b; font-size: 1.1rem; flex-shrink: 0; }

/* ---------- Estados vacíos / carga / avisos ---------- */
.chat-empty {
    margin: auto;
    padding: 26px 18px;
    text-align: center;
    color: #71717a;
    max-width: 22rem;
}
.chat-empty-icon { font-size: 2.2rem; margin-bottom: 8px; }
.chat-empty h2 { font-size: .95rem; color: #e4e4e7; margin-bottom: 6px; }
.chat-empty p { font-size: .78rem; line-height: 1.5; margin-bottom: 14px; }

.chat-empty-small {
    padding: 22px 12px;
    text-align: center;
    font-size: .78rem;
    line-height: 1.55;
    color: #71717a;
}
.chat-loading {
    margin: auto;
    padding: 24px 12px;
    text-align: center;
    font-size: .78rem;
    color: #71717a;
}

.chat-notice {
    margin: 10px 4px;
    padding: 12px 14px;
    border-radius: 10px;
    font-size: .78rem;
    line-height: 1.5;
}
.chat-notice-warning {
    background: rgba(251, 191, 36, .1);
    border: 1px solid rgba(251, 191, 36, .35);
    color: #fcd34d;
}
.chat-notice code {
    background: rgba(9, 9, 11, .6);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: .72rem;
    color: #fff;
}

/* ---------- Compositor ---------- */
.chat-composer {
    flex-shrink: 0;
    background: rgba(9, 9, 11, .97);
    border-top: 1px solid rgba(39, 39, 42, .9);
    padding: 8px 10px 10px;
}

.chat-pending {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 7px;
}
.chat-pending[hidden] { display: none; }
.chat-pending-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 6px 4px 9px;
    border-radius: 8px;
    border: 1px solid rgba(52, 153, 128, .35);
    background: rgba(52, 153, 128, .12);
    color: #d4d4d8;
    font-size: .72rem;
}
.chat-pending-chip button {
    border: none;
    background: transparent;
    color: #a1a1aa;
    font-size: .95rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.chat-pending-chip button:hover { color: #f87171; }
.chat-pending-image img {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    object-fit: cover;
}

.chat-suggest {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 190px;
    overflow-y: auto;
    margin-bottom: 6px;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid rgba(63, 63, 70, .6);
    background: #18181b;
}
.chat-suggest[hidden] { display: none; }
.chat-suggest button {
    display: flex;
    align-items: baseline;
    gap: 7px;
    width: 100%;
    padding: 7px 9px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #e4e4e7;
    text-align: left;
    cursor: pointer;
}
.chat-suggest button:hover { background: rgba(52, 153, 128, .15); }
.chat-suggest-name { font-size: .8rem; font-weight: 600; }
.chat-suggest-user { font-size: .68rem; color: #71717a; }

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 5px;
}

.chat-tool-btn {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(63, 63, 70, .45);
    border-radius: 9px;
    background: rgba(39, 39, 42, .6);
    color: #a1a1aa;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
    transition: all .15s;
}
.chat-tool-btn:hover { color: #41b89c; border-color: rgba(52, 153, 128, .45); }
.chat-tool-btn:active { transform: scale(.94); }

.chat-input {
    flex: 1;
    min-width: 0;
    min-height: 36px;
    max-height: 120px;
    padding: 8px 11px;
    border-radius: 10px;
    border: 1px solid rgba(63, 63, 70, .55);
    background: rgba(39, 39, 42, .6);
    color: #fff;
    font-size: 16px;
    font-family: inherit;
    line-height: 1.35;
    resize: none;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.chat-input:focus { border-color: rgba(52, 153, 128, .6); box-shadow: 0 0 0 2px rgba(52, 153, 128, .18); }
.chat-input::placeholder { color: #71717a; }

.chat-send-btn {
    flex-shrink: 0;
    width: 38px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: #349980;
    color: #000;
    cursor: pointer;
    transition: all .15s;
}
.chat-send-btn:hover { background: #41b89c; }
.chat-send-btn:active { transform: scale(.94); }
.chat-send-btn:disabled { opacity: .55; cursor: wait; transform: none; }

/* ---------- Modal utilitario (adjuntos, stickers, menciones) ---------- */
.chat-modal {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0, 0, 0, .68);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    padding: 0;
}
.chat-modal-card {
    width: 100%;
    max-width: 32rem;
    max-height: 82vh;
    max-height: 82dvh;
    overflow-y: auto;
    background: #18181b;
    border: 1px solid rgba(63, 63, 70, .7);
    border-bottom: none;
    border-radius: 18px 18px 0 0;
    padding: 16px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    animation: chatModalIn .22s ease;
}
@keyframes chatModalIn {
    from { transform: translateY(18px); opacity: .5; }
    to { transform: translateY(0); opacity: 1; }
}

.chat-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}
.chat-modal-title { font-size: .98rem; font-weight: 700; color: #fff; }
.chat-modal-sub { font-size: .7rem; color: #a1a1aa; margin-top: 2px; }
.chat-modal-close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: rgba(63, 63, 70, .5);
    color: #d4d4d8;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}
.chat-modal-close:hover { background: rgba(248, 113, 113, .2); color: #fca5a5; }
.chat-modal-full-btn { width: 100%; justify-content: center; margin-top: 14px; }

.chat-picker-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    margin-bottom: 10px;
    border-radius: 10px;
    background: rgba(39, 39, 42, .8);
}
.chat-picker-tabs button {
    flex: 1;
    padding: 7px 8px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: #a1a1aa;
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}
.chat-picker-tabs button.active { background: #349980; color: #000; }

.chat-picker-search { margin-bottom: 10px; }
.chat-picker-body { max-height: 46vh; overflow-y: auto; }

.chat-option {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px;
    border: none;
    border-bottom: 1px solid rgba(63, 63, 70, .3);
    background: transparent;
    color: #e4e4e7;
    text-align: left;
    cursor: pointer;
}
.chat-option:last-child { border-bottom: none; }
.chat-option:hover { background: rgba(52, 153, 128, .1); }
.chat-option-icon {
    width: 30px;
    height: 30px;
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: rgba(39, 39, 42, .9);
    font-size: .95rem;
}
.chat-option-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #09090b;
    font-size: .68rem;
    font-weight: 800;
}
.chat-option-copy { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-option-title {
    font-size: .82rem;
    font-weight: 600;
    color: #f4f4f5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-option-sub { font-size: .68rem; color: #a1a1aa; }
.chat-option-arrow { color: #52525b; font-size: 1.1rem; flex-shrink: 0; }

/* ---------- Stickers ---------- */
.chat-sticker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 8px;
}
.chat-sticker-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 6px;
    border: 1px solid rgba(63, 63, 70, .45);
    border-radius: 10px;
    background: rgba(39, 39, 42, .5);
    color: #a1a1aa;
    cursor: pointer;
    transition: all .15s;
}
.chat-sticker-btn:hover {
    border-color: rgba(52, 153, 128, .55);
    background: rgba(52, 153, 128, .1);
}
.chat-sticker-btn img {
    width: 52px;
    height: 52px;
    object-fit: contain;
}
.chat-sticker-btn .chat-sticker-emoji { font-size: 2rem; }
.chat-sticker-btn span:last-child {
    font-size: .62rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Visor de imagen ---------- */
.chat-image-modal {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0, 0, 0, .9);
}
.chat-image-modal img {
    max-width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: 10px;
    object-fit: contain;
}
.chat-image-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(39, 39, 42, .9);
    color: #fff;
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
}

/* ---------- Admin: stickers del chat ---------- */
.chat-admin-form {
    padding: 14px;
    margin-bottom: 6px;
    border-radius: 12px;
    border: 1px solid rgba(63, 63, 70, .5);
    background: rgba(39, 39, 42, .4);
}
.chat-admin-form-title {
    font-size: .86rem;
    font-weight: 700;
    color: #fff;
    margin-bottom: 10px;
}
.chat-admin-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.chat-admin-row .input { flex: 1; min-width: 140px; }
.chat-admin-emoji { max-width: 90px; text-align: center; }
.chat-admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
}
.chat-admin-sticker {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(63, 63, 70, .5);
    background: rgba(39, 39, 42, .4);
}
.chat-admin-sticker-preview {
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-admin-sticker-preview img {
    max-width: 64px;
    max-height: 64px;
    object-fit: contain;
}
.chat-admin-sticker-name {
    font-size: .72rem;
    color: #d4d4d8;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (min-width: 640px) {
    .chat-modal { align-items: center; padding: 20px; }
    .chat-modal-card {
        border-radius: 16px;
        border-bottom: 1px solid rgba(63, 63, 70, .7);
        padding-bottom: 18px;
    }
    .chat-msg-body { max-width: min(72%, 36rem); }
}

@media (max-width: 420px) {
    .chat-tool-btn { width: 30px; height: 32px; }
    .chat-send-btn { width: 34px; height: 32px; }
    .chat-input { min-height: 32px; padding: 7px 9px; }
    .chat-msg-body { max-width: 80%; }
}
