/* General Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Body Styling */
body {
    font-family: Arial, sans-serif;
    background-color: #F9EEDE;
    margin: 0;
    line-height: 1.6;
    color: #374F21;
}

/* Header Styling */
header {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 120px;
    background-color: #F9EEDE;
    border-bottom: 2px solid #374F21;
    position: relative;
}

.logo img {
    width: 100px;
    height: auto;
}

/* Navigation Styling */
nav {
    background-color: #374F21;
    padding: 10px 0;
}

.nav-links {
    list-style: none;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.nav-links li {
    display: inline;
}

.nav-links a {
    text-decoration: none;
    color: #fff;
    font-size: 1rem;
    font-weight: bold;
    transition: color 0.3s ease;
}

.nav-links a:hover {
    color: #AECF75;
}

/* Main Content Styling */
main {
    text-align: center;
    padding: 50px 20px;
}

main h1 {
    font-size: 2.5rem;
    margin-bottom: 20px;
    color: #374F21;
}

main p {
    font-size: 1.2rem;
    color: #374F21;
    margin-bottom: 40px;
}

/* Filter Buttons Styling */
.filter-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.filter-btn {
    background-color: #374F21;
    color: #F9EEDE;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.filter-btn:hover {
    background-color: #AECF75;
    color: #374F21;
}

.filter-btn.active {
    background-color: #AECF75;
    color: #374F21;
}

/* Menu Grid Styling */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    justify-content: center;
    max-width: 1200px;
    margin: 0 auto;
}

@media (max-width: 1024px) {
    .menu-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .menu-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .menu-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    /* Header adjustments */
    header {
        height: 80px;
        padding: 10px;
        position: relative;
    }
    
    .logo img {
        width: 70px;
    }
    
    /* Navigation adjustments */
    nav {
        padding: 8px 0;
    }
    
    .nav-links {
        gap: 15px;
        flex-wrap: wrap;
    }
    
    .nav-links a {
        font-size: 0.9rem;
        padding: 8px 12px;
        display: inline-block;
    }
    
    /* Main content adjustments */
    main {
        padding: 30px 15px;
    }
    
    main h1 {
        font-size: 1.8rem;
        margin-bottom: 15px;
    }
    
    main p {
        font-size: 1rem;
        margin-bottom: 30px;
    }
    
    /* Filter buttons - better for touch */
    .filter-buttons {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 20px;
    }
    
    .filter-btn {
        padding: 12px 16px;
        font-size: 0.9rem;
        min-height: 44px; /* Touch-friendly */
        flex: 1 1 auto;
        min-width: calc(50% - 4px);
    }
    
    /* Menu items - better spacing */
    .menu-item {
        padding: 20px;
        min-height: 100px;
    }
    
    .menu-item h3 {
        font-size: 1.1rem;
        margin-bottom: 8px;
    }
    
    .menu-item p {
        font-size: 0.9rem;
    }
    
    /* Popup - full width on mobile */
    .item-popup-content {
        width: calc(100% - 40px);
        max-width: 320px;
        padding: 25px 20px;
        margin: 20px;
    }
    
    .item-popup-content h3 {
        font-size: 1rem;
        margin-bottom: 20px;
    }
    
    .item-popup-content label {
        font-size: 0.9rem;
        margin: 12px 0;
        padding-left: 10px;
        min-height: 44px; /* Touch-friendly */
        display: flex;
        align-items: center;
    }
    
    .item-popup-content label input[type="checkbox"] {
        transform: scale(1.5);
        margin-right: 12px;
    }
    
    /* Quantity controls - mobile */
    .popup-quantity-controls {
        margin: 15px 0;
        gap: 12px;
    }
    
    .popup-quantity-controls label {
        font-size: 0.95rem;
        margin: 0;
        padding: 0;
        min-height: auto;
    }
    
    .popup-quantity-controls .quantity-btn-decrease,
    .popup-quantity-controls .quantity-btn-increase {
        width: 40px;
        height: 40px;
        font-size: 24px;
        min-height: 44px; /* Touch-friendly */
    }
    
    .popup-quantity-controls .quantity-input {
        width: 70px;
        height: 40px;
        font-size: 1.1rem;
        min-height: 44px; /* Touch-friendly */
    }
    
    .item-popup-close {
        width: 40px;
        height: 40px;
        right: 8px;
        top: 8px;
        font-size: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .item-popup-add-btn {
        padding: 14px 20px;
        font-size: 1rem;
        min-height: 48px; /* Touch-friendly */
        margin-top: 20px;
    }
    
    /* Cart icon - square at top, aligned with logo */
    .cart-icon {
        position: absolute;
        top: 50%;
        right: 15px;
        transform: translateY(-50%);
        left: auto;
        bottom: auto;
        padding: 0;
        font-size: 0.9rem;
        width: 55px;
        height: 55px;
        min-width: 55px;
        min-height: 55px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        z-index: 10001;
    }
    
    /* Cart popout - better for mobile */
    .cart-popout {
        position: fixed;
        top: auto;
        bottom: 80px;
        right: 20px;
        left: 20px;
        width: calc(100% - 40px);
        max-width: none;
        max-height: 50vh;
        overflow-y: auto;
    }
    
    /* Form adjustments */
    .order-form {
        padding: 0;
    }
    
    .order-form input[type="text"] {
        width: 100%;
        max-width: none;
        padding: 12px;
        font-size: 1rem;
        min-height: 44px; /* Touch-friendly */
    }
    
    #submitOrder {
        width: auto;
        max-width: 90%;
        padding: 14px 30px;
        font-size: 1rem;
        font-weight: bold;
        min-height: 48px; /* Touch-friendly */
        margin-top: 25px;
        margin-bottom: 35px;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }
}

@media (max-width: 480px) {
    /* Extra small screens */
    main {
        padding: 20px 10px;
    }
    
    main h1 {
        font-size: 1.5rem;
    }
    
    .filter-buttons {
        gap: 6px;
    }
    
    .filter-btn {
        min-width: calc(50% - 3px);
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    
    .menu-item {
        padding: 15px;
    }
    
    .item-popup-content {
        width: calc(100% - 20px);
        padding: 20px 15px;
        margin: 10px;
    }
    
    .cart-popout {
        bottom: 70px;
        right: 10px;
        left: 10px;
        width: calc(100% - 20px);
        padding: 12px;
        max-height: 45vh;
    }
    
    .cart-icon {
        right: 10px;
        width: 50px;
        height: 50px;
        min-width: 50px;
        min-height: 50px;
        font-size: 0.85rem;
        padding: 0;
    }
}

/* Prevent text selection on buttons for better mobile UX */
.filter-btn,
.item-popup-add-btn,
#submitOrder,
.remove-item,
.cart-icon,
.item-popup-close {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* Smooth scrolling for mobile */
html {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Better touch targets */
button, 
a, 
.menu-item,
.item-popup-content label {
    touch-action: manipulation;
}

/* Menu Item Styling */
.menu-item {
    background-color: #fff;
    border: 2px solid #F8D09A;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(55, 79, 33, 0.15);
    transition: opacity 0.5s ease, transform 0.5s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    opacity: 1;
    transform: translateY(0);
    cursor: pointer; /* Make the entire item clickable */
    display: block; /* JavaScript will control visibility */
}

.menu-item:hover {
    border-color: #AECF75;
    box-shadow: 0 6px 12px rgba(55, 79, 33, 0.25);
    transform: translateY(-2px);
}

.menu-item.hidden {
    display: none;
}

.menu-item h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #374F21;
}

.menu-item p {
    font-size: 1rem;
    color: #374F21;
    opacity: 0.8;
}

.menu-item-price {
    display: block;
    font-size: 1.1rem;
    font-weight: bold;
    color: #D32A29;
    margin-top: 8px;
}

/* Popup Styling - Completely Rebuilt */
.item-popup {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(55, 79, 33, 0.6);
    overflow: hidden;
}

.item-popup.active {
    display: block;
}

.item-popup-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    width: 280px;
    position: fixed;
    border: 2px solid #374F21;
    box-shadow: 0 4px 12px rgba(55, 79, 33, 0.3);
    text-align: center;
    z-index: 10001;
    box-sizing: border-box;
    overflow: visible;
    /* Position set by JavaScript */
}

.item-popup-content h3 {
    margin: 0 0 15px 0;
    padding-top: 5px;
    font-size: 1.1rem;
    color: #374F21;
}

.item-popup-content label {
    display: block;
    margin: 10px 0;
    text-align: left;
    padding-left: 15px;
    font-size: 0.95rem;
    cursor: pointer;
}

.item-popup-content label input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.2);
    cursor: pointer;
}

/* Quantity Controls in Popup */
.popup-quantity-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    padding: 10px 0;
}

.popup-quantity-controls label {
    font-size: 1rem;
    font-weight: bold;
    color: #374F21;
    margin: 0;
    padding: 0;
}

.popup-quantity-controls .quantity-btn-decrease,
.popup-quantity-controls .quantity-btn-increase {
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border: 2px solid #374F21;
    border-radius: 6px;
    background-color: #AECF75;
    color: #374F21;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.popup-quantity-controls .quantity-btn-decrease:hover,
.popup-quantity-controls .quantity-btn-increase:hover {
    background-color: #F8D09A;
    transform: scale(1.05);
}

.popup-quantity-controls .quantity-btn-decrease:active,
.popup-quantity-controls .quantity-btn-increase:active {
    transform: scale(0.95);
}

.popup-quantity-controls .quantity-input {
    width: 60px;
    height: 32px;
    text-align: center;
    font-size: 1rem;
    font-weight: bold;
    border: 2px solid #374F21;
    border-radius: 6px;
    background-color: #fff;
    color: #374F21;
    padding: 0;
    -moz-appearance: textfield;
}

.popup-quantity-controls .quantity-input::-webkit-outer-spin-button,
.popup-quantity-controls .quantity-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.item-popup-close {
    position: absolute;
    right: 12px;
    top: 8px;
    color: #374F21;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    border: none;
    background: none;
    padding: 0;
    width: 30px;
    height: 30px;
    transition: color 0.3s ease;
}

.item-popup-close:hover {
    color: #D32A29;
}

.item-popup-add-btn {
    background-color: #D32A29;
    color: #F9EEDE;
    border: none;
    padding: 10px 20px;
    font-size: 0.95rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-top: 15px;
    width: 100%;
    box-sizing: border-box;
    font-weight: bold;
}

.item-popup-add-btn:hover {
    background-color: #b02120;
}

.save-options {
    background-color: #D32A29;
    color: #F9EEDE;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-top: 15px;
    font-weight: bold;
}

.save-options:hover {
    background-color: #b02120;
}

/* Cart Icon Styling */
.cart-icon {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background-color: #D32A29;
    color: #F9EEDE;
    padding: 0;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    z-index: 10000;
    box-shadow: 0 2px 8px rgba(55, 79, 33, 0.3);
    width: 60px;
    height: 60px;
    min-width: 60px;
    min-height: 60px;
    border: 2px solid #374F21;
}

.cart-icon span {
    font-size: 0.75rem;
    font-weight: bold;
    line-height: 1;
}

.cart-icon:hover {
    background-color: #b02120;
    transform: translateY(-50%) scale(1.05);
}

/* Cart Pop-Out Styling */
.cart-popout {
    display: none; /* Initially hidden */
    position: fixed;
    top: 70px;
    right: 20px;
    background-color: #fff;
    border: 2px solid #374F21;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 6px rgba(55, 79, 33, 0.2);
    width: 300px;
    max-height: 60vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 10002;
    box-sizing: border-box;
}

/* Mobile responsive cart */
@media (max-width: 768px) {
    .cart-popout {
        width: calc(100vw - 40px);
        max-width: 400px;
        right: 20px;
        left: 20px;
        top: 70px;
        max-height: calc(100vh - 100px);
        padding: 12px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .cart-popout ul {
        width: 100%;
        overflow-x: hidden;
    }
    
    .cart-popout ul li {
        padding: 10px 8px;
        font-size: 0.9rem;
        width: 100%;
        box-sizing: border-box;
        overflow: visible;
    }
    
    .cart-popout ul li > div {
        flex-wrap: wrap;
        gap: 8px;
        width: 100%;
        align-items: flex-start;
    }
    
    .cart-popout ul li > div > div:first-child {
        /* itemInfo container */
        flex: 1 1 100%;
        min-width: 0;
        flex-wrap: wrap;
        gap: 6px;
        align-items: center;
    }
    
    .cart-popout ul li > div > div:first-child > span:first-child {
        /* Item name */
        flex: 1 1 auto;
        min-width: 0;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .cart-popout .item-quantity {
        flex-shrink: 0;
    }
    
    .cart-popout .quantity-btn {
        min-width: 28px;
        min-height: 28px;
        font-size: 16px;
        flex-shrink: 0;
    }
    
    .cart-popout .item-price {
        flex: 1 1 100%;
        width: 100%;
        text-align: left;
        margin-top: 8px;
        padding-top: 5px;
        border-top: 1px solid #AECF75;
        min-width: 0;
        color: #374F21;
        font-weight: bold;
    }
    
    .cart-popout .remove-item {
        flex: 0 0 auto;
        font-size: 0.85rem;
        padding: 6px 12px;
        white-space: nowrap;
        margin-top: 8px;
        width: 100%;
        justify-content: center;
    }
    
    .cart-popout h3 {
        font-size: 1.1rem;
        margin-bottom: 12px;
    }
    
    /* Ensure cart total is visible */
    .cart-popout #cartTotal {
        width: 100%;
        box-sizing: border-box;
        word-wrap: break-word;
        color: #374F21;
        font-weight: bold;
        font-size: 1.1rem;
        margin-top: 10px;
        padding-top: 10px;
        border-top: 2px solid #374F21;
    }
}

.cart-popout h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: #374F21;
}

.cart-popout ul {
    list-style: none;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

.cart-popout ul li {
    background-color: #F8D09A;
    margin-bottom: 5px;
    padding: 10px;
    border-radius: 5px;
    font-size: 1rem;
    color: #374F21;
    border: 1px solid #AECF75;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.cart-popout ul li > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    gap: 8px;
    min-width: 0;
}

.cart-popout .item-price {
    color: #374F21;
    font-weight: bold;
}

.cart-popout .item-quantity {
    color: #374F21;
    font-weight: bold;
}

/* Desktop cart item info container - only applies on desktop */
@media (min-width: 769px) {
    .cart-popout ul li > div > div:first-child {
        flex: 1;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        overflow: visible;
        max-width: 100%;
    }

    .cart-popout ul li > div > div:first-child > span:first-child {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: calc(100% - 140px); /* Reserve space for badge and buttons */
    }

    .cart-popout ul li > div > div:first-child .item-quantity {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Quantity controls container should not be cut off */
    .cart-popout ul li > div > div:first-child > div {
        display: flex;
        align-items: center;
        gap: 5px;
        flex-shrink: 0;
        overflow: visible;
        margin-right: 8px;
    }

    .cart-popout ul li > div > div:first-child .quantity-btn {
        flex-shrink: 0;
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }

    .cart-popout .item-price {
        min-width: 70px;
        flex-shrink: 0;
    }

    .cart-popout .remove-item {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 5px 10px;
        font-size: 0.85rem;
    }
}

.cart-popout #cartTotal {
    color: #374F21;
    font-weight: bold;
    font-size: 1.2rem;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #374F21;
}

.quantity-btn {
    transition: background-color 0.2s, transform 0.1s;
    background-color: #AECF75;
    color: #374F21;
    border: 1px solid #374F21;
}

.quantity-btn:hover {
    background-color: #F8D09A !important;
    transform: scale(1.05);
}

.quantity-btn:active {
    transform: scale(0.95);
}

.remove-item {
    background-color: #D32A29;
    color: #F9EEDE;
    border: none;
    padding: 5px 10px;
    font-size: 0.9rem;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-weight: bold;
}

.remove-item:hover {
    background-color: #b02120;
}

/* Form Styling */
.order-form h2 {
    color: #374F21;
    margin-bottom: 20px;
}

.order-form label {
    display: block;
    margin-bottom: 10px;
    font-size: 1rem;
    font-weight: bold;
    color: #374F21;
}

.order-form input[type="text"],
.order-form input[type="number"] {
    width: 100%;
    max-width: 400px;
    padding: 12px;
    margin-bottom: 10px;
    border: 2px solid #F8D09A;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    background-color: #fff;
    color: #374F21;
    font-weight: bold;
    text-align: center;
}

.order-form input[type="text"]:focus,
.order-form input[type="number"]:focus {
    outline: none;
    border-color: #AECF75;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(174, 207, 117, 0.2);
}

.order-form input[type="number"] {
    font-size: 1.3rem;
    border-width: 3px;
    border-color: #AECF75;
    background: linear-gradient(135deg, #F9FFE5 0%, #FFFFFF 100%);
    box-shadow: 0 2px 8px rgba(174, 207, 117, 0.3);
}

.order-form input[type="number"]:focus {
    border-color: #374F21;
    box-shadow: 0 0 0 4px rgba(55, 79, 33, 0.2), 0 4px 12px rgba(174, 207, 117, 0.4);
    background: #FFFFFF;
    transform: scale(1.02);
}

.order-form input[type="number"]::placeholder {
    color: #AECF75;
    opacity: 0.7;
}

#submitOrder {
    background-color: #D32A29;
    color: #F9EEDE;
    border: 2px solid #374F21;
    padding: 12px 30px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
    margin-top: 20px;
    margin-bottom: 40px;
    display: block;
    width: auto;
    max-width: 300px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: 0 4px 8px rgba(55, 79, 33, 0.3);
}

#submitOrder:hover {
    background-color: #b02120;
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(55, 79, 33, 0.4);
}

#submitOrder:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
    opacity: 0.6;
}

#submitOrder:disabled:hover {
    background-color: #cccccc;
}