/**
 * @file
 * Article card for content feeds.
 *
 * Slot content arrives with the theme's own classes (.post-title, .name,
 * .flag-wrap ...); the selectors here are doubled where custom.css would
 * otherwise win.
 */

/* Full width even inside a flex or floated parent, so the image always
   sits at the right edge however short the text is. */
.rn-article-card {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  flex-direction: column;
  gap: 12px;
  margin: 0 0 24px;
  padding: 0 0 20px;
  border-bottom: 1px solid #ececec;
}

/* Wraps when the tags and Save don't fit on one line (a long type tag such
   as "Therapeutic Update" beside the image on a narrow tablet), rather than
   pushing Save past the card's edge. */
.rn-article-card__top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

/* Save: grey until saved; the saved state keeps the theme's blue. */
.rn-article-card .rn-article-card__save,
.rn-article-card .rn-article-card__save .flag-wrap,
.rn-article-card .rn-article-card__save .flag {
  flex: 0 0 auto;
  float: none;
  margin: 0 0 0 auto;
  padding: 0;
}

/* Tripled so the flag's own link colour in custom.css does not win. */
.rn-article-card .rn-article-card__save a,
.rn-article-card .rn-article-card__save .flag.action-flag a,
.rn-article-card .rn-article-card__save .flag-wrap a.login-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 24px;
  margin: 0;
  font-family: Inter, sans-serif;
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
  color: #686868;
  text-decoration: none;
}

.rn-article-card .rn-article-card__save .flag.action-unflag a {
  color: #1585fe;
}

.rn-article-card__main {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.rn-article-card__text {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  word-break: break-word;
}

.rn-article-card__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* custom.css forces Poppins/500 on headings with !important. */
.rn-article-card .rn-article-card__title {
  margin: 0;
  padding: 0;
  font-family: Inter, sans-serif !important;
  font-size: 16px;
  line-height: 19.6px;
  font-weight: 700 !important;
  color: #121212;
}

.rn-article-card .rn-article-card__title a,
.rn-article-card .rn-article-card__title a:focus {
  font: inherit;
  color: inherit;
  text-decoration: none;
  transition: color 150ms ease;
}

.rn-article-card .rn-article-card__title a:hover,
.rn-article-card .rn-article-card__title a:focus-visible {
  color: #1585fe;
  text-decoration: underline;
}

.rn-article-card .rn-article-card__meta,
.rn-article-card .rn-article-card__meta span,
.rn-article-card .rn-article-card__meta time {
  margin: 0;
  font-family: Poppins, sans-serif;
  font-size: 14px;
  line-height: 20px;
  font-style: italic;
  font-weight: 400;
  color: #686868;
}

.rn-article-card .rn-article-card__meta a {
  font: inherit;
  color: #1585fe;
  text-decoration: none;
}

.rn-article-card .rn-article-card__meta a:hover {
  text-decoration: underline;
}

/* The author field's own .name wrapper carries spacing of its own. */
.rn-article-card .rn-article-card__meta .name {
  margin: 0;
  padding: 0;
}

.rn-article-card__author + .rn-article-card__date::before {
  content: " • ";
}

/* Three lines, then an ellipsis. */
.rn-article-card .rn-article-card__summary {
  display: -webkit-box;
  overflow: hidden;
  font-family: Poppins, sans-serif;
  font-size: 14px;
  line-height: 21px;
  font-weight: 400;
  color: #686868;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}

/* The summary can arrive as several paragraphs; run them together so the
   clamp counts lines of text, not blocks. */
.rn-article-card .rn-article-card__summary p {
  display: inline;
  margin: 0;
  font: inherit;
  color: inherit;
}

.rn-article-card__media {
  flex: 0 0 234px;
  width: 234px;
  height: 124px;
  overflow: hidden;
  background: #e5e7eb;
}

.rn-article-card .rn-article-card__media figure,
.rn-article-card .rn-article-card__media div,
.rn-article-card .rn-article-card__media a {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}

.rn-article-card .rn-article-card__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* A video passes the shared video-thumbnail as its media; it fills the box
   instead of keeping its own 16:9. Give the card rn-video-thumb-host so
   hovering anywhere on it shows the play icon. */
.rn-article-card .rn-article-card__media .rn-video-thumb {
  height: 100%;
  aspect-ratio: auto;
}

/* Image on the left, tags above the title in the text column. The markup is
   the same as the default card; the grid moves the pieces. */
.rn-article-card--media-left {
  display: grid;
  grid-template-columns: 234px minmax(0, 1fr);
  grid-template-areas:
    "media top"
    "media text";
  grid-template-rows: auto 1fr;
  gap: 8px 20px;
  align-items: start;
}

.rn-article-card--media-left.rn-article-card--no-media {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "top"
    "text";
}

.rn-article-card--media-left .rn-article-card__main {
  display: contents;
}

.rn-article-card--media-left .rn-article-card__top {
  grid-area: top;
  justify-content: flex-start;
}

.rn-article-card--media-left .rn-article-card__text {
  grid-area: text;
}

/* Two lines of summary fit beside the image. */
.rn-article-card--media-left .rn-article-card__summary {
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.rn-article-card--media-left .rn-article-card__media {
  grid-area: media;
  align-self: center;
  width: 234px;
  height: 136px;
}

@media (max-width: 600px) {
  .rn-article-card__main {
    flex-direction: column-reverse;
  }

  /* Image on top, then the tags, then the title with Save beside it. The
     wrappers drop out so their pieces can take grid cells of their own. */
  /* The topic tag also takes the space over Save (Save sits on the title
     row): long type tags such as "Therapeutic Update" plus a topic would
     otherwise not fit beside Save on a phone and push the card wider. */
  .rn-article-card--media-left {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "media media media media"
      "type topic topic topic"
      "title title title save"
      "meta meta meta meta"
      "summary summary summary summary";
    grid-template-rows: none;
    gap: 0 8px;
  }

  .rn-article-card--media-left.rn-article-card--no-media {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "type topic topic topic"
      "title title title save"
      "meta meta meta meta"
      "summary summary summary summary";
  }

  .rn-article-card--media-left .rn-article-card__top,
  .rn-article-card--media-left .rn-article-card__text,
  .rn-article-card--media-left .rn-article-card__head {
    display: contents;
  }

  .rn-article-card--media-left .rn-article-card__top > .rn-content-tag:first-child {
    grid-area: type;
    margin-bottom: 8px;
  }

  .rn-article-card--media-left .rn-article-card__top > .rn-content-tag--topic {
    grid-area: topic;
    justify-self: start;
    max-width: 100%;
    margin-bottom: 8px;
  }

  .rn-article-card--media-left .rn-article-card__save {
    grid-area: save;
    align-self: start;
    /* Taller than a one-line title; keep it from pushing the date down. */
    margin: -2px 0 -8px 16px;
  }

  .rn-article-card--media-left .rn-article-card__title {
    grid-area: title;
  }

  .rn-article-card--media-left .rn-article-card__meta {
    grid-area: meta;
    margin-top: 4px;
  }

  .rn-article-card--media-left .rn-article-card__summary {
    grid-area: summary;
    margin-top: 12px;
    -webkit-line-clamp: 4;
    line-clamp: 4;
  }

  .rn-article-card--media-left .rn-article-card__media {
    width: 100%;
    height: auto;
    margin-bottom: 12px;
    aspect-ratio: 21 / 10;
  }

  .rn-article-card__media {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }
}

/* The smallest phones (e.g. the first iPhone SE, 320px): a long type tag and
   the topic don't fit side by side, so the topic goes under the type. */
@media (max-width: 359px) {
  .rn-article-card--media-left {
    grid-template-areas:
      "media media media media"
      "type type type type"
      "topic topic topic topic"
      "title title title save"
      "meta meta meta meta"
      "summary summary summary summary";
  }

  .rn-article-card--media-left.rn-article-card--no-media {
    grid-template-areas:
      "type type type type"
      "topic topic topic topic"
      "title title title save"
      "meta meta meta meta"
      "summary summary summary summary";
  }

  .rn-article-card--media-left .rn-article-card__top > .rn-content-tag:first-child {
    justify-self: start;
    max-width: 100%;
  }
}
