/* Tối ưu cho điện thoại và máy tính bảng.
   Mọi quy tắc nằm trong media query nên giao diện máy tính không đổi. */

/* ===== Điện thoại và máy tính bảng ===== */
@media (max-width: 1024px) {
  /* Cột lưới được phép co lại; trước đây bảng rộng kéo cả trang bài viết ra ngoài màn hình. */
  .article-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .article-layout > * { min-width: 0; max-width: 100%; }
  .article-body { overflow-wrap: break-word; }
  .article-body img, .article-body video, .article-body iframe { max-width: 100%; }
  .article-body img { height: auto; }

  /* Bảng rộng: cuộn ngang trong khung riêng thay vì bị cắt. */
  .article-markdown-content .table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  .article-markdown-content .table-wrap table { min-width: 560px; }
}

@media (max-width: 768px) {
  /* Tiêu đề banner được xuống dòng. */
  .hero-title-line { white-space: normal !important; overflow: visible !important; text-overflow: clip !important; }
  .hero-content-col { min-width: 0; max-width: 100%; }

  /* Trang bài viết */
  .article-meta-header { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 12px; }
  .article-date { display: block; font-size: 13px; line-height: 1.6; color: #64748b; white-space: normal !important; }
  .article-main-title { font-size: clamp(22px, 6.4vw, 30px) !important; line-height: 1.3 !important; }
  .article-lead { font-size: 16px !important; }
  .article-markdown-content h2 { font-size: 20px !important; line-height: 1.35; margin-top: 28px !important; }
  .article-markdown-content h3 { font-size: 17.5px !important; line-height: 1.4; }
  .article-markdown-content ul, .article-markdown-content ol { padding-left: 20px; }
  .article-sidebar { padding-left: 0 !important; padding-right: 0 !important; border-left: 0 !important; }
  .article-actions .btn { width: 100%; height: auto; justify-content: center; text-align: center; white-space: normal; }

  /* Công cụ tính: hai khung co theo màn hình nhỏ (360px). */
  .quote-studio-main-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .quote-studio-main-grid > * { min-width: 0; max-width: 100%; box-sizing: border-box; }
  .quote-studio-form, .quote-live-dashboard { padding-left: 16px !important; padding-right: 16px !important; }

  /* Ô nhập từ 16px để iPhone không tự phóng to khi chạm. */
  input:not([type='checkbox']):not([type='radio']):not([type='range']),
  select,
  textarea { font-size: 16px !important; }

  /* Vùng chạm dễ bấm hơn */
  .text-link { display: inline-flex; align-items: center; min-height: 40px; }
  .btn-preset-chip, .catalog-tag-btn, .filter-button { min-height: 40px; }
  .ctrl-arrow { min-width: 40px; min-height: 40px; }
  .site-footer .f-links-col a, .site-footer .f-policy-col a { display: flex; align-items: center; min-height: 36px; }

  /* Chữ nhỏ khó đọc */
  .breadcrumb { font-size: 12px !important; line-height: 1.8; }
}

/* Bảng đặt trực tiếp trong bài (không có khung bọc) */
@media (max-width: 1024px) {
  .article-markdown-content > table,
  .article-markdown-content :not(.table-wrap) > table { display: block; width: 100% !important; min-width: 0 !important; max-width: 100%; overflow-x: auto; }
}

/* ===== Điện thoại hẹp ===== */
@media (max-width: 480px) {
  /* Lưới khai báo cột tối thiểu 330px ngay trong HTML trang Hồ sơ năng lực. */
  .legal-executive-wrapper > div { grid-template-columns: minmax(0, 1fr) !important; }
  .corporate-spec-card { padding: 20px !important; }
  .quote-form-grid-2 { grid-template-columns: minmax(0, 1fr) !important; }
}

/* Màn rất hẹp: ô thông tin pháp nhân xếp một cột. */
@media (max-width: 360px) {
  .corporate-spec-card [style*='grid-template-columns'] { grid-template-columns: minmax(0, 1fr) !important; }
  .corporate-spec-card [style*='span 2'] { grid-column: auto !important; }
}

@media (max-width: 768px) {
  /* Đưa nút chuyển ảnh lên góc trên để không đè nhãn tên dự án. */
  .home-featured-media .featured-slider-controls { top: 10px; bottom: auto; right: 10px; }
}

/* Gợi ý cho bảng cuộn ngang (bảng có khung rộng tối thiểu 560px). */
@media (max-width: 560px) {
  .article-markdown-content .table-wrap::before {
    content: '↔ Vuốt ngang để xem đủ bảng';
    display: block;
    position: sticky;
    left: 0;
    padding: 6px 10px;
    font-size: 12px;
    color: #64748b;
  }
}
