/* Mensajes (Fase 3). Estilo paisaje de Kaulo: verde montaña, dorado y niebla. */

/* ── Ícono de Mensajes en la barra (junto a la campanita) ── */
.rh-chatlink {
    position: relative;
    margin-left: auto;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: var(--xx-r);
    color: inherit;
    text-decoration: none;
}
.rh-chatlink:hover { background: rgba(255, 255, 255, .1); }
.rh-chatlink:focus-visible { outline: none; box-shadow: var(--xx-ring); }
.rh-chatlink svg { width: 20px; height: 20px; }
.rh-chatlink + .rh-bell { margin-left: 8px; }
.rh-chatlink--light { color: var(--xx-ink); border-color: var(--xx-line); margin-left: 0; }
.rh-chatlink--light:hover { background: var(--xx-navy-50); }
.rh-chatlink--light .rh-bell__count { box-shadow: 0 0 0 2px #fff; }

/* ── Pantalla: lista a la izquierda, plática a la derecha ── */
.rh-chat {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 0;
    height: calc(100dvh - 190px);
    min-height: 420px;
    background: var(--xx-surface);
    border: 1px solid var(--xx-line);
    border-radius: var(--xx-r-lg);
    overflow: hidden;
}
.rh-mi .rh-chat { height: calc(100dvh - 120px); }

.rh-chat__side { display: flex; flex-direction: column; border-right: 1px solid var(--xx-line); min-height: 0; background: var(--xx-canvas); }
.rh-chat__side-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--xx-line); }
.rh-chat__h1 { font-size: 1.25rem; margin: 0 0 10px; }
.rh-chat__new { display: flex; gap: 8px; flex-wrap: wrap; }
.rh-chat__list { overflow-y: auto; flex: 1; }

.rh-chat__item {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 2px 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--xx-line);
    color: var(--xx-ink);
    text-decoration: none;
}
.rh-chat__item:hover { background: var(--xx-neutral-bg); }
.rh-chat__item--on { background: #fff; box-shadow: inset 3px 0 0 var(--rh-mountains); }
.rh-chat__item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rh-chat__item-time { font-size: .75rem; color: var(--xx-neutral-fg); }
.rh-chat__item-preview { grid-column: 1; font-size: .85rem; color: var(--xx-neutral-fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rh-chat__item--unread .rh-chat__item-title,
.rh-chat__item--unread .rh-chat__item-preview { color: var(--xx-ink); font-weight: 700; }
.rh-chat__badge {
    grid-column: 2;
    justify-self: end;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--rh-sunglow);
    color: var(--xx-ink);
    font-size: .75rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.rh-chat__main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.rh-chat__placeholder { margin: auto; color: var(--xx-neutral-fg); padding: 24px; text-align: center; }
.rh-chat__empty { color: var(--xx-neutral-fg); padding: 16px; margin: 0; }
.rh-chat__back { display: none; }

.rh-chat__head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--xx-line); }
.rh-chat__head > div { flex: 1; min-width: 0; }
.rh-chat__title { font-size: 1.05rem; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rh-chat__info { position: relative; }
.rh-chat__info summary { list-style: none; }
.rh-chat__info summary::-webkit-details-marker { display: none; }
.rh-chat__info-body {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    width: min(340px, 86vw);
    max-height: 60vh;
    overflow-y: auto;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--xx-line);
    border-radius: var(--xx-r);
    box-shadow: var(--xx-shadow-lg);
}
.rh-chat__members { list-style: none; padding: 0; margin: 0 0 12px; }
.rh-chat__members li { padding: 3px 0; }

/* ── La plática ── */
.rh-chat__thread {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--xx-canvas);
}
.rh-chat__older { align-self: center; }
.rh-msg {
    max-width: min(78%, 620px);
    align-self: flex-start;
    padding: 8px 12px 6px;
    border-radius: 12px 12px 12px 4px;
    background: #fff;
    border: 1px solid var(--xx-line);
}
.rh-msg--mine { align-self: flex-end; background: #e6efe9; border-color: #cfe0d6; border-radius: 12px 12px 4px 12px; }
.rh-msg__who { display: block; font-size: .78rem; font-weight: 700; color: var(--rh-mountains); margin-bottom: 2px; }
.rh-msg__body { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--xx-ink); }
.rh-msg__body a { color: var(--rh-mountains); text-decoration: underline; }
.rh-msg__time { display: block; text-align: right; font-size: .7rem; color: var(--xx-neutral-fg); margin-top: 2px; }
.rh-msg--sending { opacity: .6; }
.rh-msg--failed { border-color: #d9534f; cursor: pointer; }
.rh-msg--failed .rh-msg__time { color: #b02a37; }

/* ── Desconexión y urgente (bloque 2) ── */
.rh-msg--urgent { border-color: var(--rh-sunglow); box-shadow: inset 3px 0 0 var(--rh-sunglow); }
.rh-msg__urgent { display: block; font-size: .78rem; font-weight: 700; color: #8a6a12; margin-bottom: 2px; }
.rh-msg__held { display: block; text-align: right; font-size: .72rem; color: var(--rh-mountains); font-style: italic; }
.rh-chat__away { padding: 8px 14px; border-top: 1px solid var(--xx-line); background: #fbf6e6; font-size: .88rem; color: var(--xx-ink); }
.rh-chat__urgent-toggle { display: flex; gap: 6px; align-items: center; margin-top: 6px; font-weight: 600; }
.rh-chat__urgent-why { margin-top: 6px; }
.rh-chat__urgent-why .form-label { font-size: .82rem; margin-bottom: 2px; }
.rh-chat__urgent-error { color: #b02a37; font-size: .82rem; margin-top: 4px; }

/* ── Avisos (bloque 3) ── */
.rh-chat__push { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; padding: 8px 10px; background: #fbf6e6; border-radius: var(--xx-r); font-size: .85rem; }
.rh-chat__push[hidden] { display: none; }
.rh-chat__muted-mark { font-size: .8rem; font-weight: 400; }
.rh-chat__badge--muted { background: var(--xx-line); color: var(--xx-neutral-fg); }
.rh-chat__item--muted.rh-chat__item--unread .rh-chat__item-preview { font-weight: 400; color: var(--xx-neutral-fg); }

.rh-chat__compose { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px; border-top: 1px solid var(--xx-line); background: #fff; }
.rh-chat__compose textarea { resize: none; max-height: 160px; }
/* ── Archivos, fotos y voz (bloque 4) ── */
.rh-msg__photo { display: block; margin: 2px 0 4px; }
.rh-msg__photo img { display: block; max-width: 100%; max-height: 280px; border-radius: 8px; background: var(--xx-neutral-bg); cursor: zoom-in; }
.rh-msg__voice { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 4px; }
.rh-msg__voice audio { max-width: 100%; width: 260px; height: 40px; }
.rh-msg__voice-time { font-size: .78rem; color: var(--xx-neutral-fg); }
.rh-msg__file { display: flex; align-items: center; gap: 6px; padding: 8px 10px; margin: 2px 0 4px; border: 1px solid var(--xx-line); border-radius: 8px; background: rgba(255,255,255,.7); color: var(--xx-ink); text-decoration: none; }
.rh-msg__file:hover { background: #fff; }
.rh-msg__file-name { font-weight: 600; overflow-wrap: anywhere; }
.rh-msg__file-size { font-size: .75rem; color: var(--xx-neutral-fg); white-space: nowrap; }
.rh-chat__tool { flex: 0 0 auto; padding-left: 10px; padding-right: 10px; }
.rh-chat__mic { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.rh-chat__mic--on { background: #c0392b; border-color: #c0392b; color: #fff; }
.rh-chat__pending, .rh-chat__rec, .rh-chat__hint { display: flex; align-items: center; gap: 10px; padding: 6px 14px; border-top: 1px solid var(--xx-line); background: #fbf6e6; font-size: .85rem; color: var(--xx-ink); }
.rh-chat__pending[hidden], .rh-chat__rec[hidden], .rh-chat__hint[hidden] { display: none; }
.rh-chat__pending-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; }
.rh-chat__pending-name { flex: 1 1 auto; overflow-wrap: anywhere; }
.rh-chat__rec { background: #fdecea; }
.rh-chat__rec--cancel { background: var(--xx-neutral-bg); color: var(--xx-neutral-fg); }
.rh-chat__rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #c0392b; animation: rh-rec 1s ease-in-out infinite; }
.rh-chat__rec--cancel .rh-chat__rec-dot { background: var(--xx-neutral-fg); animation: none; }
.rh-chat__rec-time { font-variant-numeric: tabular-nums; font-weight: 700; }
@keyframes rh-rec { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .rh-chat__rec-dot { animation: none; } }
.rh-chat__viewer { padding: 0; border: 0; border-radius: var(--xx-r-lg); background: #111; max-width: 96vw; max-height: 94vh; }
.rh-chat__viewer::backdrop { background: rgba(0,0,0,.75); }
.rh-chat__viewer img { display: block; max-width: 96vw; max-height: calc(94vh - 48px); margin: 0 auto; }
.rh-chat__viewer-bar { display: flex; justify-content: flex-end; gap: 8px; padding: 8px; }

.rh-chat__closed { margin: 0; padding: 12px 16px; border-top: 1px solid var(--xx-line); color: var(--xx-neutral-fg); background: #fff; }

/* ── Elegir persona / crear grupo ── */
.rh-chat__pick { padding: 16px; overflow-y: auto; }
.rh-chat__people { list-style: none; padding: 0; margin: 0; }
.rh-chat__person {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-bottom: 1px solid var(--xx-line);
    background: none;
    text-align: left;
    color: var(--xx-ink);
}
.rh-chat__person:hover { background: var(--xx-neutral-bg); }
.rh-chat__checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; max-height: 40vh; overflow-y: auto; }
.rh-chat__check { display: flex; gap: 8px; align-items: baseline; }

/* ── Celular: una columna; con plática abierta se esconde la lista ── */
@media (max-width: 767.98px) {
    .rh-chat { grid-template-columns: 1fr; height: calc(100dvh - 110px); border-radius: 0; border-left: 0; border-right: 0; }
    .rh-chat--open .rh-chat__side { display: none; }
    .rh-chat:not(.rh-chat--open) .rh-chat__main { display: none; }
    .rh-chat__back { display: inline-block; margin-right: 4px; white-space: nowrap; }
    .rh-chat__pick .rh-chat__back { margin-bottom: 8px; }
    .rh-msg { max-width: 88%; }
}

/* ── Bloque 5: responder, editar, borrar, reacciones, fijar, visto por, @menciones, búsqueda ── */
.rh-msg__foot { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 2px; font-size: .7rem; color: var(--xx-neutral-fg); }
.rh-msg__foot .rh-msg__time { display: inline; margin: 0; }
.rh-msg__edited { font-style: italic; }
.rh-msg__seen { border: 0; background: none; padding: 0; font: inherit; color: var(--xx-neutral-fg); }
button.rh-msg__seen { text-decoration: underline dotted; cursor: pointer; }
.rh-msg__seen--on { color: var(--rh-mountains); font-weight: 600; }
.rh-msg__menu {
    border: 0; background: none; padding: 0 4px; border-radius: 6px; font-size: 1rem; line-height: 1; color: var(--xx-neutral-fg); cursor: pointer;
}
.rh-msg__menu:hover, .rh-msg__menu:focus-visible { background: var(--xx-neutral-bg); color: var(--xx-ink); outline: none; }
.rh-msg__pin { display: block; font-size: .72rem; font-weight: 700; color: #8a6a12; margin-bottom: 2px; }
.rh-msg--deleted { background: transparent; border-style: dashed; }
.rh-msg__body--gone { font-style: italic; color: var(--xx-neutral-fg); }
.rh-msg--mention { box-shadow: inset 3px 0 0 var(--rh-mountains); }
.rh-msg__mention { font-weight: 700; color: var(--rh-mountains); background: #e6efe9; border-radius: 4px; padding: 0 2px; }
.rh-msg--focus { animation: rh-msg-focus 2.4s ease-out; }
@keyframes rh-msg-focus { 0%, 40% { box-shadow: 0 0 0 3px var(--rh-sunglow); } 100% { box-shadow: 0 0 0 0 transparent; } }
@media (prefers-reduced-motion: reduce) { .rh-msg--focus { animation: none; outline: 3px solid var(--rh-sunglow); } }
.rh-msg__quote {
    display: block; width: 100%; text-align: left; margin: 2px 0 6px; padding: 4px 8px; border: 0; border-left: 3px solid var(--rh-mountains);
    border-radius: 4px; background: rgba(79, 100, 87, .08); font-size: .8rem; color: var(--xx-ink); cursor: pointer;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rh-msg__quote strong { margin-right: 6px; color: var(--rh-mountains); }
.rh-msg__reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rh-msg__reaction {
    border: 1px solid var(--xx-line); background: #fff; border-radius: 12px; padding: 0 8px; font-size: .8rem; line-height: 22px; cursor: pointer;
}
.rh-msg__reaction--mine { border-color: var(--rh-mountains); background: #e6efe9; font-weight: 700; }

.rh-chat__menu {
    position: fixed; z-index: 1080; min-width: 200px; max-width: min(320px, calc(100vw - 16px)); max-height: 60vh; overflow: auto;
    padding: 6px; background: #fff; border: 1px solid var(--xx-line); border-radius: var(--xx-r); box-shadow: var(--xx-shadow-lg);
}
.rh-chat__menu-reactions { display: flex; flex-wrap: wrap; gap: 2px; padding-bottom: 6px; margin-bottom: 4px; border-bottom: 1px solid var(--xx-line); }
.rh-chat__menu-emoji { border: 0; background: none; font-size: 1.25rem; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.rh-chat__menu-emoji:hover, .rh-chat__menu-emoji:focus-visible { background: var(--xx-neutral-bg); outline: none; }
.rh-chat__menu-emoji--on { background: #e6efe9; }
.rh-chat__menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; color: var(--xx-ink); }
.rh-chat__menu-item:hover, .rh-chat__menu-item:focus-visible { background: var(--xx-neutral-bg); outline: none; }
.rh-chat__menu-item--danger { color: #b02a37; }
.rh-chat__menu-title { font-size: .75rem; font-weight: 700; color: var(--xx-neutral-fg); padding: 6px 8px 2px; }
.rh-chat__menu-name { padding: 2px 8px; font-size: .88rem; }
.rh-chat__menu-name--off { color: var(--xx-neutral-fg); }

.rh-chat__ctx {
    display: flex; align-items: center; gap: 8px; padding: 6px 14px; border-top: 1px solid var(--xx-line); background: #eef3ef;
    border-left: 3px solid var(--rh-mountains); font-size: .85rem;
}
.rh-chat__ctx-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rh-chat__mentions { display: flex; flex-direction: column; padding: 4px; border-top: 1px solid var(--xx-line); background: #fff; max-height: 220px; overflow: auto; }
.rh-chat__mention-opt { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 6px; }
.rh-chat__mention-opt--on, .rh-chat__mention-opt:hover { background: #e6efe9; }

.rh-chat__badge--at { background: var(--rh-mountains); color: #fff; }
.rh-chat__search { margin-top: 8px; }
.rh-chat__hits, .rh-chat__pins { list-style: none; padding: 0; margin: 0; }
.rh-chat__hit { display: block; padding: 10px 4px; border-bottom: 1px solid var(--xx-line); color: var(--xx-ink); text-decoration: none; }
.rh-chat__hit:hover { background: var(--xx-neutral-bg); }
.rh-chat__hit-head { display: block; font-size: .82rem; color: var(--xx-neutral-fg); }
.rh-chat__hit-head time { margin-left: 4px; }
.rh-chat__hit-text { display: block; overflow-wrap: anywhere; }
.rh-chat__pins li { padding: 6px 0; border-bottom: 1px solid var(--xx-line); font-size: .88rem; }
.rh-chat__pins a { color: var(--xx-ink); text-decoration: none; }
.rh-chat__pins a:hover { text-decoration: underline; }

/* ── Bloque 7: conservación y exportar ── */
.rh-chat__retention { margin: 0; padding: 8px 14px; border-top: 1px solid var(--xx-line); font-size: .75rem; color: var(--xx-neutral-fg); }
.rh-chat__exports { padding: 6px 14px; border-bottom: 1px solid var(--xx-line); background: #fbf6e6; font-size: .8rem; color: var(--xx-ink); }

/* ── Bloque 8: la guía ── */
.rh-help { max-width: 760px; margin: 0 auto; padding: 16px; background: var(--xx-surface); border: 1px solid var(--xx-line); border-radius: var(--xx-r-lg); }
.rh-help__lead { color: var(--xx-ink); }
.rh-help section { padding: 10px 0; border-top: 1px solid var(--xx-line); }
.rh-help ul { margin: 0; padding-left: 20px; }
.rh-help li { margin: 4px 0; }

/* ── Fase 5: videollamada en la plática ── */
.rh-msg__meeting { display: flex; flex-direction: column; gap: 6px; margin: 2px 0 4px; padding: 8px 10px; border: 1px solid var(--xx-line);
    border-left: 3px solid var(--rh-mountains); border-radius: 8px; background: #fff; }
.rh-msg__meeting-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.rh-msg__meeting--off { opacity: .7; }
.rh-msg__meeting-note { font-size: .8rem; color: var(--xx-neutral-fg); }
