/* ============================================================
   Ztor 2.0 — LIBRARY / CONTENT family refinement layer
   Mobbin-benchmarked rework. Linked AFTER components.css on:
     screening-room · database · popcorn · events · news · profile
   EVERY rule scoped under body.rf-library — zero leak into the
   rest of the site, tokens.css and components.css untouched.

   Patterns adopted (web, Mobbin):
     · Netflix / Disney+ — genre filter + SORT control above the grid
     · Disney+ / Netflix — result-count + sort bar on the catalog
     · HBO Max My List   — saved grid, remove-on-hover, empty state
     · WSJ / Quartz       — featured lead story + category sections
     · Mobbin Saved       — first-class empty + loading (skeleton) states

   Vocabulary reused as-is: .film-card .films-rail .glass-tabs
   .news-card(+--hero/--list) .page-head .section-link .btn — this
   file only adds the connective tissue the category expects.
   ============================================================ */

/* ─────────────────────────────────────────
   1 · CATALOG TOOLBAR  (sort + result count)
   The one piece every streaming catalog has and Ztor lacked:
   a control row that sits between the filter tabs and the grid.
   Netflix puts "Sort by ▾" top-right of the grid; Disney+ pins a
   "Browse by" pill. We give 片庫 the same affordance, on-skin.
   ───────────────────────────────────────── */
body.rf-library .rf-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin: 4px 0 22px;
}

body.rf-library .rf-toolbar__count {
  font-family: var(--font-cjk-text);
  font-size: var(--fs-body-sm);
  color: var(--text-tertiary);
}
body.rf-library .rf-toolbar__count strong {
  color: var(--text-secondary);
  font-weight: var(--fw-bold);
}

/* Sort control — a quiet glass pill that opens a menu. Mirrors the
   .glass-tabs material so it reads as part of the same family. */
body.rf-library .rf-sort {
  position: relative;
  margin-left: auto;
}
body.rf-library .rf-sort__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px 0 16px;
  border-radius: var(--radius-pill);
  background: var(--white-alpha-4);
  border: 1px solid var(--neutral-700);
  color: var(--text-secondary);
  font-family: var(--font-cjk-display);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  cursor: pointer;
  transition: color 160ms var(--ease-out), border-color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
body.rf-library .rf-sort__btn:hover {
  color: var(--text-primary);
  border-color: var(--border-default);
}
body.rf-library .rf-sort__btn:focus-visible {
  outline: 2px solid var(--yellow-500);
  outline-offset: 2px;
}
body.rf-library .rf-sort__btn-label { color: var(--text-tertiary); font-weight: var(--fw-regular); }
body.rf-library .rf-sort__btn-value { color: inherit; }
body.rf-library .rf-sort__chevron {
  width: 16px; height: 16px; flex: 0 0 auto;
  background-color: currentColor;
  -webkit-mask: url('icons/chevron_down.svg') center / contain no-repeat;
          mask: url('icons/chevron_down.svg') center / contain no-repeat;
  transition: transform 200ms var(--ease-out);
}
/* fallback glyph if chevron_down.svg is absent — drawn with a border */
body.rf-library .rf-sort__chevron { background-color: currentColor; }
body.rf-library .rf-sort.is-open .rf-sort__chevron { transform: rotate(180deg); }
body.rf-library .rf-sort.is-open .rf-sort__btn { color: var(--text-primary); border-color: var(--border-default); }

body.rf-library .rf-sort__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 188px;
  padding: 6px;
  border-radius: var(--radius-lg);
  background: rgba(19, 19, 19, 0.92);
  border: 1px solid var(--border-default);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  z-index: 40;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top right;
  pointer-events: none;
  transition: opacity 160ms var(--ease-out), transform 160ms var(--ease-out);
}
body.rf-library .rf-sort.is-open .rf-sort__menu {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
body.rf-library .rf-sort__option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-cjk-text);
  font-size: var(--fs-body-sm);
  font-weight: var(--fw-medium);
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms var(--ease-out), color 140ms var(--ease-out);
}
body.rf-library .rf-sort__option:hover { background: var(--white-alpha-8); color: var(--text-primary); }
body.rf-library .rf-sort__option:focus-visible {
  outline: none;
  background: var(--white-alpha-8);
  color: var(--text-primary);
}
body.rf-library .rf-sort__option[aria-checked="true"] { color: var(--yellow-500); }
body.rf-library .rf-sort__option-check {
  width: 16px; height: 16px; flex: 0 0 auto;
  opacity: 0;
  color: var(--yellow-500);
}
body.rf-library .rf-sort__option[aria-checked="true"] .rf-sort__option-check { opacity: 1; }

/* ─────────────────────────────────────────
   2 · FOCUS-VISIBLE for film cards & news cards
   Keyboard users got no ring on the catalog's primary objects.
   Category baseline: a clear, on-brand focus state.
   ───────────────────────────────────────── */
body.rf-library .film-card:focus-visible { outline: none; }
body.rf-library .film-card:focus-visible .film-card__poster {
  outline: 2px solid var(--yellow-500);
  outline-offset: 3px;
  border-color: var(--border-default);
  transform: translateY(-4px);
}
body.rf-library .news-card:focus-visible {
  outline: 2px solid var(--yellow-500);
  outline-offset: 3px;
}
body.rf-library .news-card--list:focus-visible {
  outline-offset: 6px;
  border-radius: var(--radius-md);
}

/* ─────────────────────────────────────────
   3 · EMPTY STATE  (the first sentence the product speaks)
   Mobbin "Saved" / HBO "My List": when nothing matches or
   nothing is saved, the surface should still talk. A centred
   glass tile — icon, line, sub-line, optional action.
   ───────────────────────────────────────── */
body.rf-library .rf-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: clamp(48px, 8vw, 88px) 24px;
  max-width: 460px;
  margin: 8px auto 0;
}
body.rf-library .rf-empty__icon {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-2xl);
  background:
    radial-gradient(120% 120% at 50% 0%, rgba(255, 163, 63, 0.16), rgba(255, 163, 63, 0) 70%),
    var(--white-alpha-4);
  border: 1px solid var(--border-default);
}
body.rf-library .rf-empty__icon img,
body.rf-library .rf-empty__icon span {
  width: 30px;
  height: 30px;
  display: block;
}
body.rf-library .rf-empty__icon span {
  background-color: var(--yellow-500);
  -webkit-mask: var(--icon, url('icons/library.svg')) center / contain no-repeat;
          mask: var(--icon, url('icons/library.svg')) center / contain no-repeat;
}
body.rf-library .rf-empty__title {
  margin: 0;
  font-family: var(--font-cjk-display);
  font-weight: var(--fw-bold);
  font-size: var(--fs-h4);
  line-height: var(--lh-h4);
  color: var(--text-primary);
}
body.rf-library .rf-empty__sub {
  margin: 0;
  font-family: var(--font-cjk-text);
  font-size: var(--fs-body-sm);
  line-height: var(--lh-body-sm);
  color: var(--text-tertiary);
  max-width: 36ch;
}
body.rf-library .rf-empty .btn { margin-top: 4px; }

/* ─────────────────────────────────────────
   4 · LOADING SKELETONS  (shape-matched to the cards they replace)
   Demoable via .rf-is-loading on a row; pulse honours reduced-motion.
   ───────────────────────────────────────── */
body.rf-library .rf-skel {
  position: relative;
  overflow: hidden;
  background: var(--white-alpha-4);
}
body.rf-library .rf-skel::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0) 100%);
  animation: rfShimmer 1.4s var(--ease-out) infinite;
}
/* Poster-shaped skeleton tile for a films-rail */
body.rf-library .rf-skel-card {
  flex: 0 0 var(--card-w, calc((100% - 5 * 20px) / 6));
  width: var(--card-w, calc((100% - 5 * 20px) / 6));
}
body.rf-library .rf-skel-card__poster {
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-md);
}
body.rf-library .rf-skel-card__line {
  height: 12px;
  margin-top: 12px;
  border-radius: var(--radius-pill);
}
body.rf-library .rf-skel-card__line--short { width: 60%; margin-top: 8px; }

@keyframes rfShimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  body.rf-library .rf-skel::after { animation: none; }
}

/* ─────────────────────────────────────────
   5 · NEWS — featured lead + category sections (WSJ / Quartz)
   The grid stays, but the first story becomes a wide lead and the
   feed gains date-grouped section labels. Pure layout on existing
   .news-card classes; no card-chrome changes.
   ───────────────────────────────────────── */
body.rf-library .rf-news-lead {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: clamp(20px, 3vw, 40px);
  margin-bottom: 8px;
}
@media (max-width: 1080px) {
  body.rf-library .rf-news-lead { grid-template-columns: 1fr; }
}
/* the lead photo card fills its column height (reuses --hero variant) */
body.rf-library .rf-news-lead .news-card--hero { min-height: 380px; }

/* Right-hand "more headlines" stack inside the lead */
body.rf-library .rf-news-lead__rail { display: flex; flex-direction: column; }
body.rf-library .rf-news-lead__rail-title {
  margin: 0 0 6px;
  font-family: var(--font-cjk-text);
  font-size: var(--fs-caption);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  font-weight: var(--fw-medium);
  color: var(--yellow-500);
}

/* Section label that separates editorial blocks (Quartz/WSJ rhythm) */
body.rf-library .rf-section-label {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 40px 0 8px;
  font-family: var(--font-cjk-display);
  font-weight: var(--fw-bold);
  font-size: var(--fs-h5);
  color: var(--text-primary);
}
body.rf-library .rf-section-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

/* ─────────────────────────────────────────
   6 · PROFILE — saved/收藏 grid (HBO Max My List)
   → CONSOLIDATED 2026-06-16 into css/components/saved-grid.css
     (un-prefixed, container-scoped .rf-saved-grid). Single-sourced so the
     component travels to any page; removed from this page-keyed file.
   ───────────────────────────────────────── */

/* The 收藏 tab panel hosts either the grid or the empty state */
body.rf-library .rf-tab-panel[hidden] { display: none; }

/* ─────────────────────────────────────────
   7 · DATABASE — meta on the catalog card
   The database posters carried no metadata (year / score), unlike
   every catalog Mobbin shows. Add a quiet caption strip via the
   existing .film-card__body vocabulary — opt-in with .rf-meta-card.
   ───────────────────────────────────────── */
body.rf-library .rf-meta-card .film-card__body { padding-top: 10px; gap: 4px; }
body.rf-library .rf-meta-card .film-card__title { font-size: 14px; }
body.rf-library .rf-meta-card .rf-meta-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-cjk-text);
  font-size: 11px;
  color: var(--text-tertiary);
}
body.rf-library .rf-meta-card .rf-meta-line__dot { opacity: 0.5; }
body.rf-library .rf-meta-card .rf-meta-line__score { color: var(--score-ink-high); font-weight: var(--fw-bold); }

/* ─────────────────────────────────────────
   8 · Reveal cooperation
   The pages pre-hide reveal targets via .js-reveal-ready. Our new
   toolbar/labels live OUTSIDE [data-reveal-stack]; make sure they
   are never left invisible if a reveal stack wraps them.
   ───────────────────────────────────────── */
body.rf-library .rf-toolbar,
body.rf-library .rf-section-label { opacity: 1; }

/* ─────────────────────────────────────────
   9 · Small-screen polish
   ───────────────────────────────────────── */
@media (max-width: 768px) {
  body.rf-library .rf-toolbar { margin-bottom: 16px; }
  body.rf-library .rf-sort { margin-left: 0; }
  body.rf-library .rf-sort__menu { right: auto; left: 0; transform-origin: top left; }
}
