/* CMS Copilot side panel styles. Neutral tokens so it blends with the admin. */

/* --- Floating launcher + slide-in drawer (mount shell) --- */
.copilot-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

.copilot-launcher:hover { background: #1d4ed8; }

.copilot-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 420px;
  max-width: 92vw;
  z-index: 1000;
  padding: 14px;
  background: transparent;
  transform: translateX(105%);
  transition: transform 0.22s ease;
}

.copilot-drawer.copilot-drawer--open { transform: translateX(0); }

.copilot-backdrop {
  position: fixed;
  inset: 0;
  z-index: 990;
  background: rgba(15, 23, 42, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.copilot-backdrop.copilot-backdrop--open { opacity: 1; visibility: visible; }

.copilot-drawer__close {
  position: absolute;
  top: 22px;
  right: 26px;
  z-index: 2;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.copilot {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 320px;
  background: var(--copilot-bg, #ffffff);
  border: 1px solid var(--copilot-border, #e5e7eb);
  border-radius: 10px;
  overflow: hidden;
  font-size: 14px;
  color: #1f2937;
}

.copilot__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--copilot-border, #e5e7eb);
  background: #f9fafb;
}

.copilot__title {
  font-weight: 600;
}

.copilot__log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.copilot__msg {
  padding: 8px 10px;
  border-radius: 8px;
  line-height: 1.4;
  max-width: 92%;
  white-space: pre-wrap;
  word-break: break-word;
}

.copilot__msg--user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
}

.copilot__msg--assistant {
  align-self: flex-start;
  background: #f3f4f6;
}

.copilot__msg--error {
  align-self: flex-start;
  background: #fee2e2;
  color: #991b1b;
}

.copilot__plan {
  padding: 0 14px;
}

.plan {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  background: #fff;
}

.plan__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.plan__heading {
  font-weight: 600;
}

.plan__risk,
.plan__step-risk {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.plan__risk--low,
.plan__step-risk--low {
  background: #dcfce7;
  color: #166534;
}

.plan__risk--medium,
.plan__step-risk--medium {
  background: #fef9c3;
  color: #854d0e;
}

.plan__risk--high,
.plan__step-risk--high {
  background: #fee2e2;
  color: #991b1b;
}

.plan__steps {
  list-style: decimal;
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plan__step-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.plan__action {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
}

.plan__desc {
  color: #6b7280;
  font-size: 12px;
  margin-top: 2px;
}

.plan__params {
  margin: 6px 0 0;
  padding: 8px;
  background: #f9fafb;
  border: 1px solid #f0f0f0;
  border-radius: 6px;
  font-size: 12px;
  overflow-x: auto;
  max-height: 160px;
}

.plan__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.plan__run,
.plan__cancel,
.copilot__send {
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
}

.plan__run {
  background: #2563eb;
  color: #fff;
}

.plan__run--danger {
  background: #dc2626;
}

.plan__cancel {
  background: #f3f4f6;
  color: #374151;
}

.copilot__form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--copilot-border, #e5e7eb);
  background: #f9fafb;
}

.copilot__input {
  flex: 1;
  resize: vertical;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

.copilot__send {
  background: #2563eb;
  color: #fff;
  align-self: flex-end;
}

.copilot--busy {
  opacity: 0.7;
  pointer-events: none;
}

.copilot__undo {
  margin-top: 6px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 4px 10px;
  background: #fff;
  color: #374151;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.copilot__undo:hover { background: #f3f4f6; }
.copilot__undo:disabled { opacity: 0.6; cursor: default; }

/* --- In-editor per-field AI actions (Phase 11) --- */
.ai-field {
  position: relative;
  display: inline-block;
  vertical-align: top;
  margin-left: 6px;
}

.ai-field__btn {
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 2px 8px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}

.ai-field__btn:hover { background: #f3f4f6; }
.ai-field__btn:disabled { opacity: 0.6; cursor: default; }

.ai-field__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  z-index: 950;
  min-width: 160px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  padding: 4px;
}

.ai-field__item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 10px;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  color: #1f2937;
  cursor: pointer;
}

.ai-field__item:hover { background: #f3f4f6; }

/* Which AI worker takes the request, and the line saying who answered */
.copilot__worker { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px 0; font-size: 12px; color: #6b7280; }
.copilot__worker-select { width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 8px; font: inherit; font-size: 13px; color: #1f2937; background: #fff; }
.copilot__msg--worker { align-self: flex-start; background: transparent; padding: 0 2px; font-size: 11.5px; font-weight: 600; color: #6d5efc; }

/* Attaching a document to a request */
.copilot__attach { align-self: flex-end; background: #fff; border: 1px solid #d1d5db; border-radius: 6px; padding: 7px 9px; cursor: pointer; font-size: 15px; line-height: 1; }
.copilot__attach:hover { background: #f3f4f6; }
.copilot__attached { display: flex; align-items: center; gap: 8px; margin: 0 14px 8px; padding: 6px 10px; border: 1px solid #c7d2fe; border-radius: 8px; background: #eef2ff; font-size: 12.5px; color: #3730a3; }
.copilot__attached[hidden] { display: none; }
.copilot__attached-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copilot__attached-remove { border: none; background: transparent; cursor: pointer; font-size: 16px; line-height: 1; color: #3730a3; }

/* The worker picker: a row of cards, one per AI worker this business has */
.copilot__crew { padding: 10px 12px 2px; }
.copilot__crew[hidden] { display: none; }
.copilot__crew-label { display: block; margin: 0 2px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #6b7280; }
.copilot__crew-row { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.copilot__crew-card { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 6px; width: 84px; padding: 10px 6px 8px;
  border: 1px solid #e5e7eb; border-radius: 14px; background: #fff; color: #374151; font: inherit; cursor: pointer; scroll-snap-align: center;
  opacity: 0; transform: translateY(8px) scale(.96); animation: copilot-crew-in .38s cubic-bezier(.2, .8, .2, 1) forwards;
  transition: transform .18s ease, box-shadow .22s ease, border-color .22s ease, background .22s ease; }
.copilot__crew-card:hover { transform: translateY(-2px); border-color: #c7d2fe; box-shadow: 0 10px 22px -14px rgba(79, 70, 229, .55); }
.copilot__crew-card:focus-visible { outline: 3px solid #a5b4fc; outline-offset: 2px; }
.copilot__crew-card.is-on { border-color: transparent; background: linear-gradient(#fff, #fff) padding-box, linear-gradient(135deg, #6d5efc, #22d3ee) border-box;
  box-shadow: 0 12px 26px -14px rgba(109, 94, 252, .7); }
.copilot__crew-badge { --crew-hue: 250; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; font-size: 13px; font-weight: 700;
  letter-spacing: .02em; color: #fff; background: linear-gradient(135deg, hsl(var(--crew-hue) 78% 58%), hsl(calc(var(--crew-hue) + 40) 82% 48%));
  transition: transform .22s ease; }
.copilot__crew-card.is-auto .copilot__crew-badge { font-size: 18px; background: linear-gradient(135deg, #6d5efc, #22d3ee); }
.copilot__crew-card:hover .copilot__crew-badge { transform: rotate(-6deg) scale(1.06); }
.copilot__crew-card.is-on .copilot__crew-badge { animation: copilot-crew-pulse 2.4s ease-in-out infinite; }
.copilot__crew-name { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 11px; line-height: 1.25; text-align: center; }
.copilot__crew-card.is-on .copilot__crew-name { font-weight: 600; color: #312e81; }
@keyframes copilot-crew-in { to { opacity: 1; transform: none; } }
@keyframes copilot-crew-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(109, 94, 252, .45); } 50% { box-shadow: 0 0 0 7px rgba(109, 94, 252, 0); } }
@media (prefers-reduced-motion: reduce) {
  .copilot__crew-card { animation: none; opacity: 1; transform: none; transition: none; }
  .copilot__crew-card.is-on .copilot__crew-badge { animation: none; }
}

/* ==========================================================================
   The Copilot's look. It takes the admin's own colours, so it is light on a
   light theme and dark on a dark one, with one accent gradient throughout.
   ========================================================================== */
.copilot-launcher, .copilot-drawer {
  --cp-bg: var(--bg, #ffffff);
  --cp-soft: var(--surface, #f6f7f9);
  --cp-fg: var(--fg, #18181b);
  --cp-muted: var(--fg-muted, #6b7280);
  --cp-line: var(--border, #e4e4e7);
  --cp-a: #6d5efc;
  --cp-b: #22d3ee;
  --cp-grad: linear-gradient(135deg, var(--cp-a), var(--cp-b));
}

/* The button that opens it */
.copilot-launcher { padding: 12px 18px 12px 14px; background: var(--cp-grad); background-size: 180% 180%; box-shadow: 0 10px 28px -10px rgba(109, 94, 252, .75);
  transition: transform .18s ease, box-shadow .25s ease, background-position .6s ease; isolation: isolate; }
.copilot-launcher:hover { background: var(--cp-grad); background-size: 180% 180%; background-position: 100% 50%; transform: translateY(-2px);
  box-shadow: 0 16px 34px -10px rgba(109, 94, 252, .85); }
.copilot-launcher:active { transform: scale(.97); }
.copilot-launcher::after { content: ""; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: var(--cp-grad); opacity: .55;
  animation: copilot-ring 2.8s ease-out infinite; }
.copilot-launcher__spark { display: inline-block; font-size: 16px; animation: copilot-twinkle 3.2s ease-in-out infinite; }

/* The panel */
.copilot-backdrop { background: rgba(8, 10, 20, .5); backdrop-filter: blur(3px); }
.copilot-drawer { width: 440px; padding: 12px; transition: transform .34s cubic-bezier(.2, .8, .2, 1); }
.copilot-drawer__close { top: 26px; right: 28px; width: 30px; height: 30px; border-radius: 10px; color: var(--cp-muted); font-size: 18px;
  transition: background .18s ease, color .18s ease, transform .18s ease; }
.copilot-drawer__close:hover { background: var(--cp-soft); color: var(--cp-fg); transform: rotate(90deg); }
.copilot { background: var(--cp-bg); color: var(--cp-fg); border: 1px solid var(--cp-line); border-radius: 20px;
  box-shadow: 0 30px 70px -30px rgba(8, 10, 30, .65); }

/* Its heading */
.copilot__header { gap: 12px; padding: 16px 56px 14px 16px; border-bottom: 1px solid var(--cp-line);
  background: linear-gradient(135deg, rgba(109, 94, 252, .12), rgba(34, 211, 238, .08)), var(--cp-bg); }
.copilot__mark { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border-radius: 12px; color: #fff; font-size: 17px;
  background: var(--cp-grad); box-shadow: 0 8px 18px -8px rgba(109, 94, 252, .8); }
.copilot__titles { display: flex; flex-direction: column; min-width: 0; }
.copilot__title { font-size: 15px; font-weight: 700; letter-spacing: -.01em; color: var(--cp-fg); }
.copilot__subtitle { font-size: 12px; color: var(--cp-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* The picker */
.copilot__crew { padding: 12px 14px 0; border-bottom: 1px solid var(--cp-line); }
.copilot__crew-label { color: var(--cp-muted); }
.copilot__crew-card { background: var(--cp-soft); border-color: var(--cp-line); color: var(--cp-fg); }
.copilot__crew-card.is-on { background: linear-gradient(var(--cp-bg), var(--cp-bg)) padding-box, var(--cp-grad) border-box; }
.copilot__crew-card.is-on .copilot__crew-name { color: var(--cp-fg); }

/* The conversation */
.copilot__log { gap: 10px; padding: 16px; scrollbar-width: thin; }
.copilot__welcome { margin: auto; display: grid; justify-items: center; gap: 14px; padding: 24px 12px; text-align: center; }
.copilot__orb { display: grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; color: #fff; font-size: 30px; background: var(--cp-grad);
  box-shadow: 0 0 0 10px rgba(109, 94, 252, .1), 0 0 0 22px rgba(34, 211, 238, .06), 0 18px 40px -14px rgba(109, 94, 252, .8);
  animation: copilot-float 4.5s ease-in-out infinite; }
.copilot__welcome-text { margin: 0; max-width: 260px; font-size: 14px; line-height: 1.5; color: var(--cp-muted); }
.copilot__msg { padding: 10px 13px; border-radius: 16px; line-height: 1.5; animation: copilot-msg-in .28s cubic-bezier(.2, .8, .2, 1) both; }
.copilot__msg--user { background: var(--cp-grad); color: #fff; border-bottom-right-radius: 6px; box-shadow: 0 10px 22px -14px rgba(109, 94, 252, .9); }
.copilot__msg--assistant { background: var(--cp-soft); color: var(--cp-fg); border: 1px solid var(--cp-line); border-bottom-left-radius: 6px; }
.copilot__msg--error { background: rgba(239, 68, 68, .12); color: #ef4444; border: 1px solid rgba(239, 68, 68, .3); border-bottom-left-radius: 6px; }
.copilot__msg--worker { color: var(--cp-a); letter-spacing: .01em; }
.copilot__typing { align-self: flex-start; display: inline-flex; gap: 5px; padding: 13px 14px; border-radius: 16px; border-bottom-left-radius: 6px;
  background: var(--cp-soft); border: 1px solid var(--cp-line); }
.copilot__typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--cp-a); animation: copilot-dot 1.1s ease-in-out infinite; }
.copilot__typing span:nth-child(2) { animation-delay: .15s; }
.copilot__typing span:nth-child(3) { animation-delay: .3s; background: var(--cp-b); }
.copilot--busy { opacity: 1; }                 /* the dots say it is working; the panel no longer fades */

/* A proposed plan */
.copilot__plan { padding: 0 16px; }
.plan { background: var(--cp-soft); border: 1px solid var(--cp-line); border-radius: 16px; padding: 14px; color: var(--cp-fg);
  animation: copilot-msg-in .3s cubic-bezier(.2, .8, .2, 1) both; }
.plan__desc { color: var(--cp-muted); }
.plan__params { background: var(--cp-bg); border-color: var(--cp-line); color: var(--cp-fg); border-radius: 10px; }
.plan__run { background: var(--cp-grad); border-radius: 10px; transition: transform .16s ease, box-shadow .2s ease; }
.plan__run:hover { transform: translateY(-1px); box-shadow: 0 10px 20px -12px rgba(109, 94, 252, .9); }
.plan__run--danger { background: #dc2626; }
.plan__cancel { background: transparent; color: var(--cp-muted); border: 1px solid var(--cp-line); border-radius: 10px; }
.plan__cancel:hover { color: var(--cp-fg); }
.copilot__undo { background: transparent; color: var(--cp-fg); border-color: var(--cp-line); border-radius: 10px; }
.copilot__undo:hover { background: var(--cp-soft); }

/* Where the request is written */
.copilot__attached { margin: 0 16px 8px; border-color: rgba(109, 94, 252, .4); background: rgba(109, 94, 252, .1); color: var(--cp-fg); border-radius: 12px; }
.copilot__form { align-items: flex-end; gap: 8px; margin: 10px 14px 14px; padding: 8px; border: 1px solid var(--cp-line); border-radius: 18px; background: var(--cp-soft);
  transition: border-color .2s ease, box-shadow .2s ease; }
.copilot__form:focus-within { border-color: var(--cp-a); box-shadow: 0 0 0 4px rgba(109, 94, 252, .16); }
.copilot__input { min-height: 44px; max-height: 160px; resize: none; border: 0; outline: 0; background: transparent; color: var(--cp-fg); padding: 10px 6px; line-height: 1.45; }
.copilot__input::placeholder { color: var(--cp-muted); opacity: .85; }
.copilot__attach { align-self: flex-end; width: 38px; height: 38px; padding: 0; border: 0; border-radius: 12px; background: transparent; color: var(--cp-muted);
  transition: background .18s ease, color .18s ease; }
.copilot__attach:hover { background: var(--cp-bg); color: var(--cp-fg); }
.copilot__send { align-self: flex-end; width: 38px; height: 38px; padding: 0; border-radius: 12px; background: var(--cp-grad); color: #fff; font-size: 18px; line-height: 1;
  transition: transform .16s ease, box-shadow .2s ease, opacity .2s ease; }
.copilot__send:hover { transform: translateY(-1px) scale(1.04); box-shadow: 0 10px 20px -10px rgba(109, 94, 252, .9); }
.copilot--busy .copilot__send { opacity: .5; pointer-events: none; }

@keyframes copilot-ring { 0% { transform: scale(1); opacity: .5; } 70%, 100% { transform: scale(1.35, 1.7); opacity: 0; } }
@keyframes copilot-twinkle { 0%, 100% { transform: rotate(0) scale(1); } 50% { transform: rotate(90deg) scale(1.25); } }
@keyframes copilot-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes copilot-msg-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes copilot-dot { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-5px); opacity: 1; } }
@media (max-width: 520px) { .copilot-drawer { width: 100vw; max-width: 100vw; padding: 0; } .copilot { border-radius: 0; border: 0; } }
@media (prefers-reduced-motion: reduce) {
  .copilot-launcher::after, .copilot-launcher__spark, .copilot__orb, .copilot__msg, .plan, .copilot__typing span { animation: none; }
  .copilot-drawer, .copilot-launcher, .copilot-drawer__close { transition: none; }
}
.copilot-drawer { box-sizing: border-box; }
.copilot__log { min-height: 0; }
.copilot__plan { max-height: 46vh; overflow-y: auto; }
.copilot__attach { font-size: 18px; }

/* The launcher can be dragged anywhere on the screen. */
.copilot-launcher { touch-action: none; user-select: none; -webkit-user-select: none; }
.copilot-launcher.is-dragging { cursor: grabbing; transform: scale(1.05); transition: none; }
