/*
 * InstallerHQ AI Chat widget.
 *
 * Lives inside its own iframe, so this file owns the whole document — there is
 * no host page to inherit from and nothing here can escape. The iframe is sized
 * by the parent (76×76 closed, a card or full screen open), which is why the
 * launcher and the panel are both anchored to the bottom-right of the viewport
 * rather than laid out in flow.
 *
 * The accent colour is a custom property so each installer's widget renders in
 * their brand, not ours.
 */

:root {
  --accent: #7ac943;
  --accent-deep: #4f8f2f;
  --accent-ink: #ffffff;
  --ink: #101418;
  --ink-soft: #5b6670;
  --line: #e7ebee;
  --surface: #ffffff;
  --surface-alt: #f5f7f8;
  --radius: 20px;
  --shadow: 0 24px 60px -28px rgba(16, 20, 24, 0.45), 0 4px 14px -6px rgba(16, 20, 24, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: transparent;
  font-family: Manrope, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.cw-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- launcher */

/* Centred in its own frame: the frame carries the offset from the page corner,
   so the launcher does not need to know where on the page it sits. */
.cw-launcher {
  position: fixed;
  inset: 0;
  margin: auto;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--accent-ink);
  background: linear-gradient(155deg, var(--accent), var(--accent-deep));
  box-shadow: 0 12px 26px -10px rgba(16, 20, 24, 0.5);
  display: grid;
  place-items: center;
  transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.22s;
}

.cw-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 16px 32px -10px rgba(16, 20, 24, 0.55);
}

.cw-launcher:active {
  transform: scale(0.97);
}

.cw-launcher:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 3px;
}

/* Both icons share one grid cell and cross-fade, so the button never reflows. */
.cw-launcher-ic {
  grid-area: 1 / 1;
  display: grid;
  place-items: center;
  transition: opacity 0.18s, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.cw-launcher-ic svg {
  width: 26px;
  height: 26px;
}

.cw-launcher-ic--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.cw-launcher[aria-expanded='true'] .cw-launcher-ic--chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.cw-launcher[aria-expanded='true'] .cw-launcher-ic--close {
  opacity: 1;
  transform: none;
}

/* A single quiet pulse on arrival — enough to be noticed, not a flashing dot. */
.cw-nudge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ff5a4e;
  border: 2px solid #fff;
  animation: cw-pop 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cw-pop {
  from {
    transform: scale(0);
  }
  to {
    transform: scale(1);
  }
}

/* ------------------------------------------------------------------- panel */

.cw-panel {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(0.985);
  transform-origin: bottom right;
  transition: opacity 0.2s, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

.cw-panel[hidden] {
  display: none;
}

.cw-panel.is-in {
  opacity: 1;
  transform: none;
}

.cw-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.cw-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--accent-ink);
  background: linear-gradient(155deg, var(--accent), var(--accent-deep));
}

.cw-id {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.cw-id b {
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cw-id small {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.cw-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2fbf4e;
  box-shadow: 0 0 0 3px rgba(47, 191, 78, 0.16);
}

.cw-x {
  margin-left: auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s;
}

.cw-x svg {
  width: 17px;
  height: 17px;
}

.cw-x:hover {
  background: var(--surface-alt);
  color: var(--ink);
}

.cw-x:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 1px;
}

/* --------------------------------------------------------------------- log */

.cw-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
}

/* Sit the conversation on the bottom edge rather than leaving a dead gap under
   a one-line greeting. margin-top:auto rather than justify-content:flex-end,
   which clips the top of an overflowing column in a scroll container. */
.cw-log > *:first-child {
  margin-top: auto;
}

.cw-log::-webkit-scrollbar {
  width: 6px;
}

.cw-log::-webkit-scrollbar-thumb {
  background: #d9dee2;
  border-radius: 3px;
}

.cw-msg {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 0.925rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: cw-rise 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cw-rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cw-msg--them {
  align-self: flex-start;
  background: var(--surface-alt);
  border-bottom-left-radius: 6px;
}

.cw-msg--you {
  align-self: flex-end;
  color: var(--accent-ink);
  background: linear-gradient(155deg, var(--accent), var(--accent-deep));
  border-bottom-right-radius: 6px;
}

/* Sources are shown, not hidden: the visitor can check the answer against the
   page it came from, which is the whole point of answering only from the site. */
.cw-src {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 86%;
  margin: -3px 0 2px;
}

.cw-src a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--ink-soft);
  text-decoration: none;
  background: var(--surface);
  transition: border-color 0.15s, color 0.15s;
}

.cw-src a span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-src a:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.cw-src svg {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
}

.cw-book {
  align-self: flex-start;
  margin: 2px 0 4px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 0.87rem;
  font-weight: 800;
  color: var(--accent-ink);
  background: linear-gradient(155deg, var(--accent), var(--accent-deep));
  cursor: pointer;
  box-shadow: 0 10px 22px -12px rgba(16, 20, 24, 0.6);
  transition: transform 0.18s cubic-bezier(0.22, 1, 0.36, 1);
}

.cw-book:hover {
  transform: translateY(-1px);
}

.cw-book:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 2px;
}

/* typing indicator */
.cw-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 14px;
  background: var(--surface-alt);
  border-radius: 16px;
  border-bottom-left-radius: 6px;
}

.cw-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b6bfc6;
  animation: cw-blink 1.25s infinite ease-in-out;
}

.cw-typing i:nth-child(2) {
  animation-delay: 0.16s;
}

.cw-typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes cw-blink {
  0%,
  70%,
  100% {
    opacity: 0.32;
    transform: translateY(0);
  }
  35% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ------------------------------------------------------------------- chips */

.cw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px 0;
}

.cw-chips:empty {
  display: none;
}

.cw-chip {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  animation: cw-rise 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.cw-chip:hover {
  border-color: var(--accent);
  background: var(--surface-alt);
}

.cw-chip:active {
  transform: scale(0.97);
}

.cw-chip:focus-visible {
  outline: 2px solid var(--accent-deep);
  outline-offset: 2px;
}

/* ----------------------------------------------------------------- compose */

.cw-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px 8px;
}

.cw-compose textarea {
  flex: 1;
  min-height: 44px;
  max-height: 116px;
  padding: 11px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ink);
  background: var(--surface);
  resize: none;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.cw-compose textarea::placeholder {
  color: #9aa4ac;
}

.cw-compose textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(122, 201, 67, 0.16);
}

.cw-send {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 13px;
  color: var(--accent-ink);
  background: linear-gradient(155deg, var(--accent), var(--accent-deep));
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: opacity 0.15s, transform 0.15s;
}

.cw-send svg {
  width: 19px;
  height: 19px;
  margin-left: -1px;
}

.cw-send:disabled {
  opacity: 0.4;
  cursor: default;
}

.cw-send:not(:disabled):active {
  transform: scale(0.94);
}

.cw-send:focus-visible {
  outline: 3px solid var(--accent-deep);
  outline-offset: 2px;
}

.cw-foot {
  margin: 0;
  padding: 0 14px 12px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #9aa4ac;
  text-align: center;
}

.cw-foot b {
  color: var(--ink-soft);
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 479px) {
  .cw-panel {
    border-radius: 0;
    border: 0;
    /* Keep the composer clear of the iOS home indicator. */
    padding-bottom: env(safe-area-inset-bottom);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------------------------------------------------------------- inline ---
   Embedded in the flow of a page rather than floating over it: the panel is
   the whole document, and the page around it owns the frame and shadow. */
.cw-inline .cw-launcher {
  display: none;
}

.cw-inline .cw-x {
  display: none;
}

.cw-inline .cw-panel {
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
