/* =====================================================================
   Live Support Chat — visitor widget styles (Mason C, livechat_design.md).
   Reuses the app's existing theme custom properties (styles.css :root /
   [data-theme="night"]) so light/night mode both pick this up automatically
   -- no new palette introduced. Bottom-right, unobtrusive, mobile-safe,
   respects prefers-reduced-motion.
   ===================================================================== */

#aiq-chat-widget {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 60; /* above footer/nav chrome, below any modal overlay the app already uses */
  font-family: inherit;
}

/* route-suppressed (kid lesson/mini-games/arcade/graduation, design §8 Q1) */
#aiq-chat-widget.aiqcw-hidden { display: none; }

/* [hidden] HARD GUARD (integrator, Guru_Universal 2026-08-11): the widget's JS shows/hides the
   panel and its inner rows (typing indicator, error banner, email-capture row, restart button)
   via the `hidden` attribute (`el.hidden = true/false`). Several of those elements ALSO carry an
   author `display:flex/…` rule below, which has equal-or-higher specificity than the UA
   `[hidden]{display:none}` and therefore DEFEATS it -- so a "hidden" panel stayed laid out at
   bottom-right on every page, silently intercepting clicks on page content beneath it (broke the
   myBugs "Add more details" click-path once Guru went omnipresent), and in kid mode the
   `hidden` email-capture row would still render (never ask a kid for PII). This one scoped rule
   makes the `hidden` attribute authoritative for every element inside the widget, restoring the
   JS's own show/hide contract. */
#aiq-chat-widget [hidden] { display: none !important; }

/* -------------------- S1 proactive greeting (Fable Brief 2026-08-11) --------------------
   One dismissible speech-bubble above the launcher. Sales-framed invite, no sound (visual only),
   never stacks (JS only ever builds one at a time). Entrance animation is skipped entirely under
   prefers-reduced-motion via the .aiqcw-no-anim class the widget adds itself. */
.aiqcw-greet {
  position: absolute; right: 0; bottom: 68px;
  width: 250px; max-width: calc(100vw - 24px);
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius, 16px);
  box-shadow: var(--shadow, 0 8px 30px rgba(42,36,64,.22));
  padding: 12px 30px 12px 12px;
  animation: aiqcw-greet-in .28s ease-out;
}
.aiqcw-greet.aiqcw-no-anim { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .aiqcw-greet { animation: none; }
}
@keyframes aiqcw-greet-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.aiqcw-greet-body { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; }
.aiqcw-greet-ico { font-size: 18px; line-height: 1.3; flex: none; }
.aiqcw-greet-text { font-size: 13px; line-height: 1.4; }
.aiqcw-greet-close {
  position: absolute; top: 6px; right: 8px; width: 20px; height: 20px;
  border: none; background: transparent; color: var(--muted); font-size: 12px;
  cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.aiqcw-greet-close:hover { background: var(--panel2); color: var(--ink); }

.aiqcw-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 -------------------- */
.aiqcw-launcher {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none;
  box-shadow: var(--shadow, 0 4px 14px rgba(42,36,64,.18));
  font-size: 24px; cursor: pointer; position: relative;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease;
}
.aiqcw-launcher:hover { transform: scale(1.05); }
.aiqcw-launcher:focus-visible { outline: 3px solid var(--brand2); outline-offset: 2px; }
.aiqcw-launcher-ico { line-height: 1; }
.aiqcw-launcher-dot {
  position: absolute; top: 2px; right: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--muted); border: 2px solid var(--panel);
}
.aiqcw-launcher-dot.on { background: var(--good, #2ECC71); }

/* -------------------- panel -------------------- */
.aiqcw-panel {
  position: absolute; right: 0; bottom: 68px;
  width: 340px; max-width: calc(100vw - 24px);
  height: 480px; max-height: calc(100vh - 120px);
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius, 16px);
  box-shadow: var(--shadow, 0 8px 30px rgba(42,36,64,.22));
  display: flex; flex-direction: column; overflow: hidden;
}

.aiqcw-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line);
  background: var(--panel2); flex: none;
}
.aiqcw-head-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.aiqcw-head-name { font-weight: 800; font-size: 14px; }
.aiqcw-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.aiqcw-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.aiqcw-status-dot.on { background: var(--good, #2ECC71); }
.aiqcw-head-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.aiqcw-iconbtn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; padding: 4px 8px; font-size: 11px; cursor: pointer;
}
.aiqcw-iconbtn:hover { background: var(--panel); color: var(--ink); }
.aiqcw-iconbtn.aiqcw-close { font-size: 14px; padding: 4px 8px; }

.aiqcw-error {
  margin: 8px 12px 0; padding: 8px 10px; font-size: 12px;
  background: color-mix(in srgb, var(--error) 15%, var(--panel));
  border: 1px solid var(--error); color: var(--error); border-radius: 10px; flex: none;
}

.aiqcw-msgs {
  flex: 1 1 auto; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
}

.aiqcw-row { display: flex; flex-direction: column; max-width: 88%; }
.aiqcw-row-me { align-self: flex-end; align-items: flex-end; }
.aiqcw-row-them { align-self: flex-start; align-items: flex-start; }
.aiqcw-row-system { align-self: center; max-width: 96%; align-items: center; }

.aiqcw-bubble-label { font-size: 11px; color: var(--muted); margin: 0 2px 2px; font-weight: 700; }
.aiqcw-bubble {
  padding: 8px 12px; border-radius: 14px; font-size: 13.5px; line-height: 1.4;
  word-break: break-word; white-space: pre-wrap;
}
.aiqcw-bubble-me { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.aiqcw-bubble-them { background: var(--panel2); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.aiqcw-bubble-system {
  background: transparent; color: var(--muted); font-size: 12px; text-align: center; padding: 4px 8px;
}
.aiqcw-welcome .aiqcw-bubble-system { font-weight: 600; }
/* P6 handoff copy (Fable Brief 2026-08-11) -- same system-line styling, gently called out so the
   "someone's usually here" line doesn't read as just another muted status blip. */
.aiqcw-handoff .aiqcw-bubble-system {
  background: color-mix(in srgb, var(--brand) 10%, var(--panel));
  border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--line));
  border-radius: 10px; color: var(--ink); font-weight: 600; padding: 8px 10px;
}

/* S13 single CTA (Fable Brief 2026-08-11) -- at most one button, attached to its own bot turn. */
.aiqcw-cta-row { margin-top: 6px; }
.aiqcw-cta-btn {
  font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--brand);
  background: var(--brand); color: #fff;
}
.aiqcw-cta-btn:hover { filter: brightness(1.06); }
.aiqcw-cta-btn:focus-visible { outline: 2px solid var(--brand2); outline-offset: 2px; }

.aiqcw-typing {
  display: flex; align-items: center; gap: 6px; padding: 2px 14px 6px;
  font-size: 12px; color: var(--muted); flex: none;
}
.aiqcw-hourglass { display: inline-block; animation: aiqcw-spin 1.6s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  .aiqcw-hourglass { animation: none; }
}
@keyframes aiqcw-spin {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
  100% { transform: rotate(360deg); }
}

.aiqcw-email-row {
  display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); flex: none;
  border-radius: 0; transition: background-color .2s ease;
}
/* P6 flow (Fable Brief 2026-08-11): while gathering context for a handed-off visitor, a quiet
   static tint calls attention to the email field -- no motion, so it stays reduced-motion-safe
   without needing its own media-query override. */
.aiqcw-email-row.aiqcw-highlight {
  background: color-mix(in srgb, var(--brand) 8%, transparent);
}
.aiqcw-email-input {
  flex: 1 1 auto; min-width: 0; font-size: 12.5px; padding: 8px 10px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.aiqcw-email-btn {
  flex: none; font-size: 12px; padding: 8px 10px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--ink); cursor: pointer;
}

.aiqcw-human-btn, .aiqcw-restart-btn {
  margin: 0 12px 8px; padding: 8px 10px; border-radius: 10px; font-size: 12.5px;
  border: 1px dashed var(--line); background: transparent; color: var(--brand-shade, var(--brand));
  cursor: pointer; flex: none;
}
.aiqcw-restart-btn { border-style: solid; background: var(--brand); color: #fff; border-color: var(--brand); }
.aiqcw-human-btn:disabled { opacity: .7; cursor: default; }

/* Kid-safe escalation note (Fable_Brief_Guru_Universal_2026-08-11): replaces .aiqcw-human-btn for
   role="kid" -- same slot/spacing, but a plain non-interactive note (no cursor:pointer, no button
   semantics) since there is nothing to click through to a live person. */
.aiqcw-kid-escalation {
  margin: 0 12px 8px; padding: 8px 10px; border-radius: 10px; font-size: 12.5px; line-height: 1.4;
  border: 1px dashed var(--line); background: color-mix(in srgb, var(--brand) 6%, transparent);
  color: var(--muted); flex: none;
}

.aiqcw-input-row {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--line); flex: none;
}
.aiqcw-input {
  flex: 1 1 auto; resize: none; min-height: 40px; max-height: 96px;
  padding: 9px 12px; font-size: 13.5px; font-family: inherit;
  border-radius: 12px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
.aiqcw-input:focus-visible { outline: 2px solid var(--brand2); outline-offset: 1px; }
.aiqcw-send {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand); color: #fff; border: none; font-size: 16px; cursor: pointer;
}
.aiqcw-send:disabled, .aiqcw-input:disabled { opacity: .5; cursor: not-allowed; }

/* -------------------- mobile -------------------- */
@media (max-width: 480px) {
  #aiq-chat-widget { right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .aiqcw-panel {
    width: calc(100vw - 20px);
    height: calc(100vh - 96px);
    bottom: 64px;
  }
  .aiqcw-launcher { width: 52px; height: 52px; font-size: 22px; }
  .aiqcw-greet { bottom: 64px; width: calc(100vw - 20px); }
}
