/**
 * RESPONSIVE STYLESHEET — VỊ NHÀ MÌNH (T26)
 * Chuẩn hóa 6 breakpoints:
 *   - 360px  : Điện thoại nhỏ (Galaxy S, Android màn hẹp)
 *   - 390px  : Điện thoại tiêu chuẩn (iPhone 12/13/14/15/16 Pro)
 *   - 768px  : Máy tính bảng dọc (iPad Mini, iPad Portrait)
 *   - 1024px : Máy tính bảng ngang / Laptop nhỏ (iPad Landscape)
 *   - 1280px : Desktop chuẩn (MacBook, PC tiêu chuẩn)
 *   - 1536px : Desktop màn hình lớn (Full HD+, 2K, Ultra-wide)
 *
 * Nguyên tắc vàng:
 * 1. Mobile-first & Fluid layout — tuyệt đối KHÔNG có thanh cuộn ngang (scrollWidth <= innerWidth).
 * 2. Modal trên mobile chuyển thành Bottom Sheet trượt từ đáy lên.
 * 3. Vùng chạm cảm ứng (Tap Target) tối thiểu 44x44px theo WCAG 2.5.5 / 2.5.8.
 * 4. Font size ô nhập liệu input/select/textarea ≥ 16px chống iOS Safari tự phóng to (auto-zoom).
 * 5. Bảng dữ liệu quản trị / Bếp tự động cuộn ngang trong container riêng.
 */

/* ==================== 0. CHỐNG CUỘN NGANG & TỐI ƯU CẢM ỨNG ==================== */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

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

/* Đảm bảo hình ảnh và iframe không vượt quá chiều rộng màn hình */
img, svg, picture, video, iframe {
  max-width: 100%;
  height: auto;
}

/* Vùng chạm cảm ứng (Tap Target) tối thiểu 44x44px (WCAG 2.5.5 / 2.5.8) */
button,
.btn,
.btn-icon,
.mobile-nav-item,
.chip,
.tab-btn,
input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  min-height: 44px;
}

.btn-icon,
button.btn-icon,
.mobile-nav-item {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Nút đóng X trong modal có vùng chạm tối thiểu 44x44px */
.modal-header .btn-icon,
#btn-close-modal,
#btn-close-auth,
#btn-close-checkout,
#btn-close-tracking,
#btn-close-reservation {
  min-width: 44px !important;
  min-height: 44px !important;
  font-size: 1.4rem;
}

/* Tăng kích thước vùng chạm của checkbox & radio */
input[type="checkbox"],
input[type="radio"] {
  min-width: 22px;
  min-height: 22px;
  cursor: pointer;
}

/* Khung cuộn ngang nội bộ cho bảng dữ liệu */
.table-responsive,
.table-container,
.table-wrapper {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ==================== 1. DESKTOP MÀN HÌNH LỚN (>= 1536px) ==================== */
@media (min-width: 1536px) {
  :root {
    --container-max-width: 1440px;
  }

  .container {
    padding-left: var(--space-8);
    padding-right: var(--space-8);
  }

  .dish-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: var(--space-6) !important;
  }

  .hero__heading {
    font-size: 2.75rem !important;
  }
}

/* ==================== 2. DESKTOP TIÊU CHUẨN (1280px - 1535px) ==================== */
@media (min-width: 1280px) and (max-width: 1535px) {
  :root {
    --container-max-width: 1200px;
  }

  .dish-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: var(--space-6) !important;
  }
}

/* ==================== 3. TABLET LANDSCAPE / LAPTOP NHỎ (1024px) ==================== */
@media (max-width: 1024px) {
  /* Header điều hướng iPad: cho phép flex-wrap, tránh tràn */
  .desktop-nav {
    flex-wrap: wrap;
    gap: var(--space-2) !important;
    min-width: 0;
  }

  .desktop-nav .btn {
    padding: 6px 12px !important;
    font-size: 0.85rem !important;
  }

  /* Lưới thực đơn 2 cột trên iPad */
  .dish-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-4) !important;
  }

  /* Màn hình Bếp (Kanban), Sơ đồ bàn không làm tràn trang */
  .kanban-grid {
    overflow-x: auto;
    padding-bottom: var(--space-2);
  }

  .table-map-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)) !important;
  }

  .modal-box {
    max-width: 90vw !important;
    margin: var(--space-3);
  }
}

/* ==================== 4. TABLET PORTRAIT & MOBILE (<= 768px) ==================== */
@media (max-width: 768px) {
  /* Chừa khoảng trống chân trang để không bị thanh bottom bar che khuất */
  body {
    padding-bottom: calc(64px + 16px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Ẩn navigation desktop, hiển thị mobile bottom bar */
  .desktop-nav {
    display: none !important;
  }

  .mobile-bottom-bar {
    display: block !important;
  }

  /* Mobile header: luôn hiển thị nút hamburger mở sidebar */
  #btn-toggle-sidebar {
    display: inline-flex !important;
  }

  /* Font size input ≥ 16px: Ngăn iOS Safari tự động zoom trang */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* ChatWidget không đè mobile bottom bar */
  #btn-toggle-chat {
    bottom: calc(64px + 16px + env(safe-area-inset-bottom, 0px)) !important;
    left: 16px !important;
  }

  #chat-box {
    bottom: calc(64px + 16px + env(safe-area-inset-bottom, 0px)) !important;
    left: 16px !important;
    width: min(360px, calc(100vw - 32px)) !important;
    height: min(480px, calc(100dvh - 160px)) !important;
  }

  /* Toast notification */
  .toast-container {
    bottom: calc(64px + 12px + env(safe-area-inset-bottom, 0px)) !important;
    left: 12px !important;
    right: 12px !important;
  }

  .toast {
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Lưới admin xếp thành 1 cột */
  .grid-admin-split-2-1,
  .grid-admin-split-1-2,
  .grid-3col {
    grid-template-columns: 1fr !important;
  }
}

/* ==================== 5. MOBILE BOTTOM SHEET (<= 640px) ==================== */
@media (max-width: 640px) {
  /* Chuyển toàn bộ Modal thành Bottom Sheet trượt từ đáy màn hình */
  .modal-backdrop {
    align-items: flex-end !important;
    padding: 0 !important;
  }

  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 85vh !important;
    max-height: 85dvh !important;
    border-radius: 24px 24px 0 0 !important;
    margin: 0 !important;
    border-bottom: none !important;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25) !important;
    transform: translateY(100%) !important;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  /* Pull Handle indicator ở đỉnh Bottom Sheet */
  .modal-box::before {
    content: '';
    display: block;
    width: 44px;
    height: 5px;
    background-color: var(--color-border);
    border-radius: 999px;
    margin: 10px auto 4px;
    flex-shrink: 0;
  }

  .modal-backdrop.active .modal-box {
    transform: translateY(0) !important;
  }

  .modal-header {
    padding: 12px 18px !important;
    border-bottom: 1px solid var(--color-border);
  }

  .modal-body {
    padding: 16px 18px !important;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    padding: 12px 18px max(16px, env(safe-area-inset-bottom, 16px)) !important;
    flex-wrap: wrap !important;
    gap: var(--space-2) !important;
  }

  .modal-footer .btn {
    flex: 1 1 auto;
    min-width: 120px;
  }

  /* Lưới 2 cột thành 1 cột */
  .grid-2col {
    grid-template-columns: 1fr !important;
  }

  .hero__grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-6) !important;
  }

  /* Thực đơn 1 cột */
  .dish-grid {
    grid-template-columns: 1fr !important;
    gap: var(--space-4) !important;
  }

  /* Cart Drawer chiếm full chiều rộng màn hình mobile */
  .cart-drawer {
    max-width: 100% !important;
  }

  /* Admin modal tabs tự co giãn đều trên mobile (T1.3) */
  .admin-tabs-nav {
    padding: 10px 12px !important;
    gap: 8px !important;
  }

  .admin-tab-btn {
    flex: 1 1 calc(50% - 8px) !important;
    min-height: 44px !important;
    font-size: 0.8rem !important;
    padding: 6px 8px !important;
    text-align: center;
  }

  /* Thanh lọc danh mục cuộn ngang mượt mà, không tràn trang */
  .category-bar,
  .category-scroll,
  .categories-filter {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    padding-bottom: 6px;
    gap: 8px;
    scrollbar-width: none;
  }

  .category-bar::-webkit-scrollbar,
  .category-scroll::-webkit-scrollbar,
  .categories-filter::-webkit-scrollbar {
    display: none;
  }
}

/* ==================== 6. ĐIỆN THOẠI MÀN HÌNH NHỎ (360px & 390px) ==================== */
@media (max-width: 390px) {
  .container {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Header trên iPhone 390px & Galaxy 360px */
  .brand__logo {
    width: 32px !important;
    height: 32px !important;
  }

  .brand__name {
    font-size: 1.05rem !important;
  }

  .brand__tagline {
    display: none !important;
  }

  .header-actions {
    gap: 6px !important;
  }

  #btn-open-auth {
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
  }

  /* Mobile bottom bar font chữ nhỏ gọn */
  .mobile-nav-item span {
    font-size: 0.65rem !important;
  }

  /* Thẻ món ăn và card */
  .card {
    padding: 12px !important;
  }

  .dish-card__title {
    font-size: 0.95rem !important;
  }

  /* Nút bấm full width trong card nếu cần */
  .btn-lg {
    padding: 0.65rem 0.9rem !important;
    font-size: 0.92rem !important;
  }
}
