.agency-reach {
  --reach-navy: #0b2f6b;
  --reach-ink: #111827;
  --reach-muted: #6b7280;
  --reach-line: #e6e8ee;
  --reach-paper: #fff;
  --reach-soft: #f4f6fa;
  --reach-wa: #128c7e;
  --reach-wa-deep: #075e54;
  position: fixed;
  z-index: 54;
  right: calc(max(18px, env(safe-area-inset-right)) + 72px);
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  width: max-content;
  max-width: calc(100vw - 108px);
  font-family: inherit;
  line-height: 1.4;
  color: var(--reach-ink);
  transition: bottom 0.2s ease;
}

.agency-reach[hidden],
.agency-reach-panel[hidden],
.agency-reach-pill[hidden] { display: none !important; }

body.page-panel .agency-reach,
body.tt-assist-open .agency-reach,
html.is-framed .agency-reach { display: none !important; }

body:has(#agencyReach:not([hidden])) .site-footer {
  padding-bottom: 132px;
}

body.tt-assist-invite .agency-reach {
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 108px);
}

.agency-reach-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.agency-reach-pill {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-height: 58px;
  max-width: min(280px, calc(100vw - 108px));
  padding: 7px 16px 7px 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--reach-paper);
  color: var(--reach-ink);
  text-decoration: none;
  box-shadow: 0 14px 34px rgba(17, 24, 39, 0.16);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: transform 0.22s ease, box-shadow 0.22s ease, background 0.22s ease;
  animation: reach-in 0.55s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.agency-reach-pill.is-call { animation-delay: 0.05s; }
.agency-reach-pill.is-wa { animation-delay: 0.16s; }

.agency-reach-ico {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.agency-reach-ico i {
  position: relative;
  z-index: 1;
  font-size: 1.15rem;
  line-height: 1;
}

.agency-reach-pill.is-call {
  border-color: rgba(11, 47, 107, 0.08);
  background: linear-gradient(180deg, #fff 0%, #f7f9fc 100%);
  box-shadow: 0 14px 32px rgba(11, 47, 107, 0.14);
}
.agency-reach-pill.is-call .agency-reach-ico {
  background: linear-gradient(160deg, #16448a, var(--reach-navy));
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(228, 197, 106, 0.55);
}
.agency-reach-pill.is-wa {
  background: linear-gradient(145deg, #1aa88f 0%, var(--reach-wa) 58%, var(--reach-wa-deep) 100%);
  color: #fff;
  box-shadow: 0 14px 32px rgba(7, 94, 84, 0.28);
}
.agency-reach-pill.is-wa .agency-reach-ico {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
.agency-reach-pill.is-wa .agency-reach-ico::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid rgba(255, 255, 255, 0.72);
  animation: reach-ring 2.6s ease-out infinite;
  pointer-events: none;
}

.agency-reach-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 1px;
}
.agency-reach-copy strong {
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agency-reach-copy small {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  color: #5b6b86;
}
.agency-reach-pill.is-wa .agency-reach-copy small { color: rgba(255, 255, 255, 0.86); }

.agency-reach-pill:hover {
  transform: translateX(-4px);
  box-shadow: 0 18px 36px rgba(17, 24, 39, 0.2);
}
.agency-reach-pill.is-wa:hover { background: linear-gradient(145deg, #15967f 0%, var(--reach-wa-deep) 100%); }
.agency-reach-pill:focus-visible {
  outline: 2px solid #e4c56a;
  outline-offset: 3px;
}

@keyframes reach-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

@keyframes reach-ring {
  0% { transform: scale(1); opacity: 0.7; }
  80%, 100% { transform: scale(1.32); opacity: 0; }
}

.agency-reach-panel {
  display: flex;
  flex-direction: column;
  width: min(340px, calc(100vw - 120px));
  height: min(460px, calc(100dvh - var(--header, 78px) - 168px));
  max-height: calc(100dvh - var(--header, 78px) - 168px);
  background: var(--reach-paper);
  border: 1px solid var(--reach-line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.18);
}

.agency-reach-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: var(--reach-wa-deep);
  color: #fff;
}

.agency-reach-mark {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.14);
  font-size: 1.25rem;
}

.agency-reach-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.agency-reach-id strong {
  font-size: 0.95rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agency-reach-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0.92;
}
.agency-reach-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6ee7b7;
  box-shadow: 0 0 0 4px rgba(110, 231, 183, 0.18);
}

.agency-reach-x {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  font: inherit;
  flex: 0 0 auto;
}
.agency-reach-x:hover { background: rgba(255, 255, 255, 0.22); }
.agency-reach-x:focus-visible { outline: 2px solid #e4c56a; outline-offset: 2px; }

.agency-reach-log {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: #efeae2;
}

.agency-reach-msg { display: flex; flex-direction: column; max-width: 88%; }
.agency-reach-msg p {
  margin: 0;
  padding: 10px 12px;
  font-size: 0.92rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.agency-reach-msg time {
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--reach-muted);
}
.agency-reach-msg.is-agent { align-self: flex-start; }
.agency-reach-msg.is-agent p {
  background: #fff;
  color: var(--reach-ink);
  border-radius: 16px 16px 16px 4px;
}
.agency-reach-msg.is-user { align-self: flex-end; align-items: flex-end; }
.agency-reach-msg.is-user p {
  background: #d9fdd3;
  color: var(--reach-ink);
  border-radius: 16px 16px 4px 16px;
}
.agency-reach-msg a { color: var(--reach-wa-deep); font-weight: 700; }

.agency-reach-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px 0;
  background: var(--reach-paper);
  scrollbar-width: none;
}
.agency-reach-chips::-webkit-scrollbar { display: none; }
.agency-reach-chips button {
  flex: 0 0 auto;
  border: 1px solid var(--reach-line);
  background: var(--reach-paper);
  color: var(--reach-ink);
  border-radius: 999px;
  padding: 7px 12px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.agency-reach-chips button:hover { border-color: #b7c4b4; background: #f3faf4; }

.agency-reach-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--reach-paper);
}
.agency-reach-form textarea {
  flex: 1;
  min-height: 44px;
  max-height: 96px;
  resize: none;
  border: 1px solid var(--reach-line);
  border-radius: 16px;
  padding: 11px 12px;
  font: inherit;
  font-size: 0.92rem;
  color: var(--reach-ink);
  background: var(--reach-soft);
}
.agency-reach-form textarea:focus {
  outline: 2px solid rgba(18, 140, 126, 0.35);
  border-color: var(--reach-wa);
  background: #fff;
}
.agency-reach-send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--reach-wa);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  font: inherit;
}
.agency-reach-send:hover { background: var(--reach-wa-deep); }
.agency-reach-send:focus-visible { outline: 2px solid #e4c56a; outline-offset: 2px; }

.agency-reach-note {
  margin: 0;
  padding: 0 14px 12px;
  background: var(--reach-paper);
  color: var(--reach-muted);
  font-size: 0.72rem;
}

html[data-theme="dark"] .agency-reach {
  --reach-ink: #e8edf5;
  --reach-muted: #a8b3c7;
  --reach-line: #314056;
  --reach-paper: #121a2b;
  --reach-soft: #1a2436;
}
html[data-theme="dark"] .agency-reach-pill.is-call {
  border-color: rgba(228, 197, 106, 0.16);
  background: linear-gradient(180deg, #182236 0%, #121a2b 100%);
}
html[data-theme="dark"] .agency-reach-pill.is-call .agency-reach-ico {
  background: linear-gradient(160deg, #243556, #1c2740);
  color: #e4c56a;
  box-shadow: inset 0 0 0 1px rgba(228, 197, 106, 0.4);
}
html[data-theme="dark"] .agency-reach-copy small { color: #a8b3c7; }
html[data-theme="dark"] .agency-reach-pill.is-wa .agency-reach-copy small { color: rgba(255, 255, 255, 0.86); }
html[data-theme="dark"] .agency-reach-log { background: #0e1726; }
html[data-theme="dark"] .agency-reach-msg.is-agent p { background: #1a2436; }
html[data-theme="dark"] .agency-reach-msg.is-user p { background: #1d4a3e; color: #e8edf5; }
html[data-theme="dark"] .agency-reach-msg a { color: #6ee7b7; }
html[data-theme="dark"] .agency-reach-chips button:hover { background: #1a2436; }

@media (max-width: 767.98px) {
  .agency-reach {
    right: calc(max(18px, env(safe-area-inset-right)) + 72px);
    bottom: max(18px, env(safe-area-inset-bottom));
    max-width: calc(100vw - 108px);
  }
  .agency-reach-pill { min-height: 52px; max-width: min(240px, calc(100vw - 108px)); padding-right: 12px; }
  .agency-reach-ico { width: 40px; height: 40px; }
  .agency-reach-copy strong { font-size: 0.82rem; }
  .agency-reach-copy small { font-size: 0.68rem; }
  body.tt-assist-invite .agency-reach {
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 108px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .agency-reach-pill { animation: none; transition: none; }
  .agency-reach-pill.is-wa .agency-reach-ico::after { animation: none; }
}
