/* =========================================================
   RESPONSIVE – nạp sau cùng trên mọi trang
   ---------------------------------------------------------
   Cỡ chữ gốc (1rem) theo khổ màn hình:
   • ≥ 1200px  (desktop/laptop) : 100vw / 96 → 1rem = 20px ở 1920px (đúng thiết kế, co theo tỉ lệ)
   • Dưới 1200px chữ nhỏ có cỡ tối thiểu (--fs-min / --fs-min2) để luôn dễ đọc
   • 768–1199  (tablet)   : 18px cố định, menu trượt, bố cục xếp chồng
   • < 768     (mobile)   : 17px cố định, một cột
   ========================================================= */
html { font-size: calc(100vw / 96); }

/* =========================================================
   BỐ CỤC CO GIÃN CHUNG < 1200px (nền cho tablet & mobile)
   ========================================================= */
@media (max-width: 1199px) {

  :root { --sidebar-w: 14rem; }
  .sidebar__logo { margin: 1.2rem 0 0 1.5rem; width: 11rem; height: 4.18rem; }
  .sidebar__logo img { width: 11rem; height: 4.18rem; }
  .nav { margin: 1rem 0 0 1.25rem; width: 11.5rem; gap: 0.6rem; }
  .nav__link { height: 2.9rem; padding: 0 1rem; gap: 0.9rem; }
  .nav__link.is-active { gap: 0.8rem; }
  .promo { margin: 1.4rem 0 1.5rem 1.25rem; width: 11.5rem; height: 19.25rem; }
  .promo img { width: 11.5rem; height: 19.25rem; }

  .topbar { padding: 0 1.6rem 0 1.5rem; height: 5rem; }
  :root { --topbar-h: 5rem; }
  .topbar > .user-chip { margin-right: 0; }
  .content { padding: 1.4rem 1.6rem 0 1.4rem; }

  /* ----- Trang chủ ----- */
  .ehs-home { grid-template-columns: minmax(0, 1fr) clamp(18.5rem, 30%, 22.35rem); column-gap: 1.2rem; }
  .footer--home, .footer--static { max-width: none; }
  .hero__actions { left: 31%; }
  .activities { height: auto; padding: 1.1rem 1.2rem 1.2rem; }
  .activities__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.7rem; }
  .act__body { left: 0.7rem; right: 0.2rem; }
  .act__status, .act__track { right: 0.6rem; }
  .act__cta { width: auto; padding: 0 0.6rem; }
  .score__items { gap: 0.7rem; }
  .score-item__pill { position: static; margin: 0.3rem 0 0 2.85rem; }
  .score-item__body { margin-top: 0.3rem; margin-left: 2.85rem; }
  .score-item__head { align-items: center; }
  .latest__head { width: auto; right: 0.75rem; }
  .login-card .panel__body { padding: 1rem 0.9rem 1.2rem; }

  /* ----- Bản tin ----- */
  .news-page { margin: 0 auto; max-width: 70rem; padding: 0 1.6rem; }

  /* ----- Chi tiết bài viết ----- */
  .detail { grid-template-columns: minmax(0, 1fr) 19rem; column-gap: 1.6rem; padding: 3rem 1.6rem 0 2rem; }
  .is-done .detail { padding-top: 1.8rem; }
  .article__head, .article__hero, .article__nav { width: 100%; }
  .footer--detail { padding: 1.4rem 1.6rem 2rem 2rem; }

  /* ----- Game ----- */
  .game { grid-template-columns: minmax(0, 38.1rem) 17.1rem; justify-content: center; column-gap: 1.2rem; padding: 1.85rem 1.6rem 0; }
  .footer--game { padding: 2.5rem 1.6rem 2rem; }

  /* ----- Bảng xếp hạng ----- */
  .ranking-page { padding: 1.6rem 1.6rem 0 1.4rem; }
  .rk-divider { max-width: 100%; }
  .rk-card__head { flex-wrap: wrap; }
  .rk-table { margin: 1.25rem 0.5rem 0; }
  .rk-row { grid-template-columns: 3.25rem 1.75rem minmax(0, 20.65fr) minmax(0, 10.95fr) minmax(0, 6.15fr) minmax(0, 7.5fr) minmax(0, 10.05fr) minmax(0, 5fr) minmax(0, 5.85fr); padding-right: 1rem; }
  .rk-row--head { margin-left: 0; }
  .rk-row--head > span { white-space: normal; }
  .rk-me { left: auto; right: 0.5rem; }
  .legend { flex-wrap: wrap; }
  .chart__groups { left: 4.5rem; right: 3.5rem; gap: 0; justify-content: space-between; }
  .chart__group { flex: 0 1 8.8rem; min-width: 7.8rem; }
  .chart__grid::before { right: 3rem; left: 4.2rem; }
  .chart__grid em { right: 0.6rem; }
  .ftable__row { grid-template-columns: 3.5fr 6fr 8fr 7fr 6fr 7fr 7fr minmax(9.4rem, 9fr); padding: 0 0.8rem; }
  .c-badge { width: 100%; max-width: 9.4rem; }
  .footer--ranking { padding: 1.1rem 1.6rem 2rem 1.4rem; }

  /* ----- Hồ sơ ----- */
  .profile { padding: 1.6rem 1.6rem 0 1.4rem; max-width: none; }
  .cover__meta { white-space: normal; right: 1.2rem; }
  .kpis { gap: 0.9rem; }
  .info-grid { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; }
  .rank-history { padding-left: 0; padding-right: 0; max-width: none; }
  .footer--profile { padding: 1.3rem 1.6rem 2rem 1.4rem; max-width: none; }
}

/* =========================================================
   TABLET 768–1199px  (menu trượt + bố cục xếp chồng)
   ========================================================= */
@media (max-width: 1199px) {
  html { font-size: 18px; }
  :root { --fs-min: 11.5px; --fs-min2: 13px; }
  :root { --sidebar-w: 15rem; --topbar-h: 4rem; }

  /* Sidebar -> menu trượt */
  .sidebar { width: 15rem; transform: translateX(-100%); transition: transform .3s ease; box-shadow: 0 0 2rem rgba(0, 0, 0, .15); z-index: 60; }
  .menu-open .sidebar { transform: none; }
  .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 43, .45); opacity: 0; visibility: hidden; transition: opacity .3s, visibility .3s; }
  .menu-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  .menu-open { overflow: hidden; }
  .sidebar__logo { margin: 1rem 0 0 1.2rem; width: 10rem; height: 3.8rem; }
  .sidebar__logo img { width: 10rem; height: 3.8rem; }
  .nav { margin: 1rem 0 0 1rem; width: 13rem; gap: 0.4rem; }
  .nav__link { height: 2.8rem; font-size: 0.95rem; }
  .promo { margin: 1.2rem 0 1.5rem 1rem; width: 13rem; height: 21.75rem; }
  .promo img { width: 13rem; height: 21.75rem; }

  .main { margin-left: 0; }
  .menu-btn { display: grid; }
  .topbar, .topbar--inner { height: var(--topbar-h); padding: 0 1rem 0 0.8rem; box-shadow: 0 1px 0 #eef2f7; }
  /* Sidebar (có logo) ẩn mặc định ở mobile/tablet (chỉ hiện khi mở menu trượt) -> topbar cần
     logo riêng để không mất thương hiệu khỏi màn hình. */
  .topbar__logo { display: block; flex: none; height: 1.9rem; width: auto; margin-right: 0.7rem; }
  .topbar__title { font-size: 1.15rem; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .user-chip__avatar { width: 2.4rem; height: 2.4rem; font-size: 1.05rem; }
  .user-chip__info { width: auto; max-width: 10rem; font-size: 0.75rem; line-height: 1.1rem; }
  .user-chip__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .login-chip { font-size: 0.8rem; gap: 0.5rem; }
  .content { padding: 1rem; }

  .footer, .footer--home, .footer--static, .footer--news, .footer--detail, .footer--game, .footer--ranking, .footer--profile {
    flex-wrap: wrap; white-space: normal; line-height: 1.2; padding: 1.2rem 1rem 1.6rem; margin: 0; max-width: none; font-size: 0.65rem;
  }

  /* ----- Trang chủ ----- */
  .ehs-home { grid-template-columns: 1fr; row-gap: 1rem; }
  .ehs-home__right { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
  .ehs-home__right .login-card { grid-column: 1 / -1; width: 100%; height: auto; }
  .login-form { min-height: 0; gap: 1rem; }
  .ranking, .latest { margin-top: 0; }
  .ranking { height: auto; padding-bottom: 3.6rem; }
  .latest { height: 22rem; }
  .activities { margin-top: 1rem; height: auto; }
  .activities__grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .act { height: 15rem; }
  .act__img { height: 6rem; }
  .act__body { top: 6.5rem; height: 8.2rem; }
  .act__desc { height: auto !important; }
  .score { margin-left: 0; margin-top: 1rem; }
  .score__items { grid-template-columns: 1fr; }
  .score-item { min-height: 0; }

  /* ----- Bản tin ----- */
  .news-page { padding: 0 1rem; max-width: none; }
  .news-head { margin-top: 1rem; flex-wrap: wrap; }
  .article-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: auto; gap: 1rem; }

  /* ----- Chi tiết ----- */
  .read-status { margin-top: 0; padding: 0 1rem; height: auto; min-height: 2.4rem; }
  .detail, .is-done .detail { grid-template-columns: 1fr; row-gap: 1.6rem; padding: 1.4rem 1rem 0; }
  .is-done .aside { margin-top: 0; }
  .aside { position: static; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; align-items: start; }
  .timer-card__track { width: auto; right: 0.85rem; max-width: none; }
  .related .news-list { max-height: 22rem; }
  .article__title { font-size: 1.4rem; line-height: 1.9rem; }
  .article__body, .article__quote { font-size: 0.85rem; line-height: 1.45rem; }

  /* ----- Game ----- */
  .game { grid-template-columns: 1fr; row-gap: 1rem; padding: 1rem; }
  .game-aside { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
  .quiz__question { font-size: 1.2rem; line-height: 1.65rem; }
  .answer { font-size: 0.85rem; }
  .game-main::before, .page-bg::before { background-size: cover; height: 30rem; }
  .quiz__media, .quiz__media--wide { width: 100%; max-width: 30rem; height: auto; aspect-ratio: 392 / 238; }
  .quiz__media img { width: 100%; height: 100%; object-fit: cover; }

  /* ----- Bảng xếp hạng ----- */
  .ranking-page { padding: 1rem; }
  .rk-hero { flex-direction: column; gap: 1rem; }
  .rk-hero__title { font-size: 1.35rem; line-height: 1.8rem; }
  .tiebreak { width: 100%; height: auto; }
  .rk-divider { margin-top: 1.2rem; }
  .rk-card__head { flex-direction: column; gap: 0.8rem; }
  .personal .rk-card__head { padding: 0 1rem; }
  .plant-filter { flex-wrap: wrap; }
  .personal, .factory { overflow: hidden; }
  .rk-table, .chart, .ftable { overflow-x: auto; }
  .rk-table { margin: 1rem 0.5rem 0; }
  .rk-row--head, .rk-body { min-width: 50rem; }
  .rk-body { max-height: 30rem; }
  .rk-row--head > span { white-space: normal; }
  .factory { padding: 1rem; }
  .chart { height: 23rem; }
  .chart__grid, .chart__groups { min-width: 46rem; }
  .ftable__row { min-width: 46rem; }

  /* ----- Hồ sơ ----- */
  .profile { padding: 1rem; }
  .cover { height: auto; min-height: 10.6rem; padding-bottom: 1rem; background-position: 30% center; }
  .cover__meta { right: auto; max-width: 13rem; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.8rem; }
  .kpi__art { opacity: .35; }
  .ptabs { gap: 0.4rem; }
  .ptab { min-width: 0; flex: 1; }
  .info-grid { grid-template-columns: 1fr; }
  .snapshots { grid-template-columns: 1fr 1fr; }
  .period { height: auto; }
  .current__items, .prev__items { grid-template-columns: 1fr 1fr 1fr; }
}

/* =========================================================
   MOBILE < 768px
   ========================================================= */
@media (max-width: 767px) {
  html { font-size: 17px; }
  :root { --fs-min: 12px; --fs-min2: 13px; }
  .modal__dialog { max-width: calc(100vw - 1.6rem); }
  .topbar__title { font-size: 1.05rem; }
  .user-chip__info { display: none; }
  .login-chip__label { font-size: 0.75rem; }
  .login-chip .user-chip__avatar { display: none; }
  .content, .news-page, .ranking-page, .profile { padding-left: 0.8rem; padding-right: 0.8rem; }

  .footer, .footer--home, .footer--static, .footer--news, .footer--detail, .footer--game, .footer--ranking, .footer--profile { flex-direction: column; align-items: flex-start; gap: 0.6rem; padding: 1.2rem 0.8rem 1.6rem; }

  .btn { height: 2.6rem; font-size: 0.85rem; }

  /* Trang chủ */
  .hero { aspect-ratio: 1024 / 417; }
  .hero__actions { position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; padding: 0.7rem; background: #fff; }
  .hero__actions .btn { width: 100%; }
  .hero { aspect-ratio: auto; }
  .hero > img { aspect-ratio: 1024 / 417; height: auto; }
  .ehs-home__right { grid-template-columns: 1fr; }
  .activities { padding: 1rem; }
  .activities__title { height: auto; margin-bottom: 0.8rem; font-size: 1rem; line-height: 1.4rem; }
  .activities__grid { grid-template-columns: 1fr; }
  .act { height: auto; padding-bottom: 0.8rem; }
  .act__img { height: 7rem; }
  .act__body { position: static; height: auto; padding: 0.7rem 0.8rem 0; display: flex; flex-direction: column; gap: 0.6rem; }
  .act__status, .act__track, .act__foot { position: static; }
  .act__name { font-size: 0.9rem; }
  .act__desc, .act__status { font-size: 0.7rem; }
  .score__bar span { font-size: 0.65rem; }
  .score-item__name { font-size: 0.8rem; }
  .score-item__body { font-size: 0.7rem; }
  .rank-row__name { font-size: 0.75rem; }
  .news-item__title { font-size: 0.8rem; }
  .news-item__meta { font-size: 0.65rem; }

  /* Bản tin */
  .news-head h2 { font-size: 0.9rem; }
  .news-head p { font-size: 0.65rem; }
  .article-grid { grid-template-columns: 1fr; }
  .article-card__title { font-size: 0.9rem; line-height: 1.25rem; }
  .article-card__excerpt, .article-card__meta, .article-card__cta, .article-card__read { font-size: 0.7rem; line-height: 1.1rem; }

  /* Chi tiết */
  .read-status__badge { display: none; }
  .read-status__msg { font-size: 0.75rem; }
  .aside { grid-template-columns: 1fr; }
  .article__title { font-size: 1.2rem; line-height: 1.6rem; }
  .article__hero { aspect-ratio: 4 / 3; }
  .article__nav { flex-direction: column; align-items: stretch; border-radius: 0.8rem; padding: 0.6rem; gap: 0.2rem; }
  .article__nav a { justify-content: center; }

  /* Game */
  .game-aside { grid-template-columns: 1fr; }
  .quiz { padding: 1rem 0.8rem; }
  .quiz__media, .quiz__media--wide { width: 100%; height: auto; aspect-ratio: 392 / 238; }
  .answers--grid { grid-template-columns: 1fr; }
  .answers--grid .answer { min-height: 3.2rem; }
  .quiz__question { font-size: 1.05rem; line-height: 1.5rem; }
  .quiz__hint, .quiz__percent { font-size: 0.7rem; }
  .quiz__topic, .quiz__counter { font-size: 0.65rem; }
  .explain__text { font-size: 0.7rem; }
  .quiz__actions { flex-direction: column; align-items: stretch; }
  .quiz__confirm { width: 100%; }
  .session__desc { width: auto; right: 0.85rem; }
  .result__actions { flex-direction: column; align-items: stretch; }
  .result__btn, .result__btn--primary { width: 100%; }
  .result__stats { grid-template-columns: 1fr 1fr; }

  /* Bảng xếp hạng */
  .page-bg::before, .game-main::before { opacity: .35; }
  .rk-hero__title { font-size: 1.15rem; line-height: 1.55rem; }
  .rk-hero__summary, .tiebreak { font-size: 0.7rem; }
  .plant-filter button { font-size: 0.65rem; }
  .legend span { font-size: 0.6rem; }
  .formula ul { font-size: 0.7rem; }

  /* Hồ sơ – mobile bỏ ảnh nền (hay lỗi/vỡ layout khi ảnh crop quá hẹp), dùng thẳng màu nền navy. */
  .cover { padding: 1rem 1rem 1.2rem; display: flex; flex-direction: column; gap: 0.6rem; background: #002d80; }
  .cover__eyebrow, .cover__avatar, .cover__name, .cover__meta { position: static; }
  .cover__meta { max-width: none; }
  .cover__avatar { width: 3.6rem; height: 3.6rem; font-size: 1.3rem; }
  .cover__name { font-size: 1.25rem; line-height: 1.6rem; }
  .cover__meta { font-size: 0.75rem; }
  .kpis { grid-template-columns: 1fr; }
  .kpi__art { opacity: 1; }
  .ptabs { height: auto; padding: 0.3rem; gap: 0.3rem; }
  .ptab { height: 2.4rem; font-size: 0.7rem; padding: 0 0.4rem; }
  .details__list { grid-template-columns: 7rem 1fr; }
  .details__list dt { font-size: 0.7rem; }
  .details__list dd { font-size: 0.75rem; }
  .weekly__rank { font-size: 0.9rem; }
  .snapshots, .current__items, .prev__items { grid-template-columns: 1fr; }
  .snap { height: auto; }
  .snap__detail { white-space: normal; padding-right: 3.2rem; }
  .period__max { position: static; text-align: left; margin-top: 0.6rem; }
  .period__title { font-size: 1.05rem; line-height: 1.4rem; }
  .current { padding: 1rem; }
  .current__head, .prev__head { flex-direction: column; align-items: flex-start; }
}
