.chat-launcher {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  min-height: 54px;
  padding: .78rem 1.1rem;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  background: var(--ink, #161714);
  color: #fff;
  box-shadow: 0 18px 45px rgba(22,23,20,.24);
  font: 800 .78rem/1 var(--sans, Inter, ui-sans-serif, sans-serif);
  letter-spacing: .05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform .2s ease, background .2s ease, opacity .2s ease;
}

.chat-launcher:hover {
  transform: translateY(-2px);
  background: var(--accent, #8b572a);
}

.chat-launcher:focus-visible,
.chat-close:focus-visible,
.chat-form :where(input, select, textarea, button):focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--ink, #161714);
}

.chat-launcher-icon {
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
}

.chat-launcher-icon svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-dialog {
  position: fixed;
  inset: auto max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) auto;
  width: min(430px, calc(100vw - 2rem));
  max-width: none;
  max-height: min(760px, calc(100svh - 2rem));
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 1.25rem;
  background: transparent;
  color: var(--ink, #161714);
  overflow: visible;
}

.chat-dialog::backdrop {
  background: rgba(15,16,14,.36);
  backdrop-filter: blur(4px);
}

.chat-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: min(760px, calc(100svh - 2rem));
  overflow: hidden;
  border: 1px solid rgba(22,23,20,.14);
  border-radius: 1.25rem;
  background: #fff;
  box-shadow: 0 30px 90px rgba(22,23,20,.28);
}

.chat-dialog[open] .chat-shell {
  animation: chat-panel-in .24s cubic-bezier(.2,.75,.25,1);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--ink, #161714);
  color: #fff;
}

.chat-identity {
  display: flex;
  align-items: center;
  gap: .75rem;
  min-width: 0;
}

.chat-status-dot {
  flex: 0 0 auto;
  width: .7rem;
  height: .7rem;
  border-radius: 50%;
  background: var(--accent-2, #d4b383);
  box-shadow: 0 0 0 4px rgba(212,179,131,.16);
}

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

.chat-identity strong {
  font-size: .95rem;
  line-height: 1.2;
}

.chat-identity span {
  margin-top: .18rem;
  color: rgba(255,255,255,.7);
  font-size: .72rem;
  line-height: 1.25;
}

.chat-close {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 50%;
  background: transparent;
  color: #fff;
  font: 400 1.65rem/1 var(--sans, Inter, ui-sans-serif, sans-serif);
  cursor: pointer;
  transition: background .2s ease;
}

.chat-close:hover {
  background: rgba(255,255,255,.12);
}

.chat-thread {
  display: grid;
  gap: .65rem;
  padding: 1rem 1.1rem;
  background: var(--paper, #f3eee5);
  border-bottom: 1px solid rgba(22,23,20,.12);
}

.chat-message {
  width: fit-content;
  max-width: 92%;
  margin: 0;
  padding: .78rem .9rem;
  border-radius: .9rem .9rem .9rem .25rem;
  background: #fff;
  box-shadow: 0 8px 24px rgba(22,23,20,.06);
  font-size: .9rem;
  line-height: 1.45;
}

.chat-message-note {
  background: rgba(139,87,42,.09);
  box-shadow: none;
  color: rgba(22,23,20,.76);
  font-size: .78rem;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .8rem;
  min-height: 0;
  padding: 1rem 1.1rem 1.15rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #fff;
}

.chat-field {
  display: flex;
  flex-direction: column;
  gap: .38rem;
}

.chat-field-full {
  grid-column: 1 / -1;
}

.chat-field label {
  color: var(--ink, #161714);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.chat-field input,
.chat-field select,
.chat-field textarea {
  width: 100%;
  border: 1px solid rgba(22,23,20,.2);
  border-radius: .65rem;
  background: #fff;
  color: var(--ink, #161714);
  padding: .82rem .85rem;
  font: inherit;
}

.chat-field textarea {
  min-height: 7rem;
  resize: vertical;
}

.chat-form .turnstile-slot {
  min-height: 70px;
}

.chat-form .button {
  width: 100%;
}

.chat-form .form-note {
  margin: 0;
  font-size: .75rem;
  line-height: 1.45;
}

.chat-form .form-status {
  grid-column: 1 / -1;
}

.chat-is-open .chat-launcher {
  opacity: 0;
  pointer-events: none;
}

body.chat-is-open {
  overflow: hidden;
}

@keyframes chat-panel-in {
  from { opacity: 0; transform: translateY(14px) scale(.985); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 760px) {
  .chat-launcher {
    right: max(.85rem, env(safe-area-inset-right));
    bottom: max(.85rem, env(safe-area-inset-bottom));
  }

  .chat-dialog {
    inset: auto 0 0 0;
    width: 100%;
    max-height: 92svh;
    border-radius: 1.25rem 1.25rem 0 0;
  }

  .chat-shell {
    max-height: 92svh;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 1.25rem 1.25rem 0 0;
  }

  .chat-form {
    grid-template-columns: 1fr;
    padding-bottom: calc(1.15rem + env(safe-area-inset-bottom));
  }

  .chat-field-full,
  .chat-form .form-status {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher,
  .chat-dialog[open] .chat-shell {
    animation: none;
    transition: none;
  }
}
