/* Chat widget. Uses the design tokens from style.css. */

.chat-fab {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .8rem 1.1rem;
  border: 0;
  border-radius: 999px;
  background: var(--blue-700);
  color: #fff;
  font: 600 var(--step--1) var(--font-body);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}
.chat-fab:hover { background: var(--blue-800); }
.chat-fab:focus-visible,
.chat-close:focus-visible,
.chat-send:focus-visible,
.chat-input:focus-visible {
  outline: 3px solid var(--amber-500);
  outline-offset: 2px;
}
.chat-fab svg { width: 1.25rem; height: 1.25rem; flex: none; }
.chat-fab[aria-expanded="true"] { display: none; }

.chat-panel {
  position: fixed;
  right: 1.1rem;
  bottom: 1.1rem;
  z-index: 91;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2.2rem));
  height: min(560px, calc(100vh - 2.2rem));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.chat-panel[hidden] { display: none; }

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  background: var(--blue-800);
  color: #fff;
}
.chat-title { margin: 0; font: 600 var(--step-0) var(--font-body); }
.chat-close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  padding: .1rem .5rem;
  border-radius: 8px;
  cursor: pointer;
}
.chat-close:hover { background: rgba(255, 255, 255, .15); }

.chat-notice {
  margin: 0;
  padding: .45rem 1rem;
  background: var(--amber-100);
  color: var(--ink-soft);
  font-size: var(--step--1);
  border-bottom: 1px solid var(--line);
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  background: var(--blue-050);
}
.chat-msg {
  max-width: 85%;
  padding: .6rem .8rem;
  border-radius: 14px;
  font-size: var(--step--1);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink);
}
.chat-msg--visitor {
  align-self: flex-end;
  background: var(--blue-700);
  color: #fff;
}
.chat-msg--error {
  align-self: stretch;
  max-width: 100%;
  background: var(--red-100);
  border: 1px solid var(--red-600);
  color: var(--ink);
}
.chat-typing { color: var(--muted); font-style: italic; }

.chat-form {
  display: flex;
  gap: .5rem;
  padding: .75rem;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.chat-input {
  flex: 1;
  min-width: 0;
  padding: .6rem .75rem;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  font: 400 var(--step--1) var(--font-body);
  color: var(--ink);
}
.chat-input:disabled { background: var(--blue-050); }
.chat-send {
  padding: .6rem 1rem;
  border: 0;
  border-radius: 10px;
  background: var(--blue-700);
  color: #fff;
  font: 600 var(--step--1) var(--font-body);
  cursor: pointer;
}
.chat-send:hover:not(:disabled) { background: var(--blue-800); }
.chat-send:disabled { background: var(--muted); cursor: not-allowed; }

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

@media (prefers-reduced-motion: no-preference) {
  .chat-panel:not([hidden]) { animation: chat-pop .18s ease-out; }
  @keyframes chat-pop {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}
