* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.container {
  width: 100%;
  max-width: 600px;
}

.chat-box {
  background: white;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  height: 80vh;
  max-height: 800px;
  overflow: hidden;
}

/* Header */
.header {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.header h1 {
  margin: 0;
  font-size: 24px;
}

#user-info {
  margin: 5px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
}

/* Sections */
.section {
  display: none;
  flex: 1;
  overflow: hidden;
}

.section.active {
  display: flex;
  flex-direction: column;
}

/* Login Form */
.login-form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
}

.login-form h2 {
  margin-bottom: 15px;
  color: #333;
  font-size: 20px;
}

.login-form p {
  margin-bottom: 25px;
  color: #666;
}

.login-form input {
  width: 100%;
  max-width: 300px;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 15px;
}

.login-form input:focus {
  outline: none;
  border-color: #6b7280;
  box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.1);
}

.login-form button {
  width: 100%;
  max-width: 300px;
  padding: 12px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.2s;
}

.login-form button:hover {
  transform: translateY(-2px);
}

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message {
  display: flex;
  margin-bottom: 10px;
  animation: slideIn 0.3s ease;
}

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

.bot-msg {
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
  max-width: 80%;
}

.bot-msg .msg-text {
  background: #f0f0f0;
  color: #333;
  padding: 12px 15px;
  border-radius: 8px 8px 0 0;
  width: 100%;
  word-wrap: break-word;
  line-height: 1.6;
}

/* When there's no source section, keep all corners rounded */
.bot-msg .msg-text:last-child {
  border-radius: 8px;
}

/* Markdown styling within bot messages */
.bot-msg .msg-text p {
  margin: 0 0 10px 0;
}

.bot-msg .msg-text p:last-child {
  margin-bottom: 0;
}

.bot-msg .msg-text ul,
.bot-msg .msg-text ol {
  margin: 8px 0;
  padding-left: 20px;
}

.bot-msg .msg-text li {
  margin: 4px 0;
}

.bot-msg .msg-text strong {
  font-weight: 600;
  color: #222;
}

.bot-msg .msg-text code {
  background: #e0e0e0;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 0.9em;
}

.bot-msg .msg-text pre {
  background: #e0e0e0;
  padding: 10px;
  border-radius: 5px;
  overflow-x: auto;
  margin: 10px 0;
}

.bot-msg .msg-text pre code {
  background: none;
  padding: 0;
}

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

.user-msg .msg-text {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  padding: 12px 15px;
  border-radius: 8px;
  max-width: 80%;
  word-wrap: break-word;
}

/* Source Section */
.msg-source-section {
  margin-top: 0;
  padding: 12px 15px;
  padding-top: 8px;
  background: #f0f0f0;
  border-top: 1px solid #d0d0d0;
  border-radius: 0 0 8px 8px;
  width: 100%;
}

.msg-source {
  font-size: 12px;
  color: #666;
  margin-bottom: 8px;
}

.msg-source strong {
  color: #333;
}

/* Document Links */
.msg-link {
  margin-bottom: 8px;
}

.msg-link a {
  display: inline-block;
  background: #6b7280;
  color: white;
  padding: 8px 12px;
  border-radius: 4px;
  text-decoration: none;
  font-size: 12px;
  transition: background 0.2s;
}

.msg-link a:hover {
  background: #4b5563;
}

/* Related Documents */
.msg-docs {
  margin-top: 10px;
  padding: 10px;
  background: #f5f5f5;
  border-left: 3px solid #6b7280;
  border-radius: 4px;
}

.docs-title {
  font-size: 12px;
  font-weight: bold;
  color: #333;
  margin-bottom: 8px;
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-item {
  color: #6b7280;
  text-decoration: none;
  font-size: 12px;
  padding: 4px;
  border-radius: 3px;
  transition: background 0.2s;
}

.doc-item:hover {
  background: #e5e7eb;
  text-decoration: underline;
}

/* Loading Indicator */
.loading {
  display: flex;
  gap: 4px;
  align-items: center;
}

.loading span {
  width: 6px;
  height: 6px;
  background: #6b7280;
  border-radius: 50%;
  animation: bounce 1.4s infinite;
}

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

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

@keyframes bounce {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

/* Input Area */
.input-area {
  display: flex;
  gap: 10px;
  padding: 15px;
  border-top: 1px solid #eee;
  background: #fafafa;
}

#query {
  flex: 1;
  padding: 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}

#query:focus {
  outline: none;
  border-color: #667eea;
}

#send-btn {
  padding: 12px 20px;
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  transition: transform 0.2s;
}

#send-btn:hover {
  transform: translateY(-2px);
}

#send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 10px;
}

.reset-btn,
.logout-btn {
  flex: 1;
  padding: 10px 16px;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
}

.reset-btn {
  background: #4caf50;
}

.reset-btn:hover {
  background: #45a049;
}

.logout-btn {
  background: #ff6b6b;
}

.logout-btn:hover {
  background: #ff5252;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.messages::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
  background: #999;
}

/* Responsive */
@media (max-width: 600px) {
  .chat-box {
    height: 100vh;
    border-radius: 0;
  }

  .bot-msg .msg-text,
  .user-msg .msg-text {
    max-width: 90%;
  }
}
