/* ============================================================
   Chat de mensajes — área privada del cliente
   Diseño integrado tipo iMessage / WhatsApp Web
   ============================================================ */

/* ── Contenedor principal ────────────────────────────────── */

.chat-panel {
    border: 1px solid var(--color-border);
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
    margin: 1.5rem 0;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 24px -8px rgba(16, 24, 40, 0.10);
}

/* ── Cabecera ────────────────────────────────────────────── */

.chat-panel__header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: linear-gradient(120deg, var(--color-navy) 0%, var(--color-primary) 100%);
    position: relative;
    overflow: hidden;
}

/* Decoración de fondo sutil */
.chat-panel__header::after {
    content: "";
    position: absolute;
    right: -40px;
    top: -40px;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: rgba(255,255,255,0.06);
    pointer-events: none;
}

.chat-panel__ico {
    font-size: 1.75rem;
    flex-shrink: 0;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.chat-panel__title {
    margin: 0 0 0.15rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.01em;
}

.chat-panel__sub {
    margin: 0;
    font-size: 0.83rem;
    color: rgba(255,255,255,0.7);
}

/* Indicador de estado online (opcional) */
.chat-panel__status {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.2rem;
    font-size: 0.78rem;
    color: rgba(255,255,255,0.65);
}
.chat-panel__status::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
}

/* ── Hilo de mensajes ────────────────────────────────────── */

.chat-hilo {
    flex: 1;
    overflow-y: auto;
    max-height: 520px;
    min-height: 180px;
    padding: 1.5rem 1.5rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: #f4f6fb;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(29,78,216,0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(237,139,46,0.03) 0%, transparent 50%);
    scroll-behavior: smooth;
}

/* Scrollbar discreta */
.chat-hilo::-webkit-scrollbar { width: 4px; }
.chat-hilo::-webkit-scrollbar-track { background: transparent; }
.chat-hilo::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }

/* ── Estado vacío ────────────────────────────────────────── */

.chat-vacio {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--color-muted);
    flex: 1;
}
.chat-vacio__ico { font-size: 3rem; filter: grayscale(0.3); }
.chat-vacio__titulo { font-weight: 600; font-size: 1rem; color: #374151; margin: 0; }
.chat-vacio p { margin: 0; font-size: 0.88rem; max-width: 300px; line-height: 1.5; }

/* ── Mensaje individual ──────────────────────────────────── */

.chat-msg {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    max-width: 78%;
    animation: chat-fadein 0.2s ease;
}

@keyframes chat-fadein {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Gestor — izquierda */
.chat-msg--gestor { align-self: flex-start; }

/* Cliente — derecha, orden invertido */
.chat-msg--cliente {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Avatar */
.chat-msg__avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    background: #e8eef6;
    border: 2px solid #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}
.chat-msg--gestor .chat-msg__avatar {
    background: linear-gradient(135deg, var(--color-navy), var(--color-primary));
    font-size: 0.85rem;
}
.chat-msg--cliente .chat-msg__avatar {
    background: linear-gradient(135deg, #dbeafe, #eff6ff);
}

/* Contenido (meta + burbuja) */
.chat-msg__contenido {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
    min-width: 0;
}
.chat-msg--cliente .chat-msg__contenido { align-items: flex-end; }

/* Meta: nombre + hora */
.chat-msg__meta {
    display: flex;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0 0.25rem;
}
.chat-msg__meta strong {
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
}
.chat-msg__fecha {
    font-size: 0.72rem;
    color: #9ca3af;
}

/* ── Burbujas ────────────────────────────────────────────── */

.chat-msg__burbuja {
    padding: 0.75rem 1.1rem;
    border-radius: 18px;
    font-size: 1rem;         /* más grande que antes */
    line-height: 1.6;
    max-width: 100%;
    word-break: break-word;
    position: relative;
}

/* Burbuja del gestor: blanca */
.chat-msg--gestor .chat-msg__burbuja {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 5px;
    color: #1a1a1a;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

/* Burbuja del cliente: azul sólido */
.chat-msg--cliente .chat-msg__burbuja {
    background: var(--color-primary);
    color: #fff;
    border-bottom-right-radius: 5px;
    box-shadow: 0 3px 12px rgba(29,78,216,0.28);
}

/* Mensajes consecutivos del mismo emisor: reducir gap y quitar avatar en intermedios */
.chat-msg + .chat-msg.chat-msg--gestor,
.chat-msg + .chat-msg.chat-msg--cliente {
    margin-top: -0.25rem;
}

/* Separador de fecha entre días */
.chat-fecha-sep {
    align-self: center;
    font-size: 0.73rem;
    color: #6b7280;
    background: #e8eef6;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    padding: 0.18rem 0.85rem;
    margin: 0.5rem 0;
    flex-shrink: 0;
}

/* ── Caja de composición ─────────────────────────────────── */

.chat-compose {
    border-top: 1px solid var(--color-border);
    padding: 1rem 1.25rem 1.1rem;
    background: #fff;
}

/* Wrapper con foco visible en el borde exterior */
.chat-compose__inner {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    background: #f7f9fc;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    padding: 0.75rem 0.75rem 0.75rem 1.1rem;
    transition: border-color .2s, box-shadow .2s, background .2s;
}
.chat-compose__inner:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(29,78,216,0.09);
    background: #fff;
}

/* Textarea — el cambio más importante */
.chat-compose__textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 1rem;        /* tamaño real, no micro */
    line-height: 1.6;
    padding: 0.1rem 0;
    min-height: 44px;       /* mínimo ~2 líneas visible */
    max-height: 200px;
    overflow-y: auto;
    color: var(--color-text);
    outline: none;
}
.chat-compose__textarea::placeholder {
    color: #9ca3af;
    font-size: 0.97rem;
}

/* Botón de envío */
.chat-compose__btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 0.65rem 1.2rem;
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .18s, transform .15s, box-shadow .18s;
    font-family: inherit;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(29,78,216,0.30);
    align-self: flex-end;   /* pega al fondo del textarea */
    margin-bottom: 0.05rem;
}
.chat-compose__btn:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(29,78,216,0.38);
}
.chat-compose__btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(29,78,216,0.25);
}
.chat-compose__btn svg { flex-shrink: 0; }

/* Pie de la caja */
.chat-compose__hint {
    margin: 0.55rem 0 0;
    font-size: 0.76rem;
    color: #9ca3af;
    text-align: center;
}
.chat-compose__hint kbd {
    display: inline-block;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    padding: 0 0.35rem;
    font-size: 0.73rem;
    font-family: inherit;
    color: #6b7280;
}

/* ── Mobile ──────────────────────────────────────────────── */

@media (max-width: 600px) {
    .chat-msg { max-width: 90%; }
    .chat-hilo { padding: 1rem 1rem 0.5rem; }
    .chat-compose { padding: 0.75rem 0.875rem 0.875rem; }
    .chat-compose__btn span { display: none; }
    .chat-compose__btn { padding: 0.65rem 0.8rem; border-radius: 10px; }
}

/* ── Mensaje tipo ticket (solicitud inicial empresa extranjera) ── */
.chat-msg--ticket {
    max-width: 92%;
    align-self: stretch;
}
.chat-msg__burbuja--ticket {
    background: #f0f5ff;
    border: 1.5px solid #bfdbfe;
    border-left: 4px solid #1a3a7a;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.65;
    color: #1e293b;
    white-space: pre-wrap;
    padding: 0.85rem 1rem;
}
/* Mismo estilo en admin (wapp) */
.wapp-msg--ticket .wapp-msg__burbuja {
    background: #f0f5ff;
    border: 1.5px solid #bfdbfe;
    border-left: 4px solid #1a3a7a;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.65;
    color: #1e293b;
    white-space: pre-wrap;
    max-width: 600px;
}
