:root{
  --bg:#0b1220;
  --card:#121a2b;
  --muted:#6e7a96;
  --txt:#eaf2ff;
  --accent:#18c37d;
  --accent-2:#3478f6;
  --danger:#e24d4d;
  --line:#22304a;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;font:14px/1.4 system-ui,Segoe UI,Roboto,Helvetica,Arial;
  color:var(--txt);background:var(--bg);
}

/* top */
.topbar{
  display:flex;align-items:center;justify-content:space-between;
  gap:12px;padding:12px 16px;border-bottom:1px solid var(--line);
  background:rgba(0,0,0,.15);backdrop-filter:saturate(1.2) blur(6px);
  position:sticky;top:0;z-index:10;
}
.brand{display:flex;align-items:center;gap:8px}
.logo{font-size:18px}
.name{font-weight:700}
.badge{background:#1e293b;color:#94a3b8;padding:2px 8px;border-radius:999px;font-size:12px}
.dot{width:8px;height:8px;border-radius:50%}
.dot.offline{background:#8b5cf6}
.dot.online{background:#22c55e}
.net{color:var(--muted);font-size:12px;margin-left:6px}
.right-actions{display:flex;gap:8px}

/* layout */
.container{display:grid;grid-template-columns:280px 1fr;gap:18px;padding:16px}
.left .card{position:sticky;top:68px}

.card{
  background:var(--card);border:1px solid var(--line);border-radius:12px;
  padding:14px
}
.title{margin:0 0 10px 0}
.row{display:flex;align-items:center}
.space-between{justify-content:space-between}
.gap{gap:10px}
.mt{margin-top:10px}
.end{justify-content:flex-end}
.items-center{align-items:center}
.grow{flex:1 1 auto}

/* buttons */
button{
  border:1px solid var(--line);background:#162238;color:var(--txt);
  padding:8px 12px;border-radius:10px;cursor:pointer;transition:.12s all
}
button:hover{filter:brightness(1.05)}
button.primary{background:var(--accent);border-color:transparent;color:#07130e}
button.secondary{background:#162238}
button.danger{background:var(--danger);border-color:#000;color:#fff}
button.pill{border-radius:999px;padding:6px 10px}
button.hidden{display:none}

/* inputs */
input[type="text"], input[type="file"], textarea{
  background:#0d1526;border:1px solid var(--line);color:var(--txt);
  padding:10px;border-radius:10px;width:100%
}
textarea{resize:vertical}

/* check */
.check{display:flex;align-items:center;gap:6px;color:var(--muted)}
.check input{transform:translateY(1px)}

/* lists */
.conv-list{display:flex;flex-direction:column;gap:8px;max-height:60vh;overflow:auto}
.conv-item{display:flex;align-items:center;justify-content:space-between;gap:8px;border:1px solid var(--line);background:#0f192a;border-radius:10px;padding:8px}
.conv-title{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;color:#cfe0ff}

/* chat */
.chat{height:42vh;overflow:auto;border:1px solid var(--line);border-radius:10px;background:#0d1526;padding:10px}
.msg{display:flex;gap:8px;margin-bottom:10px}
.msg .role{width:28px;text-align:center;opacity:.8}
.msg .bubble{flex:1;background:#0f1b31;border:1px solid var(--line);padding:10px;border-radius:10px}
.msg.user .bubble{background:#0e2a19;border-color:#153524}
.msg.assistant .bubble{background:#0f1b31}

/* composer */
.composer{margin-top:10px;display:flex;flex-direction:column;gap:10px}

/* table admin (reutilizable) */
.table-wrap{overflow:auto;max-height:60vh;margin-top:8px}
.table{border-collapse:collapse;width:100%;min-width:840px}
.table th,.table td{border:1px solid var(--line);padding:8px}
.table th{background:#101a2a;text-align:left}

/* foot */
.foot{border-top:1px solid var(--line);padding:16px;text-align:center;color:var(--muted)}

/* helpers */
.hidden{display:none}

@media (max-width: 960px){
  .container{grid-template-columns:1fr}
  .left .card{position:static}
  .chat{height:36vh}
}
/* Burbujas del cliente mp */
#mp-out{display:flex;flex-direction:column;gap:8px}
.mp-msg{padding:10px 12px;border-radius:12px;max-width:80ch;line-height:1.35}
.mp-msg.mp-user{align-self:flex-end;background:#2563eb;color:#fff}
.mp-msg.mp-assistant{align-self:flex-start;background:#374151;color:#fff}
/* Indicador connectivity (usa clases del body) */
body.is-offline #mp-out{opacity:.6;filter:grayscale(20%)}
/* === mp-client bubbles === */
.mp-log,#mp-out{display:flex;flex-direction:column;gap:8px;padding:8px;max-height:60vh;overflow:auto}
.mp-msg{padding:10px 12px;border-radius:12px;max-width:72ch;line-height:1.35;word-wrap:break-word}
.mp-msg.mp-user{align-self:flex-end;background:#2563eb;color:#fff}
.mp-msg.mp-assistant{align-self:flex-start;background:#374151;color:#fff}
/* Estado conectividad */
body.is-offline .mp-msg{opacity:.8;filter:grayscale(10%)}


/* --- Polished tweaks (accesibilidad & microinteracciones) --- */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
button { transition: transform .06s ease; }
button:active { transform: translateY(1px); }
textarea { outline: none; border: 1px solid var(--line); }
textarea:focus { border-color: var(--accent-2); box-shadow: 0 0 0 2px rgba(52,120,246,.25); }
html{scroll-behavior:smooth}
#chatlog, #log, #messages, #chat, #conversation, #history {
  display: flex; flex-direction: column-reverse;
}
#chatlog, #log, #messages, #chat, #conversation, #history {
  display:flex; flex-direction:column; justify-content:flex-end;
}
/* Pegamos el compositor al fondo */
#composer, .chat-input, .footer {
  position: sticky; bottom: 0; z-index: 50;
  background: rgba(10,10,14,.85); backdrop-filter: blur(6px);
}

/* --- MP UX patch --- */
.chat-log, .messages, .conversation, main {
  display: flex; flex-direction: column;
}
.chat-log, .messages, .conversation {
  overflow-y: auto; min-height: 50vh;
}

/* Forcea el área de conversación a crecer y permitir scroll global */
.chat, .chat-log, .messages, .content {
  max-height: none !important;
  overflow: visible !important;
}
