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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f5f5f5;
  color: #222;
  min-height: 100vh;
}

/* ── Layout ── */
.container { max-width: 800px; margin: 0 auto; padding: 2rem 1rem; }

header { margin-bottom: 2rem; }
header h1 { font-size: 1.4rem; font-weight: 600; margin-bottom: 0.25rem; }
header p  { font-size: 0.85rem; color: #666; }

/* ── Search ── */
.search-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.search-toolbar #search-input { margin-bottom: 0; flex: 1; }

/* ── Tabs ── */
.tab-bar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #e0e0e0;
  padding-bottom: 0.75rem;
}
.tab-btn {
  background: none;
  color: #666;
  font-size: 0.9rem;
  padding: 0.35rem 0.9rem;
  border-radius: 5px;
}
.tab-btn:hover { background: #f0f0f0; color: #222; }
.tab-btn.active { background: #222; color: #fff; }
.tab-actions { margin-left: auto; display: flex; gap: 0.4rem; }

#ai-status { font-size: 0.82rem; color: #555; margin-bottom: 0.75rem; min-height: 1em; }

.ai-search-box { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.ai-search-box textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #ddd;
  border-radius: 6px;
  outline: none;
  resize: vertical;
  line-height: 1.5;
}
.ai-search-box textarea:focus { border-color: #999; }
.ai-search-box button { align-self: flex-end; padding: 0.5rem 1.5rem; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.filter-btn {
  background: #eee;
  color: #444;
  font-size: 0.8rem;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
}
.filter-btn:hover { background: #ddd; }
.filter-btn.active { background: #222; color: #fff; }

#sync-status {
  font-size: 0.82rem;
  color: #555;
  margin-bottom: 1rem;
  min-height: 1em;
}

#search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  outline: none;
  background: #fff;
  margin-bottom: 1.5rem;
}
#search-input:focus { border-color: #999; }

/* ── Paper cards ── */
#results { display: flex; flex-direction: column; gap: 0.75rem; }

.paper-card-wrap {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem 1.25rem 0.75rem;
  transition: border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.paper-card-wrap:hover { border-color: #999; }

.paper-card {
  display: block;
  text-decoration: none;
  color: inherit;
}

.paper-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; line-height: 1.4; }

.paper-meta { font-size: 0.82rem; color: #666; display: flex; flex-wrap: wrap; gap: 0.75rem; margin-bottom: 0.2rem; }

.paper-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag {
  font-size: 0.72rem;
  background: #eee;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  color: #555;
}

.no-results { color: #888; font-size: 0.9rem; }

.card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #f0f0f0;
  margin-top: 0.25rem;
}
.edit-btn, .scholar-btn, .add-cite-btn, .project-btn {
  background: none;
  font-size: 0.78rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  color: #666;
  text-decoration: none;
  cursor: pointer;
  border: 1px solid #e0e0e0;
}
.edit-btn:hover, .scholar-btn:hover, .add-cite-btn:hover, .project-btn:hover { background: #f5f5f5; color: #222; border-color: #bbb; }
.add-cite-btn.added { color: #2a7a2a; border-color: #2a7a2a; background: #f0faf0; }

/* ── Project tags on cards ── */
.paper-projects { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.2rem; }
.project-tag {
  font-size: 0.72rem;
  background: #e8f0fe;
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
  color: #1a56b0;
  font-weight: 500;
}

/* ── Project list view ── */
.project-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.project-list-item:hover { border-color: #999; background: #fafafa; }
.project-list-name { font-size: 0.95rem; font-weight: 600; color: #1a56b0; }
.project-list-count { font-size: 0.8rem; color: #888; }

/* ── Project detail header ── */
.project-detail-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.back-btn {
  background: none;
  color: #666;
  font-size: 0.82rem;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  border: 1px solid #e0e0e0;
}
.back-btn:hover { background: #f5f5f5; color: #222; border-color: #bbb; }
.project-detail-title { font-size: 1rem; font-weight: 600; color: #1a56b0; }
.project-detail-count { font-size: 0.8rem; color: #888; margin-left: auto; }

/* ── Project chips in modal ── */
#project-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; min-height: 1.5rem; margin-top: 0.25rem; }
.project-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: #e8f0fe;
  color: #1a56b0;
  font-size: 0.82rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}
.chip-remove {
  background: none;
  border: none;
  color: #1a56b0;
  font-size: 0.7rem;
  padding: 0 0.1rem;
  cursor: pointer;
  line-height: 1;
}
.chip-remove:hover { color: #d00; background: none; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  margin: 1rem;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-close {
  background: none;
  color: #666;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
}
.modal-close:hover { background: #eee; color: #222; }

#import-status { font-size: 0.82rem; margin-top: 0.75rem; min-height: 1em; }

.edit-actions { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }

.tag-input-wrap { position: relative; }
.tag-suggestions {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 5px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 200;
  max-height: 180px;
  overflow-y: auto;
}
.tag-suggestion-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.tag-suggestion-item:hover { background: #f5f5f5; }

.apa-paste-box { margin-bottom: 0.75rem; }
.apa-paste-box label { display: block; font-size: 0.8rem; color: #555; margin-bottom: 0.3rem; }
.apa-paste-row { display: flex; gap: 0.4rem; }
.apa-paste-row input { flex: 1; padding: 0.5rem 0.75rem; font-size: 0.85rem; border: 1px solid #ddd; border-radius: 5px; outline: none; }
.apa-paste-row input:focus { border-color: #999; }

/* ── Admin ── */
.section {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.section h2 { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }

.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.8rem; color: #555; margin-bottom: 0.25rem; }
.form-group input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  outline: none;
}
.form-group input:focus { border-color: #999; }

button {
  padding: 0.5rem 1.1rem;
  font-size: 0.875rem;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  background: #222;
  color: #fff;
}
button:hover { background: #444; }
button.secondary { background: #eee; color: #222; }
button.secondary:hover { background: #ddd; }

#sync-log { font-size: 0.82rem; color: #555; margin-top: 0.75rem; min-height: 1.2em; }

#status-msg {
  display: none;
  background: #e8f5e9;
  border: 1px solid #c8e6c9;
  border-radius: 5px;
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.toolbar span { font-size: 0.85rem; color: #666; }
