#chat-toggle {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary, #3291ff);
  color: var(--on-primary, #001b3c);
  font-size: 24px;
  border: none;
  box-shadow: 0 4px 16px rgba(50, 145, 255, 0.35);
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
}
#chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(50, 145, 255, 0.5);
  background: var(--primary-fixed-dim, #5ba3ff);
}
#chat-toggle:active {
  transform: scale(0.95);
}

#chat-modal {
  position: fixed;
  bottom: 172px;
  right: 24px;
  width: 360px;
  max-height: 70vh;
  background: var(--surface-container-high, #1e2229);
  border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1001;
  transform-origin: bottom right;
  transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
}
#chat-modal.hidden {
  display: flex;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--primary, #3291ff), var(--primary-fixed-dim, #5ba3ff));
}
.chat-header h3 {
  margin: 0;
  font-family: 'Geist', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--on-primary, #001b3c);
  letter-spacing: -0.01em;
}
.chat-header .chat-header-icon {
  font-size: 20px;
  margin-right: 8px;
  vertical-align: middle;
}
.chat-close {
  background: rgba(0, 0, 0, 0.15);
  border: none;
  color: var(--on-primary, #001b3c);
  font-size: 18px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.chat-close:hover {
  background: rgba(0, 0, 0, 0.25);
}

#chat-messages {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  color: var(--on-surface, #dfe2eb);
  font-family: 'Geist', sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 200px;
  max-height: 400px;
  scroll-behavior: smooth;
}
#chat-messages:empty::after {
  content: "How can I help you?";
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--on-surface-variant, #8e9199);
  font-size: 14px;
  opacity: 0.6;
}

.chat-message {
  padding: 10px 14px;
  line-height: 1.5;
  word-wrap: break-word;
  max-width: 85%;
  animation: chatFadeIn 0.2s ease;
}
@keyframes chatFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
  background: var(--primary, #3291ff);
  color: var(--on-primary, #001b3c);
  border-radius: 16px 16px 4px 16px;
  font-weight: 500;
}

.chat-message.bot {
  align-self: flex-start;
  background: var(--surface-variant, #2d3138);
  color: var(--on-surface, #dfe2eb);
  border-radius: 16px 16px 16px 4px;
}

.chat-message.bot.error {
  background: rgba(255, 75, 75, 0.15);
  color: #ff6b6b;
}

.chat-message.typing {
  align-self: flex-start;
  background: var(--surface-variant, #2d3138);
  border-radius: 16px 16px 16px 4px;
  padding: 14px 20px;
  display: flex;
  gap: 4px;
  align-items: center;
}
.chat-message.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--on-surface-variant, #8e9199);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.chat-message.typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-message.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

#chat-form {
  display: flex;
  padding: 12px 16px;
  gap: 10px;
  align-items: flex-end;
  border-top: 1px solid var(--outline-variant, #2d3138);
  background: var(--surface-container-high, #1e2229);
}
#chat-form textarea {
  flex: 1;
  border: 1px solid var(--outline-variant, #2d3138);
  border-radius: 12px;
  background: var(--surface-variant, #2d3138);
  color: var(--on-surface, #dfe2eb);
  padding: 10px 14px;
  font-family: 'Geist', sans-serif;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 20px;
  max-height: 120px;
  line-height: 1.4;
  transition: border-color 0.15s ease;
}
#chat-form textarea:focus {
  border-color: var(--primary, #3291ff);
}
#chat-form textarea::placeholder {
  color: var(--on-surface-variant, #8e9199);
}
#chat-form button {
  background: var(--primary, #3291ff);
  color: var(--on-primary, #001b3c);
  border: none;
  border-radius: 12px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.15s ease;
}
#chat-form button:hover {
  background: var(--primary-fixed-dim, #5ba3ff);
}
#chat-form button:active {
  transform: scale(0.92);
}
#chat-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-countdown {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  margin: 0 16px 8px;
  background: rgba(255, 193, 7, 0.12);
  border: 1px solid rgba(255, 193, 7, 0.25);
  border-radius: 10px;
  color: #ffd54f;
  font-family: 'Geist', sans-serif;
  font-size: 13px;
  line-height: 1.4;
  animation: chatFadeIn 0.25s ease;
}
.chat-countdown--critical {
  background: rgba(255, 82, 82, 0.12);
  border-color: rgba(255, 82, 82, 0.3);
  color: #ff8a80;
}
.chat-countdown strong {
  font-weight: 600;
}
