body:has(#chat-launcher:not([hidden])) > footer {
  padding-bottom: 6rem;
}

html:has(#chat-panel[open]) {
  overflow: hidden;
}

#chat-launcher {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 9;
  min-height: 44px;
  padding: 0.65rem 1rem;
  border: 1px solid var(--mint);
  border-radius: 2rem;
  background: var(--navy);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 18px #0b1d2b38;
}

#chat-launcher:hover {
  background: var(--teal);
}

#chat-panel {
  position: fixed;
  --chat-gap: 1rem;
  inset: auto max(var(--chat-gap), env(safe-area-inset-right))
    calc(var(--chat-viewport-inset, 0px) + max(var(--chat-gap), env(safe-area-inset-bottom))) auto;
  width: min(26rem, calc(100% - 2rem));
  height: min(37rem, calc(var(--chat-viewport-height, 100dvh) - 2 * var(--chat-gap)));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: white;
  color: var(--ink);
  box-shadow: 0 12px 45px #0b1d2b38;
}

#chat-panel[open] {
  display: flex;
  flex-direction: column;
}

#chat-panel::backdrop {
  background: #0b1d2b33;
}

.chat-panel-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  background: var(--navy);
  color: white;
}

.chat-panel-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.chat-panel-header form {
  margin: 0;
}

.chat-close {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 0.5rem;
  background: transparent;
  color: white;
  font: inherit;
  font-size: 1.4rem;
  cursor: pointer;
}

#chat-frame {
  display: block;
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--soft, #f1f8f7);
}

@media (max-width: 480px) {
  #chat-panel {
    --chat-gap: 0.5rem;
    left: max(var(--chat-gap), env(safe-area-inset-left));
    width: auto;
  }
}

@media print {
  #chat-launcher,
  #chat-panel {
    display: none;
  }

  body:has(#chat-launcher:not([hidden])) > footer {
    padding-bottom: 0;
  }
}
