:root {
  --chat-accent: #4f46e5;
  --chat-bg: #fff;
  --chat-text: #0f172a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

#chat-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--chat-accent);
  color: #fff;
  border: 0;
  cursor: pointer;
  font-size: 22px; /* slightly bigger emoji */
  display: flex; /* center content */
  align-items: center; /* vertical center */
  justify-content: center; /* horizontal center */
  line-height: 1; /* prevent vertical offset */
  padding: 0; /* remove default button padding */
  box-shadow: var(--shadow);
  z-index: 9999;
}

/* Tooltip styles */
#chat-tooltip {
  position: fixed;
  right: 88px; /* Position to the left of the FAB */
  bottom: 32px; /* Align vertically with FAB center */
  background: #1f2937;
  color: #fff;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9998;
  opacity: 0;
  transform: translateX(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

#chat-tooltip::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid #1f2937;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

#chat-tooltip.show {
  opacity: 1;
  transform: translateX(0);
}

#chat-panel {
  position: fixed;
  right: 20px;
  bottom: 84px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--chat-bg);
  color: var(--chat-text);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9998;
}

#chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  font-weight: 600;
}

#chat-close {
  background: none;
  color: #0f172a;
  border: 0;
  font-size: 18px;
  cursor: pointer;
}

#chat-log {
  flex: 1;
  overflow: auto;
  padding: 12px 18px;
  background: #f9fafb;
  min-height: 0; /* allow shrinking so footer stays pinned at bottom */
}

.msg {
  margin: 8px 0;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.bubble {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  line-height: 1.35;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
  min-width: 0;
  box-sizing: border-box;
}

.msg.user {
  justify-content: flex-end;
}

.msg.user .bubble {
  background: var(--chat-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.bot .bubble {
  background: #fff;
  border-bottom-left-radius: 4px;
}

#chat-input {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  align-items: flex-end; /* keep Send anchored to bottom as textarea grows */
}

.textarea-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
}

#chat-text {
  flex: 0 0 auto; /* let height be content-driven */
  width: 100%;
  min-height: 60px;
  max-height: 120px; /* Set a max height to trigger scrolling */
  resize: none; /* Disable manual resizing */
  padding: 10px 45px 10px 12px; /* Add right padding for mic button */
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  outline: none;
  overflow-y: hidden; /* JS toggles when max reached */
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-sizing: border-box; /* include borders in height so bottom aligns */
}

#chat-text:disabled {
  background: #f1f5f9;
  cursor: not-allowed;
}

#chat-text.recording {
  border-color: #ef4444;
  background: #fef2f2;
  animation: borderPulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

@keyframes borderPulse {
  0%, 100% {
    border-color: #ef4444;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
  }
  50% {
    border-color: #dc2626;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.4);
  }
}

#chat-mic {
  position: absolute;
  right: 8px;
  bottom: 50%;
  transform: translateY(50%);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 18px;
  cursor: pointer;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  padding: 0;
}

#chat-mic:hover {
  background: #f1f5f9;
  color: var(--chat-accent);
}

#chat-mic:active {
  transform: translateY(50%) scale(0.95);
}

#chat-mic.recording {
  color: #ef4444;
  background: #fee2e2;
  animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% {
    opacity: 1;
    transform: translateY(50%) scale(1);
    background: #fee2e2;
  }
  50% {
    opacity: 1;
    transform: translateY(50%) scale(1.15);
    background: #fecaca;
  }
}

#chat-send {
  min-width: 84px;
  height: 40px; /* fixed height */
  border: 0;
  border-radius: 10px;
  background: var(--chat-accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto; /* do not grow/shrink with flex container */
}

#chat-send:disabled {
  background: #a5b4fc;
  cursor: not-allowed;
}

/* Simple formatting styles - MINIMAL ADDITIONS */
.bubble strong {
  font-weight: 600;
  color: inherit;
}

.bubble em {
  font-style: italic;
}

.bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 90%;
  font-family: "Courier New", monospace;
}

.bubble .list-item {
  margin-bottom: 8px;
  display: block;
}

.bubble .list-number {
  font-weight: 600;
  color: var(--chat-accent);
}

.bubble hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 8px 0;
}

/* Typing indicator */
.bubble.typing {
  min-width: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Character counter styles */
.char-counter {
  font-size: 11px;
  color: #666;
  text-align: center;
  margin: 0 0 6px 0;
}

/* Input container for counter */
.input-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* keep textarea anchored to bottom */
}

/* Stack counter on top of button */
.button-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Hide tooltip on mobile to avoid clutter */
@media (max-width: 768px) {
  #chat-tooltip {
    display: none;
  }
}
