/* ============================================================
   CHAT WIDGET — floating support chatbot
   Loaded on every page that includes <script src="/chat-widget.js">.
   The JS injects the widget markup; this stylesheet provides all
   visual rules. Uses the same design tokens as index.html.
   ============================================================ */

.chat-widget,
.chat-widget * {
  box-sizing: border-box;
  font-family: 'DM Sans', system-ui, sans-serif;
}

.chat-widget__toggle {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1F2540;
  color: #F5E8D0;
  border: none;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 17, 31, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1), background 200ms;
}
.chat-widget__toggle:hover { background: #E07856; transform: translateY(-2px); }
.chat-widget__toggle svg { width: 24px; height: 24px; }
.chat-widget__toggle[aria-expanded="true"] { display: none; }

.chat-widget__panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 360px;
  max-width: calc(100vw - 24px);
  height: 520px;
  max-height: calc(100vh - 40px);
  background: #FDFAF2;
  border: 1px solid rgba(31, 37, 64, 0.12);
  border-radius: 4px;
  box-shadow: 0 16px 48px rgba(15, 17, 31, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 10000;
}
.chat-widget__panel[data-open="true"] { display: flex; }

.chat-widget__header {
  background: #1F2540;
  color: #F5E8D0;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(31, 37, 64, 0.12);
}
.chat-widget__title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.0625rem;
  font-weight: 500;
  margin: 0;
}
.chat-widget__close {
  background: transparent;
  border: none;
  color: #F5E8D0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
}
.chat-widget__close:hover { background: rgba(245, 232, 208, 0.12); }

.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #FDFAF2;
}

.chat-widget__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9375rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-widget__msg--bot {
  align-self: flex-start;
  background: #F5E8D0;
  color: #0F111F;
  border-top-left-radius: 4px;
}
.chat-widget__msg--user {
  align-self: flex-end;
  background: #1F2540;
  color: #F5E8D0;
  border-top-right-radius: 4px;
}
.chat-widget__msg--error {
  align-self: flex-start;
  background: rgba(200, 96, 63, 0.12);
  color: #C8603F;
  border-left: 3px solid #C8603F;
  border-radius: 2px;
  font-size: 0.875rem;
}
.chat-widget__msg--bot[data-streaming="true"]::after {
  content: "▍";
  display: inline-block;
  margin-left: 2px;
  animation: chatCaret 1s steps(1) infinite;
  color: #E07856;
}
@keyframes chatCaret { 50% { opacity: 0; } }

.chat-widget__form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(31, 37, 64, 0.12);
  background: #FDFAF2;
}
.chat-widget__input {
  flex: 1;
  font-family: inherit;
  font-size: 0.9375rem;
  color: #0F111F;
  background: #F5E8D0;
  border: 1px solid rgba(31, 37, 64, 0.12);
  border-radius: 18px;
  padding: 9px 14px;
  resize: none;
  max-height: 96px;
  line-height: 1.4;
  transition: border-color 180ms;
}
.chat-widget__input:focus {
  outline: none;
  border-color: #E07856;
}
.chat-widget__send {
  background: #1F2540;
  color: #F5E8D0;
  border: none;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  transition: background 180ms;
}
.chat-widget__send:hover { background: #E07856; }
.chat-widget__send:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-widget__send svg { width: 16px; height: 16px; }

.chat-widget__footer {
  padding: 6px 14px 10px;
  font-size: 0.6875rem;
  color: rgba(15, 17, 31, 0.55);
  text-align: center;
  background: #FDFAF2;
}

@media (max-width: 480px) {
  .chat-widget__panel {
    width: calc(100vw - 16px);
    right: 8px;
    bottom: 8px;
    height: calc(100vh - 16px);
    max-height: none;
  }
  .chat-widget__toggle { right: 16px; bottom: 16px; }
}
