/* =========================================================
   VIETTRUCKS.COM - MOBILE COMPATIBILITY
   iOS Safari + Android Chrome/Samsung Internet
   ========================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
}

/* Không cho ảnh/video làm vỡ giao diện */
img,
picture,
video,
canvas,
svg {
  max-width: 100%;
  height: auto;
}

/* Form tương thích iPhone */
input,
select,
textarea,
button {
  max-width: 100%;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}

input,
select,
textarea {
  font-size: 16px !important;
}

/*
  iPhone Safari sẽ tự zoom nếu input nhỏ hơn 16px.
  Vì vậy giữ tối thiểu 16px.
*/
input,
select,
textarea {
  min-height: 44px;
}

button,
a,
input[type="button"],
input[type="submit"] {
  touch-action: manipulation;
}

button,
.btn,
.button,
a.btn {
  min-height: 44px;
}

/* Không cho nội dung dài tràn màn hình */
p,
span,
div,
td,
th,
label,
a {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Container chung */
.container,
.wrapper,
.page-container,
.content,
.main-content {
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* Table mobile */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  max-width: 100%;
}

/* Modal */
.modal,
.popup,
.dialog {
  max-width: 100vw;
}

.modal-content,
.popup-content,
.dialog-content {
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Header */
header {
  max-width: 100%;
}

nav {
  max-width: 100%;
}

/* =========================================================
   TABLET + MOBILE
   ========================================================= */

@media (max-width: 992px) {

  .container,
  .wrapper,
  .page-container,
  .content,
  .main-content {
    padding-left: 14px;
    padding-right: 14px;
  }

  /* Các grid nhiều cột chuyển mềm về ít cột */
  .grid,
  .cards-grid,
  .stats-grid,
  .features-grid,
  .services-grid,
  .orders-grid,
  .vehicles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Tránh fixed width */
  [style*="width: 1200px"],
  [style*="width:1200px"],
  [style*="width: 1000px"],
  [style*="width:1000px"],
  [style*="width: 900px"],
  [style*="width:900px"] {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* =========================================================
   PHONE
   ========================================================= */

@media (max-width: 768px) {

  body {
    font-size: 15px;
  }

  .container,
  .wrapper,
  .page-container,
  .content,
  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  h1 {
    font-size: clamp(26px, 8vw, 38px);
    line-height: 1.15;
  }

  h2 {
    font-size: clamp(22px, 6vw, 30px);
    line-height: 1.2;
  }

  h3 {
    font-size: clamp(18px, 5vw, 24px);
  }

  /* Tất cả grid về 1 cột trên điện thoại */
  .grid,
  .cards-grid,
  .stats-grid,
  .features-grid,
  .services-grid,
  .orders-grid,
  .vehicles-grid,
  .form-grid,
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }

  /* Flex ngang chuyển dọc */
  .mobile-stack {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  /* Form */
  form {
    width: 100%;
  }

  input,
  select,
  textarea {
    width: 100%;
    border-radius: 8px;
  }

  textarea {
    min-height: 100px;
  }

  form button,
  form .btn,
  .form-actions button {
    width: 100%;
  }

  .form-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  /* Card */
  .card,
  .order-card,
  .vehicle-card,
  .quote-card,
  .trip-card,
  .stat-card {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Không dùng chiều rộng cố định */
  .sidebar,
  aside {
    max-width: 100%;
  }

  /* Action buttons */
  .actions,
  .button-group,
  .btn-group {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }

  .actions > *,
  .button-group > *,
  .btn-group > * {
    width: 100%;
  }

  /* Table */
  table {
    font-size: 14px;
  }

  th,
  td {
    white-space: nowrap;
  }

  /* Hero */
  .hero,
  .hero-section {
    min-height: auto !important;
    padding-top: 48px !important;
    padding-bottom: 48px !important;
  }

  .hero-content {
    width: 100%;
    max-width: 100%;
  }

  .hero-buttons {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
  }

  .hero-buttons a,
  .hero-buttons button {
    width: 100%;
  }

  /* Footer */
  footer .footer-grid,
  .footer-grid {
    grid-template-columns: 1fr !important;
    gap: 24px !important;
  }
}

/* =========================================================
   SMALL PHONE
   ========================================================= */

@media (max-width: 480px) {

  body {
    font-size: 14px;
  }

  .container,
  .wrapper,
  .page-container,
  .content,
  .main-content {
    padding-left: 10px;
    padding-right: 10px;
  }

  button,
  .btn {
    font-size: 15px;
  }

  .card,
  .order-card,
  .vehicle-card,
  .quote-card,
  .trip-card,
  .stat-card {
    padding: 14px !important;
  }
}

/* =========================================================
   iPHONE SAFE AREA
   iPhone X trở lên
   ========================================================= */

@supports (padding: max(0px)) {

  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  footer {
    padding-bottom:
      max(16px, env(safe-area-inset-bottom));
  }

  .mobile-bottom-nav,
  .fixed-bottom {
    padding-bottom:
      max(8px, env(safe-area-inset-bottom));
  }
}

/* =========================================================
   FIX iOS 100vh
   ========================================================= */

.full-height,
.min-screen-height {
  min-height: 100vh;
  min-height: 100dvh;
}

/* =========================================================
   REDUCE ANIMATION cho thiết bị yếu
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
/* =========================================================
   FIX MOBILE CLICK / OVERLAY - VIETTRUCKS
   ========================================================= */

@media (max-width: 768px) {

  /* Header luôn nổi đúng lớp */
  .site-header {
    position: relative;
    z-index: 10000;
  }

  /* Menu chỉ nhận click khi thực sự mở */
  .menu,
  #menu {
    z-index: 10001;
  }

  /* Không để hero overlay chặn nút */
  .hero-overlay {
    pointer-events: none !important;
  }

  /* Nội dung hero phải bấm được */
  .hero-inner,
  .hero-copy,
  .search-card,
  .search-tabs,
  .search-grid {
    position: relative;
    z-index: 5;
  }

  /* Tất cả nút/link chính phải nhận thao tác */
  a,
  button,
  .btn,
  .tab {
    pointer-events: auto !important;
    touch-action: manipulation;
    position: relative;
  }

  /* Menu đóng thì không được phủ trang */
  .menu:not(.active):not(.open):not(.show) {
    pointer-events: none;
  }

  /* Nhưng các link menu khi menu mở phải bấm được */
  .menu.active,
  .menu.open,
  .menu.show {
    pointer-events: auto !important;
  }
}

/* =========================================================
   VIETTRUCK MOBILE CLICK FIX - IOS + ANDROID
   ========================================================= */

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

/* Mọi link, button và control phải nhận được thao tác chạm */
a,
button,
input,
select,
textarea,
label,
[role="button"] {
  pointer-events: auto !important;
  touch-action: manipulation !important;
  -webkit-tap-highlight-color: rgba(0,0,0,0.08);
}

/* Không cho pseudo element vô hình chặn nút */
*::before,
*::after {
  pointer-events: none;
}

/* Các vùng chính phải nằm trên background */
header,
nav,
main,
.hero,
.hero-content,
.search-box,
.search-form,
.search-tabs,
.container {
  position: relative;
}

/* Nút trong khu vực hero/search */
.search-box button,
.search-box a,
.search-tabs button,
.search-tabs a,
.hero button,
.hero a {
  position: relative;
  z-index: 20 !important;
  pointer-events: auto !important;
}

/* Menu mobile */
.mobile-menu,
.mobile-nav,
.nav-menu,
header nav {
  z-index: 9999;
}

/* Nút menu */
.menu-toggle,
.mobile-menu-toggle,
#menuToggle {
  position: relative;
  z-index: 10001 !important;
  pointer-events: auto !important;
}

/* Thanh hotline nổi không được phủ cả chiều ngang trang */
.floating-contact,
.contact-float,
.floating-buttons,
.contact-buttons {
  width: auto !important;
  max-width: calc(100vw - 24px);
  right: 12px !important;
  left: auto !important;
  pointer-events: none !important;
  z-index: 1000;
}

/* Nhưng chính từng nút hotline/zalo/facebook vẫn bấm được */
.floating-contact a,
.contact-float a,
.floating-buttons a,
.contact-buttons a {
  pointer-events: auto !important;
}

/* Tránh overlay vô hình của hero */
.hero::before,
.hero::after,
.hero-overlay,
.overlay {
  pointer-events: none !important;
}

/* iOS Safari */
@supports (-webkit-touch-callout: none) {
  a,
  button,
  input,
  select,
  textarea {
    cursor: pointer;
    touch-action: manipulation;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .hero,
  .hero-content,
  .search-box,
  .search-form {
    overflow: visible;
  }

  .search-tabs {
    position: relative;
    z-index: 30 !important;
  }

  .search-tabs button,
  .search-tabs a {
    min-height: 48px;
  }

  button,
  .btn,
  a.btn {
    min-height: 44px;
  }
}

/* =========================================================
   VIETTRUCK 4 MOBILE ACTION BUTTONS
   ========================================================= */

.mobile-action-tabs {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
  position: relative;
  z-index: 50 !important;
}

.mobile-action-tabs .tab {
  display: flex !important;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 8px;
  text-decoration: none !important;
  text-align: center;
  pointer-events: auto !important;
  touch-action: manipulation !important;
  position: relative;
  z-index: 51 !important;
}

@media (max-width: 768px) {
  .mobile-action-tabs {
    grid-template-columns: 1fr 1fr !important;
  }

  .mobile-action-tabs .tab {
    font-size: 16px;
    line-height: 1.2;
  }
}

/* FIX NÚT MENU MOBILE */
#menuBtn,
.menu-btn {
  position: relative !important;
  z-index: 10002 !important;
  pointer-events: auto !important;
  touch-action: manipulation !important;
  cursor: pointer;
}

#menu,
.menu {
  z-index: 10001 !important;
}

/* menu đóng */
#menu:not(.active),
.menu:not(.active) {
  pointer-events: none;
}

/* menu mở */
#menu.active,
.menu.active {
  pointer-events: auto !important;
}

/* =========================================================
   HIỆN ĐĂNG NHẬP / ĐĂNG KÝ TRÊN MOBILE
   ========================================================= */

@media (max-width: 768px) {

  .header-actions {
    display: flex !important;
    gap: 8px !important;
    align-items: center;
    margin-left: auto;
    margin-right: 8px;
    position: relative;
    z-index: 10002 !important;
  }

  .header-actions .btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 12px !important;
    font-size: 14px !important;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }

  .header-actions .btn-outline {
    background: #fff;
  }

  .header-actions .btn-primary {
    color: #fff;
  }
}

/* ==================================================
   FIX FORM MOBILE IOS + ANDROID
   ================================================== */

@media (max-width: 768px) {

  html,
  body {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  .container,
  main,
  section {
    max-width: 100% !important;
    min-width: 0 !important;
  }

  /* Các khung tìm kiếm / bộ lọc */
  .search-grid,
  .search-box,
  .form-grid,
  .filter-grid,
  .filters,
  .main,
  .layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    gap: 14px !important;
  }

  /* Mỗi trường chiếm trọn chiều ngang */
  .field,
  .form-group,
  .search-field {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .field label,
  .form-group label,
  .search-field label {
    display: block !important;
    width: 100% !important;
    margin-bottom: 6px !important;
  }

  /* Input/select không bị co */
  input,
  select,
  textarea {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;

    box-sizing: border-box !important;

    font-size: 16px !important;
    line-height: 1.4 !important;

    padding: 12px 14px !important;

    pointer-events: auto !important;
    touch-action: manipulation !important;

    position: relative !important;
    z-index: 2 !important;
  }

  input[type="date"] {
    width: 100% !important;
    min-width: 0 !important;
  }

  select {
    min-height: 48px !important;
  }

  /* Sidebar Bộ lọc không nằm cạnh danh sách */
  aside,
  .sidebar,
  .filter-sidebar {
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ===== FIX FORM TIM HANG MOBILE IOS + ANDROID ===== */
@media (max-width: 768px) {

  .search-box .search-grid,
  main .search-grid,
  .container-page .search-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    gap: 14px !important;
  }

  .search-grid .field {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .search-grid .field input,
  .search-grid .field select,
  .search-grid .field textarea {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;

    height: 48px !important;
    min-height: 48px !important;

    font-size: 16px !important;
    line-height: 1.3 !important;

    padding: 10px 12px !important;
    margin: 0 !important;

    -webkit-appearance: none;
    appearance: none;
  }

  .search-grid .field label {
    display: block !important;
    width: 100% !important;
    margin-bottom: 6px !important;
  }

  #pickupSearch,
  #deliverySearch,
  #cargoSearch {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    font-size: 16px !important;
    pointer-events: auto !important;
    touch-action: manipulation !important;
  }
}
