/* Gorem Chat Widget — sleek dark panel with blue accent */
.chat-widget-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: #2563EB;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.4);
  z-index: 9999;
  transition: transform 0.2s, box-shadow 0.2s;
  touch-action: manipulation;
}

.chat-widget-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(37, 99, 235, 0.5);
}

.chat-widget-fab svg {
  width: 1.5rem;
  height: 1.5rem;
}

.chat-widget-panel {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 24rem;
  max-width: calc(100vw - 3rem);
  height: 34rem;
  max-height: calc(100vh - 6rem);
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-widget-header {
  background: #1e293b;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #334155;
  border-radius: 1rem 1rem 0 0;
  flex-shrink: 0;
}

.chat-widget-header-title {
  color: #3b82f6;
  font-weight: 600;
  font-size: 0.875rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chat-widget-header-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: #64748b;
  font-size: 0.65rem;
  margin-left: 0.5rem;
  padding: 0.125rem 0.375rem;
  background: rgba(59, 130, 246, 0.1);
  border-radius: 0.25rem;
  font-weight: 500;
  letter-spacing: 0.05em;
}

.chat-widget-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-widget-header-btn {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 0.75rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
  transition: color 0.2s, background 0.2s;
  touch-action: manipulation;
}

.chat-widget-header-btn:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.05);
}

.chat-widget-close {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  border-radius: 0.25rem;
  transition: color 0.2s, background 0.2s;
  touch-action: manipulation;
}

.chat-widget-close:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.05);
}

.chat-widget-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.chat-widget-messages::-webkit-scrollbar {
  width: 4px;
}

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

.chat-widget-messages::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 2px;
}

.chat-widget-empty {
  text-align: center;
  color: #94a3b8;
  font-size: 0.875rem;
  padding: 2rem 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chat-widget-empty-sub {
  font-size: 0.75rem;
  margin-top: 0.5rem;
  color: #64748b;
}

.chat-widget-msg {
  display: flex;
}

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

.chat-widget-msg-assistant {
  justify-content: flex-start;
}

.chat-widget-bubble {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  line-height: 1.6;
  word-break: break-word;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chat-widget-bubble-user {
  background: #2563EB;
  color: #fff;
  border-bottom-right-radius: 0.25rem;
  white-space: pre-wrap;
}

.chat-widget-bubble-assistant {
  background: #1e293b;
  color: #e2e8f0;
  border-bottom-left-radius: 0.25rem;
}

/* Markdown content inside assistant bubbles */
.chat-widget-bubble-assistant p { margin: 0 0 0.5em; }
.chat-widget-bubble-assistant p:last-child { margin-bottom: 0; }
.chat-widget-bubble-assistant strong { color: #f1f5f9; font-weight: 600; }
.chat-widget-bubble-assistant em { font-style: italic; }
.chat-widget-bubble-assistant code {
  background: rgba(255,255,255,0.08);
  padding: 0.1em 0.35em;
  border-radius: 0.25rem;
  font-size: 0.8em;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.chat-widget-bubble-assistant ul,
.chat-widget-bubble-assistant ol {
  margin: 0.25em 0;
  padding-left: 1.25em;
}
.chat-widget-bubble-assistant li { margin: 0.15em 0; }
.chat-widget-bubble-assistant a {
  color: #60a5fa;
  text-decoration: underline;
}

.chat-widget-tool-badge {
  display: inline-block;
  background: rgba(59, 130, 246, 0.1);
  color: #3b82f6;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  margin-bottom: 0.375rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chat-widget-response-time {
  display: block;
  text-align: right;
  font-size: 10px;
  color: #94a3b8;
  margin-top: 4px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.chat-widget-typing {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.25rem 0;
}

.chat-widget-typing-dot {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: #64748b;
  animation: chat-bounce 1.2s infinite;
}

.chat-widget-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-widget-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

.chat-widget-error {
  text-align: center;
  color: #ef4444;
  font-size: 0.75rem;
  padding: 0.25rem 0;
}

.chat-widget-form {
  padding: 0.75rem;
  border-top: 1px solid #1e293b;
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-widget-input {
  flex: 1;
  background: #1e293b;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 0.625rem;
  padding: 0.5rem 0.875rem;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.chat-widget-input::placeholder {
  color: #64748b;
}

.chat-widget-input:focus {
  border-color: #3b82f6;
}

.chat-widget-input:disabled {
  opacity: 0.5;
}

.chat-widget-send {
  background: #2563EB;
  color: #fff;
  border: none;
  border-radius: 0.625rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.chat-widget-send:hover {
  background: #1d4ed8;
}

.chat-widget-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* When chat is open on mobile, hide page content so nothing bleeds behind keyboard */
body.chat-widget-open {
  background: #0f172a !important;
}
body.chat-widget-open > nav,
body.chat-widget-open > section,
body.chat-widget-open > footer {
  display: none !important;
}

/* Mobile: full-screen panel, keyboard-safe */
@media (max-width: 500px) {
  .chat-widget-fab {
    bottom: 1rem;
    right: 1rem;
  }

  .chat-widget-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  .chat-widget-header {
    border-radius: 0;
    padding-top: max(0.75rem, env(safe-area-inset-top));
  }

  .chat-widget-form {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
}

/* Also handle landscape phones and small tablets */
@media (max-height: 500px) {
  .chat-widget-panel {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }

  .chat-widget-header {
    border-radius: 0;
  }
}
