/* Enquiry chat assistant (scripts/browser/chat-widget.js).
   Loaded only on pages listed in site.json chatbot.pages, and only when
   chatbot.enabled is true. Tokens from styles/style.css; no hard-coded hex.
   The button sits below the cookie banner (z-index 1000), so the banner stays
   on top. The open panel sits above the sticky header (1000) and the mobile
   bottom bar (998), because the visitor opened it on purpose. */

.twe-chat-launcher {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 990;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.75rem 1.1rem;
  border: 1px solid var(--gold-dark);
  border-radius: var(--radius-full);
  background: var(--gold-brand);
  color: var(--text-on-light);
  font-family: var(--font-accent);
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--shadow-md);
  cursor: pointer;
}
.twe-chat-launcher:hover { background: var(--gold-light); }
.twe-chat-launcher:focus-visible,
.twe-chat-panel button:focus-visible,
.twe-chat-panel textarea:focus-visible,
.twe-chat-panel a:focus-visible {
  outline: 3px solid var(--gold-accessible);
  outline-offset: 2px;
}

.twe-chat-panel {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1002;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 2rem));
  border: 1px solid var(--border-on-light);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  color: var(--text-on-light);
  font-family: var(--font-body);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}
.twe-chat-panel[hidden],
.twe-chat-launcher[hidden] { display: none; }

.twe-chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.9rem 1rem 0.6rem;
  border-bottom: 1px solid var(--border-on-light);
  background: var(--bg-primary);
}
.twe-chat-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.1rem;
  line-height: 1.2;
  color: var(--text-on-light);
}
.twe-chat-close {
  flex: none;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-on-light);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.twe-chat-close:hover { background: var(--bg-tertiary); }

.twe-chat-note {
  margin: 0;
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-on-light-muted);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-on-light);
}
.twe-chat-note a { color: var(--gold-accessible); }

.twe-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.twe-chat-msg {
  max-width: 88%;
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.twe-chat-msg--bot {
  align-self: flex-start;
  background: var(--bg-tertiary);
  color: var(--text-on-light);
}
.twe-chat-msg--user {
  align-self: flex-end;
  background: var(--bg-primary);
  border: 1px solid var(--gold-brand);
  color: var(--text-on-light);
}
.twe-chat-msg a { color: var(--gold-accessible); text-decoration: underline; }
.twe-chat-msg--thinking { color: var(--text-on-light-muted); font-style: italic; }

.twe-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border-on-light);
  background: var(--bg-primary);
}
.twe-chat-form label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.twe-chat-form textarea {
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 120px;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border-on-light);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-on-light);
  font: inherit;
  font-size: 1rem; /* 16px stops iOS zooming on focus */
  resize: none;
}
.twe-chat-send {
  flex: none;
  min-width: 64px;
  min-height: 44px;
  padding: 0 1rem;
  border: 1px solid var(--gold-dark);
  border-radius: var(--radius-md);
  background: var(--gold-brand);
  color: var(--text-on-light);
  font-family: var(--font-accent);
  font-weight: 700;
  cursor: pointer;
}
.twe-chat-send:disabled { opacity: 0.6; cursor: wait; }

/* The mobile bottom bar (.mobile-sticky-nav) shows up to 768px and is about
   72px tall, so the button sits above it there. */
@media (max-width: 768px) {
  .twe-chat-launcher { bottom: calc(72px + 0.75rem); right: 0.75rem; }
}

@media (max-width: 480px) {
  .twe-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .twe-chat-panel { animation: twe-chat-in 160ms ease-out; }
  @keyframes twe-chat-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}
