:root {
  --naranja: #f77f00; --naranja-hondo: #f26400; --naranja-suave: #fff1e3;
  --noche: #141719; --grafito: #1f2326; --papel: #f6f6f4; --borde: #e5e4e0;
  --texto: #1f2326; --apagado: #6b7075; --rojo: #c62828; --verde: #2e7d32;
  --esperando: #d84315; --esperando-suave: #fdebe4; --humano: #1565c0; --humano-suave: #e6eff9;
  --agente: #5f6b73; --agente-suave: #eceeef;
  --alto-barra: 56px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--papel); color: var(--texto); font: 15px/1.45 Inter, system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
h1, h2 { font-family: Poppins, Inter, sans-serif; line-height: 1.2; margin: 0 0 .5em; }
a { color: var(--naranja-hondo); }
.apagado { color: var(--apagado); }
.chico { font-size: .85rem; }
.ok { background: #e8f5e9; color: var(--verde); padding: .6rem .8rem; border-radius: 8px; }
.error { background: #fdecea; color: var(--rojo); padding: .6rem .8rem; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--naranja); outline-offset: 2px; }

/* botones y campos */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border: 1px solid var(--borde); background: #fff; color: var(--texto); padding: .6rem 1rem; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 42px; }
.btn.principal { background: var(--naranja); border-color: var(--naranja); color: #fff; }
.btn.principal:active { background: var(--naranja-hondo); }
.btn.chico { padding: .35rem .75rem; font-size: .85rem; min-height: 34px; border-radius: 8px; }
.btn.grande { width: 100%; padding: .85rem; font-size: 1rem; }
.btn:disabled { opacity: .5; }
.btn-icono { border: none; background: none; cursor: pointer; padding: .5rem; border-radius: 8px; color: inherit; font-size: 1.1rem; line-height: 1; min-width: 40px; min-height: 40px; }
label { display: block; font-weight: 500; font-size: .88rem; margin-bottom: .8rem; }
input, textarea, select { display: block; width: 100%; margin-top: .3rem; padding: .6rem .7rem; border: 1px solid #d6d6d1; border-radius: 9px; font: inherit; font-size: 16px; background: #fff; color: var(--texto); }
textarea { resize: vertical; }

/* acceso */
body.acceso { display: grid; place-items: center; padding: 1.25rem; background: var(--noche); min-height: 100%; }
.tarjeta-acceso { width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 1.75rem; }
.logo-acceso { height: 34px; background: var(--noche); padding: .5rem .8rem; border-radius: 8px; margin-bottom: 1.2rem; }
.tarjeta-acceso h1 { font-size: 1.3rem; }
.qr { display: block; margin: .5rem auto 1rem; border: 1px solid var(--borde); border-radius: 8px; }
.pasos-config { padding-left: 1.2rem; }

/* estructura: lista a la izquierda, chat a la derecha (en el teléfono, una cosa a la vez) */
body.aplicacion { overflow: hidden; }
.app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: minmax(320px, 400px) minmax(0, 1fr); }
.col-lista { display: flex; flex-direction: column; min-height: 0; background: #fff; border-right: 1px solid var(--borde); }
.cabecera { display: flex; align-items: center; gap: .6rem; padding: .55rem .75rem; padding-top: max(.55rem, env(safe-area-inset-top)); background: var(--noche); color: #fff; }
.cabecera .logo { height: 24px; }
.pestanas { display: flex; gap: .2rem; flex: 1; justify-content: center; }
.pestana { color: #b9bdc0; text-decoration: none; font-weight: 600; padding: .45rem .8rem; border-radius: 99px; font-size: .92rem; display: inline-flex; align-items: center; gap: .35rem; }
.pestana.activa { background: rgba(255,255,255,.12); color: #fff; }
.insignia { background: var(--naranja); color: #fff; border-radius: 99px; font-size: .72rem; padding: .05rem .4rem; min-width: 1.2rem; text-align: center; }
.salir { margin: 0; }
.salir .btn-icono { color: #b9bdc0; font-size: .8rem; font-weight: 600; font-family: inherit; }
.vista { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.buscador { padding: .6rem .75rem .3rem; }
.buscador input { margin: 0; background: var(--papel); border-color: transparent; border-radius: 99px; padding: .55rem .9rem; }
.chips { display: flex; gap: .35rem; padding: .35rem .75rem .6rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--borde); }
.chip { flex: none; border: 1px solid var(--borde); background: #fff; border-radius: 99px; padding: .35rem .75rem; font: inherit; font-size: .85rem; font-weight: 500; cursor: pointer; color: var(--texto); }
.chip.activa { background: var(--noche); border-color: var(--noche); color: #fff; }
.chip b { font-weight: 700; color: var(--naranja); }
.chip.activa b { color: #ffb366; }
.chip b:empty { display: none; }

.lista { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.lista-vacia { padding: 2rem 1.25rem; color: var(--apagado); text-align: center; }
.fila { display: flex; gap: .7rem; padding: .7rem .75rem; text-decoration: none; color: inherit; border-bottom: 1px solid #f0efeb; }
.fila:hover { background: #fafaf8; }
.fila.activa { background: var(--naranja-suave); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--agente); font-family: Poppins, sans-serif; }
.avatar.estado-esperando { background: var(--esperando); box-shadow: 0 0 0 3px var(--esperando-suave); }
.avatar.estado-humano { background: var(--humano); }
.fila-centro { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .1rem; }
.fila-linea { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.fila-linea strong { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.fila-linea time { font-size: .75rem; color: var(--apagado); flex: none; }
.previa { flex: 1; min-width: 0; color: var(--apagado); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sin-leer .previa { color: var(--texto); font-weight: 500; }
.sin-leer time { color: var(--naranja-hondo); font-weight: 600; }
.contador { flex: none; background: var(--naranja); color: #fff; border-radius: 99px; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; min-width: 1.3rem; text-align: center; }
.fila-etiquetas { display: flex; gap: .3rem; align-items: center; margin-top: .15rem; min-width: 0; }
.pastilla { flex: none; font-size: .7rem; font-weight: 600; padding: .08rem .45rem; border-radius: 99px; text-transform: capitalize; background: var(--agente-suave); color: var(--agente); }
.pastilla.esperando { background: var(--esperando-suave); color: var(--esperando); }
.pastilla.humano { background: var(--humano-suave); color: var(--humano); }
.pastilla.etapa-calificado { background: #fff4d6; color: #8a5a00; }
.pastilla.etapa-propuesta { background: #ede7f6; color: #5e35b1; }
.pastilla.etapa-ganado { background: #e8f5e9; color: var(--verde); }
.pastilla.etapa-perdido { background: #f1f1f1; color: #8a8a8a; }
.motivo { font-size: .75rem; color: var(--esperando); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

/* chat */
.col-chat { position: relative; min-width: 0; min-height: 0; display: flex; background: #efeae2; }
.vacio { margin: auto; text-align: center; color: var(--apagado); }
.vacio img { opacity: .6; border-radius: 16px; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-cabeza { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; padding-top: max(.5rem, env(safe-area-inset-top)); background: #fff; border-bottom: 1px solid var(--borde); }
.chat-cabeza .avatar { width: 38px; height: 38px; font-size: .9rem; }
.volver { display: none; }
.chat-quien { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-quien strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-quien span { font-size: .8rem; color: var(--apagado); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.aviso-estado { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .6rem .9rem; font-size: .88rem; flex-wrap: wrap; }
.aviso-estado > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.aviso-estado small { color: var(--apagado); }
.aviso-estado .acciones { display: flex; gap: .4rem; }
.aviso-estado.esperando { background: var(--esperando-suave); border-bottom: 2px solid var(--esperando); }
.aviso-estado.esperando strong { color: var(--esperando); }
.aviso-estado.humano { background: var(--humano-suave); }
.aviso-estado.humano strong { color: var(--humano); }
.aviso-estado.agente { background: #fff; border-bottom: 1px solid var(--borde); }

.mensajes { flex: 1; overflow-y: auto; padding: 1rem .9rem; display: flex; flex-direction: column; gap: .35rem; }
.msg { max-width: min(78%, 560px); padding: .45rem .7rem .3rem; border-radius: 12px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.06); align-self: flex-start; }
.msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg time { display: block; text-align: right; font-size: .68rem; color: var(--apagado); margin-top: .1rem; }
.msg .quien { display: block; font-size: .7rem; font-weight: 700; margin-bottom: .1rem; }
.msg.agente { align-self: flex-end; background: #e9edef; }
.msg.agente .quien { color: var(--agente); }
.msg.humano { align-self: flex-end; background: #d9fdd3; }
.msg.humano .quien { color: var(--verde); }

.redactar { display: flex; gap: .5rem; align-items: flex-end; padding: .5rem .6rem; padding-bottom: max(.5rem, env(safe-area-inset-bottom)); background: #f0f0f0; }
.redactar textarea { margin: 0; resize: none; border-radius: 20px; padding: .6rem .9rem; max-height: 160px; }
.redactar .enviar { border-radius: 20px; }

/* ficha */
.ficha { position: absolute; inset: 0 0 0 auto; width: min(380px, 100%); background: #fff; border-left: 1px solid var(--borde); display: flex; flex-direction: column; z-index: 5; box-shadow: -8px 0 24px rgba(0,0,0,.08); }
.ficha-cabeza { display: flex; align-items: center; justify-content: space-between; padding: .6rem .9rem; padding-top: max(.6rem, env(safe-area-inset-top)); border-bottom: 1px solid var(--borde); }
.ficha-cuerpo { overflow-y: auto; padding: .9rem; flex: 1; }
.ficha-acciones { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .3rem; }

.aviso-flotante { position: fixed; left: 50%; bottom: 5.5rem; transform: translate(-50%, 1rem); background: var(--noche); color: #fff; padding: .7rem 1.1rem; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; }
.aviso-flotante.visible { opacity: 1; transform: translate(-50%, 0); }
.aviso-flotante.mal { background: var(--rojo); }

@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .col-chat { display: none; }
  body.viendo-chat .col-lista { display: none; }
  body.viendo-chat .col-chat { display: flex; }
  .volver { display: inline-block; }
  .msg { max-width: 85%; }
}
