/* Previously Purchased Widget — Right Sidebar (Vertical) */

.pp-widget {
  padding: 0;
}

.pp-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}

.pp-header-icon {
  font-size: 1.1rem;
}

.pp-header-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.pp-add-all-btn {
  margin-left: auto;
  padding: 0.35rem 0.75rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.pp-add-all-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.pp-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.pp-search-wrap {
  margin-bottom: var(--space-sm);
}

.pp-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.8rem;
  background: var(--bg-primary);
  transition: border-color 0.2s;
  box-sizing: border-box;
}

.pp-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 163, 165, 0.1);
}

.pp-loading {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: var(--space-md);
  text-align: center;
}

.pp-empty {
  text-align: center;
  padding: var(--space-lg) var(--space-sm);
  color: var(--text-muted);
}

.pp-empty p {
  margin: 0 0 0.25rem;
  font-size: 0.85rem;
}

.pp-empty-sub {
  font-size: 0.8rem !important;
  opacity: 0.7;
}

.pp-no-results {
  text-align: center;
  padding: var(--space-md);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Product list — VERTICAL stack */
.previously-purchased-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
  padding-right: 4px;
}

.previously-purchased-item {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem 0.7rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.previously-purchased-item:hover {
  border-color: var(--primary-light);
  box-shadow: var(--shadow-sm);
}

.pp-item-top {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.pp-name {
  font-family: 'Instrument Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pp-size {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.pp-item-number {
  font-family: 'Outfit', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.pp-item-bottom {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.pp-price {
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 700;
  min-width: 50px;
}

.pp-qty-ordered {
  font-size: 0.65rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Qty input row */
.pp-qty-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
}

.pp-qty-input {
  width: 42px;
  padding: 0.25rem 0.3rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  text-align: center;
  background: var(--bg-primary);
  transition: border-color 0.2s;
}

.pp-qty-input:focus {
  outline: none;
  border-color: var(--accent);
}

.pp-add-btn {
  padding: 0.3rem 0.6rem;
  font-family: 'Outfit', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  text-align: center;
}

.pp-add-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.pp-add-btn:active {
  transform: translateY(0);
}

.pp-add-btn.pp-added {
  background: #10b981 !important;
}

/* Scrollbar styling */
.previously-purchased-list::-webkit-scrollbar {
  width: 5px;
}

.previously-purchased-list::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: var(--radius-full);
}

.previously-purchased-list::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-full);
}

.previously-purchased-list::-webkit-scrollbar-thumb:hover {
  background: var(--primary-light);
}

/* ── Products page: 3-column layout ── */
.products-layout.has-pp-sidebar {
  grid-template-columns: 200px 1fr 280px;
}

#previouslyPurchasedSidebar {
  position: sticky;
  top: 100px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  border: 1px solid var(--border-light);
  max-height: calc(100vh - 120px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#previouslyPurchasedSidebar .pp-widget {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

#previouslyPurchasedSidebar .previously-purchased-list {
  flex: 1;
  min-height: 0;
}

/* ── Cart page: 2-column layout ── */
.cart-with-sidebar {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--space-lg);
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
}

.cart-main-col {
  min-width: 0;
}

.cart-pp-sidebar {
  position: sticky;
  top: 100px;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  border: 1px solid var(--border-light);
  max-height: calc(100vh - 120px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cart-pp-sidebar .pp-widget {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.cart-pp-sidebar .previously-purchased-list {
  flex: 1;
  min-height: 0;
}

/* ── Responsive ── */
@media (max-width: 1200px) {
  .products-layout.has-pp-sidebar {
    grid-template-columns: 200px 1fr;
  }

  #previouslyPurchasedSidebar {
    display: none;
  }

  /* Show inline fallback on smaller screens */
  #previouslyPurchasedWidget {
    display: block !important;
  }
}

@media (max-width: 900px) {
  .products-layout.has-pp-sidebar {
    grid-template-columns: 1fr;
  }

  .cart-with-sidebar {
    grid-template-columns: 1fr;
  }

  .cart-pp-sidebar {
    position: static;
    max-height: none;
  }

  .previously-purchased-list {
    max-height: 400px;
  }
}
