/* Layout and Base Styles */
html {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}
body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    /* touch-action: pan-y pan-x cho phép children scroll, prevent rubber-band */
    touch-action: pan-y pan-x;
    -webkit-overflow-scrolling: touch;
}

#app-container {
    border-radius: 0 !important;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;              /* mobile: dynamic viewport — handles browser chrome */
}

.header {
    flex-shrink: 0;
    /* position: sticky; */
    top: 0;
}

.menu-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scroll-behavior: smooth;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

/* Sidebar mode: menu-container không tự scroll, children (.sb-cat-list, .sb-grid) own scroll.
   ID selector specificity (110/210) đã đủ override các class rule. */
#menu-area.is-sidebar-mode {
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: none;
    display: flex;
    flex-direction: column;
}
#menu-area.is-sidebar-mode > #menu-items {
    flex: 1 1 0;
    min-height: 0;
    height: auto;
    overflow: hidden;
}

.sticky-top {
    position: sticky;
    top: 0;
    z-index: 10;
}

.footer {
    flex-shrink: 0;
    /* position: sticky; */
    bottom: 0;
    background-color: #FFF5F5;
}

.menu-scroll {
    max-height: 100%;
    overflow-y: auto;
}

.cart-item-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 6px;
    margin-right: 10px;
}

/* Cart Badge */
.cart-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 18px;
    height: 18px;
    background-color: #4B556B;
    color: white;
    border-radius: 50%;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Quantity Controls */
.quantity-control {
    display: flex;
    align-items: center;
    gap: 3px;
}

.quantity-btn {
    width: 18px;
    height: 18px;
    font-size: 10px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: all 0.15s ease;
}

.quantity-display {
    min-width: 18px;
    text-align: center;
    font-size: 12px;
}

/* Focus Styles */
button:focus-visible,
.btn:focus-visible {
    outline: none !important;
    box-shadow: 0 0 0 3px var(--primary-color-dark) !important;
}

/* Category Buttons */
.category-btn {
    flex: 0 0 auto;
    background-color: #FFEBEE;
    color: var(--primary-color);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
}

.category-btn.active {
    background-color: var(--primary-color);
    color: white;
}

/* Scrollbar Hide */
.scrollbar-hide {
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;  /* Chrome, Safari and Opera */
}

/* Smooth scroll for categories */
#sidebar-categories {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

#sidebar-categories::-webkit-scrollbar {
    width: 6px;
}

#sidebar-categories::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar-categories::-webkit-scrollbar-thumb {
    background-color: #d1d5db;
    border-radius: 3px;
}

/* Option Buttons */
.option-btn {
    border: 1px solid var(--primary-color);
    border-radius: 16px;
    padding: 2px 8px;
    font-size: 10px;
    margin-right: 2px;
    margin-bottom: 2px;
    cursor: pointer;
    white-space: nowrap;
}

.option-btn.selected {
    background-color: var(--primary-color);
    color: white;
}

.option-group {
    margin-bottom: 10px;
}

.option-title {
    font-weight: 500;
    margin-bottom: 5px;
}

.readonly-tier {
    background-color: #f3f4f6;
    border-radius: 0.375rem;
    padding: 0.5rem;
    color: #4b5563;
}

/* Line clamp utility for grid layout */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Grid layout improvements */
.menu-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

/* Search overlay styling — z-index thấp hơn TẤT CẢ modal (modal nhỏ nhất là
   z-50 cho cart/item-detail). Trước đây z=1000 → đè lên cart/item-detail/note/
   customer modal (z-50..999) → bug "search hiển thị lên trên modal". */
#search-overlay {
    z-index: 30;
}

/* Ensure search overlay has same styling and behavior as header */
#search-overlay.header {
    display: none; /* Hidden by default */
    flex-shrink: 0; /* Same as header */
}

#search-overlay.header:not(.hidden) {
    display: flex; /* Show when not hidden */
}

/* Mobile Support */
@supports (-webkit-touch-callout: none) {
    #app-container {
        height: -webkit-fill-available;
    }
}

/* Responsive */
@media (max-width: 480px) {
    .menu-items {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    #categories-bottom-sheet {
        max-height: 100vh;
    }

    #categories-bottom-sheet .bg-white {
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    #categories-bottom-sheet .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* Typography */
p {
    line-height: 1.3;
}


/* ============================================================
   SIDEBAR LAYOUT (default)
   Ported from iOS Order — 140px left category list + adaptive
   right grid. Hides scrollbars but keeps scrolling.
   ============================================================ */
.menu-items.sidebar-layout {
    display: flex;
    flex-direction: row;
    gap: 0;
    padding: 0;
    /* Height + flex sizing đã được set ở rule "#menu-area.is-sidebar-mode > #menu-items" */
    align-items: stretch;
    overflow: hidden;            /* stop the parent .menu-container from also scrolling */
}

/* (Legacy duplicate rule — đã được xử lý ở section đầu file via #menu-area.is-sidebar-mode) */

/* LEFT: category sidebar */
.menu-items.sidebar-layout .sb-categories {
    width: 132px;                /* widened from 110 — fits 1-line "TRÀ CHANH - LATTE" better */
    min-width: 132px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;               /* allow nested flex scroll on mobile */
}
.menu-items.sidebar-layout .sb-cat-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;    /* don't bubble scroll to .menu-container */
    touch-action: pan-y;             /* allow vertical swipe even on mobile */
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none;        /* IE/Edge */
    scrollbar-width: none;            /* Firefox */
}
.menu-items.sidebar-layout .sb-cat-list::-webkit-scrollbar {
    display: none;                    /* Chrome/Safari */
}
.menu-items.sidebar-layout .sb-cat-btn {
    display: block;
    width: 100%;
    text-align: left;
    padding: 11px 10px;
    font-size: 13px;
    font-weight: 400;
    color: #1f2937;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    cursor: pointer;
    line-height: 1.3;
    transition: background 0.12s, border-color 0.12s;
}
.menu-items.sidebar-layout .sb-cat-btn:hover {
    background: #f9fafb;
}
.menu-items.sidebar-layout .sb-cat-btn.is-active {
    background: rgba(233, 30, 99, 0.08);
    border-left-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 700;
}
.menu-items.sidebar-layout .sb-cat-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 0 8px;
}

/* RIGHT: items grid */
.menu-items.sidebar-layout .sb-content {
    flex: 1;
    min-height: 0;               /* allow nested flex scroll */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fafafa;
}
.menu-items.sidebar-layout .sb-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    font-size: 13px;
    color: #6b7280;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
}
.menu-items.sidebar-layout .sb-header .sb-title {
    font-weight: 600;
}
.menu-items.sidebar-layout .sb-grid {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);     /* 2 cột chuẩn industry (Shopee/Grab) */
    grid-auto-rows: 200px;                      /* image 130 + name 38 + price 22 + padding 10 */
    gap: 8px;
    align-content: start;
    -ms-overflow-style: none;
    scrollbar-width: none;
    /* Belt + suspenders so iOS Safari hides the scrollbar too */
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.menu-items.sidebar-layout .sb-grid::-webkit-scrollbar {
    display: none;
}

/* Sticky cart bar offset — khi cart bar floating-bottom hiển thị, scroll containers
   cần padding-bottom = chiều cao cart bar (~56px) + khoảng cách bottom (12px) +
   safe-area (iOS notch/home-bar) + buffer. Class `has-sticky-cart` toggle bởi
   updateCartBadge() trên <body>. Áp dụng cho cả grid (món) lẫn cat-list. */
body.has-sticky-cart .menu-items.sidebar-layout .sb-grid,
body.has-sticky-cart .menu-items.sidebar-layout .sb-cat-list {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 88px);
}
.menu-items.sidebar-layout .sb-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: #9ca3af;
    font-size: 14px;
}

/* Hidden card (filter applied) — KHÔNG remove DOM để giữ <img> trong cache. */
.menu-items.sidebar-layout .sb-card.sb-card-hidden {
    display: none !important;
}

/* Banner Collection đã bỏ — chỉ còn popup first-visit + chip filter footer. */

/* ═══════════════════════════════════════════════════════════════
   SKELETON LOADING STATE — hiển thị trong khi menu chưa load
   Perceived performance: user thấy có gì đó đang load → cảm giác nhanh hơn
   ═══════════════════════════════════════════════════════════════ */
.menu-skeleton {
    display: flex;
    height: 100%;
    gap: 0;
    /* #menu-items là CSS grid (auto-fit minmax 160px) → nếu không span hết,
       skeleton co vào 1 ô ~160px khiến card biến thành sọc mảnh. */
    grid-column: 1 / -1;
}
.menu-skeleton .skel-sidebar {
    width: 116px;
    flex-shrink: 0;
    padding: 8px 8px 8px 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #fafafa;
}
.menu-skeleton .skel-cat-btn {
    height: 36px;
    border-radius: 4px;
}
.menu-skeleton .skel-grid {
    flex: 1;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: 200px;
    gap: 8px;
}
.menu-skeleton .skel-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.menu-skeleton .skel-img {
    width: 100%;
    height: 130px;
}
.menu-skeleton .skel-name {
    margin: 8px 8px 4px;
    height: 14px;
    width: 80%;
    border-radius: 3px;
}
.menu-skeleton .skel-price {
    margin: 0 8px 8px;
    height: 14px;
    width: 50%;
    border-radius: 3px;
}
.skel-pulse {
    background: linear-gradient(90deg, #eaeaea 25%, #f5f5f5 50%, #eaeaea 75%);
    background-size: 200% 100%;
    animation: skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes skel-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
@media (max-width: 480px) {
    .menu-skeleton .skel-grid {
        grid-auto-rows: 195px;
        gap: 7px;
        padding: 7px;
    }
    .menu-skeleton .skel-img {
        height: 125px;
    }
}

/* Item card (small, iOS Order style) */
.menu-items.sidebar-layout .sb-card {
    background: #fff;
    border: 1px solid #e5e7eb;       /* viền rõ ràng tách giữa các món (giống ShopeeFood) */
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    transition: transform 0.1s, box-shadow 0.15s;
    user-select: none;
    position: relative;
    height: 100%;
    text-decoration: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
.menu-items.sidebar-layout .sb-card:active {
    transform: scale(0.97);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
/* Image FULL-WIDTH dính lên đầu card (rounded chỉ trên) — pattern Grab/Shopee */
.menu-items.sidebar-layout .sb-img-wrap {
    position: relative;
    flex: 0 0 130px;
    height: 130px;
    width: 100%;
    background: #f3f4f6;
    overflow: hidden;
    border-radius: 0;            /* card đã có border-radius bao ngoài */
    margin: 0;
}
.menu-items.sidebar-layout .sb-img-wrap img {
    position: absolute;          /* sit on top of the placeholder */
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border: 0;                   /* no broken-img red border */
    text-decoration: none;
    z-index: 1;
}
/* Placeholder sits behind the img; if img loads it covers, if it 404s the
   onerror handler removes the img and the placeholder shows through. */
.menu-items.sidebar-layout .sb-img-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    font-size: 22px;
    background: #f3f4f6;
}
/* Giá in đậm màu primary, căn trái — pattern Grab/Shopee */
.menu-items.sidebar-layout .sb-price {
    text-align: left;
    font-size: 15px;
    font-weight: 700;
    color: var(--primary-color);
    padding: 2px 8px 8px;
    line-height: 1.2;
}

/* Featured badges — góc dưới phải card (tránh đè qty top-right). 1 món có thể có
   nhiều nhãn → xếp CHỒNG dọc trong .sb-feat-stack. */
.menu-items.sidebar-layout .sb-feat-stack {
    position: absolute;
    bottom: 4px;
    right: 4px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}
.menu-items.sidebar-layout .sb-feat-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    border-radius: 4px;
    line-height: 1.2;
    letter-spacing: 0.3px;
    /* Viền trắng + đổ bóng → badge nổi bật, tách khỏi ảnh nền bất kỳ màu gì. */
    box-shadow: 0 1px 3px rgba(0,0,0,0.35), 0 0 0 1.5px rgba(255,255,255,0.9);
}
.menu-items.sidebar-layout .sb-feat-badge i { font-size: 9px; }
.sb-feat-new       { background: #16a34a; }       /* xanh lá */
.sb-feat-recommend { background: #0d9488; }       /* teal — "NÊN THỬ" */
.sb-feat-special   { background: #f97316; }       /* cam */
.sb-feat-hot       { background: var(--primary-color); }

/* Min quantity badge — góc dưới TRÁI (tránh đè feat-badge bên phải).
 * Cam đậm + viền sáng → khách nhận ra ngay "phải đặt ≥ N" trước khi tap card. */
.menu-items.sidebar-layout .sb-min-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    z-index: 2;
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    background: #ea580c;                        /* orange-600 */
    border-radius: 3px;
    line-height: 1.2;
    letter-spacing: 0.2px;
    box-shadow: 0 0 0 1px rgba(255,255,255,0.6);
}
.menu-items.sidebar-layout .sb-qty-badge {
    position: absolute;
    top: 4px;
    right: 4px;                  /* dời sang phải để combo badge chiếm trái — đỡ chen tên ở dưới */
    z-index: 2;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #16a34a;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.menu-items.sidebar-layout .sb-combo-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    z-index: 2;
    padding: 2px 6px;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    background: #8b5cf6;         /* tím (violet-600) — đặc trưng combo, không rối với màu đỏ chính */
    border-radius: 3px;
    letter-spacing: 0.3px;
}
/* Name + price căn TRÁI dưới image — name dính sát price, không stretch fill */
.menu-items.sidebar-layout .sb-name {
    padding: 6px 8px 2px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.3;
    color: #1f2937;
    text-align: left;
    overflow: hidden;
    text-decoration: none;
    min-height: 36px;            /* dự phòng cho name 2 dòng (= 2 × line-height × 14px) */
}
.menu-items.sidebar-layout .sb-name > span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-decoration: none;
    width: 100%;
}

/* Mobile: keep same shape (user requested), narrower sidebar */
@media (max-width: 640px) {
    .menu-items.sidebar-layout {
        height: 100%;            /* fill menu-container — same as desktop */
    }
    .menu-items.sidebar-layout .sb-categories {
        width: 116px;            /* widened from 96 — better fits "TRÀ CHANH - LATTE" */
        min-width: 116px;
    }
    .menu-items.sidebar-layout .sb-cat-btn {
        font-size: 12px;
        padding: 10px 8px;
    }
    .menu-items.sidebar-layout .sb-grid {
        grid-template-columns: repeat(2, 1fr);     /* 2 cột chuẩn industry */
        grid-auto-rows: 195px;                      /* image 125 + name 38 + price 22 + padding 10 */
        gap: 7px;
        padding: 7px;
    }
    .menu-items.sidebar-layout .sb-img-wrap {
        flex-basis: 125px;
        height: 125px;
    }
    .menu-items.sidebar-layout .sb-name {
        font-size: 13px;
        line-height: 1.3;
    }
    .menu-items.sidebar-layout .sb-price {
        font-size: 14px;
        padding: 2px 7px 7px;
    }
}


