/* ============================================================
   QAD Calidad — Panel de chat (asistente IA)
   Workspace con panel dividido, burbujas, markdown, indicador de
   llamada a herramienta.
   ============================================================ */

.content-area:has(.workspace-layout) {
  padding: 0;
  height: calc(100vh - var(--topbar-height));
  overflow: hidden;
}
.workspace-layout { display: flex; gap: 0; height: 100%; overflow: hidden; min-height: 0; }
.workspace-main { flex: 1; min-width: 0; overflow-y: auto; padding: 1.25rem; }
.workspace-chat {
  display: flex;
  flex-direction: row;
  flex-shrink: 0;
  width: 22rem;
  min-width: 16rem;
  max-width: 50vw;
  height: 100%;
  overflow: hidden;
}
.chat-splitter {
  flex-shrink: 0;
  width: 5px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  transition: background 0.15s;
  user-select: none;
}
.chat-splitter::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--color-border);
  transition: background 0.15s, left 0.1s, width 0.1s;
}
.chat-splitter:hover::after,
.chat-splitter.is-resizing::after { background: var(--color-accent); left: 1px; width: 3px; }

.chat-panel {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-subtle);
  height: 100%;
  overflow: hidden;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--color-border-row);
  background: var(--color-surface-alt);
}
.chat-title   { font-weight: 600; font-size: 0.875rem; color: var(--color-text); }
.chat-context {
  font-size: 0.65rem;
  color: var(--color-text-faint);
  background: var(--color-bg);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-pill);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.chat-reset-btn {
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.chat-reset-btn:hover:not(:disabled) { color: var(--color-danger); background: var(--color-danger-bg); }
.chat-reset-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18,35,63,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border-radius: var(--radius-lg);
}
.chat-modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay-lg);
  padding: 1.25rem 1.5rem;
  width: calc(100% - 2.5rem);
  max-width: 20rem;
}
.chat-modal-title { font-size: 0.9375rem; font-weight: 600; color: var(--color-text); margin-bottom: 0.5rem; }
.chat-modal-body { font-size: 0.8125rem; color: var(--color-text-muted); line-height: 1.55; margin-bottom: 1.25rem; }
.chat-modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.chat-messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; background: var(--color-bg); }
.chat-empty { display: flex; align-items: center; justify-content: center; height: 100%; text-align: center; padding: 2rem; }
.chat-message-user      { display: flex; justify-content: flex-end; }
.chat-message-assistant { display: flex; justify-content: flex-start; }
.chat-bubble {
  max-width: 86%;
  padding: 0.625rem 0.875rem;
  border-radius: 1rem;
  font-size: 0.8125rem;
  line-height: 1.55;
  white-space: pre-wrap;
}
.chat-message-user .chat-bubble {
  background: var(--color-navy);
  color: var(--color-surface);
  border-bottom-right-radius: 0.25rem;
  white-space: pre-wrap;
}
.chat-message-assistant .chat-bubble {
  background: var(--color-surface);
  color: var(--color-text-body);
  border-bottom-left-radius: 0.25rem;
  border: 1px solid var(--color-border-subtle);
}
.chat-input-area { padding: 0.75rem 1rem; border-top: 1px solid var(--color-border-row); background: var(--color-surface); }
.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  font-size: 0.8125rem;
  resize: none;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--color-bg);
}
.chat-input:focus { border-color: var(--color-accent); box-shadow: 0 0 0 3px rgba(46,92,138,0.1); background: var(--color-surface); }
.chat-input:disabled { background: var(--color-border-subtle); color: var(--color-text-faint); }
.chat-send-btn {
  width: 2.375rem;
  height: 2.375rem;
  border-radius: var(--radius-sm);
  background: var(--color-navy);
  color: var(--color-surface);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.chat-send-btn:hover:not(:disabled)  { background: #0C1B30; }
.chat-send-btn:active:not(:disabled) { transform: scale(0.95); }
.chat-send-btn:disabled { background: var(--color-border); cursor: not-allowed; }

.tool-call-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-copper);
  padding: 0.5rem 0.875rem;
  background: var(--color-copper-soft-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-copper-soft-border);
}
.tool-call-spinner {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 50%;
  border: 2px solid var(--color-copper-soft-border);
  border-top-color: var(--color-copper);
  animation: spin 0.8s linear infinite;
}
.ai-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--color-border-subtle);
  border-top-color: var(--color-accent);
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
.textarea-ai-highlight {
  outline: none !important;
  border-color: var(--color-accent) !important;
  box-shadow: 0 0 0 3px rgba(46,92,138,0.15) !important;
  transition: border-color 1.5s ease, box-shadow 1.5s ease;
}

/* ─── Markdown en burbujas de chat ──────────────────────────── */
.chat-bubble-md p             { margin-bottom: 0.5rem; line-height: 1.6; }
.chat-bubble-md p:last-child  { margin-bottom: 0; }
.chat-bubble-md h1,
.chat-bubble-md h2,
.chat-bubble-md h3,
.chat-bubble-md h4            { font-weight: 700; margin: 0.875rem 0 0.375rem; line-height: 1.3; }
.chat-bubble-md h1 { font-size: 1.1rem; }
.chat-bubble-md h2 { font-size: 1rem; }
.chat-bubble-md h3 { font-size: 0.9375rem; }
.chat-bubble-md ul,
.chat-bubble-md ol            { padding-left: 1.375rem; margin-bottom: 0.5rem; }
.chat-bubble-md ul            { list-style-type: disc; }
.chat-bubble-md ol            { list-style-type: decimal; }
.chat-bubble-md li            { margin-bottom: 0.2rem; line-height: 1.5; }
.chat-bubble-md li > ul,
.chat-bubble-md li > ol       { margin-top: 0.2rem; margin-bottom: 0.2rem; }
.chat-bubble-md code          { background: rgba(18,35,63,0.07); border-radius: var(--radius-sm); padding: 0.1rem 0.35rem; font-size: 0.8em; font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace; }
.chat-bubble-md pre           { background: var(--color-navy); color: #E4E9EE; border-radius: var(--radius-sm); padding: 0.875rem 1rem; overflow-x: auto; margin-bottom: 0.5rem; }
.chat-bubble-md pre code      { background: none; padding: 0; color: inherit; font-size: 0.8125rem; }
.chat-bubble-md blockquote    { border-left: 3px solid var(--color-border); padding-left: 0.75rem; color: var(--color-text-muted); margin: 0.5rem 0; font-style: italic; }
.chat-bubble-md strong        { font-weight: 700; }
.chat-bubble-md em            { font-style: italic; }
.chat-bubble-md a             { color: var(--color-accent); text-decoration: underline; }
.chat-bubble-md a:hover       { color: var(--color-navy); }
.chat-bubble-md table         { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-bottom: 0.5rem; border-radius: var(--radius-sm); overflow: hidden; }
.chat-bubble-md th,
.chat-bubble-md td            { padding: 0.375rem 0.625rem; border: 1px solid var(--color-border); text-align: left; }
.chat-bubble-md th            { background: var(--color-bg); font-weight: 600; color: var(--color-text-body); }
.chat-bubble-md tr:hover td   { background: var(--color-bg); }
.chat-bubble-md hr            { border: none; border-top: 1px solid var(--color-border); margin: 0.75rem 0; }
