/* Bandeja de WhatsApp (marca Casa). */
/* Casa Color y Sabor: modo claro «Crema de casa»; modo oscuro «Noche cálida». tema.js pone data-tema en <html>. */
:root {
  color-scheme: light;
  --fondo: #FFF5E1;
  --superficie: #FFFFFF;
  --superficie-2: #FFF8EC;
  --texto: #2A1E14;
  --texto-2: #6B5340;
  --linea: #EBDCC2;
  --util: #7A6450;
  --negro: #2A1E14;
  --naranja: #E85E13;
  --riel-txt: #E9D9BF;
  --riel-activo: #4A3626;
  --riel-hover: #FFF5E1;
  --nota-fondo: #FFF1D6;
  --nota-linea: #FAB729;
  --nota-txt: #6B3A00;
  --radio: 12px;
  --borde-ctl: #8F7B66;
  --env-bg: #3F6A0E;
  --env-txt: #FFFDF5;
  --rec-bg: #FFFFFF;
  --btn-bg: #E85E13;
  --btn-txt: #2A1E14;
  --chip-bg: #2A1E14;
  --chip-txt: #FFF5E1;
  --badge-txt: #2A1E14;
  --foco: #B84A06;
  --acento: #B84A06;
  --toast-bg: #2A1E14;
  --toast-txt: #FFF5E1;
  --sw-off: #8F7B66;
  --st-cola: #9A8670;
  --st-env: #7A6450;
  --st-ent: #4F7A12;
  --st-leido: #2A1E14;
  --st-fallo: #C2300B;
  --sombra: rgba(42, 30, 20, .2);
  --velo: rgba(42, 30, 20, .45);
  --fuente: "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
:root[data-tema="oscuro"] {
  color-scheme: dark;
  --fondo: #1A130C;
  --superficie: #241A11;
  --superficie-2: #2C2015;
  --texto: #F6EAD9;
  --texto-2: #B7A088;
  --linea: #3A2C1C;
  --util: #A08B73;
  --negro: #120D08;
  --naranja: #F6863E;
  --riel-txt: #8B765E;
  --riel-activo: #36271A;
  --riel-hover: #F6EAD9;
  --nota-fondo: #3A2513;
  --nota-linea: #E5A542;
  --nota-txt: #F6D9B0;
  --borde-ctl: #82705B;
  --env-bg: #4C7F2A;
  --rec-bg: #2C2015;
  --btn-bg: #F6863E;
  --btn-txt: #1A130C;
  --chip-bg: #F6863E;
  --chip-txt: #1A130C;
  --badge-txt: #1A130C;
  --foco: #F6863E;
  --acento: #F6863E;
  --toast-bg: #120D08;
  --toast-txt: #F6EAD9;
  --sw-off: #82705B;
  --st-cola: #7D6B57;
  --st-env: #A08B73;
  --st-ent: #7FAF3F;
  --st-leido: #F6EAD9;
  --st-fallo: #FF8A6B;
  --sombra: rgba(0, 0, 0, .5);
  --velo: rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 400 15px/1.45 var(--fuente);
  font-variant-numeric: tabular-nums;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; font-family: var(--fuente); color: inherit; }
a { color: inherit; }
input, select, textarea { font-size: 16px; }
:focus-visible { outline: 3px solid var(--foco); outline-offset: 2px; }
.rail :focus-visible { outline-color: var(--riel-hover); }
::placeholder { color: var(--util); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
svg.i {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex: none;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* Franja de demo */
.demo { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; background: var(--toast-bg); color: var(--toast-txt); font-size: 13px; font-weight: 700; letter-spacing: .02em; padding: 6px 12px; border-bottom: 1px solid var(--linea); }
.demo-txt { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.demo-largo { display: none; }
.demo-ver-txt { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (min-width: 640px) {
  .demo-corto { display: none; }
  .demo-largo { display: inline; }
  .demo-ver-txt { position: static; width: auto; height: auto; overflow: visible; clip: auto; white-space: normal; }
}
.demo-ver { flex: none; display: inline-flex; align-items: center; gap: 6px; font-weight: 400; }
.demo-sel { min-height: 36px; padding: 0 8px; font-size: 13px; font-weight: 700; background: var(--superficie); color: var(--texto); border: 1px solid var(--borde-ctl); border-radius: var(--radio); }

/* Estructura: riel (escritorio) + vista + menú inferior (celular) */
.shell { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
.view { min-width: 0; min-height: 0; overflow: auto; }
.cargando { padding: 24px; color: var(--texto-2); }

.rail { display: none; flex-direction: column; align-items: center; gap: 6px; padding: 14px 0; background: var(--negro); }
.rail .marca { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 8px; border-radius: 10px; }
.rail .marca img { display: block; width: 44px; height: 44px; }
.rail .riel-item {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radio);
  color: var(--riel-txt); text-decoration: none;
}
.rail .riel-item:hover { color: var(--riel-hover); }
.rail .riel-item[aria-current="page"] { background: var(--riel-activo); color: var(--riel-hover); }
.rail .yo {
  margin-top: auto; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; cursor: pointer;
}
.rail .yo span {
  width: 32px; height: 32px; border-radius: 50%; background: var(--riel-activo);
  color: var(--riel-hover); display: grid; place-items: center; font-size: 12px; font-weight: 800;
}
.rail .yo:hover span { box-shadow: 0 0 0 2px var(--riel-txt); }

.bottom {
  display: flex; justify-content: space-around; background: var(--superficie);
  border-top: 1px solid var(--linea); padding: 4px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}
.bottom a {
  flex: 1; min-width: 0; min-height: 52px; display: grid; justify-items: center; align-content: center; gap: 2px;
  font-size: 11px; color: var(--texto-2); text-decoration: none; border-radius: var(--radio);
}
.bottom a[aria-current="page"] { color: var(--texto); font-weight: 800; box-shadow: inset 0 2px 0 var(--acento); }
body[data-chat="1"] .bottom { display: none; }

@media (min-width: 640px) {
  .shell { grid-template-columns: 64px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .rail { display: flex; border-right: 1px solid var(--linea); }
  .bottom { display: none; }
}

/* Textos y controles comunes */
.kicker { margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--texto-2); }
.pantalla { padding: 24px 16px; display: grid; gap: 6px; align-content: start; }
.pantalla h1 { margin: 0; font-size: 28px; font-weight: 400; letter-spacing: -.035em; line-height: 1.1; }
.fatal { min-height: 100%; display: grid; place-content: center; justify-items: center; gap: 16px; padding: 24px; text-align: center; }
.fatal h1 { margin: 0; font-size: 28px; font-weight: 400; letter-spacing: -.035em; line-height: 1.15; }
.menu-lista { display: grid; margin-top: 12px; border-top: 1px solid var(--linea); }
.menu-lista a, .menu-lista button {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 4px;
  border-bottom: 1px solid var(--linea); text-decoration: none; font-weight: 700; width: 100%;
  background: transparent; border-left: 0; border-right: 0; border-top: 0; color: var(--texto); text-align: left; cursor: pointer;
}

.btn {
  min-height: 44px; display: inline-flex; gap: 6px; align-items: center; justify-content: center; padding: 0 14px;
  border: 1px solid var(--borde-ctl); border-radius: var(--radio); background: var(--superficie);
  color: var(--texto); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn.pri { background: var(--btn-bg); border-color: var(--btn-bg); color: var(--btn-txt); }
.btn.pri:hover { filter: brightness(.95); }
.btn[aria-pressed="true"] { background: var(--chip-bg); border-color: var(--chip-bg); color: var(--chip-txt); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-icono {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: var(--radio); background: transparent; color: var(--texto); cursor: pointer;
}

.avisos {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none;
}
.toast {
  background: var(--toast-bg); color: var(--toast-txt); padding: 12px 14px; border-radius: var(--radio);
  font-size: 14px; border: 1px solid var(--linea); box-shadow: 0 6px 20px var(--sombra);
}
.toast.error { border-left: 4px solid var(--naranja); }
@media (min-width: 640px) { .avisos { bottom: 20px; } }

/* Vista Chats: lista + chat + ficha */
.chats {
  height: 100%; position: relative; overflow: hidden; background: var(--superficie);
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
}
.lista { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--superficie); }
.lhead { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--linea); }
.lhead h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.buscar {
  display: flex; gap: 8px; align-items: center; min-height: 44px; padding: 0 12px;
  background: var(--superficie-2); border: 1px solid var(--borde-ctl); border-radius: var(--radio); color: var(--texto-2);
}
.buscar:focus-within { outline: 3px solid var(--foco); outline-offset: 2px; }
.buscar input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--texto); }
.chips, .filtros { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar, .filtros::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; gap: 6px; align-items: center; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--borde-ctl); border-radius: 999px; background: var(--superficie); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--chip-bg); border-color: var(--chip-bg); color: var(--chip-txt); font-weight: 700; }
.filtro {
  flex: none; min-height: 44px; padding: 0 8px; border: 0; border-bottom: 3px solid transparent; background: transparent;
  color: var(--texto-2); font-size: 13px; cursor: pointer; white-space: nowrap;
}
.filtro[aria-pressed="true"] { color: var(--texto); font-weight: 800; border-bottom-color: var(--acento); }
.filtro em { font-style: normal; font-size: 11px; font-weight: 700; margin-left: 4px; }
.estado-red { margin: 0; font-size: 12px; color: var(--nota-txt); font-weight: 700; }

.items { overflow: auto; min-height: 0; flex: 1; }
.vacio-lista { margin: 0; padding: 24px 16px; color: var(--texto-2); text-align: center; }
.item {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center;
  min-height: 64px; padding: 12px 14px; border-bottom: 1px solid var(--linea); text-decoration: none;
}
.item:hover { background: var(--superficie-2); }
.item[aria-current="true"] { background: var(--fondo); box-shadow: inset 3px 0 0 var(--acento); }
.ava {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--superficie-2); border: 1px solid var(--linea); font-weight: 700; font-size: 13px;
}
.cuerpo { display: grid; gap: 2px; min-width: 0; }
.nombre { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prev { font-size: 13px; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tagc { display: inline-flex; align-items: center; gap: 6px; min-width: 0; font-size: 11px; color: var(--texto-2); }
.tagc span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.meta { display: grid; justify-items: end; gap: 4px; }
.hora { font-size: 11px; color: var(--texto-2); }
.sin-leer {
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px; background: var(--naranja); color: var(--badge-txt);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.quien {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 10px; font-weight: 700;
  background: var(--superficie-2); border: 1px solid var(--linea);
}
.sin-asignar { font-size: 11px; color: var(--texto-2); }

.chat { min-height: 0; min-width: 0; display: flex; flex-direction: column; background: var(--fondo); }
.chat-cont { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.vacio-chat { margin: auto; padding: 24px; text-align: center; color: var(--texto-2); }
.chead {
  display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; padding: 10px 12px;
  background: var(--superficie); border-bottom: 1px solid var(--linea);
}
.chead .ava { width: 40px; height: 40px; }
.chead .t { display: grid; min-width: 0; flex: 1 1 140px; }
.chead .t b { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chead .t span { font-size: 12px; color: var(--texto-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.volver { display: none; }
.ficha-btn { display: grid; }
.ctl {
  display: inline-flex; gap: 6px; align-items: center; min-height: 44px; padding: 0 10px; max-width: 100%;
  background: var(--superficie); border: 1px solid var(--borde-ctl); border-radius: var(--radio); font-size: 13px;
}
.ctl:focus-within { outline: 3px solid var(--foco); outline-offset: 2px; }
.ctl.estado { background: var(--superficie-2); }
.ctl select { border: 0; background: transparent; font-weight: 700; font-size: 14px; max-width: 170px; min-height: 42px; outline: none; cursor: pointer; }

.msgs { flex: 1; min-height: 0; overflow: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 8px; }
.cargando-chat { margin: auto; color: var(--texto-2); }
.dia {
  align-self: center; font-size: 11px; color: var(--texto-2); background: var(--superficie);
  border: 1px solid var(--linea); padding: 3px 10px; border-radius: 999px; margin: 4px 0;
}
.b {
  max-width: 78%; display: flex; flex-direction: column; gap: 4px; padding: 9px 12px;
  border-radius: var(--radio); line-height: 1.45; overflow-wrap: anywhere;
}
.b { font-family: var(--fuente); }
.b.in { align-self: flex-start; background: var(--rec-bg); border: 1px solid var(--linea); }
.b.out { align-self: flex-end; background: var(--env-bg); color: var(--env-txt); }
.b.bot { align-self: flex-end; background: var(--rec-bg); border: 1px dashed var(--util); }
.b.noteb {
  align-self: center; max-width: 88%; background: var(--nota-fondo); color: var(--nota-txt);
  border: 1px dashed var(--nota-linea); font-size: 13px;
}
.b .por { font-size: 11px; font-weight: 700; opacity: .85; }
.texto { white-space: pre-wrap; }
.b small { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 8px; align-items: center; font-size: 11px; opacity: .85; }
.b.out small, .b.out .por, .b.out .motivo { opacity: 1; }
.b small > span { display: inline-flex; align-items: center; gap: 3px; }
.b small svg.i { width: 14px; height: 14px; }
.b .fallo { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; color: var(--nota-txt); opacity: 1; }
.b.out .fallo { color: var(--env-txt); text-decoration: underline; }
.b .motivo { font-size: 12px; opacity: .9; }
.b .archivo { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-weight: 700; }
.b img.foto { display: block; max-width: 100%; max-height: 260px; border-radius: 6px; object-fit: contain; }

.win {
  display: flex; gap: 8px; align-items: center; padding: 8px 14px; font-size: 12px; color: var(--texto-2);
  background: var(--superficie); border-top: 1px solid var(--linea);
}
.win b { color: var(--texto); font-weight: 700; }
.compose { display: grid; gap: 8px; padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--superficie); border-top: 1px solid var(--linea); }
.compose .caja {
  width: 100%; min-height: 44px; max-height: 140px; resize: none; padding: 10px 12px; line-height: 1.4;
  background: var(--superficie-2); border: 1px solid var(--borde-ctl); border-radius: var(--radio); outline: none;
}
.compose .caja:focus { border-color: var(--texto); box-shadow: inset 0 0 0 1px var(--texto); }
.compose.nota .caja { background: var(--nota-fondo); border: 1px dashed var(--nota-txt); color: var(--nota-txt); }
.aviso-cerrada {
  margin: 0; padding: 12px; font-size: 14px; line-height: 1.45; background: var(--superficie-2);
  border: 1px solid var(--linea); border-radius: var(--radio);
}
.acciones { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; }
.acciones .btn:first-child { margin-right: auto; }

/* Aviso de mensajes nuevos, franja del chat ajeno, archivo adjunto y menú de "/" */
.activar-avisos { justify-self: start; min-height: 44px; font-size: 13px; font-weight: 400; color: var(--texto-2); }
.lleva { margin: 0; padding: 8px 12px; font-size: 13px; color: var(--texto-2); background: var(--superficie-2); border: 1px solid var(--linea); border-radius: var(--radio); }
.adjunto { display: flex; gap: 8px; align-items: center; min-width: 0; padding: 6px 6px 6px 12px; font-size: 14px; background: var(--superficie-2); border: 1px solid var(--borde-ctl); border-radius: var(--radio); }
.adj-nombre { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sug-rap { display: grid; border: 1px solid var(--linea); border-radius: var(--radio); background: var(--superficie); overflow: hidden; }
.sug-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; align-items: center; min-height: 44px; padding: 6px 12px; border: 0; border-bottom: 1px solid var(--linea); background: transparent; text-align: left; cursor: pointer; }
.sug-item:last-child { border-bottom: 0; }
.sug-item[aria-selected="true"], .sug-item:hover { background: var(--superficie-2); }
.sug-item span, .rapida-usar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--texto-2); font-size: 13px; }
.texto a { color: inherit; text-decoration: underline; }
.b .medio { display: block; width: 100%; max-width: 280px; border-radius: 6px; }
.b video.medio { max-height: 260px; }
.b .reintentar { align-self: flex-start; }
.rapidas { display: grid; gap: 12px; }
.rapida { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-bottom: 10px; border-bottom: 1px solid var(--linea); }
.rapida-usar { flex: 1 1 100%; display: grid; gap: 2px; min-height: 44px; padding: 6px 4px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.vacio-lista .btn { margin-top: 12px; }

/* Ficha del contacto: columna en escritorio, hoja inferior en pantallas menores */
.side {
  display: flex; flex-direction: column; gap: 18px; min-height: 0; padding: 16px; overflow-x: hidden; overflow-y: auto; background: var(--superficie);
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 80dvh;
  border-radius: 16px 16px 0 0; box-shadow: 0 -10px 30px var(--sombra);
  transform: translateY(105%); visibility: hidden; transition: transform .2s ease, visibility .2s;
}
.chats.side-open .side { transform: none; visibility: visible; }
.side-cerrar { position: absolute; top: 6px; right: 6px; }
.side .big { display: grid; justify-items: center; gap: 4px; text-align: center; padding-bottom: 16px; border-bottom: 1px solid var(--linea); }
.side .big .ava { width: 56px; height: 56px; font-size: 18px; margin-bottom: 4px; }
.side .big span { font-size: 12px; color: var(--texto-2); }
.side h3 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--texto-2); }
.side .bloque { display: grid; gap: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 2px 0 12px;
  background: var(--superficie-2); border: 1px solid var(--borde-ctl); border-radius: 999px; font-size: 13px;
}
.tag button { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; border-radius: 50%; cursor: pointer; }
.sin-datos { font-size: 13px; color: var(--texto-2); }
.agregar { display: flex; gap: 8px; margin-top: 8px; }
.agregar input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; background: var(--superficie-2);
  border: 1px solid var(--borde-ctl); border-radius: var(--radio);
}
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--texto-2); }
.kv dd { margin: 0; text-align: right; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.nota-baja { margin: 0 0 6px; font-size: 13px; color: var(--texto-2); }
.velo { position: fixed; inset: 0; z-index: 25; background: var(--velo); }

/* Modal de plantilla */
dialog.modal {
  width: min(92vw, 460px); max-height: 88dvh; padding: 0; border: 0; border-radius: 12px;
  color: var(--texto); background: var(--superficie); border: 1px solid var(--linea); box-shadow: 0 20px 60px var(--sombra);
}
dialog.modal::backdrop { background: var(--velo); }
.modal-cuerpo { display: grid; gap: 14px; padding: 20px; overflow: auto; }
.modal h2 { margin: 0; font-size: 24px; font-weight: 400; letter-spacing: -.03em; line-height: 1.15; }
.nota-m { margin: 0; font-size: 14px; color: var(--texto-2); }
.campo { display: grid; gap: 6px; font-size: 13px; font-weight: 700; }
.campo select, .campo input {
  min-height: 44px; padding: 0 12px; font-weight: 400; background: var(--superficie);
  border: 1px solid var(--borde-ctl); border-radius: var(--radio);
}
.vars { display: grid; gap: 12px; }
.vista {
  padding: 12px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--superficie-2); border: 1px solid var(--linea); border-radius: var(--radio);
}
.vista .var { font-weight: 800; background: var(--superficie); border-radius: 4px; padding: 0 3px; box-shadow: inset 0 0 0 1px var(--linea); }
.vista .var.falta { font-weight: 400; font-style: italic; color: var(--texto-2); }
.error-t { margin: 0; font-size: 13px; font-weight: 700; color: var(--nota-txt); }
.modal-pie { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--linea); }

/* Escritorio con ficha fija (≥ 1020 px) */
@media (min-width: 640px) {
  .chats { grid-template-columns: 300px minmax(0, 1fr); }
  .lista { border-right: 1px solid var(--linea); }
}
@media (max-width: 639px) {
  /* Cabecera del chat: persona arriba y los dos selectores en una segunda fila compacta */
  .ficha-btn { order: 1; }
  .chead .ctl { order: 2; flex: 1 1 calc(50% - 5px); min-width: 0; }
  .ctl select { flex: 1; width: 100%; min-width: 0; max-width: none; font-size: 16px; text-overflow: ellipsis; }
  .chats.is-open .lista { display: none; }
  .chats:not(.is-open) .chat { display: none; }
  .volver { display: grid; }
}
@media (min-width: 1020px) {
  .chats { grid-template-columns: 320px minmax(0, 1fr) 280px; }
  .chats:not(.has-chat) { grid-template-columns: 320px minmax(0, 1fr); }
  .side {
    position: static; transform: none; visibility: visible; max-height: none; border-radius: 0;
    box-shadow: none; border-left: 1px solid var(--linea); z-index: auto;
  }
  .side-cerrar, .ficha-btn, .velo { display: none; }
}
.chats:not(.has-chat) .side { display: none; }
.chats:not(.side-open) .velo { display: none; }

/* ---------- Pantallas de gestión (contactos, campañas, automáticas, reportes, ajustes) ---------- */
.pagina { min-width: 0; max-width: 1100px; display: grid; gap: 16px; align-content: start; padding: 20px 16px 32px; }
@media (min-width: 640px) { .pagina { padding: 28px 28px 40px; } }
.cab-pagina { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; }
.cab-pagina h1 { margin: 0; font-size: 28px; font-weight: 400; letter-spacing: -.035em; line-height: 1.1; }
.cab-pagina .kicker { margin-bottom: 6px; }
.fila { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.fila-end { justify-content: flex-end; }
.fila > .buscar { flex: 1 1 220px; min-width: 0; }
.sel { min-height: 44px; min-width: 0; max-width: 100%; padding: 0 10px; background: var(--superficie); border: 1px solid var(--borde-ctl); border-radius: var(--radio); }
.tarjeta { min-width: 0; display: grid; gap: 12px; padding: 16px; background: var(--superficie); border: 1px solid var(--linea); border-radius: 12px; }
.tarjeta h2 { margin: 0; font-size: 16px; font-weight: 700; }
.tarjeta-cab { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-start; justify-content: space-between; min-width: 0; }
.ayuda { margin: 0; font-size: 12px; color: var(--texto-2); overflow-wrap: anywhere; }
.vacio-b { margin: 0; padding: 24px 16px; text-align: center; color: var(--texto-2); background: var(--superficie); border: 1px dashed var(--linea); border-radius: 12px; }
.aviso-b { margin: 0; padding: 12px; font-size: 14px; background: var(--superficie-2); border: 1px solid var(--linea); border-radius: var(--radio); }
.aviso-b.alerta { border-left: 4px solid var(--naranja); color: var(--nota-txt); background: var(--nota-fondo); }
.campo { display: grid; gap: 6px; min-width: 0; }
.campo > label { display: grid; gap: 6px; min-width: 0; font-size: 13px; font-weight: 700; }
.campo input:not([type="checkbox"]):not([type="color"]), .campo select, .campo textarea {
  width: 100%; min-width: 0; min-height: 44px; padding: 0 12px; font-weight: 400; background: var(--superficie);
  border: 1px solid var(--borde-ctl); border-radius: var(--radio);
}
.campo textarea { min-height: 88px; padding: 10px 12px; line-height: 1.45; resize: vertical; }
.campo input[type="color"] { width: 64px; min-height: 44px; padding: 4px; background: var(--superficie); border: 1px solid var(--borde-ctl); border-radius: var(--radio); }
.campo.invalido input:not([type="checkbox"]), .campo.invalido select, .campo.invalido textarea { border-color: var(--nota-txt); box-shadow: inset 0 0 0 1px var(--nota-txt); }
.error-campo { margin: 0; font-size: 13px; font-weight: 700; color: var(--nota-txt); }
.check {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px; padding: 0 12px;
  background: var(--superficie); border: 1px solid var(--borde-ctl); border-radius: var(--radio); font-size: 14px; cursor: pointer;
}
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--env-bg); }
.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.grupo { min-width: 0; margin: 0; padding: 0; border: 0; display: grid; gap: 10px; }
.grupo legend { padding: 0; margin-bottom: 4px; font-size: 13px; font-weight: 700; }
.horario { padding-top: 4px; border-top: 1px solid var(--linea); }
.fila-switch { display: flex; align-items: center; gap: 4px; min-width: 0; }
.switch { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 64px; min-height: 44px; padding: 0; background: transparent; border: 0; cursor: pointer; }
.switch:disabled { cursor: default; opacity: .5; }
.switch .pista { position: relative; width: 52px; height: 30px; border-radius: 15px; background: var(--sw-off); transition: background-color .15s; }
.switch .pista::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--env-txt); box-shadow: 0 1px 2px var(--sombra); transition: transform .15s;
}
.switch[aria-checked="true"] .pista { background: var(--env-bg); }
.switch[aria-checked="true"] .pista::after { transform: translateX(22px); }
.btn.peligro { color: var(--nota-txt); border-color: var(--nota-txt); }
.btn[aria-busy="true"] { opacity: .7; cursor: progress; }
.btn-icono.agregar-btn { border: 1px solid var(--borde-ctl); background: var(--superficie); }
.pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--superficie-2); border: 1px solid var(--linea); white-space: nowrap; }
.pill.on { background: var(--chip-bg); border-color: var(--chip-bg); color: var(--chip-txt); }
.pill.alerta { color: var(--nota-txt); border-color: var(--nota-linea); background: var(--nota-fondo); }
.tabla-wrap { min-width: 0; background: var(--superficie); border: 1px solid var(--linea); border-radius: 12px; overflow: hidden; }
.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th, .tabla td { padding: 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--linea); overflow-wrap: anywhere; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla th { font-size: 12px; font-weight: 700; color: var(--texto-2); }
.tabla .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tabla .acc { text-align: right; white-space: nowrap; }
.progreso { display: flex; height: 14px; overflow: hidden; background: var(--superficie-2); border: 1px solid var(--linea); border-radius: 7px; }
.progreso span { display: block; height: 100%; min-width: 2px; }
.leyenda { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0; padding: 0; list-style: none; font-size: 12px; color: var(--texto-2); }
.leyenda li { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.campanas { display: grid; gap: 12px; min-width: 0; }
.pasos-w { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; font-size: 13px; color: var(--texto-2); }
.pasos-w li { display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px; background: var(--superficie); border: 1px solid var(--linea); border-radius: 999px; }
.pasos-w li[aria-current="step"] { background: var(--chip-bg); border-color: var(--chip-bg); color: var(--chip-txt); font-weight: 700; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; min-width: 0; }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { min-width: 0; display: grid; gap: 6px; padding: 16px; background: var(--superficie); border: 1px solid var(--linea); border-radius: 12px; }
.stat b { font-size: 32px; font-weight: 400; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat span { font-size: 12px; font-weight: 700; color: var(--texto-2); }
.resultado-imp { display: grid; gap: 10px; font-size: 14px; min-width: 0; }
.url-copia { padding: 10px 12px; background: var(--superficie-2); border: 1px solid var(--linea); border-radius: var(--radio); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.plegable { min-width: 0; }
.plegable > summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; font-weight: 700; }
.plegable[open] > summary { margin-bottom: 8px; }
.sub { padding: 14px; box-shadow: none; }
@media (max-width: 639px) {
  .tabla thead { display: none; }
  .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla tr { display: grid; gap: 8px; padding: 14px; border-bottom: 1px solid var(--linea); }
  .tabla tr:last-child { border-bottom: 0; }
  .tabla td { display: flex; justify-content: space-between; gap: 12px; padding: 0; border: 0; text-align: right; }
  .tabla td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--texto-2); text-align: left; }
  .tabla td.acc { justify-content: flex-start; }
  .tabla td.acc::before { display: none; }
  .tabla .num { white-space: normal; }
  .tabla-wrap { background: transparent; border: 0; overflow: visible; }
}

/* ---------- Entrar, crear contraseña, menú del usuario y tema ---------- */
body[data-entrada] .rail, body[data-entrada] .bottom { display: none; }
body[data-entrada] .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.entrada { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--fondo); }
.entrada-caja { width: min(100%, 400px); display: grid; gap: 16px; padding: 24px 20px; background: var(--superficie); border: 1px solid var(--linea); border-radius: 16px; }
.entrada-logo { display: block; width: 200px; max-width: 70%; height: auto; }
.logo-oscuro { display: none; }
:root[data-tema="oscuro"] .logo-claro { display: none; }
:root[data-tema="oscuro"] .logo-oscuro { display: block; }
.entrada h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.entrada form { display: grid; gap: 14px; }
.entrada .btn { width: 100%; }
.entrada .btn.mostrar { width: auto; flex: none; min-width: 88px; }
.entrada-nota { margin: 0; font-size: 14px; color: var(--texto-2); }
.clave { display: flex; gap: 8px; align-items: stretch; }
.clave input { flex: 1; }
.campo input[readonly] { background: var(--superficie-2); color: var(--texto-2); }
.reglas { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; font-size: 13px; }
.reglas li { display: flex; align-items: center; gap: 8px; color: var(--texto-2); }
.reglas li[data-ok="true"] { color: var(--texto); font-weight: 700; }
.reglas svg.i { width: 18px; height: 18px; }
.reglas li[data-ok="true"] svg.i { color: var(--env-bg); }
:root[data-tema="oscuro"] .reglas li[data-ok="true"] svg.i { color: var(--st-ent); }
.selector-tema { display: grid; gap: 6px; }
.selector-tema > span { font-size: 13px; font-weight: 700; }
.selector-tema .chips { flex-wrap: wrap; overflow: visible; }
.cuenta-datos { display: grid; gap: 2px; }
.cuenta-datos b { font-size: 16px; }
.cuenta-datos span { font-size: 13px; color: var(--texto-2); overflow-wrap: anywhere; }
.mas-bloque { display: grid; gap: 14px; margin-top: 16px; }
.fila-acc { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@media (max-width: 639px) { .fila-acc { justify-content: flex-start; } }
