/* --- System Design & Color Tokens (Meta AI Light Theme) --- */
:root {
  --bg-primary: #f6f5f2; /* Light cream/beige warm background */
  --bg-secondary: #ffffff;
  --panel-bg: #ffffff;
  --border-color: #e4e6eb;
  
  --text-primary: #0f1419;
  --text-secondary: #536471;
  --text-muted: #8e9ca7;
  
  --bubble-user: #e3effd; /* Soft light blue/indigo pill */
  --bubble-user-text: #0f1419;
  --bubble-bot: #ffffff;
  --bubble-bot-border: #e4e6eb;
  
  --success-color: #0084ff;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  
  --font-family-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-family-title: 'Plus Jakarta Sans', var(--font-family-sans);
}

/* --- Base Resets & Layout --- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--bg-primary);
  /* Light pattern texture or warm soft background gradient */
  background-image: 
    radial-gradient(at 0% 0%, rgba(224, 242, 254, 0.5) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(245, 243, 255, 0.4) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

/* --- Main Application Container --- */
.app-container {
  width: 100%;
  max-width: 540px; /* Slimmer layout to match mobile interface screenshot */
  height: 100vh;
  height: 100dvh;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* --- Chat Window --- */
.chat-window {
  width: 100%;
  height: 100%;
  background: var(--panel-bg);
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

@media (max-width: 540px) {
  .chat-window {
    border-left: none;
    border-right: none;
  }
}

/* --- Chat Header --- */
.chat-header {
  padding: 14px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.bot-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-container {
  position: relative;
  width: 38px;
  height: 38px;
}

/* Verified Badge like Meta AI */
.verified-badge {
  color: #1d9bf0;
  font-size: 14px;
  margin-left: 3px;
  user-select: none;
}

.status-indicator {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.status-indicator.active {
  background-color: #00ba7c; /* Meta green */
}

.bot-details h2 {
  font-family: var(--font-family-title);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.bot-details p {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.header-actions button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-actions button:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-primary);
}

/* --- Chat Body Area --- */
.chat-body {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  background-color: #fbfcfa; /* Clean off-white background matching Meta AI screenshot */
}

/* --- Welcome / Onboarding Screen --- */
.welcome-container {
  max-width: 100%;
  margin: auto 0;
  text-align: center;
  animation: fadeIn 0.5s ease;
  padding: 20px 10px;
}

/* Meta AI Ring - Animated CSS Conic Gradient */
.meta-ring-container {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 20px;
}

.meta-ring-outer {
  position: relative;
  width: 82px;
  height: 82px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.meta-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #00c6ff, #0072ff, #f355da, #fe0979, #00c6ff);
  animation: spin 5s linear infinite;
  display: flex;
  align-items: center;
  justify-content: center;
}

.meta-ring::after {
  content: '';
  position: absolute;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: #fbfcfa; /* Must match chat-body background */
}

.meta-ring-glow {
  position: absolute;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #00c6ff, #0072ff, #f355da, #fe0979, #00c6ff);
  filter: blur(8px);
  opacity: 0.35;
  animation: spin 5s linear infinite;
}

@keyframes spin {
  100% { transform: rotate(360deg); }
}

.welcome-container h1 {
  font-family: var(--font-family-title);
  font-size: 21px;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.welcome-container .subtitle {
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.5;
  margin-bottom: 30px;
  max-width: 380px;
  margin-left: auto;
  margin-right: auto;
}

/* Horizontal or grid suggestions matching Meta AI screenshot */
.suggestions-container {
  text-align: left;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

/* Hide scrollbar for Chrome, Safari and Opera */
.suggestions-container::-webkit-scrollbar {
  display: none;
}

.suggestions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 400px;
  margin: 0 auto;
}

.suggestion-tag {
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 11px 16px;
  border-radius: 16px;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.suggestion-tag:hover {
  background: #f4f6f9;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

/* --- Bot Avatar Ring Mini (For header and bubbles) --- */
.bot-avatar-ring {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, #00c6ff, #0072ff, #f355da, #fe0979, #00c6ff);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  animation: spin 8s linear infinite;
}

.bot-avatar-ring::after {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #ffffff; /* matches header bg */
}

.bot-avatar-ring.mini {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.bot-avatar-ring.mini::after {
  width: 22px;
  height: 22px;
  background: #fbfcfa; /* matches chat body background */
}

/* --- Message Bubbles --- */
.message-row {
  display: flex;
  width: 100%;
  margin-bottom: 2px;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.bot {
  justify-content: flex-start;
  gap: 10px;
}

.message-bubble {
  max-width: 82%;
  padding: 12px 16px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.message-row.user .message-bubble {
  background: var(--bubble-user);
  border-radius: 18px 18px 4px 18px;
  color: var(--bubble-user-text);
}

.message-row.bot .message-bubble {
  background: var(--bubble-bot);
  border: 1px solid var(--bubble-bot-border);
  border-radius: 4px 18px 18px 18px;
  color: var(--text-primary);
}

/* --- Text Formatting inside Bubbles --- */
.message-bubble p {
  margin-bottom: 6px;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul, .message-bubble ol {
  margin-left: 18px;
  margin-bottom: 6px;
}

.message-bubble li {
  margin-bottom: 3px;
}

.message-bubble code {
  background: #f1f3f5;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
  color: #0f1419;
}

.message-bubble strong {
  font-weight: 600;
  color: #0f1419;
}

/* --- Vector Analysis Accordion --- */
.source-info-container {
  margin-top: 10px;
  border-top: 1px solid #f1f5f9;
  padding-top: 8px;
}

.source-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  opacity: 0.85;
}

.source-toggle-btn:hover {
  opacity: 1;
}

.source-content {
  display: none;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-secondary);
  background: #f8f9fa;
  border: 1px solid #e4e6eb;
  border-radius: 10px;
  padding: 8px 12px;
}

.source-content.show {
  display: block;
}

.source-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e4e6eb;
}

.source-item:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.source-match {
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 4px;
}

.match-high {
  background: #e6f7ed;
  color: #00ba7c;
}

.match-mid {
  background: #fef3c7;
  color: #d97706;
}

.match-fallback {
  background: #fee2e2;
  color: #ef4444;
}

/* --- Typing Indicator --- */
.typing-indicator-wrapper {
  display: none;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.typing-bubble {
  background: var(--bubble-bot);
  border: 1px solid var(--bubble-bot-border);
  padding: 12px 16px;
  border-radius: 4px 18px 18px 18px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--text-secondary);
  border-radius: 50%;
  opacity: 0.5;
  animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* --- Scroll to Bottom --- */
.scroll-bottom-btn {
  position: absolute;
  bottom: 84px;
  right: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  z-index: 5;
  transition: all 0.2s ease;
}

.scroll-bottom-btn:hover {
  background: #f8f9fa;
  color: var(--text-primary);
  transform: translateY(-1px);
}

.scroll-bottom-btn.hidden {
  opacity: 0;
  transform: translateY(10px) scale(0.8);
  pointer-events: none;
}

/* --- Chat Input Footer --- */
.chat-footer {
  padding: 12px 16px 16px 16px;
  background: #ffffff;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-input-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-wrapper {
  flex: 1;
  background: #f0f2f5; /* Meta AI input background style */
  border: 1px solid transparent;
  border-radius: 20px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
}

.input-wrapper:focus-within {
  background: #ffffff;
  border-color: #cbd5e1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}

.input-wrapper textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-family-sans);
  font-size: 14.5px;
  line-height: 1.4;
  resize: none;
  max-height: 90px;
  padding: 4px 0;
}

.input-wrapper textarea::placeholder {
  color: #7d8b99;
}

.chat-input-form button {
  background: transparent;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #0084ff; /* Meta blue send icon */
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-input-form button:hover {
  background: #f0f2f5;
  transform: scale(1.05);
}

.app-meta {
  display: flex;
  justify-content: center;
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.1px;
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* --- Admin Dashboard Styles --- */
.admin-body {
  background-color: #1a1b26; /* Dark theme for admin */
  color: #c0caf5;
  height: auto;
  min-height: 100vh;
  display: block;
  overflow-y: auto;
}

.admin-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 40px 20px;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
  border-bottom: 1px solid #292e42;
  padding-bottom: 20px;
}

.admin-header h1 {
  color: #a9b1d6;
  font-family: var(--font-family-title);
  font-size: 24px;
  margin-bottom: 5px;
}

.admin-header p {
  color: #565f89;
  font-size: 14px;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 5px;
  color: #7aa2f7;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.8;
}

.admin-main {
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.admin-card {
  background: #24283b;
  border-radius: 12px;
  padding: 25px;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  border: 1px solid #292e42;
}

.admin-card h2 {
  color: #bb9af7;
  font-size: 18px;
  margin-bottom: 20px;
  font-family: var(--font-family-title);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: #a9b1d6;
  font-size: 14px;
  font-weight: 500;
}

.form-group textarea {
  width: 100%;
  background: #1f2335;
  border: 1px solid #414868;
  border-radius: 8px;
  padding: 12px 16px;
  color: #c0caf5;
  font-family: var(--font-family-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.2s;
}

.form-group textarea:focus {
  outline: none;
  border-color: #7aa2f7;
}

.help-text {
  font-size: 12px;
  color: #565f89;
  margin-top: 8px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-group label {
  margin-bottom: 0;
  cursor: pointer;
}

.btn-primary {
  background: #7aa2f7;
  color: #1a1b26;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover {
  background: #8caaee;
  transform: translateY(-1px);
}

.status-message {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
  transition: opacity 0.3s;
}

.status-message.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.status-message.success {
  background: rgba(158, 206, 106, 0.1);
  color: #9ece6a;
  border: 1px solid #9ece6a;
}

.status-message.error {
  background: rgba(247, 118, 142, 0.1);
  color: #f7768e;
  border: 1px solid #f7768e;
}

/* --- Login Overlay --- */
.login-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(26, 27, 38, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.login-box {
  background: #24283b;
  padding: 30px;
  border-radius: 12px;
  border: 1px solid #292e42;
  width: 100%;
  max-width: 350px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  text-align: center;
}

.login-box h2 {
  color: #bb9af7;
  font-family: var(--font-family-title);
  margin-bottom: 10px;
}

.login-box p {
  color: #a9b1d6;
  font-size: 13px;
  margin-bottom: 20px;
}

.login-box input {
  width: 100%;
  background: #1f2335;
  border: 1px solid #414868;
  border-radius: 8px;
  padding: 12px;
  color: #c0caf5;
  font-family: var(--font-family-sans);
  font-size: 14px;
}

.login-box input:focus {
  outline: none;
  border-color: #7aa2f7;
}
