/*
 * Browse UI styles. Tokens are the values sampled from the Subsplash
 * screenshots in section 5 of sermon-archive-plan.md, exposed as custom
 * properties so the whole thing stays re-themeable from one place.
 *
 * Everything is scoped under .ch-sm — this has to coexist with Divi,
 * which is aggressive about global styles. No resets, no bare element
 * selectors outside the scope.
 */

.ch-sm {
  --ch-brand-red: #993333;
  --ch-text-primary: #222222;
  --ch-text-secondary: #747578;
  --ch-surface-muted: #edeef0;
  --ch-surface-input: #f5f6f7;
  --ch-page-bg: #ffffff;
  --ch-radius: 6px;

  color: var(--ch-text-primary);
  max-width: 1080px;
  margin: 0 auto;
}

.ch-sm *,
.ch-sm *::before,
.ch-sm *::after {
  box-sizing: border-box;
}

/* -- breadcrumbs ------------------------------------------------------
   Subsplash has none; drill-down there relies on the browser back
   button (noted in section 5). These are the deliberate improvement. */

.ch-sm-crumbs {
  margin: 0 0 20px;
  font-size: 14px;
}

.ch-sm-crumbs ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.ch-sm-crumbs li {
  margin: 0;
  padding: 0;
  color: var(--ch-text-secondary);
}

.ch-sm-crumbs li + li::before {
  content: "›";
  margin-right: 8px;
  color: var(--ch-text-secondary);
}

.ch-sm-crumbs a {
  color: var(--ch-text-secondary);
  text-decoration: none;
}

.ch-sm-crumbs a:hover {
  color: var(--ch-text-primary);
  text-decoration: underline;
}

.ch-sm-crumbs [aria-current="page"] {
  color: var(--ch-text-primary);
  font-weight: 600;
}

/* -- headings --------------------------------------------------------- */

.ch-sm-heading {
  margin: 0 0 4px;
  font-size: 28px;
  line-height: 1.25;
  color: var(--ch-text-primary);
}

.ch-sm-subheading {
  margin: 0 0 24px;
  font-size: 16px;
  color: var(--ch-text-secondary);
}

.ch-sm-heading--centered,
.ch-sm-subheading--centered {
  text-align: center;
}

.ch-sm-empty {
  padding: 32px 0;
  color: var(--ch-text-secondary);
  font-size: 15px;
}

/* -- tile grid --------------------------------------------------------
   Section 5: 3-column, 16:9 artwork, ~6px radius, bold title beneath,
   secondary-grey subtitle under that. */

.ch-sm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 28px 24px;
  margin: 0 0 32px;
}

/* The card is the positioning context for the stretched link below.
   Artwork is a CSS background, not an <img>: Divi and several image
   plugins auto-wrap <img> tags in a link to the full-size file, which
   nested inside our anchor and hijacked the click. */
.ch-sm-tile {
  position: relative;
  display: block;
  color: inherit;
}

.ch-sm-tile-art {
  display: block;
  aspect-ratio: 16 / 9;
  border-radius: var(--ch-radius);
  overflow: hidden;
  background-color: var(--ch-surface-muted);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: transform 0.25s ease;
}

.ch-sm-tile:hover .ch-sm-tile-art {
  transform: scale(1.02);
}

/* Belt and braces: if some plugin still manages to inject an image into
   the card, it can't sit above the stretched link and steal the click. */
.ch-sm-tile img,
.ch-sm-episode img {
  pointer-events: none;
}

/* Branded empty state. Section 5 called this out as a pattern worth
   copying deliberately rather than leaving a gap where art should be. */
.ch-sm-tile-art--placeholder {
  background: var(--ch-brand-red);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.ch-sm-tile-art--placeholder > span {
  color: #ffffff;
  opacity: 0.72;
  font-size: 15px;
  line-height: 1.3;
  text-align: center;
  letter-spacing: 0.02em;
}

/* Stretched link — the anchor's ::after covers the whole card, so the
   entire tile is clickable while the anchor itself stays a plain text
   link in the markup. */
.ch-sm-tile-title {
  display: block;
  margin-top: 10px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ch-text-primary);
  text-decoration: none;
}

.ch-sm-tile-title::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.ch-sm-tile-title:hover {
  color: var(--ch-text-primary);
  text-decoration: underline;
}

/* z-index: 2 puts this above .ch-sm-tile-title::after's stretched link
   (z-index: 1), so clicking Edit doesn't also navigate into the series. */
.ch-sm-tile-edit {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  padding: 4px 10px;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: #ffffff;
  font-size: 12px;
  cursor: pointer;
}

.ch-sm-tile-edit:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* Section 5 flagged Subsplash clipping subtitles mid-word. Clamp to two
   lines with a real ellipsis instead. */
.ch-sm-tile-sub {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: 2px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--ch-text-secondary);
}

/* -- series banner ---------------------------------------------------- */

.ch-sm-banner {
  border-radius: var(--ch-radius);
  overflow: hidden;
  margin: 0 0 20px;
  background: var(--ch-surface-muted);
}

.ch-sm-banner img {
  width: 100%;
  height: auto;
  display: block;
}

.ch-sm-banner--placeholder {
  background: var(--ch-brand-red);
  aspect-ratio: 32 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ch-sm-banner--placeholder > span {
  color: #ffffff;
  opacity: 0.78;
  font-size: 22px;
  letter-spacing: 0.06em;
  text-align: center;
}

/* -- episode rows -----------------------------------------------------
   Section 5: horizontal rows, thumbnail left, text right, hairline
   divider. Note this is a different pattern from the tile grid used for
   browsing — matching how Subsplash itself switches layout here. */

.ch-sm-episodes {
  list-style: none;
  margin: 24px 0 0;
  padding: 0;
}

.ch-sm-episode {
  margin: 0;
  border-top: 1px solid var(--ch-surface-muted);
}

.ch-sm-episode:last-child {
  border-bottom: 1px solid var(--ch-surface-muted);
}

.ch-sm-episode {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 4px;
}

.ch-sm-episode:hover {
  background: var(--ch-surface-input);
}

.ch-sm-episode-art {
  flex: 0 0 132px;
  width: 132px;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  background-color: var(--ch-surface-muted);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: block;
}

.ch-sm-episode-art--placeholder {
  background: var(--ch-brand-red);
  opacity: 0.85;
}

.ch-sm-episode-body {
  flex: 1 1 auto;
  min-width: 0;
}

.ch-sm-episode-title {
  display: block;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--ch-text-primary);
  text-decoration: none;
}

.ch-sm-episode-title::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.ch-sm-episode-title:hover {
  color: var(--ch-text-primary);
  text-decoration: underline;
}

.ch-sm-episode-meta {
  display: block;
  margin-top: 3px;
  font-size: 14px;
  color: var(--ch-text-secondary);
}

.ch-sm-episode-code {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  color: var(--ch-text-secondary);
  opacity: 0.85;
}

/* -- narrow screens ---------------------------------------------------- */

@media (max-width: 600px) {
  .ch-sm-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px 16px;
  }

  .ch-sm-heading {
    font-size: 22px;
  }

  .ch-sm-episode-art {
    flex-basis: 96px;
    width: 96px;
  }

  .ch-sm-episode-title {
    font-size: 15px;
  }

  .ch-sm-episode-meta,
  .ch-sm-episode-code {
    font-size: 13px;
  }
}

/* -- sort control ------------------------------------------------------
   Sits above the tile grid. Deliberately understated: it's a refinement,
   not the primary action on the page. */

.ch-sm-listing.is-loading {
  opacity: 0.6;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.ch-sm-sort {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0 0 20px;
  font-size: 14px;
  /* Many theme headers are fixed/sticky. Without this, jumping to
     #ch-sm-sort lands the control exactly at the top of the viewport,
     which a fixed header then covers — so the page looks like it
     scrolled straight to the first list item, with nothing visibly
     "sort-related" on screen at all. 100px is a guess at a typical
     header height; raise it if the theme's header is taller. */
  scroll-margin-top: 100px;
}

.ch-sm-sort-label {
  color: var(--ch-text-secondary);
  margin-right: 4px;
}

.ch-sm-sort-option {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 100px;
  text-decoration: none;
  color: var(--ch-text-secondary);
  background: var(--ch-surface-muted);
  line-height: 1.4;
}

.ch-sm-sort-option:hover {
  color: var(--ch-text-primary);
}

.ch-sm-sort-option.is-active {
  background: var(--ch-brand-red);
  color: #ffffff;
}

.ch-sm-sort-option.is-active:hover {
  color: #ffffff;
}

/* -- editing ----------------------------------------------------------
   Only rendered for users who can edit. Deliberately quiet: this is the
   same page visitors see, so editing affordances shouldn't shout. */

.ch-sm-editbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 0 16px;
  border-radius: var(--ch-radius);
  background: var(--ch-surface-input);
  border: 1px solid var(--ch-surface-muted);
  font-size: 13px;
  color: var(--ch-text-secondary);
}

.ch-sm-editbar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ch-brand-red);
  flex: 0 0 8px;
}

/* The row's stretched link covers the whole row, so the edit button has
   to sit above it or the click navigates instead. */
.ch-sm-episode-edit {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  align-self: center;
  padding: 5px 14px;
  border: 1px solid var(--ch-surface-muted);
  border-radius: 100px;
  background: #ffffff;
  color: var(--ch-text-secondary);
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
}

.ch-sm-episode-edit:hover {
  border-color: var(--ch-brand-red);
  color: var(--ch-brand-red);
}

.ch-sm-edit-slot {
  list-style: none;
  padding: 16px;
  border-top: 1px solid var(--ch-surface-muted);
  border-left: 3px solid var(--ch-brand-red);
  background: var(--ch-surface-input);
}

.ch-sm-edit-slot.is-error {
  color: #a12020;
}

.ch-sm-edit-heading {
  margin: 0 0 14px;
  font-size: 14px;
  color: var(--ch-text-secondary);
}

.ch-sm-edit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.ch-sm-field {
  display: block;
}

.ch-sm-field--wide {
  margin-bottom: 12px;
}

.ch-sm-field-label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--ch-text-secondary);
}

.ch-sm-field input[type="text"],
.ch-sm-field input[type="date"],
.ch-sm-field textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid #ccced2;
  border-radius: 4px;
  background: #ffffff;
  font: inherit;
  font-size: 15px;
  color: var(--ch-text-primary);
}

.ch-sm-field input:focus,
.ch-sm-field textarea:focus {
  outline: 2px solid var(--ch-brand-red);
  outline-offset: -1px;
  border-color: var(--ch-brand-red);
}

/* -- the locked series field ------------------------------------------ */

.ch-sm-field--locked .ch-sm-locked-value {
  padding: 7px 10px;
  border: 1px dashed #ccced2;
  border-radius: 4px;
  background: var(--ch-surface-muted);
  color: var(--ch-text-secondary);
  font-size: 15px;
}

.ch-sm-lock {
  font-size: 12px;
  opacity: 0.7;
}

/* -- video upload widget (plan §13 / D25) ------------------------------ */

.ch-sm-video-upload {
  padding: 10px 12px;
  border: 1px solid #ccced2;
  border-radius: var(--ch-radius);
  background: #ffffff;
}

.ch-sm-video-current {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.ch-sm-video-poster {
  width: 64px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--ch-surface-muted);
}

.ch-sm-video-status {
  font-size: 13px;
  color: var(--ch-text-secondary);
}

.ch-sm-video-status.is-error {
  color: #a12020;
}

.ch-sm-video-file {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

.ch-sm-video-progress {
  height: 6px;
  margin-bottom: 8px;
  border-radius: 3px;
  background: var(--ch-surface-muted);
  overflow: hidden;
}

.ch-sm-video-progress-bar {
  height: 100%;
  width: 0;
  background: var(--ch-brand-red);
  transition: width 0.2s ease;
}

.ch-sm-video-upload .ch-sm-video-clear {
  margin: 0 0 10px;
}

.ch-sm-video-upload .ch-sm-field {
  margin-top: 4px;
}

.ch-sm-btn:disabled,
.ch-sm-video-file:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ch-sm-series-form {
  margin: 0 0 20px;
  padding: 14px;
  border: 1px solid #ccced2;
  border-radius: var(--ch-radius);
  background: #ffffff;
}

.ch-sm-series-image {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.ch-sm-series-image-preview img {
  width: 64px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
}

.ch-sm-help {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: var(--ch-radius);
  background: #fdf6e3;
  border: 1px solid #e8dcc0;
  font-size: 13px;
  line-height: 1.5;
  color: #6b5a2e;
}

.ch-sm-help strong {
  display: block;
  margin-bottom: 2px;
  color: #5a4a20;
}

/* -- actions ----------------------------------------------------------- */

.ch-sm-edit-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ch-sm-btn {
  padding: 8px 16px;
  border: 1px solid #ccced2;
  border-radius: 4px;
  background: #ffffff;
  color: var(--ch-text-primary);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.ch-sm-btn:hover {
  border-color: var(--ch-text-secondary);
}

.ch-sm-btn--primary {
  background: var(--ch-brand-red);
  border-color: var(--ch-brand-red);
  color: #ffffff;
}

.ch-sm-btn--primary:hover {
  background: #7b2929;
  border-color: #7b2929;
}

.ch-sm-btn--danger {
  margin-left: auto;
  color: #a12020;
  border-color: #e2c4c4;
}

.ch-sm-btn--danger:hover {
  background: #a12020;
  border-color: #a12020;
  color: #ffffff;
}

.ch-sm-edit-status {
  font-size: 13px;
  color: var(--ch-text-secondary);
}

.ch-sm-edit-status.is-error {
  color: #a12020;
}

.ch-sm-editbar-text { flex: 1 1 auto; }

.ch-sm-btn--add {
  padding: 5px 14px;
  font-size: 13px;
  border-color: var(--ch-brand-red);
  color: var(--ch-brand-red);
  background: #ffffff;
}

.ch-sm-btn--add:hover {
  background: var(--ch-brand-red);
  color: #ffffff;
}

.ch-sm-btn--publish {
  background: #1f5f47;
  border-color: #1f5f47;
  color: #ffffff;
}

.ch-sm-btn--publish:hover {
  background: #174936;
  border-color: #174936;
}

.ch-sm-episode-badge {
  display: inline-block;
  margin: 0 6px 2px 0;
  padding: 1px 8px;
  border-radius: 100px;
  background: #fdf6e3;
  border: 1px solid #e8dcc0;
  color: #6b5a2e;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  vertical-align: 2px;
}

.ch-sm-episode-badge--error {
  background: #fbe4e4;
  border-color: #e2c4c4;
  color: #a12020;
}
