/* ============================================================
   COPILOT.CSS — the ✦ Backend assistant dock (hub)
   ------------------------------------------------------------
   A fixed right-edge dock plus a floating pill, present on every
   tab. Reuses the shared cc-* card vocabulary from conductor.css
   for run output; this file owns only the shell (pill, dock,
   header, thread menu, transcript, composer, banner). Porcelain +
   Midnight tokens from base.css — already theme-adaptive, so only
   a couple of explicit dark tweaks are needed.
   ============================================================ */

/* ── Topbar open button (replaces the floating pill) ──────── */
.topbar-copilot {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--gb-control-radius, 999px);
  background: transparent;
  color: var(--accent);
  transition: background var(--transition), transform 120ms var(--ease-ios);
}
.topbar-copilot:hover { background: var(--bg-highlight); }
.topbar-copilot:active { transform: scale(0.92); }
.copilot-topbar-badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-full, 999px);
  background: var(--danger, #DC3545); color: #FFFFFF;
  font-size: 9px; font-weight: 700; line-height: 16px; text-align: center;
}
.copilot-topbar-badge[hidden] { display: none; }

/* ── Dock → right glass slide-over ────────────────────────── */
.copilot-dock {
  position: fixed;
  top: var(--space-3, 12px);
  right: var(--space-3, 12px);
  bottom: var(--space-3, 12px);
  width: 380px;
  max-width: calc(100% - 24px);
  z-index: 900;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(calc(100% + 24px));
  transition: transform 0.22s var(--ease-spring, cubic-bezier(0.34, 1.36, 0.64, 1));
}
.copilot-dock--open { transform: none; }
.copilot-dock--drag { box-shadow: var(--gb-shadow), inset 0 0 0 2px var(--accent, #3B6FE0); }
@media (prefers-reduced-motion: reduce) { .copilot-dock { transition: none; } }
@supports not (backdrop-filter: blur(1px)) { .copilot-dock { background: var(--bg-surface); } }

/* ── Header ───────────────────────────────────────────────── */
.copilot-head {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  padding: var(--space-3, 12px) var(--space-4, 16px);
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-surface, #FFFFFF);
}
.copilot-head-brand {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm, 13px);
  font-weight: 700;
  color: var(--text-primary);
  /* Holds the header buttons right now that the thread <select> (which used
     flex:1 + margin-left:auto) has been replaced by the history button. */
  margin-right: auto;
}
.copilot-head-brand .tessera-icon { width: 16px; height: 16px; color: var(--accent); }

.copilot-history {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3, 12px);
}
.copilot-history-empty {
  font-family: var(--font-ui);
  font-size: var(--text-xs, 11px);
  color: var(--text-muted);
  padding: var(--space-3, 12px);
  text-align: center;
}
.copilot-history-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: var(--radius, 8px);
}
.copilot-history-row.is-active { background: var(--bg-highlight); }
.copilot-history-row:hover { background: var(--bg-highlight); }
.copilot-history-open {
  flex: 1;
  min-width: 0;
  text-align: left;
  border: 0;
  background: none;
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: var(--text-sm, 13px);
  color: var(--text-primary);
  padding: 8px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copilot-history-del {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 15px;
  line-height: 1;
  padding: 0 8px;
}
.copilot-history-del:hover { color: var(--danger, #D0342C); }

.copilot-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius, 8px);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition, 160ms ease), color var(--transition, 160ms ease);
}
.copilot-icon-btn:hover { background: var(--bg-highlight); color: var(--text-primary); }
.copilot-icon-btn .tessera-icon { width: 15px; height: 15px; }

/* ── Transcript ───────────────────────────────────────────── */
.copilot-convo {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4, 16px);
  display: flex;
  flex-direction: column;
  gap: var(--space-4, 16px);
  scroll-behavior: smooth;
}
.copilot-turn { display: flex; flex-direction: column; gap: var(--space-2, 8px); }

/* Broker's own messages: a right-aligned midnight bubble */
.copilot-turn-user {
  align-items: flex-end;
}
.copilot-turn-user .cc-final {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 16px 16px 4px 16px;
  background: var(--accent);
  color: #FFFFFF;
}
.copilot-turn-user .cc-final p { margin: 0; }
[data-theme="dark"] .copilot-turn-user .cc-final { background: var(--accent-2, #5B8DEF); }

/* System notices (errors) */
.copilot-turn-system .cc-final {
  font-size: var(--text-sm, 13px);
  color: var(--danger, #DC3545);
  background: var(--danger-dim);
  padding: 8px 12px;
  border-radius: var(--radius-md, 12px);
}

.copilot-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3, 12px);
  padding: var(--space-6, 32px) var(--space-4, 16px);
}
.copilot-empty-mark { color: var(--accent); opacity: 0.7; }
.copilot-empty-mark .tessera-icon { width: 28px; height: 28px; }
.copilot-empty p { font-size: var(--text-sm, 13px); line-height: 1.5; max-width: 240px; margin: 0; }

/* Live loading / per-turn progress line */
.copilot-convo .cc-loading {
  font-size: var(--text-sm, 13px);
  color: var(--text-secondary);
  padding: 4px 0;
}
/* small circular spinner while the Copilot is processing (dock + Home thread) */
.cc-loading { display: flex; align-items: center; gap: 8px; }
.cc-loading::before {
  content: '';
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: cc-spin 0.7s linear infinite;
}
@keyframes cc-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .cc-loading::before { animation: none; } }
.copilot-attach-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--text-xs, 11px);
  color: var(--text-muted);
}
.copilot-attach-note .tessera-icon { width: 13px; height: 13px; }

/* ── Offline banner ───────────────────────────────────────── */
.copilot-banner {
  flex-shrink: 0;
  padding: 8px var(--space-4, 16px);
  font-size: var(--text-xs, 11px);
  color: var(--amber, #b8860b);
  background: rgba(184, 134, 11, 0.12);
  border-top: 1px solid var(--border-color);
}
.copilot-banner[hidden] { display: none; }

/* ── Composer ─────────────────────────────────────────────── */
.copilot-composer {
  flex-shrink: 0;
  padding: var(--space-3, 12px) var(--space-4, 16px) var(--space-4, 16px);
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface, #FFFFFF);
}
.copilot-attach-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2, 8px);
  margin-bottom: var(--space-2, 8px);
}
.copilot-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  font-family: var(--font-ui);
  font-size: var(--text-xs, 11px);
  color: var(--text-secondary);
  background: var(--bg-highlight);
  border: 1px solid var(--border-color);
  border-radius: var(--radius, 8px);
  padding: 4px 6px 4px 10px;
}
.copilot-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.copilot-chip__x {
  border: 0;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.copilot-chip__x:hover { color: var(--danger, #D0342C); }
.copilot-input {
  width: 100%;
  resize: none;
  font-family: var(--font-ui);
  font-size: var(--text-sm, 13px);
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-highlight);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 12px);
  padding: 10px 12px;
  transition: border-color var(--transition, 160ms ease);
}
.copilot-input:focus {
  outline: none;
  border-color: var(--accent);
}
.copilot-input::placeholder { color: var(--text-muted); }

.copilot-composer-row {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  margin-top: var(--space-2, 8px);
}
.copilot-attach-btn {
  position: relative;
  cursor: pointer;
}
.copilot-send { margin-left: auto; }

/* ── Responsive: full-width sheet on phones ───────────────── */
@media (max-width: 767px) {
  .copilot-dock { width: 100%; }
  .copilot-dock.glass-bubble { top: 0; right: 0; bottom: 0; border-radius: 0; }
}
