/*
 * Trang Kiến thức nhà nông (wireframe M15, D15) — kien-thuc.html
 * bai-viet.html cũng nạp file này để dùng chung thẻ bài viết, nhãn video, khối Hỏi kỹ sư.
 * Phụ thuộc: tokens.css, base.css, components.css, layout.css
 * Class riêng mang tiền tố tg-blog-.
 */

/* Mobile: thẻ trắng cách mép 8px như wireframe */
@media (max-width: 1023px) {
  .tg-blog {
    padding-top: 0;
  }

  .tg-blog > .tg-container,
  .tg-blog-layout {
    padding-inline: var(--space-2);
  }
}

/* =========================================================
   Phần dùng chung với trang bài viết
   ========================================================= */

/* Nhãn chuyên mục: chữ hoa xanh. Wireframe 11px trên nền trắng, nâng lên 14px (chỉ nhãn trên nền màu mới được 12px) */
.tg-blog-cat {
  color: var(--color-brand);
  font-size: var(--text-meta);
  font-weight: var(--weight-bold);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.tg-blog-meta {
  color: var(--color-text-muted);
  font-size: var(--text-meta);
}

/* Nhãn video trên ảnh */
.tg-blog-badge {
  position: absolute;
  bottom: var(--space-1-5);
  left: var(--space-1-5);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px var(--space-1-5);
  border-radius: var(--radius-sm);
  background: var(--color-photo-label);
  color: var(--color-text-on-dark);
  font-size: var(--text-label);
  font-weight: var(--weight-semibold);
  line-height: 1.4;
  --icon-size: 10px;
}

.tg-blog-badge--top {
  top: var(--space-2);
  bottom: auto;
  left: var(--space-2);
  padding: 3px var(--space-2);
  font-size: var(--text-12);
  --icon-size: 12px;
}

/* Nút play tròn giữa ảnh */
.tg-blog-play {
  position: absolute;
  top: 50%;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: var(--radius-round);
  background: var(--color-on-image);
  box-shadow: var(--shadow-card);
  color: var(--color-brand);
  transform: translate(-50%, -50%);
  --icon-size: 22px;
}

/* Thẻ bài viết .tg-article-card--responsive: mobile là dòng ngang (ảnh nhỏ bên trái), desktop là thẻ dọc.
   Ở đây chỉ chỉnh cỡ ảnh, khoảng cách riêng của trang kiến thức. */
.tg-blog-card__media {
  position: relative;
  flex: none;
}

.tg-blog-card .tg-article-card__title {
  font-size: var(--text-14);
  line-height: 1.4;
}

.tg-blog-card__excerpt {
  display: none;
}

@media (max-width: 1023px) {
  .tg-blog-card {
    align-items: stretch;
    gap: var(--space-3);
    overflow: hidden;
    padding: var(--space-3) 0;
    border-top: 1px solid var(--color-divider);
  }

  .tg-blog-card .tg-blog-card__media img {
    width: 116px;
    height: 80px;
    aspect-ratio: auto;
    border-radius: var(--radius-lg);
  }

  .tg-blog-card .tg-article-card__body {
    flex: 1;
    gap: var(--space-1);
    min-width: 0;
    padding: 0;
  }
}

/* Khối Hỏi kỹ sư qua Zalo (nền xanh đậm) */
.tg-blog-ask {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4);
  border-radius: var(--radius-2xl);
  background: var(--color-brand-strong);
  color: var(--color-text-on-dark);
}

.tg-blog-ask__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-min);
  height: var(--tap-min);
  border-radius: var(--radius-round);
  background: var(--glass-bg);
}

.tg-blog-ask__title {
  font-size: var(--text-16);
  line-height: var(--leading-snug);
}

.tg-blog-ask__text {
  color: var(--color-footer-text);
  font-size: var(--text-meta);
  line-height: 1.55;
}

.tg-blog-ask .tg-btn {
  margin-top: var(--space-0-5);
}

/* =========================================================
   Riêng trang Kiến thức
   ========================================================= */

/* ---------- Tìm và lọc (mobile: một khối trắng) ---------- */
.tg-blog-top {
  display: flex;
  flex-direction: column;
  gap: var(--space-2-5);
  padding: var(--space-3) 0;
  background: var(--color-surface);
}

/* Mobile: khối đầu trang nền trắng, h1 chỉ cho trình đọc màn hình (tiêu đề hiện ở thanh trên) */
.tg-blog-hero__title {
  color: var(--color-brand-strong);
}

@media (max-width: 1023px) {
  .tg-blog-top .tg-container {
    padding-inline: var(--gutter);
  }

  .tg-blog-hero__title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }
}

.tg-blog-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: 0 var(--space-3);
  border: 1.5px solid var(--color-border-control);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text-muted);
  --icon-size: 18px;
}

.tg-blog-search:focus-within {
  border-color: var(--color-brand);
  box-shadow: var(--ring-input-focus);
}

.tg-blog-search__input {
  flex: 1;
  min-width: 0;
  height: calc(var(--tap-min) - 2px);   /* khung ô tìm cao 44px, trừ viền */
  border: 0;
  background: none;
  color: var(--color-text);
  font-size: var(--text-16);
  outline: none;
}

.tg-blog-search__btn {
  flex: none;
  height: 42px;
  padding: 0 var(--space-5);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--color-brand-strong);
  color: var(--color-text-on-dark);
  font-size: var(--text-15);
  font-weight: var(--weight-semibold);
}

.tg-blog-search__btn:hover {
  background: var(--color-brand);
}

.tg-blog-search__btn:focus-visible {
  outline: var(--focus-ring);
}

.tg-blog-filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2-5);
}

.tg-blog-row {
  --scroll-gap: var(--space-2);
  align-items: center;
}

.tg-blog-row--crops {
  --scroll-gap: var(--space-1-5);
}

.tg-blog-crops {
  display: flex;
  gap: var(--space-1-5);
}

/* Chuyên mục: viên thuốc, mục đang chọn tô xanh đặc */
.tg-blog-cat-chip {
  min-height: 36px;
  padding: 0 var(--space-3-5);
  border-width: 1px;
  font-size: var(--text-meta);
  font-weight: var(--weight-medium);
}

.tg-blog-cat-chip.is-active {
  border-color: var(--color-brand);
  background: var(--color-brand);
  box-shadow: none;
  color: var(--color-text-on-dark);
  font-weight: var(--weight-semibold);
}

.tg-blog-cat-chip.is-active:hover {
  color: var(--color-text-on-dark);
}

/* Cây trồng: ô bo nhẹ nền be, mục đang chọn nền xanh nhạt */
.tg-blog-crop {
  min-height: 32px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-surface-alt);
  color: var(--color-text-secondary);
}

.tg-blog-crop:hover {
  color: var(--color-brand-strong);
}

.tg-blog-crop.is-active {
  background: var(--color-brand-soft);
  box-shadow: inset 0 0 0 1px var(--color-brand);
  color: var(--color-brand-strong);
  font-weight: var(--weight-semibold);
}

/* Vùng bấm 44px cho ô cao 32px */
@media (max-width: 1023px) {
  .tg-blog-crop::after {
    inset: -6px 0;
  }
}

/* Công tắc Tất cả / Bài viết / Video (desktop) */
.tg-blog-type {
  display: flex;
  margin-left: auto;
  overflow: hidden;
  border: 1px solid var(--color-border-control);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font-size: var(--text-meta);
}

.tg-blog-type__opt {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-3-5);
  color: var(--color-text-secondary);
}

.tg-blog-type__opt + .tg-blog-type__opt {
  border-left: 1px solid var(--color-border-control);
}

.tg-blog-type__opt:hover {
  color: var(--color-brand-strong);
}

.tg-blog-type__opt.is-active {
  background: var(--color-brand-soft);
  color: var(--color-brand-strong);
  font-weight: var(--weight-semibold);
}

.tg-blog-type__opt:focus-visible {
  outline-offset: -2px;
}

.tg-blog-row__label {
  margin-right: var(--space-1);
  color: var(--color-text-muted);
  font-size: var(--text-14);
}

/* ---------- Bố cục nội dung ---------- */
.tg-blog-layout {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.tg-blog-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.tg-blog-status {
  padding: var(--space-2) var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--text-14);
}

.tg-blog-status a {
  margin-left: var(--space-2);
  font-weight: var(--weight-semibold);
  text-decoration: underline;
}

/* ---------- Bài nổi bật ---------- */
.tg-blog-featured {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-2xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  color: var(--color-text);
}

.tg-blog-featured__media {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--color-image-bg);
}

.tg-blog-featured__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tg-blog-featured__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1-5);
  padding: var(--space-3-5) var(--space-4) var(--space-4);
}

.tg-blog-featured__tag {
  color: var(--color-brand);
  font-size: var(--text-12);
  font-weight: var(--weight-bold);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.tg-blog-featured__title {
  color: var(--color-brand-strong);
  font-size: var(--text-18);
  line-height: 1.35;
}

.tg-blog-featured__title a {
  color: inherit;
}

/* Cả thẻ bấm được */
.tg-blog-featured__title a::after {
  content: "";
  position: absolute;
  inset: 0;
}

.tg-blog-featured:hover .tg-blog-featured__title {
  text-decoration: underline;
}

.tg-blog-featured__text {
  color: var(--color-text-secondary);
  font-size: var(--text-14);
  line-height: 1.55;
}

.tg-blog-author {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  font-size: var(--text-meta);
}

.tg-blog-avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-round);
  background: var(--color-brand);
  color: var(--color-text-on-dark);
  font-size: var(--text-label);
  font-weight: var(--weight-bold);
}

.tg-blog-featured__cta {
  align-self: flex-start;
  margin-top: var(--space-1-5);
  --icon-size: 16px;
}

/* ---------- Danh sách bài ---------- */
.tg-blog-list {
  display: flex;
  flex-direction: column;
  padding: var(--space-1) var(--space-4) var(--space-1-5);
  border-radius: var(--radius-2xl);
  background: var(--color-surface);
}

.tg-blog-list__title {
  padding: var(--space-3) 0 var(--space-1);
  font-size: var(--text-16);
}

.tg-blog-more {
  margin: var(--space-2) 0 var(--space-2-5);
  font-weight: var(--weight-semibold);
}

.tg-blog-empty {
  border-top: 1px solid var(--color-divider);
}

/* ---------- Cột phải ---------- */
.tg-blog-aside {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.tg-blog-side {
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-5) var(--space-3);
  box-shadow: var(--shadow-card);
}

.tg-blog-side__title {
  padding-bottom: var(--space-2);
  font-size: var(--text-17);
}

.tg-blog-popular__link {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-divider);
  color: var(--color-text);
}

.tg-blog-popular__link:hover {
  color: var(--color-brand-strong);
}

/* Số thứ tự: wireframe #B9D3BF trên nền trắng không đạt tương phản, dùng xanh thương hiệu */
.tg-blog-popular__num {
  flex: none;
  width: 22px;
  color: var(--color-brand);
  font-size: var(--text-22);
  font-weight: var(--weight-bold);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.tg-blog-popular__text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tg-blog-popular__name {
  font-size: var(--text-14);
  font-weight: var(--weight-semibold);
  line-height: 1.45;
}

.tg-blog-popular__cat {
  color: var(--color-text-muted);
  font-size: var(--text-meta);
}

.tg-blog-products .tg-product-row__img {
  width: 56px;
  height: 56px;
}

.tg-blog-products__name {
  font-size: var(--text-meta);
  font-weight: var(--weight-regular);
  line-height: 1.4;
}

.tg-blog-products + .tg-link-more {
  margin-top: var(--space-1);
  font-size: var(--text-14);
}

/* =========================================================
   Desktop (>= 1024px)
   ========================================================= */
@media (min-width: 1024px) {
  .tg-blog-top {
    gap: var(--space-4);
    padding: 0;
    background: none;
  }

  /* Khối đầu trang nền xanh đậm */
  .tg-blog-hero {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: var(--space-10);
    align-items: center;
    overflow: hidden;
    padding: var(--space-10) var(--space-10);
    border-radius: var(--radius-hero);
    background: linear-gradient(120deg, var(--color-brand-strong) 0%, var(--color-brand) 80%);
    color: var(--color-text-on-dark);
  }

  /* Hai vòng tròn trang trí */
  .tg-blog-hero::before,
  .tg-blog-hero::after {
    content: "";
    position: absolute;
    border-radius: var(--radius-round);
    background: var(--glass-bg);
    opacity: 0.5;
    pointer-events: none;
  }

  .tg-blog-hero::before {
    top: -90px;
    right: -70px;
    width: 300px;
    height: 300px;
  }

  .tg-blog-hero::after {
    bottom: -120px;
    left: 38%;
    width: 240px;
    height: 240px;
    opacity: 0.35;
  }

  .tg-blog-hero :focus-visible {
    outline: var(--focus-ring-on-dark);
  }

  /* Nút Tìm bài nằm trong ô trắng: viền focus xanh mới thấy được */
  .tg-blog-hero .tg-blog-search__btn:focus-visible {
    outline: var(--focus-ring);
  }

  .tg-blog-hero__intro {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-3-5);
  }

  .tg-blog-hero__eyebrow {
    display: inline-flex;
    align-self: flex-start;
    align-items: center;
    gap: var(--space-1-5);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    font-size: var(--text-13);
    font-weight: var(--weight-bold);
    letter-spacing: 0.4px;
    text-transform: uppercase;
    --icon-size: 16px;
  }

  .tg-blog-hero__title {
    color: var(--color-text-on-dark);
    font-size: var(--text-40);
    line-height: 1.15;
  }

  .tg-blog-hero__text {
    max-width: 620px;
    color: var(--color-footer-text);
    font-size: var(--text-17);
    line-height: var(--leading-relaxed);
  }

  .tg-blog-search {
    max-width: 600px;
    min-height: 54px;
    margin-top: var(--space-1-5);
    padding: 0 var(--space-1-5) 0 var(--space-4);
    border: 0;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
    color: var(--color-brand);
    --icon-size: 20px;
  }

  .tg-blog-search:focus-within {
    box-shadow: var(--shadow-float), 0 0 0 3px var(--color-gold);
  }

  .tg-blog-search__input {
    font-size: var(--text-15);
  }

  .tg-blog-hero__keys {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .tg-blog-hero__keys-label {
    margin-right: var(--space-0-5);
    color: var(--color-footer-text);
    font-size: var(--text-meta);
  }

  .tg-blog-key {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 var(--space-3);
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    color: var(--color-text-on-dark);
    font-size: var(--text-meta);
  }

  .tg-blog-key:hover {
    background: var(--glass-bg-strong);
    color: var(--color-text-on-dark);
  }

  .tg-blog-hero__img {
    position: relative;
    z-index: 1;
    width: 100%;
    height: 260px;
    border-radius: var(--radius-3xl);
    object-fit: cover;
    background: var(--color-image-bg);
  }

  /* Bộ lọc: xuống dòng thay vì cuộn ngang */
  .tg-blog-filters {
    gap: var(--space-3);
  }

  .tg-blog-row {
    flex-wrap: wrap;
    overflow: visible;
    margin-inline: 0;
    padding-inline: 0;
    --scroll-gap: var(--space-2-5);
  }

  .tg-blog-row--crops {
    --scroll-gap: var(--space-2);
  }

  .tg-blog-crops {
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  .tg-blog-cat-chip {
    min-height: 40px;
    padding: 0 var(--space-4);
    font-size: var(--text-14);
  }

  /* Nội dung bên trái, cột phải dính khi cuộn */
  .tg-blog-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: var(--space-7);
    align-items: start;
    padding-bottom: var(--space-6);
  }

  .tg-blog-main {
    gap: var(--space-5);
  }

  .tg-blog-aside {
    position: sticky;
    top: calc(var(--space-4) + var(--admin-bar-h));
    gap: var(--space-4);
  }

  .tg-blog-status {
    padding: 0;
  }

  .tg-blog-featured {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    border: 1px solid var(--color-border-warm);
    border-radius: var(--radius-xl);
  }

  .tg-blog-featured__media {
    min-height: 300px;
    aspect-ratio: auto;
  }

  .tg-blog-badge--top {
    top: var(--space-2-5);
    left: var(--space-2-5);
  }

  .tg-blog-play {
    width: 64px;
    height: 64px;
    --icon-size: 26px;
  }

  .tg-blog-featured__body {
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-7) var(--space-8);
  }

  .tg-blog-featured__tag {
    align-self: flex-start;
    padding: var(--space-1) var(--space-2-5);
    border-radius: var(--radius-pill);
    background: var(--color-brand-soft);
    color: var(--color-brand-strong);
    font-size: var(--text-12);
    letter-spacing: 0.4px;
  }

  .tg-blog-featured__title {
    font-size: var(--text-26);
    line-height: var(--leading-snug);
  }

  .tg-blog-featured__text {
    font-size: var(--text-15);
    line-height: 1.65;
  }

  .tg-blog-author {
    font-size: var(--text-meta);
  }

  /* Danh sách: lưới 3 cột thẻ dọc */
  .tg-blog-list {
    gap: var(--space-5);
    padding: 0;
    background: none;
  }

  .tg-blog-list__title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .tg-blog-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-4);
  }

  .tg-blog-card {
    box-shadow: var(--shadow-card);
  }

  .tg-blog-card .tg-article-card__body {
    flex: 1;
    gap: var(--space-1-5);
    padding: var(--space-3-5) var(--space-4) var(--space-4);
  }

  .tg-blog-card .tg-article-card__title {
    min-height: calc(2 * 1.4em);
    font-size: var(--text-16);
  }

  .tg-blog-card__excerpt {
    display: -webkit-box;
    color: var(--color-text-secondary);
    font-size: var(--text-meta);
    line-height: 1.55;
  }

  .tg-blog-card .tg-blog-meta {
    margin-top: auto;
    padding-top: var(--space-1);
  }

  .tg-blog-cat {
    font-size: var(--text-meta);
    letter-spacing: 0.4px;
  }

  .tg-blog-badge {
    top: var(--space-2-5);
    bottom: auto;
    left: var(--space-2-5);
    padding: 3px var(--space-2);
    font-size: var(--text-12);
    --icon-size: 12px;
  }

  .tg-blog-empty {
    border: 1px solid var(--color-border-warm);
    border-radius: var(--radius-xl);
    background: var(--color-surface);
  }

  .tg-blog-pagination {
    padding-top: var(--space-1);
  }

  /* Khối Hỏi kỹ sư ở cột phải */
  .tg-blog-ask {
    gap: var(--space-2-5);
    padding: var(--space-5);
    border-radius: var(--radius-3xl);
  }

  .tg-blog-ask__title {
    font-size: var(--text-18);
    line-height: 1.35;
  }

  .tg-blog-ask__text {
    font-size: var(--text-14);
  }

  .tg-blog-ask .tg-btn {
    margin-top: var(--space-1);
  }
}
