/* Cosgral live chat — matches site language (Inter / Plex Mono, ink on black) */
.cg-chat-root {
  --cg-chat-bg: rgba(8, 8, 8, 0.92);
  --cg-chat-ink: #f5f5f5;
  --cg-chat-muted: #888;
  --cg-chat-border: rgba(255, 255, 255, 0.1);
  --cg-chat-fill: #f5f5f5;
  --cg-chat-on-fill: #030303;
  --cg-chat-bubble-agent: rgba(255, 255, 255, 0.07);
  --cg-chat-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --cg-chat-font: "Inter", system-ui, sans-serif;
  --cg-chat-mono: "IBM Plex Mono", ui-monospace, monospace;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 12000;
  font-family: var(--cg-chat-font);
  color: var(--cg-chat-ink);
  pointer-events: none;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="light"] .cg-chat-root {
  --cg-chat-bg: rgba(250, 250, 250, 0.94);
  --cg-chat-ink: #030303;
  --cg-chat-muted: #666;
  --cg-chat-border: rgba(0, 0, 0, 0.12);
  --cg-chat-fill: #030303;
  --cg-chat-on-fill: #f5f5f5;
  --cg-chat-bubble-agent: rgba(0, 0, 0, 0.06);
}

.cg-chat-root * {
  box-sizing: border-box;
}

.cg-chat-launcher,
.cg-chat-panel {
  pointer-events: auto;
}

/* —— Launcher —— */
.cg-chat-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-width: 3.25rem;
  height: 3.25rem;
  padding: 0 1.15rem;
  border: 1px solid var(--cg-chat-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--cg-chat-ink);
  font-family: var(--cg-chat-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.4s var(--cg-chat-ease),
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    padding 0.35s var(--cg-chat-ease),
    width 0.35s var(--cg-chat-ease);
}

html[data-theme="light"] .cg-chat-launcher {
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.cg-chat-launcher:hover {
  transform: scale(1.04);
  border-color: rgba(255, 255, 255, 0.35);
}

html[data-theme="light"] .cg-chat-launcher:hover {
  border-color: rgba(0, 0, 0, 0.28);
}

.cg-chat-launcher:active {
  transform: scale(0.98);
}

.cg-chat-launcher[aria-expanded="true"] {
  width: 3.25rem;
  padding: 0;
  background: var(--cg-chat-fill);
  color: var(--cg-chat-on-fill);
  border-color: var(--cg-chat-fill);
}

.cg-chat-launcher__icon {
  display: grid;
  place-items: center;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
}

.cg-chat-launcher__icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cg-chat-launcher__icon--close {
  display: none;
}

.cg-chat-launcher[aria-expanded="true"] .cg-chat-launcher__icon--chat {
  display: none;
}

.cg-chat-launcher[aria-expanded="true"] .cg-chat-launcher__icon--close {
  display: grid;
}

.cg-chat-launcher[aria-expanded="true"] .cg-chat-label {
  display: none;
}

.cg-chat-badge {
  position: absolute;
  top: -0.3rem;
  right: -0.15rem;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: 999px;
  background: var(--cg-chat-fill);
  color: var(--cg-chat-on-fill);
  font-family: var(--cg-chat-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.1rem;
  text-align: center;
  text-transform: none;
  box-shadow: 0 0 0 2px var(--cg-chat-on-fill);
}

/* —— Panel —— */
.cg-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(3.25rem + 0.85rem);
  width: min(22.5rem, calc(100vw - 1.5rem));
  height: min(30rem, calc(100dvh - 7.5rem));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--cg-chat-border);
  border-radius: 1.15rem;
  background: var(--cg-chat-bg);
  backdrop-filter: blur(22px) saturate(1.15);
  -webkit-backdrop-filter: blur(22px) saturate(1.15);
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  overflow: hidden;
  transform-origin: calc(100% - 1.6rem) calc(100% + 0.4rem);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, 1.1rem, 0) scale(0.92);
  filter: blur(6px);
  transition:
    opacity 0.42s var(--cg-chat-ease),
    transform 0.52s var(--cg-chat-ease),
    filter 0.42s var(--cg-chat-ease),
    visibility 0s linear 0.42s;
}

.cg-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
  filter: blur(0);
  transition:
    opacity 0.42s var(--cg-chat-ease),
    transform 0.52s var(--cg-chat-ease),
    filter 0.42s var(--cg-chat-ease),
    visibility 0s linear 0s;
}

.cg-chat-panel.is-open .cg-chat-head,
.cg-chat-panel.is-open .cg-chat-msgs,
.cg-chat-panel.is-open .cg-chat-form {
  animation: cg-chat-rise 0.55s var(--cg-chat-ease) both;
}

.cg-chat-panel.is-open .cg-chat-head {
  animation-delay: 0.06s;
}

.cg-chat-panel.is-open .cg-chat-msgs {
  animation-delay: 0.12s;
}

.cg-chat-panel.is-open .cg-chat-form {
  animation-delay: 0.18s;
}

@keyframes cg-chat-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cg-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 1rem 1.1rem 0.9rem;
  border-bottom: 1px solid var(--cg-chat-border);
}

.cg-chat-head__brand {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}

.cg-chat-head__eyebrow {
  font-family: var(--cg-chat-mono);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--cg-chat-muted);
}

.cg-chat-head strong {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--cg-chat-ink);
}

.cg-chat-status {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--cg-chat-ink);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cg-chat-ink) 18%, transparent);
  flex-shrink: 0;
  animation: cg-chat-pulse 2.4s var(--cg-chat-ease) infinite;
}

@keyframes cg-chat-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.85);
  }
}

.cg-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.05rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

html[data-theme="light"] .cg-chat-msgs {
  scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

.cg-chat-bubble {
  max-width: 84%;
  padding: 0.7rem 0.85rem;
  border-radius: 1rem;
  font-size: 0.875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  animation: cg-chat-bubble-in 0.4s var(--cg-chat-ease) both;
}

@keyframes cg-chat-bubble-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.cg-chat-bubble--visitor {
  align-self: flex-end;
  background: var(--cg-chat-fill);
  color: var(--cg-chat-on-fill);
  border-bottom-right-radius: 0.3rem;
}

.cg-chat-bubble--agent {
  align-self: flex-start;
  background: var(--cg-chat-bubble-agent);
  color: var(--cg-chat-ink);
  border: 1px solid var(--cg-chat-border);
  border-bottom-left-radius: 0.3rem;
}

.cg-chat-empty {
  margin: auto;
  text-align: center;
  max-width: 14rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: center;
}

.cg-chat-empty__mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--cg-chat-border);
  display: grid;
  place-items: center;
  opacity: 0.7;
}

.cg-chat-empty__mark svg {
  width: 1rem;
  height: 1rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cg-chat-empty__label {
  font-family: var(--cg-chat-mono);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--cg-chat-muted);
}

.cg-chat-empty__text {
  font-size: 0.82rem;
  line-height: 1.5;
  color: color-mix(in srgb, var(--cg-chat-ink) 62%, transparent);
}

.cg-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.85rem;
  border-top: 1px solid var(--cg-chat-border);
}

.cg-chat-form input {
  flex: 1;
  min-width: 0;
  height: 2.65rem;
  border: 1px solid var(--cg-chat-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--cg-chat-ink);
  padding: 0 1rem;
  font-family: var(--cg-chat-font);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.25s ease, background 0.25s ease;
}

html[data-theme="light"] .cg-chat-form input {
  background: rgba(0, 0, 0, 0.03);
}

.cg-chat-form input::placeholder {
  color: var(--cg-chat-muted);
}

.cg-chat-form input:focus {
  border-color: color-mix(in srgb, var(--cg-chat-ink) 45%, transparent);
  background: rgba(255, 255, 255, 0.06);
}

.cg-chat-form button {
  height: 2.65rem;
  padding: 0 1.05rem;
  border: 1px solid var(--cg-chat-fill);
  border-radius: 999px;
  background: var(--cg-chat-fill);
  color: var(--cg-chat-on-fill);
  font-family: var(--cg-chat-mono);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.35s var(--cg-chat-ease), opacity 0.2s ease, filter 0.2s ease;
}

.cg-chat-form button:hover:not(:disabled) {
  transform: scale(1.04);
  filter: brightness(1.06);
}

.cg-chat-form button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Hide when megamenu / lightbox open */
html.is-nav-open .cg-chat-root,
html.is-lightbox-open .cg-chat-root,
body.is-nav-open .cg-chat-root,
.cg-nav-open .cg-chat-root {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

@media (max-width: 640px) {
  .cg-chat-launcher {
    width: 3.25rem;
    padding: 0;
  }

  .cg-chat-launcher .cg-chat-label {
    display: none;
  }

  .cg-chat-panel {
    width: min(100vw - 1.25rem, 22.5rem);
    height: min(70dvh, 30rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cg-chat-panel,
  .cg-chat-launcher,
  .cg-chat-bubble,
  .cg-chat-status,
  .cg-chat-panel.is-open .cg-chat-head,
  .cg-chat-panel.is-open .cg-chat-msgs,
  .cg-chat-panel.is-open .cg-chat-form {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }

  .cg-chat-panel {
    filter: none;
  }
}
