/* Browse papers page — uses CSS variables from body.landing-page */

.papers-section {
  padding: 32px 20px 64px;
  background: var(--bg);
  min-height: 50vh;
}

.papers-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  gap: 30px;
  align-items: flex-start;
}

.sidebar {
  width: 300px;
  background: var(--bg-white);
  border-radius: var(--radius);
  padding: 25px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: sticky;
  top: 100px;
  max-height: calc(100vh - 140px);
  overflow-x: hidden;
  overflow-y: auto;
  flex-shrink: 0;
  box-sizing: border-box;
}

.mobile-filter-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1000;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  box-shadow: 0 4px 20px rgba(0, 102, 255, 0.35);
  cursor: pointer;
  transition: transform 0.2s;
}

.mobile-filter-toggle:hover {
  transform: scale(1.05);
}

.mobile-filter-toggle svg {
  width: 24px;
  height: 24px;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.sidebar-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 400;
  color: var(--navy);
  margin: 0;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
}

.filter-section {
  margin-bottom: 20px;
  min-width: 0;
  max-width: 100%;
}

.filter-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-input-wrapper {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.search-input-sidebar {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 12px 40px 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font-sans);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-sidebar:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 102, 255, 0.12);
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

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

.subject-pills {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.subject-pill {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--bg-white);
  color: var(--navy);
  text-decoration: none;
  display: inline-block;
}

.subject-pill:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.subject-pill.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.popular-schools {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.school-tag {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--navy);
  text-decoration: none;
  transition: all 0.2s;
}

.school-tag:hover {
  background: #f0f7ff;
  border-color: var(--blue);
  color: var(--blue);
}

.schools-list {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 400px;
  overflow-y: auto;
}

.filter-section.collapsible .filter-content {
  max-height: 500px;
  overflow: hidden;
  padding: 3px 2px;
  box-sizing: border-box;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 1;
}

#searchSection .filter-content {
  overflow: visible;
}

.filter-section.collapsible.collapsed .filter-content {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  padding-top: 0;
  padding-bottom: 0;
}

.filter-section.collapsible .filter-label {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-section.collapsible .filter-label::after {
  content: '▼';
  font-size: 12px;
  transition: transform 0.3s ease;
  color: var(--text-muted);
}

.filter-section.collapsible.collapsed .filter-label::after {
  transform: rotate(-90deg);
}

.school-item {
  padding: 12px 16px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
  font-size: 15px;
  border: 2px solid transparent;
}

.school-item:hover {
  background: var(--bg);
  border-color: var(--border);
}

.school-item.active {
  background: #f0f7ff;
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 600;
}

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

#papersGrid {
  transition: opacity 0.3s ease;
}

.papers-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.papers-open-filters-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--navy);
  font-size: 0.9375rem;
  font-weight: 700;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.papers-open-filters-btn:hover,
.papers-open-filters-btn:focus-visible {
  border-color: var(--blue);
  color: var(--blue);
  outline: none;
}

.papers-open-filters-btn svg {
  flex-shrink: 0;
  color: var(--blue);
}

.papers-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 800;
  line-height: 1;
}

.papers-filter-badge[hidden] {
  display: none !important;
}

.active-filter-tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  min-height: 36px;
  background: #f0f7ff;
  border: 1px solid var(--blue);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--blue);
  animation: lpFadeIn 0.3s ease;
  flex-shrink: 0;
  max-width: min(100%, 280px);
}

.filter-tag-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-tag-label {
  font-size: 12px;
  opacity: 0.85;
}

.filter-tag-remove {
  background: none;
  border: none;
  color: var(--blue);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-width: 28px;
  border-radius: 50%;
  transition: all 0.2s;
  flex-shrink: 0;
}

.filter-tag-remove svg {
  width: 14px;
  height: 14px;
}

.filter-tag-remove:hover {
  background: var(--blue);
  color: #fff;
}

@keyframes lpFadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.add-to-cart-button {
  background: var(--blue);
  color: #fff;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.add-to-cart-button:hover {
  background: var(--blue-dark);
  transform: translateY(-1px);
}

.no-results {
  text-align: center;
  padding: 80px 20px;
}

.no-results-icon {
  font-size: 64px;
  margin-bottom: 20px;
  opacity: 0.3;
}

.no-results h3 {
  font-family: var(--font-serif);
  font-size: 1.5rem;
  color: var(--navy);
  margin-bottom: 10px;
}

.no-results p {
  font-size: 16px;
  color: var(--text-muted);
}

/* Paper browse widget */
body.landing-page .popular-searches {
  background: var(--bg);
  border: 1px solid var(--border);
}

body.landing-page .popularlink {
  color: var(--blue);
}

body.landing-page .popularlink:hover {
  border-color: var(--blue);
}

#papersGrid .papers-grid {
  width: 100%;
}

body.landing-page .load-more-past-papers {
  background: var(--blue);
  box-shadow: 0 4px 14px rgba(0, 102, 255, 0.3);
}

body.landing-page .loading-spinner {
  border-top-color: var(--blue);
}

body.landing-page .loading-text {
  color: var(--blue);
}

body.papers-filter-open {
  overflow: hidden;
}

@media (max-width: 1024px) {
  .papers-container {
    flex-direction: column;
  }

  .papers-toolbar {
    position: sticky;
    top: 64px;
    z-index: 90;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
    padding: 10px 0 12px;
    background: linear-gradient(180deg, var(--bg) 70%, rgba(248, 250, 252, 0));
  }

  .papers-open-filters-btn {
    display: inline-flex;
  }

  .active-filter-tags {
    flex: 1;
    min-width: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    align-items: center;
    padding-bottom: 2px;
  }

  .active-filter-tags::-webkit-scrollbar {
    display: none;
  }

  .active-filter-tags:empty,
  .active-filter-tags[style*="display: none"] {
    display: none !important;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(360px, 100%);
    max-width: 100%;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 2000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-radius: 0;
    padding: 16px 16px max(16px, env(safe-area-inset-bottom));
    padding-top: max(16px, env(safe-area-inset-top));
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(10, 37, 64, 0.2);
  }

  .sidebar-close {
    display: flex !important;
  }

  .sidebar-header {
    flex-shrink: 0;
    margin-bottom: 16px;
  }

  .filter-section {
    flex-shrink: 0;
    margin-bottom: 16px;
  }

  .filter-section--schools {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
  }

  .filter-section--schools .filter-label {
    flex-shrink: 0;
  }

  .schools-list {
    flex: 1;
    min-height: 120px;
    max-height: none;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-filter-toggle {
    display: none;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 37, 64, 0.5);
    z-index: 1999;
    -webkit-tap-highlight-color: transparent;
  }

  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    width: 100%;
    min-width: 0;
  }

  .subject-pill {
    min-height: 44px;
    padding: 10px 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .school-tag {
    min-height: 36px;
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
  }

  .school-item {
    min-height: 44px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
  }

  .school-item a {
    width: 100%;
  }

  .search-input-sidebar {
    min-height: 44px;
    font-size: 16px;
    padding-right: 44px;
  }

  #searchSection .filter-content {
    overflow: visible;
    padding: 4px 2px;
    max-width: 100%;
  }

  .filter-section.collapsible .filter-label {
    min-height: 44px;
    padding: 4px 0;
  }
}

@media (max-width: 768px) {
  .papers-section {
    padding: 16px 12px 40px;
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }

  .papers-toolbar {
    top: 56px;
    margin-bottom: 12px;
  }

  .papers-open-filters-btn {
    padding: 10px 14px;
    font-size: 0.875rem;
  }

  .sidebar {
    width: 100%;
  }

  .subject-pills {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .subject-pill {
    width: 100%;
    text-align: center;
    padding: 10px 8px;
  }

  #papersGrid .papers-grid {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}

@media (max-width: 480px) {
  .popular-schools {
    gap: 8px;
  }

  .school-tag {
    font-size: 11px;
    padding: 8px 10px;
  }
}
