/* ============================================================================
   Vela chat widget — styles (Phase 6).

   Matches the site aesthetic: dark slate gradients, sky (#0ea5e9 / #38bdf8)
   primary, violet (#6366f1 / #818cf8) accent, Space Grotesk headings, rounded
   surfaces, soft glows. Scoped under .vela-chat to avoid colliding with the
   rest of the site. Respects prefers-reduced-motion and the html.light theme.
   ========================================================================== */

.vela-chat {
  --vela-sky: #38bdf8;
  --vela-sky-deep: #0ea5e9;
  --vela-violet: #818cf8;
  --vela-violet-deep: #6366f1;
  --vela-surface: rgba(15, 23, 42, 0.92);
  --vela-surface-raised: rgba(30, 41, 59, 0.92);
  --vela-border: rgba(99, 102, 241, 0.28);
  --vela-text: #e2e8f0;
  --vela-muted: #94a3b8;
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 50;
  font-family: "Inter", sans-serif;
}

.vela-chat__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ----------------------------------------------------------------- launcher */
.vela-chat__launcher {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--vela-border);
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--vela-sky-deep), var(--vela-violet-deep));
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 10px 30px -8px rgba(14, 165, 233, 0.5);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    opacity 0.2s ease;
}

.vela-chat__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px -8px rgba(99, 102, 241, 0.55);
}

.vela-chat__launcher-icon {
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

/* Hide the launcher while the panel is open so they don't overlap. */
.vela-chat.is-open .vela-chat__launcher {
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 480px) {
  .vela-chat__launcher-label {
    display: none;
  }
  .vela-chat__launcher {
    padding: 0.7rem;
  }
}

/* -------------------------------------------------------------------- panel */
.vela-chat__panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: min(440px, calc(100vw - 2rem));
  height: min(680px, calc(100vh - 2rem));
  max-height: min(680px, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  background: linear-gradient(to bottom, var(--vela-surface-raised), var(--vela-surface));
  border: 1px solid var(--vela-border);
  border-radius: 1rem;
  box-shadow: 0 25px 50px -12px rgba(2, 6, 23, 0.7);
  overflow: hidden;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  animation: vela-panel-in 0.28s ease-out;
}

.vela-chat__panel[hidden] {
  display: none;
}

@keyframes vela-panel-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ------------------------------------------------------------------- header */
.vela-chat__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(99, 102, 241, 0.18);
  background: rgba(15, 23, 42, 0.4);
}

.vela-chat__heading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.vela-chat__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 9999px;
  background: linear-gradient(135deg, var(--vela-sky), var(--vela-violet));
  color: #0f172a;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.5);
}

.vela-chat__title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  margin: 0;
  line-height: 1.1;
}

.vela-chat__subtitle {
  font-size: 0.7rem;
  color: var(--vela-muted);
  margin: 0.1rem 0 0;
  letter-spacing: 0.02em;
}

.vela-chat__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  border: 1px solid transparent;
  background: rgba(99, 102, 241, 0.1);
  color: var(--vela-text);
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.vela-chat__close:hover {
  background: rgba(99, 102, 241, 0.22);
  transform: rotate(90deg);
}

/* -------------------------------------------------------------------- intro */
.vela-chat__intro {
  margin: 0;
  padding: 0.85rem 1rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--vela-muted);
}

.vela-chat__link {
  color: var(--vela-sky);
  text-decoration: underline;
  font-weight: 500;
}

.vela-chat__link:hover {
  color: var(--vela-sky-deep);
}

/* ----------------------------------------------------------------- messages */
.vela-chat__messages {
  flex: 1;
  min-height: 280px;
  overflow-y: auto;
  padding: 0.5rem 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  scroll-behavior: smooth;
}

.vela-chat__msg {
  max-width: 88%;
  padding: 0.6rem 0.8rem;
  border-radius: 0.85rem;
  font-size: 0.9rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: vela-msg-in 0.25s ease-out;
}

/* Rendered Markdown inside Vela / system bubbles. */
.vela-chat__msg p {
  margin: 0 0 0.55rem;
}
.vela-chat__msg p:last-child {
  margin-bottom: 0;
}
.vela-chat__msg strong {
  font-weight: 700;
  color: #fff;
}
.vela-chat__msg em {
  font-style: italic;
}
.vela-chat__msg a {
  color: var(--vela-sky);
  text-decoration: underline;
  word-break: break-word;
}
.vela-chat__msg code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82em;
  padding: 0.05rem 0.32rem;
  border-radius: 0.3rem;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(99, 102, 241, 0.25);
}
html.light .vela-chat__msg strong {
  color: #0f172a;
}
html.light .vela-chat__msg code {
  background: rgba(15, 23, 42, 0.06);
}

@keyframes vela-msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.vela-chat__msg--visitor {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--vela-sky-deep), var(--vela-violet-deep));
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.vela-chat__msg--vela {
  align-self: flex-start;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--vela-text);
  border-bottom-left-radius: 0.25rem;
}

/* System / error messages — in Vela's voice but visually quieter. */
.vela-chat__msg--system {
  align-self: flex-start;
  background: rgba(148, 163, 184, 0.1);
  border: 1px dashed rgba(148, 163, 184, 0.35);
  color: var(--vela-muted);
  border-bottom-left-radius: 0.25rem;
  font-style: italic;
}

/* "filed a suggestion" pill, appended under a Vela reply when filed === true. */
.vela-chat__filed {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: -0.2rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: 9999px;
}

/* Thinking indicator (three dots). */
.vela-chat__thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.7rem 0.85rem;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: 0.85rem;
  border-bottom-left-radius: 0.25rem;
}

.vela-chat__thinking span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 9999px;
  background: var(--vela-violet);
  animation: vela-bounce 1.2s infinite ease-in-out;
}

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

@keyframes vela-bounce {
  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ----------------------------------------------------------------- composer */
.vela-chat__composer {
  border-top: 1px solid rgba(99, 102, 241, 0.18);
  padding: 0.65rem 0.85rem 0.75rem;
  background: rgba(15, 23, 42, 0.4);
}

.vela-chat__input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.vela-chat__input {
  flex: 1;
  resize: none;
  max-height: 7rem;
  padding: 0.55rem 0.7rem;
  border-radius: 0.7rem;
  border: 1px solid rgba(99, 102, 241, 0.3);
  background: rgba(2, 6, 23, 0.55);
  color: var(--vela-text);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
}

.vela-chat__input::placeholder {
  color: rgba(148, 163, 184, 0.7);
}

.vela-chat__input:focus {
  outline: none;
  border-color: var(--vela-sky);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.vela-chat__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.4rem;
  height: 2.4rem;
  flex-shrink: 0;
  border: none;
  border-radius: 0.7rem;
  background: linear-gradient(135deg, var(--vela-sky-deep), var(--vela-violet-deep));
  color: #fff;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease,
    box-shadow 0.2s ease;
}

.vela-chat__send:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -6px rgba(99, 102, 241, 0.6);
}

.vela-chat__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Persistent public-data notice — never dismissible. */
.vela-chat__notice {
  margin: 0.55rem 0 0;
  font-size: 0.7rem;
  line-height: 1.4;
  color: var(--vela-muted);
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.vela-chat__notice::before {
  content: "⚠";
  color: var(--vela-violet);
  flex-shrink: 0;
}

/* ------------------------------------------------------- visible focus ring */
.vela-chat :focus-visible {
  outline: 2px solid var(--vela-sky);
  outline-offset: 2px;
}

/* -------------------------------------------------------------- light theme */
html.light .vela-chat {
  --vela-surface: rgba(255, 255, 255, 0.96);
  --vela-surface-raised: rgba(248, 250, 252, 0.98);
  --vela-border: rgba(99, 102, 241, 0.3);
  --vela-text: #1e293b;
  --vela-muted: #64748b;
}

html.light .vela-chat__panel {
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
}

html.light .vela-chat__header,
html.light .vela-chat__composer {
  background: rgba(248, 250, 252, 0.7);
}

html.light .vela-chat__title {
  color: #0f172a;
}

html.light .vela-chat__msg--vela {
  background: rgba(99, 102, 241, 0.08);
  color: #1e293b;
}

html.light .vela-chat__input {
  background: #fff;
  color: #1e293b;
}

/* -------------------------------------------------- reduced-motion fallback */
@media (prefers-reduced-motion: reduce) {
  .vela-chat__launcher,
  .vela-chat__close,
  .vela-chat__send,
  .vela-chat__msg,
  .vela-chat__panel,
  .vela-chat__messages {
    transition: none;
    animation: none;
    scroll-behavior: auto;
  }
  .vela-chat__thinking span {
    animation: none;
    opacity: 0.7;
  }
}
