/* ProTow website support chat (Stage 1). Loaded after styles.css and built only from its tokens:
   colours, radii, focus ring, font and the --chat-reserve space the page already keeps clear. */

#chat-root {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

#chat-root.is-open {
  z-index: 60;
}

body.nav-open #chat-root {
  display: none;
}

/* ── Bubble ─────────────────────────────────────────────────────────── */

.chat-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--teal-line);
  border-radius: 50%;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  transition: background-color 0.15s ease, transform 0.15s ease;
}

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

.chat-launcher:active {
  background: var(--teal-press);
  transform: translateY(1px);
}

/* ── Panel ──────────────────────────────────────────────────────────── */

.chat-panel {
  display: flex;
  flex-direction: column;
  width: min(390px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 120px));
  height: min(620px, calc(100dvh - 120px));
  background: var(--bg-raised);
  color: var(--text-soft);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  font-family: var(--font);
}

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

.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 12px 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.chat-titles {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 17px;
  line-height: 1.25;
  letter-spacing: 0;
}

.chat-subtitle {
  color: var(--teal-bright);
  font-size: 13px;
  font-weight: 600;
}

.chat-text-btn,
.chat-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.chat-text-btn:hover,
.chat-icon-btn:hover {
  border-color: var(--teal-bright);
  background: var(--teal-tint);
}

.chat-notice {
  padding: 10px 18px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.chat-msg p + p,
.chat-msg p + .chat-list,
.chat-msg .chat-list + p {
  margin-top: 8px;
}

.chat-msg-assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--teal);
  color: #fff;
  white-space: pre-wrap;
}

.chat-msg-user.chat-msg-unsent {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  color: var(--muted);
}

.chat-msg-notice {
  align-self: stretch;
  max-width: none;
  background: var(--teal-tint);
  border: 1px solid var(--teal-line);
  color: var(--text-soft);
  font-size: 14px;
}

.chat-list {
  margin: 4px 0 0;
  padding-left: 22px;
}

.chat-list li + li {
  margin-top: 4px;
}

.chat-msg a {
  color: var(--teal-bright);
}

.chat-msg-user a {
  color: #fff;
}

.chat-typing {
  display: flex;
  align-items: center;
  min-height: 40px;
}

.chat-dots,
.chat-dots::before,
.chat-dots::after {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-blink 1.2s infinite ease-in-out;
}

.chat-dots {
  position: relative;
  margin: 0 14px;
  animation-delay: 0.2s;
}

.chat-dots::before,
.chat-dots::after {
  content: "";
  position: absolute;
  top: 0;
}

.chat-dots::before {
  left: -12px;
  animation-delay: 0s;
}

.chat-dots::after {
  left: 12px;
  animation-delay: 0.4s;
}

@keyframes chat-blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* ── Composer ───────────────────────────────────────────────────────── */

.chat-form {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input {
  flex: 1;
  min-height: 48px;
  max-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px keeps iOS from zooming in on focus */
  line-height: 1.4;
  resize: none;
}

.chat-input::placeholder {
  color: var(--subtle);
}

.chat-input:disabled {
  opacity: 0.6;
}

.chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  flex: none;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  cursor: pointer;
}

.chat-send:hover {
  background: var(--teal-hover);
}

.chat-send:disabled {
  background: var(--surface-2);
  color: var(--subtle);
  cursor: not-allowed;
}

.chat-count {
  display: block;
  min-height: 0;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.chat-count:empty {
  display: none;
}

/* ── Phones: the open panel fills the screen ───────────────────────── */

@media (max-width: 639px) {
  #chat-root.is-open {
    inset: 0;
    right: 0;
    bottom: 0;
    gap: 0;
  }

  #chat-root.is-open .chat-launcher {
    display: none;
  }

  #chat-root.is-open .chat-panel {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }

  html.chat-lock,
  html.chat-lock body {
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-dots,
  .chat-dots::before,
  .chat-dots::after {
    animation: none;
    opacity: 0.7;
  }
}
