/* Episode library: search, topic filter, and the single-episode page. */

.search {
  display: flex;
  gap: var(--space-3);
  max-width: 560px;
  margin: 0 auto var(--space-5);
}
.search__input {
  flex: 1;
  font: inherit;
  font-size: var(--step-0);
  padding: 0.7rem 1.1rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--ink);
}
.search__input::placeholder { color: var(--muted); }
.search__input:focus { border-color: var(--accent); }

/* Two-column library layout: a left filter rail (designbase-style category
   list) plus the results on the right. Collapses to a single column with
   the rail turned into a horizontal scroller once it can't sit beside the
   grid without squeezing cards under ~3 per row. */
.library-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: var(--space-7);
  align-items: start;
}
.library-sidebar {
  position: sticky;
  top: var(--space-5);
}
.library-sidebar__heading {
  font-size: var(--step--1);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: var(--space-2);
}
.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.library-sidebar__favorites {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
}
/* designbase's own sidebar (see the Figma-course screenshot) doesn't fill
   the active row solid — it's a plain list with a left accent rule and
   tinted text on the selected item, everything else staying quiet. A solid
   block per row read as a button bar, not a category list. */
.sidebar-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  font: inherit;
  font-size: var(--step--1);
  text-align: left;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-left: 2px solid transparent;
  background: none;
  color: var(--ink-2);
  cursor: pointer;
  transition: color .1s ease, border-color .1s ease;
}
.sidebar-item:hover { color: var(--ink); }
.sidebar-item.is-active {
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: var(--weight-medium);
}
.sidebar-item__n { opacity: .55; font-variant-numeric: tabular-nums; font-size: var(--step--2); }
.sidebar-item.is-active .sidebar-item__n { opacity: .8; }

.library-main { min-width: 0; }

.library-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.library-controls__right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
/* Small and plain, like designbase's own sort dropdown — a caret and text,
   not a full pill-shaped input. It's a secondary control sitting right next
   to the grid/list icons, not a form field asking for attention. */
.library-controls__sort select {
  font: inherit;
  font-size: var(--step--2);
  padding: 0.3rem 1.3rem 0.3rem 0.1rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23767066' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.15rem center;
  background-size: 10px 7px;
}
.library-controls__sort select:hover,
.library-controls__sort select:focus { color: var(--ink); }
.library-controls__sort select:focus { outline: 2px solid var(--accent-line); outline-offset: 2px; }

.library-controls__view {
  display: flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.view-toggle__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.7rem;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.view-toggle__btn svg { fill: currentColor; }
.view-toggle__btn.is-active { background: var(--accent); color: var(--accent-ink); }

@media (max-width: 880px) {
  .library-layout { grid-template-columns: 1fr; gap: var(--space-4); }
  .library-sidebar { position: static; }
  .sidebar-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: var(--space-2);
    padding-bottom: var(--space-1);
  }
  /* A left accent border doesn't read in a horizontal row — swap to a
     tinted pill instead, matching how the topic chips looked before. */
  .sidebar-item {
    width: auto;
    white-space: nowrap;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-pill);
  }
  .sidebar-item.is-active {
    border-color: var(--accent);
    background: var(--accent-soft);
  }
  .library-sidebar__favorites { margin-top: var(--space-3); padding-top: 0; border-top: 0; }
}

/* Denser grid than home.css's default video-grid (280px cards) — the
   library is meant to be scanned at a glance across many episodes, closer
   to designbase's card size, not showcase-sized like the homepage. Scoped
   to .library-main only so the related-videos grid on video_detail.html
   keeps the larger, homepage-style cards. */
.library-main .video-grid {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}
.library-main .video-card__body {
  padding: var(--space-3) var(--space-3) var(--space-4);
  gap: var(--space-1);
}
.library-main .video-card__title {
  font-size: var(--step--1);
  line-height: 1.4;
}
.library-main .video-card__play { width: 44px; height: 44px; }

/* List view: one row per episode, thumbnail on the left. Grid layout
   (video-grid, home.css) stays the default; this only overrides it once
   search.js adds the modifier class. */
.video-grid.video-grid--list {
  grid-template-columns: 1fr;
  gap: var(--space-3);
}
.video-grid--list .video-card {
  flex-direction: row;
  align-items: stretch;
}
.video-grid--list .video-card__player,
.video-grid--list .video-card__facade {
  flex: 0 0 240px;
  aspect-ratio: 16 / 9;
}
.video-grid--list .video-card__body {
  flex: 1;
  justify-content: center;
}
@media (max-width: 640px) {
  .library-controls { flex-wrap: wrap; }
  .video-grid--list .video-card { flex-direction: column; }
  .video-grid--list .video-card__player,
  .video-grid--list .video-card__facade { flex: none; }
}

.result-count {
  color: var(--muted);
  font-size: var(--step--1);
  margin: 0;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: var(--space-8) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  align-items: center;
}
/* [hidden] and .empty tie on specificity, and .empty comes later in the
   cascade — without this override, search.js setting the hidden attribute
   had no visible effect and the "no results" message always showed. */
.empty[hidden] { display: none; }

.meta-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.meta-row .chip { text-decoration: none; }

.upsell { display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-start; }

/* A hidden card must not keep its grid slot. */
.video-card[hidden] { display: none; }
