/* Oficina 3D - estilos */
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1200px 800px at 50% 20%, #101822, #0b0f14);
}

#escena {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  color: #e5e7eb;
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

#hud h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0.25em;
  color: #22d3ee;
}

#hud p {
  margin: 4px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
}

#lista-agentes {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  pointer-events: auto;
  z-index: 5;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100% - 32px);
}

.agente-chip {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(15, 20, 28, 0.9);
  color: #e5e7eb;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.agente-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--acento, #22d3ee);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.03);
}

.agente-chip.activo {
  border-color: var(--acento, #22d3ee);
  box-shadow: 0 0 0 1px var(--acento, #22d3ee), 0 0 16px -6px var(--acento, #22d3ee);
}

#panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: 380px;
  max-width: 100%;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: rgba(15, 20, 28, 0.86);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 6;
  padding: 18px;
  box-sizing: border-box;
  color: #e5e7eb;
  transition: transform 200ms ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#panel.oculto {
  transform: translateX(105%);
}

.oculto {
  display: none !important;
}

#btn-cerrar {
  align-self: flex-end;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 16px;
  cursor: pointer;
  pointer-events: auto;
}

#panel-vacio {
  opacity: 0.8;
  font-size: 14px;
}

#panel-contenido {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#agente-nombre {
  margin: 0;
  font-size: 18px;
}

#agente-rol {
  margin: -6px 0 0 0;
  opacity: 0.8;
  font-size: 13px;
}

#agente-estado.chip {
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 12px;
}

#agente-estado.chip.idle {
  color: #22c55e;
  border-color: rgba(34, 197, 94, 0.6);
}

#agente-estado.chip.working {
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.7);
  animation: pulso 1.2s ease-in-out infinite;
}

#agente-estado.chip.error {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.7);
}

@keyframes pulso {
  0% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4);
  }
  70% {
    box-shadow: 0 0 0 6px rgba(245, 158, 11, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(245, 158, 11, 0);
  }
}

label[for="tarea-input"] {
  font-size: 13px;
  opacity: 0.9;
}

#tarea-input {
  width: 100%;
  box-sizing: border-box;
  background: #0f151d;
  border: 1px solid #1f2a37;
  color: #e5e7eb;
  resize: vertical;
  border-radius: 10px;
  padding: 10px;
  font-family: inherit;
  font-size: 13px;
}

.acciones {
  display: flex;
  gap: 8px;
}

#btn-enviar {
  background: #22d3ee;
  color: #041016;
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
}

#btn-reset {
  background: transparent;
  color: #e5e7eb;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}

#btn-enviar:hover:not(:disabled) {
  filter: brightness(1.05);
}

#btn-reset:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.04);
}

#btn-enviar:disabled,
#btn-reset:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#cargando {
  color: #f59e0b;
  font-size: 13px;
}

#cargando::after {
  content: "...";
  display: inline-block;
  width: 1em;
  text-align: left;
  overflow: hidden;
  vertical-align: bottom;
  animation: puntos 1.2s steps(4, end) infinite;
}

@keyframes puntos {
  to {
    width: 2.5em;
  }
}

h3 {
  margin: 6px 0 0 0;
  font-size: 13px;
  opacity: 0.9;
}

#salida {
  white-space: pre-wrap;
  max-height: 38vh;
  overflow: auto;
  background: #070a0f;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  line-height: 1.45;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  margin: 0;
}

#aviso {
  position: fixed;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  background: #111a24;
  color: #e5e7eb;
  border: 1px solid #22d3ee;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  transition: opacity 150ms ease;
}

#aviso.error {
  border-color: #ef4444;
}

button.peligro {
  background: #ef4444; color: #fff; font-weight: 600;
  border: 1px solid transparent; border-radius: 8px;
  padding: .5rem 1rem; cursor: pointer;
}
button.peligro:hover { background: #dc2626; }
button.peligro:disabled { opacity: .6; cursor: progress; }
#btn-borrar { margin-left: auto; }

@media (max-width: 720px) {
  #panel {
    width: 100%;
  }
}

/* ── Móvil ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  /* el panel se vuelve hoja inferior para no tapar la oficina */
  #panel {
    top: auto; bottom: 0; right: 0; left: 0;
    width: 100%; height: auto; max-height: 74vh;
    border-left: none; border-top: 1px solid rgba(255,255,255,.10);
    border-radius: 16px 16px 0 0;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  #panel.oculto { transform: translateY(105%); }

  /* con el panel abierto, los chips estorban: se ocultan */
  body.panel-abierto #lista-agentes { display: none; }

  #btn-cerrar {
    position: absolute; top: 10px; right: 10px;
    width: 42px; height: 42px; font-size: 1.05rem;
  }

  /* objetivos táctiles cómodos */
  .agente-chip, .btn-nuevo, .acciones button, .modal-acciones button {
    min-height: 44px; font-size: .95rem;
  }
  .agente-chip { padding: .5rem .85rem; }
  .btn-nuevo { margin-left: 0; }

  /* 16px evita el zoom automático de iOS al enfocar */
  #tarea-input, .modal-caja input { font-size: 16px; }

  #salida { max-height: 32vh; }

  .modal-caja { width: 94vw; max-height: 88vh; overflow-y: auto; }
  .modal-acciones { flex-direction: column-reverse; }
  .modal-acciones button { width: 100%; }
  #escena canvas { touch-action: none; }
}

/* pantallas muy angostas: chips en dos filas y texto más chico */
@media (max-width: 380px) {
  .agente-chip { font-size: .85rem; padding: .45rem .7rem; }
  .btn-nuevo { font-size: .85rem; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

.agente-chip.apagado { opacity: .45; }
.agente-chip.apagado:hover { opacity: .6; }
#agente-estado.chip.off {
  color: #94a3b8;
  border-color: #334155;
  background: rgba(148, 163, 184, .10);
  animation: none;
}

.btn-nuevo {
  margin-left: auto;
  padding: .45rem .9rem;
  border: 1px dashed rgba(148, 163, 184, .5);
  border-radius: 999px;
  background: transparent;
  color: #cbd5e1;
  font: inherit;
  cursor: pointer;
}
.btn-nuevo:hover { border-color: #22d3ee; color: #22d3ee; }
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 6, 23, .78); backdrop-filter: blur(3px);
}
.modal-caja {
  width: min(420px, 92vw);
  padding: 1.4rem 1.5rem;
  border: 1px solid rgba(148, 163, 184, .25);
  border-radius: 14px;
  background: #0b1220;
  color: #e2e8f0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.modal-caja h3 { margin: 0 0 .3rem; font-size: 1.1rem; }
.modal-ayuda { margin: 0 0 1rem; font-size: .82rem; color: #94a3b8; }
.modal-caja label { display: block; margin: .7rem 0 .25rem; font-size: .8rem; color: #94a3b8; }
.modal-caja input {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, .3);
  background: #0f172a; color: #e2e8f0; font: inherit;
}
.modal-caja input:focus { outline: none; border-color: #22d3ee; }
.nuevo-error { min-height: 1.1rem; margin: .6rem 0 0; font-size: .82rem; color: #f87171; }
.modal-acciones { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .9rem; }
.modal-acciones button {
  padding: .5rem 1rem; border-radius: 8px; border: 1px solid transparent;
  font: inherit; cursor: pointer;
}
#nuevo-crear { background: #22d3ee; color: #06202a; font-weight: 600; }
#nuevo-crear:disabled { opacity: .55; cursor: progress; }
.boton-secundario { background: transparent; border-color: rgba(148, 163, 184, .4); color: #cbd5e1; }

/* con el panel abierto, los chips se recorren para no quedar debajo */
body.panel-abierto #lista-agentes { left: calc(50% - 190px); max-width: calc(100% - 412px); }
@media (max-width: 720px) { body.panel-abierto #lista-agentes { left: 50%; max-width: calc(100% - 32px); } }

/* ── Móvil: chips en una sola fila deslizable ───────────── */
@media (max-width: 720px) {
  #lista-agentes {
    left: 0; right: 0; bottom: 10px; transform: none;
    width: 100%; max-width: 100%;
    padding: 0 12px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #lista-agentes::-webkit-scrollbar { display: none; }
  #lista-agentes > * { flex: 0 0 auto; }
}

/* Botón flotante de alta en móvil */
@media (max-width: 720px) {
  #btn-nuevo {
    position: fixed;
    right: 16px;
    bottom: 78px;
    width: 54px;
    height: 54px;
    padding: 0;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    line-height: 1;
    background: #22d3ee;
    color: #06202a;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .5);
    z-index: 7;
  }
  #btn-nuevo:hover { color: #06202a; }
  body.panel-abierto #btn-nuevo { display: none; }
}

/* tres botones en el panel: que el de borrar baje a su renglón si no cabe */
.acciones { flex-wrap: wrap; }
#btn-borrar { white-space: nowrap; flex: 0 0 auto; margin-left: auto; }

#barra-oficinas {
  position: fixed; top: 74px; left: 16px; z-index: 5;
  display: flex; gap: 6px; align-items: center;
  max-width: calc(100% - 32px);
}
.oficina-tab {
  padding: .38rem .85rem; border-radius: 999px;
  border: 1px solid rgba(148,163,184,.35);
  background: rgba(15,20,28,.75); color: #cbd5e1;
  font: inherit; font-size: .85rem; cursor: pointer;
  white-space: nowrap;
}
.oficina-tab.activa { border-color: #22d3ee; color: #22d3ee; background: rgba(34,211,238,.12); }
.oficina-tab .cuenta { opacity: .6; margin-left: .35rem; font-size: .78rem; }
#btn-nueva-oficina {
  padding: .38rem .75rem; border-radius: 999px;
  border: 1px dashed rgba(148,163,184,.5); background: transparent;
  color: #cbd5e1; font: inherit; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
#agente-oficina {
  width: 100%; padding: .5rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148,163,184,.3);
  background: #0f172a; color: #e2e8f0; font: inherit;
}
@media (max-width: 720px) {
  #barra-oficinas {
    top: 64px; left: 0; right: 0; max-width: 100%;
    padding: 0 12px; overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  #barra-oficinas::-webkit-scrollbar { display: none; }
  #barra-oficinas > * { flex: 0 0 auto; }
}

#oficina-vacia {
  position: fixed;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  z-index: 4;
  text-align: center;
  padding: 1.2rem 1.6rem;
  border: 1px dashed rgba(148, 163, 184, .35);
  border-radius: 14px;
  background: rgba(11, 18, 32, .72);
  color: #cbd5e1;
  max-width: min(420px, 88vw);
  pointer-events: none;
}
#oficina-vacia p { margin: 0 0 .35rem; font-size: 1.05rem; font-weight: 600; color: #e2e8f0; }
#oficina-vacia span { font-size: .86rem; color: #94a3b8; }
@media (max-width: 720px) {
  #oficina-vacia { top: 40%; padding: 1rem 1.2rem; }
  #oficina-vacia p { font-size: .98rem; }
  #oficina-vacia span { font-size: .8rem; }
}

/* ── Login ─────────────────────────────────────────────── */
.login-fondo {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 30%, #0f1c2e, #05080e 70%);
}
.login-fondo.oculto { display: none; }
.login-caja {
  width: min(360px, 90vw); padding: 1.6rem 1.5rem; border-radius: 16px;
  border: 1px solid rgba(148,163,184,.22); background: #0b1220; color: #e2e8f0;
  box-shadow: 0 30px 70px rgba(0,0,0,.6);
}
.login-caja h2 { margin: 0 0 .2rem; font-size: 1.25rem; }
.login-caja p { margin: 0 0 1rem; font-size: .84rem; color: #94a3b8; }
.login-caja label { display: block; margin: .7rem 0 .25rem; font-size: .8rem; color: #94a3b8; }
.login-caja input {
  width: 100%; padding: .6rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148,163,184,.3); background: #0f172a; color: #e2e8f0;
  font: inherit; font-size: 16px;
}
.login-caja input:focus { outline: none; border-color: #22d3ee; }
#login-entrar {
  width: 100%; margin-top: 1rem; padding: .7rem 1rem; border: none; border-radius: 10px;
  background: #22d3ee; color: #06202a; font: inherit; font-weight: 700; cursor: pointer;
}
#login-entrar:disabled { opacity: .6; cursor: progress; }
#sesion-caja { position: absolute; top: 18px; right: 18px; display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: #94a3b8; }
#btn-salir, #btn-config {
  padding: .3rem .7rem; border-radius: 999px; border: 1px solid rgba(148,163,184,.35);
  background: transparent; color: #cbd5e1; font: inherit; font-size: .78rem; cursor: pointer;
}
#btn-config { width: 34px; height: 34px; padding: 0; font-size: 1rem; }

/* ── Configuración ─────────────────────────────────────── */
.modal-config { width: min(560px, 94vw); max-height: 88vh; overflow-y: auto; position: relative; }
.config-x {
  position: absolute; top: 10px; right: 10px; width: 32px; height: 32px;
  border-radius: 50%; border: none; background: rgba(148,163,184,.15);
  color: #cbd5e1; font: inherit; cursor: pointer;
}
.config-tabs { display: flex; gap: 6px; margin: .8rem 0 1rem; }
.config-tab {
  flex: 1; padding: .5rem .4rem; border-radius: 9px; cursor: pointer;
  border: 1px solid rgba(148,163,184,.25); background: transparent;
  color: #cbd5e1; font: inherit; font-size: .85rem;
}
.config-tab.activa { border-color: #22d3ee; color: #22d3ee; background: rgba(34,211,238,.12); }
.config-panel { display: block; }
.config-form { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.config-form input, .config-form select {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148,163,184,.3); background: #0f172a; color: #e2e8f0;
  font: inherit; font-size: 16px;
}
.config-form button {
  padding: .6rem 1rem; border: none; border-radius: 9px;
  background: #22d3ee; color: #06202a; font: inherit; font-weight: 600; cursor: pointer;
}
.config-check { display: flex; align-items: center; gap: .45rem; font-size: .85rem; color: #cbd5e1; }
.config-check input { width: auto; }
.config-etiqueta { font-size: .75rem; color: #94a3b8; margin-top: .3rem; }
.config-oficinas { display: flex; flex-wrap: wrap; gap: .4rem; }
.config-oficinas label {
  display: flex; align-items: center; gap: .3rem; font-size: .8rem; color: #cbd5e1;
  border: 1px solid rgba(148,163,184,.3); border-radius: 999px; padding: .25rem .6rem;
}
.config-oficinas input { width: auto; }
.config-lista { display: flex; flex-direction: column; gap: .5rem; }
.config-item {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .6rem .7rem; border-radius: 10px;
  border: 1px solid rgba(148,163,184,.18); background: rgba(15,23,42,.7);
  font-size: .85rem; color: #e2e8f0;
}
.config-item .quien { flex: 1 1 40%; min-width: 120px; }
.config-item .detalle { flex-basis: 100%; font-size: .75rem; color: #94a3b8; }
.config-item input {
  flex: 1 1 50%; padding: .35rem .55rem; border-radius: 7px;
  border: 1px solid rgba(148,163,184,.3); background: #0f172a; color: #e2e8f0;
  font: inherit; font-size: 16px;
}
.config-item button {
  padding: .35rem .7rem; border-radius: 7px; font: inherit; font-size: .78rem; cursor: pointer;
  border: 1px solid rgba(148,163,184,.35); background: transparent; color: #cbd5e1;
}
.config-item button.peligro { background: #ef4444; border-color: transparent; color: #fff; }
@media (max-width: 720px) {
  #sesion-caja { top: 12px; right: 12px; }
  #sesion-caja span { display: none; }
  .modal-config { width: 96vw; max-height: 92vh; padding: 1rem; }
  .config-tab { font-size: .8rem; padding: .45rem .2rem; }
}

/* el bloque de sesión vive arriba a la derecha: el header no debe invadirlo */
#hud { padding-right: 210px; }
#sesion-caja { pointer-events: auto; }
@media (max-width: 720px) {
  #hud { padding-right: 120px; }
}

#editar-instrucciones {
  width: 100%; padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid rgba(148,163,184,.3); background: #0f172a; color: #e2e8f0;
  font: inherit; font-size: 15px; line-height: 1.45; resize: vertical; min-height: 96px;
}
#editar-instrucciones::placeholder { color: #64748b; }

/* ── Panel como chat ───────────────────────────────────── */
#panel { padding: 0; }
#panel-contenido {
  height: 100%;
  gap: 0;
  display: flex;
  flex-direction: column;
}
.chat-cabecera {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
  flex: 0 0 auto;
}
.chat-quien { flex: 1; min-width: 0; }
.chat-cabecera h2 {
  margin: 0;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-cabecera p {
  margin: .1rem 0 0;
  font-size: .74rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#btn-cerrar {
  position: static;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(148,163,184,.15);
  color: #cbd5e1;
  font: inherit;
  cursor: pointer;
  flex: 0 0 auto;
}
.chat-mensajes {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.burbuja {
  max-width: 86%;
  padding: .6rem .8rem;
  border-radius: 14px;
  font-size: .88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
}
.burbuja .hora {
  display: block;
  margin-top: .3rem;
  font-size: .65rem;
  opacity: .55;
}
.burbuja.usuario {
  align-self: flex-end;
  background: #22d3ee;
  color: #06202a;
  border-bottom-right-radius: 4px;
}
.burbuja.agente {
  align-self: flex-start;
  background: rgba(148,163,184,.14);
  color: #e2e8f0;
  border-bottom-left-radius: 4px;
}
.burbuja.sistema {
  align-self: center;
  background: rgba(239,68,68,.12);
  color: #fca5a5;
  font-size: .78rem;
  max-width: 94%;
  text-align: center;
}
.chat-vacio {
  margin: auto;
  text-align: center;
  color: #64748b;
  font-size: .85rem;
  padding: 1.5rem;
}
.escribiendo {
  align-self: flex-start;
  display: flex;
  gap: .25rem;
  padding: .7rem .9rem;
  background: rgba(148,163,184,.14);
  border-radius: 14px;
}
.escribiendo i {
  width: 6px; height: 6px; border-radius: 50%;
  background: #94a3b8; animation: parpadeo 1.2s infinite;
}
.escribiendo i:nth-child(2) { animation-delay: .2s; }
.escribiendo i:nth-child(3) { animation-delay: .4s; }
@keyframes parpadeo { 0%,60%,100% { opacity: .25; } 30% { opacity: 1; } }
.chat-compositor {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: .5rem;
  padding: .7rem .8rem;
  border-top: 1px solid rgba(255,255,255,.08);
}
#tarea-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: .6rem .8rem;
  border-radius: 18px;
  border: 1px solid rgba(148,163,184,.3);
  background: #0f172a;
  color: #e2e8f0;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
}
#tarea-input:focus { outline: none; border-color: #22d3ee; }
#btn-enviar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: none;
  border-radius: 50%;
  background: #22d3ee;
  color: #06202a;
  font-size: 1.1rem;
  cursor: pointer;
}
#btn-enviar:disabled { opacity: .45; cursor: not-allowed; }
.chat-pie {
  flex: 0 0 auto;
  display: flex;
  gap: .4rem;
  padding: .55rem .8rem .8rem;
  border-top: 1px solid rgba(255,255,255,.05);
}
.chat-pie select {
  flex: 1;
  min-width: 0;
  padding: .4rem .5rem;
  border-radius: 8px;
  border: 1px solid rgba(148,163,184,.25);
  background: #0f172a;
  color: #cbd5e1;
  font: inherit;
  font-size: .8rem;
}
.chat-pie button {
  padding: .4rem .65rem;
  border-radius: 8px;
  border: 1px solid rgba(148,163,184,.25);
  background: transparent;
  color: #cbd5e1;
  font: inherit;
  font-size: .78rem;
  cursor: pointer;
  white-space: nowrap;
}
.chat-pie button.peligro { background: #ef4444; border-color: transparent; color: #fff; }
@media (max-width: 720px) {
  #panel { height: 78vh; top: auto; bottom: 0; width: 100%; border-left: none; border-top-left-radius: 18px; border-top-right-radius: 18px; }
  #panel-contenido { padding-bottom: env(safe-area-inset-bottom, 0); }
  .burbuja { max-width: 92%; font-size: .9rem; }
  .chat-pie button { padding: .45rem .55rem; font-size: .75rem; }
}

.chat-pie { flex-direction: column; gap: .45rem; }
.chat-pie-fila { display: flex; gap: .4rem; }
.chat-pie-fila select { flex: 1; min-width: 0; }
.chat-pie-fila button { flex: 1; }
#agente-modelo { color: #22d3ee; }

/* móvil: sin subtítulo para que no choquen las pestañas de oficina */
@media (max-width: 720px) {
  #hud p { display: none; }
  #barra-oficinas { top: 54px; }
  #hud { padding-right: 130px; }
}

/* aviso de proveedor caído dentro del chat */
.chat-aviso {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 0 .8rem .5rem;
  padding: .55rem .7rem;
  border-radius: 10px;
  background: rgba(239,68,68,.14);
  border: 1px solid rgba(239,68,68,.35);
  color: #fecaca;
  font-size: .78rem;
  line-height: 1.35;
}
.chat-aviso span { flex: 1; min-width: 0; }
.chat-aviso button {
  flex: 0 0 auto;
  padding: .35rem .6rem;
  border: none;
  border-radius: 8px;
  background: #22d3ee;
  color: #06202a;
  font: inherit;
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* ── Escritorio: chat amplio a la IZQUIERDA, oficina a la derecha ── */
@media (min-width: 721px) {
  #panel {
    left: 0;
    right: auto;
    width: clamp(420px, 46vw, 720px);
    border-left: none;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.35);
  }
  body.panel-abierto #hud { left: calc(clamp(420px, 46vw, 720px) + 18px); padding-right: 210px; }
  body.panel-abierto #barra-oficinas { left: calc(clamp(420px, 46vw, 720px) + 18px); }
  body.panel-abierto #lista-agentes {
    left: calc(50% + clamp(210px, 23vw, 360px));
    max-width: calc(100% - clamp(420px, 46vw, 720px) - 36px);
  }
  #panel .chat-mensajes { padding: 1.1rem 1.2rem; }
  #panel .chat-compositor { padding: .8rem 1rem; }
  #panel .chat-pie { padding: .6rem 1rem .9rem; }
}

/* el chat nunca debe empujar el pie fuera de la pantalla */
#panel-contenido { overflow: hidden; }
.chat-mensajes { min-height: 0; }
@media (max-width: 720px) {
  #panel { height: 80vh; }
  .chat-pie { padding-bottom: calc(.8rem + env(safe-area-inset-bottom, 0px)); }
}

/* ── Ajuste final: chat más ancho (60%), escritorio más chico ── */
@media (min-width: 721px) {
  :root { --panel-ancho: clamp(460px, 60vw, 980px); }
  #panel { width: var(--panel-ancho); }
  body.panel-abierto #hud { left: calc(var(--panel-ancho) + 18px); }
  body.panel-abierto #barra-oficinas { left: calc(var(--panel-ancho) + 18px); }
  body.panel-abierto #lista-agentes {
    left: calc(50% + clamp(230px, 30vw, 490px));
    max-width: calc(100% - var(--panel-ancho) - 36px);
  }
  #panel .burbuja { max-width: 74%; }
}

/* ── Nuevo chat y sesiones ─────────────────────────────── */
#panel-contenido { position: relative; }
.icono-chat {
  width: 32px; height: 32px; flex: 0 0 auto;
  border-radius: 50%; border: none;
  background: rgba(148,163,184,.15); color: #cbd5e1;
  font: inherit; font-size: .95rem; line-height: 1;
  cursor: pointer;
}
.icono-chat:hover { background: rgba(34,211,238,.25); color: #22d3ee; }
.panel-sesiones {
  position: absolute; top: 56px; left: 8px; right: 8px;
  max-height: 60%; overflow-y: auto;
  background: #0b1220; border: 1px solid rgba(148,163,184,.25);
  border-radius: 12px; padding: .4rem; z-index: 20;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
}
.sesion-item {
  display: flex; align-items: center; gap: .4rem;
  padding: .5rem .55rem; border-radius: 8px; cursor: pointer;
}
.sesion-item:hover { background: rgba(148,163,184,.12); }
.sesion-item.activa { background: rgba(34,211,238,.14); }
.sesion-texto { flex: 1; min-width: 0; }
.sesion-titulo {
  font-size: .82rem; color: #e2e8f0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sesion-meta { font-size: .68rem; color: #64748b; }
.sesion-borrar {
  flex: 0 0 auto; border: none; background: transparent;
  color: #f87171; font-size: .95rem; cursor: pointer; padding: .2rem .35rem;
}
.sesion-vacia { padding: .8rem; text-align: center; color: #64748b; font-size: .8rem; }

/* ── Chat manda: 74% del ancho, oficina al 26% ─────────── */
@media (min-width: 721px) {
  :root { --panel-ancho: clamp(520px, 74vw, 1180px); }
  #panel { width: var(--panel-ancho); }
  body.panel-abierto #hud { left: calc(var(--panel-ancho) + 14px); padding-right: 150px; }
  body.panel-abierto #barra-oficinas { left: calc(var(--panel-ancho) + 14px); }
  body.panel-abierto #lista-agentes {
    left: calc(50% + clamp(260px, 37vw, 590px));
    max-width: calc(100% - var(--panel-ancho) - 28px);
  }
  #panel .burbuja { max-width: 72%; font-size: .95rem; }
  #panel .chat-mensajes { padding: 1.2rem 1.4rem; }
}

/* ── Menú de opciones del chat ─────────────────────────── */
.chat-pie { position: relative; }
.chat-pie-fila { flex-wrap: wrap; }
#btn-opciones { margin-left: auto; border-radius: 10px; }
.menu-opciones {
  position: absolute; right: .8rem; bottom: 100%; margin-bottom: .3rem;
  min-width: 232px; display: flex; flex-direction: column;
  background: #0b1220; border: 1px solid rgba(148,163,184,.25);
  border-radius: 12px; padding: .35rem; z-index: 30;
  box-shadow: 0 18px 40px rgba(0,0,0,.55);
}
.menu-opciones button {
  text-align: left; border: none; background: transparent; color: #e2e8f0;
  font: inherit; font-size: .84rem; padding: .55rem .65rem; border-radius: 8px;
  cursor: pointer; white-space: nowrap;
}
.menu-opciones button:hover { background: rgba(148,163,184,.14); }
.menu-opciones button.peligro { color: #fca5a5; }
.menu-opciones button:disabled { opacity: .4; cursor: not-allowed; }
#menu-opciones.oculto, #acciones-ocultas { display: none; }
@media (max-width: 720px) {
  .chat-pie-fila select { flex: 1 1 40%; }
  #btn-opciones { flex: 0 0 auto; }
}

/* ── Afinación del modo chat ancho ─────────────────────── */
#btn-opciones { flex: 0 0 38px; width: 38px; height: 38px; border-radius: 10px; }
@media (min-width: 721px) {
  body.panel-abierto #hud { padding-right: 0; max-width: calc(100% - var(--panel-ancho) - 20px); }
  body.panel-abierto #hud h1, body.panel-abierto #hud h2 { font-size: .95rem; }
  body.panel-abierto #hud p { display: none; }
  body.panel-abierto #sesion-caja { gap: .2rem; }
  body.panel-abierto #sesion-caja button, body.panel-abierto #sesion-caja span { font-size: .7rem; padding: .25rem .45rem; }
  #barra-oficinas { max-width: calc(100% - var(--panel-ancho) - 20px); overflow-x: auto; scrollbar-width: none; }
  #barra-oficinas::-webkit-scrollbar { display: none; }
  #lista-agentes { flex-wrap: wrap; justify-content: center; gap: 6px; }
  #lista-agentes .agente-chip { font-size: .72rem; padding: .3rem .55rem; }
}

/* botón de detener mientras trabaja */
#btn-enviar.detener { background: #ef4444; color: #fff; font-size: .95rem; }
#btn-enviar.detener:hover { background: #dc2626; }
