/* ============================================================
   FRONTIERS Knowledge — main stylesheet
   Plain CSS, no framework. System font stack throughout.
   ============================================================ */

/* --- Reset / base ------------------------------------------ */

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 0.9375rem;
  color: #1a1a1a;
  background: #f5f5f4;
  line-height: 1.5;
}

a {
  color: #4f46e5;
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  margin: 0 0 0.5rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* --- Layout ------------------------------------------------- */

.page-header {
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  padding: 0.875rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-header h1 {
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
}

.page-content {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- Buttons ------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}

.btn-primary {
  background: #18181b;
  color: #fff;
  border-color: #18181b;
}
.btn-primary:hover {
  background: #3f3f46;
  border-color: #3f3f46;
}

.btn-secondary {
  background: #fff;
  color: #18181b;
  border-color: #d1d5db;
}
.btn-secondary:hover {
  background: #f4f4f5;
}

.btn-danger {
  background: #fff;
  color: #b91c1c;
  border-color: #fca5a5;
}
.btn-danger:hover {
  background: #fef2f2;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Forms -------------------------------------------------- */

.form-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: #374151;
}

input[type="text"],
input[type="number"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* --- Cards -------------------------------------------------- */

.card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.card-meta {
  font-size: 0.8125rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
}

/* --- Paper list table --------------------------------------- */

.paper-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.paper-table th {
  text-align: left;
  font-weight: 600;
  color: #6b7280;
  border-bottom: 1px solid #e5e5e5;
  padding: 0.5rem 0.75rem;
  white-space: nowrap;
}

.paper-table th[data-col]:hover { color: #4f46e5; }

.sort-indicator {
  margin-left: 0.2rem;
  font-size: 0.7rem;
  color: #9ca3af;
}
.sort-indicator.active { color: #4f46e5; }

.paper-table td {
  padding: 0.75rem;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: top;
}

.paper-table tr:last-child td {
  border-bottom: none;
}

.paper-table tr:hover td {
  background: #fafaf9;
}

/* --- Badges ------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 0.1875rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  white-space: nowrap;
}

.badge-green  { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-red    { background: #fee2e2; color: #991b1b; }

/* --- Star rating -------------------------------------------- */

.stars {
  display: inline-flex;
  gap: 0.125rem;
}

.star {
  font-size: 1.125rem;
  cursor: pointer;
  color: #d1d5db;
  line-height: 1;
  transition: color 0.1s;
  user-select: none;
}

.star.filled { color: #f59e0b; }
.star:hover  { color: #fbbf24; }

/* --- Add-paper panel --------------------------------------- */

#add-paper-panel {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

#preview-card {
  display: none;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid #e5e5e5;
}

#preview-card.visible {
  display: block;
}

.preview-title {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.preview-meta {
  font-size: 0.8125rem;
  color: #6b7280;
  margin-bottom: 0.75rem;
}

.preview-abstract {
  font-size: 0.875rem;
  color: #374151;
  margin-bottom: 1rem;
  max-height: 120px;
  overflow-y: auto;
}

.preview-actions {
  display: flex;
  gap: 0.5rem;
}

/* --- Progress overlay -------------------------------------- */

#progress-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

#progress-overlay.visible {
  display: flex;
}

.progress-box {
  background: #fff;
  border-radius: 10px;
  padding: 2rem 2.5rem;
  min-width: 320px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.progress-box h2 {
  font-size: 1rem;
  margin-bottom: 1.25rem;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 0.875rem;
  padding: 0.375rem 0;
  color: #9ca3af;
}

.progress-step.done    { color: #166534; }
.progress-step.active  { color: #1a1a1a; font-weight: 500; }

.progress-step .step-icon {
  width: 1.25rem;
  text-align: center;
}

/* --- Note sections ----------------------------------------- */

.note-section {
  margin-bottom: 1.25rem;
}

.note-section-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.note-section-body {
  font-size: 0.9375rem;
  color: #1a1a1a;
}

.note-section-body p:last-child {
  margin-bottom: 0;
}

.note-section-body ul,
.note-section-body ol {
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.5rem;
}

/* --- Note cards (individual section cards) ------------------ */

.note-card {
  margin-bottom: 1rem;
}

.note-card-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.note-card-body {
  font-size: 0.9375rem;
  color: #1a1a1a;
}

.note-card-body p:last-child {
  margin-bottom: 0;
}

.note-card-body ul,
.note-card-body ol {
  padding-left: 1.25rem;
  margin: 0.25rem 0 0.5rem;
}

/* --- Toast -------------------------------------------------- */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: #1a1a1a;
  color: #fff;
  padding: 0.625rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: auto;
  max-width: 320px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: #991b1b;
}

/* --- Search bar -------------------------------------------- */

.search-bar-row {
  margin-bottom: 1rem;
}

.search-input {
  display: block;
  width: 100%;
  padding: 0.5625rem 0.875rem;
  font-size: 0.9375rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.search-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* --- Corpus layout (sidebar + table) ----------------------- */

.corpus-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.corpus-main {
  flex: 1;
  min-width: 0;
}

/* --- Filter panel ------------------------------------------ */

.filter-panel {
  width: 200px;
  flex-shrink: 0;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  padding: 1rem;
  font-size: 0.875rem;
}

.filter-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin-bottom: 0.875rem;
}

.clear-filters-link {
  background: none;
  border: none;
  color: #6366f1;
  font-size: 0.8125rem;
  cursor: pointer;
  padding: 0;
}
.clear-filters-link:hover {
  text-decoration: underline;
}

.filter-section {
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid #f3f4f6;
}
.filter-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.filter-label {
  font-weight: 600;
  color: #6b7280;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.filter-range-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.filter-number {
  width: 60px;
  padding: 0.3125rem 0.5rem;
  font-size: 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  outline: none;
  background: #fff;
}
.filter-number:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

.filter-range-sep {
  color: #9ca3af;
  font-size: 0.875rem;
}

.filter-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  color: #374151;
}

.filter-select {
  width: 100%;
  padding: 0.3125rem 0.5rem;
  font-size: 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  outline: none;
  background: #fff;
}
.filter-select:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

/* --- Theme chips (filter panel) ---------------------------- */

.theme-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.theme-chip-filter {
  display: inline-block;
  padding: 0.1875rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  color: #374151;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}
.theme-chip-filter:hover {
  background: #f3f4f6;
}
.theme-chip-filter.active {
  background: #eef2ff;
  border-color: #6366f1;
  color: #4338ca;
}

/* --- Theme chips (table cells) ----------------------------- */

.theme-chip-small {
  display: inline-block;
  padding: 0.125rem 0.375rem;
  font-size: 0.6875rem;
  font-weight: 500;
  border-radius: 3px;
  background: #f3f4f6;
  color: #374151;
  margin-right: 0.2rem;
  white-space: nowrap;
}

/* --- Utility ----------------------------------------------- */

.hidden { display: none !important; }

.text-muted {
  color: #9ca3af;
  font-size: 0.875rem;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }

.flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.items-center { align-items: center; }

/* --- Chat panel -------------------------------------------- */

.chat-toggle-btn {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1100;
  background: #18181b;
  color: #fff;
  border: none;
  border-radius: 24px;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  transition: background 0.12s, box-shadow 0.12s;
}
.chat-toggle-btn:hover {
  background: #3f3f46;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  height: 100vh;
  background: #fff;
  border-left: 1px solid #e5e5e5;
  display: flex;
  flex-direction: column;
  z-index: 1200;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.08);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #e5e5e5;
  background: #fafaf9;
  font-weight: 600;
  font-size: 0.9375rem;
  flex-shrink: 0;
}

.chat-header span {
  flex: 1;
}

.btn-sm {
  padding: 0.25rem 0.625rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: 5px;
  border: 1px solid #d1d5db;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: background 0.1s;
  white-space: nowrap;
}
.btn-sm:hover {
  background: #f3f4f6;
}

.chat-close {
  background: none;
  border: none;
  font-size: 1.125rem;
  color: #9ca3af;
  cursor: pointer;
  padding: 0.125rem 0.375rem;
  line-height: 1;
  border-radius: 4px;
}
.chat-close:hover {
  color: #374151;
  background: #f3f4f6;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.chat-bubble {
  max-width: 88%;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
}

.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { padding-left: 1.25rem; margin: 0.25rem 0 0.5rem; }
.chat-bubble code { background: rgba(0,0,0,0.07); border-radius: 3px; padding: 0.1em 0.3em; font-size: 0.85em; }

.chat-bubble-user {
  align-self: flex-end;
  background: #18181b;
  color: #fff;
  border-bottom-right-radius: 3px;
}

.chat-bubble-assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1a1a1a;
  border-bottom-left-radius: 3px;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid #e5e5e5;
  background: #fafaf9;
  flex-shrink: 0;
  align-items: flex-end;
}

.chat-input-row textarea {
  flex: 1;
  resize: none;
  font-size: 0.875rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  outline: none;
  background: #fff;
  transition: border-color 0.12s, box-shadow 0.12s;
  font-family: inherit;
}

.chat-input-row textarea:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

/* ============================================================
   Nav toggle button (hamburger — hidden on desktop)
   ============================================================ */

.nav-toggle-btn {
  display: none;
  background: none;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 0.375rem 0.625rem;
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
  color: #374151;
  flex-shrink: 0;
}

.nav-toggle-btn:hover {
  background: #f4f4f5;
}

/* Inbox count badge in nav */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.125rem;
  height: 1.125rem;
  font-size: 0.6875rem;
  font-weight: 700;
  background: #f59e0b;
  color: #fff;
  border-radius: 9px;
  padding: 0 0.25rem;
  vertical-align: middle;
  margin-left: 0.125rem;
}

/* ============================================================
   Responsive — 768px breakpoint
   ============================================================ */

@media (max-width: 768px) {

  /* --- Header ----------------------------------------- */

  .page-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Remove flex:1 from h1 so toggle can get margin-left:auto */
  .page-header h1 {
    flex: 0 1 auto;
  }

  .nav-toggle-btn {
    display: flex;
    align-items: center;
    margin-left: auto;
  }

  /* Nav links collapse to a vertical list, shown via .nav-open */
  .page-header nav {
    width: 100%;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.625rem !important;
    margin-right: 0 !important;
    display: none !important;
    padding: 0.625rem 0 0.25rem;
    border-top: 1px solid #f3f4f6;
  }

  .page-header nav.nav-open {
    display: flex !important;
  }

  .page-header nav a {
    font-size: 0.9375rem !important;
    font-weight: 500;
    padding: 0.125rem 0;
  }

  /* --- Page content ----------------------------------- */

  .page-content {
    padding: 1rem;
  }

  /* --- Add-paper panel -------------------------------- */

  #add-paper-panel .form-row {
    flex-direction: column;
  }

  /* --- Corpus filter + paper list layout -------------- */

  .corpus-layout {
    flex-direction: column;
  }

  .filter-panel {
    width: 100%;
  }

  /* --- Tables: hide less-critical columns ------------- */

  /* Corpus: hide Themes (col 3), Rating (col 4)
     Inbox:  hide Source (col 3), Confidence (col 4) */
  .paper-table th:nth-child(3),
  .paper-table td:nth-child(3),
  .paper-table th:nth-child(4),
  .paper-table td:nth-child(4) {
    display: none;
  }

  /* --- Chat panel: full-width on mobile --------------- */

  .chat-panel {
    width: 100%;
  }

  /* --- Header action buttons: smaller on mobile ------- */

  .page-header .btn {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }

}

@media (max-width: 480px) {

  .page-header h1 {
    font-size: 1rem;
  }

  .page-content {
    padding: 0.75rem;
  }

}
