/* =========================================================================
   Enlace — sistema visual
   Identidad propia: superficies planas, un solo color de marca, bordes de 1px
   y radios contenidos. Sin degradados ni sombras decorativas.
   ========================================================================= */

:root {
  color-scheme: light;

  /* Marca */
  --brand: #15607a;
  --brand-strong: #0f4a5e;
  --brand-soft: #e4f0f5;
  --brand-contrast: #ffffff;

  /* Superficies */
  --bg: #ffffff;
  --bg-sidebar: #fafbfc;
  --bg-canvas: #f3f1ed;
  --bg-raised: #ffffff;
  --bg-hover: #eef1f4;
  --bg-active: #e3e9ee;
  --bg-input: #ffffff;
  --bg-overlay: rgba(14, 20, 25, 0.55);

  /* Burbujas */
  --bubble-in: #ffffff;
  --bubble-in-border: #e4e1da;
  --bubble-out: #dcedf4;
  --bubble-out-border: #c6e0ea;

  /* Texto */
  --text: #161b20;
  --text-muted: #667079;
  --text-faint: #8c959d;
  --text-on-brand: #ffffff;

  /* Líneas */
  --line: #e2e6ea;
  --line-strong: #cfd6dc;

  /* Estados */
  --ok: #1a7f52;
  --warn: #9a6600;
  --danger: #b3261e;
  --danger-soft: #fcebea;
  --info: #15607a;

  /* Medidas */
  --sidebar-w: 336px;
  --info-w: 320px;
  --header-h: 56px;
  --radius-sm: 6px;
  --radius: 9px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  --fs-xs: 11.5px;
  --fs-sm: 13px;
  --fs: 14.5px;
  --fs-md: 15.5px;
  --fs-lg: 18px;
  --fs-xl: 22px;

  --ease: cubic-bezier(0.2, 0, 0.2, 1);
  --dur: 140ms;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --brand: #4aa6c9;
  --brand-strong: #6cbcdb;
  --brand-soft: #16323d;
  --brand-contrast: #06161c;

  --bg: #181c20;
  --bg-sidebar: #15181c;
  --bg-canvas: #101316;
  --bg-raised: #1f2429;
  --bg-hover: #23292f;
  --bg-active: #2b333a;
  --bg-input: #1f2429;
  --bg-overlay: rgba(0, 0, 0, 0.66);

  --bubble-in: #1f2429;
  --bubble-in-border: #2b3238;
  --bubble-out: #1b4354;
  --bubble-out-border: #255667;

  --text: #e6e9ec;
  --text-muted: #9aa3ab;
  --text-faint: #7b848c;
  --text-on-brand: #06161c;

  --line: #272d33;
  --line-strong: #353d44;

  --ok: #54c48d;
  --warn: #d9a441;
  --danger: #f2877f;
  --danger-soft: #3a1f1d;
  --info: #4aa6c9;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #4aa6c9;
    --brand-strong: #6cbcdb;
    --brand-soft: #16323d;
    --brand-contrast: #06161c;
    --bg: #181c20;
    --bg-sidebar: #15181c;
    --bg-canvas: #101316;
    --bg-raised: #1f2429;
    --bg-hover: #23292f;
    --bg-active: #2b333a;
    --bg-input: #1f2429;
    --bg-overlay: rgba(0, 0, 0, 0.66);
    --bubble-in: #1f2429;
    --bubble-in-border: #2b3238;
    --bubble-out: #1b4354;
    --bubble-out-border: #255667;
    --text: #e6e9ec;
    --text-muted: #9aa3ab;
    --text-faint: #7b848c;
    --text-on-brand: #06161c;
    --line: #272d33;
    --line-strong: #353d44;
    --ok: #54c48d;
    --warn: #d9a441;
    --danger: #f2877f;
    --danger-soft: #3a1f1d;
    --info: #4aa6c9;
  }
}

/* ------------------------------------------------------------- base ---- */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* El atributo hidden tiene que ganar siempre.
   Sin esto, cualquier regla propia con display (flex, grid…) lo anula y el
   elemento se sigue viendo: así aparecía una franja de error vacía en la
   pantalla de acceso. */
[hidden] { display: none !important; }

button {
  background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; color: inherit;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: 4px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--radius-pill);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

.icon { width: 20px; height: 20px; flex: none; stroke-width: 1.6; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.spinner {
  width: 18px; height: 18px; flex: none;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 650ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------- controles -- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text);
  font-size: var(--fs);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur) var(--ease);
}
.btn:hover:not(:disabled) { background: var(--bg-active); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--brand); color: var(--text-on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; flex: none;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.is-active { color: var(--brand); background: var(--brand-soft); }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; margin-bottom: 5px;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted);
}
.field > small { display: block; margin-top: 5px; font-size: var(--fs-xs); color: var(--text-faint); }

/* Campo con un botón dentro, como el ojo de «ver la contraseña». */
.campo-con-boton { position: relative; display: block; }
.campo-con-boton > .input { padding-right: 42px; }
.campo-ojo {
  position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; color: var(--text-muted);
}
.campo-ojo.is-active { color: var(--brand); }

.lista-simple { margin: 0 0 12px; padding-left: 20px; color: var(--text-muted); font-size: var(--fs-sm); }
.lista-simple li { margin-bottom: 4px; }

.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 11px;
  background: var(--bg-input);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: border-color var(--dur) var(--ease);
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; min-height: 80px; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input[aria-invalid="true"] { border-color: var(--danger); }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 7px 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 38px; height: 22px; flex: none; border-radius: var(--radius-pill);
  background: var(--line-strong); position: relative;
  transition: background var(--dur) var(--ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: #fff;
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .switch-track { background: var(--brand); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch-label { font-size: var(--fs); }
.switch-label small { display: block; color: var(--text-muted); font-size: var(--fs-xs); }

/* Opción de lista con botón redondo (elegir una entre varias). */
.radio { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 0; }
.radio input { position: absolute; opacity: 0; pointer-events: none; }
.radio-dot {
  width: 20px; height: 20px; flex: none; border-radius: 50%;
  border: 2px solid var(--line-strong); position: relative;
  transition: border-color var(--dur) var(--ease);
}
.radio-dot::after {
  content: ""; position: absolute; inset: 3px; border-radius: 50%;
  background: var(--brand); transform: scale(0);
  transition: transform var(--dur) var(--ease);
}
.radio input:checked + .radio-dot { border-color: var(--brand); }
.radio input:checked + .radio-dot::after { transform: scale(1); }
.radio input:focus-visible + .radio-dot { outline: 2px solid var(--brand); outline-offset: 2px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-active); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 600;
}
.badge-brand { background: var(--brand); color: var(--text-on-brand); }
.badge-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.badge-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-strong);
  font-weight: 600; font-size: var(--fs-md);
  overflow: hidden; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-sm); }
.avatar-lg { width: 76px; height: 76px; font-size: var(--fs-xl); }
.avatar-wrap { position: relative; flex: none; }
.presence-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--text-faint);
  border: 2px solid var(--bg-sidebar);
}
.presence-dot.is-online { background: var(--ok); }

/* -------------------------------------------------------------- layout - */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}
/* Los elementos de una rejilla tienen min-height: auto, así que por defecto se
   niegan a encoger por debajo de su contenido: con muchas conversaciones, la
   columna crecía más que la ventana y el campo de escribir quedaba fuera de
   la pantalla. Con min-height: 0 cada columna se queda dentro y es su propia
   lista la que hace scroll. */
.app > * { min-height: 0; }
.app.has-info { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--info-w); }
.app.has-info .info-panel { display: flex; }

/* ------------------------------------------------------------ sidebar -- */

.sidebar {
  display: flex; flex-direction: column;
  min-width: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--line);
}

.sidebar-top {
  display: flex; align-items: center; gap: 8px;
  height: var(--header-h); padding: 0 10px 0 12px;
  flex: none;
}
.search {
  position: relative; flex: 1; min-width: 0;
}
.search .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none;
}
.search input {
  width: 100%; height: 36px; padding: 0 32px 0 34px;
  background: var(--bg-hover);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
}
.search input:focus { outline: none; background: var(--bg-input); border-color: var(--brand); }
.search-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px;
}

.folders {
  display: flex; gap: 4px; padding: 0 10px 8px; flex: none;
  overflow-x: auto; scrollbar-width: none;
}
.folders::-webkit-scrollbar { display: none; }
.folder-tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px; flex: none;
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-muted);
  transition: background var(--dur) var(--ease);
}
.folder-tab:hover { background: var(--bg-hover); }
.folder-tab.is-active { background: var(--brand); color: var(--text-on-brand); }
.folder-tab .count { font-size: var(--fs-xs); opacity: 0.8; }

/* min-height: 0 para que la lista haga scroll en vez de estirar la columna. */
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; }

.chat-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-rows: auto auto;
  column-gap: 11px;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius);
  text-align: left;
  transition: background var(--dur) var(--ease);
}
.chat-row:hover { background: var(--bg-hover); }
.chat-row.is-active { background: var(--brand); color: var(--text-on-brand); }
.chat-row.is-active .chat-row-preview,
.chat-row.is-active .chat-row-time { color: color-mix(in srgb, var(--text-on-brand) 78%, transparent); }
.chat-row.is-active .avatar { background: color-mix(in srgb, var(--text-on-brand) 22%, transparent); color: var(--text-on-brand); }
.chat-row.is-active .presence-dot { border-color: var(--brand); }

.chat-row .avatar-wrap { grid-row: span 2; }
.chat-row-name {
  grid-column: 2; grid-row: 1;
  font-weight: 600; font-size: var(--fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px; min-width: 0;
}
.chat-row-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-time {
  grid-column: 3; grid-row: 1;
  font-size: var(--fs-xs); color: var(--text-faint); white-space: nowrap;
}
.chat-row-preview {
  grid-column: 2; grid-row: 2;
  font-size: var(--fs); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 5px; min-width: 0;
}
.chat-row-preview > span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.chat-row-preview .sender { color: var(--text); font-weight: 500; flex: none; max-width: 45%; }
.chat-row-preview em { font-style: normal; color: var(--text-faint); }
.chat-row-meta {
  grid-column: 3; grid-row: 2;
  display: flex; align-items: center; gap: 5px; justify-content: flex-end;
}
.unread-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--brand); color: var(--text-on-brand);
  font-size: var(--fs-xs); font-weight: 700;
}
.unread-pill.is-muted { background: var(--text-faint); }
.chat-row.is-active .unread-pill { background: var(--text-on-brand); color: var(--brand); }

.list-section-title {
  padding: 12px 12px 5px;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-faint);
}

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 44px 26px; text-align: center; color: var(--text-muted);
}
.empty-state .icon { width: 34px; height: 34px; color: var(--text-faint); }
.empty-state h3 { margin: 0; font-size: var(--fs-md); color: var(--text); font-weight: 600; }
.empty-state p { margin: 0; font-size: var(--fs-sm); max-width: 34ch; }

/* --------------------------------------------------------------- chat -- */

.chat {
  display: flex; flex-direction: column;
  min-width: 0; background: var(--bg-canvas);
  position: relative;
}

.chat-header {
  display: flex; align-items: center; gap: 11px;
  height: var(--header-h); padding: 0 8px 0 14px; flex: none;
  background: var(--bg); border-bottom: 1px solid var(--line);
  z-index: 3;
}
.chat-header-main { flex: 1; min-width: 0; cursor: pointer; text-align: left; }
.chat-header-title {
  font-weight: 600; font-size: var(--fs-md);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-sub {
  font-size: var(--fs-sm); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-header-sub.is-typing { color: var(--brand); }

.pinned-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px; flex: none;
  background: var(--bg); border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.pinned-bar .pin-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
.pinned-bar .pin-label { color: var(--brand); font-weight: 600; }

.messages {
  flex: 1; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  padding: 14px 0 6px;
  scroll-behavior: auto;
  display: flex; flex-direction: column;
}
/* `margin-top: auto` empuja la conversación al fondo cuando hay pocos
   mensajes, en lugar de dejarlos flotando arriba con un hueco enorme. */
.messages-inner { max-width: 840px; width: 100%; margin: auto auto 0; padding: 0 16px; }

.day-divider {
  display: flex; justify-content: center; margin: 14px 0 12px;
  position: sticky; top: 2px; z-index: 2; pointer-events: none;
}
.day-divider span {
  padding: 3px 12px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 1px solid var(--line);
  font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
  backdrop-filter: blur(6px);
}

.msg-group { display: flex; gap: 9px; margin-bottom: 2px; }
.msg-group.is-mine { flex-direction: row-reverse; }
.msg-group-avatar { width: 30px; flex: none; align-self: flex-end; margin-bottom: 2px; }
.msg-group-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; max-width: min(640px, 76%); }
.msg-group.is-mine .msg-group-body { align-items: flex-end; }
.msg-group + .msg-group { margin-top: 8px; }

.bubble {
  position: relative;
  padding: 7px 11px 7px;
  border-radius: var(--radius-lg);
  background: var(--bubble-in);
  border: 1px solid var(--bubble-in-border);
  max-width: 100%;
  min-width: 68px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-group.is-mine .bubble { background: var(--bubble-out); border-color: var(--bubble-out-border); }
.bubble.is-first { border-top-left-radius: var(--radius-lg); }
.msg-group:not(.is-mine) .bubble:not(.is-last) { border-bottom-left-radius: var(--radius-sm); }
.msg-group:not(.is-mine) .bubble:not(.is-first) { border-top-left-radius: var(--radius-sm); }
.msg-group.is-mine .bubble:not(.is-last) { border-bottom-right-radius: var(--radius-sm); }
.msg-group.is-mine .bubble:not(.is-first) { border-top-right-radius: var(--radius-sm); }
.bubble.is-highlight { animation: flash 1.4s var(--ease); }
@keyframes flash {
  0%, 30% { background: var(--brand-soft); border-color: var(--brand); }
}

.bubble-sender {
  font-size: var(--fs-sm); font-weight: 600; color: var(--brand);
  margin-bottom: 2px;
  display: flex; align-items: center; gap: 5px;
}
.bubble-text { white-space: pre-wrap; font-size: var(--fs-md); }
.bubble-text a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.bubble-text .mention { color: var(--brand); font-weight: 600; }
.bubble-text .mention.is-me { background: var(--brand-soft); border-radius: 4px; padding: 0 3px; }
.bubble-text code {
  font-family: var(--font-mono); font-size: 0.9em;
  background: var(--bg-hover); padding: 1px 4px; border-radius: 4px;
}
.bubble-text.is-deleted { color: var(--text-faint); font-style: italic; }

.bubble-meta {
  display: inline-flex; align-items: center; gap: 4px;
  float: right; margin: 6px 0 -2px 10px;
  font-size: var(--fs-xs); color: var(--text-faint);
  user-select: none; white-space: nowrap;
}
.bubble-meta .edited { font-style: italic; }
.receipt { display: inline-flex; align-items: center; }
.receipt .icon { width: 15px; height: 15px; stroke-width: 2; }
.receipt.is-read { color: var(--brand); }
.receipt.is-pending { opacity: 0.55; }

.reply-quote {
  display: flex; gap: 8px; align-items: stretch;
  margin-bottom: 5px; padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--brand) 9%, transparent);
  border-left: 3px solid var(--brand);
  cursor: pointer; min-width: 0;
}
.reply-quote-body { min-width: 0; }
.reply-quote .who { font-size: var(--fs-sm); font-weight: 600; color: var(--brand); }
.reply-quote .what {
  font-size: var(--fs-sm); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.forward-note {
  font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: 4px;
  display: flex; align-items: center; gap: 5px;
}

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.reaction {
  display: inline-flex; align-items: center; gap: 4px;
  height: 24px; padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-hover);
  border: 1px solid transparent;
  font-size: var(--fs-sm);
  transition: background var(--dur) var(--ease);
}
.reaction:hover { background: var(--bg-active); }
.reaction.is-mine { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); }
.reaction .count { font-weight: 600; font-size: var(--fs-xs); }

.msg-actions {
  position: absolute; top: 2px;
  display: flex; gap: 2px; padding: 2px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
  z-index: 4;
}
.msg-group:not(.is-mine) .msg-actions { right: -4px; transform: translateX(100%); }
.msg-group.is-mine .msg-actions { left: -4px; transform: translateX(-100%); }
.bubble:hover .msg-actions, .msg-actions:focus-within { opacity: 1; pointer-events: auto; }
.msg-actions .icon-btn { width: 28px; height: 28px; }
.msg-actions .icon { width: 16px; height: 16px; }

.system-msg {
  display: flex; justify-content: center; margin: 10px 0;
}
.system-msg span {
  max-width: 70ch; text-align: center;
  padding: 4px 12px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  border: 1px solid var(--line);
  font-size: var(--fs-sm); color: var(--text-muted);
}

.typing-row { display: flex; gap: 9px; padding: 2px 0 8px; }
.typing-bubble {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 10px 13px; border-radius: var(--radius-lg);
  background: var(--bubble-in); border: 1px solid var(--bubble-in-border);
}
.typing-bubble i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-faint);
  animation: bounce 1.2s infinite var(--ease);
}
.typing-bubble i:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

.jump-bottom {
  position: absolute; right: 20px; bottom: 96px; z-index: 5;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--bg-raised); border: 1px solid var(--line);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.jump-bottom[hidden] { display: none; }
.jump-bottom:hover { color: var(--text); }
.jump-bottom .unread-pill { position: absolute; top: -5px; right: -3px; }

/* ------------------------------------------------------------ adjuntos - */

.attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 5px; }
.attachments:first-child { margin-top: 0; }

.att-image {
  display: block; position: relative;
  border-radius: var(--radius); overflow: hidden;
  background: var(--bg-hover); line-height: 0;
  max-width: 420px;
}
.att-image img { max-width: 100%; height: auto; display: block; cursor: zoom-in; }
.att-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; max-width: 420px; }
.att-grid .att-image { max-width: none; }
.att-grid .att-image img { aspect-ratio: 1; object-fit: cover; width: 100%; }

.att-file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  border: 1px solid var(--line);
  min-width: 240px; max-width: 420px;
}
.att-file-icon {
  width: 38px; height: 38px; flex: none; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--brand-soft); color: var(--brand-strong);
}
.att-file-body { flex: 1; min-width: 0; }
/* El nombre es pulsable cuando el archivo se puede previsualizar. */
.att-file-open {
  text-align: left; background: none; border: 0; padding: 0;
  font: inherit; color: inherit; cursor: pointer;
}
.att-file-open:hover .att-file-name { text-decoration: underline; }
.att-file-open:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--radius-sm); }
.att-file-name {
  font-size: var(--fs); font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.att-file-info { font-size: var(--fs-xs); color: var(--text-muted); }
.att-media { max-width: 420px; width: 100%; border-radius: var(--radius); }
audio.att-media { height: 40px; }

.transfer { margin-top: 5px; }
.progress {
  height: 4px; border-radius: var(--radius-pill);
  background: var(--bg-active); overflow: hidden;
}
.progress > i {
  display: block; height: 100%; background: var(--brand);
  transition: width 180ms var(--ease);
}

/* ------------------------------------------------------------ redactor - */

.composer {
  flex: none; padding: 8px 16px 12px;
  background: var(--bg-canvas);
}
.composer-inner {
  max-width: 840px; margin: 0 auto;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  transition: border-color var(--dur) var(--ease);
}
.composer-inner.is-focus { border-color: var(--brand); }
.composer-inner.is-dragover { border-color: var(--brand); background: var(--brand-soft); }

.composer-context {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px 6px; border-bottom: 1px solid var(--line);
}
.composer-context-body { flex: 1; min-width: 0; }
.composer-context .label { font-size: var(--fs-sm); font-weight: 600; color: var(--brand); }
.composer-context .text {
  font-size: var(--fs-sm); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.composer-row { display: flex; align-items: flex-end; gap: 2px; padding: 4px 6px 4px 8px; }
.composer-input {
  flex: 1; min-width: 0;
  max-height: 180px; padding: 8px 4px;
  background: transparent; border: 0; resize: none;
  font-size: var(--fs-md); line-height: 1.45;
  overflow-y: auto;
}
.composer-input:focus { outline: none; }
.composer-input::placeholder { color: var(--text-faint); }
.send-btn {
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--brand); color: var(--text-on-brand);
  transition: background var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn:hover:not(:disabled) { background: var(--brand-strong); }

.composer-staging {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 9px 10px; border-bottom: 1px solid var(--line);
}
.staged {
  position: relative; width: 92px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); overflow: hidden;
}
.staged-thumb {
  width: 100%; height: 68px; object-fit: cover; display: block;
  background: var(--bg-hover);
}
.staged-thumb.is-generic { display: flex; align-items: center; justify-content: center; color: var(--text-muted); }
.staged-name {
  padding: 3px 5px; font-size: var(--fs-xs); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.staged-remove {
  position: absolute; top: 3px; right: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--bg-overlay); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.staged .progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; border-radius: 0; }
.staged.has-error { border-color: var(--danger); }
.staged-error { padding: 3px 5px; font-size: var(--fs-xs); color: var(--danger); }

/* ---------------------------------------------------- panel de información */

.info-panel {
  /* Oculto mientras no se pide: si no, al tener la rejilla sólo dos columnas,
     este tercer hijo se iba a una segunda fila y partía la pantalla en dos. */
  display: none;
  flex-direction: column;
  min-width: 0; background: var(--bg-sidebar);
  border-left: 1px solid var(--line);
  overflow: hidden;
}
.info-head {
  display: flex; align-items: center; gap: 8px;
  height: var(--header-h); padding: 0 8px 0 14px; flex: none;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.info-head h2 { margin: 0; font-size: var(--fs-md); font-weight: 600; flex: 1; }
.info-body { flex: 1; min-height: 0; overflow-y: auto; }
.info-hero { padding: 20px 16px; text-align: center; border-bottom: 1px solid var(--line); }
.info-hero .avatar { margin: 0 auto 10px; }
.info-hero h3 { margin: 0 0 2px; font-size: var(--fs-lg); }
.info-hero p { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }

.info-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.info-tab {
  flex: 1; height: 38px; font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent;
}
.info-tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }

.info-list { padding: 6px; }
.info-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius); text-align: left;
}
.info-item:hover { background: var(--bg-hover); }
.info-item-body { flex: 1; min-width: 0; }
.info-item-title { font-size: var(--fs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-item-sub { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.detail-row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 9px 16px; border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.detail-row dt { color: var(--text-muted); margin: 0; }
.detail-row dd { margin: 0; text-align: right; word-break: break-word; }

/* ------------------------------------------------------------- menús --- */

.menu {
  position: fixed; z-index: 60; min-width: 196px; max-width: 280px;
  padding: 5px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px -8px rgba(0, 0, 0, 0.3);
}
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 9px; border-radius: var(--radius-sm);
  font-size: var(--fs); text-align: left; color: var(--text);
}
.menu-item:hover { background: var(--bg-hover); }
.menu-item .icon { color: var(--text-muted); }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-danger .icon { color: var(--danger); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item .shortcut { margin-left: auto; font-size: var(--fs-xs); color: var(--text-faint); }
.menu-sep { height: 1px; margin: 4px 2px; background: var(--line); }
.menu-title {
  padding: 6px 9px 4px; font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint);
}

/* ------------------------------------------------------------ diálogos - */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg-overlay);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade 120ms var(--ease);
}
@keyframes fade { from { opacity: 0; } }

.dialog {
  width: min(560px, 100%); max-height: min(86dvh, 760px);
  display: flex; flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: pop 140ms var(--ease);
}
@keyframes pop { from { transform: translateY(8px) scale(0.99); opacity: 0; } }
.dialog-wide { width: min(980px, 100%); }
.dialog-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 12px; flex: none;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 600; flex: 1; }
.dialog-body { flex: 1; overflow-y: auto; padding: 16px; }
.dialog-body.is-flush { padding: 0; }
.dialog-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 14px; flex: none;
  border-top: 1px solid var(--line);
}
.dialog-foot .spacer { flex: 1; }

.notice {
  display: flex; gap: 9px; padding: 10px 12px;
  border-radius: var(--radius); font-size: var(--fs-sm);
  background: var(--bg-hover); color: var(--text-muted);
  margin-bottom: 14px;
}
.notice .icon { flex: none; }
.notice-warn { background: color-mix(in srgb, var(--warn) 12%, transparent); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.notice-info { background: var(--brand-soft); color: var(--brand-strong); }
.notice strong { color: inherit; }

/* ----------------------------------------------------------- emojis ---- */

.picker {
  position: fixed; z-index: 60;
  width: min(360px, calc(100vw - 24px)); height: 404px;
  display: flex; flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 34px -12px rgba(0, 0, 0, 0.34);
  overflow: hidden;
}
.picker-tabs { display: flex; border-bottom: 1px solid var(--line); flex: none; }
.picker-tabs button {
  flex: 1; height: 36px; font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent;
}
.picker-tabs button.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.picker-search { padding: 8px; flex: none; border-bottom: 1px solid var(--line); }
.picker-body { flex: 1; overflow-y: auto; padding: 6px; }
.picker-group-title {
  padding: 7px 6px 4px; font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint);
  position: sticky; top: -6px; background: var(--bg-raised); z-index: 1;
}
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); }
.emoji-btn {
  width: 36px; height: 36px; font-size: 23px; line-height: 1;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.emoji-btn:hover { background: var(--bg-hover); }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.sticker-btn { border-radius: var(--radius); padding: 4px; }
.sticker-btn:hover { background: var(--bg-hover); }
.sticker-btn img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.gif-grid { columns: 2; column-gap: 6px; }
.gif-grid button { width: 100%; margin-bottom: 6px; border-radius: var(--radius); overflow: hidden; display: block; }
.gif-grid img { width: 100%; display: block; }

.skin-tones { display: flex; gap: 2px; padding: 6px 8px; border-top: 1px solid var(--line); flex: none; }
.skin-tones button { width: 28px; height: 28px; font-size: 18px; border-radius: var(--radius-sm); }
.skin-tones button.is-active { background: var(--brand-soft); }

/* ------------------------------------------------------------ visor ---- */

.viewer {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(8, 11, 14, 0.94);
  display: flex; flex-direction: column;
}
.viewer-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; flex: none; color: #e9edf0;
}
.viewer-bar .name { flex: 1; min-width: 0; font-size: var(--fs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-bar .icon-btn { color: #c3cbd2; }
.viewer-bar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.viewer-stage {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  padding: 0 12px 16px; overflow: auto;
}
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-stage video { max-width: 100%; max-height: 100%; }
.viewer-stage .text-preview {
  width: min(900px, 100%); max-height: 100%; overflow: auto;
  background: var(--bg); color: var(--text);
  border-radius: var(--radius); padding: 16px;
  font-family: var(--font-mono); font-size: var(--fs-sm);
  white-space: pre-wrap;
}
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.12); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.viewer-nav:hover { background: rgba(255, 255, 255, 0.22); }
.viewer-nav.prev { left: 14px; }
.viewer-nav.next { right: 14px; }
.pdf-pages { display: flex; flex-direction: column; gap: 10px; align-items: center; width: 100%; }
.pdf-pages canvas { max-width: 100%; height: auto; background: #fff; border-radius: 4px; }
.archive-list { width: min(760px, 100%); background: var(--bg); color: var(--text); border-radius: var(--radius); overflow: hidden; }
.archive-list table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.archive-list th, .archive-list td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.archive-list th { background: var(--bg-hover); font-weight: 600; }
.archive-list td.size { text-align: right; color: var(--text-muted); white-space: nowrap; }

/* ------------------------------------------------------------ avisos --- */

.toasts {
  /* Abajo a la derecha en escritorio: en el centro taparían el redactor. */
  position: fixed; z-index: 80; bottom: 92px; right: 18px;
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  pointer-events: none; width: min(420px, calc(100vw - 24px));
}
.toast {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 13px; border-radius: var(--radius);
  background: var(--bg-raised); border: 1px solid var(--line);
  box-shadow: 0 6px 20px -8px rgba(0, 0, 0, 0.35);
  font-size: var(--fs-sm); pointer-events: auto;
  animation: toast-in 160ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.toast-body { flex: 1; min-width: 0; }
.toast.is-error { border-color: var(--danger); }
.toast.is-error .icon { color: var(--danger); }
.toast.is-ok .icon { color: var(--ok); }

.conn-banner {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 6px 14px; flex: none;
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: var(--warn); font-size: var(--fs-sm); font-weight: 500;
}
.conn-banner.is-error { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------------- acceso -- */

.auth-screen {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg-canvas);
}
.auth-card {
  width: min(400px, 100%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 28px 26px 22px;
}
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.auth-brand .mark {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: var(--brand); color: var(--brand-contrast);
  display: flex; align-items: center; justify-content: center;
}
.auth-brand h1 { margin: 0; font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.01em; }
.auth-brand p { margin: 0; font-size: var(--fs-sm); color: var(--text-muted); }
.auth-card .btn-primary { margin-top: 6px; }
.auth-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--text-faint); text-align: center; }

/* ------------------------------------------------------- administración */

.admin-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 0; flex: 1; }
.admin-nav { border-right: 1px solid var(--line); padding: 8px; overflow-y: auto; background: var(--bg-sidebar); }
.admin-nav button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius);
  font-size: var(--fs); text-align: left; color: var(--text-muted);
}
.admin-nav button:hover { background: var(--bg-hover); color: var(--text); }
.admin-nav button.is-active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 500; }
.admin-main { overflow-y: auto; padding: 18px; }
.admin-main h3 { margin: 0 0 4px; font-size: var(--fs-lg); }
.admin-main > p.lead { margin: 0 0 16px; color: var(--text-muted); font-size: var(--fs-sm); }
.admin-section { margin-bottom: 26px; }
.admin-section > h4 {
  margin: 0 0 10px; font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-faint);
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat {
  padding: 12px 13px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg);
}
.stat .label { font-size: var(--fs-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.stat .value { font-size: var(--fs-xl); font-weight: 600; line-height: 1.2; margin-top: 3px; }
.stat .hint { font-size: var(--fs-xs); color: var(--text-faint); }

.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; background: var(--bg); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data th, table.data td { padding: 8px 11px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { background: var(--bg-hover); font-weight: 600; position: sticky; top: 0; z-index: 1; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.wrap { white-space: normal; }
table.data td.actions { text-align: right; }
table.data tr:hover td { background: var(--bg-hover); }

.gw-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); margin-bottom: 10px; overflow: hidden;
}
.gw-head { display: flex; align-items: center; gap: 11px; padding: 11px 13px; }
.gw-head .gw-name { flex: 1; min-width: 0; }
.gw-head h5 { margin: 0; font-size: var(--fs-md); font-weight: 600; }
.gw-head .gw-addr { font-size: var(--fs-xs); color: var(--text-muted); font-family: var(--font-mono); }
.gw-status {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-sm); font-weight: 500;
}
.gw-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.gw-status.is-online { color: var(--ok); }
.gw-status.is-online .dot { background: var(--ok); }
.gw-status.is-error { color: var(--danger); }
.gw-status.is-error .dot { background: var(--danger); }
.gw-status.is-connecting { color: var(--warn); }
.gw-status.is-connecting .dot { background: var(--warn); animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }
.gw-body { border-top: 1px solid var(--line); padding: 11px 13px; background: var(--bg-sidebar); }
.gw-log {
  max-height: 200px; overflow-y: auto;
  font-family: var(--font-mono); font-size: var(--fs-xs);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px;
}
.gw-log div { padding: 1px 0; color: var(--text-muted); }
.gw-log .lvl-error { color: var(--danger); }
.gw-log .lvl-warn { color: var(--warn); }
.gw-log time { color: var(--text-faint); margin-right: 7px; }

.test-steps { list-style: none; margin: 10px 0 0; padding: 0; font-size: var(--fs-sm); }
.test-steps li { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.test-steps li:last-child { border-bottom: 0; }
.test-steps .ms { margin-left: auto; color: var(--text-faint); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
.test-steps .ok { color: var(--ok); }
.test-steps .ko { color: var(--danger); }

.secret-box {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px; border-radius: var(--radius);
  background: var(--bg-hover); border: 1px dashed var(--line-strong);
  font-family: var(--font-mono); font-size: var(--fs-sm);
  word-break: break-all;
}

/* -------------------------------------------------------------- móvil -- */

.mobile-only { display: none; }
.mobile-tabbar { display: none; }

@media (max-width: 900px) {
  :root { --sidebar-w: 100%; }

  .app, .app.has-info { grid-template-columns: 100%; }

  .sidebar, .chat, .info-panel {
    grid-column: 1; grid-row: 1;
    width: 100%;
  }

  /* En móvil se navega entre pantallas, no se encoge el escritorio. */
  .app[data-mobile-view="list"] .chat,
  .app[data-mobile-view="list"] .info-panel { display: none; }
  .app[data-mobile-view="chat"] .sidebar,
  .app[data-mobile-view="chat"] .info-panel { display: none; }
  .app[data-mobile-view="info"] .sidebar,
  .app[data-mobile-view="info"] .chat { display: none; }
  .app[data-mobile-view="info"] .info-panel { display: flex; }

  .info-panel { border-left: 0; }
  .mobile-only { display: inline-flex; }
  .desktop-only { display: none !important; }

  .app[data-mobile-view="list"] .mobile-tabbar { display: flex; }
  .mobile-tabbar {
    grid-column: 1; grid-row: 2;
    align-items: stretch; flex: none;
    border-top: 1px solid var(--line);
    background: var(--bg-sidebar);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app[data-mobile-view="list"] { grid-template-rows: minmax(0, 1fr) auto; }
  .mobile-tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; padding: 7px 0 5px; color: var(--text-muted);
    font-size: var(--fs-xs); position: relative;
  }
  .mobile-tabbar button.is-active { color: var(--brand); }
  .mobile-tabbar .unread-pill { position: absolute; top: 3px; left: 50%; margin-left: 4px; }

  .messages-inner { padding: 0 10px; }
  .toasts { left: 12px; right: 12px; width: auto; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .msg-group-body { max-width: 86%; }
  .composer { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .chat-header { padding-left: 4px; }
  .jump-bottom { right: 12px; bottom: 88px; }

  /* Objetivos táctiles cómodos */
  .icon-btn { width: 40px; height: 40px; }
  .btn { height: 40px; }
  .chat-row { padding: 9px 10px; }
  /* En táctil no hay hover, así que las acciones se ven siempre, pero sólo el
     menú: tres iconos en cada burbuja ensucian la conversación. Mantener
     pulsado sigue abriendo el menú completo. */
  .msg-actions { opacity: 1; pointer-events: auto; position: static; transform: none;
    background: transparent; border: 0; padding: 0; margin-top: 2px; justify-content: flex-end; }
  .msg-group.is-mine .msg-actions, .msg-group:not(.is-mine) .msg-actions { transform: none; }
  .msg-actions .icon-btn:not(:last-child) { display: none; }
  .msg-actions .icon-btn { width: 30px; height: 30px; }

  .dialog { width: 100%; max-height: 94dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .overlay { padding: 0; align-items: flex-end; }
  .dialog-wide { width: 100%; }
  .admin-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .admin-nav { border-right: 0; border-bottom: 1px solid var(--line); display: flex; gap: 4px; overflow-x: auto; }
  .admin-nav button { width: auto; white-space: nowrap; }
  .picker { width: calc(100vw - 16px); left: 8px !important; right: 8px; }
}

@media (max-width: 900px) and (orientation: landscape) {
  .picker { height: 300px; }
  .info-hero { padding: 12px; }
  .info-hero .avatar { width: 48px; height: 48px; font-size: var(--fs-md); }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .app.has-info { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .app.has-info .chat { display: none; }
}

@media print {
  .sidebar, .composer, .chat-header, .info-panel, .mobile-tabbar { display: none !important; }
  .app { display: block; height: auto; }
  .messages { overflow: visible; }
}

/* ------------------------------------------------------- lista de personas */

/* Dos vistas en la misma columna: conversaciones y personas. */
.lateral-tabs {
  display: flex; gap: 4px; padding: 0 10px 8px; flex: none;
}
.lateral-tab {
  flex: 1; height: 30px; border-radius: var(--radius);
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lateral-tab:hover { background: var(--bg-hover); }
.lateral-tab.is-active { background: var(--bg-active); color: var(--text); }
.personas-conectados {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--radius-pill);
  background: var(--ok); color: #fff;
  font-size: var(--fs-xs); font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.personas { flex: 1; min-height: 0; overflow-y: auto; padding: 0 6px 10px; }
.personas-top { padding: 0 4px 8px; display: flex; flex-direction: column; gap: 8px; }
.personas-resumen { font-size: var(--fs-xs); color: var(--text-muted); padding: 0 2px; }
.personas-grupo {
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-faint);
  padding: 12px 8px 4px;
}

.persona {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px; border-radius: var(--radius);
  text-align: left; transition: background var(--dur) var(--ease);
}
.persona:hover { background: var(--bg-hover); }
.persona .avatar { position: relative; flex: none; }
.persona.is-desconectado .avatar { opacity: .5; }
.persona.is-desconectado .persona-nombre { color: var(--text-muted); font-weight: 500; }
.persona-datos { flex: 1; min-width: 0; }
.persona-nombre {
  display: flex; align-items: center; gap: 6px;
  font-size: var(--fs); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.persona-detalle {
  font-size: var(--fs-xs); color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.persona-puesto {
  font-size: var(--fs-xs); color: var(--text-faint); flex: none;
  max-width: 35%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* El punto de color del estado, sobre el avatar. */
.punto-estado {
  position: absolute; right: -1px; bottom: -1px;
  width: 11px; height: 11px; border-radius: 50%;
  border: 2px solid var(--bg-sidebar);
  background: var(--line-strong);
}
.punto-estado.es-disponible { background: var(--ok); }
.punto-estado.es-ausente { background: var(--warn); }
.punto-estado.es-ocupado { background: var(--danger); }
.punto-estado.es-no-molestar {
  background: var(--danger);
  box-shadow: inset 0 0 0 2px var(--bg-sidebar);
}
.punto-estado.es-remoto { background: var(--brand); }
.punto-estado.es-desconectado { background: var(--line-strong); }

@media (max-width: 900px) {
  .personas { padding: 0 8px 10px; }
  .persona { padding: 10px 8px; }
}
