@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

:root{
  --poscali-blue:#0047ba; --poscali-navy:#011e41; --poscali-gray:#333333;
  --surface:#ffffff; --surface-alt:#f5f8ff; --stroke:#e6eefc;
  --shadow:0 10px 30px rgba(1,30,65,.08);
}

/* Contenedor único (tarjeta) */
.aichat-wrap{
  max-width:1100px;
  margin:24px auto;
  background:linear-gradient(180deg,#fff 0%, #f8fbff 100%);
  border:1px solid var(--stroke);
  border-radius:16px;
  box-shadow:var(--shadow);
  overflow:hidden;
  font-family:'Poppins',system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
}

/* Header del contenedor */
.aichat-header{
  padding:18px 20px;
  background:linear-gradient(135deg,var(--poscali-navy),var(--poscali-blue));
  color:#fff; border-bottom:1px solid rgba(255,255,255,.08);
}
.aichat-title{ font-size:20px; font-weight:600; letter-spacing:.2px }
.aichat-sub{ font-size:13px; opacity:.85; margin-top:2px }

/* Cuerpo en dos columnas dentro del mismo contenedor */
.aichat-body{
  display:grid;
  grid-template-columns: 280px 1fr;
  gap:16px;
  padding:16px;
}

/* Sidebar */
.aichat-sidebar{
  display:flex; flex-direction:column; overflow:hidden; min-height:520px;
  background:#fff; border:1px solid var(--stroke); border-radius:12px;
  box-shadow:0 6px 18px rgba(1,30,65,.06);
}
.aichat-side-header{
  display:flex; align-items:center; justify-content:space-between;
  padding:10px 12px; font-weight:600; color:var(--poscali-navy);
  border-bottom:1px solid var(--stroke);
  background:linear-gradient(180deg,#fff,#f9fbff);
}
.aichat-side-tools{ display:flex; align-items:center; gap:6px }

/* Lista hilos */
.aichat-threads{ overflow:auto; padding:8px }
.aichat-threads::-webkit-scrollbar{ width:10px }
.aichat-threads::-webkit-scrollbar-thumb{ background:#d9e4ff; border-radius:8px }
.aichat-threads-empty{ padding:12px; font-size:13px; color:#6b7280 }

/* Ítems */
.aichat-thread{
  display:flex; align-items:center; gap:8px; cursor:pointer;
  margin:8px 0; padding:10px; background:#fff;
  border:1px solid var(--stroke); border-radius:10px;
}
.aichat-thread.active{
  border-color:var(--poscali-blue);
  box-shadow:0 0 0 3px rgba(0,71,186,.10);
}
.aichat-thread-title{
  flex:1; font-size:13px; color:#1f2937;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

/* Acciones (icon buttons) */
.aichat-thread-actions{ display:flex; align-items:center; gap:6px }
.aichat-thread-btn.icon{
  width:32px; height:32px; display:inline-flex; align-items:center; justify-content:center;
  background:#f2f6ff; border:1px solid #e0e9ff; border-radius:8px; cursor:pointer;
  transition:transform .06s ease, filter .15s ease, box-shadow .15s ease;
}
.aichat-thread-btn.icon i{ font-size:14px; line-height:1 }
.aichat-thread-btn.icon:hover{ filter:brightness(1.03); box-shadow:0 0 0 3px rgba(0,71,186,.10) }
.aichat-thread-btn.icon:active{ transform:translateY(1px) }
.aichat-thread-btn.icon.danger{ background:#fff5f5; border-color:#ffd6d6 }
.aichat-thread-btn.icon.danger i{ color:#c23934 }

/* Columna principal del chat (tarjeta interna) */
.aichat-main{
  background:#fff;
  border:1px solid var(--stroke);
  border-radius:12px;
  box-shadow:0 6px 18px rgba(1,30,65,.06);
  display:flex; flex-direction:column; overflow:hidden;
}

/* Log */
.aichat-log{
  height:420px; overflow:auto; padding:18px; background:var(--surface-alt);
  border-bottom:1px solid var(--stroke); scroll-behavior:smooth;
  display:flex; flex-direction:column; gap:8px; word-break:break-word;
}
.aichat-log::-webkit-scrollbar{ width:10px }
.aichat-log::-webkit-scrollbar-track{ background:#eef3ff }
.aichat-log::-webkit-scrollbar-thumb{ background:#cfdaf6; border-radius:8px }

/* Mensajes */
.msg{ padding:12px 14px; border-radius:14px; margin:2px 0; line-height:1.55;
  animation:msgIn .15s ease-out; max-width:94%; box-shadow:0 4px 18px rgba(0,0,0,.04) }
@keyframes msgIn{ from{ transform:translateY(4px); opacity:0 } to{ transform:none; opacity:1 } }
.msg.user{ align-self:flex-end; margin-left:auto; background:var(--poscali-blue); color:#fff;
  border:1px solid rgba(0,0,0,.04); border-bottom-right-radius:6px }
.msg.bot{ align-self:flex-start; background:#fff; color:var(--poscali-gray);
  border:1px solid var(--stroke); border-bottom-left-radius:6px }
.msg.bot strong{ color:var(--poscali-navy); font-weight:600 }
.msg.bot code{ background:#eef4ff; border:1px solid #dbe6ff; padding:1px 6px; border-radius:6px;
  font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,"Liberation Mono",monospace; font-size:90% }

/* Escribiendo */
.msg.typing{ display:flex; gap:6px; align-items:center; background:transparent; border:none; box-shadow:none; padding-left:2px }
.msg.typing .dot{ width:7px; height:7px; border-radius:50%; background:var(--poscali-blue); display:inline-block; animation:aiblink 1s infinite ease-in-out; opacity:.6 }
.msg.typing .dot:nth-child(2){ animation-delay:.2s } .msg.typing .dot:nth-child(3){ animation-delay:.4s }
@keyframes aiblink{ 0%,80%,100%{opacity:.25; transform:translateY(0)} 40%{opacity:1; transform:translateY(-3px)} }

/* Formulario */
.aichat-form{ display:flex; gap:10px; padding:14px; background:#fff }
#aichat-input{ flex:1; padding:12px 14px; border:1px solid var(--stroke); border-radius:12px;
  resize:vertical; min-height:46px; max-height:160px; outline:none;
  transition:border-color .15s, box-shadow .15s, background-color .15s; background:#fff }
#aichat-input::placeholder{ color:#6a7895 }
#aichat-input:focus{ border-color:var(--poscali-blue); box-shadow:0 0 0 3px rgba(0,71,186,.12); background:#fcfdff }

/* Botón */
#aichat-send{ padding:0 18px; min-width:112px; border:none; border-radius:12px;
  background:linear-gradient(135deg,var(--poscali-blue),var(--poscali-navy)); color:#fff; cursor:pointer; font-weight:600;
  transition:transform .06s ease, box-shadow .15s ease, filter .2s ease; box-shadow:0 8px 18px rgba(0,71,186,.20) }
#aichat-send:hover{ filter:brightness(1.04) } #aichat-send:active{ transform:translateY(1px) }
#aichat-send:disabled{ opacity:.6; cursor:not-allowed; box-shadow:none }

/* Hint */
.aichat-hint{ font-size:12px; color:#5a6b88; padding:0 14px 16px 14px }

/* Responsive */
@media (max-width:980px){
  .aichat-body{ grid-template-columns:1fr }
  .aichat-log{ height:50vh }
}
