/* Widget de chat cliente-operador (estilos base, sin dependencias). */

:root {
    --chat-primary: #007bff;
    --chat-primary-dark: #0062cc;
    --chat-bg: #ffffff;
    --chat-texto: #212529;
    --chat-burbuja-cliente: #007bff;
    --chat-burbuja-cliente-texto: #ffffff;
    --chat-burbuja-operador: #f1f3f5;
    --chat-borde: #dee2e6;
}

#chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--chat-texto);
}

/* ---------- Modo flotante (sitio real del cliente) ---------- */

#chat-launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 56px;
    height: 56px;
    border: 0;
    border-radius: 50%;
    background: var(--chat-primary);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .25);
    z-index: 99998;
}

#chat-launcher:hover {
    background: var(--chat-primary-dark);
}

#chat-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    width: 350px;
    height: 500px;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    border: 1px solid var(--chat-borde);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
    z-index: 99999;
}

#chat-panel[hidden] {
    display: none;
}

/* ---------- Cabecera ---------- */

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: var(--chat-primary);
    color: #fff;
    font-weight: 600;
}

#chat-status {
    font-size: 12px;
    font-weight: 400;
    opacity: .9;
}

.chat-sonido-boton {
    flex: 0 0 auto;
    border: 0;
    background: transparent;
    color: inherit;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    cursor: pointer;
}

/* ---------- Mensajes ---------- */

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.35;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.msg a {
    color: inherit;
    text-decoration: underline;
    overflow-wrap: anywhere;
}

.msg--customer {
    align-self: flex-end;
    background: var(--chat-burbuja-cliente);
    color: var(--chat-burbuja-cliente-texto);
    border-bottom-right-radius: 4px;
}

.msg--operator,
.msg--system {
    align-self: flex-start;
    background: var(--chat-burbuja-operador);
    color: var(--chat-texto);
    border-bottom-left-radius: 4px;
}

.msg--system {
    font-style: italic;
    opacity: .8;
    align-self: center;
}

.msg--aviso {
    align-self: center;
    max-width: 90%;
    text-align: center;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
    font-size: 13px;
}

.msg-leido {
    display: block;
    margin-top: 3px;
    font-size: 10px;
    line-height: 1;
    text-align: right;
    opacity: .8;
}

.msg-leido:empty {
    display: none;
}

.msg-img {
    display: block;
    max-width: 100%;
    max-height: 240px;
    border-radius: 10px;
}

.chat-imagen-input {
    display: none;
}

.chat-imagen-boton {
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    padding: 0;
    background: var(--chat-burbuja-operador);
    color: var(--chat-texto);
    font-size: 16px;
    cursor: pointer;
}

.chat-imagen-boton:hover {
    background: var(--chat-borde);
}

.chat-cargar-mas {
    align-self: center;
    background: transparent;
    border: 0;
    color: var(--chat-primary);
    font-size: 12px;
    cursor: pointer;
}

/* ---------- Formulario ---------- */

#chat-form {
    display: flex;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid var(--chat-borde);
    background: var(--chat-bg);
}

#chat-input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--chat-borde);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
}

#chat-input:focus {
    border-color: var(--chat-primary);
}

#chat-form button[type="submit"] {
    border: 0;
    border-radius: 20px;
    padding: 8px 16px;
    background: var(--chat-primary);
    color: #fff;
    cursor: pointer;
    font-size: 14px;
}

#chat-form button[type="submit"]:disabled {
    opacity: .6;
    cursor: not-allowed;
}

/* ---------- Móvil ---------- */

@media (max-width: 480px) {
    #chat-panel {
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    #chat-launcher {
        right: 14px;
        bottom: 14px;
    }
}

/* ==========================================
    PANTALLA COMPLETA
========================================== */

html,
body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f8f9fb;
    color: #212529;
    overflow: hidden;
}

.chat-page {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    padding: 0;
}

/* ==========================================
    CHAT
========================================== */

#chat-widget {
    width: 100%;
    max-width: none;

    height: 100vh;
    height: 100dvh;

    min-height: 100vh;
    min-height: 100dvh;

    margin: 0;
    padding: 0;

    background: #fff;
    border: 0;
    border-radius: 0;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    box-shadow: none;
}

/* ==========================================
    HEADER
========================================== */

#chat-widget .chat-header {
    position: relative;

    min-height: 72px;

    display: flex;
    align-items: center;
    justify-content: space-between;

    flex-shrink: 0;

    padding: 12px 20px;

    background: linear-gradient(
        135deg,
        #007bff 0%,
        #0062cc 100%
    );

    color: #fff;

    font-weight: 600;

    box-shadow: 0 2px 8px rgba(0, 0, 0, .12);

    z-index: 10;
}

/* ==========================================
    CONTENIDO DEL HEADER
========================================== */

.chat-header-left {
    display: flex;
    align-items: center;

    min-width: 0;
}

.chat-header-content {
    margin-left: 50px;
}

.chat-avatar {
    width: 44px;
    height: 44px;

    border-radius: 50%;

    background: rgba(255, 255, 255, .18);

    display: flex;
    align-items: center;
    justify-content: center;

    margin-right: 12px;

    font-size: 21px;

    flex-shrink: 0;

    border: 1px solid rgba(255, 255, 255, .25);
}

.chat-title {
    display: flex;
    flex-direction: column;

    line-height: 1.2;

    min-width: 0;
}

.chat-title strong {
    font-size: 16px;

    white-space: nowrap;

    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-subtitle {
    font-size: 12px;

    font-weight: 400;

    opacity: .85;

    margin-top: 3px;
}

/* ==========================================
    ESTADO
========================================== */

.chat-status {
    display: flex;
    align-items: center;

    font-size: 12px;

    white-space: nowrap;

    margin-left: 15px;
}

.chat-status-dot {
    width: 8px;
    height: 8px;

    background: #28a745;

    border-radius: 50%;

    margin-right: 6px;

    box-shadow:
        0 0 0 3px rgba(40, 167, 69, .2);
}

/* ==========================================
    BOTÓN VOLVER
========================================== */

.chat-back-button {
    position: absolute;

    left: 18px;
    top: 50%;

    transform: translateY(-50%);

    width: 40px;
    height: 40px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    border-radius: 10px;

    color: #fff;

    background: rgba(255, 255, 255, .14);

    border: 1px solid rgba(255, 255, 255, .18);

    text-decoration: none !important;

    transition:
        background .2s ease,
        transform .2s ease;
}

.chat-back-button:hover {
    color: #fff;

    background: rgba(255, 255, 255, .25);

    transform:
        translateY(-50%)
        translateX(-2px);
}

.chat-back-button:active {
    transform:
        translateY(-50%)
        scale(.95);
}

.chat-back-button svg {
    width: 20px;
    height: 20px;
}

/* ==========================================
    ÁREA DE MENSAJES
========================================== */

#chat-messages {
    flex: 1;

    min-height: 0;

    overflow-y: auto;

    padding: 24px;

    background:
        radial-gradient(
            circle at top left,
            rgba(0, 123, 255, .035),
            transparent 35%
        ),
        #f8f9fb;

    scroll-behavior: smooth;
}

/* Scrollbar */

#chat-messages::-webkit-scrollbar {
    width: 7px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background: #ced4da;

    border-radius: 20px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* Firefox */

#chat-messages {
    scrollbar-width: thin;
    scrollbar-color: #ced4da transparent;
}

/* ==========================================
    FORMULARIO
========================================== */

#chat-form {
    display: flex;
    align-items: flex-end;

    gap: 10px;

    flex-shrink: 0;

    padding: 14px 18px;

    background: #fff;

    border-top: 1px solid #e9ecef;

    box-shadow:
        0 -3px 10px rgba(0, 0, 0, .03);
}

/* ==========================================
    INPUT (textarea multilinea que crece)
========================================== */

#chat-input {
    flex: 1;

    min-width: 0;

    min-height: 48px;
    max-height: 140px;

    padding: 14px 17px;

    border: 1px solid #dee2e6;

    border-radius: 14px;

    background: #f8f9fa;

    color: #212529;

    font-family: inherit;
    font-size: 14px;
    line-height: 20px;

    resize: none;

    overflow-y: auto;

    box-sizing: border-box;

    display: block;

    outline: none;

    transition:
        background .2s ease,
        border-color .2s ease,
        box-shadow .2s ease;
}

#chat-input::placeholder {
    color: #adb5bd;
}

#chat-input:focus {
    background: #fff;

    border-color: #80bdff;

    box-shadow:
        0 0 0 .2rem rgba(0, 123, 255, .12);
}

/* ==========================================
    BOTÓN ENVIAR
========================================== */

#chat-form button[type="submit"] {
    height: 48px;

    min-width: 105px;

    border: 0;

    border-radius: 14px;

    background: linear-gradient(
        135deg,
        #007bff,
        #0069d9
    );

    color: #fff;

    font-weight: 600;

    padding: 0 20px;

    cursor: pointer;

    transition:
        transform .2s ease,
        box-shadow .2s ease;

    box-shadow:
        0 5px 12px rgba(0, 123, 255, .20);
}

#chat-form button[type="submit"]:hover {
    transform: translateY(-1px);

    box-shadow:
        0 7px 16px rgba(0, 123, 255, .28);
}

#chat-form button[type="submit"]:active {
    transform: translateY(0);
}

/* ==========================================
    BOTÓN ADJUNTAR IMAGEN (junto a Enviar)
========================================== */

#chat-form .chat-imagen-boton {
    flex: 0 0 auto;

    width: 48px;
    height: 48px;

    padding: 0;

    border: 1px solid #dee2e6;
    border-radius: 14px;

    background: #f8f9fa;
    color: #495057;

    font-size: 19px;
    line-height: 1;

    cursor: pointer;

    transition:
        background .2s ease,
        border-color .2s ease;
}

#chat-form .chat-imagen-boton:hover {
    background: #e9ecef;
    border-color: #ced4da;
}

#chat-form .chat-imagen-boton:active {
    background: #dee2e6;
}

/* ==========================================
    TABLETS
========================================== */

@media (max-width: 991.98px) {

    #chat-widget {
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }

    #chat-messages {
        padding: 20px;
    }
}

/* ==========================================
    MÓVILES
========================================== */

@media (max-width: 767.98px) {

    .chat-page {
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }

    #chat-widget {
        width: 100%;
        height: 100vh;
        height: 100dvh;

        min-height: 100vh;
        min-height: 100dvh;

        border-radius: 0;
    }

    #chat-widget .chat-header {
        min-height: 64px;

        padding: 10px 14px;
    }

    .chat-back-button {
        left: 12px;

        width: 38px;
        height: 38px;
    }

    .chat-header-content {
        margin-left: 48px;
    }

    .chat-avatar {
        width: 40px;
        height: 40px;

        margin-right: 9px;
    }

    .chat-title strong {
        font-size: 15px;
    }

    .chat-subtitle {
        font-size: 11px;
    }

    .chat-status {
        display: none;
    }

    #chat-messages {
        padding: 16px 12px;
    }

    #chat-form {
        padding: 10px;

        gap: 8px;
    }

    #chat-input {
        min-height: 46px;

        border-radius: 13px;

        padding: 13px 14px;
    }

    #chat-form button[type="submit"] {
        height: 46px;

        min-width: 52px;

        width: 52px;

        padding: 0;

        border-radius: 13px;

        font-size: 0;
    }

    #chat-form button[type="submit"]::after {
        content: "➤";

        font-size: 18px;
    }

    #chat-form .chat-imagen-boton {
        width: 46px;
        height: 46px;

        border-radius: 13px;

        font-size: 18px;
    }
}

/* ==========================================
    MÓVILES PEQUEÑOS
========================================== */

@media (max-width: 380px) {

    .chat-avatar {
        display: none;
    }

    .chat-header-content {
        margin-left: 45px;
    }

    .chat-title strong {
        font-size: 14px;
    }

    .chat-subtitle {
        font-size: 10px;
    }

    #chat-messages {
        padding: 12px 10px;
    }
}

.msg.msg--operator, .msg.msg--customer {
    font-size: 20px;
}

/* ==========================================
    IPHONE
========================================== */

html.chat-iphone #chat-form {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px;
}

html.chat-iphone #chat-input {
    flex: 1 0 100%;
    width: 100%;
    min-height: 46px;
    font-size: 16px;
}

/* El boton Enviar ocupa el resto de la fila; el de adjuntar queda a su lado. */
html.chat-iphone #chat-form button[type="submit"] {
    flex: 1;
    width: auto;
    min-width: 0;
    height: 46px;
    padding: 0;
    border-radius: 13px;
    font-size: 14px;
}

html.chat-iphone #chat-form button[type="submit"]::after {
    content: none;
}

html.chat-iphone #chat-form .chat-imagen-boton {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    border-radius: 13px;
    font-size: 18px;
}