/* ==========================================================================
   THINHBDS.VN — Responsive (kiểm tra tại 320, 375, 390, 768, 1024, 1440px)
   Desktop-first: >=1024 = layout đầy đủ; 768–1023 = tablet; <768 = mobile
   ========================================================================== */

/* --- Tablet & nhỏ hơn: menu dạng drawer --- */
@media (max-width: 1023px) {
  .menu-toggle { display: inline-flex; }
  .primary-nav {
    position: fixed; left: 0; right: 0; top: var(--nav-top, var(--header-h)); bottom: 0; z-index: 99;
    background: var(--c-white); border-top: 1px solid var(--c-border);
    padding: 16px var(--gutter) 32px; overflow-y: auto; overscroll-behavior: contain;
    transform: translateY(-8px); opacity: 0; visibility: hidden;
    transition: opacity var(--t-base), transform var(--t-base), visibility var(--t-base);
  }
  .primary-nav.is-open { opacity: 1; transform: none; visibility: visible; }
  .primary-nav ul { flex-direction: column; align-items: stretch; gap: 2px; }
  .primary-nav a { min-height: 52px; padding: 0 14px; font-size: var(--fs-base); width: 100%; }
  .primary-nav a[aria-current="page"], .primary-nav a.is-active { box-shadow: none; background: var(--c-soft); border-radius: var(--r-sm); }
  .primary-nav .nav-cta { margin-top: 12px; }
  .primary-nav .nav-cta a { margin-left: 0; justify-content: center; }
  .has-sub { flex-wrap: wrap; }
  .has-sub > a { flex: 1; width: auto; }
  .sub-toggle { width: 52px; height: 52px; }
  .subnav { position: static; opacity: 1; visibility: visible; transform: none; display: none; width: 100%; min-width: 0; border: 0; box-shadow: none; padding: 0 0 4px 14px !important; border-left: 2px solid var(--c-border); border-radius: 0; margin-left: 14px; }
  .subnav a { min-height: 46px; }
  .has-sub:hover > .subnav { opacity: 1; visibility: visible; }
  .has-sub.is-open > .subnav { display: flex; }
  .has-sub:hover:not(.is-open) > .subnav { display: none; }
}

/* --- Tablet 768–1023 --- */
@media (max-width: 1023px) {
  .c-8, .c-7, .c-5 { grid-column: span 12; }
  .c-3 { grid-column: span 6; }
  .c-6 { grid-column: span 6; }
  .article-layout { grid-template-columns: 1fr; gap: 24px; }
  .toc { position: static; }
  .need-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .connect__inner { grid-template-columns: 1fr; }
  .card--feature .card__media { flex-basis: 46%; }
  .hero .c-7, .hero .c-5 { grid-column: span 12; }
  .hero__figure { max-width: 320px; margin-top: 8px; }
}

/* --- Mobile < 768 --- */
@media (max-width: 767px) {
  .c-12, .c-8, .c-7, .c-6, .c-5, .c-4, .c-3 { grid-column: span 12; }
  .card--feature { flex-direction: column; }
  .card--feature .card__media { flex-basis: auto; min-height: 0; aspect-ratio: 16 / 9; }
  .need-grid { grid-template-columns: 1fr 1fr; }
  .section-head { align-items: flex-start; }
  .btn-row .btn { flex: 1 1 100%; }
  .hero__cta .btn { flex: 1 1 100%; }
  .search { flex-basis: 100%; max-width: none; }
  .toolbar__row > .field-inline { width: 100%; }
  .toolbar__row > .field-inline select { flex: 1; }
  .form-actions .btn { width: 100%; }
  .doc-row .btn { width: 100%; }
  .footer-grid > div { grid-column: span 12 !important; }
  .cta-flat .btn { width: 100%; }
  .lead { font-size: var(--fs-base); }
  .prose { font-size: var(--fs-base); }
  .pagination ul { gap: 6px; }
  .pagination button { min-width: 42px; }
  .chapters li { grid-template-columns: 56px 1fr; }
}

/* --- Rất hẹp (320–359) --- */
@media (max-width: 359px) {
  :root { --gutter: 14px; }
  .need-grid { grid-template-columns: 1fr; }
  .brand-logo { height: 36px; margin-left: -4px; }
  .btn { padding: 0 16px; }
  .pagination button { min-width: 38px; padding: 0 8px; }
}

/* --- Màn hình lớn --- */
@media (min-width: 1440px) {
  :root { --gap: 28px; }
}

/* --- Tôn trọng prefers-reduced-motion --- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .card:hover, .tile--link:hover, .btn:hover { transform: none; }
  .skeleton__media, .skeleton__line { animation: none; }
}

/* --- In ấn --- */
@media print {
  .site-header, .demo-bar, .toast, .menu-toggle { display: none !important; }
}

/* ===== V1.4 ===== */
@media (max-width: 1023px) { .need-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 767px) {
  .need-grid--3 { grid-template-columns: 1fr; }
  .hero__more { font-size: var(--fs-sm); }
  .tag-row { gap: 6px; }
}
@media (max-width: 767px) { .search input::placeholder { font-size: 0.875rem; } }
@media (min-width: 360px) and (max-width: 767px) { .brand-logo { height: 40px; } .site-footer .brand-logo { height: 52px; } }

/* ===== V1.5 ===== */
@media (max-width: 1023px) {
  .card--vmain { flex-direction: column; }
  .card--vmain .card__media { flex: none; width: 100%; align-self: auto; }
}
@media (max-width: 767px) {
  /* Trang chủ mobile gọn hơn */
  .page-home .section { padding-block: clamp(36px, 10vw, 44px); }
  .page-home .section-head { margin-bottom: 20px; }
  .page-home .section-head > .link-arrow { display: none; }
  .page-home .section-head .lead { font-size: var(--fs-sm); }
  .page-home .tag-row { display: none; }
  .page-home .tile { padding: 18px; gap: 6px; }
  .page-home .tile__more { display: none; }
  .page-home .only-desktop { display: none; }
  .section-foot { display: block; }
  .section-foot .btn { width: 100%; }
  .cap-m2 > :nth-child(n + 3) { display: none; }
  .vh__side { grid-template-columns: 1fr; }
  .vh__side > :nth-child(n + 2) { display: none; }
  .card--vside { flex-direction: row; }
  .card--vside .card__media { flex: 0 0 40%; aspect-ratio: 16 / 9; align-self: flex-start; }
  .card--vmain .card__play span { width: 52px; height: 52px; }
  .card--vside .card__excerpt { display: none; }
  .card--vside .card__body { padding: 12px 14px; }
  .card--training .card__body { padding: 16px 18px 18px; }
  .card--training .card__excerpt { font-size: var(--fs-sm); }
  .proof-list li { grid-template-columns: 22px minmax(0, 1fr); }
  .proof-list li a { grid-column: 2; justify-self: start; min-height: 44px; }
  .gallery { grid-template-columns: 1fr 1fr; }
  .gallery figure:nth-child(3) { display: none; }
  .facts div { grid-template-columns: 1fr; }
  .chip { min-height: 44px; }
  .jump-links { gap: 0 16px; }
}
@media (max-width: 359px) {
  .card--vside .card__media { flex-basis: 38%; }
}
@media (max-width: 767px) {
  .page-home .hero { padding-block: 36px 44px; }
  .page-home .hero__figure { max-width: 240px; margin-top: 4px; }
  .proof-photo .media { aspect-ratio: 16 / 10; }
  .proof-photo .media img { object-position: 50% 28% !important; }
  .proof-list { margin-top: 16px; gap: 8px; }
  .proof-list li { grid-template-columns: 22px minmax(0, 1fr) auto; padding: 10px 12px; gap: 4px 10px; }
  .proof-list li > div > span { display: none; }
  .proof-list li a { grid-column: auto; justify-self: end; }
  .proof-list strong { font-size: var(--fs-sm); }
}
