/* ============================================================
   Library page — page-specific styles (Step 4).
   Shared tokens/buttons/nav/footer chrome live in theme.css;
   only sections unique to this page (filters, cards grid,
   pagination, empty/skeleton states) are defined here.
   Converted from Library.html (YummyMath Revamp mockup).
   ============================================================ */

/* ============================================================
   VISIBLE KEYBOARD FOCUS (WCAG 2.4.7) — page-specific controls
   not already covered by theme.css's shared nav/footer/button rules.
   ============================================================ */
.topic-pill:focus-visible,
.activity-card:focus-visible,
.sidebar__trigger:focus-visible,
.filter-toggle:focus-visible {
  outline: 2px solid var(--color-green);
  outline-offset: 2px;
  border-radius: 3px;
}
input[type="checkbox"]:focus-visible { outline: 2px solid var(--color-green); outline-offset: 1px; }

/* BREADCRUMB — shared .crumbs/.crumbs__inner now lives in theme.css */

/* ============================================================
   LIBRARY PAGE HEADER
   ============================================================ */
.lib-header {
  background: var(--color-cream);
  border-bottom: 1px solid var(--color-divider);
  padding: 2.5rem 2.5rem 2rem;
}
.lib-header__inner { max-width: 1140px; margin: 0 auto; }
.lib-header__eyebrow {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-accent-deep);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-accent-deep);
}
.lib-header__title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-green);
  letter-spacing: -0.01em;
  margin-bottom: 1.5rem;
}
/* Theme pills — real <a> links to /category/{slug}/, also submit the
   genre filter form on click (progressive enhancement handled inline). */
.topic-pills { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.topic-pill {
  display: inline-flex;
  align-items: center;
  background: #EEEBE4;
  color: var(--color-text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.9rem;
  border-radius: 100px;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.topic-pill:hover { background: #D8EDE9; color: var(--color-green); }
.topic-pill--active { background: var(--color-green); color: #FFF; }
/* [LIB-7] Gold "Free activities" pill — links to the existing freesample tag search. */
.topic-pill--free { background: #FBF4DE; color: #8A6D1F; border: 1px solid #E5D3A0; }
.topic-pill--free:hover { background: #F5E9C8; color: #8A6D1F; }

/* ============================================================
   MAIN LAYOUT — sidebar + content
   ============================================================ */
/* Padding lives on .lib-body-outer (full-bleed), not .lib-body — matching
   the outer-padding + inner-max-width pattern .lib-header/.hero/.ym-nav use.
   Putting padding on the same element as max-width+margin:auto instead
   (the old, single-box version of this rule) makes the padding always
   apply on top of the centering, so .lib-body's content sits further right
   than .lib-header/.ym-nav's at desktop widths — the page-wide misalignment
   this fixes. */
.lib-body-outer { padding: 2rem 2.5rem; }
.lib-body {
  max-width: 1140px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 215px 1fr;
  gap: 2.5rem;
  align-items: start;
}

.filter-toggle {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 1rem;
  background: #FFF;
  border: 1px solid var(--color-divider);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
  margin-bottom: 1.25rem;
}
.filter-toggle svg { width: 16px; height: 16px; }

/* ============================================================
   FILTER SIDEBAR — real <form method="GET"> so every checkbox
   submits the current URL's filter state without JS (progressive
   enhancement adds instant-apply via a submit-on-change script).
   ============================================================ */
.sidebar {
  background: #FFF;
  border: 1px solid var(--color-divider);
  border-radius: 8px;
  overflow: hidden;
  position: sticky;
  top: calc(56px + 1.5rem);
}
.sidebar__section { border-bottom: 1px solid var(--color-divider); }
.sidebar__section:last-child { border-bottom: none; }
.sidebar__trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.sidebar__trigger-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sidebar__chevron { width: 14px; height: 14px; color: var(--color-text-muted); flex-shrink: 0; transition: transform 0.2s; }
.sidebar__section[data-expanded="true"] .sidebar__chevron { transform: rotate(180deg); }
.sidebar__section[data-expanded="false"] .sidebar__body { display: none; }
.sidebar__body { padding: 0.2rem 0 0.6rem; }
.sidebar__item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.32rem 1rem;
  cursor: pointer;
  transition: background 0.1s;
}
.sidebar__item:hover { background: var(--color-cream); }
.sidebar__item input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--color-green); cursor: pointer; flex-shrink: 0; }
.sidebar__item-label { font-size: 0.9rem; color: var(--color-text); cursor: pointer; flex: 1; }

/* [LIB-2] Genre sidebar "See all" overflow — thematic genres collapsed
   behind a toggle, math strands shown by default (see category.tpl). */
.sidebar__genre-overflow { display: none; }
.sidebar__genre-overflow[data-expanded="true"] { display: block; }
.sidebar__see-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 1rem 0.7rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-green);
  background: none;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}
.sidebar__see-toggle:hover { opacity: 0.75; }
.sidebar__see-toggle svg { width: 12px; height: 12px; flex-shrink: 0; transition: transform 0.2s; }
.sidebar__see-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.sidebar__clear {
  display: block;
  text-align: center;
  padding: 0.7rem 1rem;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-decoration: none;
  border-top: 1px solid var(--color-divider);
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  font-family: inherit;
  width: 100%;
  transition: color 0.15s;
}
.sidebar__clear:hover { color: var(--color-green); }
.sidebar__grade-grid { display: grid; grid-template-columns: 1fr 1fr; padding: 0.25rem 0.85rem 0.65rem; gap: 0.05rem 0; }
.sidebar__grade-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.3rem 0.15rem; cursor: pointer; font-size: 0.9rem; color: var(--color-text); transition: color 0.1s; }
.sidebar__grade-item:hover { color: var(--color-green); }
.sidebar__grade-item input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--color-green); cursor: pointer; flex-shrink: 0; }
.sidebar__grade-item--hs { grid-column: 1 / -1; border-top: 1px solid var(--color-divider); margin-top: 0.3rem; padding-top: 0.5rem; }
.sidebar__ccss-search { padding: 0.5rem 1rem 0.85rem; }
.sidebar__ccss-input {
  width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--color-divider);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
  background: #FAFAF7;
  color: var(--color-text);
  transition: border-color 0.15s;
}
.sidebar__ccss-input:focus { outline: none; border-color: var(--color-green); background: #FFF; }
.sidebar__ccss-input::placeholder { color: #9E9081; }
.sidebar__ccss-hint { display: block; margin-top: 0.4rem; font-size: 0.75rem; color: var(--color-text-muted); }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { min-width: 0; transition: opacity 0.15s ease; }
.main.is-loading { opacity: 0.5; pointer-events: none; }
.main__meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.main__count { font-size: 0.88rem; color: var(--color-text-muted); }

/* Active filter summary — removable chips, hidden when none active */
.active-filters {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-divider);
}
.active-filters--visible { display: flex; }
.active-filters__label { font-size: 0.85rem; font-weight: 600; color: var(--color-text-muted); }
.active-filters__chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: #DCEEEA;
  color: var(--color-green-dark);
  font-size: 0.82rem;
  font-weight: 500;
  padding: 0.3rem 0.4rem 0.3rem 0.75rem;
  border-radius: 100px;
  text-decoration: none;
}
.filter-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(5, 131, 110, 0.16);
  color: var(--color-green-dark);
}
.active-filters__clear { font-size: 0.82rem; font-weight: 500; color: var(--color-text-muted); text-decoration: underline; }
.active-filters__clear:hover { color: var(--color-green); }

/* "Newly added" section — visually distinct */
.new-section { background: #FFFAF2; border: 1px solid var(--color-divider); border-radius: 8px; padding: 1.25rem 1.25rem 1.5rem; margin-bottom: 2.25rem; }
.new-section__header { display: flex; align-items: center; gap: 0.65rem; margin-bottom: 1rem; }
.new-section__marker { width: 3px; height: 1.15rem; background: var(--color-accent, #C9A33D); border-radius: 2px; flex-shrink: 0; }
.new-section__title { font-family: var(--font-serif); font-size: 1.1rem; font-weight: 600; color: var(--color-green); margin: 0; }

.cards-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }

.section-divider { border: none; border-top: 1px solid var(--color-divider); margin: 2rem 0 1.5rem; }
.all-section__header { display: flex; align-items: center; gap: 0.65rem; margin-bottom: 1rem; }
.all-section__marker { width: 3px; height: 1.15rem; background: var(--color-divider); border-radius: 2px; flex-shrink: 0; }
.all-section__title { font-family: var(--font-serif); font-size: 1.1rem; font-weight: 600; color: var(--color-text); margin: 0; }

/* Empty state — server-rendered when the filtered result count is 0 */
.empty-state { text-align: center; padding: 3.5rem 1.5rem; border: 1px dashed var(--color-divider); border-radius: 8px; background: #FFFDF8; }
.empty-state__icon { font-size: 2rem; line-height: 1; margin-bottom: 0.75rem; opacity: 0.8; }
.empty-state__title { font-family: var(--font-serif); font-size: 1.15rem; font-weight: 600; color: var(--color-text); margin: 0 0 0.4rem; }
.empty-state__text { font-size: 0.92rem; color: var(--color-text-muted); margin: 0 auto 1.25rem; max-width: 32rem; }
.empty-state__suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 0 0 1.1rem; }
.empty-state__clear { background: none; border: none; color: var(--color-green); font-family: inherit; font-size: 0.88rem; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; padding: 0; }
.empty-state__clear:hover { color: var(--color-green-dark); }

/* ============================================================
   ACTIVITY CARDS
   ============================================================ */
.activity-card {
  background: #FFF;
  border: 1px solid var(--color-divider);
  border-radius: 6px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.activity-card:hover { border-color: var(--color-green); transform: translateY(-2px); box-shadow: 0 4px 14px rgba(5, 131, 110, 0.09); }
.activity-card__thumb { aspect-ratio: 4 / 3; position: relative; overflow: hidden; border-bottom: 1px solid var(--color-divider); }
.activity-card__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.activity-card__new-badge {
  position: absolute;
  top: 0.55rem;
  left: 0.55rem;
  background: #FBF4DE;
  color: #8A6D1F;
  border: 1px solid #E5D3A0;
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  z-index: 1;
}
.activity-card__body { padding: 1rem 1.1rem 1.1rem; flex: 1; display: flex; flex-direction: column; }
.activity-card__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  margin-bottom: 0.5rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.activity-card__excerpt {
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--color-text-muted);
  margin: 0 0 0.75rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.activity-card__pills { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: auto; min-width: 0; }
.activity-card__pill {
  display: inline-block;
  background: #DCEEEA;
  color: var(--color-green);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.55rem;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}
.activity-card__pill--grade { background: #EFEDE7; color: var(--color-text-muted); }
.activity-card__pill--free { background: #FBF4DE; color: var(--color-accent-deep); border: 1px solid #E5D3A0; }

/* ============================================================
   PAGINATION — real crawlable links (brief §2), not "Load more".
   ============================================================ */
.pagination-nav { text-align: center; margin-top: 2rem; padding-top: 1.5rem; border-top: 1px solid var(--color-divider); }
.pagination-nav__list { display: inline-flex; list-style: none; gap: 0.35rem; padding: 0; margin: 0; flex-wrap: wrap; justify-content: center; }
.pagination-nav__link, .pagination-nav__current {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.6rem;
  border: 1.5px solid var(--color-green);
  border-radius: 6px;
  color: var(--color-green);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s;
}
.pagination-nav__link:hover { background: rgba(5, 131, 110, 0.06); }
.pagination-nav__current { background: var(--color-green); color: #FFF; }
.pagination-nav__ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  height: 2.25rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 720px) {
  .lib-header { padding: 1.75rem 1.25rem 1.5rem; }
  .lib-body-outer { padding: 1.5rem 1.25rem; }
  .lib-body { grid-template-columns: 1fr; gap: 1.25rem; }
  .sidebar { position: static; display: none; }
  .sidebar--open { display: block; }
  .filter-toggle { display: flex; }
  .cards-grid { grid-template-columns: 1fr; }
}
@media (min-width: 721px) and (max-width: 960px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}
