.copilot-launch {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 31;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 0 17px;
  border: 1px solid #ffffff3d;
  border-radius: 16px;
  background: linear-gradient(130deg, #2872fa, #154cc7);
  color: #fff;
  box-shadow: 0 8px 26px #15409354, inset 0 1px #ffffff38;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}
.copilot-launch:hover { transform: translateY(-2px); box-shadow: 0 12px 30px #15409360; }
.copilot-launch:active { transform: translateY(0); }
.copilot-launch svg { width: 21px; height: 21px; }
.copilot [hidden], .copilot-launch[hidden] { display: none; }

.copilot {
  position: fixed;
  inset: auto max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) auto;
  width: min(458px, calc(100vw - 32px));
  height: min(744px, calc(100dvh - 32px));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--work-border);
  border-radius: 21px;
  background: var(--work-panel);
  color: var(--work-ink);
  box-shadow: 0 24px 70px #091c4e3d, 0 4px 14px #091c4e21;
}
.copilot[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  animation: copilot-enter .2s ease-out;
}
.copilot::backdrop { background: #101b352e; }
@keyframes copilot-enter {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 17px 18px;
  background: radial-gradient(ellipse at 80% -70%, #366cc2 0%, transparent 76%), linear-gradient(115deg, #101c32, #143465);
  color: #fff;
}
.copilot-heading { display: flex; align-items: center; min-width: 0; gap: 12px; }
.copilot-mark {
  display: grid;
  place-items: center;
  flex: 0 0 43px;
  height: 43px;
  border: 1px solid #88b5ff92;
  border-radius: 13px;
  background: linear-gradient(145deg, #4288ff, #174bc9);
  box-shadow: 0 4px 12px #070d1846, inset 0 1px #b5d7ff70;
}
.copilot-mark svg { width: 23px; height: 23px; }
.copilot-brand { min-width: 0; }
.copilot-brand h2 { margin: 0; font-size: 17px; font-weight: 750; letter-spacing: -.025em; }
.copilot-brand p {
  overflow: hidden;
  margin: 4px 0 0;
  color: #cfdef8;
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.copilot-header-actions { display: flex; gap: 6px; flex: 0 0 auto; }
.copilot-header-actions button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #b9d1ff44;
  border-radius: 10px;
  background: #ffffff10;
  color: #edf4ff;
  cursor: pointer;
}
.copilot-header-actions button:not(:disabled):hover { background: #ffffff25; }
.copilot-header-actions button:focus-visible { outline-color: #b6d2ff; }
.copilot-header-actions svg { width: 17px; height: 17px; }
.copilot :disabled { opacity: .48; cursor: default; }

.copilot-body {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding: 22px 18px 18px;
  background: var(--work-bg);
}
.copilot-welcome {
  padding: 22px 18px;
  border: 1px solid var(--work-border);
  border-radius: 16px;
  background: radial-gradient(ellipse at 100% 0, var(--work-blue-soft), transparent 72%), var(--work-panel);
}
.copilot-welcome h3 { margin: 0; font-size: clamp(20px, 5vw, 26px); line-height: 1.18; letter-spacing: -.04em; }
.copilot-welcome p { margin: 8px 0 0; color: var(--work-muted); font-size: 13px; line-height: 1.5; }
.copilot-suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 12px 0 0; }
.copilot-suggestions button {
  position: relative;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 10px;
  min-width: 0;
  min-height: 103px;
  padding: 12px;
  border: 1px solid var(--work-border);
  border-radius: 14px;
  background: var(--work-panel);
  box-shadow: var(--work-shadow);
  color: var(--work-ink);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
}
.copilot-suggestions button svg:first-child { box-sizing: content-box; padding: 6px; border-radius: 9px; background: var(--work-blue-soft); color: var(--work-blue); }
.copilot-suggestions button svg:last-child { position: absolute; top: 20px; right: 12px; color: var(--work-muted); }
.copilot-suggestions button:hover, .copilot-source:hover { border-color: var(--work-blue); background: var(--work-blue-soft); }

.copilot-messages { display: grid; gap: 14px; }
.copilot-message {
  justify-self: start;
  min-width: 0;
  max-width: 100%;
  padding: 14px;
  border: 1px solid var(--work-border);
  border-radius: 5px 16px 16px;
  background: var(--work-panel);
  color: var(--work-ink);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.copilot-message.is-question {
  justify-self: end;
  max-width: 89%;
  padding: 10px 13px;
  border-radius: 15px 15px 4px 15px;
  background: var(--work-blue-soft);
}
.copilot-question-context { display: block; margin: 0 0 4px; color: var(--work-muted); font-size: 11px; }
.copilot-message.is-error { background: var(--crm-red-soft); color: var(--crm-red); }
.copilot-author { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; color: var(--work-blue); font-size: 11px; font-weight: 750; letter-spacing: .05em; }
.copilot-author svg { width: 16px; height: 16px; }
.copilot-message > p { margin: 0; white-space: pre-wrap; }
.copilot-message ul { display: grid; gap: 6px; margin: 9px 0 0; padding: 0 0 0 18px; font-size: 13px; }
.copilot-message li::marker { color: var(--work-blue); }

.copilot-sources { display: grid; gap: 6px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--work-border); }
.copilot-sources > p { margin: 0 0 1px; color: var(--work-muted); font-size: 11px; font-weight: 650; }
.copilot-source {
  display: grid;
  grid-template-columns: 15px minmax(0, 1fr) 14px;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--work-border);
  border-radius: 8px;
  background: var(--work-soft);
  color: var(--work-blue);
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
}
.copilot-source small { display: block; margin-top: 2px; color: var(--work-muted); font-size: 10px; }
.copilot-sources summary { width: fit-content; padding: 3px 4px; color: var(--work-blue); font-size: 12px; cursor: pointer; }
.copilot-sources details .copilot-source { margin-top: 6px; }

.copilot-status {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-top: 12px;
  padding: 8px 12px;
  border: 1px solid var(--work-border);
  border-radius: 10px;
  background: var(--work-panel);
  color: var(--work-muted);
  font-size: 12px;
}
.copilot-pulse { display: flex; gap: 3px; }
.copilot-pulse i { width: 4px; height: 4px; border-radius: 50%; background: var(--work-blue); animation: copilot-pulse 1.25s infinite ease-in-out; }
.copilot-pulse i:nth-child(2) { animation-delay: .15s; }
.copilot-pulse i:nth-child(3) { animation-delay: .3s; }
@keyframes copilot-pulse { 50% { opacity: .35; transform: translateY(-2px); } }

.copilot-compose { padding: 12px 16px; border-top: 1px solid var(--work-border); background: var(--work-panel); }
.copilot-input {
  display: flex;
  align-items: end;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--work-border);
  border-radius: 14px;
  background: var(--work-soft);
}
.copilot-input:focus-within { border-color: var(--work-blue); box-shadow: 0 0 0 2px var(--work-blue-soft); }
.copilot-input textarea {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  max-height: 122px;
  resize: none;
  field-sizing: content;
  padding: 10px 8px;
  border: 0;
  background: transparent;
  color: var(--work-ink);
  font-size: 14px;
  line-height: 20px;
}
.copilot-input textarea:focus-visible { outline: none; }
.copilot-send {
  display: grid;
  place-items: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: var(--crm-action);
  color: #fff;
  cursor: pointer;
}
.copilot-send:not(:disabled):hover { background: var(--crm-action-hover); }
.copilot-keyboard { display: flex; align-items: center; gap: 5px; margin: 8px 0 0; color: var(--work-muted); font-size: 10px; }
.copilot-keyboard kbd { padding: 1px 4px; border: 1px solid var(--work-border); border-radius: 4px; font: inherit; }

@media (max-width: 550px) {
  .copilot { inset: auto 0 0; width: auto; height: min(700px, calc(100dvh - 18px)); border-radius: 20px 20px 0 0; }
  .copilot-header { padding: 14px 14px 13px; }
  .copilot-header-actions button { width: 42px; height: 42px; }
  .copilot-body { padding: 16px 12px 14px; }
  .copilot-welcome { padding: 18px 14px; }
  .copilot-compose { padding: 10px 12px max(10px, env(safe-area-inset-bottom)); }
  .copilot-input textarea { font-size: 16px; }
  .copilot-keyboard { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .copilot[open], .copilot-pulse i { animation: none; }
  .copilot-launch { transition: none; }
}
