/* Chat entre restaurante y proveedor. Prefijo ch- para no chocar con nada.
 *
 * Se parece a un chat de verdad a propósito: burbujas, el mío a la derecha, el
 * suyo a la izquierda, campo abajo. Nadie tiene que aprender a usarlo, y quien
 * lo abre a las siete de la mañana en la cocina no está para descubrir una
 * interfaz nueva. */

.ch-overlay {
    overscroll-behavior: contain;
    position: fixed;
    inset: 0;
    z-index: 6400;                 /* por encima de ajustes (6300) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    background: rgba(15, 17, 21, .72);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: ch-aparece .18s ease-out;
}
@keyframes ch-aparece { from { opacity: 0 } to { opacity: 1 } }

.ch-caja {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 560px;
    /* Alto fijo: un chat que crece y encoge al escribir mueve todo lo demás. */
    height: min(760px, 88vh);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .28);
    overflow: hidden;
}

.ch-cargando { padding: 48px; text-align: center; color: #6c757d; }
.ch-error { color: #e03131; }

/* ── Cabecera ─────────────────────────────────────────────────────────── */
.ch-cabecera {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    padding: 18px 20px;
    border-bottom: 1px solid #f1f3f5;
}
.ch-cabecera h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.02em; color: #16181d; }
.ch-cabecera > div:first-child { flex: 1; min-width: 0; }
.ch-sub { margin: 2px 0 0; font-size: 13px; color: #868e96; }

.ch-cerrar {
    flex-shrink: 0;
    width: 34px; height: 34px;
    border: 0; border-radius: 50%;
    background: #f1f3f5; color: #495057;
    font-size: 22px; line-height: 1; cursor: pointer;
}
.ch-cerrar:hover { background: #e9ecef; }

.ch-volver, .ch-tel {
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: 0; border-radius: 50%;
    background: transparent; color: #495057;
    cursor: pointer; text-decoration: none;
}
.ch-volver:hover, .ch-tel:hover { background: #f1f3f5; }

.ch-titulo { flex: 1; min-width: 0; }
.ch-titulo strong {
    display: block; font-size: 15.5px; font-weight: 650; color: #16181d;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ch-titulo small { display: block; font-size: 12px; color: #868e96; }

/* El distintivo de verificado. Josep lo pidió "similar al de Meta"
   (reunión del 12/08, 00:28:06): dice que ComPRO ha comprobado quién es esa
   empresa, no que haya pagado más. */
.ch-verificado {
    display: inline-flex; align-items: center; justify-content: center;
    width: 15px; height: 15px;
    border-radius: 50%;
    background: #2563eb; color: #fff;
    font-size: 10px; font-weight: 700;
    vertical-align: 1px;
}

/* ── Bandeja ──────────────────────────────────────────────────────────── */
.ch-grupo {
    margin: 14px 20px 4px;
    color: #868e96;
    font-size: 11.5px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .05em;
}

.ch-lista { margin: 0; padding: 6px 10px; list-style: none; overflow-y: auto; }

.ch-fila {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color .14s ease;
}
.ch-fila:hover { background: #f8f9fa; }
.ch-fila:focus-visible { outline: 2px solid #2563eb; outline-offset: -2px; }

.ch-avatar {
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    width: 42px; height: 42px;
    border-radius: 12px;
    background: #f1f3f5;
    color: #495057;
    font-size: 14px; font-weight: 700;
    overflow: hidden;
}
.ch-avatar img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.ch-cabecera-hilo .ch-avatar { width: 36px; height: 36px; border-radius: 10px; font-size: 12.5px; }

.ch-fila-cuerpo { flex: 1; min-width: 0; }
.ch-fila-alto, .ch-fila-bajo {
    display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.ch-fila-alto strong { font-size: 14.5px; font-weight: 650; color: #16181d; }
.ch-fila-alto small { flex-shrink: 0; font-size: 11.5px; color: #adb5bd; }

.ch-previo {
    flex: 1; min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px; color: #868e96;
}
.ch-fila.es-nuevo .ch-previo { color: #16181d; font-weight: 600; }

.ch-etiqueta {
    padding: 1px 6px;
    border-radius: 5px;
    background: #eef4ff;
    color: #2563eb;
    font-size: 11px; font-weight: 700;
}

.ch-pastilla {
    flex-shrink: 0;
    min-width: 20px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #2563eb; color: #fff;
    font-size: 11px; font-weight: 700; text-align: center;
}

.ch-vacio { padding: 40px 28px; text-align: center; color: #868e96; }
.ch-vacio p { margin: 0 0 8px; font-size: 14px; line-height: 1.5; }
.ch-vacio strong { color: #16181d; }

.ch-btn, .ch-btn-sec {
    padding: 10px 18px;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #fff; color: #495057;
    font: inherit; font-size: 14px; font-weight: 600;
    cursor: pointer;
}
.ch-btn { background: #2563eb; border-color: #2563eb; color: #fff; }
.ch-btn-sec:hover { background: #f8f9fa; }
.ch-btn-nuevo { display: block; margin: 12px 20px 4px; }
.ch-pie-acciones { padding: 14px 20px; border-top: 1px solid #f1f3f5; text-align: right; }

/* ── Hilo ─────────────────────────────────────────────────────────────── */
.ch-contexto {
    flex-shrink: 0;
    padding: 9px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #f1f3f5;
    font-size: 12.5px; color: #495057;
}

.ch-mensajes {
    flex: 1;
    min-height: 0;                 /* sin esto el flex no deja encoger y no hay scroll */
    padding: 16px 18px;
    overflow-y: auto;
    background: #fbfbfc;
}

.ch-vacio-hilo {
    margin: 40px auto; max-width: 320px;
    text-align: center; font-size: 13.5px; line-height: 1.5; color: #adb5bd;
}

.ch-msg { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: 12px; }
.ch-msg.es-propio { align-items: flex-end; }

.ch-msg-autor { margin: 0 4px 3px; font-size: 11.5px; font-weight: 600; color: #868e96; }
.ch-msg-hora  { margin: 3px 4px 0; font-size: 11px; color: #adb5bd; }

.ch-burbuja {
    max-width: 78%;
    padding: 9px 13px;
    border-radius: 16px 16px 16px 4px;
    background: #fff;
    border: 1px solid #e9ecef;
    color: #16181d;
    font-size: 14.5px; line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;       /* una referencia larga no puede desbordar */
}
.ch-msg.es-propio .ch-burbuja {
    border-radius: 16px 16px 4px 16px;
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}
/* Los de ComPRO ni a un lado ni al otro: se ve que entra un tercero. */
.ch-msg.es-sistema { align-items: center; }
.ch-msg.es-sistema .ch-burbuja {
    border-radius: 12px;
    background: #fff8e1;
    border-color: #ffe08a;
    color: #66481a;
    font-size: 13.5px;
}
.ch-msg.es-enviando { opacity: .55; }

/* ── Escribir ─────────────────────────────────────────────────────────── */
.ch-escribir {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid #f1f3f5;
    background: #fff;
}
.ch-escribir textarea {
    flex: 1;
    max-height: 132px;
    padding: 10px 14px;
    border: 1px solid #dee2e6;
    border-radius: 18px;
    background: #f8f9fa;
    color: #16181d;
    font: inherit; font-size: 14.5px; line-height: 1.4;
    resize: none;
}
.ch-escribir textarea:focus { outline: 2px solid #2563eb; outline-offset: -1px; background: #fff; }

.ch-enviar {
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border: 0; border-radius: 50%;
    background: #2563eb; color: #fff;
    cursor: pointer;
}
.ch-enviar:disabled { opacity: .5; cursor: default; }
.ch-enviar:hover:not(:disabled) { background: #1d4ed8; }

/* ── Aviso en Mi Cuenta ───────────────────────────────────────────────── */
.ch-badge {
    min-width: 20px;
    margin-right: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    background: #ff3b30; color: #fff;
    font-size: 11px; font-weight: 700; text-align: center;
}
.ch-badge[hidden] { display: none; }

/* ── Móvil ────────────────────────────────────────────────────────────── */
/* A pantalla completa: la mitad de los pedidos se hacen desde el teléfono y un
   chat con márgenes en 375 px es un chat con menos sitio para hablar. */
@media (max-width: 600px) {
    .ch-overlay { padding: 0; align-items: stretch; }
    .ch-caja { max-width: none; height: 100%; border-radius: 0; }
    .ch-burbuja { max-width: 84%; }
}

@media (prefers-reduced-motion: reduce) {
    .ch-overlay { animation: none; }
}

/* La cara del autor, junto a su nombre y no en una columna aparte: con hilos
   cortos una columna de avatares deja medio ancho vacío. */
.ch-msg-autor { display: inline-flex; align-items: center; gap: 6px; }
.ch-msg-cara {
    width: 18px; height: 18px;
    border-radius: 50%;
    object-fit: cover;
    background: #f1f3f5;
}
