/* ============================================================
   DocuMind — Global Stylesheet
   ============================================================ */

/* ---------- CSS Custom Properties ---------- */
:root {
  /* Palette — dark mode first */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a28;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-muted: #65657a;

  --accent-1: #e86521;
  --accent-2: #e86521;
  --accent-3: #e86521;
  --gradient: linear-gradient(to right, #e86521 0%, #e86521 100%);
  --gradient-text: linear-gradient(to right, #e86521 0%, #e86521 100%);

  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 60px rgba(232, 101, 33, 0.15);

  --font: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: var(--font);
  border: none;
  outline: none;
  background: none;
}

.hidden {
  display: none !important;
}

/* ---------- Navbar ---------- */
#navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 64px;
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--gradient);
  color: #fff;
}

.brand-name {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav-links {
  display: flex;
  gap: 2rem;
}

.nav-link {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.nav-link:hover {
  color: var(--text-primary);
}

/* ---------- Buttons ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 2rem;
  border-radius: var(--radius-lg);
  background: var(--gradient);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 24px rgba(232, 101, 33, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 32px rgba(232, 101, 33, 0.5);
}

.btn-lg {
  padding: 1rem 2.5rem;
  font-size: 1.1rem;
}

.btn-outline-sm {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-hover);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--transition);
}

.btn-outline-sm:hover {
  border-color: var(--accent-2);
  color: var(--accent-2);
  background: rgba(232, 101, 33, 0.06);
}

.btn-ghost {
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: color var(--transition);
}

.btn-ghost:hover {
  color: var(--text-primary);
}

/* ---------- HERO ---------- */
#hero-section {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 6rem 2rem 4rem;
  text-align: center;
  overflow: hidden;
}

.hero-glow {
  position: absolute;
  width: 600px;
  height: 600px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 101, 33, 0.15), transparent 70%);
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  animation: pulse-glow 6s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.6; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

.hero-content {
  position: relative;
  z-index: 2;
  max-width: 720px;
}

.hero-badge {
  display: inline-block;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  background: rgba(232, 101, 33, 0.1);
  border: 1px solid rgba(232, 101, 33, 0.25);
  color: var(--accent-2);
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  letter-spacing: 0.02em;
}

.hero-content h1 {
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 1.25rem;
}

.gradient-text {
  background: var(--gradient-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1.15rem;
  color: var(--text-secondary);
  max-width: 560px;
  margin: 0 auto 2.5rem;
  line-height: 1.7;
}

/* floating cards */
.hero-visual {
  position: relative;
  margin-top: 3rem;
  width: 100%;
  max-width: 500px;
  height: 200px;
}

.floating-card {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.2rem;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  animation: float 5s ease-in-out infinite;
}

.card-icon {
  font-size: 1.3rem;
}

.card-label {
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.card-1 { top: 10%; left: 5%; animation-delay: 0s; }
.card-2 { top: 5%; right: 5%; animation-delay: 1.2s; }
.card-3 { bottom: 10%; left: 10%; animation-delay: 2.4s; }
.card-4 { bottom: 5%; right: 10%; animation-delay: 0.6s; }

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

/* ---------- FEATURES ---------- */
#features {
  padding: 6rem 2rem;
  max-width: 1100px;
  margin: 0 auto;
}

.section-title {
  text-align: center;
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 3.5rem;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.feature-card {
  padding: 1.8rem;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  transition: all var(--transition);
}

.feature-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
}

.feature-icon {
  font-size: 2rem;
  margin-bottom: 1rem;
}

.feature-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.feature-card p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ---------- HOW IT WORKS ---------- */
#how-it-works {
  padding: 6rem 2rem;
  max-width: 700px;
  margin: 0 auto;
}

.steps-container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.step {
  display: flex;
  gap: 1.2rem;
  align-items: flex-start;
}

.step-number {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
}

.step-content h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.step-content p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.step-connector {
  width: 2px;
  height: 32px;
  margin-left: 19px;
  background: linear-gradient(180deg, var(--accent-1), transparent);
  border-radius: 2px;
}

/* ============================================================
   APP SECTION — Sidebar + Main Area
   ============================================================ */
#app-section {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
}

.app-container {
  display: flex;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
#sidebar {
  width: 260px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  gap: 0.8rem;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid var(--border-color);
  font-weight: 700;
  font-size: 0.95rem;
}

.brand-icon-sm {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--gradient);
  color: #fff;
}

.documents-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 2rem 0;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  border: 1px solid transparent;
  overflow: hidden;
}

.doc-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.doc-item.active {
  background: rgba(232, 101, 33, 0.1);
  border-color: rgba(232, 101, 33, 0.3);
  color: var(--accent-2);
}

.doc-item-icon {
  flex-shrink: 0;
}

.doc-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

/* ---------- Main Area ---------- */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Upload Panel */
#upload-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  width: 100%;
  max-width: 520px;
  padding: 3.5rem 2rem;
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius-xl);
  background: var(--bg-card);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--accent-2);
  background: rgba(232, 101, 33, 0.04);
  box-shadow: var(--shadow-glow);
}

.upload-icon {
  color: var(--text-muted);
  transition: color var(--transition);
}

.upload-zone:hover .upload-icon {
  color: var(--accent-2);
}

.upload-zone h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.upload-zone p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.upload-hint {
  color: var(--text-muted) !important;
  font-size: 0.8rem !important;
}

/* Upload progress */
.upload-progress {
  width: 100%;
  max-width: 520px;
  margin-top: 1.5rem;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.progress-bar {
  height: 6px;
  border-radius: 3px;
  background: var(--bg-tertiary);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  background: var(--gradient);
  transition: width 0.4s ease;
}

/* ---------- Chat Panel ---------- */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.chat-doc-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.chat-doc-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  gap: 0.5rem;
}

.welcome-icon {
  font-size: 2.5rem;
}

.welcome-message h3 {
  font-size: 1.2rem;
  font-weight: 700;
}

.welcome-message p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  max-width: 400px;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 0.75rem;
  max-width: 85%;
  animation: msg-in 0.3s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.message.user .message-avatar {
  background: var(--gradient);
  color: #fff;
}

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.message-content {
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.65;
}

.message.user .message-content {
  background: var(--accent-1);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  color: var(--text-primary);
}

/* Markdown styling inside assistant messages */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
  margin-top: 0.8rem;
  margin-bottom: 0.3rem;
  font-weight: 700;
}

.message.assistant .message-content h1 { font-size: 1.1rem; }
.message.assistant .message-content h2 { font-size: 1rem; }
.message.assistant .message-content h3 { font-size: 0.95rem; }

.message.assistant .message-content p {
  margin-bottom: 0.5rem;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
  margin: 0.3rem 0 0.5rem 1.2rem;
}

.message.assistant .message-content li {
  margin-bottom: 0.2rem;
}

.message.assistant .message-content code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.85em;
}

.message.assistant .message-content pre {
  background: rgba(0, 0, 0, 0.4);
  padding: 0.8rem;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 0.5rem 0;
}

.message.assistant .message-content pre code {
  background: none;
  padding: 0;
}

.message.assistant .message-content strong {
  color: #d4d4e8;
}

/* Sources toggle */
.sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.5rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  background: rgba(232, 101, 33, 0.08);
  color: var(--accent-2);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.sources-toggle:hover {
  background: rgba(232, 101, 33, 0.15);
}

.sources-list {
  display: none;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, 0.25);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.sources-list.open {
  display: block;
}

.source-item {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border-color);
}

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

.source-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: var(--bg-card-hover);
  font-weight: 600;
  margin-right: 0.4rem;
  color: var(--accent-2);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.7rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce-dot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* Chat input */
.chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-tertiary);
  transition: border-color var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(232, 101, 33, 0.08);
}

#chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
}

#chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  opacity: 0.5;
}

.send-btn:not(:disabled) {
  opacity: 1;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.06);
  box-shadow: 0 2px 12px rgba(232, 101, 33, 0.4);
}

.send-btn:disabled {
  cursor: not-allowed;
}

.chat-disclaimer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}


/* ---------- CRAG Pipeline Trace ---------- */
.crag-trace-container {
  margin-bottom: 0.75rem;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.crag-trace-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-2);
  background: rgba(232, 101, 33, 0.05);
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}

.crag-trace-toggle:hover {
  background: rgba(232, 101, 33, 0.1);
}

.crag-trace-toggle .chevron {
  font-size: 0.6rem;
  transition: transform var(--transition);
}

.crag-trace-toggle.active .chevron {
  transform: rotate(180deg);
}

.crag-trace-list {
  display: none;
  list-style: none;
  padding: 0.6rem 0.75rem;
  margin: 0;
  border-top: 1px solid var(--border-color);
}

.crag-trace-list.open {
  display: block;
}

.crag-trace-list li {
  position: relative;
  padding-left: 1.1rem;
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 0.4rem;
}

.crag-trace-list li::before {
  content: "•";
  position: absolute;
  left: 0.25rem;
  color: var(--accent-2);
  font-weight: bold;
}

.crag-trace-list li:last-child {
  margin-bottom: 0;
}

/* Web Search styling */
.search-sources-toggle {
  background: rgba(232, 101, 33, 0.08);
  color: var(--accent-2);
  margin-top: 0.5rem;
}

.search-sources-toggle:hover {
  background: rgba(232, 101, 33, 0.15);
}

.search-badge {
  background: rgba(232, 101, 33, 0.15) !important;
  color: var(--accent-2) !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  #sidebar {
    width: 60px;
    padding: 0.5rem;
  }

  .sidebar-header span,
  .doc-item-name,
  .btn-outline-sm span,
  .sidebar-footer {
    display: none;
  }

  .btn-outline-sm {
    justify-content: center;
    padding: 0.5rem;
  }

  .doc-item {
    justify-content: center;
  }

  .message {
    max-width: 95%;
  }

  .nav-links {
    display: none;
  }
}
