/* HeyHi design system: the AI widget in the corner of every page (shared/_assistant, assistant_controller.js).
 * An amber launcher, and a dark glass panel holding one conversation with HeyHi AI, by text or by voice. Aqua marks the
 * AI, amber the visitor and their actions. The controller adds the messages, events and notices, and toggles the call
 * bar's [data-state], .is-speaking and --mic-level. */

/* ---------- Launcher: the amber button in the corner, which closes the widget while it's open ---------- */
/* Above the panel's layer, so the panel's shadow doesn't fall on it */
.assistant-launcher {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 61;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px; height: 52px; padding: 0 20px 0 16px;
  border: 0; border-radius: var(--r-pill); background: var(--signal); color: var(--night-900);
  font-size: 15px; font-weight: 650; font-stretch: 106%; letter-spacing: -0.005em; white-space: nowrap; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 0 0 1px rgba(0, 19, 42, 0.14),
    0 18px 38px -14px rgba(0, 8, 20, 0.65), 0 12px 30px -16px color-mix(in srgb, var(--signal) 80%, transparent);
  transition: transform 0.25s var(--ease), background-color 0.2s;
}
.assistant-launcher:hover { background: var(--signal-hi); transform: translateY(-1px); }
.assistant-launcher .mark { width: 21px; }
.assistant-launcher[aria-expanded="true"] { width: 52px; padding: 0; }
.assistant-launcher-close, .assistant-launcher[aria-expanded="true"] :is(.assistant-launcher-open, span) { display: none; }
.assistant-launcher[aria-expanded="true"] .assistant-launcher-close { display: block; width: 22px; height: 22px; }

/* A nudge above the launcher, once a visit, on screens with room for it */
.assistant-teaser {
  position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: calc(max(20px, env(safe-area-inset-bottom)) + 64px); z-index: 45;
  display: flex; align-items: center; max-width: 18rem; border-radius: 16px 16px 5px 16px;
  background: linear-gradient(180deg, var(--night-700), var(--night-800)); color: var(--night-text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), 0 0 0 1px var(--night-line-strong), 0 20px 44px -18px rgba(0, 3, 10, 0.85);
  animation: assistant-in 0.35s var(--ease);
}
.assistant-teaser-text { padding: 12px 4px 12px 16px; border: 0; background: none; color: inherit; font-size: 14px; font-weight: 540; line-height: 1.4; text-align: left; cursor: pointer; }
.assistant-teaser-close {
  display: grid; place-items: center; flex: none; width: 34px; height: 34px; margin-right: 6px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: var(--night-muted); cursor: pointer;
}
.assistant-teaser-close:hover { background: rgba(140, 180, 230, 0.1); color: var(--night-text); }
.assistant-teaser-close .icon { width: 15px; height: 15px; }

/* Back-to-top shares the corner, so it steps aside while the nudge or the widget is showing */
.assistant-teaser:not([hidden]) ~ .back-to-top,
.assistant-panel:not([hidden]) ~ .back-to-top { visibility: hidden; opacity: 0; }

/* ---------- Panel: the whole screen on phones, so the conversation has room ---------- */
.assistant-panel {
  position: fixed; inset: 0; z-index: 60;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--night-800) 0%, var(--night-900) 100%);
  font-size: 15px;
}
@media (max-width: 35.99em) {
  html.assistant-open { overflow: hidden; }
  .assistant-launcher[aria-expanded="true"] { display: none; }
}

/* From 36em, a window above the launcher, short enough to stay clear of the top of the screen */
@media (min-width: 36em) {
  .assistant-panel {
    inset: auto max(20px, env(safe-area-inset-right)) calc(max(20px, env(safe-area-inset-bottom)) + 64px) auto;
    width: min(400px, calc(100vw - 40px)); height: min(640px, calc(100dvh - 108px));
    border-radius: var(--r-lg); overflow: hidden;
    background: linear-gradient(180deg, rgba(12, 48, 86, 0.95) 0%, rgba(0, 20, 42, 0.97) 60%);
    -webkit-backdrop-filter: blur(24px) saturate(160%); backdrop-filter: blur(24px) saturate(160%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 0 0 1px var(--night-line-strong), 0 44px 110px -30px rgba(0, 3, 10, 0.9);
    transform-origin: 100% 100%; animation: assistant-in 0.32s var(--ease);
  }
}

.assistant-header {
  display: flex; flex: none; align-items: center; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 12px 14px 16px; border-bottom: 1px solid var(--line);
}
.assistant-avatar {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; color: var(--voice);
  background: radial-gradient(circle at 50% 30%, rgba(92, 214, 234, 0.24), rgba(92, 214, 234, 0.05) 72%);
  box-shadow: inset 0 0 0 1px rgba(92, 214, 234, 0.34);
}
.assistant-avatar .mark { width: 21px; }
.assistant-heading { display: grid; gap: 3px; min-width: 0; }
.assistant-title { font-size: 15.5px; font-weight: 680; font-stretch: 106%; letter-spacing: -0.01em; line-height: 1.2; }
.assistant-subtitle {
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
  font-family: var(--font-mono); font-stretch: var(--mono-w); font-size: 11px; letter-spacing: 0.03em; color: var(--muted);
}
.assistant-online { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }

/* Calling HeyHi Voice from the header, the way a messaging app offers a call */
.assistant-call-button {
  display: inline-flex; flex: none; align-items: center; gap: 7px; height: 36px; margin-left: auto; padding: 0 14px 0 12px;
  border-radius: var(--r-pill); border: 1px solid color-mix(in srgb, var(--voice) 42%, transparent);
  background: color-mix(in srgb, var(--voice) 13%, transparent); color: var(--voice);
  font-size: 13.5px; font-weight: 620; text-decoration: none; cursor: pointer; transition: background-color 0.2s, border-color 0.2s;
}
.assistant-call-button:hover { background: color-mix(in srgb, var(--voice) 22%, transparent); border-color: color-mix(in srgb, var(--voice) 62%, transparent); }
.assistant-call-button .icon { width: 16px; height: 16px; }
.assistant-close {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; margin-left: auto; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; transition: background-color 0.2s, color 0.2s;
}
.assistant-close:hover { background: var(--surface-2); color: var(--fg); }
.assistant-close .icon { width: 18px; height: 18px; }
.assistant-call-button:not([hidden]) + .assistant-close { margin-left: 0; }

/* ---------- The conversation, with the suggestions under the greeting until it starts ---------- */
/* Earlier lines fade as they scroll up under the header */
.assistant-thread {
  display: flex; flex: 1; flex-direction: column; gap: 14px; min-height: 0; padding: 18px 16px 16px;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent;
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 16px); mask-image: linear-gradient(to bottom, transparent, #000 16px);
}
.assistant-messages { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.assistant-message { max-width: 86%; padding: 10px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.55; overflow-wrap: anywhere; }
.assistant-message--assistant { align-self: flex-start; border-bottom-left-radius: 5px; background: rgba(140, 180, 230, 0.075); box-shadow: inset 0 0 0 1px var(--line); }
/* The visitor's side is the human "hi", in amber */
.assistant-message--user {
  align-self: flex-end; border-bottom-right-radius: 5px; white-space: pre-wrap;
  background: var(--signal); color: var(--night-900); font-weight: 500; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.assistant-message--error { color: #FFD3D3; background: color-mix(in srgb, var(--no) 12%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--no) 34%, transparent); }
.assistant-message :is(p, ul, ol) { margin: 0 0 8px; }
.assistant-message > :last-child { margin-bottom: 0; }
.assistant-message :is(ul, ol) { padding-left: 18px; }
.assistant-message li + li { margin-top: 3px; }
.assistant-message li::marker { color: var(--voice); }
.assistant-message strong { font-weight: 650; color: #FFFFFF; }
.assistant-message a { color: var(--voice); font-weight: 600; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.assistant-message a:hover { text-decoration-thickness: 2px; }

/* A call's transcript says who spoke, as the product previews do: aqua for the AI, amber for the visitor */
.assistant-speaker, .assistant-message--user.assistant-message--voice::before {
  display: block; margin-bottom: 3px;
  font-family: var(--font-mono); font-stretch: var(--mono-w); font-size: 10.5px; font-weight: 500; letter-spacing: 0.1em; text-transform: uppercase; color: var(--voice);
}
.assistant-message--user.assistant-message--voice::before { content: "You"; color: var(--signal-deep); }

/* "Call started" and "Call ended", as a rule across the conversation */
.assistant-event {
  display: flex; align-items: center; gap: 10px; margin-block: 4px; white-space: nowrap;
  font-family: var(--font-mono); font-stretch: var(--mono-w); font-size: 10.5px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint);
}
.assistant-event::before, .assistant-event::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* Why a call couldn't start, or ended early */
.assistant-notice { align-self: center; max-width: 92%; font-size: 13.5px; line-height: 1.5; text-align: center; text-wrap: balance; color: var(--muted); }
.assistant-notice a { color: var(--voice); font-weight: 600; text-underline-offset: 3px; }

/* What an answer offers to do: open the contact form, or start a call */
.assistant-action {
  display: inline-flex; align-items: center; margin: 3px 0; padding: 4px 12px;
  border-radius: var(--r-pill); border: 1px solid color-mix(in srgb, var(--signal) 48%, transparent);
  background: color-mix(in srgb, var(--signal) 12%, transparent); color: var(--signal);
  font-size: 13.5px; font-weight: 620; line-height: 1.4; cursor: pointer; transition: background-color 0.2s, border-color 0.2s;
}
.assistant-action:hover { background: color-mix(in srgb, var(--signal) 22%, transparent); border-color: var(--signal); }

/* Until the first words of an answer arrive */
.assistant-typing { display: inline-flex; gap: 4px; padding-block: 6px; vertical-align: middle; }
.assistant-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--voice); animation: assistant-typing 1.2s ease-in-out infinite; }
.assistant-typing span:nth-child(2) { animation-delay: 0.15s; }
.assistant-typing span:nth-child(3) { animation-delay: 0.3s; }

.assistant-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.assistant-suggestion {
  display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 7px 12px 7px 14px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong); background: transparent; color: var(--fg);
  font-size: 13.5px; font-weight: 520; line-height: 1.35; text-align: left; cursor: pointer; transition: background-color 0.2s, border-color 0.2s;
}
.assistant-suggestion:hover { background: var(--surface-2); border-color: color-mix(in srgb, var(--voice) 45%, transparent); }
.assistant-suggestion .icon { width: 14px; height: 14px; color: var(--faint); transition: transform 0.25s var(--ease), color 0.2s; }
.assistant-suggestion:hover .icon { transform: translateX(2px); color: var(--voice); }

/* ---------- The message box, or the call's controls in its place ---------- */
.assistant-footer { flex: none; padding: 12px 12px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(0, 10, 22, 0.3); }
.assistant-form { display: flex; align-items: flex-end; gap: 8px; }
/* 16px text, so phones don't zoom in on it */
.assistant-input {
  flex: 1; min-width: 0; min-height: 44px; max-height: 128px; padding: 11px 16px;
  border-radius: 22px; border: 1px solid var(--line-strong); background: rgba(140, 180, 230, 0.06);
  color: var(--fg); font-size: 16px; line-height: 1.35; resize: none;
  transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}
.assistant-input::placeholder { color: var(--faint); }
.assistant-input:focus { outline: none; border-color: color-mix(in srgb, var(--voice) 65%, transparent); background: rgba(140, 180, 230, 0.09); box-shadow: 0 0 0 3px color-mix(in srgb, var(--voice) 18%, transparent); }
.assistant-send {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0;
  border: 0; border-radius: 50%; background: var(--signal); color: var(--night-900); cursor: pointer; transition: background-color 0.2s, color 0.2s;
}
.assistant-send:hover:not(:disabled) { background: var(--signal-hi); }
.assistant-send:disabled { background: rgba(140, 180, 230, 0.1); color: var(--faint); cursor: default; }
.assistant-send .icon { width: 18px; height: 18px; transform: rotate(-90deg); }

/* On a call: who's talking, how long is left, and the button to hang up */
.assistant-footer:has(> .assistant-callbar:not([hidden])) { background: linear-gradient(180deg, rgba(7, 43, 80, 0.7), rgba(0, 19, 42, 0.92)); }
.assistant-callbar { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.assistant-call-info { flex: 1; min-width: 0; }
.assistant-call-name { font-size: 15px; font-weight: 680; font-stretch: 106%; letter-spacing: -0.01em; line-height: 1.25; }
.assistant-call-status { font-family: var(--font-mono); font-stretch: var(--mono-w); font-size: 11.5px; letter-spacing: 0.03em; color: var(--muted); font-variant-numeric: tabular-nums; }
.assistant-callbar[data-state="live"] .assistant-call-status { color: var(--voice); }
.assistant-call-timer { color: var(--muted); }
.assistant-call-timer:not(:empty)::before { content: " · "; color: var(--faint); }
.assistant-hangup {
  display: inline-flex; flex: none; align-items: center; gap: 7px; height: 42px; padding: 0 17px 0 14px;
  border: 0; border-radius: var(--r-pill); background: color-mix(in srgb, var(--no-deep) 80%, var(--no)); color: #FFFFFF;
  font-size: 14px; font-weight: 640; cursor: pointer; transition: background-color 0.2s;
}
.assistant-hangup:hover { background: var(--no-deep); }
/* The handset, put down */
.assistant-hangup .icon { width: 17px; height: 17px; transform: rotate(135deg); }

/* The orb: breathing while the call connects, rippling while HeyHi Voice speaks; its bars follow the visitor's voice */
.assistant-orb { position: relative; display: grid; flex: none; place-items: center; width: 46px; height: 46px; }
.assistant-orb-core {
  position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; gap: 2px; width: 100%; height: 100%;
  border-radius: 50%; background: radial-gradient(circle at 35% 28%, #B4F1F9 0%, var(--voice) 46%, #1C9DB3 100%);
  box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--voice) 70%, transparent);
}
.assistant-orb-core span { width: 3px; height: calc(4px + 16px * var(--mic-level, 0) * var(--bar, 1)); border-radius: 2px; background: var(--night-900); transition: height 0.08s linear; }
.assistant-orb-core span:nth-child(1), .assistant-orb-core span:nth-child(5) { --bar: 0.45; }
.assistant-orb-core span:nth-child(2), .assistant-orb-core span:nth-child(4) { --bar: 0.75; }
.assistant-orb-ring { position: absolute; inset: 0; border: 2px solid color-mix(in srgb, var(--voice) 55%, transparent); border-radius: 50%; opacity: 0; }
.assistant-callbar[data-state="connecting"] .assistant-orb-core { animation: assistant-breathe 1.2s ease-in-out infinite; }
.assistant-callbar.is-speaking .assistant-orb-ring { animation: assistant-ripple 1.6s ease-out infinite; }
.assistant-callbar.is-speaking .assistant-orb-ring + .assistant-orb-ring { animation-delay: 0.8s; }
/* While HeyHi Voice speaks, the bars move with it instead */
.assistant-callbar.is-speaking .assistant-orb-core span { animation: assistant-equalize 0.8s ease-in-out infinite alternate; }
.assistant-callbar.is-speaking .assistant-orb-core span:nth-child(2) { animation-delay: -0.5s; }
.assistant-callbar.is-speaking .assistant-orb-core span:nth-child(3) { animation-delay: -0.2s; }
.assistant-callbar.is-speaking .assistant-orb-core span:nth-child(4) { animation-delay: -0.65s; }
.assistant-callbar.is-speaking .assistant-orb-core span:nth-child(5) { animation-delay: -0.35s; }

@keyframes assistant-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } }
@keyframes assistant-typing { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes assistant-ripple { from { opacity: 0.8; transform: scale(1); } to { opacity: 0; transform: scale(1.6); } }
@keyframes assistant-breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes assistant-equalize { from { height: 4px; } to { height: calc(6px + 14px * var(--bar, 1)); } }

/* ---------- Fitting around the page ---------- */
/* Without chat there's only the welcome and the call, so the window is only as tall as they are */
@media (min-width: 36em) {
  .assistant-panel--call-only { height: auto; }
}
/* On phones the launcher is just the mark, so it covers as little of the page as it can */
@media (max-width: 35.99em) {
  .assistant-launcher { width: 52px; padding: 0; }
  .assistant-launcher span { display: none; }
}
/* The open menu sheet has the screen to itself */
html.menu-open .assistant-launcher,
html.menu-open .assistant-teaser { display: none; }
