/* ---------- Historial de chats de GestIA ---------- */
.chat { --chat-history-w: 276px; position: relative; grid-template-columns: var(--chat-history-w) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
.chat-main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); min-width: 0; min-height: 0; }

.chat-history {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line-soft);
  background: linear-gradient(180deg, var(--blue-50) 0%, var(--surface-2) 38%, var(--surface) 100%);
}
.ch-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px; }
.ch-new { flex: 1; justify-content: center; }
.ch-new .i { transition: transform .3s var(--spring); }
.ch-new:hover .i { transform: rotate(90deg) scale(1.1); }
.ch-close { display: none; }

.ch-search { position: relative; margin: 0 14px 8px; }
.ch-search > .i { position: absolute; top: 50%; left: 12px; width: 16px; height: 16px; color: var(--ink-4); transform: translateY(-50%); pointer-events: none; }
.ch-search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 13px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.ch-search input:focus { outline: 0; border-color: var(--blue-500); box-shadow: 0 0 0 4px var(--blue-100); }

.ch-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; scrollbar-width: thin; }
.ch-group + .ch-group { margin-top: 10px; }
.ch-group h3 { padding: 8px 10px 4px; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); }
.ch-group ul { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; margin: 0; padding: 0; list-style: none; }

.ch-item {
  position: relative;
  display: flex;
  align-items: center;
  border-radius: var(--r-sm);
  animation: rise .35s var(--spring) both;
  animation-delay: calc(var(--i, 0) * 28ms);
  transition: background-color .18s var(--ease);
}
.ch-item::before {
  content: "";
  position: absolute;
  inset: 8px auto 8px 0;
  width: 3px;
  border-radius: 99px;
  background: var(--grad-ai);
  transform: scaleY(0);
  transition: transform .3s var(--spring);
}
.ch-item:hover { background: var(--blue-50); }
.ch-item.active { background: var(--violet-50); }
.ch-item.active::before { transform: scaleY(1); }
.ch-list.settled .ch-item:not(.leaving) { animation: none; }
.ch-item.leaving { animation: pop-out .25s var(--ease) forwards; pointer-events: none; }

.ch-open {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 40px;
  padding: 8px 10px 8px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  color: var(--ink-2);
}
.ch-open .i { flex: none; width: 15px; height: 15px; color: var(--violet-500); opacity: .55; transition: opacity .2s, transform .3s var(--spring); }
.ch-open span { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ch-item:hover .ch-open .i, .ch-item.active .ch-open .i { opacity: 1; transform: scale(1.1); }
.ch-item.active .ch-open { color: var(--violet-700); font-weight: 700; }
.ch-open:focus-visible, .ch-tool:focus-visible { outline: 2px solid var(--blue-600); outline-offset: -2px; }

.ch-tools { display: flex; flex: none; gap: 2px; padding-right: 4px; opacity: 0; transform: translateX(4px); transition: opacity .18s var(--ease), transform .18s var(--ease); }
.ch-item:hover .ch-tools, .ch-item:focus-within .ch-tools, .ch-item.active .ch-tools { opacity: 1; transform: none; }
.ch-tool { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--ink-3); transition: background-color .15s, color .15s, transform .2s var(--spring); }
.ch-tool .i { width: 15px; height: 15px; }
.ch-tool:hover { background: var(--surface); color: var(--blue-700); transform: scale(1.08); }
.ch-tool.danger:hover { color: var(--red-500); }
.ch-tool:active { transform: scale(.94); }

.ch-item.renaming { background: var(--surface); box-shadow: 0 0 0 1.5px var(--blue-500); }
.ch-item.renaming .ch-tools { display: none; }
.ch-rename { flex: 1; padding: 4px; }
.ch-rename input { width: 100%; height: 32px; padding: 0 8px; border: 0; border-radius: 8px; background: var(--blue-50); font-size: 13px; font-weight: 600; outline: 0; }

.ch-more { width: 100%; margin-top: 8px; justify-content: center; }
.ch-list .empty { padding: 28px 12px; }
.ch-list .empty-art { width: 48px; height: 48px; }
.ch-list .empty-art .i { width: 22px; height: 22px; }
.ch-list .empty h4 { font-size: 14px; }
.ch-list .empty p { font-size: 12.5px; overflow-wrap: anywhere; }
.ch-skeleton { display: grid; gap: 8px; padding: 10px 6px; }
.ch-skeleton .sk { height: 34px; border-radius: var(--r-sm); }
.ch-skeleton .sk:nth-child(3n + 2) { width: 82%; }
.ch-skeleton .sk:nth-child(3n) { width: 64%; }

.ch-note { display: flex; align-items: flex-start; gap: 7px; padding: 10px 16px 14px; border-top: 1px solid var(--line-soft); font-size: 11.5px; line-height: 1.45; color: var(--ink-3); }
.ch-note .i { flex: none; width: 14px; height: 14px; margin-top: 1px; color: var(--ink-4); }

.thread-skeleton { display: grid; gap: 16px; width: 100%; max-width: 780px; margin: 0 auto; }
.thread-skeleton .sk { border-radius: 18px; }
.thread-skeleton .sk-user { justify-self: end; width: 44%; height: 46px; }
.thread-skeleton .sk-agent { width: 72%; height: 78px; }
.thread-skeleton .sk-agent.tall { height: 128px; }

.history-toggle { display: none; }
.ch-backdrop { display: none; }

/* En pantallas angostas el historial es un cajón sobre el chat. */
@media (max-width: 960px) {
  .chat { grid-template-columns: minmax(0, 1fr); }
  .history-toggle { display: grid; flex: none; margin-left: -8px; }
  .agent-id { min-width: 0; }
  .agent-id > div { min-width: 0; }
  .chat-head > .agent-id { flex: 1 1 auto; max-width: 100%; }
  .agent-id p { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .ch-close { display: grid; }
  .chat-history {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 6;
    width: min(320px, 88%);
    border-right: 0;
    box-shadow: var(--shadow-lg);
    visibility: hidden;
    transform: translateX(-104%);
    transition: transform .34s var(--ease), visibility 0s linear .34s;
  }
  .chat.history-open .chat-history { visibility: visible; transform: none; transition: transform .34s var(--ease), visibility 0s; }
  .ch-backdrop { display: block; position: absolute; inset: 0; z-index: 5; background: var(--glass-dark); animation: fade .25s var(--ease) both; }
  .ch-backdrop[hidden] { display: none; }
  .ch-tools { opacity: 1; transform: none; }
}
@media (hover: none) {
  .ch-tools { opacity: 1; transform: none; }
}
