body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

/* Page Wrapper */
.wrap {
  max-width: 100%;
  margin: 0;
  padding: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* Header / Navbar */
header {
  height: 64px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
}

.brand h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Header Search */
.header-search {
  flex: 1;
  max-width: 600px;
  margin: 0 20px;
  display: flex;
  align-items: center;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-hover);
  border-radius: 24px;
  padding: 0 16px;
  height: 40px;
  transition: all 0.2s ease;
  border: none;
  outline: 1px solid transparent;
}

.search-box:focus-within {
  background: #fff;
  outline-color: var(--color-primary);
  outline-width: 2px;
}

.search-box__icon {
  color: var(--text-tertiary);
  margin-right: 8px;
}

.search-box__input {
  border: none;
  background: transparent;
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  height: 100%;
}

.search-box__clear {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
  display: none;
}

.search-box__input:not(:placeholder-shown)+.search-box__clear {
  display: block;
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.2s;
  white-space: nowrap;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 200px;
  justify-content: flex-end;
}

/* Main Layout */
.layout {
  display: flex;
  min-height: calc(100vh - 64px);
  background: var(--bg-page);
}

/* Sidebar */
.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  overflow-y: auto;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
}

.side-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-tertiary);
  margin: 24px 12px 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.side-title:first-child {
  margin-top: 0;
}

/* Sidebar Color Accents */
.side-title.source-title {
  color: var(--color-info);
}

.side-title.filter-title {
  color: var(--color-warning);
}

.side-title.tag-title {
  color: var(--color-primary);
}

.side-title.author-title {
  color: var(--color-success);
}

.side-menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.side-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all 0.2s ease;
}

.tag-list .side-item {
  font-size: 15px;
  /* Larger font for tags */
}

.side-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateX(4px);
}

.side-item.active {
  background: #E6F7FF;
  color: var(--color-primary);
  font-weight: 600;
}

/* Main Content */
.content {
  flex: 1;
  padding: 24px;
  min-width: 0;
  height: calc(100vh - 64px);
  overflow-y: auto;
}

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

.toolbar-count {
  font-size: 14px;
  color: var(--text-secondary);
}

.sort-order {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-secondary);
}

.sort-order select {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 14px;
}

/* Model Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 24px;
  margin-bottom: 40px;
}

/* Card */
.card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  overflow: hidden;
  position: relative;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.06);
  border-color: #d0d7de;
  z-index: 2;
}

/* Card Cover */
.card-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--bg-hover);
  overflow: hidden;
  border-bottom: 1px solid var(--border-color-light);
  cursor: pointer;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.card:hover .card-cover img {
  transform: scale(1.02);
}

/* Card Body */
.card-body {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* Title */
.title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 8px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: pointer;
}

.title:hover {
  color: var(--color-primary);
}

/* Author */
.card-meta {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.author {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.author img,
.avatar-placeholder {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

.author-name {
  max-width: 140px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Stats */
.stats {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: auto;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.stat-chip i {
  font-size: 14px;
}

/* Colorful stat icons */
.stat-chip i.fa-thumbs-up {
  color: #f59e0b;
  /* Orange for likes */
}

.stat-chip i.fa-star {
  color: #eab308;
  /* Yellow for favorites */
}

.stat-chip i.fa-print {
  color: #8b5cf6;
  /* Purple for prints */
}

.stat-chip i.fa-download {
  color: #06b6d4;
  /* Cyan for downloads */
}

/* Card Dates */
.card-dates {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

.date-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.date-item i.fa-calendar-alt {
  font-size: 13px;
  color: #10b981;
  width: 16px;
  text-align: center;
}

.date-item i.fa-archive {
  font-size: 13px;
  color: #3b82f6;
  width: 16px;
  text-align: center;
}

/* Card Actions (Persistent) */
.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color-light);
  opacity: 1;
  /* Always visible */
  transform: none;
}

.action-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.action-btn:hover {
  background: var(--bg-hover);
  color: var(--color-primary);
  transform: scale(1.1);
}

.action-btn.active {
  color: var(--color-primary);
}

/* Load More Indicator */
.load-more-indicator {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
  font-size: 14px;
}

.load-more-indicator i {
  margin-right: 8px;
  color: var(--color-primary);
}

/* V1/V2 Toggle Button */
.btn-v2-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: #fff;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-v2-toggle:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: #f0f7ff;
}

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

.btn-v2-toggle.active:hover {
  background: #1565c0;
  border-color: #1565c0;
}

/* =========================================
   Mobile Responsiveness (H5)
========================================= */
@media (max-width: 992px) {

  /* Header */
  header {
    padding: 15px;
    /* Equal 15px padding all around */
    height: auto;
    /* Allow auto height based on padding */
    min-height: 60px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand {
    min-width: auto;
  }

  .header-search {
    display: none;
    /* Hide search bar on mobile for simplicity, or we can move it into a menu */
  }

  .header-actions {
    min-width: auto;
    gap: 8px;
  }

  /* Main Layout */
  .layout {
    flex-direction: column;
  }

  /* Sidebar */
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 16px;
    display: block;
    /* Use block to ensure it auto-expands height */
  }

  /* Hide all sidebar sections except the first one (Source) */
  .sidebar>.side-title:not(:first-child),
  .sidebar>.side-menu:not(:nth-of-type(2)) {
    display: none;
  }

  .sidebar::-webkit-scrollbar {
    display: none;
  }

  .side-menu {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    /* Wrap menu items */
    align-items: center;
    gap: 8px;
    width: 100%;
  }

  .side-item {
    width: auto;
    padding: 6px 12px;
    white-space: nowrap;
    margin: 0;
  }

  .side-title {
    margin: 0 0 12px 0;
    white-space: nowrap;
    width: 100%;
    display: block;
  }

  .side-title:first-child {
    margin-top: 0;
  }

  /* Content */
  .content {
    padding: 16px;
    height: auto;
    min-height: calc(100vh - 60px - 60px);
    /* Approx */
  }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .sort-order {
    width: 100%;
    justify-content: space-between;
  }

  /* Grid */
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
  }

  .card-cover {
    aspect-ratio: 1 / 1;
  }

  .card-body {
    padding: 10px;
  }

  .title {
    font-size: 14px;
  }

  .author-name {
    max-width: 80px;
  }

  .stat-chip {
    font-size: 11px;
  }
}