:root {
    --primary: #8b5a2b; /* Coffee brown */
    --primary-light: #c19a6b;
    --accent: #d2691e;
    --bg-color: #f7f3ed;
    --surface: rgba(255, 255, 255, 0.7);
    --surface-solid: #ffffff;
    --text-main: #333333;
    --text-muted: #777777;
    --border: rgba(139, 90, 43, 0.15);
    --success: #2e7d32;
    --danger: #d32f2f;
    --radius: 16px;
    --radius-sm: 8px;
    --shadow: 0 8px 32px rgba(139, 90, 43, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Kanit', 'Inter', sans-serif;
    background: linear-gradient(135deg, #f7f3ed 0%, #e8dfd1 100%);
    color: var(--text-main);
    overflow: hidden; /* Prevent body scroll on iOS */
}

/* Glassmorphism utility */
.glass-panel {
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 250px;
    height: 100%;
    background: var(--surface-solid);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: transform 0.3s ease;
}

.logo-area {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.logo-area h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: 600;
}

.categories-list {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.category-item {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
}

.category-item:hover {
    background: rgba(139, 90, 43, 0.05);
}

.category-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(139, 90, 43, 0.3);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.main-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--surface);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    z-index: 5;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--primary);
}

.main-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.cart-toggle-btn {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    position: relative;
    transition: transform 0.1s;
}

.cart-toggle-btn:active {
    transform: scale(0.95);
}

.cart-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
}

.products-grid {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 15px;
    align-content: start;
}

.product-card {
    background: var(--surface-solid);
    border-radius: var(--radius);
    padding: 15px;
    text-align: center;
    cursor: pointer;
    border: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 120px;
}

.product-card:active {
    transform: scale(0.96);
    background: #fdfaf5;
}

.product-name {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 8px;
}

.product-price {
    color: var(--primary);
    font-weight: 700;
}

/* Cart Panel */
.cart-panel {
    width: 350px;
    height: 100%;
    background: var(--surface-solid);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 20px rgba(0,0,0,0.05);
    z-index: 20;
    transition: transform 0.3s ease;
}

.cart-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
}

.close-cart-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    display: none;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.empty-cart-msg {
    text-align: center;
    color: var(--text-muted);
    margin-top: 50px;
    font-style: italic;
}

.cart-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px;
    background: #fdfaf5;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.cart-item-details h4 {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.cart-item-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.cart-item-actions {
    text-align: right;
}

.cart-item-price {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 5px;
}

.remove-btn {
    background: none;
    border: none;
    color: var(--danger);
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: underline;
}

.cart-footer {
    padding: 20px;
    background: #fff;
    border-top: 1px solid var(--border);
}

.cart-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 15px;
}

.total-price {
    color: var(--primary);
    font-size: 1.5rem;
}

.payment-methods {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.payment-methods label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-weight: 500;
}

.checkout-btn {
    width: 100%;
    padding: 15px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1.1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 15px rgba(139, 90, 43, 0.4);
}

.checkout-btn:disabled {
    background: #ccc;
    box-shadow: none;
    cursor: not-allowed;
}

.checkout-btn:not(:disabled):active {
    transform: translateY(2px);
    box-shadow: 0 2px 5px rgba(139, 90, 43, 0.4);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    width: 90%;
    max-width: 400px;
    border-radius: var(--radius);
    overflow: hidden;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    padding: 15px 20px;
    background: var(--primary);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-modal-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.option-group {
    margin-bottom: 20px;
}

.option-group h4 {
    margin-bottom: 10px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.segmented-control {
    display: flex;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: hidden;
}

.segmented-control label {
    flex: 1;
    text-align: center;
    position: relative;
    cursor: pointer;
}

.segmented-control input[type="radio"] {
    position: absolute;
    opacity: 0;
}

.seg-btn {
    display: block;
    padding: 10px 5px;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.segmented-control input[type="radio"]:checked + .seg-btn {
    background: var(--primary-light);
    color: white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.price-preview {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

.add-to-cart-confirm-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
}

/* Toast */
.toast {
    position: fixed;
    bottom: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000;
    transition: bottom 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.toast.show {
    bottom: 30px;
}

/* Responsive for iPhone / iPad */
@media (max-width: 800px) {
    .sidebar {
        position: absolute;
        left: -250px;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .mobile-menu-btn {
        display: block;
    }
    
    .cart-panel {
        position: absolute;
        right: -350px;
        width: 100%;
        max-width: 400px;
    }
    
    .cart-panel.open {
        right: 0;
    }
    
    .close-cart-btn {
        display: block;
    }
    
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
        padding: 15px;
    }
    
    .product-card {
        min-height: 100px;
        padding: 10px;
    }
}
