/* Asistente del observatorio: panel lateral derecho (estilo del observatorio: Roboto, teal UdeA, tarjetas). */
:root {
  --copilot-width: 420px;
  --copilot-ink: #262626;
  --copilot-secondary: #595959;
  --copilot-muted: #8c8c8c;
  --copilot-line: #e5e5e5;
  --copilot-split: #f0f0f0;
  --copilot-teal: #007473; /* teal institucional UdeA */
  --copilot-teal-hover: #008a88;
  --copilot-teal-soft: #eaf7f5;
  --copilot-radius: 8px;
  --copilot-radius-lg: 12px;
  /* Botón flotante y aviso: teal institucional UdeA (#007473), con ícono lima para destacarlo. */
  --copilot-cta: #007473;
  --copilot-cta-hover: #008a88;
  --copilot-lime: #93d500;
}

/* Botón flotante */
.copilot-toggle {
  position: fixed;
  right: 20px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 13px 20px 13px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--copilot-cta);
  color: #fff;
  font: 500 15px/1 Roboto, Arial, sans-serif;
  box-shadow: 0 8px 22px rgba(0, 116, 115, 0.35);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}
.copilot-toggle:hover { background: var(--copilot-cta-hover); transform: translateY(-1px); }
.copilot-toggle:focus-visible { outline: 3px solid #93d500; outline-offset: 2px; }
.copilot-toggle svg { width: 20px; height: 20px; fill: var(--copilot-lime); }
body.copilot-open .copilot-toggle { opacity: 0; pointer-events: none; }

/* Aviso de bienvenida: aparece en cada carga del observatorio, sobre el botón flotante. */
.copilot-intro {
  position: fixed;
  right: 20px;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  z-index: 61;
  width: min(300px, calc(100vw - 40px));
  padding: 14px 16px 12px;
  border-radius: var(--copilot-radius-lg);
  background: var(--copilot-cta);
  color: #fff;
  font: 13.5px/1.45 Roboto, Arial, sans-serif;
  box-shadow: 0 10px 28px rgba(0, 116, 115, 0.3);
  animation: copilot-intro-in 0.3s ease both;
}
.copilot-intro::after {
  content: "";
  position: absolute;
  right: 36px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--copilot-cta);
  transform: rotate(45deg);
}
.copilot-intro p { margin: 0 0 10px; }
.copilot-intro strong { color: var(--copilot-lime); font-weight: 500; }
.copilot-intro-pilot { font-size: 12.5px; color: #e3f1f0; }
.copilot-intro-actions { display: flex; align-items: center; justify-content: space-between; }
.copilot-intro-try {
  padding: 6px 14px;
  border: 0;
  border-radius: var(--copilot-radius);
  background: var(--copilot-lime);
  color: var(--copilot-cta);
  font: 500 13px/1 Roboto, Arial, sans-serif;
  cursor: pointer;
}
.copilot-intro-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--copilot-radius);
  background: transparent;
  color: #cde8e7;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.copilot-intro-close:hover { color: #fff; }
.copilot-intro button:focus-visible { outline: 2px solid var(--copilot-lime); outline-offset: 2px; }
body.copilot-open .copilot-intro { display: none; }
@keyframes copilot-intro-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Panel */
.copilot-panel {
  position: fixed;
  top: var(--copilot-top, 66px); /* debajo de la barra del portal (sticky, z-index 100) */
  right: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  flex-direction: column;
  width: var(--copilot-width);
  max-width: 100vw;
  border-left: 1px solid var(--copilot-line);
  background: #fff;
  color: var(--copilot-ink);
  font: 14px/1.5 Roboto, Arial, sans-serif;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.08);
  transform: translateX(100%);
  transition: transform 0.25s ease;
}
.copilot-panel[hidden] { display: flex !important; visibility: hidden; }
body.copilot-open .copilot-panel { transform: translateX(0); visibility: visible; }

/* En pantallas anchas el observatorio se corre a la izquierda en lugar de quedar tapado. */
@media (min-width: 1200px) {
  .page-content { transition: margin-right 0.25s ease; }
  body.copilot-open .page-content {
    width: min(1440px, calc(100% - var(--copilot-width)));
    margin-right: var(--copilot-width);
  }
}

.copilot-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--copilot-split);
  border-top: 3px solid var(--copilot-teal);
}
.copilot-head h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 500; }
.copilot-head p { margin: 0; color: var(--copilot-secondary); font-size: 12.5px; }
.copilot-close {
  flex: none;
  width: 32px;
  height: 32px;
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius);
  background: #fff;
  color: var(--copilot-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.copilot-close:hover { border-color: var(--copilot-teal); color: var(--copilot-teal); }
.copilot-head-actions { display: flex; flex: none; gap: 6px; }
.copilot-clear {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius);
  background: #fff;
  color: var(--copilot-secondary);
  font: 500 12.5px/1 Roboto, Arial, sans-serif;
  cursor: pointer;
}
.copilot-clear svg { width: 15px; height: 15px; fill: currentColor; }
.copilot-clear:hover:not(:disabled) { border-color: var(--copilot-teal); color: var(--copilot-teal); }
.copilot-clear.is-confirming { border-color: #d9534f; background: #fff6f5; color: #b3261e; }
.copilot-clear:disabled { cursor: not-allowed; opacity: 0.5; }

.copilot-body { flex: 1; overflow-y: auto; padding: 16px 20px; }

.copilot-notice {
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #f3d27a;
  border-radius: var(--copilot-radius);
  background: #fff8e1;
  font-size: 13px;
}
.copilot-notice a, .copilot-login {
  display: inline-block;
  margin-top: 8px;
  padding: 7px 14px;
  border-radius: var(--copilot-radius);
  background: var(--copilot-teal);
  color: #fff;
  font-weight: 500;
  text-decoration: none;
}

.copilot-empty p { margin: 0 0 10px; color: var(--copilot-secondary); font-size: 13px; }
.copilot-chips { display: grid; gap: 8px; }
.copilot-chip {
  padding: 9px 12px;
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius);
  background: #fff;
  color: var(--copilot-ink);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.copilot-chip:hover { border-color: var(--copilot-teal); background: var(--copilot-teal-soft); }

.copilot-messages { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin: 0; padding: 0; list-style: none; }
.copilot-q {
  justify-self: end;
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px 14px 4px 14px;
  background: var(--copilot-teal);
  color: #fff;
  overflow-wrap: anywhere;
}
.copilot-a {
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius-lg);
  background: #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.045);
}
.copilot-a.is-error { border-color: #f5c2c0; background: #fff6f5; }
.copilot-a p { margin: 0; }
.copilot-meta { margin-top: 8px; color: var(--copilot-muted); font-size: 12px; }

.copilot-a details { margin-top: 10px; border-top: 1px solid var(--copilot-split); padding-top: 8px; }
.copilot-a summary { color: var(--copilot-teal); font-size: 13px; font-weight: 500; cursor: pointer; }
.copilot-table-wrap { max-height: 280px; margin-top: 8px; overflow: auto; border: 1px solid var(--copilot-split); border-radius: var(--copilot-radius); }
.copilot-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.copilot-table th {
  position: sticky;
  top: 0;
  padding: 6px 8px;
  border-bottom: 1px solid var(--copilot-line);
  background: #fafafa;
  color: var(--copilot-secondary);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}
.copilot-table td { padding: 6px 8px; border-bottom: 1px solid var(--copilot-split); vertical-align: top; }
.copilot-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.copilot-csv {
  margin-top: 8px;
  padding: 5px 10px;
  border: 1px solid var(--copilot-teal);
  border-radius: var(--copilot-radius);
  background: #fff;
  color: var(--copilot-teal);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.copilot-csv:hover { background: var(--copilot-teal-soft); }
.copilot-sql {
  margin: 8px 0 0;
  padding: 10px;
  overflow-x: auto;
  border-radius: var(--copilot-radius);
  background: #f6f8fa;
  color: #1f2734;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.copilot-votes { display: flex; align-items: center; gap: 6px; margin-top: 10px; color: var(--copilot-muted); font-size: 12px; }
.copilot-votes button {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  color: var(--copilot-secondary);
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius);
  background: #fff;
  font-size: 14px;
  cursor: pointer;
}
.copilot-votes button:hover:not(:disabled) { border-color: var(--copilot-teal); }
.copilot-votes button:disabled { cursor: default; opacity: 0.5; }
.copilot-votes button.is-chosen { border-color: var(--copilot-teal); color: var(--copilot-teal); opacity: 1; }
.copilot-votes svg { width: 15px; height: 15px; fill: currentColor; }

.copilot-typing { display: flex; align-items: center; gap: 10px; color: var(--copilot-secondary); font-size: 13px; }
.copilot-dots { display: inline-flex; gap: 4px; }
.copilot-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--copilot-teal); animation: copilot-bounce 1.2s infinite ease-in-out; }
.copilot-dots span:nth-child(2) { animation-delay: 0.15s; }
.copilot-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes copilot-bounce { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.copilot-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 20px 8px;
  border-top: 1px solid var(--copilot-split);
}
.copilot-form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  resize: none;
  border: 1px solid var(--copilot-line);
  border-radius: var(--copilot-radius);
  color: var(--copilot-ink);
  font: inherit;
}
.copilot-form textarea:focus { outline: none; border-color: var(--copilot-teal); box-shadow: 0 0 0 3px rgba(0, 116, 115, 0.12); }
.copilot-form button {
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--copilot-radius);
  background: var(--copilot-teal);
  color: #fff;
  cursor: pointer;
}
.copilot-form button:hover:not(:disabled) { background: var(--copilot-teal-hover); }
.copilot-form button:disabled, .copilot-form textarea:disabled { opacity: 0.55; cursor: not-allowed; }
.copilot-form svg { width: 20px; height: 20px; fill: currentColor; }
.copilot-foot { margin: 0; padding: 0 20px calc(12px + env(safe-area-inset-bottom, 0px)); color: var(--copilot-muted); font-size: 11.5px; }
.copilot-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 600px) {
  .copilot-panel { width: 100vw; }
  .copilot-toggle span { display: none; }
  .copilot-toggle { padding: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .copilot-panel, .copilot-toggle, .page-content { transition: none; }
  .copilot-intro { animation: none; }
  .copilot-dots span { animation: none; }
}

/* «Ver en el observatorio»: un botón por entidad de la respuesta */
.copilot-obs {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--copilot-radius);
  background: var(--copilot-teal-soft);
}
.copilot-obs-title {
  display: block;
  margin-bottom: 6px;
  color: var(--copilot-teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.copilot-obs-links { display: flex; flex-wrap: wrap; gap: 6px; }
.copilot-obs-link {
  padding: 5px 10px;
  border: 1px solid var(--copilot-teal);
  border-radius: 999px;
  background: #fff;
  color: var(--copilot-teal);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.copilot-obs-link::after { content: " →"; }
.copilot-obs-link:hover { background: #fff; border-color: var(--copilot-teal-hover); color: var(--copilot-teal-hover); }
.copilot-obs-link:focus-visible { outline: 2px solid var(--copilot-teal); outline-offset: 2px; }
.copilot-obs-link.is-active { background: var(--copilot-teal); color: #fff; }
.copilot-obs-link.is-active::after { content: " ✓"; }
.copilot-obs-hint { margin: 8px 0 0; color: var(--copilot-secondary); font-size: 12px; line-height: 1.4; }
