/* =========================
   MARKETPLACE PAGE SHELL
   Self-contained: owns its own background, padding, radius and
   shadow instead of depending on a parent container (e.g. .admin-card)
   for spacing. This is what keeps the header off the edge of the
   screen and gives every section below a stable "surface" to sit on.
========================= */
.marketplace-page {
  background: #ffffff;
  border: 1px solid #ececf5;
  border-radius: 24px;
  padding: 28px;
  box-shadow:
    0 1px 2px rgba(20, 18, 31, 0.04),
    0 16px 40px rgba(76, 29, 149, 0.06);
}

.marketplace-header {
  margin-bottom: 24px;
}

.marketplace-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #7c3aed;
  background: #f3effe;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.marketplace-eyebrow svg {
  flex-shrink: 0;
}

.marketplace-header h2 {
  margin: 0 0 4px 0;
  font-size: 26px;
  font-weight: 800;
  color: #14121f;
  letter-spacing: -0.01em;
}

.marketplace-subtitle {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

.marketplace-list-wrapper {
  margin-top: 8px;
}

/* =========================
   TOOLBAR PANEL
   Groups the level/semester selectors, search box and subject
   pills into one visually distinct inset panel, so they read as a
   single "filter your results" unit instead of loose floating rows.
========================= */
.marketplace-toolbar-panel {
  background: #faf9fd;
  border: 1px solid #efeef7;
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 24px;
}

/* =========================
   QUIZ GRID + CARDS
========================= */
.marketplace-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.marketplace-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  border-radius: 16px;
  background: #fff;
  border: 1px solid #eee;
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.04),
    0 8px 20px rgba(0, 0, 0, 0.03);
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

.marketplace-card:hover {
  transform: translateY(-2px);
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.06),
    0 12px 24px rgba(0, 0, 0, 0.06);
}

.marketplace-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.marketplace-card-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #1a1a1a;
}

.marketplace-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 10px;
  flex-wrap: wrap;
}

.owned-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* =========================
   BADGES
========================= */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-subject {
  background: #ede9fe;
  color: #6d28d9;
}

.badge-week {
  background: #eff6ff;
  color: #1d4ed8;
}

.badge-price {
  background: #ecfdf5;
  color: #047857;
}

.badge-owned {
  background: #dcfce7;
  color: #15803d;
}

/* =========================
   BUTTONS
========================= */
.btn-buy {
  border: none;
  background: #7c3aed;
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition:
    background 0.15s ease,
    transform 0.1s ease;
}

.btn-buy:hover {
  background: #6d28d9;
}

.btn-buy:active {
  transform: scale(0.98);
}

.btn-open {
  border: none;
  background: #eef2ff;
  color: #4338ca;
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease;
}

.btn-open:hover {
  background: #e0e7ff;
}

.btn-primary {
  border: none;
  background: #7c3aed;
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease;
}

.btn-primary:hover {
  background: #6d28d9;
}

.btn-primary:disabled {
  background: #c4b5fd;
  cursor: not-allowed;
}

.btn-secondary {
  border: 1px solid #ddd;
  background: #fff;
  color: #444;
  padding: 12px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: #f3f3f3;
}

/* =========================
   EMPTY STATE
========================= */
.marketplace-empty-state {
  text-align: center;
  padding: 48px 20px;
  border: 1px dashed #ddd;
  border-radius: 16px;
  background: #fafafa;
  color: #888;
  font-size: 15px;
  font-weight: 500;
}

/* =========================
   MOCK PURCHASE DIALOG
========================= */
.purchase-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.purchase-dialog-overlay[hidden] {
  display: none;
}

.purchase-dialog {
  background: #fff;
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
}

.purchase-dialog h3 {
  margin: 0 0 16px 0;
}

.purchase-dialog-details {
  background: #fafafa;
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}

.purchase-dialog-title {
  margin: 0 0 6px 0;
  font-weight: 700;
  font-size: 15px;
  color: #1a1a1a;
}

.purchase-dialog-price {
  margin: 0;
  font-weight: 600;
  color: #047857;
}

.purchase-dialog-notice {
  font-size: 12px;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 8px 10px;
  margin: 0 0 18px 0;
}

.purchase-dialog-actions {
  display: flex;
  gap: 12px;
}

.purchase-dialog-actions button {
  flex: 1;
}

/* =========================
   PURCHASE SUCCESS STATE
   Swapped into #purchaseDialogBox once a payment is confirmed —
   see showPurchaseSuccess() in marketplace.js. Deliberately loud
   and explicit (big check, clear copy) so it can't read as "did
   this actually work?".
========================= */
.purchase-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 4px 4px;
}

.purchase-success-check {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #10b981, #34d399);
  color: #fff;
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.35);
  margin-bottom: 16px;
  animation: purchase-success-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes purchase-success-pop {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  60% {
    transform: scale(1.12);
    opacity: 1;
  }
  100% {
    transform: scale(1);
  }
}

.purchase-success h3 {
  margin: 0 0 6px 0;
  color: #065f46;
}

.purchase-success-quiz {
  font-weight: 700;
  font-size: 15px;
  color: #1a1a1a;
  margin: 0 0 10px 0;
}

.purchase-success-note {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.5;
  margin: 0 0 20px 0;
}

.purchase-success .btn-primary {
  width: 100%;
  background: #10b981;
}

.purchase-success .btn-primary:hover {
  background: #059669;
}

/* =========================
   SEARCH + FILTERS
   (live inside .marketplace-toolbar-panel)
========================= */

.marketplace-toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 16px;
}

.marketplace-search {
  width: 100%;
  padding: 14px 18px;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  background: #fff;
  font-size: 15px;
  color: #111827;
  box-sizing: border-box;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

.marketplace-search::placeholder {
  color: #9ca3af;
}

.marketplace-search:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

.marketplace-filters {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.marketplace-filters::-webkit-scrollbar {
  display: none;
}

/* Subject filter pills — rendered by renderMarketplaceFilters() with
   class "marketplace-filter-btn" (data-subject buttons), styled the
   same as the old .filter-chip look. */
.marketplace-filter-btn,
.filter-chip {
  border: none;
  background: #fff;
  color: #374151;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  border: 1px solid #ececf5;
}

.marketplace-filter-btn:hover,
.filter-chip:hover {
  background: #f3effe;
  color: #6d28d9;
  border-color: #ded6fb;
}

.marketplace-filter-btn.active,
.filter-chip.active {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.25);
}

/* =========================
   SUBJECT SECTIONS
========================= */

.marketplace-section {
  margin-bottom: 40px;
}

.marketplace-section:last-child {
  margin-bottom: 0;
}

.marketplace-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid #ececec;
}

.marketplace-section-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: #111827;
}

.marketplace-section-count {
  font-size: 13px;
  color: #6b7280;
  font-weight: 600;
}

/* =========================
   SUMMARY
========================= */

/* 2x2 grid: Quizzes | Subjects on row 1, Purchased | Total Purchased
   on row 2. All four stat cards share the same look. */
.marketplace-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.marketplace-stat {
  background: #fff;
  border: 1px solid #ececec;
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.04);
  transition: transform 0.15s ease;
}

.marketplace-stat:hover {
  /* matches .marketplace-card's hover lift for a consistent feel
     across every card-like surface on the page. */
  transform: translateY(-2px);
}

.marketplace-stat-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  color: #7c3aed;
}

.marketplace-stat-label {
  display: block;
  margin-top: 6px;
  color: #6b7280;
  font-size: 14px;
}

/* Total Purchased now uses the plain .marketplace-stat styling
   above — no separate rules needed, it just sits in the grid like
   the other three. */

/* =========================================================
   LEVEL & SEMESTER SELECTORS
========================================================= */

.marketplace-level-semester-filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 16px;
}

.marketplace-level-filter,
.marketplace-semester-filter {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.marketplace-level-filter label,
.marketplace-semester-filter label {
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
}

.marketplace-level-filter select,
.marketplace-semester-filter select {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  background: white;
  color: #111827;
  font-size: 15px;
  font-weight: 500;
  box-sizing: border-box;
  transition: all 0.2s ease;
  cursor: pointer;
}

.marketplace-level-filter select:hover,
.marketplace-semester-filter select:hover {
  border-color: #c4b5fd;
}

.marketplace-level-filter select:focus,
.marketplace-semester-filter select:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 720px) {
  .marketplace-page {
    padding: 18px;
    border-radius: 18px;
  }

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

  .marketplace-card-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .owned-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-buy,
  .btn-open {
    width: 100%;
  }

  .purchase-dialog-actions {
    flex-direction: column;
  }

  .marketplace-level-semester-filters {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .marketplace-page {
    padding: 14px;
  }

  .marketplace-header h2 {
    font-size: 22px;
  }

  .marketplace-toolbar-panel {
    padding: 14px;
  }

  .marketplace-summary {
    gap: 10px;
  }

  .marketplace-stat {
    padding: 12px 8px;
    border-radius: 12px;
  }

  .marketplace-stat-value {
    font-size: 20px;
  }

  .marketplace-stat-label {
    margin-top: 4px;
    font-size: 12px;
  }
}
