/* Tokens y componentes — diseno-uiux.md (normativo). Mobile-first 375px. */
:root {
  color-scheme: light;
  --brand-accent: #FFB600;
  --brand-ink: #201547;
  --brand-500: #FFB600;
  --brand-900: #201547;
  --brand-950: #160F33;
  --surface-0: #F4F5F7;
  --surface-1: #FFFFFF;
  --surface-2: #ECEEF2;
  --texto: #1D2230;
  --texto-2: #5B6172;
  --ok: #1E9E5A;
  --warn: #D98E00;
  --danger: #C93A3A;
  --muted: #8A8FA3;
  --linea: #E2E4EA;
  --radio: 8px;
  --radio-chat: 16px;
  --sombra-1: 0 1px 3px rgba(16, 16, 40, .08);
  --sombra-2: 0 8px 28px rgba(16, 16, 40, .12);
}
/* Superficies claras consistentes; no activar un tema parcial por el SO. */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; line-height: 1.5;
  background: var(--surface-0); color: var(--texto);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.boot { margin: auto; color: var(--texto-2); }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
button:disabled { opacity: .4; cursor: default; }
:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 2px; }

/* --- header --- */
.topbar {
  background: var(--brand-900); color: #fff;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
  position: sticky; top: 0; z-index: 40;
}
.topbar .logo { width: 30px; height: 30px; border-radius: 6px; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .02em; }
.topbar .spacer { flex: 1; }
.topbar .badge-global {
  background: var(--brand-500); color: var(--brand-900);
  border-radius: 999px; padding: 2px 10px; font-weight: 700; font-size: 13px;
}
.icon-btn {
  background: none; border: 0; color: inherit; padding: 10px;
  min-width: 44px; min-height: 44px; border-radius: var(--radio);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: rgba(255,255,255,.12); }

/* --- lista --- */
.buscador { padding: 12px 16px 4px; }
.buscador input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--linea);
  border-radius: var(--radio); background: var(--surface-1); min-height: 44px;
}
.chips { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; }
.chip {
  border: 1px solid var(--linea); background: var(--surface-1); color: var(--texto-2);
  border-radius: 999px; padding: 8px 14px; font-size: 14px; white-space: nowrap;
  min-height: 40px;
}
.chip.on { background: var(--brand-900); color: #fff; border-color: var(--brand-900); }
.chips select {
  border: 1px solid var(--linea); border-radius: 999px; padding: 8px 12px;
  background: var(--surface-1); color: var(--texto-2); min-height: 40px;
}
.lista { flex: 1; overflow-y: auto; padding: 4px 8px calc(env(safe-area-inset-bottom) + 16px); }
.conv {
  display: flex; gap: 12px; align-items: center; width: 100%; text-align: left;
  background: var(--surface-1); border: 0; border-bottom: 1px solid var(--linea);
  padding: 12px; min-height: 64px; border-radius: var(--radio);
}
.conv { color: var(--texto); }
.conv:active { background: var(--surface-2); }
@media (hover: hover) {
  .conv:hover { background: var(--surface-2); }
}
.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none;
  background: var(--brand-900); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.conv .cuerpo { flex: 1; min-width: 0; }
.conv .fila1 { display: flex; align-items: center; gap: 8px; }
.conv .nombre { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .hora { font-size: 12px; color: var(--texto-2); flex: none; }
.conv .preview {
  color: var(--texto-2); font-size: 14px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.canal-ico { width: 16px; height: 16px; flex: none; }
.punto { width: 10px; height: 10px; border-radius: 50%; background: var(--brand-500); flex: none; }
.badge-nl {
  background: var(--brand-500); color: var(--brand-900); border-radius: 999px;
  font-size: 12px; font-weight: 700; min-width: 20px; text-align: center; padding: 1px 6px;
}
.tag-pausa { font-size: 12px; color: var(--warn); font-weight: 600; }
.tag-ok { font-size: 12px; color: var(--muted); }

/* --- chat --- */
.chat { display: flex; flex-direction: column; height: 100dvh; }
.chat-head {
  background: var(--brand-900); color: #fff; display: flex; align-items: center;
  gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  position: sticky; top: 0; z-index: 40;
}
.chat-head .info { flex: 1; min-width: 0; }
.chat-head .nombre { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .sub { font-size: 12px; opacity: .8; display: flex; gap: 8px; align-items: center; }
.pill {
  font-size: 12px; border-radius: 999px; padding: 2px 10px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px;
}
.pill.ok { background: rgba(30,158,90,.18); color: #7fe3ae; }
.pill.warn { background: rgba(217,142,0,.2); color: #ffcf70; }
.pill.danger { background: rgba(201,58,58,.22); color: #ff9d9d; }
.pill.muted { background: rgba(138,143,163,.25); color: #c6cadb; }
.hilo {
  flex: 1; overflow-y: auto; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.dia {
  align-self: center; font-size: 12px; color: var(--texto-2);
  background: var(--surface-2); padding: 4px 12px; border-radius: 999px;
}
.burbuja {
  max-width: 82%; padding: 10px 14px; border-radius: var(--radio-chat);
  box-shadow: var(--sombra-1); white-space: pre-wrap; word-break: break-word;
}
.burbuja.cliente { align-self: flex-start; background: var(--surface-1); border-bottom-left-radius: 4px; }
.burbuja.bot { align-self: flex-end; background: var(--surface-2); border-bottom-right-radius: 4px; }
.burbuja.humano { align-self: flex-end; background: var(--brand-900); color: #fff; border-bottom-right-radius: 4px; }
.burbuja .meta { font-size: 11px; opacity: .65; margin-top: 6px; display: flex; gap: 8px; justify-content: flex-end; }
.burbuja .etiqueta { font-size: 11px; font-weight: 700; opacity: .7; margin-bottom: 2px; }
.burbuja .err { color: #ff9d9d; font-size: 12px; font-weight: 600; }
.burbuja.humano .err { color: #ffb3b3; }
.media-nota { font-style: italic; color: var(--texto-2); font-size: 14px; }
.acciones-chat {
  display: flex; gap: 8px; padding: 8px 12px; flex-wrap: wrap;
  background: var(--surface-1); border-top: 1px solid var(--linea);
}
.btn {
  border: 1px solid var(--linea); background: var(--surface-1); color: var(--texto);
  border-radius: var(--radio); padding: 10px 16px; min-height: 44px; font-weight: 600;
}
.btn.primario { background: var(--brand-500); border-color: var(--brand-500); color: var(--brand-900); }
.btn.peligro { color: var(--danger); border-color: var(--danger); }
.btn:active { transform: scale(.97); }

/* --- ficha --- */
.ficha-overlay {
  position: fixed; inset: 0; background: rgba(10,8,25,.5); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.ficha {
  background: var(--surface-1); width: 100%; max-height: 86dvh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: var(--sombra-2);
}
.ficha h2 { margin: 0 0 4px; font-size: 18px; }
.ficha .sub { color: var(--texto-2); font-size: 14px; margin-bottom: 16px; }
.ficha details { border-top: 1px solid var(--linea); padding: 10px 0; }
.ficha summary { font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.ficha .item { padding: 8px 0; font-size: 14px; border-bottom: 1px dashed var(--linea); }
.ficha .item .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.cerrar-sheet { width: 100%; margin-top: 12px; }

/* --- login: acceso editorial BMB, aislado del layout operativo --- */
.login {
  --login-paper: #FFFFFF;
  --login-ink: #201547;
  --login-muted: #5B6172;
  --login-line: #D5D8E1;
  --login-on-brand: #E1DDEB;
  --login-error: #AA2929;
  --login-error-bg: #FFF3F2;
  --login-warning: #805200;
  --login-accent-hover: #EFAA00;
  color-scheme: light;
  margin: 0; width: 100%; min-width: 0; min-height: 100dvh;
  display: flex; flex-direction: column;
  background: var(--login-paper); color: var(--login-ink);
}
.login .login-brand {
  background: var(--brand-900); color: var(--login-paper);
  padding: calc(env(safe-area-inset-top) + 24px) max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left));
  border-bottom: 4px solid var(--brand-500);
  min-width: 0;
}
.login .login-brand-mark,
.login .login-brand .marca {
  display: flex; align-items: center; gap: 12px;
  font-size: 16px; font-weight: 700; letter-spacing: -.02em;
}
.login img {
  display: block; width: 48px; height: 48px; flex: none;
  object-fit: contain; border-radius: var(--radio);
}
.login .login-brand img { width: 40px; height: 40px; }
.login .login-brand h2 {
  max-width: 16ch; margin: 24px 0 12px;
  font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -.035em;
  text-wrap: balance;
}
.login .login-brand p {
  max-width: 42ch; margin: 0; color: var(--login-on-brand);
  font-size: 14px; line-height: 1.6;
}
.login .login-brand ul,
.login .login-channels {
  display: flex; flex-wrap: wrap; gap: 8px 16px;
  list-style: none; padding: 0; margin: 20px 0 0;
  color: var(--login-on-brand); font-size: 12px;
}
.login .login-brand li { margin: 0; padding: 0; }
.login .login-brand .login-brand-note {
  margin-top: 24px; padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,.2); font-size: 12px;
}
.login .login-panel {
  flex: 1; min-width: 0; display: flex; justify-content: center; align-items: center;
  padding: 32px max(24px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}
.login .card {
  width: 100%; max-width: 416px; min-width: 0;
  background: var(--login-paper); color: var(--login-ink);
  border: 0; border-radius: var(--radio); padding: 0;
  box-shadow: none;
}
/* Cambio de clave y markup anterior: tarjeta útil sin exigir el split. */
.login > .card {
  align-self: center; margin: auto; width: calc(100% - 48px);
  padding: 32px 0;
}
.login .card > img { margin: 0 0 24px; }
.login .login-eyebrow {
  display: block; margin: 0 0 12px; color: var(--login-muted);
  font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
}
.login h1 {
  margin: 0; font-size: 32px; line-height: 1.2;
  letter-spacing: -.04em; font-weight: 700; color: var(--login-ink);
  overflow-wrap: anywhere;
}
.login .sub {
  margin: 12px 0 32px; text-align: left;
  color: var(--login-muted); font-size: 16px; line-height: 1.5;
}
.login form { margin: 0; }
.login .campo { margin-bottom: 24px; }
.login .campo label {
  color: var(--login-ink); font-size: 14px; font-weight: 600; margin-bottom: 8px;
}
.login .campo input {
  min-height: 52px; padding: 12px 16px; font-size: 16px;
  background: var(--login-paper); color: var(--login-ink);
  border: 1px solid var(--login-line); border-radius: var(--radio);
}
.login .campo input::placeholder { color: var(--login-muted); opacity: 1; }
.login .campo input:focus {
  border-color: var(--login-ink); outline: 2px solid var(--login-ink); outline-offset: 2px;
}
.login .campo input[aria-invalid="true"] { border-color: var(--login-error); }
.login .btn.full {
  min-height: 52px; font-size: 16px; font-weight: 700;
  border-radius: var(--radio); margin-top: 8px;
}
.login .btn.primario {
  background: var(--brand-500); border-color: var(--brand-500); color: var(--login-ink);
}
.login .btn:focus-visible { outline: 3px solid var(--login-ink); outline-offset: 3px; }
.login .btn:active { transform: none; }
.login .btn:disabled { opacity: .65; cursor: not-allowed; }
.login .err-campo {
  margin: 0 0 16px; padding: 12px 16px; border-left: 3px solid var(--login-error);
  border-radius: 4px; background: var(--login-error-bg); color: var(--login-error);
  font-size: 14px; overflow-wrap: anywhere;
}
.login .aviso-sesion {
  background: var(--surface-0); color: var(--login-muted); text-align: left;
  padding: 12px 16px; margin: 0 0 24px; font-size: 14px;
}
.login .aviso-espera { color: var(--login-warning); text-align: left; font-size: 14px; }
.login .login-footer {
  margin: 32px 0 0; padding-top: 24px; border-top: 1px solid var(--login-line);
  color: var(--login-muted); font-size: 14px; line-height: 1.6;
}
.login .login-footer p { margin: 0; }
@media (hover: hover) {
  .login .btn.primario:not(:disabled):hover { background: var(--login-accent-hover); border-color: var(--login-accent-hover); }
}
@media (max-width: 599px) {
  .login .login-brand h2 { max-width: none; margin: 16px 0 8px; }
  .login .login-brand ul, .login .login-channels { margin-top: 12px; }
  .login .login-brand .login-brand-note { display: none; }
  .login .login-panel { align-items: flex-start; }
}
@media (min-width: 900px) {
  .login { display: grid; grid-template-columns: minmax(0, 46fr) minmax(0, 54fr); }
  .login .login-brand {
    display: flex; flex-direction: column; align-items: flex-start;
    padding: 64px clamp(32px, 5vw, 88px); border-bottom: 0;
    border-top: 6px solid var(--brand-500);
  }
  .login .login-brand img { width: 48px; height: 48px; }
  .login .login-brand h2 { margin-top: auto; padding-top: 80px; font-size: 32px; }
  .login .login-brand p { font-size: 16px; }
  .login .login-brand ul, .login .login-channels { margin-top: 32px; font-size: 14px; gap: 12px 24px; }
  .login .login-brand .login-brand-note {
    margin-top: auto; padding-top: 24px; width: 100%; max-width: none; font-size: 12px;
    transform: translateY(24px);
  }
  .login .login-panel { padding: 64px clamp(32px, 5vw, 88px); }
  .login > .card { grid-column: 1 / -1; }
}
.campo { margin-bottom: 14px; }
.campo label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.campo input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--linea);
  border-radius: var(--radio); background: var(--surface-1); min-height: 48px;
}
.err-campo { color: var(--danger); font-size: 14px; margin-top: 6px; }
.btn.full { width: 100%; min-height: 48px; font-size: 16px; }

/* --- ajustes / usuarios --- */
.sheet {
  position: fixed; inset: 0; background: rgba(10,8,25,.5); z-index: 70;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet .panel {
  background: var(--surface-1); width: 100%; max-height: 90dvh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 20px 16px calc(env(safe-area-inset-bottom) + 20px);
  box-shadow: var(--sombra-2);
}
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--linea);
  padding: 14px 4px; min-height: 48px; font-size: 16px; color: var(--texto);
}
.menu-item.peligro { color: var(--danger); }
.usuario-fila {
  display: flex; align-items: center; gap: 10px; padding: 12px 0;
  border-bottom: 1px solid var(--linea);
}
.usuario-fila .datos { flex: 1; min-width: 0; }
.usuario-fila .datos .u { font-size: 13px; color: var(--texto-2); }
.tag-rol { font-size: 11px; background: var(--surface-2); border-radius: 999px; padding: 2px 8px; }
.tag-inactivo { font-size: 11px; background: var(--danger); color: #fff; border-radius: 999px; padding: 2px 8px; }

/* --- toast --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  background: var(--brand-950); color: #fff; padding: 12px 20px;
  border-radius: 999px; box-shadow: var(--sombra-2); z-index: 100;
  animation: sube .2s ease-out; max-width: 90vw; text-align: center;
}
@keyframes sube { from { opacity: 0; transform: translate(-50%, 8px); } }

/* --- skeleton / vacío --- */
.skel { padding: 8px; }
.skel .f {
  height: 64px; border-radius: var(--radio); margin-bottom: 8px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-1) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.vacio { text-align: center; color: var(--texto-2); padding: 48px 24px; }
.vacio svg { width: 48px; height: 48px; margin-bottom: 12px; opacity: .5; }

/* --- desktop --- */
@media (min-width: 1024px) {
  .chat-layout { display: grid; grid-template-columns: 340px 1fr 340px; height: 100dvh; }
  .ficha-overlay { position: static; background: none; }
  .ficha { border-radius: 0; max-height: none; height: 100%; box-shadow: none; border-left: 1px solid var(--linea); }
  .cerrar-sheet { display: none; }
  .sheet .panel { max-width: 480px; border-radius: 16px; margin-bottom: 10vh; }
  .burbuja { max-width: 60%; }
}

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