/* ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
   📱 BANDEJA WHATSAPP para celular y PC (31/10/2026) — la hoja de /bandeja/.
   Espejo de la pestaña «WhatsApp» de Wiselink Chat: el mismo verde, las mismas tarjetas de chat, el número en azul, la etiqueta
   de color, las burbujas de WhatsApp. Un solo frente, dos formatos: hasta 899 px dos pantallas apiladas (lista y chat, el chat
   entra desde la derecha); desde 900 px dos columnas como en la app. La elección la hace el ANCHO, no el aparato.
   Las líneas cumplen la regla canónica de las líneas que se ven (≥ 1,45 en claro, ≥ 2,0 en oscuro): --linea #c4cbd4 / #4b5b70,
   los mismos de /lineas-visibles.css. El modo oscuro va por preferencia del sistema o por el botón (data-theme), como en la app.
   ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════ */
:root {
  --verde: #25D366; --verde-tinta: #15803d; --verde-suave: #f0fdf4;
  --pagina: #f0f2f5; --tarjeta: #ffffff; --campo: #ffffff; --barra: #ffffff;
  --tinta: #111827; --tinta-2: #4b5563; --tinta-3: #6b7280; --tinta-4: #9ca3af;
  --tel: #3b82f6; --linea: #c4cbd4; --linea-suave: #c4cbd4; --linea-fuerte: #a3adbb;   /* sobre el fondo del chat y las burbujas */
  --burbuja-entra: #ffffff; --burbuja-sale: #d9fdd3; --tilde-azul: #53bdeb; --fondo-chat: #efeae2;
  --hover: #f3f4f6; --activo: #f0fdf4; --sombra: 0 1px 2px rgba(17, 24, 39, .08);
  --rojo: #dc2626; --ambar: #b45309; --ambar-fondo: #fef3c7;
  --alto-barra: 56px; --ancho-lista: 380px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --verde-tinta: #4ade80; --verde-suave: rgba(37, 211, 102, .14);
    --pagina: #0b1220; --tarjeta: #1e293b; --campo: #16202e; --barra: #1e293b;
    --tinta: #f1f5f9; --tinta-2: #cbd5e1; --tinta-3: #94a3b8; --tinta-4: #7c8aa0;
    --tel: #60a5fa; --linea: #4b5b70; --linea-suave: #4b5b70; --linea-fuerte: #7489a6;
    --burbuja-entra: #1e293b; --burbuja-sale: #1f4d3a; --fondo-chat: #0f1826;
    --hover: #2f3e54; --activo: rgba(37, 211, 102, .14); --sombra: 0 1px 3px rgba(0, 0, 0, .5);
    --rojo: #f87171; --ambar: #fbbf24; --ambar-fondo: rgba(245, 158, 11, .15);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --verde-tinta: #4ade80; --verde-suave: rgba(37, 211, 102, .14);
  --pagina: #0b1220; --tarjeta: #1e293b; --campo: #16202e; --barra: #1e293b;
  --tinta: #f1f5f9; --tinta-2: #cbd5e1; --tinta-3: #94a3b8; --tinta-4: #7c8aa0;
  --tel: #60a5fa; --linea: #4b5b70; --linea-suave: #4b5b70; --linea-fuerte: #7489a6;
  --burbuja-entra: #1e293b; --burbuja-sale: #1f4d3a; --fondo-chat: #0f1826;
  --hover: #2f3e54; --activo: rgba(37, 211, 102, .14); --sombra: 0 1px 3px rgba(0, 0, 0, .5);
  --rojo: #f87171; --ambar: #fbbf24; --ambar-fondo: rgba(245, 158, 11, .15);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--pagina); color: var(--tinta);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, .fila:focus-visible { outline: 2px solid var(--verde); outline-offset: 2px; }
.oculto { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
a { color: var(--tel); }

/* ── La app: dos columnas en PC, dos pantallas en celular ── */
.app { height: 100dvh; display: grid; grid-template-columns: 1fr; overflow: hidden; }
.col-lista, .col-chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--tarjeta); }
.col-chat { background: var(--fondo-chat); }
@media (max-width: 899px) {
  .app { position: relative; }
  .col-lista, .col-chat { position: absolute; inset: 0; }
  .col-chat { transform: translateX(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1); will-change: transform; }
  .app[data-pantalla="chat"] .col-chat { transform: translateX(0); }
  .app[data-pantalla="chat"] .col-lista { visibility: hidden; transition: visibility 0s .22s; }
  .chat-vacio { display: none; }
}
@media (min-width: 900px) {
  .app { grid-template-columns: var(--ancho-lista) 1fr; }
  .col-lista { border-right: 1px solid var(--linea); }
  .btn-volver { display: none; }
}
@media (prefers-reduced-motion: reduce) { .col-chat { transition: none; } }

/* ── Barras ── */
.barra {
  height: var(--alto-barra); flex: none; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--barra); border-bottom: 1px solid var(--linea);
  padding-top: env(safe-area-inset-top); height: calc(var(--alto-barra) + env(safe-area-inset-top));
}
.marca { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.marca img { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.marca b { display: block; font-size: 15px; line-height: 1.1; }
.marca small { display: block; font-size: 11.5px; color: var(--tinta-3); }
.icono-btn {
  width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: var(--tinta-2); font-size: 20px; flex: none;
}
.icono-btn:hover { background: var(--hover); }
.icono-btn:active { background: var(--activo); }
.icono-btn svg { width: 22px; height: 22px; }
.punto-aviso { position: relative; }
.punto-aviso::after { content: ""; position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--rojo); }

/* ── Herramientas de la lista ── */
.herr { padding: 8px 12px 0; display: flex; flex-direction: column; gap: 8px; flex: none; }
.selector {
  width: 100%; height: 38px; border: 1px solid var(--linea); border-radius: 10px; background: var(--campo); padding: 0 10px;
  color: var(--tinta); appearance: auto;
}
.buscar { position: relative; }
.buscar input {
  width: 100%; height: 40px; border: 1px solid var(--linea); border-radius: 12px; background: var(--campo); padding: 0 12px 0 38px;
  color: var(--tinta);
}
.buscar input::placeholder { color: var(--tinta-4); }
.buscar svg { position: absolute; left: 12px; top: 11px; width: 18px; height: 18px; color: var(--tinta-4); pointer-events: none; }
.filtros { display: flex; gap: 6px; padding: 8px 12px; flex: none; border-bottom: 1px solid var(--linea); overflow-x: auto; scrollbar-width: none; }
.filtros::-webkit-scrollbar { display: none; }
.filtro {
  height: 34px; padding: 0 14px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--tinta-3); white-space: nowrap;
  border: 1px solid transparent;
}
.filtro:hover { background: var(--hover); }
.filtro.activo { background: var(--tarjeta); color: var(--tinta); border-color: var(--linea); box-shadow: var(--sombra); }
.filtro .n { color: var(--verde-tinta); margin-left: 3px; }
.aviso { margin: 8px 12px 0; padding: 10px 12px; border-radius: 10px; background: var(--ambar-fondo); color: var(--ambar); font-size: 13px; flex: none; }

/* ── La lista de chats: las mismas tarjetas que la app ── */
.lista { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.fila {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 12px;
  border-left: 3px solid transparent; border-bottom: 1px solid var(--linea); min-height: 76px;
}
.fila:hover { background: var(--hover); }
.fila.activo { background: var(--activo); border-left-color: var(--verde); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex: none; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 16px; user-select: none;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.fila-info { flex: 1; min-width: 0; }
.fila-arriba { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fila-nombre { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-hora { font-size: 12px; color: var(--tinta-4); flex: none; }
.fila-tel { font-size: 12px; color: var(--tel); line-height: 1.3; }
.fila-abajo { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.fila-ult { flex: 1; min-width: 0; font-size: 13px; color: var(--tinta-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila.sin-leer .fila-ult { color: var(--tinta); font-weight: 500; }
.globo { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--verde); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; flex: none; }
.pill.gray, .pill.slate { background: var(--hover); color: var(--tinta-3); }
.pill.red { background: rgba(239, 68, 68, .14); color: #dc2626; }
.pill.yellow { background: rgba(234, 179, 8, .18); color: #a16207; }
.pill.blue { background: rgba(59, 130, 246, .14); color: #2563eb; }
.pill.green { background: rgba(34, 197, 94, .16); color: #15803d; }
.pill.purple { background: rgba(168, 85, 247, .14); color: #7e22ce; }
.pill.orange { background: rgba(249, 115, 22, .16); color: #c2410c; }
.pill.teal { background: rgba(20, 184, 166, .16); color: #0f766e; }
.pill.pink { background: rgba(236, 72, 153, .14); color: #be185d; }
:root[data-theme="dark"] .pill.red, :root[data-theme="dark"] .pill.yellow, :root[data-theme="dark"] .pill.blue, :root[data-theme="dark"] .pill.green,
:root[data-theme="dark"] .pill.purple, :root[data-theme="dark"] .pill.orange, :root[data-theme="dark"] .pill.teal, :root[data-theme="dark"] .pill.pink { filter: brightness(1.6); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pill.red, :root:not([data-theme="light"]) .pill.yellow, :root:not([data-theme="light"]) .pill.blue, :root:not([data-theme="light"]) .pill.green,
  :root:not([data-theme="light"]) .pill.purple, :root:not([data-theme="light"]) .pill.orange, :root:not([data-theme="light"]) .pill.teal, :root:not([data-theme="light"]) .pill.pink { filter: brightness(1.6); }
}
.vacio { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--tinta-4); padding: 24px; text-align: center; }
.vacio svg { width: 56px; height: 56px; opacity: .5; }

/* ── El chat ── */
.chat-vacio { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; color: var(--tinta-4); }
.chat-vacio svg { width: 64px; height: 64px; opacity: .45; }
.barra-chat { gap: 8px; padding-left: 6px; }
.barra-chat .avatar { width: 40px; height: 40px; font-size: 14px; }
.chat-quien { flex: 1; min-width: 0; }
.chat-quien b { display: block; font-size: 15px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-quien span { display: block; font-size: 12px; color: var(--tel); }
.chat-etiqueta { height: 30px; border: 1px solid var(--linea); border-radius: 999px; padding: 0 10px; font-size: 12px; font-weight: 600; color: var(--tinta-2); max-width: 40%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-etiqueta:hover { background: var(--hover); }
.mensajes { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 10px 12px 12px; display: flex; flex-direction: column; }
.mas-viejos { align-self: center; margin: 2px 0 10px; font-size: 12px; color: var(--tel); padding: 6px 12px; border-radius: 999px; border: 1px solid var(--linea-fuerte); background: var(--tarjeta); }
.fecha-sep { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 11px; color: var(--tinta-3); text-transform: capitalize; }
.fecha-sep::before, .fecha-sep::after { content: ""; flex: 1; height: 1px; background: var(--linea); opacity: .7; }
.burbuja-fila { display: flex; margin-bottom: 4px; }
.burbuja-fila.sale { justify-content: flex-end; }
.burbuja {
  max-width: min(78%, 520px); padding: 7px 10px 5px; border-radius: 14px; box-shadow: var(--sombra);
  background: var(--burbuja-entra); color: var(--tinta); font-size: 14.5px; line-height: 1.4; word-wrap: break-word; overflow-wrap: anywhere;
}
.burbuja-fila.entra .burbuja { border-top-left-radius: 4px; }
.burbuja-fila.sale .burbuja { background: var(--burbuja-sale); border-top-right-radius: 4px; }
.burbuja p { margin: 0; white-space: pre-wrap; }
.burbuja .meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 3px; font-size: 10.5px; color: var(--tinta-4); }
.burbuja .meta .tilde { display: inline-flex; align-items: center; }
.burbuja .meta .tilde svg { width: 15px; height: 11px; }
.burbuja .cita { border-left: 3px solid var(--verde); background: rgba(0, 0, 0, .06); border-radius: 6px; padding: 4px 8px; margin-bottom: 5px; font-size: 12px; color: var(--tinta-2); }
.burbuja .cita b { display: block; color: var(--verde-tinta); font-size: 11px; }
.burbuja img.foto { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; margin: 2px 0 4px; background: var(--hover); cursor: zoom-in; }
.burbuja video { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; margin: 2px 0 4px; }
.burbuja audio { display: block; width: min(68vw, 280px); margin: 2px 0 4px; }
.burbuja .adj { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(0, 0, 0, .06); color: var(--tinta); text-decoration: none; margin: 2px 0 4px; font-size: 13px; }
.burbuja .adj span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.burbuja .transcr { font-size: 12.5px; color: var(--tinta-2); font-style: italic; margin-top: 2px; }
.burbuja .bajar { font-size: 12px; color: var(--tel); border: 1px solid var(--linea-fuerte); border-radius: 8px; padding: 5px 9px; margin: 2px 0 4px; }
.burbuja .marca-linea { font-size: 10px; color: var(--tinta-4); border: 1px solid var(--linea); border-radius: 4px; padding: 0 4px; }

/* ── Redactar ── */
.adjuntos { flex: none; display: flex; gap: 8px; padding: 8px 12px 0; overflow-x: auto; background: var(--barra); border-top: 1px solid var(--linea); }
.adjunto { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--hover); border: 1px solid var(--linea); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--tinta-2); text-align: center; padding: 4px; }
.adjunto img { width: 100%; height: 100%; object-fit: cover; }
.adjunto .quitar { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.adjuntos .enviando { font-size: 12px; color: var(--ambar); align-self: center; }
.redactar {
  flex: none; display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--barra); border-top: 1px solid var(--linea);
}
.adjuntos + .redactar { border-top: 0; }
.redactar textarea {
  flex: 1; min-height: 42px; max-height: 140px; resize: none; border: 1px solid var(--linea); border-radius: 21px; background: var(--campo);
  padding: 10px 14px; line-height: 1.35; font-size: 15px;
}
.redactar textarea::placeholder { color: var(--tinta-4); }
.btn-enviar { width: 42px; height: 42px; border-radius: 50%; background: var(--verde); color: #fff; display: inline-flex; align-items: center; justify-content: center; flex: none; }
.btn-enviar:disabled { opacity: .5; cursor: default; }
.btn-enviar svg { width: 20px; height: 20px; margin-left: 2px; }
.solo-lectura { flex: none; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); font-size: 13px; color: var(--tinta-3); background: var(--barra); border-top: 1px solid var(--linea); text-align: center; }

/* ── Hojas que suben desde abajo (etiquetas, nuevo chat, menú) ── */
.hoja { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.hoja-fondo { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.hoja-panel {
  position: relative; width: 100%; max-width: 520px; max-height: 85dvh; background: var(--tarjeta); border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, .18); display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom);
  animation: subir .2s cubic-bezier(.2, .8, .2, 1);
}
@media (min-width: 900px) { .hoja { align-items: center; } .hoja-panel { border-radius: 18px; max-height: 80vh; } }
@keyframes subir { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hoja-panel { animation: none; } }
.hoja-cab { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.hoja-cab h2 { margin: 0; font-size: 16px; }
.hoja-cuerpo { overflow-y: auto; padding: 0 8px 10px; }
.hoja-cuerpo .buscar { padding: 0 8px 8px; }
.opcion { width: 100%; text-align: left; display: flex; align-items: center; gap: 12px; padding: 12px 10px; border-radius: 12px; font-size: 15px; }
.opcion:hover { background: var(--hover); }
.opcion.elegida { background: var(--activo); }
.opcion .marca-ok { margin-left: auto; color: var(--verde-tinta); font-weight: 700; }
.opcion small { color: var(--tinta-4); font-size: 12px; }
.opcion .avatar { width: 36px; height: 36px; font-size: 12px; }
.opcion .dos { min-width: 0; flex: 1; }
.opcion .dos span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.opcion .dos small { display: block; }
.interruptor { margin-left: auto; width: 44px; height: 26px; border-radius: 13px; background: var(--tinta-4); position: relative; flex: none; transition: background .15s; }
.interruptor::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.interruptor.on { background: var(--verde); }
.interruptor.on::after { transform: translateX(18px); }
.hoja-nota { padding: 4px 18px 10px; font-size: 12.5px; color: var(--tinta-3); }

/* ── Ingreso ── */
.ingreso { position: fixed; inset: 0; z-index: 60; background: var(--pagina); display: flex; align-items: center; justify-content: center; padding: 20px; }
.ingreso form { width: 100%; max-width: 360px; background: var(--tarjeta); border: 1px solid var(--linea); border-radius: 18px; padding: 24px; box-shadow: var(--sombra); }
.ingreso .marca { margin-bottom: 18px; }
.ingreso label { display: block; font-size: 13px; color: var(--tinta-2); margin: 10px 0 4px; }
.ingreso input { width: 100%; height: 42px; border: 1px solid var(--linea); border-radius: 10px; background: var(--campo); padding: 0 12px; }
.ingreso .btn-ingresar { width: 100%; height: 44px; margin-top: 16px; border-radius: 10px; background: var(--verde); color: #fff; font-weight: 700; font-size: 15px; }
.ingreso .btn-ingresar:disabled { opacity: .6; }
.ingreso .error { color: var(--rojo); font-size: 13px; margin-top: 10px; }

/* ── Avisos ── */
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 70; background: var(--tinta); color: var(--tarjeta); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; max-width: min(92vw, 420px); box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
.visor { position: fixed; inset: 0; z-index: 65; background: rgba(0, 0, 0, .92); display: flex; align-items: center; justify-content: center; }
.visor img { max-width: 100%; max-height: 100%; object-fit: contain; }
