:root {
  --marca: #e72419;
  --marca-oscuro: #b51f27;
  --fondo: #f4f4f6;
  --linea: #e2e2e6;
  --tinta: #2b2c2e;
  --tenue: #6e7073;
  --ok: #1f8a4c;
  --azul: #2563eb;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", "Open Sans", system-ui, -apple-system, sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.oculto { display: none !important; }
button { font: inherit; cursor: pointer; }
.ayuda, .sub { color: var(--tenue); font-size: .85rem; }
.msg { min-height: 1.2em; font-size: .9rem; margin: .3rem 0; }
.msg.error { color: var(--marca-oscuro); font-weight: 600; }
input, textarea {
  width: 100%; font: inherit; color: inherit; background: #fff;
  border: 1px solid var(--linea); border-radius: 10px; padding: .7rem .8rem; outline: none;
}
input:focus, textarea:focus { border-color: var(--marca); }
label { display: block; font-weight: 600; font-size: .9rem; margin: .8rem 0 .3rem; }
label > input { margin-top: .3rem; font-weight: 400; }
.primario {
  width: 100%; border: 0; border-radius: 10px; background: var(--marca); color: #fff;
  font-weight: 700; padding: .8rem 1rem;
}
.primario:active { background: var(--marca-oscuro); }
.primario:disabled { opacity: .5; }
.enlace { background: none; border: 0; color: var(--tenue); text-decoration: underline; margin-top: .8rem; width: 100%; }

/* Entrar */
.entrar { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.caja { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; padding: 24px; box-shadow: 0 6px 24px rgb(0 0 0 / .08); }
.caja h1 { margin: .4rem 0; font-size: 1.5rem; }
.logo { width: 56px; height: 56px; border-radius: 14px; }
.codigo { font-size: 1.6rem; letter-spacing: .5em; text-align: center; }

/* Pantallas */
.pantalla { height: 100%; display: flex; flex-direction: column; }
.barra {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--tinta); color: #fff;
}
.barra .titulo { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.barra .titulo b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barra .sub { color: rgb(255 255 255 / .7); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icono { background: none; border: 0; color: #fff; font-size: 1.4rem; width: 40px; height: 40px; border-radius: 50%; }
.icono:active { background: rgb(255 255 255 / .15); }
.chip { border: 1px solid rgb(255 255 255 / .35); background: none; color: #fff; border-radius: 999px; padding: .35rem .8rem; font-size: .8rem; white-space: nowrap; }
.chip.activo { border-color: var(--ok); background: var(--ok); }
.menu { background: #fff; border-bottom: 1px solid var(--linea); padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.menu button { border: 1px solid var(--linea); background: #fff; border-radius: 8px; padding: .4rem .8rem; }
.aviso { margin: 0; padding: 10px 16px; background: #fff7e6; color: #7a4b00; font-size: .85rem; border-bottom: 1px solid #f3dfb7; }

.pestanas { display: flex; background: #fff; border-bottom: 1px solid var(--linea); }
.pestanas button { flex: 1; border: 0; background: none; padding: .8rem; font-weight: 600; color: var(--tenue); border-bottom: 3px solid transparent; }
.pestanas button.activa { color: var(--marca); border-bottom-color: var(--marca); }
.cuenta { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--marca); color: #fff; font-size: .75rem; }

.chats { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chats li button {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--linea); background: #fff;
  padding: 12px 16px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
}
.chats li button:active { background: var(--fondo); }
.chats .nombre { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats .hora { color: var(--tenue); font-size: .75rem; }
.chats .ultimo { color: var(--tenue); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chats .estado { font-size: .75rem; font-weight: 700; border-radius: 6px; padding: 1px 6px; justify-self: end; align-self: center; }
.estado.esperando { background: var(--marca); color: #fff; }
.estado.mia { background: var(--ok); color: #fff; }
.estado.otro { background: var(--linea); color: var(--tinta); }
.estado.cerrada { background: var(--linea); color: var(--tenue); }
.chats .nuevo .nombre::before { content: "● "; color: var(--marca); }
.vacio { text-align: center; color: var(--tenue); padding: 40px 16px; }

/* Conversación */
.contexto { margin: 0; padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--linea); font-size: .85rem; color: var(--tenue); }
.mensajes { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.globo { max-width: 82%; padding: 8px 12px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; box-shadow: 0 1px 2px rgb(0 0 0 / .06); }
.globo small { display: block; font-size: .7rem; opacity: .7; margin-top: 2px; }
.globo.cliente { background: #fff; align-self: flex-start; border-top-left-radius: 4px; }
.globo.agente { background: var(--marca); color: #fff; align-self: flex-end; border-top-right-radius: 4px; }
.globo.sistema { align-self: center; background: none; box-shadow: none; color: var(--tenue); font-size: .8rem; text-align: center; }
.pie { background: #fff; border-top: 1px solid var(--linea); padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.pie .sub { margin: 0 0 8px; text-align: center; }
.escribir { display: flex; gap: 8px; align-items: flex-end; }
.escribir textarea { resize: none; max-height: 120px; border-radius: 20px; }
.enviar { width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 50%; background: var(--marca); color: #fff; font-size: 1.1rem; }
.enviar:disabled { opacity: .4; }
