:root {
  --qnw-green: #0aa889;
  --qnw-green-btn: linear-gradient(180deg, #0aa889, #159f45);
  --qnw-text: #0f172a;
  --qnw-muted: #61707f;
  --qnw-border: rgba(15, 23, 42, 0.10);
  --qnw-shadow: 0 18px 44px rgba(15, 23, 42, 0.14);
  --qnw-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.qunelle-ai-widget,
.qunelle-ai-widget * {
  box-sizing: border-box;
}

/* ── Launcher pill ─────────────────────────────────────────── */
.qunelle-ai-widget__launcher {
  position: fixed;
  bottom: calc(24px + var(--qnw-safe-bottom));
  right: 20px;
  z-index: 900;
  appearance: none;
  border: none;
  border-radius: 999px;
  height: 50px;
  padding: 0 22px;
  background: linear-gradient(180deg, #0aa889, #159f45);
  color: #fff;
  font: 600 15px/1 Inter, system-ui, -apple-system, sans-serif;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 18px rgba(10, 168, 137, 0.38);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  -webkit-tap-highlight-color: transparent;
}
.qunelle-ai-widget__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 7px 22px rgba(10, 168, 137, 0.48);
}

/* ── Chat panel ────────────────────────────────────────────── */
.qunelle-ai-widget[hidden] {
  display: none;
}
.qunelle-ai-widget {
  position: fixed;
  inset: auto 16px calc(16px + var(--qnw-safe-bottom)) auto;
  z-index: 901;
  width: min(420px, calc(100vw - 32px));
  max-height: min(88dvh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 24px;
  box-shadow: var(--qnw-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  color: var(--qnw-text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Topbar ────────────────────────────────────────────────── */
.qnw-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0.94), rgba(255,255,255,0.88));
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}
.qnw-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.qnw-brand-mark {
  position: relative;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #ffffff 0%, #eef4f1 100%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: inset 0 0 0 8px rgba(10, 168, 137, 0.04);
}
.qnw-brand-mark span {
  font-size: 22px;
  line-height: 1;
  font-weight: 800;
  color: #111827;
  transform: translateY(-1px);
}
.qnw-brand-mark::after {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 2px #fff;
}
.qnw-brand-info {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.qnw-brand-info strong {
  font-size: 16px;
  line-height: 1.2;
}
.qnw-brand-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--qnw-text);
  font-weight: 500;
}
.qnw-brand-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.12);
  flex: 0 0 auto;
}

/* ── Close button ──────────────────────────────────────────── */
.qunelle-ai-widget__close {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: #fff;
  color: #111827;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  position: relative;
  z-index: 1;
  appearance: none;
}

/* ── Thread ────────────────────────────────────────────────── */
.qnw-thread {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  padding: 14px 14px 10px;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,0.95) 0%, rgba(247,249,248,0.92) 26%, rgba(243,246,245,0.96) 100%);
}
.qnw-thread-inner {
  display: grid;
  gap: 12px;
  align-content: start;
}

/* ── Welcome card ──────────────────────────────────────────── */
.qnw-welcome {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfc 100%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.05);
}
.qnw-welcome-avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(214, 244, 233, 0.80), rgba(239, 249, 244, 0.94));
  color: var(--qnw-green);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.04);
}
.qnw-welcome-avatar svg {
  width: 22px;
  height: 22px;
  display: block;
}
.qnw-welcome-text {
  min-width: 0;
  display: grid;
  align-content: center;
}
.qnw-welcome-text p {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
}

/* ── Messages list ─────────────────────────────────────────── */
.qnw-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Bubbles ───────────────────────────────────────────────── */
.qnw-bubble {
  width: fit-content;
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.qnw-bubble--assistant {
  align-self: flex-start;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}
.qnw-bubble--user {
  align-self: flex-end;
  display: block;
  background: #eaf2ff;
  border: 1px solid rgba(37, 99, 235, 0.12);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.05);
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}
.qnw-bubble-avatar {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(214, 244, 233, 0.96), rgba(239, 249, 244, 0.96));
  display: grid;
  place-items: center;
  color: var(--qnw-green);
}
.qnw-bubble-avatar svg {
  width: 14px;
  height: 14px;
  display: block;
}
.qnw-bubble-content {
  flex: 1;
  min-width: 0;
}
.qnw-bubble-content p {
  margin: 0;
}

/* ── CTA card ──────────────────────────────────────────────── */
.qnw-cta-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--qnw-border);
  background: linear-gradient(180deg, #ffffff, #fbfcfc);
}
.qnw-cta-bar[hidden] {
  display: none;
}
.qnw-cta-icon {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(203, 240, 224, 0.95), rgba(239, 249, 244, 0.96));
  color: var(--qnw-green);
  flex: 0 0 auto;
}
.qnw-cta-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}
.qnw-cta-copy {
  min-width: 0;
}
.qnw-cta-copy strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}
.qnw-cta-copy span {
  display: block;
  font-size: 12px;
  color: var(--qnw-muted);
  line-height: 1.3;
  margin-top: 2px;
}
.qnw-cta-btn {
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--qnw-green-btn);
  color: #fff;
  cursor: pointer;
  font: 600 13px/1 inherit;
  white-space: nowrap;
  touch-action: manipulation;
  box-shadow: 0 8px 20px rgba(10, 168, 137, 0.20);
  -webkit-tap-highlight-color: transparent;
  appearance: none;
}
.qnw-cta-btn:active {
  opacity: 0.88;
}

/* ── Composer ──────────────────────────────────────────────── */
.qnw-composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px calc(12px + var(--qnw-safe-bottom));
  border-top: 1px solid var(--qnw-border);
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(252,252,252,0.96));
}
.qunelle-ai-widget__input {
  flex: 1;
  min-width: 0;
  height: 52px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: 999px;
  padding: 0 18px;
  background: #fff;
  color: var(--qnw-text);
  font-size: 16px;
  font-family: inherit;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}
.qunelle-ai-widget__input::placeholder {
  color: #97a3af;
}
.qunelle-ai-widget__input:focus {
  border-color: rgba(10, 168, 137, 0.45);
  box-shadow: 0 0 0 3px rgba(10, 168, 137, 0.10);
}
.qunelle-ai-widget__send {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--qnw-green-btn);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 10px 24px rgba(10, 168, 137, 0.22);
  appearance: none;
}
.qunelle-ai-widget__send svg {
  width: 22px;
  height: 22px;
  display: block;
}

/* ── Mobile: above Qunell bottom nav (~72px tall) ─────────── */
@media (max-width: 980px) {
  .qunelle-ai-widget__launcher {
    right: 12px;
    bottom: 84px;
  }
  .qunelle-ai-widget {
    inset: auto 8px calc(84px + var(--qnw-safe-bottom)) 8px;
    width: auto;
    max-height: calc(90dvh - 84px);
    border-radius: 20px;
  }
}
