/* ==========================================================================
   E-Books / Digital Library Catalog Block Styles
   ========================================================================== */

.ebook-catalog-section {
  position: relative;
  width: 100%;
  margin: 1.5rem 0 2.5rem 0;
  background-color: var(--eb-section-bg, transparent);
  box-sizing: border-box;
}

.ebook-catalog-section *,
.ebook-catalog-section *::before,
.ebook-catalog-section *::after,
.content .ebook-catalog-section *,
.content .ebook-catalog-section *::before,
.content .ebook-catalog-section *::after {
  box-sizing: border-box !important;
}

/* Neutralize legacy-global.css (.content * + * { margin-top: 1.5em }) which pushes buttons and text spans down */
.content .ebook-catalog-section * + *,
.ebook-catalog-section * + * {
  margin-top: 0;
}

.content .ebook-catalog-section .ebook-view-toggle,
.content .ebook-catalog-section .ebook-view-toggle *,
.content .ebook-catalog-section .ebook-view-toggle * + *,
.content .ebook-catalog-section .ebook-btn-read,
.content .ebook-catalog-section .ebook-btn-read *,
.content .ebook-catalog-section .ebook-btn-read * + *,
.content .ebook-catalog-section .ebook-btn-download,
.content .ebook-catalog-section .ebook-btn-download *,
.content .ebook-catalog-section .ebook-search-form,
.content .ebook-catalog-section .ebook-search-form *,
.content .ebook-catalog-section .ebook-search-form * + * {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Section Header */
.ebook-section-header {
  margin-bottom: 1.5rem;
}
.ebook-section-header.text-center {
  text-align: center;
}
.ebook-section-header.text-right {
  text-align: right;
}
.ebook-section-header.text-left {
  text-align: left;
}

.ebook-heading {
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 0.5rem 0;
  color: var(--eb-heading-color, #1e293b);
}

.ebook-subheading {
  font-size: 1rem;
  line-height: 1.5;
  color: var(--eb-subheading-color, #64748b);
  margin: 0;
}

/* ==========================================================================
   Top Controls Bar: Search & View Mode Toggle (Aligned & Height-Matched)
   ========================================================================== */

.ebook-controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

.ebook-search-form {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  height: 2.85rem;
  flex: 1 1 340px;
  max-width: 540px;
  margin: 0 !important;
  padding: 0 !important;
}

.ebook-search-wrapper {
  position: relative;
  flex: 1 1 auto;
  height: 2.85rem;
  display: flex;
  align-items: center;
}

.ebook-search-icon {
  position: absolute;
  left: 1.15rem;
  top: 50%;
  transform: translateY(-50%);
  color: #8c8285;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 2;
}

.ebook-search-icon svg {
  display: block !important;
  width: 18px !important;
  height: 18px !important;
}

.ebook-search-input {
  display: block !important;
  width: 100% !important;
  height: 2.85rem !important;
  line-height: 2.85rem !important;
  padding: 0 2.5rem 0 2.85rem !important;
  font-size: 0.95rem !important;
  color: var(--eb-search-text, #1e293b);
  background-color: var(--eb-search-bg, #ffffff);
  border: 1px solid var(--eb-search-border, #e5d7d8);
  border-radius: 9999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  outline: none;
  margin: 0 !important;
  box-sizing: border-box !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ebook-search-input::placeholder {
  color: #8e8083;
}

.ebook-search-input:focus {
  border-color: var(--eb-btn-bg, #5b1425);
  box-shadow: 0 0 0 3px rgba(91, 20, 37, 0.12);
}

.ebook-search-clear {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  padding: 0.3rem;
  cursor: pointer;
  color: #8c8285;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: color 0.15s, background-color 0.15s;
  z-index: 2;
}

.ebook-search-clear:hover {
  color: #1e293b;
  background-color: rgba(0, 0, 0, 0.05);
}

.ebook-search-button {
  height: 2.85rem !important;
  line-height: 2.85rem !important;
  padding: 0 1.5rem !important;
  font-size: 0.9rem !important;
  font-weight: 600 !important;
  color: var(--eb-btn-text, #ffffff) !important;
  background-color: var(--eb-btn-bg, #5b1425) !important;
  border: none !important;
  border-radius: 9999px !important;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(91, 20, 37, 0.25);
  transition: background-color 0.15s ease, transform 0.15s ease;
  flex-shrink: 0 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

.ebook-search-button:hover {
  background-color: var(--eb-btn-hover, #7b1d34) !important;
  transform: translateY(-1px);
}

/* View Mode Toggle (Height & Alignment Matched) */
.ebook-view-toggle {
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  gap: 0.35rem !important;
  height: 2.85rem !important;
  background-color: #ffffff;
  border: 1px solid var(--eb-search-border, #e5d7d8);
  border-radius: 12px;
  padding: 0.25rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
  margin: 0 !important;
}

.ebook-view-btn {
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  height: calc(2.85rem - 0.5rem) !important;
  padding: 0 0.95rem !important;
  font-size: 0.85rem !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  color: #64748b !important;
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  box-sizing: border-box !important;
  flex-shrink: 0 !important;
}

.ebook-view-btn svg {
  display: inline-block !important;
  flex-shrink: 0 !important;
  width: 16px !important;
  height: 16px !important;
  stroke: currentColor;
}

.ebook-view-btn span {
  display: inline-block !important;
  white-space: nowrap !important;
  line-height: 1 !important;
}

.ebook-view-btn.is-active {
  background-color: var(--eb-btn-bg, #5b1425) !important;
  color: var(--eb-btn-text, #ffffff) !important;
  box-shadow: 0 2px 4px rgba(91, 20, 37, 0.2);
}

.ebook-view-btn.is-active svg {
  stroke: var(--eb-btn-text, #ffffff) !important;
}

/* ==========================================================================
   Catalog Grid & List Layout (Auto-Fill to Prevent Single Card Stretching)
   ========================================================================== */

.ebook-catalog-container.view-grid {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
  justify-content: flex-start;
  width: 100%;
}

@media (min-width: 640px) {
  .ebook-catalog-container.view-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
  }
}

@media (min-width: 1280px) {
  .ebook-catalog-container.view-grid.cols-4 {
    grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
  }
}

/* Inside Two-Column Layout (.mainContent_well) */
.mainContent_well .ebook-catalog-container.view-grid {
  grid-template-columns: repeat(auto-fill, minmax(280px, 340px));
  justify-content: flex-start;
}

/* Inside Sidebar (.mainContent_aside) */
.mainContent_aside .ebook-catalog-container.view-grid {
  grid-template-columns: 1fr !important;
}

/* List View */
.ebook-catalog-container.view-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

/* ==========================================================================
   E-Book Card Component (Balanced Dimensions & Natural Sizing)
   ========================================================================== */

.ebook-card {
  background-color: var(--eb-card-bg, #ffffff);
  border: 1px solid var(--eb-card-border, #ebe4e5);
  border-radius: var(--eb-card-radius, 16px);
  padding: 1.15rem;
  display: flex;
  align-items: stretch;
  gap: 1rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  box-sizing: border-box;
}

/* Limit card width in grid view so a single item never stretches to 1000px */
.ebook-catalog-container.view-grid .ebook-card {
  width: 100%;
  max-width: 350px;
}

/* Shadows */
.ebook-catalog-container.shadow-none .ebook-card {
  box-shadow: none;
}
.ebook-catalog-container.shadow-subtle .ebook-card {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.03), 0 1px 3px rgba(0, 0, 0, 0.02);
}
.ebook-catalog-container.shadow-medium .ebook-card {
  box-shadow: 0 10px 22px -4px rgba(0, 0, 0, 0.06), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
}

.ebook-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px -4px rgba(91, 20, 37, 0.08), 0 4px 8px -2px rgba(0, 0, 0, 0.03);
  border-color: rgba(91, 20, 37, 0.25);
}

/* ==========================================================================
   Realistic 3D Book Cover
   ========================================================================== */

.ebook-cover-wrapper {
  position: relative;
  flex-shrink: 0;
  width: 104px;
  height: 148px;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12), 0 1px 3px rgba(0, 0, 0, 0.08);
  background-color: #f8fafc;
  box-sizing: border-box;
}

/* Spine 3D Lighting Effect */
.ebook-book-spine {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 10px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.28) 0%, rgba(255, 255, 255, 0.15) 25%, transparent 60%);
  z-index: 5;
  pointer-events: none;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
}

.ebook-cover-inner {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  border-radius: 8px;
  overflow: hidden;
}

.ebook-cover-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}

.ebook-generated-cover {
  width: 100%;
  height: 100%;
  padding: 0.75rem 0.5rem 0.65rem 0.85rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ebook-cover-title {
  font-family: inherit;
  font-size: 0.825rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.ebook-cover-graphic {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  opacity: 0.95;
}

/* ==========================================================================
   Book Details & Action Buttons (Aligned & Non-Overflowing)
   ========================================================================== */

.ebook-details-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1 1 auto;
  min-width: 0;
}

.ebook-meta-header {
  margin-bottom: 0.25rem;
}

.ebook-book-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  margin: 0 0 0.35rem 0;
  color: var(--eb-title-color, #1e293b);
  word-break: break-word;
}

.ebook-category-tag {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
  border-radius: 9999px;
  background-color: var(--eb-tag-bg, #fde8e8);
  color: var(--eb-tag-text, #5b1425);
  margin-bottom: 0.35rem;
}

.ebook-book-desc {
  font-size: 0.825rem;
  line-height: 1.4;
  color: var(--eb-desc-color, #64748b);
  margin: 0.25rem 0 0.65rem 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Actions Row (Stays Cleanly Inside the Card) */
.ebook-actions-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.5rem;
}

/* "Read Now" Button with High-Specificity Text & Icon Rules */
.ebook-btn-read,
.ebook-catalog-section a.ebook-btn-read,
.mainContent .ebook-catalog-section a.ebook-btn-read {
  display: inline-flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  height: 2.25rem !important;
  padding: 0 0.95rem !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
  line-height: 1 !important;
  white-space: nowrap !important;
  vertical-align: middle !important;
  color: var(--eb-btn-text, #ffffff) !important;
  background-color: var(--eb-btn-bg, #5b1425) !important;
  border: none !important;
  border-radius: 9999px !important;
  text-decoration: none !important;
  box-shadow: 0 2px 4px rgba(91, 20, 37, 0.2) !important;
  transition: background-color 0.15s ease, transform 0.15s ease !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

.ebook-btn-read span,
.mainContent .ebook-catalog-section a.ebook-btn-read span {
  display: inline-block !important;
  color: var(--eb-btn-text, #ffffff) !important;
  white-space: nowrap !important;
  line-height: 1 !important;
  vertical-align: middle !important;
  margin: 0 !important;
}

.ebook-btn-read svg,
.mainContent .ebook-catalog-section a.ebook-btn-read svg {
  display: inline-block !important;
  stroke: var(--eb-btn-text, #ffffff) !important;
  color: var(--eb-btn-text, #ffffff) !important;
  flex-shrink: 0 !important;
  vertical-align: middle !important;
  margin: 0 !important;
}

.ebook-btn-read:hover,
.mainContent .ebook-catalog-section a.ebook-btn-read:hover {
  background-color: var(--eb-btn-hover, #7b1d34) !important;
  transform: translateY(-1px);
}

/* Download Button */
.ebook-btn-download,
.ebook-catalog-section a.ebook-btn-download,
.mainContent .ebook-catalog-section a.ebook-btn-download {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 2.25rem !important;
  height: 2.25rem !important;
  border: 1px solid var(--eb-card-border, #ebe4e5) !important;
  border-radius: 50% !important;
  color: #4a5568 !important;
  background-color: #faf5f5 !important;
  text-decoration: none !important;
  transition: all 0.15s ease !important;
  flex-shrink: 0 !important;
  box-sizing: border-box !important;
}

.ebook-btn-download svg,
.mainContent .ebook-catalog-section a.ebook-btn-download svg {
  display: inline-block !important;
  stroke: #4a5568 !important;
  flex-shrink: 0 !important;
  vertical-align: middle !important;
  margin: 0 !important;
}

.ebook-btn-download:hover,
.mainContent .ebook-catalog-section a.ebook-btn-download:hover {
  border-color: var(--eb-btn-bg, #5b1425) !important;
  color: var(--eb-btn-bg, #5b1425) !important;
  background-color: #ffffff;
  transform: translateY(-1px);
}

.ebook-btn-download:hover svg,
.mainContent .ebook-catalog-section a.ebook-btn-download:hover svg {
  stroke: var(--eb-btn-bg, #5b1425) !important;
}

/* ==========================================================================
   List View Custom Styles
   ========================================================================== */

.ebook-catalog-container.view-list .ebook-card {
  max-width: 100% !important;
  align-items: center;
  padding: 1.15rem 1.5rem;
}

.ebook-catalog-container.view-list .ebook-details-wrapper {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1.5rem;
  min-height: auto;
}

.ebook-catalog-container.view-list .ebook-book-desc {
  -webkit-line-clamp: 3;
}

/* ==========================================================================
   Pagination
   ========================================================================== */

.ebook-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 2.5rem;
}

.ebook-page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #4a5568;
  background-color: #ffffff;
  border: 1px solid var(--eb-search-border, #e5d7d8);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ebook-page-btn:hover {
  border-color: var(--eb-btn-bg, #5b1425);
  color: var(--eb-btn-bg, #5b1425);
  background-color: #faf5f5;
}

.ebook-page-btn.is-active {
  background-color: var(--eb-btn-bg, #5b1425);
  color: var(--eb-btn-text, #ffffff) !important;
  border-color: var(--eb-btn-bg, #5b1425);
  box-shadow: 0 2px 6px rgba(91, 20, 37, 0.25);
}

/* Empty State */
.ebook-empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background-color: #faf5f5;
  border: 1px dashed #e2cbcd;
  border-radius: 16px;
  margin-top: 1rem;
}

.ebook-empty-text {
  font-size: 1.05rem;
  color: #4a5568;
  margin: 0 0 1rem 0;
}

.ebook-reset-button {
  display: inline-flex;
  align-items: center;
  padding: 0.6rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #ffffff !important;
  background-color: var(--eb-btn-bg, #5b1425);
  border: none;
  border-radius: 9999px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.ebook-reset-button:hover {
  background-color: var(--eb-btn-hover, #7b1d34);
}
