@font-face { font-family: "JoyNode"; src: url("/fuentes/JoyNodeFont-Light.woff") format("woff"); font-weight: 300; font-display: swap; }
@font-face { font-family: "JoyNode"; src: url("/fuentes/JoyNodeFont-Regular.woff") format("woff"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JoyNode"; src: url("/fuentes/JoyNodeFont-Bold.woff") format("woff"); font-weight: 600; font-display: swap; }

:root {
  --noche: #120c22;
  --noche2: #2b2048;
  --lila: #b9a6ff;
  --lila2: #8e72d8;
  --rosa: #f3b8e4;
  --texto: #f5f1ff;
  --tenue: #c9bfe6;
  --vidrio: rgba(255, 255, 255, 0.08);
  --orilla: rgba(255, 255, 255, 0.18);
  --ok: #8be3b5;
  --mal: #ff9aa8;
  --radio: 18px;
  --seguro-abajo: env(safe-area-inset-bottom, 0px);
  color-scheme: only light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color: var(--texto);
  background: linear-gradient(180deg, var(--noche) 0%, var(--noche2) 100%) fixed;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Cielo con nubes que pasan despacio */
.cielo { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: url("/cielo.webp") center / cover no-repeat; opacity: 0.55; }
.nube { position: absolute; width: 70vw; max-width: 720px; opacity: 0.35; will-change: transform; }
.n1 { top: 8%; left: -40%; animation: viento 90s linear infinite; }
.n2 { top: 55%; left: -60%; animation: viento 130s linear infinite 20s; }
@keyframes viento { to { transform: translateX(200vw); } }

.marca { font-family: "JoyNode", sans-serif; font-size: 34px; margin: 0 0 6px; letter-spacing: 0.01em; }
.marca .joy { font-weight: 300; }
.marca .node { font-weight: 600; }
.marca.chica { font-size: 22px; margin: 0; }
.marca .producto { font-family: inherit; font-weight: 400; color: var(--lila); font-size: 0.75em; margin-left: 6px; }

.cristal {
  background: var(--vidrio);
  border: 1px solid var(--orilla);
  border-radius: var(--radio);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 10px 40px rgba(10, 5, 30, 0.35);
}

h1, h2, h3 { font-family: "JoyNode", sans-serif; font-weight: 600; margin: 0 0 8px; }
h2 { font-size: 26px; }
h3 { font-size: 18px; }
.sub { color: var(--tenue); margin: 0 0 16px; }

.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 999px; cursor: pointer;
  background: rgba(255, 255, 255, 0.1); border: 1px solid var(--orilla);
  transition: transform 0.15s ease, background 0.2s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primario { background: linear-gradient(135deg, var(--lila), var(--lila2)); color: #1a1030; font-weight: 600; border: 0; }
.btn.peligro { border-color: rgba(255, 154, 168, 0.5); color: var(--mal); }
.btn.icono { width: 44px; padding: 0; font-size: 22px; }

input, textarea, select {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 12px;
  background: rgba(10, 5, 30, 0.45); border: 1px solid var(--orilla); outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--lila); box-shadow: 0 0 0 3px rgba(185, 166, 255, 0.25); }
input[type="checkbox"] { width: 22px; min-height: 22px; height: 22px; accent-color: var(--lila); flex: none; padding: 0; }
label { display: block; font-size: 14px; color: var(--tenue); }
textarea { resize: vertical; }

/* Inicio de sesion */
.login { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.tarjeta-login { width: min(420px, 100%); padding: 28px 24px; display: grid; gap: 12px; animation: entra 0.6s ease both; }
.tarjeta-login h1 { font-size: 24px; }
.error { color: var(--mal); min-height: 1.2em; margin: 0; font-size: 14px; }

@keyframes entra { from { opacity: 0; transform: translateY(14px); } }

/* App */
.app { min-height: 100svh; padding-bottom: calc(80px + var(--seguro-abajo)); }
.barra {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: rgba(18, 12, 34, 0.75);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 1px solid var(--orilla);
}
.seccion { padding: 16px; max-width: 980px; margin: 0 auto; animation: entra 0.4s ease both; }

.interruptor {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--orilla); background: rgba(255, 255, 255, 0.06); cursor: pointer; font-size: 14px;
}
.interruptor .punto { width: 10px; height: 10px; border-radius: 50%; background: var(--mal); box-shadow: 0 0 0 4px rgba(255, 154, 168, 0.15); }
.interruptor[aria-pressed="true"] .punto { background: var(--ok); box-shadow: 0 0 0 4px rgba(139, 227, 181, 0.18); animation: late 2.4s ease-in-out infinite; }
.interruptor.chico { padding: 4px 12px; min-height: 36px; }
@keyframes late { 50% { box-shadow: 0 0 0 7px rgba(139, 227, 181, 0.05); } }

.resumen { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.dato { padding: 14px; border-radius: 16px; background: var(--vidrio); border: 1px solid var(--orilla); }
.dato b { display: block; font-family: "JoyNode", sans-serif; font-size: 30px; font-weight: 600; }
.dato span { color: var(--tenue); font-size: 13px; }

.herramientas { display: grid; gap: 10px; margin-bottom: 10px; }
.todo { display: flex; align-items: center; gap: 10px; color: var(--texto); font-size: 15px; }
.lote {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; margin-bottom: 10px;
  border-radius: 16px; background: rgba(185, 166, 255, 0.14); border: 1px solid rgba(185, 166, 255, 0.35);
  position: sticky; top: 64px; z-index: 4; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.lote.fijo { position: static; }
#lote-n { flex-basis: 100%; font-size: 14px; color: var(--tenue); }

.grupo { margin-bottom: 10px; border-radius: 16px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--orilla); overflow: hidden; }
.grupo summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; cursor: pointer; font-weight: 600; list-style: none; min-height: 48px; }
.grupo summary::-webkit-details-marker { display: none; }
.grupo summary::after { content: "▾"; color: var(--tenue); margin-left: 8px; transition: transform 0.2s ease; }
.grupo:not([open]) summary::after { transform: rotate(-90deg); }
.cuenta { margin-left: auto; color: var(--tenue); font-weight: 400; font-size: 14px; }

.fila-conv { display: flex; align-items: center; gap: 12px; padding: 4px 12px; border-top: 1px solid rgba(255, 255, 255, 0.07); animation: entra 0.35s ease both; animation-delay: calc(var(--i, 0) * 30ms); }
.conv { flex: 1; min-width: 0; display: grid; gap: 4px; text-align: left; background: none; border: 0; padding: 10px 0; cursor: pointer; }
.conv .arriba, .conv .abajo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.conv b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv time { color: var(--tenue); font-size: 13px; flex: none; }
.ultimo { flex: 1; min-width: 0; color: var(--tenue); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fila-conv.nueva b { color: #fff; }
.fila-conv.nueva .ultimo { color: var(--texto); }
.burbuja { flex: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--lila); color: #1a1030; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.etiqueta { flex: none; font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--orilla); color: var(--tenue); }
.etiqueta.pausa { border-color: rgba(255, 154, 168, 0.5); color: var(--mal); }
.vacio { color: var(--tenue); text-align: center; padding: 28px 12px; }

/* Chat */
.chat { padding: 0; display: flex; flex-direction: column; height: calc(100svh - 62px); max-width: 980px; }
body.en-chat .app { padding-bottom: 0; }
body.en-chat .menu { display: none; }
.chat-cabeza { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--orilla); background: rgba(18, 12, 34, 0.55); }
.quien { flex: 1; min-width: 0; display: grid; }
.quien b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quien span { color: var(--tenue); font-size: 13px; }
.mensajes { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.dia { align-self: center; font-size: 12px; color: var(--tenue); background: rgba(255, 255, 255, 0.06); padding: 4px 12px; border-radius: 999px; margin: 8px 0; text-transform: capitalize; }
.msj { max-width: 82%; padding: 8px 12px; border-radius: 16px; animation: entra 0.25s ease both; }
.msj.entra { align-self: flex-start; background: rgba(255, 255, 255, 0.1); border-bottom-left-radius: 6px; }
.msj.sale { align-self: flex-end; background: linear-gradient(135deg, rgba(185, 166, 255, 0.32), rgba(142, 114, 216, 0.32)); border-bottom-right-radius: 6px; }
.msj.sale.humano { background: linear-gradient(135deg, rgba(243, 184, 228, 0.3), rgba(185, 166, 255, 0.26)); }
.msj .autor { display: block; font-size: 12px; font-weight: 600; color: var(--lila); margin-bottom: 2px; }
.msj.humano .autor { color: var(--rosa); }
.msj .texto { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msj .pie { display: block; text-align: right; font-size: 11px; color: var(--tenue); margin-top: 2px; }
.palomita.read { color: #9fd3ff; }
.palomita.failed { color: var(--mal); }
.responder { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px calc(10px + var(--seguro-abajo)); border-top: 1px solid var(--orilla); background: rgba(18, 12, 34, 0.75); }
.responder textarea { flex: 1; resize: none; max-height: 160px; }
.aviso { flex-basis: 100%; margin: 0; font-size: 13px; color: var(--rosa); }

/* Ajustes */
.bloque { padding: 18px; margin-bottom: 14px; display: grid; gap: 10px; }
.bloque .ok { color: var(--ok); margin: 0; }
.bloque .error { color: var(--mal); }
.fila { display: grid; gap: 10px; }
.usuario { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.usuario div { display: grid; min-width: 0; }
.usuario span { color: var(--tenue); font-size: 13px; overflow-wrap: anywhere; }
.solo-admin { display: none; }
body.es-admin .solo-admin { display: grid; }

/* Menu de abajo */
.menu {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + var(--seguro-abajo)); background: rgba(18, 12, 34, 0.85);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--orilla);
}
.menu button { position: relative; min-height: 52px; background: none; border: 0; color: var(--tenue); font-size: 14px; cursor: pointer; border-radius: 12px; }
.menu button.activo { color: var(--texto); background: rgba(185, 166, 255, 0.14); }
.menu .burbuja { position: absolute; top: 4px; right: 14%; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--seguro-abajo)); transform: translateX(-50%); z-index: 9;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px; background: rgba(30, 20, 60, 0.95);
  border: 1px solid var(--orilla); animation: entra 0.25s ease both;
}
.toast.malo { border-color: rgba(255, 154, 168, 0.6); color: var(--mal); }

@media (min-width: 760px) {
  .resumen { grid-template-columns: repeat(4, 1fr); }
  .herramientas { grid-template-columns: 1fr auto; align-items: center; }
  #lote-n { flex-basis: auto; margin-right: auto; }
  .fila { grid-template-columns: repeat(2, 1fr); }
  #f-usuario { grid-template-columns: 1fr 1fr 1fr auto auto; }
  .menu { left: 50%; right: auto; bottom: 16px; transform: translateX(-50%); width: 420px; border-radius: 999px; border: 1px solid var(--orilla); padding: 6px; }
  .menu button { border-radius: 999px; }
  .chat { height: calc(100svh - 62px); margin: 0 auto; }
}

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