/* Live chat widget - reuses design tokens from theme.css (ink/paper/cyan/copper). */

.chat-widget {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  font-family: var(--font-body);
  /* Explicit, stable footprint matching the panel's max size - this box no longer
     auto-sizes around whichever child (toggle button or panel) happens to be
     visible. Auto-sizing here used to mean the container had zero in-flow content
     (and so zero width) while the panel was open, since the toggle is display:none
     and the panel is itself position:absolute/out-of-flow - then had to jump to a
     real width the instant the toggle reappeared on close. That width discontinuity
     on a fixed-position box, right at the open/close transition, is what let a
     browser's layout engine anchor the collapsed toggle off to the wrong side.
     Giving the container a constant size up front removes the discontinuity
     entirely. It has no visible background of its own, so pointer-events: none
     keeps it from blocking clicks on page content behind the parts of this
     footprint neither child is actually painting into; the two children opt back
     into normal interaction. */
  /* dvw/dvh (dynamic viewport units) track the browser's actual visible viewport
     continuously, including iOS Safari's address bar showing/hiding/detaching -
     unlike static vw/vh, which iOS computes against the taller layout viewport and
     which was going stale for a moment during exactly that transition. The vw/vh
     declarations come first as a fallback for any browser without dvw/dvh support:
     an unsupported unit makes the whole declaration invalid, which the cascade
     ignores outright, leaving the earlier (still valid) declaration in effect - so
     this is layered fallback, not an either/or. */
  width: min(360px, calc(100vw - 2.5rem));
  width: min(360px, calc(100dvw - 2.5rem));
  height: min(520px, calc(100vh - 2.5rem));
  height: min(520px, calc(100dvh - 2.5rem));
  pointer-events: none;
}

.chat-toggle {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  padding: 0.75rem 1.1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(14, 34, 56, 0.25);
  transition: background-color 0.15s ease, border-color 0.15s ease;
  pointer-events: auto;
}

.chat-toggle:hover {
  background: #16324f;
  border-color: var(--cyan);
}

.chat-toggle-icon {
  font-size: 1rem;
  line-height: 1;
}

.chat-toggle-label {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.chat-widget.is-open .chat-toggle {
  display: none;
}

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  /* Fills .chat-widget's own footprint rather than computing a size independently -
     see the comment there. */
  width: 100%;
  height: 100%;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  box-shadow: 0 8px 30px rgba(14, 34, 56, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
}

.chat-panel-header {
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--cyan-soft);
}

.chat-panel-title {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  color: var(--cyan);
}

.chat-close {
  background: transparent;
  border: none;
  color: var(--paper-soft);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
}

.chat-close:hover {
  color: var(--paper);
}

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chat-bubble {
  max-width: 85%;
  padding: 0.6rem 0.85rem;
  border-radius: 2px;
  font-size: 0.92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.chat-bubble-assistant {
  align-self: flex-start;
  background: #ECEFF3;
  border: 1px solid var(--ink-line);
  color: var(--ink);
}

.chat-bubble-user {
  align-self: flex-end;
  background: var(--ink);
  color: var(--paper);
}

.chat-bubble-error {
  align-self: flex-start;
  background: rgba(181, 101, 45, 0.08);
  border: 1px dashed var(--copper);
  color: var(--ink);
}

.chat-bubble a {
  color: var(--copper);
  text-decoration: underline;
}

.chat-bubble a:hover {
  color: var(--copper-hover);
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0 1rem 0.6rem;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-soft);
  animation: chat-typing-bounce 1.1s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--ink-line);
  background: var(--paper);
}

.chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 90px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--ink-line);
  border-radius: 2px;
  padding: 0.55rem 0.7rem;
}

.chat-input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px var(--cyan-dim);
}

.chat-send {
  flex: 0 0 auto;
  width: 40px;
  border: 1px solid var(--copper);
  background: var(--copper);
  color: var(--paper);
  border-radius: 2px;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-send:hover {
  background: var(--copper-hover);
  border-color: var(--copper-hover);
}

.chat-send:disabled {
  opacity: 0.55;
  cursor: default;
}

@media (max-width: 480px) {
  .chat-widget {
    right: 0.75rem;
    bottom: 0.75rem;
    width: calc(100vw - 1.5rem);
    width: calc(100dvw - 1.5rem);
  }
}
