/*
 * Xyber assistant widget — Task 15. Styles for the DOM that
 * js/xyber-widget.js builds (CSP: no inline styles — everything lives here).
 * Derives strictly from tokens.css + the page-level tokens in site.css
 * (--hairline, --wash-blue, --text-micro…); BRAND.md is the law.
 *
 * The widget only exists in the DOM after the kill-switch probe answers
 * enabled:true — while the assistant is disabled this whole sheet matches
 * nothing (it is linked unconditionally; an extra idle stylesheet is cheaper
 * than a JS-injected <link> and keeps index.html honest about what it loads).
 */

/* ════════ Floating button — the page's badge/LED motif ════════ */
.xyber-root {
  position: fixed;
  right: clamp(1rem, 3vw, 2rem);
  bottom: clamp(1rem, 3vw, 2rem);
  z-index: 60; /* above the fixed header (50) */
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.8rem;
}

.xyber-fab {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.15rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-panel) 78%, transparent);
  backdrop-filter: blur(10px);
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--text-micro);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--xyber-blue-glow);
  cursor: pointer;
  transition: border-color 160ms ease, box-shadow 220ms ease;
}
.xyber-fab:hover {
  border-color: var(--xyber-blue-dim);
  box-shadow: 0 0 24px color-mix(in srgb, var(--xyber-blue-glow) 25%, transparent);
}

/* Xyber-blue LED dot — subtle breathing pulse, stilled under reduced motion */
.xyber-fab-led,
.xyber-led {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--xyber-blue);
  box-shadow: 0 0 8px var(--xyber-blue);
  animation: xyber-led-breathe 3.2s ease-in-out infinite alternate;
}

@keyframes xyber-led-breathe {
  from {
    opacity: 0.45;
  }
  to {
    opacity: 1;
  }
}

/* ════════ Panel ════════ */
/* `display: flex` below would defeat the UA's [hidden] rule — re-pin it,
   or the closed panel renders anyway. */
.xyber-panel[hidden] {
  display: none;
}

.xyber-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(22.5rem, calc(100vw - 2rem));
  height: min(32rem, calc(100dvh - var(--header-h) - 7.5rem));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--bg-panel) 88%, transparent),
    color-mix(in srgb, var(--bg-deep) 80%, transparent)
  );
  backdrop-filter: blur(14px);
  border: 1px solid var(--hairline);
}
/* blueprint corner brackets — same accent as the waitlist panel */
.xyber-panel::before,
.xyber-panel::after {
  content: '';
  position: absolute;
  width: 1.1rem;
  height: 1.1rem;
  pointer-events: none;
}
.xyber-panel::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--xyber-blue);
  border-left: 2px solid var(--xyber-blue);
}
.xyber-panel::after {
  bottom: -1px;
  right: -1px;
  border-bottom: 2px solid var(--xyber-blue);
  border-right: 2px solid var(--xyber-blue);
}

/* ── Header ── */
.xyber-head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.15rem 0.75rem;
  padding: 0.95rem 1.15rem 0.85rem;
  border-bottom: 1px solid var(--hairline-dim);
}

.xyber-title {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink);
}

.xyber-sub {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--ink-dim);
}

.xyber-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: none;
  color: var(--ink-dim);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.xyber-close:hover {
  color: var(--ink);
  border-color: var(--hairline-dim);
}

/* ── Message list ── */
.xyber-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem 1.15rem;
  scrollbar-width: thin;
  scrollbar-color: var(--xyber-blue-dim) transparent;
}

.xyber-msg {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 3px;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap; /* plain text, line breaks preserved — no markdown */
  overflow-wrap: anywhere;
}
.xyber-msg--user {
  align-self: flex-end;
  background: color-mix(in srgb, var(--xyber-blue) 14%, transparent);
  border: 1px solid var(--hairline);
  color: var(--ink);
}
.xyber-msg--bot {
  align-self: flex-start;
  background: color-mix(in srgb, var(--bg-panel) 92%, transparent);
  border: 1px solid var(--hairline-dim);
  color: var(--ink);
}

/* disclaimers + error lines — quiet annotations, not bubbles */
.xyber-note {
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--ink-dim);
}
.xyber-note--error {
  color: var(--led-magenta);
}

/* thinking indicator — three slow dots, static under reduced motion */
.xyber-thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.1rem;
}
.xyber-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--xyber-blue-glow);
  opacity: 0.35;
  animation: xyber-think 1.4s ease-in-out infinite;
}
.xyber-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.xyber-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes xyber-think {
  0%,
  60%,
  100% {
    opacity: 0.35;
  }
  30% {
    opacity: 1;
  }
}

/* ── Composer ── */
.xyber-composer {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1.15rem 1rem;
  border-top: 1px solid var(--hairline-dim);
}

.xyber-input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.85rem;
  background: color-mix(in srgb, var(--bg-void) 72%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink-dim) 32%, transparent);
  border-radius: 3px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
.xyber-input::placeholder {
  color: color-mix(in srgb, var(--ink-dim) 75%, transparent);
}
.xyber-input:focus {
  outline: none;
  border-color: var(--xyber-blue);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--xyber-blue) 22%, transparent);
}
.xyber-input:disabled {
  opacity: 0.55;
}

.xyber-send {
  flex: none;
  padding: 0.65rem 1.1rem;
  border: 0;
  border-radius: 3px;
  background: var(--xyber-blue);
  color: var(--bg-void); /* dark-on-blue: 8.2:1 (site.css .btn rationale) */
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 160ms ease, box-shadow 220ms ease;
}
.xyber-send:hover {
  background: var(--xyber-blue-glow);
  box-shadow: 0 0 18px color-mix(in srgb, var(--xyber-blue-glow) 40%, transparent);
}
.xyber-send:disabled {
  background: var(--xyber-blue-dim);
  cursor: not-allowed;
  box-shadow: none;
}

/* ════════ Mobile: full-width bottom sheet ════════ */
@media (max-width: 30rem) {
  /* while open, the sheet owns the bottom edge — the pill would sit under it */
  .xyber-root--open .xyber-fab {
    display: none;
  }
  .xyber-root--open {
    right: 0;
    bottom: 0;
    left: 0;
  }
  .xyber-root--open .xyber-panel {
    width: 100%;
    height: min(85dvh, 34rem);
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
  .xyber-root--open .xyber-panel::before,
  .xyber-root--open .xyber-panel::after {
    display: none;
  }
  /* the sheet owns the bottom edge — keep the composer clear of the home
     indicator on notched devices */
  .xyber-root--open .xyber-composer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  }
}

/* ════════ Motion discipline (BRAND.md: no exceptions) ════════ */
@media (prefers-reduced-motion: reduce) {
  .xyber-fab-led,
  .xyber-led,
  .xyber-dot {
    animation: none;
  }
  .xyber-dot {
    opacity: 0.75; /* dots stay visible as a static indicator */
  }
  .xyber-fab,
  .xyber-close,
  .xyber-input,
  .xyber-send {
    transition: none;
  }
}
