/*
 * Additional UX/UI overrides to improve section headings, image aspect ratio
 * handling and reduce layout shifts on the public site. This file is
 * loaded after the core app.css and theme styles, so any rules here
 * will override earlier definitions. See README_PATCH.txt for details.
 */

/* Section heading layout: wraps the H2 and optional link in a flex row */
.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 26px 0 14px;
}
.section-head h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  font-weight: 800;
}

/* A subtle horizontal divider between homepage sections */
.section-divider {
  height: 1px;
  background: rgba(0,0,0,.08);
  margin: 10px 0 18px;
}

/* Ensure card media preserves a 2:3 aspect ratio and reserves space */
.card__media {
  aspect-ratio: 2 / 3;
  height: auto !important;
  background: rgba(0,0,0,.04);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  /* Override the default flex layout so images fill the reserved area without centering */
  display: block;
}
/* Images fill their container and fade in once loaded */
.card__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* No opacity manipulation here; images will display normally when loaded */
}

/* Book cover on detail page uses the same aspect ratio */
.book-cover {
  aspect-ratio: 2 / 3;
  height: auto !important;
  background: rgba(0,0,0,.04);
  border-radius: var(--radius);
  overflow: hidden;
}
.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* No opacity manipulation here; images will display normally when loaded */
}

/* Adjust hero layout when tip card is disabled */
.hero.no-tip {
  /* collapse to single column to avoid unused space */
  grid-template-columns: 1fr;
}
.hero.no-tip .hero__card {
  display: none;
}

/* Improve layout for summary and tags sections on book detail page */
.book-summary,
.book-tags {
  max-width: 900px;
  margin: 0 auto 20px;
  padding: 16px;
  line-height: 1.6;
}
.book-summary p {
  line-height: 1.7;
  margin-bottom: 12px;
}
.book-tags > div {
  margin-bottom: 6px;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.book-tags strong {
  margin-right: 4px;
}

/* Layout for book info grid: cover/actions left, content right */
.book-info-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  max-width: 1200px;
  margin: 20px auto;
  align-items: flex-start;
}
@media (max-width: 900px) {
  .book-info-grid {
    grid-template-columns: 1fr;
  }
}
/* Remove extra top margins on summary/tags inside grid */
.book-info-grid .book-summary,
.book-info-grid .book-tags {
  margin-top: 0;
}

.book-left .book-cover {
  aspect-ratio: 2 / 3;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0,0,0,.04);
}
.book-left .book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-left .book-actions {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.book-right .book-head {
  margin-bottom: 14px;
}
.book-right .book-title {
  margin: 0 0 6px;
  line-height: 1.15;
}
.book-right .book-author {
  margin-bottom: 10px;
}
.book-right .book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 6px;
}
.book-right .book-meta .chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,.04);
  border: 1px solid rgba(0,0,0,.06);
}
.book-right .rating-summary {
  margin-top: 6px;
}

/* Compact card grid: show more books per row and reduce card padding */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.card__body {
  padding: 10px;
}
.card__title {
  font-size: 16px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card__meta {
  font-size: 13px;
}

/* Navigation categories dropdown in header */
.nav .nav-cats {
  position: relative;
}
.nav .nav-cats > span {
  cursor: pointer;
  padding: 0 6px;
}
.nav .nav-cats__dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 0;
  min-width: 200px;
  z-index: 1000;
}
.nav .nav-cats:hover .nav-cats__dropdown {
  display: block;
}
.nav .nav-cats__dropdown a {
  display: block;
  padding: 6px 14px;
  white-space: nowrap;
}
.nav .nav-cats__dropdown a:hover {
  background: rgba(0,0,0,.04);
}