* {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

#chat-toggle {
  position: fixed;
  bottom: 80px;
  right: 80px;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, rgba(254, 201, 185, 1) 0%, rgba(225, 95, 72, 1) 100%);
  color: #fff;
  font-size: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483647;
  box-shadow: 0 8px 32px rgba(225, 95, 72, 0.4), 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 12px 40px rgba(225, 95, 72, 0.5), 0 4px 12px rgba(0,0,0,0.15);
}

#speech-bubble {
  position: fixed;
  bottom: 88px;
  right: 160px;
  background: #fff;
  color: #333;
  padding: 12px 16px;
  border-radius: 20px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 15px;
  white-space: nowrap;
  z-index: 2147483646;
  animation: breathe 2s ease-in-out infinite;
}

#speech-bubble::after {
  content: '';
  position: absolute;
  right: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid #fff;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
}

@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

#chat-widget {
  position: fixed;
  bottom: 160px;
  right: 80px;
  width: 500px; 
  height: 740px; 
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15), 0 0 1px rgba(0,0,0,0.1);
  display: none;
  flex-direction: column;
  z-index: 2147483647;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

@media (max-width: 768px) {
  :root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
  }

  /* Floating button adjustments */
  #chat-toggle {
    bottom: calc(16px + var(--safe-bottom));
    right: calc(16px + var(--safe-right));
    width: 56px;
    height: 56px;
    font-size: 24px;
  }

  #speech-bubble {
    bottom: calc(22px + var(--safe-bottom));
    right: calc(84px + var(--safe-right));
    font-size: 13px;
    padding: 10px 14px;
    max-width: 60vw;
    white-space: normal;
    line-height: 1.3;
  }

  /* TRUE FULLSCREEN: Fill entire viewport including areas behind browser chrome */
  #chat-widget {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100vw;
    height: var(--app-height, 100vh);
    max-height: none;
    border-radius: 0;
    margin: 0;
    padding: 0; /* individual areas (header/input) use safe-area padding */
    /* DON'T set display here - let base style control visibility */
    flex-direction: column;
    z-index: 2147483647;
  }

  /* Header */
  #chat-header {
    padding: 14px 16px;
    padding-top: calc(14px + var(--safe-top));
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  /* Chat messages area */
  #chat-messages {
    flex: 1;
    padding: 16px;
    font-size: 13px;
    gap: 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Chat input */
  #chat-input {
    display: flex;
    padding: 12px 14px;
    padding-bottom: calc(12px + var(--safe-bottom));
    gap: 10px;
    background: #ffffff;
    align-items: center;
  }

  #chat-input input {
    flex: 1;
    font-size: 14px; /* slightly reduced on mobile to improve fit */
    padding: 12px 14px;
    border-radius: 12px;
    border: 2px solid #f0f0f0;
    background: #fafafa;
    outline: none;
  }

  #chat-input button {
    width: 44px;
    height: 44px;
    font-size: 18px;
  }

  /* Messages max width */
  .message {
    max-width: 92%;
    padding: 10px 12px;
    font-size: 13px;
  }
}


#chat-header {
  padding: 20px 24px;
  background: linear-gradient(135deg, rgba(254, 201, 185, 1) 0%, rgba(225, 95, 72, 1) 100%);
  color: white;
  font-weight: 600;
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

#chat-close {
  cursor: pointer;
  font-size: 24px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

#chat-close:hover {
  background: rgba(255,255,255,0.2);
}

#chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(to bottom, #fafafa 0%, #ffffff 100%);
}

/* Custom scrollbar */
#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: #d0d0d0;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #b0b0b0;
}

.message { 
  margin-bottom: 0;
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 85%;
  width: fit-content;
  word-wrap: break-word;
  line-height: 1.5;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.user { 
  background: linear-gradient(135deg, rgb(249, 153, 124) 0%, rgba(225, 95, 72, 1) 100%);
  color: #ffffff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  text-shadow: 0 1px 0 rgba(0,0,0,0.2); /* subtle lift to improve legibility */
  padding: 12px 16px;
}

.assistant { 
  background: #f5f5f5;
  color: #2d2d2d;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

/* Markdown styling for assistant messages */
.assistant h1, .assistant h2, .assistant h3 {
  margin: 12px 0 8px 0;
  font-size: 1.1em;
  font-weight: 600;
  color: #1a1a1a;
}

.assistant p {
  margin: 8px 0;
  line-height: 1.6;
}

.assistant ul, .assistant ol {
  margin: 8px 0;
  padding-left: 24px;
}

.assistant li {
  margin: 4px 0;
}

.assistant code {
  background: #e8e8e8;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
  font-size: 0.9em;
}

.assistant pre {
  background: #2d2d2d;
  color: #f5f5f5;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.assistant pre code {
  background: none;
  padding: 0;
  color: #f5f5f5;
}

.assistant strong {
  font-weight: 600;
}

.assistant em {
  font-style: italic;
}

.assistant a {
  color: rgba(225, 95, 72, 1);
  text-decoration: none;
  border-bottom: 1px solid rgba(225, 95, 72, 1);
  transition: opacity 0.2s;
}

.assistant a:hover {
  opacity: 0.7;
}

#chat-input {
  display: flex;
  padding: 16px 20px;
  background: #ffffff;
  border-top: 1px solid #f0f0f0;
  gap: 12px;
  align-items: center;
}

#chat-input input {
  flex: 1;
  border: 2px solid #f0f0f0;
  padding: 12px 16px;
  outline: none;
  border-radius: 12px;
  font-size: 15px;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafafa;
}

#chat-input input:focus {
  border-color: rgba(225, 95, 72, 1);
  box-shadow: 0 0 0 3px rgba(225, 95, 72, 0.1);
  background: #ffffff;
}

#chat-input button {
  background: linear-gradient(135deg, rgba(254, 201, 185, 1) 0%, rgba(225, 95, 72, 1) 100%);
  color: white;
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  border-radius: 12px;
  font-size: 20px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(225, 95, 72, 0.3);
}

#chat-input button:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(225, 95, 72, 0.4);
}

#chat-input button:active:not(:disabled) {
  transform: scale(0.95);
}

#chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

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

/* Improve touch targets on all sizes */
#chat-close, #send-btn, #chat-toggle {
  touch-action: manipulation;
}

/* Dynamic viewport height is applied in the mobile #chat-widget above */
