/* ─────────────────────────────────────────────────────────
   DocuMind AI — Main Stylesheet
   Theme: Clean, modern, light — inspired by Notion + Linear
   ───────────────────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ───────────────────────────────────────── */
:root {
  --white:       #ffffff;
  --bg:          #f7f8fa;
  --bg-card:     #ffffff;
  --bg-hover:    #f0f2f5;
  --border:      #e2e5ea;
  --border-dark: #c8cdd5;

  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;

  --blue:        #2563eb;
  --blue-light:  #eff6ff;
  --blue-border: #bfdbfe;
  --green:       #16a34a;
  --green-light: #f0fdf4;
  --red:         #dc2626;
  --red-light:   #fef2f2;
  --amber:       #d97706;
  --amber-light: #fffbeb;
  --purple:      #7c3aed;
  --purple-light:#f5f3ff;

  --font-body: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
}

/* ── Reset ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Layout ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 60px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  grid-area: header;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.logo-icon {
  width: 32px;
  height: 32px;
  background: var(--blue);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.logo-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}
.logo-tag {
  font-size: 11px;
  background: var(--blue-light);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid var(--blue-border);
}
.header-spacer { flex: 1; }
.api-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ── Upload Area ─────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--border-dark);
  border-radius: var(--radius-lg);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--bg);
  position: relative;
}
.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--blue);
  background: var(--blue-light);
}
.upload-icon {
  font-size: 28px;
  margin-bottom: 8px;
  display: block;
}
.upload-text {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.upload-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.upload-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.upload-progress {
  display: none;
  margin-top: 12px;
}
.progress-bar-wrap {
  background: var(--border);
  border-radius: 4px;
  height: 4px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--blue);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 4px;
}
.progress-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ── Document List ───────────────────────────────────────── */
.doc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.doc-item:hover { background: var(--bg-hover); border-color: var(--border-dark); }
.doc-item.selected {
  background: var(--blue-light);
  border-color: var(--blue-border);
}
.doc-icon {
  width: 32px;
  height: 32px;
  background: var(--red-light);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.doc-info { flex: 1; overflow: hidden; }
.doc-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.doc-delete {
  width: 24px;
  height: 24px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  opacity: 0;
  transition: opacity 0.15s;
}
.doc-item:hover .doc-delete { opacity: 1; }
.doc-delete:hover { background: var(--red-light); color: var(--red); }
.empty-docs {
  text-align: center;
  padding: 20px 10px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ── Main Chat Area ──────────────────────────────────────── */
.main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 60px);
}
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Welcome Screen ──────────────────────────────────────── */
.welcome {
  margin: auto;
  text-align: center;
  max-width: 520px;
  padding: 40px 20px;
}
.welcome-icon {
  font-size: 52px;
  margin-bottom: 16px;
  display: block;
}
.welcome h2 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  letter-spacing: -0.4px;
}
.welcome p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 28px;
}
.welcome-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}
.welcome-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.step-num {
  width: 24px;
  height: 24px;
  background: var(--blue);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 1px;
}
.step-text { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.step-text strong { color: var(--text-primary); }

/* ── Messages ────────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 820px;
  animation: fadeUp 0.25s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.message.user { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.msg-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.msg-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.7;
  max-width: 100%;
}
.message.user .msg-bubble {
  background: var(--blue);
  color: white;
  border-bottom-right-radius: 4px;
}
.message.assistant .msg-bubble {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

/* ── Answer Metadata ─────────────────────────────────────── */
.answer-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.meta-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-green  { background: var(--green-light);  color: var(--green);  border-color: #bbf7d0; }
.badge-amber  { background: var(--amber-light);  color: var(--amber);  border-color: #fde68a; }
.badge-red    { background: var(--red-light);    color: var(--red);    border-color: #fecaca; }
.badge-blue   { background: var(--blue-light);   color: var(--blue);   border-color: var(--blue-border); }
.badge-purple { background: var(--purple-light); color: var(--purple); border-color: #ddd6fe; }
.badge-gray   { background: var(--bg);           color: var(--text-secondary); border-color: var(--border); }

/* ── Sources Panel ───────────────────────────────────────── */
.sources-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
}
.sources-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}
.sources-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sources-toggle { font-size: 12px; color: var(--text-muted); transition: transform 0.2s; }
.sources-toggle.open { transform: rotate(180deg); }
.sources-list {
  display: none;
  flex-direction: column;
  divide-y: var(--border);
}
.sources-list.open { display: flex; }
.source-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.source-item:last-child { border-bottom: none; }
.source-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.source-file {
  font-weight: 500;
  color: var(--blue);
  font-size: 12px;
}
.source-page {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.source-sim {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-left: auto;
}
.source-text {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.6;
  font-style: italic;
  border-left: 3px solid var(--border-dark);
  padding-left: 10px;
}

/* ── Typing Indicator ────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

/* ── Input Bar ───────────────────────────────────────────── */
.input-bar {
  padding: 16px 28px 20px;
  background: var(--white);
  border-top: 1px solid var(--border);
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg);
  border: 1.5px solid var(--border-dark);
  border-radius: var(--radius-xl);
  padding: 10px 14px;
  transition: border-color 0.2s;
}
.input-wrap:focus-within { border-color: var(--blue); }
.query-input {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  min-height: 22px;
  line-height: 1.5;
}
.query-input::placeholder { color: var(--text-muted); }
.send-btn {
  width: 36px;
  height: 36px;
  background: var(--blue);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  font-size: 15px;
  color: white;
}
.send-btn:hover { background: #1d4ed8; transform: scale(1.05); }
.send-btn:disabled { background: var(--border-dark); cursor: not-allowed; transform: none; }
.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
}
.input-doc-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 6px 0;
}
.doc-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--blue-light);
  border: 1px solid var(--blue-border);
  border-radius: 20px;
  font-size: 12px;
  color: var(--blue);
  font-weight: 500;
}

/* ── Toast Notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  min-width: 280px;
  max-width: 380px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red);   }
.toast.info    { border-left: 3px solid var(--blue);  }
.toast-icon { font-size: 16px; }
.toast-msg  { flex: 1; color: var(--text-primary); line-height: 1.4; }

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }
.spin {
  animation: spin 1s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Rendered markdown in answers ─────────────────────────────── */
.md-body { word-wrap: break-word; line-height: 1.6; }
.md-body p { margin: 0 0 8px; }
.md-body ul, .md-body ol { margin: 4px 0 10px; padding-left: 22px; }
.md-body li { margin: 2px 0; }
.md-body code { background: rgba(100,116,139,.15); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.md-body .cite { color: #2563eb; font-size: .82em; font-weight: 600; white-space: nowrap; }
.md-body .md-table { overflow-x: auto; margin: 6px 0 10px; }
.md-body table { border-collapse: collapse; font-size: .92em; }
.md-body th, .md-body td { border: 1px solid #d5dbe5; padding: 5px 9px; text-align: left; vertical-align: top; }
.md-body th { background: rgba(100,116,139,.12); }
