/* Chat a pantalla completa (tipo WhatsApp/Telegram) y lista de chats. Colores por modo con variables --c-*. */
:root {
  --c-bg: rgba(2, 12, 27, .55);
  --c-head: rgba(6, 22, 42, .82);
  --c-them: rgba(255, 255, 255, .1);
  --c-them-ink: #f4f1ff;
  --c-me: linear-gradient(135deg, #6d4dff, #9b5cff);
  --c-me-ink: #fff;
  --c-meta: rgba(255, 255, 255, .55);
  --c-read: #5eead4;
  --c-input: rgba(255, 255, 255, .09);
  --c-line: rgba(255, 255, 255, .1);
  --c-sys: rgba(255, 255, 255, .08);
  --c-accent: #22d3ee;
}
:root[data-modo="normal"] {
  --c-bg: #eef1f6;
  --c-head: rgba(255, 255, 255, .92);
  --c-them: #fff;
  --c-them-ink: #0f172a;
  --c-me: #4f46e5;
  --c-me-ink: #fff;
  --c-meta: rgba(15, 23, 42, .45);
  --c-read: #7dd3fc;
  --c-input: #fff;
  --c-line: #e2e8f0;
  --c-sys: rgba(255, 255, 255, .8);
  --c-accent: #4f46e5;
}

/* en una conversación: sin barra de pestañas ni scroll de la página */
body.in-room { overflow: hidden; overscroll-behavior: none; }
body.in-room .tabbar { display: none !important; }
body.in-room #app { padding: 0; min-height: 0; }
body.in-room .view { animation: none; transform: none; }

.chatwrap {
  position: fixed; top: 0; left: 0; right: 0; height: 100dvh; z-index: 40;
  display: flex; flex-direction: column; max-width: 760px; margin: 0 auto;
  background: var(--c-bg);
}
@media (min-width: 761px) { .chatwrap { border-left: 1px solid var(--c-line); border-right: 1px solid var(--c-line); } }
[data-modo="normal"] .chatwrap {
  background-color: var(--c-bg);
  background-image: radial-gradient(rgba(79, 70, 229, .07) 1px, transparent 1.2px);
  background-size: 18px 18px;
}

.chatwrap svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chatwrap svg .fill, .fab svg .fill { fill: currentColor; stroke: none; }

/* cabecera */
.chathead {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: calc(6px + env(safe-area-inset-top)) 8px 6px 4px;
  background: var(--c-head); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--c-line);
}
.ch-back, .ch-btn { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%; background: transparent; color: var(--ink); cursor: pointer; text-decoration: none; flex: none; font-size: 18px; }
.ch-back:active, .ch-btn:active { background: var(--c-line); }
.ch-ava .room-ava { width: 40px; height: 40px; font-size: 21px; }
.ch-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.ch-info b { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-info small { font-size: 12.5px; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-info small.typing { color: var(--c-accent); font-weight: 700; }

/* zona de mensajes */
.cscroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 6px; -webkit-overflow-scrolling: touch; }
.sysnote { margin: 4px auto 8px; max-width: 92%; width: fit-content; text-align: center; font-size: 12.5px; line-height: 1.45; color: var(--ink2);
  background: var(--c-sys); border-radius: 10px; padding: 6px 12px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
[data-modo="normal"] .sysnote { box-shadow: 0 1px 1px rgba(15, 23, 42, .06); }
.sysnote.soft { margin-top: 30px; font-size: 14px; }
.daysep { position: sticky; top: 2px; z-index: 2; text-align: center; margin: 10px 0 6px; pointer-events: none; }
.daysep span { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 11px; border-radius: 8px; background: var(--c-head); color: var(--ink2);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .12); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); text-transform: capitalize; }
.older { display: flex; justify-content: center; padding: 8px; }
.pushpill { display: flex; align-items: center; gap: 8px; margin: 0 auto 8px; max-width: 520px; padding: 6px 6px 6px 12px; border-radius: 12px; background: var(--c-sys); font-size: 13px; color: var(--ink2); }
.pushpill .grow { flex: 1; line-height: 1.3; }
.pushpill .ch-btn { width: 30px; height: 30px; font-size: 14px; }

.clist { display: flex; flex-direction: column; }
.mrow { display: flex; align-items: flex-end; gap: 6px; margin-top: 2px; }
.mrow.first { margin-top: 8px; }
.mrow.me { justify-content: flex-end; }
.mava { width: 30px; flex: none; align-self: flex-end; }
.mava .room-ava { width: 30px; height: 30px; font-size: 16px; visibility: hidden; }
.mrow.last .mava .room-ava { visibility: visible; }
.mrow:not(.first) .bname { display: none; }
.mava .nimface { object-fit: cover; padding: 0; background: #0f766e; }
.bub {
  position: relative; max-width: min(78%, 520px); padding: 6px 9px 6px 11px; border-radius: 16px;
  background: var(--c-them); color: var(--c-them-ink); font-size: 15.5px; line-height: 1.38; overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .12); animation: bubIn .22s cubic-bezier(.2, .9, .3, 1.1) both;
}
:root:not([data-modo="normal"]) .mrow.them .bub { backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, .08); }
.mrow.them.last .bub { border-bottom-left-radius: 5px; }
.mrow.me .bub { background: var(--c-me); color: var(--c-me-ink); }
.mrow.me.last .bub { border-bottom-right-radius: 5px; }
.mrow.nim .bub { border-left: 3px solid #14b8a6; }
@keyframes bubIn { from { opacity: 0; transform: translateY(6px) scale(.98); } }
.bname { font-size: 12.5px; font-weight: 800; margin-bottom: 1px; }
.btext p { margin: 0 0 4px; } .btext p:last-child { margin: 0; display: inline; }
.btext ul, .btext ol { margin: 2px 0 4px; padding-left: 20px; }
.btext .katex-display { overflow-x: auto; overflow-y: hidden; margin: 4px 0; }
.mrow.them .katex { color: inherit; }
.bmeta { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--c-meta); white-space: nowrap; line-height: 1; }
.mrow.me .bmeta { color: rgba(255, 255, 255, .72); }
.tick { display: inline-flex; }
.tick .tk { width: 17px; height: 12px; stroke-width: 1.8; }
.tick.read { color: var(--c-read); }
.mrow.me .tick.read { color: var(--c-read); }
.room-last .tick { margin-right: 3px; vertical-align: -1px; color: var(--ink3); }
.room-last .tick.read { color: #0ea5e9; }
.mrow.failed .bub { opacity: .7; outline: 2px dashed #f43f5e; }
.mrow.pending .bub { opacity: .92; }

/* fotos y GIF */
.bmedia { display: block; position: relative; border: 0; padding: 0; margin: -2px -5px 4px -7px; background: rgba(0, 0, 0, .15); border-radius: 12px; overflow: hidden; cursor: zoom-in; }
.bmedia img { display: block; width: 100%; max-width: 280px; max-height: 340px; min-width: 120px; min-height: 80px; object-fit: cover; }
.bmedia.isgif img { max-width: 220px; }
.mediaonly .bub { padding: 4px; }
.mediaonly .bmedia { margin: 0; }
.mediaonly .bname { padding: 2px 6px 4px; }
.mediaonly .bmeta { position: absolute; right: 10px; bottom: 10px; margin: 0; padding: 3px 7px; border-radius: 9px; background: rgba(0, 0, 0, .45); color: #fff; float: none; }
.mediaonly .bmeta .tick.read { color: var(--c-read); }
.checking { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: #fff; font-size: 12.5px; font-weight: 800; background: rgba(2, 6, 23, .55); }

/* avisos del moderador y mensajes bloqueados (admin) */
.warnbub { border: 1px solid rgba(244, 63, 94, .5) !important; }
.warnbub .bname { color: #f43f5e; }
.blockedmsg .bub { outline: 2px dashed rgba(244, 63, 94, .7); opacity: .8; }
.bflag { font-size: 11px; font-weight: 800; color: #f43f5e; margin-bottom: 2px; }

/* escribiendo… */
.typingrow .bub { padding: 9px 12px; display: flex; align-items: center; gap: 8px; }
.typingrow .bub small { font-size: 12px; color: var(--c-meta); }
.typingrow .bub small:empty { display: none; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--c-meta); animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; } .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.tobottom { position: absolute; right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 5; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: var(--c-head); color: var(--ink); box-shadow: 0 4px 14px rgba(0, 0, 0, .25); display: grid; place-items: center; cursor: pointer; }
.tobottom b { position: absolute; top: -6px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: #22c55e; color: #fff; font-size: 11px; line-height: 20px; text-align: center; }

/* barra de escribir */
.cfoot { flex: none; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: var(--c-head); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--c-line); }
.cbar { display: flex; align-items: flex-end; gap: 6px; }
.cbtn { flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%; background: transparent; color: var(--ink2); display: grid; place-items: center; cursor: pointer; }
.cbtn:active { background: var(--c-line); }
.cinput { flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 2px; background: var(--c-input); border: 1px solid var(--c-line); border-radius: 22px; padding: 0 5px 0 14px; transition: border-color .15s; }
.cinput:focus-within { border-color: var(--c-accent); }
.cinput textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 120px; resize: none; border: 0; background: transparent; outline: none; color: var(--ink); font-size: 16px; line-height: 1.35; padding: 10px 0; }
.cchip { flex: none; height: 30px; min-width: 30px; margin-bottom: 5px; border: 0; border-radius: 15px; background: transparent; color: var(--ink2); font-size: 16px; cursor: pointer; padding: 0 6px; }
.cchip.gif { font-size: 11px; font-weight: 900; letter-spacing: .5px; border: 1.5px solid currentColor; height: 22px; margin-bottom: 9px; border-radius: 6px; padding: 0 4px; }
.cchip:active { background: var(--c-line); }
.csend { flex: none; width: 42px; height: 42px; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, #14b8a6, #22d3ee); box-shadow: 0 4px 14px rgba(20, 184, 166, .35); transition: transform .15s; }
[data-modo="normal"] .csend { background: #4f46e5; box-shadow: none; }
.csend svg { width: 20px; height: 20px; margin-left: 2px; }
.csend:active { transform: scale(.9); }
.cfoot:not(.hastext) .csend { opacity: .55; }
.cblock { text-align: center; font-size: 14px; color: var(--ink2); padding: 10px; }
.cprev { display: flex; align-items: center; gap: 10px; padding: 4px 4px 8px; }
.cprev img { width: 54px; height: 54px; object-fit: cover; border-radius: 10px; }
.cprev .grow { flex: 1; display: flex; flex-direction: column; line-height: 1.25; }
.cprev small { color: var(--ink3); font-size: 12px; }

/* panel de GIFs */
.gifpanel { flex: none; height: min(46vh, 340px); display: flex; flex-direction: column; background: var(--c-head); border-top: 1px solid var(--c-line); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
.gp-top { display: flex; gap: 6px; padding: 8px 8px 4px; align-items: center; }
.gp-top input { flex: 1; min-width: 0; border: 1px solid var(--c-line); background: var(--c-input); color: var(--ink); border-radius: 18px; padding: 8px 14px; font-size: 15px; outline: none; }
.gp-top input.hide + .ch-btn { margin-left: auto; }
.gp-grid { flex: 1; overflow-y: auto; padding: 4px 8px 10px; }
.gp-sec { font-size: 12px; font-weight: 800; color: var(--ink3); margin: 6px 2px; text-transform: uppercase; letter-spacing: .4px; }
.gp-cols { columns: 3 110px; column-gap: 6px; }
.gp-cell { display: block; width: 100%; margin: 0 0 6px; padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: var(--c-line); cursor: pointer; break-inside: avoid; }
.gp-cell img { display: block; width: 100%; height: 100%; object-fit: cover; }
.gp-note { text-align: center; color: var(--ink3); font-size: 13px; padding: 14px; }

/* hoja de acciones y visor */
.actsheet { position: fixed; inset: 0; z-index: 90; background: rgba(2, 6, 23, .45); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .15s; }
.as-box { width: min(480px, 100%); margin: 0 8px calc(8px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 1px; border-radius: 16px; overflow: hidden; animation: sheetUp .22s cubic-bezier(.2, .9, .3, 1.1); }
.as-box button { border: 0; padding: 15px; font-size: 16px; font-weight: 700; background: var(--c-head); color: var(--ink); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); cursor: pointer; text-align: center; }
[data-modo="normal"] .as-box button { background: #fff; }
.as-box button.danger { color: #f43f5e; }
.as-box .as-cancel { margin-top: 8px; border-radius: 16px; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } }
@keyframes fadeIn { from { opacity: 0; } }
.lightbox { position: fixed; inset: 0; z-index: 95; background: rgba(0, 0, 0, .92); display: grid; place-items: center; animation: fadeIn .15s; cursor: zoom-out; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.lb-x { position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .15); color: #fff; font-size: 18px; }

.spin { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, .3); border-top-color: currentColor; animation: spin .8s linear infinite; display: inline-block; }
[data-modo="normal"] .older .spin, [data-modo="normal"] .gp-note .spin { border-color: rgba(15, 23, 42, .15); border-top-color: #4f46e5; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- lista de chats ---------- */
.rooms { padding-bottom: 80px; }
.rsearch input { width: 100%; border: 1px solid var(--line); background: var(--glass); color: var(--ink); border-radius: 12px; padding: 9px 14px; font-size: 15px; outline: none; margin: 2px 0 10px; }
.rsearch input:focus { border-color: var(--c-accent); }
.rooms .room-list { padding: 0; background: transparent; border: 0; box-shadow: none; }
.room-row { display: flex; gap: 12px; align-items: center; padding: 9px 4px; text-decoration: none; color: inherit; border-radius: 12px; border-bottom: 0; transition: background .15s; }
.room-row:active, .room-row:hover { background: var(--glass); }
.room-ava { width: 50px; height: 50px; font-size: 26px; border-radius: 50% !important; flex: none; }
.room-ava.grp { --me: #0d9488; }
.rr-main { flex: 1; min-width: 0; padding: 3px 0 10px; border-bottom: 1px solid var(--line); }
.room-row:last-child .rr-main { border-bottom: 0; }
.rr-top, .rr-bot { display: flex; align-items: center; gap: 8px; }
.room-title { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rr-time { font-size: 12px; color: var(--ink3); flex: none; }
.room-row.unread .rr-time { color: #22c55e; font-weight: 800; }
.room-last { flex: 1; min-width: 0; color: var(--ink2); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-last b { font-weight: 700; }
.room-row.unread .room-last { color: var(--ink); }
.rtyping { color: #22c55e; font-weight: 700; }
.room-unread { min-width: 21px; height: 21px; padding: 0 6px; border-radius: 11px; background: #22c55e; color: #fff; font-size: 12px; line-height: 21px; text-align: center; flex: none; }
.rl-admin { gap: 8px; margin: 12px 4px 0; }
.rl-foot { font-size: 13px; margin-top: 14px; }
.fab { position: fixed; right: max(18px, calc(50% - 362px)); bottom: calc(100px + env(safe-area-inset-bottom)); z-index: 30; width: 56px; height: 56px; border-radius: 18px; border: 0;
  display: grid; place-items: center; color: #fff; cursor: pointer; background: linear-gradient(135deg, #14b8a6, #22d3ee); box-shadow: 0 8px 24px rgba(20, 184, 166, .4); }
[data-modo="normal"] .fab { background: #4f46e5; box-shadow: 0 8px 20px rgba(79, 70, 229, .3); }
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.fab:active { transform: scale(.94); }
