/* Premium AI chat widget: isolated namespace, no global leakage */
.ai-chat-widget,
.ai-chat-widget * {
  box-sizing: border-box;
}

.ai-chat-widget {
  --ai-chat-navy: #0f172a;
  --ai-chat-blue: #2563eb;
  --ai-chat-blue-2: #0ea5e9;
  --ai-chat-teal: #14b8a6;
  --ai-chat-text: #111827;
  --ai-chat-muted: #64748b;
  --ai-chat-soft: #f8fafc;
  --ai-chat-bot: #f1f5f9;
  --ai-chat-border: rgba(15, 23, 42, .10);
  --ai-chat-shadow: 0 24px 80px rgba(15, 23, 42, .18), 0 8px 28px rgba(15, 23, 42, .10);
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 120;
  font-family: inherit;
  color: var(--ai-chat-text);
}

.ai-chat-launcher {
  position: relative;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 34px;
  align-items: center;
  gap: 12px;
  width: 248px;
  min-height: 72px;
  padding: 11px 12px;
  border: 1px solid rgba(255,255,255,.82);
  border-radius: 999px;
  background: rgba(255,255,255,.94);
  color: var(--ai-chat-navy);
  box-shadow: 0 18px 50px rgba(15,23,42,.18), 0 7px 24px rgba(37,99,235,.12);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  cursor: pointer;
  transform-origin: 82% 82%;
  transition: transform .2s ease, box-shadow .2s ease, opacity .18s ease;
}

.ai-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 62px rgba(15,23,42,.22), 0 9px 28px rgba(37,99,235,.18);
}

.ai-chat-launcher.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px) scale(.96);
}

.ai-chat-launcher.is-pulsing::before {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: inherit;
  border: 1px solid rgba(37,99,235,.28);
  animation: aiChatPulse 1.9s ease-out 1;
  pointer-events: none;
}

.ai-chat-launcher-avatar,
.ai-chat-avatar {
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #fff;
  font-weight: 950;
  letter-spacing: -.04em;
  background: radial-gradient(circle at 28% 20%, #67e8f9 0, #2563eb 42%, #0f172a 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.30), 0 12px 26px rgba(37,99,235,.24);
  overflow: visible;
}

.ai-chat-launcher-avatar img,
.ai-chat-avatar img,
.ai-chat-row-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 50%;
  object-fit: cover;
}

.ai-chat-launcher-avatar {
  width: 48px;
  height: 48px;
  font-size: 22px;
}

.ai-chat-avatar {
  width: 46px;
  height: 46px;
  font-size: 21px;
}

.ai-chat-launcher-avatar::after,
.ai-chat-avatar::after,
.ai-chat-person::after {
  content: "";
  position: absolute;
  width: 11px;
  height: 11px;
  right: 1px;
  bottom: 2px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(34,197,94,.14);
}

.ai-chat-launcher-copy {
  display: grid;
  justify-items: start;
  min-width: 0;
  text-align: left;
  line-height: 1.1;
}

.ai-chat-launcher-copy strong {
  font-size: 15px;
  letter-spacing: -.02em;
}

.ai-chat-launcher-copy small {
  margin-top: 3px;
  color: var(--ai-chat-muted);
  font-size: 12px;
  font-weight: 750;
}

.ai-chat-launcher-copy em {
  margin-top: 7px;
  color: var(--ai-chat-blue);
  font-style: normal;
  font-size: 13px;
  font-weight: 950;
}

.ai-chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--ai-chat-blue), var(--ai-chat-teal));
  font-size: 18px;
  font-weight: 900;
}

.ai-chat-nudge {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: 286px;
  padding: 16px;
  border: 1px solid rgba(15,23,42,.08);
  border-radius: 22px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 18px 58px rgba(15,23,42,.16);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  opacity: 0;
  transform: translateY(10px) scale(.98);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.ai-chat-nudge.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-chat-nudge strong,
.ai-chat-nudge span {
  display: block;
}

.ai-chat-nudge strong {
  padding-right: 22px;
  font-size: 15px;
  letter-spacing: -.02em;
}

.ai-chat-nudge span {
  margin-top: 5px;
  color: var(--ai-chat-muted);
  font-size: 13px;
  line-height: 1.35;
}

.ai-chat-nudge-action {
  margin-top: 13px;
  min-height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--ai-chat-navy);
  font-weight: 900;
  cursor: pointer;
}

.ai-chat-nudge-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--ai-chat-muted);
  font-size: 18px;
  cursor: pointer;
}

.ai-chat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(404px, calc(100vw - 48px));
  height: min(632px, calc(100vh - 48px));
  max-height: calc(100dvh - 48px);
  overflow: hidden;
  padding: 0 !important;
  border: 1px solid var(--ai-chat-border);
  border-radius: 28px;
  background: #fff;
  box-shadow: var(--ai-chat-shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px) scale(.975);
  transform-origin: 92% 100%;
  transition: opacity .2s ease, transform .2s ease;
}

.ai-chat-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.ai-chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 76px;
  padding: 14px 14px 13px 16px;
  border-bottom: 1px solid rgba(15,23,42,.075);
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
}

.ai-chat-person {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.ai-chat-person::after {
  left: 33px;
  right: auto;
  bottom: 3px;
}

.ai-chat-person-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.ai-chat-person-text strong {
  font-size: 16px;
  line-height: 1.05;
  letter-spacing: -.03em;
}

.ai-chat-person-text small {
  color: var(--ai-chat-muted);
  font-size: 12.5px;
  line-height: 1.1;
  font-weight: 800;
}

.ai-chat-person-text em {
  color: #059669;
  font-size: 11.5px;
  line-height: 1.1;
  font-style: normal;
  font-weight: 900;
}

.ai-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.ai-chat-icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #64748b;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background .18s ease, color .18s ease, transform .18s ease;
}

.ai-chat-icon-button:hover {
  background: #f1f5f9;
  color: var(--ai-chat-navy);
}

.ai-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 14px;
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
  scrollbar-width: thin;
  scrollbar-color: rgba(100,116,139,.28) transparent;
}

.ai-chat-messages::-webkit-scrollbar { width: 8px; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: rgba(100,116,139,.24); border-radius: 999px; }

.ai-chat-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  width: 100%;
  animation: aiChatMessageIn .2s ease both;
}

.ai-chat-row.is-user {
  justify-content: flex-end;
}

.ai-chat-row.is-bot {
  justify-content: flex-start;
}

.ai-chat-row-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 50%;
  color: #fff;
  background: radial-gradient(circle at 28% 20%, #67e8f9 0, #2563eb 46%, #0f172a 100%);
  font-size: 13px;
  font-weight: 950;
  box-shadow: 0 8px 18px rgba(37,99,235,.18);
}

.ai-chat-row.is-user .ai-chat-row-avatar {
  display: none;
}

.ai-chat-bubble {
  max-width: 84%;
  padding: 11px 13px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.48;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ai-chat-row.is-bot .ai-chat-bubble {
  color: #172033;
  background: var(--ai-chat-bot);
  border: 1px solid rgba(15,23,42,.055);
  border-bottom-left-radius: 7px;
}

.ai-chat-row.is-user .ai-chat-bubble {
  color: #fff;
  background: linear-gradient(135deg, var(--ai-chat-blue), var(--ai-chat-blue-2) 55%, var(--ai-chat-teal));
  border-bottom-right-radius: 7px;
  box-shadow: 0 10px 24px rgba(37,99,235,.18);
}

.ai-chat-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
  font-weight: 850;
}

.ai-chat-typing .ai-chat-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 116px;
  color: var(--ai-chat-muted);
}

.ai-chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: aiChatTyping 1s ease-in-out infinite;
}
.ai-chat-dot:nth-child(2) { animation-delay: .14s; }
.ai-chat-dot:nth-child(3) { animation-delay: .28s; }

.ai-chat-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(15,23,42,.075);
  background: rgba(255,255,255,.98);
}

.ai-chat-quick {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  max-height: 84px;
  overflow: hidden;
  transition: opacity .18s ease, max-height .2s ease, margin .2s ease;
}

.ai-chat-quick.is-hidden {
  opacity: 0;
  max-height: 0;
  margin: -4px 0 0;
  pointer-events: none;
}

.ai-chat-chip {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid rgba(37,99,235,.10);
  border-radius: 999px;
  background: #f8fafc;
  color: #1e3a8a;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: background .18s ease, border-color .18s ease, transform .18s ease;
}

.ai-chat-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(37,99,235,.22);
  background: #eff6ff;
}

.ai-chat-manager {
  align-self: flex-start;
  min-height: 30px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ai-chat-blue);
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.ai-chat-manager:hover {
  color: #1d4ed8;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.ai-chat-composer {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 52px;
  padding: 7px 7px 7px 14px;
  border: 1px solid rgba(15,23,42,.12);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15,23,42,.055);
  transition: border-color .18s ease, box-shadow .18s ease;
}

.ai-chat-composer:focus-within {
  border-color: rgba(37,99,235,.45);
  box-shadow: 0 0 0 4px rgba(37,99,235,.10), 0 8px 24px rgba(15,23,42,.055);
}

.ai-chat-input {
  flex: 1 1 auto;
  width: 100%;
  max-height: 104px;
  min-height: 36px;
  padding: 8px 4px 6px 0;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ai-chat-text);
  font: inherit;
  font-size: 15px;
  line-height: 1.35;
}

.ai-chat-input::placeholder {
  color: #94a3b8;
}

.ai-chat-send {
  display: grid;
  place-items: center;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(135deg, var(--ai-chat-blue), var(--ai-chat-teal));
  font-size: 21px;
  font-weight: 950;
  line-height: 1;
  cursor: pointer;
  transition: opacity .18s ease, transform .18s ease, filter .18s ease;
}

.ai-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: saturate(1.08);
}

.ai-chat-send:disabled,
.ai-chat-manager:disabled,
.ai-chat-chip:disabled {
  opacity: .48;
  cursor: not-allowed;
}

.ai-chat-privacy {
  margin: 0 4px;
  color: #8a97aa;
  font-size: 11.5px;
  line-height: 1.35;
}

.ai-chat-privacy button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ai-chat-blue);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
}

.ai-chat-status {
  min-height: 0;
  margin: -2px 4px 0;
  color: var(--ai-chat-muted);
  font-size: 12.5px;
  font-weight: 800;
}

.ai-chat-status.ok { color: #059669; }
.ai-chat-status.err { color: #dc2626; }

body.ai-chat-open-mobile {
  overflow: hidden;
}

@keyframes aiChatPulse {
  0% { opacity: .75; transform: scale(.98); }
  100% { opacity: 0; transform: scale(1.16); }
}

@keyframes aiChatTyping {
  0%, 80%, 100% { opacity: .35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

@keyframes aiChatMessageIn {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .ai-chat-widget {
    right: 0;
    bottom: 0;
    left: 0;
  }

  .ai-chat-launcher {
    position: fixed;
    right: 14px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    grid-template-columns: 48px;
    width: 64px;
    min-height: 64px;
    padding: 8px;
    border-radius: 24px;
  }

  .ai-chat-launcher-copy {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .ai-chat-launcher-icon {
    display: none;
  }

  .ai-chat-nudge {
    position: fixed;
    right: 14px;
    bottom: calc(92px + env(safe-area-inset-bottom));
    width: min(304px, calc(100vw - 28px));
  }

  .ai-chat-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    transform: translateY(20px);
  }

  .ai-chat-panel.is-open {
    transform: translateY(0);
  }

  .ai-chat-header {
    min-height: 74px;
    padding: calc(12px + env(safe-area-inset-top)) 12px 12px 14px;
  }

  .ai-chat-icon-button,
  .ai-chat-manager,
  .ai-chat-chip,
  .ai-chat-send {
    min-width: 44px;
    min-height: 44px;
  }

  .ai-chat-messages {
    padding: 14px 12px;
  }

  .ai-chat-bubble {
    max-width: 86%;
    font-size: 14.5px;
  }

  .ai-chat-footer {
    padding: 9px 10px calc(10px + env(safe-area-inset-bottom));
  }

  .ai-chat-composer {
    min-height: 54px;
    border-radius: 21px;
  }
}

@media (max-width: 380px) {
  .ai-chat-person-text small { max-width: 168px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ai-chat-person-text em { display: none; }
  .ai-chat-bubble { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chat-widget *,
  .ai-chat-widget *::before,
  .ai-chat-widget *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
