.campaign-chat-widget {
  --chat-gutter: clamp(.75rem, 2vw, 1.75rem);
  --chat-edge: max(var(--chat-gutter), env(safe-area-inset-right, 0px));
  --chat-bottom: max(var(--chat-gutter), env(safe-area-inset-bottom, 0px));
  --chat-line: #52614d;
  --chat-text: #eff5ed;
  color: var(--chat-text);
}

.campaign-chat-widget button,
.campaign-chat-widget textarea { font-family: inherit; }
.campaign-chat-widget svg {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.campaign-chat-widget :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.chat-launcher {
  position: fixed;
  z-index: 12;
  right: var(--chat-edge);
  bottom: var(--chat-bottom);
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem 1.05rem;
  border-radius: 100px;
  border: 1px solid #879a70;
  background: #162016;
  box-shadow: inset 0 1px 0 #edffcb29, 0 5px 18px #0006;
  color: var(--chat-text);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.25;
}
.chat-launcher svg { color: var(--accent); }

#campaign-chat {
  position: fixed;
  inset: auto var(--chat-edge) calc(var(--chat-bottom) + var(--chat-keyboard-height, 0px)) auto;
  margin: 0;
  width: min(28.5rem, calc(100% - var(--chat-edge) - var(--chat-gutter)));
  height: min(38rem, calc(var(--chat-screen-height, 100dvh) - var(--chat-bottom) - max(var(--chat-gutter), env(safe-area-inset-top, 0px))));
  max-height: none;
  max-width: none;
  overflow: hidden;
  padding: 0;
  border: 1px solid var(--chat-line);
  border-radius: 18px;
  background: linear-gradient(125deg, #202b21f5, #121b15fa 53%);
  color: var(--chat-text);
  box-shadow: inset 0 1px 0 #eefcd326, 0 18px 60px #0007;
}
#campaign-chat[open] {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
#campaign-chat::backdrop { background: #050b0673; backdrop-filter: none; }
.chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .55rem;
  padding: .85rem 1rem .85rem 1.4rem;
  border-bottom: 1px solid #43503e;
}
#chat-title {
  font-size: clamp(1.25rem, 1.02rem + 1.2vw, 1.5rem);
  line-height: 1.15;
  letter-spacing: -.025em;
  font-weight: 600;
}
#chat-title:focus { outline: none; }
.chat-close, .chat-send {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
}
.chat-close { background: transparent; color: var(--chat-text); }
.chat-close svg { width: 19px; height: 19px; }
.chat-scroll {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #6c7e63 #151e17;
  padding: 1.4rem;
}
.chat-welcome h3 {
  max-width: 13ch;
  font-size: clamp(1.75rem, 1.4rem + 2vw, 2.45rem);
  font-weight: 500;
  line-height: 1.08;
  letter-spacing: -.035em;
  text-wrap: balance;
}
.chat-welcome > p, .chat-message p, #chat-question {
  font-size: 1.125rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.chat-welcome > p { margin: .85rem 0 1.25rem; color: var(--reading-color); }
.chat-starters { display: grid; gap: .45rem; }
.chat-starters button, .chat-action {
  min-height: 44px;
  padding: .6rem .8rem;
  font-size: 1.125rem;
  line-height: 1.35;
  text-align: start;
  overflow-wrap: anywhere;
}
.chat-starters button {
  width: 100%;
  border: 1px solid #485745;
  border-radius: 9px;
  background: #202b21;
  color: var(--chat-text);
}
.chat-messages { display: grid; gap: 1.2rem; }
.chat-message { min-width: 0; max-width: 100%; }
.chat-author {
  display: block;
  font-size: .94rem;
  font-weight: 600;
  line-height: 1.35;
  color: #c6d7bd;
  margin-bottom: .3rem;
}
.chat-message p { white-space: pre-wrap; }
.chat-user {
  justify-self: end;
  max-width: 88%;
  background: #2a392a;
  border-radius: 12px 12px 3px 12px;
  padding: .65rem .85rem;
}
.chat-answer { padding-inline: .1rem; }
.chat-action {
  display: block;
  margin-top: .5rem;
  padding-inline: 0;
  background: none;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: .22em;
}
.chat-progress:not(:empty) { margin-top: 1rem; color: var(--secondary-color); font-size: 1rem; }
.chat-form {
  padding: .85rem 1.2rem 1rem;
  border-top: 1px solid #42513e;
  background: #141d16;
}
.chat-compose {
  display: flex;
  align-items: end;
  gap: .5rem;
  padding: .35rem;
  border: 1px solid #66765e;
  border-radius: 12px;
  background: #0c130e;
}
.chat-compose:focus-within { border-color: var(--accent); }
#chat-question {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  resize: none;
  border: 0;
  padding: .5rem .35rem .45rem .5rem;
  color: var(--chat-text);
  background: transparent;
  caret-color: var(--accent);
}
#chat-question:focus { outline: none; }
#chat-question::placeholder { color: #afbea9; }
.chat-send { border-radius: 8px; background: var(--accent); color: var(--accent-ink); }
.chat-send:disabled { background: #2e3d2d; color: #a5b29f; opacity: 1; }
.chat-length, .chat-route { margin: .65rem .1rem 0; color: var(--secondary-color); font-size: .94rem; line-height: 1.35; }

@media (hover: hover) {
  .chat-launcher:hover, .chat-starters button:hover, .chat-close:hover { background: #31402d; }
  .chat-send:enabled:hover { filter: brightness(1.08); }
  .chat-action:hover { text-decoration-thickness: 2px; }
}
@supports (backdrop-filter: blur(12px)) {
  #campaign-chat { backdrop-filter: blur(14px); }
}
@media (max-width: 68rem) {
  .has-campaign-chat .visor-chrome { padding-bottom: max(4.8rem, calc(env(safe-area-inset-bottom) + 4.8rem)); }
}
.has-campaign-chat .site-footer {
  padding-bottom: max(5rem, calc(env(safe-area-inset-bottom) + 5rem));
}
@media (max-width: 30rem) {
  .campaign-chat-widget { --chat-gutter: .5rem; }
  .chat-launcher { min-height: 46px; min-width: 46px; padding: .45rem .85rem; }
  #campaign-chat { border-radius: 14px; }
  .chat-heading { padding: .5rem .6rem .5rem 1rem; }
  .chat-scroll { padding: 1.1rem 1rem; }
  .chat-form { padding: .65rem .8rem .75rem; }
}
@media (max-height: 32rem) {
  .chat-heading { padding-block: .2rem; }
  .chat-form { padding-block: .4rem; }
}
@media (prefers-reduced-motion: reduce) {
  #campaign-chat, #campaign-chat::backdrop { transition: none; transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  #campaign-chat { background: #19221b; backdrop-filter: none; }
}
