/**
 * Estilos del widget de chat en vivo (sitio público).
 * Archivo: assets/css/chat.css
 *
 * Autor: Juan Morel (jcmorelm@mvisual.cl)
 */

.mv-chat {
    position: fixed;
    right: 1rem;
    bottom: 5.5rem;
    z-index: 1055;
    font-family: var(--mv-font, 'Inter', system-ui, sans-serif);
}

.mv-chat-fab {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    background: linear-gradient(135deg, var(--mv-accent, #0037a0) 0%, #1a56c4 55%, var(--mv-teal, #348888) 100%);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.35);
    font-weight: 700;
    font-size: 0.95rem;
    padding: 0.85rem 1.15rem 0.85rem 0.95rem;
    border-radius: 999px;
    box-shadow:
        0 10px 28px rgba(0, 55, 160, 0.42),
        0 0 0 0 rgba(0, 55, 160, 0.28);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
    position: relative;
    animation: mv-chat-fab-pulse 2.2s ease-in-out infinite;
    min-height: 3.25rem;
    touch-action: manipulation;
}

.mv-chat-fab-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    flex-shrink: 0;
}

.mv-chat-fab-icon-wrap i {
    font-size: 1.35rem;
    line-height: 1;
}

.mv-chat-fab-live-dot {
    position: absolute;
    top: -0.05rem;
    right: -0.05rem;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
}

.mv-chat-fab-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.15;
    text-align: left;
}

.mv-chat-fab-label {
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}

.mv-chat-fab-sublabel {
    font-size: 0.72rem;
    font-weight: 600;
    opacity: 0.95;
}

.mv-chat-fab:hover,
.mv-chat-fab:focus {
    color: #fff;
    transform: translateY(-3px) scale(1.02);
    filter: brightness(1.03);
    box-shadow:
        0 14px 34px rgba(0, 55, 160, 0.48),
        0 0 0 10px rgba(0, 55, 160, 0.1);
    animation: none;
}

.mv-chat-fab[aria-expanded="true"] {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
}

@keyframes mv-chat-fab-pulse {
    0%,
    100% {
        box-shadow:
            0 10px 28px rgba(0, 55, 160, 0.42),
            0 0 0 0 rgba(0, 55, 160, 0.22);
    }
    50% {
        box-shadow:
            0 12px 32px rgba(0, 55, 160, 0.5),
            0 0 0 12px rgba(0, 55, 160, 0);
    }
}

.mv-chat-badge {
    position: absolute;
    top: -0.35rem;
    right: -0.2rem;
    min-width: 1.35rem;
    height: 1.35rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: var(--accent-color, #e74c3c);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.35rem;
    text-align: center;
    border: 2px solid #fff;
}

.mv-chat-panel {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    width: min(100vw - 1.5rem, 22rem);
    max-height: min(78vh, 34rem);
    height: min(78vh, 34rem);
    background: var(--mv-surface, #fff);
    border: 1px solid var(--mv-line, #d5dde5);
    border-radius: 0.75rem;
    box-shadow: 0 12px 40px rgba(44, 62, 80, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mv-chat-panel[hidden] {
    display: none !important;
}

.mv-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 0.85rem 0.65rem;
    background: linear-gradient(135deg, var(--mv-accent, #0037a0) 0%, #1a4fbf 100%);
    color: #fff;
}

.mv-chat-header-main {
    display: flex;
    gap: 0.65rem;
    min-width: 0;
    flex: 1;
}

.mv-chat-header-text {
    min-width: 0;
    flex: 1;
}

.mv-chat-avatar {
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mv-chat-avatar i {
    font-size: 1.2rem;
}

.mv-chat-titulo {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
}

.mv-chat-subtitulo {
    margin: 0.15rem 0 0;
    font-size: 0.72rem;
    opacity: 0.92;
    line-height: 1.3;
}

.mv-chat-presencia {
    margin: 0.35rem 0 0;
    font-size: 0.72rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.mv-chat-presencia-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #9ca3af;
    flex-shrink: 0;
}

.mv-chat-presencia-dot--presente {
    background: #22c55e;
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.25);
}

.mv-chat-presencia-dot--ausente {
    background: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.mv-chat-cerrar {
    background: transparent;
    border: 0;
    color: #fff;
    padding: 0.35rem;
    line-height: 1;
    opacity: 0.9;
    cursor: pointer;
    min-width: 2.75rem;
    min-height: 2.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    touch-action: manipulation;
}

.mv-chat-cerrar:hover,
.mv-chat-cerrar:focus {
    opacity: 1;
}

.mv-chat-ausente {
    padding: 0.5rem 0.75rem;
    background: #fff8e6;
    border-bottom: 1px solid #f0e2b8;
    color: #7a5b00;
    font-size: 0.78rem;
    line-height: 1.4;
}

.mv-chat-datos {
    padding: 0.4rem 0.75rem 0.5rem;
    border-bottom: 1px solid var(--mv-line, #d5dde5);
    background: transparent;
    flex-shrink: 0;
}

.mv-chat-datos-nota {
    margin: 0;
    font-size: 0.68rem;
    line-height: 1.35;
    color: #8a96a3;
    font-weight: 400;
}

.mv-chat-datos-label {
    font-size: 0.72rem;
    color: var(--mv-muted, #5a6a7a);
    font-weight: 500;
    margin-bottom: 0.15rem !important;
}

.mv-chat-mensajes {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
    background: var(--mv-bg, #f8f9fa);
}

.mv-chat-msg {
    max-width: 88%;
    padding: 0.5rem 0.65rem;
    border-radius: 0.65rem;
    font-size: 0.84rem;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.mv-chat-msg--visitante {
    align-self: flex-end;
    background: var(--mv-accent, #0037a0);
    color: #fff;
    border-bottom-right-radius: 0.2rem;
}

.mv-chat-msg--admin {
    align-self: flex-start;
    background: #fff;
    color: var(--mv-ink, #2c3e50);
    border: 1px solid var(--mv-line, #d5dde5);
    border-bottom-left-radius: 0.2rem;
}

.mv-chat-msg--sistema {
    align-self: center;
    max-width: 100%;
    background: transparent;
    color: var(--mv-muted, #5a6a7a);
    font-size: 0.75rem;
    text-align: center;
    padding: 0.25rem 0.5rem;
}

.mv-chat-msg-meta {
    display: block;
    margin-top: 0.2rem;
    font-size: 0.65rem;
    opacity: 0.75;
}

.mv-chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
    padding: 0.65rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--mv-line, #d5dde5);
    background: #fff;
    flex-shrink: 0;
}

.mv-chat-input {
    resize: none;
    min-height: 2.75rem;
    max-height: 6rem;
    font-size: 1rem;
}

.mv-chat-enviar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    flex-shrink: 0;
    white-space: nowrap;
    min-height: 2.75rem;
    min-width: 2.75rem;
    touch-action: manipulation;
}

.mv-chat-enviar:disabled {
    opacity: 0.65;
}

@media (max-width: 575.98px) {
    body.mv-chat-abierto {
        overflow: hidden;
    }

    body.mv-chat-abierto .mv-whatsapp-float {
        visibility: hidden;
        pointer-events: none;
    }

    .mv-chat {
        right: calc(0.75rem + env(safe-area-inset-right, 0px));
        bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
        z-index: 1060;
    }

    .mv-chat-panel {
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        max-width: none;
        max-height: none;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        border: 0;
        box-shadow: none;
    }

    .mv-chat-header {
        padding-top: calc(0.85rem + env(safe-area-inset-top, 0px));
    }

    .mv-chat-titulo {
        font-size: 0.9rem;
    }

    .mv-chat-subtitulo {
        font-size: 0.68rem;
    }

    .mv-chat-fab {
        padding: 0.85rem;
        min-height: 3.5rem;
        min-width: 3.5rem;
        justify-content: center;
        gap: 0;
        border-radius: 50%;
    }

    .mv-chat-fab-text {
        display: none;
    }

    .mv-chat-form {
        align-items: stretch;
    }

    .mv-chat-enviar .mv-chat-enviar-texto {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .mv-chat-enviar {
        align-self: flex-end;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
}

@media (max-width: 420px) {
    .mv-chat {
        bottom: calc(5.25rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .mv-chat-panel {
        width: min(100vw - 2rem, 24rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .mv-chat-fab {
        animation: none;
        transition: none;
    }
}
