:root {
  --fondo: #f3f4f1;
  --panel: #ffffff;
  --tinta: #1b2420;
  --suave: #5b6762;
  --linea: #dde1dc;
  --acento: #0f6e55;
  --acento-hover: #0b5a45;
  --acento-claro: #e1efe8;
  --entrante: #ffffff;
  --saliente: #dcefe5;
  --nota: #fff2c7;
  --mal: #b42318;
  --radio: 10px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--tinta); background: var(--fondo); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--acento); outline-offset: 2px; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; background: var(--fondo); padding: .1em .35em; border-radius: 4px; word-break: break-all; }

.ico { display: inline-flex; width: 18px; height: 18px; }
.ico svg { width: 100%; height: 100%; }
.ico.mini { width: 14px; height: 14px; vertical-align: -2px; }

.boton { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--linea); background: var(--panel); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; min-height: 36px; }
.boton:hover { border-color: #b9c2bc; }
.boton:disabled { opacity: .55; cursor: default; }
.boton.principal { background: var(--acento); border-color: var(--acento); color: #fff; }
.boton.principal:hover { background: var(--acento-hover); }
.boton.fantasma { border-color: transparent; background: transparent; }
.boton.fantasma:hover { background: rgba(0,0,0,.05); }
.boton.icono-solo { padding: .4rem; min-width: 36px; justify-content: center; }

label { display: grid; gap: .3rem; font-size: .9rem; color: var(--suave); }
input, select, textarea { border: 1px solid var(--linea); border-radius: 8px; padding: .5rem .65rem; background: #fff; color: var(--tinta); min-height: 38px; }
textarea { resize: vertical; }
.casilla { display: flex; align-items: center; gap: .5rem; color: var(--tinta); }
.casilla input { min-height: auto; }
fieldset { border: 1px solid var(--linea); border-radius: 8px; padding: .5rem .8rem; display: grid; gap: .3rem; }
legend { font-size: .9rem; color: var(--suave); padding: 0 .3rem; }
.error { color: var(--mal); margin: 0; min-height: 1.2em; font-size: .9rem; }
.ayuda { color: var(--suave); font-size: .9rem; margin: 0 0 .75rem; }

/* Entrar */
.pantalla-login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.tarjeta-login { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--linea); border-radius: 14px; padding: 1.75rem; display: grid; gap: 1rem; }
.tarjeta-login h1 { margin: 0; }
.marca { display: flex; align-items: center; gap: .6rem; font-weight: 600; }

/* Estructura */
.marco { height: 100%; display: flex; flex-direction: column; }
.barra { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 1rem; background: var(--panel); border-bottom: 1px solid var(--linea); }
.barra-derecha { display: flex; align-items: center; gap: .5rem; }
.quien { color: var(--suave); font-size: .9rem; }
.cuerpo { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 360px) 1fr; }

/* Lista */
.lista { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--linea); }
.lista-cabeza { padding: .75rem; display: grid; gap: .6rem; border-bottom: 1px solid var(--linea); }
.pestanas { display: flex; gap: .25rem; overflow-x: auto; }
.pestana { border: 0; background: transparent; padding: .35rem .6rem; border-radius: 6px; cursor: pointer; color: var(--suave); white-space: nowrap; }
.pestana[aria-selected="true"] { background: var(--acento-claro); color: var(--acento); font-weight: 600; }
.buscar-fila { display: flex; gap: .4rem; }
.buscar-fila input { flex: 1; min-width: 0; }
.conversaciones { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.fila { width: 100%; display: flex; gap: .7rem; padding: .7rem .8rem; border: 0; border-bottom: 1px solid #eef0ec; background: transparent; text-align: left; cursor: pointer; }
.fila:hover { background: #f7f8f6; }
.fila.activa { background: var(--acento-claro); }
.avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; background: #d7e3dc; color: #2f4a40; display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.fila-texto { flex: 1; min-width: 0; display: grid; gap: .1rem; }
.fila-arriba, .fila-abajo { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }
.nombre, .resumen { min-width: 0; }
.hueco-filtro { display: contents; }
.nombre { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hora { color: var(--suave); font-size: .8rem; flex: none; }
.resumen { color: var(--suave); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sin-leer .resumen { color: var(--tinta); }
.sin-leer .hora { color: var(--acento); font-weight: 600; }
.globo { flex: none; background: var(--acento); color: #fff; border-radius: 999px; min-width: 20px; padding: 0 6px; font-size: .75rem; text-align: center; line-height: 20px; }
.fila-meta { display: flex; gap: .3rem; flex-wrap: wrap; }
.fila-meta:empty { display: none; }
.chapa { font-size: .72rem; padding: .05rem .45rem; border-radius: 999px; background: var(--acento-claro); color: var(--acento); }
.chapa.suave { background: #eceef0; color: #4a5560; }
.chapa.gris { background: #f1efe9; color: #7a6a3e; }
.lista-vacia { padding: 2rem 1rem; color: var(--suave); text-align: center; }

/* Etiquetas */
.etiqueta { font-size: .72rem; padding: .05rem .5rem; border-radius: 4px; border-left: 3px solid; background: #f3f4f2; color: #2c3530; white-space: nowrap; }
.etq-verde { border-color: #1f8a5b; background: #e4f3ea; }
.etq-azul { border-color: #2563a8; background: #e3edf8; }
.etq-morado { border-color: #6d4bb0; background: #eee8f8; }
.etq-rosa { border-color: #b63f7f; background: #f8e6ef; }
.etq-rojo { border-color: #b42318; background: #fbe6e4; }
.etq-naranja { border-color: #c2620e; background: #fcecdc; }
.etq-amarillo { border-color: #a38200; background: #fbf3cf; }
.etq-gris { border-color: #67736e; background: #eceeec; }
.filtro-etiqueta { max-width: 120px; }
.tira-etiquetas { display: flex; gap: .35rem; flex-wrap: wrap; padding: .4rem .9rem; background: var(--panel); border-bottom: 1px solid var(--linea); }
.fila-telefono { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: .6rem; }
.fila-telefono select, .fila-telefono input { width: 100%; min-width: 0; }
@media (max-width: 480px) { .fila-telefono { grid-template-columns: 1fr; } }
.lista-casillas { display: grid; gap: .45rem; max-height: 260px; overflow-y: auto; }
.fila-crear { display: flex; gap: .4rem; flex-wrap: wrap; }
.fila-crear input { flex: 1; min-width: 160px; }
.ayuda-linea { color: var(--suave); font-size: .85rem; }

/* Chat */
.chat { display: flex; flex-direction: column; min-height: 0; background: #ebece7; }
.chat-vacio { margin: auto; max-width: 360px; text-align: center; color: var(--suave); padding: 1rem; }
.chat-vacio .grande { font-size: 1.1rem; color: var(--tinta); }
.chat-cabeza { display: flex; align-items: center; gap: .7rem; padding: .55rem .9rem; background: var(--panel); border-bottom: 1px solid var(--linea); flex-wrap: wrap; }
.chat-quien { flex: 1; min-width: 140px; display: grid; }
.nombre-editable { border: 0; background: none; padding: 0; text-align: left; font-weight: 600; cursor: pointer; }
.nombre-editable:hover { text-decoration: underline; }
.tel { color: var(--suave); font-size: .85rem; }
.chat-acciones { display: flex; gap: .4rem; flex-wrap: wrap; }
.chat-acciones select { min-height: 36px; padding: .3rem .5rem; }
.nota-contacto { margin: 0; padding: .45rem .9rem; background: var(--nota); font-size: .88rem; border-bottom: 1px solid #efdfa8; white-space: pre-wrap; }
.mensajes { list-style: none; margin: 0; padding: 1rem clamp(.75rem, 4vw, 3rem); overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: .35rem; }
.separador-dia { align-self: center; margin: .6rem 0; }
.separador-dia span { background: rgba(255,255,255,.8); color: var(--suave); font-size: .78rem; padding: .15rem .6rem; border-radius: 6px; }
.burbuja { max-width: min(620px, 82%); padding: .45rem .7rem .3rem; border-radius: 10px; background: var(--entrante); box-shadow: 0 1px 0 rgba(0,0,0,.06); }
.burbuja p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.burbuja.entrante { align-self: flex-start; border-top-left-radius: 3px; }
.burbuja.saliente { align-self: flex-end; background: var(--saliente); border-top-right-radius: 3px; }
.burbuja.nota { align-self: center; background: var(--nota); max-width: min(560px, 90%); border: 1px dashed #d8bf6a; }
.burbuja img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin-bottom: .3rem; }
.burbuja audio { max-width: 100%; }
.adjunto { display: inline-block; margin-bottom: .25rem; }
.pie { display: flex; justify-content: flex-end; align-items: center; gap: .25rem; color: var(--suave); font-size: .72rem; margin-top: .15rem; }
.estado.leido { color: #1f7ac2; }
.estado.fallido { color: var(--mal); }
.fallo { color: var(--mal); font-size: .82rem; }

.composer { background: var(--panel); border-top: 1px solid var(--linea); padding: .6rem .75rem; position: relative; }
.composer.nota { background: #fffaf0; }
.composer-fila { display: flex; gap: .5rem; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 40px; max-height: 180px; resize: none; }
.composer .enviar { min-width: 44px; min-height: 40px; justify-content: center; }
.conmutador.activo { background: var(--nota); border-color: #d8bf6a; }
.composer.cerrado p { margin: 0 0 .6rem; font-size: .9rem; }
.composer-botones { display: flex; gap: .5rem; flex-wrap: wrap; }
.ventana { margin: .35rem 0 0; color: var(--suave); font-size: .78rem; }
.sugerencias { position: absolute; bottom: 100%; left: .75rem; right: .75rem; list-style: none; margin: 0; padding: .25rem; background: #fff; border: 1px solid var(--linea); border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.sugerencias button { width: 100%; text-align: left; border: 0; background: none; padding: .45rem .5rem; border-radius: 6px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sugerencias button:hover, .sugerencias button:focus-visible { background: var(--acento-claro); }

/* Diálogos */
.dialogo { border: 0; border-radius: 14px; padding: 0; width: min(480px, calc(100% - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.dialogo::backdrop { background: rgba(20,30,25,.35); }
.dialogo form { padding: 1.25rem; display: grid; gap: .8rem; }
.dialogo h2 { margin: 0; }
.dialogo-botones { display: flex; justify-content: flex-end; gap: .5rem; }
.variables { display: grid; gap: .6rem; }
.vista-plantilla { margin: 0; padding: .6rem .75rem; background: var(--saliente); border-radius: 8px; white-space: pre-wrap; }

/* Ajustes */
.ajustes { overflow-y: auto; padding: 1.25rem 16px 3rem; width: min(860px, 100%); margin: 0 auto; }
.bloque { background: var(--panel); border: 1px solid var(--linea); border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; display: grid; gap: .6rem; justify-items: start; }
.bloque > * { max-width: 100%; }
.tabla { list-style: none; margin: 0; padding: 0; width: 100%; }
.tabla li { padding: .65rem 0; border-top: 1px solid #eef0ec; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem 1rem; }
.tabla li > .datos { flex-basis: 100%; }
.tabla li.inactivo, tr.inactivo { opacity: .55; }
.datos { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: 0; font-size: .88rem; }
.datos dt { color: var(--suave); }
.datos dd { margin: 0; min-width: 0; }
.acciones { display: flex; gap: .4rem; flex-wrap: wrap; }
.formulario { display: grid; gap: .7rem; width: min(440px, 100%); }
h3 { font-size: 1rem; margin: .5rem 0 .25rem; }
.enlaces { width: 100%; }
.uso { border-collapse: collapse; width: 100%; font-size: .9rem; }
.uso th, .uso td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid #eef0ec; }
.uso th { color: var(--suave); font-weight: 500; }

#aviso { position: fixed; bottom: 16px; left: 50%; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--tinta); color: #fff; padding: .6rem 1rem; border-radius: 8px; max-width: calc(100% - 32px); transition: opacity .2s, transform .2s; z-index: 10; }
#aviso.visible { opacity: 1; transform: translate(-50%, 0); }
#aviso.mal { background: var(--mal); }

.solo-movil { display: none; }
@media (max-width: 760px) {
  .cuerpo { grid-template-columns: 1fr; }
  .cuerpo.con-chat .lista { display: none; }
  .cuerpo:not(.con-chat) .chat { display: none; }
  .solo-movil { display: inline-flex; }
  .quien { display: none; }
  .chat-acciones { width: 100%; }
  .chat-acciones select { flex: 1; min-width: 0; }
  .burbuja { max-width: 90%; }
}
@media (prefers-reduced-motion: reduce) { #aviso { transition: none; } }
