*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22263a;
  --border: #2e3347;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --accent: #6366f1;
  --accent-hover: #5254cc;
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Layout */
.layout { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 900px;
  margin: 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { font-weight: 700; font-size: 18px; letter-spacing: -0.3px; }
.header-stats { display: flex; gap: 8px; }
.stat-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 3px 12px;
}

/* Main */
.main {
  max-width: 900px;
  margin: 32px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 100px;
  padding: 2px 8px;
  min-width: 22px;
  text-align: center;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  outline: none;
}
.drop-zone:hover, .drop-zone:focus { border-color: var(--accent); background: rgba(99,102,241,0.05); }
.drop-zone.dragging { border-color: var(--accent); background: rgba(99,102,241,0.1); }
.drop-zone-icon { font-size: 36px; margin-bottom: 12px; opacity: 0.7; }
.drop-zone-text { font-size: 15px; color: var(--text); margin-bottom: 4px; }
.drop-zone-hint { font-size: 13px; color: var(--text-muted); }
.link { color: var(--accent); text-decoration: underline; }

/* Upload queue */
.upload-queue { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.upload-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}
.upload-item-info { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.upload-name { font-size: 14px; font-weight: 500; }
.upload-status { font-size: 12px; color: var(--text-muted); }
.upload-progress { height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.upload-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0%;
}
.upload-bar.bar-success { background: var(--success); width: 100%; }
.upload-bar.bar-error { background: var(--error); width: 100%; }

/* Search */
.search-form { margin-bottom: 0; }
.search-row { display: flex; gap: 8px; }
.search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }
.select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  outline: none;
  cursor: pointer;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 10px;
  font-size: 16px;
}
.btn-ghost:hover { color: var(--error); background: rgba(239,68,68,0.1); }
.btn-delete { flex-shrink: 0; }

/* Search results */
.search-results { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }
.results-summary { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.result-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
}
.result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.result-rank { font-size: 12px; color: var(--accent); font-weight: 700; }
.result-source { font-size: 13px; font-weight: 600; color: var(--text); }
.result-score { font-size: 11px; color: var(--success); margin-left: auto; }
.result-text {
  font-size: 13px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  max-height: 200px;
  overflow-y: auto;
}

/* Document list */
.document-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  transition: background 0.15s;
}
.doc-item:hover { background: var(--surface-hover); }
.doc-icon { font-size: 22px; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { display: block; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--text-muted); }

/* Misc */
.empty-msg { color: var(--text-muted); font-size: 14px; text-align: center; padding: 20px 0; }
.error-msg { color: var(--error); font-size: 14px; }
.loading { color: var(--text-muted); font-size: 14px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  font-size: 14px;
  max-width: 360px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 200;
}
.toast-show { opacity: 1; transform: translateY(0); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--error); }
.toast-info { border-left: 3px solid var(--accent); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

@media (max-width: 640px) {
  .main { padding: 0 16px; margin: 16px auto; }
  .search-row { flex-wrap: wrap; }
  .search-input { min-width: 0; }
  .header-stats { display: none; }
}

/* ---- Navigation ---- */
.nav-tabs { display: flex; gap: 4px; }
.nav-tab {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}
.nav-tab:hover { color: var(--text); background: var(--surface-hover); }
.nav-tab-active { color: var(--text); background: var(--bg); }

/* ---- Forms (Sources) ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 20px; }
.form-label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); opacity: 0.6; }
.form-textarea { resize: vertical; min-height: 60px; font-family: 'Cascadia Code', 'Fira Code', monospace, inherit; font-size: 13px; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; }
.text-muted { color: var(--text-muted); font-weight: 400; }

/* ---- Auth Section ---- */
.auth-section { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 8px; }
.auth-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.auth-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 6px 14px;
  transition: all 0.15s;
}
.auth-tab:hover { border-color: var(--accent); color: var(--text); }
.auth-tab-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.auth-panel { display: flex; flex-direction: column; gap: 12px; }
.auth-hint { font-size: 12px; color: var(--text-muted); margin-top: -4px; }
.auth-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.auth-help summary { cursor: pointer; color: var(--accent); }
.auth-steps { margin: 8px 0 0 20px; display: flex; flex-direction: column; gap: 4px; }
.auth-steps code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.auth-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.auth-result { font-size: 13px; }
.auth-pass { color: var(--success); }
.auth-fail { color: var(--error); }

/* ---- Buttons ---- */
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  padding: 8px 16px;
  transition: all 0.15s;
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-sm { padding: 5px 12px; font-size: 12px; }

/* ---- Source Cards ---- */
.source-list { display: flex; flex-direction: column; gap: 10px; }
.source-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: background 0.15s;
}
.source-item:hover { background: var(--surface-hover); }
.source-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.source-icon { font-size: 24px; flex-shrink: 0; }
.source-info { flex: 1; min-width: 0; }
.source-name { display: block; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-meta { font-size: 12px; color: var(--text-muted); }
.source-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.source-detail { font-size: 12px; color: var(--text-muted); }
.source-actions { display: flex; gap: 6px; align-items: center; }
.source-progress { margin: 8px 0; display: flex; align-items: center; gap: 10px; }
.progress-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.auth-ok { color: var(--success); }
.auth-expired { color: var(--error); }

/* ---- Status Badges ---- */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-ok { background: rgba(34,197,94,0.15); color: var(--success); }
.status-sync { background: rgba(99,102,241,0.15); color: var(--accent); }
.status-warn { background: rgba(245,158,11,0.15); color: var(--warning); }
.status-error { background: rgba(239,68,68,0.15); color: var(--error); }
.status-idle { background: rgba(136,146,164,0.15); color: var(--text-muted); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { font-size: 18px; }

/* ---- Pulse Animation ---- */
.bar-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .source-footer { flex-direction: column; align-items: flex-start; }
  .nav-tabs { gap: 2px; }
}
