/* === Global === */
body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background-color: #0f1115;
  color: #e5e7eb;
}

.app-container {
  display: flex;
  /* Allow the page to scroll naturally while keeping the sidebar fixed */
  min-height: 100vh;
}

/* === Sidebar === */
.sidebar {
  background: #111827;
  color: #e5e7eb;
  width: 220px;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  box-shadow: 2px 0 6px rgba(0,0,0,0.4);
  /* Keep sidebar (logo + buttons) fixed while main content scrolls */
  position: sticky;
  top: 0;
  align-self: flex-start;
  height: 100vh;
}

.sidebar h2 {
  margin: 0 0 2rem 0;
  font-size: 1.4rem;
  text-align: center;
}

/* Make the logo clickable without changing its appearance */
.sidebar h2 a.logo-link {
  color: inherit;
  text-decoration: none;
  display: inline-block;
}
.sidebar h2 a.logo-link:hover {
  text-decoration: none;
  cursor: pointer;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-bottom {
  margin-top: auto;
  padding-top: 1rem;
}

.sidebar button,
.sidebar a.nav-btn {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 6px;
  color: #e5e7eb;
  padding: 0.7rem;
  cursor: pointer;
  width: 200px;
  font-size: 0.95rem;
  transition: background 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
  display: block;
  text-align: center;
}

.sidebar button:hover,
.sidebar a.nav-btn:hover {
  background: #2a3446;
}

.sidebar button.active,
.sidebar a.nav-btn.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

/* === Main Layout === */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #0f1115;
}

/* === Topbar === */
.topbar {
  /*
  background: #1a1d23;
  border-bottom: 1px solid #2b303b;
  */
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
  color: #f3f4f6;
}

.topbar form {
  display: flex;
  gap: 0.5rem;
}

input[type="text"] {
  padding: 0.6rem 1rem;
  border: 1px solid #374151;
  border-radius: 6px;
  width: 300px;
  font-size: 1rem;
  background: #111827;
  color: #e5e7eb;
}

button {
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover {
  background: #2563eb;
}

/* === Content === */
.content {
  flex: 1;
  overflow-y: auto;
  background-color: #0f1115;
  padding: 30px; /* add slight breathing room per request */
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* ============================================================
   SEARCH RESULTS GRID (Card Search View)
   ============================================================ */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
  overflow: visible;
  transform-style: preserve-3d;
}

.listing-card {
  background: #1a1d23;
  border: 1px solid #2b303b;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 5px rgba(0,0,0,0.32);
  transition: transform 0.15s ease;
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  justify-content: space-between;
}

.listing-card:hover {
  transform: translateY(-3px);
}

.listing-card img {
  width: 100%;
  height: 200px;
  object-fit: contain;
  background-color: #111827;
  display: block;
  padding: 10px;
}

.card-content {
  padding: 1rem;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card-content h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
  font-weight: 600;
  color: #f3f4f6;
}

.card-details {
  line-height: 14px;
  font-size: 12px;
  padding: 0;
  margin: 0 0 4px 0;
  color: #9ca3af;
}

a {
  text-decoration: none;
  color: #60a5fa;
  font-weight: 500;
}

a:hover {
  text-decoration: underline;
}

/* === Chart === */
#priceChart {
  width: 100%;
  height: 400px;
  box-sizing: border-box;
  background: #1a1d23;
  border-radius: 10px;
  padding: 1rem;
  border: 1px solid #2b303b;
  color: #e5e7eb;
}

/* ============================================================
   REFERENCE LIBRARY GRID (Reference Library View)
   ============================================================ */
.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.6rem;
  justify-items: center;
  align-items: start;
  padding: 0.75rem;
}

.listing-card.reference {
  width: 150px;
  background: none;
  border: none;
  box-shadow: none;
  perspective: 1000px;
  overflow: visible !important;
  transition: transform 0.15s ease;
}

.listing-card.reference:hover {
  transform: scale(1.04);
}

.listing-card.reference .image-flip {
  position: relative;
  width: 100%;
  height: 206px;
  transform-style: preserve-3d;

  /* slower return */
  transition: transform 0.8s ease;
  cursor: pointer;
  transform-origin: center;
}

.listing-card.reference:hover .image-flip {
  /* faster flip */
  transition: transform 0.4s ease;
  transform: rotateY(180deg);
}

.listing-card.reference .image-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  overflow: hidden;
  border-radius: 6px;
}

.listing-card.reference .image-face.back {
  transform: rotateY(180deg);
}

.listing-card.reference .image-face img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #1a1d23;
  display: block;
  border: 1px solid #2b303b;
      margin-left: -10px;
    margin-top: -12px;
}

.listing-card.reference .card-content {
  text-align: center;
  margin-top: 4px;
  padding: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: #e5e7eb;
}

/* ============================================================
   SERIES SECTIONS
   ============================================================ */
.series-section {
  border: 1px solid #2b303b;
  border-radius: 8px;
  background: #1a1d23;
  margin-bottom: 1.25rem;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,0.25);
}

.series-header {
  background: #3b82f6;
  color: #fff;
  padding: 0.75rem 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.series-header:hover {
  background: #2563eb;
}

.series-cards {
  display: none;
  padding: 1rem;
}

.series-section.open .series-cards {
  display: grid;
}

.series-section.open .series-header::after {
  content: " ▲";
}

.series-section .series-header::after {
  content: " ▼";
  float: right;
  opacity: 0.8;
}

/* ============================================================
   CARD DETAIL VIEW
   ============================================================ */
.card-detail-container {
  padding: 1rem;
  color: #e5e7eb;
}

.card-detail-container h2 {
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
}

.card-images {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.card-images img {
  border-radius: 8px;
  border: 1px solid #2b303b;
  background: #1a1d23;
  max-height: 280px;
  object-fit: contain;
}

#listingContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

/* ============================================================
   RESPONSIVE TWEAKS (mobile/tablet) — reacts to window resize
   ============================================================ */
@media (max-width: 900px) {
  .sidebar {
    width: 180px;
    padding: 1rem;
  }
  .sidebar button {
    width: 100%;
  }
  .topbar {
    padding: 0.5rem 1rem;
  }
  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.9rem;
  }
  .listing-card img {
    height: 180px;
  }
  .card-images img {
    max-height: 240px;
  }
}

@media (max-width: 600px) {
  .app-container {
    height: auto;
    min-height: 100vh;
  }
  .sidebar {
    width: 150px;
    padding: 0.75rem;
  }
  .topbar {
    padding: 0.5rem 0.75rem;
  }
  .results-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
  }
  .listing-card img {
    height: 160px;
  }
  .card-images {
    gap: 0.6rem;
  }
  .card-images img {
    max-height: 200px;
  }
}

/* Attribute-driven tweaks using device flag */
body[data-device="mobile"] .results-grid {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
body[data-device="mobile"] .listing-card img {
  height: 150px;
}
body[data-device="mobile"] .topbar {
  padding: 0.5rem;
}