:root {
  --cgai-navy: #07101f;
  --cgai-navy-2: #0d1b31;
  --cgai-panel: #f7f9fc;
  --cgai-white: #ffffff;
  --cgai-gold: #d9b84a;
  --cgai-gold-light: #f1da86;
  --cgai-text: #162033;
  --cgai-muted: #657086;
  --cgai-border: #dfe5ef;
  --cgai-danger: #a91d34;
  --cgai-success: #2aa778;
  --cgai-shadow: 0 24px 75px rgba(2, 9, 22, .34), 0 8px 24px rgba(2, 9, 22, .18);
}

.cgai-root,
.cgai-root * {
  box-sizing: border-box;
}

.cgai-root {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 2147482000;
  font-family: Roboto, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  color: var(--cgai-text);
  direction: ltr;
}

.cgai-launcher {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 210px;
  min-height: 62px;
  padding: 9px 17px 9px 10px;
  border: 1px solid rgba(244, 216, 122, .5);
  border-radius: 999px;
  background: linear-gradient(135deg, #0d1b31 0%, #07101f 100%);
  box-shadow: 0 14px 35px rgba(1, 7, 18, .35);
  color: #fff;
  cursor: pointer;
  text-align: left;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.cgai-launcher:hover,
.cgai-launcher:focus-visible {
  transform: translateY(-2px);
  border-color: var(--cgai-gold-light);
  box-shadow: 0 18px 44px rgba(1, 7, 18, .43);
  outline: none;
}

.cgai-launcher-icon {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  flex: 0 0 43px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--cgai-gold-light), var(--cgai-gold));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .55);
}

.cgai-launcher-icon svg {
  width: 23px;
  height: 23px;
  fill: #111827;
}

.cgai-launcher-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cgai-launcher-copy strong {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.15;
}

.cgai-launcher-copy small {
  margin-top: 3px;
  color: #c7d0df;
  font-size: 11px;
  white-space: nowrap;
}

.cgai-online-dot {
  position: absolute;
  top: 5px;
  left: 45px;
  width: 12px;
  height: 12px;
  border: 2px solid var(--cgai-navy-2);
  border-radius: 50%;
  background: var(--cgai-success);
}

.cgai-panel {
  position: absolute;
  right: 0;
  bottom: 77px;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  width: min(390px, calc(100vw - 28px));
  height: min(650px, calc(100vh - 120px));
  overflow: hidden;
  border: 1px solid rgba(217, 184, 74, .45);
  border-radius: 22px;
  background: var(--cgai-panel);
  box-shadow: var(--cgai-shadow);
  transform-origin: bottom right;
  animation: cgai-panel-in .2s ease both;
}

.cgai-panel[hidden] {
  display: none !important;
}

@keyframes cgai-panel-in {
  from { opacity: 0; transform: translateY(12px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.cgai-header {
  display: grid;
  grid-template-columns: 43px minmax(0, 1fr) 34px 34px;
  align-items: center;
  gap: 10px;
  min-height: 75px;
  padding: 13px 14px;
  background:
    radial-gradient(circle at 85% 0%, rgba(217, 184, 74, .2), transparent 34%),
    linear-gradient(135deg, #0d1b31 0%, #07101f 100%);
  color: #fff;
}

.cgai-avatar {
  display: grid;
  place-items: center;
  width: 43px;
  height: 43px;
  border: 1px solid rgba(255, 255, 255, .4);
  border-radius: 13px;
  background: linear-gradient(145deg, var(--cgai-gold-light), var(--cgai-gold));
  color: #101827;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 7px 18px rgba(0, 0, 0, .22);
}

.cgai-title-wrap {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.cgai-title-wrap strong {
  overflow: hidden;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cgai-title-wrap span {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: #c7d0df;
  font-size: 11px;
}

.cgai-title-wrap i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cgai-success);
  box-shadow: 0 0 0 3px rgba(42, 167, 120, .15);
}

.cgai-icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  color: #fff;
  font: 700 20px/1 Arial, sans-serif;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}

.cgai-icon-button:hover,
.cgai-icon-button:focus-visible {
  border-color: rgba(241, 218, 134, .65);
  background: rgba(255, 255, 255, .13);
  outline: none;
}

.cgai-context-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 39px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--cgai-border);
  background: #fff;
  color: #5a667a;
  font-size: 10.5px;
  font-weight: 600;
}

.cgai-shield {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #e3f5ed;
  color: #19865f;
  font-size: 11px;
  font-weight: 900;
}

.cgai-messages {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 17px 14px 9px;
  scrollbar-width: thin;
  scrollbar-color: #b9c3d3 transparent;
  overscroll-behavior: contain;
}

.cgai-messages::-webkit-scrollbar { width: 6px; }
.cgai-messages::-webkit-scrollbar-thumb { border-radius: 99px; background: #b9c3d3; }

.cgai-message {
  display: flex;
  margin: 0 0 14px;
  flex-direction: column;
  animation: cgai-message-in .18s ease both;
}

@keyframes cgai-message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.cgai-message--assistant { align-items: flex-start; }
.cgai-message--user { align-items: flex-end; }

.cgai-bubble {
  max-width: 88%;
  padding: 11px 13px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
}

.cgai-message--assistant .cgai-bubble {
  border: 1px solid var(--cgai-border);
  border-top-left-radius: 5px;
  background: #fff;
  color: #253047;
  box-shadow: 0 5px 13px rgba(14, 26, 47, .05);
}

.cgai-message--user .cgai-bubble {
  border: 1px solid #172b48;
  border-top-right-radius: 5px;
  background: linear-gradient(135deg, #132743, #0d1b31);
  color: #fff;
  box-shadow: 0 5px 14px rgba(9, 25, 48, .16);
}

.cgai-bubble p {
  margin: 0 0 8px;
  color: inherit;
  font: inherit;
}

.cgai-bubble p:last-child { margin-bottom: 0; }

.cgai-message-meta {
  margin-top: 4px;
  padding: 0 4px;
  color: #8a94a7;
  font-size: 9.5px;
}

.cgai-response-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid #e8ecf3;
}

.cgai-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 10px;
  border: 1px solid #cfd7e4;
  border-radius: 9px;
  text-decoration: none !important;
  font-size: 10.5px;
  font-weight: 800;
  line-height: 1.2;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}

.cgai-action:hover,
.cgai-action:focus-visible {
  transform: translateY(-1px);
  outline: none;
}

.cgai-action--primary {
  border-color: #172b48;
  background: #0d1b31;
  color: #fff !important;
}

.cgai-action--secondary {
  background: #fff;
  color: #24324b !important;
}

.cgai-action--danger {
  border-color: #9d1e34;
  background: #a91d34;
  color: #fff !important;
}

.cgai-quick-actions {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 4px 14px 10px;
  scrollbar-width: none;
  transition: max-height .2s ease, opacity .2s ease, padding .2s ease;
}

.cgai-quick-actions::-webkit-scrollbar { display: none; }

.cgai-quick-actions.is-collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
}

.cgai-quick-action {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #cbd4e2;
  border-radius: 999px;
  background: #fff;
  color: #26344c;
  font: 700 10.5px/1.2 Roboto, sans-serif;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .16s ease, color .16s ease, background .16s ease;
}

.cgai-quick-action:hover,
.cgai-quick-action:focus-visible {
  border-color: #b69735;
  background: #fffaf0;
  color: #725a12;
  outline: none;
}

.cgai-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 31px;
  padding: 2px 16px 8px;
  color: var(--cgai-muted);
  font-size: 10px;
}

.cgai-typing[hidden] { display: none !important; }

.cgai-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #8c98ab;
  animation: cgai-dot 1s infinite ease-in-out;
}

.cgai-typing span:nth-child(2) { animation-delay: .12s; }
.cgai-typing span:nth-child(3) { animation-delay: .24s; }
.cgai-typing em { margin-left: 4px; font-style: normal; }

@keyframes cgai-dot {
  0%, 70%, 100% { transform: translateY(0); opacity: .45; }
  35% { transform: translateY(-3px); opacity: 1; }
}

.cgai-composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--cgai-border);
  background: #fff;
}

.cgai-composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 112px;
  margin: 0;
  padding: 10px 12px;
  resize: none;
  overflow-y: auto;
  border: 1px solid #cfd7e4;
  border-radius: 12px;
  background: #f9fbfe;
  color: #18243a;
  box-shadow: none;
  font: 400 12px/1.45 Roboto, sans-serif;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.cgai-composer textarea::placeholder { color: #8a94a6; }

.cgai-composer textarea:focus {
  border-color: #b99735;
  outline: none;
  box-shadow: 0 0 0 3px rgba(217, 184, 74, .15);
}

.cgai-composer button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid #9c7c24;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--cgai-gold-light), var(--cgai-gold));
  color: #0d1727;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease;
}

.cgai-composer button:hover,
.cgai-composer button:focus-visible {
  transform: translateY(-1px);
  filter: brightness(1.04);
  outline: none;
}

.cgai-composer button:disabled,
.cgai-composer textarea:disabled {
  cursor: wait;
  opacity: .65;
}

.cgai-composer svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.cgai-privacy {
  margin: 0;
  padding: 0 12px 10px;
  background: #fff;
  color: #7d8798;
  font: 400 9px/1.4 Roboto, sans-serif;
  text-align: center;
}

@media (max-width: 640px) {
  html.cgai-chat-open,
  html.cgai-chat-open body {
    overflow: hidden !important;
  }

  .cgai-root {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .cgai-launcher {
    min-width: 0;
    width: 58px;
    height: 58px;
    min-height: 58px;
    padding: 7px;
  }

  .cgai-launcher-icon {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  .cgai-launcher-copy { display: none; }
  .cgai-online-dot { top: 4px; left: 42px; }

  .cgai-panel {
    position: fixed;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 8px;
    width: auto;
    height: min(720px, calc(100dvh - 16px - env(safe-area-inset-bottom)));
    max-height: none;
    border-radius: 19px;
    transform-origin: bottom center;
  }

  .cgai-bubble { max-width: 91%; }
  .cgai-context-bar { font-size: 9.8px; }
}

@media (max-width: 380px) {
  .cgai-header {
    grid-template-columns: 39px minmax(0, 1fr) 32px 32px;
    gap: 7px;
    padding-right: 10px;
    padding-left: 10px;
  }
  .cgai-avatar { width: 39px; height: 39px; }
  .cgai-icon-button { width: 32px; height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  .cgai-root *,
  .cgai-root *::before,
  .cgai-root *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .cgai-root { display: none !important; }
}
