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

:root {
  --primary: #0a58ca;
  --primary-light: #1a73e8;
  --primary-bg: #e8f0fe;
  --primary-dark: #0a2a5a;
  --bg: #f5f8ff;
  --card-bg: #ffffff;
  --text: #1a2a4a;
  --text-secondary: #4a5a7a;
  --text-muted: #8a9bb5;
  --border: #e4ecf8;
  --border-light: #c8d8f0;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(26, 115, 232, 0.04);
  --shadow-md: 0 4px 16px rgba(26, 115, 232, 0.08);
  --shadow-lg: 0 8px 40px rgba(26, 115, 232, 0.10);
  --transition: all 0.2s ease;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  background: linear-gradient(135deg, #e8f0fe 0%, #d4e4fc 100%);
  border-bottom: 1px solid rgba(26, 115, 232, 0.08);
  flex-shrink: 0;
}

.topbar-inner {
  display: flex;
  align-items: center;
  padding: 12px 0 12px 4px;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
  width: 100%;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search-bar {
  flex: 1;
  position: relative;
  max-width: 560px;
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
}

.search-bar input {
  width: 100%;
  padding: 9px 16px 9px 38px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: white;
  color: var(--text);
  outline: none;
  transition: var(--transition);
  box-shadow: 0 1px 4px rgba(0,0,0,0.02);
}

.search-bar input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Buttons ── */
.btn {
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 2px 8px rgba(26, 115, 232, 0.25);
}

.btn-primary:hover {
  box-shadow: 0 4px 12px rgba(26, 115, 232, 0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: white;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--primary-bg);
  border-color: var(--primary-light);
}

.btn-danger {
  background: white;
  border: 1px solid #f0c8c8;
  color: #c62828;
}

.btn-danger:hover {
  background: #fce4ec;
}

/* ── Main Layout ── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 230px;
  background: white;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  overflow-y: auto;
  padding: 0;
}

.sidebar-section {
  padding: 16px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  font-size: 0.7rem;
  color: #6a8ab0;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 600;
  margin-bottom: 10px;
}

/* Category Tree */
.category-tree {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.category-item {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary);
  gap: 8px;
  transition: var(--transition);
}

.category-item:hover {
  background: #f0f6ff;
}

.category-item.active {
  background: linear-gradient(135deg, var(--primary-bg), #dce8fc);
  color: var(--primary);
  font-weight: 600;
}

.category-item .cat-icon {
  font-size: 0.9rem;
}

.category-item .cat-name {
  flex: 1;
}

.category-item .cat-count {
  background: var(--primary);
  color: white;
  border-radius: 10px;
  padding: 0 8px;
  font-size: 0.7rem;
  min-width: 20px;
  text-align: center;
}

/* Source Filters */
.source-filters {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: var(--transition);
}

.filter-item .filter-icon {
  display: inline-block;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.filter-item:hover {
  background: #f0f6ff;
}

.filter-item input[type="radio"] {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
}

/* Tag Cloud */
.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-cloud .tag {
  background: var(--primary-bg);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.tag-cloud .tag:hover {
  border-color: var(--border-light);
  background: #dce8fc;
}

.tag-cloud .tag.active {
  border-color: var(--primary);
  font-weight: 600;
}

.tag-placeholder {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ── Content Area ── */
.content {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  background: #f8fbff;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Filter Chips */
.filter-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  min-height: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  background: white;
  color: var(--text-secondary);
  border: 1px solid #dce4f0;
  transition: var(--transition);
}

.chip.active {
  background: var(--primary-bg);
  color: var(--primary);
  font-weight: 500;
  border-color: var(--border-light);
}

.chip .chip-close {
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0.6;
}

.chip .chip-close:hover {
  opacity: 1;
}

/* Loading */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Document Cards */
.doc-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.doc-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.doc-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-light);
  transform: translateY(-1px);
}

.doc-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.doc-type-badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.doc-type-badge.local_doc {
  background: #e3f0ff;
  color: var(--primary);
}

.doc-type-badge.web {
  background: #fce8ec;
  color: #c62828;
}

.doc-type-badge.my_output {
  background: #e0f2e0;
  color: #2e7d32;
}

.doc-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.4;
}

.doc-card-summary {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 10px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.doc-card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.doc-card-tags .tag {
  background: var(--primary-bg);
  color: var(--primary);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
}

.doc-card-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  margin-top: 24px;
  font-size: 0.85rem;
}

.pagination .page-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  transition: var(--transition);
  font-size: 0.85rem;
}

.pagination .page-btn:hover {
  background: var(--primary-bg);
}

.pagination .page-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(26, 115, 232, 0.2);
}

.pagination .page-btn.disabled {
  color: #c0d0e8;
  cursor: default;
}

.pagination .page-info {
  margin-left: 20px;
  color: #6a8ab0;
  font-size: 0.8rem;
}

/* ── Detail View ── */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.detail-back {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 500;
  background: none;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.detail-back:hover {
  background: var(--primary-bg);
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.detail-title-area {
  margin-bottom: 20px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.detail-meta .meta-divider {
  color: #c0d0e8;
}

.detail-meta .meta-path {
  color: #6a8ab0;
  font-size: 0.75rem;
}

.detail-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.detail-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  align-items: center;
}

.detail-tags .tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary-bg);
  color: var(--primary);
  padding: 4px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--border-light);
}

.detail-tags .tag .tag-del {
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0.5;
}

.detail-tags .tag .tag-del:hover {
  opacity: 1;
}

.detail-tags .tag-add-btn {
  background: transparent;
  border: 1px dashed #b0c4dd;
  border-radius: 20px;
  padding: 4px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
}

.detail-tags .tag-add-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* AI Summary */
.detail-ai-summary {
  background: linear-gradient(135deg, #e8f4ff, #dcecff);
  border: 1px solid #c0d8f0;
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 24px;
}

.detail-ai-summary .summary-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.detail-ai-summary .summary-icon {
  background: var(--primary);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
}

.detail-ai-summary .summary-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
}

.detail-ai-summary .summary-source {
  font-size: 0.7rem;
  color: #6a8ab0;
}

.detail-ai-summary .summary-text {
  font-size: 0.9rem;
  line-height: 1.7;
  color: #2a3a5a;
}

.detail-ai-summary .summary-keywords {
  margin-top: 10px;
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
  color: #4a7aaa;
}

/* Full Text Preview */
.detail-fulltext {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: white;
}

.detail-fulltext-header {
  background: #f5f8ff;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.detail-fulltext-body {
  padding: 18px;
  font-size: 0.85rem;
  line-height: 1.8;
  color: #3a4a6a;
  max-height: 400px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-fulltext-body .empty-text {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 0;
}

.detail-fulltext-body .fulltext-content {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Related */
.detail-related {
  margin-top: 24px;
}

.detail-related-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.detail-related-title span {
  color: var(--primary);
}

.detail-related-list {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
}

.related-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  flex: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.related-card:hover {
  box-shadow: var(--shadow-md);
}

.related-card-title {
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 4px;
}

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

/* ── Status Bar ── */
.statusbar {
  display: flex;
  justify-content: space-between;
  padding: 10px 24px;
  background: linear-gradient(135deg, #e8f0fe, #dce8fc);
  border-top: 1px solid rgba(26, 115, 232, 0.08);
  font-size: 0.75rem;
  color: #4a7aaa;
  flex-shrink: 0;
}

.status-ok {
  color: #2e7d32;
  font-weight: 500;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  width: 520px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px 24px;
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.tab-btn {
  padding: 10px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  font-weight: 500;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-btn:hover {
  color: var(--text-secondary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, 0.12);
}

/* Drop Zone */
.drop-zone {
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  background: #fafcff;
}

.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-bg);
}

.drop-icon {
  font-size: 2.5rem;
  margin-bottom: 10px;
}

.drop-text {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.drop-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Upload Progress */
.upload-progress {
  margin-top: 16px;
}

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

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 3px;
  transition: width 0.3s;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.upload-result {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.upload-result.success {
  background: #e0f2e0;
  color: #2e7d32;
  border: 1px solid #c0e0c0;
}

.upload-result.error {
  background: #fce4ec;
  color: #c62828;
  border: 1px solid #f0c8d0;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .topbar-inner {
    padding: 10px 16px;
    gap: 10px;
  }

  .content {
    padding: 16px;
  }

  .detail-related-list {
    flex-direction: column;
  }

  .modal {
    max-width: 95vw;
  }
}

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

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

::-webkit-scrollbar-thumb {
  background: #c0d0e8;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #a0b8d8;
}

/* ── Tag Input ── */
.tag-input-wrapper {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px dashed #b0c4dd;
  border-radius: 20px;
  padding: 3px 14px;
}

.tag-input-wrapper input {
  border: none;
  outline: none;
  font-size: 0.8rem;
  color: var(--text);
  background: transparent;
  width: 80px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state .empty-text {
  font-size: 1rem;
  margin-bottom: 8px;
}

.empty-state .empty-hint {
  font-size: 0.85rem;
}
