/* ============================================================
   BOOK POP-UP: shared by category (category?c=N) and leaderboard.
   Moved from category.html. Markup and behavior: js/book-popup.js.
   ============================================================ */

/* ---------- Pop-up (native dialog) ---------- */
/* The button styles below set display, which would override the hidden attribute */
.wrc-dialog [hidden] { display: none !important; }
dialog.wrc-dialog {
  margin: auto; /* styles.css resets every margin to 0, which un-centers modal dialogs */
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  border: none;
  border-radius: 14px;
  padding: 0;
  box-shadow: 0 20px 60px rgba(10, 15, 30, 0.35);
  color: #1c2433;
}
dialog.wrc-dialog::backdrop { background: rgba(30, 36, 50, 0.6); }
.wrc-dialog .wrc-d-inner {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: relative;
}
.wrc-dialog .wrc-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 22px;
  background: #f1f4f8;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.wrc-dialog .wrc-close:focus-visible { outline: 3px solid #305384; outline-offset: 2px; }
.wrc-dialog .wrc-d-top { display: flex; gap: 24px; align-items: flex-start; } /* the cover keeps its 2:3 box when the text runs longer */
.wrc-dialog .wrc-d-cover {
  width: 150px;
  flex-shrink: 0;
  aspect-ratio: 2 / 3;
  background: #e3e9f1;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(20, 30, 50, 0.15);
  position: relative;
}
.wrc-dialog .wrc-d-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Shown only when a cover image fails (the grid's fallback styles don't reach the dialog) */
.wrc-dialog .wrc-cover-fallback {
  position: absolute; inset: 0; padding: 12px; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 6px; overflow: hidden;
  color: #305384; font-size: 13px; line-height: 1.25;
}
.wrc-dialog .wrc-cover-fallback strong { font-size: 16px; }
@media (max-width: 599px) {
  .wrc-dialog .wrc-cover-fallback { padding: 8px; font-size: 11px; }
  .wrc-dialog .wrc-cover-fallback strong { font-size: 12px; }
}
.wrc-dialog .wrc-d-text { display: flex; flex-direction: column; gap: 8px; padding-right: 44px; min-width: 0; }
.wrc-dialog h2 { margin: 0; font-size: 28px; line-height: 1.15; }
.wrc-dialog .wrc-d-author { font-size: 17px; color: #3f4a5c; }
.wrc-dialog .wrc-d-summary {
  font-size: 15px;
  line-height: 1.55;
  color: #3f4a5c;
  margin: 4px 0 0;
}
.wrc-dialog .wrc-d-summary.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 6;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.wrc-dialog .wrc-more {
  all: unset;
  cursor: pointer;
  color: #305384;
  font-weight: 700;
  font-size: 15px;
  /* Right edge, under the summary's closing ellipsis; full 44px tap area */
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 44px;
  min-width: 64px;
}
/* Preview (left) and More (right) share one row */
.wrc-dialog .wrc-d-actions { display: flex; align-items: center; gap: 12px; }
.wrc-dialog .wrc-more:focus-visible { outline: 2px solid #305384; outline-offset: 2px; }
.wrc-dialog .wrc-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  box-sizing: border-box;
}
.wrc-dialog .wrc-btn.primary { background: #305384; color: #fff; }
.wrc-dialog .wrc-btn.secondary { border: 2px solid #305384; color: #305384; background: #fff; }
.wrc-dialog .wrc-btn:focus-visible { outline: 3px solid #305384; outline-offset: 2px; }
.wrc-dialog .wrc-formats { border-top: 1px solid #dde3ec; }
.wrc-dialog .wrc-format {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 180px;
  gap: 12px;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid #eef1f5;
}
.wrc-dialog .wrc-format:last-child { border-bottom: none; }
.wrc-dialog .wrc-fmt-name { font-size: 16px; font-weight: 700; }
.wrc-dialog .wrc-fmt-status { font-size: 15px; font-weight: 700; }
.wrc-dialog .wrc-fmt-status.avail { color: #1d6b3a; }
.wrc-dialog .wrc-fmt-status.wait { color: #305384; }
.wrc-dialog .wrc-fmt-status.checked { color: var(--wrc-amber, #9a5b00); }
.wrc-dialog .wrc-fmt-status:not(.avail):not(.wait):not(.checked) { color: #3f4a5c; font-weight: 600; }
.wrc-dialog .wrc-fmt-where { font-size: 14px; color: #5a6474; font-weight: 400; }
.wrc-dialog .wrc-format .wrc-btn { width: 100%; cursor: pointer; font-family: inherit; }
.wrc-dialog .wrc-fmt-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wrc-dialog .wrc-fmt-actions { display: flex; gap: 8px; }
.wrc-dialog .wrc-fmt-actions .wrc-btn { flex: 1 1 0; padding: 0 10px; text-align: center; }
@media (max-width: 599px) {
  .wrc-dialog .wrc-d-inner { padding: 20px 16px; gap: 16px; }
  /* Cover beside title and author; summary, More and Preview run full width below.
     display: contents lets the text block's children join the grid. */
  .wrc-dialog .wrc-d-top {
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: auto auto 1fr;
    column-gap: 14px;
    row-gap: 4px;
  }
  .wrc-dialog .wrc-d-cover { width: 84px; grid-column: 1; grid-row: 1 / span 3; align-self: start; }
  .wrc-dialog .wrc-d-text { display: contents; }
  .wrc-dialog h2 { grid-column: 2; grid-row: 1; font-size: 21px; padding-right: 40px; }
  .wrc-dialog .wrc-d-author { grid-column: 2; grid-row: 2; font-size: 15px; }
  .wrc-dialog .wrc-d-summary { grid-column: 1 / -1; margin-top: 10px; }
  .wrc-dialog .wrc-d-summary.clamped { -webkit-line-clamp: 3; }
  .wrc-dialog .wrc-d-actions { grid-column: 1 / -1; margin-top: 4px; }
  /* Compact rows: format | status with location and call number under it | button */
  .wrc-dialog .wrc-format {
    grid-template-columns: 84px minmax(0, 1fr) 112px;
    column-gap: 10px;
    align-items: start;
    padding: 12px 0;
  }
  .wrc-dialog .wrc-fmt-name { font-size: 15px; line-height: 1.35; }
  .wrc-dialog .wrc-fmt-status { font-size: 14px; line-height: 1.35; }
  .wrc-dialog .wrc-fmt-where { font-size: 13px; overflow-wrap: anywhere; }
  .wrc-dialog .wrc-fmt-actions { flex-direction: column; gap: 6px; align-self: center; }
  .wrc-dialog .wrc-format .wrc-btn { min-height: 44px; font-size: 14px; padding: 4px 8px; line-height: 1.2; }
}

/* ---------- Leaderboard additions ---------- */
/* Submitter's review (4+ stars only); hidden when the book has none */
.wrc-dialog .wrc-d-review {
  background: #f1f4f8;
  border-radius: 8px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wrc-dialog .wrc-d-review-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.wrc-dialog .wrc-stars { display: flex; gap: 2px; color: #9a5b00; }
.wrc-dialog .wrc-stars svg { width: 18px; height: 18px; display: block; }
.wrc-dialog .wrc-d-reviewer { font-size: 15px; font-weight: 700; color: #305384; }
.wrc-dialog .wrc-d-review-text { margin: 0; font-size: 15px; line-height: 1.55; color: #1c2433; overflow-wrap: anywhere; }
/* The carousel's cached cover, shown under the large one until it loads */
.wrc-dialog .wrc-cover-preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
/* "Checking availability" and the no-data notes in the format area */
.wrc-dialog .wrc-format-msg { padding: 14px 0; font-size: 15px; color: #5a6474; }
@media (max-width: 599px) {
  .wrc-dialog .wrc-d-review { padding: 14px; }
  .wrc-dialog .wrc-stars svg { width: 16px; height: 16px; }
}

/* Interlibrary loan request (leaderboard, books not in the catalog) */
.wrc-dialog .wrc-ill { border-top: 1px solid #dde3ec; padding-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.wrc-dialog .wrc-ill-title { margin: 0; font-size: 18px; }
.wrc-dialog .wrc-ill-lead { margin: 0; font-size: 15px; line-height: 1.55; color: #3f4a5c; }
.wrc-dialog .wrc-ill-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.wrc-dialog .wrc-ill-field { display: flex; flex-direction: column; gap: 4px; }
.wrc-dialog .wrc-ill-field label { font-size: 14px; font-weight: 700; color: #1c2433; }
.wrc-dialog .wrc-ill-field input {
  font: inherit; font-size: 16px; min-height: 44px; padding: 8px 10px; box-sizing: border-box;
  border: 1px solid #8a96a8; border-radius: 6px; color: #1c2433; background: #fff; width: 100%;
}
.wrc-dialog .wrc-ill-field input:focus-visible { outline: 3px solid #305384; outline-offset: 1px; }
.wrc-dialog .wrc-ill-send { grid-column: 1 / -1; justify-self: start; cursor: pointer; font-family: inherit; border: none; }
.wrc-dialog .wrc-ill-send:disabled { opacity: 0.7; cursor: default; }
.wrc-dialog .wrc-ill-status { grid-column: 1 / -1; margin: 0; font-size: 15px; line-height: 1.5; }
.wrc-dialog .wrc-ill-status:empty { display: none; }
.wrc-dialog .wrc-ill-status.error { color: #9a3412; }
.wrc-dialog .wrc-ill-status.ok { color: #1d6b3a; font-weight: 700; }
.wrc-dialog .wrc-ill-note { grid-column: 1 / -1; margin: 0; font-size: 12px; color: #5a6474; }
.wrc-dialog .wrc-ill-note a { color: #5a6474; }
@media (max-width: 599px) {
  .wrc-dialog .wrc-ill-form { grid-template-columns: minmax(0, 1fr); }
  .wrc-dialog .wrc-ill-send { justify-self: stretch; }
}

/* ---------- Reader view (600px and up): Google's preview inside the pop-up ----------
   At least 48px of backdrop stays on every side, so a click outside always closes it
   (Esc can't: key presses inside Google's frame never reach this page). */
dialog.wrc-dialog.reading {
  width: min(920px, calc(100vw - 96px));
  height: calc(100vh - 96px);
  max-height: calc(100vh - 96px);
  overflow: hidden;
}
.wrc-dialog .wrc-reader { display: flex; flex-direction: column; height: 100%; }
.wrc-dialog .wrc-r-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 14px 14px 20px;
  border-bottom: 1px solid #dde3ec;
}
.wrc-dialog .wrc-r-back {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px 0 6px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 15px;
  color: #305384;
  flex-shrink: 0;
}
.wrc-dialog .wrc-r-back:focus-visible { outline: 3px solid #305384; outline-offset: 2px; }
.wrc-dialog .wrc-r-sep { width: 1px; height: 36px; background: #dde3ec; flex-shrink: 0; }
.wrc-dialog .wrc-r-cover {
  width: 34px;
  height: 51px;
  flex-shrink: 0;
  background: #e3e9f1;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(20, 30, 50, 0.15);
}
.wrc-dialog .wrc-r-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.wrc-dialog .wrc-r-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.wrc-dialog .wrc-r-title,
.wrc-dialog .wrc-r-author { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wrc-dialog .wrc-r-title { font-size: 17px; font-weight: 700; line-height: 1.2; }
.wrc-dialog .wrc-r-author { font-size: 14px; color: #3f4a5c; }
.wrc-dialog .wrc-r-hold { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.wrc-dialog .wrc-r-status { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.wrc-dialog .wrc-r-fmt { font-size: 13px; color: #5a6474; }
.wrc-dialog .wrc-r-state { font-size: 14px; font-weight: 700; color: #3f4a5c; }
.wrc-dialog .wrc-r-state.avail { color: #1d6b3a; }
.wrc-dialog .wrc-r-state.wait { color: #305384; }
.wrc-dialog .wrc-r-state.checked { color: var(--wrc-amber, #9a5b00); }
.wrc-dialog .wrc-r-close { position: static; flex-shrink: 0; }
.wrc-dialog .wrc-r-frame { flex: 1 1 auto; min-height: 0; background: #eef1f5; }
.wrc-dialog .wrc-r-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.wrc-dialog .wrc-r-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid #dde3ec;
  font-size: 13px;
  color: #5a6474;
}
.wrc-dialog .wrc-r-foot a {
  color: #305384;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
}
.wrc-dialog .wrc-r-foot a:focus-visible { outline: 2px solid #305384; outline-offset: 2px; }
/* Page behind the reader doesn't scroll (set on <html> by lockPage in book-popup.js) */
html.wrc-noscroll { overflow: hidden; }
html.wrc-noscroll.wrc-gutter { scrollbar-gutter: stable; }
/* Tablet widths: the separator and thumbnail give way first */
@media (max-width: 760px) {
  .wrc-dialog .wrc-r-sep,
  .wrc-dialog .wrc-r-cover { display: none; }
  .wrc-dialog .wrc-r-status { display: none; }
}
