/* ==========================================================================
   Cardinal Star Healing — home-page social feed (2.2)
   --------------------------------------------------------------------------
   Markup: csh_social_feed_html() in includes/social.php. Every layout choice
   from Admin > Social feed arrives as a custom property or data-* attribute on
   <section class="sf">, so nothing here hard-codes a value Amy can change:

     --sf-cols-d / -t / -p   columns on desktop (>= 900px), tablet (640-899px), phone
     --sf-gap                space between tiles          --sf-ratio       tile shape
     --sf-pad-top / -bottom  section padding              --sf-max         feed width
     --sf-margin-top / -bottom  space outside the section
     --sf-border-width / -style / -color, --sf-radius, --sf-tile-bg   the tiles
     --sf-heading-color, --sf-text-color, --sf-bg (+ --sf-on-bg)       colours
     --sf-lines              caption lines
     data-sf-captions none|hover|always, data-sf-hover zoom|lift|fade|none,
     data-sf-bg page|soft|tint|dark|custom, data-sf-display mixed|tabs

   Each tile is a query container (sf-tile; a text-only tile also sf-text), so
   its words, network icon and video badge fit whatever size the shape and the
   columns give it.

   A colour left on "Use theme colour" is simply not printed, so the fallbacks
   below (theme variables) apply and the feed follows every theme change.
   Motion: transitions only, switched off by prefers-reduced-motion and by the
   theme's own data-motion="off".
   ========================================================================== */

.sf {
  --sf-cols-d: 4; --sf-cols-t: 4; --sf-cols-p: 2;
  --sf-gap: 12px; --sf-pad-top: 64px; --sf-pad-bottom: 64px; --sf-margin-top: 0px; --sf-margin-bottom: 0px;
  --sf-max: 72rem; --sf-ratio: 1 / 1; --sf-border-width: 0px; --sf-border-style: solid; --sf-radius: 12px; --sf-lines: 3;
  --section-y: var(--sf-pad-top);   /* the theme's section dividers sit in this padding */
  padding-top: var(--sf-pad-top);
  padding-bottom: var(--sf-pad-bottom);
  margin-top: var(--sf-margin-top);
  margin-bottom: var(--sf-margin-bottom);
}
/* Text colour: the band's own (page / soft / tint / dark), the automatic one on a custom
   background, or Amy's choice (.sf-has-text, set when --sf-text-color is printed). */
.sf.sf-custom { background: var(--sf-bg); color: var(--sf-on-bg); }
.sf.sf-has-text { color: var(--sf-text-color); }
.sf.sf-custom .lead, .sf.sf-custom .muted { color: inherit; opacity: .82; }
.sf .lead { color: var(--sf-text-color, var(--muted)); }
.sf.band-dark .lead { color: var(--sf-text-color, var(--on-dark-muted)); }
.sf.band-tint .lead { color: var(--sf-text-color, var(--on-tint)); }
.sf-wrap {
  width: 100%; max-width: var(--sf-max); margin-left: auto; margin-right: auto;
  padding-left: var(--gutter, 1rem); padding-right: var(--gutter, 1rem); position: relative;
}
.sf[data-sf-width="full"] .sf-wrap { max-width: none; }
.sf-head { margin-bottom: 2rem; }
.sf-title { color: var(--sf-heading-color, inherit); }
.sf-sub { margin: 0; }

/* Grid ---------------------------------------------------------------------- */
.sf-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: var(--sf-gap);
  grid-template-columns: repeat(var(--sf-cols-p), minmax(0, 1fr));
}
@media (min-width: 640px) {
  .sf-grid { grid-template-columns: repeat(var(--sf-cols-t), minmax(0, 1fr)); }
}
@media (min-width: 900px) {
  .sf-grid { grid-template-columns: repeat(var(--sf-cols-d), minmax(0, 1fr)); }
}
.sf-item { margin: 0; min-width: 0; }

/* Tiles --------------------------------------------------------------------- */
.sf-tile {
  /* A query container (the badges below shrink on small tiles) and its own stacking layer. */
  container: sf-tile / inline-size;
  position: relative; z-index: 0; display: flex; flex-direction: column; height: 100%;
  color: inherit; text-decoration: none; overflow: hidden;
  border: var(--sf-border-width) var(--sf-border-style) var(--sf-border-color, var(--line));
  border-radius: var(--sf-radius);
  background: var(--sf-tile-bg, var(--surface-2));
  transition: transform .25s var(--ease, ease), box-shadow .25s var(--ease, ease);
}
a.sf-tile:hover { color: inherit; }
/* The focused (or hovered) tile is drawn above its neighbours, so the whole focus ring shows
   even when "Space between tiles" is 0. */
.sf-tile:hover, .sf-tile:focus-visible { z-index: 1; }
.sf-tile:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sf.band-dark .sf-tile { border-color: var(--sf-border-color, rgba(255, 255, 255, .22)); background: var(--sf-tile-bg, rgba(255, 255, 255, .06)); }
.sf.band-dark .sf-tile:focus-visible { outline-color: var(--on-dark); }

.sf-media {
  position: relative; display: block; flex: none; width: 100%; aspect-ratio: var(--sf-ratio); overflow: hidden;
  background: linear-gradient(150deg, var(--dark, #3A2C2C) 0%, var(--primary, #B76969) 100%);
}
.sf-media img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .45s var(--ease, ease), opacity .3s ease;
}
/* A post without a picture (a Facebook status update): its words on a soft tile. The tile is a
   size container, so the number of lines follows the room the tile shape and the columns leave
   (a query measures the content box, inside the padding); the top padding keeps the words clear
   of the network icon and the video badge. */
.sf-media-text {
  container: sf-text / size;
  display: flex; flex-direction: column; justify-content: center; justify-content: safe center; align-items: stretch;
  padding: 1rem 1rem .9rem;
  background: linear-gradient(150deg, var(--primary-soft, #F3E9E9) 0%, var(--tint, #F3E3F2) 100%);
  color: var(--ink);
}
.sf[data-sf-icons="1"] .sf-media-text, .sf-tile.is-video .sf-media-text { padding-top: 2.75rem; }
.sf-text {
  font-family: var(--font-display); font-size: 1rem; line-height: 1.45; text-align: center; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 7; overflow: hidden;
}
/* Small tiles (three columns on a phone, four on a small tablet): smaller words and padding. */
@container sf-tile (max-width: 9.5rem) {
  .sf-media-text { padding: .55rem .6rem .5rem; }
  .sf[data-sf-icons="1"] .sf-media-text, .sf-tile.is-video .sf-media-text { padding-top: 2.15rem; }
  .sf-text { font-size: .86rem; }
}
/* As many whole lines of 1.45rem as fit (the ellipsis marks the cut) ... */
@container sf-text (max-height: 10.15rem) { .sf-text { -webkit-line-clamp: 6; } }
@container sf-text (max-height: 8.7rem)   { .sf-text { -webkit-line-clamp: 5; } }
@container sf-text (max-height: 7.25rem)  { .sf-text { -webkit-line-clamp: 4; } }
@container sf-text (max-height: 5.8rem)   { .sf-text { -webkit-line-clamp: 3; } }
@container sf-text (max-height: 4.35rem)  { .sf-text { -webkit-line-clamp: 2; } }
/* ... and in very short tiles (wide 16:9 in many columns) smaller lines of 1.066rem, so two still fit. */
@container sf-text (max-height: 2.9rem)   { .sf-text { font-size: .82rem; line-height: 1.3; -webkit-line-clamp: 2; } }
@container sf-text (max-height: 2.13rem)  { .sf-text { -webkit-line-clamp: 1; } }

/* Network icon and video badge. The badge never reaches the icon: it is capped to the room
   left of it (a longer label is cut with an ellipsis), and on small tiles it is only the
   play sign. */
.sf-icon, .sf-video {
  position: absolute; top: .55rem; z-index: 2; display: inline-flex; align-items: center; gap: .3rem;
  color: #fff; background: rgba(20, 16, 18, .55); border-radius: 999px; line-height: 1;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.sf-icon { right: .55rem; width: 1.9rem; height: 1.9rem; justify-content: center; }
.sf-icon .icon { width: 16px; height: 16px; }
.sf-video {
  left: .55rem; max-width: calc(100% - 1.1rem); min-height: 1.6rem; padding: .3rem .6rem .3rem .5rem;
  font-size: .74rem; font-weight: 600; letter-spacing: .02em; white-space: nowrap; overflow: hidden;
}
.sf[data-sf-icons="1"] .sf-video { max-width: calc(100% - 1.1rem - 1.9rem - .4rem); }
.sf-video .icon { flex: none; width: 11px; height: 11px; }
.sf-video span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@container sf-tile (max-width: 9.5rem) {
  .sf-icon, .sf-video { top: .4rem; }
  .sf-icon { right: .4rem; width: 1.6rem; height: 1.6rem; }
  .sf-icon .icon { width: 14px; height: 14px; }
  .sf-video { left: .4rem; width: 1.6rem; height: 1.6rem; min-height: 0; padding: 0; justify-content: center; }
  .sf-video span { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}

/* Captions -------------------------------------------------------------------- */
.sf-cap { display: flex; flex-direction: column; gap: .35rem; font-size: .92rem; line-height: 1.45; }
.sf-cap-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--sf-lines); overflow: hidden; overflow-wrap: anywhere; }
.sf-date { font-size: .8rem; opacity: .85; font-weight: 600; letter-spacing: .02em; }

/* always: under the picture */
.sf[data-sf-captions="always"] .sf-cap { padding: .8rem .9rem .95rem; }

/* hover: over the bottom of the picture, shown on hover / keyboard focus (always on touch screens) */
.sf[data-sf-captions="hover"] .sf-cap {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1; padding: 2.2rem .9rem .85rem; color: #fff;
  background: linear-gradient(to top, rgba(18, 14, 16, .86) 0%, rgba(18, 14, 16, .55) 60%, rgba(18, 14, 16, 0) 100%);
  opacity: 0; transform: translateY(8px);
  transition: opacity .25s ease, transform .25s var(--ease, ease);
}
.sf[data-sf-captions="hover"] .sf-tile:hover .sf-cap,
.sf[data-sf-captions="hover"] .sf-tile:focus-visible .sf-cap,
.sf[data-sf-captions="hover"] .sf-tile:focus-within .sf-cap { opacity: 1; transform: none; }
@media (hover: none) {
  /* Touch screens have no hover: a lighter caption (at most two lines) stays on the picture. */
  .sf[data-sf-captions="hover"] .sf-cap { opacity: 1; transform: none; padding-top: 1.6rem; font-size: .84rem; }
  .sf[data-sf-captions="hover"] .sf-cap-text { -webkit-line-clamp: min(var(--sf-lines), 2); }
}
/* none: only a small date chip when dates are on */
.sf[data-sf-captions="none"] .sf-cap {
  position: absolute; left: .55rem; bottom: .55rem; z-index: 1; padding: .25rem .6rem;
  color: #fff; background: rgba(20, 16, 18, .6); border-radius: 999px;
}
.sf-tile.is-text .sf-cap { position: static; opacity: 1; transform: none; background: none; color: inherit; padding: .7rem .9rem .8rem; }

/* Hover effects ------------------------------------------------------------------ */
.sf[data-sf-hover="zoom"] .sf-tile:hover .sf-media img,
.sf[data-sf-hover="zoom"] .sf-tile:focus-visible .sf-media img { transform: scale(1.06); }
.sf[data-sf-hover="lift"] .sf-tile:hover,
.sf[data-sf-hover="lift"] .sf-tile:focus-visible { transform: translateY(-4px); box-shadow: var(--shadow-hover, 0 18px 40px rgba(0, 0, 0, .14)); }
.sf[data-sf-hover="fade"] .sf-tile:hover .sf-media img,
.sf[data-sf-hover="fade"] .sf-tile:focus-visible .sf-media img { opacity: .78; }

html[data-motion="off"] .sf-tile, html[data-motion="off"] .sf-media img, html[data-motion="off"] .sf-cap { transition: none; }
html[data-motion="off"] .sf[data-sf-hover="zoom"] .sf-tile:hover .sf-media img,
html[data-motion="off"] .sf[data-sf-hover="zoom"] .sf-tile:focus-visible .sf-media img,
html[data-motion="off"] .sf[data-sf-hover="lift"] .sf-tile:hover,
html[data-motion="off"] .sf[data-sf-hover="lift"] .sf-tile:focus-visible { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .sf-tile, .sf-media img, .sf-cap { transition: none !important; }
  .sf[data-sf-hover="zoom"] .sf-tile:hover .sf-media img,
  .sf[data-sf-hover="zoom"] .sf-tile:focus-visible .sf-media img,
  .sf[data-sf-hover="lift"] .sf-tile:hover,
  .sf[data-sf-hover="lift"] .sf-tile:focus-visible,
  .sf[data-sf-captions="hover"] .sf-cap { transform: none !important; }
}

/* Tabs (one per network; plain radio buttons, so they work without JavaScript) ------ */
.sf-tabs { position: relative; }
.sf-radio { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0; overflow: hidden; clip: rect(0, 0, 0, 0); opacity: 0; }
.sf-tablist { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; margin: 0 0 1.5rem; }
.sf-tab {
  display: inline-flex; align-items: center; gap: .45rem; padding: .5rem 1.05rem; min-height: 2.5rem;
  border: 1px solid var(--sf-border-color, var(--line-strong)); border-radius: var(--radius, 999px);
  background: transparent; color: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; user-select: none;
  transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}
.sf-tab:hover { border-color: var(--primary); }
.sf.band-dark .sf-tab { border-color: rgba(255, 255, 255, .4); }
.sf-panel { display: none; }
.sf-r-all:checked ~ .sf-panel-all,
.sf-r-instagram:checked ~ .sf-panel-instagram,
.sf-r-facebook:checked ~ .sf-panel-facebook,
.sf-r-tiktok:checked ~ .sf-panel-tiktok,
.sf-r-other:checked ~ .sf-panel-other { display: block; }
.sf-r-all:checked ~ .sf-tablist .sf-tab-all,
.sf-r-instagram:checked ~ .sf-tablist .sf-tab-instagram,
.sf-r-facebook:checked ~ .sf-tablist .sf-tab-facebook,
.sf-r-tiktok:checked ~ .sf-tablist .sf-tab-tiktok,
.sf-r-other:checked ~ .sf-tablist .sf-tab-other { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.sf-r-all:focus-visible ~ .sf-tablist .sf-tab-all,
.sf-r-instagram:focus-visible ~ .sf-tablist .sf-tab-instagram,
.sf-r-facebook:focus-visible ~ .sf-tablist .sf-tab-facebook,
.sf-r-tiktok:focus-visible ~ .sf-tablist .sf-tab-tiktok,
.sf-r-other:focus-visible ~ .sf-tablist .sf-tab-other { outline: 3px solid var(--focus); outline-offset: 3px; }

/* Follow buttons ------------------------------------------------------------------ */
.sf-follow { display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem; margin-top: 2rem; }
.sf.sf-custom .sf-follow .btn-outline { color: inherit; border-color: currentColor; }

/* Admin preview: shown when there is nothing to display yet */
.sf-empty-preview { max-width: 34rem; margin: 3rem auto; padding: 1.25rem 1.5rem; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius-card, 16px); background: var(--surface); color: var(--ink); }

@media print {
  .sf { display: none; }
}
