/* Cloudacio web concierge widget.
 *
 * Loaded on every page, so every value falls back to a literal: the design
 * tokens live in each page's inline <style>, and a component that silently
 * turns black-on-black when one is missing is worse than one that never used
 * them. Nothing here depends on a page having defined :root.
 */

.cx-launcher,
.cx-panel {
  --cx-purple: var(--mid-purple, #5A2AAE);
  --cx-purple-bright: var(--bright-purple, #6A2ED5);
  --cx-pale: var(--pale-purple, #F3EEFF);
  --cx-border: var(--card-border, #E8E2F2);
  --cx-heading: var(--heading, #1A0E2E);
  --cx-body: var(--body-text, #3D3354);
  --cx-mid: var(--mid-gray, #6B607F);
  --cx-white: var(--card-bg, #FFFFFF);
  --cx-deep: var(--deep-purple, #2E0B54);
  --cx-online: #22C55E;
  --cx-font: var(--font-body, 'Plus Jakarta Sans', -apple-system, sans-serif);
  font-family: var(--cx-font);
  box-sizing: border-box;
}

.cx-launcher *,
.cx-panel *,
.cx-panel *::before,
.cx-panel *::after { box-sizing: inherit; }

/* ── Launcher ─────────────────────────────────────────────────────────── */

.cx-launcher {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9998;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.72rem 1.2rem;
  border: none;
  border-radius: 999px;
  background: var(--cx-purple);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(90, 42, 174, 0.35);
  transition: transform 0.25s, background 0.25s, box-shadow 0.25s;
}

.cx-launcher:hover {
  background: var(--cx-purple-bright);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(90, 42, 174, 0.4);
}

.cx-launcher:focus-visible,
.cx-panel :focus-visible {
  outline: 2px solid var(--cx-purple-bright);
  outline-offset: 2px;
}

/* Closed, the launcher is a status light and a name — the face lives inside,
 * where there is a conversation to attach it to. On a pill this small the mark
 * was competing with the words, and the dot it sat beside had to be pushed into
 * a corner to fit, where it read as a notification badge rather than a state. */
.cx-launcher-dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cx-online);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: cx-pulse 2.4s infinite;
}

.cx-launcher[hidden] { display: none; }

/* ── Panel ────────────────────────────────────────────────────────────── */

.cx-panel {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 3rem));
  height: min(580px, calc(100vh - 3rem));
  background: var(--cx-white);
  border: 1px solid var(--cx-border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(26, 14, 46, 0.18);
  overflow: hidden;
  transform-origin: bottom right;
  animation: cx-in 0.22s ease-out;
}

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

@keyframes cx-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.cx-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: linear-gradient(135deg, var(--cx-deep) 0%, var(--cx-purple) 100%);
  color: #fff;
}

.cx-avatar {
  flex: none;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: 1.5px solid rgba(255, 255, 255, 0.25);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.cx-avatar svg { width: 26px; height: 26px; display: block; }

.cx-id { min-width: 0; }

.cx-name {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.cx-head h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.2;
  color: #fff;
}

/* A chip carries the disclosure better than a sentence did. It sits where a
 * verified badge would, reads in one glance, and survives being skimmed —
 * which "AI assistant · always on", set small and lowercase under the name,
 * did not. What it must never become is decoration: this is the only thing on
 * a widget with a name, a face and a green light that says it is not a person. */
.cx-tag {
  flex: none;
  padding: 0.1rem 0.4rem;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.28);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.4;
  color: #fff;
}

/* The status row. A green dot next to a name is the convention for "a person
 * is sitting there", so the words beside it carry the correction: this is an
 * assistant, and the dot means the service is up — which is true, always.
 * Whatever else changes here, something on this line must say it is not a
 * person. The widget this replaced claimed to be a "cloud consultant" who was
 * "Online", and answered from a canned script. */
.cx-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0.2rem 0 0;
  font-size: 0.74rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
}

.cx-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cx-online);
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: cx-pulse 2.4s infinite;
}

@keyframes cx-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.cx-close {
  margin-left: auto;
  color: rgba(255, 255, 255, 0.8);
  flex: none;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--cx-mid);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.cx-close:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* ── Transcript ───────────────────────────────────────────────────────── */

.cx-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.cx-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  max-width: 92%;
}

.cx-row-bot { align-self: flex-start; }
.cx-row-user { align-self: flex-end; }

.cx-mini {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cx-deep) 0%, var(--cx-purple) 100%);
  display: grid;
  place-items: center;
  margin-bottom: 2px;
}

.cx-mini svg { width: 16px; height: 16px; display: block; }

/* Only the first message of a run carries the avatar; the rest indent to line
 * up with it, so a long answer does not repeat the same face five times. */
.cx-mini-spacer { flex: none; width: 26px; }

.cx-msg {
  max-width: 100%;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  font-size: 0.87rem;
  line-height: 1.55;
  /* Replies arrive as plain text with real newlines and are inserted with
   * textContent, never innerHTML. This is what preserves their shape. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cx-msg-bot {
  background: var(--cx-pale);
  color: var(--cx-body);
  border-bottom-left-radius: 4px;
}

.cx-msg-user {
  background: linear-gradient(135deg, var(--cx-purple) 0%, var(--cx-purple-bright) 100%);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(90, 42, 174, 0.22);
}

.cx-msg-error {
  background: #FFF3F6;
  color: #8A1538;
  border: 1px solid #FFD4E1;
  border-bottom-left-radius: 4px;
}

.cx-captured {
  align-self: center;
  max-width: 100%;
  padding: 0.5rem 0.85rem;
  border-radius: 999px;
  background: var(--cx-pale);
  border: 1px solid var(--cx-border);
  color: var(--cx-mid);
  font-size: 0.76rem;
  font-weight: 600;
}

/* ── Typing indicator ─────────────────────────────────────────────────── */

/* The model thinks before answering: about 4s for a first reply and longer on
 * the turn that hands a lead over. Without a visible signal that long reads as
 * a broken widget, so this is load-bearing rather than decoration. */
.cx-typing {
  display: flex;
  gap: 4px;
  padding: 0.8rem 0.9rem;
  background: var(--cx-pale);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.cx-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cx-purple);
  opacity: 0.45;
  animation: cx-bounce 1.3s infinite ease-in-out;
}

.cx-typing span:nth-child(2) { animation-delay: 0.18s; }
.cx-typing span:nth-child(3) { animation-delay: 0.36s; }

@keyframes cx-bounce {
  0%, 70%, 100% { transform: none; opacity: 0.45; }
  35%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.cx-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--cx-border);
  background: var(--cx-white);
}

.cx-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--cx-border);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.87rem;
  line-height: 1.45;
  color: var(--cx-body);
  background: #fff;
  transition: border-color 0.2s;
}

.cx-input:focus { outline: none; border-color: var(--cx-purple); }
.cx-input::placeholder { color: var(--cx-mid); opacity: 0.75; }

.cx-send {
  flex: none;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 10px;
  background: var(--cx-purple);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.cx-send:hover:not(:disabled) { background: var(--cx-purple-bright); }
.cx-send:disabled { opacity: 0.4; cursor: not-allowed; }

.cx-foot {
  padding: 0 1rem 0.85rem;
  margin: 0;
  font-size: 0.7rem;
  line-height: 1.4;
  color: var(--cx-mid);
  text-align: center;
}

.cx-foot a { color: var(--cx-purple); }

/* ── Small screens ────────────────────────────────────────────────────── */

@media (max-width: 520px) {
  .cx-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
  }
  .cx-launcher { right: 1rem; bottom: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .cx-panel { animation: none; }
  .cx-launcher { transition: background 0.25s; }
  .cx-launcher:hover { transform: none; }
  .cx-typing span { animation: none; opacity: 0.6; }
}
