/**
 * Marketing Signal — floating sales consultant.
 * Closed: red Radio FAB (matches Connect). Open: right push drawer + blue accents.
 */
#pi-chat-root {
  --sig-ink: #0f1723;
  --sig-body: #33404f;
  --sig-muted: #667485;
  --sig-line: #e6e8ec;
  --sig-surface: #ffffff;
  --sig-recess: #f4f5f7;
  /* Readable blue accent (aligned with marketing --lp-blue, not purple) */
  --sig-blue: #1f4fd0;
  --sig-blue-mid: #2f6bef;
  --sig-blue-bright: #5b8cff;
  --sig-blue-soft: rgba(47, 107, 239, 0.1);
  --sig-blue-border: rgba(31, 79, 208, 0.28);
  --sig-blue-grad: linear-gradient(135deg, #1e3a8a 0%, #2f6bef 52%, #38bdf8 100%);
  --sig-font: "IBM Plex Sans", "DM Sans", system-ui, sans-serif;
  --sig-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sig-display: "Space Grotesk", "DM Sans", system-ui, sans-serif;
  --pi-signal-drawer-w: min(26.5rem, 100vw);

  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 90;
  font-family: var(--sig-font);
  color: var(--sig-body);
}

@supports (padding: max(0px)) {
  #pi-chat-root {
    bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    right: max(1rem, env(safe-area-inset-right, 0px));
  }
}

/* Push main page left when drawer is open */
html {
  --pi-signal-drawer-offset: 0px;
}

html.pi-signal-drawer-open {
  --pi-signal-drawer-offset: min(26.5rem, 100vw);
  overflow-x: hidden;
}

html.pi-signal-drawer-open body {
  padding-right: var(--pi-signal-drawer-offset);
  transition: padding-right 0.28s ease;
  box-sizing: border-box;
}

@media (prefers-reduced-motion: reduce) {
  html.pi-signal-drawer-open body {
    transition: none;
  }
}

@media (max-width: 720px) {
  html.pi-signal-drawer-open body {
    /* Full-bleed drawer on small screens — no push (page covered) */
    padding-right: 0;
  }
}

/* Soft dwell nudge — tip beside FAB; does not auto-open chat */
.pi-chat-nudge {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.75rem);
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  box-sizing: border-box;
  /* #pi-chat-root shrink-wraps to the FAB. An abspos tip with only max-width
     uses that ~3rem containing block and wraps one word per line. */
  width: min(20rem, calc(100vw - 2.5rem));
  max-width: min(20rem, calc(100vw - 2.5rem));
  padding: 0.75rem 0.7rem 0.75rem 0.95rem;
  border-radius: 14px;
  border: 1px solid rgba(220, 38, 38, 0.22);
  background: #ffffff;
  color: #0f1723;
  box-shadow: 0 14px 36px rgba(15, 23, 35, 0.16);
  animation: pi-chat-nudge-in 0.28s ease-out;
}

.pi-chat-nudge[hidden] {
  display: none !important;
  animation: none;
}

.pi-chat-nudge::after {
  content: '';
  position: absolute;
  right: 1.1rem;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-right: 1px solid rgba(220, 38, 38, 0.22);
  border-bottom: 1px solid rgba(220, 38, 38, 0.22);
  transform: rotate(45deg);
}

.pi-chat-nudge-body {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: 500 0.875rem/1.45 var(--sig-font);
  text-align: left;
  white-space: normal;
  overflow-wrap: break-word;
  cursor: pointer;
}

.pi-chat-nudge-body:hover {
  color: #b91c1c;
}

.pi-chat-nudge-dismiss {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  margin: -0.15rem -0.1rem 0 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #8792a1;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.pi-chat-nudge-dismiss:hover {
  color: #0f1723;
  background: rgba(15, 23, 35, 0.06);
}

@keyframes pi-chat-nudge-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pi-chat-nudge {
    animation: none;
  }
}

.pi-chat-open .pi-chat-nudge {
  display: none !important;
}

/* Match Connect/CRM Signal FAB: red circle + Lucide Radio */
.pi-chat-launcher {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  background: #dc2626;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(220, 38, 38, 0.35);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

@media (min-width: 768px) {
  .pi-chat-launcher {
    width: 3rem;
    height: 3rem;
  }
}

.pi-chat-launcher:hover {
  background: #ef4444;
  transform: scale(1.05);
  box-shadow: 0 14px 32px rgba(220, 38, 38, 0.42);
}

.pi-chat-launcher:focus-visible {
  outline: 2px solid #f87171;
  outline-offset: 3px;
}

.pi-chat-launcher--open {
  /* Drawer has its own close — hide FAB while open */
  opacity: 0;
  pointer-events: none;
  transform: scale(0.9);
}

.pi-chat-launcher-glyph {
  display: grid;
  place-items: center;
  line-height: 0;
}

.pi-chat-launcher-glyph .pi-chat-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.pi-chat-launcher-dot {
  position: absolute;
  top: -0.125rem;
  right: -0.125rem;
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 999px;
  background: #fca5a5;
  border: 2px solid #0e1013;
  animation: pi-chat-dot-pulse 2s ease-in-out infinite;
}

.pi-chat-launcher--open .pi-chat-launcher-dot {
  display: none;
}

@keyframes pi-chat-dot-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pi-chat-launcher-dot {
    animation: none;
  }
  .pi-chat-launcher,
  .pi-chat-chip,
  .pi-chat-panel {
    transition: none;
  }
  .pi-chat-launcher:hover {
    transform: none;
  }
}

/* Right push drawer */
.pi-chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--pi-signal-drawer-w);
  max-height: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(180deg, rgba(47, 107, 239, 0.09) 0%, transparent 28%),
    var(--sig-surface);
  border: none;
  border-left: 1px solid var(--sig-blue-border);
  border-radius: 0;
  box-shadow: -18px 0 48px rgba(15, 23, 35, 0.14);
  overflow: hidden;
  transform: translateX(0);
  animation: pi-chat-drawer-in 0.28s ease-out;
  z-index: 91;
}

.pi-chat-panel[hidden] {
  display: none !important;
  animation: none;
}

@keyframes pi-chat-drawer-in {
  from {
    opacity: 0.7;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pi-chat-panel {
    animation: none;
  }
}

.pi-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.15rem 1rem;
  border-bottom: 1px solid var(--sig-line);
  background:
    linear-gradient(120deg, rgba(30, 58, 138, 0.1) 0%, rgba(47, 107, 239, 0.12) 40%, rgba(56, 189, 248, 0.08) 100%),
    var(--sig-surface);
}

.pi-chat-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.pi-chat-brand-mark {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: #ffffff;
  background: #dc2626; /* same red Signal FAB as Connect */
  border: 1px solid rgba(248, 113, 113, 0.4);
  box-shadow: 0 6px 14px rgba(220, 38, 38, 0.28);
}

.pi-chat-brand-mark .pi-chat-icon {
  width: 1.1rem;
  height: 1.1rem;
  filter: none;
}

.pi-chat-title {
  font-family: var(--sig-display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--sig-ink);
}

.pi-chat-subtitle {
  font-family: var(--sig-mono);
  font-size: 0.68rem;
  color: var(--sig-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.14rem;
}

.pi-chat-close {
  background: none;
  border: none;
  color: var(--sig-muted);
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
}

.pi-chat-close:hover {
  color: var(--sig-ink);
  background: rgba(15, 23, 35, 0.05);
}

.pi-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 0;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(47, 107, 239, 0.06), transparent 48%),
    var(--sig-recess);
}

.pi-chat-msg {
  max-width: 94%;
  font-size: 0.9rem;
  line-height: 1.55;
}

.pi-chat-msg p {
  margin: 0;
}

.pi-chat-msg p + p {
  margin-top: 0.45rem;
}

.pi-chat-msg-bot {
  align-self: flex-start;
  background: var(--sig-surface);
  border: 1px solid var(--sig-line);
  border-radius: 14px 14px 14px 5px;
  padding: 0.9rem 1rem;
  color: var(--sig-body);
  box-shadow: 0 1px 2px rgba(15, 23, 35, 0.04);
}

.pi-chat-msg-bot strong {
  color: var(--sig-ink);
  font-weight: 650;
}

.pi-chat-msg-user {
  align-self: flex-end;
  background: var(--sig-blue-soft);
  border: 1px solid var(--sig-blue-border);
  border-radius: 14px 14px 5px 14px;
  padding: 0.55rem 0.875rem;
  color: var(--sig-ink);
}

.pi-chat-msg-typing {
  min-width: 3.2rem;
}

.pi-chat-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  min-height: 1.1rem;
}

.pi-chat-typing-dots span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--sig-blue-mid);
  opacity: 0.45;
  animation: pi-chat-dot 1.1s ease-in-out infinite;
}

.pi-chat-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.pi-chat-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pi-chat-dot {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .pi-chat-typing-dots span {
    animation: none;
    opacity: 0.7;
  }
}

.pi-chat-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.65rem;
}

.pi-chat-links a {
  font-family: var(--sig-mono);
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.4rem 0.6rem;
  border-radius: 7px;
  border: 1px solid var(--sig-blue-border);
  background: rgba(47, 107, 239, 0.08);
  color: var(--sig-blue);
  text-decoration: none;
}

.pi-chat-links a:hover {
  background: rgba(47, 107, 239, 0.16);
  text-decoration: none;
}

.pi-chat-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.2rem 1.15rem 0.95rem;
  background: var(--sig-recess);
}

.pi-chat-chip {
  font-family: var(--sig-mono);
  font-size: 0.68rem;
  padding: 0.38rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--sig-line);
  background: var(--sig-surface);
  color: var(--sig-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.pi-chat-chip:hover {
  border-color: var(--sig-blue-border);
  color: var(--sig-blue);
  background: rgba(47, 107, 239, 0.06);
}

.pi-chat-form {
  display: flex;
  gap: 0.45rem;
  padding: 0.95rem 1.15rem calc(0.95rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--sig-line);
  background: var(--sig-surface);
}

.pi-chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--sig-line);
  background: var(--sig-recess);
  color: var(--sig-ink);
  font-size: 0.9rem;
  font-family: var(--sig-font);
}

.pi-chat-input::placeholder {
  color: var(--sig-muted);
}

.pi-chat-input:focus {
  outline: none;
  border-color: var(--sig-blue-mid);
  box-shadow: 0 0 0 3px rgba(47, 107, 239, 0.15);
  background: #fff;
}

.pi-chat-input:disabled,
.pi-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.pi-chat-send {
  width: 2.6rem;
  border-radius: 10px;
  border: 1px solid var(--sig-blue-border);
  background: var(--sig-blue-grad);
  color: #ffffff;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(47, 107, 239, 0.25);
}

.pi-chat-send:hover:not(:disabled) {
  filter: brightness(1.05);
}
