:root {
  --bg: #F5FAFF; --surface: #FFFFFF; --ink: #0A1B3D; --muted: #4D5E7C; --line: #D9E4F5;
  --blue: #2F6BFF; --blue-d: #1F52E0; --teal: #07766B; --teal-tint: #E2FBF7; --sun: #FFC247; --err: #C2412F;
  --burbuja-persona: #FFFFFF; --burbuja-ia: #EAF3FF; --burbuja-equipo: #2F6BFF; --texto-equipo: #FFFFFF;
  --sombra: 0 1px 2px rgba(10, 27, 61, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070F22; --surface: #0F1C3A; --ink: #EAF1FF; --muted: #9DB0D3; --line: #1E3160;
    --blue: #4C82FF; --blue-d: #3A6EF0; --teal: #2CE0CC; --teal-tint: #0F3A52; --err: #FF8E80;
    --burbuja-persona: #0F1C3A; --burbuja-ia: #16295A; --burbuja-equipo: #3366EE;
    --sombra: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
h1 { font-size: 1.15rem; margin: 0; }

.vista { min-height: 100dvh; max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; }
.primario { background: var(--blue); color: #fff; border: 0; border-radius: 10px; padding: .7rem 1.1rem; font-weight: 600; }
.primario:hover { background: var(--blue-d); }
.primario:disabled { opacity: .5; cursor: default; }
.secundario { background: transparent; color: var(--blue); border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem; font-size: .9rem; }
.icono { background: none; border: 0; color: var(--ink); font-size: 1.6rem; line-height: 1; padding: .2rem .5rem; min-width: 44px; min-height: 44px; }

/* Entrar */
.entrar { justify-content: center; padding: 16px; }
.tarjeta { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 1.5rem; display: grid; gap: .9rem; box-shadow: var(--sombra); width: 100%; max-width: 360px; margin: 0 auto; }
.tarjeta img { justify-self: center; }
.tarjeta h1 { text-align: center; }
label { display: grid; gap: .3rem; font-size: .9rem; color: var(--muted); }
input, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .65rem .75rem; width: 100%; }
.error { color: var(--err); margin: 0; min-height: 1.2em; font-size: .9rem; }

/* Barra superior */
.barra { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: .5rem; padding: .5rem 16px; padding-top: max(.5rem, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); }
.barra h1 { flex: 1; }
.estado-red { font-size: .8rem; color: var(--muted); }
.titulo { flex: 1; min-width: 0; }
.titulo h1, .titulo p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.titulo p { margin: 0; font-size: .82rem; color: var(--muted); }

/* Filtros */
.filtros { padding: .75rem 16px .25rem; display: grid; gap: .6rem; }
.chips { display: flex; gap: .4rem; overflow-x: auto; scrollbar-width: none; padding-bottom: .2rem; }
.chip { flex: none; background: var(--surface); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem; font-size: .88rem; }
.chip.activo { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* Lista */
.lista { list-style: none; margin: 0; padding: 0 0 2rem; }
.lista button { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); color: inherit; padding: .8rem 16px; display: grid; grid-template-columns: auto 1fr auto; gap: .2rem .7rem; align-items: center; }
.lista button:hover { background: var(--surface); }
.canal { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; font-weight: 700; color: #fff; grid-row: span 2; }
.canal.whatsapp { background: #128C4B; }
.canal.instagram { background: #C13584; }
.nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hora { font-size: .78rem; color: var(--muted); }
.previa { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.marcas { display: flex; gap: .3rem; justify-content: flex-end; }
.marca { font-size: .7rem; font-weight: 700; border-radius: 6px; padding: .1rem .4rem; }
.marca.pendiente { background: var(--sun); color: #3A2A00; }
.marca.humano { background: var(--teal-tint); color: var(--teal); }
.vacio { text-align: center; color: var(--muted); padding: 2rem 16px; }

/* Chat */
.control { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.pill { font-size: .85rem; color: var(--muted); }
.pill.humano { color: var(--teal); font-weight: 600; }
.ficha { margin: .5rem 16px 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem; font-size: .9rem; }
.ficha summary { cursor: pointer; font-weight: 600; }
.ficha dl { margin: .5rem 0 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .7rem; }
.ficha dt { color: var(--muted); }
.ficha dd { margin: 0; overflow-wrap: anywhere; }
.mensajes { list-style: none; margin: 0; padding: 1rem 16px; flex: 1; display: flex; flex-direction: column; gap: .4rem; }
.msj { max-width: 82%; padding: .5rem .75rem; border-radius: 14px; box-shadow: var(--sombra); white-space: pre-wrap; overflow-wrap: anywhere; }
.msj small { display: block; font-size: .7rem; opacity: .7; margin-top: .2rem; }
.msj.persona { align-self: flex-start; background: var(--burbuja-persona); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msj.asistente, .msj.seguimiento { align-self: flex-end; background: var(--burbuja-ia); border-bottom-right-radius: 4px; }
.msj.equipo { align-self: flex-end; background: var(--burbuja-equipo); color: var(--texto-equipo); border-bottom-right-radius: 4px; }
.msj.enviando { opacity: .6; }
.dia { align-self: center; font-size: .75rem; color: var(--muted); margin: .5rem 0; }
.escribir { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: .5rem 16px; padding-bottom: max(.5rem, env(safe-area-inset-bottom)); }
.ventana { margin: 0 0 .4rem; font-size: .8rem; color: var(--muted); }
.ventana.cerrada { color: var(--err); }
.fila { display: flex; gap: .5rem; align-items: flex-end; }
.fila textarea { resize: none; max-height: 9rem; }

.aviso { position: fixed; left: 50%; bottom: 5.5rem; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; max-width: calc(100% - 32px); z-index: 5; }

/* Archivos de los chats */
.msj.con-archivo { max-width: 86%; }
.msj .texto { display: block; }
.archivo { display: grid; gap: .3rem; margin-bottom: .3rem; }
.archivo .foto { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; cursor: zoom-in; background: var(--line); min-height: 60px; }
.archivo .sticker { width: 128px; height: 128px; object-fit: contain; cursor: zoom-in; }
.archivo audio { width: 240px; max-width: 100%; }
.archivo video { max-width: 100%; max-height: 360px; border-radius: 10px; background: #000; }
.archivo-abrir { font-size: .8rem; color: inherit; opacity: .8; }
.archivo-error { font-size: .85rem; font-style: italic; opacity: .85; }
