/* =====================================================================
   OUR BOOKS PAGE — dedicated stylesheet
   Loaded on our-books.html only, after style.css.
   Uses the shared theme variables defined in style.css (:root).
   ===================================================================== */

/* 🔥 ROOT-CAUSE FIX: box-sizing reset (scoped to this page only, via
   style.css not setting one globally). Without this, any element with
   width:100% AND padding renders WIDER than its container (padding gets
   added on top of the 100%, instead of eating into it) — that's exactly
   what was pushing the Kindergarten/Other Classes filter boxes sideways,
   and cutting off popup buttons/content on small screens. */
*, *::before, *::after {
  box-sizing: border-box;
}

/* ================= PAGE LAYOUT (sticky footer) ================= */
html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
}

footer {
  margin-top: auto;
}

/* ================= FILTERS — "choose a category" card ================= */
.book-filters-pro {
  display: flex;
  justify-content: center;
  padding: 10px 20px 30px;
}

.filters-card {
  width: 100%;
  max-width: 720px;
  background: var(--paper);
  border-radius: 20px;
  padding: 34px 36px 28px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.28);
  border: 1px solid rgba(0,0,0,0.04);
}

.filters-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 22px;
}

.filter-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 16px;
  padding: 22px 16px 18px;
  transition: border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.filter-group:hover,
.filter-group:focus-within {
  border-color: var(--gold);
  box-shadow: 0 12px 26px rgba(122,31,43,0.12);
  transform: translateY(-2px);
}

.filter-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(122,31,43,0.08);
  font-size: 20px;
  margin-bottom: 12px;
}

.filter-group label {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--maroon);
  margin-bottom: 12px;
}

.select-wrap {
  position: relative;
  width: 100%;
}

.select-wrap::after {
  content: "";
  position: absolute;
  right: 16px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--maroon);
  border-bottom: 2px solid var(--maroon);
  transform: translateY(-65%) rotate(45deg);
  pointer-events: none;
}

.filter-group select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding: 11px 34px 11px 16px;
  font-size: 14px;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--paper-text);
  border-radius: 10px;
  border: 1px solid var(--gold-soft);
  background: var(--paper);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.filter-group select:hover {
  border-color: var(--maroon);
}

.filter-group select:focus {
  outline: none;
  border-color: var(--maroon);
  box-shadow: 0 0 0 3px rgba(122,31,43,0.12);
}

.filter-group select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.filters-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  flex-shrink: 0;
}

.filters-divider span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--maroon);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  box-shadow: 0 6px 14px rgba(122,31,43,0.35);
}

.filters-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
}

.reset-btn {
  padding: 11px 26px;
  border: none;
  background: var(--maroon);
  color: #fff;
  border-radius: 30px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  transition: background 0.25s ease, transform 0.2s ease, box-shadow 0.25s ease;
  box-shadow: 0 10px 22px rgba(122,31,43,0.3);
}

.reset-btn:hover {
  background: var(--maroon-light);
  transform: translateY(-1px);
}

@media (max-width: 600px) {
  .filters-card {
    padding: 26px 18px 22px;
    border-radius: 16px;
  }

  .filters-row {
    flex-direction: column;
    gap: 14px;
  }

  .filters-divider {
    width: 100%;
    padding: 2px 0;
  }

  .filter-group {
    width: 100%;
  }
}

/* ================= BOOK GRID ================= */
.book-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 180px));
  gap: 26px;
  justify-content: center;
  padding: 10px 30px 60px;
  justify-items: center;
}

.book-card {
  cursor: pointer;
  text-align: center;
  background: #ffffff;
  color: #111;
  width: 100%;
  max-width: 180px;
  border-radius: 12px;
  padding: 14px 12px 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  box-shadow: 0 12px 26px rgba(0,0,0,0.18);
  border-top: 3px solid transparent;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.book-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 38px rgba(122,31,43,0.22);
  border-top-color: var(--maroon);
}

.book-card img {
  width: 100%;
  height: 170px;
  object-fit: contain;
  border-radius: 8px;
  background: #f1f1f1;
  margin-bottom: 10px;
}

.book-card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin: 4px 0 4px;
  line-height: 1.25;
  color: #1a1a1a;
}

.book-card .book-code {
  display: inline-block;
  margin: 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--maroon);
  background: rgba(122,31,43,0.08);
  padding: 3px 10px;
  border-radius: 20px;
}

@media (max-width: 1024px) {
  .book-grid {
    grid-template-columns: repeat(3, minmax(0, 180px));
  }
}

@media (max-width: 600px) {
  .book-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    padding: 10px 16px 50px;
  }
  .book-card {
    max-width: 100%;
  }
}

/* ================= BOOK DETAIL POPUP ================= */
/* scoped under .book-popup so it never collides with the legacy
   .popup-overlay product-popup styles that live in style.css */

.book-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.book-popup.hidden {
  display: none;
}

.book-popup .popup-box {
  background: #ffffff;
  width: 720px;
  max-width: 92%;
  max-height: 80vh;
  display: flex;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  box-shadow: 0 30px 70px rgba(0,0,0,0.5);
}

.book-popup .close-popup {
  position: absolute;
  top: 10px;
  right: 15px;
  width: 30px;
  height: 30px;
  line-height: 30px;
  text-align: center;
  font-size: 20px;
  cursor: pointer;
  background: var(--maroon);
  color: #fff;
  border-radius: 50%;
  z-index: 10;
  pointer-events: auto;
}

.book-popup .popup-left {
  width: 40%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f2ea;
}

.book-popup .popup-left img {
  width: 90%;
  height: 90%;
  object-fit: contain;
}

.book-popup .popup-right {
  width: 60%;
  padding: 24px;
  overflow-y: auto;
  min-height: 0; /* 🔥 fixes flexbox scroll bug: without this, overflow-y:auto
                     is silently ignored and content just gets clipped */
  display: flex;
  flex-direction: column;
}

.book-popup .popup-right h2 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.4rem;
  margin: 0 0 4px;
  color: #111;
}

.book-popup .popup-code {
  font-size: 13px;
  color: #666;
  margin: 0 0 10px;
}

.book-popup .popup-heading {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--maroon);
  margin: 8px 0 4px;
}

.book-popup .popup-desc {
  font-size: 14px;
  line-height: 1.6;
  color: #333;
  margin: 0;
}

.book-popup .popup-price {
  font-size: 17px;
  font-weight: 700;
  margin: 14px 0 16px;
  color: #111;
}

/* ================= POPUP ACTIONS ROW (View PDF / Add to Cart / Chapters) ================= */
.popup-actions-row {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.popup-action-btn {
  flex: 1 1 0;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 10px;
  border-radius: 14px;
  border: 1.5px solid var(--gold-soft);
  background: #ffffff;
  color: var(--maroon);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.popup-action-btn .icon {
  font-size: 20px;
  line-height: 1;
}

.popup-action-btn:hover {
  border-color: var(--maroon);
  transform: translateY(-2px);
  box-shadow: 0 10px 20px rgba(122,31,43,0.15);
}

.popup-action-btn.primary {
  background: var(--maroon);
  border-color: var(--maroon);
  color: #fff;
  box-shadow: 0 10px 22px rgba(122,31,43,0.32);
}

.popup-action-btn.primary:hover {
  background: var(--maroon-light);
  border-color: var(--maroon-light);
}

/* Mobile layout for the detail popup */
@media (max-width: 600px) {
  .book-popup .popup-box {
    flex-direction: column;
    width: 92%;
    height: auto;
    max-height: 90vh;
  }

  .book-popup .popup-left {
    width: 100%;
    padding: 10px;
  }

  .book-popup .popup-left img {
    width: 100%;
    height: 220px;
    object-fit: contain;
  }

  .book-popup .popup-right {
    width: 100%;
    padding: 16px;
    text-align: left;
  }

  .book-popup .popup-right h2 {
    font-size: 18px;
    margin-bottom: 6px;
  }

  .book-popup .popup-desc {
    font-size: 14px;
    margin-bottom: 6px;
  }

  .book-popup .popup-price {
    font-size: 16px;
    margin: 10px 0;
  }

  /* actions row: keep as a neat row of 3 even on mobile */
  .book-popup .popup-right {
    display: flex;
    flex-direction: column;
  }

  .popup-actions-row {
    order: 1;
    margin-top: 14px;
  }

  .popup-action-btn {
    min-width: 0;
    padding: 12px 6px;
    font-size: 10.5px;
  }

  .popup-action-btn .icon {
    font-size: 18px;
  }

  .chapters-panel {
    order: 2;
    width: 100%;
  }

  /* keep buttons reliably tappable above the image/overlay */
  .book-popup,
  .book-popup .popup-box,
  .book-popup .popup-right {
    pointer-events: auto;
  }

  #addToCartBtn,
  #viewPdfBtn,
  #chaptersBtn {
    position: relative;
    z-index: 10;
    pointer-events: auto;
    touch-action: manipulation;
  }
}

/* ================= CHAPTERS / AUDIO / VIDEO / WORKSHEET PANEL ================= */
.chapters-panel {
  margin-top: 16px;
  border-top: 1px solid rgba(0,0,0,0.1);
  padding-top: 14px;
}

.chapters-panel.hidden {
  display: none;
}

.chapter-row {
  margin-bottom: 10px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
}

.chapter-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  padding: 12px 14px;
  border: none;
  background: #f8f6f0;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 13px;
  color: #1a1a1a;
  transition: background 0.2s ease;
}

.chapter-toggle:hover {
  background: #f1ece0;
}

.chapter-toggle .chapter-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.chapter-toggle .chapter-label {
  flex: 1;
}

.chapter-toggle .chapter-arrow {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--maroon);
  transition: transform 0.25s ease;
}

.chapter-toggle.open .chapter-arrow {
  transform: rotate(180deg);
}

.chapter-toggle.open {
  background: rgba(122,31,43,0.06);
}

.chapter-resources {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: #fffdf9;
}

.chapter-resources.hidden {
  display: none;
}

.resource-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 22px;
  border: none;
  color: #fff;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(0,0,0,0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.resource-btn .res-icon {
  font-size: 15px;
  line-height: 1;
}

.resource-btn:hover {
  transform: translateY(-2px);
  filter: brightness(1.05);
  box-shadow: 0 10px 20px rgba(0,0,0,0.18);
}

/* distinct color per resource type, for quick recognition */
.resource-btn.resource-audio { background: var(--ink-soft); }
.resource-btn.resource-video { background: var(--maroon); }
.resource-btn.resource-worksheet { background: var(--gold); color: #3a2e08; box-shadow: 0 6px 14px rgba(201,162,39,0.35); }

.inline-audio-player {
  width: 100%;
  margin-top: 6px;
}

.inline-audio-player audio {
  width: 100%;
  height: 38px;
}

.no-resource {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #888;
  font-style: italic;
  margin: 0;
}

.no-resource .icon {
  font-size: 14px;
  font-style: normal;
}
