:root {
  --rojo: #D41800;
  --rojo-hover: #b51500;
  --negro: #0B0B0B;
  --fondo: #F4F3F1;
  --tarjeta: #FFFFFF;
  --texto: #141414;
  --tenue: #6B6B6B;
  --borde: #E2E0DC;
  --verde: #1E8E3E;
  --radio: 14px;
  --toque: 46px; /* altura mínima cómoda para el dedo */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; scroll-padding-top: 116px; }
html, body { margin: 0; }
body {
  font-family: 'Archivo', system-ui, -apple-system, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h2 { font-size: 19px; margin: 0 0 16px; font-weight: 800; letter-spacing: -0.01em; }
.tenue { color: var(--tenue); font-size: 14px; }

/* Marca */
.marca { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -0.01em; min-width: 0; }
.marca b { font-weight: 800; }
.marca__texto { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.marca__punto { width: 12px; height: 12px; border-radius: 3px; background: var(--rojo); flex: none; }
.marca--oscura { font-weight: 800; }

/* Barra superior */
.barra {
  position: sticky; top: 0; z-index: 10;
  padding: 10px 16px 0; padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
  background: var(--negro); color: #fff;
}
.barra__fila { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 820px; margin: 0 auto; }
.menu { display: flex; gap: 2px; max-width: 820px; margin: 8px auto 0; overflow-x: auto; scrollbar-width: none; }
.menu::-webkit-scrollbar { display: none; }
.menu a {
  flex: 1 0 auto; text-align: center; color: #bbb; text-decoration: none; font-size: 14px; font-weight: 700;
  padding: 10px 10px 11px; border-bottom: 3px solid transparent; white-space: nowrap;
}
.menu a:hover, .menu a:focus-visible { color: #fff; border-bottom-color: var(--rojo); }
.menu b { background: var(--rojo); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; margin-left: 3px; }
.barra__lado { display: flex; align-items: center; gap: 8px; flex: none; }
.pastilla {
  font-size: 13px; font-weight: 700; padding: 7px 11px; border-radius: 999px; text-decoration: none;
  background: #2a2a2a; color: #ddd; white-space: nowrap;
}
.pastilla--ok { background: rgba(30, 142, 62, .22); color: #7ee09a; }
.pastilla--mal { background: rgba(212, 24, 0, .28); color: #ffa799; }

/* Estructura */
.contenido {
  max-width: 820px; margin: 0 auto; display: grid; gap: 14px;
  padding: 14px 16px calc(32px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
}
.tarjeta { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 20px; min-width: 0; }
.banda {
  display: block; background: var(--rojo); color: #fff; text-decoration: none; font-weight: 700;
  padding: 13px 16px; border-radius: var(--radio);
}

/* Botones */
.boton {
  font: inherit; font-weight: 700; border: 0; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  min-height: var(--toque); touch-action: manipulation;
}
.boton--primario { background: var(--rojo); color: #fff; font-size: 17px; }
.boton--primario:hover { background: var(--rojo-hover); }
.boton--primario:disabled { opacity: .6; cursor: wait; }
.boton--ancho { width: 100%; }
.boton--fantasma { background: transparent; color: #fff; border: 1px solid #444; padding: 7px 12px; font-size: 14px; min-height: 36px; }
.boton--chico { font-size: 14px; padding: 9px 14px; min-height: 40px; background: var(--negro); color: #fff; }
.boton--chico:hover { background: #333; }

/* Formulario */
.formulario { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.campo { display: grid; gap: 6px; min-width: 0; }
.campo > span, .buscador > label { font-size: 14px; font-weight: 700; }
.campo em, .buscador em { font-style: normal; font-weight: 400; color: var(--tenue); }
.campo--ancho { grid-column: 1 / -1; }
/* 16px evita que el iPhone haga zoom al tocar un campo */
input, textarea, select {
  font: inherit; font-size: 16px; width: 100%; min-width: 0; min-height: var(--toque);
  padding: 11px 13px; border: 1px solid var(--borde); border-radius: 12px; background: #fff; color: var(--texto);
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--tenue) 50%), linear-gradient(135deg, var(--tenue) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px;
}
input[type="date"], input[type="time"] { display: block; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--rojo); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 120px; }
.fecha-hora { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.atajos { display: flex; flex-wrap: wrap; gap: 8px; }
.atajos button {
  font: inherit; font-size: 14px; font-weight: 700; padding: 8px 14px; min-height: 40px; border-radius: 999px;
  border: 1px solid var(--borde); background: var(--fondo); color: var(--texto); cursor: pointer; touch-action: manipulation;
}
.atajos button:hover, .atajos button:active { border-color: var(--rojo); color: var(--rojo); }
.reloj { margin: -6px 0 0; }
.acciones { display: grid; gap: 10px; }
.aviso { margin: 0; font-size: 15px; font-weight: 700; color: var(--verde); }
.aviso--error { color: var(--rojo); }

/* Buscador de contactos */
.buscador { position: relative; display: grid; gap: 6px; }
.buscador__lista {
  position: absolute; z-index: 6; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--borde); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.14);
  max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.buscador__lista li {
  padding: 10px 12px; min-height: var(--toque); border-radius: 10px; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.buscador__lista li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.buscador__lista li small { color: var(--tenue); white-space: nowrap; font-size: 13px; }
.buscador__lista li:hover, .buscador__lista li.activo { background: var(--fondo); }
.buscador__lista li.sin { color: var(--tenue); cursor: default; }
.elegido {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #E6F4EA; color: var(--verde); border-radius: 10px; padding: 8px 12px; font-size: 14px; font-weight: 700;
}

/* Pestañas */
.pestanas { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin: -4px -4px 12px; overflow-x: auto; scrollbar-width: none; }
.pestanas::-webkit-scrollbar { display: none; }
.pestanas button {
  font: inherit; font-weight: 700; background: none; border: 0; padding: 12px 12px; min-height: var(--toque); cursor: pointer; color: var(--tenue);
  border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; flex: none;
}
.pestanas button.activa { color: var(--texto); border-bottom-color: var(--rojo); }
.pestanas b { font-size: 12px; background: var(--fondo); padding: 2px 8px; border-radius: 999px; margin-left: 4px; }

/* Lista de mensajes */
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.mensaje { border: 1px solid var(--borde); border-radius: 12px; padding: 14px; display: grid; gap: 8px; min-width: 0; }
.mensaje__cabeza { display: flex; justify-content: space-between; align-items: baseline; gap: 4px 10px; flex-wrap: wrap; }
.mensaje__quien { font-weight: 800; min-width: 0; overflow-wrap: anywhere; }
.mensaje__quien small { font-weight: 500; color: var(--tenue); margin-left: 6px; }
.mensaje__cuando { font-size: 14px; font-weight: 700; color: var(--rojo); }
.mensaje__desde { font-size: 13px; font-weight: 600; color: var(--tenue); }
.mensaje__texto { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--fondo); border-radius: 10px; padding: 10px 12px; margin: 0; }
.mensaje__detalle { font-size: 14px; color: var(--rojo); margin: 0; }
.mensaje__acciones, .cuenta__acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.mensaje__acciones button, .cuenta__acciones button {
  font: inherit; font-size: 14px; font-weight: 700; padding: 8px 14px; min-height: 40px; border-radius: 10px;
  border: 1px solid var(--borde); background: #fff; cursor: pointer; color: var(--texto); touch-action: manipulation;
}
.mensaje__acciones button:hover, .cuenta__acciones button:hover { border-color: var(--texto); }
.peligro { color: var(--rojo) !important; }
.vacio { text-align: center; padding: 18px 0 6px; margin: 0; }

/* Cuentas */
.titulo-fila { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.titulo-fila h2 { margin: 0; }
.cuentas { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.cuenta { border: 1px solid var(--borde); border-radius: 12px; padding: 14px; display: grid; gap: 12px; min-width: 0; }
.cuenta--qr { border-color: var(--rojo); }
.cuenta__fila { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.cuenta__nombre { font-weight: 800; min-width: 0; overflow-wrap: anywhere; }
.cuenta__nombre small { display: block; font-weight: 500; color: var(--tenue); font-size: 14px; }
.cuenta__estado { font-size: 12px; font-weight: 800; padding: 5px 10px; border-radius: 999px; background: #FBE9E6; color: var(--rojo); white-space: nowrap; flex: none; }
.cuenta__estado--ok { background: #E6F4EA; color: var(--verde); }
.cuenta__qr { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.cuenta__qr img, .cuenta__qr .qr-espera { width: 220px; height: 220px; border: 1px solid var(--borde); border-radius: 12px; background: #fff; }
.qr-espera { display: grid; place-items: center; color: var(--tenue); font-size: 14px; }
.ayuda { margin-top: 14px; font-size: 15px; }
.ayuda summary { cursor: pointer; font-weight: 700; color: var(--tenue); min-height: 32px; }
.ayuda ol { margin: 10px 0 6px; padding-left: 20px; }

/* Entrada */
.entrar { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: var(--negro); }
.entrar__caja { width: min(400px, 100%); display: grid; gap: 18px; }

/* ---- Celular ---- */
@media (max-width: 640px) {
  .contenido { gap: 12px; padding-top: 12px; }
  .tarjeta { padding: 16px; border-radius: 16px; }
  .formulario { grid-template-columns: 1fr; gap: 14px; }
  .marca__texto b { display: none; }
  /* En el celular la lista de resultados va dentro de la página, no flotando:
     el teclado no la tapa y se recorre con el dedo. */
  .buscador__lista { position: static; box-shadow: none; max-height: 52vh; margin-top: 2px; }
  .buscador__lista li { min-height: 52px; }
  .atajos button { flex: 1 1 auto; }
  .pestanas { margin: -4px -6px 12px; }
  .pestanas button { flex: 1 1 auto; padding: 12px 2px; font-size: 13px; }
  .pestanas b { margin-left: 1px; padding: 1px 5px; font-size: 11px; }
  .mensaje__acciones button, .cuenta__acciones button { flex: 1 1 auto; min-height: var(--toque); }
  .titulo-fila .boton--chico { width: 100%; }
  .cuenta__qr { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .cuenta__qr img, .cuenta__qr .qr-espera { width: min(260px, 100%); height: auto; aspect-ratio: 1; }
}

@media (max-width: 360px) {
  .fecha-hora { grid-template-columns: 1fr; }
  .pastilla { font-size: 12px; padding: 6px 9px; }
}

/* ===== Componentes del envío ===== */
.etiqueta { font-size: 14px; font-weight: 700; }
.nota { margin: 0; }
.boton--gris { background: var(--fondo); color: var(--texto); border: 1px solid var(--borde); }
.boton-texto {
  font: inherit; font-size: 14px; font-weight: 700; background: none; border: 0; padding: 8px 4px; cursor: pointer;
  color: var(--tenue); text-decoration: underline; text-underline-offset: 3px; min-height: 40px;
}

/* Destinatarios elegidos */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--fondo); border: 1px solid var(--borde); border-radius: 999px; padding: 4px 4px 4px 12px; font-size: 14px; font-weight: 600;
}
.chip--lista { background: #FFF1EE; border-color: #F6C7BE; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip small { color: var(--tenue); font-weight: 500; }
.chip button {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 0; background: transparent; cursor: pointer;
  font-size: 18px; line-height: 1; color: var(--tenue);
}
.chip button:hover { background: rgba(0,0,0,.06); color: var(--texto); }
.buscador__lista li .tipo { font-size: 11px; font-weight: 800; color: var(--rojo); text-transform: uppercase; letter-spacing: .04em; margin-right: 6px; }

/* Adjuntos */
.adjuntar { display: flex; flex-wrap: wrap; gap: 8px; }
.boton-adjunto {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 auto;
  font: inherit; font-size: 14px; font-weight: 700; padding: 10px 14px; min-height: var(--toque);
  border: 1px dashed #C9C6C0; border-radius: 12px; background: #fff; color: var(--texto); cursor: pointer; touch-action: manipulation;
}
.boton-adjunto:hover { border-color: var(--rojo); color: var(--rojo); }
.grabando, .subiendo, .adjunto {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  border: 1px solid var(--borde); border-radius: 12px; padding: 10px 12px; background: var(--fondo);
}
.grabando { border-color: var(--rojo); background: #FFF1EE; }
.grabando__punto { width: 12px; height: 12px; border-radius: 50%; background: var(--rojo); animation: latido 1s infinite; }
@keyframes latido { 50% { opacity: .25; } }
.grabando .boton { min-height: 40px; padding: 8px 16px; font-size: 15px; margin-left: auto; }
.subiendo progress { flex: 1 1 120px; height: 8px; accent-color: var(--rojo); }
.adjunto img { width: 88px; height: 88px; object-fit: cover; border-radius: 10px; border: 1px solid var(--borde); background: #fff; }
.adjunto audio { flex: 1 1 200px; min-width: 0; height: 40px; }
.adjunto__info { flex: 1 1 140px; min-width: 0; font-size: 14px; }
.adjunto__info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Ritmo */
.ritmo { border: 1px solid var(--borde); border-radius: 12px; background: #FCFBFA; }
.ritmo summary {
  cursor: pointer; padding: 12px 14px; min-height: var(--toque); font-weight: 700; list-style: none;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
}
.ritmo summary::-webkit-details-marker { display: none; }
.ritmo summary::before { content: '▸'; color: var(--rojo); transition: transform .15s; }
.ritmo[open] summary::before { transform: rotate(90deg); }
.ritmo summary em { font-style: normal; font-weight: 500; color: var(--tenue); font-size: 14px; }
.ritmo__cuerpo { padding: 0 14px 14px; display: grid; gap: 12px; }
.ritmo__cuerpo > p { margin: 0; }
.rango { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rango legend { font-size: 14px; font-weight: 700; padding: 0; margin-bottom: 6px; width: 100%; }
.rango label { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--tenue); }
.rango input { width: 88px; text-align: center; }
.rango span { font-size: 14px; color: var(--tenue); }
.rango em { font-style: normal; }
.ritmo__pie { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.ritmo__pie p { margin: 0; font-weight: 600; color: var(--texto); }

/* Tarjeta de envío */
.envio { border: 1px solid var(--borde); border-radius: 12px; padding: 14px; display: grid; gap: 10px; min-width: 0; }
.envio--curso { border-color: var(--rojo); }
.envio__cabeza { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px 10px; flex-wrap: wrap; }
.envio__titulo { font-weight: 800; min-width: 0; overflow-wrap: anywhere; }
.envio__titulo small { display: block; font-weight: 500; color: var(--tenue); font-size: 13px; }
.insignia { font-size: 12px; font-weight: 800; padding: 4px 10px; border-radius: 999px; white-space: nowrap; background: var(--fondo); color: var(--tenue); }
.insignia--curso { background: #FFF1EE; color: var(--rojo); }
.insignia--ok { background: #E6F4EA; color: var(--verde); }
.envio__meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--tenue); font-weight: 600; }
.envio__meta b { color: var(--texto); }
.progreso { height: 8px; border-radius: 999px; background: var(--fondo); overflow: hidden; display: flex; }
.progreso i { display: block; height: 100%; }
.progreso .ok { background: var(--verde); }
.progreso .mal { background: var(--rojo); }
.progreso .omit { background: #C9C6C0; }
.envio__contenido { display: flex; gap: 10px; align-items: flex-start; background: var(--fondo); border-radius: 10px; padding: 10px; min-width: 0; }
.envio__contenido img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.envio__contenido p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; flex: 1; }
.envio__contenido .audio { font-weight: 700; font-size: 14px; }
.envio__contenido audio { width: 100%; height: 36px; margin-top: 6px; }
.envio__siguiente { font-size: 14px; font-weight: 700; color: var(--rojo); margin: 0; }
.envio details summary { cursor: pointer; font-size: 14px; font-weight: 700; color: var(--tenue); min-height: 32px; }
.destinatarios { list-style: none; margin: 8px 0 0; padding: 0; max-height: 320px; overflow-y: auto; border: 1px solid var(--borde); border-radius: 10px; }
.destinatarios li { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; font-size: 14px; border-bottom: 1px solid var(--borde); }
.destinatarios li:last-child { border-bottom: 0; }
.destinatarios li span { min-width: 0; overflow-wrap: anywhere; }
.destinatarios li small { display: block; color: var(--rojo); }
.destinatarios .e { white-space: nowrap; font-weight: 700; font-size: 13px; }
.e--enviado { color: var(--verde); }
.e--error { color: var(--rojo); }
.e--pendiente, .e--omitido { color: var(--tenue); }

/* Listas */
.nota-listas { margin: -6px 0 14px; }
.listas { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lista-item { border: 1px solid var(--borde); border-radius: 12px; padding: 12px 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lista-item__nombre { flex: 1 1 160px; min-width: 0; font-weight: 800; overflow-wrap: anywhere; }
.lista-item__nombre small { display: block; font-weight: 500; color: var(--tenue); font-size: 13px; }
.lista-item__acciones { display: flex; gap: 8px; flex-wrap: wrap; }
.lista-item__acciones button {
  font: inherit; font-size: 14px; font-weight: 700; padding: 8px 14px; min-height: 40px; border-radius: 10px;
  border: 1px solid var(--borde); background: #fff; cursor: pointer; color: var(--texto);
}
.lista-item__acciones .usar { background: var(--negro); color: #fff; border-color: var(--negro); }
.editor { display: grid; gap: 14px; border: 2px solid var(--negro); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.pegar summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--tenue); min-height: 32px; }
.pegar textarea { margin: 8px 0; min-height: 110px; }
.pegar p { margin: 8px 0 0; }
.miembros__cabeza { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.miembros { list-style: none; margin: 0; padding: 0; max-height: 46vh; overflow-y: auto; border: 1px solid var(--borde); border-radius: 12px; }
.miembros:empty::after { content: 'Aún no hay contactos en esta lista.'; display: block; padding: 14px; color: var(--tenue); font-size: 14px; }
.miembros li { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--borde); font-size: 15px; }
.miembros li:last-child { border-bottom: 0; }
.miembros li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.miembros li small { color: var(--tenue); white-space: nowrap; font-size: 13px; }
.miembros li button { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: none; font-size: 20px; color: var(--tenue); cursor: pointer; }
.miembros li button:hover { background: var(--fondo); color: var(--rojo); }
.editor__acciones { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.editor__acciones .boton--primario { flex: 1 1 160px; }

@media (max-width: 640px) {
  .rango input { width: 76px; }
  .editor { padding: 14px; margin-left: -4px; margin-right: -4px; }
  .lista-item__acciones { width: 100%; }
  .lista-item__acciones button { flex: 1 1 auto; min-height: var(--toque); }
  .grabando .boton { margin-left: 0; flex: 1; }
}
