/* Chat: conversaciones, respuestas, archivos, reacciones y grupos */

/* ================================================================ chat */
.chat { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 18px; height: calc(100vh / var(--zoom, 1) - 64px - 56px); min-height: 460px; }
.chat-list { display: flex; flex-direction: column; gap: 10px; padding: 14px; overflow: hidden; }
.chat-items { overflow-y: auto; display: grid; gap: 2px; align-content: start; margin: 0 -6px; padding: 0 6px; }
.chat-section { padding: 14px 8px 6px; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.chat-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px; border: 0; border-radius: 9px; background: transparent; text-align: left;
  transition: background .12s;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: var(--accent-soft); }
.chat-item.active .ci-main small { color: var(--text-2); }
.ci-main { flex: 1; min-width: 0; display: grid; }
.ci-main strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-main small { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .avatar .online-dot { border-color: var(--surface); }

.chat-main { display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--border); min-height: 64px; }
.ch-main { flex: 1; min-width: 0; display: grid; }
.ch-main small { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.chat-back { display: none; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px 18px 8px; display: flex; flex-direction: column; }
.chat-messages > .empty { margin: auto; }
.chat-skel { width: 100%; }
.day-sep { display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; color: var(--muted); font-size: 12px; font-weight: 600; }
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg { position: relative; display: flex; align-items: flex-start; gap: 10px; margin-top: 10px; max-width: 78%; }
.msg.compact { margin-top: 3px; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg-gutter { width: 28px; flex-shrink: 0; }
.msg-body { display: grid; gap: 3px; min-width: 0; }
.msg.mine .msg-body { justify-items: end; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; font-size: 12px; padding: 0 4px; }
.msg-meta strong { font-size: 13px; color: color-mix(in srgb, var(--c) 45%, var(--text)); }
.msg-user { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.msg-meta time { color: var(--muted); font-size: 11.5px; }
.bubble {
  padding: 8px 13px; border-radius: 4px 14px 14px 14px;
  background: var(--surface-3); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.compact .bubble { border-radius: 14px; }
.msg.mine .bubble { background: var(--accent); color: var(--accent-text); border-radius: 14px 4px 14px 14px; }
.msg.mine.compact .bubble { border-radius: 14px; }
.edited { margin-left: 6px; font-size: 11px; opacity: .65; font-style: italic; }
.msg-actions {
  display: flex; gap: 2px; align-self: center; opacity: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-sm);
  transition: opacity .12s;
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; }
.msg-edit { display: grid; gap: 6px; width: min(480px, 60vw); }
.msg-edit div { display: flex; justify-content: flex-end; gap: 6px; }

.chat-composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px 18px 16px; border-top: 1px solid var(--border); }
.chat-composer textarea { resize: none; min-height: 42px; max-height: 160px; border-radius: 12px; }
.chat-composer .btn { height: 42px; width: 46px; border-radius: 12px; }

/* ================================================================ chat: fijados y limpieza */
.ch-main small.chat-reset { flex-wrap: nowrap; align-items: flex-start; gap: 5px; font-size: 11.5px; color: var(--muted); }
.chat-reset .icon { width: 12px; height: 12px; margin-top: 2px; }
.chat-bio { font-style: italic; color: var(--text-2) !important; }
.chat-pinned { padding: 10px 18px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); display: grid; gap: 4px; max-height: 150px; overflow-y: auto; }
.pinned-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--accent); }
.pinned-title .icon { width: 13px; height: 13px; }
.pinned-item { display: flex; align-items: center; gap: 6px; }
.pinned-jump { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 3px 4px; border-radius: 6px; font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-jump:hover { background: var(--surface-3); color: var(--text); }
.pin-mark { display: inline-flex; vertical-align: -2px; margin-right: 5px; opacity: .8; }
.pin-mark .icon { width: 13px; height: 13px; }
.msg.pinned .bubble { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.msg.flash .bubble { animation: flash 1.4s ease; }
@keyframes flash { 30% { box-shadow: 0 0 0 4px var(--accent); } }

/* ================================================================ chat: respuestas, archivos, reacciones, menciones */
.chat-main { position: relative; }
.chat-composer { flex-direction: column; align-items: stretch; gap: 8px; position: relative; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row textarea { flex: 1; }
.attach-btn { height: 42px; width: 38px; cursor: pointer; }
.composer-extra { display: grid; gap: 8px; }
.reply-bar {
  display: flex; align-items: center; gap: 10px; padding: 7px 8px 7px 12px; border-radius: 10px;
  background: var(--surface-2); border-left: 3px solid var(--accent);
}
.reply-bar > .icon { width: 16px; height: 16px; color: var(--accent); }
.reply-bar > div { flex: 1; min-width: 0; display: grid; font-size: 12.5px; }
.reply-bar span { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-files { display: flex; gap: 8px; flex-wrap: wrap; }
.pending-file {
  position: relative; display: flex; align-items: center; gap: 8px; max-width: 240px; padding: 6px 4px 6px 6px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden;
}
.pending-file img, .pf-icon { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; flex-shrink: 0; }
.pf-icon { display: grid; place-items: center; background: var(--surface-3); color: var(--muted); }
.pf-info { display: grid; min-width: 0; font-size: 12.5px; }
.pf-info span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.pf-info small { color: var(--muted); font-size: 11.5px; }
.pf-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--surface-3); }
.pf-progress i { display: block; height: 100%; background: var(--accent); transition: width .15s; }
.pending-file.has-error { border-color: var(--danger); }
.pending-file.has-error small { color: var(--danger-text); }

.mention-menu {
  position: absolute; left: 18px; bottom: calc(100% - 6px); z-index: 20; width: min(300px, calc(100% - 36px));
  padding: 6px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.mention-title { display: flex; align-items: center; gap: 6px; padding: 4px 8px 6px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mention-title .icon { width: 13px; height: 13px; }
.mention-opt { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; text-align: left; }
.mention-opt span { display: grid; }
.mention-opt small { color: var(--muted); font-family: var(--mono); font-size: 11.5px; }
.mention-opt.active, .mention-opt:hover { background: var(--accent-soft); }

.chat-drop {
  position: absolute; inset: 0; z-index: 15; display: grid; place-content: center; justify-items: center; gap: 8px;
  background: color-mix(in srgb, var(--accent) 12%, color-mix(in srgb, var(--surface) 85%, transparent));
  border: 2px dashed var(--accent); border-radius: var(--radius); color: var(--accent); pointer-events: none;
}
.chat-drop .icon { width: 36px; height: 36px; }

.bubble { white-space: normal; }
.msg-text { white-space: pre-wrap; }
.msg-text a { text-decoration: underline; text-underline-offset: 2px; }
.bubble.only-files { padding: 4px; background: transparent !important; }
.msg.mine .bubble.only-files { background: transparent; }
.mention { padding: 0 4px; border-radius: 5px; font-weight: 650; background: color-mix(in srgb, var(--c, var(--accent)) 16%, transparent); color: color-mix(in srgb, var(--c, var(--accent)) 80%, var(--text)); }
.mention.is-me { background: color-mix(in srgb, var(--warning) 25%, transparent); color: inherit; }
.msg.mine .mention { background: rgba(255, 255, 255, .22); color: inherit; }
.msg.mine .task-link { color: inherit; text-decoration: underline; }
.msg.mentions-me .bubble { box-shadow: 0 0 0 2px color-mix(in srgb, var(--warning) 60%, transparent); background: color-mix(in srgb, var(--warning) 10%, var(--surface-3)); }

.reply-quote {
  display: grid; width: 100%; margin: 0 0 6px; padding: 5px 9px; border: 0; border-left: 3px solid var(--accent);
  border-radius: 6px; background: color-mix(in srgb, var(--text) 6%, transparent); text-align: left; font-size: 12.5px; color: inherit;
}
.reply-quote strong { font-size: 12px; }
.reply-quote span { opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.reply-quote.deleted { font-style: italic; opacity: .7; }
.msg.mine .reply-quote { background: rgba(255, 255, 255, .16); border-left-color: rgba(255, 255, 255, .7); }

.msg-images { display: grid; gap: 4px; margin: 4px 0 2px; max-width: 420px; }
.msg-images.n2 { grid-template-columns: 1fr 1fr; }
.msg-images.n3 { grid-template-columns: 1fr 1fr 1fr; }
.msg-image { display: block; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--surface-3); cursor: zoom-in; }
.msg-image img { display: block; width: auto; max-width: 100%; height: auto; max-height: 320px; object-fit: cover; }
.msg-images.n1 { justify-items: start; }
.msg-images.n2 img, .msg-images.n3 img { width: 100%; }
.msg-images.n2 img, .msg-images.n3 img { aspect-ratio: 1; height: 100%; }
.msg-file {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; padding: 8px 10px; min-width: 220px; max-width: 360px;
  border-radius: 10px; background: color-mix(in srgb, var(--text) 6%, transparent); color: inherit;
}
.msg-file:hover { background: color-mix(in srgb, var(--text) 11%, transparent); }
.msg-file > span { flex: 1; min-width: 0; display: grid; }
.msg-file strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file small { font-size: 11.5px; opacity: .75; }
.msg.mine .msg-file { background: rgba(255, 255, 255, .16); }
.image-view { display: grid; place-items: center; background: var(--surface-3); border-radius: 10px; overflow: hidden; }
.image-view img { max-width: 100%; max-height: calc(100vh / var(--zoom, 1) - 220px); object-fit: contain; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 2px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px;
  border-radius: 99px; border: 1px solid var(--border); background: var(--surface); font-size: 13px;
}
.reaction span { font-size: 11.5px; font-weight: 650; color: var(--text-2); }
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction:hover { border-color: var(--border-strong); }
.react-wrap { position: relative; }
.reaction-menu {
  position: absolute; bottom: calc(100% + 6px); right: -40px; z-index: 30; display: flex; gap: 2px; padding: 4px;
  border-radius: 99px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.msg.mine .reaction-menu { right: auto; left: -40px; }
.reaction-menu button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; font-size: 18px; line-height: 1; transition: transform .1s, background .1s; }
.reaction-menu button:hover { background: var(--surface-3); transform: scale(1.2); }
.msg.menu-open .msg-actions { opacity: 1; }

/* ================================================================ chat: grupos, mensajes nuevos */
.chat-section-row { display: flex; align-items: center; justify-content: space-between; padding-right: 2px; }
.chat-section-row .icon-btn { width: 26px; height: 26px; }
.chat-empty-groups { padding: 4px 10px 6px; }
.avatar-chatgroup { background: color-mix(in srgb, var(--av) 18%, var(--surface)); color: var(--av); }
.avatar-chatgroup .icon { width: 17px; }
.chat-members { display: flex !important; align-items: center; gap: 2px !important; flex-wrap: nowrap !important; }
.chat-members .avatar { margin-right: -4px; box-shadow: 0 0 0 2px var(--surface); }
.chat-members span { margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-actions { display: flex; align-items: center; gap: 4px; }
.new-sep { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.new-sep::before, .new-sep::after { content: ""; flex: 1; height: 2px; border-radius: 2px; background: color-mix(in srgb, var(--accent) 45%, transparent); }

/* Chat → miembros de un grupo */
.group-members { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.group-members li { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.group-members li > span:not(.avatar):not(.tag) { flex: 1; min-width: 0; font-weight: 550; }
.group-add-title { margin: 16px 0 8px; font-size: 13px; color: var(--text-2); }
