/* ============ Hermes Command Center — chat multi-conversación ============ */

.chat-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  gap: 14px;
  height: calc(100vh - 130px);
  min-height: 420px;
}

/* ---- panel izquierdo: conversaciones ---- */
.chat-side {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--card, var(--card));
  border: 1px solid var(--line, var(--line));
  border-radius: 16px;
  padding: 10px;
  overflow: hidden;
}
.cs-head { display: flex; gap: 6px; }
.cs-head .btn { flex: 1; justify-content: center; }
.cs-agent { display: flex; flex-direction: column; gap: 4px; }
.cs-agent label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.cs-agent select {
  width: 100%;
  background: var(--bg3);
  color: inherit;
  border: 1px solid var(--line, var(--line));
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
}
.chat-items { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; flex: 1; padding-right: 2px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.chat-item:hover { background: var(--bg3); }
.chat-item.active { background: var(--bg3); border-color: var(--accent); }
.ci-main { min-width: 0; flex: 1; }
.ci-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-sub { font-size: 11px; opacity: .6; margin-top: 2px; }
.ci-del {
  background: none; border: 0; color: inherit; opacity: .35;
  cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 6px;
}
.ci-del:hover { opacity: 1; color: var(--red); background: var(--pill-err-bg); }
.dot-live { color: var(--green); }
.hist-panel {
  max-height: 260px; overflow-y: auto;
  border: 1px solid var(--line, var(--line)); border-radius: 12px; background: var(--bg3);
}
.hist-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--bg3); }
.hist-item:last-child { border-bottom: 0; }
.hist-item:hover { background: var(--bg3); }
.hi-title { font-size: 12.5px; font-weight: 600; }
.hi-sub { font-size: 11px; opacity: .55; margin-top: 2px; }

/* ---- panel derecho: conversación ---- */
.chat-main {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--card, var(--card));
  border: 1px solid var(--line, var(--line));
  border-radius: 16px;
  overflow: hidden;
}
.cm-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line, var(--line));
  background: linear-gradient(180deg, var(--bg2), var(--bg3));
}
.cm-title { font-weight: 700; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.cm-head > div:first-child { min-width: 0; flex: 1; }
.cm-sub { font-size: 11.5px; opacity: .6; margin-top: 2px; }
.cm-actions { display: flex; gap: 6px; }
.btn-stop { color: var(--red); border-color: var(--border); }

.chat-log {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.chat-msg { max-width: 86%; display: flex; flex-direction: column; gap: 4px; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-role { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; opacity: .5; }
.chat-text {
  padding: 10px 13px; border-radius: 14px; line-height: 1.55; font-size: 14px;
  background: var(--bg3); border: 1px solid var(--line); word-break: break-word;
}
.chat-msg.user .chat-text { background: var(--accent-soft); border-color: var(--accent); }
.chat-msg.assistant .chat-text { background: var(--card); }
.chat-text pre {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; overflow-x: auto; font-size: 12.5px; margin: 6px 0;
}
.chat-text code { background: var(--bg3); border-radius: 5px; padding: 1px 5px; font-size: 12.5px; }
.chat-text pre code { background: none; padding: 0; }
.chat-text a { color: var(--accent2); }
.chat-tool {
  align-self: flex-start; display: flex; gap: 8px; align-items: center;
  font-size: 11.5px; opacity: .8; background: var(--tool-bg); border: 1px solid var(--tool-line);
  color: var(--tool-text); border-radius: 10px; padding: 5px 10px; max-width: 90%;
}
.chat-tool code { font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-ico { opacity: .8; }
.caret { display: inline-block; animation: blink 1s steps(2) infinite; color: var(--accent2); }
@keyframes blink { 50% { opacity: 0; } }

.chat-form {
  display: flex; flex-direction: column; gap: 8px; align-items: stretch;
  padding: 10px 12px; border-top: 1px solid var(--line, var(--line)); background: var(--bg3);
}
.comp-row { display: flex; gap: 8px; align-items: flex-end; width: 100%; }
.comp-row textarea { flex: 1; }
.comp-btn {
  flex: 0 0 auto; width: 42px; padding: 0; font-size: 17px; line-height: 1;
  display: inline-grid; place-items: center;
}
.comp-btn.rec-on { color: var(--red); border-color: var(--red); background: var(--pill-err-bg); }

/* bandeja de adjuntos del compositor */
.adj-tray { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; }
.adj-tray[hidden] { display: none; }
.adj-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 4px 4px 4px 8px; font-size: 12px; line-height: 1.3;
}
.adj-chip .adj-ico { font-size: 13px; opacity: .85; }
.adj-chip .adj-nm { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adj-chip .adj-sz { color: var(--muted); font-size: 11px; white-space: nowrap; }
.adj-x {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 6px; font-family: inherit;
}
.adj-x:hover { background: var(--hover); color: var(--red); }
.adj-err { flex: 1 1 100%; color: var(--red); font-size: 12px; line-height: 1.35; }

/* grabación en curso */
.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); animation: recpulse 1.1s infinite; flex: 0 0 auto; }
@keyframes recpulse { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12.5px; }
.rec-txt { color: var(--muted); font-size: 12px; }

/* adjuntos dentro de las burbujas del historial */
.adj-msg { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.adj-msg:last-child { margin-bottom: 0; }
.adj-list { display: flex; flex-wrap: wrap; gap: 6px; }
.adj-audio { display: flex; flex-direction: column; gap: 3px; }
.adj-audio audio { width: 100%; max-width: 300px; height: 34px; }
.adj-audio .adj-nm { font-size: 11px; color: var(--muted); }
.chat-msg.user .adj-audio .adj-nm { color: inherit; opacity: .8; }
.ac-atts .adj-msg { margin-bottom: 4px; }
.ac-txt { white-space: pre-wrap; }
.agent-chat .adj-tray { margin-top: 8px; }
.agent-chat .adj-tray[hidden] { display: none; }
.agent-chat .comp-btn { height: 38px; width: 38px; font-size: 16px; }
.agent-chat .adj-chip { background: var(--bg2); }
.chat-form textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 160px;
  background: var(--bg3); color: inherit; border: 1px solid var(--line, var(--line));
  border-radius: 12px; padding: 11px 13px; font: inherit; font-size: 14px; line-height: 1.4;
}
.chat-form textarea:focus { outline: none; border-color: var(--accent); }
.chat-form .btn { height: 42px; }

/* ---- en vivo ---- */
.live-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.live-feed { display: flex; flex-direction: column; gap: 2px; max-height: 62vh; overflow-y: auto; font-size: 12.5px; }
.live-row {
  display: grid; grid-template-columns: 68px 92px 1fr; gap: 10px;
  padding: 5px 8px; border-radius: 8px; align-items: baseline;
}
.live-row:nth-child(odd) { background: var(--bg3); }
.live-row.err { background: var(--pill-err-bg); }
.lv-time { opacity: .55; font-variant-numeric: tabular-nums; }
.lv-sess { opacity: .7; font-family: ui-monospace, monospace; font-size: 11px; }
.lv-msg { word-break: break-word; }

/* ---- encaje en la página (anula el layout viejo del chat) ---- */
body.chat-mode { height: 100dvh; overflow: hidden; }
body.chat-mode .app { height: 100dvh; min-height: 0; overflow: hidden; }
body.chat-mode .content { display: flex; flex-direction: column; overflow: hidden; padding: 12px 12px 14px; }
.chat-shell { flex: 1 1 auto; height: auto; min-height: 0; }
.chat-main { min-height: 0; }
.chat-side { min-height: 0; }
.chat-log { max-height: none; margin-bottom: 0; min-height: 0; }

/* ---- móvil ---- */
@media (max-width: 900px) {
  body.chat-mode .content { padding: 8px 8px 72px; }
  .chat-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 8px;
  }
  .chat-side {
    flex-direction: row;
    align-items: center;
    gap: 6px;
    max-height: none;
    padding: 6px;
    overflow-x: auto;
  }
  .cs-head { flex: 0 0 auto; }
  .cs-head .btn { padding: 6px 9px; font-size: 12px; }
  .cs-agent { display: none; }
  .chat-items { flex-direction: row; gap: 6px; overflow: visible; flex: 0 0 auto; }
  .chat-item { min-width: 0; padding: 6px 10px; }
  .ci-title { max-width: 132px; font-size: 12px; }
  .ci-sub { display: none; }
  .chat-msg { max-width: 94%; }
  .live-row { grid-template-columns: 58px 1fr; }
  .lv-sess { display: none; }
  .cm-actions .btn { padding: 5px 8px; font-size: 11.5px; }
  .bottombar { overflow-x: auto; scrollbar-width: none; }
  .bottombar::-webkit-scrollbar { display: none; }
  .bottombar .nav-item { font-size: 9.5px; padding: 6px 4px; min-width: 42px; }
  .bottombar .nav-item .ico { font-size: 16px; }
}

/* ================= tablero kanban ================= */
.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 10px;
  align-items: start;
}
.bcol {
  background: var(--card, var(--card));
  border: 1px solid var(--line, var(--line));
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  min-height: 300px;
  transition: border-color .15s, background .15s;
}
.bcol.over { border-color: var(--accent); background: var(--accent-soft); }
.bcol-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .07em; opacity: .8; border-bottom: 1px solid var(--bg3);
}
.bcol-head b { font-size: 11px; background: var(--bg3); border-radius: 999px; padding: 1px 7px; }
.bcol-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 58vh; }
.tcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 10px; cursor: grab; display: flex; flex-direction: column; gap: 7px;
}
.tcard:hover { border-color: var(--accent); }
.tcard.dragging { opacity: .45; }
.tc-top { display: flex; gap: 8px; align-items: flex-start; }
.tc-prio { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--muted); flex: 0 0 auto; }
.tc-prio.prio-1 { background: var(--red); }
.tc-prio.prio-2 { background: var(--amber); }
.tc-prio.prio-3 { background: var(--blue); }
.tc-prio.prio-4 { background: var(--muted); }
.tc-title { font-size: 12.8px; font-weight: 600; line-height: 1.35; }
.tc-meta { display: flex; gap: 8px; align-items: center; font-size: 11px; }
.chip { background: var(--bg3); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 10.5px; }
.chip-empty { opacity: .5; }
.tc-actions { display: flex; gap: 4px; align-items: center; }
.tc-agent {
  flex: 1; min-width: 0; background: var(--bg3); color: inherit;
  border: 1px solid var(--line); border-radius: 8px; padding: 3px 6px; font-size: 11px;
}
.tiny {
  border: 1px solid var(--border); background: var(--bg2); color: inherit;
  border-radius: 7px; padding: 3px 7px; cursor: pointer; font-size: 11px; line-height: 1;
}
.tiny:hover { background: var(--bg3); }
.bempty { opacity: .25; text-align: center; padding: 22px 0; }
@media (max-width: 900px) {
  .board { grid-auto-columns: 76vw; }
  .bcol-body { max-height: 52vh; }
}

/* ===== arreglo de layout en pantallas anchas (el contenido se iba abajo) ===== */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 205px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    flex-direction: row;
    flex-wrap: nowrap;
    min-height: 100dvh;
  }
  .topbar { grid-column: 1 / -1; grid-row: 1; }
  .sidebar {
    grid-column: 1; grid-row: 2;
    align-self: start;
    position: sticky; top: 0;
    height: calc(100dvh - 57px);
    overflow-y: auto;
  }
  .content {
    grid-column: 2; grid-row: 2;
    width: auto; max-width: none; margin: 0;
    min-width: 0;
  }
  .bottombar { display: none; }
  body.chat-mode .app { height: 100dvh; }
}

/* scrollbars finas */
.board::-webkit-scrollbar, .bcol-body::-webkit-scrollbar, .chat-items::-webkit-scrollbar { height: 8px; width: 8px; }
.board::-webkit-scrollbar-thumb, .bcol-body::-webkit-scrollbar-thumb, .chat-items::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 99px;
}
.board::-webkit-scrollbar-track, .bcol-body::-webkit-scrollbar-track, .chat-items::-webkit-scrollbar-track { background: transparent; }

@media (min-width: 900px) { .board { overflow-x: auto; } .tc-title { overflow-wrap: anywhere; } }

/* costos */
.cost-bar { height: 4px; background: var(--bg3); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.cost-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent2), var(--accent)); border-radius: 99px; }

/* tabla de costos: en celular mostramos lo esencial */
@media (max-width: 700px) {
  .cost-table th:nth-child(3), .cost-table td:nth-child(3),
  .cost-table th:nth-child(4), .cost-table td:nth-child(4),
  .cost-table th:nth-child(5), .cost-table td:nth-child(5),
  .cost-table th:nth-child(6), .cost-table td:nth-child(6),
  .cost-table th:nth-child(8), .cost-table td:nth-child(8) { display: none; }
  .cost-table td:first-child { min-width: 0 !important; }
  .cost-table th, .cost-table td { padding: 8px 6px; font-size: 12.5px; }
}

/* buscador global */
.search-input {
  width: 100%; background: var(--bg3); color: inherit; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 14px; margin-bottom: 12px;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.q-res { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.hit { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.hit:hover { border-color: var(--accent); background: var(--bg3); }
.hit-top { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.hit-title { font-size: 13px; font-weight: 600; margin-top: 5px; }
.hit-txt { font-size: 12px; opacity: .72; margin-top: 3px; line-height: 1.45; }

/* cron */
.cron-list { display: flex; flex-direction: column; gap: 8px; }
.cron-item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.cron-item .ci-main { flex: 1; min-width: 0; }
.cron-item .ci-title { font-size: 13px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.cron-item .ci-sub { font-size: 11.5px; margin-top: 3px; }
.cron-item .ci-actions { display: flex; gap: 4px; }

/* personalidad */
.soul-text {
  width: 100%; min-height: 320px; background: var(--bg3); color: inherit;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5;
}
.soul-text:focus { outline: none; border-color: var(--accent); }
.agent-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ================= biblioteca ================= */
.lib-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.lib-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.lib-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; transition: border-color .15s, transform .15s; }
.lib-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.lib-thumb { height: 132px; background: var(--bg3); display: grid; place-items: center; overflow: hidden; }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-kind { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; opacity: .55; }
.lib-body { padding: 10px 12px 12px; }
.lib-title { font-size: 13px; font-weight: 600; line-height: 1.35; }
.lib-tags-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.lib-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 9px; font-size: 11px; }
.lib-check { display: flex; align-items: center; gap: 5px; opacity: .8; cursor: pointer; }
.lib-big { width: 100%; max-height: 46vh; object-fit: contain; background: var(--bg3); border-radius: 12px; }
.lib-note { margin-top: 10px; font-size: 13px; opacity: .85; }
.lib-compare { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; }
.lib-col { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.lib-col img { width: 100%; max-height: 180px; object-fit: cover; border-radius: 8px; }
.lib-col-title { font-size: 13px; font-weight: 600; margin-top: 8px; }
