/* FundOS Copilot — resizable chat sidebar with history.
 * Loaded from every FundOS page via fundos/base.html.
 * Width persists to localStorage. Collapsed state persists. History
 * persists per user (keyed by user_id from the meta tag). */

#copilot-root {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1040;
  display: flex;
  pointer-events: none;  /* children re-enable */
}

/* Collapsed toggle — always visible */
#copilot-toggle {
  position: absolute;
  right: 16px;
  bottom: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--fundos-primary, #0b1220);
  color: #fff;
  border: none;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  pointer-events: auto;
  transition: transform .2s, box-shadow .2s;
}
#copilot-toggle:hover { transform: scale(1.06); }
#copilot-toggle .bi-chevron-right { display: none; }
#copilot-root.open #copilot-toggle .bi-stars { display: none; }
#copilot-root.open #copilot-toggle .bi-chevron-right { display: inline-block; }

/* Drawer body */
#copilot-drawer {
  width: var(--copilot-w, 380px);
  min-width: 300px;
  max-width: 720px;
  height: 100%;
  background: #fff;
  box-shadow: -8px 0 24px rgba(0,0,0,.08);
  border-left: 1px solid rgba(0,0,0,.06);
  display: none;
  flex-direction: column;
  pointer-events: auto;
}
#copilot-root.open #copilot-drawer { display: flex; }

#copilot-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 6px;
  margin-left: -3px;
  cursor: ew-resize;
  background: transparent;
}
#copilot-resize:hover,
#copilot-resize.dragging {
  background: rgba(59,130,246,.25);
}

#copilot-header {
  padding: .75rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,.06);
  display: flex;
  align-items: center;
  gap: .5rem;
}
#copilot-header h6 { margin: 0; font-size: .92rem; font-weight: 600; flex-grow: 1; }
#copilot-header .btn { padding: 0 .5rem; font-size: .78rem; }

#copilot-messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
  font-size: .88rem;
  line-height: 1.5;
}
#copilot-messages .cp-msg {
  margin-bottom: .9rem;
}
#copilot-messages .cp-msg-role {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #6b7280;
  margin-bottom: .2rem;
}
#copilot-messages .cp-msg-user { color: var(--fundos-primary, #0b1220); }
#copilot-messages .cp-msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
}
#copilot-messages .cp-msg-assistant .cp-msg-body {
  background: #f9fafb;
  padding: .6rem .75rem;
  border-radius: .5rem;
}
#copilot-messages .cp-citations {
  margin-top: .4rem;
  font-size: .72rem;
  color: #6b7280;
}
#copilot-messages .cp-citations a { color: #2563eb; text-decoration: none; }
#copilot-messages .cp-empty {
  text-align: center;
  color: #9ca3af;
  padding: 2rem 1rem;
  font-size: .85rem;
}

#copilot-input-row {
  padding: .75rem;
  border-top: 1px solid rgba(0,0,0,.06);
  display: flex;
  gap: .5rem;
  align-items: flex-end;
}
#copilot-textarea {
  flex-grow: 1;
  min-height: 40px;
  max-height: 180px;
  resize: none;
  border: 1px solid rgba(0,0,0,.15);
  border-radius: .5rem;
  padding: .5rem .75rem;
  font-size: .88rem;
  font-family: inherit;
  outline: none;
}
#copilot-textarea:focus {
  border-color: var(--fundos-primary, #0b1220);
}
#copilot-send {
  background: var(--fundos-primary, #0b1220);
  color: #fff;
  border: none;
  border-radius: .5rem;
  padding: .5rem .8rem;
  font-size: .88rem;
  cursor: pointer;
}
#copilot-send:disabled { opacity: .5; cursor: not-allowed; }

#copilot-thinking {
  padding: .3rem 1rem .3rem;
  font-size: .75rem;
  color: #6b7280;
  display: none;
}
#copilot-root.thinking #copilot-thinking { display: block; }
