:root {
  --fondo: #f6f3ef; --tarjeta: #fff; --tinta: #2b2438; --suave: #776f85; --borde: #e6e0d8; --acento: #6f44a8; --acento-suave: #efe7fa;
  --ok: #1d8a4e; --mal: #b4453a; --aviso: #b07a12; --monge: #6f44a8; --sobre-monge: #fff; --radio: 14px;
  --sombra: 0 2px 10px rgba(43, 36, 56, 0.07);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --fondo: #17141d; --tarjeta: #221e2a; --tinta: #ece7f3; --suave: #a49db0; --borde: #352f40; --acento: #b48ef0; --acento-suave: #2e2540;
    --ok: #5fd18f; --mal: #f08a7e; --aviso: #f0c46e; --monge: #5b3a8c; --sombra: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--fondo); color: var(--tinta); font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
body.en-chat { padding-bottom: 0; }
a { color: var(--acento); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
#app { max-width: 720px; margin: 0 auto; padding: 12px 14px; }
.cargando, .vacio { text-align: center; color: var(--suave); padding: 40px 10px; }
h1 { font-size: 22px; margin: 6px 0 12px; display: flex; align-items: center; gap: 10px; }
h1 .accion { margin-left: auto; }
.boton { border: 0; border-radius: 999px; background: var(--acento); color: #fff; padding: 10px 18px; font-weight: 600; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.boton.claro { background: var(--acento-suave); color: var(--acento); }
.boton.peligro { background: transparent; color: var(--mal); border: 1px solid var(--mal); }
.boton.ok { background: var(--ok); }
.boton.mini { min-height: 34px; padding: 6px 12px; font-size: 14px; }
.boton:disabled { opacity: 0.5; }
.campo { width: 100%; border: 1px solid var(--borde); border-radius: 12px; background: var(--tarjeta); padding: 11px 12px; }
.tarjeta { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; box-shadow: var(--sombra); }
.lista { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.fila { display: block; text-decoration: none; color: inherit; }
.fila .arriba { display: flex; gap: 8px; align-items: baseline; }
.fila b { font-size: 16px; }
.fila .cuando { margin-left: auto; color: var(--suave); font-size: 12px; white-space: nowrap; }
.fila p { margin: 4px 0 0; color: var(--suave); font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--acento-suave); color: var(--acento); white-space: nowrap; }
.chip.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.mal { background: color-mix(in srgb, var(--mal) 15%, transparent); color: var(--mal); }
.chip.aviso { background: color-mix(in srgb, var(--aviso) 18%, transparent); color: var(--aviso); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* pestañas abajo */
.pestanas { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--tarjeta); border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.pestanas a { flex: 1; display: grid; justify-items: center; padding: 8px 0 6px; text-decoration: none; color: var(--suave); font-size: 20px; position: relative; }
.pestanas a span { font-size: 11px; }
.pestanas a.activa { color: var(--acento); }
.globo { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--mal); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; min-width: 18px; text-align: center; }

/* login */
.login { max-width: 340px; margin: 18vh auto 0; display: grid; gap: 12px; text-align: center; }
.login h1 { justify-content: center; font-size: 28px; }
.error { color: var(--mal); font-size: 14px; min-height: 1em; }

/* chat */
.chat { display: flex; flex-direction: column; height: 100dvh; max-width: 720px; margin: 0 auto; }
#app.chat-app { padding: 0; max-width: none; }
.chat header { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--borde); background: var(--tarjeta); }
.chat header .titulo { flex: 1; min-width: 0; }
.chat header .titulo b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat header .titulo small { color: var(--suave); font-size: 12px; }
.volver { font-size: 24px; text-decoration: none; padding: 0 6px; color: var(--tinta); }
.mensajes { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; overscroll-behavior: contain; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 16px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.monge { align-self: flex-end; background: var(--monge); color: var(--sobre-monge); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.agente { align-self: flex-start; background: var(--tarjeta); border: 1px solid var(--borde); border-bottom-left-radius: 4px; }
.msg.agente p { margin: 0 0 8px; } .msg.agente p:last-child { margin-bottom: 0; }
.msg.agente ul, .msg.agente ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.agente code { background: var(--acento-suave); padding: 0 4px; border-radius: 4px; font-size: 0.9em; }
.msg.agente pre { background: var(--acento-suave); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; }
.msg.agente h3, .msg.agente h4 { margin: 8px 0 4px; font-size: 16px; }
.msg img.captura { display: block; max-width: 100%; max-height: 70vh; border-radius: 10px; margin: 6px 0; border: 1px solid var(--borde); }
.msg.herramienta { align-self: flex-start; color: var(--suave); font-size: 13px; padding: 2px 10px; }
.herramientas { align-self: flex-start; color: var(--suave); font-size: 13px; }
.herramientas summary { cursor: pointer; padding: 2px 10px; list-style: none; }
.herramientas summary::-webkit-details-marker { display: none; }
.herramientas div { padding: 1px 10px; }
.msg.sistema { align-self: center; color: var(--suave); font-size: 13px; text-align: center; white-space: pre-wrap; max-width: 100%; }
.msg.sistema.largo { align-self: stretch; text-align: left; font-family: ui-monospace, monospace; font-size: 12px; background: var(--tarjeta); border: 1px dashed var(--borde); }
.adjuntos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.adjuntos img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; }
.adjuntos span { font-size: 13px; background: rgba(255,255,255,0.18); padding: 2px 8px; border-radius: 8px; }
.pensando { align-self: flex-start; color: var(--suave); font-size: 14px; padding: 4px 10px; }
.pensando::after { content: '…'; animation: puntos 1.2s infinite steps(4); display: inline-block; width: 1.2em; text-align: left; overflow: hidden; vertical-align: bottom; }
@keyframes puntos { 0% { width: 0; } 100% { width: 1.2em; } }
.escribir { border-top: 1px solid var(--borde); background: var(--tarjeta); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 6px; }
.escribir .linea { display: flex; gap: 8px; align-items: flex-end; }
.escribir textarea { flex: 1; resize: none; max-height: 40vh; min-height: 42px; border-radius: 20px; padding: 10px 14px; }
.clip { font-size: 22px; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--borde); background: var(--fondo); display: grid; place-items: center; flex: none; }
.enviar { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--acento); color: #fff; font-size: 18px; flex: none; }
.por-subir { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13px; }
.por-subir span { background: var(--acento-suave); color: var(--acento); border-radius: 8px; padding: 2px 8px; }
.progreso { height: 3px; background: var(--acento); width: 0; transition: width 0.2s; border-radius: 2px; }

/* solicitudes */
.solicitud { border: 2px solid var(--acento); }
.solicitud .acciones { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.solicitud img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; margin-top: 8px; background: var(--fondo); }
.solicitud pre { white-space: pre-wrap; font-size: 12px; background: var(--fondo); padding: 8px; border-radius: 8px; max-height: 40vh; overflow: auto; }
.solicitud.publicada { border-color: var(--ok); } .solicitud.error { border-color: var(--mal); } .solicitud.descartada { border-color: var(--borde); opacity: 0.7; }
.msg.solicitud-msg { align-self: stretch; max-width: 100%; padding: 0; }

/* invitaciones */
.buscador { display: grid; gap: 8px; margin-bottom: 12px; }
.filtros { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; }
.filtros button { border: 1px solid var(--borde); background: var(--tarjeta); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; }
.filtros button.activo { background: var(--acento); color: #fff; border-color: var(--acento); }
.detalle .botones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.detalle dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 10px 0 0; }
.detalle dt { color: var(--suave); } .detalle dd { margin: 0; overflow-wrap: anywhere; }
.aviso-barra { background: color-mix(in srgb, var(--aviso) 15%, var(--tarjeta)); border: 1px solid var(--aviso); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.hoja { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: flex-end; z-index: 20; }
.hoja > div { background: var(--fondo); width: 100%; max-width: 720px; margin: 0 auto; border-radius: 18px 18px 0 0; padding: 16px 14px calc(16px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow-y: auto; display: grid; gap: 10px; }
.hoja label { display: grid; gap: 4px; font-size: 14px; color: var(--suave); }
