/*
 * Nexme - lớp vá responsive cho giao diện công khai.
 * Chỉ tác động tablet nhỏ/mobile, không thay đổi giao diện desktop.
 */

@media (max-width: 767px) {
  html,
  body {
    max-width: 100%;
  }

  body {
    overflow-x: hidden;
  }

  img,
  video,
  iframe,
  canvas {
    max-width: 100%;
  }

  /* Menu mobile luôn nằm gọn trong chiều cao trình duyệt thực tế. */
  .site-nav__panel {
    max-height: calc(100dvh - var(--header-height));
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .site-nav__mobile-actions,
  .site-nav__mobile-actions .button {
    min-width: 0;
  }

  /* Các thanh tab/bộ lọc ngang vuốt ổn định, không làm rộng trang. */
  .project-detail-page .project-tabs__rail,
  .document-category-buttons,
  .subdivision-filters,
  .progress-timeline,
  .project-grid,
  .developer-tabs,
  .news-category-tabs {
    max-width: 100%;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .project-detail-page .project-tabs__rail::-webkit-scrollbar,
  .document-category-buttons::-webkit-scrollbar,
  .subdivision-filters::-webkit-scrollbar,
  .progress-timeline::-webkit-scrollbar,
  .project-grid::-webkit-scrollbar,
  .developer-tabs::-webkit-scrollbar,
  .news-category-tabs::-webkit-scrollbar {
    display: none;
  }

  .project-detail-page .project-tabs a,
  .project-detail-page .project-tabs button {
    flex: 0 0 auto;
    padding-inline: 16px;
  }

  /* Dialog không vượt khỏi màn hình nhỏ. */
  .project-media-modal,
  .inventory-dialog,
  .document-preview-dialog,
  .policy-dialog,
  .qna-dialog,
  .academy-dialog {
    width: min(94vw, 720px);
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    margin: auto;
  }

  /* Map bảng hàng: giải phóng vùng bản đồ khỏi legend dọc che gần nửa màn hình. */
  .project-inventory-page .inventory-map {
    min-height: 420px;
    overscroll-behavior: contain;
  }

  .project-inventory-page .inventory-map__legend {
    top: 8px;
    right: 54px;
    left: 8px;
    width: auto;
    max-height: none;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 10px;
    white-space: nowrap;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .project-inventory-page .inventory-map__legend::-webkit-scrollbar {
    display: none;
  }

  .project-inventory-page .inventory-map__legend h3 {
    display: none;
  }

  .project-inventory-page .inventory-map__legend button,
  .project-inventory-page .inventory-map__legend span {
    width: auto;
    min-height: 32px;
    flex: 0 0 auto;
    gap: 7px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 11px;
  }

  .project-inventory-page .inventory-map__legend button.is-active {
    color: var(--pi-blue);
    background: #eaf3ff;
  }

  .project-inventory-page .inventory-map__controls {
    top: 8px;
    right: 8px;
    bottom: auto;
    gap: 6px;
  }

  .project-inventory-page .inventory-map__controls button {
    width: 36px;
    height: 36px;
  }

  .project-inventory-page .inventory-map__hint {
    display: none;
  }

  .project-inventory-page .inventory-map-popup,
  .project-inventory-page .leaflet-popup-content {
    max-width: 220px;
  }

  .project-inventory-page .inventory-map:fullscreen {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
  }

  .project-inventory-page .inventory-table td {
    grid-template-columns: minmax(92px, 105px) minmax(0, 1fr);
  }

  .project-inventory-page .inventory-table td > *,
  .project-inventory-page .inventory-table td::before {
    min-width: 0;
  }

  .site-back-to-top {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  /* Gallery phân khu được chặn trong viewport, tránh kéo ngang toàn trang. */
  .project-subdivision-page .subdivision-gallery {
    max-width: 100%;
    overflow: hidden;
  }

  .project-subdivision-page .subdivision-gallery__viewport,
  .project-subdivision-page .subdivision-gallery__track {
    max-width: 100%;
  }
}

@media (max-width: 479px) {
  .project-detail-page .project-tabs a,
  .project-detail-page .project-tabs button {
    padding-inline: 14px;
  }

  .project-inventory-page .inventory-map {
    min-height: 390px;
  }

  .project-inventory-page .inventory-map__legend {
    right: 50px;
    padding: 5px;
  }

  .project-inventory-page .inventory-map__legend button,
  .project-inventory-page .inventory-map__legend span {
    min-height: 30px;
    padding-inline: 9px;
  }

  .project-inventory-page .inventory-map__controls button {
    width: 34px;
    height: 34px;
  }

  .project-inventory-page .inventory-table td {
    grid-template-columns: 88px minmax(0, 1fr);
    column-gap: 10px;
  }
}

/* Tablet dọc 768-820px: sửa gallery phân khu gây tăng scrollWidth của toàn trang. */
@media (min-width: 768px) and (max-width: 820px) {
  .project-subdivision-page .subdivision-gallery {
    max-width: 100%;
    overflow: hidden;
  }

  .project-subdivision-page .subdivision-gallery__viewport,
  .project-subdivision-page .subdivision-gallery__track {
    max-width: 100%;
  }

  .project-subdivision-page .subdivision-gallery__track button {
    min-width: 0;
    flex-basis: calc((100% - 26px) / 3);
  }
}

/* Tablet: cho phép các khối grid phân khu co đúng theo container. */
@media (min-width: 768px) and (max-width: 1023px) {
  .project-subdivision-page .subdivision-map-layout,
  .project-subdivision-page .subdivision-map-layout > *,
  .project-subdivision-page .subdivision-map-summary,
  .project-subdivision-page .subdivision-map {
    min-width: 0;
    max-width: 100%;
  }

  .project-subdivision-page .subdivision-map button,
  .project-subdivision-page .subdivision-map img {
    max-width: 100%;
  }
}
