/*
 * RF-20-U: Casos de sucesso da Unitri (grade + páginas de história).
 * Base visual: tokens var(--ui-*) de css/ui-tokens.css, cabeçalho css/secao-cabecalho.css
 * e cartões no padrão visual do catálogo (.cc-card).
 * Escopo: todo seletor dentro de .cs-casos ou .pi-pagina--caso.
 */

/* ------------------------------------------------------------------ */
/* 1. Grade de casos de sucesso (.cs-casos)                           */
/* ------------------------------------------------------------------ */
.cs-casos {
  position: relative;
  margin-top: 40px;
  padding: 64px 0 88px;
  background: var(--ui-bg-mist);
  color: var(--ui-ink);
  font-family: var(--ui-font);
  border-top: 1px solid var(--ui-line);
}

.cs-casos *,
.cs-casos *::before,
.cs-casos *::after {
  box-sizing: border-box;
}

.cs-casos i {
  color: inherit;
}

.cs-casos .cs-container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px;
}

.cs-casos .secao-cabecalho {
  margin-bottom: 32px;
}

/* Barra de filtros por curso (.cs-barra) */
.cs-casos .cs-barra {
  position: sticky;
  top: var(--pi-nav-top, 84px);
  z-index: 20;
  margin-bottom: 32px;
  padding: 16px 0;
  background: rgba(246, 245, 251, 0.94);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--ui-line);
  border-bottom: 1px solid var(--ui-line);
}

.cs-casos .cs-barra__inner {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cs-casos .cs-filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cs-casos .cs-chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1.5px solid var(--ui-line);
  border-radius: 999px;
  background: #fff;
  color: var(--ui-muted);
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.03em;
  line-height: 1.1;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.cs-casos .cs-chip:hover {
  border-color: var(--ui-navy);
  color: var(--ui-navy);
}

.cs-casos .cs-chip.is-ativo,
.cs-casos .cs-chip[aria-pressed="true"] {
  border-color: var(--ui-navy);
  background: var(--ui-navy);
  color: #fff;
  box-shadow: 0 8px 20px -12px rgba(18, 3, 99, 0.65);
}

.cs-casos .cs-chip:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 2px;
}

.cs-casos .cs-chip__qtd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--ui-tint);
  color: var(--ui-navy);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.cs-casos .cs-chip.is-ativo .cs-chip__qtd,
.cs-casos .cs-chip[aria-pressed="true"] .cs-chip__qtd {
  background: var(--ui-yellow);
  color: var(--ui-navy);
}

.cs-casos .cs-barra__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cs-casos .cs-contagem {
  margin: 0;
  color: var(--ui-muted);
  font-size: 14px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cs-casos .cs-limpar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border: 1.5px solid var(--ui-navy);
  border-radius: 999px;
  background: transparent;
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    background-color 0.18s ease,
    color 0.18s ease;
}

.cs-casos .cs-limpar[hidden] {
  display: none;
}

.cs-casos .cs-limpar:hover {
  background: var(--ui-navy);
  color: #fff;
}

.cs-casos .cs-limpar:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 2px;
}

/* Grade: 1 col no celular, 2 no tablet, 3 no desktop */
.cs-casos .cs-grade {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cs-casos .cs-grade[hidden] {
  display: none;
}

.cs-casos .cs-item {
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cs-casos .cs-item[hidden] {
  display: none;
}

@media (min-width: 768px) {
  .cs-casos .cs-grade {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 992px) {
  .cs-casos .cs-grade {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
  }
}

/* Cartão (.cs-card) no padrão visual do .cc-card */
.cs-casos .cs-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--ui-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--ui-shadow-card);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease,
    border-color 0.25s ease;
}

.cs-casos .cs-card:hover,
.cs-casos .cs-card:focus-within {
  transform: translateY(-4px);
  border-color: #cfcbe3;
  box-shadow: var(--ui-shadow-pop);
}

/* Mídia 4:3 */
.cs-casos .cs-card__midia {
  position: relative;
  flex: none;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.cs-casos .cs-card__midia--indigo {
  background: linear-gradient(160deg, var(--ui-indigo-800) 0%, var(--ui-indigo-900) 100%);
}

.cs-casos .cs-card__midia--lavanda {
  background: var(--ui-tint);
}

.cs-casos .cs-card__img,
.cs-casos .cs-card__midia > svg {
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
}

.cs-casos .cs-card__img {
  object-fit: cover;
  object-position: center 20%;
  transition: transform 0.45s ease;
}

.cs-casos .cs-card:hover .cs-card__img,
.cs-casos .cs-card:focus-within .cs-card__img {
  transform: scale(1.05);
}

.cs-casos .cs-card__midia--foto::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(28, 26, 74, 0) 45%, rgba(28, 26, 74, 0.52) 100%);
  pointer-events: none;
}

/* Selo do curso sobre a mídia */
.cs-casos .cs-card__selos {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  pointer-events: none;
}

.cs-casos .cs-card__selo {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 4px 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 4px 10px -4px rgba(28, 26, 74, 0.35);
  color: var(--ui-navy);
  font-size: 11.5px;
  font-weight: 700;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Corpo do cartão */
.cs-casos .cs-card__corpo {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px 20px;
}

.cs-casos .cs-card__titulo {
  margin: 0;
  padding: 0;
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  text-align: left;
  text-transform: none;
}

.cs-casos .cs-card__link {
  display: -webkit-box;
  padding: 0.12em 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  color: var(--ui-navy);
  text-decoration: none;
}

.cs-casos .cs-card__link::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.cs-casos .cs-card__link:hover {
  color: var(--ui-navy);
  text-decoration: none;
}

.cs-casos .cs-card__link:focus-visible {
  outline: none;
}

.cs-casos .cs-card__link:focus-visible::after {
  border-radius: 20px;
  outline: 3px solid var(--ui-navy);
  outline-offset: -3px;
}

.cs-casos .cs-card__resumo {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  color: var(--ui-muted);
  font-size: 14.5px;
  line-height: 1.5;
}

.cs-casos .cs-card__rodape {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--ui-line);
}

.cs-casos .cs-card__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ui-navy);
  font-size: 14.5px;
  font-weight: 700;
  line-height: 1.2;
}

.cs-casos .cs-card__seta {
  display: inline-block;
  transition: transform 0.2s ease;
}

.cs-casos .cs-card:hover .cs-card__cta,
.cs-casos .cs-card:focus-within .cs-card__cta {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.cs-casos .cs-card:hover .cs-card__seta,
.cs-casos .cs-card:focus-within .cs-card__seta {
  transform: translateX(4px);
}

/* Estado vazio e botão "Mostrar mais" */
.cs-casos .cs-vazio {
  max-width: 480px;
  margin: 24px auto 0;
  padding: 40px 24px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: #fff;
  text-align: center;
  box-shadow: var(--ui-shadow-card);
}

.cs-casos .cs-vazio[hidden] {
  display: none;
}

.cs-casos .cs-vazio__titulo {
  margin: 0 0 8px;
  color: var(--ui-navy);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.cs-casos .cs-vazio__texto {
  margin: 0 0 20px;
  color: var(--ui-muted);
  font-size: 15px;
  line-height: 1.5;
}

.cs-casos .cs-vazio__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 26px;
  border: 0;
  border-radius: 999px;
  background: var(--ui-yellow);
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.18s ease;
}

.cs-casos .cs-vazio__btn:hover {
  background: var(--ui-yellow-dark);
}

.cs-casos .cs-vazio__btn:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 2px;
}

.cs-casos .cs-mais-wrap {
  display: flex;
  justify-content: center;
  margin-top: 36px;
}

.cs-casos .cs-mais-wrap[hidden] {
  display: none;
}

.cs-casos .cs-mais {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 32px;
  border: 2px solid var(--ui-navy);
  border-radius: 999px;
  background: #fff;
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  box-shadow: var(--ui-shadow-card);
  transition:
    background-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease;
}

.cs-casos .cs-mais:hover {
  background: var(--ui-navy);
  color: #fff;
  box-shadow: var(--ui-shadow-pop);
}

.cs-casos .cs-mais:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ */
/* 2. Página de história (.pi-pagina--caso)                           */
/* ------------------------------------------------------------------ */
.pi-pagina--caso .pi-leitura {
  display: flow-root;
}

.pi-pagina--caso .pi-leitura a:has(> img) {
  text-decoration: none;
}

/* Primeira imagem da história: largura total acima do texto em telas menores */
.pi-pagina--caso .pi-leitura > img:first-of-type,
.pi-pagina--caso .pi-leitura > :has(img) img:first-of-type {
  display: block;
  float: none;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0 0 24px;
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-card);
}

.pi-pagina--caso .pi-leitura > figure:has(img),
.pi-pagina--caso .pi-leitura > .wp-caption:has(img) {
  float: none;
  width: 100% !important;
  max-width: 100%;
  margin: 0 0 24px;
}

.pi-pagina--caso .pi-leitura > figure:has(img) img,
.pi-pagina--caso .pi-leitura > .wp-caption:has(img) img {
  margin: 0;
}

/* Imagens seguintes mantêm o comportamento padrão da leitura */
.pi-pagina--caso .pi-leitura > :has(img) ~ :has(img) img,
.pi-pagina--caso .pi-leitura > img ~ :has(img) img,
.pi-pagina--caso .pi-leitura > :has(img) ~ img,
.pi-pagina--caso .pi-leitura > img ~ img,
.pi-pagina--caso .pi-leitura > :has(img) :has(img) ~ :has(img) img {
  display: inline-block;
  float: none;
  width: auto;
  max-width: 100%;
  margin: 0;
  border-radius: var(--ui-radius-sm);
  box-shadow: none;
}

.pi-pagina--caso .pi-leitura > :has(img) ~ figure:has(img),
.pi-pagina--caso .pi-leitura > :has(img) ~ .wp-caption:has(img),
.pi-pagina--caso .pi-leitura > img ~ figure:has(img),
.pi-pagina--caso .pi-leitura > img ~ .wp-caption:has(img) {
  float: none;
  width: auto !important;
  max-width: 100%;
  margin: 1.5em 0;
}

/* Rodapé da história (<aside class="cs-historia-rodape">) */
.pi-pagina--caso .cs-historia-rodape {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  max-width: 72ch;
  margin: 40px auto 0;
  padding-top: 32px;
  border-top: 1px solid var(--ui-line);
}

.pi-pagina--caso .cs-historia-curso {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 24px;
  padding: 24px 28px;
  border: 1px solid var(--ui-line);
  border-radius: var(--ui-radius-lg);
  background: var(--ui-bg-mist);
  box-shadow: var(--ui-shadow-card);
}

.pi-pagina--caso .cs-historia-curso__info {
  min-width: 0;
  flex: 1 1 260px;
}

.pi-pagina--caso .cs-historia-curso__eyebrow {
  margin: 0 0 6px;
  color: var(--ui-muted);
  font-family: var(--ui-font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.3;
  text-transform: uppercase;
}

.pi-pagina--caso .cs-historia-curso__titulo {
  margin: 0;
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.25;
}

.pi-pagina--caso .cs-historia-curso__cta {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 24px;
  border: 0;
  border-radius: 14px;
  background: var(--ui-yellow);
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  box-shadow: var(--ui-shadow-card);
  transition:
    background-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.pi-pagina--caso .cs-historia-curso__cta::after {
  content: "\2192";
  flex: none;
  font-size: 17px;
  line-height: 1;
  transition: transform 0.18s ease;
}

.pi-pagina--caso .cs-historia-curso__cta:hover,
.pi-pagina--caso .cs-historia-curso__cta:active {
  background: var(--ui-yellow-dark);
  color: var(--ui-navy);
  text-decoration: none;
  box-shadow: var(--ui-shadow-pop);
}

.pi-pagina--caso .cs-historia-curso__cta:hover::after {
  transform: translateX(3px);
}

.pi-pagina--caso .cs-historia-curso__cta:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 3px;
}

.pi-pagina--caso .cs-historia-voltar {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1.5px solid var(--ui-line);
  border-radius: 999px;
  background: #fff;
  color: var(--ui-navy);
  font-family: var(--ui-font);
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  transition:
    border-color 0.18s ease,
    background-color 0.18s ease,
    color 0.18s ease;
}

.pi-pagina--caso .cs-historia-voltar:hover {
  border-color: var(--ui-navy);
  background: var(--ui-tint);
  color: var(--ui-navy);
  text-decoration: none;
}

.pi-pagina--caso .cs-historia-voltar:focus-visible {
  outline: 3px solid var(--ui-navy);
  outline-offset: 2px;
}

/* Desktop (>= 992px): primeira foto flutua à direita com max-width 360px */
@media (min-width: 992px) {
  .pi-pagina--caso .pi-leitura {
    max-width: 840px;
  }

  .pi-pagina--caso .cs-historia-rodape {
    max-width: 840px;
  }

  .pi-pagina--caso .pi-corpo.pi-corpo--com-indice .cs-historia-rodape {
    grid-column: 1;
    margin-left: 0;
    margin-right: 0;
  }

  .pi-pagina--caso .pi-leitura > img:first-of-type,
  .pi-pagina--caso .pi-leitura > :not(figure):not(.wp-caption):has(img) img:first-of-type {
    float: right;
    width: auto;
    max-width: 360px;
    margin: 4px 0 20px 32px;
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow-card);
  }

  .pi-pagina--caso .pi-leitura > figure:has(img),
  .pi-pagina--caso .pi-leitura > .wp-caption:has(img) {
    float: right;
    width: auto !important;
    max-width: 360px;
    margin: 4px 0 20px 32px;
  }

  .pi-pagina--caso .pi-leitura > figure:has(img) img,
  .pi-pagina--caso .pi-leitura > .wp-caption:has(img) img {
    float: none;
    width: 100%;
    max-width: 360px;
    margin: 0;
  }

  .pi-pagina--caso .pi-leitura > :has(img) ~ :has(img) img,
  .pi-pagina--caso .pi-leitura > img ~ :has(img) img,
  .pi-pagina--caso .pi-leitura > :has(img) ~ img,
  .pi-pagina--caso .pi-leitura > img ~ img,
  .pi-pagina--caso .pi-leitura > :has(img) :has(img) ~ :has(img) img {
    float: none;
    width: auto;
    max-width: 100%;
    margin: 0;
    border-radius: var(--ui-radius-sm);
    box-shadow: none;
  }

  .pi-pagina--caso .pi-leitura > :has(img) ~ figure:has(img),
  .pi-pagina--caso .pi-leitura > :has(img) ~ .wp-caption:has(img),
  .pi-pagina--caso .pi-leitura > img ~ figure:has(img),
  .pi-pagina--caso .pi-leitura > img ~ .wp-caption:has(img) {
    float: none;
    width: auto !important;
    max-width: 100%;
    margin: 1.5em 0;
  }
}

/* ------------------------------------------------------------------ */
/* 3. Responsivo                                                      */
/* ------------------------------------------------------------------ */
@media (max-width: 991.98px) {
  .cs-casos {
    margin-top: 32px;
    padding: 48px 0 72px;
  }
}

@media (max-width: 767.98px) {
  .cs-casos {
    margin-top: 24px;
    padding: 40px 0 64px;
  }

  .cs-casos .cs-container {
    padding: 0 16px;
  }

  .cs-casos .cs-barra {
    margin-bottom: 24px;
    padding: 12px 0;
  }

  .cs-casos .cs-filtros {
    flex-wrap: nowrap;
    overflow-x: auto;
    margin: 0 -2px;
    padding: 2px 24px 4px 2px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to right, #000 88%, transparent 100%);
    mask-image: linear-gradient(to right, #000 88%, transparent 100%);
  }

  .cs-casos .cs-filtros::-webkit-scrollbar {
    display: none;
  }

  .cs-casos .cs-chip {
    scroll-snap-align: start;
  }

  .cs-casos .cs-mais {
    width: 100%;
    max-width: 320px;
  }

  .pi-pagina--caso .cs-historia-rodape {
    margin-top: 32px;
    padding-top: 24px;
  }

  .pi-pagina--caso .cs-historia-curso {
    padding: 20px;
    border-radius: var(--ui-radius);
  }

  .pi-pagina--caso .cs-historia-curso__titulo {
    font-size: 19px;
  }

  .pi-pagina--caso .cs-historia-curso__cta {
    width: 100%;
  }
}

/* ------------------------------------------------------------------ */
/* 4. Movimento reduzido                                              */
/* ------------------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .cs-casos *,
  .cs-casos *::before,
  .cs-casos *::after,
  .pi-pagina--caso .cs-historia-rodape *,
  .pi-pagina--caso .cs-historia-rodape *::before,
  .pi-pagina--caso .cs-historia-rodape *::after {
    transition: none !important;
  }

  .cs-casos .cs-card:hover,
  .cs-casos .cs-card:focus-within,
  .cs-casos .cs-card:hover .cs-card__img,
  .cs-casos .cs-card:focus-within .cs-card__img,
  .cs-casos .cs-card:hover .cs-card__seta,
  .cs-casos .cs-card:focus-within .cs-card__seta,
  .pi-pagina--caso .cs-historia-curso__cta:hover::after {
    transform: none;
  }
}

/* A imagem quebrada recebe [hidden] no JS; o display:block do .cs-card__img não pode anular o atributo. */
.cs-casos .cs-card__img[hidden] {
  display: none;
}

/* Foto da história levada ao início do texto por unitri_casos_destacar_foto() */
.pi-pagina--caso .pi-leitura > figure.cs-historia-foto {
  float: none;
  width: 100% !important;
  max-width: 420px;
  margin: 0 auto 24px;
}

.pi-pagina--caso .pi-leitura > figure.cs-historia-foto img {
  display: block;
  float: none;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0;
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-card);
}

@media (min-width: 992px) {
  .pi-pagina--caso .pi-leitura > figure.cs-historia-foto {
    float: right;
    width: 360px !important;
    margin: 4px 0 20px 32px;
  }
}
