/* Layout and Base Styles */
html, body {
    /* height: 100%; */
    margin: 0;
    padding: 0;
    overflow: hidden;
}

#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;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.sticky-top {
    position: sticky;
    top: 0;
    z-index: 10;
}

.footer {
    flex-shrink: 0;
    /* position: sticky; */
    bottom: 0;
    background-color: #FFF5F5;
}

/* Menu Items */
.menu-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
    will-change: transform;
}

.menu-scroll {
    max-height: 100%;
    overflow-y: auto;
}

.menu-item-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 12px;
}

.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;
}

/* List layout (old style) */
.menu-items.list-layout {
    display: block;
}

.menu-items.list-layout .menu-item {
    display: flex;
    margin-bottom: 16px;
}

.menu-items.list-layout .menu-item img {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
    margin-right: 12px;
    flex-shrink: 0;
}

.menu-items.list-layout .menu-item .item-content {
    flex: 1;
    min-width: 0;
}

.menu-items.list-layout .item-header {
    text-align: left;
    margin-bottom: 8px;
}

.menu-items.list-layout .item-header h4 {
    font-size: 16px;
    margin-bottom: 4px;
}

.menu-items.list-layout .item-header p {
    font-size: 14px;
    line-height: 1.4;
}

.menu-items.list-layout .option-group {
    margin-bottom: 12px;
}

.menu-items.list-layout .option-btn {
    font-size: 12px;
    padding: 4px 10px;
    margin-right: 6px;
    margin-bottom: 6px;
}

/* Search overlay styling */
#search-overlay {
    z-index: 1000;
}

/* 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 !important;
    /* Fill the menu-container (which is flex: 1 in #app-container) */
    height: 100%;
    min-height: 0;               /* allow shrink inside flex parent */
    align-items: stretch;
    overflow: hidden;            /* stop the parent .menu-container from also scrolling */
}

/* When sidebar layout is active, prevent the outer .menu-container from
   scrolling — its children (sb-cat-list + sb-grid) own their own scroll.
   Without this, scroll events bubble up and both panes scroll together.
   Class is added by layout-management.js (no :has() — Chrome Android < 105
   doesn't support it). */
#menu-area.is-sidebar-mode {
    overflow: hidden !important;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

/* 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;
}
.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;
    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(auto-fill, minmax(110px, 1fr));
    grid-auto-rows: 150px;          /* uniform card height (image 78px + name area 72px) */
    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;
}
.menu-items.sidebar-layout .sb-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: #9ca3af;
    font-size: 14px;
}

/* Item card (small, iOS Order style) */
.menu-items.sidebar-layout .sb-card {
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    transition: transform 0.1s;
    user-select: none;
    position: relative;
    height: 100%;                /* fill the fixed grid row */
    text-decoration: none;       /* defensive — no underline anywhere */
    touch-action: manipulation;  /* drop the 300ms double-tap-zoom delay */
    -webkit-tap-highlight-color: rgba(0,0,0,0);
}
.menu-items.sidebar-layout .sb-card:active {
    transform: scale(0.97);
}
.menu-items.sidebar-layout .sb-img-wrap {
    position: relative;
    flex: 0 0 78px;              /* fixed image area, no aspect-ratio collapse */
    height: 78px;
    background: #f3f4f6;
    overflow: hidden;
    border-radius: 8px;
    margin: 4px 4px 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;
}
.menu-items.sidebar-layout .sb-price-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: rgba(233, 30, 99, 0.9);
    border-radius: 4px;
    line-height: 1.2;
}
.menu-items.sidebar-layout .sb-qty-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    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;
    bottom: 4px;
    left: 4px;
    padding: 1px 5px;
    font-size: 9px;
    font-weight: 800;
    color: #fff;
    background: var(--primary-color);
    border-radius: 3px;
    letter-spacing: 0.3px;
}
.menu-items.sidebar-layout .sb-name {
    flex: 1;                     /* fill remaining card height */
    padding: 6px 6px 8px;
    font-size: 12px;
    line-height: 1.3;
    color: #1f2937;
    text-align: center;
    display: flex;               /* center vertically inside the slot */
    align-items: center;
    justify-content: center;
    overflow: hidden;
    text-decoration: none;
    /* line-clamp inside a flex centering wrapper */
}
.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(auto-fill, minmax(95px, 1fr));
        grid-auto-rows: 138px;       /* image 70 + name 68 (mobile) */
        gap: 6px;
        padding: 6px;
    }
    .menu-items.sidebar-layout .sb-img-wrap {
        flex-basis: 70px;
        height: 70px;
    }
    .menu-items.sidebar-layout .sb-name {
        font-size: 11px;
    }
}


