/* ─── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1a1f2e;
  --text-muted: #6b7280;
  --primary: #4361ee;
  --primary-hover: #3450d4;
  --primary-light: #eef1fd;
  --tag-bg: #f0f4ff;
  --tag-text: #3b4fc4;
  --tag-border: #c7d0f8;
  --tag-active-bg: #4361ee;
  --tag-active-text: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 10px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.05);
  --radius: 10px;
  --sidebar-w: 240px;
  --header-h: 68px;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Header ─────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  height: var(--header-h);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-title h1 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.header-search {
  flex: 1;
  max-width: 480px;
  margin-left: auto;
}

#search-input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s;
  outline: none;
}

#search-input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 24px;
  align-items: start;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  position: sticky;
  top: calc(var(--header-h) + 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  max-height: calc(100vh - var(--header-h) - 40px);
  overflow-y: auto;
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-section:last-of-type {
  margin-bottom: 12px;
}

.sidebar-section h2 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.tag-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag-btn {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}

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

.tag-btn.active {
  background: var(--tag-active-bg);
  color: var(--tag-active-text);
  border-color: var(--tag-active-bg);
}

.tag-btn .count {
  margin-left: 5px;
  background: rgba(0,0,0,.1);
  border-radius: 10px;
  padding: 0 5px;
  font-size: 0.7rem;
}

.tag-btn.active .count {
  background: rgba(255,255,255,.25);
}

.clear-btn {
  width: 100%;
  padding: 8px;
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all .15s;
  margin-top: 4px;
}

.clear-btn:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  min-width: 0;
}

.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

#results-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toggle-sidebar-btn {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.84rem;
  cursor: pointer;
  color: var(--text);
  transition: all .15s;
}

.toggle-sidebar-btn:hover {
  background: var(--bg);
}

/* ─── Paper Grid & Cards ──────────────────────────────────────────────────── */
.papers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.paper-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow .15s, transform .15s;
}

.paper-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.paper-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.paper-section {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  opacity: 0.75;
}

.paper-title {
  font-size: 0.93rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.paper-title a {
  color: inherit;
}

.paper-title a:hover {
  color: var(--primary);
  text-decoration: none;
}

.paper-summary {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.55;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.paper-tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--tag-border);
  border-radius: 12px;
  font-size: 0.73rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .12s;
  white-space: nowrap;
}

.paper-tag:hover,
.paper-tag.active-tag {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.paper-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.paper-issue {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.paper-issue a {
  color: var(--text-muted);
}

.paper-issue a:hover {
  color: var(--primary);
}

.paper-score {
  font-size: 0.75rem;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

/* ─── No Results ──────────────────────────────────────────────────────────── */
.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.no-results p { font-size: 1rem; }

/* ─── Footer ─────────────────────────────────────────────────────────────── */
.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ─── Active Filters Display ──────────────────────────────────────────────── */
.active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.active-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
}

.active-filter-chip button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  opacity: 0.8;
  display: flex;
  align-items: center;
}

.active-filter-chip button:hover { opacity: 1; }

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    width: 100%;
    max-width: 320px;
    height: calc(100vh - var(--header-h));
    max-height: none;
    z-index: 90;
    border-radius: 0;
    border-left: none;
    border-top: none;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .toggle-sidebar-btn {
    display: flex;
  }

  .papers-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .header-inner {
    padding: 0 16px;
    gap: 12px;
  }
  .header-title h1 { font-size: 1rem; }
  .subtitle { display: none; }
  .header-search { max-width: 200px; }
}
