:root{ --ldctx-brand:#0ea5e9; }

/* Overlay e card */
.ldctx-overlay{
  position:fixed; inset:0;
  background:rgba(0,0,0,.45);
  display:flex; align-items:center; justify-content:center;
  z-index:9999;
}
.ldctx-card{
  background:#fff;
  border-radius:16px;
  width:clamp(320px, 86vw, 600px);
  height:auto;
  max-height:80vh;
  box-shadow:0 10px 30px rgba(0,0,0,.25);
  overflow:auto;
  position:relative;
  display:flex; flex-direction:column;
  resize: both;                      /* ridimensionabile */
}

/* Header */
.ldctx-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:12px 14px;
  background:linear-gradient(135deg,var(--ldctx-brand),#6366f1);
  color:#fff;
  cursor:grab;
}
.ldctx-head:active{ cursor:grabbing; }
.ldctx-head .title{ font-weight:800; line-height:1; }
.ldctx-head .subtitle{ font-size:.85rem; opacity:.9; }
.ldctx-head .hd-right button{
  margin-left:6px; background:rgba(255,255,255,.2);
  border:0; color:#fff; border-radius:10px;
  width:32px; height:32px; cursor:pointer;
}

/* Body */
.ldctx-body{ padding:12px 14px; display:flex; flex-direction:column; gap:10px; }
.ldctx-log{
  flex:1 1 auto;
  min-height:220px;
  max-height:calc(80vh - 160px);
  overflow:auto;
  border:1px solid #eee; border-radius:10px;
  padding:10px; background:#fafafa;
}

/* Form */
.ldctx-form{ display:flex; gap:8px; align-items:flex-end; }
.ldctx-form .ldctx-q{
  flex:1; min-height:44px; max-height:180px; resize:vertical;
  padding:.6rem .75rem; border:1px solid #ddd; border-radius:10px;
}
.ldctx-form .ldctx-send{
  padding:.6rem 1rem; border-radius:10px; border:0;
  background:#111827; color:#fff; font-weight:700; cursor:pointer;
}

/* Messaggi */
.msg{ display:flex; gap:8px; align-items:flex-start; margin:.35rem 0; }
.av{
  width:28px; height:28px; display:inline-flex; align-items:center; justify-content:center;
  border-radius:50%; background:#e5e7eb; flex:0 0 28px;
}
.av-bot{ background:#dbeafe; }
.av-user{ background:#e5e7eb; }
.msg .bubble{
  background:#fff; border:1px solid #e5e7eb; border-radius:12px;
  padding:.5rem .65rem; max-width:92%;
  white-space:pre-wrap; word-wrap:break-word;
}
.msg.user .bubble{ background:#e0f2fe; border-color:#bae6fd; }
.msg.bot .bubble{ background:#fff; border-color:#e5e7eb; }

/* Typing */
.msg.bot.typing .bubble{ display:flex; align-items:center; gap:6px; }
.msg.bot.typing .dots{ display:inline-flex; gap:4px; }
.msg.bot.typing .dots i{
  width:6px; height:6px; background:#9ca3af; border-radius:50%;
  animation:ldctx-dots 1s infinite ease-in-out;
}
.msg.bot.typing .dots i:nth-child(2){ animation-delay:.15s; }
.msg.bot.typing .dots i:nth-child(3){ animation-delay:.3s; }
@keyframes ldctx-dots{ 0%,80%,100%{opacity:.2;transform:translateY(0)} 40%{opacity:1;transform:translateY(-2px)} }

/* FAB */
#ldctx-fab{
  position:fixed; right:18px; bottom:18px;
  padding:.75rem 1rem; border-radius:999px; border:0;
  background:var(--ldctx-brand,#0ea5e9); color:#fff; font-weight:800;
  z-index:9999; box-shadow:0 8px 20px rgba(0,0,0,.2); cursor:pointer;
}
#ldctx-fab.left{ right:auto; left:18px; }
#ldctx-fab:hover{ filter:brightness(1.05); }

/* Dark mode */
@media (prefers-color-scheme: dark){
  .ldctx-card{ background:#0b1020; }
  .ldctx-body{ background:#0b1020; }
  .ldctx-log{ background:#0f1428; border-color:#1f2640; }
  .msg .bubble{ background:#0f1428; border-color:#1f2640; color:#e5e7eb; }
  .msg.user .bubble{ background:#0d2030; border-color:#123447; }
}
