.bag-ai {
  --bag-ai-blue: var(--primary, #0d4f92);
  --bag-ai-yellow: var(--action, #fbca37);
  --bag-ai-blue-soft: var(--primary-ultra-light, #eef6fd);
  --bag-ai-text: #17324d;
  --bag-ai-border: #d7e3ee;
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 99998;
  font-family: "DB Heavent", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--bag-ai-text);
  line-height: 1.4;
}

.bag-ai *, .bag-ai *::before, .bag-ai *::after { box-sizing: border-box; }
body.bag-ai-chat-open { overflow: hidden !important; overscroll-behavior: none; }

.bag-ai .screen-reader-text {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.bag-ai__launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  min-height: 70px;
  padding: 8px 14px 8px 8px;
  border: 2px solid var(--bag-ai-blue);
  border-radius: 18px;
  background: var(--bag-ai-yellow);
  color: var(--bag-ai-blue);
  box-shadow: 0 14px 36px rgba(0, 28, 112, .30), 0 0 0 5px rgba(251, 202, 55, .20);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease;
}

.bag-ai__launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 42px rgba(0, 28, 112, .34), 0 0 0 6px rgba(251, 202, 55, .25);
}

.bag-ai__launcher:focus-visible,
.bag-ai button:focus-visible,
.bag-ai a:focus-visible,
.bag-ai textarea:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--bag-ai-blue);
}

.bag-ai__launcher-brand {
  display: grid;
  place-items: center;
  align-content: center;
  flex: 0 0 78px;
  min-height: 52px;
  padding: 6px 8px;
  border-radius: 12px;
  background: var(--bag-ai-blue);
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.02em;
  text-align: center;
}

.bag-ai__launcher-brand span:last-child { font-size: 11px; letter-spacing: -.03em; }
.bag-ai__launcher-copy { display: grid; flex: 1; gap: 1px; min-width: 0; }
.bag-ai__launcher-copy strong { font-size: 18px; line-height: 1.2; }
.bag-ai__launcher-copy small { font-size: 13px; font-weight: 600; line-height: 1.25; }
.bag-ai__launcher-arrow { font-family: Arial, Helvetica, sans-serif; font-size: 28px; font-weight: 700; line-height: 1; }

.bag-ai__panel {
  position: absolute;
  right: 0;
  bottom: 82px;
  display: grid;
  grid-template-rows: auto minmax(150px, 1fr) auto auto auto auto;
  width: min(410px, calc(100vw - 36px));
  height: min(720px, calc(100vh - 124px));
  height: min(720px, calc(100dvh - 124px));
  overflow: hidden;
  border: 1px solid var(--bag-ai-border);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 22px 64px rgba(0, 28, 112, .28);
  opacity: 0;
  visibility: hidden;
  transform: translateY(14px) scale(.98);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .18s ease, visibility .18s;
}

.bag-ai__panel.is-open { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.bag-ai__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 16px;
  background: var(--bag-ai-blue);
  color: #fff;
}

.bag-ai__header div { display: grid; gap: 3px; }
.bag-ai__header strong { font-size: 20px; line-height: 1.2; }

.bag-ai__close {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.bag-ai__messages {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background: linear-gradient(180deg, var(--bag-ai-blue-soft), #fff 44%);
  overscroll-behavior: contain;
}

.bag-ai__message {
  width: fit-content;
  max-width: 88%;
  margin: 0 0 12px;
  padding: 11px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 17px;
}

.bag-ai__message--assistant {
  border: 1px solid var(--bag-ai-border);
  border-bottom-left-radius: 5px;
  background: #fff;
}

.bag-ai__message--user {
  margin-left: auto;
  border-bottom-right-radius: 5px;
  background: var(--bag-ai-blue);
  color: #fff;
}

.bag-ai__message.is-pending { color: #607890; font-style: italic; }
.bag-ai__message.is-error { border-color: #d89a9a; color: #8a2929; }

.bag-ai__quick {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 14px;
  border-top: 1px solid var(--bag-ai-border);
  scrollbar-width: thin;
}

.bag-ai__quick button {
  flex: 0 0 auto;
  max-width: 235px;
  padding: 8px 11px;
  border: 1px solid var(--bag-ai-blue);
  border-radius: 999px;
  background: #fff;
  color: var(--bag-ai-blue);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  min-height: 40px;
}

.bag-ai__handoffs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 0 14px 10px;
}

.bag-ai__handoffs a {
  flex: 0 0 auto;
  padding: 7px 10px;
  border-radius: 9px;
  background: #f2f6fa;
  color: var(--bag-ai-blue);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.bag-ai__handoffs button {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: var(--bag-ai-yellow);
  color: var(--bag-ai-blue);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
}

.bag-ai__handoffs a:first-child { background: var(--bag-ai-yellow); }

.bag-ai__quote {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow-y: auto;
  padding: 18px;
  background: #fff;
  overscroll-behavior: contain;
}

.bag-ai__quote[hidden] { display: none; }

.bag-ai__quote-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--bag-ai-blue);
  font-size: 20px;
}

.bag-ai__quote-head button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--bag-ai-border);
  border-radius: 50%;
  background: #fff;
  color: var(--bag-ai-blue);
  font: inherit;
  font-size: 24px;
  cursor: pointer;
}

.bag-ai__quote-form { display: grid; gap: 12px; }

.bag-ai__quote-form label { display: grid; gap: 5px; font-size: 15px; font-weight: 700; }

.bag-ai__quote-form input[type="text"],
.bag-ai__quote-form textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #adc2d5;
  border-radius: 10px;
  color: var(--bag-ai-text);
  font: inherit;
  font-weight: 400;
}

.bag-ai__quote-form .bag-ai__consent {
  grid-template-columns: auto 1fr;
  align-items: start;
  font-size: 13px;
  font-weight: 400;
}

.bag-ai__quote-form .bag-ai__consent input { margin-top: 3px; }
.bag-ai__quote-form p { margin: 0; color: #667c90; font-size: 12px; }

.bag-ai__quote-form > button,
.bag-ai__quote-form > a {
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--bag-ai-blue);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.bag-ai__quote-form > a { background: #f2f6fa; color: var(--bag-ai-blue); }

.bag-ai__form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--bag-ai-border);
}

.bag-ai__form textarea {
  min-height: 46px;
  max-height: 105px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid #adc2d5;
  border-radius: 12px;
  background: #fff;
  color: var(--bag-ai-text);
  font: inherit;
  font-size: 16px;
}

.bag-ai__form button {
  align-self: stretch;
  min-width: 64px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--bag-ai-blue);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
}

.bag-ai__form button:disabled { cursor: wait; opacity: .55; }

.bag-ai__disclaimer {
  margin: 0;
  padding: 0 14px 12px;
  color: #667c90;
  font-size: 12px;
}

@media (max-width: 767px) {
  .bag-ai {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }
  .bag-ai__launcher {
    min-width: min(300px, calc(100vw - 20px));
    min-height: 66px;
    border-radius: 17px;
  }
  .bag-ai__launcher-brand { flex-basis: 72px; min-height: 48px; }
  .bag-ai__launcher-copy strong { font-size: 17px; }
  .bag-ai__launcher-copy small { font-size: 12px; }
  .bag-ai.is-open .bag-ai__launcher { display: none; }
  .bag-ai__panel {
    position: fixed;
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    height: auto;
    max-height: none;
    grid-template-rows: auto minmax(80px, 1fr) auto auto auto auto;
    border-radius: 20px;
    transform: translateY(18px) scale(.985);
  }
  .bag-ai__panel.is-open { transform: translateY(0) scale(1); }
  .bag-ai__header {
    align-items: center;
    min-height: 64px;
    padding: 12px 14px;
  }
  .bag-ai__header strong { font-size: 18px; }
  .bag-ai__close { width: 42px; height: 42px; flex: 0 0 42px; }
  .bag-ai__messages { padding: 14px; }
  .bag-ai__message { max-width: 92%; font-size: 16px; }
  .bag-ai__quick { padding: 9px 12px; }
  .bag-ai__quick button { min-height: 42px; font-size: 14px; }
  .bag-ai__handoffs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
    padding: 0 12px 10px;
  }
  .bag-ai__handoffs button,
  .bag-ai__handoffs a { width: 100%; min-height: 42px; padding: 8px; font-size: 13px; text-align: center; }
  .bag-ai__handoffs button:first-child { grid-column: 1 / -1; }
  .bag-ai__form { padding: 10px 12px; }
  .bag-ai__form textarea { min-height: 48px; max-height: 88px; resize: none; }
  .bag-ai__form button { min-width: 62px; min-height: 48px; }
  .bag-ai__disclaimer { padding: 0 12px 10px; font-size: 11px; }
  .bag-ai__quote { padding: 16px 14px max(16px, env(safe-area-inset-bottom)); }
  .bag-ai__quote-form input[type="text"],
  .bag-ai__quote-form textarea { min-height: 44px; font-size: 16px; }
  .bag-ai__quote-form > button,
  .bag-ai__quote-form > a { min-height: 44px; }
}

@media (max-width: 380px) {
  .bag-ai__panel {
    top: max(4px, env(safe-area-inset-top));
    right: max(4px, env(safe-area-inset-right));
    bottom: max(4px, env(safe-area-inset-bottom));
    left: max(4px, env(safe-area-inset-left));
    border-radius: 16px;
  }
  .bag-ai__header { min-height: 58px; padding: 9px 11px; }
  .bag-ai__messages { padding: 11px; }
  .bag-ai__quick { padding: 7px 10px; }
  .bag-ai__handoffs { gap: 6px; padding: 0 10px 8px; }
  .bag-ai__form { padding: 8px 10px; }
  .bag-ai__disclaimer { padding: 0 10px 8px; }
}

@media (max-width: 767px) and (orientation: landscape) {
  .bag-ai__panel { grid-template-rows: auto minmax(60px, 1fr) auto auto auto auto; border-radius: 14px; }
  .bag-ai__header { min-height: 52px; padding: 7px 12px; }
  .bag-ai__close { width: 38px; height: 38px; flex-basis: 38px; }
  .bag-ai__quick { padding-block: 6px; }
  .bag-ai__handoffs { display: flex; overflow-x: auto; padding-bottom: 7px; }
  .bag-ai__handoffs button:first-child { grid-column: auto; }
  .bag-ai__handoffs button,
  .bag-ai__handoffs a { width: auto; min-width: 120px; min-height: 38px; }
  .bag-ai__form { padding-block: 7px; }
  .bag-ai__disclaimer { padding-bottom: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .bag-ai__panel, .bag-ai__launcher { transition: none; }
}
