/*!
 * TNHA 首頁「照護知識庫」分主題導流 widget — public/widgets/home-latest.css
 * All rules scoped under .tnha-home-latest to avoid leaking into the Duda page.
 * Palette matches public/widgets/notes.css (site green #2d7a3a / accent #e67a2d,
 * per reference_duda_real_css_colors — this is the *website* palette, not the
 * platform app's v2.1 orange).
 * Layout v1.1: one full-width section per topic, cards 3-up on desktop, stacked on mobile.
 */
.tnha-home-latest {
  --thl-primary: #2d7a3a;
  --thl-primary-soft: #e8f3ea;
  --thl-accent: #e67a2d;
  --thl-bg: #fffbf4;
  --thl-surface: #fff0e0;
  --thl-card: #ffffff;
  --thl-text: #333333;
  --thl-muted: #6f6f64;
  --thl-border: #e6e2d6;
  box-sizing: border-box;
  max-width: 100%;
  color: var(--thl-text);
  font-size: 16px;
  line-height: 1.6;
  /* 載入態先佔高度，資料回來後不跳動。 */
  min-height: 560px;
}
.tnha-home-latest[data-state="ready"] {
  min-height: 0;
}
.tnha-home-latest,
.tnha-home-latest *,
.tnha-home-latest *::before,
.tnha-home-latest *::after {
  box-sizing: border-box;
}

.tnha-home-latest__sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* header */
.tnha-home-latest__header {
  margin-bottom: 24px;
  text-align: center;
}
.tnha-home-latest__title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 700;
  color: var(--thl-primary);
}
.tnha-home-latest__subtitle {
  margin: 0;
  font-size: 15px;
  color: var(--thl-muted);
}

/* sections */
.tnha-home-latest__sections {
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.tnha-home-latest__section {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "head button"
    "cards cards";
  align-items: end;
  column-gap: 16px;
  row-gap: 18px;
  padding: 24px;
  background: var(--thl-bg);
  border: 1px solid var(--thl-border);
  border-radius: 16px;
}
.tnha-home-latest__section-head {
  grid-area: head;
  min-width: 0;
  padding-left: 14px;
  border-left: 4px solid var(--thl-primary);
}
.tnha-home-latest__section-title {
  margin: 0 0 2px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--thl-text);
}
.tnha-home-latest__section-tagline {
  margin: 0;
  font-size: 15px;
  color: var(--thl-muted);
}

/* cards */
.tnha-home-latest__cards {
  grid-area: cards;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}
.tnha-home-latest__card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--thl-card);
  border: 1px solid var(--thl-border);
  border-radius: 12px;
  overflow: hidden;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.tnha-home-latest__card.is-link:hover {
  box-shadow: 0 6px 18px rgba(45, 122, 58, 0.12);
  transform: translateY(-2px);
}
.tnha-home-latest__card-media {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--thl-surface);
  overflow: hidden;
}
.tnha-home-latest__card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.tnha-home-latest__card-media--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--thl-primary-soft), #f4efe2);
  color: var(--thl-primary);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1em;
}
.tnha-home-latest__card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px 18px;
  min-width: 0;
}

/* 季刊：封面在左、文字在右（3:4 封面直式放上方會把卡片撐太高） */
.tnha-home-latest__card--quarterly {
  flex-direction: row;
  align-items: stretch;
}
.tnha-home-latest__card-media--cover {
  flex: 0 0 104px;
  width: 104px;
  aspect-ratio: 3 / 4;
}

.tnha-home-latest__badge,
.tnha-home-latest__chip {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
}
.tnha-home-latest__badge {
  color: #fff;
}
.tnha-home-latest__chip {
  color: var(--thl-primary);
  background: var(--thl-primary-soft);
}
.tnha-home-latest__card-eyebrow {
  font-size: 13px;
  font-weight: 700;
  color: var(--thl-accent);
}
.tnha-home-latest__card-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.5;
  color: var(--thl-text);
  text-decoration: none;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
/* 整張卡可點：把標題連結的點擊範圍撐滿卡片 */
a.tnha-home-latest__card-title::after {
  content: "";
  position: absolute;
  inset: 0;
}
.tnha-home-latest__card.is-link:hover .tnha-home-latest__card-title {
  color: var(--thl-primary);
}
.tnha-home-latest__card-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.65;
  color: var(--thl-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tnha-home-latest__card-date {
  margin-top: auto;
  padding-top: 4px;
  font-size: 13px;
  color: var(--thl-muted);
}

.tnha-home-latest__empty {
  grid-column: 1 / -1;
  margin: 0;
  padding: 20px;
  background: var(--thl-card);
  border: 1px dashed var(--thl-border);
  border-radius: 12px;
  color: var(--thl-muted);
  font-size: 15px;
  text-align: center;
}

/* button */
.tnha-home-latest__button {
  grid-area: button;
  justify-self: end;
  display: inline-block;
  padding: 9px 22px;
  border-radius: 999px;
  border: 1.5px solid var(--thl-primary);
  background: var(--thl-card);
  color: var(--thl-primary);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  text-align: center;
}
a.tnha-home-latest__button:hover {
  background: var(--thl-primary);
  color: #fff;
}
span.tnha-home-latest__button {
  opacity: 0.5;
  cursor: default;
}

/* skeleton */
.tnha-home-latest__section--skeleton {
  grid-template-areas:
    "head head"
    "cards cards";
}
.tnha-home-latest__skel-head {
  grid-area: head;
  width: 40%;
  height: 48px;
}
.tnha-home-latest__skel-card {
  height: 180px;
}
.tnha-home-latest__skel-head,
.tnha-home-latest__skel-card {
  border-radius: 12px;
  background: linear-gradient(90deg, var(--thl-surface) 25%, #fff7ea 37%, var(--thl-surface) 63%);
  background-size: 400% 100%;
  animation: thl-shimmer 1.4s ease infinite;
}
@keyframes thl-shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* focus visibility for keyboard nav */
.tnha-home-latest a:focus-visible {
  outline: 2px solid var(--thl-primary);
  outline-offset: 2px;
}

/* 平板：卡片兩欄 */
@media (max-width: 1024px) and (min-width: 769px) {
  .tnha-home-latest__cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* ≤768px：卡片上下疊、按鈕移到卡片下方、圖改成左側縮圖以免版面過長 */
@media (max-width: 768px) {
  .tnha-home-latest {
    min-height: 0;
  }
  .tnha-home-latest__title {
    font-size: 24px;
  }
  .tnha-home-latest__sections {
    gap: 20px;
  }
  .tnha-home-latest__section {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "cards"
      "button";
    padding: 18px 16px;
    row-gap: 14px;
  }
  .tnha-home-latest__section-title {
    font-size: 20px;
  }
  .tnha-home-latest__cards {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .tnha-home-latest__card--note {
    flex-direction: row;
  }
  .tnha-home-latest__card--note .tnha-home-latest__card-media {
    flex: 0 0 112px;
    width: 112px;
    aspect-ratio: auto;
  }
  .tnha-home-latest__card--note .tnha-home-latest__card-media--placeholder {
    font-size: 14px;
  }
  .tnha-home-latest__card-media--cover {
    flex-basis: 84px;
    width: 84px;
  }
  .tnha-home-latest__card-body {
    padding: 12px 14px;
  }
  .tnha-home-latest__card-text {
    -webkit-line-clamp: 2;
  }
  .tnha-home-latest__button {
    justify-self: stretch;
  }
  .tnha-home-latest__skel-head {
    width: 60%;
  }
  .tnha-home-latest__skel-card {
    height: 96px;
  }
}
