/* ============================================
   PaperHub — Main Stylesheet
   Clean academic design, mobile-first
   ============================================ */

:root {
  --bg: #f1f5f9;
  --card: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --orange: #d97706;
  --radius: 8px;
  --radius-sm: 6px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

body.sidebar-open {
  overflow: hidden;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

/* ── Header ── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
}

.logo span {
  color: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-email {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ── */
.btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}

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

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-outline {
  background: var(--card);
}

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

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}

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

.btn-small {
  font-size: 0.78rem;
  padding: 4px 10px;
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

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

/* ── Layout ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ── Hero ── */
.hero {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 32px 0;
}

.hero-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

.hero-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.hero-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-top: 4px;
  margin-bottom: 24px;
}

/* ── Stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.stat-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 16px 18px;
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Content ── */
.content {
  padding: 24px 0 60px;
}

/* ── Search ── */
.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 12px;
  transition: all 0.15s;
}

.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.search-box input {
  flex: 1;
  border: none;
  padding: 10px 0;
  font-size: 0.9rem;
  outline: none;
  background: transparent;
  color: var(--text);
}

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

.filter-select {
  padding: 9px 32px 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  outline: none;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.filter-select:focus {
  border-color: var(--primary);
  outline: none;
}

/* ── Subject Pills ── */
.subject-pills {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.pill {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-secondary);
  transition: all 0.12s;
}

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

/* ── Section Title ── */
.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 20px 0 12px;
  display: flex;
  justify-content: space-between;
}

.section-title .count {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Paper Grid ── */
.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

/* ── Paper Card ── */
.paper-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 18px;
  transition: all 0.15s;
  cursor: pointer;
}

.paper-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.paper-title {
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.paper-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
}

.tag-subject {
  background: #dbeafe;
  color: var(--primary);
}

.tag-year {
  background: #fef3c7;
  color: #92400e;
}

.tag-file {
  background: #fee2e2;
  color: #991b1b;
}

.paper-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.76rem;
  color: var(--text-muted);
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state .icon {
  font-size: 2rem;
  margin-bottom: 10px;
}

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

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

.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 28px;
  max-width: 460px;
  width: 94%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
}

.modal h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  outline: none;
  background: var(--card);
  color: var(--text);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.08);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row .form-group {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ── Upload Zone ── */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg);
}

.upload-zone:hover,
.upload-zone.drag {
  border-color: var(--primary);
  background: #eff6ff;
}

/* ── Detail Card ── */
.detail-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 16px;
}

.detail-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 10px;
}

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

.detail-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}

/* ── Embedded Preview ── */
.preview-panel {
  margin-top: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
  overflow: hidden;
}

.preview-panel-head {
  min-height: 42px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.86rem;
  font-weight: 600;
}

.preview-open {
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
}

.preview-surface {
  background: #0f172a;
}

.embedded-pdf {
  display: block;
  width: 100%;
  height: min(760px, 70vh);
  border: 0;
  background: #fff;
}

.embedded-video {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 70vh;
  background: #000;
}

.preview-fallback {
  padding: 9px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.76rem;
  background: var(--card);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 14px 0;
}

.back-link:hover {
  color: var(--text);
}

/* ── Review ── */
.review-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 6px;
}

.review-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stars {
  color: var(--orange);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 0.84rem;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.toast.show {
  opacity: 1;
}

/* ── Back to Top ── */
#back-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  display: none;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* ── Load More ── */
.load-more {
  text-align: center;
  padding: 16px;
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0;
}

.page-info {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ── Notification Badge ── */
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 0.6rem;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  left: -280px;
  top: 0;
  width: 280px;
  height: 100%;
  background: var(--card);
  border-right: 1px solid var(--border);
  z-index: 300;
  transition: left 0.25s ease;
  overflow-y: auto;
  padding: 20px;
  box-shadow: 2px 0 20px rgba(0, 0, 0, 0.1);
}

.sidebar.open {
  left: 0;
}

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

.sidebar-title {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  justify-content: flex-start;
  text-align: left;
  padding: 10px 12px;
}

.sidebar-divider {
  margin: 8px 0;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 8px 12px;
  word-break: break-all;
}

/* ── Overlay ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 299;
  transition: opacity 0.2s;
}

.overlay.active {
  display: block;
}

/* ── Skeleton ── */
.skeleton {
  height: 16px;
  background: #e2e8f0;
  border-radius: 4px;
  margin-bottom: 8px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-short {
  width: 60%;
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .search-row {
    flex-direction: column;
  }

  .detail-card {
    padding: 16px;
  }

  .embedded-pdf {
    height: 62vh;
  }

  .preview-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-row {
    flex-direction: column;
  }

  /* Hide desktop nav on mobile, show hamburger */
  .nav-right .btn-outline,
  .nav-right .user-email {
    display: none !important;
  }

  #loginBtn, #logoutBtn, #notifBell {
    display: flex !important;
  }

  .sidebar {
    width: 260px;
    left: -260px;
  }
}

@media (min-width: 769px) {
  /* Hide hamburger on desktop */
  #menuBtn {
    display: none;
  }
}
