/*
 * "Ask SysGlob" assistant (components/chat-widget.tsx, original/js/chat.js).
 *
 * Standalone on purpose: the same widget runs on the site and inside the
 * Watershed dashboard, which does not load the site stylesheet. Every colour
 * is a SysGlob token defined on .chat itself, so the widget looks the same
 * on any host. Fonts follow the host: the site's --display/--body, the
 * dashboard's --font (Noto, for Tamil and Malayalam), then system fonts.
 */

.chat {
  --chat-accent: #0c73e3;
  --chat-accent-100: #eaf3fe;
  --chat-accent-200: #cfe4fd;
  --chat-accent-300: #a6cdfa;
  --chat-accent-700: #0a5cb8;
  --chat-accent-900: #0a2a50;
  --chat-surface: #ffffff;
  --chat-ground: #f7f9fc;
  --chat-ink: #0f1c2e;
  --chat-line: rgba(15, 28, 46, 0.13);
  --chat-field: #dde2ea;
  --chat-dot: #98a2b1;
  --chat-muted: #5f6a7a;
  --chat-display: var(--display, var(--font, system-ui, -apple-system, "Segoe UI", sans-serif));
  --chat-body: var(--body, var(--font, system-ui, -apple-system, "Segoe UI", sans-serif));
  /* Above a host's map controls and tab bar, below its loading screens. */
  --chat-z: 2200;
  --chat-bottom: 24px;
}

.chat-launch[hidden],
.chat-panel[hidden],
.chat-suggest[hidden] {
  display: none;
}

.chat-launch {
  position: fixed;
  right: 24px;
  bottom: var(--chat-bottom);
  z-index: var(--chat-z);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border: 1px solid var(--chat-accent);
  border-radius: 999px;
  background: var(--chat-accent);
  color: #fff;
  font: 600 13px var(--chat-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(12, 115, 227, 0.28);
}
.chat-launch:hover {
  background: var(--chat-accent-700);
  border-color: var(--chat-accent-700);
}
.chat.open .chat-launch {
  display: none;
}

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: var(--chat-bottom);
  z-index: var(--chat-z);
  width: min(380px, calc(100% - 32px));
  height: min(560px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: var(--chat-surface);
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(15, 28, 46, 0.18);
  overflow: hidden;
  font-family: var(--chat-body);
  color: var(--chat-ink);
}
.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--chat-accent-900);
  color: #fff;
}
.chat-title {
  margin: 0;
  font: 600 17px var(--chat-display);
  letter-spacing: -0.01em;
}
.chat-sub {
  margin: 0;
  font-size: 12px;
  color: var(--chat-accent-300);
}
.chat-close {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 6px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
}
.chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--chat-ground);
}
.chat-msg {
  margin: 0;
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.chat-msg.bot {
  align-self: flex-start;
  background: var(--chat-surface);
  border: 1px solid var(--chat-line);
  color: var(--chat-ink);
}
.chat-msg.me {
  align-self: flex-end;
  background: var(--chat-accent-100);
  border: 1px solid var(--chat-accent-200);
  color: var(--chat-accent-900);
}
.chat-msg.note {
  border-color: var(--chat-accent-300);
}
.chat-msg a {
  color: var(--chat-accent-700);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.chat-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-dot);
  animation: chat-dot 1s infinite ease-in-out;
}
.chat-dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.chat-dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes chat-dot {
  0%,
  80%,
  100% {
    opacity: 0.3;
  }
  40% {
    opacity: 1;
  }
}

.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  background: var(--chat-ground);
}
.chat-suggest button {
  border: 1px solid var(--chat-accent-300);
  background: var(--chat-surface);
  color: var(--chat-accent-700);
  border-radius: 999px;
  padding: 6px 12px;
  font: 13px var(--chat-body);
  cursor: pointer;
}
.chat-suggest button:hover {
  background: var(--chat-accent-100);
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-line);
  background: var(--chat-surface);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--chat-field);
  border-radius: 6px;
  font: 15px/1.4 var(--chat-body);
  color: var(--chat-ink);
  background: var(--chat-surface);
}
.chat-form textarea:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 0;
  border-color: var(--chat-accent);
}
.chat-send {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: var(--chat-accent);
  color: #fff;
  cursor: pointer;
}
.chat-send:hover {
  background: var(--chat-accent-700);
}
.chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.chat-foot {
  margin: 0;
  padding: 8px 14px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--chat-muted);
  background: var(--chat-surface);
}
.chat-foot a {
  color: var(--chat-accent-700);
  text-decoration: underline;
}
.chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Phones: the panel becomes a bottom sheet across the full width. Pinned to
   both edges, not width: 100vw, which counts the scrollbar on some browsers. */
@media (max-width: 520px) {
  .chat {
    --chat-bottom: 16px;
  }
  .chat-launch {
    right: 16px;
  }
  .chat-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(78vh, 600px);
    border-radius: 12px 12px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-dots i {
    animation: none;
    opacity: 0.6;
  }
}
